diff options
Diffstat (limited to 'miasm2/jitter/jitcore_python.py')
| -rw-r--r-- | miasm2/jitter/jitcore_python.py | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index 799848ab..61bd98d0 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -4,7 +4,6 @@ import miasm2.jitter.csts as csts from miasm2.expression.simplifications import ExpressionSimplifier from miasm2.jitter.emulatedsymbexec import EmulatedSymbExec - ################################################################################ # Python jitter Core # ################################################################################ @@ -15,15 +14,19 @@ class JitCore_Python(jitcore.JitCore): SymbExecClass = EmulatedSymbExec - def __init__(self, ir_arch, bs=None): - super(JitCore_Python, self).__init__(ir_arch, bs) + def __init__(self, ir_arch, bin_stream): + super(JitCore_Python, self).__init__(ir_arch, bin_stream) self.ir_arch = ir_arch + self.ircfg = self.ir_arch.new_ircfg() # CPU & VM (None for now) will be set later expr_simp = ExpressionSimplifier() expr_simp.enable_passes(ExpressionSimplifier.PASS_COMMONS) - self.symbexec = self.SymbExecClass(None, None, self.ir_arch, {}, - sb_expr_simp=expr_simp) + self.symbexec = self.SymbExecClass( + None, None, + self.ir_arch, {}, + sb_expr_simp=expr_simp + ) self.symbexec.enable_emulated_simplifications() def set_cpu_vm(self, cpu, vm): @@ -34,10 +37,10 @@ class JitCore_Python(jitcore.JitCore): "Preload symbols according to current architecture" self.symbexec.reset_regs() - def jitirblocs(self, label, irblocks): + def jit_irblocks(self, loc_key, irblocks): """Create a python function corresponding to an irblocks' group. - @label: the label of the irblocks - @irblocks: a gorup of irblocks + @loc_key: the loc_key of the irblocks + @irblocks: a group of irblocks """ def myfunc(cpu): @@ -48,7 +51,7 @@ class JitCore_Python(jitcore.JitCore): vmmngr = cpu.vmmngr # Keep current location in irblocks - cur_label = label + cur_loc_key = loc_key # Required to detect new instructions offsets_jitted = set() @@ -57,13 +60,14 @@ class JitCore_Python(jitcore.JitCore): exec_engine = self.symbexec expr_simp = exec_engine.expr_simp + known_loc_keys = set(irb.loc_key for irb in irblocks) # For each irbloc inside irblocks while True: - # Get the current bloc for irb in irblocks: - if irb.label == cur_label: + if irb.loc_key == cur_loc_key: break + else: raise RuntimeError("Irblocks must end with returning an " "ExprInt instance") @@ -75,7 +79,7 @@ class JitCore_Python(jitcore.JitCore): for assignblk in irb: instr = assignblk.instr # For each new instruction (in assembly) - if instr.offset not in offsets_jitted: + if instr is not None and instr.offset not in offsets_jitted: # Test exceptions vmmngr.check_invalid_code_blocs() vmmngr.check_memory_breakpoint() @@ -120,23 +124,25 @@ class JitCore_Python(jitcore.JitCore): # Manage resulting address if isinstance(ad, m2_expr.ExprInt): return ad.arg.arg - elif isinstance(ad, m2_expr.ExprId): - cur_label = ad.name + elif isinstance(ad, m2_expr.ExprLoc): + cur_loc_key = ad.loc_key else: raise NotImplementedError("Type not handled: %s" % ad) - # Associate myfunc with current label - self.lbl2jitbloc[label.offset] = myfunc + # Associate myfunc with current loc_key + offset = self.ir_arch.loc_db.get_location_offset(loc_key) + assert offset is not None + self.offset_to_jitted_func[offset] = myfunc - def exec_wrapper(self, label, cpu, _lbl2jitbloc, _breakpoints, + def exec_wrapper(self, loc_key, cpu, _offset_to_jitted_func, _stop_offsets, _max_exec_per_call): - """Call the function @label with @cpu - @label: function's label + """Call the function @loc_key with @cpu + @loc_key: function's loc_key @cpu: JitCpu instance """ - # Get Python function corresponding to @label - fc_ptr = self.lbl2jitbloc[label] + # Get Python function corresponding to @loc_key + fc_ptr = self.offset_to_jitted_func[loc_key] # Execute the function return fc_ptr(cpu) |