rea-agents 2.5.0 → 3.1.0

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 (253) hide show
  1. package/README.md +20 -12
  2. package/bridge/ghidra/ReaGhidraBridge.java +477 -4
  3. package/bridge/hopper_bridge.py +54 -4
  4. package/dist/application/AnalysisContextQueries.js +142 -0
  5. package/dist/application/AnalysisSnapshotCache.js +4 -2
  6. package/dist/application/ApplicationWorkflowEvidenceResolver.js +19 -11
  7. package/dist/application/ArtifactInventory/policy.js +17 -0
  8. package/dist/application/ArtifactInventory/reader.js +1 -4
  9. package/dist/application/ArtifactInventory/scanCanonical.js +0 -3
  10. package/dist/application/ArtifactInventory/scanReader.js +7 -7
  11. package/dist/application/ArtifactInventory/types.js +1 -5
  12. package/dist/application/BinarySession.js +19 -20
  13. package/dist/application/BinarySessionComposition.js +21 -0
  14. package/dist/application/BinarySessionRecords.js +106 -10
  15. package/dist/application/BinarySessionStatus.js +11 -5
  16. package/dist/application/BrowserEvidence.js +3 -5
  17. package/dist/application/CapabilityClientRequirements.js +26 -0
  18. package/dist/application/CapabilityInventory.js +140 -55
  19. package/dist/application/ClientRegistrationStatus.js +4 -1
  20. package/dist/application/CrossVersionInventory.js +7 -6
  21. package/dist/application/DirectAnalysis.js +6 -2
  22. package/dist/application/ElectronActiveEvidence.js +55 -0
  23. package/dist/application/ElectronActiveObservationPort.js +1 -0
  24. package/dist/application/ElectronActiveObservationService.js +81 -0
  25. package/dist/application/EnhancedTools.js +49 -17
  26. package/dist/application/EvidenceBundleCommands.js +5 -1
  27. package/dist/application/EvidenceLedger.js +53 -17
  28. package/dist/application/JavaScriptArtifactAnalysis.js +13 -4
  29. package/dist/application/JavaScriptReplayPermission.js +1 -1
  30. package/dist/application/JavaScriptReplayService.js +23 -15
  31. package/dist/application/LazyAnalysisProvider.js +77 -0
  32. package/dist/application/LoopbackReplay.js +1 -1
  33. package/dist/application/ManagedRuntimeCorrelationService.js +9 -5
  34. package/dist/application/NativeApiInspection.js +80 -0
  35. package/dist/application/NodeRuntimeCharacterizationService.js +8 -9
  36. package/dist/application/ProcessCaptureLifecycle.js +5 -0
  37. package/dist/application/ProcessCli.js +2 -1
  38. package/dist/application/ProcessHarness.js +8 -3
  39. package/dist/application/ProcessNormalization.js +2 -1
  40. package/dist/application/ProjectPermissionStore.js +1 -0
  41. package/dist/application/ReferenceSourceImport.js +2 -2
  42. package/dist/application/SessionProviderRouter.js +6 -6
  43. package/dist/application/SetupClientConfiguration.js +10 -3
  44. package/dist/application/WindowsCapabilities.js +5 -4
  45. package/dist/application/runtime.js +26 -9
  46. package/dist/artifacts/ArtifactProvider.js +8 -10
  47. package/dist/artifacts/SafeOutputTree.js +7 -8
  48. package/dist/browser/CdpCaptureStorageFingerprints.js +10 -7
  49. package/dist/browser/CdpElectronInspection.js +3 -1
  50. package/dist/browser/JavaScriptRuntimeScope.js +5 -0
  51. package/dist/browser/PlaywrightBrowserScenarioProvider.js +8 -2
  52. package/dist/browser/PlaywrightElectronActiveActions.js +324 -0
  53. package/dist/browser/PlaywrightElectronActiveProvider.js +294 -0
  54. package/dist/browser/PlaywrightScenarioBrowser.js +4 -4
  55. package/dist/browser/PlaywrightScenarioSession.js +4 -4
  56. package/dist/browser/SensitiveTextCapture.js +1 -1
  57. package/dist/browser/V8InspectorCaptureProjection.js +1 -0
  58. package/dist/browser/V8InspectorProvider.js +3 -3
  59. package/dist/catalogIdentity.js +15 -9
  60. package/dist/cli/artifactCommands.js +5 -3
  61. package/dist/cli/coreAnalysisCommands.js +41 -0
  62. package/dist/cli/managedCommands.js +1 -1
  63. package/dist/cliApplicationCommands.js +2 -2
  64. package/dist/cliBrowserAdvancedCommands.js +11 -5
  65. package/dist/cliBrowserCommands.js +14 -7
  66. package/dist/cliCommandNames.js +2 -0
  67. package/dist/cliElectronCommands.js +46 -4
  68. package/dist/cliJavaScriptRuntimeCommands.js +14 -6
  69. package/dist/cliObservationOptions.js +4 -0
  70. package/dist/cliPolicyCommands.js +1 -0
  71. package/dist/config/browserScenario.js +77 -0
  72. package/dist/config/electronAutomation.js +35 -0
  73. package/dist/config/environment.js +6 -0
  74. package/dist/config/javascriptReplay.js +41 -0
  75. package/dist/config/managedRuntime.js +25 -0
  76. package/dist/config/parseConfig.js +56 -200
  77. package/dist/config/parsers.js +10 -1
  78. package/dist/config/passiveObservation.js +157 -0
  79. package/dist/config/processCapture.js +47 -0
  80. package/dist/contracts/applicationToolContracts.js +2 -5
  81. package/dist/contracts/applicationWorkflowInputContracts.js +86 -96
  82. package/dist/contracts/artifactToolContracts.js +35 -37
  83. package/dist/contracts/browserToolContracts.js +2 -2
  84. package/dist/contracts/electronToolContracts.js +30 -1
  85. package/dist/contracts/enhancedInputs.js +21 -27
  86. package/dist/contracts/functionWorkflowToolContracts.js +29 -0
  87. package/dist/contracts/managedToolContracts.js +4 -9
  88. package/dist/contracts/managedWorkflowExamples.js +12 -9
  89. package/dist/contracts/managedWorkflowToolContracts.js +30 -27
  90. package/dist/contracts/nativeToolContracts.js +2 -3
  91. package/dist/contracts/promptContracts.js +14 -15
  92. package/dist/contracts/sessionToolSchemas.js +61 -0
  93. package/dist/contracts/toolContractExamples.js +4 -0
  94. package/dist/contracts/toolContractHelpers.js +23 -0
  95. package/dist/contracts/toolContracts.js +12 -67
  96. package/dist/contracts/toolEffects.js +19 -0
  97. package/dist/contracts/toolOutputSchemaGroups.js +66 -11
  98. package/dist/contracts/toolOutputSchemaPrimitives.js +76 -26
  99. package/dist/contracts/toolSchemaMetadata.js +128 -0
  100. package/dist/doctorRuntime.js +1 -1
  101. package/dist/domain/analysisErrorPresentation.js +8 -2
  102. package/dist/domain/analysisErrorProjection.js +1 -0
  103. package/dist/domain/androidApplication.js +2 -0
  104. package/dist/domain/appleApplication.js +2 -0
  105. package/dist/domain/binaryTarget.js +7 -5
  106. package/dist/domain/binaryTargetTypes.js +1 -0
  107. package/dist/domain/browserCaptureComparison.js +21 -69
  108. package/dist/domain/browserObservation.js +22 -9
  109. package/dist/domain/bytecodeProvider.js +177 -0
  110. package/dist/domain/callPath.js +3 -2
  111. package/dist/domain/conformancePackage.js +169 -0
  112. package/dist/domain/conformanceReplay.js +104 -0
  113. package/dist/domain/conformanceTrustGate.js +328 -0
  114. package/dist/domain/customProtocolCapture.js +137 -0
  115. package/dist/domain/electronActiveObservation.js +277 -0
  116. package/dist/domain/electronObservation.js +15 -11
  117. package/dist/domain/electronStaticAnalysisValues.js +4 -1
  118. package/dist/domain/eventProcessTree.js +217 -0
  119. package/dist/domain/evidenceBundle.js +47 -0
  120. package/dist/domain/functionComparisonNormalization.js +15 -8
  121. package/dist/domain/functionDossierEvidence.js +9 -4
  122. package/dist/domain/hopperStartupFailure.js +1 -1
  123. package/dist/domain/hopperValues.js +68 -68
  124. package/dist/domain/inputIssueProjection.js +11 -2
  125. package/dist/domain/investigationWorkspace.js +16 -15
  126. package/dist/domain/javascriptExportShapeComparisonSchemas.js +2 -2
  127. package/dist/domain/javascriptReplay.js +79 -63
  128. package/dist/domain/javascriptRuntimeObservation.js +1 -0
  129. package/dist/domain/javascriptRuntimeReconciliationActive.js +89 -0
  130. package/dist/domain/javascriptRuntimeReconciliationGraph.js +11 -10
  131. package/dist/domain/javascriptRuntimeReconciliationMatching.js +57 -49
  132. package/dist/domain/javascriptRuntimeReconciliationParsing.js +5 -1
  133. package/dist/domain/javascriptRuntimeReconciliationResult.js +21 -14
  134. package/dist/domain/javascriptRuntimeReconciliationSchemas.js +1 -1
  135. package/dist/domain/javascriptSemanticAnalysis.js +8 -12
  136. package/dist/domain/javascriptSourceParser.js +15 -0
  137. package/dist/domain/javascriptStaticAnalysis.js +8 -12
  138. package/dist/domain/knownPageCoverage.js +15 -7
  139. package/dist/domain/mobileApplicationInvestigation.js +159 -0
  140. package/dist/domain/nativeApiBoundary.js +138 -0
  141. package/dist/domain/nodeRuntimeCharacterization.js +14 -13
  142. package/dist/domain/objcSwiftMetadata.js +150 -0
  143. package/dist/domain/packageAnalysis.js +123 -0
  144. package/dist/domain/peInspection.js +196 -0
  145. package/dist/domain/processCaptureReactiveValidation.js +8 -3
  146. package/dist/domain/processCaptureValidation.js +7 -3
  147. package/dist/domain/processComparison.js +12 -7
  148. package/dist/domain/processObservation.js +5 -6
  149. package/dist/domain/processReactiveMatching.js +14 -7
  150. package/dist/domain/processReactiveTransition.js +9 -3
  151. package/dist/domain/processScenario.js +6 -3
  152. package/dist/domain/processTraceComparison.js +3 -2
  153. package/dist/domain/protocolCapture.js +245 -0
  154. package/dist/domain/reconstructionReadinessSchemas.js +30 -2
  155. package/dist/domain/referenceSourceImportParsing.js +2 -2
  156. package/dist/domain/replayMachineRuntime.js +5 -3
  157. package/dist/domain/sourceToBundleComparison.js +2 -2
  158. package/dist/domain/sourceToBundleComparisonSchemas.js +8 -8
  159. package/dist/domain/sourceToBundleSignals.js +7 -1
  160. package/dist/domain/staticRuntimeCorrelation.js +7 -5
  161. package/dist/domain/webBundleAnalysis.js +14 -14
  162. package/dist/domain/webCaptureDiff.js +15 -12
  163. package/dist/dotnet/ManagedNativeBoundaryInspector.js +2 -3
  164. package/dist/dotnet/ManagedStaticProvider.js +34 -5
  165. package/dist/generatedMcpToolCatalog.js +37 -0
  166. package/dist/generatedPackageMetadata.js +4 -4
  167. package/dist/ghidra/GhidraClient.js +1 -1
  168. package/dist/ghidra/GhidraClientStartup.js +1 -1
  169. package/dist/ghidra/GhidraDefaults.js +1 -1
  170. package/dist/ghidra/GhidraFunctionValues.js +44 -16
  171. package/dist/ghidra/GhidraInventoryValues.js +57 -47
  172. package/dist/ghidra/GhidraProvider.js +18 -10
  173. package/dist/ghidra/GhidraProviderCapabilities.js +45 -39
  174. package/dist/ghidra/GhidraSocketConnection.js +1 -1
  175. package/dist/ghidra/protocol.js +19 -42
  176. package/dist/hopper/BridgeLauncher.js +3 -1
  177. package/dist/hopper/HopperAnalysisProfile.js +2 -4
  178. package/dist/hopper/HopperCleanup.js +5 -6
  179. package/dist/hopper/HopperClient.js +27 -3
  180. package/dist/hopper/HopperProvider.js +42 -44
  181. package/dist/hopper/HopperRequestQueue.js +32 -4
  182. package/dist/hopper/HopperResponseStream.js +2 -2
  183. package/dist/hopper/LinuxPrivateDisplayProbe.js +16 -10
  184. package/dist/hopper/protocol.js +63 -21
  185. package/dist/main/reload.js +1 -6
  186. package/dist/main/state.js +0 -14
  187. package/dist/main/transport.js +31 -41
  188. package/dist/main.js +17 -13
  189. package/dist/mcpDoctor.js +4 -26
  190. package/dist/mcpStartupPolicy.js +14 -0
  191. package/dist/process/PrivateRuntimeRoot.js +17 -0
  192. package/dist/process/ProcessOwnership.js +64 -128
  193. package/dist/process/ProcessOwnershipIdentity.js +13 -0
  194. package/dist/process/ProcessOwnershipObservation.js +88 -0
  195. package/dist/process/ProcessOwnershipProcessTree.js +22 -0
  196. package/dist/process/ProviderDeadline.js +8 -12
  197. package/dist/process/WindowsAuthority.js +32 -0
  198. package/dist/reference/ReferenceSourceReader.js +3 -3
  199. package/dist/reference/ReferenceSourceReaderEntries.js +2 -2
  200. package/dist/replay/JavaScriptReplayWorker.js +95 -11
  201. package/dist/replay/JavaScriptReplayWorkerTypes.js +1 -0
  202. package/dist/replay/LinuxJavaScriptReplayRunner.js +10 -15
  203. package/dist/replay/ReplayOutcome.js +26 -15
  204. package/dist/replay/ReplayWorkerProtocol.js +34 -29
  205. package/dist/server/createServer.js +101 -144
  206. package/dist/server/mcpClientMetadata.js +32 -0
  207. package/dist/server/registerApplicationTools/characterization.js +6 -13
  208. package/dist/server/registerApplicationTools/compareExportShapes.js +2 -7
  209. package/dist/server/registerApplicationTools/compareSourceToBundle.js +2 -7
  210. package/dist/server/registerApplicationTools/compareVersions.js +3 -8
  211. package/dist/server/registerApplicationTools/controlledReplay.js +6 -11
  212. package/dist/server/registerApplicationTools/coverage.js +13 -19
  213. package/dist/server/registerApplicationTools/obligationLedger.js +1 -6
  214. package/dist/server/registerApplicationTools/readiness.js +1 -6
  215. package/dist/server/registerApplicationTools/traceFeature.js +3 -8
  216. package/dist/server/registerApplicationTools/traceSemantics.js +1 -6
  217. package/dist/server/registerArtifactComparisonTool.js +12 -16
  218. package/dist/server/registerBrowserScenarioTool.js +1 -6
  219. package/dist/server/registerBrowserTools.js +37 -79
  220. package/dist/server/registerBundleComparisonTool.js +10 -14
  221. package/dist/server/registerCloseLifecycleTool.js +6 -14
  222. package/dist/server/registerElectronTools.js +30 -47
  223. package/dist/server/registerEnhancedTools.js +124 -122
  224. package/dist/server/registerEvidenceResources.js +50 -101
  225. package/dist/server/registerEvidenceTools.js +5 -9
  226. package/dist/server/registerFunctionComparisonTool.js +11 -15
  227. package/dist/server/registerInvestigationTools.js +42 -59
  228. package/dist/server/registerJavaScriptApplicationGraphResource.js +0 -4
  229. package/dist/server/registerJavaScriptRuntimeObservationTools.js +13 -27
  230. package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +4 -9
  231. package/dist/server/registerManagedWorkflowTools/contract.js +2 -3
  232. package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +3 -8
  233. package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +3 -8
  234. package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +8 -13
  235. package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +4 -9
  236. package/dist/server/registerOfficialTools.js +8 -9
  237. package/dist/server/registerProcessComparisonTool.js +19 -24
  238. package/dist/server/registerReconstructionObligationLedgerResource.js +0 -7
  239. package/dist/server/registerReconstructionReadinessResource.js +0 -7
  240. package/dist/server/registerReplayMachineTool.js +4 -10
  241. package/dist/server/registerSessionRecordTools.js +146 -47
  242. package/dist/server/registerSessionStatusTool.js +14 -29
  243. package/dist/server/registerSessionTools.js +45 -41
  244. package/dist/server/sessionAvailabilityPolicy.js +2 -1
  245. package/dist/server/sessionToolPolicies.js +1 -5
  246. package/dist/server/toolRegistrationOptions.js +4 -177
  247. package/dist/server/toolResult.js +14 -18
  248. package/package.json +35 -16
  249. package/scripts/electron-active-hook-boundaries.cjs +394 -0
  250. package/scripts/electron-active-hook.cjs +501 -0
  251. package/skills/reverse-engineer-anything/SKILL.md +10 -3
  252. package/dist/server/DynamicToolAvailability.js +0 -70
  253. package/dist/server/toolInputValidation.js +0 -77
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+
3
+ // oxlint-disable-next-line max-lines-per-function -- all adapters must close over one bounded capture context.
4
+ const createElectronActiveBoundaryPatches = ({
5
+ identity,
6
+ patchEmitter,
7
+ processType,
8
+ recordIpc,
9
+ recordRuntime,
10
+ shape,
11
+ }) => {
12
+ const patchedSessions = new WeakSet();
13
+ const patchIpcRenderer = (ipcRenderer) => {
14
+ if (ipcRenderer === null || ipcRenderer === undefined) return;
15
+ for (const [method, kind] of [
16
+ ["send", "ipc-renderer-send"],
17
+ ["sendSync", "ipc-renderer-send"],
18
+ ["invoke", "ipc-renderer-invoke"],
19
+ ["postMessage", "ipc-renderer-post-message"],
20
+ ]) {
21
+ const original = ipcRenderer[method];
22
+ if (typeof original !== "function") continue;
23
+ ipcRenderer[method] = function patchedRendererIpc(channel, ...args) {
24
+ const recorded = recordIpc(kind, channel, args, {
25
+ direction: "renderer-to-main",
26
+ sender: processType(),
27
+ receiver: "main",
28
+ frame: null,
29
+ process_type: processType(),
30
+ error: false,
31
+ });
32
+ try {
33
+ const result = original.call(this, channel, ...args);
34
+ if (result !== null && typeof result?.then === "function")
35
+ return result.then(
36
+ (value) => {
37
+ if (recorded !== null) recorded.result_shape = shape(value);
38
+ return value;
39
+ },
40
+ (cause) => {
41
+ if (recorded !== null) recorded.error = true;
42
+ throw cause;
43
+ },
44
+ );
45
+ if (recorded !== null) recorded.result_shape = shape(result);
46
+ return result;
47
+ } catch (cause) {
48
+ if (recorded !== null) recorded.error = true;
49
+ throw cause;
50
+ }
51
+ };
52
+ }
53
+ };
54
+
55
+ const patchContextBridge = (contextBridge) => {
56
+ if (contextBridge === null || contextBridge === undefined) return;
57
+ for (const method of ["exposeInMainWorld", "exposeInIsolatedWorld"]) {
58
+ const original = contextBridge[method];
59
+ if (typeof original !== "function") continue;
60
+ contextBridge[method] = function patchedContextBridge(...args) {
61
+ const target = typeof args[0] === "string" ? args[0] : null;
62
+ recordRuntime("preload", "context-bridge-exposure", "attempted", {
63
+ target,
64
+ argument_shapes: args.map((value) => shape(value)),
65
+ process_type: processType(),
66
+ });
67
+ try {
68
+ const result = original.apply(this, args);
69
+ recordRuntime("preload", "context-bridge-exposure", "completed", {
70
+ target,
71
+ process_type: processType(),
72
+ });
73
+ return result;
74
+ } catch (cause) {
75
+ recordRuntime("preload", "context-bridge-exposure", "failed", {
76
+ target,
77
+ error: true,
78
+ process_type: processType(),
79
+ });
80
+ throw cause;
81
+ }
82
+ };
83
+ }
84
+ };
85
+
86
+ const patchSession = (session) => {
87
+ if (session === null || session === undefined) return;
88
+ if (
89
+ (typeof session !== "object" && typeof session !== "function") ||
90
+ patchedSessions.has(session)
91
+ )
92
+ return;
93
+ patchedSessions.add(session);
94
+ patchEmitter(session, (event, args) => {
95
+ const kind =
96
+ event === "will-download"
97
+ ? "download"
98
+ : event.includes("certificate") || event.includes("permission")
99
+ ? "permission"
100
+ : event.includes("window") || event.includes("popup")
101
+ ? "popup-attempt"
102
+ : "web-contents-lifecycle";
103
+ if (event === "will-download") {
104
+ const cancel = args[1]?.cancel;
105
+ if (typeof cancel === "function") cancel.call(args[1]);
106
+ }
107
+ recordRuntime(
108
+ kind,
109
+ event,
110
+ event === "will-download" ? "blocked" : "observed",
111
+ {
112
+ target: identity(args[0], "webContents"),
113
+ argument_shapes: args.map((value) => shape(value)),
114
+ error: event === "will-download",
115
+ },
116
+ );
117
+ });
118
+ const originalPermissionRequest = session.setPermissionRequestHandler;
119
+ if (typeof originalPermissionRequest === "function")
120
+ session.setPermissionRequestHandler =
121
+ function blockedPermissionRequest() {
122
+ return originalPermissionRequest.call(
123
+ this,
124
+ (webContents, permission, callback) => {
125
+ recordRuntime("permission", "permission-request", "blocked", {
126
+ target: identity(webContents, "webContents"),
127
+ argument_shapes: [shape(permission)],
128
+ error: true,
129
+ });
130
+ if (typeof callback === "function") callback(false);
131
+ },
132
+ );
133
+ };
134
+ const originalPermissionCheck = session.setPermissionCheckHandler;
135
+ if (typeof originalPermissionCheck === "function")
136
+ session.setPermissionCheckHandler = function blockedPermissionCheck() {
137
+ return originalPermissionCheck.call(this, (webContents, permission) => {
138
+ recordRuntime("permission", "permission-check", "blocked", {
139
+ target: identity(webContents, "webContents"),
140
+ argument_shapes: [shape(permission)],
141
+ error: true,
142
+ });
143
+ return false;
144
+ });
145
+ };
146
+ const originalCertificate = session.setCertificateVerifyProc;
147
+ if (typeof originalCertificate === "function")
148
+ session.setCertificateVerifyProc = function blockedCertificate() {
149
+ return originalCertificate.call(this, (request, callback) => {
150
+ recordRuntime("permission", "certificate-error", "blocked", {
151
+ argument_shapes: [shape(request)],
152
+ error: true,
153
+ });
154
+ if (typeof callback === "function") callback(-2);
155
+ });
156
+ };
157
+ };
158
+
159
+ const patchWindowOpenHandler = (webContents, contentsId) => {
160
+ if (webContents === null || webContents === undefined) return;
161
+ const original = webContents.setWindowOpenHandler;
162
+ if (typeof original !== "function") return;
163
+ const createGuardedHandler =
164
+ (handler) =>
165
+ (...args) => {
166
+ try {
167
+ if (typeof handler === "function") handler(...args);
168
+ } catch {
169
+ recordRuntime("popup-attempt", "window-open-handler", "failed", {
170
+ target: contentsId,
171
+ argument_shapes: args.map((value) => shape(value)),
172
+ error: true,
173
+ });
174
+ return { action: "deny" };
175
+ }
176
+ recordRuntime("popup-attempt", "window-open-handler", "blocked", {
177
+ target: contentsId,
178
+ argument_shapes: args.map((value) => shape(value)),
179
+ error: true,
180
+ });
181
+ return { action: "deny" };
182
+ };
183
+ try {
184
+ original.call(webContents, createGuardedHandler(undefined));
185
+ } catch {
186
+ recordRuntime("popup-attempt", "window-open-handler-install", "failed", {
187
+ target: contentsId,
188
+ error: true,
189
+ });
190
+ }
191
+ webContents.setWindowOpenHandler = function blockedWindowOpenHandler(
192
+ handler,
193
+ ) {
194
+ return original.call(this, createGuardedHandler(handler));
195
+ };
196
+ };
197
+
198
+ const patchSessionManager = (sessionModule) => {
199
+ if (sessionModule === null || sessionModule === undefined) return;
200
+ patchSession(sessionModule.defaultSession);
201
+ for (const method of ["fromPartition", "fromPath"]) {
202
+ const original = sessionModule[method];
203
+ if (typeof original !== "function") continue;
204
+ sessionModule[method] = function patchedSessionFactory(...args) {
205
+ const session = original.apply(this, args);
206
+ patchSession(session);
207
+ return session;
208
+ };
209
+ }
210
+ };
211
+
212
+ const patchApplicationEffects = (app) => {
213
+ if (app === null || app === undefined) return;
214
+ for (const method of [
215
+ "relaunch",
216
+ "setAsDefaultProtocolClient",
217
+ "setLoginItemSettings",
218
+ ]) {
219
+ const original = app[method];
220
+ if (typeof original !== "function") continue;
221
+ app[method] = function blockedApplicationEffect(...args) {
222
+ recordRuntime(
223
+ method === "relaunch" ? "updater" : "protocol",
224
+ method,
225
+ "blocked",
226
+ { argument_shapes: args.map((value) => shape(value)), error: true },
227
+ );
228
+ return method === "setAsDefaultProtocolClient" ? false : undefined;
229
+ };
230
+ }
231
+ };
232
+
233
+ const patchNativeAddonLoading = () => {
234
+ const original = process.dlopen;
235
+ if (typeof original !== "function") return;
236
+ process.dlopen = function patchedDlopen(module, filename, ...args) {
237
+ let digest = null;
238
+ try {
239
+ const fs = require("node:fs");
240
+ const crypto = require("node:crypto");
241
+ const stat = fs.statSync(filename);
242
+ if (stat.isFile() && stat.size <= 16 * 1024 * 1024)
243
+ digest = crypto
244
+ .createHash("sha256")
245
+ .update(fs.readFileSync(filename))
246
+ .digest("hex");
247
+ } catch {
248
+ digest = null;
249
+ }
250
+ recordRuntime("native-addon", "dlopen", "attempted", {
251
+ artifact_path: typeof filename === "string" ? filename : null,
252
+ artifact_sha256: digest,
253
+ argument_shapes: [
254
+ shape(module),
255
+ shape(filename),
256
+ ...args.map((value) => shape(value)),
257
+ ],
258
+ });
259
+ try {
260
+ const result = original.call(this, module, filename, ...args);
261
+ recordRuntime("native-addon", "dlopen", "completed", {
262
+ artifact_path: typeof filename === "string" ? filename : null,
263
+ artifact_sha256: digest,
264
+ });
265
+ return result;
266
+ } catch (cause) {
267
+ recordRuntime("native-addon", "dlopen", "failed", {
268
+ artifact_path: typeof filename === "string" ? filename : null,
269
+ artifact_sha256: digest,
270
+ error: true,
271
+ });
272
+ throw cause;
273
+ }
274
+ };
275
+ };
276
+
277
+ const patchUtilityProcess = (utilityProcess) => {
278
+ if (utilityProcess === null || utilityProcess === undefined) return;
279
+ const original = utilityProcess.fork;
280
+ if (typeof original !== "function") return;
281
+ utilityProcess.fork = function patchedFork(...args) {
282
+ recordRuntime("process-lifecycle", "utility-process-fork", "attempted", {
283
+ argument_shapes: args.map((value) => shape(value)),
284
+ process_type: "main",
285
+ });
286
+ const child = original.apply(this, args);
287
+ const childId = identity(child, "utility");
288
+ recordRuntime("process-lifecycle", "utility-process-fork", "completed", {
289
+ target: childId,
290
+ process_type: "main",
291
+ });
292
+ patchEmitter(child, (event, eventArgs) => {
293
+ if (event === "message") {
294
+ recordIpc("ipc-utility-to-main", null, eventArgs, {
295
+ direction: "utility-to-main",
296
+ sender: childId,
297
+ receiver: "main",
298
+ target: childId,
299
+ process_type: "main",
300
+ error: false,
301
+ });
302
+ return;
303
+ }
304
+ recordRuntime("process-lifecycle", `utility.${event}`, "observed", {
305
+ target: childId,
306
+ process_type: "utility",
307
+ argument_shapes: eventArgs.map((value) => shape(value)),
308
+ });
309
+ });
310
+ if (child && typeof child.postMessage === "function") {
311
+ const postMessage = child.postMessage.bind(child);
312
+ child.postMessage = (...messageArgs) => {
313
+ const recorded = recordIpc(
314
+ "utility-process-message",
315
+ null,
316
+ messageArgs,
317
+ {
318
+ direction: "main-to-utility",
319
+ sender: "main",
320
+ receiver: childId,
321
+ target: childId,
322
+ process_type: "main",
323
+ error: false,
324
+ },
325
+ );
326
+ try {
327
+ const result = postMessage(...messageArgs);
328
+ if (recorded !== null) recorded.result_shape = shape(result);
329
+ return result;
330
+ } catch (cause) {
331
+ if (recorded !== null) recorded.error = true;
332
+ throw cause;
333
+ }
334
+ };
335
+ }
336
+ return child;
337
+ };
338
+ };
339
+
340
+ const patchShell = (shell) => {
341
+ if (shell === null || shell === undefined) return;
342
+ for (const method of ["openExternal", "openPath"]) {
343
+ const original = shell[method];
344
+ if (typeof original !== "function") continue;
345
+ shell[method] = function blockedShellCall(...args) {
346
+ recordRuntime("shell-attempt", method, "blocked", {
347
+ argument_shapes: args.map((value) => shape(value)),
348
+ error: true,
349
+ });
350
+ return Promise.reject(new Error("External shell effects are blocked"));
351
+ };
352
+ }
353
+ };
354
+
355
+ const patchChildProcess = () => {
356
+ const childProcess = require("node:child_process");
357
+ for (const method of ["spawn", "fork", "exec", "execFile"]) {
358
+ const original = childProcess[method];
359
+ if (typeof original !== "function") continue;
360
+ childProcess[method] = function patchedChildProcess(...args) {
361
+ recordRuntime("process-lifecycle", `child.${method}`, "attempted", {
362
+ argument_shapes: args.map((value) => shape(value)),
363
+ });
364
+ const child = original.apply(this, args);
365
+ const childId = identity(child, "child");
366
+ recordRuntime("process-lifecycle", `child.${method}`, "completed", {
367
+ target: childId,
368
+ });
369
+ patchEmitter(child, (event, eventArgs) =>
370
+ recordRuntime("process-lifecycle", `child.${event}`, "observed", {
371
+ target: childId,
372
+ argument_shapes: eventArgs.map((value) => shape(value)),
373
+ }),
374
+ );
375
+ return child;
376
+ };
377
+ }
378
+ };
379
+
380
+ return {
381
+ patchApplicationEffects,
382
+ patchChildProcess,
383
+ patchContextBridge,
384
+ patchIpcRenderer,
385
+ patchNativeAddonLoading,
386
+ patchSession,
387
+ patchSessionManager,
388
+ patchShell,
389
+ patchWindowOpenHandler,
390
+ patchUtilityProcess,
391
+ };
392
+ };
393
+
394
+ module.exports = { createElectronActiveBoundaryPatches };