@jshookmcp/jshook 0.2.2 → 0.2.3

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 (130) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +4 -4
  3. package/README.zh.md +3 -3
  4. package/dist/native/scripts/linux/enum-windows.sh +12 -12
  5. package/dist/native/scripts/macos/enum-windows.applescript +22 -22
  6. package/dist/native/scripts/windows/enum-windows-by-class.ps1 +51 -51
  7. package/dist/native/scripts/windows/enum-windows.ps1 +44 -44
  8. package/dist/native/scripts/windows/inject-dll.ps1 +21 -21
  9. package/dist/src/modules/analyzer/CodeAnalyzer.d.ts +1 -1
  10. package/dist/src/modules/analyzer/CodeAnalyzer.js +1 -1
  11. package/dist/src/modules/browser/BrowserDiscovery.d.ts +6 -5
  12. package/dist/src/modules/browser/BrowserDiscovery.js +1 -1
  13. package/dist/src/modules/browser/BrowserModeManager.d.ts +1 -1
  14. package/dist/src/modules/browser/BrowserModeManager.js +1 -1
  15. package/dist/src/modules/browser/UnifiedBrowserManager.js +1 -1
  16. package/dist/src/modules/captcha/AICaptchaDetector.d.ts +22 -22
  17. package/dist/src/modules/captcha/AICaptchaDetector.js +75 -75
  18. package/dist/src/modules/captcha/CaptchaDetector.d.ts +31 -17
  19. package/dist/src/modules/captcha/CaptchaDetector.js +1 -1
  20. package/dist/src/modules/collector/CodeCache.d.ts +2 -2
  21. package/dist/src/modules/collector/CodeCollector.d.ts +12 -9
  22. package/dist/src/modules/collector/CodeCollector.js +1 -1
  23. package/dist/src/modules/collector/DOMInspector.d.ts +3 -2
  24. package/dist/src/modules/collector/DOMInspector.js +1 -1
  25. package/dist/src/modules/crypto/CryptoDetector.d.ts +1 -1
  26. package/dist/src/modules/crypto/CryptoDetector.js +1 -1
  27. package/dist/src/modules/debugger/ScriptManager.impl.extract-function-tree.js +1 -1
  28. package/dist/src/modules/deobfuscator/Deobfuscator.d.ts +1 -1
  29. package/dist/src/modules/deobfuscator/Deobfuscator.js +1 -1
  30. package/dist/src/modules/deobfuscator/JSVMPDeobfuscator.restore.d.ts +1 -1
  31. package/dist/src/modules/deobfuscator/JSVMPDeobfuscator.restore.js +2 -2
  32. package/dist/src/modules/deobfuscator/PackerDeobfuscator.js +1 -1
  33. package/dist/src/modules/deobfuscator/VMDeobfuscator.d.ts +1 -1
  34. package/dist/src/modules/deobfuscator/VMDeobfuscator.js +82 -82
  35. package/dist/src/modules/emulator/AIEnvironmentAnalyzer.js +1 -1
  36. package/dist/src/modules/external/ExternalToolRunner.d.ts +1 -1
  37. package/dist/src/modules/external/ExternalToolRunner.js +1 -1
  38. package/dist/src/modules/hook/HookGeneratorBuilders.core.generators.compose.js +5 -5
  39. package/dist/src/modules/hook/HookGeneratorBuilders.core.generators.network.js +311 -311
  40. package/dist/src/modules/hook/HookGeneratorBuilders.core.generators.runtime.js +410 -410
  41. package/dist/src/modules/hook/HookGeneratorBuilders.core.generators.storage.js +122 -122
  42. package/dist/src/modules/monitor/ConsoleMonitor.impl.core.dynamic.js +194 -194
  43. package/dist/src/modules/monitor/PlaywrightNetworkMonitor.js +62 -62
  44. package/dist/src/modules/process/LinuxProcessManager.js +2 -2
  45. package/dist/src/modules/process/MacProcessManager.js +26 -26
  46. package/dist/src/modules/process/ProcessManager.impl.js +1 -1
  47. package/dist/src/modules/process/memory/availability.js +49 -49
  48. package/dist/src/modules/process/memory/injector.js +185 -185
  49. package/dist/src/modules/process/memory/reader.js +50 -50
  50. package/dist/src/modules/process/memory/regions.dump.js +51 -51
  51. package/dist/src/modules/process/memory/regions.enumerate.js +107 -107
  52. package/dist/src/modules/process/memory/regions.modules.js +80 -80
  53. package/dist/src/modules/process/memory/regions.protection.js +106 -106
  54. package/dist/src/modules/process/memory/scanner.darwin.js +41 -41
  55. package/dist/src/modules/process/memory/scanner.windows.js +124 -124
  56. package/dist/src/modules/process/memory/writer.js +54 -54
  57. package/dist/src/modules/security/ExecutionSandbox.js +44 -44
  58. package/dist/src/modules/stealth/StealthScripts.d.ts +3 -2
  59. package/dist/src/modules/stealth/StealthScripts.js +35 -1
  60. package/dist/src/modules/stealth/StealthVerifier.d.ts +1 -1
  61. package/dist/src/modules/stealth/StealthVerifier.js +1 -1
  62. package/dist/src/modules/trace/TraceDB.js +63 -63
  63. package/dist/src/native/CodeInjector.js +1 -1
  64. package/dist/src/native/HardwareBreakpoint.js +1 -1
  65. package/dist/src/server/MCPServer.js +1 -0
  66. package/dist/src/server/MCPServer.search.helpers.js +1 -1
  67. package/dist/src/server/MCPServer.tools.js +1 -1
  68. package/dist/src/server/ToolCallContextGuard.d.ts +5 -0
  69. package/dist/src/server/ToolCallContextGuard.js +77 -0
  70. package/dist/src/server/ToolRouter.d.ts +1 -1
  71. package/dist/src/server/ToolRouter.js +2 -2
  72. package/dist/src/server/domains/analysis/handlers.impl.d.ts +8 -8
  73. package/dist/src/server/domains/analysis/handlers.impl.js +8 -8
  74. package/dist/src/server/domains/analysis/handlers.web-tools.js +2 -2
  75. package/dist/src/server/domains/browser/definitions.tools.page-core.js +59 -59
  76. package/dist/src/server/domains/browser/definitions.tools.runtime.js +41 -41
  77. package/dist/src/server/domains/browser/definitions.tools.security.js +114 -114
  78. package/dist/src/server/domains/browser/handlers/facade-initializer.d.ts +3 -3
  79. package/dist/src/server/domains/browser/handlers/facade-initializer.js +3 -3
  80. package/dist/src/server/domains/browser/handlers/framework-state.js +210 -0
  81. package/dist/src/server/domains/browser/handlers/stealth-injection.js +8 -2
  82. package/dist/src/server/domains/browser/handlers.impl.d.ts +15 -11
  83. package/dist/src/server/domains/browser/handlers.impl.js +4 -4
  84. package/dist/src/server/domains/coordination/definitions.js +67 -0
  85. package/dist/src/server/domains/coordination/index.d.ts +18 -0
  86. package/dist/src/server/domains/coordination/index.js +132 -0
  87. package/dist/src/server/domains/coordination/manifest.js +15 -0
  88. package/dist/src/server/domains/graphql/handlers.impl.core.runtime.replay.js +2 -2
  89. package/dist/src/server/domains/graphql/handlers.impl.core.runtime.shared.js +77 -77
  90. package/dist/src/server/domains/hooks/ai-handlers.js +3 -3
  91. package/dist/src/server/domains/maintenance/handlers.d.ts +2 -2
  92. package/dist/src/server/domains/maintenance/handlers.js +2 -2
  93. package/dist/src/server/domains/platform/handlers/bridge-handlers.d.ts +1 -1
  94. package/dist/src/server/domains/platform/handlers/bridge-handlers.js +1 -1
  95. package/dist/src/server/domains/platform/handlers/miniapp-handlers.d.ts +1 -1
  96. package/dist/src/server/domains/platform/handlers/miniapp-handlers.js +1 -1
  97. package/dist/src/server/domains/process/handlers.impl.core.runtime.inject.js +1 -1
  98. package/dist/src/server/domains/trace/TraceSummarizer.d.ts +60 -0
  99. package/dist/src/server/domains/trace/TraceSummarizer.js +109 -0
  100. package/dist/src/server/domains/trace/definitions.tools.js +101 -71
  101. package/dist/src/server/domains/trace/handlers.d.ts +2 -1
  102. package/dist/src/server/domains/trace/handlers.js +59 -4
  103. package/dist/src/server/domains/trace/manifest.js +3 -1
  104. package/dist/src/server/domains/transform/handlers.impl.transform-base.js +103 -103
  105. package/dist/src/server/domains/wasm/handlers.js +2 -2
  106. package/dist/src/server/domains/workflow/handlers.impl.workflow-account-bundle.js +1 -1
  107. package/dist/src/server/domains/workflow/handlers.impl.workflow-api.js +51 -51
  108. package/dist/src/server/domains/workflow/handlers.impl.workflow-base.js +51 -51
  109. package/dist/src/server/extensions/ExtensionManager.roots.js +15 -5
  110. package/dist/src/server/http/HttpMiddleware.js +1 -1
  111. package/dist/src/server/registry/contracts.d.ts +6 -0
  112. package/dist/src/server/sandbox/MCPBridge.d.ts +9 -0
  113. package/dist/src/server/sandbox/MCPBridge.js +22 -0
  114. package/dist/src/server/sandbox/QuickJSSandbox.d.ts +4 -1
  115. package/dist/src/server/sandbox/QuickJSSandbox.js +149 -0
  116. package/dist/src/server/sandbox/SandboxHelpers.js +250 -250
  117. package/dist/src/server/sandbox/types.d.ts +13 -0
  118. package/dist/src/server/search/AffinityGraph.d.ts +7 -1
  119. package/dist/src/server/search/AffinityGraph.js +24 -3
  120. package/dist/src/services/LLMService.js +1 -1
  121. package/dist/src/utils/UnifiedCacheManager.d.ts +1 -1
  122. package/dist/src/utils/UnifiedCacheManager.js +2 -2
  123. package/dist/src/utils/cliFastPath.js +18 -4
  124. package/package.json +5 -3
  125. package/scripts/postinstall.cjs +37 -37
  126. package/src/native/scripts/linux/enum-windows.sh +12 -12
  127. package/src/native/scripts/macos/enum-windows.applescript +22 -22
  128. package/src/native/scripts/windows/enum-windows-by-class.ps1 +51 -51
  129. package/src/native/scripts/windows/enum-windows.ps1 +44 -44
  130. package/src/native/scripts/windows/inject-dll.ps1 +21 -21
@@ -1,447 +1,447 @@
1
1
  export function generateFunctionHook(target, action, customCode, condition, performance = false) {
2
2
  const conditionCode = condition
3
- ? `
4
- let callCount = 0;
5
- let lastCallTime = 0;
6
- const maxCalls = ${condition.maxCalls || 'Infinity'};
7
- const minInterval = ${condition.minInterval || 0};
3
+ ? `
4
+ let callCount = 0;
5
+ let lastCallTime = 0;
6
+ const maxCalls = ${condition.maxCalls || 'Infinity'};
7
+ const minInterval = ${condition.minInterval || 0};
8
8
  `
9
9
  : '';
10
10
  const performanceCode = performance
11
- ? `
12
- const startTime = performance.now();
11
+ ? `
12
+ const startTime = performance.now();
13
13
  `
14
14
  : '';
15
15
  const performanceEndCode = performance
16
- ? `
17
- const endTime = performance.now();
18
- console.log('[Hook] Execution time:', (endTime - startTime).toFixed(2), 'ms');
16
+ ? `
17
+ const endTime = performance.now();
18
+ console.log('[Hook] Execution time:', (endTime - startTime).toFixed(2), 'ms');
19
19
  `
20
20
  : '';
21
- return `
22
- (function() {
23
- 'use strict';
24
- ${conditionCode}
25
-
26
- const originalFunction = ${target};
27
-
28
- if (typeof originalFunction !== 'function') {
29
- console.error('[Hook] Target is not a function: ${target}');
30
- return;
31
- }
32
-
33
- ${target} = function(...args) {
21
+ return `
22
+ (function() {
23
+ 'use strict';
24
+ ${conditionCode}
25
+
26
+ const originalFunction = ${target};
27
+
28
+ if (typeof originalFunction !== 'function') {
29
+ console.error('[Hook] Target is not a function: ${target}');
30
+ return;
31
+ }
32
+
33
+ ${target} = function(...args) {
34
34
  ${condition
35
- ? `
36
- const now = Date.now();
37
- if (callCount >= maxCalls) {
38
- console.log('[Hook] Max calls reached, skipping');
39
- return originalFunction.apply(this, args);
40
- }
41
- if (now - lastCallTime < minInterval) {
42
- console.log('[Hook] Min interval not met, skipping');
43
- return originalFunction.apply(this, args);
44
- }
45
- callCount++;
46
- lastCallTime = now;
35
+ ? `
36
+ const now = Date.now();
37
+ if (callCount >= maxCalls) {
38
+ console.log('[Hook] Max calls reached, skipping');
39
+ return originalFunction.apply(this, args);
40
+ }
41
+ if (now - lastCallTime < minInterval) {
42
+ console.log('[Hook] Min interval not met, skipping');
43
+ return originalFunction.apply(this, args);
44
+ }
45
+ callCount++;
46
+ lastCallTime = now;
47
47
  `
48
- : ''}
49
-
50
- ${performanceCode}
51
-
52
- const hookContext = {
53
- target: '${target}',
54
- type: 'function',
55
- timestamp: Date.now(),
56
- arguments: args,
57
- stackTrace: new Error().stack
58
- };
59
-
60
- console.log('[Hook] Function called:', hookContext);
61
-
62
- ${action === 'block' ? 'return undefined;' : ''}
63
- ${action === 'modify' && customCode ? customCode : ''}
64
-
65
- const result = originalFunction.apply(this, args);
66
-
67
- ${performanceEndCode}
68
-
69
- console.log('[Hook] Function result:', result);
70
-
71
- return result;
72
- };
73
-
74
- console.log('[Hook] Successfully hooked: ${target}');
75
- })();
48
+ : ''}
49
+
50
+ ${performanceCode}
51
+
52
+ const hookContext = {
53
+ target: '${target}',
54
+ type: 'function',
55
+ timestamp: Date.now(),
56
+ arguments: args,
57
+ stackTrace: new Error().stack
58
+ };
59
+
60
+ console.log('[Hook] Function called:', hookContext);
61
+
62
+ ${action === 'block' ? 'return undefined;' : ''}
63
+ ${action === 'modify' && customCode ? customCode : ''}
64
+
65
+ const result = originalFunction.apply(this, args);
66
+
67
+ ${performanceEndCode}
68
+
69
+ console.log('[Hook] Function result:', result);
70
+
71
+ return result;
72
+ };
73
+
74
+ console.log('[Hook] Successfully hooked: ${target}');
75
+ })();
76
76
  `.trim();
77
77
  }
78
78
  export function generateEvalHook(action, customCode, _condition, _performance = false) {
79
- return `
80
- (function() {
81
- 'use strict';
82
-
83
- const originalEval = window.eval;
84
- const originalFunction = window.Function;
85
- const originalSetTimeout = window.setTimeout;
86
- const originalSetInterval = window.setInterval;
87
-
88
- let evalCounter = 0;
89
-
90
- window.eval = function(code) {
91
- const evalId = ++evalCounter;
92
- const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
93
-
94
- console.log(\`[Eval Hook #\${evalId}] eval:\`, {
95
- code: typeof code === 'string' ? (code.length > 200 ? code.substring(0, 200) + '...' : code) : code,
96
- codeType: typeof code,
97
- codeLength: code?.length || 0,
98
- stackTrace: stackTrace,
99
- timestamp: new Date().toISOString()
100
- });
101
-
102
- ${action === 'block' ? 'return undefined;' : ''}
103
- ${customCode || ''}
104
-
105
- try {
106
- const result = originalEval.call(this, code);
107
- console.log(\`[Eval Hook #\${evalId}] result:\`, typeof result);
108
- return result;
109
- } catch (error) {
110
- console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
111
- throw error;
112
- }
113
- };
114
-
115
- window.Function = function(...args) {
116
- const evalId = ++evalCounter;
117
- const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
118
-
119
- const functionBody = args[args.length - 1];
120
- const functionParams = args.slice(0, -1);
121
-
122
- console.log(\`[Eval Hook #\${evalId}] Function constructor:\`, {
123
- params: functionParams,
124
- body: typeof functionBody === 'string' ?
125
- (functionBody.length > 200 ? functionBody.substring(0, 200) + '...' : functionBody) :
126
- functionBody,
127
- bodyLength: functionBody?.length || 0,
128
- stackTrace: stackTrace,
129
- timestamp: new Date().toISOString()
130
- });
131
-
132
- ${action === 'block' ? 'return function() {};' : ''}
133
- ${customCode || ''}
134
-
135
- try {
136
- const result = originalFunction.apply(this, args);
137
- console.log(\`[Eval Hook #\${evalId}] Function created\`);
138
- return result;
139
- } catch (error) {
140
- console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
141
- throw error;
142
- }
143
- };
144
-
145
- window.setTimeout = function(handler, timeout, ...args) {
146
- if (typeof handler === 'string') {
147
- const evalId = ++evalCounter;
148
- console.log(\`[Eval Hook #\${evalId}] setTimeout with code:\`, {
149
- code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
150
- timeout: timeout,
151
- timestamp: new Date().toISOString()
152
- });
153
-
154
- ${action === 'block' ? 'return 0;' : ''}
155
- }
156
-
157
- return originalSetTimeout.apply(this, [handler, timeout, ...args]);
158
- };
159
-
160
- window.setInterval = function(handler, timeout, ...args) {
161
- if (typeof handler === 'string') {
162
- const evalId = ++evalCounter;
163
- console.log(\`[Eval Hook #\${evalId}] setInterval with code:\`, {
164
- code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
165
- timeout: timeout,
166
- timestamp: new Date().toISOString()
167
- });
168
-
169
- ${action === 'block' ? 'return 0;' : ''}
170
- }
171
-
172
- return originalSetInterval.apply(this, [handler, timeout, ...args]);
173
- };
174
-
175
- console.log('[Eval Hook] Successfully hooked eval, Function, setTimeout, setInterval');
176
- })();
79
+ return `
80
+ (function() {
81
+ 'use strict';
82
+
83
+ const originalEval = window.eval;
84
+ const originalFunction = window.Function;
85
+ const originalSetTimeout = window.setTimeout;
86
+ const originalSetInterval = window.setInterval;
87
+
88
+ let evalCounter = 0;
89
+
90
+ window.eval = function(code) {
91
+ const evalId = ++evalCounter;
92
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
93
+
94
+ console.log(\`[Eval Hook #\${evalId}] eval:\`, {
95
+ code: typeof code === 'string' ? (code.length > 200 ? code.substring(0, 200) + '...' : code) : code,
96
+ codeType: typeof code,
97
+ codeLength: code?.length || 0,
98
+ stackTrace: stackTrace,
99
+ timestamp: new Date().toISOString()
100
+ });
101
+
102
+ ${action === 'block' ? 'return undefined;' : ''}
103
+ ${customCode || ''}
104
+
105
+ try {
106
+ const result = originalEval.call(this, code);
107
+ console.log(\`[Eval Hook #\${evalId}] result:\`, typeof result);
108
+ return result;
109
+ } catch (error) {
110
+ console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
111
+ throw error;
112
+ }
113
+ };
114
+
115
+ window.Function = function(...args) {
116
+ const evalId = ++evalCounter;
117
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
118
+
119
+ const functionBody = args[args.length - 1];
120
+ const functionParams = args.slice(0, -1);
121
+
122
+ console.log(\`[Eval Hook #\${evalId}] Function constructor:\`, {
123
+ params: functionParams,
124
+ body: typeof functionBody === 'string' ?
125
+ (functionBody.length > 200 ? functionBody.substring(0, 200) + '...' : functionBody) :
126
+ functionBody,
127
+ bodyLength: functionBody?.length || 0,
128
+ stackTrace: stackTrace,
129
+ timestamp: new Date().toISOString()
130
+ });
131
+
132
+ ${action === 'block' ? 'return function() {};' : ''}
133
+ ${customCode || ''}
134
+
135
+ try {
136
+ const result = originalFunction.apply(this, args);
137
+ console.log(\`[Eval Hook #\${evalId}] Function created\`);
138
+ return result;
139
+ } catch (error) {
140
+ console.error(\`[Eval Hook #\${evalId}] error:\`, error.message);
141
+ throw error;
142
+ }
143
+ };
144
+
145
+ window.setTimeout = function(handler, timeout, ...args) {
146
+ if (typeof handler === 'string') {
147
+ const evalId = ++evalCounter;
148
+ console.log(\`[Eval Hook #\${evalId}] setTimeout with code:\`, {
149
+ code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
150
+ timeout: timeout,
151
+ timestamp: new Date().toISOString()
152
+ });
153
+
154
+ ${action === 'block' ? 'return 0;' : ''}
155
+ }
156
+
157
+ return originalSetTimeout.apply(this, [handler, timeout, ...args]);
158
+ };
159
+
160
+ window.setInterval = function(handler, timeout, ...args) {
161
+ if (typeof handler === 'string') {
162
+ const evalId = ++evalCounter;
163
+ console.log(\`[Eval Hook #\${evalId}] setInterval with code:\`, {
164
+ code: handler.length > 200 ? handler.substring(0, 200) + '...' : handler,
165
+ timeout: timeout,
166
+ timestamp: new Date().toISOString()
167
+ });
168
+
169
+ ${action === 'block' ? 'return 0;' : ''}
170
+ }
171
+
172
+ return originalSetInterval.apply(this, [handler, timeout, ...args]);
173
+ };
174
+
175
+ console.log('[Eval Hook] Successfully hooked eval, Function, setTimeout, setInterval');
176
+ })();
177
177
  `.trim();
178
178
  }
179
179
  export function generateObjectMethodHook(target, action, customCode, _condition, _performance = false) {
180
180
  const parts = target.split('.');
181
181
  const methodName = parts.pop();
182
182
  const objectPath = parts.join('.');
183
- return `
184
- (function() {
185
- 'use strict';
186
-
187
- function getObjectByPath(path) {
188
- const parts = path.split('.');
189
- let obj = window;
190
-
191
- for (const part of parts) {
192
- if (part === 'window') continue;
193
- if (!obj || !(part in obj)) {
194
- return null;
195
- }
196
- obj = obj[part];
197
- }
198
-
199
- return obj;
200
- }
201
-
202
- const targetObject = getObjectByPath('${objectPath}');
203
- const methodName = '${methodName}';
204
-
205
- if (!targetObject) {
206
- console.error('[Object Hook] Target object not found: ${objectPath}');
207
- return;
208
- }
209
-
210
- const descriptor = Object.getOwnPropertyDescriptor(targetObject, methodName) ||
211
- Object.getOwnPropertyDescriptor(Object.getPrototypeOf(targetObject), methodName);
212
-
213
- if (!descriptor) {
214
- console.error('[Object Hook] Property not found: ${target}');
215
- return;
216
- }
217
-
218
- let callCounter = 0;
219
-
220
- if (typeof targetObject[methodName] === 'function') {
221
- const originalMethod = targetObject[methodName];
222
-
223
- targetObject[methodName] = function(...args) {
224
- const callId = ++callCounter;
225
- const startTime = performance.now();
226
- const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
227
-
228
- console.log(\`[Object Hook #\${callId}] ${target}:\`, {
229
- arguments: args,
230
- this: this,
231
- thisType: this?.constructor?.name,
232
- stackTrace: stackTrace,
233
- timestamp: new Date().toISOString()
234
- });
235
-
236
- ${action === 'block' ? 'return undefined;' : ''}
237
- ${customCode || ''}
238
-
239
- try {
240
- const result = originalMethod.apply(this, args);
241
- const endTime = performance.now();
242
- const duration = (endTime - startTime).toFixed(2);
243
-
244
- console.log(\`[Object Hook #\${callId}] ${target} result:\`, {
245
- result: result,
246
- resultType: typeof result,
247
- duration: duration + 'ms'
248
- });
249
-
250
- return result;
251
- } catch (error) {
252
- console.error(\`[Object Hook #\${callId}] ${target} error:\`, error);
253
- throw error;
254
- }
255
- };
256
-
257
- Object.setPrototypeOf(targetObject[methodName], originalMethod);
258
-
259
- console.log('[Object Hook] Successfully hooked method: ${target}');
260
- }
261
- else if (descriptor.get || descriptor.set) {
262
- const originalGet = descriptor.get;
263
- const originalSet = descriptor.set;
264
-
265
- Object.defineProperty(targetObject, methodName, {
266
- get: function() {
267
- console.log('[Object Hook] getter called: ${target}');
268
- return originalGet ? originalGet.call(this) : undefined;
269
- },
270
- set: function(value) {
271
- console.log('[Object Hook] setter called: ${target}', { value });
272
- ${action === 'block' ? 'return;' : ''}
273
- if (originalSet) {
274
- originalSet.call(this, value);
275
- }
276
- },
277
- configurable: true,
278
- enumerable: descriptor.enumerable
279
- });
280
-
281
- console.log('[Object Hook] Successfully hooked property: ${target}');
282
- }
283
- })();
183
+ return `
184
+ (function() {
185
+ 'use strict';
186
+
187
+ function getObjectByPath(path) {
188
+ const parts = path.split('.');
189
+ let obj = window;
190
+
191
+ for (const part of parts) {
192
+ if (part === 'window') continue;
193
+ if (!obj || !(part in obj)) {
194
+ return null;
195
+ }
196
+ obj = obj[part];
197
+ }
198
+
199
+ return obj;
200
+ }
201
+
202
+ const targetObject = getObjectByPath('${objectPath}');
203
+ const methodName = '${methodName}';
204
+
205
+ if (!targetObject) {
206
+ console.error('[Object Hook] Target object not found: ${objectPath}');
207
+ return;
208
+ }
209
+
210
+ const descriptor = Object.getOwnPropertyDescriptor(targetObject, methodName) ||
211
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(targetObject), methodName);
212
+
213
+ if (!descriptor) {
214
+ console.error('[Object Hook] Property not found: ${target}');
215
+ return;
216
+ }
217
+
218
+ let callCounter = 0;
219
+
220
+ if (typeof targetObject[methodName] === 'function') {
221
+ const originalMethod = targetObject[methodName];
222
+
223
+ targetObject[methodName] = function(...args) {
224
+ const callId = ++callCounter;
225
+ const startTime = performance.now();
226
+ const stackTrace = new Error().stack.split('\\n').slice(2, 5).join('\\n');
227
+
228
+ console.log(\`[Object Hook #\${callId}] ${target}:\`, {
229
+ arguments: args,
230
+ this: this,
231
+ thisType: this?.constructor?.name,
232
+ stackTrace: stackTrace,
233
+ timestamp: new Date().toISOString()
234
+ });
235
+
236
+ ${action === 'block' ? 'return undefined;' : ''}
237
+ ${customCode || ''}
238
+
239
+ try {
240
+ const result = originalMethod.apply(this, args);
241
+ const endTime = performance.now();
242
+ const duration = (endTime - startTime).toFixed(2);
243
+
244
+ console.log(\`[Object Hook #\${callId}] ${target} result:\`, {
245
+ result: result,
246
+ resultType: typeof result,
247
+ duration: duration + 'ms'
248
+ });
249
+
250
+ return result;
251
+ } catch (error) {
252
+ console.error(\`[Object Hook #\${callId}] ${target} error:\`, error);
253
+ throw error;
254
+ }
255
+ };
256
+
257
+ Object.setPrototypeOf(targetObject[methodName], originalMethod);
258
+
259
+ console.log('[Object Hook] Successfully hooked method: ${target}');
260
+ }
261
+ else if (descriptor.get || descriptor.set) {
262
+ const originalGet = descriptor.get;
263
+ const originalSet = descriptor.set;
264
+
265
+ Object.defineProperty(targetObject, methodName, {
266
+ get: function() {
267
+ console.log('[Object Hook] getter called: ${target}');
268
+ return originalGet ? originalGet.call(this) : undefined;
269
+ },
270
+ set: function(value) {
271
+ console.log('[Object Hook] setter called: ${target}', { value });
272
+ ${action === 'block' ? 'return;' : ''}
273
+ if (originalSet) {
274
+ originalSet.call(this, value);
275
+ }
276
+ },
277
+ configurable: true,
278
+ enumerable: descriptor.enumerable
279
+ });
280
+
281
+ console.log('[Object Hook] Successfully hooked property: ${target}');
282
+ }
283
+ })();
284
284
  `.trim();
285
285
  }
286
286
  export function generateAntiDebugBypass() {
287
- return `
288
- (function() {
289
- 'use strict';
290
-
291
- console.log('[Anti-Debug Bypass] Initializing...');
292
-
293
- const originalEval = window.eval;
294
- window.eval = function(code) {
295
- if (typeof code === 'string') {
296
- code = code.replace(/debugger\\s*;?/g, '');
297
- }
298
- return originalEval.call(this, code);
299
- };
300
-
301
- const originalFunction = window.Function;
302
- window.Function = function(...args) {
303
- if (args.length > 0) {
304
- const lastArg = args[args.length - 1];
305
- if (typeof lastArg === 'string') {
306
- args[args.length - 1] = lastArg.replace(/debugger\\s*;?/g, '');
307
- }
308
- }
309
- return originalFunction.apply(this, args);
310
- };
311
-
312
- Object.defineProperty(window, 'outerHeight', {
313
- get: function() {
314
- return window.innerHeight;
315
- }
316
- });
317
-
318
- Object.defineProperty(window, 'outerWidth', {
319
- get: function() {
320
- return window.innerWidth;
321
- }
322
- });
323
-
324
- let lastTime = Date.now();
325
- const originalDateNow = Date.now;
326
- Date.now = function() {
327
- const currentTime = originalDateNow();
328
- if (currentTime - lastTime > 100) {
329
- lastTime += 16;
330
- return lastTime;
331
- }
332
- lastTime = currentTime;
333
- return currentTime;
334
- };
335
-
336
- const originalToString = Function.prototype.toString;
337
- Function.prototype.toString = function() {
338
- if (this === window.eval || this === window.Function) {
339
- return 'function () { [native code] }';
340
- }
341
- return originalToString.call(this);
342
- };
343
-
344
- const devtools = { open: false };
345
- const threshold = 160;
346
-
347
- setInterval(function() {
348
- if (window.outerWidth - window.innerWidth > threshold ||
349
- window.outerHeight - window.innerHeight > threshold) {
350
- devtools.open = true;
351
- } else {
352
- devtools.open = false;
353
- }
354
- }, 500);
355
-
356
- Object.defineProperty(window, 'devtools', {
357
- get: function() {
358
- return { open: false };
359
- }
360
- });
361
-
362
- console.log('[Anti-Debug Bypass] Successfully bypassed anti-debugging protections');
363
- })();
287
+ return `
288
+ (function() {
289
+ 'use strict';
290
+
291
+ console.log('[Anti-Debug Bypass] Initializing...');
292
+
293
+ const originalEval = window.eval;
294
+ window.eval = function(code) {
295
+ if (typeof code === 'string') {
296
+ code = code.replace(/debugger\\s*;?/g, '');
297
+ }
298
+ return originalEval.call(this, code);
299
+ };
300
+
301
+ const originalFunction = window.Function;
302
+ window.Function = function(...args) {
303
+ if (args.length > 0) {
304
+ const lastArg = args[args.length - 1];
305
+ if (typeof lastArg === 'string') {
306
+ args[args.length - 1] = lastArg.replace(/debugger\\s*;?/g, '');
307
+ }
308
+ }
309
+ return originalFunction.apply(this, args);
310
+ };
311
+
312
+ Object.defineProperty(window, 'outerHeight', {
313
+ get: function() {
314
+ return window.innerHeight;
315
+ }
316
+ });
317
+
318
+ Object.defineProperty(window, 'outerWidth', {
319
+ get: function() {
320
+ return window.innerWidth;
321
+ }
322
+ });
323
+
324
+ let lastTime = Date.now();
325
+ const originalDateNow = Date.now;
326
+ Date.now = function() {
327
+ const currentTime = originalDateNow();
328
+ if (currentTime - lastTime > 100) {
329
+ lastTime += 16;
330
+ return lastTime;
331
+ }
332
+ lastTime = currentTime;
333
+ return currentTime;
334
+ };
335
+
336
+ const originalToString = Function.prototype.toString;
337
+ Function.prototype.toString = function() {
338
+ if (this === window.eval || this === window.Function) {
339
+ return 'function () { [native code] }';
340
+ }
341
+ return originalToString.call(this);
342
+ };
343
+
344
+ const devtools = { open: false };
345
+ const threshold = 160;
346
+
347
+ setInterval(function() {
348
+ if (window.outerWidth - window.innerWidth > threshold ||
349
+ window.outerHeight - window.innerHeight > threshold) {
350
+ devtools.open = true;
351
+ } else {
352
+ devtools.open = false;
353
+ }
354
+ }, 500);
355
+
356
+ Object.defineProperty(window, 'devtools', {
357
+ get: function() {
358
+ return { open: false };
359
+ }
360
+ });
361
+
362
+ console.log('[Anti-Debug Bypass] Successfully bypassed anti-debugging protections');
363
+ })();
364
364
  `.trim();
365
365
  }
366
366
  export function generateHookTemplate(targetName, targetType) {
367
367
  if (targetType === 'function') {
368
- return `
369
- (function() {
370
- 'use strict';
371
-
372
- const original = ${targetName};
373
-
374
- ${targetName} = function(...args) {
375
- console.log('[Hook] ${targetName} called:', args);
376
-
377
-
378
- const result = original.apply(this, args);
379
- console.log('[Hook] ${targetName} result:', result);
380
-
381
- return result;
382
- };
383
-
384
- console.log('[Hook] Successfully hooked: ${targetName}');
385
- })();
368
+ return `
369
+ (function() {
370
+ 'use strict';
371
+
372
+ const original = ${targetName};
373
+
374
+ ${targetName} = function(...args) {
375
+ console.log('[Hook] ${targetName} called:', args);
376
+
377
+
378
+ const result = original.apply(this, args);
379
+ console.log('[Hook] ${targetName} result:', result);
380
+
381
+ return result;
382
+ };
383
+
384
+ console.log('[Hook] Successfully hooked: ${targetName}');
385
+ })();
386
386
  `.trim();
387
387
  }
388
388
  else if (targetType === 'property') {
389
- return `
390
- (function() {
391
- 'use strict';
392
-
393
- const descriptor = Object.getOwnPropertyDescriptor(${targetName.split('.').slice(0, -1).join('.')}, '${targetName.split('.').pop()}');
394
- const originalGet = descriptor?.get;
395
- const originalSet = descriptor?.set;
396
-
397
- Object.defineProperty(${targetName.split('.').slice(0, -1).join('.')}, '${targetName.split('.').pop()}', {
398
- get: function() {
399
- console.log('[Hook] ${targetName} get');
400
- return originalGet ? originalGet.call(this) : undefined;
401
- },
402
- set: function(value) {
403
- console.log('[Hook] ${targetName} set:', value);
404
- if (originalSet) {
405
- originalSet.call(this, value);
406
- }
407
- },
408
- configurable: true
409
- });
410
-
411
- console.log('[Hook] Successfully hooked property: ${targetName}');
412
- })();
389
+ return `
390
+ (function() {
391
+ 'use strict';
392
+
393
+ const descriptor = Object.getOwnPropertyDescriptor(${targetName.split('.').slice(0, -1).join('.')}, '${targetName.split('.').pop()}');
394
+ const originalGet = descriptor?.get;
395
+ const originalSet = descriptor?.set;
396
+
397
+ Object.defineProperty(${targetName.split('.').slice(0, -1).join('.')}, '${targetName.split('.').pop()}', {
398
+ get: function() {
399
+ console.log('[Hook] ${targetName} get');
400
+ return originalGet ? originalGet.call(this) : undefined;
401
+ },
402
+ set: function(value) {
403
+ console.log('[Hook] ${targetName} set:', value);
404
+ if (originalSet) {
405
+ originalSet.call(this, value);
406
+ }
407
+ },
408
+ configurable: true
409
+ });
410
+
411
+ console.log('[Hook] Successfully hooked property: ${targetName}');
412
+ })();
413
413
  `.trim();
414
414
  }
415
415
  else {
416
- return `
417
- (function() {
418
- 'use strict';
419
-
420
- const original = ${targetName};
421
-
422
- ${targetName} = function(...args) {
423
- console.log('[Hook] ${targetName} constructor called:', args);
424
-
425
- const instance = new original(...args);
426
-
427
- const methodNames = Object.getOwnPropertyNames(original.prototype);
428
- methodNames.forEach(name => {
429
- if (name !== 'constructor' && typeof instance[name] === 'function') {
430
- const originalMethod = instance[name];
431
- instance[name] = function(...methodArgs) {
432
- console.log(\`[Hook] \${name} called:\`, methodArgs);
433
- return originalMethod.apply(this, methodArgs);
434
- };
435
- }
436
- });
437
-
438
- return instance;
439
- };
440
-
441
- ${targetName}.prototype = original.prototype;
442
-
443
- console.log('[Hook] Successfully hooked prototype: ${targetName}');
444
- })();
416
+ return `
417
+ (function() {
418
+ 'use strict';
419
+
420
+ const original = ${targetName};
421
+
422
+ ${targetName} = function(...args) {
423
+ console.log('[Hook] ${targetName} constructor called:', args);
424
+
425
+ const instance = new original(...args);
426
+
427
+ const methodNames = Object.getOwnPropertyNames(original.prototype);
428
+ methodNames.forEach(name => {
429
+ if (name !== 'constructor' && typeof instance[name] === 'function') {
430
+ const originalMethod = instance[name];
431
+ instance[name] = function(...methodArgs) {
432
+ console.log(\`[Hook] \${name} called:\`, methodArgs);
433
+ return originalMethod.apply(this, methodArgs);
434
+ };
435
+ }
436
+ });
437
+
438
+ return instance;
439
+ };
440
+
441
+ ${targetName}.prototype = original.prototype;
442
+
443
+ console.log('[Hook] Successfully hooked prototype: ${targetName}');
444
+ })();
445
445
  `.trim();
446
446
  }
447
447
  }