diff --git a/scripts/lib/ghidra-legacy-snapshot-e2e.mjs b/scripts/lib/ghidra-legacy-snapshot-e2e.mjs new file mode 100644 index 00000000000..c4d5b312479 --- /dev/null +++ b/scripts/lib/ghidra-legacy-snapshot-e2e.mjs @@ -0,0 +1,50 @@ +import { + createAnalysisSnapshotEntry, + parseAnalysisSnapshot, + snapshotBinding, + snapshotTarget, +} from "../../dist/domain/analysisSnapshot.js"; +import { createEvidence } from "../../dist/domain/evidence.js"; +import { createEvidenceBundle } from "../../dist/domain/evidenceBundle.js"; + +export function createLegacyGhidraSnapshot({ + nativeTarget, + observed, + result, + legacyProfile, +}) { + const evidence = createEvidence(nativeTarget, observed.provider, { + operation: observed.operation, + parameters: observed.parameters, + result, + rawResult: result, + analysisProfile: legacyProfile, + limitations: observed.limitations, + locations: observed.locations, + }); + const binding = snapshotBinding(legacyProfile); + const identity = snapshotTarget(nativeTarget); + return parseAnalysisSnapshot({ + target: identity, + binding, + entries: [ + createAnalysisSnapshotEntry({ + target: identity, + binding, + operation: observed.operation, + parameters: observed.parameters, + execution: { + result, + rawResult: result, + provider: observed.provider, + analysisProfile: legacyProfile, + limitations: observed.limitations, + locations: observed.locations, + subject: evidence.subject, + }, + }), + ], + workflow_entries: [], + evidence_bundle: createEvidenceBundle([evidence]), + }); +} diff --git a/scripts/lib/ghidra-reference-snapshot-e2e.mjs b/scripts/lib/ghidra-reference-snapshot-e2e.mjs index f89ea72c26e..1a03257fb52 100644 --- a/scripts/lib/ghidra-reference-snapshot-e2e.mjs +++ b/scripts/lib/ghidra-reference-snapshot-e2e.mjs @@ -12,15 +12,8 @@ import { join } from "node:path"; import { promisify } from "node:util"; import { parseBinaryTarget } from "../../dist/application/BinaryTargetResolver.js"; import { createAnalysisProfile } from "../../dist/domain/analysisProfile.js"; -import { - createAnalysisSnapshotEntry, - parseAnalysisSnapshot, - serializeAnalysisSnapshot, - snapshotBinding, - snapshotTarget, -} from "../../dist/domain/analysisSnapshot.js"; -import { createEvidence } from "../../dist/domain/evidence.js"; -import { createEvidenceBundle } from "../../dist/domain/evidenceBundle.js"; +import { serializeAnalysisSnapshot } from "../../dist/domain/analysisSnapshot.js"; +import { createLegacyGhidraSnapshot } from "./ghidra-legacy-snapshot-e2e.mjs"; /** Reject a valid older snapshot whose instruction-only collector omitted a real edge. */ export async function verifyLegacyGhidraReferenceSnapshot( @@ -69,39 +62,11 @@ export async function verifyLegacyGhidraReferenceSnapshot( result.incoming_references.length, observed.normalized_result.incoming_references.length - 1, ); - const evidence = createEvidence(nativeTarget, observed.provider, { - operation: observed.operation, - parameters: observed.parameters, + const snapshot = createLegacyGhidraSnapshot({ + nativeTarget, + observed, result, - rawResult: result, - analysisProfile: legacyProfile, - limitations: observed.limitations, - locations: observed.locations, - }); - const binding = snapshotBinding(legacyProfile); - const identity = snapshotTarget(nativeTarget); - const snapshot = parseAnalysisSnapshot({ - target: identity, - binding, - entries: [ - createAnalysisSnapshotEntry({ - target: identity, - binding, - operation: observed.operation, - parameters: observed.parameters, - execution: { - result, - rawResult: result, - provider: observed.provider, - analysisProfile: legacyProfile, - limitations: observed.limitations, - locations: observed.locations, - subject: evidence.subject, - }, - }), - ], - workflow_entries: [], - evidence_bundle: createEvidenceBundle([evidence]), + legacyProfile, }); assert.equal( snapshot.entries.length, diff --git a/scripts/lib/ghidra-value-scope-snapshot-e2e.mjs b/scripts/lib/ghidra-value-scope-snapshot-e2e.mjs index bf5daed9c50..82204fb0cf5 100644 --- a/scripts/lib/ghidra-value-scope-snapshot-e2e.mjs +++ b/scripts/lib/ghidra-value-scope-snapshot-e2e.mjs @@ -5,15 +5,8 @@ import { join } from "node:path"; import { parseBinaryTarget } from "../../dist/application/BinaryTargetResolver.js"; import { createAnalysisProfile } from "../../dist/domain/analysisProfile.js"; -import { - createAnalysisSnapshotEntry, - parseAnalysisSnapshot, - serializeAnalysisSnapshot, - snapshotBinding, - snapshotTarget, -} from "../../dist/domain/analysisSnapshot.js"; -import { createEvidence } from "../../dist/domain/evidence.js"; -import { createEvidenceBundle } from "../../dist/domain/evidenceBundle.js"; +import { serializeAnalysisSnapshot } from "../../dist/domain/analysisSnapshot.js"; +import { createLegacyGhidraSnapshot } from "./ghidra-legacy-snapshot-e2e.mjs"; import { requireMcpLifecycleResult, requireMcpOutput, @@ -43,39 +36,11 @@ export async function verifyLegacyValueScopeSnapshot( value.includes("LOAD and STORE") && value.includes("address varnodes"); assert.ok(flow.limitations.some(describesScope)); flow.limitations = flow.limitations.filter((value) => !describesScope(value)); - const evidence = createEvidence(nativeTarget, observed.provider, { - operation: observed.operation, - parameters: observed.parameters, + const snapshot = createLegacyGhidraSnapshot({ + nativeTarget, + observed, result, - rawResult: result, - analysisProfile: legacyProfile, - limitations: observed.limitations, - locations: observed.locations, - }); - const binding = snapshotBinding(legacyProfile); - const identity = snapshotTarget(nativeTarget); - const snapshot = parseAnalysisSnapshot({ - target: identity, - binding, - entries: [ - createAnalysisSnapshotEntry({ - target: identity, - binding, - operation: observed.operation, - parameters: observed.parameters, - execution: { - result, - rawResult: result, - provider: observed.provider, - analysisProfile: legacyProfile, - limitations: observed.limitations, - locations: observed.locations, - subject: evidence.subject, - }, - }), - ], - workflow_entries: [], - evidence_bundle: createEvidenceBundle([evidence]), + legacyProfile, }); const path = join(env.TMPDIR, `legacy-value-scope-${randomUUID()}.json`); await writeFile(path, serializeAnalysisSnapshot(snapshot), { flag: "wx" });