From 3efca5e60cf262a7d3551bfe78d4371e2cf542ff Mon Sep 17 00:00:00 2001 From: yunxilyf <2574379425@qq.com> Date: Wed, 21 Jan 2026 09:12:10 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E7=9A=84=E6=97=B6=E5=80=99=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=90=AF=E5=8A=A8=E8=B7=AF=E5=BE=84=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/keyService.ts | 41 +++++++++++++++++++++++++++++++++ package-lock.json | 6 ----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/electron/services/keyService.ts b/electron/services/keyService.ts index 8b51c8d..08f730a 100644 --- a/electron/services/keyService.ts +++ b/electron/services/keyService.ts @@ -33,6 +33,7 @@ export class KeyService { private ReadProcessMemory: any = null private MEMORY_BASIC_INFORMATION: any = null private TerminateProcess: any = null + private QueryFullProcessImageNameW: any = null // User32 private EnumWindows: any = null @@ -194,6 +195,7 @@ export class KeyService { this.OpenProcess = this.kernel32.func('OpenProcess', 'HANDLE', ['uint32', 'bool', 'uint32']) this.CloseHandle = this.kernel32.func('CloseHandle', 'bool', ['HANDLE']) this.TerminateProcess = this.kernel32.func('TerminateProcess', 'bool', ['HANDLE', 'uint32']) + this.QueryFullProcessImageNameW = this.kernel32.func('QueryFullProcessImageNameW', 'bool', ['HANDLE', 'uint32', this.koffi.out('uint16*'), this.koffi.out('uint32*')]) this.VirtualQueryEx = this.kernel32.func('VirtualQueryEx', 'uint64', ['HANDLE', 'uint64', this.koffi.out(this.koffi.pointer(this.MEMORY_BASIC_INFORMATION)), 'uint64']) this.ReadProcessMemory = this.kernel32.func('ReadProcessMemory', 'bool', ['HANDLE', 'uint64', 'void*', 'uint64', this.koffi.out(this.koffi.pointer('uint64'))]) @@ -310,7 +312,46 @@ export class KeyService { } } + private async getProcessExecutablePath(pid: number): Promise { + if (!this.ensureKernel32()) return null + // 0x1000 = PROCESS_QUERY_LIMITED_INFORMATION + const hProcess = this.OpenProcess(0x1000, false, pid) + if (!hProcess) return null + + try { + const sizeBuf = Buffer.alloc(4) + sizeBuf.writeUInt32LE(1024, 0) + const pathBuf = Buffer.alloc(1024 * 2) + + const ret = this.QueryFullProcessImageNameW(hProcess, 0, pathBuf, sizeBuf) + if (ret) { + const len = sizeBuf.readUInt32LE(0) + return pathBuf.toString('ucs2', 0, len * 2) + } + return null + } catch (e) { + console.error('获取进程路径失败:', e) + return null + } finally { + this.CloseHandle(hProcess) + } + } + private async findWeChatInstallPath(): Promise { + // 0. 优先尝试获取正在运行的微信进程路径 + try { + const pid = await this.findWeChatPid() + if (pid) { + const runPath = await this.getProcessExecutablePath(pid) + if (runPath && existsSync(runPath)) { + console.log('发现正在运行的微信进程,使用路径:', runPath) + return runPath + } + } + } catch (e) { + console.error('尝试获取运行中微信路径失败:', e) + } + // 1. Registry - Uninstall Keys const uninstallKeys = [ 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall', diff --git a/package-lock.json b/package-lock.json index a38e504..ba9957a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8537,12 +8537,6 @@ "sherpa-onnx-win-x64": "^1.12.23" } }, - "node_modules/sherpa-onnx-node/node_modules/sherpa-onnx-darwin-x64": { - "optional": true - }, - "node_modules/sherpa-onnx-node/node_modules/sherpa-onnx-linux-arm64": { - "optional": true - }, "node_modules/sherpa-onnx-win-ia32": { "version": "1.12.23", "resolved": "https://registry.npmmirror.com/sherpa-onnx-win-ia32/-/sherpa-onnx-win-ia32-1.12.23.tgz",