Changes

2,062 bytes added ,  14:22, 28 July 2020
note discrepancy in endianness
[[Category:File formats]]'''Title metadata''' is a format used to store information about a title (a single standalone gameinstalled title, channelDLC, etc.) and all its installed contents, including which contents they consist of and their SHA1 SHA256 hashes.
[httphttps://gitbitbucket.daifukkat.suorg/trap15/?p=3dshax.git Code is available] by trap15 to parse the available information from the 3DS format of TMDs.
== Structure ==
 
All the data in the file represented in Big Endian, unless otherwise noted.
 
{| class="wikitable"
| align="center" style="background:#f0f0f0;"|'''Offset'''
| align="center" style="background:#f0f0f0;"|'''Size'''
| align="center" style="background:#f0f0f0;"|'''Description'''
|-
| 0x0||Y||Signature Data
|-
| Y ||0xC4||Header
|-
| 0xC4 + Y||0x24*64||Content Info Records.
|-
| 0x9C4 + Y||0x30*ContentCount||Content Chunk Records.
|}
 
Y denotes the total size of the "Signature Data" section and depends on the signature type.
 
=== Signature Data ===
The signature is of the header of the TMD.
{| class="wikitable"
| align="center" style="background:#f0f0f0;"|'''Offset'''
| align="center" style="background:#f0f0f0;"|'''Size'''
| align="center" style="background:#f0f0f0;"|'''Description'''
|-
| 0x0||0x4||Signature Type
|-
| 0x4 ||X||Signature
|-
| 0x4 + X|| ||Padding Aligning the signature data to 0x40 bytes
|}
 
==== Signature Type ====
{{Signature Types}}
The hash for the signature, is calculated over the header of the TMD
 
=== Header ===
 
{| class="wikitable"
| align="center" style="background:#f0f0f0;"|'''StartOffset'''| align="center" style="background:#f0f0f0;"|''' '''| align="center" style="background:#f0f0f0;"|'''LengthSize'''
| align="center" style="background:#f0f0f0;"|'''Description'''
|-
| ''RSA 2048''||''RSA 4096''0x0||0x40||Signature Issuer
|-
| 0x0000x40||0x0000x1||4||Signature typeVersion
|-
| 0x0040x41||0x0040x1||256 / 512||Signatureca_crl_version
|-
| 0x1040x42||0x2040x1||60||Padding modulo 64signer_crl_version
|-
| 0x1400x43||0x2400x1||64||IssuerReserved
|-
| 0x1800x44||0x280||10x8||System Version
|-
| 0x1810x4C||0x2810x8||1||ca_crl_versionTitle ID
|-
| 0x1820x54||0x2820x4||1||signer_crl_versionTitle Type
|-
| 0x1830x58||0x2830x2||1||Padding modulo 64Group ID
|-
| 0x1840x5A||0x2840x4||8||System VersionSave Data Size in Little Endian (Bytes) (Also SRL Public Save Data Size)
|-
| 0x18C0x5E||0x28C0x4||8||Title IDSRL Private Save Data Size in Little Endian (Bytes)
|-
| 0x1940x62||0x2940x4||4||Title typeReserved
|-
| 0x1980x66||0x2980x1||2||Group IDSRL Flag
|-
| 0x19A0x67||0x29A0x31||62||reservedReserved
|-
| 0x1D80x98||0x2D8||40x4||Access rightsRights
|-
| 0x1DC0x9C||0x2DC||20x2||Title versionVersion
|-
| 0x1DE0x9E||0x2DE0x02||2||Number of contents (contcount)Content Count
|-
| 0x1E00xA0||0x2E0||20x2||Boot contentContent
|-
| 0x2040xA2||0x3040x2||36*64||Content info recordsPadding
|-
| 0xB040xA4||0xC04||48*contcount0x20|| SHA-256 Hash of the Content chunk recordsInfo Records
|}
=== Content info records Info Records === There are 64 of these records, usually only the first is used. 
{| class="wikitable"
|-
! StartOffset! LengthSize
! Description
|-
| 0x02
| 2
| Content command count[k]
|-
| 0x04
| 320x20| SHA-256 hash? Commands?of the next k content records that have not been hashed yet
|}
=== Content chunk records ===
There is one of these for each content contained in this title. (Determined by "Content Count" in the TMD Header).
 
{| class="wikitable"
|-
! StartOffset! LengthSize
! Description
|-
|-
| 0x10
| 320x20
| SHA-256 hash
|}
==== Content Index ====
 
This indicates the content type:
 
{| class="wikitable" border="1"
|-
! Index
! Content Type
|-
| 0000
| Main Content (.[[NCCH#CXI|CXI]] for 3DS executable content/.[[NCCH#CFA|CFA]] for 3DS Data Archives/.SRL for TWL content)
|-
| 0001
| Home Menu Manual (.[[NCCH#CFA|CFA]])
|-
| 0002
| DLP Child Container (.[[NCCH#CFA|CFA]])
|}
This does not apply to DLC. === Certificates = Content Type flags ====
{| class="wikitable"
|-
! Start! LengthFlags
! Description
|-
| 0x0001| Encrypted|-| 2| Disc|-
| 4
| Signature typeCFM (abbreviation for?)
|-
| 0x0040x4000| *| SignatureOptional
|-
| 0x1040x8000| 64Shared| Issuer} == Certificate Chain ==If the TMD file is obtained from Nintendo's CDN, then it will have two [[Certificates|certificates]] appended at the end of the file: {| class="wikitable" border="1"
|-
| 0x124! CERTIFICATE| 4! SIGNATURE TYPE| Tag! RETAIL CERT NAME! DEBUG CERT NAME! DESCRIPTION
|-
| 0x128 TMD| 64 RSA-2048| Name CP0000000b| CP0000000a| Used to verify the TMD signature
|-
| 0x168 CA| RSA-4096| Key CA00000003| CA00000004| Used to verify the TMD Certificate
|}
 
The CA certificate is issued by 'Root', the public key for which is stored in NATIVE_FIRM.
== Example code application ==
44

edits