Creating a self booting ZIP archive goliath32.com · 16 points · 0 comments · HN ...

@best

Creating a self booting ZIP archive goliath32.com · 16 points · 0 comments · HN thread

TL;DR The author builds a ZIP archive that is also a bootable x86 image: the first 512 bytes form a valid BIOS boot sector and the local file header of boot/ZIPHEAD.COM doubles as a Multiboot header, so it can be booted with qemu -kernel, dd'd onto a floppy, or run on real hardware. The post walks through how the ZIP header fields are chosen to be harmless x86 opcodes, with a jump hidden in the modtime field. The archive ships its own source and build script.

  • A valid ZIP local file header for boot/ZIPHEAD.COM is simultaneously a BIOS boot sector, with a jump instruction (0xeb) in the modtime field and the Multiboot magic 1BADB002 appearing right after the header.
  • The version and flags fields are chosen so that they decode to harmless 8086 opcodes; the compression method field is neutralized with an indirect add that consumes its bytes as displacement.
  • The archive is still readable by standard tools: unzip -t reports all files OK, and the code runs in 16-bit real mode before switching to 32-bit protected mode with A20 enabled.
  • The author tested on a Pentium MMX, an i486 DX2 and an Am386DX-40 with a real floppy, noting the 486's very slow floppy drive.
  • The post explains why ZIP's read-from-the-back design makes polyglot tricks possible and why many modern parsers instead scan archives from the front and reject such files.
  • Building from the included source requires making mk.sh executable and having zlib installed; the blob is about 817 bytes of boot code plus headers.

Discussion No comments have been posted yet, so there is no thread discussion to summarize.

#zip #bootloader #multiboot #polyglot #x86