Changes

674 bytes added ,  23:23, 6 April 2024
m
Hiccup moved page Tad to SD title export
Line 1: Line 1: −
The System Settings application delivered with each DSi can be used to export applications from NAND to SD. The files created on SD are encrypted with AES CCM (CTR with CBC-MAC), using a combination of a shared key and a console specific key.
+
The System Settings application delivered with each DSi can be used to export applications from NAND to SD. The bin files created on SD are using the following file structure. They are encrypted with AES CCM (CTR with CBC-MAC), using a combination of a shared key and a console specific key.
    
The application itself (APP), and the title metadata (TMD) is encrypted with a console specific key. This means that Nintendo intended that these files can only be imported back into the same DSi.
 
The application itself (APP), and the title metadata (TMD) is encrypted with a console specific key. This means that Nintendo intended that these files can only be imported back into the same DSi.
Line 5: Line 5:  
While the banner, the public savegame, and several other metablocks are encrypted with a shared key, which means any DSi can inspect these parts of the file.
 
While the banner, the public savegame, and several other metablocks are encrypted with a shared key, which means any DSi can inspect these parts of the file.
   −
= ES blocks =
+
[[ES block encryption]] is used to encrypt the header block, footer block, and the 11 content parts. Each are their own seperate ES blocks.
An ES block, for lack of a better name, is a commonly used data encryption method on DSi by Nintendo.
     −
It uses AES CCM to encrypt a maximum of 0x20000 bytes of data per time, and extends it with a 32 byte encrypted trail block at the end.
+
= File structure overview =
   −
This trail block itself is encrypted with AES CTR, and contains the nonce for decryption and size of the ES block:
+
{| class="wikitable"
0000000: qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq
+
|-
0000010: xx nn nn nn nn nn nn nn nn nn nn nn nn yy yy yy
+
! Offset
 
+
! Size
The counter used for decrypting the trail block is the last 16 bytes of the trailblock, with the first, 12th, 13th and 14th byte set to 0:
+
! Description
00 nn nn nn nn nn nn nn nn nn nn nn nn 00 00 00
+
|-
 
+
| 0x0
After decrypting the trailblock, xx is always 0x3A, and yy is the size of the ES block (excluding the trail block). It is assumed that qq is a MAC (Message Authentication Code), used to verify the contents of the ES block after decryption, but this has not been verified yet.
+
| 0x4020
 +
| Banner/Icon
 +
|-
 +
| 0x4020
 +
| 0xD4
 +
| Header
 +
|-
 +
| 0x40F4
 +
| 0x460
 +
| Footer (certificates/hashes)
 +
|-
 +
| 0x4554
 +
| -
 +
| Content parts in sequence (TMD, SRL, savegame, custom banner).
 +
|}
    +
The banner, header, footer and savegame are encrypted with a shared key between each DSi. The other content parts are encrypted with a console specific key.
   −
= B4 block =  
+
= Header block @ 0x4020 (size 0xB4) =  
 
  0000000: 34 41 4e 54 31 30 00 01 74 e9 2c 1e 24 00 00 00  4ANT10..t.,.$...
 
  0000000: 34 41 4e 54 31 30 00 01 74 e9 2c 1e 24 00 00 00  4ANT10..t.,.$...
 
  0000010: d6 e0 39 c3 98 3f 06 b6 9a b2 9d 14 e7 06 e9 00  ..9..?..........
 
  0000010: d6 e0 39 c3 98 3f 06 b6 9a b2 9d 14 e7 06 e9 00  ..9..?..........
Line 44: Line 58:  
| 0x00
 
| 0x00
 
| 4
 
| 4
| Always 0x544E4134
+
| Always 0x544E4134 ('TNA4', endian-swapped)
 
|-
 
|-
 
| 0x04
 
| 0x04
 
| 2
 
| 2
| Unknown
+
| group_id/publisher code
 
|-
 
|-
 
| 0x06
 
| 0x06
 
| 2
 
| 2
| Unknown
+
| Title version
 
|-
 
|-
 
| 0x08
 
| 0x08
Line 64: Line 78:  
| 0x10
 
| 0x10
 
| 16
 
| 16
| Something
+
| Console ID from HWINFO_N.dat
 
|-
 
|-
 
| 0x20
 
| 0x20
 
| 4
 
| 4
| Gamecode of exported app
+
| Lower TitleID of exported app
 
|-
 
|-
 
| 0x24
 
| 0x24
 
| 4
 
| 4
| Unknown
+
| Upper TitleID of exported app
 
|-
 
|-
 
| 0x28
 
| 0x28
Line 79: Line 93:  
|-
 
|-
 
| 0x54
 
| 0x54
| ?
+
| 8 * 4
| ?
+
| List of content ids in same order as tmd
 +
|-
 +
| 0x74
 +
| 0x3e
 +
| reserved section per [http://www.wiibrew.org/wiki/TMD tmds]
 
|}
 
|}
   −
= 440 block =
+
= footer block @ 0x40F4 (size 0x460) =
    
  0000000: d6 f3 24 7c a1 0f 4a dc cd 07 34 d6 ce 62 32 93  ..$|..J...4..b2.
 
  0000000: d6 f3 24 7c a1 0f 4a dc cd 07 34 d6 ce 62 32 93  ..$|..J...4..b2.
Line 154: Line 172:  
  0000430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
 
  0000430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
   −
It is assumed that this block contains an ECC signature, aswell as the console id and serial of the DSi that exported the file.
+
 
 +
{| class="wikitable"
 +
|-
 +
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x00
 +
| 20
 +
| SHA1 of banner
 +
|-
 +
| 0x14
 +
| 20
 +
| SHA1 of tna4
 +
|-
 +
| 0x28
 +
| 20
 +
| SHA1 of tmd
 +
|-
 +
| 0x3c
 +
| 20*8
 +
| SHA1 of up to 8 contents [if unused, can be whatever happened to be in memory before]
 +
|-
 +
| 0xdc
 +
| 20
 +
| SHA1 of save data
 +
|-
 +
| 0xf0
 +
| 20
 +
| SHA1 of ?
 +
|-
 +
| 0x104
 +
| 0x3c
 +
| ECC signature of previous 0x104 bytes with AP cert
 +
|-
 +
| 0x140
 +
| 0x180
 +
| AP cert, signed by TW cert
 +
|-
 +
| 0x2c0
 +
| 0x180
 +
| TW cert, specific to a console (see dev.kp)
 +
|}
 +
 
 +
It is assumed that this block contains an ECC signature, aswell as the console id and serial of the DSi that exported the file, as part of a Nintendo cert.  Much like the Wii, the DSi carries with it a private ECC key that it can use to sign things, and a certificate signed by Nintendo that attests to the fact that the public ECC key belongs to a genuine DSi.
18

edits