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

Gallopsled / pwntools / 40bd8ba4ca272218ef13321bccc5548629fa6f77-PR-2221

pending completion
40bd8ba4ca272218ef13321bccc5548629fa6f77-PR-2221

Pull #2221

github-actions

web-flow
Merge bb0665e35 into f1d5afe32
Pull Request #2221: Add shellcraft.sleep template wrapping SYS_nanosleep

3639 of 6419 branches covered (56.69%)

11701 of 16706 relevant lines covered (70.04%)

0.7 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