@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,645 @@
1
+ import { dr as UNIDBG_TIMEOUT_MS } from "./constants-B0OANIBL.mjs";
2
+ import { a as invokePlugin, c as FridaSession, i as getAvailablePlugins, n as UnidbgRunner, o as HookCodeGenerator, r as HookGenerator, s as GhidraAnalyzer } from "./binary-instrument-CXfpx6fT.mjs";
3
+ import { access } from "node:fs/promises";
4
+ import { execFile } from "node:child_process";
5
+ //#region src/server/domains/binary-instrument/handlers/shared.ts
6
+ /**
7
+ * Shared types and helpers for binary-instrument sub-handlers.
8
+ */
9
+ const UNIDBG_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
10
+ function textResponse(text) {
11
+ return { content: [{
12
+ type: "text",
13
+ text
14
+ }] };
15
+ }
16
+ function jsonResponse(payload) {
17
+ return textResponse(JSON.stringify(payload));
18
+ }
19
+ function readRequiredString(args, key) {
20
+ const value = args[key];
21
+ if (typeof value !== "string" || value.trim().length === 0) throw new Error(`${key} is required`);
22
+ return value.trim();
23
+ }
24
+ function readOptionalString(args, key) {
25
+ const value = args[key];
26
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
27
+ }
28
+ function readOptionalNumber(args, key) {
29
+ const value = args[key];
30
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
31
+ }
32
+ function readStringArray(args, key) {
33
+ const value = args[key];
34
+ if (!Array.isArray(value)) return [];
35
+ return value.filter((entry) => typeof entry === "string" && entry.length > 0);
36
+ }
37
+ function isRecord(value) {
38
+ return typeof value === "object" && value !== null;
39
+ }
40
+ function isServerContext(value) {
41
+ return isRecord(value) && value["extensionPluginsById"] instanceof Map && value["extensionPluginRuntimeById"] instanceof Map;
42
+ }
43
+ function hasInstalledLegacyPlugin(context, pluginId) {
44
+ if (!context) return void 0;
45
+ const installed = context.extensionPluginsById;
46
+ if (!(installed instanceof Map)) return void 0;
47
+ return installed.has(pluginId);
48
+ }
49
+ async function invokeLegacyPlugin(context, pluginId, toolName, args) {
50
+ if (!context || hasInstalledLegacyPlugin(context, pluginId) === false) return textResponse(`Plugin ${pluginId.replaceAll("_", "-")} is not installed`);
51
+ const result = await invokePlugin(context, {
52
+ pluginId,
53
+ toolName,
54
+ args
55
+ });
56
+ if (result.success) return jsonResponse(result);
57
+ return textResponse(result.error ?? "Plugin invocation failed");
58
+ }
59
+ function readHookOptions(args, key) {
60
+ const raw = args[key];
61
+ if (!isRecord(raw)) return void 0;
62
+ const options = {};
63
+ const includeArgs = raw["includeArgs"];
64
+ const includeRetAddr = raw["includeRetAddr"];
65
+ if (typeof includeArgs === "boolean") options.includeArgs = includeArgs;
66
+ if (typeof includeRetAddr === "boolean") options.includeRetAddr = includeRetAddr;
67
+ return options;
68
+ }
69
+ function parsePid(target) {
70
+ if (!/^\d+$/.test(target)) return null;
71
+ const parsed = Number.parseInt(target, 10);
72
+ return Number.isNaN(parsed) ? null : parsed;
73
+ }
74
+ function makeMockId(value) {
75
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24);
76
+ }
77
+ async function getUnidbgAvailability() {
78
+ const jarPath = process.env["UNIDBG_JAR"] ?? "";
79
+ if (jarPath.length === 0) return {
80
+ available: false,
81
+ reason: "UNIDBG_JAR is not configured",
82
+ command: "java",
83
+ jarPath: ""
84
+ };
85
+ try {
86
+ await access(jarPath);
87
+ } catch {
88
+ return {
89
+ available: false,
90
+ reason: `UNIDBG_JAR not found: ${jarPath}`,
91
+ command: "java",
92
+ jarPath
93
+ };
94
+ }
95
+ return {
96
+ available: true,
97
+ reason: "",
98
+ command: "java",
99
+ jarPath
100
+ };
101
+ }
102
+ function execFileUtf8(file, args, timeoutMs) {
103
+ return new Promise((resolve, reject) => {
104
+ execFile(file, args, {
105
+ timeout: timeoutMs,
106
+ windowsHide: true,
107
+ maxBuffer: UNIDBG_MAX_BUFFER_BYTES,
108
+ encoding: "utf8"
109
+ }, (error, stdout, stderr) => {
110
+ if (error) {
111
+ reject(error);
112
+ return;
113
+ }
114
+ resolve({
115
+ stdout: typeof stdout === "string" ? stdout : "",
116
+ stderr: typeof stderr === "string" ? stderr : ""
117
+ });
118
+ });
119
+ });
120
+ }
121
+ function isGhidraAnalysisOutput(value) {
122
+ return isRecord(value) && Array.isArray(value["functions"]) && Array.isArray(value["imports"]);
123
+ }
124
+ function toHookTemplates(value) {
125
+ const templates = [];
126
+ for (const entry of value) {
127
+ if (!isRecord(entry)) continue;
128
+ const functionName = readStringRecordField(entry, "functionName");
129
+ const hookCode = readStringRecordField(entry, "hookCode");
130
+ const description = readStringRecordField(entry, "description");
131
+ const parameters = parseHookParameters(entry["parameters"]);
132
+ if (!functionName || !hookCode || !description) continue;
133
+ templates.push({
134
+ functionName,
135
+ hookCode,
136
+ description,
137
+ parameters
138
+ });
139
+ }
140
+ return templates;
141
+ }
142
+ function readStringRecordField(record, key) {
143
+ const value = record[key];
144
+ return typeof value === "string" ? value : void 0;
145
+ }
146
+ function parseHookParameters(value) {
147
+ if (!Array.isArray(value)) return [];
148
+ const parameters = [];
149
+ for (const entry of value) {
150
+ if (!isRecord(entry)) continue;
151
+ const name = readStringRecordField(entry, "name");
152
+ const type = readStringRecordField(entry, "type");
153
+ const description = readStringRecordField(entry, "description");
154
+ if (name && type && description) parameters.push({
155
+ name,
156
+ type,
157
+ description
158
+ });
159
+ }
160
+ return parameters;
161
+ }
162
+ //#endregion
163
+ //#region src/server/domains/binary-instrument/handlers/frida-handlers.ts
164
+ /**
165
+ * Frida sub-handler — attach, runScript, detach, listSessions, generateScript,
166
+ * enumerateModules, enumerateFunctions, findSymbols.
167
+ */
168
+ var FridaHandlers = class {
169
+ state;
170
+ constructor(state) {
171
+ this.state = state;
172
+ }
173
+ async handleFridaAttach(args) {
174
+ const legacyPid = readOptionalString(args, "pid");
175
+ if (!readOptionalString(args, "target") && legacyPid) return invokeLegacyPlugin(this.state.context, "plugin_frida_bridge", "frida_attach", args);
176
+ const target = readRequiredString(args, "target");
177
+ const frida = this.getFridaSession();
178
+ const availability = await frida.getAvailability();
179
+ if (!availability.available) {
180
+ const sessionId = `mock-frida-${makeMockId(target)}`;
181
+ return jsonResponse({
182
+ available: false,
183
+ target,
184
+ sessionId,
185
+ reason: availability.reason ?? "Frida CLI is not available",
186
+ sessions: [{
187
+ id: sessionId,
188
+ target,
189
+ pid: parsePid(target),
190
+ status: "unavailable"
191
+ }]
192
+ });
193
+ }
194
+ const sessionId = await frida.attach(target);
195
+ this.state.context?.eventBus.emit("frida:attached", {
196
+ target,
197
+ sessionId,
198
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
199
+ });
200
+ return jsonResponse({
201
+ available: true,
202
+ target,
203
+ sessionId,
204
+ sessions: frida.listSessions()
205
+ });
206
+ }
207
+ async handleFridaEnumerateModules(args) {
208
+ const sessionId = readRequiredString(args, "sessionId");
209
+ const frida = this.getFridaSession();
210
+ const availability = await frida.getAvailability();
211
+ if (!availability.available) return jsonResponse({
212
+ available: false,
213
+ sessionId,
214
+ reason: availability.reason ?? "Frida CLI is not available",
215
+ modules: [{
216
+ name: "mock-module",
217
+ base: "0x0",
218
+ size: 0,
219
+ path: "<unavailable>"
220
+ }]
221
+ });
222
+ if (!frida.useSession(sessionId)) return jsonResponse({
223
+ available: false,
224
+ sessionId,
225
+ reason: `Unknown Frida session: ${sessionId}`,
226
+ modules: []
227
+ });
228
+ return jsonResponse({
229
+ available: true,
230
+ sessionId,
231
+ modules: await frida.enumerateModules()
232
+ });
233
+ }
234
+ async handleFridaRunScript(args) {
235
+ const sessionId = readOptionalString(args, "sessionId");
236
+ if (!sessionId) return textResponse("Missing required string argument: sessionId");
237
+ const script = readRequiredString(args, "script");
238
+ const frida = this.getFridaSession();
239
+ const availability = await frida.getAvailability();
240
+ if (!availability.available) return {
241
+ available: false,
242
+ sessionId,
243
+ reason: availability.reason ?? "Frida CLI is not available",
244
+ execution: {
245
+ output: "",
246
+ error: "Frida unavailable"
247
+ }
248
+ };
249
+ if (!frida.useSession(sessionId)) return {
250
+ available: false,
251
+ sessionId,
252
+ reason: `Unknown Frida session: ${sessionId}`,
253
+ execution: {
254
+ output: "",
255
+ error: "Unknown session"
256
+ }
257
+ };
258
+ return {
259
+ available: true,
260
+ sessionId,
261
+ execution: await frida.executeScript(script)
262
+ };
263
+ }
264
+ async handleFridaDetach(args) {
265
+ const sessionId = readOptionalString(args, "sessionId");
266
+ if (!sessionId) return textResponse("Missing required string argument: sessionId");
267
+ const frida = this.getFridaSession();
268
+ if ((await frida.getAvailability()).available && frida.hasSession(sessionId)) {
269
+ frida.useSession(sessionId);
270
+ await frida.detach();
271
+ return jsonResponse({
272
+ success: true,
273
+ sessionId,
274
+ detached: true
275
+ });
276
+ }
277
+ return invokeLegacyPlugin(this.state.context, "plugin_frida_bridge", "frida_detach", args);
278
+ }
279
+ async handleFridaListSessions(_args) {
280
+ if (hasInstalledLegacyPlugin(this.state.context, "plugin_frida_bridge") === false) return textResponse("Plugin plugin-frida-bridge is not installed");
281
+ const frida = this.getFridaSession();
282
+ if ((await frida.getAvailability()).available) {
283
+ const sessions = frida.listSessions();
284
+ return jsonResponse({
285
+ success: true,
286
+ sessions,
287
+ count: sessions.length
288
+ });
289
+ }
290
+ return invokeLegacyPlugin(this.state.context, "plugin_frida_bridge", "frida_list_sessions", _args);
291
+ }
292
+ async handleFridaGenerateScript(args) {
293
+ if (hasInstalledLegacyPlugin(this.state.context, "plugin_frida_bridge") === false) return textResponse("Plugin plugin-frida-bridge is not installed");
294
+ const target = readOptionalString(args, "target") ?? "unknown";
295
+ const template = readOptionalString(args, "template") ?? "trace";
296
+ const functionName = readOptionalString(args, "functionName") ?? "target_function";
297
+ const templates = [{
298
+ functionName,
299
+ hookCode: `console.log('[${template}] ${functionName} called');`,
300
+ description: `${template} hook for ${functionName}`,
301
+ parameters: []
302
+ }];
303
+ return jsonResponse({
304
+ success: true,
305
+ target,
306
+ template,
307
+ functionName,
308
+ script: this.state.hookCodeGenerator.exportScript(templates, "frida")
309
+ });
310
+ }
311
+ async handleFridaEnumerateFunctions(args) {
312
+ const sessionId = readRequiredString(args, "sessionId");
313
+ const moduleName = readRequiredString(args, "moduleName");
314
+ const frida = this.getFridaSession();
315
+ const availability = await frida.getAvailability();
316
+ if (!availability.available) return {
317
+ available: false,
318
+ sessionId,
319
+ moduleName,
320
+ reason: availability.reason ?? "Frida CLI is not available",
321
+ functions: []
322
+ };
323
+ if (!frida.useSession(sessionId)) return {
324
+ available: false,
325
+ sessionId,
326
+ reason: `Unknown Frida session: ${sessionId}`,
327
+ functions: []
328
+ };
329
+ const functions = await frida.enumerateFunctions(moduleName);
330
+ return {
331
+ available: true,
332
+ sessionId,
333
+ moduleName,
334
+ functions,
335
+ count: functions.length
336
+ };
337
+ }
338
+ async handleFridaFindSymbols(args) {
339
+ const sessionId = readRequiredString(args, "sessionId");
340
+ const pattern = readRequiredString(args, "pattern");
341
+ const frida = this.getFridaSession();
342
+ const availability = await frida.getAvailability();
343
+ if (!availability.available) return {
344
+ available: false,
345
+ sessionId,
346
+ pattern,
347
+ reason: availability.reason ?? "Frida CLI is not available",
348
+ symbols: []
349
+ };
350
+ if (!frida.useSession(sessionId)) return {
351
+ available: false,
352
+ sessionId,
353
+ reason: `Unknown Frida session: ${sessionId}`,
354
+ symbols: []
355
+ };
356
+ const symbols = await frida.findSymbols(pattern);
357
+ return {
358
+ available: true,
359
+ sessionId,
360
+ pattern,
361
+ symbols,
362
+ count: symbols.length
363
+ };
364
+ }
365
+ getFridaSession() {
366
+ if (!this.state.fridaSession) this.state.fridaSession = new FridaSession();
367
+ return this.state.fridaSession;
368
+ }
369
+ };
370
+ //#endregion
371
+ //#region src/server/domains/binary-instrument/handlers/analysis-handlers.ts
372
+ /**
373
+ * Static analysis sub-handler — Ghidra, IDA, JADX, Unidbg, hooks, plugins.
374
+ */
375
+ var AnalysisHandlers = class {
376
+ state;
377
+ constructor(state) {
378
+ this.state = state;
379
+ }
380
+ async handleGhidraAnalyze(args) {
381
+ const legacyTargetPath = readOptionalString(args, "targetPath");
382
+ if (!readOptionalString(args, "binaryPath") && legacyTargetPath) return invokeLegacyPlugin(this.state.context, "plugin_ghidra_bridge", "ghidra_analyze", args);
383
+ const binaryPath = readRequiredString(args, "binaryPath");
384
+ const timeout = readOptionalNumber(args, "timeout");
385
+ const ghidra = this.getGhidraAnalyzer();
386
+ const availability = await ghidra.getAvailability();
387
+ const analysis = await ghidra.analyze(binaryPath, timeout !== void 0 ? { timeout } : void 0);
388
+ if (!availability.available) return {
389
+ available: false,
390
+ binaryPath,
391
+ reason: availability.reason ?? "Ghidra analyzeHeadless is not available",
392
+ analysis
393
+ };
394
+ return {
395
+ available: true,
396
+ binaryPath,
397
+ analysis
398
+ };
399
+ }
400
+ async handleGhidraDecompile(args) {
401
+ return invokeLegacyPlugin(this.state.context, "plugin_ghidra_bridge", "ghidra_decompile", args);
402
+ }
403
+ async handleIdaDecompile(args) {
404
+ return invokeLegacyPlugin(this.state.context, "plugin_ida_bridge", "ida_decompile", args);
405
+ }
406
+ async handleJadxDecompile(args) {
407
+ return invokeLegacyPlugin(this.state.context, "plugin_jadx_bridge", "jadx_decompile", args);
408
+ }
409
+ async handleGenerateHooks(args) {
410
+ const legacyGhidraOutput = readOptionalString(args, "ghidraOutput");
411
+ if (legacyGhidraOutput) return this.handleLegacyGenerateHooks(legacyGhidraOutput);
412
+ const legacyGhidraOutputObj = args["ghidraOutput"];
413
+ if (isRecord(legacyGhidraOutputObj)) return this.handleLegacyGenerateHooks(JSON.stringify(legacyGhidraOutputObj));
414
+ const symbols = readStringArray(args, "symbols");
415
+ if (symbols.length === 0) return textResponse("symbols or ghidraOutput is required");
416
+ const options = readHookOptions(args, "options");
417
+ const script = this.getHookGenerator().generateFridaHookScript(symbols, options);
418
+ return jsonResponse({
419
+ available: true,
420
+ symbolCount: symbols.length,
421
+ script
422
+ });
423
+ }
424
+ async handleExportHookScript(args) {
425
+ const rawTemplates = readOptionalString(args, "hookTemplates");
426
+ if (!rawTemplates) {
427
+ const generated = this.state.hookCodeGenerator.exportScript([], "frida");
428
+ return jsonResponse({
429
+ format: "frida",
430
+ hookCount: 0,
431
+ script: generated.includes("Java.perform") ? generated : `Java.perform(function() {\n${generated}\n});`
432
+ });
433
+ }
434
+ try {
435
+ const parsed = JSON.parse(rawTemplates);
436
+ if (!Array.isArray(parsed)) return textResponse("Invalid JSON");
437
+ const templates = toHookTemplates(parsed);
438
+ const script = this.state.hookCodeGenerator.exportScript(templates, "frida");
439
+ return jsonResponse({
440
+ format: "frida",
441
+ hookCount: templates.length,
442
+ script
443
+ });
444
+ } catch {
445
+ return textResponse("Invalid JSON");
446
+ }
447
+ }
448
+ async handleUnidbgEmulate(args) {
449
+ const binaryPath = readRequiredString(args, "binaryPath");
450
+ const functionName = readRequiredString(args, "functionName");
451
+ const invokeArgs = readStringArray(args, "args");
452
+ const availability = await getUnidbgAvailability();
453
+ if (!availability.available) return {
454
+ available: false,
455
+ binaryPath,
456
+ functionName,
457
+ args: invokeArgs,
458
+ reason: availability.reason,
459
+ result: {
460
+ returnValue: "0x0",
461
+ stdout: "",
462
+ stderr: "",
463
+ trace: ["mock-unidbg-unavailable"]
464
+ }
465
+ };
466
+ const result = await execFileUtf8(availability.command, [
467
+ "-jar",
468
+ availability.jarPath,
469
+ binaryPath,
470
+ functionName,
471
+ ...invokeArgs
472
+ ], UNIDBG_TIMEOUT_MS);
473
+ return {
474
+ available: true,
475
+ binaryPath,
476
+ functionName,
477
+ args: invokeArgs,
478
+ result: {
479
+ returnValue: "0x0",
480
+ stdout: result.stdout.trim(),
481
+ stderr: result.stderr.trim(),
482
+ trace: []
483
+ }
484
+ };
485
+ }
486
+ async handleUnidbgLaunch(args) {
487
+ const soPath = readOptionalString(args, "soPath");
488
+ if (!soPath) return textResponse("Missing required string argument: soPath");
489
+ const arch = readOptionalString(args, "arch") ?? "arm";
490
+ try {
491
+ const result = await this.state.unidbgRunner.launch(soPath, arch);
492
+ return {
493
+ available: true,
494
+ sessionId: result.sessionId,
495
+ soPath: result.soPath,
496
+ arch: result.arch,
497
+ sessions: this.state.unidbgRunner.listSessions()
498
+ };
499
+ } catch (error) {
500
+ return {
501
+ available: false,
502
+ soPath,
503
+ arch,
504
+ reason: error instanceof Error ? error.message : String(error),
505
+ sessions: this.state.unidbgRunner.listSessions()
506
+ };
507
+ }
508
+ }
509
+ async handleUnidbgCall(args) {
510
+ const sessionId = readOptionalString(args, "sessionId");
511
+ if (!sessionId) return textResponse("Missing required string argument: sessionId");
512
+ const functionName = readOptionalString(args, "functionName");
513
+ if (!functionName) return textResponse("Missing required string argument: functionName");
514
+ const callArgs = isRecord(args["args"]) ? args["args"] : {};
515
+ try {
516
+ return jsonResponse(await this.state.unidbgRunner.callFunction(sessionId, functionName, callArgs));
517
+ } catch (error) {
518
+ const message = error instanceof Error ? error.message : String(error);
519
+ return textResponse(message.startsWith("No unidbg session found") ? `${message} (not found)` : message);
520
+ }
521
+ }
522
+ async handleUnidbgTrace(args) {
523
+ const sessionId = readOptionalString(args, "sessionId");
524
+ if (!sessionId) return textResponse("Missing required string argument: sessionId");
525
+ try {
526
+ return jsonResponse(await this.state.unidbgRunner.trace(sessionId));
527
+ } catch (error) {
528
+ const message = error instanceof Error ? error.message : String(error);
529
+ return textResponse(message.startsWith("No unidbg session found") ? `${message} (not found)` : message);
530
+ }
531
+ }
532
+ async handleGetAvailablePlugins(_args) {
533
+ const plugins = this.state.context ? getAvailablePlugins(this.state.context) : [];
534
+ return jsonResponse({
535
+ plugins,
536
+ count: plugins.length
537
+ });
538
+ }
539
+ getGhidraAnalyzer() {
540
+ if (!this.state.ghidra) this.state.ghidra = new GhidraAnalyzer();
541
+ return this.state.ghidra;
542
+ }
543
+ getHookGenerator() {
544
+ if (!this.state.hookGen) this.state.hookGen = new HookGenerator();
545
+ return this.state.hookGen;
546
+ }
547
+ handleLegacyGenerateHooks(ghidraOutput) {
548
+ let parsed;
549
+ try {
550
+ parsed = JSON.parse(ghidraOutput);
551
+ } catch {
552
+ return textResponse("Invalid JSON");
553
+ }
554
+ if (!isGhidraAnalysisOutput(parsed)) return textResponse("ghidraOutput is required");
555
+ const hooks = this.state.hookCodeGenerator.generateHooks(parsed);
556
+ return jsonResponse({
557
+ count: hooks.length,
558
+ hooks
559
+ });
560
+ }
561
+ };
562
+ //#endregion
563
+ //#region src/server/domains/binary-instrument/handlers.impl.core.ts
564
+ /**
565
+ * BinaryInstrument domain — composition facade.
566
+ *
567
+ * Frida operations in ./handlers/frida-handlers.ts.
568
+ * Analysis/unidbg/hook operations in ./handlers/analysis-handlers.ts.
569
+ */
570
+ var BinaryInstrumentHandlers = class {
571
+ state;
572
+ frida;
573
+ analysis;
574
+ constructor(first, second, third) {
575
+ this.state = {
576
+ hookCodeGenerator: new HookCodeGenerator(),
577
+ unidbgRunner: new UnidbgRunner()
578
+ };
579
+ if (first instanceof FridaSession) this.state.fridaSession = first;
580
+ else if (isServerContext(first)) this.state.context = first;
581
+ if (second) this.state.ghidra = second;
582
+ if (third) this.state.hookGen = third;
583
+ this.frida = new FridaHandlers(this.state);
584
+ this.analysis = new AnalysisHandlers(this.state);
585
+ }
586
+ handleFridaAttach(args) {
587
+ return this.frida.handleFridaAttach(args);
588
+ }
589
+ handleFridaEnumerateModules(args) {
590
+ return this.frida.handleFridaEnumerateModules(args);
591
+ }
592
+ handleFridaRunScript(args) {
593
+ return this.frida.handleFridaRunScript(args);
594
+ }
595
+ handleFridaDetach(args) {
596
+ return this.frida.handleFridaDetach(args);
597
+ }
598
+ handleFridaListSessions(args) {
599
+ return this.frida.handleFridaListSessions(args);
600
+ }
601
+ handleFridaGenerateScript(args) {
602
+ return this.frida.handleFridaGenerateScript(args);
603
+ }
604
+ handleFridaEnumerateFunctions(args) {
605
+ return this.frida.handleFridaEnumerateFunctions(args);
606
+ }
607
+ handleFridaFindSymbols(args) {
608
+ return this.frida.handleFridaFindSymbols(args);
609
+ }
610
+ handleGhidraAnalyze(args) {
611
+ return this.analysis.handleGhidraAnalyze(args);
612
+ }
613
+ handleGhidraDecompile(args) {
614
+ return this.analysis.handleGhidraDecompile(args);
615
+ }
616
+ handleIdaDecompile(args) {
617
+ return this.analysis.handleIdaDecompile(args);
618
+ }
619
+ handleJadxDecompile(args) {
620
+ return this.analysis.handleJadxDecompile(args);
621
+ }
622
+ handleGenerateHooks(args) {
623
+ return this.analysis.handleGenerateHooks(args);
624
+ }
625
+ handleExportHookScript(args) {
626
+ return this.analysis.handleExportHookScript(args);
627
+ }
628
+ handleUnidbgEmulate(args) {
629
+ return this.analysis.handleUnidbgEmulate(args);
630
+ }
631
+ handleUnidbgLaunch(args) {
632
+ return this.analysis.handleUnidbgLaunch(args);
633
+ }
634
+ handleUnidbgCall(args) {
635
+ return this.analysis.handleUnidbgCall(args);
636
+ }
637
+ handleUnidbgTrace(args) {
638
+ return this.analysis.handleUnidbgTrace(args);
639
+ }
640
+ handleGetAvailablePlugins(args) {
641
+ return this.analysis.handleGetAvailablePlugins(args);
642
+ }
643
+ };
644
+ //#endregion
645
+ export { BinaryInstrumentHandlers };