dosMzHeader(): Coder<DosMzHeader>
Creates a coder for a DOS MZ executable header.
Covers only the fixed 64-byte header — it does not read the DOS stub
program or anything at newHeaderOffset. Nothing is validated on encode
or decode: signature is surfaced and written exactly as given.
Decode a known header (a minimal "hello world" .exe)
Decode a known header (a minimal "hello world" .exe)
import { assertEquals } from "@std/assert"; import { dosMzHeader, MZ_HEADER_SIZE, MZ_SIGNATURE } from "@binstruct/dos-mz"; // deno-fmt-ignore const wire = new Uint8Array([ 0x4d, 0x5a, // signature = "MZ" 0x90, 0x00, // lastPageBytes = 0x90 0x03, 0x00, // pageCount = 3 0x00, 0x00, // relocationCount = 0 0x04, 0x00, // headerParagraphs = 4 0x00, 0x00, // minExtraParagraphs = 0 0xff, 0xff, // maxExtraParagraphs = 0xffff 0x00, 0x00, // initialSS = 0 0xb8, 0x00, // initialSP = 0xb8 0x00, 0x00, // checksum = 0 0x00, 0x00, // initialIP = 0 0x00, 0x00, // initialCS = 0 0x40, 0x00, // relocationTableOffset = 0x40 0x00, 0x00, // overlayNumber = 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved1 0x00, 0x00, // oemIdentifier = 0 0x00, 0x00, // oemInfo = 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved2 0x80, 0x00, 0x00, 0x00, // newHeaderOffset = 0x80 ]); const [decoded, read] = dosMzHeader().decode(wire); assertEquals(read, MZ_HEADER_SIZE); assertEquals(decoded.signature, MZ_SIGNATURE); assertEquals(decoded.pageCount, 3); assertEquals(decoded.relocationTableOffset, 0x40); assertEquals(decoded.newHeaderOffset, 0x80);
Coder<DosMzHeader>
A coder for DosMzHeader values.