The Nintendo Switch SDK provides basic binary file parsing functions under the nn::util namespace. This is used by various Switch libraries, such as the Bezel engine.

In general, the files have the following structure:

File Header

OffsetSizeDescription
0x08Magic number
0x81Micro version
0x91Minor version
0xA2Major version
0xC2Endianness (0xFEFF=Big, 0xFFFE=Little)
0xE1Alignment
0xF1Address size
0x104Filename offset
0x142Flags:
1 - Is relocated
0x162First block offset
0x184Relocation table offset
0x1C4Filesize
0x20Depends on file format

Block Header

The block size is usually the same as the offset to the next block, but in the last block the offset is set to 0.

Most blocks depend on the file format, but there is one block that is always present: the string pool. This block is stored behind the format-specific blocks.

OffsetSizeDescription
0x04Signature
0x44Offset to next block
0x84Block size, including header
0xC4Padding
0x10Block body

String Pool

OffsetSizeDescription
0x016Block header (_STR)
0x104String count
0x14Strings

String

Every string is null-terminated. If the string contains an odd number of bytes, an additional null byte is added such that the size field of the next string is aligned.

OffsetSizeDescription
0x02Size without null terminator
0x2Null-terminated string

Relocation Table

When the file is loaded into memory, it is relocated by converting offsets to memory addresses. Which offsets need to be converted is defined by the relocation table.

OffsetSizeDescription
0x04Signature (_RLT)
0x44Offset of relocation table (see file header)
0x84Number of sections
0xC4Padding
0x10Sections
Relocations

Relocation Section

OffsetSizeDescription
0x08Memory address
0x84File offset
0xC4File size
0x104Index of first relocation
0x144Number of relocations

Relocation Entry

OffsetSizeDescription
0x04File offset
0x42Number of chunks
0x61Relocated words per chunk
0x71Non-relocated words per chunk