WeChat local data CLI with daemon architecture
 
 
 
 
Go to file
jackwener e44990ba01 fix: drop privileges after key scan to avoid root-owned ~/.wx-cli/ (#7 #8)
Root cause: `wx init` does two conceptually-separate things in one
privileged process: (1) scan WeChat memory for keys (needs root) and
(2) write ~/.wx-cli/{all_keys,config}.json (needs only user). When
run under sudo, the files inherit root ownership, so later the daemon
(forked as the user) can't create daemon.sock/log/pid → silent 15s
timeout.

Also: all_keys.json is the raw AES key; 0644 leaked it to every user
on the system.

Fix in init.rs: after the scan completes, immediately setgid+setuid
back to \$SUDO_UID/\$SUDO_GID and set umask 0o077 before any file I/O.
Files are then created as the real user with 0600 by default. Migrate
old broken installs by chown+chmod-recursive before the setuid call.

Fix in transport.rs: pre-check that ~/.wx-cli/ is writable before
spawning daemon; on EACCES print a clear "sudo chown -R ..." hint
instead of the useless "daemon 启动超时" message.
2026-04-18 01:48:42 +08:00
.claude chore: 从 index 移除编译产物和 worktree 子仓库 2026-04-16 14:48:19 +08:00
.github/workflows chore: bump to 0.1.5, fix publish to skip already-published versions 2026-04-17 09:25:04 +08:00
docs fix: replace nonexistent scan_keys.js with actual tools in quickstart 2026-03-05 23:26:55 +08:00
npm chore: bump version to 0.1.7 2026-04-17 16:42:02 +08:00
src fix: drop privileges after key scan to avoid root-owned ~/.wx-cli/ (#7 #8) 2026-04-18 01:48:42 +08:00
.gitignore chore: 从 index 移除编译产物和 worktree 子仓库 2026-04-16 14:48:19 +08:00
AGENTS.md docs: add CLAUDE.md and AGENTS.md with cross-platform check rules 2026-04-16 23:38:47 +08:00
CLAUDE.md docs: add Windows cross-check setup and IPC same-library rule 2026-04-17 16:43:05 +08:00
Cargo.lock chore: bump version to 0.1.7 2026-04-17 16:42:02 +08:00
Cargo.toml chore: bump version to 0.1.7 2026-04-17 16:42:02 +08:00
LICENSE chore: Apache-2.0 license, Windows support, install.ps1 2026-04-16 22:30:45 +08:00
README.md docs: emphasize YAML is more token-efficient, JSON for jq 2026-04-17 11:19:35 +08:00
SKILL.md fix(skill): add YAML frontmatter to SKILL.md so `skills` CLI can detect it 2026-04-17 13:27:07 +09:00
config.example.json feat: add Linux support with cross-platform memory scanning 2026-03-07 21:35:24 +08:00
install.ps1 chore: Apache-2.0 license, Windows support, install.ps1 2026-04-16 22:30:45 +08:00
install.sh chore: add install.sh one-liner installer 2026-04-16 22:21:11 +08:00

README.md

wx-cli

从命令行查询本地微信数据

License: Apache-2.0 Platform Rust

会话 · 聊天记录 · 搜索 · 联系人 · 群成员 · 收藏 · 统计 · 导出


AI Agent Skill

通过 skills CLI 一键安装到 Claude Code、Cursor、Codex 等 agent

npx skills add jackwener/wx-cli

或全局安装:

npx skills add jackwener/wx-cli -g

安装后 agent 会自动读取 SKILL.md,了解如何安装和调用 wx-cli。


特性

  • 零依赖安装 — 单一 Rust 二进制,一行命令装完
  • 毫秒级响应 — 后台 daemon 持久缓存解密数据库mtime 不变则复用
  • AI 友好 — 默认 YAML 输出,更省 token & 易读;--json 可切换为 JSON方便 jq 处理等)
  • 完全本地 — 数据不出本机,实时解密,无需全量预解密

安装

npm推荐全平台

npm install -g @jackwener/wx-cli

macOS / Linuxcurl

curl -fsSL https://raw.githubusercontent.com/jackwener/wx-cli/main/install.sh | bash

WindowsPowerShell以管理员身份运行

irm https://raw.githubusercontent.com/jackwener/wx-cli/main/install.ps1 | iex
其他安装方式

手动下载

Releases 下载对应平台文件:

平台 文件
macOS Apple Silicon wx-macos-arm64
macOS Intel wx-macos-x86_64
Linux x86_64 wx-linux-x86_64
Linux arm64 wx-linux-arm64
Windows x86_64 wx-windows-x86_64.exe

macOS / Linuxchmod +x wx && sudo mv wx /usr/local/bin/

从源码构建

git clone git@github.com:jackwener/wx-cli.git && cd wx-cli
cargo build --release
# 产物target/release/wxWindows: wx.exe

快速开始

保持微信运行,然后初始化(只需一次):

macOS(需要先对微信做 ad-hoc 签名,才能扫描其内存)

# 1. 签名只需做一次WeChat 更新后重做)
codesign --force --deep --sign - /Applications/WeChat.app

# 2. 重启微信,等待完全登录
killall WeChat && open /Applications/WeChat.app

# 3. 初始化
sudo wx init

如果 codesignsignature in use,先执行:

codesign --remove-signature "/Applications/WeChat.app/Contents/Frameworks/vlc_plugins/librtp_mpeg4_plugin.dylib"
codesign --force --deep --sign - /Applications/WeChat.app

Linux

sudo wx init

Windows(以管理员身份运行 PowerShell

wx init

验证安装:

wx sessions

能看到最近会话即表示一切正常。daemon 在首次调用时自动启动。


命令

消息

wx sessions                                      # 最近 20 个会话
wx unread                                        # 有未读消息的会话
wx new-messages                                  # 上次检查后的新消息(增量)
wx history "张三"                                # 最近 50 条记录
wx history "AI群" --since 2026-04-01 --until 2026-04-15
wx search "关键词"                               # 全库搜索
wx search "会议" --in "工作群" --since 2026-01-01

联系人 & 群组

wx contacts                  # 联系人列表
wx contacts --query "李"     # 按名字搜索
wx members "AI交流群"        # 群成员列表

收藏 & 统计

wx favorites                          # 全部收藏
wx favorites --type image             # 按类型筛选text/image/article/card/video
wx favorites --query "关键词"         # 搜索收藏内容
wx stats "AI群"                       # 聊天统计
wx stats "AI群" --since 2026-01-01   # 指定时间范围

导出

wx export "张三" --format markdown -o chat.md
wx export "AI群" --since 2026-01-01 --format json

输出格式

默认输出 YAML更省 token & 易读;--json 可切换为 JSON方便 jq 处理等):

wx sessions --json
wx search "关键词" --json | jq '.[0].content'
wx new-messages --json

Daemon 管理

wx daemon status
wx daemon stop
wx daemon logs --follow

架构

wx (CLI) ──Unix socket──▶ wx-daemon (后台进程)
                              │
                    ┌─────────┴──────────┐
               DBCache               联系人缓存
           (mtime 感知复用)

daemon 首次解密后将数据库和 mtime 持久化到 ~/.wx-cli/cache/。重启后 mtime 未变则直接复用,无需重解密。

~/.wx-cli/
├── config.json       # 配置
├── all_keys.json     # 数据库密钥
├── daemon.sock       # Unix socket
├── daemon.pid / .log
└── cache/
    ├── _mtimes.json  # mtime 索引
    └── *.db          # 解密后的数据库

原理

微信 4.x 使用 SQLCipher 4 加密本地数据库AES-256-CBC + HMAC-SHA512PBKDF2 256,000 次迭代。WCDB 在进程内存中缓存派生后的 raw key格式为 x'<64hex_key><32hex_salt>'

wx-cli 通过 macOS Mach VM APImach_vm_region + mach_vm_read)或 Linux /proc/<pid>/mem 扫描微信进程内存匹配该模式提取密钥daemon 按需解密并缓存。


致谢

本项目受 ylytdeng/wechat-decrypt 启发,在其基础上进行了重新设计与实现。感谢原作者的研究与探索。


免责声明

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