Difference between revisions of "Title metadata"

From WiiBrew
Jump to: navigation, search
(C code application)
 
(19 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Software]]
+
'''Title metadata''' is a format used to store information about a title (a single standalone game, channel, etc.) and all its installed contents, including which contents they consist of and their SHA1 hashes.
 
 
== 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.)
 
 
   
 
   
 
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.
  
=== TMD file structure ===
+
== Structure ==
==== Header ====
+
=== Header ===
{| 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'''
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x000
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature type
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x004
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 256
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x104
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 60
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x140
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 64
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Issuer
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x180
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Version
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x181
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ca_crl_version
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x182
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | signer_crl_version
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x183
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 1
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x184
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | System Version
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x18C
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title ID
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x194
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title type
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x198
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Group ID
 
 
|- style="background-color: #ddd;"
 
|- style="background-color: #ddd;"
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x19A
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 62
+
! Length
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | reserved
+
! Description
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1D8
+
| 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;" | Access rights
+
| Signature type
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1DC
+
| 0x004
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 256
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Title version
+
| Signature
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1DE
+
| 0x104
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 60
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Number of contents (nbr_cont)
+
| Padding modulo 64
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E0
+
| 0x140
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 64
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | boot index
+
| Issuer
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E2
+
| 0x180
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding modulo 64
+
| Version
|- style="background-color: #ddd;"
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1E4
+
| 0x181
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 36*nbr_cont
+
| 1
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Contents
+
| ca_crl_version
 +
|-
 +
| 0x182
 +
| 1
 +
| signer_crl_version
 +
|-
 +
| 0x183
 +
| 1
 +
| Padding modulo 64
 +
|-
 +
| 0x184
 +
| 8
 +
| System Version (the ios that the title needs)
 +
|-
 +
| 0x18C
 +
| 8
 +
| Title ID
 +
|-
 +
| 0x194
 +
| 4
 +
| Title type
 +
|-
 +
| 0x198
 +
| 2
 +
| Group ID
 +
|-
 +
| 0x19A
 +
| 2
 +
| Zero
 +
|-
 +
| 0x19C
 +
| 2
 +
| Region
 +
|-
 +
| 0x19E
 +
| 16
 +
| Ratings
 +
|-
 +
| 0x1AE
 +
| 12
 +
| Reserved
 +
|-
 +
| 0x1BA
 +
| 12
 +
| IPC Mask
 +
|-
 +
| 0x1C6
 +
| 18
 +
| Reserved
 +
|-
 +
| 0x1D8
 +
| 4
 +
| Access rights (flags for [[DVDX|DVD-video access]] and [http://hackmii.com/2009/08/of-tmds-and-hardware/ full PPC hardware access])
 +
|-
 +
| 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 ====
+
 
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
+
=== Content ===
|- style="background-color: #ddd;"
+
{| class="wikitable"
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #cdc;" | '''Start'''
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
+
! Length
|- style="background-color: #ddd;"
+
! Description
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x00
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 0x00
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Content ID
+
| 4
|- style="background-color: #ddd;"
+
| Content ID
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x04
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 0x04
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Index
+
| 2
|- style="background-color: #ddd;"
+
| Index
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x06
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 2
+
| 0x06
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Type
+
| 2
|- style="background-color: #ddd;"
+
| Type
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x08
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 8
+
| 0x08
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Size
+
| 8
|- style="background-color: #ddd;"
+
| Size
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x10
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 20
+
| 0x10
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | SHA1 hash
+
| 20
 +
| SHA1 hash
 
|}
 
|}
==== Certificates ====
+
 
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
+
=== Certificates ===
|- style="background-color: #ddd;"
+
{| class="wikitable"
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #cdc;" | '''Start'''
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ccc;" | '''Length'''
+
! Start
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dcc;" | '''Description'''
+
! Length
|- style="background-color: #ddd;"
+
! Description
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x000
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 0x000
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Signature type
+
| 4
|- style="background-color: #ddd;"
+
| Signature type
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x004
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 256
+
| 0x004
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Siganture
+
| 256
|- style="background-color: #ddd;"
+
| Signature
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x104
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 32
+
| 0x104
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Issuer
+
| 64
|- style="background-color: #ddd;"
+
| Issuer
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x124
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
+
| 0x124
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Tag
+
| 4
|- style="background-color: #ddd;"
+
| Tag
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x128
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 64
+
| 0x128
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Name
+
| 64
|- style="background-color: #ddd;"
+
| Name
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x168
+
|-
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" |  
+
| 0x168
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Key
+
|  
 +
| Key
 
|}
 
|}
=== C code application ===
+
 
 +
== Example code application ==
 
<source lang="c">
 
<source lang="c">
 
  typedef unsigned char  u8;
 
  typedef unsigned char  u8;
Line 161: Line 180:
 
   u32 cid; // content id
 
   u32 cid; // content id
 
   u16 index; // # number of the file
 
   u16 index; // # number of the file
   u16  type;
+
   u16  type; // normal: 0x0001; shared: 0x8001
 
   u64 size;
 
   u64 size;
 
   u8  hash [20]; //  SHA1 hash content
 
   u8  hash [20]; //  SHA1 hash content
Line 167: Line 186:
 
</source>
 
</source>
 
<source lang="c">
 
<source lang="c">
enum sig_type {
+
enum sig_type {
      RSA_2048 = 0x00010001,
+
  RSA_2048 = 0x00010001,
      RSA_4096 = 0x00010000
+
  RSA_4096 = 0x00010000
};
+
};
 +
 
 +
// High 32 bits of the title ID
 +
enum title_type : u32 {
 +
  System = 0x00000001,
 +
  Game = 0x00010000,
 +
  Channel = 0x00010001,
 +
  SystemChannel = 0x00010002,
 +
  GameWithChannel = 0x00010004,
 +
  DLC = 0x00010005,
 +
  HiddenChannel = 0x00010008,
 +
};
 +
 
 +
// title_type (offset 0x194)
 +
enum title_flags {
 +
  // All official titles have this flag set.
 +
  Default = 0x1,
 +
  Unknown_0x4 = 0x4,
 +
  // Used for DLC titles.
 +
  Data = 0x8,
 +
  Unknown_0x10 = 0x10,
 +
  // Seems to be used for WFS titles.
 +
  Maybe_WFS = 0x20,
 +
  Unknown_CT = 0x40,
 +
};
 
</source>
 
</source>
 
<source lang="c">
 
<source lang="c">
Line 204: Line 247:
 
   u8 key[...];
 
   u8 key[...];
 
</source>
 
</source>
 +
 +
There is also a structure called a TmdView which is select sections of the Tmd. It has a length of 0x60+0x10*number_of_contents. The structure is somewhat like this [as returned by ES_GetTmdView] :
 +
<source lang="c">
 +
struct tmd_view_content_t
 +
{
 +
uint32_t id;
 +
uint16_t index;
 +
uint16_t type;
 +
uint64_t size;
 +
};
 +
 +
struct tmd_view_t
 +
{
 +
uint8_t version; // 0x0000;
 +
uint8_t filler[3];
 +
uint64_t ios_title_id; //0x0004
 +
uint64_t title_id; // 0x00c
 +
uint32_t title_type; //0x0014
 +
uint16_t group_id; //0x0018
 +
uint8_t reserved[0x3e]; //0x001a this is the same reserved 0x3e bytes from the tmd
 +
uint16_t title_version; //0x0058
 +
uint16_t number_contents; //0x005a
 +
tmd_view_content_t contents[]; //0x005c
 +
};
 +
</source>
 +
 +
[[Category:File formats]]

Latest revision as of 01:25, 6 November 2018

Title metadata is a format used to store information about a title (a single standalone game, channel, etc.) and all its installed contents, including which contents they consist of and their SHA1 hashes.

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.

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 (the ios that the title needs)
0x18C 8 Title ID
0x194 4 Title type
0x198 2 Group ID
0x19A 2 Zero
0x19C 2 Region
0x19E 16 Ratings
0x1AE 12 Reserved
0x1BA 12 IPC Mask
0x1C6 18 Reserved
0x1D8 4 Access rights (flags for DVD-video access and full PPC hardware access)
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 64 Issuer
0x124 4 Tag
0x128 64 Name
0x168 Key

Example 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;		// normal: 0x0001; shared: 0x8001
   u64 size;
   u8  hash [20]; 		//  SHA1 hash content
 } content_record; 			// size: 0x24 bytes
enum sig_type {
  RSA_2048 = 0x00010001,
  RSA_4096 = 0x00010000
};

// High 32 bits of the title ID
enum title_type : u32 {
  System = 0x00000001,
  Game = 0x00010000,
  Channel = 0x00010001,
  SystemChannel = 0x00010002,
  GameWithChannel = 0x00010004,
  DLC = 0x00010005,
  HiddenChannel = 0x00010008,
};

// title_type (offset 0x194)
enum title_flags {
  // All official titles have this flag set.
  Default = 0x1,
  Unknown_0x4 = 0x4,
  // Used for DLC titles.
  Data = 0x8,
  Unknown_0x10 = 0x10,
  // Seems to be used for WFS titles.
  Maybe_WFS = 0x20,
  Unknown_CT = 0x40,
};
 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[...];

There is also a structure called a TmdView which is select sections of the Tmd. It has a length of 0x60+0x10*number_of_contents. The structure is somewhat like this [as returned by ES_GetTmdView] :

struct tmd_view_content_t
{
	uint32_t id;
	uint16_t index;
	uint16_t type;
	uint64_t size;
};

struct tmd_view_t
{
	uint8_t version; // 0x0000;
	uint8_t filler[3];
	uint64_t ios_title_id; //0x0004
	uint64_t title_id; // 0x00c
	uint32_t title_type; //0x0014
	uint16_t group_id; //0x0018
	uint8_t reserved[0x3e]; //0x001a this is the same reserved 0x3e bytes from the tmd
	uint16_t title_version; //0x0058
	uint16_t number_contents; //0x005a
	tmd_view_content_t contents[]; //0x005c
};