summaryrefslogtreecommitdiff
path: root/src/core/loader/ncch.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2014-06-27 15:33:23 -0400
committerGravatar bunnei2014-06-27 17:49:01 -0400
commitd8da707bb90c233d5e815a508bea3473e6e50afa (patch)
treedd9056678f602276691bb4613ea38c7c2ac9126f /src/core/loader/ncch.cpp
parentFS: Added stubbed code to intercept and decode file system service functions. (diff)
downloadyuzu-d8da707bb90c233d5e815a508bea3473e6e50afa.tar.gz
yuzu-d8da707bb90c233d5e815a508bea3473e6e50afa.tar.xz
yuzu-d8da707bb90c233d5e815a508bea3473e6e50afa.zip
Loader: Refactored interface such that data is no longer stored by loader.
NCCH: Removed extra qualification ‘Loader::AppLoader_NCCH::’.
Diffstat (limited to 'src/core/loader/ncch.cpp')
-rw-r--r--src/core/loader/ncch.cpp77
1 files changed, 34 insertions, 43 deletions
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 60505bdfa..0e3f768ce 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -125,25 +125,22 @@ ResultStatus AppLoader_NCCH::LoadExec() {
125 if (!is_loaded) 125 if (!is_loaded)
126 return ResultStatus::ErrorNotLoaded; 126 return ResultStatus::ErrorNotLoaded;
127 127
128 ResultStatus res; 128 std::vector<u8> code;
129 code = ReadCode(res); 129 if (ResultStatus::Success == ReadCode(code)) {
130
131 if (ResultStatus::Success == res) {
132 Memory::WriteBlock(entry_point, &code[0], code.size()); 130 Memory::WriteBlock(entry_point, &code[0], code.size());
133 Kernel::LoadExec(entry_point); 131 Kernel::LoadExec(entry_point);
132 return ResultStatus::Success;
134 } 133 }
135 return res; 134 return ResultStatus::Error;
136} 135}
137 136
138/** 137/**
139 * Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) 138 * Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.)
140 * @param name Name of section to read out of NCCH file 139 * @param name Name of section to read out of NCCH file
141 * @param buffer Vector to read data into 140 * @param buffer Vector to read data into
142 * @param error ResultStatus result of function 141 * @return ResultStatus result of function
143 * @return Reference to buffer of data that was read
144 */ 142 */
145const std::vector<u8>& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer, 143ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) {
146 ResultStatus& error) {
147 // Iterate through the ExeFs archive until we find the .code file... 144 // Iterate through the ExeFs archive until we find the .code file...
148 for (int i = 0; i < kMaxSections; i++) { 145 for (int i = 0; i < kMaxSections; i++) {
149 // Load the specified section... 146 // Load the specified section...
@@ -169,20 +166,17 @@ const std::vector<u8>& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::v
169 buffer.resize(decompressed_size); 166 buffer.resize(decompressed_size);
170 if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0], 167 if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0],
171 decompressed_size)) { 168 decompressed_size)) {
172 error = ResultStatus::ErrorInvalidFormat; 169 return ResultStatus::ErrorInvalidFormat;
173 return buffer;
174 } 170 }
175 // Section is uncompressed... 171 // Section is uncompressed...
176 } else { 172 } else {
177 buffer.resize(exefs_header.section[i].size); 173 buffer.resize(exefs_header.section[i].size);
178 file.ReadBytes(&buffer[0], exefs_header.section[i].size); 174 file.ReadBytes(&buffer[0], exefs_header.section[i].size);
179 } 175 }
180 error = ResultStatus::Success; 176 return ResultStatus::Success;
181 return buffer;
182 } 177 }
183 } 178 }
184 error = ResultStatus::ErrorNotUsed; 179 return ResultStatus::ErrorNotUsed;
185 return buffer;
186} 180}
187 181
188/** 182/**
@@ -247,46 +241,46 @@ ResultStatus AppLoader_NCCH::Load() {
247 241
248/** 242/**
249 * Get the code (typically .code section) of the application 243 * Get the code (typically .code section) of the application
250 * @param error ResultStatus result of function 244 * @param buffer Reference to buffer to store data
251 * @return Reference to code buffer 245 * @return ResultStatus result of function
252 */ 246 */
253const std::vector<u8>& AppLoader_NCCH::ReadCode(ResultStatus& error) { 247ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) {
254 return LoadSectionExeFS(".code", code, error); 248 return LoadSectionExeFS(".code", buffer);
255} 249}
256 250
257/** 251/**
258 * Get the icon (typically icon section) of the application 252 * Get the icon (typically icon section) of the application
259 * @param error ResultStatus result of function 253 * @param buffer Reference to buffer to store data
260 * @return Reference to icon buffer 254 * @return ResultStatus result of function
261 */ 255 */
262const std::vector<u8>& AppLoader_NCCH::ReadIcon(ResultStatus& error) { 256ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) {
263 return LoadSectionExeFS("icon", icon, error); 257 return LoadSectionExeFS("icon", buffer);
264} 258}
265 259
266/** 260/**
267 * Get the banner (typically banner section) of the application 261 * Get the banner (typically banner section) of the application
268 * @param error ResultStatus result of function 262 * @param buffer Reference to buffer to store data
269 * @return Reference to banner buffer 263 * @return ResultStatus result of function
270 */ 264 */
271const std::vector<u8>& AppLoader_NCCH::ReadBanner(ResultStatus& error) { 265ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) {
272 return LoadSectionExeFS("banner", banner, error); 266 return LoadSectionExeFS("banner", buffer);
273} 267}
274 268
275/** 269/**
276 * Get the logo (typically logo section) of the application 270 * Get the logo (typically logo section) of the application
277 * @param error ResultStatus result of function 271 * @param buffer Reference to buffer to store data
278 * @return Reference to logo buffer 272 * @return ResultStatus result of function
279 */ 273 */
280const std::vector<u8>& AppLoader_NCCH::ReadLogo(ResultStatus& error) { 274ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) {
281 return LoadSectionExeFS("logo", logo, error); 275 return LoadSectionExeFS("logo", buffer);
282} 276}
283 277
284/** 278/**
285 * Get the RomFs archive of the application 279 * Get the RomFS of the application
286 * @param error ResultStatus result of function 280 * @param buffer Reference to buffer to store data
287 * @return Reference to RomFs archive buffer 281 * @return ResultStatus result of function
288 */ 282 */
289const std::vector<u8>& AppLoader_NCCH::ReadRomFS(ResultStatus& error) { 283ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) {
290 // Check if the NCCH has a RomFS... 284 // Check if the NCCH has a RomFS...
291 if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) { 285 if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) {
292 u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; 286 u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000;
@@ -295,18 +289,15 @@ const std::vector<u8>& AppLoader_NCCH::ReadRomFS(ResultStatus& error) {
295 INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset); 289 INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset);
296 INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size); 290 INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size);
297 291
298 romfs.resize(romfs_size); 292 buffer.resize(romfs_size);
299 293
300 file.Seek(romfs_offset, 0); 294 file.Seek(romfs_offset, 0);
301 file.ReadBytes(&romfs[0], romfs_size); 295 file.ReadBytes(&buffer[0], romfs_size);
302 296
303 error = ResultStatus::Success; 297 return ResultStatus::Success;
304 return romfs;
305 } else {
306 NOTICE_LOG(LOADER, "RomFS unused");
307 } 298 }
308 error = ResultStatus::ErrorNotUsed; 299 NOTICE_LOG(LOADER, "RomFS unused");
309 return romfs; 300 return ResultStatus::ErrorNotUsed;
310} 301}
311 302
312} // namespace Loader 303} // namespace Loader