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

Gallopsled / pwntools / 11532588290

26 Oct 2024 02:29PM UTC coverage: 73.585% (+2.1%) from 71.491%
11532588290

push

github

peace-maker
Merge branch 'dev' into interactive

3767 of 6364 branches covered (59.19%)

1463 of 2234 new or added lines in 69 files covered. (65.49%)

85 existing lines in 22 files now uncovered.

13246 of 18001 relevant lines covered (73.58%)

0.74 hits per line

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

87.04
/pwnlib/commandline/disasm.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3
from __future__ import print_function
1✔
4

5
import argparse
1✔
6
import re
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
        dis = disasm(dat, vma=safeeval.const(args.address))
1✔
81

82
        # Note: those patterns are copied from disasm function
83
        pattern = '^( *[0-9a-f]+: *)((?:[0-9a-f]+ )+ *)(.*)'
1✔
84
        lines = []
1✔
85
        for line in dis.splitlines():
1✔
86
            match = re.search(pattern, line)
1✔
87
            if not match:
1!
88
                # Append as one element tuple
NEW
89
                lines.append((line,))
×
NEW
90
                continue
×
91

92
            groups = match.groups()
1✔
93
            o, b, i = groups
1✔
94

95
            lines.append((o, b, i))
1✔
96

97

98
        highlight_bytes = lambda t: ''.join(map(lambda x: x.replace('00', text.red('00')).replace('0a', text.red('0a')), group(2, t)))
1✔
99
        for line in lines:
1✔
100
            if len(line) == 3:
1!
101
                o, b, i = line
1✔
102
                b = ' '.join(highlight_bytes(bb) for bb in b.split(' '))
1✔
103
                i = highlight(i.strip(), PwntoolsLexer(), TerminalFormatter()).strip()
1✔
104
                i = i.replace(',',', ')
1✔
105
                print(o,b,i)
1✔
106
            else:
NEW
107
                print(line[0])
×
108
        return
1✔
109

110
    print(disasm(dat, vma=safeeval.const(args.address)))
×
111

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