Skip to content

Instantly share code, notes, and snippets.

@mwhudson
Created December 15, 2014 00:00
Show Gist options
  • Save mwhudson/01923f69d75be25c3d5a to your computer and use it in GitHub Desktop.
Save mwhudson/01923f69d75be25c3d5a to your computer and use it in GitHub Desktop.
import os, sys
state = 'before'
bytes = ''
goasm = []
for line in sys.stdin:
words = line.strip().split()
if state == 'before':
if words[0] == '0x0000':
state = 'goasm'
if state == 'goasm':
if len(words[1]) == 2:
state = 'during'
else:
goasm.append(line[:-1])
if state == 'during':
if not words[0].startswith('0x'):
state = 'after'
continue
bytes += ''.join(chr(int(w, 16)) for w in words[1:17])
open('t.data', 'w').write(bytes)
armasm = os.popen("aarch64-linux-gnu-objdump -D -b binary -m aarch64 t.data").read().splitlines()
for i in range(len(armasm)):
if armasm[i].startswith('0000000'):
i += 1
break
print
for g, a in zip(goasm[3:], armasm[i:]):
g = g[1:]
gaddr = int(g.split()[0], 16)
gg = g[1:].index(')')
print g[1:][gg+2:]
a = a.lstrip()
aaddr = int(a.split(':')[0], 16)
assert aaddr == gaddr
print a.split('\t', 2)[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment