• 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/phd.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 os
×
UNCOV
7
import sys
×
UNCOV
8
import io
×
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
    'phd',
18
    help = 'Pwnlib HexDump'
19
)
20

UNCOV
21
parser.add_argument(
×
22
    'file',
23
    metavar='file',
24
    nargs='?',
25
    help='File to hexdump.  Reads from stdin if missing.',
26
    type=argparse.FileType('rb'),
27
    default=getattr(sys.stdin, 'buffer', sys.stdin)
28
)
29

UNCOV
30
parser.add_argument(
×
31
    "-w", "--width",
32
    help="Number of bytes per line.",
33
    default='16',
34
)
35

UNCOV
36
parser.add_argument(
×
37
    "-l", "--highlight",
38
    help="Byte to highlight.",
39
    nargs="*",
40
)
41

UNCOV
42
parser.add_argument(
×
43
    "-s", "--skip",
44
    help="Skip this many initial bytes.",
45
    default='0',
46
)
47

UNCOV
48
parser.add_argument(
×
49
    "-c", "--count",
50
    help="Only show this many bytes.",
51
    default='-1',
52
)
53

UNCOV
54
parser.add_argument(
×
55
    "-o", "--offset",
56
    help="Addresses in left hand column starts at this address.",
57
    default='0',
58
)
59

UNCOV
60
parser.add_argument(
×
61
    "--color",
62
    nargs='?',
63
    help="Colorize the output.  When 'auto' output is colorized exactly when stdout is a TTY.  Default is 'auto'.",
64
    choices = ('always', 'never', 'auto'),
65
    default='auto',
66
)
67

UNCOV
68
def asint(s):
×
69
    if   s.startswith('0x'):
×
70
        return int(s, 16)
×
71
    elif s.startswith('0'):
×
72
        return int(s, 8)
×
73
    else:
74
        return int(s, 10)
×
75

UNCOV
76
def main(args):
×
77
    infile = args.file
×
78
    width  = asint(args.width)
×
79
    skip   = asint(args.skip)
×
80
    count  = asint(args.count)
×
81
    offset = asint(args.offset)
×
82

83
    # if `--color` has no argument it is `None`
84
    color = args.color or 'always'
×
85
    text.when = color
×
86

87
    if skip:
×
88
        if infile == sys.stdin:
×
89
            infile.read(skip)
×
90
        else:
91
            infile.seek(skip, os.SEEK_CUR)
×
92

93
    if count:
×
94
        infile = io.BytesIO(infile.read(count))
×
95

96
    hl = []
×
97
    if args.highlight:
×
98
        for hs in args.highlight:
×
99
            for h in hs.split(','):
×
100
                hl.append(asint(h))
×
101

102
    try:
×
103
        for line in hexdump_iter(infile, width, highlight = hl, begin = offset + skip):
×
104
            print(line)
×
105
    except (KeyboardInterrupt, IOError):
×
106
        pass
×
107

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