diff options
| author | 2014-06-18 18:58:09 -0400 | |
|---|---|---|
| committer | 2014-06-24 19:29:58 -0400 | |
| commit | 7889cafc76ac99b8509fa3cd1558a09f8a7e5f91 (patch) | |
| tree | e6ffea9ec1c334bfca13404c47a2191fd281554c /src/core/loader/ncch.h | |
| parent | NCCH: Changed decompression to load .code directly into memory rather than an... (diff) | |
| download | yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.tar.gz yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.tar.xz yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.zip | |
Loader: Implemented AppLoader interface for abstracting application loading.
- Various cleanups/refactorings to Loader, ELF, and NCCH modules.
- Added AppLoader interface to ELF and NCCH.
- Updated Qt/GLFW frontends to check AppLoader ResultStatus.
NCCH: Removed extra qualification typos.
Loader: Removed unnecessary #include's.
NCCH: Improved readability of memcmp statements.
NCCH: Added missing space.
Elf: Removed unnecessary usage of unique_ptr.
Loader: Removed unnecessary usage of unique_ptr.
Diffstat (limited to 'src/core/loader/ncch.h')
| -rw-r--r-- | src/core/loader/ncch.h | 181 |
1 files changed, 174 insertions, 7 deletions
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 778e8b456..3aae5417c 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h | |||
| @@ -5,17 +5,184 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common.h" | 7 | #include "common/common.h" |
| 8 | #include "common/file_util.h" | ||
| 9 | |||
| 10 | #include "core/loader/loader.h" | ||
| 11 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 13 | /// NCCH header (Note: "NCCH" appears to be a publically unknown acronym) | ||
| 14 | |||
| 15 | struct NCCH_Header { | ||
| 16 | u8 signature[0x100]; | ||
| 17 | char magic[4]; | ||
| 18 | u32 content_size; | ||
| 19 | u8 partition_id[8]; | ||
| 20 | u16 maker_code; | ||
| 21 | u16 version; | ||
| 22 | u8 reserved_0[4]; | ||
| 23 | u8 program_id[8]; | ||
| 24 | u8 temp_flag; | ||
| 25 | u8 reserved_1[0x2f]; | ||
| 26 | u8 product_code[0x10]; | ||
| 27 | u8 extended_header_hash[0x20]; | ||
| 28 | u32 extended_header_size; | ||
| 29 | u8 reserved_2[4]; | ||
| 30 | u8 flags[8]; | ||
| 31 | u32 plain_region_offset; | ||
| 32 | u32 plain_region_size; | ||
| 33 | u8 reserved_3[8]; | ||
| 34 | u32 exefs_offset; | ||
| 35 | u32 exefs_size; | ||
| 36 | u32 exefs_hash_region_size; | ||
| 37 | u8 reserved_4[4]; | ||
| 38 | u32 romfs_offset; | ||
| 39 | u32 romfs_size; | ||
| 40 | u32 romfs_hash_region_size; | ||
| 41 | u8 reserved_5[4]; | ||
| 42 | u8 exefs_super_block_hash[0x20]; | ||
| 43 | u8 romfs_super_block_hash[0x20]; | ||
| 44 | }; | ||
| 45 | |||
| 46 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 47 | // ExeFS (executable file system) headers | ||
| 48 | |||
| 49 | typedef struct { | ||
| 50 | char name[8]; | ||
| 51 | u32 offset; | ||
| 52 | u32 size; | ||
| 53 | } ExeFs_SectionHeader; | ||
| 54 | |||
| 55 | typedef struct { | ||
| 56 | ExeFs_SectionHeader section[8]; | ||
| 57 | u8 reserved[0x80]; | ||
| 58 | u8 hashes[8][0x20]; | ||
| 59 | } ExeFs_Header; | ||
| 60 | |||
| 61 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 62 | // ExHeader (executable file system header) headers | ||
| 63 | |||
| 64 | struct ExHeader_SystemInfoFlags{ | ||
| 65 | u8 reserved[5]; | ||
| 66 | u8 flag; | ||
| 67 | u8 remaster_version[2]; | ||
| 68 | }; | ||
| 69 | |||
| 70 | struct ExHeader_CodeSegmentInfo{ | ||
| 71 | u32 address; | ||
| 72 | u32 num_max_pages; | ||
| 73 | u32 code_size; | ||
| 74 | }; | ||
| 75 | |||
| 76 | struct ExHeader_CodeSetInfo { | ||
| 77 | u8 name[8]; | ||
| 78 | ExHeader_SystemInfoFlags flags; | ||
| 79 | ExHeader_CodeSegmentInfo text; | ||
| 80 | u8 stacksize[4]; | ||
| 81 | ExHeader_CodeSegmentInfo ro; | ||
| 82 | u8 reserved[4]; | ||
| 83 | ExHeader_CodeSegmentInfo data; | ||
| 84 | u8 bsssize[4]; | ||
| 85 | }; | ||
| 86 | |||
| 87 | struct ExHeader_DependencyList{ | ||
| 88 | u8 program_id[0x30][8]; | ||
| 89 | }; | ||
| 90 | |||
| 91 | struct ExHeader_SystemInfo{ | ||
| 92 | u32 save_data_size; | ||
| 93 | u8 reserved[4]; | ||
| 94 | u8 jump_id[8]; | ||
| 95 | u8 reserved_2[0x30]; | ||
| 96 | }; | ||
| 97 | |||
| 98 | struct ExHeader_StorageInfo{ | ||
| 99 | u8 ext_save_data_id[8]; | ||
| 100 | u8 system_save_data_id[8]; | ||
| 101 | u8 reserved[8]; | ||
| 102 | u8 access_info[7]; | ||
| 103 | u8 other_attributes; | ||
| 104 | }; | ||
| 105 | |||
| 106 | struct ExHeader_ARM11_SystemLocalCaps{ | ||
| 107 | u8 program_id[8]; | ||
| 108 | u8 flags[8]; | ||
| 109 | u8 resource_limit_descriptor[0x10][2]; | ||
| 110 | ExHeader_StorageInfo storage_info; | ||
| 111 | u8 service_access_control[0x20][8]; | ||
| 112 | u8 reserved[0x1f]; | ||
| 113 | u8 resource_limit_category; | ||
| 114 | }; | ||
| 115 | |||
| 116 | struct ExHeader_ARM11_KernelCaps{ | ||
| 117 | u8 descriptors[28][4]; | ||
| 118 | u8 reserved[0x10]; | ||
| 119 | }; | ||
| 120 | |||
| 121 | struct ExHeader_ARM9_AccessControl{ | ||
| 122 | u8 descriptors[15]; | ||
| 123 | u8 descversion; | ||
| 124 | }; | ||
| 125 | |||
| 126 | struct ExHeader_Header{ | ||
| 127 | ExHeader_CodeSetInfo codeset_info; | ||
| 128 | ExHeader_DependencyList dependency_list; | ||
| 129 | ExHeader_SystemInfo system_info; | ||
| 130 | ExHeader_ARM11_SystemLocalCaps arm11_system_local_caps; | ||
| 131 | ExHeader_ARM11_KernelCaps arm11_kernel_caps; | ||
| 132 | ExHeader_ARM9_AccessControl arm9_access_control; | ||
| 133 | struct { | ||
| 134 | u8 signature[0x100]; | ||
| 135 | u8 ncch_public_key_modulus[0x100]; | ||
| 136 | ExHeader_ARM11_SystemLocalCaps arm11_system_local_caps; | ||
| 137 | ExHeader_ARM11_KernelCaps arm11_kernel_caps; | ||
| 138 | ExHeader_ARM9_AccessControl arm9_access_control; | ||
| 139 | } access_desc; | ||
| 140 | }; | ||
| 8 | 141 | ||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 142 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 143 | // Loader namespace | ||
| 10 | 144 | ||
| 11 | namespace Loader { | 145 | namespace Loader { |
| 12 | 146 | ||
| 13 | /** | 147 | /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) |
| 14 | * Loads an NCCH file (e.g. from a CCI or CXI) | 148 | class AppLoader_NCCH : public AppLoader { |
| 15 | * @param filename String filename of NCCH file | 149 | public: |
| 16 | * @param error_string Pointer to string to put error message if an error has occurred | 150 | AppLoader_NCCH(std::string& filename); |
| 17 | * @return True on success, otherwise false | 151 | ~AppLoader_NCCH(); |
| 18 | */ | 152 | |
| 19 | bool Load_NCCH(std::string& filename, std::string* error_string); | 153 | /** |
| 154 | * Load the application | ||
| 155 | * @return ResultStatus result of function | ||
| 156 | */ | ||
| 157 | const ResultStatus Load(); | ||
| 158 | |||
| 159 | private: | ||
| 160 | |||
| 161 | /** | ||
| 162 | * Reads an application section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) | ||
| 163 | * @param file Handle to file to read from | ||
| 164 | * @param name Name of section to read out of NCCH file | ||
| 165 | * @param buffer Buffer to read section into. | ||
| 166 | */ | ||
| 167 | const ResultStatus LoadSection(File::IOFile& file, const char* name, | ||
| 168 | std::vector<u8>& buffer); | ||
| 169 | |||
| 170 | /** | ||
| 171 | * Loads .code section into memory for booting | ||
| 172 | * @return ResultStatus result of function | ||
| 173 | */ | ||
| 174 | const ResultStatus LoadExec() const; | ||
| 175 | |||
| 176 | std::string filename; | ||
| 177 | bool is_loaded; | ||
| 178 | bool is_compressed; | ||
| 179 | u32 entry_point; | ||
| 180 | |||
| 181 | u32 ncch_offset; // Offset to NCCH header, can be 0 or after NCSD header | ||
| 182 | u32 exefs_offset; | ||
| 183 | |||
| 184 | ExeFs_Header exefs_header; | ||
| 185 | ExHeader_Header exheader_header; | ||
| 186 | }; | ||
| 20 | 187 | ||
| 21 | } // namespace Loader | 188 | } // namespace Loader |