Hacking - DS Generation: Nitro File Format

The Nitro File Format is the basic file format of almost every data file found in a NDS file. A Nitro file contains a number of frames of data that are explained in detail in other files.

Every Nitro file begins with a specific NFF header. The format of the header (as a C-struct) is:

struct nff_header {
    char magic[4];    // Contains a string representing the file type
    short bom;        /*
                       * Like the byte-order marker of UTF-16, this short, which
                       * always contains 0xFFFE, represents the endianness of
                       * 'magic' (if it reads 0xFEFF, reverse the 4 bytes to get
                       * the correct left-to-right reading.)
                       */
    short unknown1;   // Appears to always contain 0x0100
    long file_size;   // Size of the Nitro file (in bytes)
    short unknown3;   // Possibly the size of this header (in bytes). Appears to
                      // always contain 0x0010
    short num_frames; // Contains the number of frames in this file
};

This header is followed by num_frames NFF frames which always begin with a specific frame header of this type:

struct nff_frame_header {
    char magic[4];    // Contains a string representing the frame type. Always
                      // must be reversed to read.
    long frame_size;  // Size of the frame including this header (in bytes)
};

Each frame header is then followed by (frame_size - 6) bytes that are the contents of the frame.