-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript_demo.py
37 lines (28 loc) · 988 Bytes
/
script_demo.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
# -*- coding: utf-8 -*-
import os, json, traceback
import idc, idautils, ida_auto, idaapi, ida_nalt
features = {"EA": []}
def analysis():
for ea in idautils.Functions():
flags = idc.get_func_flags(ea)
# 筛选 THUNK (跳转) or 典型库函数
if flags & idc.FUNC_LIB or flags & idc.FUNC_THUNK:
continue
features['EA'].append(f"{ea:X}")
def main():
analysis()
if __name__ == "__main__":
# 运行脚本逻辑前等待自动分析完成
ida_auto.auto_wait()
binary_name = ida_nalt.get_root_filename().split('.')[0]
path = ida_nalt.get_input_file_path()[:-len(ida_nalt.get_root_filename())]
outputPath = os.path.join(path, '_code.json')
try:
main()
# 输出特征为json
with open(outputPath, "w") as f:
f.write(json.dumps(features)) # , indent=2
except Exception as e:
# 发生异常
traceback.print_exc(file=open(outputPath, "a"))
idc.qexit(0)