From 144ce6af2977ca5f679aea1b770e3a8d0cb8ffc5 Mon Sep 17 00:00:00 2001 From: jackwener Date: Thu, 11 Jun 2026 20:09:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(init):=20task=5Ffor=5Fpid=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E6=8C=89=20root=20=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=88=86=E6=B5=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 非 root 运行是 kr=5 最常见原因,先提示加 sudo; 仅当已是 root 仍失败(SIP 开启 + 官方签名)才提示 codesign 重签。 原提示无脑让用户重签,对关闭 SIP 的用户是误导。 --- src/scanner/macos.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/scanner/macos.rs b/src/scanner/macos.rs index c22d3bb..c7c4423 100644 --- a/src/scanner/macos.rs +++ b/src/scanner/macos.rs @@ -109,8 +109,25 @@ pub fn scan_keys(db_dir: &Path) -> Result> { let mut task: mach_port_t = 0; let kr = task_for_pid(mach_task_self(), pid, &mut task); if kr != KERN_SUCCESS { + // task_for_pid 读取目标进程内存始终需要 root。 + // 最常见的 kr=5 (KERN_FAILURE) 就是没加 sudo,先指出这一点; + // 只有已经是 root 仍然失败,才是 SIP 开启下的签名问题,需要重签。 + if libc::geteuid() != 0 { + bail!( + "task_for_pid 失败 (kr={}):抓取密钥需要 root 权限。\n\ + \n\ + 请改用 sudo 重新运行:\n\ + sudo wx init\n\ + \n\ + (若已用 sudo 仍失败,说明 SIP 开启且 WeChat 未 ad-hoc 签名,\n\ + 此时才需要 codesign 重签,详见 README。)", + kr + ); + } bail!( - "task_for_pid 失败 (kr={})。请按以下步骤修复:\n\ + "task_for_pid 失败 (kr={}):已是 root 但仍无法获取 task port,\n\ + 通常是 SIP 开启且 WeChat 为官方签名(hardened runtime)所致。\n\ + 请按以下步骤修复:\n\ \n\ 1. 对 WeChat 重新签名(只需做一次):\n\ codesign --force --deep --sign - /Applications/WeChat.app\n\ @@ -118,12 +135,14 @@ pub fn scan_keys(db_dir: &Path) -> Result> { 2. 重启 WeChat:\n\ killall WeChat && open /Applications/WeChat.app\n\ \n\ - 3. 再次运行(需要 root):\n\ + 3. 再次运行:\n\ sudo wx init\n\ \n\ 如果 codesign 报 \"signature in use\",先执行:\n\ codesign --remove-signature /Applications/WeChat.app/Contents/Frameworks/vlc_plugins/librtp_mpeg4_plugin.dylib\n\ - codesign --force --deep --sign - /Applications/WeChat.app", + codesign --force --deep --sign - /Applications/WeChat.app\n\ + \n\ + (若已关闭 SIP,则无需重签,只要确保用 sudo 运行即可。)", kr ); }