diff --git a/src/domain/uefi/uefiFirmwareAnalysis.ts b/src/domain/uefi/uefiFirmwareAnalysis.ts index d91ba65af9..a14d5df800 100644 --- a/src/domain/uefi/uefiFirmwareAnalysis.ts +++ b/src/domain/uefi/uefiFirmwareAnalysis.ts @@ -108,7 +108,7 @@ export const uefiCompressionSchema = z.union([ kind: z.enum([ "lzma-custom", "lzmaf86", - "ami-zlib", + "amd-zlib", "tiano", "efi-standard", "unknown-compression", diff --git a/src/uefi/FfsSections.test.ts b/src/uefi/FfsSections.test.ts index b18c2c3c93..e5014b386e 100644 --- a/src/uefi/FfsSections.test.ts +++ b/src/uefi/FfsSections.test.ts @@ -9,7 +9,7 @@ import { import { imageRegion } from "./UefiBytes.js"; import { AMD_ZLIB_HEADER_LENGTH, - peelAmiZlibPayload, + peelAmdZlibPayload, walkSections, } from "./FfsSections.js"; @@ -47,7 +47,7 @@ it("classifies a guided LZMA section through its definition GUID", () => { expect(draft?.payload).toEqual({ start: 24, end: 24 + compressed.length }); }); -it("classifies the AMI-zlib guided section and peels its AMD header", () => { +it("classifies the AMD-zlib guided section and peels its AMD header", () => { const stream = Buffer.from([0x78, 0xda, 0x01, 0x02, 0x03]); const amdHeader = Buffer.alloc(AMD_ZLIB_HEADER_LENGTH, 0); amdHeader.writeUInt32LE(stream.length, 0x14); @@ -60,7 +60,7 @@ it("classifies the AMI-zlib guided section and peels its AMD header", () => { expect(walked.sections).toHaveLength(1); const draft = walked.sections[0]; expect(draft?.compression).toMatchObject({ - kind: "ami-zlib", + kind: "amd-zlib", guid: "ce3233f5-2cd6-4d87-9152-4a238bb6d1c4", dataOffset: 24, attributes: 0, @@ -69,9 +69,9 @@ it("classifies the AMI-zlib guided section and peels its AMD header", () => { start: 24, end: 24 + AMD_ZLIB_HEADER_LENGTH + stream.length, }); - const peeled = peelAmiZlibPayload(Buffer.concat([amdHeader, stream])); + const peeled = peelAmdZlibPayload(Buffer.concat([amdHeader, stream])); expect(peeled).toEqual({ stream, declaredCompressedSize: stream.length }); - expect(peelAmiZlibPayload(Buffer.alloc(0x40, 0))).toBeNull(); + expect(peelAmdZlibPayload(Buffer.alloc(0x40, 0))).toBeNull(); }); it("marks unknown definition GUIDs instead of guessing", () => { diff --git a/src/uefi/FfsSections.ts b/src/uefi/FfsSections.ts index d2c82ca438..4d84a3b665 100644 --- a/src/uefi/FfsSections.ts +++ b/src/uefi/FfsSections.ts @@ -1,4 +1,5 @@ import { BinaryReader } from "../domain/binaryContainer.js"; +import type { UefiSectionRecord } from "../domain/uefi/uefiFirmwareAnalysis.js"; import { Buffer } from "node:buffer"; import { absoluteOffset, @@ -48,15 +49,10 @@ export interface SectionDraft { readonly compression: | { readonly kind: "none" } | { - readonly kind: - | "lzma-custom" - | "lzmaf86" - | "ami-zlib" - | "tiano" - | "unknown-compression" - | "efi-standard" - | "crc32-guided" - | "unknown-guid"; + readonly kind: Exclude< + UefiSectionRecord["compression"]["kind"], + "none" + >; readonly guid: string | null; readonly dataOffset: number; readonly attributes: number | null; @@ -125,7 +121,7 @@ function guidedSectionContent( if (kind === "lzma-custom") return { kind: "decode", format: "lzma" }; if (kind === "lzmaf86") return { kind: "decode", format: "lzmaf86" }; - if (kind === "ami-zlib") return { kind: "decode", format: "zlib" }; + if (kind === "amd-zlib") return { kind: "decode", format: "zlib" }; if ( (attributes & GUIDED_PROCESSING_REQUIRED) === 0 && @@ -304,8 +300,8 @@ export function walkSections( */ export const AMD_ZLIB_HEADER_LENGTH = 0x100; -/** Peel the 0x100-byte AMD header off one ami-zlib payload, or null when short. */ -export function peelAmiZlibPayload( +/** Peel the 0x100-byte AMD header off one amd-zlib payload, or null when short. */ +export function peelAmdZlibPayload( payload: Buffer, ): { stream: Buffer; declaredCompressedSize: number } | null { if (payload.length < AMD_ZLIB_HEADER_LENGTH) { diff --git a/src/uefi/UefiCodeTables.ts b/src/uefi/UefiCodeTables.ts index d87cd51e8a..f1bcc26533 100644 --- a/src/uefi/UefiCodeTables.ts +++ b/src/uefi/UefiCodeTables.ts @@ -57,12 +57,12 @@ export const SECTION_TYPE_NAME_BY_CODE: Readonly> = export const COMPRESSION_GUID_BY_DISPLAY: Readonly< Record< string, - "lzma-custom" | "lzmaf86" | "ami-zlib" | "tiano" | "crc32-guided" + "lzma-custom" | "lzmaf86" | "amd-zlib" | "tiano" | "crc32-guided" > > = { "ee4e5898-3914-4259-9d6e-dc7bd79403cf": "lzma-custom", "d42ae6bd-1352-4bfb-909a-ca72a6eae889": "lzmaf86", - "ce3233f5-2cd6-4d87-9152-4a238bb6d1c4": "ami-zlib", + "ce3233f5-2cd6-4d87-9152-4a238bb6d1c4": "amd-zlib", "a31280ad-481e-41b6-95e8-127f4c984779": "tiano", "fc1bcdb0-7d31-49aa-936a-a4600d9dd083": "crc32-guided", }; diff --git a/src/uefi/UefiImageScan.test.ts b/src/uefi/UefiImageScan.test.ts index 18d54555ed..3193c4e665 100644 --- a/src/uefi/UefiImageScan.test.ts +++ b/src/uefi/UefiImageScan.test.ts @@ -332,7 +332,7 @@ it("preserves a decoded sibling after an on-disk retrieval wildcard", async () = ); }); -it("decodes AMI-zlib guided sections after peeling the AMD header", async () => { +it("decodes AMD-zlib guided sections after peeling the AMD header", async () => { const nestedInner = buildFfsFile({ guid: "2b111111-2222-3333-4444-555555555555", typeCode: 0x07, @@ -364,7 +364,7 @@ it("decodes AMI-zlib guided sections after peeling the AMD header", async () => expect(nested?.logical_path).toContain("/zlib/FV@"); const zlibSection = summary.volumes[0]?.ffs_files[0]?.sections[0]; expect(zlibSection?.compression).toMatchObject({ - kind: "ami-zlib", + kind: "amd-zlib", data_offset: 24, }); expect(zlibSection?.sub_volumes).toEqual([summary.volumes[1]?.logical_path]); diff --git a/src/uefi/UefiImageScan.ts b/src/uefi/UefiImageScan.ts index a665ca3b32..577377cd90 100644 --- a/src/uefi/UefiImageScan.ts +++ b/src/uefi/UefiImageScan.ts @@ -30,7 +30,7 @@ import { } from "./FfsFile.js"; import { AMD_ZLIB_HEADER_LENGTH, - peelAmiZlibPayload, + peelAmdZlibPayload, startsWithSectionFrame, walkSections, type UefiDecodeFormat, @@ -982,7 +982,7 @@ export const scanUefiImage = async ( ); let carrier = payload; if (format === "zlib") { - const peeled = peelAmiZlibPayload(payload.bytes); + const peeled = peelAmdZlibPayload(payload.bytes); if ( peeled === null || peeled.declaredCompressedSize !== peeled.stream.length