diff options
| -rw-r--r-- | miasm/expression/simplifications_common.py | 9 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/miasm/expression/simplifications_common.py b/miasm/expression/simplifications_common.py index ddd21a63..e96d6fea 100644 --- a/miasm/expression/simplifications_common.py +++ b/miasm/expression/simplifications_common.py @@ -1570,7 +1570,8 @@ def simp_compose_and_mask(_, expr): return expr if not arg2.is_int(): return expr - for i in range(8, arg1.size, 8): - if arg2.arg == ExprInt(0, i).mask.arg: - return ExprSlice(arg1, 0, i) - return expr + int2 = arg2.arg.arg + if (int2 + 1) & int2 != 0: + return expr + mask_size = int2.bit_length() + 7 // 8 + return ExprSlice(arg1, 0, mask_size).zeroExtend(expr.size) diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index ddaa2f20..31d55b71 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -193,8 +193,8 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (ExprOp('<<', ExprOp('>>', a, ExprInt(0x4, 32)), ExprInt(0x4, 32)), ExprOp('&', a, ExprInt(0xFFFFFFF0, 32))), - (ExprCompose(ExprInt(0x1234, 16), ExprId("a", 16)) & ExprInt(0xFF, 32), ExprInt(0x34, 8)), - (ExprCompose(ExprInt(0x12, 8), ExprInt(0x34, 8)) & ExprInt(0xFFFF, 16), ExprInt(0x3412, 16)), + (ExprCompose(ExprInt(0x1234, 16), ExprId("a", 16)) & ExprInt(0xFF, 32), ExprInt(0x34, 32)), + (ExprCompose(ExprInt(0x12, 8), ExprInt(0x34, 8)) & ExprInt(0xFFFF, 16), ExprInt(0x3412, 32)), (ExprCompose(ExprInt(0x12, 8), ExprInt(0x3456, 16), ExprInt(0x78, 8)) & ExprInt(0xFFFFFF, 32), ExprInt(0x345612, 32)), (ExprCompose(ExprInt(0x1234, 16), ExprId("a", 8), ExprInt(0x67, 8)) & ExprInt(0xFFFFFFFF, 32), ExprCompose(ExprInt(0x1234, 16), ExprId("a", 8), ExprInt(0x67, 8))), |