diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2017-06-02 15:47:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-02 15:47:29 +0200 |
| commit | db9c8ea88376eb62f178829151b6a272b068b39d (patch) | |
| tree | 163258e5e4981a7a2b1b53eeee16ff80b0f55e6d | |
| parent | e0235fcd5ee2e29d0b6b13cc576ae6fe23ed0b30 (diff) | |
| parent | 274cff35ec85c149c9fbcccbc135349509baa31c (diff) | |
| download | miasm-db9c8ea88376eb62f178829151b6a272b068b39d.tar.gz miasm-db9c8ea88376eb62f178829151b6a272b068b39d.zip | |
Merge pull request #564 from commial/feature/compose-mem-simpl
Add a new simplification merging ExprMem sharing the same base in ExprCompose
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 11 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 01db7597..eb9d0958 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -542,6 +542,17 @@ def simp_compose(e_s, e): new_e = args[0].arg >> ExprInt(args[0].start, args[0].arg.size) return new_e + # {@X[base + i] 0 X, @Y[base + i + X] X (X + Y)} => @(X+Y)[base + i] + for i, arg in enumerate(args[:-1]): + nxt = args[i + 1] + if arg.is_mem() and nxt.is_mem(): + gap = e_s(nxt.arg - arg.arg) + if gap.is_int() and int(gap) == arg.size / 8: + args = args[:i] + [ExprMem(arg.arg, + arg.size + nxt.size)] + args[i + 2:] + return ExprCompose(*args) + + # Compose with ExprCond with integers for src1/src2 and intergers => # propagage integers # {XXX?(0x0,0x1)?(0x0,0x1),0,8, 0x0,8,32} => XXX?(int1, int2) diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 60c328dc..efabddb5 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -314,6 +314,11 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (ExprOp("imod", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], ExprInt(0x01, 8)), + (ExprCompose(ExprInt(0x0123, 16), ExprMem(a + ExprInt(0x40, a.size), 16), + ExprMem(a + ExprInt(0x42, a.size), 16), ExprInt(0x0321, 16)), + ExprCompose(ExprInt(0x0123, 16), ExprMem(a + ExprInt(0x40, a.size), 32), + ExprInt(0x0321, 16))), + ] for e, e_check in to_test[:]: |