forked from shuixi2013/export_func_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_func_code.py
More file actions
78 lines (65 loc) · 2.23 KB
/
export_func_code.py
File metadata and controls
78 lines (65 loc) · 2.23 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding:utf-8 -*-
import os
from idaapi import plugin_t
from idaapi import PLUGIN_PROC
from idaapi import PLUGIN_OK
import ida_nalt
import idaapi
import idautils
import idc
import time
# 获取SO文件名和路径
def getSoPathAndName():
fullpath = ida_nalt.get_input_file_path()
filepath,filename = os.path.split(fullpath)
return filepath,filename
# 获取代码段的范围
def getSegAddr():
textStart = []
textEnd = []
for seg in idautils.Segments():
if (idc.get_segm_name(seg)).lower() == '.text' or (
idc.get_segm_name(seg)).lower() == 'text':
tempStart = idc.get_segm_start(seg)
tempEnd = idc.get_segm_end(seg)
textStart.append(tempStart)
textEnd.append(tempEnd)
return min(textStart), max(textEnd)
class traceNatives(plugin_t):
flags = PLUGIN_PROC
comment = "export_func_code"
help = ""
wanted_name = "export_func_code"
wanted_hotkey = ""
def init(self):
print("export_func_code(v0.1) plugin has been loaded.")
return PLUGIN_OK
def run(self, arg):
# 查找需要的函数
ea, ed = getSegAddr()
so_path, so_name = getSoPathAndName()
script_name = so_name.split(".")[0] + "_" + str(int(time.time())) +".cc"
save_path = os.path.join(so_path, script_name)
print(f"导出路径:{save_path}")
F=open(save_path, "w+", encoding="utf-8")
F.write("\n#####################################\n")
for func in idautils.Functions(ea, ed):
try:
functionName = str(idaapi.ida_funcs.get_func_name(func))
if len(list(idautils.FuncItems(func))) > 10:
# 如果是thumb模式,地址+1
arm_or_thumb = idc.get_sreg(func, "T")
if arm_or_thumb:
func += 1
code=str(idaapi.decompile(func))+"\n#####################################\n"
print(code)
F.write(code)
F.flush()
except Exception as e:
print(e)
print(f"导出完成:{save_path}")
F.close()
def term(self):
pass
def PLUGIN_ENTRY():
return traceNatives()