Commit 9e07f85451e08e20318251a8b6303b85767d5773

Authored by yibo
1 parent 56ee9a7a

fix(wechat-viewer): 账号自动发现跳过非账号目录,少发 38 次多余 su 探测

discover_accounts() 对 MicroMsg/ 下全部 56 个子目录逐个发 su -c test -f,
但只有 18 个是 32 位十六进制的真实账号目录,其余是微信自己的缓存/功能目录
(CronetCache/emoji/jscache/hpRevert/...)。这段逻辑在模块导入时跑一次,
即 Flask app.py 每次启动/重启都重新扫一遍,白白多发 38 次 su 进程。

改为先按目录名过滤(^[0-9a-f]{32}$)再探测。真机验证:账号发现结果不变
(仍正确识别当前登录账号 653cdc2320abb089e149a3f7a7683fcf),单账号池
1.11s 内完成。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Showing 1 changed file with 6 additions and 1 deletions
wechat-viewer/config.py
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 import subprocess 3 import subprocess
4 import json 4 import json
5 import os 5 import os
  6 +import re
6 from pathlib import Path 7 from pathlib import Path
7 8
8 BASE_DIR = Path(__file__).parent 9 BASE_DIR = Path(__file__).parent
@@ -68,6 +69,8 @@ def _get_custom_name(account_id): @@ -68,6 +69,8 @@ def _get_custom_name(account_id):
68 pass 69 pass
69 return None 70 return None
70 71
  72 +_ACCOUNT_DIR_RE = re.compile(r"^[0-9a-f]{32}$")
  73 +
71 def discover_accounts(): 74 def discover_accounts():
72 accounts = [] 75 accounts = []
73 base = "/data/data/com.tencent.mm/MicroMsg" 76 base = "/data/data/com.tencent.mm/MicroMsg"
@@ -80,9 +83,11 @@ def discover_accounts(): @@ -80,9 +83,11 @@ def discover_accounts():
80 line = line.strip() 83 line = line.strip()
81 if not line: 84 if not line:
82 continue 85 continue
  86 + folder = os.path.basename(line.rstrip("/"))
  87 + if not _ACCOUNT_DIR_RE.match(folder):
  88 + continue # 跳过微信自己的缓存/功能目录(CronetCache/emoji/jscache/...),不是账号
83 db_path = os.path.join(line, "EnMicroMsg.db") 89 db_path = os.path.join(line, "EnMicroMsg.db")
84 if _su_exists(db_path): 90 if _su_exists(db_path):
85 - folder = os.path.basename(line.rstrip("/"))  
86 key = _get_key_for_account(folder) 91 key = _get_key_for_account(folder)
87 # 名字优先级:自定义名 > 从DB读 > hash前缀 92 # 名字优先级:自定义名 > 从DB读 > hash前缀
88 name = _get_custom_name(folder) or _get_nickname(db_path, key) or folder[:8] 93 name = _get_custom_name(folder) or _get_nickname(db_path, key) or folder[:8]