← Sat, Nov 14 digest

Creating a self booting ZIP archive

read article ↗ hn thread ↗

A developer engineered a fully functional ZIP archive that doubles as a bootable x86 operating system kernel and MBR boot sector.

read it A fascinating deep dive into binary polyglots and x86 boot mechanics that rewards reading the full technical breakdown.

summary

The author built a self-booting ZIP archive by carefully crafting the initial local file header to act as a valid MBR boot sector and Multiboot kernel header. By exploiting x86 opcodes that overlap with ZIP magic numbers and routing execution past them with a jump instruction placed in the timestamp field, the file can boot directly in QEMU or on vintage hardware. The archive contains its own source code and build scripts to recreate itself from scratch.

key points

  1. The first bytes of a ZIP local file header decode to valid x86 assembly instructions, allowing the metadata to double as executable code.
  2. A relative jump instruction is cleverly embedded in the ZIP file timestamp field to bypass non-executable header sections and reach the bootloader.
  3. The archive complies with the Multiboot specification, allowing it to boot in QEMU or from a floppy/hard drive on vintage x86 hardware.

who should read it

Low-level engineers, systems programmers, and retrocomputing hobbyists.

discussion warm

consensus

Commenters thoroughly enjoy the deep dive into file format polyglots and share insights into other creative uses for ZIP files like HTTP range requests.

best comment by sltkr ↗

Note that the end-of-central-directory record at the end of the file contains the size and offset of the central directory, so if the central directory is not in the final 64 KiB you already have, you know exactly which range you need to request to get it (i.e. you don't need to keep scanning backwards 64 KiB at a time).

It points out that ZIP's end-of-central-directory record eliminates the need for backward scanning when fetching files over HTTP.

Generated by an LLM from the article and thread. Check the sources before relying on it.