• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 11306103413

12 Oct 2024 01:37PM CUT coverage: 74.245%. First build
11306103413

Pull #2486

github

web-flow
Merge ebc37cbe2 into 78dd77773
Pull Request #2486: Test Python version >= 3.10 in CI and fix tests on Python 3.12

3678 of 6140 branches covered (59.9%)

20 of 34 new or added lines in 22 files covered. (58.82%)

12972 of 17472 relevant lines covered (74.24%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/pwnlib/commandline/debug.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import argparse
1✔
5
import sys
1✔
6

7
from pwn import *
1✔
8
from pwnlib.commandline import common
1✔
9

10
parser = common.parser_commands.add_parser(
1✔
11
    'debug',
12
    help = 'Debug a binary in GDB',
13
    description = 'Debug a binary in GDB'
14
)
15
parser.add_argument(
1✔
16
    '-x', metavar='GDBSCRIPT',
17
    type=argparse.FileType('r'),
18
    help='Execute GDB commands from this file.'
19
)
20
parser.add_argument(
1✔
21
    '--pid',
22
    type=int,
23
    help="PID to attach to"
24
)
25
parser.add_argument(
1✔
26
    '-c', '--context',
27
    metavar = 'context',
28
    action = 'append',
29
    type   = common.context_arg,
30
    choices = common.choices,
31
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
32
)
33
parser.add_argument(
1✔
34
    '--exec',
35

36
    # NOTE: Type cannot be "file" because we may be referring to a remote
37
    #       file, or a file on an Android device.
38
    type=str,
39

40
    dest='executable',
41
    help='File to debug'
42
)
43
parser.add_argument(
1✔
44
    '--process', metavar='PROCESS_NAME',
45
    help='Name of the process to attach to (e.g. "bash")'
46
)
47
parser.add_argument(
1✔
48
    '--sysroot', metavar='SYSROOT',
49
    type=str,
50
    default='',
51
    help="GDB sysroot path"
52
)
53

54
def main(args):
1✔
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__':
1!
NEW
105
    pwnlib.commandline.common.main(__file__, main)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc