Created
October 26, 2019 17:31
-
-
Save Und3rf10w/15fe32226fb048b24f3d420e6ee6a4ca to your computer and use it in GitHub Desktop.
Convert a binary file to a hexbyte string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import binascii | |
import argparse | |
from os import path | |
parser = argparse.ArgumentParser(description ='Convert input raw binary file to a hex byte string') | |
parser.add_argument('-i', '--input', dest='input_file', required=True, help="The input file to convert") | |
parser.add_argument('-o', '--output', dest='output_file', required=False, help="The output file to write to") | |
args = parser.parse_args() | |
if path.exists(args.input_file): | |
with open(args.input_file, 'rb') as f: | |
content = f.read() | |
if args.output_file: | |
try: | |
o = open(args.output_file, 'w') | |
o.write(binascii.hexlify(content)) | |
o.close() | |
except Exception as e: | |
print("ERROR: %s") % (str(e)) | |
else: | |
print(binascii.hexlify(content)) | |
f.close() | |
else: | |
print("ERROR: Provided input file does not exist!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment