def simple_debugger(argv): myutil = winapputil.WinAppUtil(cmd=argv) debug = myutil.debug() set_breakpoint(debug, 0x401036, breakpoint_401036) set_breakpoint(debug, 0x40105B, breakpoint_40105B) # Wait for the debugee to finish. debug.loop()
def main(): parser = argparse.ArgumentParser(description="WinAppDbg stuff.") # Make -r and -pid mutually exclusive group = parser.add_mutually_exclusive_group() group.add_argument("-r", "--run", nargs="+", help="path to application followed by parameters") group.add_argument("-pid", "--attach-pid", type=int, dest="pid", help="pid of process to attach and instrument") group.add_argument("-pname", "--attach-process-name", dest="pname", help="pid of process to attach and instrument") parser.add_argument("-i", "--sysinfo", action="store_true", help="print system information") # Add optional log file parser.add_argument("-o", "--output", dest="output", help="log filename") args = parser.parse_args() # Setup logging # https://github.com/MarioVilas/winappdbg/blob/master/winappdbg/textio.py#L1766 global 1 if args.output: # verbose=False disables printing to stdout mylogger = winappdbg.Logger(args.output, verbose=False) else: mylogger = winappdbg.Logger() # Create an instance of our eventhandler class myeventhandler = DebugEvents() if (args.run): try: myutil = winapputil.WinAppUtil(cmd=args.run, eventhandler=myeventhandler, logger=mylogger) debug = myutil.debug() debug.loop() except winapputil.DebugError as error: mylogger.log_text("Exception in %s: %s" % (error.pid_pname, error.msg)) except KeyboardInterrupt: debug.stop() mylogger.log_text("Killed process") elif args.pid: try: myutil = winapputil.WinAppUtil(pid_pname=args.pid, logger=mylogger, eventhandler=myeventhandler, attach=True) debug = myutil.debug() debug.loop() except winapputil.DebugError as error: mylogger.log_text("Exception in %s: %s" % (error.pid_pname, error.msg)) except KeyboardInterrupt: debug.stop() mylogger.log_text("Killed process") elif args.pname: try: myutil = winapputil.WinAppUtil(pid_pname=args.pname, logger=mylogger, eventhandler=myeventhandler, attach=True) debug = myutil.debug() debug.loop() except winapputil.DebugError as error: mylogger.log_text("Exception in %s: %s" % (error.pid_pname, error.msg)) except KeyboardInterrupt: debug.stop() mylogger.log_text("Killed process") elif args.sysinfo: myutil = winapputil.WinAppUtil() print (myutil.sysinfo()) else: myutil = winapputil.WinAppUtil() print (myutil.get_processes()) pass