From eebb61353ea5dd2036d1db8c3cc4aab6c1cc5662 Mon Sep 17 00:00:00 2001 From: Ajax Date: Fri, 24 Jun 2016 17:19:33 +0200 Subject: Use a local expr_simp, instead of activating simps on global expr_simp --- miasm2/jitter/jitcore_python.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'miasm2/jitter/jitcore_python.py') diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index ae72b307..70131157 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: -- cgit 1.4.1 From 48e3279683c16cb00d7c006b4716781a44d39798 Mon Sep 17 00:00:00 2001 From: Ajax Date: Wed, 29 Jun 2016 08:24:29 +0200 Subject: Handle CPU exception in Jitcore Python This patch may affect performance, but this jitter is already slow (compared to others) and without it, the emulation is not correct --- miasm2/jitter/csts.py | 1 + miasm2/jitter/jitcore_python.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'miasm2/jitter/jitcore_python.py') 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 70131157..87259f71 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -91,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() -- cgit 1.4.1