"""Run the frozen key worker against local WeCom; never print or retain keys.""" import json import os import subprocess import tempfile import time from pathlib import Path import wxwork_db project = Path(__file__).resolve().parents[1] executable = project / "dist/ZhenAI-WeCom-Assistant-v1.4.3/ZhenAI-WeCom-Assistant-v1.4.3.exe" source = wxwork_db.detect_wxwork_dir() if not source or not executable.is_file(): raise SystemExit("Source or packaged executable is unavailable") temporary_root = (project / "tmp").resolve() with tempfile.TemporaryDirectory(prefix="packaged-key-probe-", dir=temporary_root) as temporary: directory = Path(temporary).resolve() if not directory.is_relative_to(temporary_root): raise RuntimeError("Probe output must stay inside workspace tmp") environment = os.environ.copy() environment["LOCALAPPDATA"] = str(directory) environment["WECOM_ARCHIVE_SOURCE_DIR"] = str(source) started = time.monotonic() completed = subprocess.run([str(executable), "--wechat-db-key-worker"], env=environment, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=subprocess.CREATE_NO_WINDOW, timeout=60) if completed.returncode: raise RuntimeError(f"Packaged key worker exit code: {completed.returncode}") keys = wxwork_db.load_keys(directory / "ZhenYangTangRPA/wxwork_keys.json") verified = 0 for database in Path(source).glob("*/Data/message.db"): if any(wxwork_db.verify_key(bytes.fromhex(key), str(database)) for key in keys.values()): verified += 1 if not verified: raise RuntimeError("No packaged worker keys matched a local database") print("Packaged EXE live worker verified accounts:", verified, "; elapsed seconds:", round(time.monotonic() - started, 1), flush=True) print("Temporary probe keys removed; installed account data unchanged.")