WeChat 4.0 macOS 数据库解密工具。从微信进程内存提取密钥,解密本地 SQLCipher 4 加密数据库。
Fork 自 ylytdeng/wechat-decrypt,适配 macOS。
WeChat 4.0 使用 SQLCipher 4 加密本地数据库:
- 加密: AES-256-CBC + HMAC-SHA512
- KDF: PBKDF2-HMAC-SHA512, 256,000 次迭代
- 页大小: 4096 bytes, reserve = 80 bytes (IV 16 + HMAC 64)
WCDB 在进程内存中缓存 raw key,格式为 x'<64hex_enc_key><32hex_salt>'。本工具扫描 WeChat 进程内存,匹配数据库文件的 salt,提取密钥后解密。
| 组件 | Windows 原版 | macOS 版 |
|---|---|---|
| 进程内存读取 | ReadProcessMemory / VirtualQueryEx |
task_for_pid / mach_vm_region / mach_vm_read |
| 进程查找 | tasklist |
pgrep |
| 数据库路径 | D:\xwechat_files\<wxid>\db_storage\ |
~/Library/Containers/com.tencent.xinWeChat/... |
| Session DB | session\session.db |
Session/session_new.db |
| Contact DB | contact\contact.db |
Contact/wccontact_new2.db |
| Message DB | message\message_N.db |
Message/msg_N.db |
pip3 install pycryptodome
# MCP server 额外需要:
pip3 install mcp zstandard# 确保 WeChat 正在运行且已登录
sudo python3 find_all_keys.py首次运行会自动检测 WeChat 数据目录并生成 config.json。
python3 decrypt_db.py解密后的数据库在 decrypted/ 目录,可用任何 SQLite 工具打开。
# CLI 模式 (每3秒轮询)
python3 monitor.py
# Web UI (SSE 实时推送)
python3 monitor_web.py
# 打开 http://localhost:5678将以下配置添加到 Claude Code 的 MCP 设置中:
{
"mcpServers": {
"wechat": {
"command": "python3",
"args": ["/path/to/wechat-decrypt-mac/mcp_server.py"]
}
}
}提供的 MCP 工具:
| 工具 | 功能 |
|---|---|
get_recent_sessions(limit) |
最近会话列表 |
get_chat_history(chat_name, limit) |
聊天记录(模糊匹配) |
search_messages(keyword, limit) |
全库关键词搜索 |
get_contacts(query, limit) |
联系人搜索 |
get_new_messages() |
增量新消息 |
~/Library/Containers/com.tencent.xinWeChat/
Data/Library/Application Support/com.tencent.xinWeChat/
<version>/
<user_hash>/
├── Session/session_new.db # 会话列表
├── Contact/wccontact_new2.db # 联系人
├── Message/
│ ├── msg_0.db ~ msg_9.db # 聊天记录
│ ├── fileMsg.db # 文件消息
│ ├── mediaData/mediaData.db # 媒体索引
│ └── fts/ftsmessage.db # 全文搜索索引
├── Group/group_new.db # 群信息
├── Favorites/favorites.db # 收藏
└── ...
- 需要 sudo 权限读取 WeChat 进程内存
- WeChat 必须正在运行且已登录
- 密钥在 WeChat 重启后可能变化,需重新提取
- 此工具仅用于访问你自己的聊天数据
MIT