rea-agents 2.0.0 → 2.2.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 (273) hide show
  1. package/README.md +103 -38
  2. package/bridge/ghidra/ReaGhidraBridge.java +96 -11
  3. package/dist/application/AndroidApplicationService.js +17 -0
  4. package/dist/application/AppleApplicationService.js +17 -0
  5. package/dist/application/ArtifactExtraction.js +1 -1
  6. package/dist/application/ArtifactInventory/classify.js +42 -0
  7. package/dist/application/ArtifactInventory/hash.js +43 -0
  8. package/dist/application/ArtifactInventory/reader.js +41 -0
  9. package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
  10. package/dist/application/ArtifactInventory/scanReader.js +124 -0
  11. package/dist/application/ArtifactInventory/types.js +10 -0
  12. package/dist/application/ArtifactInventory.js +9 -351
  13. package/dist/application/AuthorizedArtifactInventory.js +2 -2
  14. package/dist/application/BinarySession.js +47 -270
  15. package/dist/application/BinarySessionExecution.js +28 -0
  16. package/dist/application/BinarySessionOpen.js +39 -0
  17. package/dist/application/BinarySessionRecords.js +149 -0
  18. package/dist/application/BinarySessionStatus.js +75 -0
  19. package/dist/application/CapabilityInventory.js +24 -2
  20. package/dist/application/ClientRegistrationStatus.js +11 -4
  21. package/dist/application/CrossVersionInventory.js +8 -2
  22. package/dist/application/CrossVersionInvestigation.js +1 -23
  23. package/dist/application/CrossVersionInvestigationCollections.js +23 -0
  24. package/dist/application/DirectAnalysis.js +47 -44
  25. package/dist/application/Doctor.js +156 -238
  26. package/dist/application/DoctorDiagnostics.js +180 -0
  27. package/dist/application/ElectronBoundaryAnalysis.js +23 -7
  28. package/dist/application/ElectronBoundaryGraphWindows.js +32 -8
  29. package/dist/application/EnhancedToolPagination.js +22 -0
  30. package/dist/application/EnhancedToolTypes.js +4 -0
  31. package/dist/application/EnhancedTools.js +20 -37
  32. package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
  33. package/dist/application/InventoryProjectionEvidence.js +41 -0
  34. package/dist/application/InvestigationProviders.js +12 -0
  35. package/dist/application/InvestigationWorkspaceStore.js +24 -10
  36. package/dist/application/JavaScriptArtifactAnalysis.js +45 -6
  37. package/dist/application/JavaScriptArtifactFiles.js +6 -2
  38. package/dist/application/JavaScriptArtifactGraphBuilder.js +23 -1
  39. package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
  40. package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
  41. package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
  42. package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
  43. package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
  44. package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
  45. package/dist/application/JavaScriptArtifactReconstruction.js +1 -1
  46. package/dist/application/JavaScriptJsonModules.js +39 -0
  47. package/dist/application/JavaScriptModuleRelationships.js +262 -0
  48. package/dist/application/JavaScriptReplayPermission.js +16 -0
  49. package/dist/application/JavaScriptReplayService.js +182 -156
  50. package/dist/application/LinuxHopper.js +10 -0
  51. package/dist/application/MacHopper.js +22 -11
  52. package/dist/application/NodeRuntimeCharacterizationService.js +196 -0
  53. package/dist/application/PermissionAuthority.js +106 -63
  54. package/dist/application/ProcessCaptureCapability.js +1 -1
  55. package/dist/application/ProcessCapturePermission.js +13 -0
  56. package/dist/application/ProcessCli.js +2 -12
  57. package/dist/application/ProcessHarness.js +1 -1
  58. package/dist/application/ProcessPairedExperiment.js +72 -0
  59. package/dist/application/ProjectPermissionStore.js +48 -9
  60. package/dist/application/RealHopperAssertions.js +76 -0
  61. package/dist/application/ReconstructionCoverageService.js +69 -0
  62. package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
  63. package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
  64. package/dist/application/Setup.js +148 -260
  65. package/dist/application/SetupClientConfiguration.js +224 -0
  66. package/dist/application/SetupClients.js +24 -2
  67. package/dist/application/SetupPlan.js +124 -12
  68. package/dist/application/SetupSkill.js +54 -36
  69. package/dist/application/SupportedClients.js +1 -0
  70. package/dist/application/Uninstall.js +12 -3
  71. package/dist/application/Upgrade.js +16 -1
  72. package/dist/application/WindowsCapabilities.js +86 -0
  73. package/dist/artifacts/AsarArtifactReader.js +11 -0
  74. package/dist/browser/BrowserProcessStartup.js +88 -0
  75. package/dist/browser/CdpCaptureDocuments.js +12 -8
  76. package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
  77. package/dist/browser/CdpCaptureEventHandlers.js +336 -0
  78. package/dist/browser/CdpCaptureEventHelpers.js +71 -0
  79. package/dist/browser/CdpCaptureEventState.js +1 -0
  80. package/dist/browser/CdpCaptureEventTypes.js +1 -0
  81. package/dist/browser/CdpCaptureEvents.js +29 -496
  82. package/dist/browser/CdpObservationSession.js +51 -8
  83. package/dist/browser/CdpPageCapture.js +12 -133
  84. package/dist/browser/CdpPageCaptureScripts.js +97 -0
  85. package/dist/browser/CdpPageCaptureWorkers.js +46 -0
  86. package/dist/browser/CdpWebMcpDiscovery.js +38 -14
  87. package/dist/browser/PngVisualDiff.js +9 -2
  88. package/dist/catalogIdentity.js +4 -0
  89. package/dist/cli/artifactCommands.js +82 -0
  90. package/dist/cli/coreAnalysisCommands.js +232 -0
  91. package/dist/cli/managedCommands.js +397 -0
  92. package/dist/cli/managedProjectGraphCommand.js +24 -0
  93. package/dist/cli/options.js +9 -0
  94. package/dist/cli/setupCommands.js +113 -0
  95. package/dist/cli/types.js +1 -0
  96. package/dist/cli/utilityCommands.js +122 -0
  97. package/dist/cli.js +10 -768
  98. package/dist/cliApplicationCommands.js +118 -4
  99. package/dist/cliBrowserAdvancedCommands.js +73 -16
  100. package/dist/cliBrowserCommands.js +39 -115
  101. package/dist/cliCommandNames.js +4 -0
  102. package/dist/cliElectronCommands.js +33 -62
  103. package/dist/cliEvidenceCommands.js +13 -2
  104. package/dist/cliInvestigationCommands.js +53 -10
  105. package/dist/cliObservationOptions.js +137 -0
  106. package/dist/cliPolicyCommands.js +80 -46
  107. package/dist/cliSetup.js +306 -0
  108. package/dist/config/environment.js +107 -0
  109. package/dist/config/parseConfig.js +228 -0
  110. package/dist/config/parsers.js +68 -0
  111. package/dist/config/permissions.js +30 -0
  112. package/dist/config/types.js +1 -0
  113. package/dist/config.js +1 -375
  114. package/dist/contracts/applicationToolContracts.js +134 -0
  115. package/dist/contracts/electronToolContracts.js +51 -3
  116. package/dist/contracts/managedToolContracts.js +8 -3
  117. package/dist/contracts/managedWorkflowToolContracts.js +3 -3
  118. package/dist/contracts/providerSelection.js +2 -0
  119. package/dist/contracts/sessionStatusContract.js +26 -0
  120. package/dist/contracts/toolContractTypes.js +12 -1
  121. package/dist/contracts/toolContracts.js +5 -12
  122. package/dist/contracts/toolEffects.js +14 -0
  123. package/dist/contracts/toolOutputSchemaGroups.js +274 -0
  124. package/dist/contracts/toolOutputSchemaPrimitives.js +328 -0
  125. package/dist/contracts/toolOutputSchemas.js +2 -550
  126. package/dist/domain/analysisErrorPresentation.js +234 -0
  127. package/dist/domain/analysisErrorProjection.js +284 -0
  128. package/dist/domain/androidApplication.js +206 -0
  129. package/dist/domain/appleApplication.js +221 -0
  130. package/dist/domain/artifactComparison.js +34 -15
  131. package/dist/domain/binaryTarget.js +87 -37
  132. package/dist/domain/boundedCartesianProjection.js +15 -0
  133. package/dist/domain/browserObservation.js +1 -285
  134. package/dist/domain/browserObservationSchemas.js +286 -0
  135. package/dist/domain/electronStaticAnalysisBrowser.js +14 -2
  136. package/dist/domain/errors.js +4 -486
  137. package/dist/domain/functionComparison.js +4 -165
  138. package/dist/domain/functionComparisonDimensions.js +164 -0
  139. package/dist/domain/javascriptApplicationVersionItems.js +18 -6
  140. package/dist/domain/javascriptApplicationVersionKeys.js +8 -8
  141. package/dist/domain/javascriptExportInstrumentation.js +97 -0
  142. package/dist/domain/javascriptFeatureTraversal.js +19 -7
  143. package/dist/domain/javascriptRuntimeStaticCandidates.js +3 -1
  144. package/dist/domain/javascriptSemanticAnalysis.js +386 -0
  145. package/dist/domain/javascriptSemanticIr.js +30 -0
  146. package/dist/domain/javascriptSemanticProjection.js +366 -0
  147. package/dist/domain/javascriptSemanticState.js +40 -0
  148. package/dist/domain/javascriptSemanticTraversal.js +22 -0
  149. package/dist/domain/javascriptSemanticValues.js +352 -0
  150. package/dist/domain/javascriptStaticAnalysis.js +5 -221
  151. package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
  152. package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
  153. package/dist/domain/javascriptStaticAnalysisHelpers.js +71 -2
  154. package/dist/domain/knownPageCoverage.js +21 -0
  155. package/dist/domain/managedApplicationGraph.js +14 -364
  156. package/dist/domain/managedApplicationGraphCoverage.js +170 -0
  157. package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
  158. package/dist/domain/managedApplicationGraphNodes.js +336 -0
  159. package/dist/domain/managedArtifact.js +16 -8
  160. package/dist/domain/managedMemberComparison.js +37 -391
  161. package/dist/domain/managedMemberComparisonCoverage.js +72 -0
  162. package/dist/domain/managedMemberComparisonMatch.js +356 -0
  163. package/dist/domain/managedNativeVerification.js +27 -389
  164. package/dist/domain/managedNativeVerificationMatch.js +272 -0
  165. package/dist/domain/managedNativeVerificationSchemas.js +141 -0
  166. package/dist/domain/managedReconstruction.js +82 -69
  167. package/dist/domain/managedRuntimeCorrelation.js +12 -3
  168. package/dist/domain/nodeRuntimeCharacterization.js +66 -0
  169. package/dist/domain/permissionPolicy.js +2 -0
  170. package/dist/domain/processComparison.js +19 -0
  171. package/dist/domain/processPairedExperiment.js +128 -0
  172. package/dist/domain/reconstructionCoverage.js +387 -0
  173. package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
  174. package/dist/domain/reconstructionVerificationSchemas.js +8 -0
  175. package/dist/domain/replayMachine.js +316 -0
  176. package/dist/domain/replayMachineRuntime.js +215 -0
  177. package/dist/domain/runtimeCharacterization.js +85 -0
  178. package/dist/domain/runtimeIdentification.js +210 -0
  179. package/dist/domain/webBundleAnalyzer.js +3 -409
  180. package/dist/domain/webBundleAnalyzerAst.js +77 -0
  181. package/dist/domain/webBundleAnalyzerInspection.js +307 -0
  182. package/dist/domain/webBundleAnalyzerResult.js +120 -0
  183. package/dist/dotnet/ManagedArtifactInspector.js +50 -29
  184. package/dist/dotnet/ManagedMemberInspector.js +51 -785
  185. package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
  186. package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
  187. package/dist/dotnet/ManagedMemberRows.js +120 -0
  188. package/dist/dotnet/ManagedMetadataInventory.js +42 -306
  189. package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
  190. package/dist/dotnet/ManagedMetadataLayout.js +48 -111
  191. package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
  192. package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
  193. package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
  194. package/dist/dotnet/ManagedNativeBoundaryInspector.js +102 -350
  195. package/dist/dotnet/ManagedPeReader.js +59 -28
  196. package/dist/evaluation/CodexAgentEval.js +132 -0
  197. package/dist/generatedPackageMetadata.js +2 -2
  198. package/dist/ghidra/GhidraClient.js +76 -91
  199. package/dist/ghidra/GhidraClientStartup.js +29 -0
  200. package/dist/ghidra/GhidraClientWire.js +34 -0
  201. package/dist/ghidra/GhidraDefaults.js +1 -1
  202. package/dist/ghidra/GhidraDiagnostics.js +6 -1
  203. package/dist/ghidra/GhidraInstallation.js +20 -15
  204. package/dist/ghidra/GhidraLauncher.js +93 -29
  205. package/dist/ghidra/GhidraProvider.js +61 -161
  206. package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
  207. package/dist/ghidra/GhidraSessionValues.js +2 -0
  208. package/dist/ghidra/GhidraSocketConnection.js +44 -7
  209. package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
  210. package/dist/ghidra/GhidraTransport.js +71 -0
  211. package/dist/identity.js +4 -2
  212. package/dist/main/messages.js +5 -0
  213. package/dist/main/reload.js +49 -0
  214. package/dist/main/shutdown.js +25 -0
  215. package/dist/main/startup.js +14 -0
  216. package/dist/main/state.js +26 -0
  217. package/dist/main/transport.js +61 -0
  218. package/dist/main/types.js +1 -0
  219. package/dist/main.js +35 -146
  220. package/dist/process/PrivateRuntimeRoot.js +3 -2
  221. package/dist/process/ProcessOwnership.js +35 -0
  222. package/dist/process/ProviderProcess.js +2 -0
  223. package/dist/replay/JavaScriptReplayWorker.js +64 -50
  224. package/dist/replay/LinuxJavaScriptReplayRunner.js +173 -390
  225. package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
  226. package/dist/replay/ReplayOutcome.js +95 -0
  227. package/dist/replay/ReplayProcessLifecycle.js +71 -0
  228. package/dist/server/ProcessCaptureElicitation.js +157 -0
  229. package/dist/server/createServer.js +124 -56
  230. package/dist/server/javascriptApplicationResult.js +85 -0
  231. package/dist/server/registerApplicationTools/characterization.js +57 -0
  232. package/dist/server/registerApplicationTools/compareVersions.js +34 -0
  233. package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
  234. package/dist/server/registerApplicationTools/coverage.js +84 -0
  235. package/dist/server/registerApplicationTools/helpers.js +42 -0
  236. package/dist/server/registerApplicationTools/traceFeature.js +26 -0
  237. package/dist/server/registerApplicationTools/types.js +1 -0
  238. package/dist/server/registerApplicationTools.js +10 -112
  239. package/dist/server/registerBrowserTools.js +59 -83
  240. package/dist/server/registerElectronTools.js +48 -49
  241. package/dist/server/registerEnhancedTools.js +34 -42
  242. package/dist/server/registerEvidenceResources.js +56 -0
  243. package/dist/server/registerInvestigationTools/helpers.js +74 -0
  244. package/dist/server/registerInvestigationTools/types.js +1 -0
  245. package/dist/server/registerInvestigationTools.js +83 -116
  246. package/dist/server/registerJavaScriptApplicationGraphResource.js +69 -0
  247. package/dist/server/registerManagedTools.js +18 -1
  248. package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
  249. package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
  250. package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
  251. package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
  252. package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
  253. package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
  254. package/dist/server/registerManagedWorkflowTools/types.js +1 -0
  255. package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
  256. package/dist/server/registerManagedWorkflowTools.js +10 -274
  257. package/dist/server/registerOfficialTools.js +73 -59
  258. package/dist/server/registerSessionRecordTools.js +137 -0
  259. package/dist/server/registerSessionStatusTool.js +97 -26
  260. package/dist/server/registerSessionTools.js +60 -164
  261. package/dist/server/sessionAvailabilityPolicy.js +10 -0
  262. package/dist/server/toolRegistrationOptions.js +101 -3
  263. package/dist/server/toolResult.js +15 -4
  264. package/package.json +11 -11
  265. package/skills/reverse-engineer-anything/SKILL.md +76 -0
  266. package/skills/reverse-engineer-anything/references/controlled-replay.md +12 -0
  267. package/skills/reverse-engineer-anything/references/evidence-workflows.md +33 -0
  268. package/skills/reverse-engineer-anything/references/javascript-applications.md +25 -0
  269. package/skills/reverse-engineer-anything/references/native-and-artifacts.md +36 -0
  270. package/skills/reverse-engineer-anything/references/runtime-observation.md +24 -0
  271. package/scripts/prepare-node-pty.mjs +0 -35
  272. package/scripts/rebuild-native.mjs +0 -22
  273. package/skills/rea-analysis/SKILL.md +0 -222
@@ -0,0 +1,427 @@
1
+ const opcode = (code) => OPCODES.get(code);
2
+ const OPCODES = new Map([
3
+ [0x00, { name: "nop", operand: "none" }],
4
+ [0x01, { name: "break", operand: "none" }],
5
+ [0x02, { name: "ldarg.0", operand: "none" }],
6
+ [0x03, { name: "ldarg.1", operand: "none" }],
7
+ [0x04, { name: "ldarg.2", operand: "none" }],
8
+ [0x05, { name: "ldarg.3", operand: "none" }],
9
+ [0x06, { name: "ldloc.0", operand: "none" }],
10
+ [0x07, { name: "ldloc.1", operand: "none" }],
11
+ [0x08, { name: "ldloc.2", operand: "none" }],
12
+ [0x09, { name: "ldloc.3", operand: "none" }],
13
+ [0x0a, { name: "stloc.0", operand: "none" }],
14
+ [0x0b, { name: "stloc.1", operand: "none" }],
15
+ [0x0c, { name: "stloc.2", operand: "none" }],
16
+ [0x0d, { name: "stloc.3", operand: "none" }],
17
+ [0x0e, { name: "ldarg.s", operand: "short-var" }],
18
+ [0x0f, { name: "ldarga.s", operand: "short-var" }],
19
+ [0x10, { name: "starg.s", operand: "short-var" }],
20
+ [0x11, { name: "ldloc.s", operand: "short-var" }],
21
+ [0x12, { name: "ldloca.s", operand: "short-var" }],
22
+ [0x13, { name: "stloc.s", operand: "short-var" }],
23
+ [0x14, { name: "ldnull", operand: "none" }],
24
+ [0x15, { name: "ldc.i4.m1", operand: "none" }],
25
+ [0x16, { name: "ldc.i4.0", operand: "none" }],
26
+ [0x17, { name: "ldc.i4.1", operand: "none" }],
27
+ [0x18, { name: "ldc.i4.2", operand: "none" }],
28
+ [0x19, { name: "ldc.i4.3", operand: "none" }],
29
+ [0x1a, { name: "ldc.i4.4", operand: "none" }],
30
+ [0x1b, { name: "ldc.i4.5", operand: "none" }],
31
+ [0x1c, { name: "ldc.i4.6", operand: "none" }],
32
+ [0x1d, { name: "ldc.i4.7", operand: "none" }],
33
+ [0x1e, { name: "ldc.i4.8", operand: "none" }],
34
+ [0x1f, { name: "ldc.i4.s", operand: "short-i" }],
35
+ [0x20, { name: "ldc.i4", operand: "i" }],
36
+ [0x21, { name: "ldc.i8", operand: "i8" }],
37
+ [0x22, { name: "ldc.r4", operand: "r4" }],
38
+ [0x23, { name: "ldc.r8", operand: "r8" }],
39
+ [0x25, { name: "dup", operand: "none" }],
40
+ [0x26, { name: "pop", operand: "none" }],
41
+ [0x27, { name: "jmp", operand: "method" }],
42
+ [0x28, { name: "call", operand: "method" }],
43
+ [0x29, { name: "calli", operand: "signature" }],
44
+ [0x2a, { name: "ret", operand: "none" }],
45
+ [0x2b, { name: "br.s", operand: "short-branch" }],
46
+ [0x2c, { name: "brfalse.s", operand: "short-branch" }],
47
+ [0x2d, { name: "brtrue.s", operand: "short-branch" }],
48
+ [0x2e, { name: "beq.s", operand: "short-branch" }],
49
+ [0x2f, { name: "bge.s", operand: "short-branch" }],
50
+ [0x30, { name: "bgt.s", operand: "short-branch" }],
51
+ [0x31, { name: "ble.s", operand: "short-branch" }],
52
+ [0x32, { name: "blt.s", operand: "short-branch" }],
53
+ [0x33, { name: "bne.un.s", operand: "short-branch" }],
54
+ [0x34, { name: "bge.un.s", operand: "short-branch" }],
55
+ [0x35, { name: "bgt.un.s", operand: "short-branch" }],
56
+ [0x36, { name: "ble.un.s", operand: "short-branch" }],
57
+ [0x37, { name: "blt.un.s", operand: "short-branch" }],
58
+ [0x38, { name: "br", operand: "branch" }],
59
+ [0x39, { name: "brfalse", operand: "branch" }],
60
+ [0x3a, { name: "brtrue", operand: "branch" }],
61
+ [0x3b, { name: "beq", operand: "branch" }],
62
+ [0x3c, { name: "bge", operand: "branch" }],
63
+ [0x3d, { name: "bgt", operand: "branch" }],
64
+ [0x3e, { name: "ble", operand: "branch" }],
65
+ [0x3f, { name: "blt", operand: "branch" }],
66
+ [0x40, { name: "bne.un", operand: "branch" }],
67
+ [0x41, { name: "bge.un", operand: "branch" }],
68
+ [0x42, { name: "bgt.un", operand: "branch" }],
69
+ [0x43, { name: "ble.un", operand: "branch" }],
70
+ [0x44, { name: "blt.un", operand: "branch" }],
71
+ [0x45, { name: "switch", operand: "switch" }],
72
+ [0x46, { name: "ldind.i1", operand: "none" }],
73
+ [0x47, { name: "ldind.u1", operand: "none" }],
74
+ [0x48, { name: "ldind.i2", operand: "none" }],
75
+ [0x49, { name: "ldind.u2", operand: "none" }],
76
+ [0x4a, { name: "ldind.i4", operand: "none" }],
77
+ [0x4b, { name: "ldind.u4", operand: "none" }],
78
+ [0x4c, { name: "ldind.i8", operand: "none" }],
79
+ [0x4d, { name: "ldind.i", operand: "none" }],
80
+ [0x4e, { name: "ldind.r4", operand: "none" }],
81
+ [0x4f, { name: "ldind.r8", operand: "none" }],
82
+ [0x50, { name: "ldind.ref", operand: "none" }],
83
+ [0x51, { name: "stind.ref", operand: "none" }],
84
+ [0x52, { name: "stind.i1", operand: "none" }],
85
+ [0x53, { name: "stind.i2", operand: "none" }],
86
+ [0x54, { name: "stind.i4", operand: "none" }],
87
+ [0x55, { name: "stind.i8", operand: "none" }],
88
+ [0x56, { name: "stind.r4", operand: "none" }],
89
+ [0x57, { name: "stind.r8", operand: "none" }],
90
+ [0x58, { name: "add", operand: "none" }],
91
+ [0x59, { name: "sub", operand: "none" }],
92
+ [0x5a, { name: "mul", operand: "none" }],
93
+ [0x5b, { name: "div", operand: "none" }],
94
+ [0x5c, { name: "div.un", operand: "none" }],
95
+ [0x5d, { name: "rem", operand: "none" }],
96
+ [0x5e, { name: "rem.un", operand: "none" }],
97
+ [0x5f, { name: "and", operand: "none" }],
98
+ [0x60, { name: "or", operand: "none" }],
99
+ [0x61, { name: "xor", operand: "none" }],
100
+ [0x62, { name: "shl", operand: "none" }],
101
+ [0x63, { name: "shr", operand: "none" }],
102
+ [0x64, { name: "shr.un", operand: "none" }],
103
+ [0x65, { name: "neg", operand: "none" }],
104
+ [0x66, { name: "not", operand: "none" }],
105
+ [0x67, { name: "conv.i1", operand: "none" }],
106
+ [0x68, { name: "conv.i2", operand: "none" }],
107
+ [0x69, { name: "conv.i4", operand: "none" }],
108
+ [0x6a, { name: "conv.i8", operand: "none" }],
109
+ [0x6b, { name: "conv.r4", operand: "none" }],
110
+ [0x6c, { name: "conv.r8", operand: "none" }],
111
+ [0x6d, { name: "conv.u4", operand: "none" }],
112
+ [0x6e, { name: "conv.u8", operand: "none" }],
113
+ [0x6f, { name: "callvirt", operand: "method" }],
114
+ [0x70, { name: "cpobj", operand: "type" }],
115
+ [0x71, { name: "ldobj", operand: "type" }],
116
+ [0x72, { name: "ldstr", operand: "string" }],
117
+ [0x73, { name: "newobj", operand: "method" }],
118
+ [0x74, { name: "castclass", operand: "type" }],
119
+ [0x75, { name: "isinst", operand: "type" }],
120
+ [0x76, { name: "conv.r.un", operand: "none" }],
121
+ [0x79, { name: "unbox", operand: "type" }],
122
+ [0x7a, { name: "throw", operand: "none" }],
123
+ [0x7b, { name: "ldfld", operand: "field" }],
124
+ [0x7c, { name: "ldflda", operand: "field" }],
125
+ [0x7d, { name: "stfld", operand: "field" }],
126
+ [0x7e, { name: "ldsfld", operand: "field" }],
127
+ [0x7f, { name: "ldsflda", operand: "field" }],
128
+ [0x80, { name: "stsfld", operand: "field" }],
129
+ [0x81, { name: "stobj", operand: "type" }],
130
+ [0x82, { name: "conv.ovf.i1.un", operand: "none" }],
131
+ [0x83, { name: "conv.ovf.i2.un", operand: "none" }],
132
+ [0x84, { name: "conv.ovf.i4.un", operand: "none" }],
133
+ [0x85, { name: "conv.ovf.i8.un", operand: "none" }],
134
+ [0x86, { name: "conv.ovf.u1.un", operand: "none" }],
135
+ [0x87, { name: "conv.ovf.u2.un", operand: "none" }],
136
+ [0x88, { name: "conv.ovf.u4.un", operand: "none" }],
137
+ [0x89, { name: "conv.ovf.u8.un", operand: "none" }],
138
+ [0x8a, { name: "conv.ovf.i.un", operand: "none" }],
139
+ [0x8b, { name: "conv.ovf.u.un", operand: "none" }],
140
+ [0x8c, { name: "box", operand: "type" }],
141
+ [0x8d, { name: "newarr", operand: "type" }],
142
+ [0x8e, { name: "ldlen", operand: "none" }],
143
+ [0x8f, { name: "ldelema", operand: "type" }],
144
+ [0x90, { name: "ldelem.i1", operand: "none" }],
145
+ [0x91, { name: "ldelem.u1", operand: "none" }],
146
+ [0x92, { name: "ldelem.i2", operand: "none" }],
147
+ [0x93, { name: "ldelem.u2", operand: "none" }],
148
+ [0x94, { name: "ldelem.i4", operand: "none" }],
149
+ [0x95, { name: "ldelem.u4", operand: "none" }],
150
+ [0x96, { name: "ldelem.i8", operand: "none" }],
151
+ [0x97, { name: "ldelem.i", operand: "none" }],
152
+ [0x98, { name: "ldelem.r4", operand: "none" }],
153
+ [0x99, { name: "ldelem.r8", operand: "none" }],
154
+ [0x9a, { name: "ldelem.ref", operand: "none" }],
155
+ [0x9b, { name: "stelem.i", operand: "none" }],
156
+ [0x9c, { name: "stelem.i1", operand: "none" }],
157
+ [0x9d, { name: "stelem.i2", operand: "none" }],
158
+ [0x9e, { name: "stelem.i4", operand: "none" }],
159
+ [0x9f, { name: "stelem.i8", operand: "none" }],
160
+ [0xa0, { name: "stelem.r4", operand: "none" }],
161
+ [0xa1, { name: "stelem.r8", operand: "none" }],
162
+ [0xa2, { name: "stelem.ref", operand: "none" }],
163
+ [0xa3, { name: "ldelem", operand: "type" }],
164
+ [0xa4, { name: "stelem", operand: "type" }],
165
+ [0xa5, { name: "unbox.any", operand: "type" }],
166
+ [0xb3, { name: "conv.ovf.i1", operand: "none" }],
167
+ [0xb4, { name: "conv.ovf.u1", operand: "none" }],
168
+ [0xb5, { name: "conv.ovf.i2", operand: "none" }],
169
+ [0xb6, { name: "conv.ovf.u2", operand: "none" }],
170
+ [0xb7, { name: "conv.ovf.i4", operand: "none" }],
171
+ [0xb8, { name: "conv.ovf.u4", operand: "none" }],
172
+ [0xb9, { name: "conv.ovf.i8", operand: "none" }],
173
+ [0xba, { name: "conv.ovf.u8", operand: "none" }],
174
+ [0xc2, { name: "refanyval", operand: "type" }],
175
+ [0xc3, { name: "ckfinite", operand: "none" }],
176
+ [0xc6, { name: "mkrefany", operand: "type" }],
177
+ [0xd0, { name: "ldtoken", operand: "token" }],
178
+ [0xd1, { name: "conv.u2", operand: "none" }],
179
+ [0xd2, { name: "conv.u1", operand: "none" }],
180
+ [0xd3, { name: "conv.i", operand: "none" }],
181
+ [0xd4, { name: "conv.ovf.i", operand: "none" }],
182
+ [0xd5, { name: "conv.ovf.u", operand: "none" }],
183
+ [0xd6, { name: "add.ovf", operand: "none" }],
184
+ [0xd7, { name: "add.ovf.un", operand: "none" }],
185
+ [0xd8, { name: "mul.ovf", operand: "none" }],
186
+ [0xd9, { name: "mul.ovf.un", operand: "none" }],
187
+ [0xda, { name: "sub.ovf", operand: "none" }],
188
+ [0xdb, { name: "sub.ovf.un", operand: "none" }],
189
+ [0xdc, { name: "endfinally", operand: "none" }],
190
+ [0xdd, { name: "leave", operand: "branch" }],
191
+ [0xde, { name: "leave.s", operand: "short-branch" }],
192
+ [0xdf, { name: "stind.i", operand: "none" }],
193
+ [0xe0, { name: "conv.u", operand: "none" }],
194
+ [0xfe00, { name: "arglist", operand: "none" }],
195
+ [0xfe01, { name: "ceq", operand: "none" }],
196
+ [0xfe02, { name: "cgt", operand: "none" }],
197
+ [0xfe03, { name: "cgt.un", operand: "none" }],
198
+ [0xfe04, { name: "clt", operand: "none" }],
199
+ [0xfe05, { name: "clt.un", operand: "none" }],
200
+ [0xfe06, { name: "ldftn", operand: "method" }],
201
+ [0xfe07, { name: "ldvirtftn", operand: "method" }],
202
+ [0xfe09, { name: "ldarg", operand: "var" }],
203
+ [0xfe0a, { name: "ldarga", operand: "var" }],
204
+ [0xfe0b, { name: "starg", operand: "var" }],
205
+ [0xfe0c, { name: "ldloc", operand: "var" }],
206
+ [0xfe0d, { name: "ldloca", operand: "var" }],
207
+ [0xfe0e, { name: "stloc", operand: "var" }],
208
+ [0xfe0f, { name: "localloc", operand: "none" }],
209
+ [0xfe11, { name: "endfilter", operand: "none" }],
210
+ [0xfe12, { name: "unaligned.", operand: "short-i" }],
211
+ [0xfe13, { name: "volatile.", operand: "none" }],
212
+ [0xfe14, { name: "tail.", operand: "none" }],
213
+ [0xfe15, { name: "initobj", operand: "type" }],
214
+ [0xfe16, { name: "constrained.", operand: "type" }],
215
+ [0xfe17, { name: "cpblk", operand: "none" }],
216
+ [0xfe18, { name: "initblk", operand: "none" }],
217
+ [0xfe1a, { name: "rethrow", operand: "none" }],
218
+ [0xfe1c, { name: "sizeof", operand: "type" }],
219
+ [0xfe1d, { name: "refanytype", operand: "none" }],
220
+ [0xfe1e, { name: "readonly.", operand: "none" }],
221
+ ]);
222
+ const tokenKind = (token) => {
223
+ if (token.startsWith("0x06") ||
224
+ token.startsWith("0x0a") ||
225
+ token.startsWith("0x2b"))
226
+ return "method";
227
+ if (token.startsWith("0x04"))
228
+ return "field";
229
+ if (token.startsWith("0x70"))
230
+ return "string";
231
+ if (token.startsWith("0x11"))
232
+ return "signature";
233
+ if (token.startsWith("0x01") ||
234
+ token.startsWith("0x02") ||
235
+ token.startsWith("0x1b"))
236
+ return "type";
237
+ return "token";
238
+ };
239
+ const FIXED_OPERAND_READERS = new Map([
240
+ [
241
+ "none",
242
+ (_il, offset) => ({ next: offset, anchorKind: "none", value: null }),
243
+ ],
244
+ [
245
+ "short-var",
246
+ (il, offset) => ({
247
+ next: offset + 1,
248
+ anchorKind: "variable",
249
+ value: String(il.readUInt8(offset)),
250
+ }),
251
+ ],
252
+ [
253
+ "var",
254
+ (il, offset) => ({
255
+ next: offset + 2,
256
+ anchorKind: "variable",
257
+ value: String(il.readUInt16LE(offset)),
258
+ }),
259
+ ],
260
+ [
261
+ "short-i",
262
+ (il, offset) => ({
263
+ next: offset + 1,
264
+ anchorKind: "constant",
265
+ value: String(il.readInt8(offset)),
266
+ }),
267
+ ],
268
+ [
269
+ "i",
270
+ (il, offset) => ({
271
+ next: offset + 4,
272
+ anchorKind: "constant",
273
+ value: String(il.readInt32LE(offset)),
274
+ }),
275
+ ],
276
+ [
277
+ "i8",
278
+ (il, offset) => ({
279
+ next: offset + 8,
280
+ anchorKind: "constant",
281
+ value: il.readBigInt64LE(offset).toString(),
282
+ }),
283
+ ],
284
+ [
285
+ "r4",
286
+ (il, offset) => ({
287
+ next: offset + 4,
288
+ anchorKind: "constant",
289
+ value: String(il.readFloatLE(offset)),
290
+ }),
291
+ ],
292
+ [
293
+ "r8",
294
+ (il, offset) => ({
295
+ next: offset + 8,
296
+ anchorKind: "constant",
297
+ value: String(il.readDoubleLE(offset)),
298
+ }),
299
+ ],
300
+ [
301
+ "short-branch",
302
+ (il, offset) => ({
303
+ next: offset + 1,
304
+ anchorKind: "branch",
305
+ value: String(offset + 1 + il.readInt8(offset)),
306
+ }),
307
+ ],
308
+ [
309
+ "branch",
310
+ (il, offset) => ({
311
+ next: offset + 4,
312
+ anchorKind: "branch",
313
+ value: String(offset + 4 + il.readInt32LE(offset)),
314
+ }),
315
+ ],
316
+ ]);
317
+ const TOKEN_OPERAND_KINDS = new Map([
318
+ ["method", "method"],
319
+ ["field", "field"],
320
+ ["type", "type"],
321
+ ["string", "string"],
322
+ ["signature", "signature"],
323
+ ]);
324
+ const readOperand = (il, offset, kind) => {
325
+ const fixed = FIXED_OPERAND_READERS.get(kind);
326
+ if (fixed !== undefined)
327
+ return fixed(il, offset);
328
+ if (kind === "switch") {
329
+ const count = il.readUInt32LE(offset);
330
+ return {
331
+ next: offset + 4 + count * 4,
332
+ anchorKind: "switch",
333
+ value: String(count),
334
+ };
335
+ }
336
+ const raw = il.readUInt32LE(offset);
337
+ const token = `0x${raw.toString(16).padStart(8, "0")}`;
338
+ const tokenOperandKind = TOKEN_OPERAND_KINDS.get(kind);
339
+ if (tokenOperandKind !== undefined)
340
+ return { next: offset + 4, anchorKind: tokenOperandKind, value: token };
341
+ if (kind === "token")
342
+ return { next: offset + 4, anchorKind: tokenKind(token), value: token };
343
+ return { next: offset, anchorKind: "unknown", value: null };
344
+ };
345
+ export const decodeInstructions = (il, limit) => {
346
+ const parsed = [];
347
+ let offset = 0;
348
+ let issue = null;
349
+ try {
350
+ while (offset < il.length && parsed.length < limit) {
351
+ const start = offset;
352
+ const first = il.readUInt8(offset);
353
+ offset += 1;
354
+ const code = first === 0xfe ? 0xfe00 + il.readUInt8(offset++) : first;
355
+ const descriptor = opcode(code);
356
+ if (descriptor === undefined) {
357
+ issue = `Unsupported CIL opcode 0x${code.toString(16)} at IL offset ${String(start)}`;
358
+ break;
359
+ }
360
+ const operand = readOperand(il, offset, descriptor.operand);
361
+ if (operand.next < offset || operand.next > il.length) {
362
+ issue = `Instruction ${descriptor.name} at IL offset ${String(start)} leaves method body`;
363
+ break;
364
+ }
365
+ offset = operand.next;
366
+ parsed.push({
367
+ offset: start,
368
+ opcode: descriptor.name,
369
+ operandKind: operand.anchorKind,
370
+ operand: operand.value,
371
+ });
372
+ }
373
+ }
374
+ catch (cause) {
375
+ issue =
376
+ cause instanceof Error ? cause.message : "Instruction decode failed";
377
+ }
378
+ const truncated = offset < il.length && issue === null ? 1 : 0;
379
+ return { parsed, count: parsed.length, truncated, issue };
380
+ };
381
+ export const parseExceptionRegions = (bytes, offset, methodEnd) => {
382
+ if (offset >= methodEnd)
383
+ return [];
384
+ const kind = bytes.readUInt8(offset);
385
+ if ((kind & 0x3f) !== 1)
386
+ return [];
387
+ const fat = (kind & 0x40) !== 0;
388
+ const size = fat
389
+ ? bytes.readUInt32LE(offset) >>> 8
390
+ : bytes.readUInt8(offset + 1);
391
+ const start = fat ? offset + 4 : offset + 4;
392
+ const clauseSize = fat ? 24 : 12;
393
+ if (size < 4 || offset > methodEnd - size)
394
+ return [];
395
+ const count = Math.floor((size - 4) / clauseSize);
396
+ const regions = [];
397
+ for (let index = 0; index < count; index += 1) {
398
+ const clause = start + index * clauseSize;
399
+ if (fat) {
400
+ const flags = bytes.readUInt32LE(clause);
401
+ const extra = bytes.readUInt32LE(clause + 20);
402
+ regions.push({
403
+ flags,
404
+ try_offset: bytes.readUInt32LE(clause + 4),
405
+ try_length: bytes.readUInt32LE(clause + 8),
406
+ handler_offset: bytes.readUInt32LE(clause + 12),
407
+ handler_length: bytes.readUInt32LE(clause + 16),
408
+ class_token: flags === 0 ? `0x${extra.toString(16).padStart(8, "0")}` : null,
409
+ filter_offset: flags === 1 ? extra : null,
410
+ });
411
+ }
412
+ else {
413
+ const flags = bytes.readUInt16LE(clause);
414
+ const extra = bytes.readUInt32LE(clause + 8);
415
+ regions.push({
416
+ flags,
417
+ try_offset: bytes.readUInt16LE(clause + 2),
418
+ try_length: bytes.readUInt8(clause + 4),
419
+ handler_offset: bytes.readUInt16LE(clause + 5),
420
+ handler_length: bytes.readUInt8(clause + 7),
421
+ class_token: flags === 0 ? `0x${extra.toString(16).padStart(8, "0")}` : null,
422
+ filter_offset: flags === 1 ? extra : null,
423
+ });
424
+ }
425
+ }
426
+ return regions;
427
+ };
@@ -0,0 +1,120 @@
1
+ import { codedToken, declaringType, rowCursor, signature, } from "./ManagedMemberInspectorCore.js";
2
+ import { metadataToken, readMetadataBlob, readMetadataString, } from "./ManagedMetadataHeaps.js";
3
+ import { methodBody } from "./ManagedMethodBodyReader.js";
4
+ export const parseFields = (bytes, layout, ranges, maxBytes) => {
5
+ const fields = [];
6
+ const core = new Map();
7
+ const table = layout.table(4);
8
+ for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
9
+ const cursor = rowCursor(bytes, layout, 4, row);
10
+ const flags = cursor.readUInt16();
11
+ const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
12
+ const sig = readMetadataBlob(bytes, layout, cursor.readIndex(layout.blobIndexSize), maxBytes);
13
+ const declared = declaringType(ranges, "field", row);
14
+ const token = metadataToken(4, row);
15
+ fields.push({
16
+ token,
17
+ row_offset: cursor.start,
18
+ declaring_type_token: declared?.token ?? null,
19
+ declaring_type: declared?.fullName ?? null,
20
+ name,
21
+ flags,
22
+ signature: signature(sig),
23
+ });
24
+ core.set(token, { token, name });
25
+ }
26
+ return { fields, core };
27
+ };
28
+ export const parseMemberRefs = (bytes, layout, maxBytes) => {
29
+ const refs = [];
30
+ const core = new Map();
31
+ const table = layout.table(10);
32
+ for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
33
+ const cursor = rowCursor(bytes, layout, 10, row);
34
+ const parentRaw = cursor.readIndex(layout.codedIndexSize("MemberRefParent"));
35
+ const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
36
+ const sig = readMetadataBlob(bytes, layout, cursor.readIndex(layout.blobIndexSize), maxBytes);
37
+ const token = metadataToken(10, row);
38
+ refs.push({
39
+ token,
40
+ row_offset: cursor.start,
41
+ parent_token: codedToken(parentRaw, 3, [2, 1, 26, 6, 27]),
42
+ name,
43
+ signature: signature(sig),
44
+ });
45
+ core.set(token, { token, name });
46
+ }
47
+ return { refs, core };
48
+ };
49
+ export const parseMethods = ({ bytes, layout, pe, ranges, maxBytes, limits, }) => {
50
+ const methods = [];
51
+ const core = new Map();
52
+ const table = layout.table(6);
53
+ for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
54
+ const cursor = rowCursor(bytes, layout, 6, row);
55
+ const rva = cursor.readUInt32();
56
+ const implFlags = cursor.readUInt16();
57
+ const flags = cursor.readUInt16();
58
+ const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
59
+ const sig = readMetadataBlob(bytes, layout, cursor.readIndex(layout.blobIndexSize), maxBytes);
60
+ cursor.readIndex(layout.tableIndexSize(8));
61
+ const declared = declaringType(ranges, "method", row);
62
+ const token = metadataToken(6, row);
63
+ methods.push({
64
+ token,
65
+ row_offset: cursor.start,
66
+ declaring_type_token: declared?.token ?? null,
67
+ declaring_type: declared?.fullName ?? null,
68
+ name,
69
+ rva,
70
+ impl_flags: implFlags,
71
+ flags,
72
+ signature: signature(sig),
73
+ body: methodBody(bytes, pe, rva, limits),
74
+ });
75
+ core.set(token, { token, name, declaringType: declared?.fullName ?? null });
76
+ }
77
+ return { methods, core };
78
+ };
79
+ const targetKind = (token) => token.startsWith("0x06")
80
+ ? "method-def"
81
+ : token.startsWith("0x0a")
82
+ ? "member-ref"
83
+ : token.startsWith("0x2b")
84
+ ? "method-spec"
85
+ : "unknown";
86
+ export const edges = (methods, methodCore, fieldCore, refCore) => {
87
+ const callEdges = [];
88
+ const fieldAccesses = [];
89
+ for (const method of methods) {
90
+ for (const anchor of method.body.anchors) {
91
+ if (anchor.operand_kind === "method" && anchor.operand !== null) {
92
+ const named = methodCore.get(anchor.operand)?.name ??
93
+ refCore.get(anchor.operand)?.name ??
94
+ null;
95
+ callEdges.push({
96
+ caller_token: method.token,
97
+ caller: method.declaring_type === null
98
+ ? method.name
99
+ : `${method.declaring_type}.${method.name}`,
100
+ opcode: anchor.opcode,
101
+ target_token: anchor.operand,
102
+ target_kind: targetKind(anchor.operand),
103
+ target_name: named,
104
+ });
105
+ }
106
+ if (anchor.operand_kind === "field" && anchor.operand !== null) {
107
+ fieldAccesses.push({
108
+ method_token: method.token,
109
+ method: method.declaring_type === null
110
+ ? method.name
111
+ : `${method.declaring_type}.${method.name}`,
112
+ opcode: anchor.opcode,
113
+ field_token: anchor.operand,
114
+ field_name: fieldCore.get(anchor.operand)?.name ?? null,
115
+ });
116
+ }
117
+ }
118
+ }
119
+ return { callEdges, fieldAccesses };
120
+ };