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,297 @@
|
|
|
1
|
+
import { metadataRowOffset, } from "./ManagedMetadataLayout.js";
|
|
2
|
+
import { MetadataRowCursor, metadataToken, readMetadataString, sha256Bytes, } from "./ManagedMetadataHeaps.js";
|
|
3
|
+
import { managedFailure } from "./ManagedReaderFailure.js";
|
|
4
|
+
export const emptyPage = (offset, limit) => ({
|
|
5
|
+
items: [],
|
|
6
|
+
offset,
|
|
7
|
+
limit,
|
|
8
|
+
total: 0,
|
|
9
|
+
returned: 0,
|
|
10
|
+
dropped: 0,
|
|
11
|
+
complete: offset === 0,
|
|
12
|
+
});
|
|
13
|
+
export const page = (all, offset, limit) => {
|
|
14
|
+
const items = all.slice(offset, offset + limit);
|
|
15
|
+
return {
|
|
16
|
+
items,
|
|
17
|
+
offset,
|
|
18
|
+
limit,
|
|
19
|
+
total: all.length,
|
|
20
|
+
returned: items.length,
|
|
21
|
+
dropped: all.length - items.length,
|
|
22
|
+
complete: offset === 0 && offset + limit >= all.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const rowCursor = (bytes, layout, table, row) => {
|
|
26
|
+
const descriptor = layout.table(table);
|
|
27
|
+
const start = metadataRowOffset(layout, table, row);
|
|
28
|
+
if (descriptor === undefined)
|
|
29
|
+
throw managedFailure("invalid-row", `metadata.${String(table)}`, "Metadata table is absent", start);
|
|
30
|
+
return new MetadataRowCursor(bytes, start, start + descriptor.rowSize, `metadata.${descriptor.name}`);
|
|
31
|
+
};
|
|
32
|
+
export const codedToken = (raw, bits, tables) => {
|
|
33
|
+
if (raw === 0)
|
|
34
|
+
return null;
|
|
35
|
+
const tag = raw & (2 ** bits - 1);
|
|
36
|
+
const row = Math.floor(raw / 2 ** bits);
|
|
37
|
+
const table = tables[tag];
|
|
38
|
+
return table === undefined || row === 0 ? null : metadataToken(table, row);
|
|
39
|
+
};
|
|
40
|
+
const rowRange = (table, start, nextStart) => {
|
|
41
|
+
const total = table?.rowCount ?? 0;
|
|
42
|
+
if (total === 0 || start === 0)
|
|
43
|
+
return { first: null, last: null, count: 0 };
|
|
44
|
+
const end = Math.min(nextStart === 0 ? total + 1 : nextStart, total + 1);
|
|
45
|
+
if (start >= end)
|
|
46
|
+
return { first: null, last: null, count: 0 };
|
|
47
|
+
return { first: start, last: end - 1, count: end - start };
|
|
48
|
+
};
|
|
49
|
+
const fullName = (namespace, name) => namespace.length === 0 ? name : `${namespace}.${name}`;
|
|
50
|
+
const readTypeRange = (bytes, layout, row, maxBytes) => {
|
|
51
|
+
const methods = layout.table(6);
|
|
52
|
+
const fields = layout.table(4);
|
|
53
|
+
const cursor = rowCursor(bytes, layout, 2, row);
|
|
54
|
+
cursor.readUInt32();
|
|
55
|
+
const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
56
|
+
const namespace = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
57
|
+
cursor.readIndex(layout.codedIndexSize("TypeDefOrRef"));
|
|
58
|
+
const fieldStart = cursor.readIndex(layout.tableIndexSize(4));
|
|
59
|
+
const methodStart = cursor.readIndex(layout.tableIndexSize(6));
|
|
60
|
+
let nextField = (fields?.rowCount ?? 0) + 1;
|
|
61
|
+
let nextMethod = (methods?.rowCount ?? 0) + 1;
|
|
62
|
+
const typeTable = layout.table(2);
|
|
63
|
+
if (typeTable !== undefined && row < typeTable.rowCount) {
|
|
64
|
+
const next = rowCursor(bytes, layout, 2, row + 1);
|
|
65
|
+
next.readUInt32();
|
|
66
|
+
next.readIndex(layout.stringIndexSize);
|
|
67
|
+
next.readIndex(layout.stringIndexSize);
|
|
68
|
+
next.readIndex(layout.codedIndexSize("TypeDefOrRef"));
|
|
69
|
+
nextField = next.readIndex(layout.tableIndexSize(4));
|
|
70
|
+
nextMethod = next.readIndex(layout.tableIndexSize(6));
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
token: metadataToken(2, row),
|
|
74
|
+
fullName: fullName(namespace, name),
|
|
75
|
+
fieldStart,
|
|
76
|
+
fieldEnd: nextField,
|
|
77
|
+
methodStart,
|
|
78
|
+
methodEnd: nextMethod,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export const typeRanges = (bytes, layout, maxBytes) => {
|
|
82
|
+
const typeTable = layout.table(2);
|
|
83
|
+
const ranges = [];
|
|
84
|
+
for (let row = 1; row <= (typeTable?.rowCount ?? 0); row += 1)
|
|
85
|
+
ranges.push(readTypeRange(bytes, layout, row, maxBytes));
|
|
86
|
+
return ranges;
|
|
87
|
+
};
|
|
88
|
+
export const declaringType = (ranges, table, row) => {
|
|
89
|
+
for (const range of ranges) {
|
|
90
|
+
const start = table === "field" ? range.fieldStart : range.methodStart;
|
|
91
|
+
const end = table === "field" ? range.fieldEnd : range.methodEnd;
|
|
92
|
+
if (row >= start && row < end)
|
|
93
|
+
return { token: range.token, fullName: range.fullName };
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
};
|
|
97
|
+
export const parseTypes = (bytes, layout, ranges, maxBytes) => {
|
|
98
|
+
const typeTable = layout.table(2);
|
|
99
|
+
const fields = layout.table(4);
|
|
100
|
+
const methods = layout.table(6);
|
|
101
|
+
const items = [];
|
|
102
|
+
for (let row = 1; row <= (typeTable?.rowCount ?? 0); row += 1) {
|
|
103
|
+
const cursor = rowCursor(bytes, layout, 2, row);
|
|
104
|
+
const flags = cursor.readUInt32();
|
|
105
|
+
const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
106
|
+
const namespace = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
107
|
+
const extendsRaw = cursor.readIndex(layout.codedIndexSize("TypeDefOrRef"));
|
|
108
|
+
const fieldStart = cursor.readIndex(layout.tableIndexSize(4));
|
|
109
|
+
const methodStart = cursor.readIndex(layout.tableIndexSize(6));
|
|
110
|
+
const nextRange = ranges[row] ?? null;
|
|
111
|
+
const fieldRange = rowRange(fields, fieldStart, nextRange?.fieldStart ?? 0);
|
|
112
|
+
const methodRange = rowRange(methods, methodStart, nextRange?.methodStart ?? 0);
|
|
113
|
+
items.push({
|
|
114
|
+
token: metadataToken(2, row),
|
|
115
|
+
row_offset: cursor.start,
|
|
116
|
+
namespace,
|
|
117
|
+
name,
|
|
118
|
+
full_name: fullName(namespace, name),
|
|
119
|
+
flags,
|
|
120
|
+
extends_token: codedToken(extendsRaw, 2, [2, 1, 27]),
|
|
121
|
+
field_list: {
|
|
122
|
+
first_row: fieldRange.first,
|
|
123
|
+
last_row: fieldRange.last,
|
|
124
|
+
count: fieldRange.count,
|
|
125
|
+
},
|
|
126
|
+
method_list: {
|
|
127
|
+
first_row: methodRange.first,
|
|
128
|
+
last_row: methodRange.last,
|
|
129
|
+
count: methodRange.count,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return items;
|
|
134
|
+
};
|
|
135
|
+
const readCompressed = (bytes, offset) => {
|
|
136
|
+
const first = bytes[offset];
|
|
137
|
+
if (first === undefined)
|
|
138
|
+
throw new RangeError("truncated compressed integer");
|
|
139
|
+
if ((first & 0x80) === 0)
|
|
140
|
+
return { value: first, next: offset + 1 };
|
|
141
|
+
const second = bytes[offset + 1];
|
|
142
|
+
if ((first & 0xc0) === 0x80 && second !== undefined)
|
|
143
|
+
return { value: ((first & 0x3f) << 8) | second, next: offset + 2 };
|
|
144
|
+
const b1 = bytes[offset + 1];
|
|
145
|
+
const b2 = bytes[offset + 2];
|
|
146
|
+
const b3 = bytes[offset + 3];
|
|
147
|
+
if ((first & 0xe0) === 0xc0 &&
|
|
148
|
+
b1 !== undefined &&
|
|
149
|
+
b2 !== undefined &&
|
|
150
|
+
b3 !== undefined)
|
|
151
|
+
return {
|
|
152
|
+
value: (first & 0x1f) * 0x01_00_00_00 + b1 * 0x01_00_00 + b2 * 0x0100 + b3,
|
|
153
|
+
next: offset + 4,
|
|
154
|
+
};
|
|
155
|
+
throw new RangeError("reserved compressed integer");
|
|
156
|
+
};
|
|
157
|
+
const ELEMENT_TYPES = new Map([
|
|
158
|
+
[0x01, "void"],
|
|
159
|
+
[0x02, "bool"],
|
|
160
|
+
[0x03, "char"],
|
|
161
|
+
[0x04, "i1"],
|
|
162
|
+
[0x05, "u1"],
|
|
163
|
+
[0x06, "i2"],
|
|
164
|
+
[0x07, "u2"],
|
|
165
|
+
[0x08, "i4"],
|
|
166
|
+
[0x09, "u4"],
|
|
167
|
+
[0x0a, "i8"],
|
|
168
|
+
[0x0b, "u8"],
|
|
169
|
+
[0x0c, "r4"],
|
|
170
|
+
[0x0d, "r8"],
|
|
171
|
+
[0x0e, "string"],
|
|
172
|
+
[0x18, "native-int"],
|
|
173
|
+
[0x19, "native-uint"],
|
|
174
|
+
[0x1c, "object"],
|
|
175
|
+
]);
|
|
176
|
+
const ELEMENT_TYPE_SUFFIXES = new Map([
|
|
177
|
+
[0x0f, "*"],
|
|
178
|
+
[0x10, "&"],
|
|
179
|
+
]);
|
|
180
|
+
const readTypeSignature = (blob, offset) => {
|
|
181
|
+
const kind = blob[offset];
|
|
182
|
+
if (kind === undefined)
|
|
183
|
+
throw new RangeError("truncated type signature");
|
|
184
|
+
const named = ELEMENT_TYPES.get(kind);
|
|
185
|
+
if (named !== undefined)
|
|
186
|
+
return { value: named, next: offset + 1 };
|
|
187
|
+
const suffix = ELEMENT_TYPE_SUFFIXES.get(kind);
|
|
188
|
+
if (suffix !== undefined) {
|
|
189
|
+
const inner = readTypeSignature(blob, offset + 1);
|
|
190
|
+
return { value: `${inner.value}${suffix}`, next: inner.next };
|
|
191
|
+
}
|
|
192
|
+
if (kind === 0x11 || kind === 0x12) {
|
|
193
|
+
const token = readCompressed(blob, offset + 1);
|
|
194
|
+
return {
|
|
195
|
+
value: `${kind === 0x11 ? "valuetype" : "class"}:${String(token.value)}`,
|
|
196
|
+
next: token.next,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (kind === 0x1d) {
|
|
200
|
+
const inner = readTypeSignature(blob, offset + 1);
|
|
201
|
+
return { value: `${inner.value}[]`, next: inner.next };
|
|
202
|
+
}
|
|
203
|
+
if (kind === 0x1e) {
|
|
204
|
+
const variable = readCompressed(blob, offset + 1);
|
|
205
|
+
return { value: `mvar:${String(variable.value)}`, next: variable.next };
|
|
206
|
+
}
|
|
207
|
+
if (kind === 0x13) {
|
|
208
|
+
const variable = readCompressed(blob, offset + 1);
|
|
209
|
+
return { value: `var:${String(variable.value)}`, next: variable.next };
|
|
210
|
+
}
|
|
211
|
+
throw new RangeError(`unsupported element type 0x${kind.toString(16)}`);
|
|
212
|
+
};
|
|
213
|
+
const callingConvention = (value) => {
|
|
214
|
+
const base = value & 0x0f;
|
|
215
|
+
const flags = [
|
|
216
|
+
(value & 0x20) === 0 ? null : "has-this",
|
|
217
|
+
(value & 0x40) === 0 ? null : "explicit-this",
|
|
218
|
+
(value & 0x10) === 0 ? null : "generic",
|
|
219
|
+
].filter((flag) => flag !== null);
|
|
220
|
+
const name = base === 0
|
|
221
|
+
? "default"
|
|
222
|
+
: base === 5
|
|
223
|
+
? "vararg"
|
|
224
|
+
: base === 6
|
|
225
|
+
? "field"
|
|
226
|
+
: `unknown:${String(base)}`;
|
|
227
|
+
return flags.length === 0 ? name : `${name} ${flags.join(" ")}`;
|
|
228
|
+
};
|
|
229
|
+
export const signature = (blob) => {
|
|
230
|
+
const raw = {
|
|
231
|
+
raw_length: blob.length,
|
|
232
|
+
raw_sha256: sha256Bytes(blob),
|
|
233
|
+
};
|
|
234
|
+
try {
|
|
235
|
+
if (blob.length === 0)
|
|
236
|
+
throw new RangeError("empty signature");
|
|
237
|
+
const first = blob[0] ?? 0;
|
|
238
|
+
if ((first & 0x0f) === 6) {
|
|
239
|
+
const fieldType = readTypeSignature(blob, 1);
|
|
240
|
+
return {
|
|
241
|
+
...raw,
|
|
242
|
+
kind: "field",
|
|
243
|
+
parse_status: fieldType.next === blob.length ? "decoded" : "partial",
|
|
244
|
+
calling_convention: callingConvention(first),
|
|
245
|
+
generic_parameter_count: null,
|
|
246
|
+
parameter_count: null,
|
|
247
|
+
return_type: null,
|
|
248
|
+
parameter_types: [],
|
|
249
|
+
field_type: fieldType.value,
|
|
250
|
+
issue: fieldType.next === blob.length ? null : "Trailing signature data",
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
let offset = 1;
|
|
254
|
+
let genericParameterCount = null;
|
|
255
|
+
if ((first & 0x10) !== 0) {
|
|
256
|
+
const generic = readCompressed(blob, offset);
|
|
257
|
+
genericParameterCount = generic.value;
|
|
258
|
+
offset = generic.next;
|
|
259
|
+
}
|
|
260
|
+
const parameterCount = readCompressed(blob, offset);
|
|
261
|
+
offset = parameterCount.next;
|
|
262
|
+
const returnType = readTypeSignature(blob, offset);
|
|
263
|
+
offset = returnType.next;
|
|
264
|
+
const parameters = [];
|
|
265
|
+
for (let index = 0; index < parameterCount.value; index += 1) {
|
|
266
|
+
const parameter = readTypeSignature(blob, offset);
|
|
267
|
+
parameters.push(parameter.value);
|
|
268
|
+
offset = parameter.next;
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
...raw,
|
|
272
|
+
kind: "method",
|
|
273
|
+
parse_status: offset === blob.length ? "decoded" : "partial",
|
|
274
|
+
calling_convention: callingConvention(first),
|
|
275
|
+
generic_parameter_count: genericParameterCount,
|
|
276
|
+
parameter_count: parameterCount.value,
|
|
277
|
+
return_type: returnType.value,
|
|
278
|
+
parameter_types: parameters,
|
|
279
|
+
field_type: null,
|
|
280
|
+
issue: offset === blob.length ? null : "Trailing signature data",
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
catch (cause) {
|
|
284
|
+
return {
|
|
285
|
+
...raw,
|
|
286
|
+
kind: "unknown",
|
|
287
|
+
parse_status: cause instanceof RangeError ? "unsupported" : "malformed",
|
|
288
|
+
calling_convention: null,
|
|
289
|
+
generic_parameter_count: null,
|
|
290
|
+
parameter_count: null,
|
|
291
|
+
return_type: null,
|
|
292
|
+
parameter_types: [],
|
|
293
|
+
field_type: null,
|
|
294
|
+
issue: cause instanceof Error ? cause.message : "Signature parse failed",
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
};
|