about summary refs log tree commit diff stats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--miasm/jitter/jitload.py16
-rw-r--r--test/jitter/mem_breakpoint.py3
-rw-r--r--test/jitter/test_post_instr.py3
3 files changed, 19 insertions, 3 deletions
diff --git a/miasm/jitter/jitload.py b/miasm/jitter/jitload.py
index 6f3af033..49c74254 100644
--- a/miasm/jitter/jitload.py
+++ b/miasm/jitter/jitload.py
@@ -173,6 +173,18 @@ class ExceptionHandle(object):
         return not self.__eq__(to_cmp)
 
 
+class JitterException(Exception):
+
+    "Raised when any unhandled exception occurs (in jitter.vm or jitter.cpu)"
+
+    def __init__(self, exception_flag):
+        super(JitterException, self).__init__()
+        self.exception_flag = exception_flag
+
+    def __str__(self):
+        return "A jitter exception occurred (0x%x)" % (self.exception_flag)
+
+
 class Jitter(object):
 
     "Main class for JIT handling"
@@ -374,7 +386,9 @@ class Jitter(object):
             return
 
         # Exceptions should never be activated before run
-        assert(self.get_exception() == 0)
+        exception_flag = self.get_exception()
+        if exception_flag:
+            raise JitterException(exception_flag)
 
         # Run the block at PC
         self.pc = self.run_at(self.pc)
diff --git a/test/jitter/mem_breakpoint.py b/test/jitter/mem_breakpoint.py
index 8a5d69c5..bd51e692 100644
--- a/test/jitter/mem_breakpoint.py
+++ b/test/jitter/mem_breakpoint.py
@@ -6,6 +6,7 @@ from miasm.analysis.machine import Machine
 from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, \
     EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL
 from miasm.core.locationdb import LocationDB
+from miasm.jitter.jitload import JitterException
 
 def mem_breakpoint_handler(jitter):
     print("======")
@@ -79,6 +80,6 @@ jitter.init_run(0xFFFFFF800901EBEC)
 
 try:
     jitter.continue_run()
-except AssertionError:
+except JitterException:
     assert jitter.vm.get_exception() == EXCEPT_ACCESS_VIOL
 
diff --git a/test/jitter/test_post_instr.py b/test/jitter/test_post_instr.py
index 16e51830..5a690e6b 100644
--- a/test/jitter/test_post_instr.py
+++ b/test/jitter/test_post_instr.py
@@ -6,6 +6,7 @@ from miasm.analysis.machine import Machine
 from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, \
     EXCEPT_BREAKPOINT_MEMORY, EXCEPT_ACCESS_VIOL
 from miasm.core.locationdb import LocationDB
+from miasm.jitter.jitload import JitterException
 
 machine = Machine("x86_32")
 loc_db = LocationDB()
@@ -45,5 +46,5 @@ jitter.vm.add_memory_breakpoint(0x11000-4, 4, PAGE_READ | PAGE_WRITE)
 jitter.init_run(0x1000)
 try:
     jitter.continue_run()
-except AssertionError:
+except JitterException:
     assert jitter.vm.get_exception() == EXCEPT_ACCESS_VIOL