Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2014 14:39
Show Gist options
  • Save anonymous/8804728 to your computer and use it in GitHub Desktop.
Save anonymous/8804728 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import fileinput, re, sys, binascii, struct
hexword = '([A-Fa-f0-9]{4})'
pattern = '%(hexword)s:' + 8*'\s*%(hexword)s'
pattern = pattern % locals()
write = sys.stdout.write
unhex = binascii.unhexlify
word = lambda b: struct.unpack('!H', b)[0]
offset = 0
for line in fileinput.input():
match = re.match(pattern, line)
if match:
groups = match.groups()
start = word(unhex(groups[0]))
data = unhex(''.join(groups[1:]))
write('\x00' * (start-offset))
write(data)
offset = start + len(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment