diff options
| -rw-r--r-- | example/ida/utils.py | 2 | ||||
| -rw-r--r-- | miasm2/ir/translators/python.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/example/ida/utils.py b/example/ida/utils.py index 9af98cc5..a7d2418a 100644 --- a/example/ida/utils.py +++ b/example/ida/utils.py @@ -113,7 +113,7 @@ def expr2colorstr(regs_ids, expr): s += ", ".join(["%s, %s, %s" % (expr2colorstr(regs_ids, subexpr), idaapi.COLSTR(str(idx), idaapi.SCOLOR_RPTCMT), - idaapi.COLSTR(str(idx + expr.size), + idaapi.COLSTR(str(idx + subexpr.size), idaapi.SCOLOR_RPTCMT)) for idx, subexpr in expr.iter_args()]) s += "}" 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): |