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

Gallopsled / pwntools / 1a384d573800b95a97d435af0b8458be1c4e6c25

18 Sep 2023 09:52AM UTC coverage: 73.393% (+1.9%) from 71.5%
1a384d573800b95a97d435af0b8458be1c4e6c25

push

github-actions

peace-maker
Fix tube.clean_and_log not logging buffered data

Only new data received after the `clean_and_log` call is printed while
data already received and buffered earlier is not.
Print the buffered data first before waiting for more so we don't miss
anything.

3901 of 6417 branches covered (0.0%)

5 of 5 new or added lines in 1 file covered. (100.0%)

12250 of 16691 relevant lines covered (73.39%)

0.73 hits per line

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

71.15
/pwnlib/commandline/asm.py
1
#!/usr/bin/env python2
2
from __future__ import absolute_import
1✔
3
from __future__ import division
1✔
4

5
import argparse
1✔
6
import sys
1✔
7

8
import pwnlib.args
1✔
9
pwnlib.args.free_form = False
1✔
10

11
from pwn import *
1✔
12
from pwnlib.commandline import common
1✔
13

14
parser = common.parser_commands.add_parser(
1✔
15
    'asm',
16
    help = 'Assemble shellcode into bytes',
17
    description = 'Assemble shellcode into bytes',
18
)
19

20
parser.add_argument(
1✔
21
    'lines',
22
    metavar='line',
23
    nargs='*',
24
    help='Lines to assemble. If none are supplied, use stdin'
25
)
26

27
parser.add_argument(
1✔
28
    "-f", "--format",
29
    help="Output format (defaults to hex for ttys, otherwise raw)",
30
    choices=['raw', 'hex', 'string', 'elf']
31
)
32

33
parser.add_argument(
1✔
34
    "-o","--output",
35
    metavar='file',
36
    help="Output file (defaults to stdout)",
37
    type=argparse.FileType('wb'),
38
    default=getattr(sys.stdout, 'buffer', sys.stdout)
39
)
40

41
parser.add_argument(
1✔
42
    '-c', '--context',
43
    metavar = 'context',
44
    action = 'append',
45
    type   = common.context_arg,
46
    choices = common.choices,
47
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
48
)
49

50
parser.add_argument(
1✔
51
    '-v', '--avoid',
52
    action='append',
53
    help = 'Encode the shellcode to avoid the listed bytes (provided as hex)'
54
)
55

56
parser.add_argument(
1✔
57
    '-n', '--newline',
58
    dest='avoid',
59
    action='append_const',
60
    const='0a',
61
    help = 'Encode the shellcode to avoid newlines'
62
)
63

64
parser.add_argument(
1✔
65
    '-z', '--zero',
66
    dest='avoid',
67
    action='append_const',
68
    const='00',
69
    help = 'Encode the shellcode to avoid NULL bytes'
70
)
71

72

73
parser.add_argument(
1✔
74
    '-d',
75
    '--debug',
76
    help='Debug the shellcode with GDB',
77
    action='store_true'
78
)
79

80
parser.add_argument(
1✔
81
    '-e',
82
    '--encoder',
83
    help="Specific encoder to use"
84
)
85

86
parser.add_argument(
1✔
87
    '-i',
88
    '--infile',
89
    help="Specify input file",
90
    default=sys.stdin,
91
    type=argparse.FileType('r')
92
)
93

94
parser.add_argument(
1✔
95
    '-r',
96
    '--run',
97
    help="Run output",
98
    action='store_true'
99
)
100

101
def main(args):
1✔
102
    tty    = args.output.isatty()
1✔
103

104
    if args.infile.isatty() and not args.lines:
1!
105
        parser.print_usage()
×
106
        sys.exit(1)
×
107

108
    data   = '\n'.join(args.lines) or args.infile.read()
1✔
109
    output = asm(data.replace(';', '\n'))
1✔
110
    fmt    = args.format or ('hex' if tty else 'raw')
1✔
111
    formatters = {'r':bytes, 'h':enhex, 's':repr}
1✔
112

113
    if args.avoid:
1!
114
        avoid = unhex(''.join(args.avoid))
×
115
        output = encode(output, avoid)
×
116

117
    if args.debug:
1!
118
        proc = gdb.debug_shellcode(output, arch=context.arch)
×
119
        proc.interactive()
×
120
        sys.exit(0)
×
121

122
    if args.run:
1!
123
        proc = run_shellcode(output)
×
124
        proc.interactive()
×
125
        sys.exit(0)
×
126

127
    if fmt[0] == 'e':
1!
128
        args.output.write(make_elf(output))
×
129
        try: os.fchmod(args.output.fileno(), 0o700)
×
130
        except OSError: pass
×
131
    else:
132
        output = formatters[fmt[0]](output)
1✔
133
        if not hasattr(output, 'decode'):
1!
134
            output = output.encode('ascii')
×
135
        args.output.write(output)
1✔
136

137
    if tty and fmt != 'raw':
1!
138
        args.output.write(b'\n')
×
139

140
if __name__ == '__main__':
1✔
141
    pwnlib.commandline.common.main(__file__)
1✔
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