mirror of https://github.com/jackwener/wx-cli.git
fix: 统一所有 JSON 文件读写为 UTF-8 编码
Windows 中文环境默认编码为 GBK,未指定 encoding 会导致 config.json/all_keys.json 解析失败。修复 9 个文件共 17 处。 Closes #32 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>feat/daemon-cli
parent
67244597f2
commit
944546beb1
|
|
@ -169,7 +169,7 @@ def load_config():
|
|||
cfg = {}
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
try:
|
||||
with open(CONFIG_FILE) as f:
|
||||
with open(CONFIG_FILE, encoding="utf-8") as f:
|
||||
cfg = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
print(f"[!] {CONFIG_FILE} 格式损坏,将使用默认配置")
|
||||
|
|
@ -181,12 +181,12 @@ def load_config():
|
|||
if detected:
|
||||
print(f"[+] 自动检测到微信数据目录: {detected}")
|
||||
cfg = {**_DEFAULT, **cfg, "db_dir": detected}
|
||||
with open(CONFIG_FILE, "w") as f:
|
||||
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(cfg, f, indent=4, ensure_ascii=False)
|
||||
print(f"[+] 已保存到: {CONFIG_FILE}")
|
||||
else:
|
||||
if not os.path.exists(CONFIG_FILE):
|
||||
with open(CONFIG_FILE, "w") as f:
|
||||
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(_DEFAULT, f, indent=4, ensure_ascii=False)
|
||||
print(f"[!] 未能自动检测微信数据目录")
|
||||
print(f" 请手动编辑 {CONFIG_FILE} 中的 db_dir 字段")
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ def main():
|
|||
print("请先运行 find_all_keys.py")
|
||||
sys.exit(1)
|
||||
|
||||
with open(KEYS_FILE) as f:
|
||||
with open(KEYS_FILE, encoding="utf-8") as f:
|
||||
keys = json.load(f)
|
||||
|
||||
keys = strip_key_metadata(keys)
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ def verify_and_decrypt(attach_dir, aes_key_str, xor_key):
|
|||
|
||||
def main():
|
||||
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
|
||||
with open(config_path) as f:
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
|
||||
db_dir = config['db_dir']
|
||||
|
|
@ -392,7 +392,7 @@ def main():
|
|||
config['image_aes_key'] = aes_key
|
||||
if xor_key is not None:
|
||||
config['image_xor_key'] = xor_key
|
||||
with open(config_path, 'w') as f:
|
||||
with open(config_path, 'w', encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2, ensure_ascii=False)
|
||||
print(f"Saved to {config_path}", flush=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ def verify_and_decrypt(attach_dir, aes_key_str, xor_key):
|
|||
|
||||
def main():
|
||||
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
|
||||
with open(config_path) as f:
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
|
||||
db_dir = config['db_dir']
|
||||
|
|
@ -292,7 +292,7 @@ def main():
|
|||
config['image_aes_key'] = aes_key
|
||||
if xor_key is not None:
|
||||
config['image_xor_key'] = xor_key
|
||||
with open(config_path, 'w') as f:
|
||||
with open(config_path, 'w', encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2, ensure_ascii=False)
|
||||
print(f"Saved to {config_path}", flush=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ DB_DIR = _cfg["db_dir"]
|
|||
KEYS_FILE = _cfg["keys_file"]
|
||||
DECRYPTED = os.path.join(_cfg["decrypted_dir"], "session", "session.db")
|
||||
|
||||
with open(KEYS_FILE) as f:
|
||||
with open(KEYS_FILE, encoding="utf-8") as f:
|
||||
keys = json.load(f)
|
||||
enc_key = bytes.fromhex(keys["session/session.db"]["enc_key"])
|
||||
|
||||
|
|
|
|||
4
main.py
4
main.py
|
|
@ -28,7 +28,7 @@ def ensure_keys(keys_file, db_dir):
|
|||
"""确保密钥文件存在且匹配当前 db_dir,否则重新提取"""
|
||||
if os.path.exists(keys_file):
|
||||
try:
|
||||
with open(keys_file) as f:
|
||||
with open(keys_file, encoding="utf-8") as f:
|
||||
keys = json.load(f)
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
keys = {}
|
||||
|
|
@ -59,7 +59,7 @@ def ensure_keys(keys_file, db_dir):
|
|||
print("[!] 密钥提取失败")
|
||||
sys.exit(1)
|
||||
try:
|
||||
with open(keys_file) as f:
|
||||
with open(keys_file, encoding="utf-8") as f:
|
||||
keys = json.load(f)
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
keys = {}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ WAL_FRAME_HEADER_SZ = 24
|
|||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
CONFIG_FILE = os.path.join(SCRIPT_DIR, "config.json")
|
||||
|
||||
with open(CONFIG_FILE) as f:
|
||||
with open(CONFIG_FILE, encoding="utf-8") as f:
|
||||
_cfg = json.load(f)
|
||||
for _key in ("keys_file", "decrypted_dir"):
|
||||
if _key in _cfg and not os.path.isabs(_cfg[_key]):
|
||||
|
|
@ -52,7 +52,7 @@ if not DECODED_IMAGE_DIR:
|
|||
elif not os.path.isabs(DECODED_IMAGE_DIR):
|
||||
DECODED_IMAGE_DIR = os.path.join(SCRIPT_DIR, DECODED_IMAGE_DIR)
|
||||
|
||||
with open(KEYS_FILE) as f:
|
||||
with open(KEYS_FILE, encoding="utf-8") as f:
|
||||
ALL_KEYS = strip_key_metadata(json.load(f))
|
||||
|
||||
# ============ 解密函数 ============
|
||||
|
|
@ -143,7 +143,7 @@ class DBCache:
|
|||
if not os.path.exists(self.MTIME_FILE):
|
||||
return
|
||||
try:
|
||||
with open(self.MTIME_FILE) as f:
|
||||
with open(self.MTIME_FILE, encoding="utf-8") as f:
|
||||
saved = json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return
|
||||
|
|
@ -172,7 +172,7 @@ class DBCache:
|
|||
for rel_key, (db_mt, wal_mt, path) in self._cache.items():
|
||||
data[rel_key] = {"db_mt": db_mt, "wal_mt": wal_mt, "path": path}
|
||||
try:
|
||||
with open(self.MTIME_FILE, 'w') as f:
|
||||
with open(self.MTIME_FILE, 'w', encoding="utf-8") as f:
|
||||
json.dump(data, f)
|
||||
except OSError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ def main():
|
|||
print("=" * 60)
|
||||
|
||||
# 加载密钥
|
||||
with open(KEYS_FILE) as f:
|
||||
with open(KEYS_FILE, encoding="utf-8") as f:
|
||||
keys = strip_key_metadata(json.load(f))
|
||||
|
||||
session_key_info = get_key_info(keys, os.path.join("session", "session.db"))
|
||||
|
|
|
|||
|
|
@ -1883,7 +1883,7 @@ def main():
|
|||
print(" 微信实时监听 (WAL增量 + SSE推送)", flush=True)
|
||||
print("=" * 60, flush=True)
|
||||
|
||||
with open(KEYS_FILE) as f:
|
||||
with open(KEYS_FILE, encoding="utf-8") as f:
|
||||
keys = strip_key_metadata(json.load(f))
|
||||
|
||||
session_key_info = get_key_info(keys, os.path.join("session", "session.db"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue