diff options
| author | 2014-06-18 23:53:22 -0400 | |
|---|---|---|
| committer | 2014-06-24 19:30:05 -0400 | |
| commit | 3da2bc6830e05d943c4d131a3167c2df25bff344 (patch) | |
| tree | 8f77cc09046ea8be33eb9816ffbf89d9cecdf524 /src/core/loader/ncch.cpp | |
| parent | Loader: Implemented AppLoader interface for abstracting application loading. (diff) | |
| download | yuzu-3da2bc6830e05d943c4d131a3167c2df25bff344.tar.gz yuzu-3da2bc6830e05d943c4d131a3167c2df25bff344.tar.xz yuzu-3da2bc6830e05d943c4d131a3167c2df25bff344.zip | |
NCCH: Fixes reduce unnecessary logging and load logo/banner/etc. sections correctly.
Loader: Added ErrorNotUsed ReturnStatus type to specify when something is not used.
Diffstat (limited to 'src/core/loader/ncch.cpp')
| -rw-r--r-- | src/core/loader/ncch.cpp | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 765efcf65..4cf805ba0 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -15,8 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | namespace Loader { | 16 | namespace Loader { |
| 17 | 17 | ||
| 18 | const int kExeFs_MaxSections = 8; ///< Maximum number of sections (files) in an ExeFs | 18 | static const int kMaxSections = 8; ///< Maximum number of sections (files) in an ExeFs |
| 19 | const int kExeFs_BlockSize = 0x200; ///< Size of ExeFS blocks (in bytes) | 19 | static const int kBlockSize = 0x200; ///< Size of ExeFS blocks (in bytes) |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | * Get the decompressed size of an LZSS compressed ExeFS file | 22 | * Get the decompressed size of an LZSS compressed ExeFS file |
| @@ -132,22 +132,24 @@ const ResultStatus AppLoader_NCCH::LoadExec() const { | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | /** | 134 | /** |
| 135 | * Reads an application section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) | 135 | * Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) |
| 136 | * @param file Handle to file to read from | 136 | * @param file Handle to file to read from |
| 137 | * @param name Name of section to read out of NCCH file | 137 | * @param name Name of section to read out of NCCH file |
| 138 | * @param buffer Buffer to read section into. | 138 | * @param buffer Buffer to read section into. |
| 139 | */ | 139 | */ |
| 140 | const ResultStatus AppLoader_NCCH::LoadSection(File::IOFile& file, const char* name, | 140 | const ResultStatus AppLoader_NCCH::LoadSectionExeFS(File::IOFile& file, const char* name, |
| 141 | std::vector<u8>& buffer) { | 141 | std::vector<u8>& buffer) { |
| 142 | |||
| 142 | // Iterate through the ExeFs archive until we find the .code file... | 143 | // Iterate through the ExeFs archive until we find the .code file... |
| 143 | for (int i = 0; i < kExeFs_MaxSections; i++) { | 144 | for (int i = 0; i < kMaxSections; i++) { |
| 144 | INFO_LOG(LOADER, "ExeFS section %d:", i); | ||
| 145 | INFO_LOG(LOADER, " name: %s", exefs_header.section[i].name); | ||
| 146 | INFO_LOG(LOADER, " offset: 0x%08X", exefs_header.section[i].offset); | ||
| 147 | INFO_LOG(LOADER, " size: 0x%08X", exefs_header.section[i].size); | ||
| 148 | 145 | ||
| 149 | // Load the .code section (executable code)... | 146 | // Load the specified section... |
| 150 | if (strcmp((const char*)exefs_header.section[i].name, name) == 0) { | 147 | if (strcmp((const char*)exefs_header.section[i].name, name) == 0) { |
| 148 | INFO_LOG(LOADER, "ExeFS section %d:", i); | ||
| 149 | INFO_LOG(LOADER, " name: %s", exefs_header.section[i].name); | ||
| 150 | INFO_LOG(LOADER, " offset: 0x%08X", exefs_header.section[i].offset); | ||
| 151 | INFO_LOG(LOADER, " size: 0x%08X", exefs_header.section[i].size); | ||
| 152 | |||
| 151 | s64 section_offset = (exefs_header.section[i].offset + exefs_offset + | 153 | s64 section_offset = (exefs_header.section[i].offset + exefs_offset + |
| 152 | sizeof(ExeFs_Header) + ncch_offset); | 154 | sizeof(ExeFs_Header) + ncch_offset); |
| 153 | file.Seek(section_offset, 0); | 155 | file.Seek(section_offset, 0); |
| @@ -173,7 +175,7 @@ const ResultStatus AppLoader_NCCH::LoadSection(File::IOFile& file, const char* n | |||
| 173 | return ResultStatus::Success; | 175 | return ResultStatus::Success; |
| 174 | } | 176 | } |
| 175 | } | 177 | } |
| 176 | return ResultStatus::Error; | 178 | return ResultStatus::ErrorNotUsed; |
| 177 | } | 179 | } |
| 178 | 180 | ||
| 179 | /** | 181 | /** |
| @@ -206,7 +208,8 @@ const ResultStatus AppLoader_NCCH::Load() { | |||
| 206 | if (0 != memcmp(&ncch_header.magic, "NCCH", 4)) | 208 | if (0 != memcmp(&ncch_header.magic, "NCCH", 4)) |
| 207 | return ResultStatus::ErrorInvalidFormat; | 209 | return ResultStatus::ErrorInvalidFormat; |
| 208 | 210 | ||
| 209 | // Read ExHeader | 211 | // Read ExHeader... |
| 212 | |||
| 210 | file.ReadBytes(&exheader_header, sizeof(ExHeader_Header)); | 213 | file.ReadBytes(&exheader_header, sizeof(ExHeader_Header)); |
| 211 | 214 | ||
| 212 | is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; | 215 | is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; |
| @@ -216,9 +219,10 @@ const ResultStatus AppLoader_NCCH::Load() { | |||
| 216 | INFO_LOG(LOADER, "Code compressed: %s", is_compressed ? "yes" : "no"); | 219 | INFO_LOG(LOADER, "Code compressed: %s", is_compressed ? "yes" : "no"); |
| 217 | INFO_LOG(LOADER, "Entry point: 0x%08X", entry_point); | 220 | INFO_LOG(LOADER, "Entry point: 0x%08X", entry_point); |
| 218 | 221 | ||
| 219 | // Read ExeFS | 222 | // Read ExeFS... |
| 220 | exefs_offset = ncch_header.exefs_offset * kExeFs_BlockSize; | 223 | |
| 221 | u32 exefs_size = ncch_header.exefs_size * kExeFs_BlockSize; | 224 | exefs_offset = ncch_header.exefs_offset * kBlockSize; |
| 225 | u32 exefs_size = ncch_header.exefs_size * kBlockSize; | ||
| 222 | 226 | ||
| 223 | INFO_LOG(LOADER, "ExeFS offset: 0x%08X", exefs_offset); | 227 | INFO_LOG(LOADER, "ExeFS offset: 0x%08X", exefs_offset); |
| 224 | INFO_LOG(LOADER, "ExeFS size: 0x%08X", exefs_size); | 228 | INFO_LOG(LOADER, "ExeFS size: 0x%08X", exefs_size); |
| @@ -226,11 +230,12 @@ const ResultStatus AppLoader_NCCH::Load() { | |||
| 226 | file.Seek(exefs_offset + ncch_offset, 0); | 230 | file.Seek(exefs_offset + ncch_offset, 0); |
| 227 | file.ReadBytes(&exefs_header, sizeof(ExeFs_Header)); | 231 | file.ReadBytes(&exefs_header, sizeof(ExeFs_Header)); |
| 228 | 232 | ||
| 229 | // TODO(bunnei): Check ResultStatus here... | 233 | // TODO(bunnei): Check ResultStatus of these... |
| 230 | LoadSection(file, ".code", code); | 234 | |
| 231 | LoadSection(file, ".icon", icon); | 235 | LoadSectionExeFS(file, ".code", code); |
| 232 | LoadSection(file, ".banner", banner); | 236 | LoadSectionExeFS(file, "banner", banner); |
| 233 | LoadSection(file, ".logo", logo); | 237 | LoadSectionExeFS(file, "icon", icon); |
| 238 | LoadSectionExeFS(file, "logo", logo); | ||
| 234 | 239 | ||
| 235 | is_loaded = true; // Set state to loaded | 240 | is_loaded = true; // Set state to loaded |
| 236 | 241 | ||