-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbin-to-opcodes.py
More file actions
executable file
·33 lines (25 loc) · 935 Bytes
/
bin-to-opcodes.py
File metadata and controls
executable file
·33 lines (25 loc) · 935 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
#!/usr/bin/python
import sys
import binascii
import argparse
def main(inputFile, outputFile):
with open(inputFile, 'rb') as f:
content = f.read()
rawHexString = binascii.hexlify(content)
formatedHexString = ""
for i in range(0, len(rawHexString), 2):
formatedHexString += "\\x{byteValue}".format(byteValue = rawHexString[i:i+2].upper().decode('utf-8'))
with open(outputFile, 'w') as f:
f.write(formatedHexString)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = 'Extract the contents of a binary file and output an escaped string to a file.')
parser.add_argument("-i", "--input", type=str, help="The import binary file.")
parser.add_argument("-o", "--output", type=str, help="The output file name.")
args = parser.parse_args()
if args.input:
if args.output:
main(args.input, args.output)
else:
main(args.input, args.input + '.optcodes')
else:
parser.print_help(sys.stderr)