diff --git a/packages/napcat-common/src/helper.ts b/packages/napcat-common/src/helper.ts index d7f8a2a40..94d898df9 100644 --- a/packages/napcat-common/src/helper.ts +++ b/packages/napcat-common/src/helper.ts @@ -184,6 +184,35 @@ export function stringifyWithBigInt (obj: any) { ); } +export function parseAppidFromMajorV2 (nodeMajor: string): string | undefined { + const marker = Buffer.from('QQAppId/', 'utf-8'); + const filePath = path.resolve(nodeMajor); + const fileContent = fs.readFileSync(filePath); + + let searchPosition = 0; + while (true) { + const index = fileContent.indexOf(marker, searchPosition); + if (index === -1) { + break; + } + + const start = index + marker.length; + const end = fileContent.indexOf(0x00, start); + if (end === -1) { + break; + } + const content = fileContent.subarray(start, end); + const str = content.toString('utf-8'); + if (/^\d+$/.test(str)) { + return str; + } + + searchPosition = end + 1; + } + + return undefined; +} + export function parseAppidFromMajor (nodeMajor: string): string | undefined { const hexSequence = 'A4 09 00 00 00 35'; const sequenceBytes = Buffer.from(hexSequence.replace(/ /g, ''), 'hex'); diff --git a/packages/napcat-core/helper/qq-basic-info.ts b/packages/napcat-core/helper/qq-basic-info.ts index b9c2e3e4b..c151779de 100644 --- a/packages/napcat-core/helper/qq-basic-info.ts +++ b/packages/napcat-core/helper/qq-basic-info.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import { systemPlatform } from 'napcat-common/src/system'; -import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor } from 'napcat-common/src/helper'; +import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor, parseAppidFromMajorV2 } from 'napcat-common/src/helper'; import AppidTable from '@/napcat-core/external/appid.json'; import { LogWrapper } from './log'; import { getMajorPath } from '@/napcat-core/index'; @@ -107,7 +107,13 @@ export class QQBasicInfoWrapper { if (!this.QQMainPath) { throw new Error('QQMainPath未定义 无法通过Major获取Appid'); } - const majorPath = getMajorPath(QQVersion, this.QQMainPath); + const majorPath = getMajorPath(this.QQMainPath, QQVersion); + // 优先通过 QQAppId/ 标记搜索 + const appidV2 = parseAppidFromMajorV2(majorPath); + if (appidV2) { + return appidV2; + } + // 回落到旧方式 const appid = parseAppidFromMajor(majorPath); return appid; }