From a393337d0d25bbb66708bde6c4b18c4766667249 Mon Sep 17 00:00:00 2001 From: yibo Date: Wed, 8 Jul 2026 17:12:23 +0800 Subject: [PATCH] fix(wechathook): 微信 DB 多账号选库改用 MD5("mm"+uin) 定位当前账号 --- lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/vision/WeChatDb.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/vision/WeChatDb.kt b/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/vision/WeChatDb.kt index d58a997..0bc3c5f 100644 --- a/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/vision/WeChatDb.kt +++ b/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/vision/WeChatDb.kt @@ -12,6 +12,7 @@ import java.security.MessageDigest * 端上解密打开微信 `EnMicroMsg.db`(SQLCipher,明文化后供 chat / contacts 等复用)。**纯本地,不经 Mac/Frida**。 * * key 推导(真机验证):`MD5("1234567890ABCDEF" + uin)[:7]`(imei 用微信默认值;uin 从 shared_prefs 读)。 + * 选库(多账号):当前账号目录名 = `MD5("mm" + uin)`,不能用 `ls|head -1`(字典序会选错号 → key 套错库解密失败)。 * SQLCipher:`cipher_compatibility=1` + `page_size=1024`。两个 app-su 坑(--mount-master / 空 PATH)见 §七。 * 详见 memory `wechat-android-decrypt`。 */ @@ -36,12 +37,16 @@ object WeChatDb { val script = buildString { append("export PATH=/system/bin:/system/xbin:\$PATH; ") append("BASE=/data/user/0/com.tencent.mm; ") - append("DB=\$(ls \$BASE/MicroMsg/*/EnMicroMsg.db 2>/dev/null | head -1); ") + append("UIN=\$(grep -hoE 'last_login_uin\">[0-9-]+' \$BASE/shared_prefs/*.xml 2>/dev/null | grep -oE '[0-9-]+' | head -1); ") + // 多账号:当前登录账号的库目录名 = MD5("mm"+uin)。旧的 `ls|head -1` 会按字典序选错账号, + // 把主账号的 key 套到别的号的库上 → 解密失败。定位不到(uin 空/版本变)再回退 head -1。 + append("DIR=\$(printf 'mm%s' \"\$UIN\" | md5sum | cut -c1-32); ") + append("DB=\$BASE/MicroMsg/\$DIR/EnMicroMsg.db; ") + append("[ -f \"\$DB\" ] || DB=\$(ls \$BASE/MicroMsg/*/EnMicroMsg.db 2>/dev/null | head -1); ") append("[ -z \"\$DB\" ] && exit 3; ") append("cp \"\$DB\" $sp/en.db || exit 4; ") append("[ -f \"\$DB-wal\" ] && cp \"\$DB-wal\" $sp/en.db-wal; ") append("[ -f \"\$DB-shm\" ] && cp \"\$DB-shm\" $sp/en.db-shm; ") - append("UIN=\$(grep -hoE 'last_login_uin\">[0-9-]+' \$BASE/shared_prefs/*.xml 2>/dev/null | grep -oE '[0-9-]+' | head -1); ") append("echo \"uin=\$UIN\"; ") append("chown -R $uid:$uid $sp; chmod -R u+rwX $sp") } -- libgit2 0.21.4