WeChat 4.0 Database Decryptor logo

WeChat 4.0 Database Decryptor

Community
328336690

微信4.0数据库解密工具 | WeChat 4.0 Database Decryptor — memory-based key extraction, real-time message monitoring, MCP Server for Claude AI

Publisher328336690
Repositorywechat-decrypt
LanguagePython
Forks
60
Stars
70
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    WeChat 4.0 Database Decryptor exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    70 stars and 60 forks from the linked repository.

WeChat 4.0 Database Decryptor

License: MIT Python 3.10+ Platform PRs Welcome CI

微信 4.0 (Windows) 本地数据库解密工具。从运行中的微信进程内存提取加密密钥,解密所有 SQLCipher 4 加密数据库,并提供实时消息监听。

原理

微信 4.0 使用 SQLCipher 4 加密本地数据库:

  • 加密算法: AES-256-CBC + HMAC-SHA512
  • KDF: PBKDF2-HMAC-SHA512, 256,000 iterations
  • 页面大小: 4096 bytes, reserve = 80 (IV 16 + HMAC 64)
  • 每个数据库有独立的 salt 和 enc_key

WCDB (微信的 SQLCipher 封装) 会在进程内存中缓存派生后的 raw key,格式为 x'<64hex_enc_key><32hex_salt>'。本工具通过扫描进程内存中的这种模式,匹配数据库文件的 salt,并通过 HMAC 验证来提取正确的密钥。

使用方法

环境要求

  • Windows 10/11
  • Python 3.10+
  • 微信 4.0 (正在运行)
  • 需要管理员权限 (读取进程内存)

安装依赖

bash
pip install pycryptodome

1. 配置

复制配置模板并修改:

bash
copy config.example.json config.json

编辑 config.json:

json
{
    "db_dir": "D:\\xwechat_files\\你的微信ID\\db_storage",
    "keys_file": "all_keys.json",
    "decrypted_dir": "decrypted",
    "wechat_process": "Weixin.exe"
}

db_dir 路径可以在 微信设置 → 文件管理 中找到。

2. 提取密钥

确保微信正在运行,以管理员权限运行:

bash
python find_all_keys.py

密钥将保存到 all_keys.json。

3. 解密数据库

bash
python decrypt_db.py

解密后的数据库保存在 decrypted/ 目录,可以直接用 SQLite 工具打开。

4. 实时消息监听

Web UI (推荐)

bash
python monitor_web.py

打开 http://localhost:5678 查看实时消息流。

  • 30ms 轮询 WAL 文件变化 (mtime)
  • 检测到变化后全量解密 + WAL patch (~70ms)
  • SSE 实时推送到浏览器
  • 总延迟约 100ms
  • 图片消息内联预览(支持旧 XOR / V1 / V2 三种 .dat 加密格式)

命令行

bash
python monitor.py

每 3 秒轮询一次,在终端显示新消息。

5. MCP Server (Claude AI 集成)

将微信数据查询能力接入 Claude Code,让 AI 直接读取你的微信消息。

bash
pip install mcp

注册到 Claude Code:

bash
claude mcp add wechat -- python C:\Users\你的用户名\wechat-decrypt\mcp_server.py

或手动编辑 ~/.claude.json:

json
{
  "mcpServers": {
    "wechat": {
      "type": "stdio",
      "command": "python",
      "args": ["C:\\Users\\你的用户名\\wechat-decrypt\\mcp_server.py"]
    }
  }
}

注册后在 Claude Code 中即可使用以下工具:

Tool功能
get_recent_sessions(limit)最近会话列表(含消息摘要、未读数)
get_chat_history(chat_name, limit)指定聊天的消息记录(支持模糊匹配名字)
search_messages(keyword, limit)全库搜索消息内容
get_contacts(query, limit)搜索/列出联系人
get_new_messages()获取自上次调用以来的新消息

前置条件:需要先完成步骤 1-2(配置 + 提取密钥)。

查看使用案例 →

6. 图片解密 (V2 格式)

微信 4.0 (2025-08+) 的 .dat 图片文件使用 AES-128-ECB + XOR 混合加密 (V2 格式)。AES 密钥需要从运行中的微信进程内存中提取:

bash
# 1. 在微信中打开查看 2-3 张图片(点击看大图)
# 2. 立即运行密钥提取(持续监控版):
python find_image_key_monitor.py

# 或单次扫描版:
python find_image_key.py

密钥会自动保存到 config.json 的 image_aes_key 字段。之后 monitor_web.py 启动时会自动加载密钥,图片消息将显示内联预览。

注意: AES 密钥仅在微信查看图片时临时加载到内存中。如果扫描未找到密钥,请先在微信中查看几张图片,然后立即重新运行脚本。

文件说明

文件说明
config.py配置加载器
find_all_keys.py从微信进程内存提取所有数据库密钥
decrypt_db.py全量解密所有数据库
mcp_server.pyMCP Server,让 Claude AI 查询微信数据
monitor_web.py实时消息监听 (Web UI + SSE + 图片预览)
monitor.py实时消息监听 (命令行)
decode_image.py图片 .dat 文件解密模块 (XOR / V1 / V2)
find_image_key.py从微信进程内存提取图片 AES 密钥
find_image_key_monitor.py持续监控版密钥提取(推荐)
latency_test.py延迟测量诊断工具

技术细节

WAL 处理

微信使用 SQLite WAL 模式,WAL 文件是预分配固定大小 (4MB)。检测变化时:

  • 不能用文件大小 (永远不变)
  • 使用 mtime 检测写入
  • 解密 WAL frame 时需校验 salt 值,跳过旧周期遗留的 frame

图片 .dat 加密格式

微信本地图片 (.dat) 有三种加密格式:

格式时期Magic加密方式密钥来源
旧 XOR~2025-07无单字节 XOR自动检测 (对比 magic bytes)
V1过渡期07 08 V1 08 07AES-ECB + XOR固定 key: cfcd208495d565ef
V22025-08+07 08 V2 08 07AES-128-ECB + XOR从进程内存提取

V2 文件结构: [6B signature] [4B aes_size LE] [4B xor_size LE] [1B padding] + [AES-ECB encrypted] [raw unencrypted] [XOR encrypted]

数据库结构

解密后包含约 26 个数据库:

  • session/session.db - 会话列表 (最新消息摘要)
  • message/message_*.db - 聊天记录
  • contact/contact.db - 联系人
  • media_*/media_*.db - 媒体文件索引
  • 其他: head_image, favorite, sns, emoticon 等

免责声明

本工具仅用于学习和研究目的,用于解密自己的微信数据。请遵守相关法律法规,不要用于未经授权的数据访问。

Installation

TypingMind
{
  "mcpServers": {
    "wechat-decrypt": {
      "command": "python",
      "args": [
        "C:\\Users\\你的用户名\\wechat-decrypt\\mcp_server.py"
      ]
    }
  }
}

Use WeChat 4.0 Database Decryptor MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once WeChat 4.0 Database Decryptor is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add WeChat 4.0 Database Decryptor as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the WeChat 4.0 Database Decryptor MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "wechat-decrypt": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the WeChat 4.0 Database Decryptor MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the WeChat 4.0 Database Decryptor MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use WeChat 4.0 Database Decryptor to help me with this task?
WeChat 4.0 Database Decryptor
Sure. I read it.
Here is what I found using WeChat 4.0 Database Decryptor.

Frequently asked questions

What is the WeChat 4.0 Database Decryptor MCP server used for?

WeChat 4.0 Database Decryptor is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use WeChat 4.0 Database Decryptor MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use WeChat 4.0 Database Decryptor with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use WeChat 4.0 Database Decryptor MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With WeChat 4.0 Database Decryptor connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect WeChat 4.0 Database Decryptor MCP to TypingMind?

WeChat 4.0 Database Decryptor runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does WeChat 4.0 Database Decryptor MCP provide in TypingMind?

WeChat 4.0 Database Decryptor exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use WeChat 4.0 Database Decryptor MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If WeChat 4.0 Database Decryptor requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇