Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple hex dump using python. using binascii and struct modules
#try to write a simple hex dump
import binascii,struct
fd = open("abcd.exe", "r")
fd_contents_str = fd.read()
fd_contents_hex = (binascii.b2a_hex(fd_contents_str)).upper()
Hex_dump = []
Byte_str = ""
for i, Half_byte in enumerate(fd_contents_hex):
Byte_str = Byte_str + Half_byte
if i % 2:
Byte_hex = struct.unpack('2b', Byte_str)#"4D" converted into (52,68)
Hex_dump.append(Byte_hex)
Byte_str = ""
print Hex_dump
fd.close()
@peta909
Copy link
Author

peta909 commented Feb 15, 2019

simple hex dumper using python
demo use of modules in binascii and struct for manipulating hex values and bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment