@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,244 @@
1
+ //#region src/server/instrumentation/InstrumentationSession.ts
2
+ let _nextId = 0;
3
+ function uid(prefix) {
4
+ return `${prefix}-${Date.now().toString(36)}-${(++_nextId).toString(36)}`;
5
+ }
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ function parseToolPayload(response) {
10
+ const firstText = response.content.find((item) => item.type === "text" && typeof item.text === "string");
11
+ if (!firstText) throw new Error("Expected JSON text payload from wrapped tool response");
12
+ let parsed;
13
+ try {
14
+ parsed = JSON.parse(firstText.text);
15
+ } catch (error) {
16
+ throw new Error(
17
+ /* istanbul ignore next */
18
+ `Wrapped tool returned non-JSON text payload: ${error instanceof Error ? error.message : String(error)}`,
19
+ { cause: error }
20
+ );
21
+ }
22
+ if (!isRecord(parsed)) throw new Error("Wrapped tool returned JSON that is not an object");
23
+ return parsed;
24
+ }
25
+ function getStringArray(value) {
26
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
27
+ }
28
+ var InstrumentationSessionManager = class {
29
+ /** All sessions (including destroyed). */
30
+ sessions = /* @__PURE__ */ new Map();
31
+ /** Session ID → operations. */
32
+ operations = /* @__PURE__ */ new Map();
33
+ /** Session ID → artifacts. */
34
+ artifacts = /* @__PURE__ */ new Map();
35
+ /** Operation ID → owning session ID (reverse index). */
36
+ operationIndex = /* @__PURE__ */ new Map();
37
+ /** Optional evidence graph bridge for auto-population (EVID-04). */
38
+ evidenceBridge;
39
+ /** Set the evidence graph bridge for auto-populating evidence nodes. */
40
+ setEvidenceBridge(bridge) {
41
+ this.evidenceBridge = bridge;
42
+ }
43
+ createSession(name) {
44
+ const id = uid("sess");
45
+ const info = {
46
+ id,
47
+ name,
48
+ createdAt: Date.now(),
49
+ operationCount: 0,
50
+ artifactCount: 0,
51
+ status: "active"
52
+ };
53
+ this.sessions.set(id, info);
54
+ this.operations.set(id, []);
55
+ this.artifacts.set(id, []);
56
+ return info;
57
+ }
58
+ destroySession(sessionId) {
59
+ const session = this.sessions.get(sessionId);
60
+ if (!session) throw new Error(`Session "${sessionId}" not found`);
61
+ session.status = "destroyed";
62
+ /* istanbul ignore next */
63
+ const ops = this.operations.get(sessionId) ?? [];
64
+ for (const op of ops) if (op.status === "active") op.status = "completed";
65
+ }
66
+ listSessions() {
67
+ return [...this.sessions.values()].filter((s) => s.status === "active");
68
+ }
69
+ getSession(sessionId) {
70
+ return this.sessions.get(sessionId);
71
+ }
72
+ registerOperation(sessionId, type, target, config) {
73
+ const session = this.sessions.get(sessionId);
74
+ if (!session) throw new Error(`Session "${sessionId}" not found`);
75
+ if (session.status === "destroyed") throw new Error(`Session "${sessionId}" is destroyed — cannot register new operations`);
76
+ const id = uid("op");
77
+ const op = {
78
+ id,
79
+ sessionId,
80
+ type,
81
+ target,
82
+ config,
83
+ createdAt: Date.now(),
84
+ status: "active"
85
+ };
86
+ const ops = this.operations.get(sessionId);
87
+ ops.push(op);
88
+ this.operationIndex.set(id, sessionId);
89
+ session.operationCount = ops.length;
90
+ this.evidenceBridge?.onOperation(op);
91
+ return op;
92
+ }
93
+ getSessionOperations(sessionId) {
94
+ /* istanbul ignore next */
95
+ return this.operations.get(sessionId) ?? [];
96
+ }
97
+ recordArtifact(operationId, data) {
98
+ const sessionId = this.operationIndex.get(operationId);
99
+ if (!sessionId) throw new Error(`Operation "${operationId}" not found`);
100
+ const op = (this.operations.get(sessionId) ?? []).find((o) => o.id === operationId);
101
+ if (!op) throw new Error(`Operation "${operationId}" metadata missing`);
102
+ const artifact = {
103
+ operationId,
104
+ sessionId,
105
+ type: op.type,
106
+ timestamp: Date.now(),
107
+ data
108
+ };
109
+ const sessionArtifacts = this.artifacts.get(sessionId);
110
+ sessionArtifacts.push(artifact);
111
+ const session = this.sessions.get(sessionId);
112
+ session.artifactCount = sessionArtifacts.length;
113
+ this.evidenceBridge?.onArtifact(artifact);
114
+ return artifact;
115
+ }
116
+ getArtifacts(sessionId, type) {
117
+ /* istanbul ignore next */
118
+ const all = this.artifacts.get(sessionId) ?? [];
119
+ if (!type) return all;
120
+ return all.filter((a) => a.type === type);
121
+ }
122
+ getSessionSnapshot(sessionId) {
123
+ const session = this.sessions.get(sessionId);
124
+ if (!session) return;
125
+ return {
126
+ session,
127
+ stats: this.getSessionStats(sessionId),
128
+ operations: [...this.getSessionOperations(sessionId)],
129
+ artifacts: [...this.getArtifacts(sessionId)]
130
+ };
131
+ }
132
+ listSessionSnapshots() {
133
+ return this.listSessions().map((session) => ({
134
+ session,
135
+ stats: this.getSessionStats(session.id),
136
+ operations: [...this.getSessionOperations(session.id)],
137
+ artifacts: [...this.getArtifacts(session.id)]
138
+ }));
139
+ }
140
+ async applyHookPreset(sessionId, presetInvoker, args) {
141
+ const presetNames = getStringArray(args["presets"]);
142
+ const target = (typeof args["preset"] === "string" ? args["preset"] : void 0) ?? (presetNames.length > 0 ? presetNames.join(", ") : "hook_preset");
143
+ return this.executeTrackedTool({
144
+ sessionId,
145
+ type: "runtime-hook",
146
+ target,
147
+ config: { ...args },
148
+ invoke: () => presetInvoker.handleHookPreset(args),
149
+ isSuccessful: (payload) => {
150
+ return getStringArray(payload.injected).length > 0;
151
+ },
152
+ buildArtifacts: (payload) => {
153
+ const injected = getStringArray(payload.injected);
154
+ return [{
155
+ presetIds: injected,
156
+ failedPresets: Array.isArray(payload.failed) ? payload.failed.filter((item) => isRecord(item) && typeof item["preset"] === "string" && typeof item["error"] === "string") : [],
157
+ injectionPoint: payload.method === "evaluateOnNewDocument" ? "before-load" : "runtime",
158
+ scriptContent: injected.join(", "),
159
+ body: payload
160
+ }];
161
+ }
162
+ });
163
+ }
164
+ async replayNetworkRequest(sessionId, replayInvoker, args) {
165
+ const requestId = typeof args["requestId"] === "string" ? args["requestId"] : "network_replay";
166
+ const urlOverride = typeof args["urlOverride"] === "string" ? args["urlOverride"] : void 0;
167
+ return this.executeTrackedTool({
168
+ sessionId,
169
+ type: "network-intercept",
170
+ target: requestId,
171
+ config: { ...args },
172
+ invoke: () => replayInvoker.handleNetworkReplayRequest(args),
173
+ buildArtifacts: (payload) => {
174
+ if (payload.dryRun === true && isRecord(payload.preview)) return [{
175
+ requestId,
176
+ url: typeof payload.preview["url"] === "string" ? payload.preview["url"] : urlOverride,
177
+ method: typeof payload.preview["method"] === "string" ? payload.preview["method"] : void 0,
178
+ headers: isRecord(payload.preview["headers"]) ? payload.preview["headers"] : void 0,
179
+ body: payload.preview["body"],
180
+ replayMode: "dry-run"
181
+ }];
182
+ return [{
183
+ requestId: typeof payload.requestId === "string" ? payload.requestId : requestId,
184
+ url: urlOverride,
185
+ method: typeof args["methodOverride"] === "string" ? args["methodOverride"] : void 0,
186
+ headers: isRecord(payload.headers) ? payload.headers : void 0,
187
+ body: payload.body,
188
+ statusCode: typeof payload.status === "number" ? payload.status : void 0,
189
+ statusText: typeof payload.statusText === "string" ? payload.statusText : void 0,
190
+ bodyTruncated: typeof payload.bodyTruncated === "boolean" ? payload.bodyTruncated : void 0,
191
+ replayMode: "live"
192
+ }];
193
+ }
194
+ });
195
+ }
196
+ getSessionStats(sessionId) {
197
+ const session = this.sessions.get(sessionId);
198
+ if (!session) return {
199
+ operationCount: 0,
200
+ artifactCount: 0
201
+ };
202
+ return {
203
+ operationCount: session.operationCount,
204
+ artifactCount: session.artifactCount
205
+ };
206
+ }
207
+ findOperation(operationId) {
208
+ const sessionId = this.operationIndex.get(operationId);
209
+ if (!sessionId) return;
210
+ /* istanbul ignore next */
211
+ return (this.operations.get(sessionId) ?? []).find((operation) => operation.id === operationId);
212
+ }
213
+ setOperationStatus(operationId, status) {
214
+ const operation = this.findOperation(operationId);
215
+ if (operation) operation.status = status;
216
+ }
217
+ async executeTrackedTool(spec) {
218
+ const operation = this.registerOperation(spec.sessionId, spec.type, spec.target, spec.config);
219
+ try {
220
+ const payload = parseToolPayload(await spec.invoke());
221
+ if (!(spec.isSuccessful ? spec.isSuccessful(payload) : payload["success"] !== false)) {
222
+ this.setOperationStatus(operation.id, "failed");
223
+ return {
224
+ operation,
225
+ artifacts: [],
226
+ payload
227
+ };
228
+ }
229
+ /* istanbul ignore next */
230
+ const artifacts = (spec.buildArtifacts?.(payload) ?? []).map((artifactData) => this.recordArtifact(operation.id, artifactData));
231
+ this.setOperationStatus(operation.id, "completed");
232
+ return {
233
+ operation,
234
+ artifacts,
235
+ payload
236
+ };
237
+ } catch (error) {
238
+ this.setOperationStatus(operation.id, "failed");
239
+ throw error;
240
+ }
241
+ }
242
+ };
243
+ //#endregion
244
+ export { InstrumentationSessionManager };
@@ -1,6 +1,6 @@
1
- import { cr as WRITE_HISTORY_MAX, q as FREEZE_DEFAULT_INTERVAL_MS } from "./constants-CCvsN80K.mjs";
2
- import { _ as WriteProcessMemory, b as openProcessForMemory, d as ReadProcessMemory, m as VirtualProtectEx, t as CloseHandle, u as PAGE } from "./Win32API-Bc0QnQsN.mjs";
3
- import { i as parsePattern } from "./NativeMemoryManager.utils-BML4q1ry.mjs";
1
+ import { Or as WRITE_HISTORY_MAX, X as FREEZE_DEFAULT_INTERVAL_MS } from "./constants-B0OANIBL.mjs";
2
+ import { _ as WriteProcessMemory, b as openProcessForMemory, d as ReadProcessMemory, m as VirtualProtectEx, t as CloseHandle, u as PAGE } from "./Win32API-CePkipZY.mjs";
3
+ import { i as parsePattern } from "./NativeMemoryManager.utils-B-FjA2mJ.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  //#region src/native/MemoryController.ts
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { Gt as SCAN_SESSION_MAX_COUNT, Kt as SCAN_SESSION_TTL_MS } from "./constants-CCvsN80K.mjs";
2
- import { n as parseAddress, t as formatAddress } from "./formatAddress-ChCSIRWT.mjs";
1
+ import { gn as SCAN_SESSION_TTL_MS, hn as SCAN_SESSION_MAX_COUNT } from "./constants-B0OANIBL.mjs";
2
+ import { n as parseAddress, t as formatAddress } from "./formatAddress-DVkj9kpI.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/native/ScanComparators.ts
5
5
  const FLOAT_EPSILON = 1e-6;
@@ -44,94 +44,97 @@ function getDefaultAlignment(type) {
44
44
  default: return 1;
45
45
  }
46
46
  }
47
- /**
48
- * Read a typed numeric value from a buffer at offset 0.
49
- */
50
- function readTypedValue(buf, type) {
47
+ function makeReader(type) {
51
48
  switch (type) {
52
- case "byte": return buf.readUInt8(0);
53
- case "int8": return buf.readInt8(0);
54
- case "int16": return buf.readInt16LE(0);
55
- case "uint16": return buf.readUInt16LE(0);
56
- case "int32": return buf.readInt32LE(0);
57
- case "uint32": return buf.readUInt32LE(0);
58
- case "int64": return buf.readBigInt64LE(0);
49
+ case "byte": return (buf) => buf.readUInt8(0);
50
+ case "int8": return (buf) => buf.readInt8(0);
51
+ case "int16": return (buf) => buf.readInt16LE(0);
52
+ case "uint16": return (buf) => buf.readUInt16LE(0);
53
+ case "int32": return (buf) => buf.readInt32LE(0);
54
+ case "uint32": return (buf) => buf.readUInt32LE(0);
55
+ case "int64": return (buf) => buf.readBigInt64LE(0);
59
56
  case "uint64":
60
- case "pointer": return buf.readBigUInt64LE(0);
61
- case "float": return buf.readFloatLE(0);
62
- case "double": return buf.readDoubleLE(0);
63
- default: return buf.readInt32LE(0);
57
+ case "pointer": return (buf) => buf.readBigUInt64LE(0);
58
+ case "float": return (buf) => buf.readFloatLE(0);
59
+ case "double": return (buf) => buf.readDoubleLE(0);
60
+ default: return (buf) => buf.readInt32LE(0);
64
61
  }
65
62
  }
66
- /**
67
- * Check if two numeric values are approximately equal, using epsilon for floats.
68
- */
69
- function approxEqual(a, b, type) {
70
- if (typeof a === "bigint" && typeof b === "bigint") return a === b;
71
- const na = Number(a);
72
- const nb = Number(b);
73
- if (type === "float") return Math.abs(na - nb) < FLOAT_EPSILON;
74
- if (type === "double") return Math.abs(na - nb) < DOUBLE_EPSILON;
75
- return na === nb;
63
+ function makeApproxEqual(type) {
64
+ if (type === "float") return (a, b) => Math.abs(Number(a) - Number(b)) < FLOAT_EPSILON;
65
+ if (type === "double") return (a, b) => Math.abs(Number(a) - Number(b)) < DOUBLE_EPSILON;
66
+ if (type === "int64" || type === "uint64" || type === "pointer") return (a, b) => a === b;
67
+ return (a, b) => Number(a) === Number(b);
76
68
  }
77
- /**
78
- * Compare a numeric value against another for ordering.
79
- * Returns negative if a < b, 0 if equal, positive if a > b.
80
- */
81
- function compareValues(a, b) {
82
- if (typeof a === "bigint" && typeof b === "bigint") {
83
- if (a < b) return -1;
84
- if (a > b) return 1;
85
- return 0;
69
+ function makeComparator(mode, type) {
70
+ const read = makeReader(type);
71
+ const approxEq = makeApproxEqual(type);
72
+ const compare = type === "int64" || type === "uint64" || type === "pointer" ? (a, b) => {
73
+ const ba = BigInt(a);
74
+ const bb = BigInt(b);
75
+ return ba < bb ? -1 : ba > bb ? 1 : 0;
76
+ } : (a, b) => Number(a) - Number(b);
77
+ switch (mode) {
78
+ case "exact": return (cur, _prev, tgt, _tgt2) => {
79
+ if (!tgt) return false;
80
+ return approxEq(read(cur), read(tgt));
81
+ };
82
+ case "unknown_initial": return () => true;
83
+ case "changed": return (cur, prev, _tgt, _tgt2) => {
84
+ if (!prev) return false;
85
+ return !approxEq(read(cur), read(prev));
86
+ };
87
+ case "unchanged": return (cur, prev, _tgt, _tgt2) => {
88
+ if (!prev) return true;
89
+ return approxEq(read(cur), read(prev));
90
+ };
91
+ case "increased": return (cur, prev, _tgt, _tgt2) => {
92
+ if (!prev) return false;
93
+ return compare(read(cur), read(prev)) > 0;
94
+ };
95
+ case "decreased": return (cur, prev, _tgt, _tgt2) => {
96
+ if (!prev) return false;
97
+ return compare(read(cur), read(prev)) < 0;
98
+ };
99
+ case "greater_than": return (cur, _prev, tgt, _tgt2) => {
100
+ if (!tgt) return false;
101
+ return compare(read(cur), read(tgt)) > 0;
102
+ };
103
+ case "less_than": return (cur, _prev, tgt, _tgt2) => {
104
+ if (!tgt) return false;
105
+ return compare(read(cur), read(tgt)) < 0;
106
+ };
107
+ case "between": return (cur, _prev, tgt, tgt2) => {
108
+ if (!tgt || !tgt2) return false;
109
+ return compare(read(cur), read(tgt)) >= 0 && compare(read(cur), read(tgt2)) <= 0;
110
+ };
111
+ case "not_equal": return (cur, _prev, tgt, _tgt2) => {
112
+ if (!tgt) return false;
113
+ return !approxEq(read(cur), read(tgt));
114
+ };
115
+ default: return () => false;
86
116
  }
87
- return Number(a) - Number(b);
117
+ }
118
+ const comparatorCache = /* @__PURE__ */ new Map();
119
+ function getComparator(mode, valueType) {
120
+ const key = `${mode}:${valueType}`;
121
+ let comp = comparatorCache.get(key);
122
+ if (!comp) {
123
+ comp = makeComparator(mode, valueType);
124
+ comparatorCache.set(key, comp);
125
+ }
126
+ return comp;
88
127
  }
89
128
  /**
90
129
  * Compare scan values according to the specified mode.
91
130
  *
92
- * @param current - Current value buffer read from memory
93
- * @param previous - Previous value buffer from last scan (null on first scan)
94
- * @param target - Target value buffer for exact/greater/less/not_equal comparisons
95
- * @param target2 - Second target value buffer for 'between' mode (upper bound)
96
- * @param mode - Comparison mode
97
- * @param valueType - Value type for proper reading
131
+ * Dispatches to a monomorphic specialist comparator that is cached per
132
+ * (mode, valueType) pair. This avoids per-call switch dispatch on valueType
133
+ * in the hot scan loop, allowing V8 TurboFan to inline and optimize the
134
+ * typed read + compare path.
98
135
  */
99
136
  function compareScanValues(current, previous, target, target2, mode, valueType) {
100
- const cur = readTypedValue(current, valueType);
101
- switch (mode) {
102
- case "exact":
103
- if (!target) return false;
104
- return approxEqual(cur, readTypedValue(target, valueType), valueType);
105
- case "unknown_initial": return true;
106
- case "changed":
107
- if (!previous) return false;
108
- return !approxEqual(cur, readTypedValue(previous, valueType), valueType);
109
- case "unchanged":
110
- if (!previous) return true;
111
- return approxEqual(cur, readTypedValue(previous, valueType), valueType);
112
- case "increased":
113
- if (!previous) return false;
114
- return compareValues(cur, readTypedValue(previous, valueType)) > 0;
115
- case "decreased":
116
- if (!previous) return false;
117
- return compareValues(cur, readTypedValue(previous, valueType)) < 0;
118
- case "greater_than":
119
- if (!target) return false;
120
- return compareValues(cur, readTypedValue(target, valueType)) > 0;
121
- case "less_than":
122
- if (!target) return false;
123
- return compareValues(cur, readTypedValue(target, valueType)) < 0;
124
- case "between": {
125
- if (!target || !target2) return false;
126
- const lo = readTypedValue(target, valueType);
127
- const hi = readTypedValue(target2, valueType);
128
- return compareValues(cur, lo) >= 0 && compareValues(cur, hi) <= 0;
129
- }
130
- case "not_equal":
131
- if (!target) return false;
132
- return !approxEqual(cur, readTypedValue(target, valueType), valueType);
133
- default: return false;
134
- }
137
+ return getComparator(mode, valueType)(current, previous, target, target2);
135
138
  }
136
139
  //#endregion
137
140
  //#region src/native/MemoryScanSession.ts
@@ -1,9 +1,9 @@
1
- import { Ht as SCAN_GROUP_MAX_PATTERN_SIZE, Ut as SCAN_MAX_RESULTS_PER_SCAN, Vt as SCAN_DISPLAY_RESULTS_LIMIT, Wt as SCAN_POINTER_MAX_RESULTS, qt as SCAN_UNKNOWN_INITIAL_MAX_ADDRESSES } from "./constants-CCvsN80K.mjs";
2
- import { t as nativeMemoryManager } from "./NativeMemoryManager.impl-CB6gJ0NM.mjs";
3
- import { t as createPlatformProvider } from "./factory-CibqTNC8.mjs";
4
- import { i as parsePattern } from "./NativeMemoryManager.utils-BML4q1ry.mjs";
5
- import { n as parseAddress, t as formatAddress } from "./formatAddress-ChCSIRWT.mjs";
6
- import { n as getDefaultAlignment, r as getValueSize, scanSessionManager, t as compareScanValues } from "./MemoryScanSession-RMixN3bX.mjs";
1
+ import { _n as SCAN_UNKNOWN_INITIAL_MAX_ADDRESSES, dn as SCAN_DISPLAY_RESULTS_LIMIT, fn as SCAN_GROUP_MAX_PATTERN_SIZE, mn as SCAN_POINTER_MAX_RESULTS, pn as SCAN_MAX_RESULTS_PER_SCAN } from "./constants-B0OANIBL.mjs";
2
+ import { t as createPlatformProvider } from "./factory-DxlGh9Xf.mjs";
3
+ import { i as parsePattern } from "./NativeMemoryManager.utils-B-FjA2mJ.mjs";
4
+ import { t as nativeMemoryManager } from "./NativeMemoryManager.impl-dZtA1ZGn.mjs";
5
+ import { n as parseAddress, t as formatAddress } from "./formatAddress-DVkj9kpI.mjs";
6
+ import { n as getDefaultAlignment, r as getValueSize, scanSessionManager, t as compareScanValues } from "./MemoryScanSession-BsDZbLYm.mjs";
7
7
  //#region src/native/MemoryScanner.ts
8
8
  /**
9
9
  * Memory Scanner — orchestrates iterative scan workflows.
@@ -67,14 +67,28 @@ var MemoryScanner = class {
67
67
  } catch {
68
68
  break;
69
69
  }
70
- const alignStep = alignment > 0 ? alignment : 1;
71
- const startOffset = alignment > 0 ? (alignStep - offset % alignStep) % alignStep : 0;
72
- for (let i = startOffset; i <= chunk.length - valueSize; i += alignStep) {
73
- const currentBuf = chunk.subarray(i, i + valueSize);
74
- if (compareScanValues(currentBuf, null, targetBuf, null, "exact", valueType)) {
70
+ if (alignment === valueSize && valueSize > 0) {
71
+ const alignStep = this.getAlignStep(alignment);
72
+ let searchFrom = this.getAlignedChunkStart(chunkAddr, alignStep);
73
+ while (searchFrom <= chunk.length - valueSize && addresses.length < maxResults) {
74
+ const hit = chunk.indexOf(targetBuf, searchFrom);
75
+ if (hit === -1) break;
76
+ if (!this.isAlignedAddress(chunkAddr + BigInt(hit), alignStep)) {
77
+ searchFrom = hit + 1;
78
+ continue;
79
+ }
80
+ const addr = chunkAddr + BigInt(hit);
81
+ addresses.push(addr);
82
+ values.set(addr, Buffer.from(chunk.subarray(hit, hit + valueSize)));
83
+ searchFrom = hit + alignStep;
84
+ }
85
+ } else {
86
+ const alignStep = this.getAlignStep(alignment);
87
+ const chunkStart = this.getAlignedChunkStart(chunkAddr, alignStep);
88
+ for (let i = chunkStart; i <= chunk.length - valueSize; i += alignStep) if (Buffer.compare(chunk.subarray(i, i + valueSize), targetBuf) === 0) {
75
89
  const addr = chunkAddr + BigInt(i);
76
90
  addresses.push(addr);
77
- values.set(addr, Buffer.from(currentBuf));
91
+ values.set(addr, Buffer.from(chunk.subarray(i, i + valueSize)));
78
92
  if (addresses.length >= maxResults) break;
79
93
  }
80
94
  }
@@ -183,12 +197,12 @@ var MemoryScanner = class {
183
197
  } catch {
184
198
  break;
185
199
  }
186
- const alignStep = alignment > 0 ? alignment : 1;
187
- for (let i = 0; i <= chunk.length - valueSize; i += alignStep) {
200
+ const alignStep = this.getAlignStep(alignment);
201
+ const chunkStart = this.getAlignedChunkStart(chunkAddr, alignStep);
202
+ for (let i = chunkStart; i <= chunk.length - valueSize; i += alignStep) {
188
203
  const addr = chunkAddr + BigInt(i);
189
- const currentBuf = chunk.subarray(i, i + valueSize);
190
204
  addresses.push(addr);
191
- values.set(addr, Buffer.from(currentBuf));
205
+ values.set(addr, Buffer.from(chunk.subarray(i, i + valueSize)));
192
206
  if (addresses.length >= maxAddresses) break;
193
207
  }
194
208
  }
@@ -312,8 +326,9 @@ var MemoryScanner = class {
312
326
  } catch {
313
327
  break;
314
328
  }
315
- const alignStep = alignment > 0 ? alignment : 1;
316
- for (let i = 0; i <= chunk.length - maxOffset; i += alignStep) {
329
+ const alignStep = this.getAlignStep(alignment);
330
+ const chunkStart = this.getAlignedChunkStart(chunkAddr, alignStep);
331
+ for (let i = chunkStart; i <= chunk.length - maxOffset; i += alignStep) {
317
332
  let match = true;
318
333
  for (let j = 0; j < maxOffset; j++) if (compositeMask[j] === 1 && chunk[i + j] !== compositePattern[j]) {
319
334
  match = false;
@@ -342,6 +357,17 @@ var MemoryScanner = class {
342
357
  elapsed
343
358
  };
344
359
  }
360
+ getAlignStep(alignment) {
361
+ return alignment > 0 ? alignment : 1;
362
+ }
363
+ getAlignedChunkStart(chunkAddr, alignStep) {
364
+ const align = BigInt(alignStep);
365
+ const remainder = chunkAddr % align;
366
+ return remainder === 0n ? 0 : Number(align - remainder);
367
+ }
368
+ isAlignedAddress(address, alignStep) {
369
+ return address % BigInt(alignStep) === 0n;
370
+ }
345
371
  /**
346
372
  * Pattern-based first scan for variable-length types (hex/string).
347
373
  * Delegates to existing NativeMemoryManager.scanMemory.
@@ -1,49 +1,10 @@
1
- import { t as logger } from "./logger-BmWzC2lM.mjs";
2
- import { a as MemoryProtection, t as createPlatformProvider } from "./factory-CibqTNC8.mjs";
3
- import { v as isKoffiAvailable, y as isWindows } from "./Win32API-Bc0QnQsN.mjs";
4
- import { i as parsePattern, t as findPatternInBuffer } from "./NativeMemoryManager.utils-BML4q1ry.mjs";
1
+ import { t as logger } from "./logger-Dh_xb7_2.mjs";
2
+ import { v as isKoffiAvailable, y as isWindows } from "./Win32API-CePkipZY.mjs";
3
+ import { n as cpuLimit } from "./concurrency-Bt0yv1kJ.mjs";
4
+ import { t as createPlatformProvider } from "./factory-DxlGh9Xf.mjs";
5
+ import { i as parsePattern, t as findPatternInBuffer } from "./NativeMemoryManager.utils-B-FjA2mJ.mjs";
5
6
  import { exec } from "node:child_process";
6
7
  import { promisify } from "node:util";
7
- //#region src/utils/concurrency.ts
8
- function pLimit(concurrency) {
9
- if (concurrency < 1) throw new RangeError("concurrency must be >= 1");
10
- let activeCount = 0;
11
- const queue = [];
12
- function next() {
13
- if (queue.length > 0 && activeCount < concurrency) {
14
- activeCount++;
15
- queue.shift()();
16
- }
17
- }
18
- function run(fn) {
19
- return new Promise((resolve, reject) => {
20
- const execute = async () => {
21
- try {
22
- resolve(await fn());
23
- } catch (err) {
24
- reject(err);
25
- } finally {
26
- activeCount--;
27
- next();
28
- }
29
- };
30
- if (activeCount < concurrency) {
31
- activeCount++;
32
- execute();
33
- } else queue.push(() => {
34
- execute();
35
- });
36
- });
37
- }
38
- return run;
39
- }
40
- /** External CLI calls, HAR export, large file I/O */
41
- const ioLimit = pLimit(parseInt(process.env.jshook_IO_CONCURRENCY || "4", 10));
42
- /** CPU-heavy: AST parsing, deobfuscation, binary decoding */
43
- const cpuLimit = pLimit(parseInt(process.env.jshook_CPU_CONCURRENCY || "2", 10));
44
- /** CDP-heavy: heap snapshots, traces, profiling */
45
- const cdpLimit = pLimit(parseInt(process.env.jshook_CDP_CONCURRENCY || "2", 10));
46
- //#endregion
47
8
  //#region src/native/NativeMemoryManager.availability.ts
48
9
  async function checkNativeMemoryAvailability(execAsync) {
49
10
  if (process.platform === "darwin") return checkDarwinAvailability(execAsync);
@@ -363,7 +324,7 @@ var NativeMemoryManager = class {
363
324
  error: "DLL injection is only supported on Windows"
364
325
  };
365
326
  try {
366
- const { openProcessForMemory, CloseHandle, WriteProcessMemory, VirtualAllocEx, CreateRemoteThread, GetModuleHandle, GetProcAddress, PAGE, MEM } = await import("./Win32API-Bc0QnQsN.mjs").then((n) => n.g);
327
+ const { openProcessForMemory, CloseHandle, WriteProcessMemory, VirtualAllocEx, CreateRemoteThread, GetModuleHandle, GetProcAddress, PAGE, MEM } = await import("./Win32API-CePkipZY.mjs").then((n) => n.g);
367
328
  const handle = openProcessForMemory(pid, true);
368
329
  try {
369
330
  const loadLibraryAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
@@ -413,7 +374,7 @@ var NativeMemoryManager = class {
413
374
  let buffer;
414
375
  if (encoding === "base64") buffer = Buffer.from(shellcode, "base64");
415
376
  else buffer = Buffer.from(shellcode.replace(/\s/g, ""), "hex");
416
- const { openProcessForMemory, CloseHandle, WriteProcessMemory, VirtualAllocEx, VirtualProtectEx, CreateRemoteThread, PAGE, MEM } = await import("./Win32API-Bc0QnQsN.mjs").then((n) => n.g);
377
+ const { openProcessForMemory, CloseHandle, WriteProcessMemory, VirtualAllocEx, VirtualProtectEx, CreateRemoteThread, PAGE, MEM } = await import("./Win32API-CePkipZY.mjs").then((n) => n.g);
417
378
  const handle = openProcessForMemory(pid, true);
418
379
  try {
419
380
  const remoteMem = VirtualAllocEx(handle, 0n, buffer.length, MEM.COMMIT | MEM.RESERVE, PAGE.READWRITE);
@@ -460,7 +421,7 @@ var NativeMemoryManager = class {
460
421
  error: "Debug port check is only supported on Windows"
461
422
  };
462
423
  try {
463
- const { openProcessForMemory, CloseHandle, NtQueryInformationProcess } = await import("./Win32API-Bc0QnQsN.mjs").then((n) => n.g);
424
+ const { openProcessForMemory, CloseHandle, NtQueryInformationProcess } = await import("./Win32API-CePkipZY.mjs").then((n) => n.g);
464
425
  const handle = openProcessForMemory(pid, false);
465
426
  try {
466
427
  const { status, debugPort } = NtQueryInformationProcess(handle, 7);
@@ -502,12 +463,12 @@ function regionInfoToMemoryRegion(info) {
502
463
  }
503
464
  /** Convert MemoryProtection flags to human-readable string */
504
465
  function protectionToString(prot) {
505
- if (prot === MemoryProtection.NoAccess) return "NOACCESS";
466
+ if (prot === 0) return "NOACCESS";
506
467
  const parts = [];
507
- const hasRead = (prot & MemoryProtection.Read) !== 0;
508
- const hasWrite = (prot & MemoryProtection.Write) !== 0;
509
- const hasExec = (prot & MemoryProtection.Execute) !== 0;
510
- const hasGuard = (prot & MemoryProtection.Guard) !== 0;
468
+ const hasRead = (prot & 1) !== 0;
469
+ const hasWrite = (prot & 2) !== 0;
470
+ const hasExec = (prot & 4) !== 0;
471
+ const hasGuard = (prot & 8) !== 0;
511
472
  if (hasRead && hasWrite && hasExec) parts.push("RWX");
512
473
  else if (hasRead && hasExec) parts.push("RX");
513
474
  else if (hasRead && hasWrite) parts.push("RW");
@@ -518,4 +479,4 @@ function protectionToString(prot) {
518
479
  }
519
480
  const nativeMemoryManager = new NativeMemoryManager();
520
481
  //#endregion
521
- export { ioLimit as i, cdpLimit as n, cpuLimit as r, nativeMemoryManager as t };
482
+ export { nativeMemoryManager as t };
@@ -1,4 +1,4 @@
1
- import { u as PAGE, v as isKoffiAvailable$1 } from "./Win32API-Bc0QnQsN.mjs";
1
+ import { u as PAGE, v as isKoffiAvailable$1 } from "./Win32API-CePkipZY.mjs";
2
2
  //#region src/native/NativeMemoryManager.utils.ts
3
3
  function isKoffiAvailable() {
4
4
  return isKoffiAvailable$1();
@@ -1,5 +1,5 @@
1
- import { t as logger } from "./logger-BmWzC2lM.mjs";
2
- import { a as GetModuleFileNameEx, b as openProcessForMemory, d as ReadProcessMemory, i as GetModuleBaseName, n as EnumProcessModules, s as GetModuleInformation, t as CloseHandle } from "./Win32API-Bc0QnQsN.mjs";
1
+ import { t as logger } from "./logger-Dh_xb7_2.mjs";
2
+ import { a as GetModuleFileNameEx, b as openProcessForMemory, d as ReadProcessMemory, i as GetModuleBaseName, n as EnumProcessModules, s as GetModuleInformation, t as CloseHandle } from "./Win32API-CePkipZY.mjs";
3
3
  import { promises } from "node:fs";
4
4
  //#region src/native/PEAnalyzer.types.ts
5
5
  /** PE section characteristic flags */