-
Notifications
You must be signed in to change notification settings - Fork 14
/
pyBinHexEncoder.py
51 lines (41 loc) · 1.14 KB
/
pyBinHexEncoder.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
45
46
47
48
49
50
51
# -*- encoding: utf-8 -*-
#
# FECT/pyBinHexEncoder.py
#
# Author: Jean-Philippe Teissier ( @Jipe_ )
#
# This work is licensed under the GNU General Public License
#
import binascii
import argparse
import sys
__version__ = '0.1'
def Main():
''' main '''
parser = argparse.ArgumentParser(description='Create a hex encoded file from a binary file')
parser.add_argument('-i', '--input', help='Input filename')
parser.add_argument('-o', '--output', help='Output filename')
args = parser.parse_args()
if args.input and args.output:
bytes = None
print '[*] ' + args.input + ' -> ' + args.output
try:
with open(args.input, 'rb') as f:
bytes = f.read()
except IOError as e:
print '[!] Input Error: ' + e.strerror
except:
print '[!] Unexpected input error:', sys.exc_info()[0]
if bytes:
hexdata = binascii.hexlify(bytes)
try:
with open(args.output, 'w+') as f2:
f2.write(hexdata)
except IOError as e:
print '[!] Output Error: ' + e.strerror
except:
print '[!] Unexpected output error:', sys.exc_info()[0]
else:
print '[!] Error: missing parameter (-i or -o)'
if __name__ == '__main__':
Main()