From c887ab5c5da2c12ccb84be93da238a9c9be3e229 Mon Sep 17 00:00:00 2001 From: Ajax Date: Tue, 13 Feb 2018 14:46:18 +0100 Subject: A >> X >> Y => A >> (X+Y) ONLY IF X + Y does not overflow --- miasm2/expression/simplifications_common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'miasm2/expression/simplifications_common.py') diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 6eb5e804..6840a0ac 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -212,10 +212,15 @@ def simp_cst_propagation(e_s, expr): args0 = args[0].args[0] args = [args0, args1] - # A >> X >> Y => A >> (X+Y) + # A >> X >> Y => A >> (X+Y) if X + Y does not overflow + # To be sure, only consider the simplification when X.msb and Y.msb are 0 if (op_name in ['<<', '>>'] and args[0].is_op(op_name)): - args = [args[0].args[0], args[0].args[1] + args[1]] + X = args[0].args[1] + Y = args[1] + if (e_s(X.msb()) == ExprInt(0, 1) and + e_s(Y.msb()) == ExprInt(0, 1)): + args = [args[0].args[0], X + Y] # ((A & A.mask) if op_name == "&" and args[-1] == expr.mask: -- cgit 1.4.1