Skip to content

fix(macos): rewrite passphrase capture with native lldb breakpoint commands - #18

Merged
zhuobichen merged 1 commit into
zhuobichen:masterfrom
aji110905:fix/macos-capture-lldb-native
Nov 19, 2026
Merged

zhuobichen merged 1 commit into
zhuobichen:masterfrom
aji110905:fix/macos-capture-lldb-native

Conversation

@aji110905

Copy link
Copy Markdown
Contributor

macOS 上 capture-passphrase 此前完全不可用,两个必炸的 bug:

  1. npm 包缺 scripts/*.py(安装后报 can't open file .../macos_capture.py)——
    疑似发布时 files 字段问题,本 PR 不涉及,但建议核对;
  2. 断点回调在 lldb 里 import gdb——lldb 的 Python 环境没有 gdb 模块,
    回调必抛异常 → lldb 秒退 → 轮询把子进程退出当失败提前 break,
    用户设的 timeout 形同虚设,且最终提示误归因为「被 SIP 挡住」。

本 PR 重写为纯 lldb 原生断点命令(零 Python API 依赖),并修了三个真机踩过的坑:

  • 「退出登录 → 重新登录」后微信 PID 会变:持续扫描并补挂新进程;
  • 口令可能在 WeChatAppEx 辅助进程里派生:两类进程都挂;
  • 断点回调自带 process continue:微信不会冻在断点上(旧版会导致登录转圈掉帧)。

失败路径也修准了:SIP 开着时明确报「无法 attach,需临时 csrutil disable」,
不再误报「没有命中」。

真机验证:macOS 27.2 / Apple M4 / App Store版 微信 4.1.15 / weflow-cli 1.21.17
→ 恢复模式 csrutil disable → 一次登录命中 → nt_decrypt.py verify-passphrase-all
10/10 库通过首页 HMAC → init --passphrase 成功,sessions/messages/export 实跑正常。

测试钉住新契约(含 AST 级「不许再 import gdb」回归检查),test/macos_capture_test.py 6 项全过。
docs/MACOS.md 状态同步为已验证。

备注:代码和PR文案都是ai写的,技术栈不是这里,看不懂。如果需要提供更多信息和帮助测试我话我很愿意。

…mmands

The previous implementation injected a GDB-Python callback into lldb
(import gdb), which always throws inside lldb's script module. lldb
exited immediately; the polling loop treated the child exit as failure
and broke out before the timeout, so users never got the promised
wait window, and the final hint misattributed the crash to SIP.

Also:
- watch for new PIDs (re-login changes them) and attach WeChatAppEx
  helper processes, where the derivation may happen
- auto-continue at the breakpoint so WeChat never freezes mid-login
- accurate failure paths: 'attach failed' now reports the real SIP /
  Hardened Runtime prerequisite instead of 'no hits'
- docs/MACOS.md updated with the verified end-to-end status
  (macOS 27.2 / M4 / WeChat 4.1.15, 10/10 dbs pass HMAC)
- tests pinned to the new contract (AST-level no-gdb regression guard)
zhuobichen added a commit that referenced this pull request Nov 19, 2026
在 #18 的基础上的修正,都是它新引入的:

1. **attach 失败后无限重试 + fd 泄漏**(最严重)。原循环里 `procs[pid].poll() is
   not None` 就重开 lldb,SIP 没关时每 0.5 秒一个,5 分钟六百次;`_attach` 打开的
   日志句柄从不关闭,每次泄漏一个 fd,macOS 默认 `ulimit -n` 256 一到就抛
   `OSError` traceback——而函数本意是给"需要 csrutil disable"的提示。
   现在:句柄关闭(子进程已 dup)、失败过 attach 的 pid 不再重试、一检测到
   `attach failed` 立刻收工并报准确原因,不再等满 timeout。

2. **两条库路径被删**。原实现支持 `Containers/.../Data/Library/Application Support`
   与 `com.tencent.WeChat` 容器,PR 把它们删了、只留两条,而正文没提。现在四条都在。

3. **口令长度校验丢失**。旧版用 `passwordLen` 判 32,不匹配时报"命中了但长度不对";
   新版直接取前 32 字节,ABI 对上与否都产出候选。现在长度诊断补回:
   命中过、但 `passwordLen` 不是 32 时给出明确错误,别让人以为是自己没操作对。

顺带修:错误信息里写死的"300 秒"改成实际 timeout;`docs/MACOS.md` 的
"最后更新"从 2026-12-19(未来)改回 2026-11-19。

文档:`PROJECT_STATE.md` 的 macOS 状态改为"真机已验证(贡献者提供)";
新增 D-157 记录"捕获阶段必须临时关闭 SIP、工具不自动化这一步"这个安全取舍。

测试:`macos_capture_test.py` 6 → 13 项,新增 attach 调度策略(含"失败不再重试")、
四种库布局、长度寄存器解析。Python 全量 1467 项通过。
@zhuobichen
zhuobichen merged commit 761783a into zhuobichen:master Nov 19, 2026
@zhuobichen

Copy link
Copy Markdown
Owner

@aji110905 谢谢,这个误归因找得准。

已合并。合并后又修了三处:

  1. attach 失败会每 0.5 秒重开一个 lldb,SIP 没关时默认参数下能跑六百次;日志句柄也没关,
    而 macOS 的 ulimit -n 是 256——先撞上的会是 OSError traceback,不是"需要关 SIP"那句。
    现在失败一次就不再试。
  2. 库路径只剩两条,容器内 Application Support 与 com.tencent.WeChat 两类布局会
    "找不到库目录"。已恢复成四条。
  3. passwordLen 不再校验,ABI 对不上时产出垃圾候选、只报"没有命中"。现在会直说长度不对。

你提的第 1 点不成立,已发布的包里就有:

$ tar -tzf weflow-cli-1.21.17.tgz | grep -c package/scripts/
92

以后有类似的 PR 照样欢迎。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants