fix(init): task_for_pid 失败时按 root 状态分流提示

非 root 运行是 kr=5 最常见原因,先提示加 sudo;
仅当已是 root 仍失败(SIP 开启 + 官方签名)才提示 codesign 重签。
原提示无脑让用户重签,对关闭 SIP 的用户是误导。
pull/109/head
jackwener 2026-06-11 20:09:59 +08:00
parent 08af894594
commit 144ce6af29
1 changed files with 22 additions and 3 deletions

View File

@ -109,8 +109,25 @@ pub fn scan_keys(db_dir: &Path) -> Result<Vec<KeyEntry>> {
let mut task: mach_port_t = 0; let mut task: mach_port_t = 0;
let kr = task_for_pid(mach_task_self(), pid, &mut task); let kr = task_for_pid(mach_task_self(), pid, &mut task);
if kr != KERN_SUCCESS { if kr != KERN_SUCCESS {
// task_for_pid 读取目标进程内存始终需要 root。
// 最常见的 kr=5 (KERN_FAILURE) 就是没加 sudo先指出这一点
// 只有已经是 root 仍然失败,才是 SIP 开启下的签名问题,需要重签。
if libc::geteuid() != 0 {
bail!( bail!(
"task_for_pid 失败 (kr={})。请按以下步骤修复:\n\ "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={}):已是 root 但仍无法获取 task port\n\
SIP WeChat hardened runtime\n\
\n\
\n\ \n\
1. WeChat \n\ 1. WeChat \n\
codesign --force --deep --sign - /Applications/WeChat.app\n\ codesign --force --deep --sign - /Applications/WeChat.app\n\
@ -118,12 +135,14 @@ pub fn scan_keys(db_dir: &Path) -> Result<Vec<KeyEntry>> {
2. WeChat\n\ 2. WeChat\n\
killall WeChat && open /Applications/WeChat.app\n\ killall WeChat && open /Applications/WeChat.app\n\
\n\ \n\
3. root\n\ 3. \n\
sudo wx init\n\ sudo wx init\n\
\n\ \n\
codesign \"signature in use\",先执行:\n\ codesign \"signature in use\",先执行:\n\
codesign --remove-signature /Applications/WeChat.app/Contents/Frameworks/vlc_plugins/librtp_mpeg4_plugin.dylib\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 kr
); );
} }