From 6e5dff6098f7455d01cf5f3e21cdb6aa223a7bab Mon Sep 17 00:00:00 2001 From: Aldrich Chen <109075336+Chen17-sq@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:27:11 +0800 Subject: [PATCH] fix(keys/macos): report correct key count after init 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 #2 --- wechat_cli/keys/scanner_macos.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/wechat_cli/keys/scanner_macos.py b/wechat_cli/keys/scanner_macos.py index ea316ee..f095e2f 100644 --- a/wechat_cli/keys/scanner_macos.py +++ b/wechat_cli/keys/scanner_macos.py @@ -127,7 +127,7 @@ def extract_keys(db_dir, output_path, pid=None): pid: 未使用(C 二进制自动检测进程) Returns: - dict: salt_hex -> enc_key_hex 映射 + dict: rel_path -> enc_key_hex 映射(与 C 二进制输出 schema 一致) """ import json @@ -212,11 +212,14 @@ def extract_keys(db_dir, output_path, pid=None): if os.path.abspath(c_output) != os.path.abspath(output_path): os.remove(c_output) - # 构建 salt -> key 映射 - key_map = {} - for rel, info in keys_data.items(): - if isinstance(info, dict) and "enc_key" in info and "salt" in info: - key_map[info["salt"]] = info["enc_key"] + # 构建 rel_path -> enc_key 映射。C 二进制输出 schema 是 + # {"db.path": {"enc_key": "..."}}(不含 salt),下游 get_key_info + # 也按 rel_path 查询,所以这里保持同样的索引方式。 + key_map = { + rel: info["enc_key"] + for rel, info in keys_data.items() + if isinstance(info, dict) and "enc_key" in info + } print(f"\n[+] 提取到 {len(key_map)} 个密钥,保存到: {output_path}") return key_map