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

Gallopsled / pwntools / 1

04 Jun 2023 06:34PM UTC coverage: 19.326% (+19.3%) from 0.0%
1

push

github

peace-maker
Merge branch 'dev' into pr/2117

189 of 5942 branches covered (3.18%)

0 of 2 new or added lines in 2 files covered. (0.0%)

3610 existing lines in 45 files now uncovered.

3286 of 17003 relevant lines covered (19.33%)

0.19 hits per line

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

0.0
/pwnlib/commandline/hex.py
1
#!/usr/bin/env python2
2
from __future__ import absolute_import
×
3
from __future__ import division
×
4

5
import argparse
×
6
import sys
×
7

8
from pwnlib.commandline import common
×
9
from pwnlib.util.fiddling import enhex
×
UNCOV
10
from pwnlib.util.lists import group
×
11

UNCOV
12
parser = common.parser_commands.add_parser(
×
13
    'hex',
14
    help = 'Hex-encodes data provided on the command line or stdin',
15
    description = 'Hex-encodes data provided on the command line or stdin')
16

UNCOV
17
parser.add_argument('data', nargs='*',
×
18
    help='Data to convert into hex')
19

20
parser.add_argument(
×
21
    '-p', '--prefix',
22
    metavar = 'prefix',
23
    type = str,
24
    default = '',
25
    help = 'Insert a prefix before each byte',
26
)
27

28
parser.add_argument(
×
29
    '-s', '--separator',
30
    metavar = 'separator',
31
    type = str,
32
    default = '',
33
    help = 'Add a separator between each byte',
34
)
35

UNCOV
36
def format_hex(hex_string, prefix, separator):
×
UNCOV
37
    return separator.join([prefix + x for x in group(2, hex_string)])
×
38

UNCOV
39
def main(args):
×
UNCOV
40
    if not args.data:
×
UNCOV
41
        encoded = enhex(getattr(sys.stdin, 'buffer', sys.stdin).read())
×
42
    else:
UNCOV
43
        data = ' '.join(args.data)
×
UNCOV
44
        if not hasattr(data, 'decode'):
×
UNCOV
45
            data = data.encode('utf-8', 'surrogateescape')
×
UNCOV
46
        encoded = enhex(data)
×
47

UNCOV
48
    if args.prefix or args.separator:
×
UNCOV
49
        encoded = format_hex(encoded, args.prefix, args.separator)
×
50

UNCOV
51
    print(encoded)
×
52

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