CTXT: Difference between revisions

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 .ctx files located at [[Title_Data_Structure|nand:/title/<titlepath>/00000000.ctx]].
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.


=Structure=
{| class="wikitable" border="1"
{| class="wikitable" border="1"
! Offset
! Offset !! Size !! Description
! Size
! Description
|-
|-
| 0x0
| 0x0
| 0x10
| 0x10
| AESMAC over SHA256 of bytes 0x10..0x30
| AES-CMAC over SHA256 of bytes 0x10..0x30, see below for keyslots used
|-
|-
| 0x10
| 0x10
Line 17: Line 18:
| 0x14
| 0x14
| 0x4
| 0x4
| Value 0 usually?
| CTXT version, must be 1
|-
|-
| 0x18
| 0x18
| 0x4
| 0x4
| Value 1 usually?
| Number of active content imports (X)
|-
|-
| 0x1C
| 0x1C
| 0x4
| 0x4
| Value 0 usually?
| padding
|-
|-
| 0x20
| 0x20
Line 33: Line 34:
| 0x28
| 0x28
| 0x4
| 0x4
| Unknown u32
| 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
|-
|-
| 0x200
| 0x0
| 0x10
| 0x10
| AES-MAC?
| AES-CMAC over the SHA256 of bytes 0x10 to the end, see below for keyslots used
|-
|-
| 0x210
| 0x10
| 0x8
| 0x8
| TitleID
| TitleID
|-
|-
| 0x218
| 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
| contentID for contentindex0
| 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
|-
|-
| 0x21C
| 0x1 || 0x3 || padding
| 0x4
|-
| Unknown u32 for contentindex0
| 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
|-
|-
| 0x220
| 0x0 || 0x200 || [[CTXT#Title_Import_Context|Title Import Context]] (contains X)
| 0x8
| content-size for contentindex0
|-
|-
| 0x228
| 0x200 || 0x400 * X || [[CTXT#Content_Import_Context|Content Import Contexts]]
| 0x8
|}
| Usually zero?
 
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"
|-
|-
| 0x230
! Media Type !! [[AES#Keyslots|Keyslot]] Used
| 0x3CC
|-
| Usually 0xFF?
| SD || 0x30
|-
|-
| 0x5FC
| NAND || 0xB
| 0x4
| This has the same value as the u32 at 0x28.
|}
|}