diff options
| -rw-r--r-- | miasm2/arch/x86/arch.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/x86/sem.py | 43 | ||||
| -rw-r--r-- | miasm2/expression/expression_helper.py | 2 | ||||
| -rw-r--r-- | miasm2/expression/simplifications.py | 5 | ||||
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 4 |
5 files changed, 32 insertions, 24 deletions
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py index 5ccc4a9c..b8991887 100644 --- a/miasm2/arch/x86/arch.py +++ b/miasm2/arch/x86/arch.py @@ -476,6 +476,8 @@ class instruction_x86(instruction): return True if self.name.startswith('LOOP'): return True + if self.name.startswith('INT'): + return True if self.name.startswith('SYS'): return True # repxx yyy generate split flow diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 4b8a357b..f85a6bcf 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -314,10 +314,22 @@ def l_test(ir, instr, a, b): return None, e, [] + +def get_shift(a, b): + # b.size must match a + b = b.zeroExtend(a.size) + if a.size == 64: + shift = b & ExprInt_from(b, 0x3f) + else: + shift = b & ExprInt_from(b, 0x1f) + shift = expr_simp(shift) + return shift + + def l_rol(ir, instr, a, b): e = [] - b = b.zeroExtend(a.size) - c = ExprOp('<<<', a, b) + shifter = get_shift(a, b) + c = ExprOp('<<<', a, shifter) new_cf = c[:1] e.append(ExprAff(cf, new_cf)) @@ -329,8 +341,8 @@ def l_rol(ir, instr, a, b): def l_ror(ir, instr, a, b): e = [] - b = b.zeroExtend(a.size) - c = ExprOp('>>>', a, b) + shifter = get_shift(a, b) + c = ExprOp('>>>', a, shifter) e.append(ExprAff(cf, c.msb())) # hack (only valid if b=1): when count == 1: a = msb-1(dest) @@ -341,9 +353,9 @@ def l_ror(ir, instr, a, b): def rcl(ir, instr, a, b): e = [] - b = b.zeroExtend(a.size) - c = ExprOp('<<<c_rez', a, b, cf.zeroExtend(a.size)) - new_cf = ExprOp('<<<c_cf', a, b, cf.zeroExtend(a.size))[:1] + shifter = get_shift(a, b) + c = ExprOp('<<<c_rez', a, shifter, cf.zeroExtend(a.size)) + new_cf = ExprOp('<<<c_cf', a, shifter, cf.zeroExtend(a.size))[:1] e.append(ExprAff(cf, new_cf)) # hack (only valid if b=1) @@ -354,9 +366,9 @@ def rcl(ir, instr, a, b): def rcr(ir, instr, a, b): e = [] - b = b.zeroExtend(a.size) - c = ExprOp('>>>c_rez', a, b, cf.zeroExtend(a.size)) - new_cf = ExprOp('>>>c_cf', a, b, cf.zeroExtend(a.size))[:1] + shifter = get_shift(a, b) + c = ExprOp('>>>c_rez', a, shifter, cf.zeroExtend(a.size)) + new_cf = ExprOp('>>>c_cf', a, shifter, cf.zeroExtend(a.size))[:1] e.append(ExprAff(cf, new_cf)) # hack (only valid if b=1) @@ -366,17 +378,6 @@ def rcr(ir, instr, a, b): return None, e, [] -def get_shift(a, b): - # b.size must match a - b = b.zeroExtend(a.size) - if a.size == 64: - shift = b & ExprInt_from(b, 0x3f) - else: - shift = b & ExprInt_from(b, 0x1f) - shift = expr_simp(shift) - return shift - - def sar(ir, instr, a, b): shifter = get_shift(a, b) diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py index cd59730b..0a4dd3ca 100644 --- a/miasm2/expression/expression_helper.py +++ b/miasm2/expression/expression_helper.py @@ -128,7 +128,7 @@ def merge_sliceto_slice(args): op_propag_cst = ['+', '*', '^', '&', '|', '>>', - '<<', "a>>", ">>>", "/", "%", 'idiv', 'irem'] + '<<', "a>>", ">>>", "<<<", "/", "%", 'idiv', 'irem'] def is_pure_int(e): diff --git a/miasm2/expression/simplifications.py b/miasm2/expression/simplifications.py index e93ccd8c..d633cf3e 100644 --- a/miasm2/expression/simplifications.py +++ b/miasm2/expression/simplifications.py @@ -2,9 +2,10 @@ # Simplification methods library # # # -import miasm2.expression.expression as m2_expr -from miasm2.expression import simplifications_common, simplifications_cond +from miasm2.expression import simplifications_common +from miasm2.expression import simplifications_cond from miasm2.expression.expression_helper import fast_unify +import miasm2.expression.expression as m2_expr # Expression Simplifier # --------------------- diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index e620a97d..c907fe84 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -21,6 +21,7 @@ def simp_cst_propagation(e_s, e): op = e.op # simpl integer manip # int OP int => int + # TODO: <<< >>> << >> are architecture dependant if op in op_propag_cst: while (len(args) >= 2 and isinstance(args[-1], ExprInt) and @@ -46,7 +47,10 @@ def simp_cst_propagation(e_s, e): x2 = mod_size2int[i2.arg.size](i2.arg) o = mod_size2uint[i1.arg.size](x1 >> x2) elif op == '>>>': + rounds = i2.arg o = i1.arg >> i2.arg | i1.arg << (i1.size - i2.arg) + elif op == '<<<': + o = i1.arg << i2.arg | i1.arg >> (i1.size - i2.arg) elif op == '/': o = i1.arg / i2.arg elif op == '%': |