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

Gallopsled / pwntools / 1

11 Jul 2023 10:24PM UTC coverage: 19.327% (-52.2%) from 71.479%
1

push

github

web-flow
shellcraft: more explicit sleep.asm docstring (#2226)

This commit adds information that the sleep shellcraft function does not check if it returned as part of an interrupt and it does not retry the syscall if this occured.

189 of 5940 branches covered (3.18%)

3286 of 17002 relevant lines covered (19.33%)

0.39 hits per line

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

0.0
/pwnlib/commandline/debug.py
1
#!/usr/bin/env python2
2
from __future__ import absolute_import
×
3
from __future__ import division
×
4

5
import argparse
×
6
import sys
×
7

8
from pwn import *
×
9
from pwnlib.commandline import common
×
10

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

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

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

55
def main(args):
×
56
    gdbscript = ''
×
57
    if args.x:
×
58
        gdbscript = args.x.read()
×
59

60
    if context.os == 'android':
×
61
        context.device = adb.wait_for_device()
×
62

63
    if args.executable:
×
64
        if os.path.exists(args.executable):
×
65
            context.binary = ELF(args.executable)
×
66
            target = context.binary.path
×
67

68
        # This path does nothing, but avoids the "print_usage()"
69
        # path below.
70
        elif context.os == 'android':
×
71
            target = args.executable
×
72
    elif args.pid:
×
73
        target = int(args.pid)
×
74
    elif args.process:
×
75
        if context.os == 'android':
×
76
            target = adb.pidof(args.process)
×
77
        else:
78
            target = pidof(args.process)
×
79

80
        # pidof() returns a list
81
        if not target:
×
82
            log.error("Could not find a PID for %r", args.process)
×
83

84
        target = target[0]
×
85

86
        # pidof will sometimes return all PIDs, including init
87
        if target == 1:
×
88
            log.error("Got PID 1 from pidof.  Check the process name, or use --pid 1 to debug init")
×
89
    else:
90
        parser.print_usage()
×
91
        return 1
×
92

93
    if args.pid or args.process:
×
94
        pid = gdb.attach(target, gdbscript=gdbscript, sysroot=args.sysroot)
×
95

96
        # Since we spawned the gdbserver process, and process registers an
97
        # atexit handler to close itself, gdbserver will be terminated when
98
        # we exit.  This will manifest as a "remote connected ended" or
99
        # similar error message.  Hold it open for the user.
100
        log.info("GDB connection forwarding will terminate when you press enter")
×
101
        pause()
×
102
    else:
103
        gdb.debug(target, gdbscript=gdbscript, sysroot=args.sysroot).interactive()
×
104

105
if __name__ == '__main__':
×
106
    pwnlib.commandline.common.main(__file__)
×
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

© 2026 Coveralls, Inc