diff --git a/scripts/verify/advertised-schemas/tools/extract_uefi_firmware.json b/scripts/verify/advertised-schemas/tools/extract_uefi_firmware.json index 8f26b416674..dc5669c732a 100644 --- a/scripts/verify/advertised-schemas/tools/extract_uefi_firmware.json +++ b/scripts/verify/advertised-schemas/tools/extract_uefi_firmware.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "5d5b440228963575", + "input compact": "bd4ced5a290a86f6", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/scripts/verify/advertised-schemas/tools/inspect_uefi_firmware.json b/scripts/verify/advertised-schemas/tools/inspect_uefi_firmware.json index c8148345ac5..30c90cd3738 100644 --- a/scripts/verify/advertised-schemas/tools/inspect_uefi_firmware.json +++ b/scripts/verify/advertised-schemas/tools/inspect_uefi_firmware.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "129e7906d66c823a", + "input compact": "a704b08506e82abe", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/src/domain/analysisView/uefiExtractionView.test.ts b/src/domain/analysisView/uefiExtractionView.test.ts new file mode 100644 index 00000000000..b0f06c1e8a4 --- /dev/null +++ b/src/domain/analysisView/uefiExtractionView.test.ts @@ -0,0 +1,93 @@ +import { expect, it } from "vitest"; +import { projectAnalysisView } from "./analysisView.js"; +import type { AnalysisViewParent } from "./analysisViewParent.js"; +import { analysisViewRequestSchema } from "./analysisViewRequest.js"; + +const digest = (fill: string) => fill.repeat(64); +const file = (index: number, ffs_file?: unknown) => ({ + relative_path: `flash/FV@0x0/FFS-x@0x${index.toString(16)}/section-0.payload.bin`, + path: `/out/flash/FV@0x0/FFS-x@0x${index.toString(16)}/section-0.payload.bin`, + size: 16 + index, + sha256: digest(index.toString(16)), + original_file_range: { offset: 0x100 + index * 0x40, length: 16 + index }, + source_stream: null, + source_range: { offset: 0x100 + index * 0x40, length: 16 + index }, + runtime_address: null, + media_type: "application/vnd.microsoft.portable-executable", + source: "raw-section", + parent_logical_path: `flash/FV@0x0/FFS:x@0x${index.toString(16)}`, + ...(ffs_file === undefined ? {} : { ffs_file }), +}); +const extraction = (files: readonly unknown[]) => ({ + parser: { name: "rea-uefi", version: "1.0.0" }, + selection: { + offset: 0, + length: 4096, + source_stream: null, + target_kind: "whole-image", + }, + output_directory: "/out", + coverage: "complete", + files, + derivations: [], + extraction_gaps: [], + diagnostics: "1 volumes mapped", + published_bytes: 0, +}); +const project = (report: unknown, view: unknown) => { + const parent: AnalysisViewParent = { + predicateType: "rea.analysis", + evidenceId: `ev_${digest("b")}`, + operation: "extract_uefi_firmware", + normalizedResult: report, + limitations: [], + }; + const result = projectAnalysisView( + parent, + analysisViewRequestSchema.parse(view), + ); + if (!result.ok) throw result.error; + return result.value; +}; + +it("reads extraction Evidence saved before files recorded their FFS owner", () => { + const report = extraction([file(0), file(1)]); + expect(project(report, { kind: "summary" })).toMatchObject({ + summary: { file_count: 2, files_preview: { omitted: 0 } }, + }); + expect( + project(report, { + kind: "uefi-extraction", + collection: "files", + order: "size-desc", + }), + ).toMatchObject({ + items: [{ source_index: 1 }, { source_index: 0 }], + coverage: { total: 2 }, + }); + // An unrecorded owner is unknown, so it matches no owner filter. + expect( + project(report, { + kind: "uefi-extraction", + collection: "files", + ffs_type_names: ["driver"], + }), + ).toMatchObject({ items: [], coverage: { total: 0 } }); +}); + +it("accepts owner filters longer than 64 values", () => { + const owner = { + guid: "9e21fd93-9c72-4c15-8c4b-e77f9db8d4d2", + ui_string: "DemoDxe", + type_name: "driver", + logical_path: "flash/FV@0x0/FFS:9e21fd93-9c72-4c15-8c4b-e77f9db8d4d2@0x48", + }; + const names = Array.from({ length: 100 }, (_, i) => `Other${String(i)}`); + expect( + project(extraction([file(0, owner), file(1, null)]), { + kind: "uefi-extraction", + collection: "files", + ffs_ui_names: [...names, "DemoDxe"], + }), + ).toMatchObject({ items: [{ source_index: 0 }], coverage: { total: 1 } }); +}); diff --git a/src/domain/analysisView/uefiExtractionView.ts b/src/domain/analysisView/uefiExtractionView.ts index 0219b63f6c8..4956327bfd9 100644 --- a/src/domain/analysisView/uefiExtractionView.ts +++ b/src/domain/analysisView/uefiExtractionView.ts @@ -40,7 +40,6 @@ const exactNames = (schema: Schema, what: string) => z .array(schema) .min(1) - .max(64) .optional() .describe(`Exact ${what}; any listed value matches`); @@ -204,7 +203,8 @@ const fileFilter = (view: FilesView) => view.ffs_type_names === undefined ? undefined : (file: ExtractedFile): boolean => { - const owner = file.ffs_file; + // Older Evidence omits the owner; an unrecorded owner matches no owner filter. + const owner = file.ffs_file ?? null; return ( (view.media_types === undefined || (file.media_type !== null && diff --git a/src/domain/analysisView/uefiFirmwareView.ts b/src/domain/analysisView/uefiFirmwareView.ts index 5be4838e3a8..0e51ff66c03 100644 --- a/src/domain/analysisView/uefiFirmwareView.ts +++ b/src/domain/analysisView/uefiFirmwareView.ts @@ -48,7 +48,6 @@ const exactNames = (schema: Schema, what: string) => z .array(schema) .min(1) - .max(64) .optional() .describe(`Exact ${what}; any listed value matches`); diff --git a/src/domain/uefi/uefiFirmwareAnalysis.ts b/src/domain/uefi/uefiFirmwareAnalysis.ts index 0d122d12d9b..a1a0e239c20 100644 --- a/src/domain/uefi/uefiFirmwareAnalysis.ts +++ b/src/domain/uefi/uefiFirmwareAnalysis.ts @@ -480,8 +480,9 @@ export const uefiResultSchemas = { parent_logical_path: z.string().nullable(), ffs_file: uefiExtractedFileOwnerSchema .nullable() + .optional() .describe( - "FFS file whose body or section produced these bytes; null for a stream outside any mapped file", + "FFS file whose body or section produced these bytes; null for a stream outside any mapped file. The extractor always records it; Evidence saved before this field existed omits it.", ), }), ),