Skip to content

Instantly share code, notes, and snippets.

@zaneGittins
Last active January 19, 2023 16:53
Show Gist options
  • Save zaneGittins/b1b2f153b9f2bc2ec9d7a8e410367dab to your computer and use it in GitHub Desktop.
Save zaneGittins/b1b2f153b9f2bc2ec9d7a8e410367dab to your computer and use it in GitHub Desktop.
exhexdump.py
#!/usr/bin/env python2
# Author: Zane Gittins
# Small tool to assist in parsing hexdumps and optionally writing to binary file.
import re
import sys
import binascii
import argparse
def extract_hex(file_path):
regex = re.compile("\:(.*?)\|")
dataHex = ""
with open(file_path) as f:
for line in f:
result = regex.search(line)
dataHex += result.group(1)
dataHex = dataHex.replace(' ', '')
dataHex = dataHex.replace('\n', '')
dataHex = dataHex.replace('\r', '')
return dataHex
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-hx", "--hexdump", help="Hexdump file.")
parser.add_argument("-wb", "--writebin", help="Binary file to write to.")
args = parser.parse_args()
if args.hexdump:
extracted = extract_hex(args.hexdump)
if args.writebin:
with open(args.writebin, "wb") as fd_out:
chunk = binascii.unhexlify(extracted.rstrip())
fd_out.write(chunk)
else:
print(extracted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment