Add process bypass option and update bypass fields

Introduce a new 'process' bypass option and remove the old 'maps' key, updating all related schemas, types, defaults and validation. Adjusted napcat.json ordering and NapcatConfig defaults, updated BypassOptions schema and TypeScript interfaces, backend validation keys, loader/default parsing logic, and the web UI form mappings/labels to reflect the new field set and ordering.
This commit is contained in:
手瓜一十雪
2026-02-18 22:14:31 +08:00
parent b9f61cc0ee
commit 10bda7f9b4
8 changed files with 51 additions and 55 deletions

View File

@@ -8,10 +8,10 @@
"o3HookMode": 1,
"bypass": {
"hook": true,
"module": true,
"window": true,
"js": true,
"module": true,
"process": true,
"container": true,
"maps": true
"js": true
}
}

View File

@@ -5,11 +5,11 @@ import { AnySchema } from 'ajv';
export const BypassOptionsSchema = Type.Object({
hook: Type.Boolean({ default: true }),
module: Type.Boolean({ default: true }),
window: Type.Boolean({ default: true }),
js: Type.Boolean({ default: true }),
module: Type.Boolean({ default: true }),
process: Type.Boolean({ default: true }),
container: Type.Boolean({ default: true }),
maps: Type.Boolean({ default: true }),
js: Type.Boolean({ default: true }),
});
export const NapcatConfigSchema = Type.Object({

View File

@@ -6,11 +6,11 @@ import { LogWrapper } from '../../helper/log';
export interface BypassOptions {
hook?: boolean;
module?: boolean;
window?: boolean;
js?: boolean;
module?: boolean;
process?: boolean;
container?: boolean;
maps?: boolean;
js?: boolean;
}
export interface Napi2NativeExportType {

View File

@@ -50,11 +50,11 @@ export async function NCoreInitFramework (
// 读取 napcat.json 配置
let bypassOptions: BypassOptions = {
hook: false,
module: false,
window: false,
js: false,
module: false,
process: false,
container: false,
maps: false,
js: false,
};
try {
const configFile = path.join(pathWrapper.configPath, 'napcat.json');

View File

@@ -51,15 +51,14 @@ import { connectToNamedPipe } from './pipe';
function loadBypassConfig (configPath: string, logger: LogWrapper): BypassOptions {
const defaultOptions: BypassOptions = {
hook: true,
module: true,
window: true,
js: true,
module: true,
process: true,
container: true,
maps: true,
js: true,
};
let options = { ...defaultOptions };
try {
const configFile = path.join(configPath, 'napcat.json');
if (fs.existsSync(configFile)) {
@@ -72,13 +71,11 @@ function loadBypassConfig (configPath: string, logger: LogWrapper): BypassOption
} catch (e) {
logger.logWarn('[NapCat] 读取 bypass 配置失败,使用默认值:', e);
}
// 根据分步禁用级别覆盖配置
const disableLevel = parseInt(process.env['NAPCAT_BYPASS_DISABLE_LEVEL'] || '0', 10);
if (disableLevel > 0) {
const levelDescriptions = ['全部启用', '禁用 hook', '禁用 hook + module', '全部禁用 bypass'];
logger.logWarn(`[NapCat] 崩溃恢复:当前 bypass 禁用级别 ${disableLevel} (${levelDescriptions[disableLevel] ?? '未知'})`);
if (disableLevel >= 1) {
options.hook = false;
}
@@ -87,14 +84,13 @@ function loadBypassConfig (configPath: string, logger: LogWrapper): BypassOption
}
if (disableLevel >= 3) {
options.hook = false;
options.module = false;
options.window = false;
options.js = false;
options.module = false;
options.process = false;
options.container = false;
options.maps = false;
options.js = false;
}
}
return options;
}
// NapCat Shell App ES 入口文件

View File

@@ -16,11 +16,11 @@ const defaultNapcatConfig = {
o3HookMode: 1,
bypass: {
hook: true,
module: true,
window: true,
js: true,
module: true,
process: true,
container: true,
maps: true,
js: true,
},
};
@@ -81,7 +81,7 @@ export const NapCatSetConfigHandler: RequestHandler = (req, res) => {
// 验证 bypass 字段
if (mergedConfig.bypass && typeof mergedConfig.bypass === 'object') {
const bypass = mergedConfig.bypass as Record<string, unknown>;
const validKeys = ['hook', 'module', 'window', 'js', 'container', 'maps'];
const validKeys = ['hook', 'window', 'module', 'process', 'container', 'js'];
for (const key of validKeys) {
if (key in bypass && typeof bypass[key] !== 'boolean') {
return sendError(res, `bypass.${key} must be boolean`);

View File

@@ -10,20 +10,20 @@ import QQManager from '@/controllers/qq_manager';
interface BypassFormData {
hook: boolean;
module: boolean;
window: boolean;
js: boolean;
module: boolean;
process: boolean;
container: boolean;
maps: boolean;
js: boolean;
}
const defaultBypass: BypassFormData = {
hook: true,
module: true,
window: true,
js: true,
module: true,
process: true,
container: true,
maps: true,
js: true,
};
const BypassConfigCard = () => {
@@ -43,11 +43,11 @@ const BypassConfigCard = () => {
const config = await QQManager.getNapCatConfig();
const bypass = config.bypass ?? defaultBypass;
setValue('hook', bypass.hook ?? true);
setValue('module', bypass.module ?? true);
setValue('window', bypass.window ?? true);
setValue('js', bypass.js ?? true);
setValue('module', bypass.module ?? true);
setValue('process', bypass.process ?? true);
setValue('container', bypass.container ?? true);
setValue('maps', bypass.maps ?? true);
setValue('js', bypass.js ?? true);
if (showTip) toast.success('刷新成功');
} catch (error) {
const msg = (error as Error).message;
@@ -101,17 +101,6 @@ const BypassConfigCard = () => {
/>
)}
/>
<Controller
control={control}
name='module'
render={({ field }) => (
<SwitchCard
{...field}
label='Module'
description='加载模块隐藏'
/>
)}
/>
<Controller
control={control}
name='window'
@@ -125,12 +114,23 @@ const BypassConfigCard = () => {
/>
<Controller
control={control}
name='js'
name='module'
render={({ field }) => (
<SwitchCard
{...field}
label='JS'
description='JS Bypass保留'
label='Module'
description='加载模块隐藏'
/>
)}
/>
<Controller
control={control}
name='process'
render={({ field }) => (
<SwitchCard
{...field}
label='Process'
description='进程反检测'
/>
)}
/>
@@ -147,12 +147,12 @@ const BypassConfigCard = () => {
/>
<Controller
control={control}
name='maps'
name='js'
render={({ field }) => (
<SwitchCard
{...field}
label='Maps'
description='linux maps反检测'
label='JS'
description='JS反检测'
/>
)}
/>

View File

@@ -1,10 +1,10 @@
interface BypassOptions {
hook: boolean;
module: boolean;
window: boolean;
js: boolean;
module: boolean;
process: boolean;
container: boolean;
maps: boolean;
js: boolean;
}
interface NapCatConfig {