about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/ir/translators/python.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/miasm2/ir/translators/python.py b/miasm2/ir/translators/python.py
index c06d865c..d7369e9e 100644
--- a/miasm2/ir/translators/python.py
+++ b/miasm2/ir/translators/python.py
@@ -1,3 +1,4 @@
+from miasm2.expression.expression import ExprInt
 from miasm2.ir.translators.translator import Translator
 
 
@@ -55,6 +56,19 @@ class TranslatorPython(Translator):
         elif expr.op == "parity":
             return "(%s & 0x1)" % self.from_expr(expr.args[0])
 
+        elif expr.op in ["<<<", ">>>"]:
+            amount_raw = expr.args[1]
+            amount = expr.args[1] % ExprInt(amount_raw.size, expr.size)
+            amount_inv = ExprInt(expr.size, expr.size) - amount
+            if expr.op == "<<<":
+                amount, amount_inv = amount_inv, amount
+            part1 = "(%s >> %s)"% (self.from_expr(expr.args[0]),
+                                   self.from_expr(amount))
+            part2 = "(%s << %s)"% (self.from_expr(expr.args[0]),
+                                         self.from_expr(amount_inv))
+
+            return "((%s | %s) &0x%x)" % (part1, part2, int(expr.mask))
+
         raise NotImplementedError("Unknown operator: %s" % expr.op)
 
     def from_ExprAff(self, expr):