Skip to content

kknd0/wechat-decrypt-mac

Repository files navigation

wechat-decrypt-mac

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,提取密钥后解密。

macOS 适配

组件 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

快速开始

1. 安装依赖

pip3 install pycryptodome
# MCP server 额外需要:
pip3 install mcp zstandard

2. 提取密钥 (需要 sudo)

# 确保 WeChat 正在运行且已登录
sudo python3 find_all_keys.py

首次运行会自动检测 WeChat 数据目录并生成 config.json

3. 解密数据库

python3 decrypt_db.py

解密后的数据库在 decrypted/ 目录,可用任何 SQLite 工具打开。

4. 实时消息监听

# CLI 模式 (每3秒轮询)
python3 monitor.py

# Web UI (SSE 实时推送)
python3 monitor_web.py
# 打开 http://localhost:5678

5. Claude MCP Server

将以下配置添加到 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() 增量新消息

数据库结构 (macOS)

~/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 重启后可能变化,需重新提取
  • 此工具仅用于访问你自己的聊天数据

License

MIT

About

WeChat 4.0 macOS database decryptor - extract keys from memory, decrypt SQLCipher 4 databases. Fork of ylytdeng/wechat-decrypt adapted for macOS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages