Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Nintendo backward LZ (BLZ code compression)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

The LZ10-like compression that Nintendo DS builds apply to the ARM9/ARM7 main binaries and to overlays: the stream is read from the end of the file towards the start and an 8-byte trailer at the end of the file holds the sizes.

Layout

As implemented by ndspy codeCompression.py (RoadrunnerWMC/ndspy, GPL-3.0, commit 00165f177d03c6ca9e15e37decf54d9c6754bf54; decompressor lines 59-213, compressor 233-294). Little endian trailer.

  • The file ends with a trailer: u32 extraSize in the last 4 bytes and, in the 4 bytes before it, u32 whose top byte is the header length (at least 8) and whose low 24 bits are the compressed length. If the header length is more than 8, the bytes between the compressed data and the 8-byte core are 0xFF padding (Fact:Nintendo backward LZ (BLZ code compression)/struct/BLZ trailer).
  • The decompressed size is the file length plus extraSize. If the last 4 bytes are zero the file is not compressed at all (ndspy then returns it unchanged).
  • If the compressed length is smaller than the file, the first part of the file is stored uncompressed (passthrough); in the compressor an ARM9 main binary keeps its first 0x4000 bytes (the secure area) outside the compressed part, overlays do not (Fact:Nintendo backward LZ (BLZ code compression)/behavior/BLZ decoding).
  • The body is LZ10-style (flag byte, 8 items, most significant bit first, 1 = back reference) but read backwards from the end of the compressed region and written backwards from the end of the output. A reference is two bytes: length = (high nibble of the first byte) + 3, displacement = ((low nibble << 8) | second byte) + 3. ndspy's source comment says 2 is added to the displacement, its code adds 3.
  • ndspy detects a compressed file by scanning for the trailer at the very end or up to 0x1C bytes before the end (appended data of 0 to 28 bytes in steps of 4), so a file with extra bytes after the trailer is still recognized.

Where it is used

Unverified: that every commercial game uses exactly this variant, and the meaning of the 0xFF padding beyond the 8-byte trailer; to test, decompress the ARM9 of several games and check that the result length equals file length + extraSize.

Related

The plain forward variants are in Format:Nintendo LZ77 (LZ10 and LZ11); the BIOS Huffman and run-length codecs are in Format:Nintendo BIOS Huffman and run-length.

Code & repositories

  • https://github.com/RoadrunnerWMC/ndspy @ 00165f177d03c6ca9e15e37decf54d9c6754bf54 · license: GPL-3.0
    ndspy (GPL-3.0): codeCompression.py (BLZ decoder and encoder) and code.py (module params, overlay table entries).
    Tested on: source read, not run · checked 2026-10-19; last activity 2026-08-29