dnSpy MCP
用于静态的模型上下文协议服务器。NET程序集分析,由ICSharpCode提供支持。解压器(dnSpyEx引擎)。通过stdio将反编译、IL反汇编、元数据检查和保护分析作为MCP工具公开。从不执行目标程序集。
需求
- .NET 8 SDK或更高版本
- 兼容的MCP客户端(Claude Desktop、Cursor或任何支持MCP stdio传输的客户端)
安装
git clone https://github.com/ZeraTS/dnSpy-MCP.git
cd dnSpy-MCP
dotnet build src/DnSpyMcp/DnSpyMcp.csproj -c ReleaseClaude桌面配置
增添 claude_desktop_config.json:
{
"mcpServers": {
"dnspy-mcp": {
"command": "dotnet",
"args": ["/path/to/src/DnSpyMcp/bin/Release/net8.0/DnSpyMcp.dll"]
}
}
}工具
| 工具 | 说明 | 关键参数 |
|---|---|---|
get_pe_info | 获取PE/COFF头信息、程序集元数据和目标框架 | assemblyPath |
get_resources | 列出程序集中嵌入的所有清单资源 | assemblyPath |
resolve_token | 解析元数据令牌(十六进制,例如。 0x02000001)对其定义 | assemblyPath, tokenHex |
list_pinvokes | 列出程序集中的所有P/Invoke(DllImport)声明 | assemblyPath |
find_attributes | 查找用特定属性装饰的所有类型和方法 | assemblyPath, attributeName |
get_methods_for_type | 获取特定类型上定义的所有方法 | assemblyPath, typeName |
decompile_assembly | 将整个程序集解压缩为C#源代码 | assemblyPath |
decompile_type | 将特定类型解压缩为C#源代码 | assemblyPath, typeName |
decompile_method | 将特定方法分解为C#源代码 | assemblyPath, typeName, methodName |
dump_il | 倾倒IL(CIL)拆卸整个组件、类型或特定方法 | assemblyPath, typeName?, methodName? |
inspect_type | 检查类型的结构:字段、方法、属性、接口,可选地使用源代码 | assemblyPath, typeName, includeSource? |
inspect_method | 检查特定方法:签名、参数、反编译源代码,可选IL | assemblyPath, typeName, methodName, includeSource?, includeIL? |
list_types | 列出程序集中的所有类型定义 | assemblyPath |
find_methods | 在程序集中查找方法,可选择按名称模式筛选 | assemblyPath, pattern? |
search_strings | 在程序集的反编译源代码中搜索字符串文字 | assemblyPath, pattern, useRegex? |
search_members | 按名称模式搜索类型、方法、字段和属性 | assemblyPath, pattern |
set_breakpoint | 在特定IL偏移处的方法上设置虚拟断点 | assemblyPath, typeName, methodName, ilOffset |
list_breakpoints | 列出所有活动虚拟断点 | |
inspect_breakpoint | 在断点偏移处显示IL,推断堆栈类型,并找到该方法的所有调用者 | id |
clear_breakpoints | 删除所有虚拟断点或按id删除特定断点 | id? |
detect_anti_debug | 静态分析,检测7个类别的反调试技术 | assemblyPath |
detect_anti_tamper | 用于检测混淆和防篡改保护的静态分析 | assemblyPath |
get_protection_report | 将防调试和防篡改分析汇总到一份报告中,其中包含风险评分(0-10)和绕过建议 | assemblyPath |
保护分析
detect_anti_debug, detect_anti_tamper,以及 get_protection_report 仅执行静态分析。目标程序集从不作为加载。NET类型,从不JIT编译,也从不执行。分析使用ICSharpCode。仅提供反编译器的类型系统和PE阅读器。
反调试检测类别
- 针对已知反调试API(IsDebuggerPresent、NtQueryInformationProcess等)的P/Invoke声明
- 托管API使用情况(System.Diagnostics.Debugger.IsAttached等)
- 基于时间的检查(秒表、GetTickCount、QueryPerformanceCounter模式)
- 线程隐藏(带ThreadHideFromDebugger的NtSetInformationThread)
- TLS回调存在(在主入口点之前执行)
- 硬件断点检测(CONTEXT Dr0-Dr3读取)
- 基于异常的反调试模式
防篡改检测类别
- 模糊器指纹识别(ConfusedEx、Dotfuscator、Eazfuscator、.NET Reactor、SmartAssembly、KoiVM等10+)
- 名称混淆启发式(控制字符、零宽度字符、饱和度)
- 字符串加密存根(cctor数组初始化模式,int到字符串解密方法签名)
- 控制流混淆(切换代理,高goto密度)
- 完整性检查(自哈希、自身程序集上的File.ReadAllBytes、哈希比较后的终止)
- VM/虚拟化(大型交换机调度程序、加密IL存根)
- 包装(PE部分名称:UPX、MPRESS、.vmp0、Themida等)
风险评分
get_protection_report 计算风险评分(0-10):
- 高严重性/置信度发现:+1.5分
- 中等:+0.75分
- 低点:+0.25点
- 上限为10
项目结构
src/DnSpyMcp/
├── Program.cs
├── Core/
│ ├── AssemblyCache.cs Thread-safe decompiler cache (keyed by path + mtime)
│ └── BreakpointRegistry.cs In-memory virtual breakpoint store
├── Models/
│ └── Results.cs All result record types
└── Tools/
├── Analysis/
│ ├── AnalysisTools.cs PE info, resources, token resolution, P/Invokes, attributes
│ ├── BreakpointTools.cs Virtual breakpoints: set, list, inspect, clear
│ ├── DecompileTools.cs C# decompilation, IL disassembly
│ ├── InspectTools.cs Type and method inspection
│ └── SearchTools.cs Type/method/member/string search
└── Security/
├── AntiDebugTools.cs Anti-debug pattern detection
├── AntiTamperTools.cs Obfuscation and anti-tamper detection
└── ProtectionReportTools.cs Aggregated protection report已知问题
Analysis of heavily obfuscated assemblies may produce false positives in name obfuscation heuristics
名称混淆检测器用单字母名称或编译器生成的名称(包含 ``).标准。NET编译器生成的类型(lambda闭包、异步状态机)将导致混淆名称比率。阈值设置为30%以减少噪声,但大量使用泛型或LINQ的程序集仍可能触发它。
String encryption detection requires obfuscated method names
字符串解密方法检测器仅在方法名称本身被混淆(包含控制字符或是单个字母)时才会触发。如果保护程序为其字符串解密例程使用可读的方法名,则此检查将无法检测到它们。cctor数组初始化模式不受影响。
Assembly resolver errors on assemblies with missing dependencies
ICSharpCode。反编译器尝试从与目标相同的目录中解析引用的程序集。如果缺少依赖项,受影响方法的反编译将退回到部分输出或跳过。PE级操作(get_pe_info, get_resources, resolve_token, list_pinvokes)不受影响。 ThrowOnAssemblyResolveErrors 默认设置为false以抑制解析器错误。
P/Invoke entry point detection is limited to DllImportAttribute
这 list_pinvokes 防调试P/Invoke扫描程序仅检测用 [DllImport].使用动态P/Invoke模式 NativeLibrary.Load + GetExport, GetProcAddress 通过 Marshal,或手动构建的委托函数指针将不会被检测到。
学分
轻松检测(DIE)
保护检测逻辑 Tools/Security/ 直接从所使用的检测方法中提取 轻松检测 由霍西克。
DIE的核心见解——保护器指纹识别应该对原始二进制字节模式、PE段元数据和元数据字符串堆搜索进行操作,而不是对源代码进行反编译——是该项目亚毫秒检测性能的基础。几个混淆器签名(ConfusedEx、Eazuscator、KoiVM、.NET Reactor、VMProtect、Dotfuscator、MPRESS、Themida等)是从DIE的PE签名脚本改编而来的 db/PE/.DIE由horsicq和贡献者维护,并在MIT许可下可用。
反调试研究
反调试检测类别和API覆盖范围由以下内容通知:
- 孟加拉1994年, 使用进行反调试。NET在Windows环境下的应用 --PEB字段检查(BeingDebugged、NtGlobalFlag、堆标志/ForceFlags)、StartupInfo.lpDesktop、NtCreateThreadEx线程隐藏
- hsheric0210, Antidebug。净 --全面。NET反调试和反VM技术参考,涵盖动态IAT解析、手动模块映射和钩子绕过模式
- 检查点研究, 反调试技巧 --通过AntiDebug引用。网
