From 47dbc540ace74e6776302b3b3a59c4060579c332 Mon Sep 17 00:00:00 2001 From: hicccc77 <98377878+hicccc77@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=89=AB=E5=86=85?= =?UTF-8?q?=E5=AD=98=E8=8E=B7=E5=8F=96=E5=AF=86=E9=92=A5=E6=97=B6=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E6=89=BE=E4=B8=8D=E5=88=B0=E5=88=99=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E6=9B=B4=E5=A4=9A=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 首次扫描 32 个模板文件 - 如果找不到有效的 XOR 密钥,自动扩展到 100 个文件 - 提高密钥获取成功率 --- electron/services/keyService.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/electron/services/keyService.ts b/electron/services/keyService.ts index fe6e9bf..d9d607b 100644 --- a/electron/services/keyService.ts +++ b/electron/services/keyService.ts @@ -810,7 +810,16 @@ export class KeyService { try { // 1. 查找模板文件获取密文和 XOR 密钥 onProgress?.('正在查找模板文件...') - const { ciphertext, xorKey } = await this._findTemplateData(userDir) + let result = await this._findTemplateData(userDir, 32) + let { ciphertext, xorKey } = result + + // 如果找不到密钥,尝试扫描更多文件 + if (ciphertext && xorKey === null) { + onProgress?.('未找到有效密钥,尝试扫描更多文件...') + result = await this._findTemplateData(userDir, 100) + xorKey = result.xorKey + } + if (!ciphertext) return { success: false, error: '未找到 V2 模板文件,请先在微信中查看几张图片' } if (xorKey === null) return { success: false, error: '未能从模板文件中计算出有效的 XOR 密钥,请确保在微信中查看了多张不同的图片' } @@ -846,26 +855,26 @@ export class KeyService { } } - private async _findTemplateData(userDir: string): Promise<{ ciphertext: Buffer | null; xorKey: number | null }> { + private async _findTemplateData(userDir: string, limit: number = 32): Promise<{ ciphertext: Buffer | null; xorKey: number | null }> { const { readdirSync, readFileSync, statSync } = await import('fs') const { join } = await import('path') const V2_MAGIC = Buffer.from([0x07, 0x08, 0x56, 0x32, 0x08, 0x07]) // 递归收集 *_t.dat 文件 - const collect = (dir: string, results: string[], limit = 32) => { - if (results.length >= limit) return + const collect = (dir: string, results: string[], maxFiles: number) => { + if (results.length >= maxFiles) return try { for (const entry of readdirSync(dir, { withFileTypes: true })) { - if (results.length >= limit) break + if (results.length >= maxFiles) break const full = join(dir, entry.name) - if (entry.isDirectory()) collect(full, results, limit) + if (entry.isDirectory()) collect(full, results, maxFiles) else if (entry.isFile() && entry.name.endsWith('_t.dat')) results.push(full) } } catch { /* 忽略无权限目录 */ } } const files: string[] = [] - collect(userDir, files) + collect(userDir, files, limit) // 按修改时间降序 files.sort((a, b) => {