libctru  v2.3.1
exheader.h
Go to the documentation of this file.
1 /**
2  * @file exheader.h
3  * @brief NCCH extended header definitions.
4  */
5 #pragma once
6 
7 #include <3ds/types.h>
8 
9 /// ARM9 descriptor flags
10 enum
11 {
12  ARM9DESC_MOUNT_NAND = BIT(0), ///< Mount "nand:/"
13  ARM9DESC_MOUNT_NANDRO_RW = BIT(1), ///< Mount nand:/ro/ as read-write
14  ARM9DESC_MOUNT_TWLN = BIT(2), ///< Mount "twln:/"
15  ARM9DESC_MOUNT_WNAND = BIT(3), ///< Mount "wnand:/"
16  ARM9DESC_MOUNT_CARDSPI = BIT(4), ///< Mount "cardspi:/"
17  ARM9DESC_USE_SDIF3 = BIT(5), ///< Use SDIF3
18  ARM9DESC_CREATE_SEED = BIT(6), ///< Create seed (movable.sed)
19  ARM9DESC_USE_CARD_SPI = BIT(7), ///< Use card SPI, required by multiple pxi:dev commands
20  ARM9DESC_SD_APPLICATION = BIT(8), ///< SD application (not checked)
21  ARM9DESC_MOUNT_SDMC_RW = BIT(9), ///< Mount "sdmc:/" as read-write
22 };
23 
24 /// Filesystem access flags
25 enum
26 {
27  FSACCESS_CATEGORY_SYSTEM_APPLICATION = BIT(0), ///< Category "system application"
28  FSACCESS_CATEGORY_HARDWARE_CHECK = BIT(1), ///< Category "hardware check"
29  FSACCESS_CATEGORY_FILESYSTEM_TOOL = BIT(2), ///< Category "filesystem tool"
30  FSACCESS_DEBUG = BIT(3), ///< Debug
31  FSACCESS_TWLCARD_BACKUP = BIT(4), ///< TWLCARD backup
32  FSACCESS_TWLNAND_DATA = BIT(5), ///< TWLNAND data
33  FSACCESS_BOSS = BIT(6), ///< BOSS (SpotPass)
34  FSACCESS_SDMC_RW = BIT(7), ///< SDMC (read-write)
35  FSACCESS_CORE = BIT(8), ///< Core
36  FSACCESS_NANDRO_RO = BIT(9), ///< nand:/ro/ (read-only)
37  FSACCESS_NANDRW = BIT(10), ///< nand:/rw/
38  FSACCESS_NANDRO_RW = BIT(11), ///< nand:/ro/ (read-write)
39  FSACCESS_CATEGORY_SYSTEM_SETTINGS = BIT(12), ///< Category "System Settings"
40  FSACCESS_CARDBOARD = BIT(13), ///< Cardboard (System Transfer)
41  FSACCESS_EXPORT_IMPORT_IVS = BIT(14), ///< Export/Import IVs (movable.sed)
42  FSACCESS_SDMC_WO = BIT(15), ///< SDMC (write-only)
43  FSACCESS_SWITCH_CLEANUP = BIT(16), ///< "Switch cleanup" (3.0+)
44  FSACCESS_SAVEDATA_MOVE = BIT(17), ///< Savedata move (5.0+)
45  FSACCESS_SHOP = BIT(18), ///< Shop (5.0+)
46  FSACCESS_SHELL = BIT(19), ///< Shop (5.0+)
47  FSACCESS_CATEGORY_HOME_MENU = BIT(20), ///< Category "Home Menu" (6.0+)
48  FSACCESS_SEEDDB = BIT(21), ///< Seed DB (9.6+)
49 };
50 
51 /// The resource limit category of a title
52 typedef enum
53 {
54  RESLIMIT_CATEGORY_APPLICATION = 0, ///< Regular application
55  RESLIMIT_CATEGORY_SYS_APPLET = 1, ///< System applet
56  RESLIMIT_CATEGORY_LIB_APPLET = 2, ///< Library applet
57  RESLIMIT_CATEGORY_OTHER = 3, ///< System modules running inside the BASE memregion
59 
60 /// The system mode a title should be launched under
61 typedef enum
62 {
63  SYSMODE_O3DS_PROD = 0, ///< 64MB of usable application memory
64  SYSMODE_N3DS_PROD = 1, ///< 124MB of usable application memory. Unusable on O3DS
65  SYSMODE_DEV1 = 2, ///< 97MB/178MB of usable application memory
66  SYSMODE_DEV2 = 3, ///< 80MB/124MB of usable application memory
67  SYSMODE_DEV3 = 4, ///< 72MB of usable application memory. Same as "Prod" on N3DS
68  SYSMODE_DEV4 = 5, ///< 32MB of usable application memory. Same as "Prod" on N3DS
69 } SystemMode;
70 
71 
72 /// The system info flags and remaster version of a title
73 typedef struct
74 {
75  u8 reserved[5]; ///< Reserved
76  bool compress_exefs_code : 1; ///< Whether the ExeFS's .code section is compressed
77  bool is_sd_application : 1; ///< Whether the title is meant to be used on an SD card
78  u16 remaster_version; ///< Remaster version
80 
81 /// Information about a title's section
82 typedef struct
83 {
84  u32 address; ///< The address of the section
85  u32 num_pages; ///< The number of pages the section occupies
86  u32 size; ///< The size of the section
88 
89 /// The name of a title and infomation about its section
90 typedef struct
91 {
92  char name[8]; ///< Title name
93  ExHeader_SystemInfoFlags flags; ///< System info flags, see @ref ExHeader_SystemInfoFlags
94  ExHeader_CodeSectionInfo text; ///< .text section info, see @ref ExHeader_CodeSectionInfo
95  u32 stack_size; ///< Stack size
96  ExHeader_CodeSectionInfo rodata; ///< .rodata section info, see @ref ExHeader_CodeSectionInfo
97  u32 reserved; ///< Reserved
98  ExHeader_CodeSectionInfo data; ///< .data section info, see @ref ExHeader_CodeSectionInfo
99  u32 bss_size; ///< .bss section size
101 
102 /// The savedata size and jump ID of a title
103 typedef struct
104 {
105  u64 savedata_size; ///< Savedata size
106  u64 jump_id; ///< Jump ID
107  u8 reserved[0x30]; ///< Reserved
109 
110 /// The code set info, dependencies and system info of a title (SCI)
111 typedef struct
112 {
113  ExHeader_CodeSetInfo codeset_info; ///< Code set info, see @ref ExHeader_CodeSetInfo
114  u64 dependencies[48]; ///< Title IDs of the titles that this program depends on
115  ExHeader_SystemInfo system_info; ///< System info, see @ref ExHeader_SystemInfo
117 
118 /// The ARM11 filesystem info of a title
119 typedef struct
120 {
121  u64 extdata_id; ///< Extdata ID
122  u32 system_savedata_ids[2]; ///< IDs of the system savedata accessible by the title
123  u64 accessible_savedata_ids; ///< IDs of the savedata accessible by the title, 20 bits each, followed by "Use other variation savedata"
124  u32 fs_access_info; ///< FS access flags
125  u32 reserved : 24; ///< Reserved
126  bool no_romfs : 1; ///< Don't use any RomFS
127  bool use_extended_savedata_access : 1; ///< Use the "extdata_id" field to store 3 additional accessible savedata IDs
129 
130 /// The CPU-related and memory-layout-related info of a title
131 typedef struct
132 {
133  u32 core_version; ///< The low title ID of the target firmware
134  bool use_cpu_clockrate_804MHz : 1; ///< Whether to start the title with the 804MHz clock rate
135  bool enable_l2c : 1; ///< Whether to start the title with the L2C-310 enabled enabled
136  u8 flag1_unused : 6; ///< Unused
137  SystemMode n3ds_system_mode : 4; ///< The system mode to use on N3DS
138  u8 flag2_unused : 4; ///< Unused
139  u8 ideal_processor : 2; ///< The ideal processor to start the title on
140  u8 affinity_mask : 2; ///< The affinity mask of the title
141  SystemMode o3ds_system_mode : 4; ///< The system mode to use on N3DS
142  u8 priority; ///< The priority of the title's main thread
144 
145 /// The ARM11 system-local capabilities of a title
146 typedef struct
147 {
148  u64 title_id; ///< Title ID
149  ExHeader_Arm11CoreInfo core_info; ///< Core info, see @ref ExHeader_Arm11CoreInfo
150  u16 reslimits[16]; ///< Resource limit descriptors, only "CpuTime" (first byte) sems to be used
151  ExHeader_Arm11StorageInfo storage_info; ///< Storage info, see @ref ExHeader_Arm11StorageInfo
152  char service_access[34][8]; ///< List of the services the title has access to. Limited to 32 prior to system version 9.3
153  u8 reserved[15]; ///< Reserved
154  ResourceLimitCategory reslimit_category; ///< Resource limit category, see @ref ExHeader_Arm11SystemLocalCapabilities
156 
157 /// The ARM11 kernel capabilities of a title
158 typedef struct
159 {
160  u32 descriptors[28]; ///< ARM11 kernel descriptors, see 3dbrew
161  u8 reserved[16]; ///< Reserved
163 
164 /// The ARM9 access control of a title
165 typedef struct
166 {
167  u8 descriptors[15]; ///< Process9 FS descriptors, see 3dbrew
168  u8 descriptor_version; ///< Descriptor version
170 
171 /// The access control information of a title
172 typedef struct
173 {
174  ExHeader_Arm11SystemLocalCapabilities local_caps; ///< ARM11 system-local capabilities, see @ref ExHeader_Arm11SystemLocalCapabilities
175  ExHeader_Arm11KernelCapabilities kernel_caps; ///< ARM11 kernel capabilities, see @ref ExHeader_Arm11SystemLocalCapabilities
176  ExHeader_Arm9AccessControl access_control; ///< ARM9 access control, see @ref ExHeader_Arm9AccessControl
178 
179 /// Main extended header data, as returned by PXIPM, Loader and FSREG service commands
180 typedef struct
181 {
182  ExHeader_SystemControlInfo sci; ///< System control info, see @ref ExHeader_SystemControlInfo
183  ExHeader_AccessControlInfo aci; ///< Access control info, see @ref ExHeader_AccessControlInfo
184 } ExHeader_Info;
185 
186 /// Extended header access descriptor
187 typedef struct
188 {
189  u8 signature[0x100]; ///< The signature of the access descriptor (RSA-2048-SHA256)
190  u8 ncchModulus[0x100]; ///< The modulus used for the above signature, with 65537 as public exponent
191  ExHeader_AccessControlInfo acli; ///< This is compared for equality with the first ACI by Process9, see @ref ExHeader_AccessControlInfo
193 
194 /// The NCCH Extended Header of a title
195 typedef struct
196 {
197  ExHeader_Info info; ///< Main extended header data, see @ref ExHeader_Info
198  ExHeader_AccessDescriptor access_descriptor; ///< Access descriptor, see @ref ExHeader_AccessDescriptor
199 } ExHeader;
ResourceLimitCategory
The resource limit category of a title.
Definition: exheader.h:53
@ RESLIMIT_CATEGORY_LIB_APPLET
Library applet.
Definition: exheader.h:56
@ RESLIMIT_CATEGORY_APPLICATION
Regular application.
Definition: exheader.h:54
@ RESLIMIT_CATEGORY_SYS_APPLET
System applet.
Definition: exheader.h:55
@ RESLIMIT_CATEGORY_OTHER
System modules running inside the BASE memregion.
Definition: exheader.h:57
SystemMode
The system mode a title should be launched under.
Definition: exheader.h:62
@ SYSMODE_DEV4
32MB of usable application memory. Same as "Prod" on N3DS
Definition: exheader.h:68
@ SYSMODE_O3DS_PROD
64MB of usable application memory
Definition: exheader.h:63
@ SYSMODE_N3DS_PROD
124MB of usable application memory. Unusable on O3DS
Definition: exheader.h:64
@ SYSMODE_DEV1
97MB/178MB of usable application memory
Definition: exheader.h:65
@ SYSMODE_DEV3
72MB of usable application memory. Same as "Prod" on N3DS
Definition: exheader.h:67
@ SYSMODE_DEV2
80MB/124MB of usable application memory
Definition: exheader.h:66
@ FSACCESS_NANDRO_RO
nand:/ro/ (read-only)
Definition: exheader.h:36
@ FSACCESS_TWLNAND_DATA
TWLNAND data.
Definition: exheader.h:32
@ FSACCESS_NANDRO_RW
nand:/ro/ (read-write)
Definition: exheader.h:38
@ FSACCESS_CATEGORY_SYSTEM_APPLICATION
Category "system application".
Definition: exheader.h:27
@ FSACCESS_CATEGORY_HOME_MENU
Category "Home Menu" (6.0+)
Definition: exheader.h:47
@ FSACCESS_SHELL
Shop (5.0+)
Definition: exheader.h:46
@ FSACCESS_CORE
Core.
Definition: exheader.h:35
@ FSACCESS_TWLCARD_BACKUP
TWLCARD backup.
Definition: exheader.h:31
@ FSACCESS_SAVEDATA_MOVE
Savedata move (5.0+)
Definition: exheader.h:44
@ FSACCESS_SDMC_WO
SDMC (write-only)
Definition: exheader.h:42
@ FSACCESS_NANDRW
nand:/rw/
Definition: exheader.h:37
@ FSACCESS_SDMC_RW
SDMC (read-write)
Definition: exheader.h:34
@ FSACCESS_CATEGORY_SYSTEM_SETTINGS
Category "System Settings".
Definition: exheader.h:39
@ FSACCESS_EXPORT_IMPORT_IVS
Export/Import IVs (movable.sed)
Definition: exheader.h:41
@ FSACCESS_SWITCH_CLEANUP
"Switch cleanup" (3.0+)
Definition: exheader.h:43
@ FSACCESS_CATEGORY_HARDWARE_CHECK
Category "hardware check".
Definition: exheader.h:28
@ FSACCESS_SHOP
Shop (5.0+)
Definition: exheader.h:45
@ FSACCESS_BOSS
BOSS (SpotPass)
Definition: exheader.h:33
@ FSACCESS_CARDBOARD
Cardboard (System Transfer)
Definition: exheader.h:40
@ FSACCESS_DEBUG
Debug.
Definition: exheader.h:30
@ FSACCESS_CATEGORY_FILESYSTEM_TOOL
Category "filesystem tool".
Definition: exheader.h:29
@ FSACCESS_SEEDDB
Seed DB (9.6+)
Definition: exheader.h:48
@ ARM9DESC_MOUNT_NANDRO_RW
Mount nand:/ro/ as read-write.
Definition: exheader.h:13
@ ARM9DESC_SD_APPLICATION
SD application (not checked)
Definition: exheader.h:20
@ ARM9DESC_MOUNT_NAND
Mount "nand:/".
Definition: exheader.h:12
@ ARM9DESC_MOUNT_SDMC_RW
Mount "sdmc:/" as read-write.
Definition: exheader.h:21
@ ARM9DESC_MOUNT_WNAND
Mount "wnand:/".
Definition: exheader.h:15
@ ARM9DESC_MOUNT_CARDSPI
Mount "cardspi:/".
Definition: exheader.h:16
@ ARM9DESC_USE_CARD_SPI
Use card SPI, required by multiple pxi:dev commands.
Definition: exheader.h:19
@ ARM9DESC_USE_SDIF3
Use SDIF3.
Definition: exheader.h:17
@ ARM9DESC_CREATE_SEED
Create seed (movable.sed)
Definition: exheader.h:18
@ ARM9DESC_MOUNT_TWLN
Mount "twln:/".
Definition: exheader.h:14
The access control information of a title.
Definition: exheader.h:173
ExHeader_Arm11SystemLocalCapabilities local_caps
ARM11 system-local capabilities, see ExHeader_Arm11SystemLocalCapabilities.
Definition: exheader.h:174
ExHeader_Arm9AccessControl access_control
ARM9 access control, see ExHeader_Arm9AccessControl.
Definition: exheader.h:176
ExHeader_Arm11KernelCapabilities kernel_caps
ARM11 kernel capabilities, see ExHeader_Arm11SystemLocalCapabilities.
Definition: exheader.h:175
Extended header access descriptor.
Definition: exheader.h:188
ExHeader_AccessControlInfo acli
This is compared for equality with the first ACI by Process9, see ExHeader_AccessControlInfo.
Definition: exheader.h:191
The CPU-related and memory-layout-related info of a title.
Definition: exheader.h:132
u8 flag1_unused
Unused.
Definition: exheader.h:136
u8 ideal_processor
The ideal processor to start the title on.
Definition: exheader.h:139
SystemMode n3ds_system_mode
The system mode to use on N3DS.
Definition: exheader.h:137
bool enable_l2c
Whether to start the title with the L2C-310 enabled enabled.
Definition: exheader.h:135
u8 flag2_unused
Unused.
Definition: exheader.h:138
u32 core_version
The low title ID of the target firmware.
Definition: exheader.h:133
u8 affinity_mask
The affinity mask of the title.
Definition: exheader.h:140
u8 priority
The priority of the title's main thread.
Definition: exheader.h:142
bool use_cpu_clockrate_804MHz
Whether to start the title with the 804MHz clock rate.
Definition: exheader.h:134
SystemMode o3ds_system_mode
The system mode to use on N3DS.
Definition: exheader.h:141
The ARM11 kernel capabilities of a title.
Definition: exheader.h:159
The ARM11 filesystem info of a title.
Definition: exheader.h:120
bool no_romfs
Don't use any RomFS.
Definition: exheader.h:126
u32 reserved
Reserved.
Definition: exheader.h:125
u64 accessible_savedata_ids
IDs of the savedata accessible by the title, 20 bits each, followed by "Use other variation savedata"...
Definition: exheader.h:123
u32 fs_access_info
FS access flags.
Definition: exheader.h:124
u64 extdata_id
Extdata ID.
Definition: exheader.h:121
bool use_extended_savedata_access
Use the "extdata_id" field to store 3 additional accessible savedata IDs.
Definition: exheader.h:127
The ARM11 system-local capabilities of a title.
Definition: exheader.h:147
ExHeader_Arm11StorageInfo storage_info
Storage info, see ExHeader_Arm11StorageInfo.
Definition: exheader.h:151
ExHeader_Arm11CoreInfo core_info
Core info, see ExHeader_Arm11CoreInfo.
Definition: exheader.h:149
u64 title_id
Title ID.
Definition: exheader.h:148
ResourceLimitCategory reslimit_category
Resource limit category, see ExHeader_Arm11SystemLocalCapabilities.
Definition: exheader.h:154
The ARM9 access control of a title.
Definition: exheader.h:166
u8 descriptor_version
Descriptor version.
Definition: exheader.h:168
Information about a title's section.
Definition: exheader.h:83
u32 size
The size of the section.
Definition: exheader.h:86
u32 num_pages
The number of pages the section occupies.
Definition: exheader.h:85
u32 address
The address of the section.
Definition: exheader.h:84
The name of a title and infomation about its section.
Definition: exheader.h:91
ExHeader_SystemInfoFlags flags
System info flags, see ExHeader_SystemInfoFlags.
Definition: exheader.h:93
u32 stack_size
Stack size.
Definition: exheader.h:95
u32 reserved
Reserved.
Definition: exheader.h:97
ExHeader_CodeSectionInfo text
.text section info, see ExHeader_CodeSectionInfo
Definition: exheader.h:94
u32 bss_size
.bss section size
Definition: exheader.h:99
ExHeader_CodeSectionInfo data
.data section info, see ExHeader_CodeSectionInfo
Definition: exheader.h:98
ExHeader_CodeSectionInfo rodata
.rodata section info, see ExHeader_CodeSectionInfo
Definition: exheader.h:96
Main extended header data, as returned by PXIPM, Loader and FSREG service commands.
Definition: exheader.h:181
ExHeader_SystemControlInfo sci
System control info, see ExHeader_SystemControlInfo.
Definition: exheader.h:182
ExHeader_AccessControlInfo aci
Access control info, see ExHeader_AccessControlInfo.
Definition: exheader.h:183
The code set info, dependencies and system info of a title (SCI)
Definition: exheader.h:112
ExHeader_CodeSetInfo codeset_info
Code set info, see ExHeader_CodeSetInfo.
Definition: exheader.h:113
ExHeader_SystemInfo system_info
System info, see ExHeader_SystemInfo.
Definition: exheader.h:115
The system info flags and remaster version of a title.
Definition: exheader.h:74
bool is_sd_application
Whether the title is meant to be used on an SD card.
Definition: exheader.h:77
bool compress_exefs_code
Whether the ExeFS's .code section is compressed.
Definition: exheader.h:76
u16 remaster_version
Remaster version.
Definition: exheader.h:78
The savedata size and jump ID of a title.
Definition: exheader.h:104
u64 savedata_size
Savedata size.
Definition: exheader.h:105
u64 jump_id
Jump ID.
Definition: exheader.h:106
The NCCH Extended Header of a title.
Definition: exheader.h:196
ExHeader_Info info
Main extended header data, see ExHeader_Info.
Definition: exheader.h:197
ExHeader_AccessDescriptor access_descriptor
Access descriptor, see ExHeader_AccessDescriptor.
Definition: exheader.h:198
Various system types.
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:47
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23