• 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/disasm.py
1
#!/usr/bin/env python2
UNCOV
2
from __future__ import absolute_import
×
UNCOV
3
from __future__ import division
×
UNCOV
4
from __future__ import print_function
×
5

UNCOV
6
import argparse
×
UNCOV
7
import string
×
UNCOV
8
import sys
×
9

UNCOV
10
import pwnlib
×
UNCOV
11
pwnlib.args.free_form = False
×
12

UNCOV
13
from pwn import *
×
UNCOV
14
from pwnlib.commandline import common
×
15

UNCOV
16
parser = common.parser_commands.add_parser(
×
17
    'disasm',
18
    help = 'Disassemble bytes into text format'
19
)
20

UNCOV
21
parser.add_argument(
×
22
    'hex',
23
    metavar = 'hex',
24
    nargs = '*',
25
    help = 'Hex-string to disassemble. If none are supplied, then it uses stdin in non-hex mode.'
26
)
27

UNCOV
28
parser.add_argument(
×
29
    '-c', '--context',
30
    metavar = 'arch_or_os',
31
    action = 'append',
32
    type   = common.context_arg,
33
    choices = common.choices,
34
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
35
)
36

37

UNCOV
38
parser.add_argument(
×
39
    "-a","--address",
40
    metavar='address',
41
    help="Base address",
42
    type=str,
43
    default='0'
44
)
45

46

UNCOV
47
parser.add_argument(
×
48
    '--color',
49
    help="Color output",
50
    action='store_true',
51
    default=sys.stdout.isatty()
52
)
53

UNCOV
54
parser.add_argument(
×
55
    '--no-color',
56
    help="Disable color output",
57
    action='store_false',
58
    dest='color'
59
)
60

61

UNCOV
62
def main(args):
×
63
    if len(args.hex) > 0:
×
64
        dat = ''.join(args.hex).encode('utf-8', 'surrogateescape')
×
65
        dat = dat.translate(None, string.whitespace.encode('ascii'))
×
66
        if not set(string.hexdigits.encode('ascii')) >= set(dat):
×
67
            print("This is not a hex string")
×
68
            exit(-1)
×
69
        dat = unhex(dat)
×
70
    else:
71
        dat = getattr(sys.stdin, 'buffer', sys.stdin).read()
×
72

73

74
    if args.color:
×
75
        from pygments import highlight
×
76
        from pygments.formatters import TerminalFormatter
×
77
        from pwnlib.lexer import PwntoolsLexer
×
78

79
        offsets = disasm(dat, vma=safeeval.const(args.address), instructions=False, byte=False)
×
80
        bytes   = disasm(dat, vma=safeeval.const(args.address), instructions=False, offset=False)
×
81
        instrs  = disasm(dat, vma=safeeval.const(args.address), byte=False, offset=False)
×
82
        # instrs  = highlight(instrs, PwntoolsLexer(), TerminalFormatter())
83

84
        for o,b,i in zip(*map(str.splitlines, (offsets, bytes, instrs))):
×
85
            b = b.replace('00', text.red('00'))
×
86
            b = b.replace('0a', text.red('0a'))
×
87
            i = highlight(i.strip(), PwntoolsLexer(), TerminalFormatter()).strip()
×
88
            i = i.replace(',',', ')
×
89

90
            print(o,b,i)
×
91
        return
×
92

93
    print(disasm(dat, vma=safeeval.const(args.address)))
×
94

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