fix(keys/macos): report correct key count after init#4
Open
Chen17-sq wants to merge 1 commit intohuohuoer:mainfrom
Open
fix(keys/macos): report correct key count after init#4Chen17-sq wants to merge 1 commit intohuohuoer:mainfrom
Chen17-sq wants to merge 1 commit intohuohuoer:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sudo wechat-cli initon macOS prints提取到 0 个数据库密钥even when key extraction succeeds and~/.wechat-cli/all_keys.jsonis correctly written. Subsequent commands (sessions,history,search) all work — the count is just wrong.Fixes #2.
Root cause
The C binary
find_all_keys_macoswrites 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-219was filtering on bothenc_keyandsalt, so every entry was rejected andkey_mapended up empty.init.py:69then echoedlen(key_map) == 0.The on-disk
all_keys.jsonhas always been correct.core/key_utils.get_key_infoalready looks keys up by rel path, not by salt, so downstream queries work regardless.Change
Build
key_mapkeyed by rel path (matching the C binary's output andget_key_info's lookup path). 6-line diff inwechat_cli/keys/scanner_macos.py.Also updated the docstring
Returns:line to reflect the actual schema.Test plan
sudo wechat-cli initon macOS 26.x with WeChat 4.1.x running提取到 17 个密钥) instead of0wechat-cli sessions,wechat-cli history "<contact>",wechat-cli search "<keyword>"all return data unchanged~/.wechat-cli/all_keys.jsoncontent is byte-identical before and after this PR (only the in-memory return value changed)Out of scope (follow-ups)
scanner_*.pyreturn{salt_hex: enc_key_hex}viacommon.save_results, while macOS now returns{rel_path: enc_key_hex}. The schemas ofextract_keys's return value still differ across platforms. Since the only caller (init.py) useslen(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.tests/directory yet. Setting one up is its own conversation; I can propose it separately.