diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-10-29 10:35:32 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-10-29 13:37:03 +0100 |
| commit | c4e4273c2d4e459eddc96c8ef0af0e5eff9c3f7e (patch) | |
| tree | eae7ae526c7e45d1e640c814ec3a03d5b999fac8 | |
| parent | e37d545e07a22b0ea9a5ce21b975c73927dd4d50 (diff) | |
| download | miasm-c4e4273c2d4e459eddc96c8ef0af0e5eff9c3f7e.tar.gz miasm-c4e4273c2d4e459eddc96c8ef0af0e5eff9c3f7e.zip | |
Expression: fix api
| -rw-r--r-- | miasm2/arch/aarch64/arch.py | 22 | ||||
| -rw-r--r-- | miasm2/arch/arm/arch.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/msp430/arch.py | 20 | ||||
| -rw-r--r-- | miasm2/arch/msp430/sem.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/x86/arch.py | 33 | ||||
| -rw-r--r-- | miasm2/arch/x86/sem.py | 71 | ||||
| -rw-r--r-- | miasm2/core/cpu.py | 6 | ||||
| -rw-r--r-- | miasm2/core/parse_asm.py | 2 | ||||
| -rw-r--r-- | miasm2/expression/expression.py | 14 | ||||
| -rw-r--r-- | miasm2/expression/expression_helper.py | 9 | ||||
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 22 | ||||
| -rw-r--r-- | miasm2/ir/translators/miasm.py | 2 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore_python.py | 8 | ||||
| -rw-r--r-- | test/arch/arm/sem.py | 4 | ||||
| -rw-r--r-- | test/arch/msp430/sem.py | 2 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 14 |
16 files changed, 110 insertions, 123 deletions
diff --git a/miasm2/arch/aarch64/arch.py b/miasm2/arch/aarch64/arch.py index 816d67f4..3545e4c5 100644 --- a/miasm2/arch/aarch64/arch.py +++ b/miasm2/arch/aarch64/arch.py @@ -592,7 +592,7 @@ class aarch64_simdreg_32_64_zero(aarch64_simdreg_32_64): def decode(self, v): if v == 0 and self.parent.opc.value == 1: size = 64 if self.parent.size.value else 32 - self.expr = m2_expr.ExprInt_fromsize(size, 0) + self.expr = m2_expr.ExprInt(0, size) return True else: return super(aarch64_simdreg_32_64_zero, self).decode(v) @@ -651,7 +651,7 @@ class aarch64_gpreg0(bsi, m_arg): def decode(self, v): size = 64 if self.parent.sf.value else 32 if v == 0x1F: - self.expr = m2_expr.ExprInt_fromsize(size, 0) + self.expr = m2_expr.ExprInt(0, size) else: self.expr = self.gpregs_info[size].expr[v] return True @@ -806,11 +806,11 @@ def set_imm_to_size(size, expr): if size == expr.size: return expr if size > expr.size: - expr = m2_expr.ExprInt_fromsize(size, expr.arg) + expr = m2_expr.ExprInt(int(expr.arg), size) else: if expr.arg > (1 << size) - 1: return None - expr = m2_expr.ExprInt_fromsize(size, expr.arg) + expr = m2_expr.ExprInt(int(expr.arg), size) return expr @@ -845,7 +845,7 @@ class aarch64_imm_sf(imm_noarg): def decode(self, v): size = 64 if self.parent.sf.value else 32 - self.expr = m2_expr.ExprInt_fromsize(size, v) + self.expr = m2_expr.ExprInt(v, size) return True @@ -872,9 +872,9 @@ class aarch64_imm_sft(aarch64_imm_sf, m_arg): def decode(self, v): size = 64 if self.parent.sf.value else 32 if self.parent.shift.value == 0: - self.expr = m2_expr.ExprInt_fromsize(size, v) + self.expr = m2_expr.ExprInt(v, size) elif self.parent.shift.value == 1: - self.expr = m2_expr.ExprInt_fromsize(size, v << 12) + self.expr = m2_expr.ExprInt(v << 12, size) else: return False return True @@ -1076,7 +1076,7 @@ class aarch64_imm_nsr(aarch64_imm_sf, m_arg): size = 64 if self.parent.sf.value else 32 mask = UINTS[size]((1 << (v + 1)) - 1) mask = ror(mask, self.parent.immr.value, size) - self.expr = m2_expr.ExprInt_fromsize(size, mask) + self.expr = m2_expr.ExprInt(mask, size) return True def encode(self): @@ -1158,7 +1158,7 @@ class aarch64_imm_hw(m_arg): def decode(self, v): size = 64 if self.parent.sf.value else 32 - self.expr = m2_expr.ExprInt_fromsize(size, v << (16 * self.parent.hw.value)) + self.expr = m2_expr.ExprInt(v << (16 * self.parent.hw.value), size) return True def encode(self): @@ -1184,8 +1184,8 @@ class aarch64_imm_hw_sc(m_arg): def decode(self, v): size = 64 if self.parent.sf.value else 32 - expr = m2_expr.ExprInt_fromsize(size, v) - amount = m2_expr.ExprInt_fromsize(size, 16 * self.parent.hw.value) + expr = m2_expr.ExprInt(v, size) + amount = m2_expr.ExprInt(16 * self.parent.hw.value, size) if self.parent.hw.value: self.expr = m2_expr.ExprOp(self.shift_op, expr, amount) else: diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py index 41c99d4d..23ce170c 100644 --- a/miasm2/arch/arm/arch.py +++ b/miasm2/arch/arm/arch.py @@ -783,7 +783,7 @@ class arm_offs(arm_imm): def int2expr(self, v): if v & ~self.intmask != 0: return None - return ExprInt_fromsize(self.intsize, v) + return ExprInt(v, self.intsize) def decodeval(self, v): v <<= 2 diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py index 875915c3..cda49608 100644 --- a/miasm2/arch/msp430/arch.py +++ b/miasm2/arch/msp430/arch.py @@ -192,7 +192,7 @@ class instruction_msp430(instruction): # Call argument is an absolute offset # Other offsets are relative to instruction offset if self.name != "call": - self.args[0] = ExprInt_fromsize(16, e.arg - self.offset) + self.args[0] = ExprInt(int(e.arg) - self.offset, 16) def get_info(self, c): pass @@ -328,34 +328,34 @@ class msp430_sreg_arg(reg_noarg, m_arg): e = self.reg_info.expr[v] if self.parent.a_s.value == 0b00: if e == R3: - self.expr = ExprInt_fromsize(size, 0) + self.expr = ExprInt(0, size) else: self.expr = e elif self.parent.a_s.value == 0b01: if e == SR: self.expr = ExprMem(ExprInt16(self.parent.off_s.value), size) elif e == R3: - self.expr = ExprInt_fromsize(size, 1) + self.expr = ExprInt(1, size) else: self.expr = ExprMem( e + ExprInt16(self.parent.off_s.value), size) elif self.parent.a_s.value == 0b10: if e == SR: - self.expr = ExprInt_fromsize(size, 4) + self.expr = ExprInt(4, size) elif e == R3: - self.expr = ExprInt_fromsize(size, 2) + self.expr = ExprInt(2, size) else: self.expr = ExprMem(e, size) elif self.parent.a_s.value == 0b11: if e == SR: - self.expr = ExprInt_fromsize(size, 8) + self.expr = ExprInt(8, size) elif e == R3: if self.parent.size.value == 0: - self.expr = ExprInt_fromsize(size, 0xffff) + self.expr = ExprInt(0xffff, size) else: - self.expr = ExprInt_fromsize(size, 0xff) + self.expr = ExprInt(0xff, size) elif e == PC: - self.expr = ExprInt_fromsize(size, self.parent.off_s.value) + self.expr = ExprInt(self.parent.off_s.value, size) else: self.expr = ExprOp('autoinc', e) else: @@ -523,7 +523,7 @@ class msp430_offs(imm_noarg, m_arg): def int2expr(self, v): if v & ~self.intmask != 0: return None - return ExprInt_fromsize(16, v) + return ExprInt(v, 16) def decodeval(self, v): v <<= 1 diff --git a/miasm2/arch/msp430/sem.py b/miasm2/arch/msp430/sem.py index 7f753381..169a631f 100644 --- a/miasm2/arch/msp430/sem.py +++ b/miasm2/arch/msp430/sem.py @@ -25,7 +25,7 @@ def bcd2hex(val): def reset_sr_res(): - return [ExprAff(res, ExprInt_fromsize(7, 0))] + return [ExprAff(res, ExprInt(0, 7))] def update_flag_zf(a): diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py index bfd6e504..916b5428 100644 --- a/miasm2/arch/x86/arch.py +++ b/miasm2/arch/x86/arch.py @@ -548,8 +548,7 @@ class instruction_x86(instruction): if not isinstance(expr, ExprInt): log.warning('dynamic dst %r', expr) return - self.args[0] = ExprInt_fromsize( - self.mode, expr.arg - self.offset) + self.args[0] = ExprInt(int(expr.arg) - self.offset, self.mode) def get_info(self, c): self.additional_info.g1.value = c.g1.value @@ -1085,8 +1084,8 @@ class x86_08_ne(x86_imm): v = swap_uint(self.l, v) p = self.parent admode = p.v_admode() - expr = sign_ext(v, self.intsize, admode) - self.expr = ExprInt_fromsize(admode, expr) + value = sign_ext(v, self.intsize, admode) + self.expr = ExprInt(value, admode) return True @@ -1872,12 +1871,12 @@ def modrm2expr(modrm, parent, w8, sx=0, xmm=0, mm=0): if isinstance(modrm_k, (int, long)): expr = size2gpregs[admode].expr[modrm_k] if scale != 1: - expr = ExprInt_fromsize(admode, scale) * expr + expr = ExprInt(scale, admode) * expr o.append(expr) if f_imm in modrm: if parent.disp.value is None: return None - o.append(ExprInt_fromsize(admode, parent.disp.expr.arg)) + o.append(ExprInt(int(parent.disp.expr.arg), admode)) expr = ExprOp('+', *o) if w8 == 0: opmode = 8 @@ -2551,7 +2550,7 @@ class bs_cond_disp(bs_cond): v = swap_uint(self.l, v) self.value = v v = sign_ext(v, self.l, admode) - v = ExprInt_fromsize(admode, v) + v = ExprInt(v, admode) self.expr = v return True @@ -2577,8 +2576,7 @@ class bs_cond_imm(bs_cond_scale, m_arg): if isinstance(self.expr, ExprInt): v = int(self.expr.arg) mask = ((1 << l) - 1) - v = v & mask - self.expr = ExprInt_fromsize(l, v) + self.expr = ExprInt(v & mask, l) if self.expr is None: log.debug('cannot fromstring int %r', s) @@ -2663,8 +2661,7 @@ class bs_cond_imm(bs_cond_scale, m_arg): if hasattr(self.parent, 'w8') and self.parent.w8.value == 0: l_out = 8 v = sign_ext(v, self.l, l_out) - v = ExprInt_fromsize(l_out, v) - self.expr = v + self.expr = ExprInt(v, l_out) return True @@ -2702,8 +2699,7 @@ class bs_rel_off(bs_cond_imm): if isinstance(self.expr, ExprInt): v = int(self.expr.arg) mask = ((1 << l) - 1) - v = v & mask - self.expr = ExprInt_fromsize(l, v) + self.expr = ExprInt(v & mask, l) return start, stop @classmethod @@ -2744,8 +2740,7 @@ class bs_rel_off(bs_cond_imm): size = offsize(self.parent) v = sign_ext(v, self.l, size) v += self.parent.l - v = ExprInt_fromsize(size, v) - self.expr = v + self.expr = ExprInt(v, size) return True class bs_s08(bs_rel_off): @@ -2778,8 +2773,7 @@ class bs_s08(bs_rel_off): v = swap_uint(self.l, v) size = offsize(self.parent) v = sign_ext(v, self.l, size) - v = ExprInt_fromsize(size, v) - self.expr = v + self.expr = ExprInt(v, size) return True @@ -2827,8 +2821,7 @@ class bs_moff(bsi): v = swap_uint(self.l, v) self.value = v v = sign_ext(v, self.l, opmode) - v = ExprInt_fromsize(opmode, v) - self.expr = v + self.expr = ExprInt(v, opmode) return True @@ -2891,7 +2884,7 @@ class bs_movoff(m_arg): v = swap_uint(self.l, v) self.value = v v = sign_ext(v, self.l, l) - v = ExprInt_fromsize(l, v) + v = ExprInt(v, l) size = self.parent.v_opmode() if self.parent.w8.value == 0: size = 8 diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index c0dff4fd..e511a534 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -307,7 +307,7 @@ def xadd(ir, instr, a, b): def adc(ir, instr, a, b): e = [] - c = a + (b + m2_expr.ExprCompose([(m2_expr.ExprInt_fromsize(a.size - 1, 0), + c = a + (b + m2_expr.ExprCompose([(m2_expr.ExprInt(0, a.size - 1), 1, a.size), (cf, 0, 1)])) e += update_flag_arith(c) @@ -331,7 +331,7 @@ def sub(ir, instr, a, b): def sbb(ir, instr, a, b): e = [] - c = a - (b + m2_expr.ExprCompose([(m2_expr.ExprInt_fromsize(a.size - 1, 0), + c = a - (b + m2_expr.ExprCompose([(m2_expr.ExprInt(0, a.size - 1), 1, a.size), (cf, 0, 1)])) e += update_flag_arith(c) @@ -1008,7 +1008,7 @@ def compose_eflag(s=32): for i in xrange(len(regs)): args.append((regs[i], i + 14, i + 15)) if s == 32: - args.append((m2_expr.ExprInt_fromsize(10, 0), 22, 32)) + args.append((m2_expr.ExprInt(0, 10), 22, 32)) return m2_expr.ExprCompose(args) @@ -1068,7 +1068,7 @@ def popfw(ir, instr): e.append(m2_expr.ExprAff(of, m2_expr.ExprSlice(tmp, 11, 12))) e.append(m2_expr.ExprAff(iopl, m2_expr.ExprSlice(tmp, 12, 14))) e.append(m2_expr.ExprAff(nt, m2_expr.ExprSlice(tmp, 14, 15))) - e.append(m2_expr.ExprAff(mRSP[instr.mode], mRSP[instr.mode] + m2_expr.ExprInt_fromsize(mRSP[instr.mode].size, 2))) + e.append(m2_expr.ExprAff(mRSP[instr.mode], mRSP[instr.mode] + m2_expr.ExprInt(2, mRSP[instr.mode].size))) return e, [] @@ -1086,8 +1086,7 @@ def pushad(ir, instr): mRSI[instr.mode][:s], mRDI[instr.mode][:s]] for i in xrange(len(regs)): - c = mRSP[instr.mode][:s] + m2_expr.ExprInt_fromsize(s, - -(s / 8) * (i + 1)) + c = mRSP[instr.mode][:s] + m2_expr.ExprInt(-(s / 8) * (i + 1), s) e.append(m2_expr.ExprAff(m2_expr.ExprMem(c, s), regs[i])) e.append(m2_expr.ExprAff(mRSP[instr.mode][:s], c)) return e, [] @@ -1141,20 +1140,20 @@ def call(ir, instr, dst): e.append(m2_expr.ExprAff(ir.IRDst, m2)) - c = myesp + m2_expr.ExprInt_fromsize(s, -s/8) + c = myesp + m2_expr.ExprInt(-s/8, s) e.append(m2_expr.ExprAff(m2_expr.ExprMem(c, size=s).zeroExtend(s), CS.zeroExtend(s))) - c = myesp + m2_expr.ExprInt_fromsize(s, -2*s/8) + c = myesp + m2_expr.ExprInt(-2*s/8, s) e.append(m2_expr.ExprAff(m2_expr.ExprMem(c, size=s).zeroExtend(s), meip.zeroExtend(s))) - c = myesp + m2_expr.ExprInt_fromsize(s, (-2*s) / 8) + c = myesp + m2_expr.ExprInt((-2*s) / 8, s) e.append(m2_expr.ExprAff(myesp, c)) return e, [] - c = myesp + m2_expr.ExprInt_fromsize(s, (-s / 8)) + c = myesp + m2_expr.ExprInt((-s / 8), s) e.append(m2_expr.ExprAff(myesp, c)) if ir.do_stk_segm: c = m2_expr.ExprOp('segm', SS, c) @@ -1175,11 +1174,11 @@ def ret(ir, instr, a=None): myesp = mRSP[instr.mode][:s] if a is None: - a = m2_expr.ExprInt_fromsize(s, 0) - value = (myesp + (m2_expr.ExprInt_fromsize(s, (s / 8)))) + a = m2_expr.ExprInt(0, s) + value = (myesp + (m2_expr.ExprInt((s / 8), s))) else: a = a.zeroExtend(s) - value = (myesp + (m2_expr.ExprInt_fromsize(s, (s / 8)) + a)) + value = (myesp + (m2_expr.ExprInt((s / 8), s) + a)) e.append(m2_expr.ExprAff(myesp, value)) c = myesp @@ -1197,7 +1196,7 @@ def retf(ir, instr, a=None): meip = mRIP[instr.mode] opmode, admode = instr.v_opmode(), instr.v_admode() if a is None: - a = m2_expr.ExprInt_fromsize(s, 0) + a = m2_expr.ExprInt(0, s) s = opmode myesp = mRSP[instr.mode][:s] @@ -1210,12 +1209,12 @@ def retf(ir, instr, a=None): e.append(m2_expr.ExprAff(ir.IRDst, m2_expr.ExprMem(c, size=s).zeroExtend(s))) # e.append(m2_expr.ExprAff(meip, m2_expr.ExprMem(c, size = s))) - c = myesp + m2_expr.ExprInt_fromsize(s, (s / 8)) + c = myesp + m2_expr.ExprInt(s / 8, s) if ir.do_stk_segm: c = m2_expr.ExprOp('segm', SS, c) e.append(m2_expr.ExprAff(CS, m2_expr.ExprMem(c, size=16))) - value = myesp + (m2_expr.ExprInt_fromsize(s, (2*s) / 8) + a) + value = myesp + (m2_expr.ExprInt((2*s) / 8, s) + a) e.append(m2_expr.ExprAff(myesp, value)) return e, [] @@ -1228,7 +1227,7 @@ def leave(ir, instr): e.append(m2_expr.ExprAff(mRBP[size], m2_expr.ExprMem(mRBP[size], size=size))) e.append(m2_expr.ExprAff(myesp, - m2_expr.ExprInt_fromsize(size, size / 8) + mRBP[size])) + m2_expr.ExprInt(size / 8, size) + mRBP[size])) return e, [] @@ -1241,13 +1240,13 @@ def enter(ir, instr, a, b): a = a.zeroExtend(s) e = [] - esp_tmp = myesp - m2_expr.ExprInt_fromsize(s, s / 8) + esp_tmp = myesp - m2_expr.ExprInt(s / 8, s) e.append(m2_expr.ExprAff(m2_expr.ExprMem(esp_tmp, size=s), myebp)) e.append(m2_expr.ExprAff(myebp, esp_tmp)) e.append(m2_expr.ExprAff(myesp, - myesp - (a + m2_expr.ExprInt_fromsize(s, s / 8)))) + myesp - (a + m2_expr.ExprInt(s / 8, s)))) return e, [] @@ -1384,7 +1383,7 @@ def loopne(ir, instr, dst): n = m2_expr.ExprId(ir.get_next_label(instr), instr.mode) - c = m2_expr.ExprCond(mRCX[instr.mode][:s] - m2_expr.ExprInt_fromsize(s, 1), + c = m2_expr.ExprCond(mRCX[instr.mode][:s] - m2_expr.ExprInt(1, s), m2_expr.ExprInt1(1), m2_expr.ExprInt1(0)) c &= zf ^ m2_expr.ExprInt1(1) @@ -1406,7 +1405,7 @@ def loope(ir, instr, dst): myecx = mRCX[instr.mode][:admode] n = m2_expr.ExprId(ir.get_next_label(instr), instr.mode) - c = m2_expr.ExprCond(mRCX[instr.mode][:s] - m2_expr.ExprInt_fromsize(s, 1), + c = m2_expr.ExprCond(mRCX[instr.mode][:s] - m2_expr.ExprInt(1, s), m2_expr.ExprInt1(1), m2_expr.ExprInt1(0)) c &= zf @@ -1759,7 +1758,7 @@ def float_pop(avoid_flt=None, popcount=1): m2_expr.ExprInt_from(float_list[i], 0))) e.append( m2_expr.ExprAff(float_stack_ptr, - float_stack_ptr - m2_expr.ExprInt_fromsize(3, popcount))) + float_stack_ptr - m2_expr.ExprInt(popcount, 3))) return e # XXX TODO @@ -1963,7 +1962,7 @@ def fld(ir, instr, a): e.append(m2_expr.ExprAff(float_st0, src)) e.append( m2_expr.ExprAff(float_stack_ptr, - float_stack_ptr + m2_expr.ExprInt_fromsize(3, 1))) + float_stack_ptr + m2_expr.ExprInt(1, 3))) e += set_float_cs_eip(instr) return e, [] @@ -2349,7 +2348,7 @@ def fptan(ir, instr): m2_expr.ExprInt32(1)))) e.append( m2_expr.ExprAff(float_stack_ptr, - float_stack_ptr + m2_expr.ExprInt_fromsize(3, 1))) + float_stack_ptr + m2_expr.ExprInt(1, 3))) return e, [] @@ -2386,7 +2385,7 @@ def fsincos(ir, instr): e.append(m2_expr.ExprAff(float_st0, m2_expr.ExprOp('fcos', float_st0))) e.append( m2_expr.ExprAff(float_stack_ptr, - float_stack_ptr + m2_expr.ExprInt_fromsize(3, 1))) + float_stack_ptr + m2_expr.ExprInt(1, 3))) return e, [] @@ -2508,7 +2507,7 @@ def daa(ir, instr): e = [] r_al = mRAX[instr.mode][:8] - cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt_fromsize(4, 0x9)) | af + cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) @@ -2538,7 +2537,7 @@ def das(ir, instr): e = [] r_al = mRAX[instr.mode][:8] - cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt_fromsize(4, 0x9)) | af + cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) @@ -2832,7 +2831,7 @@ def l_outs(ir, instr, size): def xlat(ir, instr): e = [] - a = m2_expr.ExprCompose([(m2_expr.ExprInt_fromsize(24, 0), 8, 32), + a = m2_expr.ExprCompose([(m2_expr.ExprInt(0, 24), 8, 32), (mRAX[instr.mode][0:8], 0, 8)]) b = m2_expr.ExprMem(m2_expr.ExprOp('+', mRBX[instr.mode], a), 8) e.append(m2_expr.ExprAff(mRAX[instr.mode][0:8], b)) @@ -2843,16 +2842,16 @@ def cpuid(ir, instr): e = [] e.append( m2_expr.ExprAff(mRAX[instr.mode], - m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt_fromsize(instr.mode, 0)))) + m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt(0, instr.mode)))) e.append( m2_expr.ExprAff(mRBX[instr.mode], - m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt_fromsize(instr.mode, 1)))) + m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt(1, instr.mode)))) e.append( m2_expr.ExprAff(mRCX[instr.mode], - m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt_fromsize(instr.mode, 2)))) + m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt(2, instr.mode)))) e.append( m2_expr.ExprAff(mRDX[instr.mode], - m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt_fromsize(instr.mode, 3)))) + m2_expr.ExprOp('cpuid', mRAX[instr.mode], m2_expr.ExprInt(3, instr.mode)))) return e, [] @@ -2862,8 +2861,8 @@ def bittest_get(a, b): b_mask = {16:4, 32:5, 64:6} b_decal = {16:1, 32:3, 64:7} ptr = a.arg - off_bit = b.zeroExtend(a.size) & m2_expr.ExprInt_fromsize(a.size, - (1<<b_mask[a.size])-1) + off_bit = b.zeroExtend(a.size) & m2_expr.ExprInt((1<<b_mask[a.size])-1, + a.size) off_byte = ((b.zeroExtend(ptr.size) >> m2_expr.ExprInt_from(ptr, 3)) & m2_expr.ExprInt_from(ptr, ((1<<a.size)-1) ^ b_decal[a.size])) @@ -3050,7 +3049,7 @@ def movd(ir, instr, a, b): (m2_expr.ExprInt32(0), 32, 64)]))) elif a in regs_xmm_expr: e.append(m2_expr.ExprAff(a, m2_expr.ExprCompose([(b, 0, 32), - (m2_expr.ExprInt_fromsize(96, 0), 32, 128)]))) + (m2_expr.ExprInt(0, 96), 32, 128)]))) else: e.append(m2_expr.ExprAff(a, b[:32])) return e, [] @@ -3375,7 +3374,7 @@ def movss(ir, instr, a, b): else: # Source Mem Destination XMM e.append(m2_expr.ExprAff(a, m2_expr.ExprCompose([(b, 0, 32), - (m2_expr.ExprInt_fromsize(96, 0), 32, 128)]))) + (m2_expr.ExprInt(0, 96), 32, 128)]))) return e, [] diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py index c42de507..cfbc1dfb 100644 --- a/miasm2/core/cpu.py +++ b/miasm2/core/cpu.py @@ -260,7 +260,7 @@ def extract_ast_core(v, my_id2expr, my_int2expr): pass elif len(sizes) == 1: size = sizes.pop() - my_int2expr = lambda x: m2_expr.ExprInt_fromsize(size, x) + my_int2expr = lambda x: m2_expr.ExprInt(x, size) else: raise ValueError('multiple sizes in ids') e = ast_raw2expr(ast_tokens, my_id2expr, my_int2expr) @@ -965,7 +965,7 @@ class instruction(object): if size is None: default_size = self.get_symbol_size(x, symbols) size = default_size - value = m2_expr.ExprInt_fromsize(size, symbols[name].offset) + value = m2_expr.ExprInt(symbols[name].offset, size) fixed_ids[x] = value e = e.replace_expr(fixed_ids) e = expr_simp(e) @@ -1468,7 +1468,7 @@ class imm_noarg(object): def int2expr(self, v): if (v & ~self.intmask) != 0: return None - return m2_expr.ExprInt_fromsize(self.intsize, v) + return m2_expr.ExprInt(v, self.intsize) def expr2int(self, e): if not isinstance(e, m2_expr.ExprInt): diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py index 3a5751ac..1df8e85b 100644 --- a/miasm2/core/parse_asm.py +++ b/miasm2/core/parse_asm.py @@ -134,7 +134,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0): base_expr = gen_base_expr()[2] my_var_parser = parse_ast(lambda x: m2_expr.ExprId(x, size), lambda x: - m2_expr.ExprInt_fromsize(size, x)) + m2_expr.ExprInt(x, size)) base_expr.setParseAction(my_var_parser) for b in data_raw: diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index bd8c0c58..ca93eb4f 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -288,7 +288,7 @@ class Expr(object): if self.size == size: return self ad_size = size - self.size - n = ExprInt_fromsize(ad_size, 0) + n = ExprInt(0, ad_size) return ExprCompose([(self, 0, self.size), (n, self.size, size)]) @@ -302,9 +302,8 @@ class Expr(object): ad_size = size - self.size c = ExprCompose([(self, 0, self.size), (ExprCond(self.msb(), - ExprInt_fromsize( - ad_size, size2mask(ad_size)), - ExprInt_fromsize(ad_size, 0)), + ExprInt(size2mask(ad_size), ad_size), + ExprInt(0, ad_size)), self.size, size) ]) return c @@ -331,7 +330,7 @@ class Expr(object): def set_mask(self, value): raise ValueError('mask is not mutable') - mask = property(lambda self: ExprInt_fromsize(self.size, -1)) + mask = property(lambda self: ExprInt(-1, self.size)) class ExprInt(Expr): @@ -1168,11 +1167,6 @@ def ExprInt_from(e, i): return ExprInt(mod_size2uint[e.size](i)) -def ExprInt_fromsize(size, i): - "Generate ExprInt with a given size" - return ExprInt(mod_size2uint[size](i)) - - def get_expr_ids_visit(e, ids): if isinstance(e, ExprId): ids.add(e) diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py index 196ad5cd..ece720e0 100644 --- a/miasm2/expression/expression_helper.py +++ b/miasm2/expression/expression_helper.py @@ -43,9 +43,8 @@ def merge_sliceto_slice(args): # sources_int[a.start] = a # copy ExprInt because we will inplace modify arg just below # /!\ TODO XXX never ever modify inplace args... - sources_int[a[1]] = (m2_expr.ExprInt_fromsize(a[2] - a[1], - a[0].arg.__class__( - a[0].arg)), + sources_int[a[1]] = (m2_expr.ExprInt(int(a[0].arg), + a[2] - a[1]), a[1], a[2]) elif isinstance(a[0], m2_expr.ExprSlice): @@ -86,7 +85,7 @@ def merge_sliceto_slice(args): out[0] = m2_expr.ExprInt(a) sorted_s.pop() out[1] = s_start - out[0] = m2_expr.ExprInt_fromsize(size, out[0].arg) + out[0] = m2_expr.ExprInt(int(out[0].arg), size) final_sources.append((start, out)) final_sources_int = final_sources @@ -409,7 +408,7 @@ class ExprRandom(object): @size: (optional) number max bits """ num = random.randint(0, cls.number_max % (2**size)) - return m2_expr.ExprInt_fromsize(size, num) + return m2_expr.ExprInt(num, size) @classmethod def atomic(cls, size=32): diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index d89b7518..d50e81a1 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -76,7 +76,7 @@ def simp_cst_propagation(e_s, e): - o = ExprInt_fromsize(i1.size, o) + o = ExprInt(o, i1.size) args.append(o) # bsf(int) => int @@ -281,7 +281,7 @@ def simp_cst_propagation(e_s, e): filter_args.append((expr, start, stop)) min_index = min(start, min_index) # create entry 0 - expr = ExprInt_fromsize(min_index, 0) + expr = ExprInt(0, min_index) filter_args = [(expr, 0, min_index)] + filter_args return ExprCompose(filter_args) @@ -305,7 +305,7 @@ def simp_cst_propagation(e_s, e): filter_args.append((expr, start, stop)) max_index = max(stop, max_index) # create entry 0 - expr = ExprInt_fromsize(final_size - max_index, 0) + expr = ExprInt(0, final_size - max_index) filter_args += [(expr, max_index, final_size)] return ExprCompose(filter_args) @@ -401,7 +401,7 @@ def simp_slice(e_s, e): elif isinstance(e.arg, ExprInt): total_bit = e.stop - e.start mask = (1 << (e.stop - e.start)) - 1 - return ExprInt_fromsize(total_bit, (e.arg.arg >> e.start) & mask) + return ExprInt(int((e.arg.arg >> e.start) & mask), total_bit) # Slice(Slice(A, x), y) => Slice(A, z) elif isinstance(e.arg, ExprSlice): if e.stop - e.start > e.arg.stop - e.arg.start: @@ -511,18 +511,20 @@ def simp_compose(e_s, e): if len(args) == 1 and args[0][1] == 0 and args[0][2] == e.size: return args[0][0] - # {(X[X.size-z, 0, z), (0, z, X.size)} => (X >> x) + # {(X[z:], 0, X.size-z), (0, X.size-z, X.size)} => (X >> z) if (len(args) == 2 and isinstance(args[1][0], ExprInt) and args[1][0].arg == 0): a1 = args[0] a2 = args[1] if (isinstance(a1[0], ExprSlice) and - a1[1] == 0 and a1[0].stop == a1[0].arg.size): - if a2[1] == a1[0].size and a2[2] == a1[0].arg.size: - new_e = a1[0].arg >> ExprInt_fromsize( - a1[0].arg.size, a1[0].start) - return new_e + a1[1] == 0 and + a1[0].stop == a1[0].arg.size and + a2[1] == a1[0].size and + a2[2] == a1[0].arg.size): + new_e = a1[0].arg >> ExprInt( + a1[0].start, a1[0].arg.size) + return new_e # Compose with ExprCond with integers for src1/src2 and intergers => # propagage integers diff --git a/miasm2/ir/translators/miasm.py b/miasm2/ir/translators/miasm.py index 004a1ba9..f1e4c5ae 100644 --- a/miasm2/ir/translators/miasm.py +++ b/miasm2/ir/translators/miasm.py @@ -10,7 +10,7 @@ class TranslatorMiasm(Translator): return "ExprId(%s, size=%d)" % (repr(expr.name), expr.size) def from_ExprInt(self, expr): - return "ExprInt_fromsize(%d, 0x%x)" % (expr.size, int(expr.arg)) + return "ExprInt(0x%x, %d)" % (int(expr.arg), expr.size) def from_ExprCond(self, expr): return "ExprCond(%s, %s, %s)" % (self.from_expr(expr.cond), diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index bc284825..96db3a2b 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -34,8 +34,8 @@ def update_engine_from_cpu(cpu, exec_engine): for symbol in exec_engine.symbols: if isinstance(symbol, m2_expr.ExprId): if hasattr(cpu, symbol.name): - value = m2_expr.ExprInt_fromsize(symbol.size, - getattr(cpu, symbol.name)) + value = m2_expr.ExprInt(getattr(cpu, symbol.name), + symbol.size) exec_engine.symbols.symbols_id[symbol] = value else: raise NotImplementedError("Type not handled: %s" % symbol) @@ -73,8 +73,8 @@ class JitCore_Python(jitcore.JitCore): size = expr_mem.size / 8 value = self.cpu.get_mem(addr, size) - return m2_expr.ExprInt_fromsize(expr_mem.size, - int(value[::-1].encode("hex"), 16)) + return m2_expr.ExprInt(int(value[::-1].encode("hex"), 16), + expr_mem.size) def func_write(self, symb_exec, dest, data, mem_cache): """Memory read wrapper for symbolic execution diff --git a/test/arch/arm/sem.py b/test/arch/arm/sem.py index 51c42fd1..feef7372 100644 --- a/test/arch/arm/sem.py +++ b/test/arch/arm/sem.py @@ -16,7 +16,7 @@ EXCLUDE_REGS = set([ir_arch().IRDst]) def M(addr): - return ExprMem(ExprInt_fromsize(16, addr), 16) + return ExprMem(ExprInt(addr, 16), 16) def compute(asm, inputstate={}, debug=False): @@ -285,7 +285,7 @@ class TestARMSemantic(unittest.TestCase): self.assertEqual(compute('AND R4, R4, R5 LSR 2 ', {R4: 0xFFFFFFFF, R5: 0x80000041, }), {R4: 0x20000010, R5: 0x80000041, }) self.assertEqual(compute('AND R4, R4, R5 ASR 3 ', {R4: 0xF00000FF, R5: 0x80000081, }), {R4: 0xF0000010, R5: 0x80000081, }) self.assertEqual(compute('AND R4, R4, R5 ROR 4 ', {R4: 0xFFFFFFFF, R5: 0x000000FF, }), {R4: 0xF000000F, R5: 0x000000FF, }) - self.assertEqual(compute('AND R4, R4, R5 RRX ', {R4: 0xFFFFFFFF, R5: 0x00000101, }), {R4: ExprCompose([(ExprInt_fromsize(31, 0x80),0,31), (cf_init,31,32)]), R5: 0x00000101, }) + self.assertEqual(compute('AND R4, R4, R5 RRX ', {R4: 0xFFFFFFFF, R5: 0x00000101, }), {R4: ExprCompose([(ExprInt(0x80, 31),0,31), (cf_init,31,32)]), R5: 0x00000101, }) # §A8.8.15: AND{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <type> <Rs> self.assertEqual(compute('AND R4, R6, R4 LSL R5', {R4: 0x00000001, R5: 0x00000004, R6: -1, }), {R4: 0x00000010, R5: 0x00000004, R6: 0xFFFFFFFF, }) diff --git a/test/arch/msp430/sem.py b/test/arch/msp430/sem.py index 5340a4d2..2488d633 100644 --- a/test/arch/msp430/sem.py +++ b/test/arch/msp430/sem.py @@ -14,7 +14,7 @@ logging.getLogger('cpuhelper').setLevel(logging.ERROR) EXCLUDE_REGS = set([res, ir_arch().IRDst]) def M(addr): - return ExprMem(ExprInt_fromsize(16, addr), 16) + return ExprMem(ExprInt(addr, 16), 16) def compute(asm, inputstate={}, debug=False): diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 6290a807..12d8f958 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -154,9 +154,9 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprCond(a, b, c) >> ExprCond(a, d, e), ExprCond(a, b >> d, c >> e)), - (a & b & ExprInt_fromsize(a.size, -1), a & b), - (a | b | ExprInt_fromsize(a.size, -1), - ExprInt_fromsize(a.size, -1)), + (a & b & ExprInt(-1, a.size), a & b), + (a | b | ExprInt(-1, a.size), + ExprInt(-1, a.size)), (ExprOp('-', ExprInt8(1), ExprInt8(0)), ExprInt8(1)), @@ -165,9 +165,9 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) << ExprInt64(0x10), ExprCompose([(ExprInt16(0), 0, 16), (a, 16, 48), (ExprInt16(0), 48, 64)])), (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) << ExprInt64(0x30), - ExprCompose([(ExprInt_fromsize(48, 0), 0, 48), (a[:0x10], 48, 64)])), + ExprCompose([(ExprInt(0, 48), 0, 48), (a[:0x10], 48, 64)])), (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) << ExprInt64(0x11), - ExprCompose([(ExprInt_fromsize(0x11, 0), 0, 0x11), (a, 0x11, 0x31), (ExprInt_fromsize(0xF, 0), 0x31, 0x40)])), + ExprCompose([(ExprInt(0, 0x11), 0, 0x11), (a, 0x11, 0x31), (ExprInt(0, 0xF), 0x31, 0x40)])), (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) << ExprInt64(0x40), ExprInt64(0)), (ExprCompose([(a, 0, 32), (ExprInt32(0), 32, 64)]) << ExprInt64(0x50), @@ -178,9 +178,9 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprCompose([(ExprInt32(0), 0, 32), (a, 32, 64)]) >> ExprInt64(0x10), ExprCompose([(ExprInt16(0), 0, 16), (a, 16, 48), (ExprInt16(0), 48, 64)])), (ExprCompose([(ExprInt32(0), 0, 32), (a, 32, 64)]) >> ExprInt64(0x30), - ExprCompose([(a[0x10:], 0, 16), (ExprInt_fromsize(48, 0), 16, 64)])), + ExprCompose([(a[0x10:], 0, 16), (ExprInt(0, 48), 16, 64)])), (ExprCompose([(ExprInt32(0), 0, 32), (a, 32, 64)]) >> ExprInt64(0x11), - ExprCompose([(ExprInt_fromsize(0xf, 0), 0, 0xf), (a, 0xf, 0x2f), (ExprInt_fromsize(0x11, 0), 0x2f, 0x40)])), + ExprCompose([(ExprInt(0, 0xf), 0, 0xf), (a, 0xf, 0x2f), (ExprInt(0, 0x11), 0x2f, 0x40)])), (ExprCompose([(ExprInt32(0), 0, 32), (a, 32, 64)]) >> ExprInt64(0x40), ExprInt64(0)), (ExprCompose([(ExprInt32(0), 0, 32), (a, 32, 64)]) >> ExprInt64(0x50), |