@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.
- package/README.md +36 -5
- package/README.zh.md +36 -5
- package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-BNk-EoBt.mjs} +3 -3
- package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-Cq8q01kp.mjs} +5 -5
- package/dist/ConsoleMonitor-CPVQW1Y-.mjs +2201 -0
- package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-BNPxu0RH.mjs} +1 -1
- package/dist/DetailedDataManager-BQQcxh64.mjs +217 -0
- package/dist/EventBus-DgPmwpeu.mjs +141 -0
- package/dist/EvidenceGraphBridge-SFesNera.mjs +153 -0
- package/dist/{ExtensionManager-CZ6IveoV.mjs → ExtensionManager-CWYgw0YW.mjs} +13 -6
- package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-gzWtkKuf.mjs} +1 -1
- package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-B9gZCdFP.mjs} +3 -3
- package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-BLDH0dCv.mjs} +4 -4
- package/dist/HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs +639 -0
- package/dist/InstrumentationSession-CvPC7Jwy.mjs +244 -0
- package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CbVdCIJF.mjs} +3 -3
- package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-BsDZbLYm.mjs} +81 -78
- package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-Bcpml6II.mjs} +44 -18
- package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-dZtA1ZGn.mjs} +14 -53
- package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-B-FjA2mJ.mjs} +1 -1
- package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-D1lzJ_VG.mjs} +2 -2
- package/dist/PageController-Bqm2kZ_X.mjs +417 -0
- package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-BOhyVsjx.mjs} +4 -4
- package/dist/PrerequisiteError-Dl33Svkz.mjs +20 -0
- package/dist/ResponseBuilder-D3iFYx2N.mjs +143 -0
- package/dist/ReverseEvidenceGraph-Dlsk94LC.mjs +269 -0
- package/dist/ScriptManager-aHHq0X7U.mjs +3000 -0
- package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-CqdIFlQl.mjs} +2 -2
- package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-DhFaPvRO.mjs} +3 -3
- package/dist/ToolCatalog-C0JGZoOm.mjs +582 -0
- package/dist/ToolError-jh9whhMd.mjs +15 -0
- package/dist/ToolProbe-oC7aPrkv.mjs +45 -0
- package/dist/ToolRegistry-BjaF4oNz.mjs +131 -0
- package/dist/ToolRouter.policy-BWV67ZK-.mjs +304 -0
- package/dist/TraceRecorder-DgxyVbdQ.mjs +519 -0
- package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-CePkipZY.mjs} +1 -1
- package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-BvKs-gxc.mjs} +2 -2
- package/dist/WorkflowEngine-CuvkZtWu.mjs +598 -0
- package/dist/analysis-CL9uACt9.mjs +463 -0
- package/dist/antidebug-CqDTB_uk.mjs +1081 -0
- package/dist/artifactRetention-CFEprwPw.mjs +591 -0
- package/dist/artifacts-Bk2-_uPq.mjs +59 -0
- package/dist/betterSqlite3-0pqusHHH.mjs +74 -0
- package/dist/binary-instrument-CXfpx6fT.mjs +979 -0
- package/dist/bind-helpers-xFfRF-qm.mjs +22 -0
- package/dist/boringssl-inspector-BH2D3VKc.mjs +180 -0
- package/dist/browser-BpOr5PEx.mjs +4082 -0
- package/dist/concurrency-Bt0yv1kJ.mjs +41 -0
- package/dist/{constants-CCvsN80K.mjs → constants-B0OANIBL.mjs} +88 -46
- package/dist/coordination-qUbyF8KU.mjs +259 -0
- package/dist/debugger-gnKxRSN0.mjs +1271 -0
- package/dist/definitions-6M-eejaT.mjs +53 -0
- package/dist/definitions-B18eyf0B.mjs +18 -0
- package/dist/definitions-B3QdlrHv.mjs +34 -0
- package/dist/definitions-B4rAvHNZ.mjs +63 -0
- package/dist/definitions-BB_4jnmy.mjs +37 -0
- package/dist/definitions-BMfYXoNC.mjs +43 -0
- package/dist/definitions-Beid2EB3.mjs +27 -0
- package/dist/definitions-C1UvM5Iy.mjs +126 -0
- package/dist/definitions-CXEI7QC72.mjs +216 -0
- package/dist/definitions-C_4r7Fo-2.mjs +14 -0
- package/dist/definitions-CkFDALoa.mjs +26 -0
- package/dist/definitions-Cke7zEb8.mjs +94 -0
- package/dist/definitions-ClJLzsJQ.mjs +25 -0
- package/dist/definitions-Cq-zroAU.mjs +28 -0
- package/dist/definitions-Cy3Sl6gV.mjs +34 -0
- package/dist/definitions-D3VsGcvz.mjs +47 -0
- package/dist/definitions-DVGfrn7y.mjs +96 -0
- package/dist/definitions-LKpC3-nL.mjs +9 -0
- package/dist/definitions-bAhHQJq9.mjs +359 -0
- package/dist/encoding-Bvz5jLRv.mjs +1065 -0
- package/dist/evidence-graph-bridge-C_fv9PuC.mjs +135 -0
- package/dist/{factory-CibqTNC8.mjs → factory-DxlGh9Xf.mjs} +37 -52
- package/dist/graphql-DYWzJ29s.mjs +1026 -0
- package/dist/handlers-9sAbfIg-.mjs +2552 -0
- package/dist/handlers-Bl8zkwz1.mjs +2716 -0
- package/dist/handlers-C67ktuRN.mjs +710 -0
- package/dist/handlers-C87g8oCe.mjs +276 -0
- package/dist/handlers-CTsDAO6p.mjs +681 -0
- package/dist/handlers-Cgyg6c0U.mjs +645 -0
- package/dist/handlers-D6j6yka7.mjs +2124 -0
- package/dist/handlers-DdFzXLvF.mjs +446 -0
- package/dist/handlers-DeLOCd5m.mjs +799 -0
- package/dist/handlers-DlCJN4Td.mjs +757 -0
- package/dist/handlers-DxGIq15_2.mjs +917 -0
- package/dist/handlers-U6L4xhuF.mjs +585 -0
- package/dist/handlers-tB9Mp9ZK.mjs +84 -0
- package/dist/handlers-tiy7EIBp.mjs +572 -0
- package/dist/handlers.impl-DS0d9fUw.mjs +761 -0
- package/dist/hooks-CzCWByww.mjs +898 -0
- package/dist/index.mjs +384 -155
- package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
- package/dist/maintenance-P7ePRXQC.mjs +830 -0
- package/dist/manifest-2ToTpjv8.mjs +106 -0
- package/dist/manifest-3g71z6Bg.mjs +79 -0
- package/dist/manifest-82baTv4U.mjs +45 -0
- package/dist/manifest-B3QVVeBS.mjs +82 -0
- package/dist/manifest-BB2J8IMJ.mjs +149 -0
- package/dist/manifest-BKbgbSiY.mjs +60 -0
- package/dist/manifest-Bcf-TJzH.mjs +848 -0
- package/dist/manifest-BmtZzQiQ2.mjs +45 -0
- package/dist/manifest-Bnd7kqEY.mjs +55 -0
- package/dist/manifest-BqQX6OQC2.mjs +65 -0
- package/dist/manifest-BqrQ4Tpj.mjs +81 -0
- package/dist/manifest-Br4RPFt5.mjs +370 -0
- package/dist/manifest-C5qDjysN.mjs +107 -0
- package/dist/manifest-C9RT5nk32.mjs +34 -0
- package/dist/manifest-CAhOuvSl.mjs +204 -0
- package/dist/manifest-CBYWCUBJ.mjs +51 -0
- package/dist/manifest-CFADCRa1.mjs +37 -0
- package/dist/manifest-CQVhavRF.mjs +114 -0
- package/dist/manifest-CT7zZBV1.mjs +48 -0
- package/dist/manifest-CV12bcrF.mjs +121 -0
- package/dist/manifest-CXsRWjjI.mjs +224 -0
- package/dist/manifest-CZLUCfG02.mjs +95 -0
- package/dist/manifest-D6phHKFd.mjs +131 -0
- package/dist/manifest-DCyjf4n2.mjs +294 -0
- package/dist/manifest-DHsnKgP6.mjs +60 -0
- package/dist/manifest-Df_dliIe.mjs +55 -0
- package/dist/manifest-Dh8WBmEW.mjs +129 -0
- package/dist/manifest-DhKRAT8_.mjs +92 -0
- package/dist/manifest-DlpTj4ic2.mjs +193 -0
- package/dist/manifest-DrbmZcFl2.mjs +253 -0
- package/dist/manifest-DuwHjUa5.mjs +70 -0
- package/dist/manifest-DzwvxPJX.mjs +38 -0
- package/dist/manifest-NXctwWQq.mjs +68 -0
- package/dist/manifest-Sc_0JQ13.mjs +418 -0
- package/dist/manifest-gZ4s_UtG.mjs +96 -0
- package/dist/manifest-qSleDqdO.mjs +1023 -0
- package/dist/modules-C184v-S9.mjs +11365 -0
- package/dist/mojo-ipc-B_H61Afw.mjs +525 -0
- package/dist/network-671Cw6hV.mjs +3346 -0
- package/dist/{artifacts-BbdOMET5.mjs → outputPaths-B1uGmrWZ.mjs} +219 -212
- package/dist/parse-args-BlRjqlkL.mjs +39 -0
- package/dist/platform-WmNn8Sxb.mjs +2070 -0
- package/dist/process-QcbIy5Zq.mjs +1401 -0
- package/dist/proxy-DqNs0bAd.mjs +170 -0
- package/dist/registry-D-6e18lB.mjs +34 -0
- package/dist/response-BQVP-xUn.mjs +28 -0
- package/dist/server/plugin-api.mjs +2 -2
- package/dist/shared-state-board-DV-dpHFJ.mjs +586 -0
- package/dist/sourcemap-Dq8ez8vS.mjs +650 -0
- package/dist/ssrf-policy-ZaUfvhq7.mjs +166 -0
- package/dist/streaming-BUQ0VJsg.mjs +725 -0
- package/dist/tool-builder-DCbIC5Eo.mjs +186 -0
- package/dist/transform-CiYJfNX0.mjs +1007 -0
- package/dist/types-Bx92KJfT.mjs +4 -0
- package/dist/wasm-DQTnHDs4.mjs +531 -0
- package/dist/workflow-f3xJOcjx.mjs +725 -0
- package/package.json +48 -78
- package/dist/ExtensionManager-DqUSOamB.mjs +0 -2
- package/dist/ToolCatalog-CnwmMIw3.mjs +0 -61483
- package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-CDe5WPSV.mjs} +0 -0
- package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-Bo4T3bz8.mjs} +0 -0
- package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-CwVLVdDM.mjs} +0 -0
- package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-DVkj9kpI.mjs} +0 -0
- package/dist/{types-BBjOqye-.mjs → types-CPhOReNX.mjs} +1 -1
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { n as __require } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
+
import { Ht as MOJO_MONITOR_TIMEOUT_MS } from "./constants-B0OANIBL.mjs";
|
|
3
|
+
import { a as argString, r as argNumber } from "./parse-args-BlRjqlkL.mjs";
|
|
4
|
+
import "./manifest-B3QVVeBS.mjs";
|
|
5
|
+
import { execFile, spawn } from "node:child_process";
|
|
6
|
+
//#region src/modules/mojo-ipc/MojoMonitor.ts
|
|
7
|
+
function getDefaultInterfaces() {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "blink.mojom.WidgetHost",
|
|
11
|
+
version: 1,
|
|
12
|
+
pendingMessages: 0
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "content.mojom.FrameHost",
|
|
16
|
+
version: 2,
|
|
17
|
+
pendingMessages: 0
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "network.mojom.URLLoaderFactory",
|
|
21
|
+
version: 3,
|
|
22
|
+
pendingMessages: 0
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
function detectFridaNpmPackage() {
|
|
27
|
+
try {
|
|
28
|
+
__require.resolve("frida");
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function probeFridaCli() {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const child = spawn("frida", ["--version"], {
|
|
37
|
+
timeout: MOJO_MONITOR_TIMEOUT_MS,
|
|
38
|
+
windowsHide: true
|
|
39
|
+
});
|
|
40
|
+
let stdout = "";
|
|
41
|
+
child.stdout?.on("data", (chunk) => {
|
|
42
|
+
stdout += chunk.toString();
|
|
43
|
+
});
|
|
44
|
+
child.on("close", (code) => {
|
|
45
|
+
if (code === 0 && stdout.trim().length > 0) {
|
|
46
|
+
resolve("frida");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
resolve(null);
|
|
50
|
+
});
|
|
51
|
+
child.on("error", () => {
|
|
52
|
+
resolve(null);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function detectAvailability() {
|
|
57
|
+
const flag = process.env["JSHOOK_ENABLE_MOJO_IPC"];
|
|
58
|
+
const fridaNpm = detectFridaNpmPackage();
|
|
59
|
+
const fridaCli = await probeFridaCli();
|
|
60
|
+
const fridaAvailable = fridaNpm || fridaCli !== null;
|
|
61
|
+
if (flag === "0" || flag === "false") return {
|
|
62
|
+
available: false,
|
|
63
|
+
fridaAvailable,
|
|
64
|
+
fridaCliAvailable: fridaCli !== null,
|
|
65
|
+
reason: "Mojo IPC disabled by JSHOOK_ENABLE_MOJO_IPC=0."
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
available: fridaAvailable,
|
|
69
|
+
fridaAvailable,
|
|
70
|
+
fridaCliAvailable: fridaCli !== null,
|
|
71
|
+
reason: fridaAvailable ? void 0 : "Mojo IPC backend is not connected. Install Frida for real IPC monitoring: https://frida.re/docs/installation/"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function matchesFilter(message, filter) {
|
|
75
|
+
if (filter.interfaceName && message.interfaceName !== filter.interfaceName) return false;
|
|
76
|
+
if (filter.messageType && message.messageType !== filter.messageType) return false;
|
|
77
|
+
if (typeof filter.pid === "number" && message.sourcePid !== filter.pid && message.targetPid !== filter.pid) return false;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
function buildFridaScript() {
|
|
81
|
+
return `
|
|
82
|
+
const messages = [];
|
|
83
|
+
recv('message', () => {});
|
|
84
|
+
rpc.exports = {
|
|
85
|
+
flush() {
|
|
86
|
+
return messages;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
var MojoMonitor = class {
|
|
92
|
+
active = false;
|
|
93
|
+
simulationMode = false;
|
|
94
|
+
deviceId;
|
|
95
|
+
messages = [];
|
|
96
|
+
interfaces = /* @__PURE__ */ new Map();
|
|
97
|
+
availability = {
|
|
98
|
+
available: false,
|
|
99
|
+
fridaAvailable: false,
|
|
100
|
+
fridaCliAvailable: false,
|
|
101
|
+
reason: "Not yet initialized. Call start() to probe availability."
|
|
102
|
+
};
|
|
103
|
+
constructor() {
|
|
104
|
+
for (const item of getDefaultInterfaces()) this.interfaces.set(item.name, { ...item });
|
|
105
|
+
}
|
|
106
|
+
isAvailable() {
|
|
107
|
+
return this.availability.available;
|
|
108
|
+
}
|
|
109
|
+
getUnavailableReason() {
|
|
110
|
+
return this.availability.reason;
|
|
111
|
+
}
|
|
112
|
+
isSimulationMode() {
|
|
113
|
+
return this.simulationMode;
|
|
114
|
+
}
|
|
115
|
+
setSimulationMode(enabled) {
|
|
116
|
+
this.simulationMode = enabled;
|
|
117
|
+
}
|
|
118
|
+
isActive() {
|
|
119
|
+
return this.active;
|
|
120
|
+
}
|
|
121
|
+
getDeviceId() {
|
|
122
|
+
return this.deviceId;
|
|
123
|
+
}
|
|
124
|
+
async start(deviceId) {
|
|
125
|
+
this.deviceId = deviceId;
|
|
126
|
+
this.availability = await detectAvailability();
|
|
127
|
+
if (!this.availability.available) {
|
|
128
|
+
this.active = false;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.active = true;
|
|
132
|
+
this.resetPendingCounts();
|
|
133
|
+
if (this.availability.fridaCliAvailable) await this.captureWithFrida(deviceId);
|
|
134
|
+
else this.simulationMode = true;
|
|
135
|
+
}
|
|
136
|
+
async stop() {
|
|
137
|
+
this.active = false;
|
|
138
|
+
this.deviceId = void 0;
|
|
139
|
+
this.messages.length = 0;
|
|
140
|
+
this.resetPendingCounts();
|
|
141
|
+
}
|
|
142
|
+
async captureMessages(filter = {}) {
|
|
143
|
+
if (!this.active) return [];
|
|
144
|
+
const captured = [];
|
|
145
|
+
const remaining = [];
|
|
146
|
+
for (const message of this.messages) if (matchesFilter(message, filter)) captured.push({ ...message });
|
|
147
|
+
else remaining.push(message);
|
|
148
|
+
this.messages.length = 0;
|
|
149
|
+
this.messages.push(...remaining);
|
|
150
|
+
this.recomputePendingCounts();
|
|
151
|
+
return captured;
|
|
152
|
+
}
|
|
153
|
+
async listInterfaces() {
|
|
154
|
+
return [...this.interfaces.values()].map((item) => ({
|
|
155
|
+
name: item.name,
|
|
156
|
+
version: item.version,
|
|
157
|
+
pendingMessages: item.pendingMessages
|
|
158
|
+
})).toSorted((left, right) => left.name.localeCompare(right.name));
|
|
159
|
+
}
|
|
160
|
+
async getMessages(options) {
|
|
161
|
+
if (!this.active) return {
|
|
162
|
+
messages: [],
|
|
163
|
+
totalAvailable: 0,
|
|
164
|
+
filtered: false,
|
|
165
|
+
_simulation: this.simulationMode
|
|
166
|
+
};
|
|
167
|
+
const filter = {};
|
|
168
|
+
if (options?.interfaceName) filter.interfaceName = options.interfaceName;
|
|
169
|
+
const allMessages = await this.captureMessages(filter);
|
|
170
|
+
const limit = options?.limit ?? 100;
|
|
171
|
+
return {
|
|
172
|
+
messages: allMessages.slice(0, limit),
|
|
173
|
+
totalAvailable: allMessages.length,
|
|
174
|
+
filtered: !!options?.interfaceName,
|
|
175
|
+
_simulation: this.simulationMode
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
recordMessage(message, version = 1) {
|
|
179
|
+
if (!this.active) return;
|
|
180
|
+
this.messages.push({ ...message });
|
|
181
|
+
const existing = this.interfaces.get(message.interfaceName);
|
|
182
|
+
if (existing) {
|
|
183
|
+
existing.pendingMessages += 1;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.interfaces.set(message.interfaceName, {
|
|
187
|
+
name: message.interfaceName,
|
|
188
|
+
version,
|
|
189
|
+
pendingMessages: 1
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async captureWithFrida(deviceId) {
|
|
193
|
+
const targetProcess = deviceId ?? "chrome";
|
|
194
|
+
const script = buildFridaScript();
|
|
195
|
+
await new Promise((resolve, reject) => {
|
|
196
|
+
execFile("frida", [
|
|
197
|
+
"-q",
|
|
198
|
+
"-n",
|
|
199
|
+
targetProcess,
|
|
200
|
+
"-l",
|
|
201
|
+
"-",
|
|
202
|
+
"--runtime=v8"
|
|
203
|
+
], {
|
|
204
|
+
timeout: MOJO_MONITOR_TIMEOUT_MS,
|
|
205
|
+
windowsHide: true
|
|
206
|
+
}, (error) => {
|
|
207
|
+
if (error) {
|
|
208
|
+
this.simulationMode = true;
|
|
209
|
+
reject(error);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
this.simulationMode = false;
|
|
213
|
+
resolve();
|
|
214
|
+
}).stdin?.end(script);
|
|
215
|
+
}).catch(() => {
|
|
216
|
+
this.simulationMode = true;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
recomputePendingCounts() {
|
|
220
|
+
this.resetPendingCounts();
|
|
221
|
+
for (const message of this.messages) {
|
|
222
|
+
const item = this.interfaces.get(message.interfaceName);
|
|
223
|
+
if (item) item.pendingMessages += 1;
|
|
224
|
+
else this.interfaces.set(message.interfaceName, {
|
|
225
|
+
name: message.interfaceName,
|
|
226
|
+
version: 1,
|
|
227
|
+
pendingMessages: 1
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
resetPendingCounts() {
|
|
232
|
+
for (const item of this.interfaces.values()) item.pendingMessages = 0;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/modules/mojo-ipc/MojoDecoder.ts
|
|
237
|
+
function isRecord(value) {
|
|
238
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
239
|
+
}
|
|
240
|
+
const FIELD_TYPE_BOOL = 1;
|
|
241
|
+
const FIELD_TYPE_INT32 = 6;
|
|
242
|
+
const FIELD_TYPE_UINT32 = 8;
|
|
243
|
+
const FIELD_TYPE_STRING = 12;
|
|
244
|
+
const FIELD_TYPE_HANDLE = 16;
|
|
245
|
+
function isHandleField(value) {
|
|
246
|
+
if (!isRecord(value)) return false;
|
|
247
|
+
return typeof value["handle"] === "number";
|
|
248
|
+
}
|
|
249
|
+
function normalizeHexInput(hex) {
|
|
250
|
+
const cleaned = hex.replace(/\s+/g, "");
|
|
251
|
+
if (cleaned.length % 2 === 0) return cleaned.toLowerCase();
|
|
252
|
+
return `0${cleaned.toLowerCase()}`;
|
|
253
|
+
}
|
|
254
|
+
var MojoDecoder = class {
|
|
255
|
+
decodePayload(hex, context) {
|
|
256
|
+
const raw = this.cleanHex(hex);
|
|
257
|
+
const bytes = Buffer.from(raw, "hex");
|
|
258
|
+
const version = this.readUInt8(bytes, 0);
|
|
259
|
+
const flags = this.readUInt8(bytes, 1);
|
|
260
|
+
const messageType = this.readUInt8(bytes, 2);
|
|
261
|
+
const numFields = this.readUInt8(bytes, 3);
|
|
262
|
+
const declaredHandles = this.readUInt16LE(bytes, 4);
|
|
263
|
+
const fields = {};
|
|
264
|
+
const summaryParts = [];
|
|
265
|
+
let cursor = 6;
|
|
266
|
+
let actualHandles = 0;
|
|
267
|
+
for (let index = 0; index < numFields; index += 1) {
|
|
268
|
+
if (cursor >= bytes.length) {
|
|
269
|
+
summaryParts.push("payload ended before all fields were decoded");
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
const typeCode = this.readUInt8(bytes, cursor);
|
|
273
|
+
cursor += 1;
|
|
274
|
+
const fieldName = `field${index}`;
|
|
275
|
+
if (typeCode === FIELD_TYPE_BOOL) {
|
|
276
|
+
if (!this.hasBytes(bytes, cursor, 1)) {
|
|
277
|
+
summaryParts.push(`${fieldName} truncated`);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
fields[fieldName] = this.readUInt8(bytes, cursor) !== 0;
|
|
281
|
+
cursor += 1;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (typeCode === FIELD_TYPE_INT32) {
|
|
285
|
+
if (!this.hasBytes(bytes, cursor, 4)) {
|
|
286
|
+
summaryParts.push(`${fieldName} truncated`);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
fields[fieldName] = bytes.readInt32LE(cursor);
|
|
290
|
+
cursor += 4;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (typeCode === FIELD_TYPE_UINT32) {
|
|
294
|
+
if (!this.hasBytes(bytes, cursor, 4)) {
|
|
295
|
+
summaryParts.push(`${fieldName} truncated`);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
fields[fieldName] = bytes.readUInt32LE(cursor);
|
|
299
|
+
cursor += 4;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (typeCode === FIELD_TYPE_STRING) {
|
|
303
|
+
if (!this.hasBytes(bytes, cursor, 2)) {
|
|
304
|
+
summaryParts.push(`${fieldName} length prefix truncated`);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
const length = this.readUInt16LE(bytes, cursor);
|
|
308
|
+
cursor += 2;
|
|
309
|
+
if (!this.hasBytes(bytes, cursor, length)) {
|
|
310
|
+
summaryParts.push(`${fieldName} string data truncated`);
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
fields[fieldName] = bytes.subarray(cursor, cursor + length).toString("utf8");
|
|
314
|
+
cursor += length;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (typeCode === FIELD_TYPE_HANDLE) {
|
|
318
|
+
if (!this.hasBytes(bytes, cursor, 4)) {
|
|
319
|
+
summaryParts.push(`${fieldName} handle truncated`);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
fields[fieldName] = { handle: bytes.readUInt32LE(cursor) };
|
|
323
|
+
actualHandles += 1;
|
|
324
|
+
cursor += 4;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
summaryParts.push(`unknown field type 0x${typeCode.toString(16).padStart(2, "0")}`);
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
const summary = summaryParts.length > 0 ? summaryParts.join("; ") : this.buildSummary(context, Object.keys(fields).length, numFields, actualHandles);
|
|
331
|
+
return {
|
|
332
|
+
header: {
|
|
333
|
+
version,
|
|
334
|
+
flags,
|
|
335
|
+
messageType,
|
|
336
|
+
numFields,
|
|
337
|
+
handles: declaredHandles
|
|
338
|
+
},
|
|
339
|
+
fields,
|
|
340
|
+
handles: actualHandles,
|
|
341
|
+
raw,
|
|
342
|
+
_raw_summary: summary
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
encodeMessage(interfaceName, messageType, fields) {
|
|
346
|
+
const encodedParts = [];
|
|
347
|
+
let handles = 0;
|
|
348
|
+
for (const field of fields) {
|
|
349
|
+
if (typeof field === "boolean") {
|
|
350
|
+
encodedParts.push(Buffer.from([FIELD_TYPE_BOOL, field ? 1 : 0]));
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (typeof field === "number" && Number.isInteger(field) && field >= 0) {
|
|
354
|
+
const chunk = Buffer.alloc(5);
|
|
355
|
+
chunk.writeUInt8(FIELD_TYPE_UINT32, 0);
|
|
356
|
+
chunk.writeUInt32LE(field, 1);
|
|
357
|
+
encodedParts.push(chunk);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (typeof field === "number" && Number.isInteger(field)) {
|
|
361
|
+
const chunk = Buffer.alloc(5);
|
|
362
|
+
chunk.writeUInt8(FIELD_TYPE_INT32, 0);
|
|
363
|
+
chunk.writeInt32LE(field, 1);
|
|
364
|
+
encodedParts.push(chunk);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (isHandleField(field)) {
|
|
368
|
+
const chunk = Buffer.alloc(5);
|
|
369
|
+
chunk.writeUInt8(FIELD_TYPE_HANDLE, 0);
|
|
370
|
+
chunk.writeUInt32LE(field.handle, 1);
|
|
371
|
+
encodedParts.push(chunk);
|
|
372
|
+
handles += 1;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const text = typeof field === "string" ? field : JSON.stringify(field);
|
|
376
|
+
const textBuffer = Buffer.from(text, "utf8");
|
|
377
|
+
const header = Buffer.alloc(3);
|
|
378
|
+
header.writeUInt8(FIELD_TYPE_STRING, 0);
|
|
379
|
+
header.writeUInt16LE(textBuffer.length, 1);
|
|
380
|
+
encodedParts.push(header, textBuffer);
|
|
381
|
+
}
|
|
382
|
+
const messageTypeCode = this.resolveMessageType(interfaceName, messageType);
|
|
383
|
+
const fieldCount = Math.min(fields.length, 255);
|
|
384
|
+
const header = Buffer.alloc(6);
|
|
385
|
+
header.writeUInt8(1, 0);
|
|
386
|
+
header.writeUInt8(0, 1);
|
|
387
|
+
header.writeUInt8(messageTypeCode, 2);
|
|
388
|
+
header.writeUInt8(fieldCount, 3);
|
|
389
|
+
header.writeUInt16LE(handles, 4);
|
|
390
|
+
return Buffer.concat([header, ...encodedParts]).toString("hex");
|
|
391
|
+
}
|
|
392
|
+
cleanHex(hex) {
|
|
393
|
+
return normalizeHexInput(hex);
|
|
394
|
+
}
|
|
395
|
+
resolveMessageType(interfaceName, messageType) {
|
|
396
|
+
if (/^[0-9]+$/.test(messageType)) return Number.parseInt(messageType, 10) & 255;
|
|
397
|
+
if (/^0x[0-9a-f]+$/i.test(messageType)) return Number.parseInt(messageType.slice(2), 16) & 255;
|
|
398
|
+
let hash = 0;
|
|
399
|
+
const seed = `${interfaceName}:${messageType}`;
|
|
400
|
+
for (const char of seed) hash = hash * 31 + char.charCodeAt(0) & 255;
|
|
401
|
+
return hash;
|
|
402
|
+
}
|
|
403
|
+
buildSummary(context, decodedFields, declaredFields, handles) {
|
|
404
|
+
return `${context ? `${context}: ` : ""}decoded ${decodedFields}/${declaredFields} fields, ${handles} handle(s)`;
|
|
405
|
+
}
|
|
406
|
+
readUInt8(bytes, offset) {
|
|
407
|
+
if (!this.hasBytes(bytes, offset, 1)) return 0;
|
|
408
|
+
return bytes.readUInt8(offset);
|
|
409
|
+
}
|
|
410
|
+
readUInt16LE(bytes, offset) {
|
|
411
|
+
if (!this.hasBytes(bytes, offset, 2)) return 0;
|
|
412
|
+
return bytes.readUInt16LE(offset);
|
|
413
|
+
}
|
|
414
|
+
hasBytes(bytes, offset, length) {
|
|
415
|
+
return offset >= 0 && length >= 0 && offset + length <= bytes.length;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/server/domains/mojo-ipc/handlers.impl.ts
|
|
420
|
+
function unavailablePayload(reason, action) {
|
|
421
|
+
return {
|
|
422
|
+
success: false,
|
|
423
|
+
available: false,
|
|
424
|
+
action,
|
|
425
|
+
error: reason
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
var MojoIPCHandlers = class {
|
|
429
|
+
constructor(monitor, decoder, eventBus) {
|
|
430
|
+
this.monitor = monitor;
|
|
431
|
+
this.decoder = decoder;
|
|
432
|
+
this.eventBus = eventBus;
|
|
433
|
+
}
|
|
434
|
+
async handleMojoMonitorDispatch(args) {
|
|
435
|
+
return String(args["action"] ?? "") === "stop" ? this.handleMojoMonitorStop() : this.handleMojoMonitorStart(args);
|
|
436
|
+
}
|
|
437
|
+
async handleMojoMonitorStart(args) {
|
|
438
|
+
const monitor = this.getMonitor();
|
|
439
|
+
if (!monitor.isAvailable()) return unavailablePayload(monitor.getUnavailableReason() ?? "Mojo IPC monitoring is not available", "mojo_monitor");
|
|
440
|
+
const deviceId = argString(args, "deviceId");
|
|
441
|
+
await monitor.start(deviceId);
|
|
442
|
+
return {
|
|
443
|
+
success: true,
|
|
444
|
+
available: true,
|
|
445
|
+
started: monitor.isActive(),
|
|
446
|
+
deviceId: monitor.getDeviceId() ?? null
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
async handleMojoMonitorStop() {
|
|
450
|
+
const monitor = this.getMonitor();
|
|
451
|
+
if (!monitor.isAvailable()) return unavailablePayload(monitor.getUnavailableReason() ?? "Mojo IPC monitoring is not available", "mojo_monitor");
|
|
452
|
+
await monitor.stop();
|
|
453
|
+
return {
|
|
454
|
+
success: true,
|
|
455
|
+
available: true,
|
|
456
|
+
started: false
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
async handleMojoDecodeMessage(args) {
|
|
460
|
+
const hexPayload = argString(args, "hexPayload", "");
|
|
461
|
+
if (hexPayload.length === 0) return {
|
|
462
|
+
success: false,
|
|
463
|
+
error: "hexPayload is required"
|
|
464
|
+
};
|
|
465
|
+
return {
|
|
466
|
+
success: true,
|
|
467
|
+
decoded: this.getDecoder().decodePayload(hexPayload)
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
async handleMojoListInterfaces() {
|
|
471
|
+
const monitor = this.getMonitor();
|
|
472
|
+
if (!monitor.isAvailable()) return {
|
|
473
|
+
...unavailablePayload(monitor.getUnavailableReason() ?? "Mojo IPC monitoring is not available", "mojo_list_interfaces"),
|
|
474
|
+
interfaces: []
|
|
475
|
+
};
|
|
476
|
+
const interfaces = await monitor.listInterfaces();
|
|
477
|
+
return {
|
|
478
|
+
success: true,
|
|
479
|
+
available: true,
|
|
480
|
+
active: monitor.isActive(),
|
|
481
|
+
interfaces
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
async handleMojoMessagesGet(args) {
|
|
485
|
+
const monitor = this.getMonitor();
|
|
486
|
+
if (!monitor.isAvailable()) return {
|
|
487
|
+
...unavailablePayload(monitor.getUnavailableReason() ?? "Mojo IPC monitoring is not available", "mojo_messages_get"),
|
|
488
|
+
messages: [],
|
|
489
|
+
totalAvailable: 0,
|
|
490
|
+
filtered: false,
|
|
491
|
+
_simulation: true
|
|
492
|
+
};
|
|
493
|
+
const limit = argNumber(args, "limit");
|
|
494
|
+
const interfaceName = argString(args, "interface");
|
|
495
|
+
const result = await monitor.getMessages({
|
|
496
|
+
limit: limit !== void 0 ? Math.min(limit, 1e4) : 100,
|
|
497
|
+
interfaceName
|
|
498
|
+
});
|
|
499
|
+
const response = {
|
|
500
|
+
success: true,
|
|
501
|
+
available: true,
|
|
502
|
+
active: monitor.isActive(),
|
|
503
|
+
messages: result.messages,
|
|
504
|
+
totalAvailable: result.totalAvailable,
|
|
505
|
+
filtered: result.filtered,
|
|
506
|
+
_simulation: result._simulation
|
|
507
|
+
};
|
|
508
|
+
if (result.messages && Array.isArray(result.messages) && result.messages.length > 0) this.eventBus?.emit("mojo:message_captured", {
|
|
509
|
+
messageCount: result.messages.length,
|
|
510
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
511
|
+
});
|
|
512
|
+
if (monitor.isSimulationMode()) response._warning = "Mojo IPC is operating in simulation mode. Messages are not captured from real Frida hooks. Install Frida for live IPC monitoring.";
|
|
513
|
+
return response;
|
|
514
|
+
}
|
|
515
|
+
getMonitor() {
|
|
516
|
+
if (!this.monitor) this.monitor = new MojoMonitor();
|
|
517
|
+
return this.monitor;
|
|
518
|
+
}
|
|
519
|
+
getDecoder() {
|
|
520
|
+
if (!this.decoder) this.decoder = new MojoDecoder();
|
|
521
|
+
return this.decoder;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
//#endregion
|
|
525
|
+
export { MojoIPCHandlers };
|