@jshookmcp/jshook 0.2.7 → 0.2.9

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.
Files changed (157) hide show
  1. package/README.md +36 -5
  2. package/README.zh.md +36 -5
  3. package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-BNk-EoBt.mjs} +3 -3
  4. package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-Cq8q01kp.mjs} +5 -5
  5. package/dist/ConsoleMonitor-CPVQW1Y-.mjs +2201 -0
  6. package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-BNPxu0RH.mjs} +1 -1
  7. package/dist/DetailedDataManager-BQQcxh64.mjs +217 -0
  8. package/dist/EventBus-DgPmwpeu.mjs +141 -0
  9. package/dist/EvidenceGraphBridge-SFesNera.mjs +153 -0
  10. package/dist/{ExtensionManager-CZ6IveoV.mjs → ExtensionManager-CWYgw0YW.mjs} +13 -6
  11. package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-gzWtkKuf.mjs} +1 -1
  12. package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-B9gZCdFP.mjs} +3 -3
  13. package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-BLDH0dCv.mjs} +4 -4
  14. package/dist/HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs +639 -0
  15. package/dist/InstrumentationSession-CvPC7Jwy.mjs +244 -0
  16. package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CbVdCIJF.mjs} +3 -3
  17. package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-BsDZbLYm.mjs} +81 -78
  18. package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-Bcpml6II.mjs} +44 -18
  19. package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-dZtA1ZGn.mjs} +14 -53
  20. package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-B-FjA2mJ.mjs} +1 -1
  21. package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-D1lzJ_VG.mjs} +2 -2
  22. package/dist/PageController-Bqm2kZ_X.mjs +417 -0
  23. package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-BOhyVsjx.mjs} +4 -4
  24. package/dist/PrerequisiteError-Dl33Svkz.mjs +20 -0
  25. package/dist/ResponseBuilder-D3iFYx2N.mjs +143 -0
  26. package/dist/ReverseEvidenceGraph-Dlsk94LC.mjs +269 -0
  27. package/dist/ScriptManager-aHHq0X7U.mjs +3000 -0
  28. package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-CqdIFlQl.mjs} +2 -2
  29. package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-DhFaPvRO.mjs} +3 -3
  30. package/dist/ToolCatalog-C0JGZoOm.mjs +582 -0
  31. package/dist/ToolError-jh9whhMd.mjs +15 -0
  32. package/dist/ToolProbe-oC7aPrkv.mjs +45 -0
  33. package/dist/ToolRegistry-BjaF4oNz.mjs +131 -0
  34. package/dist/ToolRouter.policy-BWV67ZK-.mjs +304 -0
  35. package/dist/TraceRecorder-DgxyVbdQ.mjs +519 -0
  36. package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-CePkipZY.mjs} +1 -1
  37. package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-BvKs-gxc.mjs} +2 -2
  38. package/dist/WorkflowEngine-CuvkZtWu.mjs +598 -0
  39. package/dist/analysis-CL9uACt9.mjs +463 -0
  40. package/dist/antidebug-CqDTB_uk.mjs +1081 -0
  41. package/dist/artifactRetention-CFEprwPw.mjs +591 -0
  42. package/dist/artifacts-Bk2-_uPq.mjs +59 -0
  43. package/dist/betterSqlite3-0pqusHHH.mjs +74 -0
  44. package/dist/binary-instrument-CXfpx6fT.mjs +979 -0
  45. package/dist/bind-helpers-xFfRF-qm.mjs +22 -0
  46. package/dist/boringssl-inspector-BH2D3VKc.mjs +180 -0
  47. package/dist/browser-BpOr5PEx.mjs +4082 -0
  48. package/dist/concurrency-Bt0yv1kJ.mjs +41 -0
  49. package/dist/{constants-CCvsN80K.mjs → constants-B0OANIBL.mjs} +88 -46
  50. package/dist/coordination-qUbyF8KU.mjs +259 -0
  51. package/dist/debugger-gnKxRSN0.mjs +1271 -0
  52. package/dist/definitions-6M-eejaT.mjs +53 -0
  53. package/dist/definitions-B18eyf0B.mjs +18 -0
  54. package/dist/definitions-B3QdlrHv.mjs +34 -0
  55. package/dist/definitions-B4rAvHNZ.mjs +63 -0
  56. package/dist/definitions-BB_4jnmy.mjs +37 -0
  57. package/dist/definitions-BMfYXoNC.mjs +43 -0
  58. package/dist/definitions-Beid2EB3.mjs +27 -0
  59. package/dist/definitions-C1UvM5Iy.mjs +126 -0
  60. package/dist/definitions-CXEI7QC72.mjs +216 -0
  61. package/dist/definitions-C_4r7Fo-2.mjs +14 -0
  62. package/dist/definitions-CkFDALoa.mjs +26 -0
  63. package/dist/definitions-Cke7zEb8.mjs +94 -0
  64. package/dist/definitions-ClJLzsJQ.mjs +25 -0
  65. package/dist/definitions-Cq-zroAU.mjs +28 -0
  66. package/dist/definitions-Cy3Sl6gV.mjs +34 -0
  67. package/dist/definitions-D3VsGcvz.mjs +47 -0
  68. package/dist/definitions-DVGfrn7y.mjs +96 -0
  69. package/dist/definitions-LKpC3-nL.mjs +9 -0
  70. package/dist/definitions-bAhHQJq9.mjs +359 -0
  71. package/dist/encoding-Bvz5jLRv.mjs +1065 -0
  72. package/dist/evidence-graph-bridge-C_fv9PuC.mjs +135 -0
  73. package/dist/{factory-CibqTNC8.mjs → factory-DxlGh9Xf.mjs} +37 -52
  74. package/dist/graphql-DYWzJ29s.mjs +1026 -0
  75. package/dist/handlers-9sAbfIg-.mjs +2552 -0
  76. package/dist/handlers-Bl8zkwz1.mjs +2716 -0
  77. package/dist/handlers-C67ktuRN.mjs +710 -0
  78. package/dist/handlers-C87g8oCe.mjs +276 -0
  79. package/dist/handlers-CTsDAO6p.mjs +681 -0
  80. package/dist/handlers-Cgyg6c0U.mjs +645 -0
  81. package/dist/handlers-D6j6yka7.mjs +2124 -0
  82. package/dist/handlers-DdFzXLvF.mjs +446 -0
  83. package/dist/handlers-DeLOCd5m.mjs +799 -0
  84. package/dist/handlers-DlCJN4Td.mjs +757 -0
  85. package/dist/handlers-DxGIq15_2.mjs +917 -0
  86. package/dist/handlers-U6L4xhuF.mjs +585 -0
  87. package/dist/handlers-tB9Mp9ZK.mjs +84 -0
  88. package/dist/handlers-tiy7EIBp.mjs +572 -0
  89. package/dist/handlers.impl-DS0d9fUw.mjs +761 -0
  90. package/dist/hooks-CzCWByww.mjs +898 -0
  91. package/dist/index.mjs +384 -155
  92. package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
  93. package/dist/maintenance-P7ePRXQC.mjs +830 -0
  94. package/dist/manifest-2ToTpjv8.mjs +106 -0
  95. package/dist/manifest-3g71z6Bg.mjs +79 -0
  96. package/dist/manifest-82baTv4U.mjs +45 -0
  97. package/dist/manifest-B3QVVeBS.mjs +82 -0
  98. package/dist/manifest-BB2J8IMJ.mjs +149 -0
  99. package/dist/manifest-BKbgbSiY.mjs +60 -0
  100. package/dist/manifest-Bcf-TJzH.mjs +848 -0
  101. package/dist/manifest-BmtZzQiQ2.mjs +45 -0
  102. package/dist/manifest-Bnd7kqEY.mjs +55 -0
  103. package/dist/manifest-BqQX6OQC2.mjs +65 -0
  104. package/dist/manifest-BqrQ4Tpj.mjs +81 -0
  105. package/dist/manifest-Br4RPFt5.mjs +370 -0
  106. package/dist/manifest-C5qDjysN.mjs +107 -0
  107. package/dist/manifest-C9RT5nk32.mjs +34 -0
  108. package/dist/manifest-CAhOuvSl.mjs +204 -0
  109. package/dist/manifest-CBYWCUBJ.mjs +51 -0
  110. package/dist/manifest-CFADCRa1.mjs +37 -0
  111. package/dist/manifest-CQVhavRF.mjs +114 -0
  112. package/dist/manifest-CT7zZBV1.mjs +48 -0
  113. package/dist/manifest-CV12bcrF.mjs +121 -0
  114. package/dist/manifest-CXsRWjjI.mjs +224 -0
  115. package/dist/manifest-CZLUCfG02.mjs +95 -0
  116. package/dist/manifest-D6phHKFd.mjs +131 -0
  117. package/dist/manifest-DCyjf4n2.mjs +294 -0
  118. package/dist/manifest-DHsnKgP6.mjs +60 -0
  119. package/dist/manifest-Df_dliIe.mjs +55 -0
  120. package/dist/manifest-Dh8WBmEW.mjs +129 -0
  121. package/dist/manifest-DhKRAT8_.mjs +92 -0
  122. package/dist/manifest-DlpTj4ic2.mjs +193 -0
  123. package/dist/manifest-DrbmZcFl2.mjs +253 -0
  124. package/dist/manifest-DuwHjUa5.mjs +70 -0
  125. package/dist/manifest-DzwvxPJX.mjs +38 -0
  126. package/dist/manifest-NXctwWQq.mjs +68 -0
  127. package/dist/manifest-Sc_0JQ13.mjs +418 -0
  128. package/dist/manifest-gZ4s_UtG.mjs +96 -0
  129. package/dist/manifest-qSleDqdO.mjs +1023 -0
  130. package/dist/modules-C184v-S9.mjs +11365 -0
  131. package/dist/mojo-ipc-B_H61Afw.mjs +525 -0
  132. package/dist/network-671Cw6hV.mjs +3346 -0
  133. package/dist/{artifacts-BbdOMET5.mjs → outputPaths-B1uGmrWZ.mjs} +219 -212
  134. package/dist/parse-args-BlRjqlkL.mjs +39 -0
  135. package/dist/platform-WmNn8Sxb.mjs +2070 -0
  136. package/dist/process-QcbIy5Zq.mjs +1401 -0
  137. package/dist/proxy-DqNs0bAd.mjs +170 -0
  138. package/dist/registry-D-6e18lB.mjs +34 -0
  139. package/dist/response-BQVP-xUn.mjs +28 -0
  140. package/dist/server/plugin-api.mjs +2 -2
  141. package/dist/shared-state-board-DV-dpHFJ.mjs +586 -0
  142. package/dist/sourcemap-Dq8ez8vS.mjs +650 -0
  143. package/dist/ssrf-policy-ZaUfvhq7.mjs +166 -0
  144. package/dist/streaming-BUQ0VJsg.mjs +725 -0
  145. package/dist/tool-builder-DCbIC5Eo.mjs +186 -0
  146. package/dist/transform-CiYJfNX0.mjs +1007 -0
  147. package/dist/types-Bx92KJfT.mjs +4 -0
  148. package/dist/wasm-DQTnHDs4.mjs +531 -0
  149. package/dist/workflow-f3xJOcjx.mjs +725 -0
  150. package/package.json +48 -78
  151. package/dist/ExtensionManager-DqUSOamB.mjs +0 -2
  152. package/dist/ToolCatalog-CnwmMIw3.mjs +0 -61483
  153. package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-CDe5WPSV.mjs} +0 -0
  154. package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-Bo4T3bz8.mjs} +0 -0
  155. package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-CwVLVdDM.mjs} +0 -0
  156. package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-DVkj9kpI.mjs} +0 -0
  157. package/dist/{types-BBjOqye-.mjs → types-CPhOReNX.mjs} +1 -1
@@ -0,0 +1,639 @@
1
+ import { t as logger } from "./logger-Dh_xb7_2.mjs";
2
+ import { W as EXTERNAL_TOOL_FORCE_KILL_GRACE_MS } from "./constants-B0OANIBL.mjs";
3
+ //#region src/utils/ProcessRegistry.ts
4
+ /**
5
+ * Global singleton registry to track and safely terminate orphaned child
6
+ * processes and worker threads upon server shutdown.
7
+ */
8
+ var ProcessRegistrySingleton = class {
9
+ processes = /* @__PURE__ */ new Set();
10
+ /**
11
+ * Register a ChildProcess or Worker for automatic cleanup on shutdown.
12
+ */
13
+ register(proc) {
14
+ if (!proc) return;
15
+ this.processes.add(proc);
16
+ if ("kill" in proc) proc.once("close", () => this.unregister(proc));
17
+ else if ("terminate" in proc) {
18
+ if (typeof proc.once === "function") proc.once("exit", () => this.unregister(proc));
19
+ else if (typeof proc.on === "function") proc.on("exit", () => this.unregister(proc));
20
+ }
21
+ }
22
+ /**
23
+ * Unregister a process/worker.
24
+ */
25
+ unregister(proc) {
26
+ if (!proc) return;
27
+ this.processes.delete(proc);
28
+ }
29
+ /**
30
+ * Terminate all tracked processes and workers.
31
+ * Sends SIGTERM, then after a grace period sends SIGKILL.
32
+ */
33
+ async terminateAll() {
34
+ if (this.processes.size === 0) return;
35
+ logger.debug(`[ProcessRegistry] Attempting to terminate ${this.processes.size} active processes/workers...`);
36
+ const terminationPromises = [];
37
+ for (const proc of this.processes) if ("terminate" in proc) terminationPromises.push(proc.terminate().then(() => {
38
+ this.processes.delete(proc);
39
+ }).catch((err) => {
40
+ logger.warn(`[ProcessRegistry] Error terminating worker: ${err.message}`);
41
+ }));
42
+ else if ("kill" in proc) terminationPromises.push(new Promise((resolve) => {
43
+ if (proc.killed || proc.exitCode !== null || proc.signalCode !== null) {
44
+ this.processes.delete(proc);
45
+ return resolve();
46
+ }
47
+ proc.kill("SIGTERM");
48
+ let settled = false;
49
+ const handleExit = () => {
50
+ if (settled) return;
51
+ settled = true;
52
+ this.processes.delete(proc);
53
+ resolve();
54
+ };
55
+ proc.once("exit", handleExit);
56
+ proc.once("close", handleExit);
57
+ setTimeout(() => {
58
+ if (!settled && !proc.killed && proc.exitCode === null) {
59
+ logger.debug(`[ProcessRegistry] Force killing child process PID ${proc.pid}`);
60
+ try {
61
+ proc.kill("SIGKILL");
62
+ } catch {}
63
+ handleExit();
64
+ }
65
+ }, EXTERNAL_TOOL_FORCE_KILL_GRACE_MS).unref();
66
+ }));
67
+ await Promise.race([Promise.all(terminationPromises), new Promise((resolve) => setTimeout(resolve, EXTERNAL_TOOL_FORCE_KILL_GRACE_MS + 1e3).unref())]);
68
+ this.processes.clear();
69
+ logger.debug(`[ProcessRegistry] Termination sweep complete.`);
70
+ }
71
+ };
72
+ const ProcessRegistry = new ProcessRegistrySingleton();
73
+ //#endregion
74
+ //#region src/modules/hook/HookGeneratorBuilders.core.generators.runtime.ts
75
+ function generateFunctionHook(target, action, customCode, condition, performance = false) {
76
+ return `
77
+ (function() {
78
+ 'use strict';
79
+ ${condition ? `
80
+ let callCount = 0;
81
+ let lastCallTime = 0;
82
+ const maxCalls = ${condition.maxCalls || "Infinity"};
83
+ const minInterval = ${condition.minInterval || 0};
84
+ ` : ""}
85
+
86
+ const originalFunction = ${target};
87
+
88
+ if (typeof originalFunction !== 'function') {
89
+ console.error('[Hook] Target is not a function: ${target}');
90
+ return;
91
+ }
92
+
93
+ ${target} = function(...args) {
94
+ ${condition ? `
95
+ const now = Date.now();
96
+ if (callCount >= maxCalls) {
97
+ console.log('[Hook] Max calls reached, skipping');
98
+ return originalFunction.apply(this, args);
99
+ }
100
+ if (now - lastCallTime < minInterval) {
101
+ console.log('[Hook] Min interval not met, skipping');
102
+ return originalFunction.apply(this, args);
103
+ }
104
+ callCount++;
105
+ lastCallTime = now;
106
+ ` : ""}
107
+
108
+ ${performance ? `
109
+ const startTime = performance.now();
110
+ ` : ""}
111
+
112
+ const hookContext = {
113
+ target: '${target}',
114
+ type: 'function',
115
+ timestamp: Date.now(),
116
+ arguments: args,
117
+ stackTrace: new Error().stack
118
+ };
119
+
120
+ console.log('[Hook] Function called:', hookContext);
121
+
122
+ ${action === "block" ? "return undefined;" : ""}
123
+ ${action === "modify" && customCode ? customCode : ""}
124
+
125
+ const result = originalFunction.apply(this, args);
126
+
127
+ ${performance ? `
128
+ const endTime = performance.now();
129
+ console.log('[Hook] Execution time:', (endTime - startTime).toFixed(2), 'ms');
130
+ ` : ""}
131
+
132
+ console.log('[Hook] Function result:', result);
133
+
134
+ return result;
135
+ };
136
+
137
+ console.log('[Hook] Successfully hooked: ${target}');
138
+ })();
139
+ `.trim();
140
+ }
141
+ function generateEvalHook(action, customCode, _condition, _performance = false) {
142
+ return `
143
+ (function() {
144
+ 'use strict';
145
+
146
+ const originalEval = window.eval;
147
+ const originalFunction = window.Function;
148
+ const originalSetTimeout = window.setTimeout;
149
+ const originalSetInterval = window.setInterval;
150
+
151
+ let evalCounter = 0;
152
+
153
+ window.eval = function(code) {
154
+ const evalId = ++evalCounter;
155
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
156
+
157
+ console.log(\`[Eval Hook #\${evalId}] eval:\`, {
158
+ code: typeof code === 'string' ? (code.length > 200 ? code.substring(0, 200) + '...' : code) : code,
159
+ codeType: typeof code,
160
+ codeLength: code?.length || 0,
161
+ stackTrace: stackTrace,
162
+ timestamp: new Date().toISOString()
163
+ });
164
+
165
+ ${action === "block" ? "return undefined;" : ""}
166
+ ${customCode || ""}
167
+
168
+ try {
169
+ const result = originalEval.call(this, code);
170
+ console.log(\`[Eval Hook #\${evalId}] result:\`, typeof result);
171
+ return result;
172
+ } catch (error) {
173
+ console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
174
+ throw error;
175
+ }
176
+ };
177
+
178
+ window.Function = function(...args) {
179
+ const evalId = ++evalCounter;
180
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
181
+
182
+ const functionBody = args[args.length - 1];
183
+ const functionParams = args.slice(0, -1);
184
+
185
+ console.log(\`[Eval Hook #\${evalId}] Function constructor:\`, {
186
+ params: functionParams,
187
+ body: typeof functionBody === 'string' ?
188
+ (functionBody.length > 200 ? functionBody.substring(0, 200) + '...' : functionBody) :
189
+ functionBody,
190
+ bodyLength: functionBody?.length || 0,
191
+ stackTrace: stackTrace,
192
+ timestamp: new Date().toISOString()
193
+ });
194
+
195
+ ${action === "block" ? "return function() {};" : ""}
196
+ ${customCode || ""}
197
+
198
+ try {
199
+ const result = originalFunction.apply(this, args);
200
+ console.log(\`[Eval Hook #\${evalId}] Function created\`);
201
+ return result;
202
+ } catch (error) {
203
+ console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
204
+ throw error;
205
+ }
206
+ };
207
+
208
+ window.setTimeout = function(handler, timeout, ...args) {
209
+ if (typeof handler === 'string') {
210
+ const evalId = ++evalCounter;
211
+ console.log(\`[Eval Hook #\${evalId}] setTimeout with code:\`, {
212
+ code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
213
+ timeout: timeout,
214
+ timestamp: new Date().toISOString()
215
+ });
216
+
217
+ ${action === "block" ? "return 0;" : ""}
218
+ }
219
+
220
+ return originalSetTimeout.apply(this, [handler, timeout, ...args]);
221
+ };
222
+
223
+ window.setInterval = function(handler, timeout, ...args) {
224
+ if (typeof handler === 'string') {
225
+ const evalId = ++evalCounter;
226
+ console.log(\`[Eval Hook #\${evalId}] setInterval with code:\`, {
227
+ code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
228
+ timeout: timeout,
229
+ timestamp: new Date().toISOString()
230
+ });
231
+
232
+ ${action === "block" ? "return 0;" : ""}
233
+ }
234
+
235
+ return originalSetInterval.apply(this, [handler, timeout, ...args]);
236
+ };
237
+
238
+ console.log('[Eval Hook] Successfully hooked eval, Function, setTimeout, setInterval');
239
+ })();
240
+ `.trim();
241
+ }
242
+ function generateObjectMethodHook(target, action, customCode, _condition, _performance = false) {
243
+ const parts = target.split(".");
244
+ const methodName = parts.pop();
245
+ const objectPath = parts.join(".");
246
+ return `
247
+ (function() {
248
+ 'use strict';
249
+
250
+ function getObjectByPath(path) {
251
+ const parts = path.split('.');
252
+ let obj = window;
253
+
254
+ for (const part of parts) {
255
+ if (part === 'window') continue;
256
+ if (!obj || !(part in obj)) {
257
+ return null;
258
+ }
259
+ obj = obj[part];
260
+ }
261
+
262
+ return obj;
263
+ }
264
+
265
+ const targetObject = getObjectByPath('${objectPath}');
266
+ const methodName = '${methodName}';
267
+
268
+ if (!targetObject) {
269
+ console.error('[Object Hook] Target object not found: ${objectPath}');
270
+ return;
271
+ }
272
+
273
+ const descriptor = Object.getOwnPropertyDescriptor(targetObject, methodName) ||
274
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(targetObject), methodName);
275
+
276
+ if (!descriptor) {
277
+ console.error('[Object Hook] Property not found: ${target}');
278
+ return;
279
+ }
280
+
281
+ let callCounter = 0;
282
+
283
+ if (typeof targetObject[methodName] === 'function') {
284
+ const originalMethod = targetObject[methodName];
285
+
286
+ targetObject[methodName] = function(...args) {
287
+ const callId = ++callCounter;
288
+ const startTime = performance.now();
289
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
290
+
291
+ console.log(\`[Object Hook #\${callId}] ${target}:\`, {
292
+ arguments: args,
293
+ this: this,
294
+ thisType: this?.constructor?.name,
295
+ stackTrace: stackTrace,
296
+ timestamp: new Date().toISOString()
297
+ });
298
+
299
+ ${action === "block" ? "return undefined;" : ""}
300
+ ${customCode || ""}
301
+
302
+ try {
303
+ const result = originalMethod.apply(this, args);
304
+ const endTime = performance.now();
305
+ const duration = (endTime - startTime).toFixed(2);
306
+
307
+ console.log(\`[Object Hook #\${callId}] ${target} result:\`, {
308
+ result: result,
309
+ resultType: typeof result,
310
+ duration: duration + 'ms'
311
+ });
312
+
313
+ return result;
314
+ } catch (error) {
315
+ console.error(\`[Object Hook #\${callId}] ${target} error:\`, error);
316
+ throw error;
317
+ }
318
+ };
319
+
320
+ Object.setPrototypeOf(targetObject[methodName], originalMethod);
321
+
322
+ console.log('[Object Hook] Successfully hooked method: ${target}');
323
+ }
324
+ else if (descriptor.get || descriptor.set) {
325
+ const originalGet = descriptor.get;
326
+ const originalSet = descriptor.set;
327
+
328
+ Object.defineProperty(targetObject, methodName, {
329
+ get: function() {
330
+ console.log('[Object Hook] getter called: ${target}');
331
+ return originalGet ? originalGet.call(this) : undefined;
332
+ },
333
+ set: function(value) {
334
+ console.log('[Object Hook] setter called: ${target}', { value });
335
+ ${action === "block" ? "return;" : ""}
336
+ if (originalSet) {
337
+ originalSet.call(this, value);
338
+ }
339
+ },
340
+ configurable: true,
341
+ enumerable: descriptor.enumerable
342
+ });
343
+
344
+ console.log('[Object Hook] Successfully hooked property: ${target}');
345
+ }
346
+ })();
347
+ `.trim();
348
+ }
349
+ function generateAntiDebugBypass() {
350
+ return `
351
+ (function() {
352
+ 'use strict';
353
+
354
+ console.log('[Anti-Debug Bypass] Initializing...');
355
+
356
+ const originalEval = window.eval;
357
+ window.eval = function(code) {
358
+ if (typeof code === 'string') {
359
+ code = code.replace(/debugger\\s*;?/g, '');
360
+ }
361
+ return originalEval.call(this, code);
362
+ };
363
+
364
+ const originalFunction = window.Function;
365
+ window.Function = function(...args) {
366
+ if (args.length > 0) {
367
+ const lastArg = args[args.length - 1];
368
+ if (typeof lastArg === 'string') {
369
+ args[args.length - 1] = lastArg.replace(/debugger\\s*;?/g, '');
370
+ }
371
+ }
372
+ return originalFunction.apply(this, args);
373
+ };
374
+
375
+ Object.defineProperty(window, 'outerHeight', {
376
+ get: function() {
377
+ return window.innerHeight;
378
+ }
379
+ });
380
+
381
+ Object.defineProperty(window, 'outerWidth', {
382
+ get: function() {
383
+ return window.innerWidth;
384
+ }
385
+ });
386
+
387
+ let lastTime = Date.now();
388
+ const originalDateNow = Date.now;
389
+ Date.now = function() {
390
+ const currentTime = originalDateNow();
391
+ if (currentTime - lastTime > 100) {
392
+ lastTime += 16;
393
+ return lastTime;
394
+ }
395
+ lastTime = currentTime;
396
+ return currentTime;
397
+ };
398
+
399
+ const originalToString = Function.prototype.toString;
400
+ Function.prototype.toString = function() {
401
+ if (this === window.eval || this === window.Function) {
402
+ return 'function () { [native code] }';
403
+ }
404
+ return originalToString.call(this);
405
+ };
406
+
407
+ const devtools = { open: false };
408
+ const threshold = 160;
409
+
410
+ setInterval(function() {
411
+ if (window.outerWidth - window.innerWidth > threshold ||
412
+ window.outerHeight - window.innerHeight > threshold) {
413
+ devtools.open = true;
414
+ } else {
415
+ devtools.open = false;
416
+ }
417
+ }, 500);
418
+
419
+ Object.defineProperty(window, 'devtools', {
420
+ get: function() {
421
+ return { open: false };
422
+ }
423
+ });
424
+
425
+ console.log('[Anti-Debug Bypass] Successfully bypassed anti-debugging protections');
426
+ })();
427
+ `.trim();
428
+ }
429
+ function generateHookTemplate(targetName, targetType) {
430
+ if (targetType === "function") return `
431
+ (function() {
432
+ 'use strict';
433
+
434
+ const original = ${targetName};
435
+
436
+ ${targetName} = function(...args) {
437
+ console.log('[Hook] ${targetName} called:', args);
438
+
439
+
440
+ const result = original.apply(this, args);
441
+ console.log('[Hook] ${targetName} result:', result);
442
+
443
+ return result;
444
+ };
445
+
446
+ console.log('[Hook] Successfully hooked: ${targetName}');
447
+ })();
448
+ `.trim();
449
+ else if (targetType === "property") return `
450
+ (function() {
451
+ 'use strict';
452
+
453
+ const descriptor = Object.getOwnPropertyDescriptor(${targetName.split(".").slice(0, -1).join(".")}, '${targetName.split(".").pop()}');
454
+ const originalGet = descriptor?.get;
455
+ const originalSet = descriptor?.set;
456
+
457
+ Object.defineProperty(${targetName.split(".").slice(0, -1).join(".")}, '${targetName.split(".").pop()}', {
458
+ get: function() {
459
+ console.log('[Hook] ${targetName} get');
460
+ return originalGet ? originalGet.call(this) : undefined;
461
+ },
462
+ set: function(value) {
463
+ console.log('[Hook] ${targetName} set:', value);
464
+ if (originalSet) {
465
+ originalSet.call(this, value);
466
+ }
467
+ },
468
+ configurable: true
469
+ });
470
+
471
+ console.log('[Hook] Successfully hooked property: ${targetName}');
472
+ })();
473
+ `.trim();
474
+ else return `
475
+ (function() {
476
+ 'use strict';
477
+
478
+ const original = ${targetName};
479
+
480
+ ${targetName} = function(...args) {
481
+ console.log('[Hook] ${targetName} constructor called:', args);
482
+
483
+ const instance = new original(...args);
484
+
485
+ const methodNames = Object.getOwnPropertyNames(original.prototype);
486
+ methodNames.forEach(name => {
487
+ if (name !== 'constructor' && typeof instance[name] === 'function') {
488
+ const originalMethod = instance[name];
489
+ instance[name] = function(...methodArgs) {
490
+ console.log(\`[Hook] \${name} called:\`, methodArgs);
491
+ return originalMethod.apply(this, methodArgs);
492
+ };
493
+ }
494
+ });
495
+
496
+ return instance;
497
+ };
498
+
499
+ ${targetName}.prototype = original.prototype;
500
+
501
+ console.log('[Hook] Successfully hooked prototype: ${targetName}');
502
+ })();
503
+ `.trim();
504
+ }
505
+ //#endregion
506
+ //#region src/modules/hook/HookGeneratorBuilders.core.generators.storage.ts
507
+ function generateLocalStorageHook(action, customCode, _condition, _performance = false) {
508
+ return `
509
+ (function() {
510
+ 'use strict';
511
+
512
+ const originalSetItem = Storage.prototype.setItem;
513
+ const originalGetItem = Storage.prototype.getItem;
514
+ const originalRemoveItem = Storage.prototype.removeItem;
515
+ const originalClear = Storage.prototype.clear;
516
+
517
+ Storage.prototype.setItem = function(key, value) {
518
+ const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
519
+ const stackTrace = new Error().stack.split('\\n').slice(2, 4).join('\\n');
520
+
521
+ console.log(\`[Storage Hook] \${storageType}.setItem:\`, {
522
+ key: key,
523
+ value: value,
524
+ valueType: typeof value,
525
+ valueLength: value?.length || 0,
526
+ stackTrace: stackTrace
527
+ });
528
+
529
+ ${action === "block" ? "return;" : ""}
530
+ ${customCode || ""}
531
+
532
+ return originalSetItem.apply(this, arguments);
533
+ };
534
+
535
+ Storage.prototype.getItem = function(key) {
536
+ const value = originalGetItem.apply(this, arguments);
537
+ const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
538
+
539
+ console.log(\`[Storage Hook] \${storageType}.getItem:\`, {
540
+ key: key,
541
+ value: value,
542
+ found: value !== null
543
+ });
544
+
545
+ return value;
546
+ };
547
+
548
+ Storage.prototype.removeItem = function(key) {
549
+ const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
550
+ const oldValue = this.getItem(key);
551
+
552
+ console.log(\`[Storage Hook] \${storageType}.removeItem:\`, {
553
+ key: key,
554
+ oldValue: oldValue
555
+ });
556
+
557
+ return originalRemoveItem.apply(this, arguments);
558
+ };
559
+
560
+ Storage.prototype.clear = function() {
561
+ const storageType = this === window.localStorage ? 'localStorage' : 'sessionStorage';
562
+ const itemCount = this.length;
563
+
564
+ console.log(\`[Storage Hook] \${storageType}.clear:\`, {
565
+ itemCount: itemCount,
566
+ items: Object.keys(this)
567
+ });
568
+
569
+ return originalClear.apply(this, arguments);
570
+ };
571
+
572
+ console.log('[Storage Hook] Successfully hooked localStorage and sessionStorage');
573
+ })();
574
+ `.trim();
575
+ }
576
+ function generateCookieHook(action, customCode, _condition, _performance = false) {
577
+ return `
578
+ (function() {
579
+ 'use strict';
580
+
581
+ const cookieDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
582
+ Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
583
+
584
+ if (!cookieDescriptor) {
585
+ console.error('[Cookie Hook] Failed to get cookie descriptor');
586
+ return;
587
+ }
588
+
589
+ const originalGet = cookieDescriptor.get;
590
+ const originalSet = cookieDescriptor.set;
591
+
592
+ function parseCookie(cookieString) {
593
+ const parts = cookieString.split(';')[0].split('=');
594
+ return {
595
+ name: parts[0]?.trim(),
596
+ value: parts[1]?.trim(),
597
+ raw: cookieString
598
+ };
599
+ }
600
+
601
+ Object.defineProperty(document, 'cookie', {
602
+ get: function() {
603
+ const value = originalGet.call(this);
604
+
605
+ console.log('[Cookie Hook] get:', {
606
+ value: value,
607
+ cookieCount: value ? value.split(';').length : 0
608
+ });
609
+
610
+ return value;
611
+ },
612
+ set: function(value) {
613
+ const cookieInfo = parseCookie(value);
614
+ const stackTrace = new Error().stack.split('\\n').slice(2, 4).join('\\n');
615
+
616
+ console.log('[Cookie Hook] set:', {
617
+ name: cookieInfo.name,
618
+ value: cookieInfo.value,
619
+ raw: cookieInfo.raw,
620
+ stackTrace: stackTrace
621
+ });
622
+
623
+ ${action === "block" ? "return;" : ""}
624
+ ${customCode || ""}
625
+
626
+ return originalSet.call(this, value);
627
+ },
628
+ configurable: true
629
+ });
630
+
631
+ console.log('[Cookie Hook] Successfully hooked document.cookie');
632
+ })();
633
+ `.trim();
634
+ }
635
+ function getInjectionInstructions(type) {
636
+ return `This hook script monitors ${type} operations. Inject it into the target page via page_evaluate or console_execute to activate.`;
637
+ }
638
+ //#endregion
639
+ export { generateEvalHook as a, generateObjectMethodHook as c, generateAntiDebugBypass as i, ProcessRegistry as l, generateLocalStorageHook as n, generateFunctionHook as o, getInjectionInstructions as r, generateHookTemplate as s, generateCookieHook as t };