Skip to content

fix(keys/macos): report correct key count after init#4

Open
Chen17-sq wants to merge 1 commit intohuohuoer:mainfrom
Chen17-sq:fix/macos-key-count-after-init
Open

fix(keys/macos): report correct key count after init#4
Chen17-sq wants to merge 1 commit intohuohuoer:mainfrom
Chen17-sq:fix/macos-key-count-after-init

Conversation

@Chen17-sq
Copy link
Copy Markdown

Summary

sudo wechat-cli init on macOS prints 提取到 0 个数据库密钥 even when key extraction succeeds and ~/.wechat-cli/all_keys.json is correctly written. Subsequent commands (sessions, history, search) all work — the count is just wrong.

Fixes #2.

Root cause

The C binary find_all_keys_macos writes JSON in the schema:

{ "message/message_0.db": { "enc_key": "abcd…" } }

(see wechat_cli/bin/find_all_keys_macos.c:309)

The Python wrapper at wechat_cli/keys/scanner_macos.py:215-219 was filtering on both enc_key and salt, so every entry was rejected and key_map ended up empty. init.py:69 then echoed len(key_map) == 0.

The on-disk all_keys.json has always been correct. core/key_utils.get_key_info already looks keys up by rel path, not by salt, so downstream queries work regardless.

Change

Build key_map keyed by rel path (matching the C binary's output and get_key_info's lookup path). 6-line diff in wechat_cli/keys/scanner_macos.py.

Also updated the docstring Returns: line to reflect the actual schema.

Test plan

  • sudo wechat-cli init on macOS 26.x with WeChat 4.1.x running
  • Confirmed summary line now reports the real number of keys (e.g. 提取到 17 个密钥) instead of 0
  • Confirmed wechat-cli sessions, wechat-cli history "<contact>", wechat-cli search "<keyword>" all return data unchanged
  • Confirmed ~/.wechat-cli/all_keys.json content is byte-identical before and after this PR (only the in-memory return value changed)

Out of scope (follow-ups)

  • Linux/Windows scanner_*.py return {salt_hex: enc_key_hex} via common.save_results, while macOS now returns {rel_path: enc_key_hex}. The schemas of extract_keys's return value still differ across platforms. Since the only caller (init.py) uses len(key_map) and nothing else, this is functionally a no-op — but it's worth unifying eventually. Happy to do that as a separate PR if you'd like.
  • No tests added — the repo doesn't have a tests/ directory yet. Setting one up is its own conversation; I can propose it separately.

The C binary find_all_keys_macos writes JSON in the schema
{"db.path": {"enc_key": "..."}} (without a salt field), but the
Python wrapper at scanner_macos.py was filtering on both enc_key and salt,
so every entry was rejected and key_map ended up empty. init.py then
echoed 'Extracted 0 keys' even though all_keys.json was correctly written
and downstream queries worked.

Build key_map keyed by rel_path instead, matching the C binary's actual
output and how core/key_utils.get_key_info already does lookups.

Fixes huohuoer#2
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.

1 participant