diff options
| -rw-r--r-- | miasm/jitter/csts.py | 18 | ||||
| -rw-r--r-- | miasm/jitter/jitload.py | 25 | ||||
| -rw-r--r-- | test/jitter/mem_breakpoint.py | 3 | ||||
| -rw-r--r-- | test/jitter/test_post_instr.py | 3 |
4 files changed, 46 insertions, 3 deletions
diff --git a/miasm/jitter/csts.py b/miasm/jitter/csts.py index 3829ed98..f40cbe74 100644 --- a/miasm/jitter/csts.py +++ b/miasm/jitter/csts.py @@ -21,6 +21,24 @@ EXCEPT_ILLEGAL_INSN = ((1 << 18) | EXCEPT_DO_NOT_UPDATE_PC) EXCEPT_UNK_MNEMO = ((1 << 19) | EXCEPT_DO_NOT_UPDATE_PC) EXCEPT_INT_1 = ((1 << 20) | EXCEPT_DO_NOT_UPDATE_PC) +JitterExceptions = { + "DO_NOT_UPDATE_PC": EXCEPT_DO_NOT_UPDATE_PC, + "NUM_UPDT_EIP": EXCEPT_NUM_UPDT_EIP, + "CODE_AUTOMOD": EXCEPT_CODE_AUTOMOD, + "SOFT_BP": EXCEPT_SOFT_BP, + "INT_XX": EXCEPT_INT_XX, + "SPR_ACCESS": EXCEPT_SPR_ACCESS, + "SYSCALL": EXCEPT_SYSCALL, + "BREAKPOINT_MEMORY": EXCEPT_BREAKPOINT_MEMORY, + "BREAKPOINT_INTERN": EXCEPT_BREAKPOINT_INTERN, + "ACCESS_VIOL": EXCEPT_ACCESS_VIOL, + "DIV_BY_ZERO": EXCEPT_DIV_BY_ZERO, + "PRIV_INSN": EXCEPT_PRIV_INSN, + "ILLEGAL_INSN": EXCEPT_ILLEGAL_INSN, + "UNK_MNEMO": EXCEPT_UNK_MNEMO, + "INT_1": EXCEPT_INT_1, +} + # VM Mngr constants PAGE_READ = 1 diff --git a/miasm/jitter/jitload.py b/miasm/jitter/jitload.py index 6f3af033..34c4d157 100644 --- a/miasm/jitter/jitload.py +++ b/miasm/jitter/jitload.py @@ -173,6 +173,27 @@ 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: %s (0x%x)" % ( + self.exception_flag_to_str(), self.exception_flag + ) + + def exception_flag_to_str(self): + exception_flag_list = [] + for name, value in JitterExceptions.items(): + if value & self.exception_flag == value: + exception_flag_list.append(name) + return ' & '.join(exception_flag_list) + + class Jitter(object): "Main class for JIT handling" @@ -374,7 +395,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 |