@jshookmcp/jshook 0.2.8 → 0.3.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/README.md +36 -5
- package/README.zh.md +36 -5
- package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-CqGDXmfc.mjs} +160 -54
- package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-BdjRfNx7.mjs} +5 -5
- package/dist/ConsoleMonitor-DykL3IAw.mjs +2269 -0
- package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-ETyy0xyo.mjs} +1 -1
- package/dist/DetailedDataManager-HT49OrvF.mjs +217 -0
- package/dist/EventBus-DFKvADm3.mjs +141 -0
- package/dist/EvidenceGraphBridge-318Oi0Lf.mjs +153 -0
- package/dist/{ExtensionManager-D5-bO9D8.mjs → ExtensionManager-BDMsY2Dz.mjs} +27 -13
- package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-BN4UQWnX.mjs} +1 -1
- package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-Cc2AFq1Y.mjs} +3 -3
- package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-DruMgsgj.mjs} +21 -21
- package/dist/HookGeneratorBuilders.core.generators.storage-CTbB4Lcx.mjs +566 -0
- package/dist/InstrumentationSession-DLH0vd-z.mjs +244 -0
- package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CMtviNW_.mjs} +3 -3
- package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-ITgb_NMi.mjs} +81 -78
- package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-CiL7Z3ey.mjs} +50 -21
- package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-D9Lkovvn.mjs} +20 -56
- package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-BBlAixF5.mjs} +1 -1
- package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-DMQ44gen.mjs} +16 -16
- package/dist/PageController-BPJNqqBN.mjs +431 -0
- package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-K7wN8Z-w.mjs} +10 -7
- package/dist/PrerequisiteError-TuyZIs6n.mjs +20 -0
- package/dist/ProcessRegistry-zGg12QbE.mjs +74 -0
- package/dist/ResponseBuilder-CJXWmWNw.mjs +143 -0
- package/dist/ReverseEvidenceGraph-C02-gXOh.mjs +269 -0
- package/dist/ScriptManager-ZuWD-0Jg.mjs +3003 -0
- package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-D-z0umeT.mjs} +2 -2
- package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-Cav5AVSL.mjs} +9 -6
- package/dist/ToolCatalog-5OJdMiF0.mjs +582 -0
- package/dist/ToolError-jh9whhMd.mjs +15 -0
- package/dist/ToolProbe-DbCFGyrg.mjs +45 -0
- package/dist/ToolRegistry-B9krbTtI.mjs +180 -0
- package/dist/ToolRouter.policy-BGDAGyeH.mjs +344 -0
- package/dist/TraceRecorder-B41Z5XBj.mjs +1286 -0
- package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-C2kjj0ze.mjs} +19 -13
- package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-CKrGOTpo.mjs} +3 -3
- package/dist/WorkflowEngine-DJ6M4opp.mjs +569 -0
- package/dist/analysis-BHeJW2Nb.mjs +1234 -0
- package/dist/antidebug-BRKeyt27.mjs +1081 -0
- package/dist/artifactRetention-CPXkUJXp.mjs +598 -0
- package/dist/artifacts-DkfosXH3.mjs +59 -0
- package/dist/authorization-schema-DRqyJMSk.mjs +31 -0
- package/dist/betterSqlite3-DLSBZodi.mjs +74 -0
- package/dist/binary-instrument--V3MAhJ4.mjs +971 -0
- package/dist/bind-helpers-ClV34xdn.mjs +42 -0
- package/dist/boringssl-inspector-Bo_LOLaS.mjs +180 -0
- package/dist/browser-Dx3_S2cG.mjs +4369 -0
- package/dist/capabilities-CcHlvWgK.mjs +33 -0
- package/dist/concurrency-Drev_Vz9.mjs +41 -0
- package/dist/{constants-CCvsN80K.mjs → constants-CDZLOoVv.mjs} +105 -48
- package/dist/coordination-DgItD9DL.mjs +259 -0
- package/dist/debugger-RS3RSAqs.mjs +1288 -0
- package/dist/definitions-BEoYofW5.mjs +47 -0
- package/dist/definitions-BRaefg3u.mjs +365 -0
- package/dist/definitions-BbkvZkiv.mjs +96 -0
- package/dist/definitions-BtWSHJ3o.mjs +17 -0
- package/dist/definitions-C1gCHO0i.mjs +43 -0
- package/dist/definitions-CDOg_b-l.mjs +138 -0
- package/dist/definitions-CVPD9hzZ.mjs +54 -0
- package/dist/definitions-Cea8Lgl7.mjs +94 -0
- package/dist/definitions-DAgIyjxM.mjs +10 -0
- package/dist/definitions-DJA27nsL.mjs +66 -0
- package/dist/definitions-DKPFU3LW.mjs +25 -0
- package/dist/definitions-DPRpZQ96.mjs +47 -0
- package/dist/definitions-DUE5gmdn.mjs +18 -0
- package/dist/definitions-DYVjOtxa.mjs +26 -0
- package/dist/definitions-DcYLVLCo.mjs +37 -0
- package/dist/definitions-Pp5LI2H4.mjs +27 -0
- package/dist/definitions-j9KdHVNR.mjs +14 -0
- package/dist/definitions-uzkjBwa7.mjs +258 -0
- package/dist/definitions-va-AnLuQ.mjs +28 -0
- package/dist/encoding-DJeqHmpd.mjs +1079 -0
- package/dist/evidence-graph-bridge-DcYizFk2.mjs +136 -0
- package/dist/{factory-CibqTNC8.mjs → factory-C90tBff6.mjs} +41 -56
- package/dist/flat-target-session-Dgax2Cy3.mjs +29 -0
- package/dist/graphql-CoHrhweh.mjs +1197 -0
- package/dist/handlers-4jmR0nMs.mjs +898 -0
- package/dist/handlers-BAHPxcch.mjs +789 -0
- package/dist/handlers-BOs9b907.mjs +2600 -0
- package/dist/handlers-BWXEy6ef.mjs +917 -0
- package/dist/handlers-Bndn6QvE.mjs +111 -0
- package/dist/handlers-BqC4bD4s.mjs +681 -0
- package/dist/handlers-BtYq60bM2.mjs +276 -0
- package/dist/handlers-BzgcB4iv.mjs +799 -0
- package/dist/handlers-CRyRWj2b.mjs +859 -0
- package/dist/handlers-CVv2H1uq.mjs +592 -0
- package/dist/handlers-Dl5a7JS4.mjs +572 -0
- package/dist/handlers-Dx2d7jt7.mjs +2537 -0
- package/dist/handlers-Dz9PYsCa.mjs +2805 -0
- package/dist/handlers-HujRKC3b.mjs +661 -0
- package/dist/handlers.impl-XWXkQfyi.mjs +807 -0
- package/dist/hooks-B1B8NRHL.mjs +898 -0
- package/dist/index.mjs +491 -259
- package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
- package/dist/maintenance-PRMkLVRW.mjs +835 -0
- package/dist/manifest-67Bok-Si.mjs +58 -0
- package/dist/manifest-6lNTMZAB2.mjs +87 -0
- package/dist/manifest-B2duEHiH.mjs +90 -0
- package/dist/manifest-B6EY9Vm8.mjs +57 -0
- package/dist/manifest-B6nKSbyY.mjs +95 -0
- package/dist/manifest-BL8AQNPF.mjs +106 -0
- package/dist/manifest-BSZvJJmV.mjs +47 -0
- package/dist/manifest-BU7qzUyX.mjs +418 -0
- package/dist/manifest-Bl62e8WK.mjs +49 -0
- package/dist/manifest-Bo5cXjdt.mjs +82 -0
- package/dist/manifest-BpS4gtUK.mjs +1347 -0
- package/dist/manifest-Bv65_e2W.mjs +101 -0
- package/dist/manifest-BytNIF4Z.mjs +117 -0
- package/dist/manifest-C-xtsjS3.mjs +81 -0
- package/dist/manifest-CDYl7OhA.mjs +66 -0
- package/dist/manifest-CRZ3xmkD.mjs +61 -0
- package/dist/manifest-CoW6u4Tp.mjs +132 -0
- package/dist/manifest-Cq5zN_8A.mjs +50 -0
- package/dist/manifest-D7YZM_2e.mjs +194 -0
- package/dist/manifest-DE_VrAeQ.mjs +314 -0
- package/dist/manifest-DGsXSCpT.mjs +39 -0
- package/dist/manifest-DJ2vfEuW.mjs +156 -0
- package/dist/manifest-DPXDYhEu.mjs +80 -0
- package/dist/manifest-Dd4fQb0a.mjs +322 -0
- package/dist/manifest-Deq6opGg.mjs +223 -0
- package/dist/manifest-DfJTafJK.mjs +37 -0
- package/dist/manifest-DgOdgN_j.mjs +50 -0
- package/dist/manifest-DlbMW4v4.mjs +47 -0
- package/dist/manifest-DmVfbH0w.mjs +374 -0
- package/dist/manifest-Dog6Ddjr.mjs +109 -0
- package/dist/manifest-DvgU5FWb.mjs +58 -0
- package/dist/manifest-HsfDBs7j.mjs +50 -0
- package/dist/manifest-I8oQHvCG.mjs +186 -0
- package/dist/manifest-NvH_a-av.mjs +786 -0
- package/dist/manifest-cEJU1v0Z.mjs +129 -0
- package/dist/manifest-wOl5XLB12.mjs +112 -0
- package/dist/modules-tZozf0LQ.mjs +10635 -0
- package/dist/mojo-ipc-DXNEXEqb.mjs +640 -0
- package/dist/network-CPVvwvFg.mjs +3852 -0
- package/dist/{artifacts-BbdOMET5.mjs → outputPaths-um7lCRY3.mjs} +219 -216
- package/dist/parse-args-B4cY5Vx5.mjs +39 -0
- package/dist/platform-CYeFoTWp.mjs +2161 -0
- package/dist/process-BTbgcVc6.mjs +1306 -0
- package/dist/proxy-r8YN6nP1.mjs +192 -0
- package/dist/registry-Bl8ZQW61.mjs +34 -0
- package/dist/response-CWhh2aLo.mjs +34 -0
- package/dist/server/plugin-api.mjs +2 -2
- package/dist/shared-state-board-BoZnSoj-.mjs +586 -0
- package/dist/sourcemap-BIDHUVXy.mjs +934 -0
- package/dist/ssrf-policy-Dsqd-DTX.mjs +166 -0
- package/dist/streaming-Dal6utPp.mjs +725 -0
- package/dist/tool-builder-BHJp32mV.mjs +186 -0
- package/dist/transform-DRVgGG90.mjs +1011 -0
- package/dist/types-Bx92KJfT.mjs +4 -0
- package/dist/wasm-BYx5UOeG.mjs +1044 -0
- package/dist/webcrack-Be0_FccV.mjs +747 -0
- package/dist/workflow-BpuKEtvn.mjs +725 -0
- package/package.json +82 -49
- package/dist/ExtensionManager-CPTJhHFg.mjs +0 -2
- package/dist/ToolCatalog-Bq4V2sbJ.mjs +0 -67201
- package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-jJFy20G-.mjs} +0 -0
- package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-BWmPgQsv.mjs} +0 -0
- package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-K3V4vGsw.mjs} +0 -0
- package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-nnMvEohD.mjs} +0 -0
- package/dist/{types-BBjOqye-.mjs → types-DDBWs9UP.mjs} +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as logger } from "./logger-
|
|
2
|
-
import {
|
|
3
|
-
import { b as openProcessForMemory, d as ReadProcessMemory, t as CloseHandle } from "./Win32API-
|
|
4
|
-
import { m as TH32CS } from "./Win32Debug-
|
|
1
|
+
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
2
|
+
import { ct as HEAP_SPRAY_THRESHOLD, lt as HEAP_SUSPICIOUS_BLOCK_SIZE, ot as HEAP_ENUMERATE_MAX_BLOCKS, st as HEAP_SPRAY_SIZE_TOLERANCE } from "./constants-CDZLOoVv.mjs";
|
|
3
|
+
import { b as openProcessForMemory, d as ReadProcessMemory, t as CloseHandle } from "./Win32API-C2kjj0ze.mjs";
|
|
4
|
+
import { m as TH32CS } from "./Win32Debug-CKrGOTpo.mjs";
|
|
5
5
|
import koffi from "koffi";
|
|
6
6
|
//#region src/native/HeapAnalyzer.types.ts
|
|
7
7
|
/** Heap block flags */
|
|
@@ -25,7 +25,7 @@ const HF32 = {
|
|
|
25
25
|
*
|
|
26
26
|
* @module HeapAnalyzer
|
|
27
27
|
*/
|
|
28
|
-
let
|
|
28
|
+
let heapApisCache = null;
|
|
29
29
|
function loadHeapApis() {
|
|
30
30
|
const k32 = koffi.load("kernel32.dll");
|
|
31
31
|
return {
|
|
@@ -44,8 +44,8 @@ function loadHeapApis() {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
function getHeapApis() {
|
|
47
|
-
if (!
|
|
48
|
-
return
|
|
47
|
+
if (!heapApisCache) heapApisCache = loadHeapApis();
|
|
48
|
+
return heapApisCache;
|
|
49
49
|
}
|
|
50
50
|
const SIZE_RANGES = [
|
|
51
51
|
[
|
|
@@ -113,7 +113,7 @@ var HeapAnalyzer = class {
|
|
|
113
113
|
const processId = hlBuf.readUInt32LE(8);
|
|
114
114
|
const heapId = hlBuf.readBigUInt64LE(12);
|
|
115
115
|
const flags = hlBuf.readUInt32LE(20);
|
|
116
|
-
const blocks = await this.
|
|
116
|
+
const blocks = await this.enumerateBlocksInternal(pid, heapId, HEAP_ENUMERATE_MAX_BLOCKS);
|
|
117
117
|
heaps.push({
|
|
118
118
|
heapId: `0x${heapId.toString(16)}`,
|
|
119
119
|
processId,
|
|
@@ -130,7 +130,7 @@ var HeapAnalyzer = class {
|
|
|
130
130
|
}
|
|
131
131
|
return {
|
|
132
132
|
heaps,
|
|
133
|
-
stats: this.
|
|
133
|
+
stats: this.computeStats(heaps, [])
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
@@ -139,7 +139,7 @@ var HeapAnalyzer = class {
|
|
|
139
139
|
async enumerateBlocks(pid, heapId, options) {
|
|
140
140
|
const id = BigInt(heapId);
|
|
141
141
|
const max = options?.maxBlocks ?? HEAP_ENUMERATE_MAX_BLOCKS;
|
|
142
|
-
return this.
|
|
142
|
+
return this.enumerateBlocksInternal(pid, id, max);
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Get full statistical breakdown for all heaps.
|
|
@@ -148,10 +148,10 @@ var HeapAnalyzer = class {
|
|
|
148
148
|
const { heaps } = await this.enumerateHeaps(pid);
|
|
149
149
|
const allBlocks = [];
|
|
150
150
|
for (const heap of heaps) {
|
|
151
|
-
const blocks = await this.
|
|
151
|
+
const blocks = await this.enumerateBlocksInternal(pid, BigInt(heap.heapId), HEAP_ENUMERATE_MAX_BLOCKS);
|
|
152
152
|
allBlocks.push(...blocks);
|
|
153
153
|
}
|
|
154
|
-
return this.
|
|
154
|
+
return this.computeStats(heaps, allBlocks);
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Detect heap anomalies: spray, UAF heuristic, suspicious sizes.
|
|
@@ -160,14 +160,14 @@ var HeapAnalyzer = class {
|
|
|
160
160
|
const anomalies = [];
|
|
161
161
|
const { heaps } = await this.enumerateHeaps(pid);
|
|
162
162
|
for (const heap of heaps) {
|
|
163
|
-
const blocks = await this.
|
|
164
|
-
this.
|
|
165
|
-
this.
|
|
166
|
-
await this.
|
|
163
|
+
const blocks = await this.enumerateBlocksInternal(pid, BigInt(heap.heapId), HEAP_ENUMERATE_MAX_BLOCKS);
|
|
164
|
+
this.detectSpray(blocks, heap.heapId, anomalies);
|
|
165
|
+
this.detectSuspiciousSizes(blocks, heap.heapId, anomalies);
|
|
166
|
+
await this.detectPossibleUaf(pid, blocks, heap.heapId, anomalies);
|
|
167
167
|
}
|
|
168
168
|
return anomalies;
|
|
169
169
|
}
|
|
170
|
-
async
|
|
170
|
+
async enumerateBlocksInternal(pid, heapId, maxBlocks) {
|
|
171
171
|
const apis = getHeapApis();
|
|
172
172
|
const blocks = [];
|
|
173
173
|
const heBuf = Buffer.alloc(apis.HEAPENTRY32_SIZE);
|
|
@@ -189,7 +189,7 @@ var HeapAnalyzer = class {
|
|
|
189
189
|
}
|
|
190
190
|
return blocks;
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
computeStats(heaps, blocks) {
|
|
193
193
|
const buckets = SIZE_RANGES.map(([range]) => ({
|
|
194
194
|
range,
|
|
195
195
|
count: 0,
|
|
@@ -223,7 +223,7 @@ var HeapAnalyzer = class {
|
|
|
223
223
|
fragmentationRatio: totalSize > 0 ? freeSize / totalSize : 0
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
detectSpray(blocks, heapId, anomalies) {
|
|
227
227
|
const sizeGroups = /* @__PURE__ */ new Map();
|
|
228
228
|
for (const block of blocks) {
|
|
229
229
|
if (block.isFree) continue;
|
|
@@ -240,7 +240,7 @@ var HeapAnalyzer = class {
|
|
|
240
240
|
heapId
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
detectSuspiciousSizes(blocks, heapId, anomalies) {
|
|
244
244
|
for (const block of blocks) if (block.size === 0) anomalies.push({
|
|
245
245
|
type: "suspicious_size",
|
|
246
246
|
severity: "medium",
|
|
@@ -256,7 +256,7 @@ var HeapAnalyzer = class {
|
|
|
256
256
|
heapId
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
|
-
async
|
|
259
|
+
async detectPossibleUaf(pid, blocks, heapId, anomalies) {
|
|
260
260
|
const sampled = blocks.filter((b) => b.isFree && b.size >= 8).slice(0, 100);
|
|
261
261
|
let hProcess = null;
|
|
262
262
|
try {
|
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
//#region src/modules/hook/HookGeneratorBuilders.core.generators.runtime.ts
|
|
2
|
+
function generateFunctionHook(target, action, customCode, condition, performance = false) {
|
|
3
|
+
return `
|
|
4
|
+
(function() {
|
|
5
|
+
'use strict';
|
|
6
|
+
${condition ? `
|
|
7
|
+
let callCount = 0;
|
|
8
|
+
let lastCallTime = 0;
|
|
9
|
+
const maxCalls = ${condition.maxCalls || "Infinity"};
|
|
10
|
+
const minInterval = ${condition.minInterval || 0};
|
|
11
|
+
` : ""}
|
|
12
|
+
|
|
13
|
+
const originalFunction = ${target};
|
|
14
|
+
|
|
15
|
+
if (typeof originalFunction !== 'function') {
|
|
16
|
+
console.error('[Hook] Target is not a function: ${target}');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
${target} = function(...args) {
|
|
21
|
+
${condition ? `
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
if (callCount >= maxCalls) {
|
|
24
|
+
console.log('[Hook] Max calls reached, skipping');
|
|
25
|
+
return originalFunction.apply(this, args);
|
|
26
|
+
}
|
|
27
|
+
if (now - lastCallTime < minInterval) {
|
|
28
|
+
console.log('[Hook] Min interval not met, skipping');
|
|
29
|
+
return originalFunction.apply(this, args);
|
|
30
|
+
}
|
|
31
|
+
callCount++;
|
|
32
|
+
lastCallTime = now;
|
|
33
|
+
` : ""}
|
|
34
|
+
|
|
35
|
+
${performance ? `
|
|
36
|
+
const startTime = performance.now();
|
|
37
|
+
` : ""}
|
|
38
|
+
|
|
39
|
+
const hookContext = {
|
|
40
|
+
target: '${target}',
|
|
41
|
+
type: 'function',
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
arguments: args,
|
|
44
|
+
stackTrace: new Error().stack
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
console.log('[Hook] Function called:', hookContext);
|
|
48
|
+
|
|
49
|
+
${action === "block" ? "return undefined;" : ""}
|
|
50
|
+
${action === "modify" && customCode ? customCode : ""}
|
|
51
|
+
|
|
52
|
+
const result = originalFunction.apply(this, args);
|
|
53
|
+
|
|
54
|
+
${performance ? `
|
|
55
|
+
const endTime = performance.now();
|
|
56
|
+
console.log('[Hook] Execution time:', (endTime - startTime).toFixed(2), 'ms');
|
|
57
|
+
` : ""}
|
|
58
|
+
|
|
59
|
+
console.log('[Hook] Function result:', result);
|
|
60
|
+
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
console.log('[Hook] Successfully hooked: ${target}');
|
|
65
|
+
})();
|
|
66
|
+
`.trim();
|
|
67
|
+
}
|
|
68
|
+
function generateEvalHook(action, customCode, _condition, _performance = false) {
|
|
69
|
+
return `
|
|
70
|
+
(function() {
|
|
71
|
+
'use strict';
|
|
72
|
+
|
|
73
|
+
const originalEval = window.eval;
|
|
74
|
+
const originalFunction = window.Function;
|
|
75
|
+
const originalSetTimeout = window.setTimeout;
|
|
76
|
+
const originalSetInterval = window.setInterval;
|
|
77
|
+
|
|
78
|
+
let evalCounter = 0;
|
|
79
|
+
|
|
80
|
+
window.eval = function(code) {
|
|
81
|
+
const evalId = ++evalCounter;
|
|
82
|
+
const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
|
|
83
|
+
|
|
84
|
+
console.log(\`[Eval Hook #\${evalId}] eval:\`, {
|
|
85
|
+
code: typeof code === 'string' ? (code.length > 200 ? code.substring(0, 200) + '...' : code) : code,
|
|
86
|
+
codeType: typeof code,
|
|
87
|
+
codeLength: code?.length || 0,
|
|
88
|
+
stackTrace: stackTrace,
|
|
89
|
+
timestamp: new Date().toISOString()
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
${action === "block" ? "return undefined;" : ""}
|
|
93
|
+
${customCode || ""}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const result = originalEval.call(this, code);
|
|
97
|
+
console.log(\`[Eval Hook #\${evalId}] result:\`, typeof result);
|
|
98
|
+
return result;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
window.Function = function(...args) {
|
|
106
|
+
const evalId = ++evalCounter;
|
|
107
|
+
const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
|
|
108
|
+
|
|
109
|
+
const functionBody = args[args.length - 1];
|
|
110
|
+
const functionParams = args.slice(0, -1);
|
|
111
|
+
|
|
112
|
+
console.log(\`[Eval Hook #\${evalId}] Function constructor:\`, {
|
|
113
|
+
params: functionParams,
|
|
114
|
+
body: typeof functionBody === 'string' ?
|
|
115
|
+
(functionBody.length > 200 ? functionBody.substring(0, 200) + '...' : functionBody) :
|
|
116
|
+
functionBody,
|
|
117
|
+
bodyLength: functionBody?.length || 0,
|
|
118
|
+
stackTrace: stackTrace,
|
|
119
|
+
timestamp: new Date().toISOString()
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
${action === "block" ? "return function() {};" : ""}
|
|
123
|
+
${customCode || ""}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const result = originalFunction.apply(this, args);
|
|
127
|
+
console.log(\`[Eval Hook #\${evalId}] Function created\`);
|
|
128
|
+
return result;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
window.setTimeout = function(handler, timeout, ...args) {
|
|
136
|
+
if (typeof handler === 'string') {
|
|
137
|
+
const evalId = ++evalCounter;
|
|
138
|
+
console.log(\`[Eval Hook #\${evalId}] setTimeout with code:\`, {
|
|
139
|
+
code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
|
|
140
|
+
timeout: timeout,
|
|
141
|
+
timestamp: new Date().toISOString()
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
${action === "block" ? "return 0;" : ""}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return originalSetTimeout.apply(this, [handler, timeout, ...args]);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
window.setInterval = function(handler, timeout, ...args) {
|
|
151
|
+
if (typeof handler === 'string') {
|
|
152
|
+
const evalId = ++evalCounter;
|
|
153
|
+
console.log(\`[Eval Hook #\${evalId}] setInterval with code:\`, {
|
|
154
|
+
code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
|
|
155
|
+
timeout: timeout,
|
|
156
|
+
timestamp: new Date().toISOString()
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
${action === "block" ? "return 0;" : ""}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return originalSetInterval.apply(this, [handler, timeout, ...args]);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
console.log('[Eval Hook] Successfully hooked eval, Function, setTimeout, setInterval');
|
|
166
|
+
})();
|
|
167
|
+
`.trim();
|
|
168
|
+
}
|
|
169
|
+
function generateObjectMethodHook(target, action, customCode, _condition, _performance = false) {
|
|
170
|
+
const parts = target.split(".");
|
|
171
|
+
const methodName = parts.pop();
|
|
172
|
+
const objectPath = parts.join(".");
|
|
173
|
+
return `
|
|
174
|
+
(function() {
|
|
175
|
+
'use strict';
|
|
176
|
+
|
|
177
|
+
function getObjectByPath(path) {
|
|
178
|
+
const parts = path.split('.');
|
|
179
|
+
let obj = window;
|
|
180
|
+
|
|
181
|
+
for (const part of parts) {
|
|
182
|
+
if (part === 'window') continue;
|
|
183
|
+
if (!obj || !(part in obj)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
obj = obj[part];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return obj;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const targetObject = getObjectByPath('${objectPath}');
|
|
193
|
+
const methodName = '${methodName}';
|
|
194
|
+
|
|
195
|
+
if (!targetObject) {
|
|
196
|
+
console.error('[Object Hook] Target object not found: ${objectPath}');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const descriptor = Object.getOwnPropertyDescriptor(targetObject, methodName) ||
|
|
201
|
+
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(targetObject), methodName);
|
|
202
|
+
|
|
203
|
+
if (!descriptor) {
|
|
204
|
+
console.error('[Object Hook] Property not found: ${target}');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let callCounter = 0;
|
|
209
|
+
|
|
210
|
+
if (typeof targetObject[methodName] === 'function') {
|
|
211
|
+
const originalMethod = targetObject[methodName];
|
|
212
|
+
|
|
213
|
+
targetObject[methodName] = function(...args) {
|
|
214
|
+
const callId = ++callCounter;
|
|
215
|
+
const startTime = performance.now();
|
|
216
|
+
const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
|
|
217
|
+
|
|
218
|
+
console.log(\`[Object Hook #\${callId}] ${target}:\`, {
|
|
219
|
+
arguments: args,
|
|
220
|
+
this: this,
|
|
221
|
+
thisType: this?.constructor?.name,
|
|
222
|
+
stackTrace: stackTrace,
|
|
223
|
+
timestamp: new Date().toISOString()
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
${action === "block" ? "return undefined;" : ""}
|
|
227
|
+
${customCode || ""}
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const result = originalMethod.apply(this, args);
|
|
231
|
+
const endTime = performance.now();
|
|
232
|
+
const duration = (endTime - startTime).toFixed(2);
|
|
233
|
+
|
|
234
|
+
console.log(\`[Object Hook #\${callId}] ${target} result:\`, {
|
|
235
|
+
result: result,
|
|
236
|
+
resultType: typeof result,
|
|
237
|
+
duration: duration + 'ms'
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return result;
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error(\`[Object Hook #\${callId}] ${target} error:\`, error);
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
Object.setPrototypeOf(targetObject[methodName], originalMethod);
|
|
248
|
+
|
|
249
|
+
console.log('[Object Hook] Successfully hooked method: ${target}');
|
|
250
|
+
}
|
|
251
|
+
else if (descriptor.get || descriptor.set) {
|
|
252
|
+
const originalGet = descriptor.get;
|
|
253
|
+
const originalSet = descriptor.set;
|
|
254
|
+
|
|
255
|
+
Object.defineProperty(targetObject, methodName, {
|
|
256
|
+
get: function() {
|
|
257
|
+
console.log('[Object Hook] getter called: ${target}');
|
|
258
|
+
return originalGet ? originalGet.call(this) : undefined;
|
|
259
|
+
},
|
|
260
|
+
set: function(value) {
|
|
261
|
+
console.log('[Object Hook] setter called: ${target}', { value });
|
|
262
|
+
${action === "block" ? "return;" : ""}
|
|
263
|
+
if (originalSet) {
|
|
264
|
+
originalSet.call(this, value);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
configurable: true,
|
|
268
|
+
enumerable: descriptor.enumerable
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
console.log('[Object Hook] Successfully hooked property: ${target}');
|
|
272
|
+
}
|
|
273
|
+
})();
|
|
274
|
+
`.trim();
|
|
275
|
+
}
|
|
276
|
+
function generateAntiDebugBypass() {
|
|
277
|
+
return `
|
|
278
|
+
(function() {
|
|
279
|
+
'use strict';
|
|
280
|
+
|
|
281
|
+
console.log('[Anti-Debug Bypass] Initializing...');
|
|
282
|
+
|
|
283
|
+
const originalEval = window.eval;
|
|
284
|
+
window.eval = function(code) {
|
|
285
|
+
if (typeof code === 'string') {
|
|
286
|
+
code = code.replace(/debugger\\s*;?/g, '');
|
|
287
|
+
}
|
|
288
|
+
return originalEval.call(this, code);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const originalFunction = window.Function;
|
|
292
|
+
window.Function = function(...args) {
|
|
293
|
+
if (args.length > 0) {
|
|
294
|
+
const lastArg = args[args.length - 1];
|
|
295
|
+
if (typeof lastArg === 'string') {
|
|
296
|
+
args[args.length - 1] = lastArg.replace(/debugger\\s*;?/g, '');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return originalFunction.apply(this, args);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
Object.defineProperty(window, 'outerHeight', {
|
|
303
|
+
get: function() {
|
|
304
|
+
return window.innerHeight;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
Object.defineProperty(window, 'outerWidth', {
|
|
309
|
+
get: function() {
|
|
310
|
+
return window.innerWidth;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
let lastTime = Date.now();
|
|
315
|
+
const originalDateNow = Date.now;
|
|
316
|
+
Date.now = function() {
|
|
317
|
+
const currentTime = originalDateNow();
|
|
318
|
+
if (currentTime - lastTime > 100) {
|
|
319
|
+
lastTime += 16;
|
|
320
|
+
return lastTime;
|
|
321
|
+
}
|
|
322
|
+
lastTime = currentTime;
|
|
323
|
+
return currentTime;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const originalToString = Function.prototype.toString;
|
|
327
|
+
Function.prototype.toString = function() {
|
|
328
|
+
if (this === window.eval || this === window.Function) {
|
|
329
|
+
return 'function () { [native code] }';
|
|
330
|
+
}
|
|
331
|
+
return originalToString.call(this);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const devtools = { open: false };
|
|
335
|
+
const threshold = 160;
|
|
336
|
+
|
|
337
|
+
setInterval(function() {
|
|
338
|
+
if (window.outerWidth - window.innerWidth > threshold ||
|
|
339
|
+
window.outerHeight - window.innerHeight > threshold) {
|
|
340
|
+
devtools.open = true;
|
|
341
|
+
} else {
|
|
342
|
+
devtools.open = false;
|
|
343
|
+
}
|
|
344
|
+
}, 500);
|
|
345
|
+
|
|
346
|
+
Object.defineProperty(window, 'devtools', {
|
|
347
|
+
get: function() {
|
|
348
|
+
return { open: false };
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
console.log('[Anti-Debug Bypass] Successfully bypassed anti-debugging protections');
|
|
353
|
+
})();
|
|
354
|
+
`.trim();
|
|
355
|
+
}
|
|
356
|
+
function generateHookTemplate(targetName, targetType) {
|
|
357
|
+
if (targetType === "function") return `
|
|
358
|
+
(function() {
|
|
359
|
+
'use strict';
|
|
360
|
+
|
|
361
|
+
const original = ${targetName};
|
|
362
|
+
|
|
363
|
+
${targetName} = function(...args) {
|
|
364
|
+
console.log('[Hook] ${targetName} called:', args);
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
const result = original.apply(this, args);
|
|
368
|
+
console.log('[Hook] ${targetName} result:', result);
|
|
369
|
+
|
|
370
|
+
return result;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
console.log('[Hook] Successfully hooked: ${targetName}');
|
|
374
|
+
})();
|
|
375
|
+
`.trim();
|
|
376
|
+
else if (targetType === "property") return `
|
|
377
|
+
(function() {
|
|
378
|
+
'use strict';
|
|
379
|
+
|
|
380
|
+
const descriptor = Object.getOwnPropertyDescriptor(${targetName.split(".").slice(0, -1).join(".")}, '${targetName.split(".").pop()}');
|
|
381
|
+
const originalGet = descriptor?.get;
|
|
382
|
+
const originalSet = descriptor?.set;
|
|
383
|
+
|
|
384
|
+
Object.defineProperty(${targetName.split(".").slice(0, -1).join(".")}, '${targetName.split(".").pop()}', {
|
|
385
|
+
get: function() {
|
|
386
|
+
console.log('[Hook] ${targetName} get');
|
|
387
|
+
return originalGet ? originalGet.call(this) : undefined;
|
|
388
|
+
},
|
|
389
|
+
set: function(value) {
|
|
390
|
+
console.log('[Hook] ${targetName} set:', value);
|
|
391
|
+
if (originalSet) {
|
|
392
|
+
originalSet.call(this, value);
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
configurable: true
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
console.log('[Hook] Successfully hooked property: ${targetName}');
|
|
399
|
+
})();
|
|
400
|
+
`.trim();
|
|
401
|
+
else return `
|
|
402
|
+
(function() {
|
|
403
|
+
'use strict';
|
|
404
|
+
|
|
405
|
+
const original = ${targetName};
|
|
406
|
+
|
|
407
|
+
${targetName} = function(...args) {
|
|
408
|
+
console.log('[Hook] ${targetName} constructor called:', args);
|
|
409
|
+
|
|
410
|
+
const instance = new original(...args);
|
|
411
|
+
|
|
412
|
+
const methodNames = Object.getOwnPropertyNames(original.prototype);
|
|
413
|
+
methodNames.forEach(name => {
|
|
414
|
+
if (name !== 'constructor' && typeof instance[name] === 'function') {
|
|
415
|
+
const originalMethod = instance[name];
|
|
416
|
+
instance[name] = function(...methodArgs) {
|
|
417
|
+
console.log(\`[Hook] \${name} called:\`, methodArgs);
|
|
418
|
+
return originalMethod.apply(this, methodArgs);
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
return instance;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
${targetName}.prototype = original.prototype;
|
|
427
|
+
|
|
428
|
+
console.log('[Hook] Successfully hooked prototype: ${targetName}');
|
|
429
|
+
})();
|
|
430
|
+
`.trim();
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/modules/hook/HookGeneratorBuilders.core.generators.storage.ts
|
|
434
|
+
function generateLocalStorageHook(action, customCode, _condition, _performance = false) {
|
|
435
|
+
return `
|
|
436
|
+
(function() {
|
|
437
|
+
'use strict';
|
|
438
|
+
|
|
439
|
+
const originalSetItem = Storage.prototype.setItem;
|
|
440
|
+
const originalGetItem = Storage.prototype.getItem;
|
|
441
|
+
const originalRemoveItem = Storage.prototype.removeItem;
|
|
442
|
+
const originalClear = Storage.prototype.clear;
|
|
443
|
+
|
|
444
|
+
Storage.prototype.setItem = function(key, value) {
|
|
445
|
+
const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
|
|
446
|
+
const stackTrace = new Error().stack.split('\\n').slice(2, 4).join('\\n');
|
|
447
|
+
|
|
448
|
+
console.log(\`[Storage Hook] \${storageType}.setItem:\`, {
|
|
449
|
+
key: key,
|
|
450
|
+
value: value,
|
|
451
|
+
valueType: typeof value,
|
|
452
|
+
valueLength: value?.length || 0,
|
|
453
|
+
stackTrace: stackTrace
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
${action === "block" ? "return;" : ""}
|
|
457
|
+
${customCode || ""}
|
|
458
|
+
|
|
459
|
+
return originalSetItem.apply(this, arguments);
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
Storage.prototype.getItem = function(key) {
|
|
463
|
+
const value = originalGetItem.apply(this, arguments);
|
|
464
|
+
const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
|
|
465
|
+
|
|
466
|
+
console.log(\`[Storage Hook] \${storageType}.getItem:\`, {
|
|
467
|
+
key: key,
|
|
468
|
+
value: value,
|
|
469
|
+
found: value !== null
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
return value;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
Storage.prototype.removeItem = function(key) {
|
|
476
|
+
const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
|
|
477
|
+
const oldValue = this.getItem(key);
|
|
478
|
+
|
|
479
|
+
console.log(\`[Storage Hook] \${storageType}.removeItem:\`, {
|
|
480
|
+
key: key,
|
|
481
|
+
oldValue: oldValue
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
return originalRemoveItem.apply(this, arguments);
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
Storage.prototype.clear = function() {
|
|
488
|
+
const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
|
|
489
|
+
const itemCount = this.length;
|
|
490
|
+
|
|
491
|
+
console.log(\`[Storage Hook] \${storageType}.clear:\`, {
|
|
492
|
+
itemCount: itemCount,
|
|
493
|
+
items: Object.keys(this)
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
return originalClear.apply(this, arguments);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
console.log('[Storage Hook] Successfully hooked localStorage and sessionStorage');
|
|
500
|
+
})();
|
|
501
|
+
`.trim();
|
|
502
|
+
}
|
|
503
|
+
function generateCookieHook(action, customCode, _condition, _performance = false) {
|
|
504
|
+
return `
|
|
505
|
+
(function() {
|
|
506
|
+
'use strict';
|
|
507
|
+
|
|
508
|
+
const cookieDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
|
|
509
|
+
Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
|
|
510
|
+
|
|
511
|
+
if (!cookieDescriptor) {
|
|
512
|
+
console.error('[Cookie Hook] Failed to get cookie descriptor');
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const originalGet = cookieDescriptor.get;
|
|
517
|
+
const originalSet = cookieDescriptor.set;
|
|
518
|
+
|
|
519
|
+
function parseCookie(cookieString) {
|
|
520
|
+
const parts = cookieString.split(';')[0].split('=');
|
|
521
|
+
return {
|
|
522
|
+
name: parts[0]?.trim(),
|
|
523
|
+
value: parts[1]?.trim(),
|
|
524
|
+
raw: cookieString
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
Object.defineProperty(document, 'cookie', {
|
|
529
|
+
get: function() {
|
|
530
|
+
const value = originalGet.call(this);
|
|
531
|
+
|
|
532
|
+
console.log('[Cookie Hook] get:', {
|
|
533
|
+
value: value,
|
|
534
|
+
cookieCount: value ? value.split(';').length : 0
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
return value;
|
|
538
|
+
},
|
|
539
|
+
set: function(value) {
|
|
540
|
+
const cookieInfo = parseCookie(value);
|
|
541
|
+
const stackTrace = new Error().stack.split('\\n').slice(2, 4).join('\\n');
|
|
542
|
+
|
|
543
|
+
console.log('[Cookie Hook] set:', {
|
|
544
|
+
name: cookieInfo.name,
|
|
545
|
+
value: cookieInfo.value,
|
|
546
|
+
raw: cookieInfo.raw,
|
|
547
|
+
stackTrace: stackTrace
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
${action === "block" ? "return;" : ""}
|
|
551
|
+
${customCode || ""}
|
|
552
|
+
|
|
553
|
+
return originalSet.call(this, value);
|
|
554
|
+
},
|
|
555
|
+
configurable: true
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
console.log('[Cookie Hook] Successfully hooked document.cookie');
|
|
559
|
+
})();
|
|
560
|
+
`.trim();
|
|
561
|
+
}
|
|
562
|
+
function getInjectionInstructions(type) {
|
|
563
|
+
return `This hook script monitors ${type} operations. Inject it into the target page via page_evaluate or console_execute to activate.`;
|
|
564
|
+
}
|
|
565
|
+
//#endregion
|
|
566
|
+
export { generateEvalHook as a, generateObjectMethodHook as c, generateAntiDebugBypass as i, generateLocalStorageHook as n, generateFunctionHook as o, getInjectionInstructions as r, generateHookTemplate as s, generateCookieHook as t };
|