HEHANG / KNOWLEDGE
wechat-decrypt-contributors
微信数据工具箱 / WeChat Decrypt Toolkit:本地数据库解密、实时监听与智能回复工作台。(说人话:微信AI回复)
仓库 README 快照,完整保留原文;功能和版本以仓库为准。Repository README snapshot. Check the repository for current versions and behavior.
GitHub ↗ · Python
微信数据工具箱 / WeChat Decrypt Toolkit
本项目在 Windows 本机读取和解密微信 4.x 数据库,提供实时消息监听、图片解密、聊天查询、AI 回复草稿和受控桌面自动发送。
This Windows-only toolkit reads and decrypts local WeChat 4.x databases and provides real-time monitoring, media decoding, chat queries, AI reply drafts, and controlled desktop sending.
中文说明
功能概览
- 实时监听微信新消息,使用 WAL 变化检测和 SSE 推送;
- 加载真实联系人与会话;
- 解密本地微信数据库和图片;
- 搜索联系人、聊天记录和最近消息;
- 调用 OpenAI 兼容模型生成 3 条回复草稿;
- 为白名单私聊配置受控自动发送;
- 提供演练模式、敏感词拦截、联系人冷却、发送上限、手动解锁和全局急停。
所有本地服务只监听 127.0.0.1,不会开放给局域网。项目不会修改微信原始数据库。
两个网页入口
启动完整工作台后使用:
| 入口 | 地址 | 用途 |
|---|---|---|
| 自动发送平台 | http://localhost:5678/#automation | 会话、AI 草稿、白名单、发送规则、演练和真实发送控制 |
| 监听后台 | http://localhost:5680/ | 查看监听核心收到的新消息和 SSE 状态 |
5678 是日常使用的主界面;5680 主要用于确认监听核心是否正常。
已验证环境
当前版本已在以下环境实际运行:
| 项目 | 版本 |
|---|---|
| Windows | Windows x64 |
| 微信桌面版 | 4.1.12.55,进程名 Weixin.exe |
| Python | 3.12.13 x64;支持 Python 3.10+ |
| 浏览器 | Chrome、Edge 或其他现代浏览器 |
微信升级可能改变数据库或内存结构。如果你的微信版本不同,建议先使用测试账号验证。
1. 下载项目
git clone https://github.com/2933684073/wechat-decrypt-contributors.git
cd wechat-decrypt-contributors也可以在 GitHub 点击 Code → Download ZIP,解压后进入项目目录。
2. 安装 Python 依赖
推荐使用独立虚拟环境:
python -m venv .venv
Set-ExecutionPolicy -Scope Process Bypass
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt验证依赖:
python -c "import Crypto, zstandard, win32crypt, win32clipboard; print('依赖正常')"3. 找到微信数据库目录
微信 4.x 的数据库目录通常类似:
<微信文件目录>\xwechat_files\<你的 wxid>\db_storage正确目录中通常可以看到:
session\session.db
contact\contact.db
message\message_0.db
message\message_resource.db如果找不到,可以在磁盘中搜索 session.db。不要选择本项目生成的 decrypted 目录。
4. 配置项目
Copy-Item config.example.json config.json
notepad config.json示例:
{
"db_dir": "D:\\WeChatData\\xwechat_files\\your_wxid\\db_storage",
"keys_file": "all_keys.json",
"decrypted_dir": "decrypted",
"decoded_image_dir": "decoded_images",
"wechat_process": "Weixin.exe"
}JSON 中的 Windows 路径必须使用双反斜杠 \\。
5. 提取数据库密钥
先启动并登录微信,打开几个最近会话,然后:
- 右键
01_extract_keys_as_admin_with_log.cmd; - 选择 以管理员身份运行;
- 等待扫描完成;
- 查看
find_all_keys.output.log; - 确认日志中至少出现
OK: session\session.db。
微信 4.1+ 会优先使用只读 Config.Cipher runtime 扫描。每个密钥都必须通过数据库第一页 HMAC 校验后才会写入 all_keys.json。
如果旧版扫描显示 0 hex模式,不一定是失败;应查看最终有多少条 OK:。提取器会保留仍然有效的旧密钥,也不会用空结果覆盖可用的密钥文件。
6. 初次解密数据库
.\.venv\Scripts\python.exe decrypt_db.py或直接运行 02_decrypt_and_start_web.cmd。
解密结果保存在 decrypted。该目录包含聊天数据,不要上传或分享。
7. 启动完整工作台
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\start_workspace.ps1也可以双击 05_start_workspace.cmd。
启动脚本会依次启动:
monitor_web_core.py:监听核心,端口5680;wechat_workspace.py:自动发送与 AI 工作台,端口5678。
只有监听核心成功启动后,工作台才会继续启动。出现问题时请查看:
monitor_core.stdout.log
monitor_core.stderr.log
workspace.stdout.log
workspace.stderr.log8. 验证实时监听
打开 监听后台,页面应显示正在等待新消息。
让另一个账号给当前微信发送一条新消息。新消息应同时出现在:
http://localhost:5680/监听后台;http://localhost:5678主工作台;monitor_core.stdout.log。
监听核心会把启动时已有消息作为基线,因此不会把所有旧消息重新推送一遍。请使用启动后收到的新消息测试。
9. 配置 AI 回复
打开 http://localhost:5678,点击 设置中心:
- 填写 OpenAI 兼容模型服务地址;
- 填写 API 密钥;
- 点击 检测 获取模型;
- 选择或填写模型名称;
- 设置回复风格、语气和上下文数量;
- 建议开启 仅未读来信触发;
- 点击 测试连接;
- 保存设置。
API 密钥使用当前 Windows 用户的 DPAPI 加密保存,不会在网页中回显明文。
10. 配置自动发送平台
打开 自动发送平台,或在左侧点击 自动化管理。
10.1 添加白名单
在左侧联系人列表中选择允许自动回复的私聊联系人,然后点击 保存全部规则。只有私聊联系人可以加入白名单,群聊不会自动回复。
10.2 设置发送规则
建议首次测试使用:
| 设置 | 建议值 |
|---|---|
| 白名单 | 只选择 1 个测试联系人 |
| 联系人冷却 | 30 秒或更长 |
| 统计窗口 | 300 秒 |
| 窗口内最多发送 | 1 条 |
| 敏感词拦截 | 开启 |
| 演练模式 | 开启 |
10.3 自动发送按钮在哪里
自动发送开关位于:
自动化管理 → 运行方式 → 启用自动发送模块
在同一个 运行方式 区域中还有:
- 启用自动发送模块:允许符合条件的消息进入发送流程;
- 演练模式(不执行桌面操作):只记录计划,不点击微信,也不发送;
- 保存全部规则:保存白名单和所有安全设置。
只勾选“启用自动发送模块”不会立即开启真实发送。默认仍处于演练模式。
11. 校准微信发送坐标
真实发送前必须校准:
- 保持微信主窗口可见,并固定窗口位置和大小;
- 双击
07_calibrate_sender.cmd; - 按提示记录微信搜索框中心;
- 记录搜索结果第一项中心;
- 记录消息输入框中心;
- 完成后生成
wechat_sender_calibration.json。
校准程序只读取鼠标坐标,不会点击或发送消息。更改分辨率、缩放比例、显示器或微信窗口布局后,需要重新校准。
12. 从演练切换到真实发送
请按顺序操作:
- 白名单只保留一个测试联系人;
- 在 自动化管理 → 运行方式 中勾选 启用自动发送模块;
- 保持 演练模式 开启并保存;
- 让测试联系人发送一条普通文本;
- 确认工作台生成了草稿,服务记录显示“演练”,微信没有发送;
- 完成坐标校准;
- 回到 自动化管理 → 运行方式,关闭 演练模式 并保存;
- 在右侧 自动发送控制 中点击 解锁真实自动发送;
- 确认安全提示;
- 再发送一条测试消息,检查联系人和回复是否正确。
真实自动发送必须同时满足:
- 新消息是私聊文本;
- 联系人在白名单中;
- 自动回复总开关已开启;
- 运行方式 → 启用自动发送模块 已勾选;
- 演练模式已关闭;
- 真实发送已经手动解锁;
- 坐标校准已完成;
- 未命中敏感词;
- 未触发冷却或发送上限;
- 微信已登录,Windows 桌面保持解锁。
系统会从 3 条 AI 草稿中选择第一条发送。
13. 立即急停
如果联系人、坐标或回复有任何异常,立即点击右侧的 立即急停。
急停后,后续消息不会真实发送,真实发送解锁状态也会被清除。恢复时必须先点击 恢复演练,完成演练验证后才能再次解锁。
14. 运行截图
15. 停止服务
双击 06_stop_workspace.cmd。脚本会按当前监听端口查找服务,避免因为 PID 被 Windows 复用而结束无关程序。
16. 常见问题
5678 打不开
Get-NetTCPConnection -State Listen -LocalPort 5678,5680
Get-Content .\monitor_core.stderr.log -Tail 80
Get-Content .\workspace.stderr.log -Tail 80如果 5680 没有启动,5678 也无法获得实时消息。
能看到会话,但没有新消息
请使用另一个账号发送一条启动后到达的新消息。旧会话只用于加载联系人列表,不会全部重新进入实时记录。
能生成草稿,但不发送
重点检查:
- 联系人是否已加入白名单;
- 自动发送按钮是否已在 自动化管理 → 运行方式 中开启;
- 是否仍处于演练模式;
- 是否点击了 解锁真实自动发送;
- 是否完成坐标校准;
- 是否命中敏感词或频率限制;
- 服务记录是否显示明确的拦截原因。
自动发送点错位置
立即急停,恢复演练,固定微信窗口后重新校准。当前实现会搜索联系人显示名并点击第一条结果,因此不要为重名联系人开启真实自动发送。
图片无法预览
文字监听只依赖 session 数据库。图片预览还需要消息资源密钥和图片密钥;可根据日志提示运行 find_image_key.py。
17. 主要文件
| 文件 | 用途 |
|---|---|
find_all_keys.py |
从微信进程只读提取并校验数据库密钥 |
decrypt_db.py |
解密微信数据库 |
monitor_web_core.py |
5680 实时监听核心 |
wechat_workspace.py |
5678 AI 与自动发送工作台 |
wechat_sender.py |
受控微信桌面发送层 |
calibrate_wechat_sender.py |
发送坐标校准 |
mcp_server.py |
为本地 AI 客户端提供查询接口 |
decode_image.py |
解密微信图片 |
docs/USER_GUIDE_ZH.md |
更完整的中文使用与排错说明 |
docs/CONTRIBUTOR_ONBOARDING.md |
贡献者开发指南 |
18. 隐私与安全
以下内容绝不能提交到 GitHub:
config.json;all_keys.json;smart_reply_config.json;wechat_sender_calibration.json;decrypted/和decoded_images/;- SQLite 数据库、运行日志、API 密钥和真实聊天截图。
提交前请执行:
git status --short
git check-ignore config.json all_keys.json smart_reply_config.json wechat_sender_calibration.json完整中文说明见 docs/USER_GUIDE_ZH.md。
English
What This Project Does
- Monitors new WeChat messages through WAL change detection and SSE;
- Loads real local contacts and sessions;
- Decrypts local WeChat databases and media;
- Searches contacts and chat history;
- Uses an OpenAI-compatible model to generate three reply drafts;
- Supports controlled desktop sending for whitelisted private chats;
- Includes dry-run, sensitive-term blocking, cooldowns, rate limits, explicit arming, and emergency stop.
All HTTP services bind to 127.0.0.1 only. The project does not modify the original WeChat databases.
Web Interfaces
| Interface | URL | Purpose |
|---|---|---|
| Automation platform | http://localhost:5678/#automation | Sessions, AI drafts, whitelist, safety rules, dry-run, and real-send controls |
| Monitor backend | http://localhost:5680/ | Live message feed and SSE monitor status |
Use port 5678 for normal operation. Port 5680 is mainly for checking the monitoring core.
Tested Environment
| Component | Version |
|---|---|
| Windows | Windows x64 |
| WeChat Desktop | 4.1.12.55, process name Weixin.exe |
| Python | 3.12.13 x64; Python 3.10+ supported |
| Browser | Chrome, Edge, or another modern browser |
1. Download and Install
git clone https://github.com/2933684073/wechat-decrypt-contributors.git
cd wechat-decrypt-contributors
python -m venv .venv
Set-ExecutionPolicy -Scope Process Bypass
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt2. Configure the Database Path
Copy-Item config.example.json config.json
notepad config.jsonSet db_dir to the current account's db_storage directory. It normally looks like:
<WeChat data root>\xwechat_files\<your wxid>\db_storageThe directory should contain files such as session\session.db, contact\contact.db, and message\message_0.db.
3. Extract Database Keys
Keep WeChat running and logged in. Right-click 01_extract_keys_as_admin_with_log.cmd and choose Run as administrator.
Check find_all_keys.output.log and make sure it includes:
OK: session\session.dbWeChat 4.1+ uses the read-only Config.Cipher runtime scan first. Every candidate must pass page-one HMAC verification before it is stored.
4. Decrypt the Databases
.\.venv\Scripts\python.exe decrypt_db.pyDecrypted files are written to decrypted. Never upload that directory.
5. Start the Full Workspace
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\start_workspace.ps1The launcher starts:
monitor_web_core.pyon127.0.0.1:5680;wechat_workspace.pyon127.0.0.1:5678.
Open the monitor backend and send a new message from another account to verify the live feed. Messages that existed before startup are used as the baseline and are not replayed as new events.
6. Configure the AI Model
Open http://localhost:5678 and select Settings:
- Enter an OpenAI-compatible API endpoint;
- Enter the API key;
- Detect or enter the model name;
- Configure reply style and context size;
- Keep “unread messages only” enabled for initial testing;
- Test the connection and save.
The API key is encrypted with Windows DPAPI for the current Windows user.
7. Configure Automation
Open the automation platform, or click Automation Management in the left navigation.
Add only one controlled test contact to the whitelist first. Groups are never eligible for automatic replies.
The auto-send switch is located at:
Automation Management → Run Mode → Enable Auto-Send Module
The same Run Mode section also contains Dry Run. With dry-run enabled, the system only records planned actions and never clicks or sends in WeChat.
Recommended initial settings:
| Setting | Recommended value |
|---|---|
| Whitelist | One controlled test contact |
| Per-contact cooldown | 30 seconds or longer |
| Rate window | 300 seconds |
| Maximum sends in the window | 1 |
| Sensitive-term blocking | Enabled |
| Auto-send module | Enabled |
| Dry run | Enabled |
8. Calibrate Desktop Sending
Keep the WeChat main window visible and fixed, then run 07_calibrate_sender.cmd.
Record these three positions as instructed:
- WeChat search box;
- First search result;
- Message input box.
The calibration tool only reads cursor coordinates. It does not click, type, or send.
Recalibrate after changing display resolution, scaling, monitor layout, or WeChat window position.
9. Enable Real Sending
Follow this order:
- Keep only one test contact in the whitelist;
- Enable Automation Management → Run Mode → Enable Auto-Send Module;
- Keep Dry Run enabled and save;
- Send a harmless test message from the test contact;
- Confirm that drafts are created but WeChat does not send anything;
- Complete coordinate calibration;
- Disable Dry Run and save;
- Click Unlock Real Auto-Send in the right-side send controls;
- Confirm the warning;
- Send another test message and verify the recipient and reply.
Real sending requires all of these conditions:
- A new private text message;
- A whitelisted contact;
- Automation enabled;
- Auto-send module enabled under Run Mode;
- Dry-run disabled;
- Real sending explicitly armed;
- Calibration completed;
- No sensitive-term or rate-limit block;
- WeChat logged in and the Windows desktop unlocked.
The first of the three generated AI drafts is selected for automatic sending.
10. Emergency Stop
Click Emergency Stop immediately if a contact, coordinate, or reply looks wrong. This disables later real sends and clears the armed state. Resume in dry-run mode, verify again, and only then re-arm.
11. Screenshots
The three screenshots are shown in the Chinese section above.
12. Stop the Services
Run 06_stop_workspace.cmd. It resolves the current listeners on ports 5678 and 5680 instead of blindly trusting stale PID files.
13. Troubleshooting
If port 5678 does not open:
Get-NetTCPConnection -State Listen -LocalPort 5678,5680
Get-Content .\monitor_core.stderr.log -Tail 80
Get-Content .\workspace.stderr.log -Tail 80If sessions load but no new messages appear, send a new message after the listener has started.
If drafts are generated but nothing is sent, verify the whitelist, Run Mode auto-send switch, dry-run state, real-send arm, calibration, sensitive-term block, and cooldown limits.
If desktop clicks target the wrong location, use Emergency Stop, return to dry-run, fix the WeChat window position, and recalibrate.
14. Privacy and Security
Never commit or upload:
config.json;all_keys.json;smart_reply_config.json;wechat_sender_calibration.json;decrypted/ordecoded_images/;- SQLite databases, logs, API keys, or real chat screenshots.
See docs/USER_GUIDE_ZH.md for the full Chinese guide and docs/CONTRIBUTOR_ONBOARDING.md for contributor documentation.
License
MIT License. See LICENSE for details.