diff options
| author | Pierre Lalet <pierre@droids-corp.org> | 2015-03-24 10:52:56 +0100 |
|---|---|---|
| committer | Pierre Lalet <pierre@droids-corp.org> | 2015-03-24 10:52:56 +0100 |
| commit | 9d6111f4ba840486d18457e900dc2cc8457c624a (patch) | |
| tree | 2204c336a1f4a70b4a30b8a4720de2f908b4ba65 | |
| parent | 4ff91550b953a661abaa49b936ae76a6b955df9f (diff) | |
| parent | d8fdbbc563df9f99d29387951d9f007d59623703 (diff) | |
| download | miasm-9d6111f4ba840486d18457e900dc2cc8457c624a.tar.gz miasm-9d6111f4ba840486d18457e900dc2cc8457c624a.zip | |
Merge pull request #129 from serpilliere/fix_mul_simp
Fix mul simp.
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 5 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 16 |
2 files changed, 11 insertions, 10 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 13588ffd..ab3e2e82 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -447,9 +447,8 @@ def simp_slice(e_s, e): e = ExprCond(e.arg.cond, src1, src2) # (a * int)[0:y] => (a[0:y] * int[0:y]) - elif (isinstance(e.arg, ExprOp) and - e.arg.op == "*" and - isinstance(e.arg.args[-1], ExprInt)): + elif (e.start == 0 and isinstance(e.arg, ExprOp) and + e.arg.op == "*" and isinstance(e.arg.args[-1], ExprInt)): args = [e_s.expr_simp_wrapper(a[e.start:e.stop]) for a in e.arg.args] e = ExprOp(e.arg.op, *args) diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index f4b4fcd6..e5bb109c 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -36,7 +36,7 @@ x = ExprMem(a + b + ExprInt32(0x42)) # Define tests: (expression to simplify, expected value) to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), ((ExprInt32(5) + c + a + b - a + ExprInt32(1) - ExprInt32(5)), - b + c + ExprInt32(1)), + ExprOp('+', b, c, ExprInt32(1))), (a + b + c - a - b - c + a, a), (a + a + b + c - (a + (b + c)), a), (c ^ b ^ a ^ c ^ b, a), @@ -52,13 +52,13 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprOp('<<<', a, ExprOp('<<<', b, c)), ExprOp('<<<', a, ExprOp('<<<', b, c))), (ExprOp('<<<', ExprOp('<<<', a, b), c), - ExprOp('<<<', ExprOp('<<<', a, b), c)), + ExprOp('<<<', a, (b+c))), (ExprOp('<<<', ExprOp('>>>', a, b), c), - ExprOp('<<<', ExprOp('>>>', a, b), c)), + ExprOp('>>>', a, (b-c))), (ExprOp('>>>', ExprOp('<<<', a, b), c), - ExprOp('>>>', ExprOp('<<<', a, b), c)), + ExprOp('<<<', a, (b-c))), (ExprOp('>>>', ExprOp('<<<', a, b), b), - ExprOp('>>>', ExprOp('<<<', a, b), b)), + a), (ExprOp('>>>', ExprOp('<<<', a, ExprInt32(10)), ExprInt32(2)), @@ -137,7 +137,7 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprOp('*', -a, -b, c, ExprInt32(0x12)), ExprOp('*', a, b, c, ExprInt32(0x12))), (ExprOp('*', -a, -b, -c, ExprInt32(0x12)), - ExprOp('*', -a, b, c, ExprInt32(0x12))), + - ExprOp('*', a, b, c, ExprInt32(0x12))), (a | ExprInt32(0xffffffff), ExprInt32(0xffffffff)), (ExprCond(a, ExprInt32(1), ExprInt32(2)) * ExprInt32(4), @@ -197,13 +197,15 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), ExprCompose([(a, 0, 32), (d, 32, 64)])), (ExprCompose([(f[:32], 0, 32), (ExprInt32(0), 32, 64)]) | ExprCompose([(ExprInt32(0), 0, 32), (f[32:], 32, 64)]), f), + ((ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) * ExprInt64(0x123))[32:64], + (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) * ExprInt64(0x123))[32:64]) + ] for e, e_check in to_test[:]: # print "#" * 80 - e_check = expr_simp(e_check) # print str(e), str(e_check) e_new = expr_simp(e) print "original: ", str(e), "new: ", str(e_new) |