Changes

Jump to navigation Jump to search
1,646 bytes added ,  03:15, 5 December 2019
Line 12: Line 12:  
| 0x0
 
| 0x0
 
| 0x100
 
| 0x100
| RSA-2048 signature (PKCS#1 v2.1 RSASSA-PSS-VERIFY with SHA256)
+
| [[#Public Keys|RSA-2048]] signature (PKCS#1 v2.1 RSASSA-PSS-VERIFY with SHA256)
 
|-
 
|-
 
| 0x100
 
| 0x100
Line 40: Line 40:  
| 0x0
 
| 0x0
 
| 0x10
 
| 0x10
| Decrypted header's CTR
+
| Header's CTR, official code copies the pre-decryption CTR over the decrypted result. Also used as metadata.
 
|-
 
|-
 
| 0x10
 
| 0x10
Line 64: Line 64:  
| 0x54
 
| 0x54
 
| 0x4
 
| 0x4
| Unknown
+
| Base offset
 
|-
 
|-
 
| 0x58
 
| 0x58
 
| 0x4
 
| 0x4
| Unknown
+
| Always 0
 
|-
 
|-
 
| 0x5C
 
| 0x5C
Line 76: Line 76:  
| 0x5E
 
| 0x5E
 
| 0x2
 
| 0x2
| ?
+
| Padding
 
|-
 
|-
 
| 0x60
 
| 0x60
Line 96: Line 96:  
| 0x70
 
| 0x70
 
| 0x4
 
| 0x4
| Unknown
+
| Section 0 offset
 
|-
 
|-
 
| 0x74
 
| 0x74
 
| 0x4
 
| 0x4
| Unknown
+
| Section 1 offset
 
|-
 
|-
 
| 0x78
 
| 0x78
 
| 0x4
 
| 0x4
| Unknown
+
| Section 2 offset
 
|-
 
|-
 
| 0x7C
 
| 0x7C
 
| 0x4
 
| 0x4
| Unknown
+
| Section 3 offset
 
|-
 
|-
 
| 0x80
 
| 0x80
Line 128: Line 128:     
Each section follows each other immediately and is encrypted with the same key used for encrypting the header.
 
Each section follows each other immediately and is encrypted with the same key used for encrypting the header.
 +
The section offsets are relative to a base, which is typically 0x80000000 pointing to the base of DRAM.
 +
 +
Before being decrypted, the encrypted header's CTR additionally encodes metadata used to validate package2's contents as follows:
 +
* Size of the entire package2 with the raw header = ctr_word2 ^ ctr_word3 ^ ctr_word0
 +
* Metadata version field = ((ctr_word1 ^ (ctr_word1 >> 16)) & 0xFF) ^ (ctr_word1 >> 24)
 +
 +
In [4.0.0], the metadata version field must be less or equal to 4.
    
== Section 0 ==
 
== Section 0 ==
Line 134: Line 141:  
== Section 1 ==
 
== Section 1 ==
 
When decrypted, this section contains the built-in system modules encapsulated in a custom format.
 
When decrypted, this section contains the built-in system modules encapsulated in a custom format.
 +
 +
Note: On firmware [[8.0.0]] INI1 is contained within the Kernel and section 1 is empty with NULL SHA256 to match.
    
=== INI1 ===
 
=== INI1 ===
Line 152: Line 161:  
| 0x8
 
| 0x8
 
| u32
 
| u32
| NumberProcesses
+
| NumberProcesses (Must be <0x51)
 
|-
 
|-
 
| 0xC
 
| 0xC
 
| u32
 
| u32
| Zero
+
| Padding (zero)
 
|}
 
|}
    
==== KIP1 ====
 
==== KIP1 ====
Kernel internal process?
+
Kernel Initial Process.
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 182: Line 191:  
| 0x18
 
| 0x18
 
| u32
 
| u32
|  
+
| Process category (0: regular title, 1: kernel built-in). Should be 1 here.
 
|-
 
|-
 
| 0x1C
 
| 0x1C
| u32
+
| u8
| Flags / etc. Byte3 bit0-2: compression-enable for each section, when set.
+
| Main thread priority
 +
|-
 +
| 0x1D
 +
| u8
 +
| Default CPU core
 +
|-
 +
| 0x1E
 +
| u8
 +
| Reserved (unused)
 +
|-
 +
| 0x1F
 +
| u8
 +
| Flags: bit0-2: compression-enable for each section, when set. Bit3: Is64Bit. Bit4: IsAddrSpace36Bit. Bit5: [2.0.0+] UseSystemPoolPartition (1: System, 0: Application). Bit6, Bit7: reserved (unused)
 
|-
 
|-
 
| 0x20
 
| 0x20
| [[#SectionHeader]][3]
+
| [[#SectionHeader]][6]
| Sections
+
| Sections: .text, .rodata, .data, .bss and two reserved (ignored) sections.
 
|-
 
|-
| 0x50
+
| 0x80
| char[0x20]
+
| u32[0x20]
| Padding
  −
|-
  −
| 0x70
  −
| u64[0x20]
   
| KernelCaps
 
| KernelCaps
 
|}
 
|}
Line 222: Line 239:  
| 0xC
 
| 0xC
 
| u32
 
| u32
|  
+
| Attribute: the size in pages of the main thread's stack for .rodata, reserved otherwise.
 
|}
 
|}
 +
 +
Compressed size can be 0 or lower than exepected, this is the case for BSS for example.
    
===== Compression =====
 
===== Compression =====
Line 241: Line 260:  
! Package1 minver constant
 
! Package1 minver constant
 
! Package2 version field
 
! Package2 version field
 +
|-
 +
| [[1.0.0]]
 +
| 0x2
 +
| 0x3
 +
| 0x0104
 
|-
 
|-
 
| [[2.0.0]]
 
| [[2.0.0]]
 
| 0x3
 
| 0x3
 
| 0x4
 
| 0x4
 +
| 0x0205
 +
|-
 +
| [[3.0.0]]
 +
| 0x4
 +
| 0x5
 +
| 0x0306
 
|-
 
|-
| [[4.1.0]]
+
| [[3.0.2]]
 +
| 0x5
 +
| 0x6
 +
| 0x0407
 +
|-
 +
| [[4.0.0]]
 
| 0x6
 
| 0x6
 
| 0x7
 
| 0x7
|  
+
| 0x0508
 +
|-
 +
| [[5.0.0]]
 +
| 0x7
 +
| 0x8
 +
| 0x0609
 +
|-
 +
| [[6.0.0]]
 +
| 0x8
 +
| 0x9
 +
| 0x070A
 +
|-
 +
| [[6.2.0]]
 +
| 0x9
 +
| 0xA
 +
| 0x080B
 +
|-
 +
| [[7.0.0]]
 +
| 0xA
 +
| 0xB
 +
| 0x090C
 +
|-
 +
| [[8.1.0]]
 +
| 0xB
 +
| 0xC
 +
| 0x0A0D
 +
|-
 +
| [[9.0.0]]
 +
| 0xC
 +
| 0xD
 +
| 0x0B0E
 +
|-
 +
| [[9.1.0]]
 +
| 0xD
 +
| 0xE
 +
| 0x0C0F
 
|}
 
|}
    
= Public Keys =
 
= Public Keys =
   −
== Exponent ==
+
=== Exponent ===
  10001
+
  0x10001
 
  −
== 4.1.0 ==
      
=== Retail Modulus ===
 
=== Retail Modulus ===

Navigation menu