-
-
Save dmazin/7348f61312c647e79e75eb6e8521ef68 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 format_hex_dump(dump_str): | |
# Split string into lines | |
lines = dump_str.split('\n') | |
# Create a list to hold all bytes | |
all_bytes = [] | |
# Process each line | |
for line in lines: | |
# Split the line into address and bytes | |
address, bytes_str = line.split(':') | |
# Split the bytes string into individual bytes | |
bytes_list = bytes_str.split() | |
# Strip leading "0x" from each byte and add it to the list | |
all_bytes.extend([byte[2:] for byte in bytes_list]) | |
# Group all bytes by 16 | |
grouped_bytes = [all_bytes[i:i+16] for i in range(0, len(all_bytes), 16)] | |
# Join bytes in each group with spaces and groups with line breaks | |
formatted_dump = '\n'.join([' '.join(group) for group in grouped_bytes]) | |
return formatted_dump | |
format_hex_dump(dump_str.strip()) # strip leading/trailing whitespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment