CTXT: Difference between revisions
WulfyStylez (talk | contribs) No edit summary |
TimmSkiller (talk | contribs) Correct information about location of CTX files |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
This page describes the structure of the | This page describes the structure of the [[Titles#Data_Structure|.ctx files]] created during title installations on the SD card or NAND. | ||
== Title Import Context == | |||
This represents an active/pending title installation. | |||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
! | ! Offset !! Size !! Description | ||
! | |||
! | |||
|- | |- | ||
| 0x0 | | 0x0 | ||
| 0x10 | | 0x10 | ||
| | | AES-CMAC over SHA256 of bytes 0x10..0x30, see below for keyslots used | ||
|- | |- | ||
| 0x10 | | 0x10 | ||
| Line 17: | Line 18: | ||
| 0x14 | | 0x14 | ||
| 0x4 | | 0x4 | ||
| | | CTXT version, must be 1 | ||
|- | |- | ||
| 0x18 | | 0x18 | ||
| 0x4 | | 0x4 | ||
| | | Number of active content imports (X) | ||
|- | |- | ||
| 0x1C | | 0x1C | ||
| 0x4 | | 0x4 | ||
| | | padding | ||
|- | |- | ||
| 0x20 | | 0x20 | ||
| Line 33: | Line 34: | ||
| 0x28 | | 0x28 | ||
| 0x4 | | 0x4 | ||
| | | Random u32 value generated during creation | ||
|- | |- | ||
| 0x2C | | 0x2C | ||
| 0x1D4 | | 0x1D4 | ||
| All-zero | | All-zero | ||
|} | |||
== Content Import Context == | |||
This represents an active content installation. | |||
{| class="wikitable" border="1" | |||
! Offset !! Size !! Description | |||
|- | |- | ||
| | | 0x0 | ||
| 0x10 | | 0x10 | ||
| AES- | | AES-CMAC over the SHA256 of bytes 0x10 to the end, see below for keyslots used | ||
|- | |- | ||
| | | 0x10 | ||
| 0x8 | | 0x8 | ||
| TitleID | | TitleID | ||
|- | |- | ||
| | | 0x18 | ||
| 0x18 | |||
| [[Application_Manager_Services#ImportContentContext|ImportContentContext]] for this content | |||
|- | |||
| 0x30 | |||
| 0x3CC | |||
| [[CTXT#Content_Import_Context_State|Content Import Context State]] (initially filled with FFs) | |||
|- | |||
| 0x3FC | |||
| 0x4 | | 0x4 | ||
| | | Same random number as in [[CTXT#Title_Import_Context|Title Import Context]] | ||
|} | |||
=== Paused Content Import State === | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset !! Size !! Description | |||
|- | |||
| 0x0 || 0x1 || bool, is paused | |||
|- | |- | ||
| | | 0x1 || 0x3 || padding | ||
| 0x4 | |- | ||
| | | 0x4 || 0x4 || u32, always 1 (checked to be 1, too) | ||
|- | |||
| 0x8 || 0x8 || u64, title ID | |||
|- | |||
| 0x10 || 0x4 || u32, content ID from [[Title_metadata|TMD]] | |||
|- | |||
| 0x14 || 0xA0 || SHA-256 state for this content (to continue where hashing left off) | |||
|- | |||
| 0xB4 || 0x10 || AES-CBC IV for CDN-level decryption (if enabled in the corresponding [[Title_metadata|TMD]] content chunk record) | |||
|- | |||
| 0xC4 || 0x8 || u64, current installation offset | |||
|} | |||
=== Content Import Context State === | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset !! Size !! Description | |||
|- | |||
| 0x0 || 0xCC || [[CTXT#Paused_Content_Import_State|Paused Content Import State]] | |||
|- | |||
| 0xCC || 0x180 || APCert | |||
|- | |||
| 0x24C || 0x3C || ECDSA signature using SHA-256 over the [[CTXT#Paused_Content_Import_State|Paused Content Import State]], signed by the APCert | |||
|- | |||
| 0x288 || 0x144 || Reserved | |||
|} | |||
== CTX Files == | |||
CTX files, usually found in the root of the title folder of the corresponding title (see [[Titles#Data_Structure|Title Data Structure]]) contain information about an active title installation, as well as data to resume the installation if it is paused. This is usually one file, called <code>00000000.ctx</code> which consists of one [[CTXT#Title_Import_Context|Title Import Context]] and one or more [[CTXT#Content_Import_Context|Content Import Contexts]]: | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset !! Size !! Description | |||
|- | |- | ||
| | | 0x0 || 0x200 || [[CTXT#Title_Import_Context|Title Import Context]] (contains X) | ||
| | |||
| | |||
|- | |- | ||
| | | 0x200 || 0x400 * X || [[CTXT#Content_Import_Context|Content Import Contexts]] | ||
| | |} | ||
| | |||
CTX files are created during any form of content installation after the TMD has been fully installled and persist for as long as title installation does (this includes pausing installations). When the CTX file is created, a random number is generated and stored in both the title/content import contexts in the CTX file and in the corresponding [[Title_Database#Title_Info_Entry|Title Info Entry]] in the title database. | |||
When title installation is finalized, this value is compared against the existing value in the title database. If it does not match, error 0xD8A08042 is returned. | |||
After content installation and successful install finalization, the .ctx file is removed from the title directory. | |||
Both title and content import contexts use CMACs over SHA256 hashes for verification: | |||
{| class="wikitable" border="1" | |||
|- | |- | ||
| | ! Media Type !! [[AES#Keyslots|Keyslot]] Used | ||
| | |- | ||
| | | SD || 0x30 | ||
|- | |- | ||
| | | NAND || 0xB | ||
| | |||
| | |||
|} | |} | ||
Latest revision as of 18:12, 27 May 2026
This page describes the structure of the .ctx files created during title installations on the SD card or NAND.
Title Import Context
This represents an active/pending title installation.
| Offset | Size | Description |
|---|---|---|
| 0x0 | 0x10 | AES-CMAC over SHA256 of bytes 0x10..0x30, see below for keyslots used |
| 0x10 | 0x4 | Magic "CTXT" |
| 0x14 | 0x4 | CTXT version, must be 1 |
| 0x18 | 0x4 | Number of active content imports (X) |
| 0x1C | 0x4 | padding |
| 0x20 | 0x8 | TitleID |
| 0x28 | 0x4 | Random u32 value generated during creation |
| 0x2C | 0x1D4 | All-zero |
Content Import Context
This represents an active content installation.
| Offset | Size | Description |
|---|---|---|
| 0x0 | 0x10 | AES-CMAC over the SHA256 of bytes 0x10 to the end, see below for keyslots used |
| 0x10 | 0x8 | TitleID |
| 0x18 | 0x18 | ImportContentContext for this content |
| 0x30 | 0x3CC | Content Import Context State (initially filled with FFs) |
| 0x3FC | 0x4 | Same random number as in Title Import Context |
Paused Content Import State
| Offset | Size | Description |
|---|---|---|
| 0x0 | 0x1 | bool, is paused |
| 0x1 | 0x3 | padding |
| 0x4 | 0x4 | u32, always 1 (checked to be 1, too) |
| 0x8 | 0x8 | u64, title ID |
| 0x10 | 0x4 | u32, content ID from TMD |
| 0x14 | 0xA0 | SHA-256 state for this content (to continue where hashing left off) |
| 0xB4 | 0x10 | AES-CBC IV for CDN-level decryption (if enabled in the corresponding TMD content chunk record) |
| 0xC4 | 0x8 | u64, current installation offset |
Content Import Context State
| Offset | Size | Description |
|---|---|---|
| 0x0 | 0xCC | Paused Content Import State |
| 0xCC | 0x180 | APCert |
| 0x24C | 0x3C | ECDSA signature using SHA-256 over the Paused Content Import State, signed by the APCert |
| 0x288 | 0x144 | Reserved |
CTX Files
CTX files, usually found in the root of the title folder of the corresponding title (see Title Data Structure) contain information about an active title installation, as well as data to resume the installation if it is paused. This is usually one file, called 00000000.ctx which consists of one Title Import Context and one or more Content Import Contexts:
| Offset | Size | Description |
|---|---|---|
| 0x0 | 0x200 | Title Import Context (contains X) |
| 0x200 | 0x400 * X | Content Import Contexts |
CTX files are created during any form of content installation after the TMD has been fully installled and persist for as long as title installation does (this includes pausing installations). When the CTX file is created, a random number is generated and stored in both the title/content import contexts in the CTX file and in the corresponding Title Info Entry in the title database.
When title installation is finalized, this value is compared against the existing value in the title database. If it does not match, error 0xD8A08042 is returned.
After content installation and successful install finalization, the .ctx file is removed from the title directory.
Both title and content import contexts use CMACs over SHA256 hashes for verification:
| Media Type | Keyslot Used |
|---|---|
| SD | 0x30 |
| NAND | 0xB |