NCA: Difference between revisions
Myster-Tee (talk | contribs) No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
| 0x204 | | 0x204 | ||
| 0x1 | | 0x1 | ||
| DistributionType (0x00 = | | DistributionType (0x00 = Download, 0x01 = GameCard) | ||
|- | |- | ||
| 0x205 | | 0x205 | ||
Line 120: | Line 120: | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| | | 0x8 | ||
| Reserved | | Reserved | ||
|} | |} | ||
Line 141: | Line 137: | ||
| 0x2 | | 0x2 | ||
| 0x1 | | 0x1 | ||
| FsType (0 = | | FsType (0 = RomFS, 1 = PartitionFS) | ||
|- | |- | ||
| 0x3 | | 0x3 | ||
| 0x1 | | 0x1 | ||
| HashType (0 = Auto, 2 = | | HashType (0 = Auto, 1 = None, 2 = HierarchicalSha256Hash, 3 = HierarchicalIntegrityHash) | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
| 0x1 | | 0x1 | ||
| EncryptionType (0 = Auto, 1 = None, 2 = | | EncryptionType (0 = Auto, 1 = None, 2 = XTS, 3 = AesCtr, 4 = AesCtrEx) | ||
|- | |- | ||
| 0x5 | | 0x5 | ||
Line 157: | Line 153: | ||
| 0x8 | | 0x8 | ||
| 0xF8 | | 0xF8 | ||
| [[# | | [[#HashData|HashData]] | ||
|- | |- | ||
| 0x100 | | 0x100 | ||
Line 173: | Line 169: | ||
| 0x148 | | 0x148 | ||
| 0x30 | | 0x30 | ||
| SparseInfo (only used in sections with sparse storage) | | [[#SparseInfo|SparseInfo]] (only used in sections with sparse storage) | ||
|- | |- | ||
| 0x178 | | 0x178 | ||
| | | 0x20 | ||
| [[#CompressionInfo|CompressionInfo]] | |||
|- | |||
| 0x198 | |||
| 0x68 | |||
| Reserved | | Reserved | ||
|} | |} | ||
Line 182: | Line 182: | ||
The FsHeader for each section is at absoluteoffset+0x400+(sectionid*0x200), where sectionid corresponds to the index used with the entry/hash tables. | The FsHeader for each section is at absoluteoffset+0x400+(sectionid*0x200), where sectionid corresponds to the index used with the entry/hash tables. | ||
== | == HashData == | ||
This contains information specific to the hash type in use. | This contains information specific to the hash type in use. | ||
=== | === HierarchicalSha256Data === | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
Line 194: | Line 194: | ||
| 0x0 | | 0x0 | ||
| 0x20 | | 0x20 | ||
| SHA256 hash over the hash-table at section-start+0 with the below hash-table size | | MasterHash (SHA256 hash over the hash-table at section-start+0 with the below hash-table size) | ||
|- | |- | ||
| 0x20 | | 0x20 | ||
| 0x4 | | 0x4 | ||
| | | BlockSize | ||
|- | |- | ||
| 0x24 | | 0x24 | ||
| 0x4 | | 0x4 | ||
| | | LayerCount (always 2) | ||
|- | |- | ||
| 0x28 | | 0x28 | ||
| | | 0x50 | ||
| | | [[#Region|LayerRegions]] (one region for the hash-table and another for PFS0 filesystem) | ||
|- | |||
| 0x78 | |||
| 0x80 | |||
| Reserved | |||
|} | |||
==== Region ==== | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset | |||
! Size | |||
! Description | |||
|- | |- | ||
| | | 0x0 | ||
| 0x8 | | 0x8 | ||
| | | Offset | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| 0x8 | | 0x8 | ||
| | | Size | ||
|} | |} | ||
=== | === IntegrityMetaInfo === | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
Line 234: | Line 238: | ||
| 0x0 | | 0x0 | ||
| 0x4 | | 0x4 | ||
| | | Magic ("IVFC") | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
| 0x4 | | 0x4 | ||
| | | Version | ||
|- | |- | ||
| | | 0x8 | ||
| 0x4 | | 0x4 | ||
| | | MasterHashSize | ||
|- | |- | ||
| | | 0xC | ||
| | | 0xB4 | ||
| | | [[#InfoLevelHash|InfoLevelHash]] | ||
| | |||
|- | |- | ||
| 0xC0 | |||
| 0x20 | | 0x20 | ||
| | | MasterHash | ||
|- | |- | ||
| | | 0xE0 | ||
| | | 0x18 | ||
| Reserved | | Reserved | ||
|} | |||
==== InfoLevelHash ==== | |||
{| class="wikitable" border="1" | |||
|- | |- | ||
! Offset | |||
! Size | |||
! Description | |||
|- | |- | ||
| | | 0x0 | ||
| 0x4 | | 0x4 | ||
| | | MaxLayers | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
| | | 0x90 | ||
| [[#HierarchicalIntegrityVerificationLevelInformation|Levels]] | |||
|- | |- | ||
| | | 0x94 | ||
| | | 0x20 | ||
| | | SignatureSalt | ||
|} | |||
===== HierarchicalIntegrityVerificationLevelInformation ===== | |||
{| class="wikitable" border="1" | |||
|- | |- | ||
! Offset | |||
! Size | |||
! Description | |||
|- | |- | ||
| | | 0x0 | ||
| 0x8 | | 0x8 | ||
| | | LogicalOffset | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| 0x8 | | 0x8 | ||
| | | HashDataSize | ||
|- | |- | ||
| | | 0x10 | ||
| 0x4 | | 0x4 | ||
| | | BlockSize (in log2) | ||
|- | |- | ||
| | | 0x14 | ||
| 0x4 | | 0x4 | ||
| Reserved | | Reserved | ||
|} | |} | ||
Line 362: | Line 314: | ||
| 0x0 | | 0x0 | ||
| 0x8 | | 0x8 | ||
| | | IndirectOffset | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| 0x8 | | 0x8 | ||
| | | IndirectSize | ||
|- | |- | ||
| 0x10 | | 0x10 | ||
| | | 0x10 | ||
| | | [[#BucketTreeHeader|IndirectHeader]] | ||
|- | |- | ||
| | | 0x20 | ||
| | | 0x8 | ||
| | | AesCtrExOffset | ||
|- | |- | ||
| | | 0x28 | ||
| | | 0x8 | ||
| | | AesCtrExSize | ||
|- | |- | ||
| | | 0x30 | ||
| | | 0x10 | ||
| | | [[#BucketTreeHeader|AesCtrExHeader]] | ||
| | |||
|} | |} | ||
Line 541: | Line 489: | ||
Official code assumes the relocation entries are sorted, and performs a binary search when determining where to read from. Each subsection in the Patch RomFs has its CTR calculated separately from the others based on the value in its entry (the BKTR entries use normal crypto). Thus decrypting a Patch RomFS requires decrypting and parsing the BKTR entries before anything else. | Official code assumes the relocation entries are sorted, and performs a binary search when determining where to read from. Each subsection in the Patch RomFs has its CTR calculated separately from the others based on the value in its entry (the BKTR entries use normal crypto). Thus decrypting a Patch RomFS requires decrypting and parsing the BKTR entries before anything else. | ||
== SparseInfo == | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset | |||
! Size | |||
! Description | |||
|- | |||
| 0x0 | |||
| 0x8 | |||
| TableOffset | |||
|- | |||
| 0x8 | |||
| 0x8 | |||
| TableSize | |||
|- | |||
| 0x10 | |||
| 0x10 | |||
| [[#BucketTreeHeader|TableHeader]] | |||
|- | |||
| 0x20 | |||
| 0x8 | |||
| PhysicalOffset | |||
|- | |||
| 0x28 | |||
| 0x2 | |||
| Generation | |||
|- | |||
| 0x2A | |||
| 0x6 | |||
| Reserved | |||
|} | |||
== CompressionInfo == | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset | |||
! Size | |||
! Description | |||
|- | |||
| 0x0 | |||
| 0x8 | |||
| TableOffset | |||
|- | |||
| 0x8 | |||
| 0x8 | |||
| TableSize | |||
|- | |||
| 0x10 | |||
| 0x10 | |||
| [[#BucketTreeHeader|TableHeader]] | |||
|} | |||
== BucketTreeHeader == | |||
{| class="wikitable" border="1" | |||
|- | |||
! Offset | |||
! Size | |||
! Description | |||
|- | |||
| 0x0 | |||
| 0x4 | |||
| Magic ("BKTR") | |||
|- | |||
| 0x4 | |||
| 0x4 | |||
| Version | |||
|- | |||
| 0x8 | |||
| 0x4 | |||
| EntryCount | |||
|- | |||
| 0xC | |||
| 0x4 | |||
| Reserved | |||
|} | |||
= Logo Section = | = Logo Section = | ||
Line 591: | Line 615: | ||
| 0x0 | | 0x0 | ||
| 0x4 | | 0x4 | ||
| | | Magic ("PFS0") | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
| 0x4 | | 0x4 | ||
| | | EntryCount | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| 0x4 | | 0x4 | ||
| | | StringTableSize | ||
|- | |- | ||
| 0xC | | 0xC | ||
| 0x4 | | 0x4 | ||
| | | Reserved | ||
|- | |- | ||
| 0x10 | | 0x10 | ||
| X | | X | ||
| | | [[#PartitionEntry|PartitionEntryTable]] | ||
|- | |- | ||
| 0x10 + X | | 0x10 + X | ||
| Y | | Y | ||
| | | StringTable | ||
|- | |- | ||
| 0x10 + X + Y | | 0x10 + X + Y | ||
| Z | | Z | ||
| | | FileData | ||
|} | |} | ||
== PartitionEntry == | |||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
Line 627: | Line 651: | ||
| 0x0 | | 0x0 | ||
| 0x8 | | 0x8 | ||
| Offset | | Offset | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
| 0x8 | | 0x8 | ||
| Size | | Size | ||
|- | |- | ||
| 0x10 | | 0x10 | ||
| 0x4 | | 0x4 | ||
| | | StringOffset | ||
|- | |- | ||
| 0x14 | | 0x14 | ||
| 0x4 | | 0x4 | ||
| | | Reserved | ||
|} | |} |