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

Gallopsled / pwntools / 4c743a92f3eed7759ae5f16bdf9079e7854f0003

pending completion
4c743a92f3eed7759ae5f16bdf9079e7854f0003

push

github-actions

gogo
Fix testing.

3938 of 6504 branches covered (60.55%)

17 of 17 new or added lines in 1 file covered. (100.0%)

12343 of 16873 relevant lines covered (73.15%)

0.73 hits per line

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

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

5
import argparse
1✔
6
import sys
1✔
7

8
from pwnlib.commandline import common
1✔
9
from pwnlib.util.fiddling import enhex
1✔
10
from pwnlib.util.lists import group
1✔
11

12
parser = common.parser_commands.add_parser(
1✔
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

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

20
parser.add_argument(
1✔
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(
1✔
29
    '-s', '--separator',
30
    metavar = 'separator',
31
    type = str,
32
    default = '',
33
    help = 'Add a separator between each byte',
34
)
35

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

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

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

51
    print(encoded)
1✔
52

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