|
传统 Android 逆向分析常常需要在 Jadx (反编译工具) 和各种笔记/编辑器之间来回切换。随着大模型和 MCP(Model Context Protocol,模型上下文协议)的普及,我们现在可以直接在 VS Code 中,通过自然语言让 GitHub Copilot 远程调用 Jadx 来帮我们反编译、搜索代码、甚至直接分析出加密算法和 Flag!
这篇博客将手把手教你如何搭建这套工作流。
一、前期准备:下载并运行 Jadx-MCP 插件
jadx-mcp 是一个桥接服务,它通过在本地启动一个 Python 或 Java 服务器,将 Jadx 的 API(例如获取 Class 源码、搜索关键词、获取 AndroidManifest)暴露给外部大模型客户端(如 VS Code 中的 Copilot 或 Cline)。
1. 软件环境
- 安装 Java (JDK 11+):用于运行 Jadx 本体。
- 安装 Python (3.10+):MCP 桥接服务通常基于 Python (FastMCP) 构建。
- 下载 Jadx-MCP 服务包:获取对应的
jadx-mcp-server-vX.X.X.zip 以及 Jadx 本体(部分封装版直接将它作为 Jadx 插件发布,如 jadx-ai-mcp-x.x.x.jar)。
2. 初始化核心依赖 (Python端)
如果你拿到的 jadx-mcp 是一个带有 jadx_mcp_server.py 的解压包,你需要先在终端为其安装环境依赖。
打开命令行(以刚才的解压目录为例):
# 激活你的 Python 环境 (如果你有虚拟环境)
# 必须安装 fastmcp 及其网络依赖包
pip install pydantic fastapi httpx "fastmcp>=3.0.2" -U
排坑避坑:如果你使用的是 java -jar jadx-ai-mcp.jar 遇到 no main manifest attribute 闪退报错,请务必确认该 jar 文件只是个由 Jadx GUI 挂载的插件(默认在 8650 端口通信)。你实际需要让 Copilot 运行的是那个 .py 的桥接服务端脚本。
二、配置 VS Code:将 Jadx 注册进 Copilot 大脑
GitHub Copilot 及同类 AI 插件(如 Claude Dev/Roo Code)都是通过读取 VS Code 的全局 mcp.json 配置文件来加载外部工具的。我们需要将 Jadx 服务手动注入其中。
1. 修改全局 MCP 配置文件
找到并打开你的 VS Code mcp.json 文件。
- Windows 路径:
C:\Users\<你的用户名>\AppData\Roaming\Code\User\mcp.json
- macOS 路径:
~/Library/Application Support/Code/User/mcp.json
(如果该文件不存在,新建一个即可)
2. 注入 jadx-mcp 节点配置
在 "servers" JSON 对象中,新增 jadx-mcp 的配置。以下是经过实测的完美跑通配置(请注意将路径替换为你本地真实的 Python 路径和服务脚本路径):
{
"servers": {
"jadx-mcp": {
"isActive": true,
"command": "D:\\Programs\\Python\\Python310\\python.exe",
"args": [
"D:\\Programs\\Android Reverse\\jadx-mcp\\jadx-mcp-server-v6.2.0\\jadx-mcp-server\\jadx_mcp_server.py"
],
"timeout": 1800,
"disabled": false,
"autoApprove": [
"fetch_current_class",
"get_selected_text",
"get_method_by_name",
"get_all_classes",
"get_class_source",
"search_method_by_name",
"get_methods_of_class",
"search_classes_by_keyword",
"get_fields_of_class",
"get_smali_of_class",
"get_manifest_component",
"get_android_manifest",
"get_strings",
"get_all_resource_file_names",
"get_resource_file",
"get_main_application_classes_names",
"get_main_application_classes_code",
"get_main_activity_class",
"get_xrefs_to_class",
"get_xrefs_to_method",
"get_xrefs_to_field"
],
"alwaysAllow": [
"fetch_current_class",
"get_selected_text",
"get_method_by_name",
"get_all_classes",
"get_class_source",
"search_method_by_name",
"get_methods_of_class",
"search_classes_by_keyword",
"get_fields_of_class",
"get_smali_of_class",
"get_manifest_component",
"get_android_manifest",
"get_strings",
"get_all_resource_file_names",
"get_resource_file",
"get_main_application_classes_names",
"get_main_application_classes_code",
"get_main_activity_class",
"get_xrefs_to_class",
"get_xrefs_to_method",
"get_xrefs_to_field"
],
"name": "jadx-mcp"
}
}
}
设定说明:autoApprove / alwaysAllow 列表里的工具名(如 get_class_source 等)意味着 Copilot 在调用 Jadx 拉取代码时,不需要每次都弹窗要求你手动点击“Allow”。这是实现自动化行云流水体验的关键。
3. 重启 VS Code 生效
配置写完毕后,必须要重启 VS Code。
可以直接使用快捷键 Ctrl+Shift+P -> 输入 Reload Window (重新加载窗口)。
三、神力初现:实战应用体验
配置完成后,Jadx 强大的逆向功能就已经内化进 Copilot 里了。
工作流协同演示:
- 获取应用样本:从雷电模拟器或手机中提取出待分析的 APK 文件,用运行着 MCP 插件的 Jadx-GUI 将其打开。
- 呼唤 AI:在 VS Code 打开 Copilot Chat,你可以像跟专业逆向工程师对话一样发送指令了。
转载请注明来源 Joyooosama - 博客园!
来源:https://www.cnblogs.com/Joyooo/p/19842866 |