wx-cli/README.md

196 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<div align="center">
# wx-cli
**从命令行查询本地微信数据**
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey.svg)](#安装)
[![Rust](https://img.shields.io/badge/built%20with-Rust-orange.svg)](https://www.rust-lang.org)
会话 · 聊天记录 · 搜索 · 联系人 · 群成员 · 收藏 · 统计 · 导出
</div>
---
## 特性
- **零依赖安装** — 单一 Rust 二进制,一行命令装完
- **毫秒级响应** — 后台 daemon 持久缓存解密数据库mtime 不变则复用
- **AI 友好** — `--json` 输出纯 JSON方便 LLM agent 直接调用
- **完全本地** — 数据不出本机,实时解密,无需全量预解密
---
## 安装
**macOS / Linux**
```bash
curl -fsSL https://raw.githubusercontent.com/jackwener/wx-cli/main/install.sh | bash
```
**Windows**PowerShell以管理员身份运行
```powershell
irm https://raw.githubusercontent.com/jackwener/wx-cli/main/install.ps1 | iex
```
<details>
<summary>其他安装方式</summary>
**手动下载**
从 [Releases](https://github.com/jackwener/wx-cli/releases) 下载对应平台文件:
| 平台 | 文件 |
|------|------|
| macOS Apple Silicon | `wx-macos-arm64` |
| macOS Intel | `wx-macos-x86_64` |
| Linux x86_64 | `wx-linux-x86_64` |
| Windows x86_64 | `wx-windows-x86_64.exe` |
macOS / Linux`chmod +x wx && sudo mv wx /usr/local/bin/`
**从源码构建**
```bash
git clone git@github.com:jackwener/wx-cli.git && cd wx-cli
cargo build --release
# 产物target/release/wxWindows: wx.exe
```
</details>
---
## 快速开始
保持微信运行,然后初始化(只需一次):
**macOS**(需要先对微信做 ad-hoc 签名,才能扫描其内存)
```bash
sudo codesign --force --deep --sign - /Applications/WeChat.app
sudo wx init
```
**Linux**
```bash
sudo wx init
```
**Windows**(以管理员身份运行 PowerShell
```powershell
wx init
```
之后直接用daemon 会在首次调用时自动启动:
```bash
wx sessions # 查看最近会话
wx history "张三" # 查看聊天记录
wx search "Claude" # 搜索消息
```
---
## 命令
### 消息
```bash
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
```
### 联系人 & 群组
```bash
wx contacts # 联系人列表
wx contacts -q "李" # 按名字搜索
wx members "AI交流群" # 群成员列表
```
### 收藏 & 统计
```bash
wx favorites # 全部收藏
wx favorites --type image # 按类型筛选text/image/article/card/video
wx favorites -q "关键词" # 搜索收藏内容
wx stats "AI群" # 聊天统计
wx stats "AI群" --since 2026-01-01 # 指定时间范围
```
### 导出
```bash
wx export "张三" --format markdown -o chat.md
wx export "AI群" --since 2026-01-01 --format json
```
### JSON 输出AI agent 用)
所有命令加 `--json` 输出机器可读的 JSON
```bash
wx sessions --json
wx search "关键词" --json | jq '.[0].content'
wx new-messages --json
```
### Daemon 管理
```bash
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 API`mach_vm_region` + `mach_vm_read`)或 Linux `/proc/<pid>/mem` 扫描微信进程内存匹配该模式提取密钥daemon 按需解密并缓存。
---
## 免责声明
本工具仅用于学习和研究目的,用于解密**自己的**微信数据。请遵守相关法律法规,不得用于未经授权的数据访问。