about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/expression/expression.py3
-rw-r--r--miasm2/expression/expression_helper.py2
-rw-r--r--miasm2/expression/simplifications_common.py4
-rw-r--r--test/expression/simplifications.py2
4 files changed, 9 insertions, 2 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py
index de6746ef..c9c2627c 100644
--- a/miasm2/expression/expression.py
+++ b/miasm2/expression/expression.py
@@ -217,6 +217,9 @@ class Expr(object):
     def __neg__(self):
         return ExprOp('-', self)
 
+    def __pow__(self, a):
+        return ExprOp("**",self, a)
+
     def __invert__(self):
         s = self.size
         return ExprOp('^', self, ExprInt(mod_size2uint[s](size2mask(s))))
diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py
index 44b4b5af..09feffc2 100644
--- a/miasm2/expression/expression_helper.py
+++ b/miasm2/expression/expression_helper.py
@@ -135,7 +135,7 @@ def merge_sliceto_slice(args):
 
 op_propag_cst = ['+', '*', '^', '&', '|', '>>',
                  '<<', "a>>", ">>>", "<<<",
-                 "/", "%", 'idiv', 'imod', 'umod', 'udiv']
+                 "/", "%", 'idiv', 'imod', 'umod', 'udiv','**']
 
 
 def is_pure_int(e):
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py
index a52debe6..2d5e4e6b 100644
--- a/miasm2/expression/simplifications_common.py
+++ b/miasm2/expression/simplifications_common.py
@@ -30,6 +30,8 @@ def simp_cst_propagation(e_s, e):
                 o = i1.arg + i2.arg
             elif op == '*':
                 o = i1.arg * i2.arg
+            elif op == '**':
+                o =i1.arg ** i2.arg
             elif op == '^':
                 o = i1.arg ^ i2.arg
             elif op == '&':
@@ -194,7 +196,7 @@ def simp_cst_propagation(e_s, e):
             j += 1
         i += 1
 
-    if op in ['|', '&', '%', '/'] and len(args) == 1:
+    if op in ['|', '&', '%', '/', '**'] and len(args) == 1:
         return args[0]
 
     # A <<< A.size => A
diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py
index a4592e9d..99cc7c35 100644
--- a/test/expression/simplifications.py
+++ b/test/expression/simplifications.py
@@ -144,6 +144,8 @@ 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('**', ExprInt32(2), ExprInt32(8)), ExprInt32(0x100)),
+     (ExprInt32(2)**ExprInt32(8), ExprInt32(256)),
     (a | ExprInt32(0xffffffff),
      ExprInt32(0xffffffff)),
     (ExprCond(a, ExprInt32(1), ExprInt32(2)) * ExprInt32(4),