Commit Graph

14 Commits

Author SHA1 Message Date
Dru / Lu Rui
d86e0acad1 feat: macOS 自动检测微信数据目录 + 部署排错文档 (#80)
* feat: macOS 自动检测微信数据目录

新增 _auto_detect_db_dir_macos() 函数,搜索 ~/Library/Containers/ 下的
xwechat_files/*/db_storage 目录,按 mtime 排序优先最近活跃账号。

同时改进检测失败时的提示信息,macOS 给出正确的默认路径格式。

* docs: 记录 macOS 部署常见问题及修复方案

记录 task_for_pid failed:5、自动检测 db_dir 失败、
PEP 668 pip 安装拒绝三个问题的现象、原因和解决方法,
附完整 macOS 部署流程和修复状态汇总。

* docs: 增强 README macOS 部署说明和常见问题

- 安装依赖部分补充 PEP 668 虚拟环境解决方案
- 修正 macOS db_dir 路径为正确的 xwechat_files 格式
- 快速开始增加重签名前退出微信的步骤
- 新增 macOS 密钥扫描常见问题排错章节
  - task_for_pid failed:5 的原因和完整排查步骤
  - 自动检测数据目录失败的临时解决方案

---------

Co-authored-by: drulu <drulu@tencent.com>
2026-05-12 16:18:30 +08:00
Belugary
1841be6419 fix: config.json 路径字段支持 ~ / 环境变量展开 (#63)
## 问题

`load_config()` 目前对路径只做"绝对或项目根相对"的二分。如果用户在
config.json 里写 `~/Documents/wechat_decrypted` 或 `$HOME/wechat`,会被当成
项目相对,join 后变成 `<repo>/~/Documents/wechat_decrypted`(字面 `~` 目录),
静默错路径,无报错。

复现:
```json
{ "decrypted_dir": "~/Documents/wechat_decrypted" }
```
当前行为:解密文件落到 `<repo>/~/Documents/wechat_decrypted/`。

## 修改

`config.py` 中 `load_config()` 末段:对 `db_dir` / `keys_file` /
`decrypted_dir` / `decoded_image_dir` 四个字段先 `expanduser` + `expandvars`,
再判 `isabs`。+9 / -3 行,纯 stdlib。

顺手把 `if key in cfg` 改成 `if cfg.get(key)`,避免 `null` / `""` 触发
`TypeError`(原本就是边界 bug,这次顺手收掉)。

## 兼容性

- 已有绝对路径(`D:\\xwechat_files\\...` / `/Users/x/...`):不变
- 已有项目相对(`"all_keys.json"`):不变
- 新增支持:`~/...` / `$HOME/...` / `%USERPROFILE%\\...`
- 跨 Windows / Linux / macOS 一致(`expanduser` / `expandvars` 在三平台
  对无 `~` / 无 `$` / 无 `%` 的路径都是 no-op)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 17:07:01 +08:00
btc-z
66eddaff0e feat: transcribe_voice 新增 OpenAI Whisper API 后端 (#66)
默认 local,零行为变化。opt-in 双因素:transcription_backend=openai
且 openai_api_key 都齐才生效;任一缺失静默回退 local + stderr 一行警告。
首次进入云路径会 stderr 警告"语音将上传至 OpenAI 服务器"。

新增 config.json 字段:
- transcription_backend: "local" (默认) | "openai"
- local_whisper_model: "base" (替换 mcp_server.py 里硬编码 DEFAULT_WHISPER_MODEL)
- openai_api_key: "" (默认空;openai 包为 optional,按需 pip install)

关键技术选择:
- _transcribe(wav, backend) 单一 if/else 分发,不引入插件/工厂层
  (Rule of Three —— 只有一个云后端时不值得抽象)
- 文件 > 25MB 在 OpenAI() 实例化之前提前拒绝,避免无谓上传
- 错误分类清晰: 缺 key / 缺 openai 包 / 401 / 429 / APIError 各自的提示
- PR #58 缓存 schema 自然扩展: 条目加 backend 字段,命中需 backend+model_size 都匹配
- 旧条目缺 backend 字段视为 "local",向前兼容 PR #58 已落盘的所有数据
- transcribe_chat.py 批量 CLI 与 MCP 工具共享同一份配置,保持一致

新增 2 个测试 (tests/test_openai_backend.py),只覆盖回归风险最高的两条:
- 文件 > 25MB 必须在 SDK 实例化前拒绝(隐私契约的防线)
- backend 不匹配的旧条目不命中(避免切后端时返回错后端结果)

其余路径要么琐碎(默认值读取)、要么坏掉时声音很大(SDK 错误、ImportError),
要么已被 PR #58 现有测试隐式覆盖(缺 backend 字段的旧条目),不再单独写测试。

顺手把 README 里 PR #53 漏掉的 voice 三件套(get_voice_messages /
decode_voice / transcribe_voice)补进 MCP 工具表,并新增"⚠️ 语音转录隐私"
章节说清数据流向、成本(约 \$0.006/分钟)、25MB 上限、回退行为。

Closes ylytdeng/wechat-decrypt#59
2026-05-01 13:56:32 +08:00
ylytdeng
944546beb1 fix: 统一所有 JSON 文件读写为 UTF-8 编码
Windows 中文环境默认编码为 GBK,未指定 encoding 会导致
config.json/all_keys.json 解析失败。修复 9 个文件共 17 处。

Closes #32

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 14:32:37 +08:00
PeanutSplash
30112b9a10 fix(linux): address code review feedback
- SUDO_USER: skip fallback entirely when user is invalid (KeyError)
- load_config: move default merge after db_dir check to avoid dead code
- _is_wechat_process: prefer exact comm match, use exe substring as fallback
2026-03-07 21:35:24 +08:00
PeanutSplash
3d58b6508c fix(linux): validate SUDO_USER and use prefix matching for interpreters
- Validate SUDO_USER via pwd.getpwnam() to prevent path injection
- Use prefix matching for interpreter detection to cover python3.10+ etc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 21:35:24 +08:00
PeanutSplash
bf77cc97d8 refactor(linux): improve wechat detection and sudo db path fallback 2026-03-07 21:35:24 +08:00
PeanutSplash
6d9b2c0fe4 refactor(find_all_keys): extract shared key scan logic 2026-03-07 21:35:24 +08:00
PeanutSplash
f9c338b48d feat: add Linux support with cross-platform memory scanning
- Add Linux memory scanner (`find_all_keys_linux.py`) using `/proc/<pid>/mem`,
  same approach as Windows/macOS — no GDB, no function offsets, no restart needed
- Extract Windows-specific code to `find_all_keys_windows.py`
- Make `find_all_keys.py` a platform dispatcher (Windows / Linux)
- Add `key_utils.py` for cross-platform path matching (`/` vs `\` in all_keys.json)
- Update `config.py` with Linux auto-detection of db_storage paths
- Update all consumers (decrypt_db, monitor, monitor_web, mcp_server) to use
  `get_key_info()` for platform-agnostic key lookup

Tested on remote Linux container: 15/15 DBs scanned, decrypted, and verified.
2026-03-07 21:35:24 +08:00
PeanutSplash
fd4a2fce31 fix(config): handle corrupted config file and improve encoding detection 2026-03-03 22:49:03 +08:00
PeanutSplash
eb6471d42c fix: Updated prompt messages for detecting multiple data directories and added instructions for users to select their current WeChat account. 2026-03-03 22:23:41 +08:00
PeanutSplash
2fa95b283f feat: Added automatic detection of WeChat data directories and optimized configuration loading process 2026-03-03 21:42:31 +08:00
ylytdeng
da7525db95 Add image decryption and inline preview for WeChat V2 format
Support all three .dat encryption formats:
- Old XOR format: single-byte XOR, auto-detect key from magic bytes
- V1 format: AES-ECB with fixed key (md5("0")[:16]) + XOR tail
- V2 format (2025-08+): AES-128-ECB + raw middle + XOR tail

New files:
- decode_image.py: unified image decryption module (XOR/V1/V2)
- find_image_key.py: extract AES key from WeChat process memory
- find_image_key_monitor.py: continuous monitoring version for key capture

monitor_web.py changes:
- Inline image preview in Web UI with async decryption
- MonitorDBCache for mtime-based DB decryption caching
- username-to-DB mapping for image resolution chain
- /img/ endpoint for serving decoded images
- SSE image_update events for real-time preview updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 00:30:01 +08:00
joshua-deng
4c91eb34ef WeChat 4.0 database decryptor and real-time message monitor
Extract encryption keys from Weixin.exe process memory, decrypt all
SQLCipher 4 databases, and monitor new messages via Web UI with ~100ms latency.
2026-02-28 12:03:38 +08:00