David Oberhollenzer, the author of the squashfs-tools-ng toolkit, proposed the concept of self-booting ZIP archives. The project adapts the mechanism of self-extracting ZIP archives for using a ZIP file as a bootable image, requiring no separate extraction to boot the system contained within the image. The image remains a full ZIP archive that passes the 'unzip -t' check.
Unlike TAR or CPIO formats, the ZIP format starts with only a small header, while the directory of all files and their offsets is stored at the end of the file, allowing arbitrary data to be placed near the beginning of the archive. In this project, the ZIP archive header parameters are set up in such a way that they can be used as boot sectors for MBR.
The first bytes of the archive 'PK\03\04' are interpreted by the x86 processor as machine code corresponding to the 16-bit instructions of the i8086 processor 'push %ax; dec %bx; add (%si),%ax'. This is followed by a header with version, flags, compression method, and modification time, the data of which can be crafted so that when executed, the content corresponds to harmless instructions and the unconditional jump command jmp, transferring control to the main bootloader code.
The ZIP file also specifies the signature '1BADB002', which is identified by bootloaders supporting Multiboot as an indicator of a compatible boot image (kernel). Because of this, the ZIP image can be booted using GRUB or by specifying the '-kernel' option in QEMU. In this case, the bootloader extracts the uncompressed binary file, places it in memory according to the header, and hands over control in 32-bit protected mode. The ZIP image can also be written to the first sector of the hard disk, where the first 512 bytes are treated as a classic MBR.
Vse začetne zagonske kode, vključno z glavi ZIP in Multiboot, tabelo GDT, logiko nalaganja vsebine arhiva v pomnilnik in prehodom v zaščiten način, je bilo mogoče stisniti v 817 bajtov. Datoteke v ZIP-arhivu so nameščene brez stiskanja (na področju načina stiskanja je navedena vrednost 0), zato je po nalaganju ZIP-arhiva v pomnilnik mogoče neposredno dostopati do datotek, ki so vanj vključene, z uporabo indeksa, ki se nahaja na koncu ZIP-arhiva (Central Directory), da simuliramo najpreprostejši datotečni sistem.
Izvor: opennet.ru
