Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "r", encoding="utf-8") as f:
cfg = json.load(f)
except json.JSONDecodeError:
print(f"[!] {CONFIG_FILE} 格式损坏,将使用默认配置")
Expand All @@ -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 字段")
Expand Down
46 changes: 23 additions & 23 deletions decrypt_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import hashlib, struct, os, sys, json
import hmac as hmac_mod
from Crypto.Cipher import AES
from Crypto.Cipher import AES

import functools
print = functools.partial(print, flush=True)
Expand All @@ -20,12 +20,12 @@
RESERVE_SZ = 80 # IV(16) + HMAC(64)
SQLITE_HDR = b'SQLite format 3\x00'

from config import load_config
from key_utils import get_key_info, strip_key_metadata
_cfg = load_config()
DB_DIR = _cfg["db_dir"]
OUT_DIR = _cfg["decrypted_dir"]
KEYS_FILE = _cfg["keys_file"]
from config import load_config
from key_utils import get_key_info, strip_key_metadata
_cfg = load_config()
DB_DIR = _cfg["db_dir"]
OUT_DIR = _cfg["decrypted_dir"]
KEYS_FILE = _cfg["keys_file"]


def derive_mac_key(enc_key, salt):
Expand Down Expand Up @@ -116,13 +116,13 @@ def main():
print("请先运行 find_all_keys.py")
sys.exit(1)

with open(KEYS_FILE) as f:
keys = json.load(f)

keys = strip_key_metadata(keys)
print(f"\n加载 {len(keys)} 个数据库密钥")
print(f"输出目录: {OUT_DIR}")
os.makedirs(OUT_DIR, exist_ok=True)
with open(KEYS_FILE, "r", encoding="utf-8") as f:
keys = json.load(f)
keys = strip_key_metadata(keys)
print(f"\n加载 {len(keys)} 个数据库密钥")
print(f"输出目录: {OUT_DIR}")
os.makedirs(OUT_DIR, exist_ok=True)

# 收集所有DB文件
db_files = []
Expand All @@ -142,15 +142,15 @@ def main():
failed = 0
total_bytes = 0

for rel, path, sz in db_files:
key_info = get_key_info(keys, rel)
if not key_info:
print(f"SKIP: {rel} (无密钥)")
failed += 1
continue

enc_key = bytes.fromhex(key_info["enc_key"])
out_path = os.path.join(OUT_DIR, rel)
for rel, path, sz in db_files:
key_info = get_key_info(keys, rel)
if not key_info:
print(f"SKIP: {rel} (无密钥)")
failed += 1
continue
enc_key = bytes.fromhex(key_info["enc_key"])
out_path = os.path.join(OUT_DIR, rel)

print(f"解密: {rel} ({sz/1024/1024:.1f}MB) ...", end=" ")

Expand Down
4 changes: 2 additions & 2 deletions find_image_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "r", encoding="utf-8") as f:
config = json.load(f)

db_dir = config['db_dir']
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions find_image_key_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "r", encoding="utf-8") as f:
config = json.load(f)

db_dir = config['db_dir']
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion latency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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, "r", encoding="utf-8") as f:
keys = json.load(f)
enc_key = bytes.fromhex(keys["session/session.db"]["enc_key"])

Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "r", encoding="utf-8") as f:
keys = json.load(f)
except (json.JSONDecodeError, ValueError):
keys = {}
Expand Down Expand Up @@ -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, "r", encoding="utf-8") as f:
keys = json.load(f)
except (json.JSONDecodeError, ValueError):
keys = {}
Expand Down
Loading