Last active
September 17, 2018 12:50
-
-
Save p1-olm/a2504c07046e84da8270958e2ac8c4bc to your computer and use it in GitHub Desktop.
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
def hex_dump(pdu): | |
""" Useful routine to dump pdu, "xxd" way | |
""" | |
import string | |
length = 0x10 | |
for i in range(0, len(pdu) // length + 1): | |
begin = i * length | |
end = (i + 1) * length | |
padding = " " * (length - len(pdu[begin:end])) * 3 | |
bytes_chunk = "".join("{:02x} ".format(ord(c)) for c in pdu[begin:end]) | |
ascii_repr = padding + "".join(a if a in string.printable[:-5] else "." for a in pdu[begin:end]) | |
print("{:08x}: {} {}".format(begin, bytes_chunk, ascii_repr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment