Skip to content

Instantly share code, notes, and snippets.

@radare

radare/assnam.py

Created Oct 23, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@radare radare commented Oct 23, 2019

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

@radare

This comment has been minimized.

Copy link
Owner Author

@radare 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