Add enableAllBypasses and call on startup

Expose an optional enableAllBypasses export in the Napi2Native loader and invoke it during initialization in both napcat-framework and napcat-shell to enable bypasses (logs when enabled). Pre-initialize native modules earlier in the shell startup flow and await nativePacketHandler.init. Also update config o3HookMode from 1 to 0, apply a small signature whitespace fix in clientContext.sendOidbPacket, and include an updated native binary.
This commit is contained in:
手瓜一十雪
2026-02-13 14:56:18 +08:00
parent 62c9246368
commit 5c72f771c3
6 changed files with 27 additions and 16 deletions

View File

@@ -1,9 +1,9 @@
{ {
"fileLog": false, "fileLog": false,
"consoleLog": true, "consoleLog": true,
"fileLogLevel": "debug", "fileLogLevel": "debug",
"consoleLogLevel": "info", "consoleLogLevel": "info",
"packetBackend": "auto", "packetBackend": "auto",
"packetServer": "", "packetServer": "",
"o3HookMode": 1 "o3HookMode": 0
} }

View File

@@ -67,7 +67,7 @@ export class PacketClientContext {
await this._client.init(pid, recv, send); await this._client.init(pid, recv, send);
} }
async sendOidbPacket<T extends boolean = false>(pkt: OidbPacket, rsp?: T, timeout?: number): Promise<T extends true ? Buffer : void> { async sendOidbPacket<T extends boolean = false> (pkt: OidbPacket, rsp?: T, timeout?: number): Promise<T extends true ? Buffer : void> {
const raw = await this._client.sendOidbPacket(pkt, rsp, timeout); const raw = await this._client.sendOidbPacket(pkt, rsp, timeout);
return raw.data as T extends true ? Buffer : void; return raw.data as T extends true ? Buffer : void;
} }

View File

@@ -6,6 +6,8 @@ import { LogWrapper } from '../../helper/log';
export interface Napi2NativeExportType { export interface Napi2NativeExportType {
initHook?: (send: string, recv: string) => boolean; initHook?: (send: string, recv: string) => boolean;
setVerbose?: (verbose: boolean) => void; // 默认关闭日志
enableAllBypasses?: () => void;
} }
export class Napi2NativeLoader { export class Napi2NativeLoader {

View File

@@ -42,6 +42,11 @@ export async function NCoreInitFramework (
const wrapper = loadQQWrapper(basicInfoWrapper.QQMainPath, basicInfoWrapper.getFullQQVersion()); const wrapper = loadQQWrapper(basicInfoWrapper.QQMainPath, basicInfoWrapper.getFullQQVersion());
const nativePacketHandler = new NativePacketHandler({ logger }); // 初始化 NativePacketHandler 用于后续使用 const nativePacketHandler = new NativePacketHandler({ logger }); // 初始化 NativePacketHandler 用于后续使用
const napi2nativeLoader = new Napi2NativeLoader({ logger }); // 初始化 Napi2NativeLoader 用于后续使用 const napi2nativeLoader = new Napi2NativeLoader({ logger }); // 初始化 Napi2NativeLoader 用于后续使用
//console.log('[NapCat] [Napi2NativeLoader]', napi2nativeLoader.nativeExports.enableAllBypasses?.());
const bypassEnabled = napi2nativeLoader.nativeExports.enableAllBypasses?.();
if (bypassEnabled) {
logger.log('[NapCat] Napi2NativeLoader: 已启用Bypass');
}
// nativePacketHandler.onAll((packet) => { // nativePacketHandler.onAll((packet) => {
// console.log('[Packet]', packet.uin, packet.cmd, packet.hex_data); // console.log('[Packet]', packet.uin, packet.cmd, packet.hex_data);
// }); // });

View File

@@ -388,21 +388,25 @@ export async function NCoreInitShell () {
handleUncaughtExceptions(logger); handleUncaughtExceptions(logger);
await applyPendingUpdates(pathWrapper, logger); await applyPendingUpdates(pathWrapper, logger);
// 提前初始化 Native 模块(在登录前加载)
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
const nativePacketHandler = new NativePacketHandler({ logger });
const napi2nativeLoader = new Napi2NativeLoader({ logger });
await nativePacketHandler.init(basicInfoWrapper.getFullQQVersion());
// 初始化 FFmpeg 服务 // 初始化 FFmpeg 服务
await FFmpegService.init(pathWrapper.binaryPath, logger); await FFmpegService.init(pathWrapper.binaryPath, logger);
if (!(process.env['NAPCAT_DISABLE_PIPE'] === '1' || process.env['NAPCAT_WORKER_PROCESS'] === '1')) { if (!(process.env['NAPCAT_DISABLE_PIPE'] === '1' || process.env['NAPCAT_WORKER_PROCESS'] === '1')) {
await connectToNamedPipe(logger).catch(e => logger.logError('命名管道连接失败', e)); await connectToNamedPipe(logger).catch(e => logger.logError('命名管道连接失败', e));
} }
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
const wrapper = loadQQWrapper(basicInfoWrapper.QQMainPath, basicInfoWrapper.getFullQQVersion()); const wrapper = loadQQWrapper(basicInfoWrapper.QQMainPath, basicInfoWrapper.getFullQQVersion());
const nativePacketHandler = new NativePacketHandler({ logger }); // 初始化 NativePacketHandler 用于后续使用
const napi2nativeLoader = new Napi2NativeLoader({ logger }); // 初始化 Napi2NativeLoader 用于后续使用
// nativePacketHandler.onAll((packet) => { // wrapper.node 加载后立刻启用 Bypass
// console.log('[Packet]', packet.uin, packet.cmd, packet.hex_data); const bypassEnabled = napi2nativeLoader.nativeExports.enableAllBypasses?.();
// }); if (bypassEnabled) {
await nativePacketHandler.init(basicInfoWrapper.getFullQQVersion()); logger.log('[NapCat] Napi2NativeLoader: 已启用Bypass');
}
const o3Service = wrapper.NodeIO3MiscService.get(); const o3Service = wrapper.NodeIO3MiscService.get();
o3Service.addO3MiscListener(new NodeIO3MiscListener()); o3Service.addO3MiscListener(new NodeIO3MiscListener());