diff options
Diffstat (limited to 'miasm2/jitter')
| -rw-r--r-- | miasm2/jitter/arch/JitCore_x86.c | 8 | ||||
| -rw-r--r-- | miasm2/jitter/codegen.py | 6 | ||||
| -rw-r--r-- | miasm2/jitter/csts.py | 1 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore_python.py | 23 |
4 files changed, 24 insertions, 14 deletions
diff --git a/miasm2/jitter/arch/JitCore_x86.c b/miasm2/jitter/arch/JitCore_x86.c index 0b788071..94729b90 100644 --- a/miasm2/jitter/arch/JitCore_x86.c +++ b/miasm2/jitter/arch/JitCore_x86.c @@ -57,6 +57,8 @@ reg_dict gpreg_dict[] = { {.name = "RAX", .offset = offsetof(vm_cpu_t, RAX)}, {.name = "tsc1", .offset = offsetof(vm_cpu_t, tsc1)}, {.name = "tsc2", .offset = offsetof(vm_cpu_t, tsc2)}, + {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags)}, + {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num)}, }; @@ -521,6 +523,9 @@ getset_reg_u64(MM7); getset_reg_u32(tsc1); getset_reg_u32(tsc2); +getset_reg_u32(exception_flags); +getset_reg_u32(interrupt_num); + PyObject* get_gpreg_offset_all(void) { @@ -674,6 +679,9 @@ static PyGetSetDef JitCpu_getseters[] = { {"tsc1", (getter)JitCpu_get_tsc1, (setter)JitCpu_set_tsc1, "tsc1", NULL}, {"tsc2", (getter)JitCpu_get_tsc2, (setter)JitCpu_set_tsc2, "tsc2", NULL}, + {"exception_flags", (getter)JitCpu_get_exception_flags, (setter)JitCpu_set_exception_flags, "exception_flags", NULL}, + {"interrupt_num", (getter)JitCpu_get_interrupt_num, (setter)JitCpu_set_interrupt_num, "interrupt_num", NULL}, + {NULL} /* Sentinel */ }; diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py index 7630a2ef..c5f28b9f 100644 --- a/miasm2/jitter/codegen.py +++ b/miasm2/jitter/codegen.py @@ -307,14 +307,10 @@ class CGen(object): return ("%s" % dst2index[label], "0") - elif (isinstance(expr, m2_expr.ExprId) or - isinstance(expr, m2_expr.ExprMem) or - isinstance(expr, m2_expr.ExprSlice)): + else: dst2index[expr] = -1 return ("-1", self.id_to_c(expr)) - else: - raise RuntimeError("Unsupported IRDst type %s" % expr) def gen_assignblk_dst(self, dst): dst2index = {} diff --git a/miasm2/jitter/csts.py b/miasm2/jitter/csts.py index 7af2435f..95cd34a8 100644 --- a/miasm2/jitter/csts.py +++ b/miasm2/jitter/csts.py @@ -4,6 +4,7 @@ # VM Mngr Exceptions EXCEPT_DO_NOT_UPDATE_PC = 1 << 25 +EXCEPT_NUM_UPDT_EIP = (1<<11) EXCEPT_CODE_AUTOMOD = (1 << 0) EXCEPT_SOFT_BP = (1 << 1) diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index ae72b307..87259f71 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -1,7 +1,7 @@ import miasm2.jitter.jitcore as jitcore import miasm2.expression.expression as m2_expr import miasm2.jitter.csts as csts -from miasm2.expression.simplifications import expr_simp +from miasm2.expression.simplifications import ExpressionSimplifier from miasm2.jitter.emulatedsymbexec import EmulatedSymbExec @@ -17,8 +17,11 @@ class JitCore_Python(jitcore.JitCore): super(JitCore_Python, self).__init__(ir_arch, bs) self.ir_arch = ir_arch - # CPU & VM (None for now) will be set by the "jitted" Python function - self.symbexec = EmulatedSymbExec(None, None, self.ir_arch, {}) + # CPU & VM (None for now) will be set later + expr_simp = ExpressionSimplifier() + expr_simp.enable_passes(ExpressionSimplifier.PASS_COMMONS) + self.symbexec = EmulatedSymbExec(None, None, self.ir_arch, {}, + sb_expr_simp=expr_simp) self.symbexec.enable_emulated_simplifications() def set_cpu_vm(self, cpu, vm): @@ -49,6 +52,7 @@ class JitCore_Python(jitcore.JitCore): # Get exec engine exec_engine = self.symbexec + expr_simp = exec_engine.expr_simp # For each irbloc inside irblocs while True: @@ -87,17 +91,18 @@ class JitCore_Python(jitcore.JitCore): if self.log_mn: print "%08x %s" % (line.offset, line) - # Check for memory exception - if (vmmngr.get_exception() != 0): + # Check for exception + if (vmmngr.get_exception() != 0 or + cpu.get_exception() != 0): exec_engine.update_cpu_from_engine() return line.offset # Eval current instruction (in IR) exec_engine.eval_ir(ir) - - # Check for memory exception which do not update PC - if (vmmngr.get_exception() & csts.EXCEPT_DO_NOT_UPDATE_PC != 0): - exec_engine.update_cpu_from_engine() + # Check for exceptions which do not update PC + exec_engine.update_cpu_from_engine() + if (vmmngr.get_exception() & csts.EXCEPT_DO_NOT_UPDATE_PC != 0 or + cpu.get_exception() > csts.EXCEPT_NUM_UPDT_EIP): return line.offset vmmngr.check_invalid_code_blocs() |