about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorHugo Porcher <hugo.r.porcher@gmail.com>2019-03-21 10:55:38 -0400
committerHugo Porcher <hugo.r.porcher@gmail.com>2019-03-21 10:55:38 -0400
commitaef466589f35233ddd0931ca030c5238eb99a58e (patch)
tree85ad4097162fdd4b2ce7123713c1ae52290100ab
parent9352e00584b64efd54f15e2c128f7482da64ae10 (diff)
downloadmiasm-aef466589f35233ddd0931ca030c5238eb99a58e.tar.gz
miasm-aef466589f35233ddd0931ca030c5238eb99a58e.zip
Add zeroextend and fix loop
Diffstat (limited to '')
-rw-r--r--miasm/expression/simplifications_common.py9
-rw-r--r--test/expression/simplifications.py4
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))),