From 37fb2d68d7b18b29532c0578d6cb19be21397721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 8 Feb 2026 09:55:31 +0800 Subject: [PATCH] Prefer QQAppId/ marker when parsing AppID Add parseAppidFromMajorV2 to napcat-common to scan a Major file for the "QQAppId/" marker and extract a null-terminated numeric AppID. Update qq-basic-info to import and prefer this new parser (falling back to the existing parseAppidFromMajor). Also correct the getMajorPath argument order when obtaining the major file path. This enables detection of AppID from a newer Major format while preserving legacy fallback behavior. --- packages/napcat-common/src/helper.ts | 29 ++++++++++++++++++++ packages/napcat-core/helper/qq-basic-info.ts | 10 +++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/napcat-common/src/helper.ts b/packages/napcat-common/src/helper.ts index d7f8a2a4..94d898df 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 b9c2e3e4..c151779d 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; }