Skip to content

Instantly share code, notes, and snippets.

@fritschy
Created August 31, 2011 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fritschy/1183292 to your computer and use it in GitHub Desktop.
Save fritschy/1183292 to your computer and use it in GitHub Desktop.
Sort objdump -d ouput by function name (useful for text compares).
#!/usr/bin/python
import sys, re
infunction=False
currfunc=""
funclines=[]
functions={}
for line in sys.stdin:
line=line.rstrip()
if len(line) == 0:
if infunction:
infunction=False
functions[currfunc[0]] = (currfunc[1], "\n".join(funclines))
funclines=[]
else:
continue
if infunction:
try:
addr,code=map(str.lstrip, line.split(':', 1))
except:
pass
funclines.append(code)
continue
if re.match(r"^[0-9a-fA-F]+ .*$", line):
addr,name=line.split(' ', 1)
name=name.rstrip(':').lstrip('<').rstrip('>')
currfunc=(name, addr)
infunction=True
print('Found %d functions' % len(functions))
function_names=functions.keys()
function_names.sort()
for i in function_names:
print('%s %s' % (functions[i][0], i))
print(functions[i][1])
print(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment