Skip to content

Instantly share code, notes, and snippets.

@radare
Created October 23, 2019 09:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radare/04612d3804fa72c0cc832d06208cadaf to your computer and use it in GitHub Desktop.
Save radare/04612d3804fa72c0cc832d06208cadaf to your computer and use it in GitHub Desktop.
radare2 script to autoname functions by taking it from the assert calls
#!/usr/bin/env python3
import r2pipe
r2 = r2pipe.open()
a = r2.cmd('ii~__assert_rtn[1]').strip()
if not a:
print('[assnam] Cannot find assert_rtn import')
exit(1)
if int(r2.cmd('aflc')) == 0:
r2.cmd('aa;aac')
u = 0
refs = r2.cmd('axt '+a+'~[1]').strip().split('\n')
for r in refs:
f = r2.cmd('afi.@'+r).strip()
if not f:
print('[assnam] Cannot find function at '+ r)
continue
n = r2.cmd('pdsb@' + r + '~str,":0[1]').strip()
if n is '':
print('[assnam] Cannot resolve assert name ' + r)
continue
sn = n.replace('str', 'sym')
if sn != f:
o = r2.cmd('afo ' + r).strip()
c = "afn " + sn + " @ " + o
r2.cmd(c)
u += 1
print('[assnam] Renamed ' + str(u) + ' functions')
@radare
Copy link
Author

radare commented Oct 23, 2019

$ r2 -i assnam.py /usr/bin/ldapsearch

@radare
Copy link
Author

radare commented Oct 23, 2019

before -> after

Screenshot 2019-10-23 at 12 24 27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment