diff --git a/wechat-viewer/config.py b/wechat-viewer/config.py index 9f45f45..8756275 100644 --- a/wechat-viewer/config.py +++ b/wechat-viewer/config.py @@ -3,6 +3,7 @@ import subprocess import json import os +import re from pathlib import Path BASE_DIR = Path(__file__).parent @@ -68,6 +69,8 @@ def _get_custom_name(account_id): pass return None +_ACCOUNT_DIR_RE = re.compile(r"^[0-9a-f]{32}$") + def discover_accounts(): accounts = [] base = "/data/data/com.tencent.mm/MicroMsg" @@ -80,9 +83,11 @@ def discover_accounts(): line = line.strip() if not line: continue + folder = os.path.basename(line.rstrip("/")) + if not _ACCOUNT_DIR_RE.match(folder): + continue # 跳过微信自己的缓存/功能目录(CronetCache/emoji/jscache/...),不是账号 db_path = os.path.join(line, "EnMicroMsg.db") if _su_exists(db_path): - folder = os.path.basename(line.rstrip("/")) key = _get_key_for_account(folder) # 名字优先级:自定义名 > 从DB读 > hash前缀 name = _get_custom_name(folder) or _get_nickname(db_path, key) or folder[:8]