MCPcopy
hub / github.com/Gallopsled/pwntools / main

Function main

pwnlib/commandline/debug.py:54–102  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

52)
53
54def main(args):
55 gdbscript = ''
56 if args.x:
57 gdbscript = args.x.read()
58
59 if context.os == 'android':
60 context.device = adb.wait_for_device()
61
62 if args.executable:
63 if os.path.exists(args.executable):
64 context.binary = ELF(args.executable)
65 target = context.binary.path
66
67 # This path does nothing, but avoids the "print_usage()"
68 # path below.
69 elif context.os == 'android':
70 target = args.executable
71 elif args.pid:
72 target = int(args.pid)
73 elif args.process:
74 if context.os == 'android':
75 target = adb.pidof(args.process)
76 else:
77 target = pidof(args.process)
78
79 # pidof() returns a list
80 if not target:
81 log.error("Could not find a PID for %r", args.process)
82
83 target = target[0]
84
85 # pidof will sometimes return all PIDs, including init
86 if target == 1:
87 log.error("Got PID 1 from pidof. Check the process name, or use --pid 1 to debug init")
88 else:
89 parser.print_usage()
90 return 1
91
92 if args.pid or args.process:
93 pid = gdb.attach(target, gdbscript=gdbscript, sysroot=args.sysroot)
94
95 # Since we spawned the gdbserver process, and process registers an
96 # atexit handler to close itself, gdbserver will be terminated when
97 # we exit. This will manifest as a "remote connected ended" or
98 # similar error message. Hold it open for the user.
99 log.info("GDB connection forwarding will terminate when you press enter")
100 pause()
101 else:
102 gdb.debug(target, gdbscript=gdbscript, sysroot=args.sysroot).interactive()
103
104if __name__ == '__main__':
105 pwnlib.commandline.common.main(__file__, main)

Callers

nothing calls this directly

Calls 10

ELFClass · 0.85
pauseFunction · 0.85
wait_for_deviceMethod · 0.80
existsMethod · 0.80
errorMethod · 0.80
infoMethod · 0.80
pidofFunction · 0.50
readMethod · 0.45
interactiveMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected