Difference between revisions of "Title metadata"

From WiiBrew
Jump to: navigation, search
m
Line 3: Line 3:
 
== Nintendo Wii Title-Metadata (tmd) file structure ==
 
== Nintendo Wii Title-Metadata (tmd) file structure ==
  
A "title" is a standalone entity -- a game, a channel, etc.  Titles can be made up of multiple "contents". (Don't ask me. I just work here.)
+
A "title" is a standalone entity -- a game, a channel, etc.  Titles can be made up of multiple "contents".
 
   
 
   
 
Many operations are done in terms of 64-byte blocks, which means you will often see padding out to the nearest 64-byte boundary at the end of a field.
 
Many operations are done in terms of 64-byte blocks, which means you will often see padding out to the nearest 64-byte boundary at the end of a field.
Line 9: Line 9:
 
=== TMD file structure ===
 
=== TMD file structure ===
 
==== Header ====
 
==== Header ====
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
+
{| class="wikitable"
 
|- style="background-color: #ddd;"
 
|- style="background-color: #ddd;"
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #cdc;" | '''Start'''
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
+
! Length
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
+
! Description
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x000
+
| 0x000
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature type
+
| Signature type
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x004
+
| 0x004
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 256
+
| 256
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature
+
| Signature
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x104
+
| 0x104
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 60
+
| 60
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
+
| Padding modulo 64
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x140
+
| 0x140
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 64
+
| 64
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Issuer
+
| Issuer
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x180
+
| 0x180
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Version
+
| Version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x181
+
| 0x181
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ca_crl_version
+
| ca_crl_version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x182
+
| 0x182
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | signer_crl_version
+
| signer_crl_version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x183
+
| 0x183
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
+
| Padding modulo 64
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x184
+
| 0x184
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
+
| 8
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | System Version
+
| System Version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x18C
+
| 0x18C
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
+
| 8
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title ID
+
| Title ID
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x194
+
| 0x194
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title type
+
| Title type
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x198
+
| 0x198
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Group ID
+
| Group ID
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x19A
+
| 0x19A
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 62
+
| 62
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | reserved
+
| reserved
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1D8
+
| 0x1D8
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Access rights
+
| Access rights
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1DC
+
| 0x1DC
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title version
+
| Title version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1DE
+
| 0x1DE
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Number of contents (nbr_cont)
+
| Number of contents (nbr_cont)
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E0
+
| 0x1E0
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | boot index
+
| boot index
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E2
+
| 0x1E2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
+
| Padding modulo 64
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E4
+
| 0x1E4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 36*nbr_cont
+
| 36*nbr_cont
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Contents
+
| Contents
 
|}
 
|}
 
==== Content ====
 
==== Content ====
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
+
{| class="wikitable"
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #cdc;" | '''Start'''
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
+
! Length
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
+
! Description
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x00
+
| 0x00
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Content ID
+
| Content ID
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x04
+
| 0x04
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Index
+
| Index
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x06
+
| 0x06
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 2
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Type
+
| Type
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x08
+
| 0x08
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
+
| 8
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Size
+
| Size
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x10
+
| 0x10
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 20
+
| 20
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | SHA1 hash
+
| SHA1 hash
 
|}
 
|}
 +
 
==== Certificates ====
 
==== Certificates ====
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
+
{| class="wikitable"
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #cdc;" | '''Start'''
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
+
! Length
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
+
! Description
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x000
+
| 0x000
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature type
+
| Signature type
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x004
+
| 0x004
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 256
+
| 256
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature
+
| Signature
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x104
+
| 0x104
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 32
+
| 32
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Issuer
+
| Issuer
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x124
+
| 0x124
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Tag
+
| Tag
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x128
+
| 0x128
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 64
+
| 64
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Name
+
| Name
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x168
+
| 0x168
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" |  
+
|  
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Key
+
| Key
 
|}
 
|}
  

Revision as of 22:33, 22 October 2008


Nintendo Wii Title-Metadata (tmd) file structure

A "title" is a standalone entity -- a game, a channel, etc. Titles can be made up of multiple "contents".

Many operations are done in terms of 64-byte blocks, which means you will often see padding out to the nearest 64-byte boundary at the end of a field.

TMD file structure

Header

Start Length Description
0x000 4 Signature type
0x004 256 Signature
0x104 60 Padding modulo 64
0x140 64 Issuer
0x180 1 Version
0x181 1 ca_crl_version
0x182 1 signer_crl_version
0x183 1 Padding modulo 64
0x184 8 System Version
0x18C 8 Title ID
0x194 4 Title type
0x198 2 Group ID
0x19A 62 reserved
0x1D8 4 Access rights
0x1DC 2 Title version
0x1DE 2 Number of contents (nbr_cont)
0x1E0 2 boot index
0x1E2 2 Padding modulo 64
0x1E4 36*nbr_cont Contents

Content

Start Length Description
0x00 4 Content ID
0x04 2 Index
0x06 2 Type
0x08 8 Size
0x10 20 SHA1 hash

Certificates

Start Length Description
0x000 4 Signature type
0x004 256 Signature
0x104 32 Issuer
0x124 4 Tag
0x128 64 Name
0x168 Key

C code application

 typedef unsigned char  u8;
 typedef unsigned short u16;
 typedef unsigned int   u32; 
/* On a 32bit system, long is only 4 bytes- use long long instead */
 typedef unsigned long u64;
 typedef struct {
   u32 cid;		// content id
   u16 index;		// # number of the file
   u16  type;
   u64 size;
   u8  hash [20]; 		//  SHA1 hash content
 } content_record; 			// size: 0x24 bytes
 enum sig_type {
      RSA_2048 = 0x00010001,
      RSA_4096 = 0x00010000
 };
 typedef struct {
        u32 sig_type; 
        u8 sig[256];
        u8 fill1[60];
        u8 issuer[64]; // Root-CA%08x-CP%08x
        u8 version;
        u8 ca_crl_version;
        u8 signer_crl_version;
        u8 fill2;
        u64 sys_version;
        u64 title_id;
        u32 title_type;
        u16 group_id; // publisher
        u8 reserved[62];
        u32 access_rights;
        u16 title_version;
        u16 num_contents;
        u16 boot_index;
        u16 fill3;
        content_record contents[num_contents];
 } tmd;

The tmd is then followed by a chain of certificates, where each certificate is of the general form

  u32 sig_type;  //
  u8 sig[256];   // 256 for RSA_2048, 512 for RSA_4096
  u8 issuer[32];
  u32 tag;  // identifies what is being signed
  u8 name[64]; // name of thing being signed
  u8 key[...];