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

Gallopsled / pwntools / 1

29 Jun 2023 03:26PM UTC coverage: 18.943% (+17.6%) from 1.313%
1

push

github

web-flow
Merge branch 'dev' into dev

189 of 6160 branches covered (3.07%)

42 of 620 new or added lines in 43 files covered. (6.77%)

2088 existing lines in 31 files now uncovered.

3364 of 17759 relevant lines covered (18.94%)

0.19 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
2
from __future__ import absolute_import
×
3
from __future__ import division
×
4
from __future__ import print_function
×
5

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

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

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

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

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

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

38

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

47

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

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

62

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

74

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

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

NEW
85
        highlight_bytes = lambda t: ''.join(map(lambda x: x.replace('00', text.red('00')).replace('0a', text.red('0a')), group(2, t)))
×
86
        for o,b,i in zip(*map(str.splitlines, (offsets, bytes, instrs))):
×
NEW
87
            b = ' '.join(highlight_bytes(bb) for bb in b.split(' '))
×
88
            i = highlight(i.strip(), PwntoolsLexer(), TerminalFormatter()).strip()
×
89
            i = i.replace(',',', ')
×
90

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

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

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