Created
October 23, 2019 09:57
-
-
Save radare/04612d3804fa72c0cc832d06208cadaf to your computer and use it in GitHub Desktop.
radare2 script to autoname functions by taking it from the assert calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ r2 -i assnam.py /usr/bin/ldapsearch