diff options
38 files changed, 595 insertions, 594 deletions
diff --git a/example/expression/basic_simplification.py b/example/expression/basic_simplification.py index 17b1a35b..ef904686 100644 --- a/example/expression/basic_simplification.py +++ b/example/expression/basic_simplification.py @@ -10,7 +10,7 @@ a = ExprId('eax') b = ExprId('ebx') exprs = [a + b - a, - ExprInt32(0x12) + ExprInt32(0x30) - a, + ExprInt(0x12, 32) + ExprInt(0x30, 32) - a, ExprCompose(a[:8], a[8:16])] for e in exprs: diff --git a/example/expression/expr_grapher.py b/example/expression/expr_grapher.py index 3137e6d2..0de2142b 100644 --- a/example/expression/expr_grapher.py +++ b/example/expression/expr_grapher.py @@ -9,7 +9,7 @@ d = ExprId("D") m = ExprMem(a + b + c + a) e1 = ExprCompose(a + b - (c * a) / m | b, a + m) -e2 = ExprInt64(15) +e2 = ExprInt(15, 64) e = ExprCond(d, e1, e2)[0:32] print "[+] Expression:" diff --git a/example/expression/simplification_tools.py b/example/expression/simplification_tools.py index 9b8aeed5..6a4ff715 100644 --- a/example/expression/simplification_tools.py +++ b/example/expression/simplification_tools.py @@ -21,8 +21,8 @@ e = ExprId('e') m = ExprMem(a) s = a[:8] -i1 = ExprInt(uint32(0x1)) -i2 = ExprInt(uint32(0x2)) +i1 = ExprInt(0x1, 32) +i2 = ExprInt(0x2, 32) cc = ExprCond(a, b, c) o = ExprCompose(a[8:16], a[:8]) @@ -33,12 +33,12 @@ l = [a[:8], b[:8], c[:8], m[:8], s, i1[:8], i2[:8], o[:8]] l2 = l[::-1] -x = ExprMem(a + b + ExprInt32(0x42)) +x = ExprMem(a + b + ExprInt(0x42, 32)) def replace_expr(e): # print 'visit', e - dct = {c + ExprInt32(0x42): d, + dct = {c + ExprInt(0x42, 32): d, a + b: c, } if e in dct: return dct[e] @@ -60,9 +60,9 @@ print z.copy() print z[:31].copy().visit(replace_expr) print 'replace' -print x.replace_expr({c + ExprInt32(0x42): d, +print x.replace_expr({c + ExprInt(0x42, 32): d, a + b: c, }) -print z.replace_expr({c + ExprInt32(0x42): d, +print z.replace_expr({c + ExprInt(0x42, 32): d, a + b: c, }) diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 03d652cf..0ca17faa 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -11,6 +11,7 @@ from miasm2.arch.x86.sem import * from miasm2.core.bin_stream import bin_stream_str from miasm2.core import asmblock from miasm2.expression.expression import get_rw +from miasm2.expression.modint import uint32 from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.expression.simplifications import expr_simp from miasm2.expression import stp @@ -134,7 +135,7 @@ if __name__ == '__main__': reg_and_id = dict(mn_x86.regs.all_regs_ids_byname) def my_ast_int2expr(a): - return ExprInt32(a) + return ExprInt(a, 32) # Modifify parser to avoid label creation in PUSH argc def my_ast_id2expr(string_parsed): diff --git a/example/symbol_exec/depgraph.py b/example/symbol_exec/depgraph.py index b4f793c0..0b971b15 100644 --- a/example/symbol_exec/depgraph.py +++ b/example/symbol_exec/depgraph.py @@ -5,7 +5,7 @@ import json from miasm2.analysis.machine import Machine from miasm2.analysis.binary import Container from miasm2.analysis.depgraph import DependencyGraph -from miasm2.expression.expression import ExprMem, ExprId, ExprInt32 +from miasm2.expression.expression import ExprMem, ExprId, ExprInt parser = ArgumentParser("Dependency grapher") parser.add_argument("filename", help="Binary to analyse") @@ -55,7 +55,7 @@ if args.rename_args: if arch == "x86_32": # StdCall example for i in xrange(4): - e_mem = ExprMem(ExprId("ESP_init") + ExprInt32(4 * (i + 1)), 32) + e_mem = ExprMem(ExprId("ESP_init") + ExprInt(4 * (i + 1), 32), 32) init_ctx[e_mem] = ExprId("arg%d" % i) # Disassemble the targeted function diff --git a/miasm2/arch/aarch64/arch.py b/miasm2/arch/aarch64/arch.py index 6f95df99..1a2283d6 100644 --- a/miasm2/arch/aarch64/arch.py +++ b/miasm2/arch/aarch64/arch.py @@ -10,7 +10,7 @@ import regs as regs_module from regs import * from miasm2.core.asmblock import AsmLabel from miasm2.core.cpu import log as log_cpu -from miasm2.expression.modint import uint32, uint64 +from miasm2.expression.modint import uint32, uint64, mod_size2int import math log = logging.getLogger("aarch64dis") @@ -62,8 +62,8 @@ replace_regs = { WSP: SP[:32], - WZR: m2_expr.ExprInt32(0), - XZR: m2_expr.ExprInt64(0), + WZR: m2_expr.ExprInt(0, 32), + XZR: m2_expr.ExprInt(0, 64), } @@ -81,7 +81,7 @@ def ast_id2expr32(t): return t def ast_int2expr32(a): - return m2_expr.ExprInt32(a) + return m2_expr.ExprInt(a, 32) def ast_id2expr64(t): @@ -93,7 +93,7 @@ def ast_id2expr64(t): def ast_int2expr64(a): - return m2_expr.ExprInt64(a) + return m2_expr.ExprInt(a, 64) my_var_parser32 = ParseAst(ast_id2expr32, ast_int2expr32, default_size=32) my_var_parser64 = ParseAst(ast_id2expr64, ast_int2expr64, default_size=64) @@ -129,7 +129,7 @@ def shift2expr(t): return t[0] elif len(t) == 3: if t[0].size == 32 and isinstance(t[2], m2_expr.ExprInt): - t[2] = m2_expr.ExprInt32(t[2].arg) + t[2] = m2_expr.ExprInt(int(t[2]), 32) return m2_expr.ExprOp(t[1], t[0], t[2]) else: raise ValueError('bad string') @@ -140,7 +140,7 @@ def shift2expr_sc(t): return t[0] elif len(t) == 3: if t[0].size == 32 and isinstance(t[2], m2_expr.ExprInt): - t[2] = m2_expr.ExprInt32(t[2].arg) + t[2] = m2_expr.ExprInt(t[2].arg, 32) if t[1] != '<<': raise ValueError('bad op') return m2_expr.ExprOp("slice_at", t[0], t[2]) @@ -214,7 +214,7 @@ def ast_id2expr(t): def ast_int2expr(a): - return m2_expr.ExprInt64(a) + return m2_expr.ExprInt(a, 64) gpregs_info = {32: gpregs32_info, 64: gpregs64_info} @@ -236,7 +236,7 @@ base_expr.setParseAction(my_var_parser) def deref2expr_nooff(t): t = t[0] # XXX default - return m2_expr.ExprOp("preinc", t[0], m2_expr.ExprInt64(0)) + return m2_expr.ExprOp("preinc", t[0], m2_expr.ExprInt(0, 64)) def deref2expr_post(t): @@ -416,7 +416,7 @@ class instruction_aarch64(instruction): off = e.arg - self.offset if int(off % 4): raise ValueError('strange offset! %r' % off) - self.args[index] = m2_expr.ExprInt64(off) + self.args[index] = m2_expr.ExprInt(int(off), 64) @@ -782,15 +782,15 @@ class aarch64_int64_noarg(int32_noarg): parser = base_expr intsize = 64 intmask = (1 << intsize) - 1 - int2expr = lambda self, x: m2_expr.ExprInt64( - sign_ext(x, self.l, self.intsize)) + int2expr = lambda self, x: m2_expr.ExprInt( + sign_ext(x, self.l, self.intsize), 64) class aarch64_uint64_noarg(imm_noarg): parser = base_expr intsize = 64 intmask = (1 << intsize) - 1 - int2expr = lambda self, x: m2_expr.ExprInt64(x) + int2expr = lambda self, x: m2_expr.ExprInt(x, 64) class aarch64_uint64(aarch64_uint64_noarg, m_arg): @@ -1110,7 +1110,7 @@ class aarch64_immhip_page(aarch64_imm_32): def decode(self, v): v = ((v << 2) | self.parent.immlo.value) << 12 v = sign_ext(v, 33, 64) - self.expr = m2_expr.ExprInt64(v) + self.expr = m2_expr.ExprInt(v, 64) return True def encode(self): @@ -1132,7 +1132,7 @@ class aarch64_immhi_page(aarch64_imm_32): def decode(self, v): v = ((v << 2) | self.parent.immlo.value) v = sign_ext(v, 21, 64) - self.expr = m2_expr.ExprInt64(v) + self.expr = m2_expr.ExprInt(v, 64) return True def encode(self): @@ -1222,7 +1222,7 @@ class aarch64_offs(imm_noarg, m_arg): v = v & self.lmask v = (v << 2) v = sign_ext(v, (self.l + 2), 64) - self.expr = m2_expr.ExprInt64(v) + self.expr = m2_expr.ExprInt(v, 64) return True def encode(self): @@ -1285,7 +1285,7 @@ class aarch64_deref(m_arg): off = self.parent.imm.expr.arg op = self.get_postpre(self.parent) off = self.decode_w_size(off) - self.expr = m2_expr.ExprOp(op, reg, m2_expr.ExprInt64(off)) + self.expr = m2_expr.ExprOp(op, reg, m2_expr.ExprInt(off, 64)) return True def encode(self): @@ -1308,7 +1308,7 @@ class aarch64_deref(m_arg): imm = self.encode_w_size(imm) if imm is False: return False - self.parent.imm.expr = m2_expr.ExprInt64(imm) + self.parent.imm.expr = m2_expr.ExprInt(imm, 64) if not self.parent.imm.encode(): return False self.value = gpregs64_info.expr.index(reg) diff --git a/miasm2/arch/aarch64/regs.py b/miasm2/arch/aarch64/regs.py index 9de82c04..01ae4252 100644 --- a/miasm2/arch/aarch64/regs.py +++ b/miasm2/arch/aarch64/regs.py @@ -107,12 +107,12 @@ all_regs_ids_init = (simd08_init + gpregs32_init + gpregs64_init + [ - ExprInt32(0), + ExprInt(0, 32), PC_init, WZR_init, XZR_init, zf_init, nf_init, of_init, cf_init, - ExprInt64(0), ExprInt32(0), + ExprInt(0, 64), ExprInt(0, 32), ] ) diff --git a/miasm2/arch/aarch64/sem.py b/miasm2/arch/aarch64/sem.py index 792a4984..e9eaffc8 100644 --- a/miasm2/arch/aarch64/sem.py +++ b/miasm2/arch/aarch64/sem.py @@ -10,7 +10,7 @@ EXCEPT_PRIV_INSN = (1 << 17) def update_flag_zf(a): - return [m2_expr.ExprAff(zf, m2_expr.ExprCond(a, m2_expr.ExprInt1(0), m2_expr.ExprInt1(1)))] + return [m2_expr.ExprAff(zf, m2_expr.ExprCond(a, m2_expr.ExprInt(0, 1), m2_expr.ExprInt(1, 1)))] def update_flag_nf(a): @@ -28,7 +28,7 @@ def update_flag_logic(a): e = [] e += update_flag_zn(a) # XXX TODO: set cf if ROT imm in argument - # e.append(m2_expr.ExprAff(cf, m2_expr.ExprInt1(0))) + # e.append(m2_expr.ExprAff(cf, m2_expr.ExprInt(0, 1))) return e @@ -66,7 +66,7 @@ def update_flag_add_of(op1, op2, res): def update_flag_sub_cf(op1, op2, res): "Compote CF in @res = @op1 - @op2" return m2_expr.ExprAff(cf, - ((((op1 ^ op2) ^ res) ^ ((op1 ^ res) & (op1 ^ op2))).msb()) ^ m2_expr.ExprInt1(1)) + ((((op1 ^ op2) ^ res) ^ ((op1 ^ res) & (op1 ^ op2))).msb()) ^ m2_expr.ExprInt(1, 1)) def update_flag_sub_of(op1, op2, res): @@ -93,22 +93,22 @@ def update_flag_sub(x, y, z): cond2expr = {'EQ': zf, - 'NE': zf ^ m2_expr.ExprInt1(1), + 'NE': zf ^ m2_expr.ExprInt(1, 1), 'CS': cf, - 'CC': cf ^ m2_expr.ExprInt1(1), + 'CC': cf ^ m2_expr.ExprInt(1, 1), 'MI': nf, - 'PL': nf ^ m2_expr.ExprInt1(1), + 'PL': nf ^ m2_expr.ExprInt(1, 1), 'VS': of, - 'VC': of ^ m2_expr.ExprInt1(1), - 'HI': cf & (zf ^ m2_expr.ExprInt1(1)), - 'LS': (cf ^ m2_expr.ExprInt1(1)) | zf, - 'GE': nf ^ of ^ m2_expr.ExprInt1(1), + 'VC': of ^ m2_expr.ExprInt(1, 1), + 'HI': cf & (zf ^ m2_expr.ExprInt(1, 1)), + 'LS': (cf ^ m2_expr.ExprInt(1, 1)) | zf, + 'GE': nf ^ of ^ m2_expr.ExprInt(1, 1), 'LT': nf ^ of, - 'GT': ((zf ^ m2_expr.ExprInt1(1)) & - (nf ^ of ^ m2_expr.ExprInt1(1))), + 'GT': ((zf ^ m2_expr.ExprInt(1, 1)) & + (nf ^ of ^ m2_expr.ExprInt(1, 1))), 'LE': zf | (nf ^ of), - 'AL': m2_expr.ExprInt1(1), - 'NV': m2_expr.ExprInt1(0) + 'AL': m2_expr.ExprInt(1, 1), + 'NV': m2_expr.ExprInt(0, 1) } @@ -277,9 +277,9 @@ def movk(ir, instr, arg1, arg2): isinstance(arg2.args[1], m2_expr.ExprInt)) value, shift = int(arg2.args[0].arg), int(arg2.args[1]) e.append( - m2_expr.ExprAff(arg1[shift:shift + 16], m2_expr.ExprInt16(value))) + m2_expr.ExprAff(arg1[shift:shift + 16], m2_expr.ExprInt(value, 16))) else: - e.append(m2_expr.ExprAff(arg1[:16], m2_expr.ExprInt16(int(arg2)))) + e.append(m2_expr.ExprAff(arg1[:16], m2_expr.ExprInt(int(arg2), 16))) return e, [] @@ -298,7 +298,7 @@ def movn(arg1, arg2): def bl(arg1): PC = arg1 ir.IRDst = arg1 - LR = m2_expr.ExprInt64(instr.offset + instr.l) + LR = m2_expr.ExprInt(instr.offset + instr.l, 64) @sbuild.parse def csel(arg1, arg2, arg3, arg4): @@ -649,7 +649,7 @@ def ret(arg1): @sbuild.parse def adrp(arg1, arg2): - arg1 = (PC & m2_expr.ExprInt64(0xfffffffffffff000)) + arg2 + arg1 = (PC & m2_expr.ExprInt(0xfffffffffffff000, 64)) + arg2 @sbuild.parse @@ -797,7 +797,7 @@ class ir_aarch64l(IntermediateRepresentation): def mod_pc(self, instr, instr_ir, extra_ir): "Replace PC by the instruction's offset" - cur_offset = m2_expr.ExprInt64(instr.offset) + cur_offset = m2_expr.ExprInt(instr.offset, 64) for i, expr in enumerate(instr_ir): dst, src = expr.dst, expr.src if dst != self.pc: diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py index 54a168af..0d10d6f8 100644 --- a/miasm2/arch/arm/arch.py +++ b/miasm2/arch/arm/arch.py @@ -103,14 +103,14 @@ CIRCUNFLEX = Literal("^") def check_bounds(left_bound, right_bound, value): if left_bound <= value and value <= right_bound: - return ExprInt32(value) + return ExprInt(value, 32) else: raise ValueError('shift operator immediate value out of bound') def check_values(values, value): if value in values: - return ExprInt32(value) + return ExprInt(value, 32) else: raise ValueError('shift operator immediate value out of bound') @@ -184,7 +184,7 @@ def ast_id2expr(t): def ast_int2expr(a): - return ExprInt32(a) + return ExprInt(a, 32) my_var_parser = ParseAst(ast_id2expr, ast_int2expr) @@ -208,13 +208,13 @@ rot2_expr = (gpregs.parser + Optional( def deref2expr_nooff(s, l, t): t = t[0] # XXX default - return ExprOp("preinc", t[0], ExprInt32(0)) + return ExprOp("preinc", t[0], ExprInt(0, 32)) def deref2expr_pre(s, l, t): t = t[0] if len(t) == 1: - return ExprOp("preinc", t[0], ExprInt32(0)) + return ExprOp("preinc", t[0], ExprInt(0, 32)) elif len(t) == 2: return ExprOp("preinc", t[0], t[1]) else: @@ -224,7 +224,7 @@ def deref2expr_pre(s, l, t): def deref2expr_pre_mem(s, l, t): t = t[0] if len(t) == 1: - return ExprMem(ExprOp("preinc", t[0], ExprInt32(0))) + return ExprMem(ExprOp("preinc", t[0], ExprInt(0, 32))) elif len(t) == 2: return ExprMem(ExprOp("preinc", t[0], t[1])) else: @@ -425,7 +425,7 @@ class instruction_arm(instruction): off = e.arg - self.offset if int(off % 4): raise ValueError('strange offset! %r' % off) - self.args[0] = ExprInt32(off) + self.args[0] = ExprInt(off, 32) def get_args_expr(self): args = [a for a in self.args] @@ -500,7 +500,7 @@ class instruction_armt(instruction_arm): off = e.arg - self.offset if int(off % 2): raise ValueError('strange offset! %r' % off) - self.args[0] = ExprInt32(off) + self.args[0] = ExprInt(off, 32) def get_asm_offset(self, expr): # ADR XXX, PC, imm => PC is 4 aligned + imm @@ -824,7 +824,7 @@ class arm_offs(arm_imm): if (1 << (self.l - 1)) & v: v |= ~0 ^ self.lmask v = self.decodeval(v) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -844,9 +844,9 @@ class arm_imm8_12(m_arg): def decode(self, v): v = v & self.lmask if self.parent.updown.value: - e = ExprInt32(v << 2) + e = ExprInt(v << 2, 32) else: - e = ExprInt32(-v << 2) + e = ExprInt(-v << 2, 32) if self.parent.ppi.value: e = ExprOp('preinc', self.parent.rn.expr, e) else: @@ -900,7 +900,7 @@ class arm_imm_4_12(m_arg): def decode(self, v): v = v & self.lmask imm = (self.parent.imm4.value << 12) | v - self.expr = ExprInt32(imm) + self.expr = ExprInt(imm, 32) return True def encode(self): @@ -920,7 +920,7 @@ class arm_imm_12_4(m_arg): def decode(self, v): v = v & self.lmask imm = (self.parent.imm.value << 4) | v - self.expr = ExprInt32(imm) + self.expr = ExprInt(imm, 32) return True def encode(self): @@ -952,7 +952,7 @@ class arm_op2(m_arg): rot = val >> 8 imm = val & 0xff imm = myror32(imm, rot * 2) - self.expr = ExprInt32(imm) + self.expr = ExprInt(imm, 32) return True rm = val & 0xf shift = val >> 4 @@ -974,9 +974,9 @@ class arm_op2(m_arg): else: # shift kind is imm amount = shift - shift_op = ExprInt32(amount) + shift_op = ExprInt(amount, 32) a = regs_expr[rm] - if shift_op == ExprInt32(0): + if shift_op == ExprInt(0, 32): if shift_type == 3: self.expr = ExprOp(allshifts[4], a) else: @@ -1049,9 +1049,9 @@ class arm_op2imm(arm_imm8_12): if self.parent.updown.value == 0: imm = -imm if self.parent.ppi.value: - e = ExprOp('preinc', self.parent.rn.expr, ExprInt32(imm)) + e = ExprOp('preinc', self.parent.rn.expr, ExprInt(imm, 32)) else: - e = ExprOp('postinc', self.parent.rn.expr, ExprInt32(imm)) + e = ExprOp('postinc', self.parent.rn.expr, ExprInt(imm, 32)) if self.parent.wback.value == 1: e = ExprOp('wback', e) self.expr = ExprMem(e) @@ -1069,9 +1069,9 @@ class arm_op2imm(arm_imm8_12): else: # shift kind is imm amount = shift - shift_op = ExprInt32(amount) + shift_op = ExprInt(amount, 32) a = regs_expr[rm] - if shift_op == ExprInt32(0): + if shift_op == ExprInt(0, 32): pass else: a = ExprOp(allshifts[shift_type], a, shift_op) @@ -1249,7 +1249,7 @@ class arm_offs_blx(arm_imm): v = sign_ext(v, 26, 32) # Add pipeline offset v += 8 - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -1359,7 +1359,7 @@ class arm_immed(m_arg): def decode(self, v): if self.parent.immop.value == 1: - imm = ExprInt32((self.parent.immedH.value << 4) | v) + imm = ExprInt((self.parent.immedH.value << 4) | v, 32) else: imm = gpregs.expr[v] if self.parent.updown.value == 0: @@ -1454,7 +1454,7 @@ class arm_mem_rn_imm(m_arg): value = self.parent.imm.value if self.parent.rw.value == 0: value = -value - imm = ExprInt32(value) + imm = ExprInt(value, 32) reg = gpregs.expr[v] if value: expr = ExprMem(reg + imm) @@ -1622,7 +1622,7 @@ armop("isb", [bs8(0xF5), bs8(0x7F), bs8(0xF0), bs8(0x6F)]) class arm_widthm1(arm_imm, m_arg): def decode(self, v): - self.expr = ExprInt32(v+1) + self.expr = ExprInt(v+1, 32) return True def encode(self): @@ -1639,7 +1639,7 @@ class arm_rm_rot2(m_arg): expr = gpregs.expr[v] shift_value = self.parent.rot2.value if shift_value: - expr = ExprOp(allshifts[3], expr, ExprInt32(shift_value * 8)) + expr = ExprOp(allshifts[3], expr, ExprInt(shift_value * 8, 32)) self.expr = expr return True def encode(self): @@ -1715,7 +1715,7 @@ class arm_offreg(m_arg): v = v & self.lmask v = self.decodeval(v) if v: - self.expr = self.off_reg + ExprInt32(v) + self.expr = self.off_reg + ExprInt(v, 32) else: self.expr = self.off_reg @@ -1746,7 +1746,7 @@ class arm_offpc(arm_offreg): v = v & self.lmask v <<= 2 if v: - self.expr = ExprMem(self.off_reg + ExprInt32(v)) + self.expr = ExprMem(self.off_reg + ExprInt(v, 32)) else: self.expr = ExprMem(self.off_reg) @@ -1853,7 +1853,7 @@ class arm_offbw(imm_noarg): v = v & self.lmask if self.parent.trb.value == 0: v <<= 2 - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -1874,7 +1874,7 @@ class arm_offh(imm_noarg): def decode(self, v): v = v & self.lmask v <<= 1 - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -2177,7 +2177,7 @@ class armt_gpreg_rm_shift_off(arm_reg): shift = allshifts_armt[self.parent.stype.value] else: shift = allshifts_armt[4] - self.expr = ExprOp(shift, r, ExprInt32(i)) + self.expr = ExprOp(shift, r, ExprInt(i, 32)) return True def encode(self): @@ -2219,26 +2219,26 @@ class armt2_imm12(arm_imm): # simple encoding if 0 <= v < 0x100: - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True # 00XY00XY form if v >> 8 == 1: v &= 0xFF - self.expr = ExprInt32((v << 16) | v) + self.expr = ExprInt((v << 16) | v, 32) return True # XY00XY00 form if v >> 8 == 2: v &= 0xFF - self.expr = ExprInt32((v << 24) | (v << 8)) + self.expr = ExprInt((v << 24) | (v << 8), 32) return True # XYXYXYXY if v >> 8 == 3: v &= 0xFF - self.expr = ExprInt32((v << 24) | (v << 16) | (v << 8) | v) + self.expr = ExprInt((v << 24) | (v << 16) | (v << 8) | v, 32) return True r = v >> 7 v = v & 0xFF - self.expr = ExprInt32(myror32(v, r)) + self.expr = ExprInt(myror32(v, r), 32) return True def encode(self): @@ -2290,7 +2290,7 @@ class armt2_imm10l(arm_imm): v = (s << 24) | (i1 << 23) | ( i2 << 22) | (imm10h << 12) | (imm10l << 2) v = sign_ext(v, 25, 32) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -2329,7 +2329,7 @@ class armt2_imm11l(arm_imm): v = (s << 24) | (i1 << 23) | ( i2 << 22) | (imm10h << 12) | (imm11l << 1) v = sign_ext(v, 25, 32) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -2369,7 +2369,7 @@ class armt_imm5_1(arm_imm): def decode(self, v): v = sign_ext(((self.parent.imm1.value << 5) | v) << 1, 7, 32) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): diff --git a/miasm2/arch/arm/regs.py b/miasm2/arch/arm/regs.py index a44878a8..69488cb5 100644 --- a/miasm2/arch/arm/regs.py +++ b/miasm2/arch/arm/regs.py @@ -78,7 +78,7 @@ all_regs_ids_init = [R0_init, R1_init, R2_init, R3_init, R8_init, R9_init, R10_init, R11_init, R12_init, SP_init, LR_init, PC_init, zf_init, nf_init, of_init, cf_init, - ExprInt32(0), ExprInt32(0) + ExprInt(0, 32), ExprInt(0, 32) ] regs_init = {} diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py index 8c74aa76..710cdc9f 100644 --- a/miasm2/arch/arm/sem.py +++ b/miasm2/arch/arm/sem.py @@ -13,7 +13,7 @@ EXCEPT_PRIV_INSN = (1 << 17) def update_flag_zf(a): - return [ExprAff(zf, ExprCond(a, ExprInt1(0), ExprInt1(1)))] + return [ExprAff(zf, ExprCond(a, ExprInt(0, 1), ExprInt(1, 1)))] def update_flag_nf(a): @@ -31,7 +31,7 @@ def update_flag_logic(a): e = [] e += update_flag_zn(a) # XXX TODO: set cf if ROT imm in argument - #e.append(ExprAff(cf, ExprInt1(0))) + #e.append(ExprAff(cf, ExprInt(0, 1))) return e @@ -68,7 +68,7 @@ def update_flag_add_of(op1, op2, res): def update_flag_sub_cf(op1, op2, res): "Compote CF in @res = @op1 - @op2" return ExprAff(cf, - ((((op1 ^ op2) ^ res) ^ ((op1 ^ res) & (op1 ^ op2))).msb()) ^ ExprInt1(1)) + ((((op1 ^ op2) ^ res) ^ ((op1 ^ res) & (op1 ^ op2))).msb()) ^ ExprInt(1, 1)) def update_flag_sub_of(op1, op2, res): @@ -227,7 +227,7 @@ def sbc(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = (b + cf.zeroExtend(32)) - (c + ExprInt32(1)) + r = (b + cf.zeroExtend(32)) - (c + ExprInt(1, 32)) e.append(ExprAff(a, r)) dst = get_dst(a) if dst is not None: @@ -239,7 +239,7 @@ def sbcs(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = (b + cf.zeroExtend(32)) - (c + ExprInt32(1)) + r = (b + cf.zeroExtend(32)) - (c + ExprInt(1, 32)) e += update_flag_arith(r) e += update_flag_sub(b, c, r) e.append(ExprAff(a, r)) @@ -253,7 +253,7 @@ def rsc(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = (c + cf.zeroExtend(32)) - (b + ExprInt32(1)) + r = (c + cf.zeroExtend(32)) - (b + ExprInt(1, 32)) e.append(ExprAff(a, r)) dst = get_dst(a) if dst is not None: @@ -265,7 +265,7 @@ def rscs(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = (c + cf.zeroExtend(32)) - (b + ExprInt32(1)) + r = (c + cf.zeroExtend(32)) - (b + ExprInt(1, 32)) e.append(ExprAff(a, r)) e += update_flag_arith(r) e += update_flag_sub(c, b, r) @@ -348,7 +348,7 @@ def mov(ir, instr, a, b): def movt(ir, instr, a, b): - r = a | b << ExprInt32(16) + r = a | b << ExprInt(16, 32) e = [ExprAff(a, r)] dst = get_dst(a) if dst is not None: @@ -368,7 +368,7 @@ def movs(ir, instr, a, b): def mvn(ir, instr, a, b): - r = b ^ ExprInt32(-1) + r = b ^ ExprInt(-1, 32) e = [ExprAff(a, r)] dst = get_dst(a) if dst is not None: @@ -378,7 +378,7 @@ def mvn(ir, instr, a, b): def mvns(ir, instr, a, b): e = [] - r = b ^ ExprInt32(-1) + r = b ^ ExprInt(-1, 32) e.append(ExprAff(a, r)) # XXX TODO check e += update_flag_logic(r) @@ -405,7 +405,7 @@ def bic(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = b & (c ^ ExprInt(uint32(-1))) + r = b & (c ^ ExprInt(-1, 32)) e.append(ExprAff(a, r)) dst = get_dst(a) if dst is not None: @@ -417,7 +417,7 @@ def bics(ir, instr, a, b, c=None): e = [] if c is None: b, c = a, b - r = b & (c ^ ExprInt(uint32(-1))) + r = b & (c ^ ExprInt(-1, 32)) e += update_flag_logic(r) e.append(ExprAff(a, r)) dst = get_dst(a) @@ -512,7 +512,7 @@ def b(ir, instr, a): def bl(ir, instr, a): e = [] - l = ExprInt32(instr.offset + instr.l) + l = ExprInt(instr.offset + instr.l, 32) e.append(ExprAff(PC, a)) e.append(ExprAff(ir.IRDst, a)) e.append(ExprAff(LR, l)) @@ -528,7 +528,7 @@ def bx(ir, instr, a): def blx(ir, instr, a): e = [] - l = ExprInt32(instr.offset + instr.l) + l = ExprInt(instr.offset + instr.l, 32) e.append(ExprAff(PC, a)) e.append(ExprAff(ir.IRDst, a)) e.append(ExprAff(LR, l)) @@ -549,9 +549,9 @@ def st_ld_r(ir, instr, a, b, store=False, size=32, s_ext=False, z_ext=False): postinc = True if isinstance(b, ExprOp) and b.op in ["postinc", 'preinc']: # XXX TODO CHECK - base, off = b.args[0], b.args[1] # ExprInt32(size/8) + base, off = b.args[0], b.args[1] # ExprInt(size/8, 32) else: - base, off = b, ExprInt32(0) + base, off = b, ExprInt(0, 32) # print a, wb, base, off, postinc if postinc: ad = base @@ -584,14 +584,14 @@ def st_ld_r(ir, instr, a, b, store=False, size=32, s_ext=False, z_ext=False): if store: e.append(ExprAff(m, a)) if dmem: - e.append(ExprAff(ExprMem(ad + ExprInt32(4), size=size), a2)) + e.append(ExprAff(ExprMem(ad + ExprInt(4, 32), size=size), a2)) else: if a == PC: dst = PC e.append(ExprAff(ir.IRDst, m)) e.append(ExprAff(a, m)) if dmem: - e.append(ExprAff(a2, ExprMem(ad + ExprInt32(4), size=size))) + e.append(ExprAff(a2, ExprMem(ad + ExprInt(4, 32), size=size))) # XXX TODO check multiple write cause by wb if wb or postinc: @@ -668,9 +668,9 @@ def st_ld_m(ir, instr, a, b, store=False, postinc=False, updown=False): if postinc: pass else: - base += ExprInt32(step) + base += ExprInt(step, 32) for i, r in enumerate(regs): - ad = base + ExprInt32(i * step) + ad = base + ExprInt(i * step, 32) if store: e.append(ExprAff(ExprMem(ad), r)) else: @@ -680,9 +680,9 @@ def st_ld_m(ir, instr, a, b, store=False, postinc=False, updown=False): # XXX TODO check multiple write cause by wb if wb: if postinc: - e.append(ExprAff(a, base + ExprInt32(len(regs) * step))) + e.append(ExprAff(a, base + ExprInt(len(regs) * step, 32))) else: - e.append(ExprAff(a, base + ExprInt32((len(regs) - 1) * step))) + e.append(ExprAff(a, base + ExprInt((len(regs) - 1) * step, 32))) if store: pass else: @@ -726,7 +726,7 @@ def stmdb(ir, instr, a, b): def svc(ir, instr, a): # XXX TODO implement e = [ - ExprAff(exception_flags, ExprInt32(EXCEPT_PRIV_INSN))] + ExprAff(exception_flags, ExprInt(EXCEPT_PRIV_INSN, 32))] return e @@ -812,9 +812,9 @@ def push(ir, instr, a): e = [] regs = list(a.args) for i in xrange(len(regs)): - r = SP + ExprInt32(-4 * (i + 1)) + r = SP + ExprInt(-4 * (i + 1), 32) e.append(ExprAff(ExprMem(r), regs[i])) - r = SP + ExprInt32(-4 * len(regs)) + r = SP + ExprInt(-4 * len(regs), 32) e.append(ExprAff(SP, r)) return e @@ -824,11 +824,11 @@ def pop(ir, instr, a): regs = list(a.args) dst = None for i in xrange(len(regs)): - r = SP + ExprInt32(4 * i) + r = SP + ExprInt(4 * i, 32) e.append(ExprAff(regs[i], ExprMem(r))) if regs[i] == ir.pc: dst = ExprMem(r) - r = SP + ExprInt32(4 * len(regs)) + r = SP + ExprInt(4 * len(regs), 32) e.append(ExprAff(SP, r)) if dst is not None: e.append(ExprAff(ir.IRDst, dst)) @@ -913,7 +913,7 @@ def bfc(ir, instr, a, b, c): out.append(a[:start]) last = start if stop - start: - out.append(ExprInt32(0)[last:stop]) + out.append(ExprInt(0, 32)[last:stop]) last = stop if last < 32: out.append(a[last:]) @@ -942,13 +942,13 @@ def clz(ir, instr, a, b): def uxtab(ir, instr, a, b, c): e = [] - e.append(ExprAff(a, b + (c & ExprInt32(0xff)))) + e.append(ExprAff(a, b + (c & ExprInt(0xff, 32)))) return e def bkpt(ir, instr, a): e = [] - e.append(ExprAff(exception_flags, ExprInt32(EXCEPT_SOFT_BP))) + e.append(ExprAff(exception_flags, ExprInt(EXCEPT_SOFT_BP, 32))) e.append(ExprAff(bp_num, a)) return e @@ -1003,26 +1003,26 @@ cond_dct = { tab_cond = {COND_EQ: zf, - COND_NE: ExprCond(zf, ExprInt1(0), ExprInt1(1)), + COND_NE: ExprCond(zf, ExprInt(0, 1), ExprInt(1, 1)), COND_CS: cf, - COND_CC: ExprCond(cf, ExprInt1(0), ExprInt1(1)), + COND_CC: ExprCond(cf, ExprInt(0, 1), ExprInt(1, 1)), COND_MI: nf, - COND_PL: ExprCond(nf, ExprInt1(0), ExprInt1(1)), + COND_PL: ExprCond(nf, ExprInt(0, 1), ExprInt(1, 1)), COND_VS: of, - COND_VC: ExprCond(of, ExprInt1(0), ExprInt1(1)), - COND_HI: cf & ExprCond(zf, ExprInt1(0), ExprInt1(1)), + COND_VC: ExprCond(of, ExprInt(0, 1), ExprInt(1, 1)), + COND_HI: cf & ExprCond(zf, ExprInt(0, 1), ExprInt(1, 1)), # COND_HI: cf, # COND_HI: ExprOp('==', # ExprOp('|', cf, zf), - # ExprInt1(0)), - COND_LS: ExprCond(cf, ExprInt1(0), ExprInt1(1)) | zf, - COND_GE: ExprCond(nf - of, ExprInt1(0), ExprInt1(1)), + # ExprInt(0, 1)), + COND_LS: ExprCond(cf, ExprInt(0, 1), ExprInt(1, 1)) | zf, + COND_GE: ExprCond(nf - of, ExprInt(0, 1), ExprInt(1, 1)), COND_LT: nf ^ of, # COND_GT: ExprOp('|', - # ExprOp('==', zf, ExprInt1(0)) & (nf | of), - # ExprOp('==', nf, ExprInt1(0)) & ExprOp('==', of, ExprInt1(0))), - COND_GT: (ExprCond(zf, ExprInt1(0), ExprInt1(1)) & - ExprCond(nf - of, ExprInt1(0), ExprInt1(1))), + # ExprOp('==', zf, ExprInt(0, 1)) & (nf | of), + # ExprOp('==', nf, ExprInt(0, 1)) & ExprOp('==', of, ExprInt(0, 1))), + COND_GT: (ExprCond(zf, ExprInt(0, 1), ExprInt(1, 1)) & + ExprCond(nf - of, ExprInt(0, 1), ExprInt(1, 1))), COND_LE: zf | (nf ^ of), } @@ -1250,13 +1250,13 @@ class ir_arml(IntermediateRepresentation): # return instr_ir, extra_ir for i, x in enumerate(instr_ir): x = ExprAff(x.dst, x.src.replace_expr( - {self.pc: ExprInt32(instr.offset + 8)})) + {self.pc: ExprInt(instr.offset + 8, 32)})) instr_ir[i] = x for irblock in extra_ir: for irs in irblock.irs: for i, x in enumerate(irs): x = ExprAff(x.dst, x.src.replace_expr( - {self.pc: ExprInt32(instr.offset + 8)})) + {self.pc: ExprInt(instr.offset + 8, 32)})) irs[i] = x # return out_ir, extra_ir return instr_ir, extra_ir diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py index f11c6e3a..d64e27df 100644 --- a/miasm2/arch/mips32/arch.py +++ b/miasm2/arch/mips32/arch.py @@ -5,7 +5,7 @@ from collections import defaultdict from pyparsing import Literal, Group, Optional -from miasm2.expression.expression import ExprMem, ExprInt, ExprInt32, ExprId +from miasm2.expression.expression import ExprMem, ExprInt, ExprId from miasm2.core.bin_stream import bin_stream import miasm2.arch.mips32.regs as regs import miasm2.core.cpu as cpu @@ -56,7 +56,7 @@ def ast_id2expr(t): def ast_int2expr(a): - return ExprInt32(a) + return ExprInt(a, 32) my_var_parser = cpu.ParseAst(ast_id2expr, ast_int2expr) @@ -176,7 +176,7 @@ class instruction_mips32(cpu.instruction): off = e.arg - self.offset if int(off % 4): raise ValueError('strange offset! %r' % off) - self.args[ndx] = ExprInt32(off) + self.args[ndx] = ExprInt(off, 32) def get_args_expr(self): args = [a for a in self.args] @@ -299,7 +299,7 @@ class mips32_s16imm_noarg(mips32_imm): def decode(self, v): v = v & self.lmask v = cpu.sign_ext(v, 16, 32) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -319,7 +319,7 @@ class mips32_soff_noarg(mips32_imm): v <<= 2 v = cpu.sign_ext(v, 16+2, 32) # Add pipeline offset - self.expr = ExprInt32(v + 4) + self.expr = ExprInt(v + 4, 32) return True def encode(self): @@ -345,7 +345,7 @@ class mips32_soff(mips32_soff_noarg, cpu.m_arg): class mips32_instr_index(mips32_imm, cpu.m_arg): def decode(self, v): v = v & self.lmask - self.expr = ExprInt32(v<<2) + self.expr = ExprInt(v<<2, 32) return True def encode(self): @@ -364,7 +364,7 @@ class mips32_instr_index(mips32_imm, cpu.m_arg): class mips32_u16imm(mips32_imm, cpu.m_arg): def decode(self, v): v = v & self.lmask - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -389,7 +389,7 @@ class mips32_dreg_imm(cpu.m_arg): return False arg = e.arg if isinstance(arg, ExprId): - self.parent.imm.expr = ExprInt32(0) + self.parent.imm.expr = ExprInt(0, 32) r = arg elif len(arg.args) == 2 and arg.op == "+": self.parent.imm.expr = arg.args[1] @@ -411,7 +411,7 @@ class mips32_dreg_imm(cpu.m_arg): class mips32_esize(mips32_imm, cpu.m_arg): def decode(self, v): v = v & self.lmask - self.expr = ExprInt32(v+1) + self.expr = ExprInt(v+1, 32) return True def encode(self): @@ -424,7 +424,7 @@ class mips32_esize(mips32_imm, cpu.m_arg): class mips32_eposh(mips32_imm, cpu.m_arg): def decode(self, v): - self.expr = ExprInt32(v-int(self.parent.epos.expr)+1) + self.expr = ExprInt(v-int(self.parent.epos.expr)+1, 32) return True def encode(self): diff --git a/miasm2/arch/mips32/ira.py b/miasm2/arch/mips32/ira.py index dd02ff50..92af5cc5 100644 --- a/miasm2/arch/mips32/ira.py +++ b/miasm2/arch/mips32/ira.py @@ -1,6 +1,6 @@ #-*- coding:utf-8 -*- -from miasm2.expression.expression import ExprAff, ExprInt32, ExprId +from miasm2.expression.expression import ExprAff, ExprInt, ExprId from miasm2.ir.ir import IntermediateRepresentation, IRBlock, AssignBlock from miasm2.ir.analysis import ira from miasm2.arch.mips32.sem import ir_mips32l, ir_mips32b @@ -29,7 +29,7 @@ class ir_a_mips32l(ir_mips32l, ira): if not expr_is_int_or_label(lr_val): continue if expr_is_label(lr_val): - lr_val = ExprInt32(lr_val.name.offset) + lr_val = ExprInt(lr_val.name.offset, 32) line = block.lines[-2] if lr_val.arg != line.offset + 8: diff --git a/miasm2/arch/mips32/sem.py b/miasm2/arch/mips32/sem.py index d982f033..bc050b38 100644 --- a/miasm2/arch/mips32/sem.py +++ b/miasm2/arch/mips32/sem.py @@ -443,13 +443,13 @@ class ir_mips32l(IntermediateRepresentation): for i, x in enumerate(instr_ir): x = m2_expr.ExprAff(x.dst, x.src.replace_expr( - {self.pc: m2_expr.ExprInt32(instr.offset + 4)})) + {self.pc: m2_expr.ExprInt(instr.offset + 4, 32)})) instr_ir[i] = x for irblock in extra_ir: for irs in irblock.irs: for i, x in enumerate(irs): x = m2_expr.ExprAff(x.dst, x.src.replace_expr( - {self.pc: m2_expr.ExprInt32(instr.offset + 4)})) + {self.pc: m2_expr.ExprInt(instr.offset + 4, 32)})) irs[i] = x return instr_ir, extra_ir diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py index 07ba3019..9728d776 100644 --- a/miasm2/arch/msp430/arch.py +++ b/miasm2/arch/msp430/arch.py @@ -75,7 +75,7 @@ def ast_id2expr(t): def ast_int2expr(a): - return ExprInt16(a) + return ExprInt(a, 16) variable, operand, base_expr = gen_base_expr() @@ -328,12 +328,12 @@ class msp430_sreg_arg(reg_noarg, m_arg): self.expr = e elif self.parent.a_s.value == 0b01: if e == SR: - self.expr = ExprMem(ExprInt16(self.parent.off_s.value), size) + self.expr = ExprMem(ExprInt(self.parent.off_s.value, 16), size) elif e == R3: self.expr = ExprInt(1, size) else: self.expr = ExprMem( - e + ExprInt16(self.parent.off_s.value), size) + e + ExprInt(self.parent.off_s.value, 16), size) elif self.parent.a_s.value == 0b10: if e == SR: self.expr = ExprInt(4, size) @@ -431,9 +431,9 @@ class msp430_dreg_arg(msp430_sreg_arg): self.expr = e elif self.parent.a_d.value == 1: if e == SR: - x = ExprInt16(self.parent.off_d.value) + x = ExprInt(self.parent.off_d.value, 16) else: - x = e + ExprInt16(self.parent.off_d.value) + x = e + ExprInt(self.parent.off_d.value, 16) self.expr = ExprMem(x, size) else: raise NotImplementedError( @@ -448,7 +448,7 @@ class msp430_dreg_arg(msp430_sreg_arg): self.value = self.reg_info.expr.index(e) elif isinstance(e, ExprMem): if isinstance(e.arg, ExprId): - r, i = e.arg, ExprInt16(0) + r, i = e.arg, ExprInt(0, 16) elif isinstance(e.arg, ExprOp): r, i = e.arg.args[0], e.arg.args[1] elif isinstance(e.arg, ExprInt): @@ -538,7 +538,7 @@ class msp430_offs(imm_noarg, m_arg): if (1 << (self.l - 1)) & v: v |= ~0 ^ self.lmask v = self.decodeval(v) - self.expr = ExprInt16(v) + self.expr = ExprInt(v, 16) return True def encode(self): diff --git a/miasm2/arch/msp430/sem.py b/miasm2/arch/msp430/sem.py index e8eb91cc..5bf2999f 100644 --- a/miasm2/arch/msp430/sem.py +++ b/miasm2/arch/msp430/sem.py @@ -53,7 +53,7 @@ def update_flag_zn_r(a): def update_flag_sub_cf(a, b, c): return [ExprAff(cf, - ((((a ^ b) ^ c) ^ ((a ^ c) & (a ^ b))).msb()) ^ ExprInt1(1))] + ((((a ^ b) ^ c) ^ ((a ^ c) & (a ^ b))).msb()) ^ ExprInt(1, 1))] def update_flag_add_cf(a, b, c): @@ -77,7 +77,7 @@ def mng_autoinc(a, b, size): e.append(ExprAff(a_r, a_r + ExprInt(size / 8, a_r.size))) a = ExprMem(a_r, size) if isinstance(b, ExprMem) and a_r in b.arg: - b = ExprMem(b.arg + ExprInt16(size / 8), b.size) + b = ExprMem(b.arg + ExprInt(size / 8, 16), b.size) return e, a, b # Mnemonics @@ -108,7 +108,7 @@ def and_b(ir, instr, a, b): e.append(ExprAff(b, c.zeroExtend(16))) e += update_flag_zn_r(c) e += update_flag_cf_inv_zf(c) - e += [ExprAff(of, ExprInt1(0))] + e += [ExprAff(of, ExprInt(0, 1))] return e, [] @@ -118,13 +118,13 @@ def and_w(ir, instr, a, b): e.append(ExprAff(b, c)) e += update_flag_zn_r(c) e += update_flag_cf_inv_zf(c) - e += [ExprAff(of, ExprInt1(0))] + e += [ExprAff(of, ExprInt(0, 1))] return e, [] def bic_b(ir, instr, a, b): e, a, b = mng_autoinc(a, b, 8) - c = (a[:8] ^ ExprInt8(0xff)) & b[:8] + c = (a[:8] ^ ExprInt(0xff, 8)) & b[:8] c = c.zeroExtend(b.size) e.append(ExprAff(b, c)) return e, [] @@ -132,7 +132,7 @@ def bic_b(ir, instr, a, b): def bic_w(ir, instr, a, b): e, a, b = mng_autoinc(a, b, 16) - c = (a ^ ExprInt16(0xffff)) & b + c = (a ^ ExprInt(0xffff, 16)) & b e.append(ExprAff(b, c)) return e, [] @@ -149,7 +149,7 @@ def bit_w(ir, instr, a, b): c = a & b e += update_flag_zn_r(c) e += update_flag_cf_inv_zf(c) - e.append(ExprAff(of, ExprInt1(0))) + e.append(ExprAff(of, ExprInt(0, 1))) return e, [] """ @@ -231,16 +231,16 @@ def xor_w(ir, instr, a, b): def push_w(ir, instr, a): e = [] - e.append(ExprAff(ExprMem(SP - ExprInt16(2), 16), a)) - e.append(ExprAff(SP, SP - ExprInt16(2))) + e.append(ExprAff(ExprMem(SP - ExprInt(2, 16), 16), a)) + e.append(ExprAff(SP, SP - ExprInt(2, 16))) return e, [] def call(ir, instr, a): e, a, dummy = mng_autoinc(a, None, 16) n = ExprId(ir.get_next_label(instr), 16) - e.append(ExprAff(ExprMem(SP - ExprInt16(2), 16), n)) - e.append(ExprAff(SP, SP - ExprInt16(2))) + e.append(ExprAff(ExprMem(SP - ExprInt(2, 16), 16), n)) + e.append(ExprAff(SP, SP - ExprInt(2, 16))) e.append(ExprAff(PC, a)) e.append(ExprAff(ir.IRDst, a)) return e, [] @@ -338,7 +338,7 @@ def rrc_w(ir, instr, a): # e += update_flag_nf(a) e += reset_sr_res() - e.append(ExprAff(of, ExprInt1(0))) + e.append(ExprAff(of, ExprInt(0, 1))) return e, [] @@ -355,7 +355,7 @@ def rra_w(ir, instr, a): # e += update_flag_nf(a) e += reset_sr_res() - e.append(ExprAff(of, ExprInt1(0))) + e.append(ExprAff(of, ExprInt(0, 1))) return e, [] @@ -366,7 +366,7 @@ def sxt(ir, instr, a): e += update_flag_zn_r(c) e += update_flag_cf_inv_zf(c) - e.append(ExprAff(of, ExprInt1(0))) + e.append(ExprAff(of, ExprInt(0, 1))) return e, [] @@ -441,7 +441,7 @@ class ir_msp430(IntermediateRepresentation): instr_ir[i:i+1] = xx for i, x in enumerate(instr_ir): x = ExprAff(x.dst, x.src.replace_expr( - {self.pc: ExprInt16(instr.offset + instr.l)})) + {self.pc: ExprInt(instr.offset + instr.l, 16)})) instr_ir[i] = x if extra_ir: diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py index 634cbf43..3d0eee00 100644 --- a/miasm2/arch/sh4/arch.py +++ b/miasm2/arch/sh4/arch.py @@ -38,7 +38,7 @@ def ast_id2expr(t): return mn_sh4.regs.all_regs_ids_byname.get(t, t) def ast_int2expr(a): - return ExprInt32(a) + return ExprInt(a, 32) my_var_parser = ParseAst(ast_id2expr, ast_int2expr) @@ -219,7 +219,7 @@ class sh4_dgpreg_imm(sh4_dgpreg): p = self.parent r = gpregs.expr[v] s = self.sz - d = ExprInt32(p.disp.value * s / 8) + d = ExprInt(p.disp.value * s / 8, 32) e = ExprMem(r + d, s) self.expr = e return True @@ -263,7 +263,7 @@ class sh4_simm(sh4_imm): def decode(self, v): v = sign_ext(v, self.l, 32) v = self.decodeval(v) - self.expr = ExprInt32(v) + self.expr = ExprInt(v, 32) return True def encode(self): @@ -281,7 +281,7 @@ class sh4_dpc16imm(sh4_dgpreg): parser = deref_pc def decode(self, v): - self.expr = ExprMem(PC + ExprInt32(v * 2 + 4), 16) + self.expr = ExprMem(PC + ExprInt(v * 2 + 4, 32), 16) return True def calcdisp(self, v): @@ -308,7 +308,7 @@ class sh4_dgbrimm8(sh4_dgpreg): def decode(self, v): s = self.sz - self.expr = ExprMem(GBR + ExprInt32(v * s / 8), s) + self.expr = ExprMem(GBR + ExprInt(v * s / 8, 32), s) return True def encode(self): @@ -331,7 +331,7 @@ class sh4_dpc32imm(sh4_dpc16imm): def decode(self, v): self.expr = ExprMem( - (PC & ExprInt32(0xfffffffc)) + ExprInt32(v * 4 + 4)) + (PC & ExprInt(0xfffffffc, 32)) + ExprInt(v * 4 + 4, 32)) return True def calcdisp(self, v): @@ -342,7 +342,7 @@ class sh4_dpc32imm(sh4_dpc16imm): def encode(self): res = MatchExpr( - self.expr, ExprMem((PC & ExprInt32(0xFFFFFFFC)) + jra, 32), [jra]) + self.expr, ExprMem((PC & ExprInt(0xFFFFFFFC, 32)) + jra, 32), [jra]) if not res: return False if not isinstance(res[jra], ExprInt): @@ -358,11 +358,11 @@ class sh4_pc32imm(m_arg): parser = pcdisp def decode(self, v): - self.expr = (PC & ExprInt32(0xfffffffc)) + ExprInt32(v * 4 + 4) + self.expr = (PC & ExprInt(0xfffffffc, 32)) + ExprInt(v * 4 + 4, 32) return True def encode(self): - res = MatchExpr(self.expr, (PC & ExprInt32(0xfffffffc)) + jra, [jra]) + res = MatchExpr(self.expr, (PC & ExprInt(0xfffffffc, 32)) + jra, [jra]) if not res: return False if not isinstance(res[jra], ExprInt): @@ -455,7 +455,7 @@ class instruction_sh4(instruction): print hex(off) if int(off % 4): raise ValueError('strange offset! %r' % off) - self.args[0] = ExprInt32(off) + self.args[0] = ExprInt(off, 32) print 'final', self.args[0] def get_args_expr(self): diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py index d686cd55..300021c1 100644 --- a/miasm2/arch/x86/arch.py +++ b/miasm2/arch/x86/arch.py @@ -227,7 +227,7 @@ def ast_id2expr(t): def ast_int2expr(a): - return ExprInt64(a) + return ExprInt(a, 64) my_var_parser = ParseAst(ast_id2expr, ast_int2expr) @@ -1126,7 +1126,7 @@ class x86_s08to16(x86_imm): out_size = 16 def myexpr(self, x): - return ExprInt16(x) + return ExprInt(x, 16) def int2expr(self, v): return self.myexpr(v) @@ -1143,7 +1143,7 @@ class x86_s08to16(x86_imm): v = v & self.lmask v = self.decodeval(v) if self.parent.v_opmode() == 64: - self.expr = ExprInt64(sign_ext(v, self.in_size, 64)) + self.expr = ExprInt(sign_ext(v, self.in_size, 64), 64) else: if (1 << (self.l - 1)) & v: v = sign_ext(v, self.l, self.out_size) @@ -1191,15 +1191,15 @@ class x86_s08to32(x86_s08to16): out_size = 32 def myexpr(self, x): - return ExprInt32(x) + return ExprInt(x, 32) def decode(self, v): v = v & self.lmask v = self.decodeval(v) if self.parent.rex_w.value == 1: - v = ExprInt64(sign_ext(v, self.in_size, 64)) + v = ExprInt(sign_ext(v, self.in_size, 64), 64) else: - v = ExprInt32(sign_ext(v, self.in_size, 32)) + v = ExprInt(sign_ext(v, self.in_size, 32), 32) self.expr = v return True @@ -1210,7 +1210,7 @@ class x86_s08to64(x86_s08to32): out_size = 64 def myexpr(self, x): - return ExprInt64(x) + return ExprInt(x, 64) class x86_s32to64(x86_s08to32): @@ -1218,7 +1218,7 @@ class x86_s32to64(x86_s08to32): out_size = 64 def myexpr(self, x): - return ExprInt64(x) + return ExprInt(x, 64) class bs_eax(m_arg): @@ -1754,15 +1754,15 @@ def parse_mem(expr, parent, w8, sx=0, xmm=0, mm=0): out = [] if disp is None: # add 0 disp - disp = ExprInt32(0) + disp = ExprInt(0, 32) if disp is not None: - for signed, encoding, cast_int in [(True, f_s08, ExprInt8), - (True, f_s16, ExprInt16), - (True, f_s32, ExprInt32), - (False, f_u08, ExprInt8), - (False, f_u16, ExprInt16), - (False, f_u32, ExprInt32)]: - value = cast_int(int(disp)) + for signed, encoding, cast_size in [(True, f_s08, 8), + (True, f_s16, 16), + (True, f_s32, 32), + (False, f_u08, 8), + (False, f_u16, 16), + (False, f_u32, 32)]: + value = ExprInt(int(disp), cast_size) if admode < value.size: if signed: if int(disp.arg) != sign_ext(int(value), admode, disp.size): @@ -2581,7 +2581,7 @@ class bs_cl1(bsi, m_arg): if v == 1: self.expr = regs08_expr[1] else: - self.expr = ExprInt8(1) + self.expr = ExprInt(1, 8) return True def encode(self): @@ -3069,7 +3069,7 @@ class bs_msegoff(m_arg): opmode = self.parent.v_opmode() v = swap_uint(self.l, v) self.value = v - v = ExprInt16(v) + v = ExprInt(v, 16) self.expr = ExprOp('segm', v, self.parent.off.expr) return True diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 729806b5..98866e65 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -673,7 +673,7 @@ def cli(_, instr): def sti(_, instr): - e = [m2_expr.ExprAff(exception_flags, m2_expr.ExprInt32(EXCEPT_PRIV_INSN))] + e = [m2_expr.ExprAff(exception_flags, m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))] return e, [] @@ -1009,13 +1009,13 @@ def scas(ir, instr, size): def compose_eflag(s=32): args = [] - args = [cf, m2_expr.ExprInt1(1), pf, m2_expr.ExprInt1(0), af, - m2_expr.ExprInt1(0), zf, nf, tf, i_f, df, of, iopl] + args = [cf, m2_expr.ExprInt(1, 1), pf, m2_expr.ExprInt(0, 1), af, + m2_expr.ExprInt(0, 1), zf, nf, tf, i_f, df, of, iopl] if s == 32: - args += [nt, m2_expr.ExprInt1(0), rf, vm, ac, vif, vip, i_d] + args += [nt, m2_expr.ExprInt(0, 1), rf, vm, ac, vif, vip, i_d] elif s == 16: - args += [nt, m2_expr.ExprInt1(0)] + args += [nt, m2_expr.ExprInt(0, 1)] else: raise ValueError('unk size') if s == 32: @@ -1059,8 +1059,8 @@ def popfd(ir, instr): mRSP[instr.mode] + m2_expr.ExprInt(instr.mode / 8, mRSP[instr.mode].size))) e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprCond(m2_expr.ExprSlice(tmp, 8, 9), - m2_expr.ExprInt32( - EXCEPT_SOFT_BP), + m2_expr.ExprInt( + EXCEPT_SOFT_BP, 32), exception_flags ) ) @@ -1406,9 +1406,9 @@ def loopne(ir, instr, dst): n = m2_expr.ExprId(ir.get_next_label(instr), ir.IRDst.size) c = m2_expr.ExprCond(myecx - m2_expr.ExprInt(1, size=myecx.size), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) - c &= zf ^ m2_expr.ExprInt1(1) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) + c &= zf ^ m2_expr.ExprInt(1, 1) e.append(m2_expr.ExprAff(myecx, myecx - m2_expr.ExprInt(1, myecx.size))) dst_o = m2_expr.ExprCond(c, @@ -1427,8 +1427,8 @@ def loope(ir, instr, dst): n = m2_expr.ExprId(ir.get_next_label(instr), ir.IRDst.size) c = m2_expr.ExprCond(myecx - m2_expr.ExprInt(1, size=myecx.size), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) c &= zf e.append(m2_expr.ExprAff(myecx, myecx - m2_expr.ExprInt(1, myecx.size))) dst_o = m2_expr.ExprCond(c, @@ -1512,11 +1512,11 @@ def mul(_, instr, src1): raise ValueError('unknow size') e.append(m2_expr.ExprAff(of, m2_expr.ExprCond(result[size:size * 2], - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)))) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)))) e.append(m2_expr.ExprAff(cf, m2_expr.ExprCond(result[size:size * 2], - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)))) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)))) return e, [] @@ -1539,12 +1539,12 @@ def imul(_, instr, src1, src2=None, src3=None): e.append(m2_expr.ExprAff(dst, result)) value = m2_expr.ExprCond(result - result[:size].signExtend(size * 2), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) e.append(m2_expr.ExprAff(cf, value)) value = m2_expr.ExprCond(result - result[:size].signExtend(size * 2), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) e.append(m2_expr.ExprAff(of, value)) else: @@ -1557,12 +1557,12 @@ def imul(_, instr, src1, src2=None, src3=None): e.append(m2_expr.ExprAff(src1, result[:size])) value = m2_expr.ExprCond(result - result[:size].signExtend(size * 2), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) e.append(m2_expr.ExprAff(cf, value)) value = m2_expr.ExprCond(result - result[:size].signExtend(size * 2), - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) e.append(m2_expr.ExprAff(of, value)) return e, [] @@ -1808,7 +1808,7 @@ def ftst(_, instr): dst = float_st0 e = [] - src = m2_expr.ExprOp('int_32_to_double', m2_expr.ExprInt32(0)) + src = m2_expr.ExprOp('int_32_to_double', m2_expr.ExprInt(0, 32)) e.append(m2_expr.ExprAff(float_c0, m2_expr.ExprOp('fcom_c0', dst, src))) e.append(m2_expr.ExprAff(float_c1, m2_expr.ExprOp('fcom_c1', dst, src))) e.append(m2_expr.ExprAff(float_c2, m2_expr.ExprOp('fcom_c2', dst, src))) @@ -1868,9 +1868,9 @@ def fcomi(_, instr, dst=None, src=None): e.append(m2_expr.ExprAff(pf, m2_expr.ExprOp('fcom_c2', dst, src))) e.append(m2_expr.ExprAff(zf, m2_expr.ExprOp('fcom_c3', dst, src))) - e.append(m2_expr.ExprAff(of, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(of, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) e += set_float_cs_eip(instr) return e, [] @@ -1941,9 +1941,9 @@ def comiss(_, instr, dst, src): e.append(m2_expr.ExprAff(pf, m2_expr.ExprOp('fcom_c2', dst, src))) e.append(m2_expr.ExprAff(zf, m2_expr.ExprOp('fcom_c3', dst, src))) - e.append(m2_expr.ExprAff(of, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(of, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) e += set_float_cs_eip(instr) return e, [] @@ -1961,9 +1961,9 @@ def comisd(_, instr, dst, src): e.append(m2_expr.ExprAff(pf, m2_expr.ExprOp('fcom_c2', dst, src))) e.append(m2_expr.ExprAff(zf, m2_expr.ExprOp('fcom_c3', dst, src))) - e.append(m2_expr.ExprAff(of, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(of, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) e += set_float_cs_eip(instr) return e, [] @@ -2064,47 +2064,47 @@ def fild(ir, instr, src): def fldz(ir, instr): return fld(ir, instr, m2_expr.ExprOp('int_32_to_double', - m2_expr.ExprInt32(0))) + m2_expr.ExprInt(0, 32))) def fld1(ir, instr): return fld(ir, instr, m2_expr.ExprOp('int_32_to_double', - m2_expr.ExprInt32(1))) + m2_expr.ExprInt(1, 32))) def fldl2t(ir, instr): value_f = math.log(10) / math.log(2) value = struct.unpack('I', struct.pack('f', value_f))[0] return fld(ir, instr, m2_expr.ExprOp('int_32_to_double', - m2_expr.ExprInt32(value))) + m2_expr.ExprInt(value, 32))) def fldpi(ir, instr): value_f = math.pi value = struct.unpack('I', struct.pack('f', value_f))[0] return fld(ir, instr, m2_expr.ExprOp('int_32_to_double', - m2_expr.ExprInt32(value))) + m2_expr.ExprInt(value, 32))) def fldln2(ir, instr): value_f = math.log(2) value = struct.unpack('Q', struct.pack('d', value_f))[0] return fld(ir, instr, m2_expr.ExprOp('mem_64_to_double', - m2_expr.ExprInt64(value))) + m2_expr.ExprInt(value, 64))) def fldl2e(ir, instr): x = struct.pack('d', 1 / math.log(2)) x = struct.unpack('Q', x)[0] return fld(ir, instr, m2_expr.ExprOp('mem_64_to_double', - m2_expr.ExprInt64(x))) + m2_expr.ExprInt(x, 64))) def fldlg2(ir, instr): x = struct.pack('d', math.log10(2)) x = struct.unpack('Q', x)[0] return fld(ir, instr, m2_expr.ExprOp('mem_64_to_double', - m2_expr.ExprInt64(x))) + m2_expr.ExprInt(x, 64))) def fadd(_, instr, dst, src=None): @@ -2164,7 +2164,7 @@ def fprem(_, instr): m2_expr.ExprAff(float_c3, remain[1:2]), m2_expr.ExprAff(float_c1, remain[0:1]), # Consider the reduction is always completed - m2_expr.ExprAff(float_c2, m2_expr.ExprInt1(0)), + m2_expr.ExprAff(float_c2, m2_expr.ExprInt(0, 1)), ] e += set_float_cs_eip(instr) return e, [] @@ -2207,10 +2207,10 @@ def fyl2x(_, instr): def fnstenv(ir, instr, dst): e = [] # XXX TODO tag word, ... - status_word = m2_expr.ExprCompose(m2_expr.ExprInt8(0), + status_word = m2_expr.ExprCompose(m2_expr.ExprInt(0, 8), float_c0, float_c1, float_c2, float_stack_ptr, float_c3, - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(0, 1)) s = instr.mode # The behaviour in 64bit is identical to 32 bit @@ -2424,7 +2424,7 @@ def fptan(_, instr): e.append(m2_expr.ExprAff(float_st1, m2_expr.ExprOp('ftan', float_st0))) e.append(m2_expr.ExprAff(float_st0, m2_expr.ExprOp('int_32_to_double', - m2_expr.ExprInt32(1)))) + m2_expr.ExprInt(1, 32)))) e.append( m2_expr.ExprAff(float_stack_ptr, float_stack_ptr + m2_expr.ExprInt(1, 3))) @@ -2507,14 +2507,14 @@ def fabs(_, instr): def fnstsw(_, instr, dst): args = [ # Exceptions -> 0 - m2_expr.ExprInt8(0), + m2_expr.ExprInt(0, 8), float_c0, float_c1, float_c2, float_stack_ptr, float_c3, # B: FPU is not busy -> 0 - m2_expr.ExprInt1(0)] + m2_expr.ExprInt(0, 1)] e = [m2_expr.ExprAff(dst, m2_expr.ExprCompose(*args))] return e, [] @@ -2592,17 +2592,16 @@ def ud2(_, instr, src=None): def hlt(_, instr): e = [] except_int = EXCEPT_PRIV_INSN - e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt32(except_int))) + e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt(except_int, 32))) return e, [] def rdtsc(_, instr): e = [] - e.append(m2_expr.ExprAff(tsc1, tsc1 + m2_expr.ExprInt32(1))) + e.append(m2_expr.ExprAff(tsc1, tsc1 + m2_expr.ExprInt(1, 32))) e.append(m2_expr.ExprAff(tsc2, tsc2 + m2_expr.ExprCond(tsc1 - tsc1.mask, - m2_expr.ExprInt32( - 0), - m2_expr.ExprInt32(1)))) + m2_expr.ExprInt(0, 32), + m2_expr.ExprInt(1, 32)))) e.append(m2_expr.ExprAff(mRAX[32], tsc1)) e.append(m2_expr.ExprAff(mRDX[32], tsc2)) return e, [] @@ -2615,23 +2614,23 @@ def daa(_, instr): cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) - cond2 = expr_cmpu(m2_expr.ExprInt8(6), r_al) - cond3 = expr_cmpu(r_al, m2_expr.ExprInt8(0x99)) | cf + cond2 = expr_cmpu(m2_expr.ExprInt(6, 8), r_al) + cond3 = expr_cmpu(r_al, m2_expr.ExprInt(0x99, 8)) | cf cf_c1 = m2_expr.ExprCond(cond1, cf | (cond2), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(0, 1)) new_cf = m2_expr.ExprCond(cond3, - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(1, 1), + m2_expr.ExprInt(0, 1)) e.append(m2_expr.ExprAff(cf, new_cf)) al_c1 = m2_expr.ExprCond(cond1, - r_al + m2_expr.ExprInt8(6), + r_al + m2_expr.ExprInt(6, 8), r_al) new_al = m2_expr.ExprCond(cond3, - al_c1 + m2_expr.ExprInt8(0x60), + al_c1 + m2_expr.ExprInt(0x60, 8), al_c1) e.append(m2_expr.ExprAff(r_al, new_al)) e += update_flag_znp(new_al) @@ -2645,23 +2644,23 @@ def das(_, instr): cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt(0x9, 4)) | af e.append(m2_expr.ExprAff(af, cond1)) - cond2 = expr_cmpu(m2_expr.ExprInt8(6), r_al) - cond3 = expr_cmpu(r_al, m2_expr.ExprInt8(0x99)) | cf + cond2 = expr_cmpu(m2_expr.ExprInt(6, 8), r_al) + cond3 = expr_cmpu(r_al, m2_expr.ExprInt(0x99, 8)) | cf cf_c1 = m2_expr.ExprCond(cond1, cf | (cond2), - m2_expr.ExprInt1(0)) + m2_expr.ExprInt(0, 1)) new_cf = m2_expr.ExprCond(cond3, - m2_expr.ExprInt1(1), + m2_expr.ExprInt(1, 1), cf_c1) e.append(m2_expr.ExprAff(cf, new_cf)) al_c1 = m2_expr.ExprCond(cond1, - r_al - m2_expr.ExprInt8(6), + r_al - m2_expr.ExprInt(6, 8), r_al) new_al = m2_expr.ExprCond(cond3, - al_c1 - m2_expr.ExprInt8(0x60), + al_c1 - m2_expr.ExprInt(0x60, 8), al_c1) e.append(m2_expr.ExprAff(r_al, new_al)) e += update_flag_znp(new_al) @@ -2676,7 +2675,7 @@ def aam(_, instr, src): mRAX[instr.mode][16:]) e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)] e += update_flag_arith(newEAX) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) return e, [] @@ -2684,12 +2683,12 @@ def aad(_, instr, src): e = [] tempAL = mRAX[instr.mode][0:8] tempAH = mRAX[instr.mode][8:16] - newEAX = m2_expr.ExprCompose((tempAL + (tempAH * src)) & m2_expr.ExprInt8(0xFF), - m2_expr.ExprInt8(0), + newEAX = m2_expr.ExprCompose((tempAL + (tempAH * src)) & m2_expr.ExprInt(0xFF, 8), + m2_expr.ExprInt(0, 8), mRAX[instr.mode][16:]) e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)] e += update_flag_arith(newEAX) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) return e, [] @@ -2701,10 +2700,10 @@ def _tpl_aaa(_, instr, op): r_al = mRAX[instr.mode][:8] r_ah = mRAX[instr.mode][8:16] r_ax = mRAX[instr.mode][:16] - i0 = m2_expr.ExprInt1(0) - i1 = m2_expr.ExprInt1(1) + i0 = m2_expr.ExprInt(0, 1) + i1 = m2_expr.ExprInt(1, 1) # cond: if (al & 0xf) > 9 OR af == 1 - cond = (r_al & m2_expr.ExprInt8(0xf)) - m2_expr.ExprInt8(9) + cond = (r_al & m2_expr.ExprInt(0xf, 8)) - m2_expr.ExprInt(9, 8) cond = ~cond.msb() & m2_expr.ExprCond(cond, i1, i0) cond |= af & i1 @@ -2772,13 +2771,13 @@ def bsr(ir, instr, dst, src): def arpl(_, instr, dst, src): e = [] - e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt32(1 << 7))) + e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt(1 << 7, 32))) return e, [] def ins(_, instr, size): e = [] - e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt32(1 << 7))) + e.append(m2_expr.ExprAff(exception_flags, m2_expr.ExprInt(1 << 7, 32))) return e, [] @@ -2789,10 +2788,10 @@ def sidt(ir, instr, dst): ptr = dst.arg print "DEFAULT SIDT ADDRESS %s!!" % str(dst) e.append(m2_expr.ExprAff(ir.ExprMem(ptr, 32), - m2_expr.ExprInt32(0xe40007ff))) + m2_expr.ExprInt(0xe40007ff, 32))) e.append( m2_expr.ExprAff(ir.ExprMem(ptr + m2_expr.ExprInt(4, ptr.size), 16), - m2_expr.ExprInt16(0x8245))) + m2_expr.ExprInt(0x8245, 16))) return e, [] @@ -2869,7 +2868,7 @@ def cmovns(ir, instr, dst, src): def icebp(_, instr): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_SOFT_BP))) + m2_expr.ExprInt(EXCEPT_SOFT_BP, 32))) return e, [] # XXX @@ -2882,7 +2881,7 @@ def l_int(_, instr, src): else: except_int = EXCEPT_INT_XX e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(except_int))) + m2_expr.ExprInt(except_int, 32))) e.append(m2_expr.ExprAff(interrupt_num, src)) return e, [] @@ -2890,14 +2889,14 @@ def l_int(_, instr, src): def l_sysenter(_, instr): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_PRIV_INSN))) + m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))) return e, [] def l_syscall(_, instr): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_PRIV_INSN))) + m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))) return e, [] # XXX @@ -2906,7 +2905,7 @@ def l_syscall(_, instr): def l_out(_, instr, src1, src2): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_PRIV_INSN))) + m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))) return e, [] # XXX @@ -2915,7 +2914,7 @@ def l_out(_, instr, src1, src2): def l_outs(_, instr, size): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_PRIV_INSN))) + m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))) return e, [] # XXX actually, xlat performs al = (ds:[e]bx + ZeroExtend(al)) @@ -3020,7 +3019,7 @@ def into(_, instr): def l_in(_, instr, src1, src2): e = [] e.append(m2_expr.ExprAff(exception_flags, - m2_expr.ExprInt32(EXCEPT_PRIV_INSN))) + m2_expr.ExprInt(EXCEPT_PRIV_INSN, 32))) return e, [] @@ -3094,8 +3093,8 @@ def lgs(ir, instr, dst, src): def lahf(_, instr): e = [] - args = [cf, m2_expr.ExprInt1(1), pf, m2_expr.ExprInt1(0), af, - m2_expr.ExprInt1(0), zf, nf] + args = [cf, m2_expr.ExprInt(1, 1), pf, m2_expr.ExprInt(0, 1), af, + m2_expr.ExprInt(0, 1), zf, nf] e.append( m2_expr.ExprAff(mRAX[instr.mode][8:16], m2_expr.ExprCompose(*args))) return e, [] @@ -3139,7 +3138,7 @@ def fnclex(_, instr): def l_str(_, instr, dst): e = [] e.append(m2_expr.ExprAff(dst, m2_expr.ExprOp('load_tr_segment_selector', - m2_expr.ExprInt32(0)))) + m2_expr.ExprInt(0, 32)))) return e, [] @@ -3147,7 +3146,7 @@ def movd(_, instr, dst, src): e = [] if dst in regs_mm_expr: e.append(m2_expr.ExprAff( - dst, m2_expr.ExprCompose(src, m2_expr.ExprInt32(0)))) + dst, m2_expr.ExprCompose(src, m2_expr.ExprInt(0, 32)))) elif dst in regs_xmm_expr: e.append(m2_expr.ExprAff( dst, m2_expr.ExprCompose(src, m2_expr.ExprInt(0, 96)))) @@ -3191,7 +3190,8 @@ def xorps(_, instr, dst, src): def rdmsr(ir, instr): - msr_addr = m2_expr.ExprId('MSR') + m2_expr.ExprInt32( + msr_addr = m2_expr.ExprId('MSR') + m2_expr.ExprInt( + 0, 8) * mRCX[instr.mode][:32] e = [] e.append( @@ -3202,8 +3202,9 @@ def rdmsr(ir, instr): def wrmsr(ir, instr): - msr_addr = m2_expr.ExprId('MSR') + m2_expr.ExprInt32( - 8) * mRCX[instr.mode][:32] + msr_addr = m2_expr.ExprId('MSR') + m2_expr.ExprInt( + 8, + 32) * mRCX[instr.mode][:32] e = [] src = m2_expr.ExprCompose(mRAX[instr.mode][:32], mRDX[instr.mode][:32]) e.append(m2_expr.ExprAff(ir.ExprMem(msr_addr, 64), src)) @@ -3392,7 +3393,7 @@ def cvtpd2dq(_, instr, dst, src): m2_expr.ExprAff(dst[:32], m2_expr.ExprOp('double_to_int_32', src[:64]))) e.append( m2_expr.ExprAff(dst[32:64], m2_expr.ExprOp('double_to_int_32', src[64:128]))) - e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt64(0))) + e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt(0, 64))) return e, [] @@ -3411,7 +3412,7 @@ def cvtpd2ps(_, instr, dst, src): m2_expr.ExprAff(dst[:32], m2_expr.ExprOp('double_to_float', src[:64]))) e.append( m2_expr.ExprAff(dst[32:64], m2_expr.ExprOp('double_to_float', src[64:128]))) - e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt64(0))) + e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt(0, 64))) return e, [] @@ -3521,7 +3522,7 @@ def cvttpd2dq(_, instr, dst, src): m2_expr.ExprAff(dst[:32], m2_expr.ExprOp('double_trunc_to_int_32', src[:64]))) e.append( m2_expr.ExprAff(dst[32:64], m2_expr.ExprOp('double_trunc_to_int_32', src[64:128]))) - e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt64(0))) + e.append(m2_expr.ExprAff(dst[64:128], m2_expr.ExprInt(0, 64))) return e, [] @@ -3585,9 +3586,9 @@ def ucomiss(_, instr, src1, src2): e.append(m2_expr.ExprAff(cf, m2_expr.ExprOp( 'ucomiss_cf', src1[:32], src2[:32]))) - e.append(m2_expr.ExprAff(of, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) - e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt1(0))) + e.append(m2_expr.ExprAff(of, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1))) + e.append(m2_expr.ExprAff(nf, m2_expr.ExprInt(0, 1))) return e, [] @@ -3606,7 +3607,7 @@ def pshufb(_, instr, dst, src): value = (dst >> index)[:8] e.append(m2_expr.ExprAff(dst[i:i + 8], m2_expr.ExprCond(src[i + 7:i + 8], - m2_expr.ExprInt8(0), + m2_expr.ExprInt(0, 8), value))) return e, [] @@ -4556,14 +4557,14 @@ class ir_x86_16(IntermediateRepresentation): zf_val = e.src cond_dec = m2_expr.ExprCond(c_reg - m2_expr.ExprInt(1, c_reg.size), - m2_expr.ExprInt1(0), m2_expr.ExprInt1(1)) + m2_expr.ExprInt(0, 1), m2_expr.ExprInt(1, 1)) # end condition if zf_val is None: c_cond = cond_dec elif instr.additional_info.g1.value & 2: # REPNE c_cond = cond_dec | zf elif instr.additional_info.g1.value & 4: # REP - c_cond = cond_dec | (zf ^ m2_expr.ExprInt1(1)) + c_cond = cond_dec | (zf ^ m2_expr.ExprInt(1, 1)) # gen while lbl_do = m2_expr.ExprId(self.gen_label(), self.IRDst.size) @@ -4652,17 +4653,17 @@ class ir_x86_64(ir_x86_16): dst, src = expr.dst, expr.src if dst != self.pc: dst = dst.replace_expr( - {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)}) + {self.pc: m2_expr.ExprInt(instr.offset + instr.l, 64)}) src = src.replace_expr( - {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)}) + {self.pc: m2_expr.ExprInt(instr.offset + instr.l, 64)}) instr_ir[i] = m2_expr.ExprAff(dst, src) for irblock in extra_ir: for irs in irblock.irs: for i, expr in enumerate(irs): dst, src = expr.dst, expr.src if dst != self.pc: - new_pc = m2_expr.ExprInt64(instr.offset + instr.l) + new_pc = m2_expr.ExprInt(instr.offset + instr.l, 64) dst = dst.replace_expr({self.pc: new_pc}) src = src.replace_expr( - {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)}) + {self.pc: m2_expr.ExprInt(instr.offset + instr.l, 64)}) irs[i] = m2_expr.ExprAff(dst, src) diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py index 8b906027..3502397d 100644 --- a/miasm2/core/cpu.py +++ b/miasm2/core/cpu.py @@ -196,7 +196,7 @@ def ast_id2expr(a): def ast_int2expr(a): - return m2_expr.ExprInt32(a) + return m2_expr.ExprInt(a, 32) @@ -1558,19 +1558,19 @@ class imm_noarg(object): class imm08_noarg(object): - int2expr = lambda self, x: m2_expr.ExprInt08(x) + int2expr = lambda self, x: m2_expr.ExprInt(x, 8) class imm16_noarg(object): - int2expr = lambda self, x: m2_expr.ExprInt16(x) + int2expr = lambda self, x: m2_expr.ExprInt(x, 16) class imm32_noarg(object): - int2expr = lambda self, x: m2_expr.ExprInt32(x) + int2expr = lambda self, x: m2_expr.ExprInt(x, 32) class imm64_noarg(object): - int2expr = lambda self, x: m2_expr.ExprInt64(x) + int2expr = lambda self, x: m2_expr.ExprInt(x, 64) class int32_noarg(imm_noarg): diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index ead881ee..85471e05 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -30,7 +30,8 @@ import itertools from operator import itemgetter -from miasm2.expression.modint import mod_size2uint, is_modint, size2mask +from miasm2.expression.modint import mod_size2uint, is_modint, size2mask, \ + define_uint from miasm2.core.graph import DiGraph import warnings @@ -462,7 +463,7 @@ class ExprInt(Expr): return self def copy(self): - return ExprInt(self.__arg) + return ExprInt(self.__arg, self.__size) def depth(self): return 1 diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py index 36e5f1d5..1e718faa 100644 --- a/miasm2/expression/expression_helper.py +++ b/miasm2/expression/expression_helper.py @@ -521,7 +521,7 @@ class CondConstraintNotZero(CondConstraint): operator = "!=" def to_constraint(self): - cst1, cst2 = m2_expr.ExprInt1(0), m2_expr.ExprInt1(1) + cst1, cst2 = m2_expr.ExprInt(0, 1), m2_expr.ExprInt(1, 1) return m2_expr.ExprAff(cst1, m2_expr.ExprCond(self.expr, cst1, cst2)) diff --git a/miasm2/expression/modint.py b/miasm2/expression/modint.py index b6a0e4ee..51a2620e 100644 --- a/miasm2/expression/modint.py +++ b/miasm2/expression/modint.py @@ -224,7 +224,7 @@ def define_uint(size): return cls def define_common_int(): - "Define common int: ExprInt1, ExprInt2, .." + "Define common int" common_int = xrange(1, 257) for i in common_int: diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index c9b7932a..01db7597 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -238,7 +238,7 @@ def simp_cst_propagation(e_s, e): # parity(int) => int if op == 'parity' and args[0].is_int(): - return ExprInt1(parity(int(args[0]))) + return ExprInt(parity(int(args[0])), 1) # (-a) * b * (-c) * (-d) => (-a) * b * c * d if op == "*" and len(args) > 1: @@ -581,8 +581,8 @@ def simp_cond(e_s, e): # eval exprcond src1/src2 with satifiable/unsatisfiable condition # propagation if (not e.cond.is_int()) and e.cond.size == 1: - src1 = e.src1.replace_expr({e.cond: ExprInt1(1)}) - src2 = e.src2.replace_expr({e.cond: ExprInt1(0)}) + src1 = e.src1.replace_expr({e.cond: ExprInt(1, 1)}) + src2 = e.src2.replace_expr({e.cond: ExprInt(0, 1)}) if src1 != e.src1 or src2 != e.src2: return ExprCond(e.cond, src1, src2) diff --git a/miasm2/expression/simplifications_cond.py b/miasm2/expression/simplifications_cond.py index 03bf6166..0d194d9a 100644 --- a/miasm2/expression/simplifications_cond.py +++ b/miasm2/expression/simplifications_cond.py @@ -169,7 +169,7 @@ def expr_simp_inverse(expr_simp, e): def expr_simp_equal(expr_simp, e): """(x - y)?(0:1) == (x == y)""" - to_match = m2_expr.ExprCond(jok1 + jok2, m2_expr.ExprInt1(0), m2_expr.ExprInt1(1)) + to_match = m2_expr.ExprCond(jok1 + jok2, m2_expr.ExprInt(0, 1), m2_expr.ExprInt(1, 1)) r = __MatchExprWrap(e, to_match, [jok1, jok2]) @@ -188,13 +188,13 @@ def exec_inf_unsigned(expr_simp, e): arg1, arg2 = e.args if isinstance(arg1, m2_expr.ExprInt) and isinstance(arg2, m2_expr.ExprInt): - return m2_expr.ExprInt1(1) if (arg1.arg < arg2.arg) else m2_expr.ExprInt1(0) + return m2_expr.ExprInt(1, 1) if (arg1.arg < arg2.arg) else m2_expr.ExprInt(0, 1) else: return e def __comp_signed(arg1, arg2): - """Return ExprInt1(1) if arg1 <s arg2 else ExprInt1(0) + """Return ExprInt(1, 1) if arg1 <s arg2 else ExprInt(0, 1) @arg1, @arg2: ExprInt""" val1 = int(arg1) @@ -205,7 +205,7 @@ def __comp_signed(arg1, arg2): if val2 >> (arg2.size - 1) == 1: val2 = - ((int(arg2.mask) ^ val2) + 1) - return m2_expr.ExprInt1(1) if (val1 < val2) else m2_expr.ExprInt1(0) + return m2_expr.ExprInt(1, 1) if (val1 < val2) else m2_expr.ExprInt(0, 1) def exec_inf_signed(expr_simp, e): "Compute x <s y" @@ -228,6 +228,6 @@ def exec_equal(expr_simp, e): arg1, arg2 = e.args if isinstance(arg1, m2_expr.ExprInt) and isinstance(arg2, m2_expr.ExprInt): - return m2_expr.ExprInt1(1) if (arg1.arg == arg2.arg) else m2_expr.ExprInt1(0) + return m2_expr.ExprInt(1, 1) if (arg1.arg == arg2.arg) else m2_expr.ExprInt(0, 1) else: return e diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 226a1b8e..85000935 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -945,7 +945,7 @@ class LLVMFunction(): if isinstance(offset, (int, long)): offset = self.add_ir(m2_expr.ExprInt(offset, PC.size)) self.affect(offset, PC) - self.affect(self.add_ir(m2_expr.ExprInt8(1)), m2_expr.ExprId("status")) + self.affect(self.add_ir(m2_expr.ExprInt(1, 8)), m2_expr.ExprId("status")) self.set_ret(offset) builder.position_at_end(merge_block) @@ -992,7 +992,7 @@ class LLVMFunction(): if isinstance(offset, (int, long)): offset = self.add_ir(m2_expr.ExprInt(offset, PC.size)) self.affect(offset, PC) - self.affect(self.add_ir(m2_expr.ExprInt8(1)), m2_expr.ExprId("status")) + self.affect(self.add_ir(m2_expr.ExprInt(1, 8)), m2_expr.ExprId("status")) self.set_ret(offset) builder.position_at_end(merge_block) @@ -1102,7 +1102,7 @@ class LLVMFunction(): self.gen_post_code(attrib) self.affect(dst, PC) self.gen_post_instr_checks(attrib, dst) - self.affect(self.add_ir(m2_expr.ExprInt8(0)), m2_expr.ExprId("status")) + self.affect(self.add_ir(m2_expr.ExprInt(0, 8)), m2_expr.ExprId("status")) self.set_ret(dst) @@ -1198,7 +1198,7 @@ class LLVMFunction(): builder = self.builder m2_exception_flag = self.llvm_context.ir_arch.arch.regs.exception_flags t_size = LLVMType.IntType(m2_exception_flag.size) - self.affect(self.add_ir(m2_expr.ExprInt8(1)), + self.affect(self.add_ir(m2_expr.ExprInt(1, 8)), m2_expr.ExprId("status")) self.affect(t_size(m2_csts.EXCEPT_UNK_MNEMO), m2_exception_flag) @@ -1216,7 +1216,7 @@ class LLVMFunction(): builder.position_at_end(self.get_basic_bloc_by_label(next_label)) # Common code - self.affect(self.add_ir(m2_expr.ExprInt8(0)), + self.affect(self.add_ir(m2_expr.ExprInt(0, 8)), m2_expr.ExprId("status")) # Check if IRDst has been set @@ -1240,7 +1240,7 @@ class LLVMFunction(): PC = self.llvm_context.PC to_ret = self.add_ir(codegen.delay_slot_dst) self.affect(to_ret, PC) - self.affect(self.add_ir(m2_expr.ExprInt8(0)), + self.affect(self.add_ir(m2_expr.ExprInt(0, 8)), m2_expr.ExprId("status")) self.set_ret(to_ret) diff --git a/test/analysis/data_flow.py b/test/analysis/data_flow.py index a40d000a..1784f87f 100644 --- a/test/analysis/data_flow.py +++ b/test/analysis/data_flow.py @@ -1,5 +1,5 @@ """ Test cases for dead code elimination""" -from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprMem +from miasm2.expression.expression import ExprId, ExprInt, ExprAff, ExprMem from miasm2.core.asmblock import AsmLabel from miasm2.analysis.data_flow import * from miasm2.ir.analysis import ira @@ -20,9 +20,9 @@ r_init = ExprId("r_init") # Return register pc = ExprId("pc") sp = ExprId("sp") -CST1 = ExprInt32(0x11) -CST2 = ExprInt32(0x12) -CST3 = ExprInt32(0x13) +CST1 = ExprInt(0x11, 32) +CST2 = ExprInt(0x12, 32) +CST3 = ExprInt(0x13, 32) LBL0 = AsmLabel("lbl0") LBL1 = AsmLabel("lbl1") diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index 24095c7b..005ab32c 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -1,6 +1,5 @@ """Regression test module for DependencyGraph""" -from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprCond, \ - ExprInt +from miasm2.expression.expression import ExprId, ExprInt, ExprAff, ExprCond from miasm2.core.asmblock import AsmLabel from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock @@ -31,16 +30,16 @@ D_INIT = ExprId("d_init") PC = ExprId("pc") SP = ExprId("sp") -CST0 = ExprInt32(0x0) -CST1 = ExprInt32(0x1) -CST2 = ExprInt32(0x2) -CST3 = ExprInt32(0x3) -CST22 = ExprInt32(0x22) -CST23 = ExprInt32(0x23) -CST24 = ExprInt32(0x24) -CST33 = ExprInt32(0x33) -CST35 = ExprInt32(0x35) -CST37 = ExprInt32(0x37) +CST0 = ExprInt(0x0, 32) +CST1 = ExprInt(0x1, 32) +CST2 = ExprInt(0x2, 32) +CST3 = ExprInt(0x3, 32) +CST22 = ExprInt(0x22, 32) +CST23 = ExprInt(0x23, 32) +CST24 = ExprInt(0x24, 32) +CST33 = ExprInt(0x33, 32) +CST35 = ExprInt(0x35, 32) +CST37 = ExprInt(0x37, 32) LBL0 = AsmLabel("lbl0") LBL1 = AsmLabel("lbl1") diff --git a/test/analysis/range.py b/test/analysis/range.py index 4cc27f2c..8b1224f9 100644 --- a/test/analysis/range.py +++ b/test/analysis/range.py @@ -11,62 +11,62 @@ for expr in [ a, b, b[4:6], - a + ExprInt8(4), - ExprInt8(5) + ExprInt8(4), - a.zeroExtend(32) + ExprInt32(0x100), - (a.zeroExtend(32) * ExprInt32(3)) + ExprInt32(0x100), - (a.zeroExtend(32) + ExprInt32(0x80)) * ExprInt32(3), - ExprCond(b, a.zeroExtend(32) + ExprInt32(0x100), - a.zeroExtend(32) + ExprInt32(0x500)), - ExprCond(b[1:2], a.zeroExtend(32), a.zeroExtend(32) + ExprInt32(0x1000)) + \ - ExprCond(b[0:1], a.zeroExtend(32) + ExprInt32(0x5000), a.zeroExtend(32) + ExprInt32(0x10000)), + a + ExprInt(4, 8), + ExprInt(5, 8) + ExprInt(4, 8), + a.zeroExtend(32) + ExprInt(0x100, 32), + (a.zeroExtend(32) * ExprInt(3, 32)) + ExprInt(0x100, 32), + (a.zeroExtend(32) + ExprInt(0x80, 32)) * ExprInt(3, 32), + ExprCond(b, a.zeroExtend(32) + ExprInt(0x100, 32), + a.zeroExtend(32) + ExprInt(0x500, 32)), + ExprCond(b[1:2], a.zeroExtend(32), a.zeroExtend(32) + ExprInt(0x1000, 32)) + \ + ExprCond(b[0:1], a.zeroExtend(32) + ExprInt(0x5000, 32), a.zeroExtend(32) + ExprInt(0x10000, 32)), - a, - - ExprInt8(4), - b[:8].zeroExtend(16) - ExprInt16(4), - a[4:6].zeroExtend(32) + ExprInt32(-1), - a >> ExprInt8(4), - a << ExprInt8(4), - ExprOp("a>>", a, ExprInt8(4)), - ExprInt8(4) >> a, - ExprInt8(4) << a, - ExprOp("a>>", ExprInt8(4), a), + - ExprInt(4, 8), + b[:8].zeroExtend(16) - ExprInt(4, 16), + a[4:6].zeroExtend(32) + ExprInt(-1, 32), + a >> ExprInt(4, 8), + a << ExprInt(4, 8), + ExprOp("a>>", a, ExprInt(4, 8)), + ExprInt(4, 8) >> a, + ExprInt(4, 8) << a, + ExprOp("a>>", ExprInt(4, 8), a), a >> a, a << a, ExprOp("a>>", a, a), - ExprInt8(4) >> ExprCond(b[0:1], ExprInt8(1), ExprInt8(10)), - ExprInt8(4) << ExprCond(b[0:1], ExprInt8(1), ExprInt8(10)), - ExprOp("a>>", ExprInt8(4), ExprCond(b[0:1], ExprInt8(1), ExprInt8(10))), - a | ExprInt8(4), + ExprInt(4, 8) >> ExprCond(b[0:1], ExprInt(1, 8), ExprInt(10, 8)), + ExprInt(4, 8) << ExprCond(b[0:1], ExprInt(1, 8), ExprInt(10, 8)), + ExprOp("a>>", ExprInt(4, 8), ExprCond(b[0:1], ExprInt(1, 8), ExprInt(10, 8))), + a | ExprInt(4, 8), a[3:5] | a[6:8], - ExprInt8(0) | a, - ExprInt8(0xF) | ExprInt8(0xC), - ExprCond(a[0:1], ExprInt8(5), ExprInt8(18)) | a[5:7].zeroExtend(8), - a & ExprInt8(4), + ExprInt(0, 8) | a, + ExprInt(0xF, 8) | ExprInt(0xC, 8), + ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8)) | a[5:7].zeroExtend(8), + a & ExprInt(4, 8), a[3:5] & a[6:8], - ExprInt8(8) & a, - ExprInt8(0xF) & ExprInt8(0xC), - ExprCond(a[0:1], ExprInt8(5), ExprInt8(18)) & (a[4:7].zeroExtend(8) << ExprInt8(2)), - a ^ ExprInt8(4), + ExprInt(8, 8) & a, + ExprInt(0xF, 8) & ExprInt(0xC, 8), + ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8)) & (a[4:7].zeroExtend(8) << ExprInt(2, 8)), + a ^ ExprInt(4, 8), a[3:5] ^ a[6:8], - ExprInt8(0xF) ^ a, - ExprInt8(0xF) ^ ExprInt8(0xC), - ExprCond(a[0:1], ExprInt8(5), ExprInt8(18)) ^ (a[4:7].zeroExtend(8) << ExprInt8(2)), - a % ExprInt8(8), - ExprInt8(33) % ExprInt8(8), + ExprInt(0xF, 8) ^ a, + ExprInt(0xF, 8) ^ ExprInt(0xC, 8), + ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8)) ^ (a[4:7].zeroExtend(8) << ExprInt(2, 8)), + a % ExprInt(8, 8), + ExprInt(33, 8) % ExprInt(8, 8), a % a, - a[:2].zeroExtend(8) + ExprInt8(0xF) % ExprCond(a[0:1], ExprInt8(5), ExprInt8(18)), - ExprOp("<<<", ExprInt8(4), ExprInt8(1)), - ExprOp("<<<", ExprInt8(4), ExprInt8(14)), - ExprOp("<<<", ExprInt8(4), a), - ExprOp("<<<", a, ExprInt8(4)), + a[:2].zeroExtend(8) + ExprInt(0xF, 8) % ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8)), + ExprOp("<<<", ExprInt(4, 8), ExprInt(1, 8)), + ExprOp("<<<", ExprInt(4, 8), ExprInt(14, 8)), + ExprOp("<<<", ExprInt(4, 8), a), + ExprOp("<<<", a, ExprInt(4, 8)), ExprOp("<<<", a, a), - ExprOp("<<<", a[1:2].zeroExtend(8) + ExprInt8(1), ExprCond(a[0:1], ExprInt8(5), ExprInt8(18))), - ExprOp(">>>", ExprInt8(4), ExprInt8(1)), - ExprOp(">>>", ExprInt8(4), ExprInt8(14)), - ExprOp(">>>", ExprInt8(4), a), - ExprOp(">>>", a, ExprInt8(4)), + ExprOp("<<<", a[1:2].zeroExtend(8) + ExprInt(1, 8), ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8))), + ExprOp(">>>", ExprInt(4, 8), ExprInt(1, 8)), + ExprOp(">>>", ExprInt(4, 8), ExprInt(14, 8)), + ExprOp(">>>", ExprInt(4, 8), a), + ExprOp(">>>", a, ExprInt(4, 8)), ExprOp(">>>", a, a), - ExprOp(">>>", a[1:2].zeroExtend(8) + ExprInt8(1), ExprCond(a[0:1], ExprInt8(5), ExprInt8(18))), + ExprOp(">>>", a[1:2].zeroExtend(8) + ExprInt(1, 8), ExprCond(a[0:1], ExprInt(5, 8), ExprInt(18, 8))), # Fuzzed by ExprRandom, with previous bug ExprSlice(ExprSlice(ExprOp('<<<', ExprInt(0x7FBE84D6, 51), ExprId('WYBZj', 51)), 6, 48), 3, 35), diff --git a/test/expression/expression.py b/test/expression/expression.py index 8e8b5e07..ac145a04 100644 --- a/test/expression/expression.py +++ b/test/expression/expression.py @@ -6,8 +6,8 @@ from miasm2.expression.expression import * from miasm2.expression.expression_helper import * # Expression comparison -assert(ExprInt64(-1) != ExprInt64(-2)) -assert(ExprInt64(1) != ExprInt32(1)) +assert(ExprInt(-1, 64) != ExprInt(-2, 64)) +assert(ExprInt(1, 64) != ExprInt(1, 32)) # Expression size big_cst = ExprInt(1, size=0x1000) @@ -18,10 +18,10 @@ assert big_cst.size == 0x1000 A = ExprId("A") cond1 = ExprId("cond1", 1) cond2 = ExprId("cond2", 16) -cst1 = ExprInt32(1) -cst2 = ExprInt32(2) -cst3 = ExprInt32(3) -cst4 = ExprInt32(4) +cst1 = ExprInt(1, 32) +cst2 = ExprInt(2, 32) +cst3 = ExprInt(3, 32) +cst4 = ExprInt(4, 32) #- Launch tests for expr in [ diff --git a/test/expression/expression_helper.py b/test/expression/expression_helper.py index 6c800020..a4c221e9 100755 --- a/test/expression/expression_helper.py +++ b/test/expression/expression_helper.py @@ -11,7 +11,7 @@ class TestExpressionExpressionHelper(unittest.TestCase): from miasm2.expression.expression_helper import Variables_Identifier # Build a complex expression - cst = m2_expr.ExprInt16(0x100) + cst = m2_expr.ExprInt(0x100, 16) eax = m2_expr.ExprId("EAX") ebx = m2_expr.ExprId("EBX") ax = eax[0:16] @@ -62,7 +62,7 @@ class TestExpressionExpressionHelper(unittest.TestCase): ## Corner case: each sub var depends on itself mem1 = m2_expr.ExprMem(ebx, size=32) mem2 = m2_expr.ExprMem(mem1, size=32) - cst2 = m2_expr.ExprInt32(-1) + cst2 = m2_expr.ExprInt(-1, 32) expr_mini = ((eax ^ mem2 ^ cst2) & (mem2 ^ (eax + mem2)))[31:32] ## Build diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 5391fbee..d4553495 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -32,23 +32,23 @@ l = [a[:8], b[:8], c[:8], m[:8], s, i1[:8], i2[:8], o[:8]] l2 = l[::-1] -x = ExprMem(a + b + ExprInt32(0x42)) +x = ExprMem(a + b + ExprInt(0x42, 32)) # Define tests: (expression to simplify, expected value) -to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), - ((ExprInt32(5) + c + a + b - a + ExprInt32(1) - ExprInt32(5)), - ExprOp('+', b, c, ExprInt32(1))), +to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), + ((ExprInt(5, 32) + c + a + b - a + ExprInt(1, 32) - ExprInt(5, 32)), + ExprOp('+', b, c, ExprInt(1, 32))), (a + b + c - a - b - c + a, a), (a + a + b + c - (a + (b + c)), a), (c ^ b ^ a ^ c ^ b, a), - (a ^ ExprInt32(0), a), + (a ^ ExprInt(0, 32), a), ((a + b) - b, a), - (-(ExprInt32(0) - ((a + b) - b)), a), + (-(ExprInt(0, 32) - ((a + b) - b)), a), - (ExprOp('<<<', a, ExprInt32(32)), a), - (ExprOp('>>>', a, ExprInt32(32)), a), - (ExprOp('>>>', a, ExprInt32(0)), a), - (ExprOp('<<', a, ExprInt32(0)), a), + (ExprOp('<<<', a, ExprInt(32, 32)), a), + (ExprOp('>>>', a, ExprInt(32, 32)), a), + (ExprOp('>>>', a, ExprInt(0, 32)), a), + (ExprOp('<<', a, ExprInt(0, 32)), a), (ExprOp('<<<', a, ExprOp('<<<', b, c)), ExprOp('<<<', a, ExprOp('<<<', b, c))), @@ -60,31 +60,31 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), ExprOp('<<<', a, (b-c))), (ExprOp('>>>', ExprOp('<<<', a, b), b), a), - (ExprOp(">>>", ExprInt16(0x1000), ExprInt16(0x11)), - ExprInt16(0x800)), - (ExprOp("<<<", ExprInt16(0x1000), ExprInt16(0x11)), - ExprInt16(0x2000)), - - (ExprOp('>>>', ExprOp('<<<', a, ExprInt32(10)), ExprInt32(2)), - ExprOp('<<<', a, ExprInt32(8))), - - (ExprOp('>>>', ExprOp('<<<', a, ExprInt32(10)), ExprInt32(2)) ^ ExprOp('>>>', ExprOp('<<<', a, ExprInt32(10)), ExprInt32(2)), - ExprInt32(0)), - (ExprOp(">>", (a & ExprInt32(0xF)), ExprInt32(0x15)), - ExprInt32(0)), - (ExprOp(">>", (ExprInt32(0x12345678)), ExprInt32(0x4)), - ExprInt32(0x1234567)), - (ExprOp("a>>", (ExprInt32(0x12345678)), ExprInt32(0x4)), - ExprInt32(0x1234567)), - (ExprOp("a>>", (ExprInt32(0xF1234567)), ExprInt32(0x4)), - ExprInt32(0xFF123456)), - (ExprOp("a>>", (ExprInt32(0xF1234567)), ExprInt32(28)), - ExprInt32(0xFFFFFFFF)), - (ExprOp("parity", ExprInt32(0xf)), ExprInt1(1)), - (ExprOp("parity", ExprInt32(0xe)), ExprInt1(0)), - (ExprInt32(0x4142)[:32], ExprInt32(0x4142)), - (ExprInt32(0x4142)[:8], ExprInt8(0x42)), - (ExprInt32(0x4142)[8:16], ExprInt8(0x41)), + (ExprOp(">>>", ExprInt(0x1000, 16), ExprInt(0x11, 16)), + ExprInt(0x800, 16)), + (ExprOp("<<<", ExprInt(0x1000, 16), ExprInt(0x11, 16)), + ExprInt(0x2000, 16)), + + (ExprOp('>>>', ExprOp('<<<', a, ExprInt(10, 32)), ExprInt(2, 32)), + ExprOp('<<<', a, ExprInt(8, 32))), + + (ExprOp('>>>', ExprOp('<<<', a, ExprInt(10, 32)), ExprInt(2, 32)) ^ ExprOp('>>>', ExprOp('<<<', a, ExprInt(10, 32)), ExprInt(2, 32)), + ExprInt(0, 32)), + (ExprOp(">>", (a & ExprInt(0xF, 32)), ExprInt(0x15, 32)), + ExprInt(0, 32)), + (ExprOp(">>", (ExprInt(0x12345678, 32)), ExprInt(0x4, 32)), + ExprInt(0x1234567, 32)), + (ExprOp("a>>", (ExprInt(0x12345678, 32)), ExprInt(0x4, 32)), + ExprInt(0x1234567, 32)), + (ExprOp("a>>", (ExprInt(0xF1234567, 32)), ExprInt(0x4, 32)), + ExprInt(0xFF123456, 32)), + (ExprOp("a>>", (ExprInt(0xF1234567, 32)), ExprInt(28, 32)), + ExprInt(0xFFFFFFFF, 32)), + (ExprOp("parity", ExprInt(0xf, 32)), ExprInt(1, 1)), + (ExprOp("parity", ExprInt(0xe, 32)), ExprInt(0, 1)), + (ExprInt(0x4142, 32)[:32], ExprInt(0x4142, 32)), + (ExprInt(0x4142, 32)[:8], ExprInt(0x42, 8)), + (ExprInt(0x4142, 32)[8:16], ExprInt(0x41, 8)), (a[:32], a), (a[:8][:8], a[:8]), (a[:16][:8], a[:8]), @@ -100,59 +100,59 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (ExprMem(a)[:32], ExprMem(a)), (ExprMem(a)[:16], ExprMem(a, size=16)), - (ExprCond(ExprInt32(1), a, b), a), - (ExprCond(ExprInt32(0), b, a), a), + (ExprCond(ExprInt(1, 32), a, b), a), + (ExprCond(ExprInt(0, 32), b, a), a), - (ExprInt32(0x80000000)[31:32], ExprInt1(1)), - (ExprCompose(ExprInt16(0x1337)[:8], ExprInt16(0x1337)[8:16]), - ExprInt16(0x1337)), + (ExprInt(0x80000000, 32)[31:32], ExprInt(1, 1)), + (ExprCompose(ExprInt(0x1337, 16)[:8], ExprInt(0x1337, 16)[8:16]), + ExprInt(0x1337, 16)), - (ExprCompose(ExprInt32(0x1337beef)[:8], - ExprInt32(0x1337beef)[8:16], - ExprInt32(0x1337beef)[16:32]), - ExprInt32(0x1337BEEF)), + (ExprCompose(ExprInt(0x1337beef, 32)[:8], + ExprInt(0x1337beef, 32)[8:16], + ExprInt(0x1337beef, 32)[16:32]), + ExprInt(0x1337BEEF, 32)), (ExprCond(a, ExprCond(a, b, c), d), ExprCond(a, b, d)), - ((a & b & ExprInt32(0x12))[31:32], ExprInt1(0)), + ((a & b & ExprInt(0x12, 32))[31:32], ExprInt(0, 1)), (ExprCompose( - ExprCond(a, ExprInt16(0x10), ExprInt16(0x20)), - ExprInt16(0x1337)), - ExprCond(a, ExprInt32(0x13370010), ExprInt32(0x13370020))), - (ExprCond(ExprCond(a, ExprInt1(0), ExprInt1(1)), b, c), + ExprCond(a, ExprInt(0x10, 16), ExprInt(0x20, 16)), + ExprInt(0x1337, 16)), + ExprCond(a, ExprInt(0x13370010, 32), ExprInt(0x13370020, 32))), + (ExprCond(ExprCond(a, ExprInt(0, 1), ExprInt(1, 1)), b, c), ExprCond(a, c, b)), - (ExprCond(a, ExprInt32(0x10), ExprInt32(0x20)) + ExprInt32(0x13370000), - ExprCond(a, ExprInt32(0x13370010), ExprInt32(0x13370020))), - - (ExprCond(a, ExprInt32(0x10), ExprInt32(0x20)) + ExprCond(a, ExprInt32(0x13370000), ExprInt32(0x13380000)), - ExprCond(a, ExprInt32(0x13370010), ExprInt32(0x13380020))), - (-ExprCond(a, ExprInt32(0x1), ExprInt32(0x2)), - ExprCond(a, ExprInt32(-0x1), ExprInt32(-0x2))), - (ExprOp('*', a, b, c, ExprInt32(0x12))[0:17], + (ExprCond(a, ExprInt(0x10, 32), ExprInt(0x20, 32)) + ExprInt(0x13370000, 32), + ExprCond(a, ExprInt(0x13370010, 32), ExprInt(0x13370020, 32))), + + (ExprCond(a, ExprInt(0x10, 32), ExprInt(0x20, 32)) + ExprCond(a, ExprInt(0x13370000, 32), ExprInt(0x13380000, 32)), + ExprCond(a, ExprInt(0x13370010, 32), ExprInt(0x13380020, 32))), + (-ExprCond(a, ExprInt(0x1, 32), ExprInt(0x2, 32)), + ExprCond(a, ExprInt(-0x1, 32), ExprInt(-0x2, 32))), + (ExprOp('*', a, b, c, ExprInt(0x12, 32))[0:17], ExprOp( '*', a[0:17], b[0:17], c[0:17], ExprInt(0x12, 17))), - (ExprOp('*', a, ExprInt32(0xffffffff)), + (ExprOp('*', a, ExprInt(0xffffffff, 32)), -a), - (ExprOp('*', -a, -b, c, ExprInt32(0x12)), - 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), - ExprCond(a, ExprInt32(4), ExprInt32(8))), + (ExprOp('*', -a, -b, c, ExprInt(0x12, 32)), + ExprOp('*', a, b, c, ExprInt(0x12, 32))), + (ExprOp('*', -a, -b, -c, ExprInt(0x12, 32)), + - ExprOp('*', a, b, c, ExprInt(0x12, 32))), + (ExprOp('**', ExprInt(2, 32), ExprInt(8, 32)), ExprInt(0x100, 32)), + (ExprInt(2, 32)**ExprInt(8, 32), ExprInt(256, 32)), + (a | ExprInt(0xffffffff, 32), + ExprInt(0xffffffff, 32)), + (ExprCond(a, ExprInt(1, 32), ExprInt(2, 32)) * ExprInt(4, 32), + ExprCond(a, ExprInt(4, 32), ExprInt(8, 32))), (ExprCond(a, b, c) + ExprCond(a, d, e), ExprCond(a, b + d, c + e)), (ExprCond(a, b, c) * ExprCond(a, d, e), ExprCond(a, b * d, c * e)), - (ExprCond(a, ExprInt32(8), ExprInt32(4)) >> ExprInt32(1), - ExprCond(a, ExprInt32(4), ExprInt32(2))), + (ExprCond(a, ExprInt(8, 32), ExprInt(4, 32)) >> ExprInt(1, 32), + ExprCond(a, ExprInt(4, 32), ExprInt(2, 32))), (ExprCond(a, b, c) >> ExprCond(a, d, e), ExprCond(a, b >> d, c >> e)), @@ -160,52 +160,52 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (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)), - - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x20), - ExprCompose(ExprInt32(0), a)), - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x10), - ExprCompose(ExprInt16(0), a, ExprInt16(0))), - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x30), + (ExprOp('-', ExprInt(1, 8), ExprInt(0, 8)), + ExprInt(1, 8)), + + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x20, 64), + ExprCompose(ExprInt(0, 32), a)), + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x10, 64), + ExprCompose(ExprInt(0, 16), a, ExprInt(0, 16))), + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x30, 64), ExprCompose(ExprInt(0, 48), a[:0x10])), - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x11), + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x11, 64), ExprCompose(ExprInt(0, 0x11), a, ExprInt(0, 0xF))), - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x40), - ExprInt64(0)), - (ExprCompose(a, ExprInt32(0)) << ExprInt64(0x50), - ExprInt64(0)), - - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x20), - ExprCompose(a, ExprInt32(0))), - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x10), - ExprCompose(ExprInt16(0), a, ExprInt16(0))), - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x30), + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x40, 64), + ExprInt(0, 64)), + (ExprCompose(a, ExprInt(0, 32)) << ExprInt(0x50, 64), + ExprInt(0, 64)), + + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x20, 64), + ExprCompose(a, ExprInt(0, 32))), + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x10, 64), + ExprCompose(ExprInt(0, 16), a, ExprInt(0, 16))), + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x30, 64), ExprCompose(a[0x10:], ExprInt(0, 48))), - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x11), + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x11, 64), ExprCompose(ExprInt(0, 0xf), a, ExprInt(0, 0x11))), - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x40), - ExprInt64(0)), - (ExprCompose(ExprInt32(0), a) >> ExprInt64(0x50), - ExprInt64(0)), + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x40, 64), + ExprInt(0, 64)), + (ExprCompose(ExprInt(0, 32), a) >> ExprInt(0x50, 64), + ExprInt(0, 64)), - (ExprCompose(a, b) << ExprInt64(0x20), - ExprCompose(ExprInt32(0), a)), - (ExprCompose(a, b) << ExprInt64(0x10), - ExprCompose(ExprInt16(0), a, b[:16])), + (ExprCompose(a, b) << ExprInt(0x20, 64), + ExprCompose(ExprInt(0, 32), a)), + (ExprCompose(a, b) << ExprInt(0x10, 64), + ExprCompose(ExprInt(0, 16), a, b[:16])), (ExprCompose(a, b) | ExprCompose(c, d), ExprCompose(a|c, b|d)), - (ExprCompose(a, ExprInt32(0)) | ExprCompose(ExprInt32(0), d), + (ExprCompose(a, ExprInt(0, 32)) | ExprCompose(ExprInt(0, 32), d), ExprCompose(a, d)), - (ExprCompose(f[:32], ExprInt32(0)) | ExprCompose(ExprInt32(0), f[32:]), + (ExprCompose(f[:32], ExprInt(0, 32)) | ExprCompose(ExprInt(0, 32), f[32:]), f), - ((ExprCompose(a, ExprInt32(0)) * ExprInt64(0x123))[32:64], - (ExprCompose(a, ExprInt32(0)) * ExprInt64(0x123))[32:64]), + ((ExprCompose(a, ExprInt(0, 32)) * ExprInt(0x123, 64))[32:64], + (ExprCompose(a, ExprInt(0, 32)) * ExprInt(0x123, 64))[32:64]), - (ExprInt32(0x12), - ExprInt32(0x12L)), + (ExprInt(0x12, 32), + ExprInt(0x12L, 32)), (ExprCompose(a, b, c)[:16], @@ -235,13 +235,13 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), & ExprInt(0x1L, 24), ExprInt(0x0L, 40)), - ExprInt64(0)), + ExprInt(0, 64)), (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[:8] & ExprInt(0x1L, 8), (ExprInt(0x0L, 56))), - ExprCompose(a[:8]&ExprInt8(1), ExprInt(0, 56))), + ExprCompose(a[:8]&ExprInt(1, 8), ExprInt(0, 56))), (ExprCompose(ExprCompose(a[:8], ExprInt(0x0L, 56))[:32] @@ -256,63 +256,63 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), ), (ExprCompose(a[:16], b[:16])[8:32], ExprCompose(a[8:16], b[:16])), - ((a >> ExprInt32(16))[:16], + ((a >> ExprInt(16, 32))[:16], a[16:32]), - ((a >> ExprInt32(16))[8:16], + ((a >> ExprInt(16, 32))[8:16], a[24:32]), - ((a << ExprInt32(16))[16:32], + ((a << ExprInt(16, 32))[16:32], a[:16]), - ((a << ExprInt32(16))[24:32], + ((a << ExprInt(16, 32))[24:32], a[8:16]), - (expr_cmpu(ExprInt32(0), ExprInt32(0)), - ExprInt1(0)), - (expr_cmpu(ExprInt32(10), ExprInt32(0)), - ExprInt1(1)), - (expr_cmpu(ExprInt32(10), ExprInt32(5)), - ExprInt1(1)), - (expr_cmpu(ExprInt32(5), ExprInt32(10)), - ExprInt1(0)), - (expr_cmpu(ExprInt32(-1), ExprInt32(0)), - ExprInt1(1)), - (expr_cmpu(ExprInt32(-1), ExprInt32(-1)), - ExprInt1(0)), - (expr_cmpu(ExprInt32(0), ExprInt32(-1)), - ExprInt1(0)), - (expr_cmps(ExprInt32(0), ExprInt32(0)), - ExprInt1(0)), - (expr_cmps(ExprInt32(10), ExprInt32(0)), - ExprInt1(1)), - (expr_cmps(ExprInt32(10), ExprInt32(5)), - ExprInt1(1)), - (expr_cmps(ExprInt32(5), ExprInt32(10)), - ExprInt1(0)), - (expr_cmps(ExprInt32(-1), ExprInt32(0)), - ExprInt1(0)), - (expr_cmps(ExprInt32(-1), ExprInt32(-1)), - ExprInt1(0)), - (expr_cmps(ExprInt32(0), ExprInt32(-1)), - ExprInt1(1)), - (expr_cmps(ExprInt32(-5), ExprInt32(-10)), - ExprInt1(1)), - (expr_cmps(ExprInt32(-10), ExprInt32(-5)), - ExprInt1(0)), + (expr_cmpu(ExprInt(0, 32), ExprInt(0, 32)), + ExprInt(0, 1)), + (expr_cmpu(ExprInt(10, 32), ExprInt(0, 32)), + ExprInt(1, 1)), + (expr_cmpu(ExprInt(10, 32), ExprInt(5, 32)), + ExprInt(1, 1)), + (expr_cmpu(ExprInt(5, 32), ExprInt(10, 32)), + ExprInt(0, 1)), + (expr_cmpu(ExprInt(-1, 32), ExprInt(0, 32)), + ExprInt(1, 1)), + (expr_cmpu(ExprInt(-1, 32), ExprInt(-1, 32)), + ExprInt(0, 1)), + (expr_cmpu(ExprInt(0, 32), ExprInt(-1, 32)), + ExprInt(0, 1)), + (expr_cmps(ExprInt(0, 32), ExprInt(0, 32)), + ExprInt(0, 1)), + (expr_cmps(ExprInt(10, 32), ExprInt(0, 32)), + ExprInt(1, 1)), + (expr_cmps(ExprInt(10, 32), ExprInt(5, 32)), + ExprInt(1, 1)), + (expr_cmps(ExprInt(5, 32), ExprInt(10, 32)), + ExprInt(0, 1)), + (expr_cmps(ExprInt(-1, 32), ExprInt(0, 32)), + ExprInt(0, 1)), + (expr_cmps(ExprInt(-1, 32), ExprInt(-1, 32)), + ExprInt(0, 1)), + (expr_cmps(ExprInt(0, 32), ExprInt(-1, 32)), + ExprInt(1, 1)), + (expr_cmps(ExprInt(-5, 32), ExprInt(-10, 32)), + ExprInt(1, 1)), + (expr_cmps(ExprInt(-10, 32), ExprInt(-5, 32)), + ExprInt(0, 1)), (ExprOp("<<<c_rez", i1, i0, i0), i1), (ExprOp("<<<c_rez", i1, i1, i0), - ExprInt32(2)), + ExprInt(2, 32)), (ExprOp("<<<c_rez", i1, i1, i1), - ExprInt32(3)), + ExprInt(3, 32)), (ExprOp(">>>c_rez", icustom, i0, i0), icustom), (ExprOp(">>>c_rez", icustom, i1, i0), - ExprInt32(0x91A2B3C)), + ExprInt(0x91A2B3C, 32)), (ExprOp(">>>c_rez", icustom, i1, i1), - ExprInt32(0x891A2B3C)), - (ExprOp("idiv", ExprInt16(0x0123), ExprInt16(0xfffb))[:8], - ExprInt8(0xc6)), - (ExprOp("imod", ExprInt16(0x0123), ExprInt16(0xfffb))[:8], - ExprInt8(0x01)), + ExprInt(0x891A2B3C, 32)), + (ExprOp("idiv", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], + ExprInt(0xc6, 8)), + (ExprOp("imod", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], + ExprInt(0x01, 8)), ] @@ -334,21 +334,21 @@ to_test = [ ExprOp_inf_signed(a, b)), ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b).msb(), ExprOp_inf_unsigned(a, b)), - (ExprOp_inf_unsigned(ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), - (ExprOp_inf_signed(ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), + (ExprOp_inf_unsigned(ExprInt(-1, 32), ExprInt(3, 32)), ExprInt(0, 1)), + (ExprOp_inf_signed(ExprInt(-1, 32), ExprInt(3, 32)), ExprInt(1, 1)), (ExprOp_inf_unsigned(a, b) ^ (a ^ b).msb(), ExprOp_inf_signed(a, b)), (ExprOp_inf_signed(a, b) ^ (a ^ b).msb(), ExprOp_inf_unsigned(a, b)), - (ExprOp_equal(ExprInt32(12), ExprInt32(10)), ExprInt1(0)), - (ExprOp_equal(ExprInt32(12), ExprInt32(12)), ExprInt1(1)), - (ExprOp_equal(ExprInt32(12), ExprInt32(-12)), ExprInt1(0)), - (ExprCond(a - b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, b)), - (ExprCond(a + b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, -b)), - (ExprOp_inf_signed(ExprInt32(-2), ExprInt32(3)), ExprInt1(1)), - (ExprOp_inf_signed(ExprInt32(3), ExprInt32(-3)), ExprInt1(0)), - (ExprOp_inf_signed(ExprInt32(2), ExprInt32(3)), ExprInt1(1)), - (ExprOp_inf_signed(ExprInt32(-3), ExprInt32(-2)), ExprInt1(1)), - (ExprOp_inf_signed(ExprInt32(0), ExprInt32(2)), ExprInt1(1)), - (ExprOp_inf_signed(ExprInt32(-3), ExprInt32(0)), ExprInt1(1)), + (ExprOp_equal(ExprInt(12, 32), ExprInt(10, 32)), ExprInt(0, 1)), + (ExprOp_equal(ExprInt(12, 32), ExprInt(12, 32)), ExprInt(1, 1)), + (ExprOp_equal(ExprInt(12, 32), ExprInt(-12, 32)), ExprInt(0, 1)), + (ExprCond(a - b, ExprInt(0, 1), ExprInt(1, 1)), ExprOp_equal(a, b)), + (ExprCond(a + b, ExprInt(0, 1), ExprInt(1, 1)), ExprOp_equal(a, -b)), + (ExprOp_inf_signed(ExprInt(-2, 32), ExprInt(3, 32)), ExprInt(1, 1)), + (ExprOp_inf_signed(ExprInt(3, 32), ExprInt(-3, 32)), ExprInt(0, 1)), + (ExprOp_inf_signed(ExprInt(2, 32), ExprInt(3, 32)), ExprInt(1, 1)), + (ExprOp_inf_signed(ExprInt(-3, 32), ExprInt(-2, 32)), ExprInt(1, 1)), + (ExprOp_inf_signed(ExprInt(0, 32), ExprInt(2, 32)), ExprInt(1, 1)), + (ExprOp_inf_signed(ExprInt(-3, 32), ExprInt(0, 32)), ExprInt(1, 1)), ] expr_simp_cond = ExpressionSimplifier() @@ -382,18 +382,18 @@ jrb = ExprId('jrb') jrint1 = ExprId('jrint1') -e1 = ExprMem((a & ExprInt32(0xFFFFFFFC)) + ExprInt32(0x10), 32) -e2 = ExprMem((a & ExprInt32(0xFFFFFFFC)) + b, 32) +e1 = ExprMem((a & ExprInt(0xFFFFFFFC, 32)) + ExprInt(0x10, 32), 32) +e2 = ExprMem((a & ExprInt(0xFFFFFFFC, 32)) + b, 32) e3 = (a ^ b ^ ((a ^ b) & (b ^ (b - a))) ^ (b - a)).canonize() match_tests = [ - (MatchExpr(ExprInt32(12), a, [a]), {a: ExprInt32(12)}), + (MatchExpr(ExprInt(12, 32), a, [a]), {a: ExprInt(12, 32)}), (MatchExpr(x, a, [a]), {a: x}), (MatchExpr(x + y, a, [a]), {a: x + y}), (MatchExpr(x + y, a + y, [a]), {a: x}), (MatchExpr(x + y, x + a, [a]), {a: y}), (MatchExpr(x + y, a + b, [a, b]), {a: x, b: y}), - (MatchExpr(x + ExprInt32(12), a + b, [a, b]), {a: x, b: ExprInt32(12)}), + (MatchExpr(x + ExprInt(12, 32), a + b, [a, b]), {a: x, b: ExprInt(12, 32)}), (MatchExpr(ExprMem(x), a, [a]), {a: ExprMem(x)}), (MatchExpr(ExprMem(x), ExprMem(a), [a]), {a: x}), (MatchExpr(x[0:8], a, [a]), {a: x[0:8]}), @@ -407,7 +407,7 @@ match_tests = [ (MatchExpr(ExprCompose(x[:8], y[:8]), ExprCompose(a[:8], b[:8]), [a, b]), {a: x, b: y}), - (MatchExpr(e1, e2, [b]), {b: ExprInt32(0x10)}), + (MatchExpr(e1, e2, [b]), {b: ExprInt(0x10, 32)}), (MatchExpr(e3, (((jra ^ jrb) & (jrb ^ jrint1)) ^ jra ^ jrb ^ jrint1).canonize(), diff --git a/test/expression/stp.py b/test/expression/stp.py index b911a2a4..a4b037de 100755 --- a/test/expression/stp.py +++ b/test/expression/stp.py @@ -7,9 +7,9 @@ import unittest class TestIrIr2STP(unittest.TestCase): def test_ExprOp_strcst(self): - from miasm2.expression.expression import ExprInt32, ExprOp + from miasm2.expression.expression import ExprInt, ExprOp import miasm2.expression.stp # /!\ REALLY DIRTY HACK - args = [ExprInt32(i) for i in xrange(9)] + args = [ExprInt(i, 32) for i in xrange(9)] self.assertEqual( ExprOp('|', *args[:2]).strcst(), r'(0bin00000000000000000000000000000000 | 0bin00000000000000000000000000000001)') @@ -20,9 +20,9 @@ class TestIrIr2STP(unittest.TestCase): self.assertRaises(ValueError, ExprOp('X', *args[:1]).strcst) def test_ExprSlice_strcst(self): - from miasm2.expression.expression import ExprInt32, ExprSlice + from miasm2.expression.expression import ExprInt, ExprSlice import miasm2.expression.stp # /!\ REALLY DIRTY HACK - args = [ExprInt32(i) for i in xrange(9)] + args = [ExprInt(i, 32) for i in xrange(9)] self.assertEqual( args[0][1:2].strcst(), r'(0bin00000000000000000000000000000000)[1:1]') diff --git a/test/ir/ir2C.py b/test/ir/ir2C.py index 395703ed..a966938b 100755 --- a/test/ir/ir2C.py +++ b/test/ir/ir2C.py @@ -13,10 +13,10 @@ class TestIrIr2C(unittest.TestCase): self.assertEqual(translator.from_expr(expr), expected) def test_ExprOp_toC(self): - from miasm2.expression.expression import ExprInt32, ExprOp + from miasm2.expression.expression import ExprInt, ExprOp from miasm2.ir.translators.C import Translator - args = [ExprInt32(i) for i in xrange(9)] + args = [ExprInt(i, 32) for i in xrange(9)] translator = Translator.to_language("C") # Unary operators diff --git a/test/ir/symbexec.py b/test/ir/symbexec.py index 48de6573..bd28c4ee 100755 --- a/test/ir/symbexec.py +++ b/test/ir/symbexec.py @@ -7,20 +7,20 @@ import unittest class TestSymbExec(unittest.TestCase): def test_ClassDef(self): - from miasm2.expression.expression import ExprInt32, ExprId, ExprMem, \ + from miasm2.expression.expression import ExprInt, ExprId, ExprMem, \ ExprCompose, ExprAff from miasm2.arch.x86.sem import ir_x86_32 from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.ir.ir import AssignBlock - addrX = ExprInt32(-1) - addr0 = ExprInt32(0) - addr1 = ExprInt32(1) - addr8 = ExprInt32(8) - addr9 = ExprInt32(9) - addr20 = ExprInt32(20) - addr40 = ExprInt32(40) - addr50 = ExprInt32(50) + addrX = ExprInt(-1, 32) + addr0 = ExprInt(0, 32) + addr1 = ExprInt(1, 32) + addr8 = ExprInt(8, 32) + addr9 = ExprInt(9, 32) + addr20 = ExprInt(20, 32) + addr40 = ExprInt(40, 32) + addr50 = ExprInt(50, 32) mem0 = ExprMem(addr0) mem1 = ExprMem(addr1, 8) mem8 = ExprMem(addr8) @@ -44,18 +44,18 @@ class TestSymbExec(unittest.TestCase): self.assertEqual(e.eval_expr(ExprMem(addr1 - addr1)), id_x) self.assertEqual(e.eval_expr(ExprMem(addr1, 8)), id_y) self.assertEqual(e.eval_expr(ExprMem(addr1 + addr1)), ExprCompose( - id_x[16:32], ExprMem(ExprInt32(4), 16))) + id_x[16:32], ExprMem(ExprInt(4, 32), 16))) self.assertEqual(e.eval_expr(mem8), ExprCompose( - id_x[0:24], ExprMem(ExprInt32(11), 8))) + id_x[0:24], ExprMem(ExprInt(11, 32), 8))) self.assertEqual(e.eval_expr(mem40v), id_x[:8]) self.assertEqual(e.eval_expr(mem50w), ExprCompose( - id_y, ExprMem(ExprInt32(51), 8))) + id_y, ExprMem(ExprInt(51, 32), 8))) self.assertEqual(e.eval_expr(mem20), mem20) e.func_read = lambda x: x self.assertEqual(e.eval_expr(mem20), mem20) self.assertEqual(set(e.modified()), set(e.symbols)) self.assertRaises( - KeyError, e.symbols.__getitem__, ExprMem(ExprInt32(100))) + KeyError, e.symbols.__getitem__, ExprMem(ExprInt(100, 32))) self.assertEqual(e.apply_expr(id_eax), addr0) self.assertEqual(e.apply_expr(ExprAff(id_eax, addr9)), addr9) self.assertEqual(e.apply_expr(id_eax), addr9) diff --git a/test/ir/translators/smt2.py b/test/ir/translators/smt2.py index 97877a3b..838b0bc5 100644 --- a/test/ir/translators/smt2.py +++ b/test/ir/translators/smt2.py @@ -14,10 +14,10 @@ left = ExprCond(e + ExprOp('parity', a), ExprMem(a * a, 64), ExprMem(a, 64)) -cond = ExprSlice(ExprSlice(ExprSlice(a, 0, 32) + b, 0, 16) * c, 0, 8) << ExprOp('>>>', d, ExprInt(uint8(0x5L))) +cond = ExprSlice(ExprSlice(ExprSlice(a, 0, 32) + b, 0, 16) * c, 0, 8) << ExprOp('>>>', d, ExprInt(0x5L, 8)) right = ExprCond(cond, - a + ExprInt(uint64(0x64L)), - ExprInt(uint64(0x16L))) + a + ExprInt(0x64L, 64), + ExprInt(0x16L, 64)) e = ExprAff(left, right) diff --git a/test/ir/translators/z3_ir.py b/test/ir/translators/z3_ir.py index 0251c2fe..83744786 100644 --- a/test/ir/translators/z3_ir.py +++ b/test/ir/translators/z3_ir.py @@ -60,8 +60,8 @@ z3_e = z3.BitVec('x', 32) assert equiv(ez3, z3_e) # -------------------------------------------------------------------------- -four = ExprInt32(4) -five = ExprInt32(5) +four = ExprInt(4, 32) +five = ExprInt(5, 32) e2 = (e + five + four) * five ez3 = Translator.to_language('z3').from_expr(e2) @@ -71,9 +71,9 @@ z3_e2 = (z3_e + z3_five + z3_four) * z3_five assert equiv(ez3, z3_e2) # -------------------------------------------------------------------------- -emem = ExprMem(ExprInt32(0xdeadbeef), size=32) -emem2 = ExprMem(ExprInt32(0xfee1dead), size=32) -e3 = (emem + e) * ExprInt32(2) * emem2 +emem = ExprMem(ExprInt(0xdeadbeef, 32), size=32) +emem2 = ExprMem(ExprInt(0xfee1dead, 32), size=32) +e3 = (emem + e) * ExprInt(2, 32) * emem2 ez3 = Translator.to_language('z3').from_expr(e3) mem = Z3Mem() @@ -122,8 +122,8 @@ assert equiv(ez3, z3_e5) # -------------------------------------------------------------------------- # Parity -seven = ExprInt32(7) -one0seven = ExprInt32(0x107) +seven = ExprInt(7, 32) +one0seven = ExprInt(0x107, 32) for miasm_int, res in [(five, 1), (four, 0), (seven, 0), (one0seven, 0)]: e6 = ExprOp('parity', miasm_int) ez3 = Translator.to_language('z3').from_expr(e6) diff --git a/test/jitter/jitload.py b/test/jitter/jitload.py index 544e9d18..dff1f0d6 100644 --- a/test/jitter/jitload.py +++ b/test/jitter/jitload.py @@ -3,8 +3,7 @@ from pdb import pm from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE from miasm2.analysis.machine import Machine -from miasm2.expression.expression import ExprId, ExprInt32, ExprInt64, ExprAff, \ - ExprMem +from miasm2.expression.expression import ExprId, ExprAff, ExprInt, ExprMem # Initial data: from 'example/samples/x86_32_sc.bin' data = "8d49048d5b0180f90174058d5bffeb038d5b0189d8c3".decode("hex") @@ -38,8 +37,8 @@ assert myjit.cpu.ECX == 4 # Check eval_expr eax = ExprId("RAX", 64)[:32] -imm0, imm4, imm4_64 = ExprInt32(0), ExprInt32(4), ExprInt64(4) -memdata = ExprMem(ExprInt32(run_addr), len(data) * 8) +imm0, imm4, imm4_64 = ExprInt(0, 32), ExprInt(4, 32), ExprInt(4, 64) +memdata = ExprMem(ExprInt(run_addr, 32), len(data) * 8) assert myjit.eval_expr(eax) == imm0 ## Due to ExprAff construction, imm4 is "promoted" to imm4_64 assert myjit.eval_expr(ExprAff(eax, imm4)) == imm4_64 |