Skip to the yard
Waxsealai

Developer Builds a Valid ZIP Archive That Also Boots as a BIOS and Multiboot OS Image

Shipped
Shipper
[email protected] (Bruno Ferreira)
Readers
737

David Oberhollenzer’s ZIPHEAD.COM combines a standard ZIP archive with Multiboot support and direct BIOS boot, using carefully chosen bytes.

Developer Builds a Valid ZIP Archive That Also Boots as a BIOS and Multiboot OS Image

A single file can serve three roles here: it’s a valid ZIP archive, a Multiboot-compatible operating system image, and a disk image that a compatible PC BIOS can boot directly. Developer David Oberhollenzer, who goes by Goliath, built the file by arranging its archive metadata and executable bytes so each format’s rules are satisfied at once. The result is a compact demonstration of how file formats can overlap when their layouts leave room for creative interpretation.

The file, named ZIPHEAD.COM, can be unpacked as a ZIP like an ordinary archive. It can also be started through GRUB, QEMU, or another Multiboot-compatible loader. Written to a floppy as a disk image, it can boot directly on compatible BIOS-based PCs without alteration. Those uses rely on different parts of the same byte sequence: archive readers interpret it as a collection of files, while boot software treats selected bytes as startup information and code.

Putting boot information inside an archive

ZIP’s layout makes this combination possible. The archive’s central directory, which records information about its files, appears at the end. Before that directory, the archive stores each file’s local header and contents in sequence. That means a ZIP begins with file data structures rather than with the directory that describes the archive as a whole.

A local file header starts with the two characters “PK” followed by the bytes 03 04. The header then carries metadata such as the filename, along with optional fields, before the file’s contents begin. ZIP allows a file to be stored without compression. Oberhollenzer uses that option for the archive’s first entry, ZIPHEAD.COM, so its contents can include executable code and boot information in a predictable location.

For Multiboot, the image needs a specific marker, 0x1BADB002, within its first 8 KiB, followed by flags and a checksum. Oberhollenzer places the required data in ZIPHEAD.COM’s contents and includes information identifying where the bootloader is located. A Multiboot loader can scan for the marker, read the initialization details, and hand over control. It doesn’t need to interpret the ZIP file’s other structures as part of starting the system.

This division of responsibilities is useful to the construction: once a loader has found the Multiboot information, the image’s bootloader handles the remaining startup work. The same uncompressed ZIP entry contains that bootloader. The archive’s data therefore has to meet the ZIP reader’s expectations while also carrying the bytes that the loader needs.

Making the first 512 bytes executable

Direct BIOS startup imposes a different constraint. A BIOS reads the first 512 bytes from a bootable disk and checks for the signature bytes 0x55AA at positions 510 and 511. If the signature is present, the BIOS begins executing code from the start of that sector. For an image that must remain a ZIP file, those first bytes also need to form a usable ZIP header.

Oberhollenzer places the BIOS signature at the required offset within ZIPHEAD.COM’s contents. The Multiboot marker and related data can coexist with it because the Multiboot specification permits the boot information to appear at different locations within the image. The challenge is the beginning of the file: BIOS execution starts at byte zero, which is also where the ZIP local header begins.

That header isn’t normally machine code. Its opening “PK” and 03 04 bytes, however, happen to correspond to CPU instructions that can execute without disrupting the startup process. Oberhollenzer then adjusts metadata fields, including the modification-time bytes, so they encode instructions that safely advance execution to later code. The header remains meaningful to ZIP software while its bytes also participate in the boot sequence.

Each byte has to work in context. Values used for a filename, timestamp, or other archive field must remain acceptable to ZIP readers, avoid instructions that would crash the processor, and contribute to setting up the boot process where needed. Once control reaches the uncompressed bootloader, it can continue with the rest of startup. The trick is less a matter of hiding a program inside an archive than of choosing values that satisfy several separate interpreters at once.

A format puzzle with practical boundaries

The file depends on the particular rules of ZIP, Multiboot, and BIOS disk startup. It doesn’t mean any ZIP archive can be made bootable by simply adding a signature: the file’s opening layout, metadata, executable instructions, and boot details all have to align. Compatibility also depends on using a suitable Multiboot loader or a compatible BIOS-based machine, and the floppy demonstration requires writing the image to disk.

For developers, ZIPHEAD.COM offers a concrete example of format polyglots: files whose bytes have valid meanings under more than one format or execution environment. Such constructions can expose assumptions in tools that identify a file by its extension or inspect only one layer of its structure. They also show why format-aware analysis matters: an archive can contain data that another system interprets as executable instructions.

Oberhollenzer describes the Multiboot portion as straightforward; the BIOS-compatible opening required the more intricate byte-level work. The central lesson is that file formats are specifications for interpreting data, and their rules can intersect in unexpected ways. This ZIP is both an archive people can unpack and a bootable image because its first entry was designed to make those interpretations coexist.

The technical write-up explains the construction in more detail. For anyone working with loaders, binary formats, or file inspection tools, the useful takeaway is how much behavior can hinge on a few bytes at the start of a file—and how carefully those bytes must be chosen when multiple systems read them differently.

===
Source: [email protected] (Bruno Ferreira) · www.tomshardware.com

Same vesselRelated cargo