-
Notifications
You must be signed in to change notification settings - Fork 2
/
idapro-decompile.py
executable file
·48 lines (39 loc) · 1.54 KB
/
idapro-decompile.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
from idaapi import *
from idautils import *
from idc import *
import json
exclude_func = [ '_start', 'deregister_tm_clones', 'register_tm_clones',
'__do_global_dtors_aux', 'frame_dummy', '__libc_csu_init', '__libc_csu_fini',
'_fini', '_init', '__gmon_start__']
def run_ida_decompiler():
for seg_start in Segments():
if get_segm_name(seg_start) == '.text':
for f_ea in Functions(seg_start, idc.get_segm_end(seg_start)):
f = idaapi.get_func(f_ea)
fname = idc.get_func_name(f_ea)
if f is None:
print ("Failed to obtain the function@0x%08x" % (f_ea))
if fname in exclude_func:
continue
for (startea, endea) in Chunks(f_ea):
try:
df = idaapi.decompile(startea)
if df is None:
print ("Failed to decompile the function %s" % fname)
result.append(str(df))
except:
print ("Failed to attempt decompilation of the function@0x%08x" % (f_ea))
# wait until ida analysis done
ida_auto.auto_wait()
result=list()
# set binary info
filename = ida_nalt.get_root_filename()
# run ida decompiler
run_ida_decompiler()
buf='\n'.join(result)
# save decompile code
with open("D:\\koharin\\Decompile\\output\\{0}.c".format(filename), 'w') as file:
file.write(buf)
file.close()
idc.qexit(0)
exit(0)