deepspider 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/check.md +122 -0
- package/.claude/agents/debug.md +106 -0
- package/.claude/agents/dispatch.md +214 -0
- package/.claude/agents/implement.md +96 -0
- package/.claude/agents/plan.md +396 -0
- package/.claude/agents/research.md +120 -0
- package/.claude/commands/evolve/merge.md +80 -0
- package/.claude/commands/trellis/before-backend-dev.md +13 -0
- package/.claude/commands/trellis/before-frontend-dev.md +13 -0
- package/.claude/commands/trellis/break-loop.md +107 -0
- package/.claude/commands/trellis/check-backend.md +13 -0
- package/.claude/commands/trellis/check-cross-layer.md +153 -0
- package/.claude/commands/trellis/check-frontend.md +13 -0
- package/.claude/commands/trellis/create-command.md +154 -0
- package/.claude/commands/trellis/finish-work.md +129 -0
- package/.claude/commands/trellis/integrate-skill.md +219 -0
- package/.claude/commands/trellis/onboard.md +358 -0
- package/.claude/commands/trellis/parallel.md +193 -0
- package/.claude/commands/trellis/record-session.md +62 -0
- package/.claude/commands/trellis/start.md +280 -0
- package/.claude/commands/trellis/update-spec.md +213 -0
- package/.claude/hooks/inject-subagent-context.py +758 -0
- package/.claude/hooks/ralph-loop.py +374 -0
- package/.claude/hooks/session-start.py +126 -0
- package/.claude/settings.json +41 -0
- package/.claude/skills/deepagents-guide/SKILL.md +428 -0
- package/.cursor/commands/trellis-before-backend-dev.md +13 -0
- package/.cursor/commands/trellis-before-frontend-dev.md +13 -0
- package/.cursor/commands/trellis-break-loop.md +107 -0
- package/.cursor/commands/trellis-check-backend.md +13 -0
- package/.cursor/commands/trellis-check-cross-layer.md +153 -0
- package/.cursor/commands/trellis-check-frontend.md +13 -0
- package/.cursor/commands/trellis-create-command.md +154 -0
- package/.cursor/commands/trellis-finish-work.md +129 -0
- package/.cursor/commands/trellis-integrate-skill.md +219 -0
- package/.cursor/commands/trellis-onboard.md +358 -0
- package/.cursor/commands/trellis-record-session.md +62 -0
- package/.cursor/commands/trellis-start.md +156 -0
- package/.cursor/commands/trellis-update-spec.md +213 -0
- package/.env.example +11 -0
- package/.husky/pre-commit +1 -0
- package/.mcp.json +8 -0
- package/.trellis/.template-hashes.json +65 -0
- package/.trellis/.version +1 -0
- package/.trellis/scripts/add-session.sh +384 -0
- package/.trellis/scripts/common/developer.sh +129 -0
- package/.trellis/scripts/common/git-context.sh +263 -0
- package/.trellis/scripts/common/paths.sh +208 -0
- package/.trellis/scripts/common/phase.sh +150 -0
- package/.trellis/scripts/common/registry.sh +247 -0
- package/.trellis/scripts/common/task-queue.sh +142 -0
- package/.trellis/scripts/common/task-utils.sh +151 -0
- package/.trellis/scripts/common/worktree.sh +128 -0
- package/.trellis/scripts/create-bootstrap.sh +299 -0
- package/.trellis/scripts/get-context.sh +7 -0
- package/.trellis/scripts/get-developer.sh +15 -0
- package/.trellis/scripts/init-developer.sh +34 -0
- package/.trellis/scripts/multi-agent/cleanup.sh +396 -0
- package/.trellis/scripts/multi-agent/create-pr.sh +241 -0
- package/.trellis/scripts/multi-agent/plan.sh +207 -0
- package/.trellis/scripts/multi-agent/start.sh +310 -0
- package/.trellis/scripts/multi-agent/status.sh +828 -0
- package/.trellis/scripts/task.sh +1118 -0
- package/.trellis/spec/backend/deepagents-guide.md +337 -0
- package/.trellis/spec/backend/directory-structure.md +126 -0
- package/.trellis/spec/backend/examples/skills/deepagents-guide/README.md +11 -0
- package/.trellis/spec/backend/examples/skills/deepagents-guide/agent.js.template +20 -0
- package/.trellis/spec/backend/examples/skills/deepagents-guide/skills-config.js.template +13 -0
- package/.trellis/spec/backend/examples/skills/deepagents-guide/subagent.js.template +19 -0
- package/.trellis/spec/backend/hook-guidelines.md +178 -0
- package/.trellis/spec/backend/index.md +36 -0
- package/.trellis/spec/backend/quality-guidelines.md +201 -0
- package/.trellis/spec/backend/state-management.md +76 -0
- package/.trellis/spec/backend/tool-guidelines.md +144 -0
- package/.trellis/spec/backend/type-safety.md +71 -0
- package/.trellis/spec/guides/code-reuse-thinking-guide.md +92 -0
- package/.trellis/spec/guides/cross-layer-thinking-guide.md +94 -0
- package/.trellis/spec/guides/index.md +79 -0
- package/.trellis/tasks/archive/02-02-evolving-skills/prd.md +61 -0
- package/.trellis/tasks/archive/02-02-evolving-skills/task.json +29 -0
- package/.trellis/tasks/archive/2026-02/00-bootstrap-guidelines/prd.md +86 -0
- package/.trellis/tasks/archive/2026-02/00-bootstrap-guidelines/task.json +27 -0
- package/.trellis/tasks/archive/2026-02/02-02-skills-system/check.jsonl +3 -0
- package/.trellis/tasks/archive/2026-02/02-02-skills-system/debug.jsonl +2 -0
- package/.trellis/tasks/archive/2026-02/02-02-skills-system/implement.jsonl +5 -0
- package/.trellis/tasks/archive/2026-02/02-02-skills-system/prd.md +33 -0
- package/.trellis/tasks/archive/2026-02/02-02-skills-system/task.json +41 -0
- package/.trellis/workflow.md +407 -0
- package/.trellis/workspace/index.md +123 -0
- package/.trellis/workspace/pony/index.md +40 -0
- package/.trellis/workspace/pony/journal-1.md +7 -0
- package/.trellis/worktree.yaml +47 -0
- package/AGENTS.md +18 -0
- package/CLAUDE.md +292 -0
- package/README.md +134 -0
- package/agents/deepspider.md +142 -0
- package/docs/DEBUG.md +42 -0
- package/docs/GUIDE.md +334 -0
- package/docs/PROMPT.md +60 -0
- package/docs/USAGE.md +226 -0
- package/eslint.config.js +51 -0
- package/package.json +78 -0
- package/requirements-crypto.txt +14 -0
- package/src/agent/index.js +97 -0
- package/src/agent/logger.js +164 -0
- package/src/agent/middleware/filterTools.js +64 -0
- package/src/agent/middleware/report.js +79 -0
- package/src/agent/prompts/system.js +315 -0
- package/src/agent/run.js +575 -0
- package/src/agent/skills/anti-detect/SKILL.md +28 -0
- package/src/agent/skills/anti-detect/evolved.md +12 -0
- package/src/agent/skills/captcha/SKILL.md +37 -0
- package/src/agent/skills/captcha/evolved.md +12 -0
- package/src/agent/skills/config.js +30 -0
- package/src/agent/skills/crawler/SKILL.md +9 -0
- package/src/agent/skills/crawler/evolved.md +16 -0
- package/src/agent/skills/dynamic-analysis/SKILL.md +91 -0
- package/src/agent/skills/dynamic-analysis/evolved.md +12 -0
- package/src/agent/skills/env/SKILL.md +72 -0
- package/src/agent/skills/env/evolved.md +12 -0
- package/src/agent/skills/evolve.js +79 -0
- package/src/agent/skills/general/SKILL.md +12 -0
- package/src/agent/skills/general/evolved.md +12 -0
- package/src/agent/skills/js2python/SKILL.md +30 -0
- package/src/agent/skills/js2python/evolved.md +13 -0
- package/src/agent/skills/report/SKILL.md +21 -0
- package/src/agent/skills/report/evolved.md +12 -0
- package/src/agent/skills/sandbox/SKILL.md +22 -0
- package/src/agent/skills/sandbox/evolved.md +16 -0
- package/src/agent/skills/static-analysis/SKILL.md +93 -0
- package/src/agent/skills/static-analysis/evolved.md +12 -0
- package/src/agent/skills/xpath/SKILL.md +119 -0
- package/src/agent/subagents/anti-detect.js +45 -0
- package/src/agent/subagents/captcha.js +51 -0
- package/src/agent/subagents/crawler.js +138 -0
- package/src/agent/subagents/dynamic.js +64 -0
- package/src/agent/subagents/env-agent.js +82 -0
- package/src/agent/subagents/index.js +37 -0
- package/src/agent/subagents/js2python.js +72 -0
- package/src/agent/subagents/sandbox.js +55 -0
- package/src/agent/subagents/static.js +66 -0
- package/src/agent/tools/analysis.js +135 -0
- package/src/agent/tools/analyzer.js +85 -0
- package/src/agent/tools/anti-detect.js +89 -0
- package/src/agent/tools/antidebug.js +64 -0
- package/src/agent/tools/async.js +43 -0
- package/src/agent/tools/browser.js +324 -0
- package/src/agent/tools/captcha.js +223 -0
- package/src/agent/tools/capture.js +179 -0
- package/src/agent/tools/correlate.js +303 -0
- package/src/agent/tools/crawler.js +116 -0
- package/src/agent/tools/cryptohook.js +80 -0
- package/src/agent/tools/debug.js +246 -0
- package/src/agent/tools/deobfuscator.js +90 -0
- package/src/agent/tools/env.js +83 -0
- package/src/agent/tools/envdump.js +92 -0
- package/src/agent/tools/evolve.js +164 -0
- package/src/agent/tools/extract.js +114 -0
- package/src/agent/tools/extractor.js +54 -0
- package/src/agent/tools/file.js +224 -0
- package/src/agent/tools/hook.js +84 -0
- package/src/agent/tools/hookManager.js +178 -0
- package/src/agent/tools/index.js +137 -0
- package/src/agent/tools/nodejs.js +101 -0
- package/src/agent/tools/patch.js +46 -0
- package/src/agent/tools/preprocess.js +71 -0
- package/src/agent/tools/profile.js +122 -0
- package/src/agent/tools/python.js +627 -0
- package/src/agent/tools/report.js +124 -0
- package/src/agent/tools/runtime.js +132 -0
- package/src/agent/tools/sandbox.js +79 -0
- package/src/agent/tools/store.js +73 -0
- package/src/agent/tools/trace.js +74 -0
- package/src/agent/tools/tracing.js +201 -0
- package/src/agent/tools/utils.js +51 -0
- package/src/agent/tools/verify.js +184 -0
- package/src/agent/tools/webcrack.js +109 -0
- package/src/analyzer/ASTAnalyzer.js +387 -0
- package/src/analyzer/CallStackAnalyzer.js +379 -0
- package/src/analyzer/Deobfuscator.js +289 -0
- package/src/analyzer/EncryptionAnalyzer.js +99 -0
- package/src/analyzer/index.js +22 -0
- package/src/browser/EnvBridge.js +186 -0
- package/src/browser/cdp.js +168 -0
- package/src/browser/client.js +197 -0
- package/src/browser/collector.js +444 -0
- package/src/browser/collectors/RequestCryptoLinker.js +109 -0
- package/src/browser/collectors/ResponseSearcher.js +107 -0
- package/src/browser/collectors/ScriptCollector.js +158 -0
- package/src/browser/collectors/index.js +26 -0
- package/src/browser/defaultHooks.js +932 -0
- package/src/browser/hooks/crypto.js +55 -0
- package/src/browser/hooks/index.js +64 -0
- package/src/browser/hooks/native.js +9 -0
- package/src/browser/hooks/network.js +33 -0
- package/src/browser/index.js +42 -0
- package/src/browser/interceptors/NetworkInterceptor.js +116 -0
- package/src/browser/interceptors/ScriptInterceptor.js +76 -0
- package/src/browser/interceptors/index.js +6 -0
- package/src/browser/ui/analysisPanel.js +1782 -0
- package/src/browser/ui/confirmDialog.js +158 -0
- package/src/browser/ui/panel.html +152 -0
- package/src/browser/ui/selector.js +170 -0
- package/src/config/index.js +5 -0
- package/src/config/paths.js +71 -0
- package/src/config/patterns/crypto.js +36 -0
- package/src/config/profiles/chrome.json +71 -0
- package/src/config/profiles/firefox.json +44 -0
- package/src/config/profiles/safari.json +38 -0
- package/src/core/EnvMonitor.js +200 -0
- package/src/core/PatchGenerator.js +278 -0
- package/src/core/Sandbox.js +181 -0
- package/src/env/AntiAntiDebug.js +111 -0
- package/src/env/AsyncHook.js +68 -0
- package/src/env/BrowserAPIList.js +265 -0
- package/src/env/CookieHook.js +48 -0
- package/src/env/CryptoHook.js +205 -0
- package/src/env/EnvCodeGenerator.js +157 -0
- package/src/env/EnvDumper.js +356 -0
- package/src/env/EnvExtractor.js +220 -0
- package/src/env/HookBase.js +618 -0
- package/src/env/NetworkHook.js +159 -0
- package/src/env/modules/bom/history.js +29 -0
- package/src/env/modules/bom/location.js +26 -0
- package/src/env/modules/bom/navigator.js +70 -0
- package/src/env/modules/bom/screen.js +26 -0
- package/src/env/modules/bom/storage.js +23 -0
- package/src/env/modules/dom/document.js +110 -0
- package/src/env/modules/dom/event.js +51 -0
- package/src/env/modules/index.js +34 -0
- package/src/env/modules/webapi/fetch.js +46 -0
- package/src/env/modules/webapi/url.js +47 -0
- package/src/env/modules/webapi/xhr.js +48 -0
- package/src/index.js +27 -0
- package/src/mcp/server.js +89 -0
- package/src/store/DataStore.js +708 -0
- package/src/store/Store.js +158 -0
- package/src/store/Validator.js +24 -0
- package/test/analyze.test.js +90 -0
- package/test/envdump.test.js +74 -0
- package/test/flow.test.js +90 -0
- package/test/hooks.test.js +138 -0
- package/test/plugin.test.js +35 -0
- package/test/refactor-full.test.js +30 -0
- package/test/refactor.test.js +21 -0
- package/test/samples/obfuscated.js +61 -0
- package/test/samples/original.js +66 -0
- package/test/samples/v10_eval_chain.js +52 -0
- package/test/samples/v11_bytecode_vm.js +81 -0
- package/test/samples/v12_polymorphic.js +69 -0
- package/test/samples/v1_ob_basic.js +98 -0
- package/test/samples/v2_ob_advanced.js +99 -0
- package/test/samples/v3_jjencode.js +77 -0
- package/test/samples/v4_aaencode.js +73 -0
- package/test/samples/v5_control_flow.js +86 -0
- package/test/samples/v6_string_encryption.js +71 -0
- package/test/samples/v7_jsvmp.js +83 -0
- package/test/samples/v8_anti_debug.js +79 -0
- package/test/samples/v9_proxy_trap.js +49 -0
- package/test/samples.test.js +96 -0
- package/test/webcrack.test.js +55 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSpider - 沙箱管理器
|
|
3
|
+
* 基于 isolated-vm 的安全执行环境
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import ivm from 'isolated-vm';
|
|
7
|
+
import { EnvMonitor } from './EnvMonitor.js';
|
|
8
|
+
|
|
9
|
+
export class Sandbox {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.isolate = null;
|
|
12
|
+
this.context = null;
|
|
13
|
+
this.missingEnv = [];
|
|
14
|
+
this.monitor = new EnvMonitor();
|
|
15
|
+
this.envLoaded = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async init(options = {}) {
|
|
19
|
+
const { memoryLimit = 128 } = options;
|
|
20
|
+
|
|
21
|
+
this.isolate = new ivm.Isolate({ memoryLimit });
|
|
22
|
+
this.context = await this.isolate.createContext();
|
|
23
|
+
|
|
24
|
+
const jail = this.context.global;
|
|
25
|
+
await jail.set('global', jail.derefInto());
|
|
26
|
+
|
|
27
|
+
await this._injectBase(jail);
|
|
28
|
+
await this._injectMonitor(jail);
|
|
29
|
+
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 加载环境代码
|
|
34
|
+
async loadEnv(envCode) {
|
|
35
|
+
if (!envCode) return;
|
|
36
|
+
await this.context.eval(envCode);
|
|
37
|
+
this.envLoaded = true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async _injectBase(jail) {
|
|
41
|
+
// console
|
|
42
|
+
await jail.set('console', {
|
|
43
|
+
log: new ivm.Callback((...args) => console.log('[DeepSpider:sandbox]', ...args)),
|
|
44
|
+
error: new ivm.Callback((...args) => console.error('[DeepSpider:sandbox]', ...args)),
|
|
45
|
+
warn: new ivm.Callback((...args) => console.warn('[DeepSpider:sandbox]', ...args))
|
|
46
|
+
}, { copy: true });
|
|
47
|
+
|
|
48
|
+
// Base64
|
|
49
|
+
await jail.set('atob', new ivm.Callback((s) =>
|
|
50
|
+
Buffer.from(s, 'base64').toString('binary')
|
|
51
|
+
));
|
|
52
|
+
await jail.set('btoa', new ivm.Callback((s) =>
|
|
53
|
+
Buffer.from(s, 'binary').toString('base64')
|
|
54
|
+
));
|
|
55
|
+
|
|
56
|
+
// Timers (stub)
|
|
57
|
+
await jail.set('setTimeout', new ivm.Callback(() => 0));
|
|
58
|
+
await jail.set('setInterval', new ivm.Callback(() => 0));
|
|
59
|
+
await jail.set('clearTimeout', new ivm.Callback(() => {}));
|
|
60
|
+
await jail.set('clearInterval', new ivm.Callback(() => {}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async _injectMonitor(jail) {
|
|
64
|
+
const self = this;
|
|
65
|
+
|
|
66
|
+
await jail.set('__recordMissing__', new ivm.Callback((path) => {
|
|
67
|
+
if (!self.missingEnv.includes(path)) {
|
|
68
|
+
self.missingEnv.push(path);
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
const monitorCode = `
|
|
73
|
+
const window = global;
|
|
74
|
+
global.window = window;
|
|
75
|
+
global.self = window;
|
|
76
|
+
|
|
77
|
+
global.__createProxy__ = function(obj, path) {
|
|
78
|
+
return new Proxy(obj, {
|
|
79
|
+
get(t, p) {
|
|
80
|
+
if (typeof p === 'symbol') return t[p];
|
|
81
|
+
const fullPath = path ? path + '.' + p : String(p);
|
|
82
|
+
if (t[p] === undefined && !(p in t)) {
|
|
83
|
+
__recordMissing__(fullPath);
|
|
84
|
+
}
|
|
85
|
+
return t[p];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
await this.context.eval(monitorCode);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async inject(code) {
|
|
95
|
+
try {
|
|
96
|
+
await this.context.eval(code);
|
|
97
|
+
// 返回更多信息帮助 Agent 判断下一步
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
message: '代码已注入沙箱,请使用 sandbox_execute 验证执行',
|
|
101
|
+
codeLength: code.length,
|
|
102
|
+
hint: '建议调用 sandbox_execute 测试注入的函数是否可用'
|
|
103
|
+
};
|
|
104
|
+
} catch (e) {
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
error: e.message,
|
|
108
|
+
hint: '注入失败,请检查代码语法'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async execute(code, options = {}) {
|
|
114
|
+
const { timeout = 5000 } = options;
|
|
115
|
+
this.missingEnv = [];
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const script = await this.isolate.compileScript(code);
|
|
119
|
+
const result = await script.run(this.context, { timeout });
|
|
120
|
+
|
|
121
|
+
// 记录到监控系统
|
|
122
|
+
this.missingEnv.forEach(p => this.monitor.logMissing(p));
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
success: true,
|
|
126
|
+
result: this._serialize(result),
|
|
127
|
+
missingEnv: [...this.missingEnv],
|
|
128
|
+
stats: this.monitor.getStats()
|
|
129
|
+
};
|
|
130
|
+
} catch (e) {
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
error: e.message,
|
|
134
|
+
errorType: this._classifyError(e),
|
|
135
|
+
missingEnv: [...this.missingEnv],
|
|
136
|
+
stats: this.monitor.getStats()
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 错误分类(帮助判断是环境缺失还是代码错误)
|
|
142
|
+
_classifyError(e) {
|
|
143
|
+
const msg = e.message || '';
|
|
144
|
+
if (/is not defined/.test(msg)) return 'undefined-reference';
|
|
145
|
+
if (/is not a function/.test(msg)) return 'not-a-function';
|
|
146
|
+
if (/Cannot read propert/.test(msg)) return 'null-access';
|
|
147
|
+
if (/timeout/.test(msg)) return 'timeout';
|
|
148
|
+
return 'runtime-error';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_serialize(val) {
|
|
152
|
+
if (val === undefined) return 'undefined';
|
|
153
|
+
if (val === null) return 'null';
|
|
154
|
+
if (typeof val === 'function') return `[Function]`;
|
|
155
|
+
if (typeof val === 'object') {
|
|
156
|
+
try { return JSON.stringify(val); }
|
|
157
|
+
catch { return '[Object]'; }
|
|
158
|
+
}
|
|
159
|
+
return String(val);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async reset() {
|
|
163
|
+
await this.dispose();
|
|
164
|
+
this.monitor.clearLogs();
|
|
165
|
+
this.envLoaded = false;
|
|
166
|
+
await this.init();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async dispose() {
|
|
170
|
+
if (this.context) {
|
|
171
|
+
this.context.release();
|
|
172
|
+
this.context = null;
|
|
173
|
+
}
|
|
174
|
+
if (this.isolate) {
|
|
175
|
+
this.isolate.dispose();
|
|
176
|
+
this.isolate = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export default Sandbox;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSpider - 反反调试模块
|
|
3
|
+
* 绕过常见的反调试检测
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { HookBase } from './HookBase.js';
|
|
7
|
+
|
|
8
|
+
export class AntiAntiDebug {
|
|
9
|
+
/**
|
|
10
|
+
* 绕过无限 debugger
|
|
11
|
+
*/
|
|
12
|
+
generateAntiDebuggerCode() {
|
|
13
|
+
return HookBase.getBaseCode() + `
|
|
14
|
+
(function() {
|
|
15
|
+
const deepspider = window.__deepspider__;
|
|
16
|
+
if (!deepspider) return;
|
|
17
|
+
|
|
18
|
+
const origCtor = Function.prototype.constructor;
|
|
19
|
+
Function.prototype.constructor = deepspider.native(function(...args) {
|
|
20
|
+
if (args[0] && args[0].includes('debugger')) {
|
|
21
|
+
deepspider.log('debug', { action: 'block.debugger.constructor' });
|
|
22
|
+
return function() {};
|
|
23
|
+
}
|
|
24
|
+
return origCtor.apply(this, args);
|
|
25
|
+
}, origCtor);
|
|
26
|
+
|
|
27
|
+
const origEval = eval;
|
|
28
|
+
eval = deepspider.native(function(code) {
|
|
29
|
+
if (typeof code === 'string' && code.includes('debugger')) {
|
|
30
|
+
deepspider.log('debug', { action: 'block.debugger.eval' });
|
|
31
|
+
code = code.replace(/debugger/g, '');
|
|
32
|
+
}
|
|
33
|
+
return origEval(code);
|
|
34
|
+
}, origEval);
|
|
35
|
+
|
|
36
|
+
const origSetInterval = setInterval;
|
|
37
|
+
setInterval = deepspider.native(function(fn, delay) {
|
|
38
|
+
if (fn.toString().includes('debugger')) {
|
|
39
|
+
deepspider.log('debug', { action: 'block.debugger.setInterval' });
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
return origSetInterval(fn, delay);
|
|
43
|
+
}, origSetInterval);
|
|
44
|
+
|
|
45
|
+
console.log('[DeepSpider:debug] 无限 debugger 防护已启用');
|
|
46
|
+
})();
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 绕过控制台检测
|
|
52
|
+
*/
|
|
53
|
+
generateAntiConsoleDetectCode() {
|
|
54
|
+
return HookBase.getBaseCode() + `
|
|
55
|
+
(function() {
|
|
56
|
+
const deepspider = window.__deepspider__;
|
|
57
|
+
if (!deepspider) return;
|
|
58
|
+
|
|
59
|
+
Object.defineProperty(window, 'outerWidth', { get: () => window.innerWidth });
|
|
60
|
+
Object.defineProperty(window, 'outerHeight', { get: () => window.innerHeight + 100 });
|
|
61
|
+
|
|
62
|
+
const origLog = console.log;
|
|
63
|
+
console.log = deepspider.native(function(...args) {
|
|
64
|
+
if (args[0]?.toString?.().includes('devtools')) {
|
|
65
|
+
deepspider.log('debug', { action: 'block.console.devtools' });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
return origLog.apply(console, args);
|
|
69
|
+
}, origLog);
|
|
70
|
+
|
|
71
|
+
console.table = function() {};
|
|
72
|
+
console.clear = function() {};
|
|
73
|
+
|
|
74
|
+
console.log('[DeepSpider:debug] 控制台检测防护已启用');
|
|
75
|
+
})();
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 绕过 CDP 检测
|
|
81
|
+
*/
|
|
82
|
+
generateAntiCDPDetectCode() {
|
|
83
|
+
return HookBase.getBaseCode() + `
|
|
84
|
+
(function() {
|
|
85
|
+
delete window.cdc_adoQpoasnfa76pfcZLmcfl_Array;
|
|
86
|
+
delete window.cdc_adoQpoasnfa76pfcZLmcfl_Promise;
|
|
87
|
+
delete window.cdc_adoQpoasnfa76pfcZLmcfl_Symbol;
|
|
88
|
+
|
|
89
|
+
Object.defineProperty(navigator, 'webdriver', {
|
|
90
|
+
get: () => false,
|
|
91
|
+
configurable: true
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log('[DeepSpider:debug] CDP 检测防护已启用');
|
|
95
|
+
})();
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 生成完整的反反调试代码
|
|
101
|
+
*/
|
|
102
|
+
generateFullAntiDebugCode() {
|
|
103
|
+
return [
|
|
104
|
+
this.generateAntiDebuggerCode(),
|
|
105
|
+
this.generateAntiConsoleDetectCode(),
|
|
106
|
+
this.generateAntiCDPDetectCode(),
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default AntiAntiDebug;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSpider - 异步追踪 Hook
|
|
3
|
+
* 追踪 Promise、setTimeout 等异步调用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { HookBase } from './HookBase.js';
|
|
7
|
+
|
|
8
|
+
export class AsyncHook {
|
|
9
|
+
/**
|
|
10
|
+
* 生成 Promise Hook 代码
|
|
11
|
+
*/
|
|
12
|
+
generatePromiseHookCode() {
|
|
13
|
+
return HookBase.getBaseCode() + `
|
|
14
|
+
(function() {
|
|
15
|
+
const deepspider = window.__deepspider__;
|
|
16
|
+
if (!deepspider) return;
|
|
17
|
+
|
|
18
|
+
const originalThen = Promise.prototype.then;
|
|
19
|
+
Promise.prototype.then = deepspider.native(function(onFulfilled, onRejected) {
|
|
20
|
+
const stack = new Error().stack;
|
|
21
|
+
|
|
22
|
+
const wrappedFulfilled = onFulfilled ? function(value) {
|
|
23
|
+
deepspider.log('async', { action: 'promise.then', stack });
|
|
24
|
+
return onFulfilled(value);
|
|
25
|
+
} : onFulfilled;
|
|
26
|
+
|
|
27
|
+
return originalThen.call(this, wrappedFulfilled, onRejected);
|
|
28
|
+
}, originalThen);
|
|
29
|
+
|
|
30
|
+
console.log('[DeepSpider:async] Promise Hook 已启用');
|
|
31
|
+
})();
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 生成 setTimeout/setInterval Hook 代码
|
|
37
|
+
*/
|
|
38
|
+
generateTimerHookCode() {
|
|
39
|
+
return HookBase.getBaseCode() + `
|
|
40
|
+
(function() {
|
|
41
|
+
const deepspider = window.__deepspider__;
|
|
42
|
+
if (!deepspider) return;
|
|
43
|
+
|
|
44
|
+
const origSetTimeout = setTimeout;
|
|
45
|
+
const origSetInterval = setInterval;
|
|
46
|
+
|
|
47
|
+
setTimeout = deepspider.native(function(fn, delay) {
|
|
48
|
+
deepspider.log('timer', { action: 'setTimeout', delay });
|
|
49
|
+
return origSetTimeout(function() {
|
|
50
|
+
deepspider.log('timer', { action: 'setTimeout.callback', delay });
|
|
51
|
+
if (typeof fn === 'function') fn.apply(this, arguments);
|
|
52
|
+
}, delay);
|
|
53
|
+
}, origSetTimeout);
|
|
54
|
+
|
|
55
|
+
setInterval = deepspider.native(function(fn, delay) {
|
|
56
|
+
deepspider.log('timer', { action: 'setInterval', delay });
|
|
57
|
+
return origSetInterval(function() {
|
|
58
|
+
if (typeof fn === 'function') fn.apply(this, arguments);
|
|
59
|
+
}, delay);
|
|
60
|
+
}, origSetInterval);
|
|
61
|
+
|
|
62
|
+
console.log('[DeepSpider:timer] Timer Hook 已启用');
|
|
63
|
+
})();
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default AsyncHook;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSpider - 浏览器 API 列表
|
|
3
|
+
* 借鉴 v_jstools 的 v_getsetfunc_list.js
|
|
4
|
+
* 用于批量 Hook 和环境代码生成
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Getter/Setter 属性列表 [类名, 属性名]
|
|
8
|
+
export const GETSET_LIST = [
|
|
9
|
+
// Navigator
|
|
10
|
+
['Navigator', 'userAgent'],
|
|
11
|
+
['Navigator', 'platform'],
|
|
12
|
+
['Navigator', 'language'],
|
|
13
|
+
['Navigator', 'languages'],
|
|
14
|
+
['Navigator', 'cookieEnabled'],
|
|
15
|
+
['Navigator', 'onLine'],
|
|
16
|
+
['Navigator', 'hardwareConcurrency'],
|
|
17
|
+
['Navigator', 'deviceMemory'],
|
|
18
|
+
['Navigator', 'maxTouchPoints'],
|
|
19
|
+
['Navigator', 'webdriver'],
|
|
20
|
+
['Navigator', 'vendor'],
|
|
21
|
+
['Navigator', 'appVersion'],
|
|
22
|
+
['Navigator', 'appName'],
|
|
23
|
+
['Navigator', 'product'],
|
|
24
|
+
['Navigator', 'productSub'],
|
|
25
|
+
|
|
26
|
+
// Screen
|
|
27
|
+
['Screen', 'width'],
|
|
28
|
+
['Screen', 'height'],
|
|
29
|
+
['Screen', 'availWidth'],
|
|
30
|
+
['Screen', 'availHeight'],
|
|
31
|
+
['Screen', 'colorDepth'],
|
|
32
|
+
['Screen', 'pixelDepth'],
|
|
33
|
+
|
|
34
|
+
// Document
|
|
35
|
+
['Document', 'cookie'],
|
|
36
|
+
['Document', 'domain'],
|
|
37
|
+
['Document', 'referrer'],
|
|
38
|
+
['Document', 'title'],
|
|
39
|
+
['Document', 'URL'],
|
|
40
|
+
['Document', 'documentElement'],
|
|
41
|
+
['Document', 'body'],
|
|
42
|
+
['Document', 'head'],
|
|
43
|
+
['Document', 'hidden'],
|
|
44
|
+
['Document', 'visibilityState'],
|
|
45
|
+
|
|
46
|
+
// Location
|
|
47
|
+
['Location', 'href'],
|
|
48
|
+
['Location', 'protocol'],
|
|
49
|
+
['Location', 'host'],
|
|
50
|
+
['Location', 'hostname'],
|
|
51
|
+
['Location', 'port'],
|
|
52
|
+
['Location', 'pathname'],
|
|
53
|
+
['Location', 'search'],
|
|
54
|
+
['Location', 'hash'],
|
|
55
|
+
['Location', 'origin'],
|
|
56
|
+
|
|
57
|
+
// Window
|
|
58
|
+
['Window', 'innerWidth'],
|
|
59
|
+
['Window', 'innerHeight'],
|
|
60
|
+
['Window', 'outerWidth'],
|
|
61
|
+
['Window', 'outerHeight'],
|
|
62
|
+
['Window', 'screenX'],
|
|
63
|
+
['Window', 'screenY'],
|
|
64
|
+
['Window', 'devicePixelRatio'],
|
|
65
|
+
['Window', 'localStorage'],
|
|
66
|
+
['Window', 'sessionStorage'],
|
|
67
|
+
['Window', 'name'],
|
|
68
|
+
|
|
69
|
+
// HTMLElement
|
|
70
|
+
['HTMLElement', 'offsetWidth'],
|
|
71
|
+
['HTMLElement', 'offsetHeight'],
|
|
72
|
+
['HTMLElement', 'clientWidth'],
|
|
73
|
+
['HTMLElement', 'clientHeight'],
|
|
74
|
+
['HTMLElement', 'scrollWidth'],
|
|
75
|
+
['HTMLElement', 'scrollHeight'],
|
|
76
|
+
['HTMLElement', 'innerHTML'],
|
|
77
|
+
['HTMLElement', 'innerText'],
|
|
78
|
+
['HTMLElement', 'textContent'],
|
|
79
|
+
|
|
80
|
+
// Canvas
|
|
81
|
+
['HTMLCanvasElement', 'width'],
|
|
82
|
+
['HTMLCanvasElement', 'height'],
|
|
83
|
+
['CanvasRenderingContext2D', 'fillStyle'],
|
|
84
|
+
['CanvasRenderingContext2D', 'strokeStyle'],
|
|
85
|
+
['CanvasRenderingContext2D', 'font'],
|
|
86
|
+
|
|
87
|
+
// WebGL
|
|
88
|
+
['WebGLRenderingContext', 'drawingBufferWidth'],
|
|
89
|
+
['WebGLRenderingContext', 'drawingBufferHeight'],
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
// 方法列表 [类名, 方法名]
|
|
93
|
+
export const FUNC_LIST = [
|
|
94
|
+
// Document
|
|
95
|
+
['Document', 'getElementById'],
|
|
96
|
+
['Document', 'getElementsByClassName'],
|
|
97
|
+
['Document', 'getElementsByTagName'],
|
|
98
|
+
['Document', 'getElementsByName'],
|
|
99
|
+
['Document', 'querySelector'],
|
|
100
|
+
['Document', 'querySelectorAll'],
|
|
101
|
+
['Document', 'createElement'],
|
|
102
|
+
['Document', 'createTextNode'],
|
|
103
|
+
['Document', 'createEvent'],
|
|
104
|
+
['Document', 'write'],
|
|
105
|
+
['Document', 'writeln'],
|
|
106
|
+
|
|
107
|
+
// Element
|
|
108
|
+
['Element', 'querySelector'],
|
|
109
|
+
['Element', 'querySelectorAll'],
|
|
110
|
+
['Element', 'getAttribute'],
|
|
111
|
+
['Element', 'setAttribute'],
|
|
112
|
+
['Element', 'removeAttribute'],
|
|
113
|
+
['Element', 'hasAttribute'],
|
|
114
|
+
['Element', 'getBoundingClientRect'],
|
|
115
|
+
['Element', 'getClientRects'],
|
|
116
|
+
|
|
117
|
+
// Canvas
|
|
118
|
+
['HTMLCanvasElement', 'getContext'],
|
|
119
|
+
['HTMLCanvasElement', 'toDataURL'],
|
|
120
|
+
['HTMLCanvasElement', 'toBlob'],
|
|
121
|
+
['CanvasRenderingContext2D', 'fillRect'],
|
|
122
|
+
['CanvasRenderingContext2D', 'fillText'],
|
|
123
|
+
['CanvasRenderingContext2D', 'strokeText'],
|
|
124
|
+
['CanvasRenderingContext2D', 'measureText'],
|
|
125
|
+
['CanvasRenderingContext2D', 'getImageData'],
|
|
126
|
+
['CanvasRenderingContext2D', 'putImageData'],
|
|
127
|
+
['CanvasRenderingContext2D', 'drawImage'],
|
|
128
|
+
|
|
129
|
+
// WebGL
|
|
130
|
+
['WebGLRenderingContext', 'getParameter'],
|
|
131
|
+
['WebGLRenderingContext', 'getExtension'],
|
|
132
|
+
['WebGLRenderingContext', 'getSupportedExtensions'],
|
|
133
|
+
['WebGLRenderingContext', 'getShaderPrecisionFormat'],
|
|
134
|
+
['WebGL2RenderingContext', 'getParameter'],
|
|
135
|
+
|
|
136
|
+
// Navigator
|
|
137
|
+
['Navigator', 'getBattery'],
|
|
138
|
+
['Navigator', 'getGamepads'],
|
|
139
|
+
['Navigator', 'sendBeacon'],
|
|
140
|
+
['Navigator', 'vibrate'],
|
|
141
|
+
|
|
142
|
+
// Window
|
|
143
|
+
['Window', 'getComputedStyle'],
|
|
144
|
+
['Window', 'matchMedia'],
|
|
145
|
+
['Window', 'requestAnimationFrame'],
|
|
146
|
+
['Window', 'cancelAnimationFrame'],
|
|
147
|
+
['Window', 'fetch'],
|
|
148
|
+
['Window', 'open'],
|
|
149
|
+
['Window', 'close'],
|
|
150
|
+
['Window', 'postMessage'],
|
|
151
|
+
|
|
152
|
+
// Storage
|
|
153
|
+
['Storage', 'getItem'],
|
|
154
|
+
['Storage', 'setItem'],
|
|
155
|
+
['Storage', 'removeItem'],
|
|
156
|
+
['Storage', 'clear'],
|
|
157
|
+
['Storage', 'key'],
|
|
158
|
+
|
|
159
|
+
// Performance
|
|
160
|
+
['Performance', 'now'],
|
|
161
|
+
['Performance', 'getEntries'],
|
|
162
|
+
['Performance', 'getEntriesByType'],
|
|
163
|
+
['Performance', 'getEntriesByName'],
|
|
164
|
+
|
|
165
|
+
// Crypto
|
|
166
|
+
['Crypto', 'getRandomValues'],
|
|
167
|
+
['SubtleCrypto', 'encrypt'],
|
|
168
|
+
['SubtleCrypto', 'decrypt'],
|
|
169
|
+
['SubtleCrypto', 'sign'],
|
|
170
|
+
['SubtleCrypto', 'verify'],
|
|
171
|
+
['SubtleCrypto', 'digest'],
|
|
172
|
+
|
|
173
|
+
// Event
|
|
174
|
+
['EventTarget', 'addEventListener'],
|
|
175
|
+
['EventTarget', 'removeEventListener'],
|
|
176
|
+
['EventTarget', 'dispatchEvent'],
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
// HTML 标签到类的映射
|
|
180
|
+
export const HTML_TAG_MAP = {
|
|
181
|
+
HTMLElement: ['abbr', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'cite', 'code', 'dd', 'dfn', 'dt', 'em', 'figcaption', 'figure', 'footer', 'header', 'hgroup', 'i', 'kbd', 'main', 'mark', 'nav', 'noscript', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'small', 'strong', 'sub', 'summary', 'sup', 'u', 'var', 'wbr'],
|
|
182
|
+
HTMLAnchorElement: ['a'],
|
|
183
|
+
HTMLAreaElement: ['area'],
|
|
184
|
+
HTMLAudioElement: ['audio'],
|
|
185
|
+
HTMLBRElement: ['br'],
|
|
186
|
+
HTMLBaseElement: ['base'],
|
|
187
|
+
HTMLBodyElement: ['body'],
|
|
188
|
+
HTMLButtonElement: ['button'],
|
|
189
|
+
HTMLCanvasElement: ['canvas'],
|
|
190
|
+
HTMLDListElement: ['dl'],
|
|
191
|
+
HTMLDataElement: ['data'],
|
|
192
|
+
HTMLDataListElement: ['datalist'],
|
|
193
|
+
HTMLDetailsElement: ['details'],
|
|
194
|
+
HTMLDialogElement: ['dialog'],
|
|
195
|
+
HTMLDivElement: ['div'],
|
|
196
|
+
HTMLEmbedElement: ['embed'],
|
|
197
|
+
HTMLFieldSetElement: ['fieldset'],
|
|
198
|
+
HTMLFormElement: ['form'],
|
|
199
|
+
HTMLFrameSetElement: ['frameset'],
|
|
200
|
+
HTMLHRElement: ['hr'],
|
|
201
|
+
HTMLHeadElement: ['head'],
|
|
202
|
+
HTMLHeadingElement: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
|
203
|
+
HTMLHtmlElement: ['html'],
|
|
204
|
+
HTMLIFrameElement: ['iframe'],
|
|
205
|
+
HTMLImageElement: ['img'],
|
|
206
|
+
HTMLInputElement: ['input'],
|
|
207
|
+
HTMLLIElement: ['li'],
|
|
208
|
+
HTMLLabelElement: ['label'],
|
|
209
|
+
HTMLLegendElement: ['legend'],
|
|
210
|
+
HTMLLinkElement: ['link'],
|
|
211
|
+
HTMLMapElement: ['map'],
|
|
212
|
+
HTMLMetaElement: ['meta'],
|
|
213
|
+
HTMLMeterElement: ['meter'],
|
|
214
|
+
HTMLOListElement: ['ol'],
|
|
215
|
+
HTMLObjectElement: ['object'],
|
|
216
|
+
HTMLOptGroupElement: ['optgroup'],
|
|
217
|
+
HTMLOptionElement: ['option'],
|
|
218
|
+
HTMLOutputElement: ['output'],
|
|
219
|
+
HTMLParagraphElement: ['p'],
|
|
220
|
+
HTMLPictureElement: ['picture'],
|
|
221
|
+
HTMLPreElement: ['pre'],
|
|
222
|
+
HTMLProgressElement: ['progress'],
|
|
223
|
+
HTMLQuoteElement: ['blockquote', 'q'],
|
|
224
|
+
HTMLScriptElement: ['script'],
|
|
225
|
+
HTMLSelectElement: ['select'],
|
|
226
|
+
HTMLSlotElement: ['slot'],
|
|
227
|
+
HTMLSourceElement: ['source'],
|
|
228
|
+
HTMLSpanElement: ['span'],
|
|
229
|
+
HTMLStyleElement: ['style'],
|
|
230
|
+
HTMLTableCaptionElement: ['caption'],
|
|
231
|
+
HTMLTableCellElement: ['td', 'th'],
|
|
232
|
+
HTMLTableColElement: ['col', 'colgroup'],
|
|
233
|
+
HTMLTableElement: ['table'],
|
|
234
|
+
HTMLTableRowElement: ['tr'],
|
|
235
|
+
HTMLTableSectionElement: ['thead', 'tbody', 'tfoot'],
|
|
236
|
+
HTMLTemplateElement: ['template'],
|
|
237
|
+
HTMLTextAreaElement: ['textarea'],
|
|
238
|
+
HTMLTimeElement: ['time'],
|
|
239
|
+
HTMLTitleElement: ['title'],
|
|
240
|
+
HTMLTrackElement: ['track'],
|
|
241
|
+
HTMLUListElement: ['ul'],
|
|
242
|
+
HTMLVideoElement: ['video'],
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// 获取类的原型链
|
|
246
|
+
export function getPrototypeChain(className) {
|
|
247
|
+
const chains = {
|
|
248
|
+
'HTMLDivElement': ['HTMLDivElement', 'HTMLElement', 'Element', 'Node', 'EventTarget'],
|
|
249
|
+
'HTMLCanvasElement': ['HTMLCanvasElement', 'HTMLElement', 'Element', 'Node', 'EventTarget'],
|
|
250
|
+
'HTMLInputElement': ['HTMLInputElement', 'HTMLElement', 'Element', 'Node', 'EventTarget'],
|
|
251
|
+
'Document': ['Document', 'Node', 'EventTarget'],
|
|
252
|
+
'Window': ['Window', 'EventTarget'],
|
|
253
|
+
'Navigator': ['Navigator'],
|
|
254
|
+
'Screen': ['Screen'],
|
|
255
|
+
'Location': ['Location'],
|
|
256
|
+
};
|
|
257
|
+
return chains[className] || [className];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export default {
|
|
261
|
+
GETSET_LIST,
|
|
262
|
+
FUNC_LIST,
|
|
263
|
+
HTML_TAG_MAP,
|
|
264
|
+
getPrototypeChain,
|
|
265
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSpider - Cookie 监控模块
|
|
3
|
+
* 监控 document.cookie 的读写操作
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { HookBase } from './HookBase.js';
|
|
7
|
+
|
|
8
|
+
export class CookieHook {
|
|
9
|
+
/**
|
|
10
|
+
* 生成 Cookie Hook 代码
|
|
11
|
+
*/
|
|
12
|
+
generateCookieHookCode(options = {}) {
|
|
13
|
+
const { trackRead = true, trackWrite = true } = options;
|
|
14
|
+
|
|
15
|
+
return HookBase.getBaseCode() + `
|
|
16
|
+
(function() {
|
|
17
|
+
const deepspider = window.__deepspider__;
|
|
18
|
+
if (!deepspider) return;
|
|
19
|
+
|
|
20
|
+
const cookieDesc = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
|
|
21
|
+
Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
|
|
22
|
+
|
|
23
|
+
if (cookieDesc) {
|
|
24
|
+
Object.defineProperty(document, 'cookie', {
|
|
25
|
+
${trackRead ? `
|
|
26
|
+
get: function() {
|
|
27
|
+
const value = cookieDesc.get.call(document);
|
|
28
|
+
deepspider.log('cookie', { action: 'read', value: value?.slice(0, 100) });
|
|
29
|
+
return value;
|
|
30
|
+
},
|
|
31
|
+
` : 'get: cookieDesc.get,'}
|
|
32
|
+
${trackWrite ? `
|
|
33
|
+
set: function(val) {
|
|
34
|
+
deepspider.log('cookie', { action: 'write', value: val });
|
|
35
|
+
return cookieDesc.set.call(document, val);
|
|
36
|
+
},
|
|
37
|
+
` : 'set: cookieDesc.set,'}
|
|
38
|
+
configurable: true
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('[DeepSpider:cookie] Cookie Hook 已启用');
|
|
43
|
+
})();
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default CookieHook;
|