Repository navigation
Expand file tree
/
Copy pathtest_plugin.py
More file actions
executable file
·166 lines (137 loc) · 4.53 KB
/
Copy pathtest_plugin.py
File metadata and controls
executable file
·166 lines (137 loc) · 4.53 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
"""
测试 IDA Pro MCP 插件是否可以在 Python 3.9 下加载
"""
import sys
import subprocess
def test_plugin_syntax():
"""测试插件语法是否正确"""
print("=" * 60)
print("测试 1: 插件语法检查")
print("=" * 60)
import os
plugin_path = os.path.expanduser("~/.idapro/plugins/mcp-plugin.py")
python_path = "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3"
result = subprocess.run(
[python_path, "-m", "py_compile", plugin_path],
capture_output=True,
text=True
)
if result.returncode == 0:
print("✅ 插件语法检查通过")
return True
else:
print("❌ 插件语法检查失败")
print(result.stderr)
return False
def test_import():
"""测试关键导入"""
print("\n" + "=" * 60)
print("测试 2: 关键模块导入")
print("=" * 60)
python_path = "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3"
tests = [
("typing_extensions", "from typing_extensions import NotRequired"),
("future annotations", "from __future__ import annotations"),
("TypedDict", "from typing import TypedDict"),
]
all_passed = True
for name, import_stmt in tests:
result = subprocess.run(
[python_path, "-c", import_stmt],
capture_output=True,
text=True
)
if result.returncode == 0:
print(f"✅ {name} 导入成功")
else:
print(f"❌ {name} 导入失败")
print(result.stderr)
all_passed = False
return all_passed
def test_python_version():
"""测试 IDA Pro Python 版本"""
print("\n" + "=" * 60)
print("测试 3: IDA Pro Python 版本")
print("=" * 60)
import os
link_path = "/Applications/IDA Pro 8.4/ida64.app/Contents/MacOS/libpython3.link.dylib"
if os.path.islink(link_path):
target = os.readlink(link_path)
print(f"Python 链接: {target}")
if "3.9" in target:
print("✅ IDA Pro 使用 Python 3.9")
return True
else:
print(f"⚠️ IDA Pro 使用的不是 Python 3.9: {target}")
return False
else:
print("❌ 找不到 Python 链接文件")
return False
def test_mcp_server():
"""测试 MCP 服务器安装"""
print("\n" + "=" * 60)
print("测试 4: MCP 服务器")
print("=" * 60)
# 尝试多个可能的 Python 路径
python_paths = [
"/opt/miniconda3/bin/python3.12",
"/usr/local/bin/python3.12",
"/usr/bin/python3.12",
"python3.12",
]
python_path = None
for path in python_paths:
result = subprocess.run(
[path, "--version"],
capture_output=True,
text=True
)
if result.returncode == 0:
python_path = path
break
if not python_path:
print("⚠️ 未找到 Python 3.12,跳过 MCP 测试")
return True
result = subprocess.run(
[python_path, "-c", "import ida_pro_mcp; print('MCP 已安装')"],
capture_output=True,
text=True
)
if result.returncode == 0:
print(f"✅ {result.stdout.strip()}")
return True
else:
print("❌ MCP 服务器未安装")
print(result.stderr)
return False
def main():
print("🧪 IDA Pro MCP 插件测试套件\n")
results = []
# 运行所有测试
results.append(("语法检查", test_plugin_syntax()))
results.append(("模块导入", test_import()))
results.append(("Python 版本", test_python_version()))
results.append(("MCP 服务器", test_mcp_server()))
# 总结
print("\n" + "=" * 60)
print("测试总结")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✅ 通过" if result else "❌ 失败"
print(f"{status}: {name}")
print(f"\n总计: {passed}/{total} 测试通过")
if passed == total:
print("\n🎉 所有测试通过!插件已准备好在 IDA Pro 中使用。")
print("\n下一步:")
print("1. 打开 IDA Pro")
print("2. 加载一个二进制文件")
print("3. 按 Ctrl+Option+M 启动插件")
return 0
else:
print("\n⚠️ 部分测试失败,请检查上述错误信息。")
return 1
if __name__ == "__main__":
sys.exit(main())