From acd44376ba3f763d68d68423ebd00e65ab65484c Mon Sep 17 00:00:00 2001 From: Belugary <53219544+Belugary@users.noreply.github.com> Date: Tue, 5 May 2026 22:47:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20find=5Fimage=5Fkey=20=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=20fallback=20=E5=85=A5=E5=8F=A3=E8=B7=AF=E5=BE=84=E5=B1=95?= =?UTF-8?q?=E5=BC=80=20+=20=E6=96=B9=E6=A1=882=20hint=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: find_image_key 三个 fallback CLI 入口对齐 config.load_config 路径展开 PR #63 给 config.load_config() 加了 expanduser + expandvars, 但 find_image_key.py / find_image_key_macos.py / find_image_key_monitor.py 三个 CLI 入口的 main() 为了让单测注入隔离 config (find_image_key_macos.py docstring 明文写着), 走 raw json.load(config_path), 绕开了 load_config 那层路径展开. 用户 config.json 里写 "db_dir": "~/Documents/..." 或 "$HOME/Documents/..." 时, 下游拼出的 attach_dir 仍带 ~ / $HOME 字面字符, glob *_t.dat 扫不到 → find_image_key.py / monitor.py 报 "No V2 .dat files found", macOS 文件 dispatcher 还会误报"请先在微信中查看 1-2 张图片让微信生成 V2 .dat 文件", 但磁盘上 attach 已经塞满了 .dat. 三个文件各加 1 行 expanduser(expandvars(...)), 与 PR #63 / config.py:213 对齐, 不动 main() 既有的 raw json.load(为保留单测注入口子). * fix(find_image_key_macos): 方案2 V2 _t.dat 样本不足时补一行下一步指引 dispatcher 层 (找不到 V2 模板分支) 已有"请先在微信中查看 1-2 张图片让微信 生成 V2 .dat 文件"指引, 但 _find_via_bruteforce 子路径在 V2 _t.dat 样本 < 3 时只 print "样本不足 (需 >= 3 个), 无法投票反推 xor_key", 用户不知该做什么. 加一行等价 hint, 与 dispatcher 层 UX 风格保持一致. --- find_image_key.py | 2 +- find_image_key_macos.py | 3 +++ find_image_key_monitor.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/find_image_key.py b/find_image_key.py index afb9ad1..f163c7e 100644 --- a/find_image_key.py +++ b/find_image_key.py @@ -337,7 +337,7 @@ def main(): with open(config_path, encoding="utf-8") as f: config = json.load(f) - db_dir = config['db_dir'] + db_dir = os.path.expanduser(os.path.expandvars(config['db_dir'])) base_dir = os.path.dirname(db_dir) attach_dir = os.path.join(base_dir, 'msg', 'attach') diff --git a/find_image_key_macos.py b/find_image_key_macos.py index 3779f7f..b1b1703 100644 --- a/find_image_key_macos.py +++ b/find_image_key_macos.py @@ -494,6 +494,8 @@ def _find_via_bruteforce(db_dir, attach_dir, templates): if not xres: print("[!] 方案2: V2 .dat 样本不足 (需 >= 3 个), 无法投票反推 xor_key", flush=True) + print(" 请先在微信中再看 1-2 张图片,让微信生成更多 V2 .dat 文件", + flush=True) return None xor_key, votes, total = xres if votes == total: @@ -607,6 +609,7 @@ def main(config_path=None): if not db_dir: print("[!] config.json 中未配置 db_dir", file=sys.stderr, flush=True) sys.exit(1) + db_dir = os.path.expanduser(os.path.expandvars(db_dir)) print(f"[*] db_dir = {db_dir}", flush=True) # 短路:如果已有 image_aes_key 且仍能在所有模板上验证通过,直接退出 diff --git a/find_image_key_monitor.py b/find_image_key_monitor.py index 437a47f..fa1b6f4 100644 --- a/find_image_key_monitor.py +++ b/find_image_key_monitor.py @@ -230,7 +230,7 @@ def main(): with open(config_path, encoding="utf-8") as f: config = json.load(f) - db_dir = config['db_dir'] + db_dir = os.path.expanduser(os.path.expandvars(config['db_dir'])) base_dir = os.path.dirname(db_dir) attach_dir = os.path.join(base_dir, 'msg', 'attach')