rea-agents 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -59
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/ArtifactExtraction.js +1 -1
- package/dist/application/ArtifactInventory/classify.js +42 -0
- package/dist/application/ArtifactInventory/hash.js +43 -0
- package/dist/application/ArtifactInventory/reader.js +41 -0
- package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
- package/dist/application/ArtifactInventory/scanReader.js +124 -0
- package/dist/application/ArtifactInventory/types.js +10 -0
- package/dist/application/ArtifactInventory.js +9 -351
- package/dist/application/AuthorizedArtifactInventory.js +2 -2
- package/dist/application/BinarySession.js +47 -270
- package/dist/application/BinarySessionExecution.js +28 -0
- package/dist/application/BinarySessionOpen.js +39 -0
- package/dist/application/BinarySessionRecords.js +149 -0
- package/dist/application/BinarySessionStatus.js +75 -0
- package/dist/application/CapabilityInventory.js +42 -2
- package/dist/application/ClientRegistrationStatus.js +1 -1
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +11 -29
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +165 -197
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +112 -0
- package/dist/application/ElectronBoundaryGraph.js +9 -0
- package/dist/application/ElectronBoundaryGraphContext.js +62 -0
- package/dist/application/ElectronBoundaryGraphIpc.js +242 -0
- package/dist/application/ElectronBoundaryGraphNative.js +86 -0
- package/dist/application/ElectronBoundaryGraphWindows.js +223 -0
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +58 -50
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InvestigationProviders.js +30 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- package/dist/application/JavaScriptApplicationEvidence.js +26 -0
- package/dist/application/JavaScriptApplicationEvidenceGraph.js +89 -0
- package/dist/application/JavaScriptApplicationService.js +74 -0
- package/dist/application/JavaScriptApplicationWorkflowEvidence.js +29 -0
- package/dist/application/JavaScriptApplicationWorkflowService.js +90 -0
- package/dist/application/JavaScriptArtifactAnalysis.js +52 -7
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +82 -17
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- package/dist/application/JavaScriptArtifactGraphEvidence.js +24 -14
- package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
- package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
- package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +4 -1
- package/dist/application/JavaScriptArtifactReconstructionInput.js +2 -83
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayPlanning.js +201 -0
- package/dist/application/JavaScriptReplayService.js +292 -0
- package/dist/application/JavaScriptRuntimeReconciliationEvidence.js +25 -0
- package/dist/application/JavaScriptRuntimeReconciliationService.js +27 -0
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- package/dist/application/ManagedApplicationGraphService.js +55 -0
- package/dist/application/ManagedMemberComparisonService.js +122 -0
- package/dist/application/ManagedNativeVerificationService.js +39 -0
- package/dist/application/ManagedReconstructionService.js +58 -0
- package/dist/application/ManagedRuntimeCorrelationService.js +103 -0
- package/dist/application/NodeRuntimeCharacterizationService.js +196 -0
- package/dist/application/PermissionAuthority.js +106 -63
- package/dist/application/ProcessCaptureCapability.js +1 -1
- package/dist/application/ProcessCapturePermission.js +13 -0
- package/dist/application/ProcessCli.js +2 -12
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProcessSampling.js +15 -11
- package/dist/application/ProjectPermissionStore.js +49 -9
- package/dist/application/RealHopperAssertions.js +76 -0
- package/dist/application/ReconstructionCoverageService.js +69 -0
- package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
- package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
- package/dist/application/Setup.js +147 -259
- package/dist/application/SetupClientConfiguration.js +220 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +123 -12
- package/dist/application/SetupSkill.js +26 -12
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +6 -3
- package/dist/application/WindowsCapabilities.js +86 -0
- package/dist/application/runtime.js +2 -0
- package/dist/artifacts/AsarArtifactReader.js +11 -0
- package/dist/browser/BrowserProcessStartup.js +88 -0
- package/dist/browser/CdpCaptureDocuments.js +12 -8
- package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
- package/dist/browser/CdpCaptureEventHandlers.js +336 -0
- package/dist/browser/CdpCaptureEventHelpers.js +71 -0
- package/dist/browser/CdpCaptureEventState.js +1 -0
- package/dist/browser/CdpCaptureEventTypes.js +1 -0
- package/dist/browser/CdpCaptureEvents.js +46 -464
- package/dist/browser/CdpElectronInspection.js +106 -162
- package/dist/browser/CdpElectronProvider.js +5 -1
- package/dist/browser/CdpElectronScriptEvents.js +69 -0
- package/dist/browser/CdpElectronScripts.js +94 -0
- package/dist/browser/CdpElectronWorkers.js +56 -0
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -129
- package/dist/browser/CdpPageCaptureScripts.js +97 -0
- package/dist/browser/CdpPageCaptureWorkers.js +46 -0
- package/dist/browser/CdpWebMcpDiscovery.js +38 -14
- package/dist/browser/PngVisualDiff.js +9 -2
- package/dist/catalogIdentity.js +8 -1
- package/dist/cli/artifactCommands.js +82 -0
- package/dist/cli/coreAnalysisCommands.js +232 -0
- package/dist/cli/managedCommands.js +397 -0
- package/dist/cli/managedProjectGraphCommand.js +24 -0
- package/dist/cli/options.js +9 -0
- package/dist/cli/setupCommands.js +108 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +13 -383
- package/dist/cliApplicationCommands.js +176 -0
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +17 -0
- package/dist/cliElectronCommands.js +100 -27
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliJsonInput.js +54 -0
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +289 -0
- package/dist/config/environment.js +107 -0
- package/dist/config/parseConfig.js +228 -0
- package/dist/config/parsers.js +68 -0
- package/dist/config/permissions.js +30 -0
- package/dist/config/types.js +1 -0
- package/dist/config.js +1 -292
- package/dist/contracts/applicationToolContracts.js +225 -0
- package/dist/contracts/artifactToolContracts.js +5 -9
- package/dist/contracts/browserToolContracts.js +14 -62
- package/dist/contracts/electronToolContracts.js +45 -19
- package/dist/contracts/errorSchemas.js +1 -0
- package/dist/contracts/investigationExamples.js +0 -6
- package/dist/contracts/javascriptApplicationWorkflowExamples.js +46 -0
- package/dist/contracts/javascriptRuntimeReconciliationExample.js +208 -0
- package/dist/contracts/managedToolContracts.js +153 -0
- package/dist/contracts/managedWorkflowExamples.js +346 -0
- package/dist/contracts/managedWorkflowToolContracts.js +203 -0
- package/dist/contracts/nativeToolContracts.js +2 -6
- package/dist/contracts/promptContracts.js +18 -2
- package/dist/contracts/providerSelection.js +2 -0
- package/dist/contracts/toolContractExamples.js +10 -25
- package/dist/contracts/toolContracts.js +49 -47
- package/dist/contracts/toolEffects.js +174 -0
- package/dist/contracts/toolOutputSchemaGroups.js +232 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +327 -0
- package/dist/contracts/toolOutputSchemas.js +2 -535
- package/dist/doctorRuntime.js +42 -1
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/artifactComparison.js +37 -19
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/browserObservation.js +1 -282
- package/dist/domain/browserObservationSchemas.js +286 -0
- package/dist/domain/bundleComparison.js +4 -4
- package/dist/domain/electronObservation.js +13 -0
- package/dist/domain/electronStaticAnalysis.js +9 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +206 -0
- package/dist/domain/electronStaticAnalysisIpc.js +171 -0
- package/dist/domain/electronStaticAnalysisNative.js +164 -0
- package/dist/domain/electronStaticAnalysisTypes.js +1 -0
- package/dist/domain/electronStaticAnalysisValues.js +103 -0
- package/dist/domain/errors.js +32 -448
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/functionComparisonSchemas.js +3 -8
- package/dist/domain/inputIssueProjection.js +52 -0
- package/dist/domain/javascriptApplicationAnalysis.js +155 -0
- package/dist/domain/javascriptApplicationChangeGraph.js +231 -0
- package/dist/domain/javascriptApplicationEvidenceSchemas.js +18 -0
- package/dist/domain/javascriptApplicationGraph.js +2 -1
- package/dist/domain/javascriptApplicationGraphSchemas.js +7 -0
- package/dist/domain/javascriptApplicationVersionComparison.js +116 -0
- package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionItems.js +233 -0
- package/dist/domain/javascriptApplicationVersionKeys.js +170 -0
- package/dist/domain/javascriptExportInstrumentation.js +97 -0
- package/dist/domain/javascriptFeatureSeed.js +140 -0
- package/dist/domain/javascriptFeatureTrace.js +232 -0
- package/dist/domain/javascriptFeatureTraceSchemas.js +136 -0
- package/dist/domain/javascriptFeatureTraversal.js +100 -0
- package/dist/domain/javascriptNativeHandoff.js +85 -0
- package/dist/domain/javascriptReplay.js +361 -0
- package/dist/domain/javascriptRuntimeLoadState.js +106 -0
- package/dist/domain/javascriptRuntimeReconciliation.js +42 -0
- package/dist/domain/javascriptRuntimeReconciliationGraph.js +169 -0
- package/dist/domain/javascriptRuntimeReconciliationMatching.js +247 -0
- package/dist/domain/javascriptRuntimeReconciliationParsing.js +160 -0
- package/dist/domain/javascriptRuntimeReconciliationResult.js +119 -0
- package/dist/domain/javascriptRuntimeReconciliationRuntime.js +316 -0
- package/dist/domain/javascriptRuntimeReconciliationSchemas.js +245 -0
- package/dist/domain/javascriptRuntimeStaticCandidates.js +193 -0
- package/dist/domain/javascriptSemanticAnalysis.js +386 -0
- package/dist/domain/javascriptSemanticIr.js +30 -0
- package/dist/domain/javascriptSemanticProjection.js +366 -0
- package/dist/domain/javascriptSemanticState.js +40 -0
- package/dist/domain/javascriptSemanticTraversal.js +22 -0
- package/dist/domain/javascriptSemanticValues.js +352 -0
- package/dist/domain/javascriptStaticAnalysis.js +26 -254
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisFindings.js +39 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +81 -2
- package/dist/domain/javascriptStaticAnalysisState.js +6 -0
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +206 -0
- package/dist/domain/managedApplicationGraphCoverage.js +170 -0
- package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
- package/dist/domain/managedApplicationGraphNodes.js +336 -0
- package/dist/domain/managedArtifact.js +452 -0
- package/dist/domain/managedMemberComparison.js +211 -0
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +46 -0
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +196 -0
- package/dist/domain/managedRuntimeCorrelation.js +184 -0
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +9 -3
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/webBundleAnalyzer.js +3 -409
- package/dist/domain/webBundleAnalyzerAst.js +77 -0
- package/dist/domain/webBundleAnalyzerInspection.js +307 -0
- package/dist/domain/webBundleAnalyzerResult.js +120 -0
- package/dist/dotnet/ManagedArtifactInspector.js +339 -0
- package/dist/dotnet/ManagedMemberInspector.js +153 -0
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataHeaps.js +131 -0
- package/dist/dotnet/ManagedMetadataInventory.js +104 -0
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +259 -0
- package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
- package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
- package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +143 -0
- package/dist/dotnet/ManagedPeReader.js +188 -0
- package/dist/dotnet/ManagedReaderFailure.js +10 -0
- package/dist/dotnet/ManagedStaticProvider.js +203 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraClient.js +76 -91
- package/dist/ghidra/GhidraClientStartup.js +29 -0
- package/dist/ghidra/GhidraClientWire.js +34 -0
- package/dist/ghidra/GhidraDefaults.js +1 -1
- package/dist/ghidra/GhidraDiagnostics.js +6 -1
- package/dist/ghidra/GhidraInstallation.js +20 -15
- package/dist/ghidra/GhidraLauncher.js +93 -29
- package/dist/ghidra/GhidraProvider.js +67 -161
- package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
- package/dist/ghidra/GhidraSessionValues.js +2 -0
- package/dist/ghidra/GhidraSocketConnection.js +44 -7
- package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
- package/dist/ghidra/GhidraTransport.js +71 -0
- package/dist/identity.js +3 -2
- package/dist/main/messages.js +5 -0
- package/dist/main/reload.js +49 -0
- package/dist/main/shutdown.js +25 -0
- package/dist/main/startup.js +14 -0
- package/dist/main/state.js +26 -0
- package/dist/main/transport.js +61 -0
- package/dist/main/types.js +1 -0
- package/dist/main.js +35 -132
- package/dist/process/PrivateRuntimeRoot.js +3 -2
- package/dist/process/ProcessOwnership.js +35 -0
- package/dist/process/ProviderProcess.js +2 -0
- package/dist/replay/JavaScriptReplayWorker.js +300 -0
- package/dist/replay/LinuxJavaScriptReplayRunner.js +217 -0
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/LinuxRuntimeClosure.js +46 -0
- package/dist/replay/LinuxSeccompPolicy.js +40 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/replay/ReplayWorkerProtocol.js +55 -0
- package/dist/replay/SystemJavaScriptReplayHost.js +182 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +158 -41
- package/dist/server/registerApplicationTools/characterization.js +57 -0
- package/dist/server/registerApplicationTools/compareVersions.js +34 -0
- package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
- package/dist/server/registerApplicationTools/coverage.js +84 -0
- package/dist/server/registerApplicationTools/helpers.js +42 -0
- package/dist/server/registerApplicationTools/traceFeature.js +26 -0
- package/dist/server/registerApplicationTools/types.js +1 -0
- package/dist/server/registerApplicationTools.js +13 -0
- package/dist/server/registerArtifactComparisonTool.js +16 -9
- package/dist/server/registerBrowserTools.js +61 -60
- package/dist/server/registerBundleComparisonTool.js +17 -20
- package/dist/server/registerElectronTools.js +39 -12
- package/dist/server/registerEnhancedTools.js +52 -15
- package/dist/server/registerEvidenceResources.js +54 -0
- package/dist/server/registerEvidenceTools.js +5 -1
- package/dist/server/registerFunctionComparisonTool.js +14 -7
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +103 -132
- package/dist/server/registerManagedTools.js +6 -0
- package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
- package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
- package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
- package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
- package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
- package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
- package/dist/server/registerManagedWorkflowTools/types.js +1 -0
- package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
- package/dist/server/registerManagedWorkflowTools.js +13 -0
- package/dist/server/registerOfficialTools.js +81 -67
- package/dist/server/registerProcessComparisonTool.js +25 -47
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +9 -8
- package/dist/server/registerSessionTools.js +77 -216
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/sessionEvidence.js +14 -19
- package/dist/server/toolInputValidation.js +77 -0
- package/dist/server/toolRegistrationOptions.js +177 -2
- package/dist/server/toolResult.js +30 -17
- package/package.json +21 -14
- package/scripts/rea.mjs +1 -1
- package/skills/{rea-analysis → reverse-engineer-anything}/SKILL.md +75 -6
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { managedFailure, ManagedReaderFailure, } from "./ManagedReaderFailure.js";
|
|
2
|
+
const requireRange = (bytes, offset, length, scope) => {
|
|
3
|
+
if (!Number.isSafeInteger(offset) ||
|
|
4
|
+
!Number.isSafeInteger(length) ||
|
|
5
|
+
offset < 0 ||
|
|
6
|
+
length < 0 ||
|
|
7
|
+
offset > bytes.length - length)
|
|
8
|
+
throw managedFailure("invalid-directory", scope, `${scope} leaves the artifact byte range`, Number.isSafeInteger(offset) && offset >= 0 ? offset : null);
|
|
9
|
+
};
|
|
10
|
+
const add = (left, right, scope) => {
|
|
11
|
+
const result = left + right;
|
|
12
|
+
if (!Number.isSafeInteger(result) || result < left)
|
|
13
|
+
throw managedFailure("invalid-directory", scope, `${scope} offset arithmetic overflowed`, left);
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const architectureFor = (machine) => {
|
|
17
|
+
switch (machine) {
|
|
18
|
+
case 0x014c:
|
|
19
|
+
return "x86";
|
|
20
|
+
case 0x8664:
|
|
21
|
+
return "x86_64";
|
|
22
|
+
case 0x01c0:
|
|
23
|
+
return "arm";
|
|
24
|
+
case 0xaa64:
|
|
25
|
+
return "arm64";
|
|
26
|
+
default:
|
|
27
|
+
throw managedFailure("invalid-directory", "pe.machine", `Unsupported PE machine 0x${machine.toString(16).padStart(4, "0")}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const mapRva = (mapping) => {
|
|
31
|
+
const { bytes, sections, rva, size, scope } = mapping;
|
|
32
|
+
if (rva === 0 && size === 0)
|
|
33
|
+
return 0;
|
|
34
|
+
for (const section of sections) {
|
|
35
|
+
const mappedSize = Math.max(section.virtualSize, section.rawSize);
|
|
36
|
+
if (rva < section.virtualAddress)
|
|
37
|
+
continue;
|
|
38
|
+
const within = rva - section.virtualAddress;
|
|
39
|
+
if (within > mappedSize || size > mappedSize - within)
|
|
40
|
+
continue;
|
|
41
|
+
if (within > section.rawSize || size > section.rawSize - within)
|
|
42
|
+
throw managedFailure("invalid-directory", scope, `${scope} occupies virtual bytes without file-backed data`);
|
|
43
|
+
const offset = add(section.rawOffset, within, scope);
|
|
44
|
+
requireRange(bytes, offset, size, scope);
|
|
45
|
+
return offset;
|
|
46
|
+
}
|
|
47
|
+
throw managedFailure("invalid-directory", scope, `${scope} RVA is not covered by a PE section`);
|
|
48
|
+
};
|
|
49
|
+
const readDirectory = (bytes, offset) => {
|
|
50
|
+
requireRange(bytes, offset, 8, "pe.data-directory");
|
|
51
|
+
return {
|
|
52
|
+
rva: bytes.readUInt32LE(offset),
|
|
53
|
+
size: bytes.readUInt32LE(offset + 4),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const readCliHeader = (bytes, sections, directory) => {
|
|
57
|
+
if (directory.size < 72)
|
|
58
|
+
throw managedFailure("invalid-cli-header", "cli.header", "CLI header is shorter than the required 72 bytes");
|
|
59
|
+
const offset = mapRva({
|
|
60
|
+
bytes,
|
|
61
|
+
sections,
|
|
62
|
+
rva: directory.rva,
|
|
63
|
+
size: 72,
|
|
64
|
+
scope: "cli.header",
|
|
65
|
+
});
|
|
66
|
+
const headerSize = bytes.readUInt32LE(offset);
|
|
67
|
+
if (headerSize < 72 || headerSize > directory.size)
|
|
68
|
+
throw managedFailure("invalid-cli-header", "cli.header", "CLI header size is outside its PE data directory", offset);
|
|
69
|
+
const metadata = readDirectory(bytes, offset + 8);
|
|
70
|
+
if (metadata.rva === 0 || metadata.size === 0)
|
|
71
|
+
throw managedFailure("invalid-cli-header", "cli.metadata", "CLI metadata directory is absent", offset + 8);
|
|
72
|
+
const flags = bytes.readUInt32LE(offset + 16);
|
|
73
|
+
const managedNativeHeader = readDirectory(bytes, offset + 64);
|
|
74
|
+
let readyToRunSignature = false;
|
|
75
|
+
if (managedNativeHeader.rva !== 0 && managedNativeHeader.size >= 4) {
|
|
76
|
+
const nativeOffset = mapRva({
|
|
77
|
+
bytes,
|
|
78
|
+
sections,
|
|
79
|
+
rva: managedNativeHeader.rva,
|
|
80
|
+
size: 4,
|
|
81
|
+
scope: "cli.managed-native-header",
|
|
82
|
+
});
|
|
83
|
+
readyToRunSignature = bytes.readUInt32LE(nativeOffset) === 0x0052_5452;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
headerOffset: offset,
|
|
87
|
+
headerSize,
|
|
88
|
+
runtimeMajor: bytes.readUInt16LE(offset + 4),
|
|
89
|
+
runtimeMinor: bytes.readUInt16LE(offset + 6),
|
|
90
|
+
metadata,
|
|
91
|
+
flags,
|
|
92
|
+
entryPoint: bytes.readUInt32LE(offset + 20),
|
|
93
|
+
resources: readDirectory(bytes, offset + 24),
|
|
94
|
+
strongName: readDirectory(bytes, offset + 32),
|
|
95
|
+
managedNativeHeader,
|
|
96
|
+
readyToRunSignature,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const readCoffHeader = (bytes) => {
|
|
100
|
+
const peOffset = bytes.readUInt32LE(0x3c);
|
|
101
|
+
requireRange(bytes, peOffset, 24, "pe.coff-header");
|
|
102
|
+
if (bytes.readUInt32LE(peOffset) !== 0x0000_4550)
|
|
103
|
+
throw managedFailure("invalid-directory", "pe.signature", "PE signature is invalid", peOffset);
|
|
104
|
+
const coff = peOffset + 4;
|
|
105
|
+
const machine = bytes.readUInt16LE(coff);
|
|
106
|
+
const sectionCount = bytes.readUInt16LE(coff + 2);
|
|
107
|
+
if (sectionCount === 0 || sectionCount > 96)
|
|
108
|
+
throw managedFailure("invalid-directory", "pe.sections", "PE section count is outside the admitted range", coff + 2);
|
|
109
|
+
const optionalSize = bytes.readUInt16LE(coff + 16);
|
|
110
|
+
const characteristics = bytes.readUInt16LE(coff + 18);
|
|
111
|
+
return { coff, machine, sectionCount, optionalSize, characteristics };
|
|
112
|
+
};
|
|
113
|
+
const readOptionalHeader = (bytes, coff) => {
|
|
114
|
+
const optionalOffset = coff.coff + 20;
|
|
115
|
+
requireRange(bytes, optionalOffset, coff.optionalSize, "pe.optional-header");
|
|
116
|
+
if (coff.optionalSize < 96)
|
|
117
|
+
throw managedFailure("invalid-directory", "pe.optional-header", "PE optional header is too short", optionalOffset);
|
|
118
|
+
const magic = bytes.readUInt16LE(optionalOffset);
|
|
119
|
+
const optionalHeader = magic === 0x010b ? "pe32" : magic === 0x020b ? "pe32-plus" : undefined;
|
|
120
|
+
if (optionalHeader === undefined)
|
|
121
|
+
throw managedFailure("invalid-directory", "pe.optional-header", "PE optional header magic is unsupported", optionalOffset);
|
|
122
|
+
return {
|
|
123
|
+
optionalOffset,
|
|
124
|
+
optionalHeader,
|
|
125
|
+
directoryCountOffset: optionalOffset + (optionalHeader === "pe32" ? 92 : 108),
|
|
126
|
+
directoryOffset: optionalOffset + (optionalHeader === "pe32" ? 96 : 112),
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const readSections = (bytes, coff, optional) => {
|
|
130
|
+
const sectionOffset = add(optional.optionalOffset, coff.optionalSize, "pe.sections");
|
|
131
|
+
requireRange(bytes, sectionOffset, coff.sectionCount * 40, "pe.sections");
|
|
132
|
+
const sections = [];
|
|
133
|
+
for (let index = 0; index < coff.sectionCount; index += 1) {
|
|
134
|
+
const offset = sectionOffset + index * 40;
|
|
135
|
+
const section = {
|
|
136
|
+
virtualSize: bytes.readUInt32LE(offset + 8),
|
|
137
|
+
virtualAddress: bytes.readUInt32LE(offset + 12),
|
|
138
|
+
rawSize: bytes.readUInt32LE(offset + 16),
|
|
139
|
+
rawOffset: bytes.readUInt32LE(offset + 20),
|
|
140
|
+
};
|
|
141
|
+
if (section.rawSize > 0)
|
|
142
|
+
requireRange(bytes, section.rawOffset, section.rawSize, "pe.section-data");
|
|
143
|
+
sections.push(section);
|
|
144
|
+
}
|
|
145
|
+
return sections;
|
|
146
|
+
};
|
|
147
|
+
const readCliDirectory = (bytes, coff, optional) => {
|
|
148
|
+
requireRange(bytes, optional.directoryCountOffset, 4, "pe.data-directories");
|
|
149
|
+
const directoryCount = bytes.readUInt32LE(optional.directoryCountOffset);
|
|
150
|
+
if (directoryCount <= 14 ||
|
|
151
|
+
coff.optionalSize < optional.directoryOffset - optional.optionalOffset + 120)
|
|
152
|
+
return { rva: 0, size: 0 };
|
|
153
|
+
return readDirectory(bytes, optional.directoryOffset + 14 * 8);
|
|
154
|
+
};
|
|
155
|
+
/** Parse the file-backed PE and CLI layout without loading target code. */
|
|
156
|
+
export const readManagedPeLayout = (bytes) => {
|
|
157
|
+
requireRange(bytes, 0, 64, "pe.dos-header");
|
|
158
|
+
if (bytes[0] !== 0x4d || bytes[1] !== 0x5a)
|
|
159
|
+
throw managedFailure("invalid-directory", "pe.dos-header", "Artifact does not start with an MZ header", 0);
|
|
160
|
+
const coff = readCoffHeader(bytes);
|
|
161
|
+
const optional = readOptionalHeader(bytes, coff);
|
|
162
|
+
const sections = readSections(bytes, coff, optional);
|
|
163
|
+
const cliDirectory = readCliDirectory(bytes, coff, optional);
|
|
164
|
+
const cliDirectoryPresent = cliDirectory.rva !== 0 || cliDirectory.size !== 0;
|
|
165
|
+
let cli = null;
|
|
166
|
+
let cliIssue = null;
|
|
167
|
+
if (cliDirectoryPresent)
|
|
168
|
+
try {
|
|
169
|
+
cli = readCliHeader(bytes, sections, cliDirectory);
|
|
170
|
+
}
|
|
171
|
+
catch (cause) {
|
|
172
|
+
if (!(cause instanceof ManagedReaderFailure))
|
|
173
|
+
throw cause;
|
|
174
|
+
cliIssue = cause.issue;
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
machine: coff.machine,
|
|
178
|
+
architecture: architectureFor(coff.machine),
|
|
179
|
+
optionalHeader: optional.optionalHeader,
|
|
180
|
+
sectionCount: coff.sectionCount,
|
|
181
|
+
characteristics: coff.characteristics,
|
|
182
|
+
sections,
|
|
183
|
+
cli,
|
|
184
|
+
cliDirectoryPresent,
|
|
185
|
+
cliIssue,
|
|
186
|
+
rvaToOffset: (rva, size, scope) => mapRva({ bytes, sections, rva, size, scope }),
|
|
187
|
+
};
|
|
188
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Bounded format failure retained as caller-visible managed coverage. */
|
|
2
|
+
export class ManagedReaderFailure extends Error {
|
|
3
|
+
issue;
|
|
4
|
+
constructor(issue, options) {
|
|
5
|
+
super(issue.detail, options);
|
|
6
|
+
this.issue = issue;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Construct a typed managed parse failure at an exact byte location. */
|
|
10
|
+
export const managedFailure = (code, scope, detail, offset = null) => new ManagedReaderFailure({ code, scope, offset, detail });
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { createAnalysisExecution, } from "../application/AnalysisProvider.js";
|
|
4
|
+
import { MANAGED_STATIC_PROVIDER } from "../application/InvestigationProviders.js";
|
|
5
|
+
import { MANAGED_TOOL_CONTRACTS, managedArtifactInputSchema, managedMemberInputSchema, managedNativeBoundaryInputSchema, } from "../contracts/managedToolContracts.js";
|
|
6
|
+
import { AnalysisCancelledError, AnalysisCapabilityUnavailableError, EvidenceIntegrityError, ProviderAdapterError, } from "../domain/errors.js";
|
|
7
|
+
import { err, ok } from "../domain/result.js";
|
|
8
|
+
import { inspectManagedArtifactBytes } from "./ManagedArtifactInspector.js";
|
|
9
|
+
import { inspectManagedMembersBytes } from "./ManagedMemberInspector.js";
|
|
10
|
+
import { inspectManagedNativeBoundariesBytes } from "./ManagedNativeBoundaryInspector.js";
|
|
11
|
+
const IDENTITY = Object.freeze(MANAGED_STATIC_PROVIDER);
|
|
12
|
+
/** Execution-free managed PE/CLI auxiliary provider. */
|
|
13
|
+
export class ManagedStaticProvider {
|
|
14
|
+
#capabilities = Object.freeze(MANAGED_TOOL_CONTRACTS.map((contract) => Object.freeze({
|
|
15
|
+
provider: IDENTITY,
|
|
16
|
+
operation: contract.name,
|
|
17
|
+
inputContractVersion: 1,
|
|
18
|
+
outputContractVersion: 1,
|
|
19
|
+
available: true,
|
|
20
|
+
reason: null,
|
|
21
|
+
pagination: "offset",
|
|
22
|
+
exhaustive: false,
|
|
23
|
+
effects: Object.freeze({
|
|
24
|
+
mutatesArtifact: false,
|
|
25
|
+
launchesProcess: false,
|
|
26
|
+
mayShowUi: false,
|
|
27
|
+
mayAccessNetwork: false,
|
|
28
|
+
mayWriteFilesystem: false,
|
|
29
|
+
changesPermissions: false,
|
|
30
|
+
requiresRoot: false,
|
|
31
|
+
}),
|
|
32
|
+
limits: Object.freeze({
|
|
33
|
+
maxResults: 500,
|
|
34
|
+
maxPayloadBytes: 4 * 1024 * 1024,
|
|
35
|
+
timeoutMs: null,
|
|
36
|
+
}),
|
|
37
|
+
limitations: limitationsFor(contract.name),
|
|
38
|
+
})));
|
|
39
|
+
identity() {
|
|
40
|
+
return IDENTITY;
|
|
41
|
+
}
|
|
42
|
+
capabilities() {
|
|
43
|
+
return this.#capabilities;
|
|
44
|
+
}
|
|
45
|
+
createClient(target) {
|
|
46
|
+
return new ManagedStaticClient(target);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class ManagedStaticClient {
|
|
50
|
+
target;
|
|
51
|
+
constructor(target) {
|
|
52
|
+
this.target = target;
|
|
53
|
+
}
|
|
54
|
+
async execute(operation, parameters, options) {
|
|
55
|
+
if (operation === "health")
|
|
56
|
+
return ok(createAnalysisExecution(null, IDENTITY));
|
|
57
|
+
if (!isManagedOperation(operation))
|
|
58
|
+
return err(new AnalysisCapabilityUnavailableError(IDENTITY.id, operation, "Operation is not implemented by the managed static provider."));
|
|
59
|
+
if (this.target.format !== "pe")
|
|
60
|
+
return err(new AnalysisCapabilityUnavailableError(IDENTITY.id, operation, `Managed static triage requires a PE target; observed ${this.target.format}.`));
|
|
61
|
+
try {
|
|
62
|
+
if (options?.signal?.aborted === true)
|
|
63
|
+
return err(new AnalysisCancelledError(operation));
|
|
64
|
+
const maxFileBytes = maxRequestedFileBytes(operation, parameters);
|
|
65
|
+
const metadata = await stat(this.target.path);
|
|
66
|
+
if (metadata.size > maxFileBytes)
|
|
67
|
+
return err(new AnalysisCapabilityUnavailableError(IDENTITY.id, operation, `Artifact size ${String(metadata.size)} exceeds max_file_bytes ${String(maxFileBytes)}.`));
|
|
68
|
+
const bytes = await readFile(this.target.path, options?.signal === undefined ? undefined : { signal: options.signal });
|
|
69
|
+
if (bytes.length > maxFileBytes)
|
|
70
|
+
return err(new AnalysisCapabilityUnavailableError(IDENTITY.id, operation, `Artifact grew beyond max_file_bytes ${String(maxFileBytes)} while it was read.`));
|
|
71
|
+
const observedDigest = createHash("sha256").update(bytes).digest("hex");
|
|
72
|
+
if (observedDigest !== this.target.sha256)
|
|
73
|
+
return err(new EvidenceIntegrityError(`Managed artifact digest changed after open: expected ${this.target.sha256}, observed ${observedDigest} at ${this.target.path}`));
|
|
74
|
+
const result = inspectManagedOperation(operation, parameters, bytes, this.target);
|
|
75
|
+
return ok(createAnalysisExecution(result, IDENTITY, {
|
|
76
|
+
rawResult: null,
|
|
77
|
+
limitations: result.limitations,
|
|
78
|
+
subject: this.target,
|
|
79
|
+
locations: managedLocations(result),
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
if (options?.signal?.aborted === true)
|
|
84
|
+
return err(new AnalysisCancelledError(operation));
|
|
85
|
+
return err(new ProviderAdapterError(IDENTITY.id, operation, { cause }));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
close() {
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const isManagedOperation = (operation) => MANAGED_TOOL_CONTRACTS.some(({ name }) => name === operation);
|
|
93
|
+
const limitationsFor = (operation) => Object.freeze(operation === "inspect_managed_artifact"
|
|
94
|
+
? [
|
|
95
|
+
"This capability inventories PE/CLI identity only; inspect_managed_members admits bounded metadata members, signatures, and CIL anchors.",
|
|
96
|
+
"It never loads the target assembly, resolves dependencies through a CLR, decompiles C#, or executes target code.",
|
|
97
|
+
]
|
|
98
|
+
: operation === "inspect_managed_native_boundaries"
|
|
99
|
+
? [
|
|
100
|
+
"This capability inventories managed declarations for native boundaries only; native exports, thunks, and addresses require separate native-provider evidence.",
|
|
101
|
+
"It never loads the target assembly, resolves dependencies through a CLR, decompiles C#, or executes target code.",
|
|
102
|
+
]
|
|
103
|
+
: [
|
|
104
|
+
"This capability decodes bounded PE/CLI metadata members, signatures, and file-backed method bodies; decompiled C# and cross-build matching are separate future contracts.",
|
|
105
|
+
"It never loads the target assembly, resolves dependencies through a CLR, decompiles C#, or executes target code.",
|
|
106
|
+
]);
|
|
107
|
+
const maxRequestedFileBytes = (operation, parameters) => {
|
|
108
|
+
if (operation === "inspect_managed_artifact")
|
|
109
|
+
return managedArtifactInputSchema.parse(parameters).max_file_bytes;
|
|
110
|
+
if (operation === "inspect_managed_native_boundaries")
|
|
111
|
+
return managedNativeBoundaryInputSchema.parse(parameters).max_file_bytes;
|
|
112
|
+
return managedMemberInputSchema.parse(parameters).max_file_bytes;
|
|
113
|
+
};
|
|
114
|
+
const inspectManagedOperation = (operation, parameters, bytes, target) => {
|
|
115
|
+
if (operation === "inspect_managed_artifact") {
|
|
116
|
+
const input = managedArtifactInputSchema.parse(parameters);
|
|
117
|
+
return inspectManagedArtifactBytes(bytes, target, {
|
|
118
|
+
referenceOffset: input.reference_offset,
|
|
119
|
+
referenceLimit: input.reference_limit,
|
|
120
|
+
resourceOffset: input.resource_offset,
|
|
121
|
+
resourceLimit: input.resource_limit,
|
|
122
|
+
attributeOffset: input.attribute_offset,
|
|
123
|
+
attributeLimit: input.attribute_limit,
|
|
124
|
+
maxMetadataBytes: input.max_metadata_bytes,
|
|
125
|
+
maxTableRows: input.max_table_rows,
|
|
126
|
+
maxHeapItemBytes: input.max_heap_item_bytes,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (operation === "inspect_managed_native_boundaries") {
|
|
130
|
+
const input = managedNativeBoundaryInputSchema.parse(parameters);
|
|
131
|
+
return inspectManagedNativeBoundariesBytes(bytes, target, {
|
|
132
|
+
moduleRefOffset: input.module_ref_offset,
|
|
133
|
+
moduleRefLimit: input.module_ref_limit,
|
|
134
|
+
importOffset: input.import_offset,
|
|
135
|
+
importLimit: input.import_limit,
|
|
136
|
+
implementationOffset: input.implementation_offset,
|
|
137
|
+
implementationLimit: input.implementation_limit,
|
|
138
|
+
maxMetadataBytes: input.max_metadata_bytes,
|
|
139
|
+
maxTableRows: input.max_table_rows,
|
|
140
|
+
maxHeapItemBytes: input.max_heap_item_bytes,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const input = managedMemberInputSchema.parse(parameters);
|
|
144
|
+
return inspectManagedMembersBytes(bytes, target, {
|
|
145
|
+
typeOffset: input.type_offset,
|
|
146
|
+
typeLimit: input.type_limit,
|
|
147
|
+
methodOffset: input.method_offset,
|
|
148
|
+
methodLimit: input.method_limit,
|
|
149
|
+
fieldOffset: input.field_offset,
|
|
150
|
+
fieldLimit: input.field_limit,
|
|
151
|
+
memberRefOffset: input.member_ref_offset,
|
|
152
|
+
memberRefLimit: input.member_ref_limit,
|
|
153
|
+
edgeOffset: input.edge_offset,
|
|
154
|
+
edgeLimit: input.edge_limit,
|
|
155
|
+
instructionAnchorLimit: input.instruction_anchor_limit,
|
|
156
|
+
maxMetadataBytes: input.max_metadata_bytes,
|
|
157
|
+
maxTableRows: input.max_table_rows,
|
|
158
|
+
maxHeapItemBytes: input.max_heap_item_bytes,
|
|
159
|
+
maxMethodBodyBytes: input.max_method_body_bytes,
|
|
160
|
+
maxMethodInstructions: input.max_method_instructions,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const managedLocations = (result) => {
|
|
164
|
+
if ("pe" in result) {
|
|
165
|
+
if (result.pe.cli === null)
|
|
166
|
+
return [{ kind: "file-offset", offset: 0 }];
|
|
167
|
+
return [
|
|
168
|
+
{
|
|
169
|
+
kind: "file-offset-range",
|
|
170
|
+
start: result.pe.cli.header_offset,
|
|
171
|
+
end: result.pe.cli.header_offset + result.pe.cli.header_size,
|
|
172
|
+
},
|
|
173
|
+
...[result.module, result.assembly]
|
|
174
|
+
.filter((value) => value !== null)
|
|
175
|
+
.map((value) => ({
|
|
176
|
+
kind: "file-offset",
|
|
177
|
+
offset: value.row_offset,
|
|
178
|
+
})),
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
if ("methods" in result)
|
|
182
|
+
return [
|
|
183
|
+
...(result.module === null
|
|
184
|
+
? [{ kind: "file-offset", offset: 0 }]
|
|
185
|
+
: [{ kind: "file-offset", offset: result.module.row_offset }]),
|
|
186
|
+
...result.methods.items
|
|
187
|
+
.filter((method) => method.body.file_offset !== null)
|
|
188
|
+
.slice(0, 8)
|
|
189
|
+
.map((method) => ({
|
|
190
|
+
kind: "file-offset",
|
|
191
|
+
offset: method.body.file_offset ?? 0,
|
|
192
|
+
})),
|
|
193
|
+
];
|
|
194
|
+
return [
|
|
195
|
+
...(result.module === null
|
|
196
|
+
? [{ kind: "file-offset", offset: 0 }]
|
|
197
|
+
: [{ kind: "file-offset", offset: result.module.row_offset }]),
|
|
198
|
+
...result.pinvoke_imports.items.slice(0, 8).map((mapping) => ({
|
|
199
|
+
kind: "file-offset",
|
|
200
|
+
offset: mapping.row_offset,
|
|
201
|
+
})),
|
|
202
|
+
];
|
|
203
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Generated from package.json and package-lock.json; do not edit. */
|
|
2
2
|
export const PACKAGE_METADATA = {
|
|
3
3
|
name: "rea-agents",
|
|
4
|
-
version: "1.
|
|
4
|
+
version: "2.1.0",
|
|
5
5
|
serverSdkVersion: "2.0.0-beta.4",
|
|
6
6
|
clientSdkVersion: "2.0.0-beta.4",
|
|
7
7
|
coreSdkVersion: "2.0.0-beta.4",
|
|
8
|
-
skillVersion: "
|
|
8
|
+
skillVersion: "22",
|
|
9
9
|
};
|