libctr9
Nintendo 3DS ARM9 library
ctr_headers.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2016 Gabriel Marcano
3  *
4  * Refer to the COPYING.txt file at the top of the project directory. If that is
5  * missing, this file is licensed under the GPL version 2.0 or later.
6  *
7  ******************************************************************************/
8 
11 #ifndef CTR_HEADERS_H_
12 #define CTR_HEADERS_H_
13 
14 #include <stdint.h>
15 #include <stddef.h>
16 
19 typedef struct
20 {
21  uint8_t signature[0x100]; //rsa 2048 signature of a sha256 of the header
22  uint8_t magic[4]; //Should be the string NCSD
23  uint32_t media_size; //Size of NCSD image, in media units
24  uint8_t media_id[8]; //or title id (CTR-[etc])
25  uint8_t partition_type[8]; //0 == none, 1 == normal, 3 == FIRM, 4 == AGB_FIRM save
26  uint8_t partition_crypt[8]; //one byte per partition in the table
27  struct
28  {
29  uint32_t media_offset; //in media units
30  uint32_t media_length; //in media units
31  } partition_offset_length_table[8];
32 
33  uint8_t exheader_sha256[0x20]; //sha256 of exheader
34  uint32_t header_size;
35  uint32_t sector_zero_offset;
36  uint8_t partition_id_table[8][8];
37  uint8_t partition_flags[8];
38  uint8_t reserved1[0x20];
39  uint8_t reserved2[0xE];
40  uint8_t anti_piracy_; //This is a guess on the function of this thing, based on 3dbrew
41  uint8_t save_crypto_extra; //This is somewhat documented in Parition Flags for 9.6+
42 
44 
47 typedef struct
48 {
49  uint8_t signature[0x100]; //rsa 2048 signature of a sha256 of the header
50  uint8_t magic[4];
51  uint32_t content_size; //in media units
52  uint8_t partition_id[8];
53  uint8_t maker_code[2];
54  uint8_t version[2];
55  uint32_t hash_content_lock_verify;
56  uint8_t program_id[8];
57  uint8_t reserved1[0x10];
58  uint8_t logo_region_sha256[0x20]; //used 5.0.0-11+
59  uint8_t product_code[0x10];
60  uint8_t exheader_sha256[0x20]; //(SHA256 of 2x Alignment Size, beginning at 0x0 of ExHeader)
61  uint32_t exheader_size; //in bytes
62  uint8_t reserved2[4];
63  uint8_t flags[8];
64  uint32_t plain_offset_region; //in media units
65  uint32_t plain_region_size; //in media units
66  uint32_t logo_offset_region; //in media units
67  uint32_t logo_region_size; //in media units
68  uint32_t exefs_offset_region; //in media units
69  uint32_t exefs_region_size; //in media units
70  uint32_t exefs_hash_region_size; //in media units
71  uint8_t reserved3[4];
72  uint32_t romfs_offset_region; //in media units
73  uint32_t romfs_region_size; //in media units
74  uint32_t romfs_hash_region_size; //in media units
75  uint8_t reserved4[4];
76  uint8_t exefs_superblock_sha256[0x20]; //starting at 0x0 of the ExeFS over the number of media units specified in the ExeFS hash region size
77  uint8_t romfs_superblock_sha256[0x20]; //starting at 0x0 of the RomFS over the number of media units specified in the RomFS hash region size
79 
92 void ctr_ncsd_header_load(ctr_ncsd_cart_header *header, const uint8_t *data, size_t data_size);
93 
106 void ctr_ncch_header_load(ctr_ncch_header *header, const uint8_t *data, size_t data_size);
107 
108 #endif//CTR_HEADERS_H_
109 
Struct representing the NCSD header for carts.
Definition: ctr_headers.h:19
void ctr_ncch_header_load(ctr_ncch_header *header, const uint8_t *data, size_t data_size)
Loads the given ctr_ncch_header with the data from the actual NCCH header in memory.
Struct representing the NCCH header.
Definition: ctr_headers.h:47
void ctr_ncsd_header_load(ctr_ncsd_cart_header *header, const uint8_t *data, size_t data_size)
Loads the given ctr_ncsd_cart_header with the data from the actual NCSD cart header in memory...