(args)
| 52 | ) |
| 53 | |
| 54 | def 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 | |
| 104 | if __name__ == '__main__': |
| 105 | pwnlib.commandline.common.main(__file__, main) |
nothing calls this directly
no test coverage detected