From f5aa0474bd7ea8078bacf0085ff6942d1cf3bc42 Mon Sep 17 00:00:00 2001 From: Ajax Date: Fri, 22 Jun 2018 17:08:14 +0200 Subject: Jitcore: remove useless strucs and rename for more meaningful names --- miasm2/jitter/jitcore_python.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'miasm2/jitter/jitcore_python.py') diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index 785e3fa1..1f753b07 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -15,8 +15,8 @@ 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 # CPU & VM (None for now) will be set later @@ -34,10 +34,10 @@ class JitCore_Python(jitcore.JitCore): "Preload symbols according to current architecture" self.symbexec.reset_regs() - def jitirblocs(self, loc_key, irblocks): + def jit_irblocks(self, loc_key, irblocks): """Create a python function corresponding to an irblocks' group. @loc_key: the loc_key of the irblocks - @irblocks: a gorup of irblocks + @irblocks: a group of irblocks """ def myfunc(cpu): @@ -129,9 +129,9 @@ class JitCore_Python(jitcore.JitCore): # Associate myfunc with current loc_key offset = self.ir_arch.symbol_pool.loc_key_to_offset(loc_key) assert offset is not None - self.loc_key_to_jit_block[offset] = myfunc + self.offset_to_jitted_func[offset] = myfunc - def exec_wrapper(self, loc_key, cpu, _loc_key_to_jit_block, _breakpoints, + def exec_wrapper(self, loc_key, cpu, _offset_to_jitted_func, _breakpoints, _max_exec_per_call): """Call the function @loc_key with @cpu @loc_key: function's loc_key @@ -139,7 +139,7 @@ class JitCore_Python(jitcore.JitCore): """ # Get Python function corresponding to @loc_key - fc_ptr = self.loc_key_to_jit_block[loc_key] + fc_ptr = self.offset_to_jitted_func[loc_key] # Execute the function return fc_ptr(cpu) -- cgit 1.4.1 From c33f2d988bda28a1b6dbe5a2c8bceb5819db9e42 Mon Sep 17 00:00:00 2001 From: Ajax Date: Fri, 22 Jun 2018 17:27:30 +0200 Subject: Jitcore: run_at actually takes a list of stop_offset, instead of a "breakpoints" specificity --- miasm2/jitter/Jitgcc.c | 8 ++++---- miasm2/jitter/Jitllvm.c | 8 ++++---- miasm2/jitter/jitcore.py | 15 +++++++++++---- miasm2/jitter/jitcore_python.py | 2 +- miasm2/jitter/jitload.py | 5 ++++- 5 files changed, 24 insertions(+), 14 deletions(-) (limited to 'miasm2/jitter/jitcore_python.py') diff --git a/miasm2/jitter/Jitgcc.c b/miasm2/jitter/Jitgcc.c index 6273627a..329b7db4 100644 --- a/miasm2/jitter/Jitgcc.c +++ b/miasm2/jitter/Jitgcc.c @@ -16,7 +16,7 @@ PyObject* gcc_exec_block(PyObject* self, PyObject* args) PyObject* jitcpu; PyObject* func_py; PyObject* lbl2ptr; - PyObject* breakpoints; + PyObject* stop_offsets; PyObject* retaddr = NULL; int status; block_id BlockDst; @@ -26,7 +26,7 @@ PyObject* gcc_exec_block(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "OOOO|K", - &retaddr, &jitcpu, &lbl2ptr, &breakpoints, + &retaddr, &jitcpu, &lbl2ptr, &stop_offsets, &max_exec_per_call)) return NULL; @@ -73,8 +73,8 @@ PyObject* gcc_exec_block(PyObject* self, PyObject* args) if (status) return retaddr; - // Check breakpoint - if (PyDict_Contains(breakpoints, retaddr)) + // Check stop offsets + if (PySet_Contains(stop_offsets, retaddr)) return retaddr; } } diff --git a/miasm2/jitter/Jitllvm.c b/miasm2/jitter/Jitllvm.c index 325e6606..6ecbd483 100644 --- a/miasm2/jitter/Jitllvm.c +++ b/miasm2/jitter/Jitllvm.c @@ -20,14 +20,14 @@ PyObject* llvm_exec_block(PyObject* self, PyObject* args) uint8_t status; PyObject* func_py; PyObject* lbl2ptr; - PyObject* breakpoints; + PyObject* stop_offsets; PyObject* retaddr = NULL; uint64_t max_exec_per_call = 0; uint64_t cpt; int do_cpt; if (!PyArg_ParseTuple(args, "OOOO|K", - &retaddr, &jitcpu, &lbl2ptr, &breakpoints, + &retaddr, &jitcpu, &lbl2ptr, &stop_offsets, &max_exec_per_call)) return NULL; @@ -68,8 +68,8 @@ PyObject* llvm_exec_block(PyObject* self, PyObject* args) if (status) return retaddr; - // Check breakpoint - if (PyDict_Contains(breakpoints, retaddr)) + // Check stop offsets + if (PySet_Contains(stop_offsets, retaddr)) return retaddr; } } diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 77defa30..b636782d 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -166,10 +166,16 @@ class JitCore(object): self.add_block_to_mem_interval(vm, cur_block) return cur_block - def run_at(self, cpu, offset, breakpoints): - """Run from the starting address @offset + def run_at(self, cpu, offset, stop_offsets): + """Run from the starting address @offset. + Execution will stop if: + - max_exec_per_call option is reached + - a new, yet unknown, block is reached after the execution of block at + address @offset + - an address in @stop_offsets is reached @cpu: JitCpu instance - @offset: target offset + @offset: starting address (int) + @stop_offsets: set of address on which the jitter must stop """ if offset is None: @@ -189,7 +195,8 @@ class JitCore(object): return offset # Run the block and update cpu/vmmngr state - return self.exec_wrapper(offset, cpu, self.offset_to_jitted_func.data, breakpoints, + return self.exec_wrapper(offset, cpu, self.offset_to_jitted_func.data, + stop_offsets, self.options["max_exec_per_call"]) def blocks_to_memrange(self, blocks): diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index 1f753b07..45b418b5 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -131,7 +131,7 @@ class JitCore_Python(jitcore.JitCore): assert offset is not None self.offset_to_jitted_func[offset] = myfunc - def exec_wrapper(self, loc_key, cpu, _offset_to_jitted_func, _breakpoints, + def exec_wrapper(self, loc_key, cpu, _offset_to_jitted_func, _stop_offsets, _max_exec_per_call): """Call the function @loc_key with @cpu @loc_key: function's loc_key diff --git a/miasm2/jitter/jitload.py b/miasm2/jitter/jitload.py index 097826bf..5f8b4ad6 100644 --- a/miasm2/jitter/jitload.py +++ b/miasm2/jitter/jitload.py @@ -307,7 +307,10 @@ class Jitter(object): """Wrapper on JiT backend. Run the code at PC and return the next PC. @pc: address of code to run""" - return self.jit.run_at(self.cpu, pc, self.breakpoints_handler.callbacks) + return self.jit.run_at( + self.cpu, pc, + set(self.breakpoints_handler.callbacks.keys()) + ) def runiter_once(self, pc): """Iterator on callbacks results on code running from PC. -- cgit 1.4.1