def do_trace(then_quit_ida=True): debugHook = TraceHook() debugHook.hook() # Start tracing when entry point is hit ep = ida_ida.inf_get_start_ip() ida_dbg.enable_step_trace(1) ida_dbg.set_step_trace_options(ida_dbg.ST_OVER_DEBUG_SEG | ida_dbg.ST_OVER_LIB_FUNC) print("Running to %x" % ep) ida_dbg.run_to(ep) while ida_dbg.get_process_state() != 0: ida_dbg.wait_for_next_event(1, 0) if not debugHook.epReached: raise Exception("Entry point wasn't reached!") if not debugHook.unhook(): raise Exception("Error uninstalling hooks!") del debugHook if then_quit_ida: # we're done; exit IDA ida_pro.qexit(0)
def dbg_run_to(self, pid, tid=0, ea=0): # print("dbg_run_to 0x%x pid=%d" % (ea, pid)) if self.line_trace: ida_dbg.enable_insn_trace(True) ida_dbg.enable_step_trace(True) ida_dbg.request_continue_process() ida_dbg.run_requests()
def dbg_bpt(self, tid, ea): print("Break point at 0x%x tid=%d" % (ea, tid)) if ea in self.end_ea: ida_dbg.enable_insn_trace(False) ida_dbg.enable_step_trace(False) ida_dbg.suspend_process() return 0 return 0
def dbg_bpt(self, tid, ea): print("Break point at 0x%x tid=%d" % (ea, tid)) if (ea == self.start_ea): print("auto suspend_other_thread") suspend_other_thread() ida_dbg.request_clear_trace() ida_dbg.run_requests() ida_dbg.enable_insn_trace(True) ida_dbg.enable_step_trace(True) # if ea in self.end_ea: ida_dbg.enable_insn_trace(False) ida_dbg.enable_step_trace(False) #ida_dbg.suspend_process() print("auto resume_other_thread") resume_other_thread() # return 0
def dbg_trace(self, tid, ea): # print("Trace tid=%d ea=0x%x" % (tid, ea)) # return values: # 1 - do not log this trace event; # 0 - log it if self.line_trace: # if ((base <= ea) and (ea <= (base + size)) ): if base <= ea <= (base + size): in_mine_so = True else: in_mine_so = False self.trace_size += 1 if (not in_mine_so) or (ea in self.skip_functions): if (self.trace_lr != 0) and (self.trace_step_into_count < self.trace_step_into_size): self.trace_step_into_count += 1 return 0 if (self.trace_lr != 0) and (self.trace_step_into_count == self.trace_step_into_size): ida_dbg.enable_insn_trace(False) ida_dbg.enable_step_trace(False) ida_dbg.suspend_process() if self.trace_size > self.trace_total_size: self.trace_size = 0 ida_dbg.request_clear_trace() ida_dbg.run_requests() ida_dbg.request_run_to(self.trace_lr) ida_dbg.run_requests() self.trace_lr = 0 self.trace_step_into_count = 0 return 0 if self.trace_lr == 0: self.trace_lr = my_get_reg_value( "X30") # arm thumb LR arm64 X30 return 0
def dbg_trace(self, tid, ea): #print("Trace tid=%d ea=0x%x" % (tid, ea)) # return values: # 1 - do not log this trace event; # 0 - log it if self.line_trace: in_mine_so = False for module_info in self.modules_info: # print (module_info) so_base = module_info["base"] so_size = module_info["size"] if so_base <= ea <= (so_base + so_size): in_mine_so = True break self.trace_size += 1 if (not in_mine_so) or (ea in self.skip_functions): if (self.trace_lr != 0) and (self.trace_step_into_count < self.trace_step_into_size): self.trace_step_into_count += 1 return 0 if (self.trace_lr != 0) and (self.trace_step_into_count == self.trace_step_into_size): ida_dbg.enable_insn_trace(False) ida_dbg.enable_step_trace(False) ida_dbg.suspend_process() if self.trace_size > self.trace_total_size: self.trace_size = 0 ida_dbg.request_clear_trace() ida_dbg.run_requests() ida_dbg.request_run_to(self.trace_lr & 0xFFFFFFFE) ida_dbg.run_requests() self.trace_lr = 0 self.trace_step_into_count = 0 return 0 if self.trace_lr == 0: self.trace_lr = my_get_reg_value("LR") return 0