From 3fb09bad0dc687157e280ae82644a626e136f072 Mon Sep 17 00:00:00 2001 From: hicccc77 <98377878+hicccc77@users.noreply.github.com> Date: Sat, 28 Mar 2026 19:05:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Linux=20=E4=B8=8B?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=89=AB=E6=8F=8F=E6=89=BE=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E8=BF=9B=E7=A8=8B=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?\n\n=E5=A2=9E=E5=8A=A0=20pidof/pgrep/ps=20aux=20=E4=B8=89?= =?UTF-8?q?=E9=87=8D=E5=85=9C=E5=BA=95=E9=80=BB=E8=BE=91=EF=BC=8C=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=B8=8D=E5=90=8C=E5=8F=91=E8=A1=8C=E7=89=88\n?= =?UTF-8?q?=EF=BC=88flatpak=E3=80=81AppImage=E3=80=81wechat-bin=20?= =?UTF-8?q?=E7=AD=89=E5=AE=89=E8=A3=85=E6=96=B9=E5=BC=8F=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20#575?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/keyServiceLinux.ts | 44 ++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/electron/services/keyServiceLinux.ts b/electron/services/keyServiceLinux.ts index 7364f83..92c80d0 100644 --- a/electron/services/keyServiceLinux.ts +++ b/electron/services/keyServiceLinux.ts @@ -256,11 +256,45 @@ export class KeyServiceLinux { onProgress?.(`XOR 密钥: 0x${xorKey.toString(16).padStart(2, '0')},正在查找微信进程...`) - // 2. 找微信 PID - const { stdout } = await execAsync('pidof wechat wechat-bin xwechat').catch(() => ({ stdout: '' })) - const pids = stdout.trim().split(/\s+/).filter(p => p) - if (pids.length === 0) return { success: false, error: '微信未运行,无法扫描内存' } - const pid = parseInt(pids[0], 10) + // 2. 找微信 PID(多种方式兜底,兼容不同发行版/安装方式) + const envWithPath = { + ...process.env, + PATH: `${process.env.PATH || ''}:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin` + } + let pid = 0 + + // 方式1: pidof + try { + const { stdout } = await execAsync('pidof wechat wechat-bin xwechat WeChat', { env: envWithPath }) + const pids = stdout.trim().split(/\s+/).filter(p => p) + if (pids.length > 0) pid = parseInt(pids[0], 10) + } catch { /* 未找到进程,继续尝试 */ } + + // 方式2: pgrep 兜底 + if (!pid) { + try { + const { stdout } = await execAsync('pgrep -x -i "wechat|wechat-bin|xwechat"', { env: envWithPath }) + const pids = stdout.trim().split(/\s+/).filter(p => p) + if (pids.length > 0) pid = parseInt(pids[0], 10) + } catch { /* 继续 */ } + } + + // 方式3: ps aux 全名匹配(覆盖 flatpak / AppImage 等场景) + if (!pid) { + try { + const { stdout } = await execAsync('ps aux', { env: envWithPath }) + for (const line of stdout.split('\n')) { + const lower = line.toLowerCase() + if (lower.includes('wechat') && !lower.includes('grep')) { + const parts = line.trim().split(/\s+/) + const candidate = parseInt(parts[1], 10) + if (!isNaN(candidate)) { pid = candidate; break } + } + } + } catch { /* 继续 */ } + } + + if (!pid) return { success: false, error: '微信未运行,无法扫描内存(已尝试 pidof/pgrep/ps,均未找到微信进程)' } onProgress?.(`已找到微信进程 PID=${pid},正在提权扫描进程内存...`);