diff options
| -rw-r--r-- | example/jitter/unpack_upx.py | 3 | ||||
| -rw-r--r-- | miasm2/analysis/debugging.py | 23 | ||||
| -rw-r--r-- | miasm2/analysis/gdbserver.py | 9 |
3 files changed, 29 insertions, 6 deletions
diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py index 08b733a4..2d0a02ea 100644 --- a/example/jitter/unpack_upx.py +++ b/example/jitter/unpack_upx.py @@ -81,6 +81,9 @@ def update_binary(jitter): sdata = sb.jitter.vm.get_mem(sb.pe.rva2virt(s.addr), s.rawsize) sb.pe.virt[sb.pe.rva2virt(s.addr)] = sdata + # Stop execution + jitter.run = False + return False # Set callbacks sb.jitter.add_breakpoint(end_label, update_binary) diff --git a/miasm2/analysis/debugging.py b/miasm2/analysis/debugging.py index 4e6982b3..3fffbf66 100644 --- a/miasm2/analysis/debugging.py +++ b/miasm2/analysis/debugging.py @@ -22,6 +22,16 @@ class DebugBreakpointSoft(DebugBreakpoint): return "Soft BP @0x%08x" % self.addr +class DebugBreakpointTerminate(DebugBreakpoint): + "Stand for an execution termination" + + def __init__(self, status): + self.status = status + + def __str__(self): + return "Terminate with %s" % self.status + + class DebugBreakpointMemory(DebugBreakpoint): "Stand for memory breakpoint" @@ -131,8 +141,9 @@ class Debugguer(object): self.myjit.jit.log_newbloc = newbloc def handle_exception(self, res): - if res is None: - return + if not res: + # A breakpoint has stopped the execution + return DebugBreakpointTerminate(res) if isinstance(res, DebugBreakpointSoft): print "Breakpoint reached @0x%08x" % res.addr @@ -149,6 +160,9 @@ class Debugguer(object): else: raise NotImplementedError("type res") + # Repropagate res + return res + def step(self): "Step in jit" @@ -165,9 +179,8 @@ class Debugguer(object): return res def run(self): - res = self.myjit.continue_run() - self.handle_exception(res) - return res + status = self.myjit.continue_run() + return self.handle_exception(status) def get_mem(self, addr, size=0xF): "hexdump @addr, size" diff --git a/miasm2/analysis/gdbserver.py b/miasm2/analysis/gdbserver.py index a930cc88..cbc8fe8d 100644 --- a/miasm2/analysis/gdbserver.py +++ b/miasm2/analysis/gdbserver.py @@ -134,7 +134,8 @@ class GdbServer(object): elif msg_type == "k": # Kill self.sock.close() - exit(1) + self.send_queue = [] + self.sock = None elif msg_type == "!": # Extending debugging will be used @@ -245,6 +246,12 @@ class GdbServer(object): self.send_queue.append("S05") else: raise NotImplementedError("Unknown Except") + elif isinstance(ret, debugging.DebugBreakpointTerminate): + # Connexion should close, but keep it running as a TRAP + # The connexion will be close on instance destruction + print ret + self.status = "S05" + self.send_queue.append("S05") else: raise NotImplementedError() |