-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin2hex.py
executable file
·46 lines (30 loc) · 1.05 KB
/
bin2hex.py
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
40
41
42
43
44
#!/usr/bin/env python3
import argparse
import sys
def parse_cmd_line():
usage = """
Convert bin to hex
"""
parse = argparse.ArgumentParser(
description=usage, formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parse.add_argument('--infile', '-i', type=str, default="", \
dest='infile', help='input file that contains some file')
parse.add_argument('--outfile', '-o', type=str, default="", \
dest='outfile', help='output file that will get the input file in hexadecimal text')
return parse.parse_args(), parse
def convert_fun(in_file_name, out_file_name):
with open(in_file_name,'rb') as in_file:
hex_bytes = in_file.read()
with open(out_file_name, 'w') as out_file:
out_file.write(hex_bytes.hex())
cmd, parse = parse_cmd_line()
if cmd.infile == '':
print("Error: missing -i argument")
parse.print_help()
sys.exit(1)
if cmd.outfile == '':
print("Error: missing -o argument")
parse.print_help()
sys.exit(1)
convert_fun(cmd.infile, cmd.outfile)