-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrename.py
66 lines (56 loc) · 1.91 KB
/
rename.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Get the correct syntax to rename the function name. Otherwise we're all good :)
"""
import idaapi
import idautils
import time
def read_input():
"""
This function reads the results of the output generated by the function_compare.py script and creates a dictionary of the function to be renamed and what it should be
renamed to.
"""
input_file_name= 'input_to_rename_function.txt'
with open(input_file_name, 'r') as f:
functions= f.readlines()
renamed_functions= {}
for i in functions:
t1= i.split("\t")
src= t1[0].split('<')
address= src[1]
address= address.rstrip()
dest= t1[1].split(',')
"""
Use the destination filename as the value. This is what you need to rename your function to.
"""
#renamed_functions[address]= str(dest[0])
renamed_functions[address]= dest
return renamed_functions
def rename_functions_ida(renamed_functions):
single_count= 0
multiple_count= 0
for key, val in renamed_functions.items():
funcname= GetFunctionName(int(key))
if len(val) == 1 and funcname.startswith('sub_'):
single_count+= 1
val= 'single_'+str(single_count)
elif len(val) > 1 and funcname.startswith('sub_'):
multiple_count+= 1
val= 'multiple_'+str(multiple_count)
else:
continue
r1= MakeNameEx(int(key), val, SN_NOWARN)
if r1 == 0:
print "Renaming of %s failed" %int(key)
else:
print "Renaming of %s succeeded" %int(key)
print single_count+multiple_count," functions were renamed in IDA"
time.sleep(3)
#Wait for analysis to complete
idaapi.autoWait()
#Read results of function_compare.py which compares functions inside a binary with functions in all the existing libraries
renamed_functions= {}
renamed_functions= read_input()
#Rename functions in IDA for the source binary
rename_functions_ida(renamed_functions)
#Exit IDA
idc.Exit(0)