Example #1
0
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)
Example #2
0
	def __call__(self):
		target_pid = -1

		if idaapi.is_debugger_on():
			idaapi.msg("[%s] the debugger is currently running\n" % PLUGNAME)
			return -1

		if not self.times%5:
			idaapi.msg("[%s] waiting for the process (%ds left)...\n" % \
				(PLUGNAME, self.times))

		filename = ida_nalt.get_root_filename()
		pis = ida_idd.procinfo_vec_t()
		ida_dbg.get_processes(pis)

		for proc in pis:
			proc_name = proc.name.split(" ")[1]
			idx = proc_name.rfind("/")

			if idx != -1:
				proc_name = proc_name[idx+1:]

			if filename == proc_name:
				target_pid = proc.pid
				break

		if target_pid != -1:
			idaapi.msg("[%s] found. start debug (PID: %d)\n" % (PLUGNAME, target_pid))
			ida_dbg.attach_process(target_pid, -1)
			ida_dbg.wait_for_next_event(ida_dbg.WFNE_SUSP, -1)
			ida_dbg.continue_process()
			return -1

		self.times -= 1
		return -1 if self.times == 0 else self.interval
Example #3
0
	def prepare_debug_ui(self):
		if idaapi.is_debugger_on():
			idaapi.warning("[%s] the debugger is currently running" % PLUGNAME)
			return

		wd = WaitDialog()
		idaapi.msg("[%s] waiting...\n" % (PLUGNAME))
		wd.thread.start()
		wd.exec_()

		target_pid = wd.get_target_pid()
		if target_pid != -1:
			ida_dbg.attach_process(target_pid,-1)
			ida_dbg.wait_for_next_event(ida_dbg.WFNE_SUSP, -1)
			ida_dbg.continue_process()
		else:
			idaapi.msg("[%s] exit waiting\n" % (PLUGNAME))
Example #4
0
def RESimClient():
    #Wait()
    ida_dbg.wait_for_next_event(idc.WFNE_ANY, -1)
    print('back from dbg wait')
    reg_list = idautils.GetRegisterList()
    kernel_base = 0xc0000000
    info = idaapi.get_inf_structure()
    if info.is_64bit():
        print('64-bit')
        kernel_base = 0xFFFFFFFF00000000
    else:
        print('32-bit')
    idc.refresh_lists()
    idc.auto_wait()

    bookmark_view = bookmarkView.bookmarkView()
    stack_trace = stackTrace.StackTrace()
    data_watch = dataWatch.DataWatch()
    branch_not_taken = branchNotTaken.BranchNotTaken()
    write_watch = writeWatch.WriteWatch()
    #print('back from init bookmarkView')
    keymap_done = False
    #primePump()
    #nameSysCalls(True)
    #print('back from nameSysCalls')
    #print('now create bookmark_view')
    isim = idaSIM.IdaSIM(stack_trace, bookmark_view, data_watch,
                         branch_not_taken, write_watch, kernel_base, reg_list)

    idaversion.grab_focus('Stack view')
    bm_title = "Bookmarks"
    bookmark_view.Create(isim, bm_title)
    idaversion.grab_focus(bm_title)
    bookmark_view.register()
    bookmark_list = bookmark_view.updateBookmarkView()
    if bookmark_list is not None:
        for bm in bookmark_list:
            if 'nox' in bm:
                eip_str = getTagValue(bm, 'nox')
                eip = int(eip_str, 16)
                idc.MakeCode(eip)

    idaversion.grab_focus(bm_title)
    st_title = 'stack trace'
    stack_trace.Create(isim, st_title)
    idaversion.grab_focus(st_title)
    stack_trace.register()

    idaversion.grab_focus(st_title)
    dw_title = 'data watch'
    data_watch.Create(isim, dw_title)
    idaversion.grab_focus(dw_title)
    data_watch.register()

    bnt_title = 'BNT'
    idaversion.grab_focus(dw_title)
    branch_not_taken.Create(isim, bnt_title)
    idaversion.grab_focus(bnt_title)
    branch_not_taken.register()
    #branch_not_taken.updateList()

    idaversion.grab_focus(bnt_title)
    ww_title = 'write watch'
    write_watch.Create(isim, ww_title)
    idaversion.grab_focus(ww_title)
    write_watch.register()

    reHooks.register(isim)
    re_hooks = reHooks.Hooks()
    re_hooks.hook()

    dbg_hooks = dbgHooks.DBGHooks(isim)
    dbg_hooks.hook()

    #form=idaversion.find_widget("IDA View-EIP")
    #idaversion.activate_widget(form, True)
    #print('IDA View-EIP form is %s' % str(form))
    # MakeCode(eip)
    '''
    run_to_connect_desc = idaapi.action_desc_t(
        'run_to_connect:action',   # The action name. This acts like an ID and must be unique
        'Run to connect',  # The action text.
        RunToConnectHandler())   # The action handler.

    idaapi.register_action(run_to_connect_desc)

    idaapi.attach_action_to_menu(
        'Debugger/O Run to/', # The relative path of where to add the action
        'run_to_connect:action',                        # The action ID (see above)
        idaapi.SETMENU_APP)                 # We want to append the action after the 'Manual instruction...'
    '''

    if not keymap_done:
        doKeyMap(isim)
        print('dbg %r' % idaapi.dbg_is_loaded())

        isim.showSimicsMessage()

        idaversion.refresh_debugger_memory()
    #checkHelp()
    isim.recordText()
    isim.showSimicsMessage()
    if not isim.just_debug:
        # first origin is sometimes off, call twice.
        #goToOrigin()
        pass
    idaversion.batch(0)
    #isim.resynch()
    print('IDA SDK VERSION: %d' % idaapi.IDA_SDK_VERSION)
    print('RESim Ida Client Version 1.2')
Example #5
0
def wait_for_next_event(kind, flag):
    if idaapi.IDA_SDK_VERSION <= 699:
        event = idc.GetDebuggerEvent(kind, flag)
    else:
        event = ida_dbg.wait_for_next_event(kind, flag)