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

Gallopsled / pwntools / 1

29 May 2020 09:05AM UTC coverage: 0.0% (-72.4%) from 72.414%
1

push

github

layderv
__str__ to __bytes__ in python2

0 of 8 new or added lines in 2 files covered. (0.0%)

11301 existing lines in 133 files now uncovered.

0 of 15497 relevant lines covered (0.0%)

0.0 hits per line

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

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

UNCOV
5
import argparse
×
UNCOV
6
import sys
×
7

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

UNCOV
11
parser = common.parser_commands.add_parser(
×
12
    'asm',
13
    help = 'Assemble shellcode into bytes'
14
)
15

UNCOV
16
parser.add_argument(
×
17
    'lines',
18
    metavar='line',
19
    nargs='*',
20
    help='Lines to assemble. If none are supplied, use stdin'
21
)
22

UNCOV
23
parser.add_argument(
×
24
    "-f", "--format",
25
    help="Output format (defaults to hex for ttys, otherwise raw)",
26
    choices=['raw', 'hex', 'string', 'elf']
27
)
28

UNCOV
29
parser.add_argument(
×
30
    "-o","--output",
31
    metavar='file',
32
    help="Output file (defaults to stdout)",
33
    type=argparse.FileType('wb'),
34
    default=getattr(sys.stdout, 'buffer', sys.stdout)
35
)
36

UNCOV
37
parser.add_argument(
×
38
    '-c', '--context',
39
    metavar = 'context',
40
    action = 'append',
41
    type   = common.context_arg,
42
    choices = common.choices,
43
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
44
)
45

UNCOV
46
parser.add_argument(
×
47
    '-v', '--avoid',
48
    action='append',
49
    help = 'Encode the shellcode to avoid the listed bytes (provided as hex)'
50
)
51

UNCOV
52
parser.add_argument(
×
53
    '-n', '--newline',
54
    dest='avoid',
55
    action='append_const',
56
    const='0a',
57
    help = 'Encode the shellcode to avoid newlines'
58
)
59

UNCOV
60
parser.add_argument(
×
61
    '-z', '--zero',
62
    dest='avoid',
63
    action='append_const',
64
    const='00',
65
    help = 'Encode the shellcode to avoid NULL bytes'
66
)
67

68

UNCOV
69
parser.add_argument(
×
70
    '-d',
71
    '--debug',
72
    help='Debug the shellcode with GDB',
73
    action='store_true'
74
)
75

UNCOV
76
parser.add_argument(
×
77
    '-e',
78
    '--encoder',
79
    help="Specific encoder to use"
80
)
81

UNCOV
82
parser.add_argument(
×
83
    '-i',
84
    '--infile',
85
    help="Specify input file",
86
    default=sys.stdin,
87
    type=argparse.FileType('r')
88
)
89

UNCOV
90
parser.add_argument(
×
91
    '-r',
92
    '--run',
93
    help="Run output",
94
    action='store_true'
95
)
96

UNCOV
97
def main(args):
×
98
    tty    = args.output.isatty()
×
99

100
    if args.infile.isatty() and not args.lines:
×
101
        parser.print_usage()
×
102
        sys.exit(1)
×
103

104
    data   = '\n'.join(args.lines) or args.infile.read()
×
105
    output = asm(data.replace(';', '\n'))
×
106
    fmt    = args.format or ('hex' if tty else 'raw')
×
107
    formatters = {'r':bytes, 'h':enhex, 's':repr}
×
108

109
    if args.avoid:
×
110
        avoid = unhex(''.join(args.avoid))
×
111
        output = encode(output, avoid)
×
112

113
    if args.debug:
×
114
        proc = gdb.debug_shellcode(output, arch=context.arch)
×
115
        proc.interactive()
×
116
        sys.exit(0)
×
117

118
    if args.run:
×
119
        proc = run_shellcode(output)
×
120
        proc.interactive()
×
121
        sys.exit(0)
×
122

123
    if fmt[0] == 'e':
×
124
        args.output.write(make_elf(output))
×
125
        try: os.fchmod(args.output.fileno(), 0o700)
×
126
        except OSError: pass
×
127
    else:
128
        output = formatters[fmt[0]](output)
×
129
        if not hasattr(output, 'decode'):
×
130
            output = output.encode('ascii')
×
131
        args.output.write(output)
×
132

133
    if tty and fmt != 'raw':
×
134
        args.output.write(b'\n')
×
135

UNCOV
136
if __name__ == '__main__':
×
137
    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