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

Gallopsled / pwntools / 8d7613a419f51385e765cb9998da65eb488faa2e

pending completion
8d7613a419f51385e765cb9998da65eb488faa2e

push

github-actions

web-flow
Merge branch 'dev' into process-env-add-2

3905 of 6422 branches covered (60.81%)

1649 of 1649 new or added lines in 79 files covered. (100.0%)

12255 of 16708 relevant lines covered (73.35%)

0.73 hits per line

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

87.5
/pwnlib/commandline/disasm.py
1
#!/usr/bin/env python2
2
from __future__ import absolute_import
1✔
3
from __future__ import division
1✔
4
from __future__ import print_function
1✔
5

6
import argparse
1✔
7
import string
1✔
8
import sys
1✔
9

10
import pwnlib.args
1✔
11
pwnlib.args.free_form = False
1✔
12

13
from pwn import *
1✔
14
from pwnlib.commandline import common
1✔
15

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

22
parser.add_argument(
1✔
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(
1✔
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(
1✔
40
    "-a","--address",
41
    metavar='address',
42
    help="Base address",
43
    type=str,
44
    default='0'
45
)
46

47

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

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

62

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

74

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

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

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

91
            print(o,b,i)
1✔
92
        return
1✔
93

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

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