Changes

1,823 bytes added ,  10:55, 6 April 2013
Structure may need re-formating
Line 52: Line 52:  
|}
 
|}
   −
== Embedded Database Format ==
+
The .db [[extdata|Extdata]] image embeds two almost identical copies(the latter is probably an older backup) of the title database. These database files consist of a pre-header with size of 0x80 identifying the Database Type, followed by a BDRI container. The offsets in the BDRI header are usually relative to the offset to the start of the BDRI header (0x80 in the file)
   −
=== Header ===
+
== Pre Header ==
    
{| class="wikitable"
 
{| class="wikitable"
Line 69: Line 69:  
| 0x78
 
| 0x78
 
| Reserved
 
| Reserved
 +
|}
 +
 +
=== Database Magic ===
 +
 +
{| class="wikitable"
 +
|-
 +
! Database Type
 +
! Magic
 +
|-
 +
| CTR-NAND import.db
 +
| NANDIDB
 +
|-
 +
| CTR-NAND title.db
 +
| NANDTDB
 +
|-
 +
| CTR-NAND tmp_i.db
 +
| TEMPIDB
 +
|-
 +
| CTR-NAND tmp_t.db
 +
| TEMPIDB
 +
|-
 +
| SD Card import.db
 +
| ?
 +
|-
 +
| SD Card title.db
 +
| TEMPTDB
 +
|}
 +
 +
== BDRI ==
 +
 +
Information stored about titles in these Title Database files are stored in two parts in a BDRI partition. Firstly in a Title Entry Table, and secondly in a Title Info Table. 
 +
 +
{| class="wikitable"
 +
|-
 +
! Start
 +
! Length
 +
! Description
 
|-
 
|-
| 0x80
+
| 0x0
 
| 4
 
| 4
 
| Database Magic ("BDRI")
 
| Database Magic ("BDRI")
 
|-
 
|-
| 0x84
+
| 0x4
 
| 4
 
| 4
 
| Magic Number (0x30000)
 
| Magic Number (0x30000)
 
|-
 
|-
| 0x88
+
| 0x8
 
| 8
 
| 8
 
| Unknown
 
| Unknown
 
|-
 
|-
| 0x90
+
| 0x10
 
| 8
 
| 8
| File Size, divided by the value at 0x98 (usually = 0x80)
+
| File Size(including pre header), divided by the value at relative offset 0x18 (usually = 0x80)
 
|-
 
|-
| 0x98
+
| 0x18
 
| 4
 
| 4
 
| Usually 0x80
 
| Usually 0x80
 
|-
 
|-
| 0x9C
+
| 0x1C
 
| 4
 
| 4
 
| Reserved
 
| Reserved
 
|-
 
|-
| 0xA0
+
| 0x20
 
| 0x20
 
| 0x20
 
| Unknown/Constant
 
| Unknown/Constant
 
|-
 
|-
| 0xC0
+
| 0x40
 
| 0x18
 
| 0x18
 
| Unknown
 
| Unknown
 
|-
 
|-
| 0xD8
+
| 0x58
 
| 8
 
| 8
| Title Entry Table Offset
+
| Relative Title Entry Table Offset
 
|-
 
|-
| 0xE0
+
| 0x60
 
| 0x20
 
| 0x20
 
| Unknown
 
| Unknown
 
|}
 
|}
   −
==== Database Magic ====
+
== Title Entry Table ==
 +
 
 +
This contains 'Entries' for all the titles stored in the database. However this contains minimal information about a title, but contains the offset (relative to the actual offset of the Title Entry Table) to the title's extended info in the Title Info Table.
 +
 
 +
=== Header ===
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0x0
 +
| 4
 +
| Unknown
 +
|-
 +
| 0x4
 +
| 4
 +
| Unknown
 +
|-
 +
| 0x8
 +
| 0x24
 +
| Reserved
 +
|-
 +
| 0x2C
 +
| 4
 +
| Unknown
 +
|-
 +
| 0x30
 +
| 0x50
 +
| Reserved
 +
|-
 +
| 0x80
 +
| 4
 +
| MAX Number of Title Entries
 +
|-
 +
| 0x84
 +
| 4
 +
| Unknown
 +
|-
 +
| 0x88
 +
| 0x20
 +
| Reserved
 +
|}
 +
 
 +
== Title Entry Format ==
 +
 
 +
The entries are 0x2C bytes long.
    
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! Database Type
+
! Start
! Magic
+
! Length
 +
! Description
 +
|-
 +
| 0x0
 +
| 4
 +
| Unknown
 +
|-
 +
| 0x4
 +
| 4
 +
| Entry Flag. If this isn't = 0x1, then this entry slot is unused
 +
|-
 +
| 0x8
 +
| 0x8
 +
| Title ID
 +
|-
 +
| 0x10
 +
| 4
 +
| Title Entry Index
 +
|-
 +
| 0x14
 +
| 4
 +
| Relative Title Info Offset, divided by the value at offset 0x18 in this Title Entry (usually 0x80)
 +
|-
 +
| 0x18
 +
| 0x4
 +
| Usually 0x80
 +
|-
 +
| 0x1c
 +
| 4
 +
| Reserved
 +
|-
 +
| 0x20
 +
| 4
 +
| When value at relative offset 0x24 = 0x1, then this value is the title's "Title ID lower"
 +
|-
 +
| 0x24
 +
| 0x4
 +
| Unknown
 +
|-
 +
| 0x28
 +
| 0x4
 +
| Unknown
 +
|}
 +
 
 +
* The actual Title Info offset is calculated by the following: Offset of BDRI Header + Relative Offset of Title Entry Table + Relative Title Info Offset
 +
 
 +
 
 +
== Title Info Format ==
 +
 
 +
These are 0x80 bytes long.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0x0
 +
| 8
 +
| Title Size
 +
|-
 +
| 0x8
 +
| 0x4
 +
| Title Type(usually 0x40)
 +
|-
 +
| 0xC
 +
| 0x4
 +
| Title Version
 +
|-
 +
| 0x10
 +
| 4
 +
| Flags_0
 +
|-
 +
| 0x14
 +
| 4
 +
| TMD Content ID
 +
|-
 +
| 0x18
 +
| 0x4
 +
| CMD Content ID
 +
|-
 +
| 0x1c
 +
| 4
 +
| Flags_1
 +
|-
 +
| 0x20
 +
| 4
 +
| ExtdataID low (zero if title doesn't use Extdata)
 +
|-
 +
| 0x24
 +
| 0x4
 +
| Reserved
 +
|-
 +
| 0x28
 +
| 0x8
 +
| Flags_2
 +
|-
 +
| 0x30
 +
| 0x10
 +
| Product Code
 +
|-
 +
| 0x40
 +
| 0x10
 +
| Reserved
 +
|-
 +
| 0x50
 +
| 0x4
 +
| Unknown
 +
|-
 +
| 0x54
 +
| 0x2c
 +
| Reserved
 +
|}
 +
 
 +
==== Flags_0 ====
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Index
 +
! Description
 +
|-
 +
| 0
 +
| Electronic Manual
 +
|-
 +
| 1
 +
| ?
 +
|-
 +
| 2
 +
| ?
 
|-
 
|-
| CTR-NAND import.db
+
| 3
| NANDIDB
+
| ?
 +
|}
 +
 
 +
==== Flags_1 ====
 +
 
 +
{| class="wikitable"
 
|-
 
|-
| CTR-NAND title.db
+
! Index
| NANDTDB
+
! Description
 
|-
 
|-
| CTR-NAND tmp_i.db
+
| 0
| TEMPIDB
+
| SD Save Data
 
|-
 
|-
| CTR-NAND tmp_t.db
+
| 1
| TEMPIDB
+
| ?
 
|-
 
|-
| SD Card import.db
+
| 2
 
| ?
 
| ?
 
|-
 
|-
| SD Card title.db
+
| 3
| TEMPTDB
+
| ?
 
|}
 
|}
   −
"'''title.db'''" - With a fixed size of 0x31E400 bytes, this [[Extdata]] image embeds two almost identical copies(the latter is probably an older backup) of the Title Database. For each installed title, the following information is known to be stored:
+
==== Flags_2 ====
   −
* Title ID - Taken from the main [[NCCH#CXI|CXI]]/[[TMD]]
+
{| class="wikitable"
* Product Code - Taken from the main [[NCCH#CXI|CXI]]
+
|-
* [[TMD|Title Size]] - This is generally larger than the total size of the Content.
+
! Index
* [[TMD|Title Type]]
+
! Description
* [[TMD|Title Version]]
+
|-
* [[Title Data Structure|.tmd]] Content ID
+
| 0
* [[Title Data Structure|.cmd]] Content ID
+
| DSiWare Related (Visibility on Home Menu/Export Flag?)
* [[Extdata#SD Extdata|ExtdataID low]] (if the title uses ExtData)
+
|-
* Whether or not a [[NCCH#CFA|Electronic Manual]] is used
+
| 1
* Whether or not [[Savegames|Savedata]] is used
+
| ?
 +
|-
 +
| 2
 +
| ?
 +
|-
 +
| 3
 +
| ?
 +
|-
 +
| 4
 +
| Related to Titles with an 'Application' Title ID
 +
|-
 +
| 5
 +
| DSiWare Related (Visibility on Home Menu/Export Flag?)
 +
|-
 +
| 6
 +
| ?
 +
|-
 +
| 7
 +
| ?
 +
|}
 +
 
 +
'''NOTES:'''
    
It is important to note the database doesn't contain a hash of the [[Title Data Structure|.cmd]]. So if a user has more than one valid set of [[Title Data Structure|application data]] for a given .cmd Content ID they can be manually interchanged without issue. Though renaming a .cmd file to match the Content ID which the title.db is expecting will result in an error, as the CTR for the per-console encryption layer changes depending on the file path, and the MAC of the .cmd is probably generated with the .cmd Content ID in mind.
 
It is important to note the database doesn't contain a hash of the [[Title Data Structure|.cmd]]. So if a user has more than one valid set of [[Title Data Structure|application data]] for a given .cmd Content ID they can be manually interchanged without issue. Though renaming a .cmd file to match the Content ID which the title.db is expecting will result in an error, as the CTR for the per-console encryption layer changes depending on the file path, and the MAC of the .cmd is probably generated with the .cmd Content ID in mind.
    +
These NAND/SD /dbs images seem to be loaded by the ARM9 while NATIVE_FIRM is booting.
   −
"'''import.db'''" - The function of the file is not well understood. It appears to be related to the download/install of titles, as in the progress of downloading titles this file will have changed but the title.db will not be modified until the title has been properly downloaded.
+
== Tools ==
*This file doesn't contain any title specific data which the [[Application Manager Services PXI|ARM9]] has been noted to use in relation to installed titles, even though this file is modified when titles are installed/deleted. In fact, no matter what titles you install, if you use an old copy of the "import.db" with a recent copy of the "title.db", this creates no noticeable issues.
     −
These NAND/SD /dbs images seem to be loaded by the ARM9 while NATIVE_FIRM is booting.
+
[https://github.com/ps3hen/ctr_toolchain/tree/master/extdata_tool extdata_tool] - parsing cleartext .db extdata images
839

edits