13 """Updates @cpu instance according to new CPU values
15 @exec_engine: symbexec instance"""
17 for symbol
in exec_engine.symbols:
18 if isinstance(symbol, m2_expr.ExprId):
19 if hasattr(cpu, symbol.name):
20 value = exec_engine.symbols.symbols_id[symbol]
21 if not isinstance(value, m2_expr.ExprInt):
22 raise ValueError(
"A simplification is missing: %s" % value)
24 setattr(cpu, symbol.name, value.arg.arg)
26 raise NotImplementedError(
"Type not handled: %s" % symbol)
30 """Updates CPU values according to @cpu instance
32 @exec_engine: symbexec instance"""
34 for symbol
in exec_engine.symbols:
35 if isinstance(symbol, m2_expr.ExprId):
36 if hasattr(cpu, symbol.name):
37 value = m2_expr.ExprInt(getattr(cpu, symbol.name),
39 exec_engine.symbols.symbols_id[symbol] = value
41 raise NotImplementedError(
"Type not handled: %s" % symbol)
50 "JiT management, using Miasm2 Symbol Execution engine as backend"
53 super(JitCore_Python, self).
__init__(ir_arch, bs)
58 "Preload symbols according to current architecture"
61 for r
in self.ir_arch.arch.regs.all_regs_ids_no_alias:
62 symbols_init[r] = self.ir_arch.arch.regs.regs_init[r]
69 """Memory read wrapper for symbolic execution
72 addr = expr_mem.arg.arg.arg
73 size = expr_mem.size / 8
74 value = self.cpu.get_mem(addr, size)
76 return m2_expr.ExprInt(int(value[::-1].encode(
"hex"), 16),
80 """Memory read wrapper for symbolic execution
81 @symb_exec: symbexec instance
82 @dest: ExprMem instance
88 if not isinstance(data, m2_expr.ExprInt):
89 raise NotImplementedError(
"A simplification is missing: %s" % data)
90 to_write = data.arg.arg
93 addr = dest.arg.arg.arg
95 content = hex(to_write).replace(
"0x",
"").replace(
"L",
"")
96 content =
"0" * (size * 2 - len(content)) + content
97 content = content.decode(
"hex")[::-1]
100 self.cpu.set_mem(addr, content)
103 """Create a python function corresponding to an irblocs' group.
104 @label: the label of the irblocs
105 @irblocs: a gorup of irblocs
108 def myfunc(cpu, vmmngr):
109 """Execute the function according to cpu and vmmngr states
110 @cpu: JitCpu instance
119 offsets_jitted = set()
130 if irb.label == cur_label:
135 assert(loop
is not False)
141 for ir, line
in zip(irb.irs, irb.lines):
144 if line.offset
not in offsets_jitted:
145 offsets_jitted.add(line.offset)
154 print "%08x %s" % (line.offset, line)
157 if (vmmngr.get_exception() != 0):
162 exec_engine.eval_ir(ir)
165 if (vmmngr.get_exception() & csts.EXCEPT_DO_NOT_UPDATE_PC != 0):
170 ad =
expr_simp(exec_engine.eval_expr(self.ir_arch.IRDst))
176 if isinstance(ad, m2_expr.ExprInt):
178 elif isinstance(ad, m2_expr.ExprId):
181 raise NotImplementedError(
"Type not handled: %s" % ad)
186 def jit_call(self, label, cpu, vmmngr, _breakpoints):
187 """Call the function label with cpu and vmmngr states
188 @label: function's label
189 @cpu: JitCpu instance
199 return fc_ptr(cpu, vmmngr)
def update_engine_from_cpu
def update_cpu_from_engine
Util methods for Python jitter #.