-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunhex.py
More file actions
executable file
·39 lines (32 loc) · 916 Bytes
/
Copy pathunhex.py
File metadata and controls
executable file
·39 lines (32 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
import binascii
import json
import optparse
import pprint
import subprocess
import sys
def main():
parser = optparse.OptionParser(
description='',
prog='unhex.py',
usage='unhex.py [options]',
add_help_option=True)
parser.add_option(
'-j', '--json',
action='store_true',
dest='json',
default=False,
help='Parse decoded string as JSON and pretty print.')
(options, args) = parser.parse_args(sys.argv[1:])
if len(args) == 0:
options.arg = True
args.append(str(subprocess.check_output('pbpaste').decode('utf8')))
for s in args:
unhex_s = binascii.unhexlify(s)
if options.json:
j = json.loads(unhex_s)
print(pprint.PrettyPrinter(indent=4).pprint(j))
else:
print(unhex_s.decode('utf-8'))
if __name__ == '__main__':
main()