Created
February 15, 2019 08:36
-
-
Save peta909/648e8f401ec57c3299e4650fe8a1ee60 to your computer and use it in GitHub Desktop.
Simple hex dump using python. using binascii and struct modules
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
#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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple hex dumper using python
demo use of modules in binascii and struct for manipulating hex values and bytes.