rea-agents 3.2.1 → 4.0.1

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 (434) hide show
  1. package/README.md +183 -332
  2. package/bridge/ghidra/ReaGhidraBridge.java +561 -74
  3. package/bridge/hopper_bridge.py +70 -27
  4. package/bridge/native/ReaNativeUI.swift +157 -0
  5. package/dist/application/AnalysisContextQueries.js +19 -5
  6. package/dist/application/AnalysisSnapshotCache.js +30 -11
  7. package/dist/application/AppleAssetCatalogAnalysis.js +171 -0
  8. package/dist/application/ArtifactExtractionDestination.js +0 -12
  9. package/dist/application/ArtifactGraphConstruction.js +44 -11
  10. package/dist/application/ArtifactInventory/classify.js +7 -15
  11. package/dist/application/ArtifactInventory/hash.js +4 -2
  12. package/dist/application/ArtifactInventory/policy.js +2 -17
  13. package/dist/application/ArtifactInventory/reader.js +3 -3
  14. package/dist/application/ArtifactInventory/scanCanonical.js +2 -2
  15. package/dist/application/ArtifactInventory/scanReader.js +12 -4
  16. package/dist/application/ArtifactInventory/types.js +0 -3
  17. package/dist/application/BinarySession.js +28 -43
  18. package/dist/application/BinarySessionExecution.js +37 -1
  19. package/dist/application/BinaryTargetResolver.js +50 -4
  20. package/dist/application/BrowserEvidence.js +36 -7
  21. package/dist/application/BrowserObservationService.js +17 -44
  22. package/dist/application/BrowserScenarioCaptureService.js +2 -35
  23. package/dist/application/BrowserScenarioEvidence.js +13 -9
  24. package/dist/application/CapabilityClientRequirements.js +2 -11
  25. package/dist/application/CapabilityInventory.js +21 -35
  26. package/dist/application/ClientConfigurationDocument.js +84 -7
  27. package/dist/application/ClientRegistrationIdentity.js +32 -0
  28. package/dist/application/ClientRegistrationStatus.js +59 -6
  29. package/dist/application/DirectAnalysis.js +37 -58
  30. package/dist/application/DirectAnalysisStatus.js +4 -4
  31. package/dist/application/Doctor.js +89 -80
  32. package/dist/application/DoctorDiagnostics.js +2 -26
  33. package/dist/application/DoctorScope.js +8 -14
  34. package/dist/application/ElectronActiveEvidence.js +10 -27
  35. package/dist/application/ElectronActiveObservationService.js +9 -36
  36. package/dist/application/ElectronBoundaryAnalysis.js +2 -0
  37. package/dist/application/ElectronBoundaryGraphNative.js +1 -1
  38. package/dist/application/ElectronEvidence.js +8 -3
  39. package/dist/application/ElectronObservationService.js +9 -25
  40. package/dist/application/EnhancedLiteralTracing.js +4 -8
  41. package/dist/application/EnhancedTools.js +15 -35
  42. package/dist/application/FilesystemSnapshot.js +7 -8
  43. package/dist/application/JavaScriptApplicationEvidenceGraph.js +2 -1
  44. package/dist/application/JavaScriptApplicationWorkflowService.js +31 -7
  45. package/dist/application/JavaScriptArtifactAnalysis.js +6 -4
  46. package/dist/application/JavaScriptArtifactFiles.js +5 -0
  47. package/dist/application/JavaScriptArtifactPathResolution.js +179 -47
  48. package/dist/application/JavaScriptRuntimeObservationEvidence.js +6 -3
  49. package/dist/application/JavaScriptRuntimeObservationService.js +9 -25
  50. package/dist/application/JavaScriptRuntimeReconciliationService.js +45 -4
  51. package/dist/application/JavaScriptSemanticGraphAsyncProjection.js +11 -0
  52. package/dist/application/JavaScriptSemanticGraphChildProcessProjection.js +11 -0
  53. package/dist/application/JavaScriptSemanticGraphDataProjection.js +11 -0
  54. package/dist/application/JavaScriptSemanticGraphFlowProjection.js +14 -5
  55. package/dist/application/JsonFiles.js +1 -1
  56. package/dist/application/LazyAnalysisProvider.js +27 -6
  57. package/dist/application/ManagedMemberComparisonService.js +19 -6
  58. package/dist/application/NativeApiInspection.js +2 -0
  59. package/dist/application/NativeCallRoutes.js +72 -0
  60. package/dist/application/NativeDispatchMetadataInspection.js +33 -0
  61. package/dist/application/NativeUiActionTrace.js +73 -49
  62. package/dist/application/NativeValueTrace.js +320 -0
  63. package/dist/application/ProcessCaptureCapability.js +32 -5
  64. package/dist/application/ProcessCaptureEnvironment.js +9 -26
  65. package/dist/application/ProcessCaptureError.js +1 -5
  66. package/dist/application/ProcessCaptureJournal.js +3 -40
  67. package/dist/application/ProcessCaptureLifecycle.js +102 -111
  68. package/dist/application/ProcessCli.js +18 -25
  69. package/dist/application/ProcessEvidence.js +5 -7
  70. package/dist/application/ProcessFilesystemEffects.js +36 -0
  71. package/dist/application/ProcessHarness.js +41 -120
  72. package/dist/application/ProcessNormalization.js +2 -17
  73. package/dist/application/ProcessScenarioRuntimeValidation.js +76 -0
  74. package/dist/application/ReferenceSourceImport.js +3 -4
  75. package/dist/application/Setup.js +236 -84
  76. package/dist/application/SetupClientConfiguration.js +14 -9
  77. package/dist/application/SetupPlan.js +138 -86
  78. package/dist/application/SetupSkill.js +0 -1
  79. package/dist/application/SupportedClients.js +102 -21
  80. package/dist/application/Uninstall.js +31 -20
  81. package/dist/application/Update.js +93 -0
  82. package/dist/application/UpdateMaintenance.js +108 -0
  83. package/dist/application/UpdateRuntime.js +126 -0
  84. package/dist/application/runtime.js +13 -2
  85. package/dist/artifacts/ArtifactPaths.js +6 -8
  86. package/dist/artifacts/ArtifactProvider.js +94 -41
  87. package/dist/artifacts/AsarArtifactReader.js +19 -4
  88. package/dist/artifacts/KeyedArchiveReader.js +110 -0
  89. package/dist/artifacts/MachOSliceArtifactReader.js +53 -5
  90. package/dist/artifacts/ZipArtifactReader.js +18 -1
  91. package/dist/browser/BrowserScenarioSecrets.js +28 -1
  92. package/dist/browser/CdpBrowserProvider.js +36 -15
  93. package/dist/browser/CdpCaptureDocuments.js +22 -8
  94. package/dist/browser/CdpCaptureEventHandlers.js +14 -5
  95. package/dist/browser/CdpCaptureEventHelpers.js +13 -0
  96. package/dist/browser/CdpCaptureEvents.js +10 -1
  97. package/dist/browser/CdpElectronInspection.js +5 -10
  98. package/dist/browser/CdpElectronProvider.js +1 -5
  99. package/dist/browser/CdpElectronScripts.js +1 -1
  100. package/dist/browser/CdpEndpoint.js +3 -2
  101. package/dist/browser/CdpObservationSession.js +14 -10
  102. package/dist/browser/CdpPageCapture.js +1 -1
  103. package/dist/browser/CdpPageCaptureScripts.js +1 -1
  104. package/dist/browser/CdpSafeMetadata.js +5 -4
  105. package/dist/browser/CdpScreenshot.js +16 -5
  106. package/dist/browser/CdpTargetSession.js +25 -4
  107. package/dist/browser/CdpWebMcpDiscovery.js +93 -20
  108. package/dist/browser/JavaScriptRuntimeScope.js +28 -2
  109. package/dist/browser/PlaywrightBrowserScenarioProvider.js +9 -8
  110. package/dist/browser/PlaywrightElectronActiveActions.js +3 -10
  111. package/dist/browser/PlaywrightElectronActiveProvider.js +5 -5
  112. package/dist/browser/PlaywrightScenarioActions.js +1 -1
  113. package/dist/browser/PlaywrightScenarioArtifacts.js +13 -25
  114. package/dist/browser/PlaywrightScenarioBrowser.js +28 -25
  115. package/dist/browser/PlaywrightScenarioEvents.js +82 -93
  116. package/dist/browser/PlaywrightScenarioSession.js +27 -123
  117. package/dist/browser/PngVisualDiff.js +22 -3
  118. package/dist/browser/V8InspectorCaptureProjection.js +7 -1
  119. package/dist/browser/V8InspectorProvider.js +60 -7
  120. package/dist/browser/WebSourceMapFetcher.js +99 -53
  121. package/dist/cli/artifactCommands.js +56 -12
  122. package/dist/cli/coreAnalysisCommands.js +110 -0
  123. package/dist/cli/managedCommands.js +1 -31
  124. package/dist/cli/setupCommands.js +16 -14
  125. package/dist/cli/utilityCommands.js +61 -4
  126. package/dist/cli.js +5 -7
  127. package/dist/cliApplicationCommands.js +0 -83
  128. package/dist/cliBrowserAdvancedCommands.js +7 -11
  129. package/dist/cliBrowserCommands.js +15 -23
  130. package/dist/cliBrowserContext.js +3 -24
  131. package/dist/cliBrowserScenarioCommands.js +2 -10
  132. package/dist/cliCommandNames.js +82 -7
  133. package/dist/cliElectronCommands.js +10 -36
  134. package/dist/cliJavaScriptRuntimeCommands.js +6 -30
  135. package/dist/cliJsonInput.js +4 -2
  136. package/dist/cliLogging.js +16 -7
  137. package/dist/cliObservationOptions.js +1 -1
  138. package/dist/cliOutput.js +2 -4
  139. package/dist/cliProcessCommands.js +6 -33
  140. package/dist/cliSetup.js +90 -160
  141. package/dist/config/environment.js +2 -78
  142. package/dist/config/parseConfig.js +18 -109
  143. package/dist/config/parsers.js +0 -23
  144. package/dist/contracts/applicationToolContracts.js +1 -118
  145. package/dist/contracts/artifactToolContracts.js +11 -19
  146. package/dist/contracts/browserScenarioToolContracts.js +1 -5
  147. package/dist/contracts/browserToolContracts.js +9 -16
  148. package/dist/contracts/electronToolContracts.js +5 -6
  149. package/dist/contracts/enhancedInputs.js +3 -2
  150. package/dist/contracts/errorSchemas.js +16 -40
  151. package/dist/contracts/functionWorkflowToolContracts.js +2 -2
  152. package/dist/contracts/javascriptApplicationWorkflowExamples.js +2 -2
  153. package/dist/contracts/javascriptRuntimeObservationToolContracts.js +4 -4
  154. package/dist/contracts/javascriptRuntimeReconciliationExample.js +1 -1
  155. package/dist/contracts/managedToolContracts.js +7 -4
  156. package/dist/contracts/managedWorkflowExamples.js +0 -22
  157. package/dist/contracts/managedWorkflowToolContracts.js +16 -31
  158. package/dist/contracts/nativeToolContracts.js +9 -0
  159. package/dist/contracts/promptContracts.js +6 -6
  160. package/dist/contracts/sessionToolSchemas.js +3 -3
  161. package/dist/contracts/toolContractExamples.js +4 -3
  162. package/dist/contracts/toolContracts.js +18 -7
  163. package/dist/contracts/toolEffects.js +34 -21
  164. package/dist/contracts/toolOutputSchemaGroups.js +18 -5
  165. package/dist/contracts/toolOutputSchemaPrimitives.js +9 -6
  166. package/dist/contracts/toolSchemaMetadata.js +5 -8
  167. package/dist/doctorRuntime.js +0 -41
  168. package/dist/domain/analysisErrorPresentation.js +4 -28
  169. package/dist/domain/analysisErrorProjection.js +33 -50
  170. package/dist/domain/analysisProfile.js +1 -1
  171. package/dist/domain/analysisSnapshot.js +77 -3
  172. package/dist/domain/androidApplication.js +5 -4
  173. package/dist/domain/appleApplication.js +5 -4
  174. package/dist/domain/appleAssetCatalog.js +127 -0
  175. package/dist/domain/artifactComparison.js +7 -11
  176. package/dist/domain/artifactGraph.js +8 -6
  177. package/dist/domain/artifactInspection.js +13 -12
  178. package/dist/domain/binaryTarget.js +23 -9
  179. package/dist/domain/browserObservation.js +43 -24
  180. package/dist/domain/browserObservationSchemas.js +2 -1
  181. package/dist/domain/browserScenario.js +7 -107
  182. package/dist/domain/browserScenarioCapture.js +0 -1
  183. package/dist/domain/browserScenarioCaptureValues.js +5 -4
  184. package/dist/domain/browserScenarioDiff.js +1 -3
  185. package/dist/domain/browserScenarioValues.js +16 -107
  186. package/dist/domain/bundleComparison.js +18 -17
  187. package/dist/domain/callPathSchemas.js +17 -7
  188. package/dist/domain/changedBehavior.js +2 -3
  189. package/dist/domain/comparisonSemantics.js +19 -0
  190. package/dist/domain/completionLedgerGeneration.js +3 -2
  191. package/dist/domain/conformancePackage.js +2 -1
  192. package/dist/domain/conformanceTrustGate.js +3 -5
  193. package/dist/domain/customProtocolCapture.js +2 -2
  194. package/dist/domain/digests.js +30 -0
  195. package/dist/domain/dosMz.js +83 -0
  196. package/dist/domain/electronActiveObservation.js +7 -5
  197. package/dist/domain/electronObservation.js +3 -2
  198. package/dist/domain/electronStaticAnalysisNative.js +15 -6
  199. package/dist/domain/emptyArraySchema.js +3 -0
  200. package/dist/domain/errors.js +10 -28
  201. package/dist/domain/evidence.js +5 -3
  202. package/dist/domain/evidenceCompletionLedger.js +3 -2
  203. package/dist/domain/functionComparisonNormalization.js +24 -18
  204. package/dist/domain/functionComparisonResults.js +3 -7
  205. package/dist/domain/functionComparisonSchemas.js +3 -2
  206. package/dist/domain/hopperValues.js +108 -8
  207. package/dist/domain/javascriptApplicationAnalysis.js +4 -7
  208. package/dist/domain/javascriptApplicationEvidenceSchemas.js +4 -3
  209. package/dist/domain/javascriptApplicationGraphSchemas.js +8 -7
  210. package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +9 -7
  211. package/dist/domain/javascriptApplicationVersionItems.js +12 -18
  212. package/dist/domain/javascriptAstValues.js +4 -0
  213. package/dist/domain/javascriptExportShapeComparison.js +1 -6
  214. package/dist/domain/javascriptExportShapeComparisonSchemas.js +6 -10
  215. package/dist/domain/javascriptExportShapeVariants.js +15 -2
  216. package/dist/domain/javascriptFeatureTraceSchemas.js +8 -7
  217. package/dist/domain/javascriptRuntimeObservation.js +14 -2
  218. package/dist/domain/javascriptRuntimeReconciliationMatching.js +8 -0
  219. package/dist/domain/javascriptRuntimeReconciliationParsing.js +4 -2
  220. package/dist/domain/javascriptRuntimeReconciliationResult.js +6 -4
  221. package/dist/domain/javascriptRuntimeReconciliationRuntime.js +15 -4
  222. package/dist/domain/javascriptRuntimeReconciliationSchemas.js +19 -18
  223. package/dist/domain/javascriptRuntimeStaticCandidates.js +18 -6
  224. package/dist/domain/javascriptSemanticAnalysis.js +57 -19
  225. package/dist/domain/javascriptSemanticAsyncEffects.js +39 -40
  226. package/dist/domain/javascriptSemanticCalls.js +46 -27
  227. package/dist/domain/javascriptSemanticChildProcesses.js +43 -50
  228. package/dist/domain/javascriptSemanticDataEffectHelpers.js +91 -18
  229. package/dist/domain/javascriptSemanticDataEffects.js +22 -10
  230. package/dist/domain/javascriptSemanticGraphSchemas.js +8 -6
  231. package/dist/domain/javascriptSemanticObjects.js +13 -3
  232. package/dist/domain/javascriptSemanticProjection.js +144 -38
  233. package/dist/domain/javascriptSemanticPromises.js +14 -27
  234. package/dist/domain/javascriptSemanticQuerySchemas.js +6 -9
  235. package/dist/domain/javascriptSemanticResources.js +2 -5
  236. package/dist/domain/javascriptSemanticState.js +4 -0
  237. package/dist/domain/javascriptSemanticTraceSchemas.js +2 -1
  238. package/dist/domain/javascriptSemanticTraversal.js +13 -5
  239. package/dist/domain/javascriptSemanticValues.js +10 -9
  240. package/dist/domain/javascriptSourceParser.js +5 -1
  241. package/dist/domain/javascriptStaticAnalysisCalls.js +8 -5
  242. package/dist/domain/javascriptStaticAnalysisHelpers.js +16 -7
  243. package/dist/domain/keyedArchive.js +181 -0
  244. package/dist/domain/managedApplicationGraph.js +4 -3
  245. package/dist/domain/managedArtifact.js +2 -1
  246. package/dist/domain/managedMemberComparison.js +18 -13
  247. package/dist/domain/managedMemberComparisonCoverage.js +2 -1
  248. package/dist/domain/managedMemberComparisonItems.js +27 -7
  249. package/dist/domain/managedMemberComparisonMatch.js +22 -6
  250. package/dist/domain/managedNativeVerificationMatch.js +2 -2
  251. package/dist/domain/managedNativeVerificationSchemas.js +7 -5
  252. package/dist/domain/managedReconstruction.js +6 -5
  253. package/dist/domain/nativeApiBoundary.js +7 -0
  254. package/dist/domain/nativeDataType.js +51 -0
  255. package/dist/domain/nativeInspection.js +0 -1
  256. package/dist/domain/nativeInstruction.js +82 -0
  257. package/dist/domain/nativeInvestigationGraph.js +9 -5
  258. package/dist/domain/nativeUiObservation.js +123 -0
  259. package/dist/domain/nativeValueFlow.js +17 -0
  260. package/dist/domain/nativeValueTrace.js +64 -0
  261. package/dist/domain/objcSwiftMetadata.js +39 -0
  262. package/dist/domain/peInspection.js +1 -0
  263. package/dist/domain/processCapture.js +5 -55
  264. package/dist/domain/processCaptureExample.js +0 -9
  265. package/dist/domain/processCaptureValidation.js +13 -144
  266. package/dist/domain/processComparison.js +3 -25
  267. package/dist/domain/processObservation.js +0 -29
  268. package/dist/domain/processScenario.js +28 -228
  269. package/dist/domain/processTraceDimensionProjection.js +0 -15
  270. package/dist/domain/processTraceEvaluation.js +0 -6
  271. package/dist/domain/protocolCapture.js +8 -36
  272. package/dist/domain/reconstructionCoverage.js +3 -2
  273. package/dist/domain/reconstructionObligationLedgerSchemas.js +4 -12
  274. package/dist/domain/reconstructionReadinessSchemas.js +4 -3
  275. package/dist/domain/reconstructionVerification.js +2 -1
  276. package/dist/domain/reconstructionVerificationSchemas.js +6 -13
  277. package/dist/domain/referenceSourceClassification.js +0 -110
  278. package/dist/domain/referenceSourceGraph.js +15 -5
  279. package/dist/domain/residualUnknown.js +3 -2
  280. package/dist/domain/runtimeIdentification.js +6 -5
  281. package/dist/domain/sourceMapContents.js +5 -0
  282. package/dist/domain/sourceToBundleComparison.js +3 -10
  283. package/dist/domain/sourceToBundleComparisonSchemas.js +7 -6
  284. package/dist/domain/sourceToBundleSignals.js +9 -3
  285. package/dist/domain/staticRuntimeCorrelation.js +5 -11
  286. package/dist/domain/webBundleAnalysis.js +17 -9
  287. package/dist/domain/webBundleAnalyzer.js +1 -1
  288. package/dist/domain/webCaptureDiff.js +5 -11
  289. package/dist/domain/webCaptureDiffSchemas.js +2 -1
  290. package/dist/domain/webMcpDiscovery.js +2 -1
  291. package/dist/dotnet/ManagedMemberInspectorCore.js +15 -7
  292. package/dist/dotnet/ManagedMemberInstructionDecoder.js +57 -40
  293. package/dist/dotnet/ManagedMemberRows.js +2 -0
  294. package/dist/dotnet/ManagedMethodBodyReader.js +15 -8
  295. package/dist/dotnet/ManagedPeReader.js +2 -0
  296. package/dist/generatedMcpToolCatalog.js +1 -1
  297. package/dist/generatedPackageMetadata.js +2 -2
  298. package/dist/ghidra/GhidraAnalysisProfile.js +15 -5
  299. package/dist/ghidra/GhidraClient.js +38 -8
  300. package/dist/ghidra/GhidraFunctionValues.js +56 -20
  301. package/dist/ghidra/GhidraInstallation.js +7 -4
  302. package/dist/ghidra/GhidraInventoryValues.js +44 -9
  303. package/dist/ghidra/GhidraLauncher.js +18 -3
  304. package/dist/ghidra/GhidraProvider.js +23 -2
  305. package/dist/ghidra/GhidraRequestQueue.js +45 -4
  306. package/dist/ghidra/GhidraSessionValues.js +5 -0
  307. package/dist/hopper/HopperAnalysisProfile.js +2 -0
  308. package/dist/hopper/HopperProvider.js +29 -6
  309. package/dist/hopper/HopperTargetLease.js +18 -4
  310. package/dist/logger.js +0 -13
  311. package/dist/main/messages.js +0 -1
  312. package/dist/main/reload.js +3 -32
  313. package/dist/main/shutdown.js +1 -2
  314. package/dist/main/transport.js +0 -17
  315. package/dist/main.js +0 -10
  316. package/dist/native/AppleDispatchMetadata.js +582 -0
  317. package/dist/native/AppleObjcProtocols.js +88 -0
  318. package/dist/native/AppleSwiftVtables.js +86 -0
  319. package/dist/native/CommandRunner.js +1 -1
  320. package/dist/native/NativeHostCapabilities.js +23 -0
  321. package/dist/native/NativeMacOSProvider.js +61 -9
  322. package/dist/native/NativeMachoInspection.js +39 -6
  323. package/dist/native/NativeUiHelperRuntime.js +42 -0
  324. package/dist/native/NativeUiObservation.js +174 -0
  325. package/dist/native/parsers/codesign.js +4 -1
  326. package/dist/native/parsers/dyldInfo.js +51 -25
  327. package/dist/native/parsers/lipo.js +13 -4
  328. package/dist/native/parsers/otool.js +84 -39
  329. package/dist/native/parsers/plist.js +2 -1
  330. package/dist/process/ExecFileOutput.js +5 -1
  331. package/dist/process/ProcessOwnership.js +69 -33
  332. package/dist/process/ProcessOwnershipObservation.js +31 -12
  333. package/dist/process/ProviderProcess.js +4 -2
  334. package/dist/reference/ReferenceSourceReaderEntries.js +48 -31
  335. package/dist/reference/ReferenceSourceReaderErrors.js +24 -0
  336. package/dist/reference/ReferenceSourceReaderFile.js +11 -5
  337. package/dist/reference/ReferenceSourceReaderValidate.js +22 -8
  338. package/dist/server/createServer.js +7 -62
  339. package/dist/server/registerApplicationTools/helpers.js +2 -9
  340. package/dist/server/registerApplicationTools.js +0 -4
  341. package/dist/server/registerArtifactComparisonTool.js +1 -1
  342. package/dist/server/registerBrowserScenarioTool.js +4 -2
  343. package/dist/server/registerBrowserTools.js +7 -7
  344. package/dist/server/registerBundleComparisonTool.js +1 -1
  345. package/dist/server/registerCloseLifecycleTool.js +1 -1
  346. package/dist/server/registerElectronTools.js +10 -4
  347. package/dist/server/registerEnhancedTools.js +20 -12
  348. package/dist/server/registerEvidenceTools.js +4 -28
  349. package/dist/server/registerFunctionComparisonTool.js +1 -1
  350. package/dist/server/registerInvestigationTools.js +6 -6
  351. package/dist/server/registerJavaScriptRuntimeObservationTools.js +2 -2
  352. package/dist/server/registerManagedTools.js +28 -14
  353. package/dist/server/registerManagedWorkflowTools.js +0 -2
  354. package/dist/server/registerProcessComparisonTool.js +1 -3
  355. package/dist/server/registerSessionRecordTools.js +9 -9
  356. package/dist/server/registerSessionStatusTool.js +1 -1
  357. package/dist/server/registerSessionTools.js +28 -57
  358. package/dist/server/sessionAvailabilityPolicy.js +2 -3
  359. package/dist/server/sessionToolPolicies.js +0 -4
  360. package/dist/server/toolResult.js +8 -10
  361. package/package.json +32 -22
  362. package/skills/reverse-engineer-anything/SKILL.md +15 -11
  363. package/skills/reverse-engineer-anything/references/evidence-workflows.md +3 -2
  364. package/skills/reverse-engineer-anything/references/javascript-applications.md +3 -2
  365. package/skills/reverse-engineer-anything/references/native-and-artifacts.md +8 -6
  366. package/skills/reverse-engineer-anything/references/runtime-observation.md +15 -11
  367. package/dist/application/CommandShimReplay.js +0 -152
  368. package/dist/application/ConfiguredRoots.js +0 -19
  369. package/dist/application/InstrumentedJavaScriptReplayHost.js +0 -36
  370. package/dist/application/JavaScriptReplayPermission.js +0 -16
  371. package/dist/application/JavaScriptReplayPlanning.js +0 -207
  372. package/dist/application/JavaScriptReplayService.js +0 -274
  373. package/dist/application/LoopbackReplay.js +0 -389
  374. package/dist/application/LoopbackReplayRecorder.js +0 -129
  375. package/dist/application/ManagedRuntimeCorrelationService.js +0 -104
  376. package/dist/application/NodeRuntimeCharacterizationService.js +0 -191
  377. package/dist/application/PermissionAuthority.js +0 -268
  378. package/dist/application/PermissionConfiguration.js +0 -26
  379. package/dist/application/PermissionFailure.js +0 -5
  380. package/dist/application/ProcessCaptureAuthority.js +0 -24
  381. package/dist/application/ProcessCapturePermission.js +0 -13
  382. package/dist/application/ProcessCheckpoints.js +0 -178
  383. package/dist/application/ProcessReactiveCoordinator.js +0 -223
  384. package/dist/application/ProcessReactiveEffects.js +0 -153
  385. package/dist/application/ProcessReactiveHarness.js +0 -106
  386. package/dist/application/ProcessReactiveObservations.js +0 -105
  387. package/dist/application/ProjectPermissionStore.js +0 -199
  388. package/dist/application/RuntimeExecutableDiagnostics.js +0 -198
  389. package/dist/application/Upgrade.js +0 -134
  390. package/dist/browser/SensitiveTextCapture.js +0 -8
  391. package/dist/cliPolicyCommands.js +0 -185
  392. package/dist/config/browserScenario.js +0 -77
  393. package/dist/config/electronAutomation.js +0 -35
  394. package/dist/config/javascriptReplay.js +0 -41
  395. package/dist/config/managedRuntime.js +0 -25
  396. package/dist/config/passiveObservation.js +0 -87
  397. package/dist/config/permissions.js +0 -23
  398. package/dist/config/processCapture.js +0 -47
  399. package/dist/contracts/replayMachineExample.js +0 -37
  400. package/dist/domain/javascriptExportInstrumentation.js +0 -95
  401. package/dist/domain/javascriptReplay.js +0 -360
  402. package/dist/domain/managedRuntimeCorrelation.js +0 -181
  403. package/dist/domain/nodeRuntimeCharacterization.js +0 -63
  404. package/dist/domain/permissionPolicy.js +0 -176
  405. package/dist/domain/processCaptureReactiveSchema.js +0 -68
  406. package/dist/domain/processCaptureReactiveValidation.js +0 -180
  407. package/dist/domain/processReactiveCheckpointDataflow.js +0 -32
  408. package/dist/domain/processReactiveMatching.js +0 -196
  409. package/dist/domain/processReactiveRuntime.js +0 -116
  410. package/dist/domain/processReactiveScenario.js +0 -296
  411. package/dist/domain/processReactiveScenarioPreflight.js +0 -95
  412. package/dist/domain/processReactiveTransition.js +0 -187
  413. package/dist/domain/replayMachine.js +0 -320
  414. package/dist/domain/replayMachineRun.js +0 -168
  415. package/dist/domain/replayMachineRuntime.js +0 -296
  416. package/dist/domain/replayMachineValues.js +0 -84
  417. package/dist/domain/runtimeCharacterization.js +0 -84
  418. package/dist/replay/JavaScriptReplayWorker.js +0 -382
  419. package/dist/replay/JavaScriptReplayWorkerTypes.js +0 -1
  420. package/dist/replay/LinuxJavaScriptReplayRunner.js +0 -216
  421. package/dist/replay/LinuxJavaScriptReplaySandbox.js +0 -121
  422. package/dist/replay/LinuxRuntimeClosure.js +0 -44
  423. package/dist/replay/LinuxSeccompPolicy.js +0 -40
  424. package/dist/replay/ReplayOutcome.js +0 -104
  425. package/dist/replay/ReplayProcessLifecycle.js +0 -96
  426. package/dist/replay/ReplaySeccompFile.js +0 -29
  427. package/dist/replay/ReplayWorkerProtocol.js +0 -58
  428. package/dist/replay/SystemJavaScriptReplayHost.js +0 -153
  429. package/dist/server/ProcessCaptureElicitation.js +0 -153
  430. package/dist/server/registerApplicationTools/characterization.js +0 -46
  431. package/dist/server/registerApplicationTools/controlledReplay.js +0 -31
  432. package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +0 -29
  433. package/dist/server/registerReplayMachineTool.js +0 -14
  434. package/skills/reverse-engineer-anything/references/controlled-replay.md +0 -12
@@ -0,0 +1,582 @@
1
+ import { createHash } from "node:crypto";
2
+ import { open } from "node:fs/promises";
3
+ import { constants } from "node:fs";
4
+ import { objcSwiftMetadataSchema, nativeDispatchMetadataResultSchema, } from "../domain/objcSwiftMetadata.js";
5
+ import { AnalysisCancelledError, EvidenceIntegrityError, } from "../domain/errors.js";
6
+ import { decodeSwiftClassVtables } from "./AppleSwiftVtables.js";
7
+ import { createObjcProtocolReader } from "./AppleObjcProtocols.js";
8
+ const hex = (value) => `0x${value.toString(16)}`;
9
+ const decoded = { status: "decoded", reason: null };
10
+ /** Decode validated little-endian 64-bit Apple Objective-C metadata without loading target code. */
11
+ export const decodeAppleDispatchMetadata = (bytes, maxRecords, provenance, architecture = "arm64") => {
12
+ if (bytes.length < 4)
13
+ throw new RangeError("Truncated Mach-O header");
14
+ const { slice, sliceEnd } = selectMachoSlice(bytes, architecture);
15
+ if (slice === 0 && sliceEnd === bytes.length && bytes.length < 32)
16
+ throw new RangeError("Truncated Mach-O header");
17
+ if (slice + 32 > sliceEnd || bytes.readUInt32LE(slice) !== 0xfeedfacf)
18
+ throw new TypeError("Only little-endian 64-bit Mach-O metadata is supported");
19
+ const commands = bytes.readUInt32LE(slice + 16);
20
+ const commandEnd = slice + 32 + bytes.readUInt32LE(slice + 20);
21
+ if (commands > 4096 || commandEnd > sliceEnd)
22
+ throw new RangeError("Malformed Mach-O command bounds");
23
+ const segments = [];
24
+ const sections = [];
25
+ let cursor = slice + 32;
26
+ for (let index = 0; index < commands; index++) {
27
+ if (cursor + 8 > commandEnd)
28
+ throw new RangeError("Truncated load command");
29
+ const kind = bytes.readUInt32LE(cursor), size = bytes.readUInt32LE(cursor + 4);
30
+ if (size < 8 || cursor + size > commandEnd)
31
+ throw new RangeError("Invalid load command size");
32
+ if (kind === 0x19) {
33
+ if (size < 72)
34
+ throw new RangeError("Truncated segment command");
35
+ const address = bytes.readBigUInt64LE(cursor + 24), fileSize = bytes.readBigUInt64LE(cursor + 48), fileOffset = bytes.readBigUInt64LE(cursor + 40);
36
+ if (fileOffset + fileSize > BigInt(sliceEnd - slice))
37
+ throw new RangeError("Segment file range exceeds target bytes");
38
+ segments.push({
39
+ address,
40
+ size: fileSize,
41
+ offset: slice + Number(fileOffset),
42
+ executable: (bytes.readUInt32LE(cursor + 60) & 4) !== 0,
43
+ });
44
+ const count = bytes.readUInt32LE(cursor + 64);
45
+ if (72 + count * 80 > size)
46
+ throw new RangeError("Truncated section table");
47
+ for (let section = 0; section < count; section++) {
48
+ const position = cursor + 72 + section * 80;
49
+ const sectionSize = bytes.readBigUInt64LE(position + 40);
50
+ if (sectionSize > BigInt(Number.MAX_SAFE_INTEGER))
51
+ throw new RangeError("Section size exceeds exact numeric range");
52
+ sections.push({
53
+ name: bytes
54
+ .subarray(position, position + 16)
55
+ .toString("ascii")
56
+ .replace(/\0.*$/u, ""),
57
+ address: bytes.readBigUInt64LE(position + 32),
58
+ size: Number(sectionSize),
59
+ });
60
+ }
61
+ }
62
+ cursor += size;
63
+ }
64
+ const offset = (address, size = 1) => {
65
+ const matches = segments.filter((segment) => address >= segment.address &&
66
+ address + BigInt(size) <= segment.address + segment.size);
67
+ if (matches.length !== 1)
68
+ throw new RangeError(`Unmapped or ambiguous metadata pointer ${hex(address)}`);
69
+ const segment = matches[0];
70
+ if (segment === undefined)
71
+ throw new RangeError("Missing metadata segment");
72
+ return segment.offset + Number(address - segment.address);
73
+ };
74
+ const u32 = (address) => bytes.readUInt32LE(offset(address, 4));
75
+ const pointer = (address) => bytes.readBigUInt64LE(offset(address, 8));
76
+ const location = (address) => ({
77
+ address: hex(address),
78
+ file_offset: offset(address),
79
+ });
80
+ const evidence = (address, description) => [
81
+ {
82
+ kind: "binary_metadata",
83
+ description,
84
+ location: location(address),
85
+ artifact_path: provenance.path,
86
+ artifact_sha256: provenance.sha256,
87
+ },
88
+ ];
89
+ const string = (address) => {
90
+ const start = offset(address);
91
+ let end = start;
92
+ while (end < bytes.length && end - start < 4096 && bytes[end] !== 0)
93
+ end++;
94
+ if (end === bytes.length || end - start >= 4096)
95
+ throw new RangeError("Unterminated or oversized metadata string");
96
+ offset(address, end - start + 1);
97
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(start, end));
98
+ };
99
+ const result = objcSwiftMetadataSchema.parse({ db_save_result: null });
100
+ const failures = [];
101
+ let records = 0, examined = 0, truncated = false;
102
+ const admit = () => {
103
+ if (records >= maxRecords) {
104
+ truncated = true;
105
+ return false;
106
+ }
107
+ records++;
108
+ return true;
109
+ };
110
+ const methods = (list, className, methodType) => {
111
+ if (list === 0n)
112
+ return;
113
+ const flags = u32(list), count = u32(list + 4n), relative = (flags & 0x80000000) !== 0;
114
+ const stride = flags & 0xfffc;
115
+ if (stride !== (relative ? 12 : 24))
116
+ throw new TypeError(`Unsupported method stride/flags at ${hex(list)}`);
117
+ for (let index = 0; index < count; index++) {
118
+ if (!admit())
119
+ break;
120
+ const entry = list + 8n + BigInt(index * stride);
121
+ const rel = (field) => {
122
+ const displacement = bytes.readInt32LE(offset(field, 4));
123
+ const target = field + BigInt(displacement);
124
+ let fileOffset = null;
125
+ try {
126
+ fileOffset = offset(target);
127
+ }
128
+ catch {
129
+ /* serialized target remains unresolved */
130
+ }
131
+ if (admit())
132
+ result.relative_pointers.push({
133
+ field: location(field),
134
+ target: { address: hex(target), file_offset: fileOffset },
135
+ displacement,
136
+ indirectable: false,
137
+ indirect: false,
138
+ decode: fileOffset === null
139
+ ? { status: "partial", reason: "relative_target_unmapped" }
140
+ : decoded,
141
+ evidence: evidence(field, "Signed-relative Objective-C method-list pointer"),
142
+ });
143
+ return target;
144
+ };
145
+ let selectorAddress = relative ? rel(entry) : pointer(entry);
146
+ if (relative && (flags & 0x40000000) === 0)
147
+ selectorAddress = pointer(selectorAddress);
148
+ const implementation = relative ? rel(entry + 8n) : pointer(entry + 16n);
149
+ let implementationLocation = null;
150
+ try {
151
+ if (!segments.some((segment) => segment.executable &&
152
+ implementation >= segment.address &&
153
+ implementation < segment.address + segment.size))
154
+ throw new RangeError("Method implementation is not in an executable segment");
155
+ implementationLocation = location(implementation);
156
+ }
157
+ catch {
158
+ /* external/chained pointers remain unresolved */
159
+ }
160
+ result.objc_dispatch_implementations.push({
161
+ class_name: className,
162
+ selector: string(selectorAddress),
163
+ method_type: methodType,
164
+ implementation_address: implementationLocation?.address ?? null,
165
+ location: location(entry),
166
+ decode: implementationLocation === null
167
+ ? {
168
+ status: "partial",
169
+ reason: "implementation_pointer_unmapped_or_encoded",
170
+ }
171
+ : decoded,
172
+ evidence: evidence(entry, relative
173
+ ? "Encoded relative Objective-C method entry"
174
+ : "Encoded absolute Objective-C method entry"),
175
+ });
176
+ }
177
+ };
178
+ const protocolReader = createObjcProtocolReader({
179
+ readers: {
180
+ u32,
181
+ pointer,
182
+ string,
183
+ location,
184
+ evidence,
185
+ admit,
186
+ i32: (address) => bytes.readInt32LE(offset(address, 4)),
187
+ },
188
+ result,
189
+ failures,
190
+ });
191
+ for (const section of sections.filter(({ name }) => name === "__objc_protolist")) {
192
+ if (section.size % 8 !== 0)
193
+ throw new RangeError("Misaligned Objective-C protocol list");
194
+ for (let index = 0; index < section.size / 8; index++) {
195
+ if (records >= maxRecords) {
196
+ truncated = true;
197
+ break;
198
+ }
199
+ protocolReader.record(pointer(section.address + BigInt(index * 8)));
200
+ }
201
+ }
202
+ const visited = new Set();
203
+ const readClass = (address, meta = false) => {
204
+ if (address === 0n || visited.has(hex(address)) || !admit())
205
+ return;
206
+ visited.add(hex(address));
207
+ const ro = pointer(address + 32n) & ~7n;
208
+ const name = string(pointer(ro + 24n));
209
+ const superclass = pointer(address + 8n);
210
+ const root = (u32(ro) & 2) !== 0;
211
+ let superclassName = null;
212
+ if (superclass !== 0n) {
213
+ try {
214
+ superclassName = string(pointer((pointer(superclass + 32n) & ~7n) + 24n));
215
+ }
216
+ catch {
217
+ failures.push(`Superclass pointer ${hex(superclass)} of ${name} requires unsupported binding/fixup resolution`);
218
+ }
219
+ }
220
+ if (superclass === 0n && !root)
221
+ failures.push(`Superclass of ${name} requires external binding resolution`);
222
+ const ivarList = pointer(ro + 48n);
223
+ let ivarCount = 0;
224
+ if (ivarList !== 0n && !meta) {
225
+ const stride = u32(ivarList), count = u32(ivarList + 4n);
226
+ if (stride !== 32)
227
+ throw new TypeError("Unsupported Objective-C ivar entry size");
228
+ ivarCount = count;
229
+ for (let index = 0; index < count; index++) {
230
+ if (!admit())
231
+ break;
232
+ const entry = ivarList + 8n + BigInt(index * stride);
233
+ const encodedOffset = pointer(entry);
234
+ let value = null;
235
+ try {
236
+ value = u32(encodedOffset);
237
+ }
238
+ catch {
239
+ failures.push(`Unresolved ivar offset pointer ${hex(encodedOffset)}`);
240
+ }
241
+ result.objc_ivars.push({
242
+ class_name: name,
243
+ name: string(pointer(entry + 8n)),
244
+ type_encoding: string(pointer(entry + 16n)),
245
+ offset: value,
246
+ size: u32(entry + 28n),
247
+ alignment: u32(entry + 24n) < 31 ? 2 ** u32(entry + 24n) : null,
248
+ location: location(entry),
249
+ decode: value === null
250
+ ? { status: "partial", reason: "ivar_offset_pointer_unresolved" }
251
+ : decoded,
252
+ evidence: evidence(entry, "Objective-C ivar entry and encoded offset storage"),
253
+ });
254
+ }
255
+ }
256
+ methods(pointer(ro + 32n), name, meta ? "class" : "instance");
257
+ result.objc_classes.push({
258
+ name,
259
+ super_class: superclassName,
260
+ is_meta_class: meta,
261
+ is_root_class: root,
262
+ methods: result.objc_dispatch_implementations
263
+ .filter((item) => item.class_name === name &&
264
+ item.method_type === (meta ? "class" : "instance"))
265
+ .map((item) => ({
266
+ selector: item.selector,
267
+ method_type: item.method_type,
268
+ address: item.implementation_address !== null &&
269
+ BigInt(item.implementation_address) <=
270
+ BigInt(Number.MAX_SAFE_INTEGER)
271
+ ? Number(BigInt(item.implementation_address))
272
+ : null,
273
+ is_required: false,
274
+ is_optional: false,
275
+ })),
276
+ properties: [],
277
+ protocols: protocolReader.list(pointer(ro + 40n)),
278
+ ivar_count: ivarCount,
279
+ instance_size: u32(ro + 8n),
280
+ location: location(address),
281
+ superclass_address: superclass === 0n ? null : hex(superclass),
282
+ metaclass_address: meta ? null : hex(pointer(address)),
283
+ decode: superclassName === null && !root
284
+ ? { status: "partial", reason: "superclass_binding_unresolved" }
285
+ : decoded,
286
+ evidence: evidence(address, "Objective-C class and class_ro_t records"),
287
+ });
288
+ if (!meta) {
289
+ try {
290
+ readClass(pointer(address), true);
291
+ }
292
+ catch (cause) {
293
+ failures.push(`Metaclass of ${name}: ${cause instanceof Error ? cause.message : String(cause)}`);
294
+ }
295
+ }
296
+ };
297
+ for (const section of sections.filter(({ name }) => name === "__objc_classlist")) {
298
+ if (section.size % 8 !== 0)
299
+ throw new RangeError("Misaligned Objective-C class-list size");
300
+ for (let index = 0; index < section.size / 8; index++) {
301
+ if (records >= maxRecords) {
302
+ truncated = true;
303
+ break;
304
+ }
305
+ examined++;
306
+ const field = section.address + BigInt(index * 8);
307
+ try {
308
+ readClass(pointer(field));
309
+ }
310
+ catch (cause) {
311
+ failures.push(`${hex(field)}: ${cause instanceof Error ? cause.message : String(cause)}`);
312
+ }
313
+ }
314
+ }
315
+ const swiftRelative = (field, indirectable = false) => {
316
+ const displacement = bytes.readInt32LE(offset(field, 4));
317
+ const indirect = indirectable && (displacement & 1) !== 0;
318
+ let target = displacement === 0
319
+ ? 0n
320
+ : field + BigInt(indirectable ? displacement & ~1 : displacement);
321
+ let fileOffset = null;
322
+ let reason = null;
323
+ try {
324
+ if (indirect && target !== 0n)
325
+ target = pointer(target);
326
+ if (target !== 0n)
327
+ fileOffset = offset(target);
328
+ }
329
+ catch (cause) {
330
+ reason = cause instanceof Error ? cause.message : String(cause);
331
+ }
332
+ if (admit())
333
+ result.relative_pointers.push({
334
+ field: location(field),
335
+ target: {
336
+ address: target === 0n ? null : hex(target),
337
+ file_offset: fileOffset,
338
+ },
339
+ displacement,
340
+ indirectable,
341
+ indirect,
342
+ decode: reason === null ? decoded : { status: "partial", reason },
343
+ evidence: evidence(field, "Swift ABI signed-relative metadata pointer"),
344
+ });
345
+ if (reason !== null)
346
+ throw new RangeError(reason);
347
+ return target;
348
+ };
349
+ const swiftFailures = [];
350
+ let swiftExamined = 0;
351
+ for (const section of sections.filter(({ name }) => name === "__swift5_proto")) {
352
+ if (section.size % 4 !== 0)
353
+ throw new RangeError("Misaligned Swift conformance section");
354
+ for (let index = 0; index < section.size / 4; index++) {
355
+ if (!admit())
356
+ break;
357
+ swiftExamined++;
358
+ const field = section.address + BigInt(index * 4);
359
+ try {
360
+ const descriptor = swiftRelative(field);
361
+ const flags = u32(descriptor + 12n);
362
+ const protocol = swiftRelative(descriptor, true);
363
+ if ((u32(protocol) & 31) !== 3)
364
+ throw new TypeError("Unsupported Swift protocol descriptor kind");
365
+ const protocolName = string(swiftRelative(protocol + 8n));
366
+ const typeKind = (flags >>> 3) & 7;
367
+ if (typeKind !== 0 && typeKind !== 1)
368
+ throw new TypeError("Unsupported Swift conformance type-reference kind");
369
+ let type = swiftRelative(descriptor + 4n);
370
+ if (typeKind === 1)
371
+ type = pointer(type);
372
+ if (![16, 17, 18].includes(u32(type) & 31))
373
+ throw new TypeError("Unsupported Swift type descriptor kind");
374
+ const typeName = string(swiftRelative(type + 8n));
375
+ const witness = swiftRelative(descriptor + 8n);
376
+ const staticWitness = witness !== 0n && (flags & ~0x38) === 0 && (u32(type) & 0x80) === 0;
377
+ let witnessReason = staticWitness
378
+ ? null
379
+ : "Conditional, generic, resilient or missing static witness table is not decoded";
380
+ if (staticWitness && pointer(witness) !== descriptor)
381
+ witnessReason =
382
+ "Witness-table conformance header is unresolved or encoded";
383
+ result.swift_conformances.push({
384
+ type_name: typeName,
385
+ protocol_name: protocolName,
386
+ module: null,
387
+ witness_table: witness === 0n
388
+ ? { address: null, file_offset: null }
389
+ : location(witness),
390
+ location: location(descriptor),
391
+ decode: witnessReason === null
392
+ ? decoded
393
+ : {
394
+ status: "partial",
395
+ reason: witnessReason,
396
+ },
397
+ evidence: evidence(descriptor, "Swift protocol conformance descriptor and directly encoded type/protocol names"),
398
+ });
399
+ if (witnessReason !== null) {
400
+ swiftFailures.push(`${typeName}: ${witnessReason}`);
401
+ continue;
402
+ }
403
+ const count = u32(protocol + 16n);
404
+ const signatureCount = u32(protocol + 12n);
405
+ if (count > 20_000 || signatureCount > 20_000)
406
+ throw new RangeError("Swift witness requirement count exceeds 20000");
407
+ for (let slot = 0; slot < count; slot++) {
408
+ if (!admit())
409
+ break;
410
+ const entry = witness + BigInt((slot + 1) * 8);
411
+ const implementation = pointer(entry);
412
+ const requirementFlags = u32(protocol + 24n + BigInt(signatureCount * 12 + slot * 8));
413
+ const kind = requirementFlags & 15;
414
+ const synchronousFunction = kind >= 1 && kind <= 4 && (requirementFlags & 0x20) === 0;
415
+ const executable = synchronousFunction &&
416
+ segments.some((segment) => segment.executable &&
417
+ implementation >= segment.address &&
418
+ implementation < segment.address + segment.size);
419
+ result.swift_dispatch_slots.push({
420
+ owner: `${typeName}: ${protocolName}`,
421
+ table_kind: "witness_table",
422
+ slot_index: slot + 1,
423
+ requirement: null,
424
+ implementation: null,
425
+ implementation_address: executable ? hex(implementation) : null,
426
+ thunk_address: null,
427
+ location: location(entry),
428
+ decode: executable
429
+ ? decoded
430
+ : {
431
+ status: "partial",
432
+ reason: "Witness slot is non-function, async, nil, external, authenticated or encoded; implementation target is unresolved",
433
+ },
434
+ evidence: evidence(entry, "Static Swift witness slot, indexed after the conformance-descriptor header"),
435
+ });
436
+ }
437
+ }
438
+ catch (cause) {
439
+ swiftFailures.push(`${hex(field)}: ${cause instanceof Error ? cause.message : String(cause)}`);
440
+ }
441
+ }
442
+ }
443
+ result.coverage.push({
444
+ facet: "swift_conformances_static_witness_slots",
445
+ status: swiftFailures.length > 0 || truncated ? "partial" : "complete",
446
+ reason: [...swiftFailures, ...(truncated ? ["max_records_reached"] : [])].join("; ") || null,
447
+ examined: swiftExamined,
448
+ decoded: result.swift_conformances.length,
449
+ });
450
+ const typeEntries = [];
451
+ for (const section of sections.filter(({ name }) => name === "__swift5_types")) {
452
+ if (section.size % 4 !== 0)
453
+ throw new RangeError("Misaligned Swift type section");
454
+ for (let index = 0; index < section.size / 4 && index < maxRecords; index++)
455
+ typeEntries.push(section.address + BigInt(index * 4));
456
+ if (section.size / 4 > maxRecords)
457
+ truncated = true;
458
+ }
459
+ decodeSwiftClassVtables({
460
+ entries: typeEntries,
461
+ result,
462
+ readers: {
463
+ u32,
464
+ relative: swiftRelative,
465
+ string,
466
+ location,
467
+ evidence,
468
+ admit,
469
+ executable: (address) => segments.some((segment) => segment.executable &&
470
+ address >= segment.address &&
471
+ address < segment.address + segment.size),
472
+ },
473
+ });
474
+ result.coverage.push({
475
+ facet: "objc_class_method_ivar_metadata",
476
+ status: failures.length > 0 || truncated ? "partial" : "complete",
477
+ reason: [...failures, ...(truncated ? ["max_records_reached"] : [])].join("; ") ||
478
+ null,
479
+ examined,
480
+ decoded: result.objc_classes.length,
481
+ });
482
+ result.coverage.push({
483
+ facet: "binary_relative_pointers",
484
+ status: truncated ||
485
+ result.relative_pointers.some((item) => item.decode.status !== "decoded")
486
+ ? "partial"
487
+ : "complete",
488
+ reason: truncated
489
+ ? "max_records_reached"
490
+ : result.relative_pointers.some((item) => item.decode.status !== "decoded")
491
+ ? "relative_pointer_targets_unresolved"
492
+ : null,
493
+ examined: result.relative_pointers.length,
494
+ decoded: result.relative_pointers.filter((item) => item.decode.status === "decoded").length,
495
+ });
496
+ for (const facet of [
497
+ "objc_properties_categories",
498
+ "swift_generic_resilient_witnesses_overrides_async_coroutines",
499
+ ])
500
+ result.coverage.push({
501
+ facet,
502
+ status: "unsupported",
503
+ reason: "This reader admits validated 64-bit Objective-C class/ivar/method lists and simple Swift conformance/static witness records; chained fixups, generic/resilient tables and other metadata families are not decoded",
504
+ examined: 0,
505
+ decoded: 0,
506
+ });
507
+ return objcSwiftMetadataSchema.parse(result);
508
+ };
509
+ /** Read digest-verified target bytes under a 64 MiB static metadata budget. */
510
+ export const inspectAppleDispatchMetadata = async (target, maxRecords, signal) => {
511
+ if (target.kind !== "executable" || target.format !== "mach-o")
512
+ throw new TypeError("Apple dispatch metadata requires a Mach-O target");
513
+ const handle = await open(target.path, constants.O_RDONLY | constants.O_NOFOLLOW);
514
+ try {
515
+ const before = await handle.stat();
516
+ if (!before.isFile() || before.size > 64 * 1024 * 1024)
517
+ throw new RangeError("Apple metadata target must be a regular file no larger than 64 MiB");
518
+ if (signal?.aborted)
519
+ throw new AnalysisCancelledError("inspect_native_dispatch_metadata");
520
+ const bytes = await handle.readFile({ signal });
521
+ const digest = createHash("sha256").update(bytes).digest("hex");
522
+ if (digest !== target.sha256)
523
+ throw new EvidenceIntegrityError("Apple metadata target digest changed after session binding");
524
+ return nativeDispatchMetadataResultSchema.parse({
525
+ target_sha256: target.sha256,
526
+ provider: {
527
+ id: "native-macos",
528
+ name: "macOS native inspection utilities",
529
+ version: "apple-metadata-reader-1",
530
+ },
531
+ analysis_profile_digest: null,
532
+ result: decodeAppleDispatchMetadata(bytes, maxRecords, { path: target.path, sha256: digest }, target.architecture),
533
+ });
534
+ }
535
+ finally {
536
+ await handle.close();
537
+ }
538
+ };
539
+ const selectMachoSlice = (bytes, architecture) => {
540
+ const magic = bytes.readUInt32BE(0);
541
+ const littleEndian = magic === 0xbebafeca || magic === 0xbfbafeca;
542
+ if (magic !== 0xcafebabe && magic !== 0xcafebabf && !littleEndian)
543
+ return { slice: 0, sliceEnd: bytes.length };
544
+ const fat64 = magic === 0xcafebabf || magic === 0xbfbafeca;
545
+ const stride = fat64 ? 32 : 20;
546
+ const readUInt32 = littleEndian
547
+ ? (offset) => bytes.readUInt32LE(offset)
548
+ : (offset) => bytes.readUInt32BE(offset);
549
+ const readUInt64 = littleEndian
550
+ ? (offset) => bytes.readBigUInt64LE(offset)
551
+ : (offset) => bytes.readBigUInt64BE(offset);
552
+ const byteOrder = littleEndian ? "little-endian" : "big-endian";
553
+ const malformed = (reason) => new RangeError(`${reason} (FAT header byte order: ${byteOrder})`);
554
+ const invalid = (reason) => new TypeError(`${reason} (FAT header byte order: ${byteOrder})`);
555
+ if (bytes.length < 8)
556
+ throw malformed("Malformed FAT architecture table");
557
+ const count = readUInt32(4);
558
+ const headerEnd = 8 + count * stride;
559
+ if (count > 128 || headerEnd > bytes.length)
560
+ throw malformed("Malformed FAT architecture table");
561
+ const cpu = architecture === "arm64" ? 0x0100000c : 0x01000007;
562
+ let selected;
563
+ for (let index = 0; index < count; index++) {
564
+ const offset = 8 + index * stride;
565
+ if (readUInt32(offset) !== cpu)
566
+ continue;
567
+ if (selected !== undefined)
568
+ throw invalid("Ambiguous FAT architecture slice");
569
+ const start = fat64
570
+ ? readUInt64(offset + 8)
571
+ : BigInt(readUInt32(offset + 8));
572
+ const size = fat64
573
+ ? readUInt64(offset + 16)
574
+ : BigInt(readUInt32(offset + 12));
575
+ if (start < BigInt(headerEnd) || start + size > BigInt(bytes.length))
576
+ throw malformed("FAT slice exceeds file");
577
+ selected = { slice: Number(start), sliceEnd: Number(start + size) };
578
+ }
579
+ if (selected === undefined)
580
+ throw invalid("Requested FAT architecture is absent");
581
+ return selected;
582
+ };
@@ -0,0 +1,88 @@
1
+ /** Read protocol lists and absolute protocol method declarations with cycle-safe identities. */
2
+ export const createObjcProtocolReader = (input) => {
3
+ const { readers: read, result, failures } = input;
4
+ const visited = new Set();
5
+ const name = (address) => read.string(read.pointer(address + 8n));
6
+ const list = (address) => {
7
+ if (address === 0n)
8
+ return [];
9
+ const count = read.pointer(address);
10
+ if (count > 20000n)
11
+ throw new RangeError("Protocol list exceeds 20000 entries");
12
+ const names = [];
13
+ for (let index = 0n; index < count; index++) {
14
+ if (!read.admit())
15
+ break;
16
+ const protocol = read.pointer(address + 8n + index * 8n);
17
+ names.push(name(protocol));
18
+ record(protocol);
19
+ }
20
+ return names;
21
+ };
22
+ const methods = (address, required, instance) => {
23
+ const output = [];
24
+ if (address === 0n)
25
+ return output;
26
+ const flags = read.u32(address), count = read.u32(address + 4n);
27
+ const relative = (flags & 0x80000000) !== 0;
28
+ const stride = flags & 0xfffc;
29
+ if (stride !== (relative ? 12 : 24))
30
+ throw new TypeError("Unsupported Objective-C protocol method entry size");
31
+ for (let index = 0; index < count; index++) {
32
+ if (!read.admit())
33
+ break;
34
+ const entry = address + 8n + BigInt(index * stride);
35
+ let selector = relative
36
+ ? entry + BigInt(read.i32(entry))
37
+ : read.pointer(entry);
38
+ if (relative && (flags & 0x40000000) === 0)
39
+ selector = read.pointer(selector);
40
+ output.push({
41
+ selector: read.string(selector),
42
+ method_type: instance ? "instance" : "class",
43
+ address: null,
44
+ is_required: required,
45
+ is_optional: !required,
46
+ });
47
+ }
48
+ return output;
49
+ };
50
+ const record = (address) => {
51
+ if (address === 0n || visited.has(address) || !read.admit())
52
+ return;
53
+ visited.add(address);
54
+ try {
55
+ if (read.u32(address + 64n) < 72)
56
+ throw new RangeError("Truncated Objective-C protocol declaration");
57
+ const protocolName = name(address);
58
+ const adopted = list(read.pointer(address + 16n));
59
+ const required = [
60
+ ...methods(read.pointer(address + 24n), true, true),
61
+ ...methods(read.pointer(address + 32n), true, false),
62
+ ];
63
+ const optional = [
64
+ ...methods(read.pointer(address + 40n), false, true),
65
+ ...methods(read.pointer(address + 48n), false, false),
66
+ ];
67
+ result.objc_protocols.push({
68
+ name: protocolName,
69
+ methods: required,
70
+ optional_methods: optional,
71
+ properties: [],
72
+ });
73
+ result.objc_protocol_records.push({
74
+ name: protocolName,
75
+ adopted_protocols: adopted,
76
+ methods: required,
77
+ optional_methods: optional,
78
+ location: read.location(address),
79
+ decode: { status: "decoded", reason: null },
80
+ evidence: read.evidence(address, "Objective-C protocol declaration and encoded method lists; IMP fields are not handler targets"),
81
+ });
82
+ }
83
+ catch (cause) {
84
+ failures.push(`Protocol 0x${address.toString(16)}: ${cause instanceof Error ? cause.message : String(cause)}`);
85
+ }
86
+ };
87
+ return { list, record };
88
+ };