rea-agents 1.6.0 → 2.0.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 +157 -66
- package/bridge/ghidra/ReaGhidraBridge.java +2075 -0
- package/bridge/hopper_bridge.py +13 -3
- package/dist/application/AbortablePromise.js +25 -0
- package/dist/application/AnalysisProvider.js +3 -0
- package/dist/application/AnalysisProviderEvaluation.js +60 -0
- package/dist/application/AnalysisProviderRegistry.js +228 -0
- package/dist/application/AnalysisSnapshotCache.js +41 -21
- package/dist/application/AnalysisSnapshotFiles.js +5 -6
- package/dist/application/BinarySession.js +218 -101
- package/dist/application/CapabilityInventory.js +18 -0
- package/dist/application/CompositeProvider.js +20 -8
- package/dist/application/CrossVersionInvestigation.js +10 -6
- package/dist/application/DirectAnalysis.js +49 -35
- package/dist/application/Doctor.js +110 -8
- package/dist/application/ElectronBoundaryAnalysis.js +96 -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 +199 -0
- package/dist/application/EnhancedTools.js +39 -14
- package/dist/application/InvestigationProviders.js +41 -0
- 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 +305 -0
- package/dist/application/JavaScriptArtifactAnalysisTypes.js +1 -0
- package/dist/application/JavaScriptArtifactFiles.js +231 -0
- package/dist/application/JavaScriptArtifactGraphAccumulator.js +54 -0
- package/dist/application/JavaScriptArtifactGraphBuilder.js +144 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +205 -0
- package/dist/application/JavaScriptArtifactGraphDocuments.js +108 -0
- package/dist/application/JavaScriptArtifactGraphEvidence.js +99 -0
- package/dist/application/JavaScriptArtifactGraphFindings.js +271 -0
- package/dist/application/JavaScriptArtifactGraphStructure.js +409 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +77 -0
- package/dist/application/JavaScriptArtifactReconstructionInput.js +18 -0
- package/dist/application/JavaScriptReplayPlanning.js +201 -0
- package/dist/application/JavaScriptReplayService.js +266 -0
- package/dist/application/JavaScriptRuntimeReconciliationEvidence.js +25 -0
- package/dist/application/JavaScriptRuntimeReconciliationService.js +27 -0
- package/dist/application/MacHopper.js +20 -4
- 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/PermissionAuthority.js +1 -1
- package/dist/application/ProcessCaptureLifecycle.js +1 -1
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProcessSampling.js +16 -12
- package/dist/application/ProjectPermissionStore.js +1 -0
- package/dist/application/SessionProviderRouter.js +219 -0
- package/dist/application/Setup.js +84 -60
- package/dist/application/SetupClients.js +1 -1
- package/dist/application/SetupPlan.js +9 -2
- package/dist/application/SupportedClients.js +40 -16
- package/dist/application/Upgrade.js +1 -1
- package/dist/application/runtime.js +11 -6
- package/dist/artifacts/AsarArtifactReader.js +23 -3
- package/dist/browser/CdpBrowserProvider.js +4 -2
- package/dist/browser/CdpCaptureEvents.js +49 -0
- package/dist/browser/CdpElectronInspection.js +106 -162
- package/dist/browser/CdpElectronProvider.js +9 -3
- package/dist/browser/CdpElectronScriptEvents.js +69 -0
- package/dist/browser/CdpElectronScripts.js +94 -0
- package/dist/browser/CdpElectronWorkers.js +56 -0
- package/dist/browser/CdpEndpoint.js +14 -1
- package/dist/browser/CdpPageCapture.js +8 -4
- package/dist/catalogIdentity.js +6 -42
- package/dist/cli.js +446 -34
- package/dist/cliApplicationCommands.js +62 -0
- package/dist/cliBrowserAdvancedCommands.js +5 -4
- package/dist/cliBrowserCommands.js +5 -4
- package/dist/cliCommandNames.js +56 -0
- package/dist/cliElectronCommands.js +106 -3
- package/dist/cliEvidenceCommands.js +4 -3
- package/dist/cliInvestigationCommands.js +2 -1
- package/dist/cliJsonInput.js +54 -0
- package/dist/cliPolicyCommands.js +2 -1
- package/dist/cliProcessCommands.js +3 -2
- package/dist/config.js +101 -2
- package/dist/contracts/applicationToolContracts.js +91 -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/enhancedInputs.js +2 -2
- 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 +28 -0
- package/dist/contracts/sessionLifecycleInputs.js +2 -0
- package/dist/contracts/toolContractExamples.js +10 -25
- package/dist/contracts/toolContracts.js +69 -65
- package/dist/contracts/toolEffects.js +160 -0
- package/dist/contracts/toolOutputSchemas.js +152 -42
- package/dist/doctorRuntime.js +47 -0
- package/dist/domain/analysisProfile.js +78 -0
- package/dist/domain/analysisSnapshot.js +92 -46
- package/dist/domain/artifactComparison.js +3 -4
- package/dist/domain/artifactGraph.js +1 -0
- package/dist/domain/binaryTarget.js +4 -29
- package/dist/domain/browserObservation.js +3 -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 +194 -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 +148 -7
- package/dist/domain/evidence.js +44 -5
- package/dist/domain/evidenceBundle.js +9 -7
- package/dist/domain/functionComparison.js +9 -3
- package/dist/domain/functionComparisonNormalization.js +37 -0
- package/dist/domain/functionComparisonSchemas.js +3 -8
- package/dist/domain/functionDossierEvidence.js +4 -1
- package/dist/domain/hopperValues.js +66 -9
- package/dist/domain/inputIssueProjection.js +52 -0
- package/dist/domain/investigationWorkspace.js +2 -1
- package/dist/domain/javascriptApplicationAnalysis.js +155 -0
- package/dist/domain/javascriptApplicationChangeGraph.js +231 -0
- package/dist/domain/javascriptApplicationEvidenceSchemas.js +379 -0
- package/dist/domain/javascriptApplicationGraph.js +282 -0
- package/dist/domain/javascriptApplicationGraphSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionComparison.js +116 -0
- package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionItems.js +221 -0
- package/dist/domain/javascriptApplicationVersionKeys.js +170 -0
- package/dist/domain/javascriptAstFingerprint.js +143 -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 +88 -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 +191 -0
- package/dist/domain/javascriptStaticAnalysis.js +346 -0
- package/dist/domain/javascriptStaticAnalysisFindings.js +39 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +274 -0
- package/dist/domain/javascriptStaticAnalysisState.js +23 -0
- package/dist/domain/javascriptStaticAnalysisTypes.js +1 -0
- package/dist/domain/managedApplicationGraph.js +556 -0
- package/dist/domain/managedArtifact.js +444 -0
- package/dist/domain/managedMemberComparison.js +565 -0
- package/dist/domain/managedNativeVerification.js +408 -0
- package/dist/domain/managedReconstruction.js +183 -0
- package/dist/domain/managedRuntimeCorrelation.js +175 -0
- package/dist/domain/reconstructionVerificationSchemas.js +1 -3
- package/dist/dotnet/ManagedArtifactInspector.js +318 -0
- package/dist/dotnet/ManagedMemberInspector.js +887 -0
- package/dist/dotnet/ManagedMetadataHeaps.js +131 -0
- package/dist/dotnet/ManagedMetadataInventory.js +368 -0
- package/dist/dotnet/ManagedMetadataLayout.js +322 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +391 -0
- package/dist/dotnet/ManagedPeReader.js +157 -0
- package/dist/dotnet/ManagedReaderFailure.js +10 -0
- package/dist/dotnet/ManagedStaticProvider.js +203 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraAnalysisProfile.js +37 -0
- package/dist/ghidra/GhidraClient.js +400 -0
- package/dist/ghidra/GhidraClientTypes.js +1 -0
- package/dist/ghidra/GhidraDefaults.js +20 -0
- package/dist/ghidra/GhidraDiagnostics.js +43 -0
- package/dist/ghidra/GhidraDoctor.js +59 -0
- package/dist/ghidra/GhidraFunctionValues.js +264 -0
- package/dist/ghidra/GhidraInstallation.js +239 -0
- package/dist/ghidra/GhidraInventoryValues.js +217 -0
- package/dist/ghidra/GhidraLauncher.js +139 -0
- package/dist/ghidra/GhidraProvider.js +366 -0
- package/dist/ghidra/GhidraRequestQueue.js +98 -0
- package/dist/ghidra/GhidraResponseBuffer.js +31 -0
- package/dist/ghidra/GhidraResponseRouter.js +24 -0
- package/dist/ghidra/GhidraSessionError.js +39 -0
- package/dist/ghidra/GhidraSessionValues.js +62 -0
- package/dist/ghidra/GhidraSocketConnection.js +46 -0
- package/dist/ghidra/protocol.js +69 -0
- package/dist/hopper/BridgeLauncher.js +19 -54
- package/dist/hopper/HopperAnalysisProfile.js +106 -0
- package/dist/hopper/HopperClient.js +154 -162
- package/dist/hopper/HopperProvider.js +99 -7
- package/dist/hopper/HopperSessionValues.js +27 -0
- package/dist/hopper/HopperSocketConnection.js +31 -0
- package/dist/main.js +14 -0
- package/dist/native/NativeMacOSProvider.js +3 -1
- package/dist/process/PendingOperations.js +59 -0
- package/dist/process/PrivateRuntimeRoot.js +33 -0
- package/dist/process/ProviderDeadline.js +95 -0
- package/dist/process/ProviderProcess.js +275 -0
- package/dist/replay/JavaScriptReplayWorker.js +286 -0
- package/dist/replay/LinuxJavaScriptReplayRunner.js +434 -0
- package/dist/replay/LinuxRuntimeClosure.js +46 -0
- package/dist/replay/LinuxSeccompPolicy.js +40 -0
- package/dist/replay/ReplayWorkerProtocol.js +55 -0
- package/dist/replay/SystemJavaScriptReplayHost.js +182 -0
- package/dist/server/createServer.js +53 -0
- package/dist/server/promptCompletion.js +9 -3
- package/dist/server/registerApplicationTools.js +115 -0
- package/dist/server/registerArtifactComparisonTool.js +16 -9
- package/dist/server/registerBrowserTools.js +33 -8
- package/dist/server/registerBundleComparisonTool.js +17 -20
- package/dist/server/registerElectronTools.js +45 -3
- package/dist/server/registerEnhancedTools.js +67 -19
- package/dist/server/registerEvidenceTools.js +5 -1
- package/dist/server/registerFunctionComparisonTool.js +14 -7
- package/dist/server/registerInvestigationTools.js +21 -17
- package/dist/server/registerManagedTools.js +6 -0
- package/dist/server/registerManagedWorkflowTools.js +277 -0
- package/dist/server/registerOfficialTools.js +11 -8
- package/dist/server/registerProcessComparisonTool.js +25 -47
- package/dist/server/registerSessionStatusTool.js +7 -7
- package/dist/server/registerSessionTools.js +57 -87
- package/dist/server/sessionEvidence.js +14 -19
- package/dist/server/toolInputValidation.js +77 -0
- package/dist/server/toolRegistrationOptions.js +79 -2
- package/dist/server/toolResult.js +25 -17
- package/package.json +17 -7
- package/scripts/rea.mjs +36 -2
- package/skills/rea-analysis/SKILL.md +59 -3
- /package/dist/{application → process}/ProcessOwnership.js +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { addArtifactContainsEdge, addStaticInferenceEdge, createElectronRoleNode, resolveArtifactPath, } from "./JavaScriptArtifactGraphContext.js";
|
|
2
|
+
import { artifactObservationEvidence, completeReconstructionCoverage, partialReconstructionCoverage, } from "./JavaScriptArtifactGraphEvidence.js";
|
|
3
|
+
/** Project HTML renderer entrypoints and their local script assets. */
|
|
4
|
+
export const addJavaScriptHtmlRoles = (context) => {
|
|
5
|
+
const byHtml = new Map();
|
|
6
|
+
for (const script of context.analysis.html_scripts) {
|
|
7
|
+
const existing = byHtml.get(script.html_path);
|
|
8
|
+
byHtml.set(script.html_path, existing === undefined ? [script] : [...existing, script]);
|
|
9
|
+
}
|
|
10
|
+
for (const [htmlPath, scripts] of byHtml) {
|
|
11
|
+
const html = context.filesByPath.get(htmlPath);
|
|
12
|
+
if (html === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
const role = createElectronRoleNode(context, {
|
|
15
|
+
kind: "electron-renderer",
|
|
16
|
+
anchor: html,
|
|
17
|
+
declaredPath: html.path,
|
|
18
|
+
resolvedPath: html.path,
|
|
19
|
+
mechanism: "html-script-entrypoint",
|
|
20
|
+
});
|
|
21
|
+
addArtifactContainsEdge(context, {
|
|
22
|
+
source: context.root,
|
|
23
|
+
target: role,
|
|
24
|
+
file: html,
|
|
25
|
+
operation: "discover-html-renderer",
|
|
26
|
+
});
|
|
27
|
+
for (const script of scripts) {
|
|
28
|
+
const resolvedPath = resolveArtifactPath(script.script_path, html.path, context.filesByPath);
|
|
29
|
+
if (resolvedPath === null)
|
|
30
|
+
continue;
|
|
31
|
+
const resolved = context.fileNodes.get(resolvedPath);
|
|
32
|
+
if (resolved === undefined)
|
|
33
|
+
continue;
|
|
34
|
+
addStaticInferenceEdge(context, {
|
|
35
|
+
source: role,
|
|
36
|
+
target: resolved,
|
|
37
|
+
file: html,
|
|
38
|
+
range: script.location,
|
|
39
|
+
coverage: completeReconstructionCoverage(),
|
|
40
|
+
relation: "loads",
|
|
41
|
+
properties: {
|
|
42
|
+
script_path: script.script_path,
|
|
43
|
+
resolved_path: resolvedPath,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Project original source names and optional content digests from approved maps. */
|
|
50
|
+
export const addJavaScriptSourceMapOriginals = (context) => {
|
|
51
|
+
for (const sourceMap of context.analysis.source_maps) {
|
|
52
|
+
const mapFile = context.filesByPath.get(sourceMap.path);
|
|
53
|
+
const mapNode = context.fileNodes.get(sourceMap.path);
|
|
54
|
+
if (mapFile === undefined || mapNode === undefined)
|
|
55
|
+
continue;
|
|
56
|
+
const coverage = sourceMap.status === "truncated"
|
|
57
|
+
? partialReconstructionCoverage([
|
|
58
|
+
{
|
|
59
|
+
name: "max-source-map-sources",
|
|
60
|
+
value: context.input.limits.max_source_map_sources,
|
|
61
|
+
unit: "items",
|
|
62
|
+
},
|
|
63
|
+
], sourceMap.omitted_sources, true)
|
|
64
|
+
: completeReconstructionCoverage();
|
|
65
|
+
for (const original of sourceMap.sources) {
|
|
66
|
+
const node = context.accumulator.addNode({
|
|
67
|
+
kind: "source-module",
|
|
68
|
+
identity: {
|
|
69
|
+
strategy: "source-map-original",
|
|
70
|
+
stability: "source-map-exact",
|
|
71
|
+
source_map_sha256: mapFile.sha256,
|
|
72
|
+
original_source: original.source,
|
|
73
|
+
source_sha256: original.content_sha256,
|
|
74
|
+
},
|
|
75
|
+
observations: [
|
|
76
|
+
{
|
|
77
|
+
label: original.source,
|
|
78
|
+
properties: {
|
|
79
|
+
source: original.source,
|
|
80
|
+
content_available: original.content !== null,
|
|
81
|
+
source_sha256: original.content_sha256,
|
|
82
|
+
},
|
|
83
|
+
evidence: artifactObservationEvidence({
|
|
84
|
+
sha256: mapFile.sha256,
|
|
85
|
+
path: mapFile.path,
|
|
86
|
+
operation: "parse-local-source-map",
|
|
87
|
+
coverage,
|
|
88
|
+
limitations: sourceMap.limitation === null ? [] : [sourceMap.limitation],
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
context.accumulator.addEdge({
|
|
94
|
+
source_node_id: mapNode.node_id,
|
|
95
|
+
target_node_id: node.node_id,
|
|
96
|
+
relation: "contains",
|
|
97
|
+
properties: { original_source: original.source },
|
|
98
|
+
evidence: artifactObservationEvidence({
|
|
99
|
+
sha256: mapFile.sha256,
|
|
100
|
+
path: mapFile.path,
|
|
101
|
+
operation: "parse-local-source-map",
|
|
102
|
+
coverage,
|
|
103
|
+
limitations: sourceMap.limitation === null ? [] : [sourceMap.limitation],
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const EXTRACTOR = {
|
|
2
|
+
name: "rea-javascript-artifact-reconstruction",
|
|
3
|
+
version: "1",
|
|
4
|
+
executable_sha256: null,
|
|
5
|
+
};
|
|
6
|
+
/** Exact artifact-byte evidence for one safely inventoried local file. */
|
|
7
|
+
export const artifactObservationEvidence = (input) => ({
|
|
8
|
+
authority: "artifact-bytes",
|
|
9
|
+
state: "observed",
|
|
10
|
+
confidence: "exact",
|
|
11
|
+
artifact: artifactReference(input.sha256),
|
|
12
|
+
location: {
|
|
13
|
+
available: true,
|
|
14
|
+
value: { kind: "artifact-path", path: input.path },
|
|
15
|
+
},
|
|
16
|
+
extractor: { ...EXTRACTOR, operation: input.operation },
|
|
17
|
+
coverage: input.coverage,
|
|
18
|
+
limitations: [...(input.limitations ?? [])],
|
|
19
|
+
evidence_ids: [],
|
|
20
|
+
});
|
|
21
|
+
/** Exact AST syntax evidence with an actionable source range. */
|
|
22
|
+
export const astObservationEvidence = (input) => {
|
|
23
|
+
const limitations = [
|
|
24
|
+
...(input.limitations ?? []),
|
|
25
|
+
...(input.coverage.status === "complete"
|
|
26
|
+
? []
|
|
27
|
+
: [
|
|
28
|
+
"AST coverage is incomplete; omitted or dynamic facts must not be interpreted as absence.",
|
|
29
|
+
]),
|
|
30
|
+
];
|
|
31
|
+
return {
|
|
32
|
+
authority: "ast-static-analysis",
|
|
33
|
+
state: "observed",
|
|
34
|
+
confidence: "exact",
|
|
35
|
+
artifact: artifactReference(input.sha256),
|
|
36
|
+
location: {
|
|
37
|
+
available: true,
|
|
38
|
+
value: { kind: "source-range", source: input.path, ...input.range },
|
|
39
|
+
},
|
|
40
|
+
extractor: { ...EXTRACTOR, operation: input.operation },
|
|
41
|
+
coverage: input.coverage,
|
|
42
|
+
limitations,
|
|
43
|
+
evidence_ids: [],
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** Explicit static relationship inference; never promoted to observation. */
|
|
47
|
+
export const staticInferenceEvidence = (input) => ({
|
|
48
|
+
authority: "static-relationship-inference",
|
|
49
|
+
state: "inferred",
|
|
50
|
+
confidence: input.confidence ?? "high",
|
|
51
|
+
artifact: artifactReference(input.sha256),
|
|
52
|
+
location: input.range === undefined
|
|
53
|
+
? { available: true, value: { kind: "artifact-path", path: input.path } }
|
|
54
|
+
: {
|
|
55
|
+
available: true,
|
|
56
|
+
value: { kind: "source-range", source: input.path, ...input.range },
|
|
57
|
+
},
|
|
58
|
+
extractor: { ...EXTRACTOR, operation: input.operation },
|
|
59
|
+
coverage: input.coverage,
|
|
60
|
+
limitations: [
|
|
61
|
+
"Static syntax does not prove that this relationship executes at runtime.",
|
|
62
|
+
...(input.limitations ?? []),
|
|
63
|
+
],
|
|
64
|
+
evidence_ids: [],
|
|
65
|
+
});
|
|
66
|
+
/** Unavailable AST fact that preserves a parse, approval, or limit gap. */
|
|
67
|
+
export const unavailableAstEvidence = (input) => ({
|
|
68
|
+
authority: "ast-static-analysis",
|
|
69
|
+
state: "unavailable",
|
|
70
|
+
confidence: "unknown",
|
|
71
|
+
artifact: artifactReference(input.sha256),
|
|
72
|
+
location: {
|
|
73
|
+
available: true,
|
|
74
|
+
value: { kind: "artifact-path", path: input.path },
|
|
75
|
+
},
|
|
76
|
+
extractor: { ...EXTRACTOR, operation: input.operation },
|
|
77
|
+
coverage: input.coverage,
|
|
78
|
+
limitations: [input.limitation, ...(input.limitations ?? [])],
|
|
79
|
+
evidence_ids: [],
|
|
80
|
+
});
|
|
81
|
+
/** Complete local projection coverage under named hard limits. */
|
|
82
|
+
export const completeReconstructionCoverage = (limits = []) => ({
|
|
83
|
+
status: "complete",
|
|
84
|
+
truncated: false,
|
|
85
|
+
omitted_count: 0,
|
|
86
|
+
limits: [...limits],
|
|
87
|
+
});
|
|
88
|
+
/** Partial reconstruction coverage with either exact truncation or a policy gap. */
|
|
89
|
+
export const partialReconstructionCoverage = (limits, omitted, truncated) => ({
|
|
90
|
+
status: "partial",
|
|
91
|
+
truncated,
|
|
92
|
+
omitted_count: omitted,
|
|
93
|
+
limits: [...limits],
|
|
94
|
+
});
|
|
95
|
+
const artifactReference = (sha256) => ({
|
|
96
|
+
available: true,
|
|
97
|
+
artifact_id: `art_${sha256}`,
|
|
98
|
+
sha256,
|
|
99
|
+
});
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { addStaticInferenceEdge, artifactLocalIdentity, createElectronRoleNode, javascriptAnalysisCoverage, linkElectronRoleToAsset, moduleLookupKey, resolveArtifactPath, sourceNodeFor, } from "./JavaScriptArtifactGraphContext.js";
|
|
2
|
+
import { astObservationEvidence, staticInferenceEvidence, } from "./JavaScriptArtifactGraphEvidence.js";
|
|
3
|
+
/** Project imports, workers, roles, endpoints, storage, and source-map links. */
|
|
4
|
+
export const addJavaScriptStaticFindings = (context) => {
|
|
5
|
+
for (const analyzed of context.analysis.files) {
|
|
6
|
+
const { file, javascript } = analyzed;
|
|
7
|
+
const asset = context.assetNodes.get(file.path);
|
|
8
|
+
if (javascript === null || asset === undefined)
|
|
9
|
+
continue;
|
|
10
|
+
const coverage = javascriptAnalysisCoverage(javascript, context.input);
|
|
11
|
+
for (const value of javascript.references)
|
|
12
|
+
addReference(context, { file, asset, value, coverage });
|
|
13
|
+
for (const value of javascript.endpoints)
|
|
14
|
+
addEndpoint(context, { file, asset, value, coverage });
|
|
15
|
+
for (const value of javascript.storage)
|
|
16
|
+
addStorage(context, { file, asset, value, coverage });
|
|
17
|
+
for (const value of javascript.role_paths)
|
|
18
|
+
addDiscoveredRole(context, { file, asset, value, coverage });
|
|
19
|
+
for (const value of javascript.source_map_urls)
|
|
20
|
+
addSourceMapEdge(context, { file, asset, value, coverage });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const addReference = (context, input) => {
|
|
24
|
+
const source = sourceNodeFor(context, input.file.path, input.value.module_key) ??
|
|
25
|
+
input.asset;
|
|
26
|
+
const resolved = input.value.specifier === null
|
|
27
|
+
? null
|
|
28
|
+
: resolveReference(context, input.file.path, input.value.specifier);
|
|
29
|
+
if (input.value.kind === "worker" || input.value.kind === "service-worker") {
|
|
30
|
+
const worker = context.accumulator.addNode({
|
|
31
|
+
kind: input.value.kind === "worker" ? "worker" : "service-worker",
|
|
32
|
+
identity: artifactLocalIdentity(input.file.sha256, input.value.kind, input.value.specifier ?? input.value.expression ?? "[dynamic]"),
|
|
33
|
+
observations: [
|
|
34
|
+
{
|
|
35
|
+
label: input.value.specifier,
|
|
36
|
+
properties: {
|
|
37
|
+
declared_specifier: input.value.specifier,
|
|
38
|
+
expression: input.value.expression,
|
|
39
|
+
resolved_path: resolved?.path ?? null,
|
|
40
|
+
},
|
|
41
|
+
evidence: staticInferenceEvidence({
|
|
42
|
+
sha256: input.file.sha256,
|
|
43
|
+
path: input.file.path,
|
|
44
|
+
range: input.value.location,
|
|
45
|
+
operation: "discover-worker",
|
|
46
|
+
coverage: input.coverage,
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
addStaticInferenceEdge(context, {
|
|
52
|
+
source,
|
|
53
|
+
target: worker,
|
|
54
|
+
file: input.file,
|
|
55
|
+
range: input.value.location,
|
|
56
|
+
coverage: input.coverage,
|
|
57
|
+
relation: "loads",
|
|
58
|
+
properties: { kind: input.value.kind },
|
|
59
|
+
});
|
|
60
|
+
if (resolved !== null)
|
|
61
|
+
addStaticInferenceEdge(context, {
|
|
62
|
+
source: worker,
|
|
63
|
+
target: resolved.node,
|
|
64
|
+
file: input.file,
|
|
65
|
+
range: input.value.location,
|
|
66
|
+
coverage: input.coverage,
|
|
67
|
+
relation: "maps_to",
|
|
68
|
+
properties: { resolved_path: resolved.path },
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const target = resolved?.node ??
|
|
73
|
+
unresolvedReferenceNode(context, input.file, input.value, input.coverage);
|
|
74
|
+
addStaticInferenceEdge(context, {
|
|
75
|
+
source,
|
|
76
|
+
target,
|
|
77
|
+
file: input.file,
|
|
78
|
+
range: input.value.location,
|
|
79
|
+
coverage: input.coverage,
|
|
80
|
+
relation: resolved?.file.kind === "native-addon" ? "loads" : "imports",
|
|
81
|
+
properties: {
|
|
82
|
+
kind: input.value.kind,
|
|
83
|
+
specifier: input.value.specifier,
|
|
84
|
+
expression: input.value.expression,
|
|
85
|
+
resolved_path: resolved?.path ?? null,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const addEndpoint = (context, input) => {
|
|
90
|
+
const source = sourceNodeFor(context, input.file.path, input.value.module_key) ??
|
|
91
|
+
input.asset;
|
|
92
|
+
const node = context.accumulator.addNode({
|
|
93
|
+
kind: "endpoint",
|
|
94
|
+
identity: artifactLocalIdentity(input.file.sha256, input.value.kind, input.value.value),
|
|
95
|
+
observations: [
|
|
96
|
+
{
|
|
97
|
+
label: input.value.value,
|
|
98
|
+
properties: {
|
|
99
|
+
endpoint_kind: input.value.kind,
|
|
100
|
+
value: input.value.value,
|
|
101
|
+
mechanism: input.value.mechanism,
|
|
102
|
+
},
|
|
103
|
+
evidence: astObservationEvidence({
|
|
104
|
+
sha256: input.file.sha256,
|
|
105
|
+
path: input.file.path,
|
|
106
|
+
range: input.value.location,
|
|
107
|
+
operation: "discover-static-endpoint",
|
|
108
|
+
coverage: input.coverage,
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
addStaticInferenceEdge(context, {
|
|
114
|
+
source,
|
|
115
|
+
target: node,
|
|
116
|
+
file: input.file,
|
|
117
|
+
range: input.value.location,
|
|
118
|
+
coverage: input.coverage,
|
|
119
|
+
relation: input.value.kind === "route" ? "exposes" : "calls",
|
|
120
|
+
properties: { mechanism: input.value.mechanism },
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const addStorage = (context, input) => {
|
|
124
|
+
const source = sourceNodeFor(context, input.file.path, input.value.module_key) ??
|
|
125
|
+
input.asset;
|
|
126
|
+
const node = context.accumulator.addNode({
|
|
127
|
+
kind: "storage",
|
|
128
|
+
identity: artifactLocalIdentity(input.file.sha256, input.value.kind, input.value.name ?? input.value.mechanism),
|
|
129
|
+
observations: [
|
|
130
|
+
{
|
|
131
|
+
label: input.value.name ?? input.value.kind,
|
|
132
|
+
properties: {
|
|
133
|
+
storage_kind: input.value.kind,
|
|
134
|
+
name: input.value.name,
|
|
135
|
+
mechanism: input.value.mechanism,
|
|
136
|
+
},
|
|
137
|
+
evidence: astObservationEvidence({
|
|
138
|
+
sha256: input.file.sha256,
|
|
139
|
+
path: input.file.path,
|
|
140
|
+
range: input.value.location,
|
|
141
|
+
operation: "discover-static-storage",
|
|
142
|
+
coverage: input.coverage,
|
|
143
|
+
}),
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
addStaticInferenceEdge(context, {
|
|
148
|
+
source,
|
|
149
|
+
target: node,
|
|
150
|
+
file: input.file,
|
|
151
|
+
range: input.value.location,
|
|
152
|
+
coverage: input.coverage,
|
|
153
|
+
relation: "persists_to",
|
|
154
|
+
properties: { mechanism: input.value.mechanism },
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
const addDiscoveredRole = (context, input) => {
|
|
158
|
+
const resolvedPath = resolveArtifactPath(input.value.path, input.file.path, context.filesByPath);
|
|
159
|
+
const role = createElectronRoleNode(context, {
|
|
160
|
+
kind: input.value.role === "preload" ? "electron-preload" : "electron-renderer",
|
|
161
|
+
anchor: input.file,
|
|
162
|
+
declaredPath: input.value.path,
|
|
163
|
+
resolvedPath,
|
|
164
|
+
mechanism: input.value.mechanism,
|
|
165
|
+
range: input.value.location,
|
|
166
|
+
coverage: input.coverage,
|
|
167
|
+
});
|
|
168
|
+
const source = sourceNodeFor(context, input.file.path, input.value.module_key) ??
|
|
169
|
+
input.asset;
|
|
170
|
+
addStaticInferenceEdge(context, {
|
|
171
|
+
source,
|
|
172
|
+
target: role,
|
|
173
|
+
file: input.file,
|
|
174
|
+
range: input.value.location,
|
|
175
|
+
coverage: input.coverage,
|
|
176
|
+
relation: "loads",
|
|
177
|
+
properties: { mechanism: input.value.mechanism },
|
|
178
|
+
});
|
|
179
|
+
linkElectronRoleToAsset(context, {
|
|
180
|
+
role,
|
|
181
|
+
anchor: input.file,
|
|
182
|
+
path: resolvedPath,
|
|
183
|
+
range: input.value.location,
|
|
184
|
+
coverage: input.coverage,
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const addSourceMapEdge = (context, input) => {
|
|
188
|
+
const resolvedPath = resolveArtifactPath(input.value.declared_url, input.file.path, context.filesByPath);
|
|
189
|
+
const resolvedFile = resolvedPath === null ? undefined : context.filesByPath.get(resolvedPath);
|
|
190
|
+
const resolvedNode = resolvedPath === null ? undefined : context.fileNodes.get(resolvedPath);
|
|
191
|
+
const target = resolvedFile?.kind === "source-map" && resolvedNode !== undefined
|
|
192
|
+
? resolvedNode
|
|
193
|
+
: context.accumulator.addNode({
|
|
194
|
+
kind: "source-map",
|
|
195
|
+
identity: artifactLocalIdentity(input.file.sha256, "unresolved-source-map", input.value.declared_url),
|
|
196
|
+
observations: [
|
|
197
|
+
{
|
|
198
|
+
label: input.value.declared_url,
|
|
199
|
+
properties: {
|
|
200
|
+
declared_url: input.value.declared_url,
|
|
201
|
+
resolved_path: resolvedPath,
|
|
202
|
+
available: false,
|
|
203
|
+
},
|
|
204
|
+
evidence: staticInferenceEvidence({
|
|
205
|
+
sha256: input.file.sha256,
|
|
206
|
+
path: input.file.path,
|
|
207
|
+
range: input.value.location,
|
|
208
|
+
operation: "discover-source-map",
|
|
209
|
+
coverage: input.coverage,
|
|
210
|
+
confidence: "medium",
|
|
211
|
+
limitations: [
|
|
212
|
+
"The declared source map was not present in the inventoried artifact.",
|
|
213
|
+
],
|
|
214
|
+
}),
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
addStaticInferenceEdge(context, {
|
|
219
|
+
source: input.asset,
|
|
220
|
+
target,
|
|
221
|
+
file: input.file,
|
|
222
|
+
range: input.value.location,
|
|
223
|
+
coverage: input.coverage,
|
|
224
|
+
relation: "maps_to",
|
|
225
|
+
properties: {
|
|
226
|
+
declared_url: input.value.declared_url,
|
|
227
|
+
resolved_path: resolvedPath,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const resolveReference = (context, sourcePath, specifier) => {
|
|
232
|
+
const module = context.moduleNodes.get(moduleLookupKey(sourcePath, specifier));
|
|
233
|
+
if (module !== undefined) {
|
|
234
|
+
const file = context.filesByPath.get(sourcePath);
|
|
235
|
+
return file === undefined
|
|
236
|
+
? null
|
|
237
|
+
: { path: `${sourcePath}#module:${specifier}`, file, node: module };
|
|
238
|
+
}
|
|
239
|
+
const path = resolveArtifactPath(specifier, sourcePath, context.filesByPath);
|
|
240
|
+
if (path === null)
|
|
241
|
+
return null;
|
|
242
|
+
const file = context.filesByPath.get(path);
|
|
243
|
+
const node = context.fileNodes.get(path);
|
|
244
|
+
return file === undefined || node === undefined ? null : { path, file, node };
|
|
245
|
+
};
|
|
246
|
+
const unresolvedReferenceNode = (context, file, reference, coverage) => context.accumulator.addNode({
|
|
247
|
+
kind: "javascript-module",
|
|
248
|
+
identity: artifactLocalIdentity(file.sha256, "unresolved-reference", `${reference.kind}:${reference.specifier ?? reference.expression ?? "[dynamic]"}`),
|
|
249
|
+
observations: [
|
|
250
|
+
{
|
|
251
|
+
label: reference.specifier,
|
|
252
|
+
properties: {
|
|
253
|
+
reference_kind: reference.kind,
|
|
254
|
+
specifier: reference.specifier,
|
|
255
|
+
expression: reference.expression,
|
|
256
|
+
resolution: "unresolved",
|
|
257
|
+
},
|
|
258
|
+
evidence: staticInferenceEvidence({
|
|
259
|
+
sha256: file.sha256,
|
|
260
|
+
path: file.path,
|
|
261
|
+
range: reference.location,
|
|
262
|
+
operation: "resolve-static-reference",
|
|
263
|
+
coverage,
|
|
264
|
+
confidence: "low",
|
|
265
|
+
limitations: [
|
|
266
|
+
"The static reference could not be resolved within the inventoried artifact.",
|
|
267
|
+
],
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
});
|