Common nn::util: Difference between revisions

From EPD Wiki
Jump to navigation Jump to search
(Add common all common nn::util file format structures I know.)
 
(Add category.)
 
Line 285: Line 285:
|Empty String entry (0x0000, 0x00)
|Empty String entry (0x0000, 0x00)
|}
|}
[[Category:File formats]]

Latest revision as of 07:59, 9 May 2023

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.

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 Tables

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

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*))

Dictionaries

nn::util::ResDic::ResDicNode (unofficial name)

An array of nodes immediately following the ResDic. 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

nn::util::ResDic

Offset Size Type Description
0x0 0x4 u32 Magic ("_DIC" in big-endian or 0x0)
0x4 0x4 u32 ResDicNode count (does not count root node, which is part of the header)
0x8 0x nn::util::ResDic::ResDicNode Root node (null key)

StringPool

nn::util::StringPool

Header that precedes string arrays in nn::util based files. Strings pointed to in nn::util files actually start with a u16 of the string length, to access the string "string + sizeof(u16)" must be performed.

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)