Difference between revisions of "WAD files"

From WiiBrew
Jump to: navigation, search
(updated.)
Line 26: Line 26:
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x007
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x007
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Header type (0x49730000 or 0x69620000)
+
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | WAD Type ('Is\0\0' or 'ib\0\0' or 'Bk\0\0')
 
|- style="background-color: #ddd;"
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x008
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x008
Line 51: Line 51:
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x01B
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x01B
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | APP size
+
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | data size
 
|- style="background-color: #ddd;"
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x01C
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x01C
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x01F
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x01F
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Trailer size
+
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Footer size
 
|}
 
|}
  
The files are stored in the WAD in the same order that in the header. After each block (header, files), the file is aligned to 0x40 bytes.
+
The contents are stored in the WAD in the same order as in the TMD. Each block (header, contents) is aligned to 0x40 bytes.
  
=== Chain of Certificates ===
+
The contents are encrypted using the title key (decrypt it from the [[Ticket|ticket]]) and the content index (in the TMD, the 2 first bytes of the IV are the index, the last 14 bytes are zeroes) as IV.  The SHA1 of the decrypted content must match that stored in the TMD.
  
'''<span style="color: red;">It's recommended to read the [[Certificate chain|certificate chain]] article and using the header information instead of that info and constant offsets.</span>'''
+
=== Footer ===
 
+
The "footer" is an optional, unencrypted timestamp / buildstamp.
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
 
|- 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: #ccd;" | '''End'''
 
| 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;" | 0x040
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x043
 
| 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 (0x00010001 RSA2048, 0x00010000 RSA4096)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x044
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x143+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 256 for RSA2048 (d=0x000), 512 for RSA4096 (d=0x100)
 
| 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;" | 0x144+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x17F+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 60
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | zero filled
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x180+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x1BF+d
 
| 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;" | 0x1C0+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x1C3+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ? subject type (0x00000000, 0x00000001)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x1C4+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x203+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 64
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | subject
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x204+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x307+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 260
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ? public key
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x308+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x30B+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 4
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ?? unknown (0x00010001)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x30C+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x33F+d
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 52
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | zero filled
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | ...
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | ...
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | ...
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | ...
 
|}
 
 
 
=== Key and IV ===
 
 
 
'''<span style="color: red;">It's recommended to read the [[Ticket|ticket]] article and using the header information instead of that info and constant offsets.</span>'''
 
 
 
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
 
|- 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: #ccd;" | '''End'''
 
| 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;" | 0x0bff
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x0c0e
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x0010
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Encrypted title key (decrypt using the master key)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x0c1c
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x0c23
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x0008
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | First 8 bytes of IV for title key decryption (last 8 bytes are zero)
 
|}
 
 
 
To obtain the title key, simply decrypt it using the master key and the given IV (last eight bytes zero, first eight bytes supplied).
 
 
 
Note: this is probably part of the TMD/ticket/whatever. I'm throwing the offsets here for now, since this is arguably the most important part for extraction purposes.
 
 
 
=== File Table ===
 
 
 
'''<span style="color: red;">It's recommended to read the [[Tmd file structure|TMD]] article and using the header information instead of that info and constant offsets.</span>'''
 
 
 
WAD files contain a number of "files" in them. The number of files can be obtained from the halfword (2 bytes) at 0xede. The table itself starts at 0xee4, and it is composed of a number of file entries:
 
 
 
{| style="border-collapse: collapse; padding: 0.2em 0.2em 0.2em 0.2em;"
 
|- 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: #ccd;" | '''End'''
 
| 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;" | 0x00
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x03
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x04
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | File number / ID
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x04
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x05
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x02
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | First 2 bytes of IV to decrypt contents (last 14 bytes are zero)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x06
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x07
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x02
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Flags ?
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x08
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x0B
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x04
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | Padding (zero)
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x0C
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x0F
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x04
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | File size
 
|- style="background-color: #ddd;"
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ded;" | 0x10
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #dde;" | 0x24
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #ddd;" | 0x14
 
| style="border: 1px solid #ccc; padding: 0.2em; background-color: #edd;" | SHA-1 sum of decrypted file
 
|}
 
 
 
The files are located after the file table, with their starts aligned to a 64 byte boundary. To read a file, skip bytes until the next 64 byte boundary (unless already at one), read the ''File size'' bytes rounded to the next 16 bytes (the AES block size), decrypt using AES (using the title key and the IV in the file table entry plus 14 zero bytes), and take filesize bytes from the result to create the output file. The SHA-1 sum of this should match the one in the file table.
 
 
 
=== APP ===
 
The "APP" block in the WAD is a block of encrypted data that contains the info that is actually used.
 
 
 
The contents in the APP are referenced by the TMD content table. The APP is aligned to 64 bytes after each file.
 
 
 
The files are encrypted using the title key (decrypt it from the [[Ticket|ticket]]) and the file index (in the TMD, the 2 first bytes of the IV are the index, the last 14 bytes are zeroes) as IV.
 
 
 
=== Trailer ===
 
The "trailer" is a copy of the first file in the APP section. It's unencrypted.
 
 
 
=== Modification tools ===
 
There are tools which allow wad manipulation, but they will not be provided here because of piracy concerns.
 

Revision as of 00:29, 20 June 2008

WAD Format

The data within a WAD file has the following format.

This page is horribly out of date. Expect an update when the dust of recent events settles.

NOTE: Recently updated, should the certificate/ticket/TMD data be deleted?.

Thanks to Segher for his source.

Header

Start End Length Description
0x000 0x003 4 Header size = 0x0020
0x004 0x007 4 WAD Type ('Is\0\0' or 'ib\0\0' or 'Bk\0\0')
0x008 0x00B 4 Certificate chain size.
0x00C 0x00F 4 Reserved = 0
0x010 0x013 4 Ticket size
0x014 0x017 4 TMD size
0x018 0x01B 4 data size
0x01C 0x01F 4 Footer size

The contents are stored in the WAD in the same order as in the TMD. Each block (header, contents) is aligned to 0x40 bytes.

The contents are encrypted using the title key (decrypt it from the ticket) and the content index (in the TMD, the 2 first bytes of the IV are the index, the last 14 bytes are zeroes) as IV. The SHA1 of the decrypted content must match that stored in the TMD.

Footer

The "footer" is an optional, unencrypted timestamp / buildstamp.