diff options
| author | Camille Mougey <commial@gmail.com> | 2018-06-22 10:28:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-22 10:28:38 +0200 |
| commit | 9f040a7013f471ecb96c5f64e5ab3f139d1a09c7 (patch) | |
| tree | f4f21334788d6c153ce08cead01e614349cdf700 /miasm2/expression/simplifications_common.py | |
| parent | 1c64ca68ff3ad2985d2c89b4b8a8e13ec282c0e1 (diff) | |
| parent | 189d72985236b0b35586669e7d9309951ffdccb6 (diff) | |
| download | miasm-9f040a7013f471ecb96c5f64e5ab3f139d1a09c7.tar.gz miasm-9f040a7013f471ecb96c5f64e5ab3f139d1a09c7.zip | |
Merge branch 'master' into patch-2
Diffstat (limited to 'miasm2/expression/simplifications_common.py')
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 13b25ce2..149c5b8d 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -250,6 +250,26 @@ def simp_cst_propagation(e_s, expr): e_s(Y.msb()) == ExprInt(0, 1)): args = [args[0].args[0], X + Y] + # ((var >> int1) << int1) => var & mask + # ((var << int1) >> int1) => var & mask + if (op_name in ['<<', '>>'] and + args[0].is_op() and + args[0].op in ['<<', '>>'] and + op_name != args[0]): + var = args[0].args[0] + int1 = args[0].args[1] + int2 = args[1] + if int1 == int2 and int1.is_int() and int(int1) < expr.size: + if op_name == '>>': + mask = ExprInt((1 << (expr.size - int(int1))) - 1, expr.size) + else: + mask = ExprInt( + ((1 << int(int1)) - 1) ^ ((1 << expr.size) - 1), + expr.size + ) + ret = var & mask + return ret + # ((A & A.mask) if op_name == "&" and args[-1] == expr.mask: return ExprOp('&', *args[:-1]) |