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.
- package/README.md +103 -38
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/AndroidApplicationService.js +17 -0
- package/dist/application/AppleApplicationService.js +17 -0
- 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 +24 -2
- package/dist/application/ClientRegistrationStatus.js +11 -4
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +1 -23
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +156 -238
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +23 -7
- package/dist/application/ElectronBoundaryGraphWindows.js +32 -8
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +20 -37
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InventoryProjectionEvidence.js +41 -0
- package/dist/application/InvestigationProviders.js +12 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- package/dist/application/JavaScriptArtifactAnalysis.js +45 -6
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +23 -1
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- 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 +1 -1
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayService.js +182 -156
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- 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/ProcessPairedExperiment.js +72 -0
- package/dist/application/ProjectPermissionStore.js +48 -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 +148 -260
- package/dist/application/SetupClientConfiguration.js +224 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +124 -12
- package/dist/application/SetupSkill.js +54 -36
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +12 -3
- package/dist/application/Upgrade.js +16 -1
- package/dist/application/WindowsCapabilities.js +86 -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 +29 -496
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -133
- 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 +4 -0
- 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 +113 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +10 -768
- package/dist/cliApplicationCommands.js +118 -4
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +4 -0
- package/dist/cliElectronCommands.js +33 -62
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +306 -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 -375
- package/dist/contracts/applicationToolContracts.js +134 -0
- package/dist/contracts/electronToolContracts.js +51 -3
- package/dist/contracts/managedToolContracts.js +8 -3
- package/dist/contracts/managedWorkflowToolContracts.js +3 -3
- package/dist/contracts/providerSelection.js +2 -0
- package/dist/contracts/sessionStatusContract.js +26 -0
- package/dist/contracts/toolContractTypes.js +12 -1
- package/dist/contracts/toolContracts.js +5 -12
- package/dist/contracts/toolEffects.js +14 -0
- package/dist/contracts/toolOutputSchemaGroups.js +274 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +328 -0
- package/dist/contracts/toolOutputSchemas.js +2 -550
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/androidApplication.js +206 -0
- package/dist/domain/appleApplication.js +221 -0
- package/dist/domain/artifactComparison.js +34 -15
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/boundedCartesianProjection.js +15 -0
- package/dist/domain/browserObservation.js +1 -285
- package/dist/domain/browserObservationSchemas.js +286 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +14 -2
- package/dist/domain/errors.js +4 -486
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/javascriptApplicationVersionItems.js +18 -6
- package/dist/domain/javascriptApplicationVersionKeys.js +8 -8
- package/dist/domain/javascriptExportInstrumentation.js +97 -0
- package/dist/domain/javascriptFeatureTraversal.js +19 -7
- package/dist/domain/javascriptRuntimeStaticCandidates.js +3 -1
- 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 +5 -221
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +71 -2
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +14 -364
- 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 +16 -8
- package/dist/domain/managedMemberComparison.js +37 -391
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +27 -389
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +82 -69
- package/dist/domain/managedRuntimeCorrelation.js +12 -3
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/processComparison.js +19 -0
- package/dist/domain/processPairedExperiment.js +128 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +8 -0
- package/dist/domain/replayMachine.js +316 -0
- package/dist/domain/replayMachineRuntime.js +215 -0
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/runtimeIdentification.js +210 -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 +50 -29
- package/dist/dotnet/ManagedMemberInspector.js +51 -785
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataInventory.js +42 -306
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +48 -111
- 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 +102 -350
- package/dist/dotnet/ManagedPeReader.js +59 -28
- package/dist/evaluation/CodexAgentEval.js +132 -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 +61 -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 +4 -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 -146
- 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 +64 -50
- package/dist/replay/LinuxJavaScriptReplayRunner.js +173 -390
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +124 -56
- package/dist/server/javascriptApplicationResult.js +85 -0
- 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 +10 -112
- package/dist/server/registerBrowserTools.js +59 -83
- package/dist/server/registerElectronTools.js +48 -49
- package/dist/server/registerEnhancedTools.js +34 -42
- package/dist/server/registerEvidenceResources.js +56 -0
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +83 -116
- package/dist/server/registerJavaScriptApplicationGraphResource.js +69 -0
- package/dist/server/registerManagedTools.js +18 -1
- 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 +10 -274
- package/dist/server/registerOfficialTools.js +73 -59
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +97 -26
- package/dist/server/registerSessionTools.js +60 -164
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/toolRegistrationOptions.js +101 -3
- package/dist/server/toolResult.js +15 -4
- package/package.json +11 -11
- package/skills/reverse-engineer-anything/SKILL.md +76 -0
- package/skills/reverse-engineer-anything/references/controlled-replay.md +12 -0
- package/skills/reverse-engineer-anything/references/evidence-workflows.md +33 -0
- package/skills/reverse-engineer-anything/references/javascript-applications.md +25 -0
- package/skills/reverse-engineer-anything/references/native-and-artifacts.md +36 -0
- package/skills/reverse-engineer-anything/references/runtime-observation.md +24 -0
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
- package/skills/rea-analysis/SKILL.md +0 -222
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { managedNativeBoundaryInspectionSchema, } from "../domain/managedArtifact.js";
|
|
2
|
+
import { metadataRowOffset, } from "./ManagedMetadataLayout.js";
|
|
3
|
+
import { MetadataRowCursor, metadataToken, readMetadataString, } from "./ManagedMetadataHeaps.js";
|
|
4
|
+
import { managedTableRowCounts } from "./ManagedMetadataInventory.js";
|
|
5
|
+
import { managedFailure } from "./ManagedReaderFailure.js";
|
|
6
|
+
const rowCursor = ({ bytes, layout, table, row, }) => {
|
|
7
|
+
const descriptor = layout.table(table);
|
|
8
|
+
const start = metadataRowOffset(layout, table, row);
|
|
9
|
+
if (descriptor === undefined)
|
|
10
|
+
throw managedFailure("invalid-row", `metadata.${String(table)}`, "Metadata table is absent", start);
|
|
11
|
+
return new MetadataRowCursor(bytes, start, start + descriptor.rowSize, `metadata.${descriptor.name}`);
|
|
12
|
+
};
|
|
13
|
+
const codedToken = (raw, tagBits, tables) => {
|
|
14
|
+
const tagMask = (1 << tagBits) - 1;
|
|
15
|
+
const table = tables[raw & tagMask];
|
|
16
|
+
const row = raw >> tagBits;
|
|
17
|
+
if (table === undefined || row === 0)
|
|
18
|
+
return null;
|
|
19
|
+
return metadataToken(table, row);
|
|
20
|
+
};
|
|
21
|
+
const flagsHex = (value) => `0x${value.toString(16).padStart(4, "0")}`;
|
|
22
|
+
const page = (items, offset, limit) => {
|
|
23
|
+
const safeOffset = Math.min(offset, items.length);
|
|
24
|
+
const selected = items.slice(safeOffset, safeOffset + limit);
|
|
25
|
+
return {
|
|
26
|
+
items: selected,
|
|
27
|
+
offset,
|
|
28
|
+
limit,
|
|
29
|
+
total: items.length,
|
|
30
|
+
returned: selected.length,
|
|
31
|
+
dropped: Math.max(0, items.length - safeOffset - selected.length),
|
|
32
|
+
complete: safeOffset === 0 && selected.length === items.length,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export const parseModuleRefs = (bytes, layout, maxBytes) => {
|
|
36
|
+
const refs = [];
|
|
37
|
+
const table = layout.table(26);
|
|
38
|
+
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
|
|
39
|
+
const cursor = rowCursor({ bytes, layout, table: 26, row });
|
|
40
|
+
refs.push({
|
|
41
|
+
token: metadataToken(26, row),
|
|
42
|
+
row_offset: cursor.start,
|
|
43
|
+
name: readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return refs;
|
|
47
|
+
};
|
|
48
|
+
export const parseFields = (bytes, layout, maxBytes) => {
|
|
49
|
+
const fields = new Map();
|
|
50
|
+
const table = layout.table(4);
|
|
51
|
+
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
|
|
52
|
+
const cursor = rowCursor({ bytes, layout, table: 4, row });
|
|
53
|
+
const flags = cursor.readUInt16();
|
|
54
|
+
const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
55
|
+
cursor.readIndex(layout.blobIndexSize);
|
|
56
|
+
const token = metadataToken(4, row);
|
|
57
|
+
fields.set(token, {
|
|
58
|
+
token,
|
|
59
|
+
rowOffset: cursor.start,
|
|
60
|
+
kind: "field",
|
|
61
|
+
name,
|
|
62
|
+
flags,
|
|
63
|
+
implFlags: null,
|
|
64
|
+
rva: null,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return fields;
|
|
68
|
+
};
|
|
69
|
+
export const parseMethods = (bytes, layout, maxBytes) => {
|
|
70
|
+
const methods = new Map();
|
|
71
|
+
const table = layout.table(6);
|
|
72
|
+
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
|
|
73
|
+
const cursor = rowCursor({ bytes, layout, table: 6, row });
|
|
74
|
+
const rva = cursor.readUInt32();
|
|
75
|
+
const implFlags = cursor.readUInt16();
|
|
76
|
+
const flags = cursor.readUInt16();
|
|
77
|
+
const name = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
78
|
+
cursor.readIndex(layout.blobIndexSize);
|
|
79
|
+
cursor.readIndex(layout.tableIndexSize(8));
|
|
80
|
+
const token = metadataToken(6, row);
|
|
81
|
+
methods.set(token, {
|
|
82
|
+
token,
|
|
83
|
+
rowOffset: cursor.start,
|
|
84
|
+
kind: "method",
|
|
85
|
+
name,
|
|
86
|
+
flags,
|
|
87
|
+
implFlags,
|
|
88
|
+
rva,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return methods;
|
|
92
|
+
};
|
|
93
|
+
export const parseImplMaps = ({ bytes, layout, maxBytes, modules, members, }) => {
|
|
94
|
+
const moduleNames = new Map(modules.map((module) => [module.token, module]));
|
|
95
|
+
const imports = [];
|
|
96
|
+
const table = layout.table(28);
|
|
97
|
+
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
|
|
98
|
+
const cursor = rowCursor({ bytes, layout, table: 28, row });
|
|
99
|
+
const mappingFlags = cursor.readUInt16();
|
|
100
|
+
const memberToken = codedToken(cursor.readIndex(layout.codedIndexSize("MemberForwarded")), 1, [4, 6]);
|
|
101
|
+
const importName = readMetadataString(bytes, layout, cursor.readIndex(layout.stringIndexSize), maxBytes);
|
|
102
|
+
const importScopeRow = cursor.readIndex(layout.tableIndexSize(26));
|
|
103
|
+
const importScopeToken = importScopeRow === 0 ? null : metadataToken(26, importScopeRow);
|
|
104
|
+
const member = memberToken === null ? undefined : members.get(memberToken);
|
|
105
|
+
imports.push({
|
|
106
|
+
token: metadataToken(28, row),
|
|
107
|
+
row_offset: cursor.start,
|
|
108
|
+
mapping_flags: mappingFlags,
|
|
109
|
+
mapping_flags_hex: flagsHex(mappingFlags),
|
|
110
|
+
member_token: memberToken,
|
|
111
|
+
member_kind: member?.kind ?? "unknown",
|
|
112
|
+
member_name: member?.name ?? null,
|
|
113
|
+
import_name: importName,
|
|
114
|
+
import_scope_token: importScopeToken,
|
|
115
|
+
import_scope_name: importScopeToken === null
|
|
116
|
+
? null
|
|
117
|
+
: (moduleNames.get(importScopeToken)?.name ?? null),
|
|
118
|
+
no_mangle: (mappingFlags & 0x0001) !== 0,
|
|
119
|
+
char_set: charSet(mappingFlags),
|
|
120
|
+
call_convention: callConvention(mappingFlags),
|
|
121
|
+
supports_last_error: (mappingFlags & 0x0040) !== 0,
|
|
122
|
+
best_fit: bestFit(mappingFlags),
|
|
123
|
+
throw_on_unmappable_char: throwOnUnmappable(mappingFlags),
|
|
124
|
+
verification: "managed-declaration-only",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return imports;
|
|
128
|
+
};
|
|
129
|
+
const charSet = (flags) => {
|
|
130
|
+
switch (flags & 0x0006) {
|
|
131
|
+
case 0x0000:
|
|
132
|
+
return "not-specified";
|
|
133
|
+
case 0x0002:
|
|
134
|
+
return "ansi";
|
|
135
|
+
case 0x0004:
|
|
136
|
+
return "unicode";
|
|
137
|
+
case 0x0006:
|
|
138
|
+
return "auto";
|
|
139
|
+
default:
|
|
140
|
+
return "unknown";
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const callConvention = (flags) => {
|
|
144
|
+
switch (flags & 0x0700) {
|
|
145
|
+
case 0x0000:
|
|
146
|
+
return "not-specified";
|
|
147
|
+
case 0x0100:
|
|
148
|
+
return "winapi";
|
|
149
|
+
case 0x0200:
|
|
150
|
+
return "cdecl";
|
|
151
|
+
case 0x0300:
|
|
152
|
+
return "stdcall";
|
|
153
|
+
case 0x0400:
|
|
154
|
+
return "thiscall";
|
|
155
|
+
case 0x0500:
|
|
156
|
+
return "fastcall";
|
|
157
|
+
default:
|
|
158
|
+
return "unknown";
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const bestFit = (flags) => {
|
|
162
|
+
switch (flags & 0x0030) {
|
|
163
|
+
case 0x0000:
|
|
164
|
+
return "assembly-default";
|
|
165
|
+
case 0x0010:
|
|
166
|
+
return "enabled";
|
|
167
|
+
case 0x0020:
|
|
168
|
+
return "disabled";
|
|
169
|
+
default:
|
|
170
|
+
return "unknown";
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const throwOnUnmappable = (flags) => {
|
|
174
|
+
switch (flags & 0x3000) {
|
|
175
|
+
case 0x0000:
|
|
176
|
+
return "assembly-default";
|
|
177
|
+
case 0x1000:
|
|
178
|
+
return "enabled";
|
|
179
|
+
case 0x2000:
|
|
180
|
+
return "disabled";
|
|
181
|
+
default:
|
|
182
|
+
return "unknown";
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
export const nativeImplementations = (methods, pinvokeTokens) => {
|
|
186
|
+
const implementations = [];
|
|
187
|
+
for (const method of methods) {
|
|
188
|
+
const implFlags = method.implFlags ?? 0;
|
|
189
|
+
const codeType = codeTypeFor(implFlags);
|
|
190
|
+
const managedKind = managedKindFor(implFlags);
|
|
191
|
+
const pinvokeDeclared = pinvokeTokens.has(method.token) || (method.flags & 0x2000) !== 0;
|
|
192
|
+
if (!pinvokeDeclared && codeType === "il" && managedKind === "managed")
|
|
193
|
+
continue;
|
|
194
|
+
implementations.push({
|
|
195
|
+
token: method.token,
|
|
196
|
+
row_offset: method.rowOffset,
|
|
197
|
+
name: method.name,
|
|
198
|
+
rva: method.rva ?? 0,
|
|
199
|
+
flags: method.flags,
|
|
200
|
+
impl_flags: implFlags,
|
|
201
|
+
code_type: codeType,
|
|
202
|
+
managed_kind: managedKind,
|
|
203
|
+
pinvoke_declared: pinvokeDeclared,
|
|
204
|
+
boundary_kind: boundaryKind(pinvokeDeclared, codeType, managedKind),
|
|
205
|
+
body_interpretation: codeType === "il" && managedKind === "managed" && !pinvokeDeclared
|
|
206
|
+
? "managed-cil"
|
|
207
|
+
: method.rva === 0
|
|
208
|
+
? "not-file-backed"
|
|
209
|
+
: "native-or-runtime",
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return implementations;
|
|
213
|
+
};
|
|
214
|
+
const codeTypeFor = (implFlags) => {
|
|
215
|
+
switch (implFlags & 0x0003) {
|
|
216
|
+
case 0x0000:
|
|
217
|
+
return "il";
|
|
218
|
+
case 0x0001:
|
|
219
|
+
return "native";
|
|
220
|
+
case 0x0002:
|
|
221
|
+
return "optil";
|
|
222
|
+
case 0x0003:
|
|
223
|
+
return "runtime";
|
|
224
|
+
default:
|
|
225
|
+
return "unknown";
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const managedKindFor = (implFlags) => {
|
|
229
|
+
switch (implFlags & 0x0004) {
|
|
230
|
+
case 0x0000:
|
|
231
|
+
return "managed";
|
|
232
|
+
case 0x0004:
|
|
233
|
+
return "unmanaged";
|
|
234
|
+
default:
|
|
235
|
+
return "unknown";
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const boundaryKind = (pinvokeDeclared, codeType, managedKind) => {
|
|
239
|
+
if (pinvokeDeclared)
|
|
240
|
+
return "pinvoke";
|
|
241
|
+
if (codeType === "native")
|
|
242
|
+
return "native-body";
|
|
243
|
+
if (codeType === "runtime")
|
|
244
|
+
return "runtime-provided";
|
|
245
|
+
if (managedKind === "unmanaged")
|
|
246
|
+
return "unmanaged-method";
|
|
247
|
+
return "mixed-or-unknown";
|
|
248
|
+
};
|
|
249
|
+
export const cliNative = (pe) => {
|
|
250
|
+
if (pe.cli === null)
|
|
251
|
+
return {
|
|
252
|
+
il_only: false,
|
|
253
|
+
requires_32bit: false,
|
|
254
|
+
strong_name_signed: false,
|
|
255
|
+
native_entry_point: false,
|
|
256
|
+
ready_to_run_signature: false,
|
|
257
|
+
managed_native_header_rva: 0,
|
|
258
|
+
managed_native_header_size: 0,
|
|
259
|
+
};
|
|
260
|
+
return {
|
|
261
|
+
il_only: (pe.cli.flags & 0x0000_0001) !== 0,
|
|
262
|
+
requires_32bit: (pe.cli.flags & 0x0000_0002) !== 0,
|
|
263
|
+
strong_name_signed: (pe.cli.flags & 0x0000_0008) !== 0,
|
|
264
|
+
native_entry_point: (pe.cli.flags & 0x0000_0010) !== 0,
|
|
265
|
+
ready_to_run_signature: pe.cli.readyToRunSignature,
|
|
266
|
+
managed_native_header_rva: pe.cli.managedNativeHeader.rva,
|
|
267
|
+
managed_native_header_size: pe.cli.managedNativeHeader.size,
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
export const buildNativeBoundaryInspection = ({ target, bytes, limits, layout, inventory, moduleRefs, imports, implementations, native, issues, }) => managedNativeBoundaryInspectionSchema.parse({
|
|
271
|
+
schema_version: 1,
|
|
272
|
+
artifact: {
|
|
273
|
+
path: target.path,
|
|
274
|
+
sha256: target.sha256,
|
|
275
|
+
byte_length: bytes.length,
|
|
276
|
+
format: "pe",
|
|
277
|
+
},
|
|
278
|
+
module: inventory.module,
|
|
279
|
+
metadata: {
|
|
280
|
+
status: issues.length === 0 ? "complete" : "partial",
|
|
281
|
+
version: layout.version,
|
|
282
|
+
table_row_counts: managedTableRowCounts(layout),
|
|
283
|
+
},
|
|
284
|
+
identity_scope: {
|
|
285
|
+
token_identity: "build-local",
|
|
286
|
+
requires_artifact_sha256: target.sha256,
|
|
287
|
+
requires_mvid: inventory.module?.mvid ?? null,
|
|
288
|
+
},
|
|
289
|
+
cli_native: native,
|
|
290
|
+
module_refs: page(moduleRefs, limits.moduleRefOffset, limits.moduleRefLimit),
|
|
291
|
+
pinvoke_imports: page(imports, limits.importOffset, limits.importLimit),
|
|
292
|
+
native_implementations: page(implementations, limits.implementationOffset, limits.implementationLimit),
|
|
293
|
+
summary: {
|
|
294
|
+
module_ref_count: moduleRefs.length,
|
|
295
|
+
pinvoke_import_count: imports.length,
|
|
296
|
+
native_implementation_count: implementations.length,
|
|
297
|
+
ready_to_run: native.ready_to_run_signature,
|
|
298
|
+
mixed_mode_or_native_header: native.managed_native_header_rva !== 0 ||
|
|
299
|
+
native.managed_native_header_size !== 0 ||
|
|
300
|
+
native.native_entry_point,
|
|
301
|
+
},
|
|
302
|
+
coverage: {
|
|
303
|
+
state: issues.length === 0 ? "complete" : "partial",
|
|
304
|
+
issues,
|
|
305
|
+
},
|
|
306
|
+
limitations: [
|
|
307
|
+
"P/Invoke rows prove managed import declarations only; this inspection does not verify that a native library, export, thunk, or provider-qualified function exists.",
|
|
308
|
+
"Managed metadata tokens are build-local coordinates and are only meaningful with the reported artifact SHA-256 and MVID.",
|
|
309
|
+
"ReadyToRun, NativeAOT, C++/CLI, and IL2CPP native semantics require separately selected native-provider evidence; this tool does not translate managed tokens into native addresses.",
|
|
310
|
+
],
|
|
311
|
+
});
|