Common nn::util: Difference between revisions
Add common all common nn::util file format structures I know. |
Cleanup, add NWPtr<T> and NWString to use as helpers in the other NW file format pages. |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
These are file structures common to multiple NintendoWare file formats. Namely the nn::gfx file formats [[Bntx]] and [[Bnsh]], the nn::g3d file formats [[Bfres]], and [[Bfsha]], and the nn::bezel file formats [[Bea]], [[Bnbshpk]], and [[Nbmap]]. | These are file structures common to multiple NintendoWare file formats. Namely the nn::gfx file formats [[Bntx]] and [[Bnsh]], the nn::g3d file formats [[Bfres]], and [[Bfsha]], the nn::vg file format [[Bnvg]], and the nn::bezel file formats [[Bea]], [[Bnbshpk]], and [[Nbmap]]. | ||
== Headers == | |||
=== nn::util::BinaryFileHeader === | |||
The base struct of almost if not every file format using nn::util file structures. | The base struct of almost if not every file format using nn::util file structures. | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 72: | Line 72: | ||
|} | |} | ||
=== nn::util::BinaryBlockHeader === | |||
A common base struct of sub sections in nn::util based files. | A common base struct of sub sections in nn::util based files. | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 102: | Line 102: | ||
|} | |} | ||
== Relocation Table == | |||
Relocation tables are iterated to relocate pointers all throughout the BinaryFileHeader derived file. Converting the file into just a collection of structs in memory. | Relocation tables are iterated to relocate pointers all throughout the BinaryFileHeader derived file. Converting the file into just a collection of structs in memory. | ||
==== nn::util::RelocationTable | === NWPtr<T> === | ||
A template type to a pointer to type T that is relocatable by the relocation table. The size should match the address size in the file header, in Switch games this is almost always 64-bits. | |||
=== nn::util::RelocationTable === | |||
{| class="wikitable" | {| class="wikitable" | ||
!Offset | !Offset | ||
| Line 167: | Line 170: | ||
|} | |} | ||
==== nn::util::RelocationTable::Entry (unofficial name) ==== | ===== nn::util::RelocationTable::Entry (unofficial name) ===== | ||
Immediately following the Section array is an array of information about relocation entries. Each entry defines a set of continuous pointer arrays with a stride between each array. | Immediately following the Section array is an array of information about relocation entries. Each entry defines a set of continuous pointer arrays with a stride between each array. | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 196: | Line 199: | ||
|} | |} | ||
=== | == Dictionary == | ||
=== nn::util::ResDic === | |||
A dictionary, each element must have a unique string key. | |||
{| class="wikitable" | |||
!Offset | |||
!Size | |||
!Type | |||
!Description | |||
|- | |||
|0x0 | |||
|0x4 | |||
|u32 | |||
|Magic ("_DIC" in big-endian or 0x0) | |||
|- | |||
|0x4 | |||
|0x4 | |||
|u32 | |||
|Count (does not count root node, which is part of the header) | |||
|- | |||
|0x8 | |||
|0x10 | |||
|nn::util::ResDic::Node | |||
|Root node (null key) | |||
|- | |||
|0x18 | |||
|0x10 * Count | |||
|nn::util::ResDic::Node[Count] | |||
|Node array | |||
|} | |||
==== nn::util::ResDic:: | ==== nn::util::ResDic::Node (unofficial name) ==== | ||
The ref bit is used for a radix tree style lookup. | |||
{| class="wikitable" | {| class="wikitable" | ||
!Offset | !Offset | ||
| Line 227: | Line 259: | ||
|} | |} | ||
==== | == StringPool == | ||
=== NWString === | |||
NintendoWare file string pointers are preceded by a u16 string length. The strings are also aligned to 2 bytes. | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |||
!Offset | !Offset | ||
!Size | !Size | ||
| Line 235: | Line 271: | ||
|- | |- | ||
|0x0 | |0x0 | ||
| | |0x2 | ||
| | |u16 | ||
| | |String Length | ||
|- | |- | ||
| | |0x2 | ||
| | |0x1 * String Length | ||
| | |char[String Length] | ||
| | |String Data | ||
|} | |} | ||
=== nn::util::StringPool === | |||
Header that precedes the deduplicated string table. | |||
Header that precedes | |||
{| class="wikitable" | {| class="wikitable" | ||
!Offset | !Offset | ||
| Line 278: | Line 307: | ||
|0x4 | |0x4 | ||
|u32 | |u32 | ||
|String | |String Count | ||
|- | |- | ||
|0x10 | |0x10 | ||
| Line 284: | Line 313: | ||
|u32 | |u32 | ||
|Empty String entry (0x0000, 0x00) | |Empty String entry (0x0000, 0x00) | ||
|- | |||
|0x14 | |||
| | |||
|NWString[StringCount] | |||
|String region | |||
|} | |} | ||
[[Category:File formats]] | |||
Latest revision as of 06:57, 16 February 2026
These are file structures common to multiple NintendoWare file formats. Namely the nn::gfx file formats Bntx and Bnsh, the nn::g3d file formats Bfres, and Bfsha, the nn::vg file format Bnvg, and the nn::bezel file formats Bea, Bnbshpk, and Nbmap.
Headers
nn::util::BinaryFileHeader
The base struct of almost if not every file format using nn::util file structures.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x8 | u64 | Magic (dependent on file type) |
| 0x8 | 0x1 | u8 | Micro version (no code breaking changes) |
| 0x9 | 0x1 | u8 | Minor version |
| 0xa | 0x2 | u16 | Major version |
| 0xc | 0x2 | u16 | Endianess (0xfffe in big endian) |
| 0xe | 0x1 | u8 | Packed alignment (alignment = 1 << packed alignment) |
| 0xf | 0x1 | u8 | Always 64 (address size?) |
| 0x10 | 0x4 | u32 | File name offset |
| 0x14 | 0x2 | u16 | Is relocated (set on runtime by nn::util::RelocationTable::Relocate to prevent double relocation) |
| 0x16 | 0x2 | u16 | First BinaryBlockHeader offset relative to this header |
| 0x18 | 0x4 | u32 | RelocationTable offset relative to this header |
| 0x1c | 0x4 | u32 | File size |
nn::util::BinaryBlockHeader
A common base struct of sub sections in nn::util based files.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | Magic (dependent on file block type) |
| 0x4 | 0x4 | u32 | Next BinaryBlockHeader offset relative to this header |
| 0x8 | 0x4 | u32 | Size of sub section |
| 0xc | 0x4 | u32 | Reserved |
Relocation Table
Relocation tables are iterated to relocate pointers all throughout the BinaryFileHeader derived file. Converting the file into just a collection of structs in memory.
NWPtr<T>
A template type to a pointer to type T that is relocatable by the relocation table. The size should match the address size in the file header, in Switch games this is almost always 64-bits.
nn::util::RelocationTable
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | Magic ("_RLT" in big-endian) |
| 0x4 | 0x4 | u32 | Offset of this table relative to the binary file header |
| 0x8 | 0x4 | u32 | Section count |
| 0xc | 0x4 | u32 | Reserved |
nn::util::RelocationTable::Section
Immediately following the RelocationTable header is an array of section information. Which can divide up the file into distinct regions relative to a base offset.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x8 | void * | Base pointer for file region offsets, if null the file region is relative to the BinaryFileHeader) |
| 0x8 | 0x4 | u32 | File region offset (relative to BinaryFileHeader or Base pointer) |
| 0xc | 0x4 | u32 | File region size |
| 0x10 | 0x4 | u32 | Base entry index |
| 0x14 | 0x4 | u32 | Entry count |
nn::util::RelocationTable::Entry (unofficial name)
Immediately following the Section array is an array of information about relocation entries. Each entry defines a set of continuous pointer arrays with a stride between each array.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | File region offset (relative to section file region offset) |
| 0x4 | 0x2 | u16 | Array count |
| 0x6 | 0x1 | u8 | Per array pointer count |
| 0x7 | 0x1 | u8 | Array stride (in pointer count, so (stride * sizeof(void*)) |
Dictionary
nn::util::ResDic
A dictionary, each element must have a unique string key.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | Magic ("_DIC" in big-endian or 0x0) |
| 0x4 | 0x4 | u32 | Count (does not count root node, which is part of the header) |
| 0x8 | 0x10 | nn::util::ResDic::Node | Root node (null key) |
| 0x18 | 0x10 * Count | nn::util::ResDic::Node[Count] | Node array |
nn::util::ResDic::Node (unofficial name)
The ref bit is used for a radix tree style lookup.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | Ref bit (bit 0-2 = right shift, bit 2-31 = length) |
| 0x4 | 0x2 | u16 | Left node index |
| 0x6 | 0x2 | u16 | Right node index |
| 0x8 | 0x8 | const char * (NW) | String key |
StringPool
NWString
NintendoWare file string pointers are preceded by a u16 string length. The strings are also aligned to 2 bytes.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x2 | u16 | String Length |
| 0x2 | 0x1 * String Length | char[String Length] | String Data |
nn::util::StringPool
Header that precedes the deduplicated string table.
| Offset | Size | Type | Description |
|---|---|---|---|
| 0x0 | 0x4 | u32 | Magic ("_STR" in big-endian) |
| 0x4 | 0x4 | u32 | Next BinaryBlockHeader offset relative to this header |
| 0c8 | 0x8 | void* | Reserved |
| 0xc | 0x4 | u32 | String Count |
| 0x10 | 0x4 | u32 | Empty String entry (0x0000, 0x00) |
| 0x14 | NWString[StringCount] | String region |