From d8da707bb90c233d5e815a508bea3473e6e50afa Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 27 Jun 2014 15:33:23 -0400 Subject: Loader: Refactored interface such that data is no longer stored by loader. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NCCH: Removed extra qualification ‘Loader::AppLoader_NCCH::’. --- src/core/loader/loader.h | 54 +++++++++++++-------------------- src/core/loader/ncch.cpp | 77 +++++++++++++++++++++--------------------------- src/core/loader/ncch.h | 38 +++++++++++------------- 3 files changed, 73 insertions(+), 96 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 95f16fcb1..7891c1ed7 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -48,60 +48,48 @@ public: /** * Get the code (typically .code section) of the application - * @param error ResultStatus result of function - * @return Reference to code buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - virtual const std::vector& ReadCode(ResultStatus& error) const { - error = ResultStatus::ErrorNotImplemented; - return code; + virtual ResultStatus ReadCode(std::vector& buffer) { + return ResultStatus::ErrorNotImplemented; } /** * Get the icon (typically icon section) of the application - * @param error ResultStatus result of function - * @return Reference to icon buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - virtual const std::vector& ReadIcon(ResultStatus& error) const { - error = ResultStatus::ErrorNotImplemented; - return icon; + virtual ResultStatus ReadIcon(std::vector& buffer) { + return ResultStatus::ErrorNotImplemented; } /** * Get the banner (typically banner section) of the application - * @param error ResultStatus result of function - * @return Reference to banner buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - virtual const std::vector& ReadBanner(ResultStatus& error) const { - error = ResultStatus::ErrorNotImplemented; - return banner; + virtual ResultStatus ReadBanner(std::vector& buffer) { + return ResultStatus::ErrorNotImplemented; } /** * Get the logo (typically logo section) of the application - * @param error ResultStatus result of function - * @return Reference to logo buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - virtual const std::vector& ReadLogo(ResultStatus& error) const { - error = ResultStatus::ErrorNotImplemented; - return logo; + virtual ResultStatus ReadLogo(std::vector& buffer) { + return ResultStatus::ErrorNotImplemented; } /** - * Get the RomFs archive of the application - * @param error ResultStatus result of function - * @return Reference to RomFs archive buffer + * Get the RomFS of the application + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - virtual const std::vector& ReadRomFS(ResultStatus& error) const { - error = ResultStatus::ErrorNotImplemented; - return romfs; + virtual ResultStatus ReadRomFS(std::vector& buffer) { + return ResultStatus::ErrorNotImplemented; } - -protected: - std::vector code; ///< ExeFS .code section - std::vector icon; ///< ExeFS .icon section - std::vector banner; ///< ExeFS .banner section - std::vector logo; ///< ExeFS .logo section - std::vector romfs; ///< RomFs archive }; /** 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() { if (!is_loaded) return ResultStatus::ErrorNotLoaded; - ResultStatus res; - code = ReadCode(res); - - if (ResultStatus::Success == res) { + std::vector code; + if (ResultStatus::Success == ReadCode(code)) { Memory::WriteBlock(entry_point, &code[0], code.size()); Kernel::LoadExec(entry_point); + return ResultStatus::Success; } - return res; + return ResultStatus::Error; } /** * Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) * @param name Name of section to read out of NCCH file * @param buffer Vector to read data into - * @param error ResultStatus result of function - * @return Reference to buffer of data that was read + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector& buffer, - ResultStatus& error) { +ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector& buffer) { // Iterate through the ExeFs archive until we find the .code file... for (int i = 0; i < kMaxSections; i++) { // Load the specified section... @@ -169,20 +166,17 @@ const std::vector& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::v buffer.resize(decompressed_size); if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0], decompressed_size)) { - error = ResultStatus::ErrorInvalidFormat; - return buffer; + return ResultStatus::ErrorInvalidFormat; } // Section is uncompressed... } else { buffer.resize(exefs_header.section[i].size); file.ReadBytes(&buffer[0], exefs_header.section[i].size); } - error = ResultStatus::Success; - return buffer; + return ResultStatus::Success; } } - error = ResultStatus::ErrorNotUsed; - return buffer; + return ResultStatus::ErrorNotUsed; } /** @@ -247,46 +241,46 @@ ResultStatus AppLoader_NCCH::Load() { /** * Get the code (typically .code section) of the application - * @param error ResultStatus result of function - * @return Reference to code buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::ReadCode(ResultStatus& error) { - return LoadSectionExeFS(".code", code, error); +ResultStatus AppLoader_NCCH::ReadCode(std::vector& buffer) { + return LoadSectionExeFS(".code", buffer); } /** * Get the icon (typically icon section) of the application - * @param error ResultStatus result of function - * @return Reference to icon buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::ReadIcon(ResultStatus& error) { - return LoadSectionExeFS("icon", icon, error); +ResultStatus AppLoader_NCCH::ReadIcon(std::vector& buffer) { + return LoadSectionExeFS("icon", buffer); } /** * Get the banner (typically banner section) of the application - * @param error ResultStatus result of function - * @return Reference to banner buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::ReadBanner(ResultStatus& error) { - return LoadSectionExeFS("banner", banner, error); +ResultStatus AppLoader_NCCH::ReadBanner(std::vector& buffer) { + return LoadSectionExeFS("banner", buffer); } /** * Get the logo (typically logo section) of the application - * @param error ResultStatus result of function - * @return Reference to logo buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::ReadLogo(ResultStatus& error) { - return LoadSectionExeFS("logo", logo, error); +ResultStatus AppLoader_NCCH::ReadLogo(std::vector& buffer) { + return LoadSectionExeFS("logo", buffer); } /** - * Get the RomFs archive of the application - * @param error ResultStatus result of function - * @return Reference to RomFs archive buffer + * Get the RomFS of the application + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ -const std::vector& AppLoader_NCCH::ReadRomFS(ResultStatus& error) { +ResultStatus AppLoader_NCCH::ReadRomFS(std::vector& buffer) { // Check if the NCCH has a RomFS... if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) { u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; @@ -295,18 +289,15 @@ const std::vector& AppLoader_NCCH::ReadRomFS(ResultStatus& error) { INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset); INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size); - romfs.resize(romfs_size); + buffer.resize(romfs_size); file.Seek(romfs_offset, 0); - file.ReadBytes(&romfs[0], romfs_size); + file.ReadBytes(&buffer[0], romfs_size); - error = ResultStatus::Success; - return romfs; - } else { - NOTICE_LOG(LOADER, "RomFS unused"); + return ResultStatus::Success; } - error = ResultStatus::ErrorNotUsed; - return romfs; + NOTICE_LOG(LOADER, "RomFS unused"); + return ResultStatus::ErrorNotUsed; } } // namespace Loader diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index bf65425a4..99753b244 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -158,38 +158,38 @@ public: /** * Get the code (typically .code section) of the application - * @param error ResultStatus result of function - * @return Reference to code buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - const std::vector& ReadCode(ResultStatus& error); + ResultStatus ReadCode(std::vector& buffer); /** * Get the icon (typically icon section) of the application - * @param error ResultStatus result of function - * @return Reference to icon buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - const std::vector& ReadIcon(ResultStatus& error); + ResultStatus ReadIcon(std::vector& buffer); /** * Get the banner (typically banner section) of the application - * @param error ResultStatus result of function - * @return Reference to banner buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - const std::vector& ReadBanner(ResultStatus& error); + ResultStatus ReadBanner(std::vector& buffer); /** * Get the logo (typically logo section) of the application - * @param error ResultStatus result of function - * @return Reference to logo buffer + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - const std::vector& ReadLogo(ResultStatus& error); + ResultStatus ReadLogo(std::vector& buffer); /** - * Get the RomFs archive of the application - * @param error ResultStatus result of function - * @return Reference to RomFs archive buffer + * Get the RomFS of the application + * @param buffer Reference to buffer to store data + * @return ResultStatus result of function */ - const std::vector& ReadRomFS(ResultStatus& error); + ResultStatus ReadRomFS(std::vector& buffer); private: @@ -197,11 +197,9 @@ private: * Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) * @param name Name of section to read out of NCCH file * @param buffer Vector to read data into - * @param error ResultStatus result of function - * @return Reference to buffer of data that was read + * @return ResultStatus result of function */ - const std::vector& LoadSectionExeFS(const char* name, std::vector& buffer, - ResultStatus& error); + ResultStatus LoadSectionExeFS(const char* name, std::vector& buffer); /** * Loads .code section into memory for booting -- cgit v1.2.3 From 17a6148f9df406a6ca4bdca98777e0aaf21f582a Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 27 Jun 2014 16:18:56 -0400 Subject: FileSys: Added preliminary support for applications reading the RomFS archive. Archive: Fixed brace ugliness for neobrain :) FS: Commented out unused local variables to prevent warnings. ...But keeping them here for future use. archive_romfs: Removed unused #include. --- src/core/loader/loader.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 96cb81de0..2b42e3c64 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -4,9 +4,11 @@ #include +#include "core/file_sys/archive_romfs.h" #include "core/loader/loader.h" #include "core/loader/elf.h" #include "core/loader/ncch.h" +#include "core/hle/kernel/archive.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -51,14 +53,20 @@ ResultStatus LoadFile(const std::string& filename) { switch (IdentifyFile(filename)) { // Standard ELF file format... - case FileType::ELF: { + case FileType::ELF: return AppLoader_ELF(filename).Load(); - } // NCCH/NCSD container formats... case FileType::CXI: case FileType::CCI: { - return AppLoader_NCCH(filename).Load(); + AppLoader_NCCH app_loader(filename); + + // Load application and RomFS + if (ResultStatus::Success == app_loader.Load()) { + Kernel::CreateArchive(new FileSys::Archive_RomFS(app_loader), "RomFS"); + return ResultStatus::Success; + } + break; } // Error occurred durring IdentifyFile... @@ -70,7 +78,6 @@ ResultStatus LoadFile(const std::string& filename) { default: return ResultStatus::ErrorInvalidFormat; } - return ResultStatus::Error; } -- cgit v1.2.3 From 2c62d9255160b7302942d536c9c990b86c7fb907 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Jul 2014 13:11:09 -0400 Subject: Loader: Updated read methods to be const - Required "file" handle to be made local and explicitly opened/closed as needed --- src/core/loader/loader.h | 10 ++-- src/core/loader/ncch.cpp | 118 ++++++++++++++++++++++++++--------------------- src/core/loader/ncch.h | 15 +++--- 3 files changed, 77 insertions(+), 66 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 7891c1ed7..c27b5b4b6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -51,7 +51,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadCode(std::vector& buffer) { + virtual ResultStatus ReadCode(std::vector& buffer) const { return ResultStatus::ErrorNotImplemented; } @@ -60,7 +60,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadIcon(std::vector& buffer) { + virtual ResultStatus ReadIcon(std::vector& buffer) const { return ResultStatus::ErrorNotImplemented; } @@ -69,7 +69,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadBanner(std::vector& buffer) { + virtual ResultStatus ReadBanner(std::vector& buffer) const { return ResultStatus::ErrorNotImplemented; } @@ -78,7 +78,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadLogo(std::vector& buffer) { + virtual ResultStatus ReadLogo(std::vector& buffer) const { return ResultStatus::ErrorNotImplemented; } @@ -87,7 +87,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadRomFS(std::vector& buffer) { + virtual ResultStatus ReadRomFS(std::vector& buffer) const { return ResultStatus::ErrorNotImplemented; } }; diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 0e3f768ce..a82338904 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -113,15 +113,13 @@ AppLoader_NCCH::AppLoader_NCCH(const std::string& filename) { /// AppLoader_NCCH destructor AppLoader_NCCH::~AppLoader_NCCH() { - if (file.IsOpen()) - file.Close(); } /** * Loads .code section into memory for booting * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::LoadExec() { +ResultStatus AppLoader_NCCH::LoadExec() const { if (!is_loaded) return ResultStatus::ErrorNotLoaded; @@ -140,41 +138,48 @@ ResultStatus AppLoader_NCCH::LoadExec() { * @param buffer Vector to read data into * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector& buffer) { +ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector& buffer) const { // Iterate through the ExeFs archive until we find the .code file... - for (int i = 0; i < kMaxSections; i++) { - // Load the specified section... - if (strcmp((const char*)exefs_header.section[i].name, name) == 0) { - INFO_LOG(LOADER, "ExeFS section %d:", i); - INFO_LOG(LOADER, " name: %s", exefs_header.section[i].name); - INFO_LOG(LOADER, " offset: 0x%08X", exefs_header.section[i].offset); - INFO_LOG(LOADER, " size: 0x%08X", exefs_header.section[i].size); - - s64 section_offset = (exefs_header.section[i].offset + exefs_offset + - sizeof(ExeFs_Header) + ncch_offset); - file.Seek(section_offset, 0); - - // Section is compressed... - if (i == 0 && is_compressed) { - // Read compressed .code section... - std::unique_ptr temp_buffer(new u8[exefs_header.section[i].size]); - file.ReadBytes(&temp_buffer[0], exefs_header.section[i].size); - - // Decompress .code section... - u32 decompressed_size = LZSS_GetDecompressedSize(&temp_buffer[0], - exefs_header.section[i].size); - buffer.resize(decompressed_size); - if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0], - decompressed_size)) { - return ResultStatus::ErrorInvalidFormat; + File::IOFile file(filename, "rb"); + if (file.IsOpen()) { + for (int i = 0; i < kMaxSections; i++) { + // Load the specified section... + if (strcmp((const char*)exefs_header.section[i].name, name) == 0) { + INFO_LOG(LOADER, "ExeFS section %d:", i); + INFO_LOG(LOADER, " name: %s", exefs_header.section[i].name); + INFO_LOG(LOADER, " offset: 0x%08X", exefs_header.section[i].offset); + INFO_LOG(LOADER, " size: 0x%08X", exefs_header.section[i].size); + + s64 section_offset = (exefs_header.section[i].offset + exefs_offset + + sizeof(ExeFs_Header)+ncch_offset); + file.Seek(section_offset, 0); + + // Section is compressed... + if (i == 0 && is_compressed) { + // Read compressed .code section... + std::unique_ptr temp_buffer(new u8[exefs_header.section[i].size]); + file.ReadBytes(&temp_buffer[0], exefs_header.section[i].size); + + // Decompress .code section... + u32 decompressed_size = LZSS_GetDecompressedSize(&temp_buffer[0], + exefs_header.section[i].size); + buffer.resize(decompressed_size); + if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0], + decompressed_size)) { + return ResultStatus::ErrorInvalidFormat; + } + // Section is uncompressed... } - // Section is uncompressed... - } else { - buffer.resize(exefs_header.section[i].size); - file.ReadBytes(&buffer[0], exefs_header.section[i].size); + else { + buffer.resize(exefs_header.section[i].size); + file.ReadBytes(&buffer[0], exefs_header.section[i].size); + } + return ResultStatus::Success; } - return ResultStatus::Success; } + } else { + ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str()); + return ResultStatus::Error; } return ResultStatus::ErrorNotUsed; } @@ -191,8 +196,7 @@ ResultStatus AppLoader_NCCH::Load() { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; - file = File::IOFile(filename, "rb"); - + File::IOFile file(filename, "rb"); if (file.IsOpen()) { file.ReadBytes(&ncch_header, sizeof(NCCH_Header)); @@ -235,6 +239,8 @@ ResultStatus AppLoader_NCCH::Load() { LoadExec(); // Load the executable into memory for booting return ResultStatus::Success; + } else { + ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str()); } return ResultStatus::Error; } @@ -244,7 +250,7 @@ ResultStatus AppLoader_NCCH::Load() { * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::ReadCode(std::vector& buffer) { +ResultStatus AppLoader_NCCH::ReadCode(std::vector& buffer) const { return LoadSectionExeFS(".code", buffer); } @@ -253,7 +259,7 @@ ResultStatus AppLoader_NCCH::ReadCode(std::vector& buffer) { * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::ReadIcon(std::vector& buffer) { +ResultStatus AppLoader_NCCH::ReadIcon(std::vector& buffer) const { return LoadSectionExeFS("icon", buffer); } @@ -262,7 +268,7 @@ ResultStatus AppLoader_NCCH::ReadIcon(std::vector& buffer) { * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::ReadBanner(std::vector& buffer) { +ResultStatus AppLoader_NCCH::ReadBanner(std::vector& buffer) const { return LoadSectionExeFS("banner", buffer); } @@ -271,7 +277,7 @@ ResultStatus AppLoader_NCCH::ReadBanner(std::vector& buffer) { * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::ReadLogo(std::vector& buffer) { +ResultStatus AppLoader_NCCH::ReadLogo(std::vector& buffer) const { return LoadSectionExeFS("logo", buffer); } @@ -280,24 +286,30 @@ ResultStatus AppLoader_NCCH::ReadLogo(std::vector& buffer) { * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ -ResultStatus AppLoader_NCCH::ReadRomFS(std::vector& buffer) { - // Check if the NCCH has a RomFS... - if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) { - u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; - u32 romfs_size = (ncch_header.romfs_size * kBlockSize) - 0x1000; +ResultStatus AppLoader_NCCH::ReadRomFS(std::vector& buffer) const { + File::IOFile file(filename, "rb"); + if (file.IsOpen()) { + // Check if the NCCH has a RomFS... + if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) { + u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; + u32 romfs_size = (ncch_header.romfs_size * kBlockSize) - 0x1000; - INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset); - INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size); + INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset); + INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size); - buffer.resize(romfs_size); + buffer.resize(romfs_size); - file.Seek(romfs_offset, 0); - file.ReadBytes(&buffer[0], romfs_size); + file.Seek(romfs_offset, 0); + file.ReadBytes(&buffer[0], romfs_size); - return ResultStatus::Success; + return ResultStatus::Success; + } + NOTICE_LOG(LOADER, "RomFS unused"); + return ResultStatus::ErrorNotUsed; + } else { + ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str()); } - NOTICE_LOG(LOADER, "RomFS unused"); - return ResultStatus::ErrorNotUsed; + return ResultStatus::Error; } } // namespace Loader diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 99753b244..c9a35228e 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -161,35 +161,35 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadCode(std::vector& buffer); + ResultStatus ReadCode(std::vector& buffer) const; /** * Get the icon (typically icon section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadIcon(std::vector& buffer); + ResultStatus ReadIcon(std::vector& buffer) const; /** * Get the banner (typically banner section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadBanner(std::vector& buffer); + ResultStatus ReadBanner(std::vector& buffer) const; /** * Get the logo (typically logo section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadLogo(std::vector& buffer); + ResultStatus ReadLogo(std::vector& buffer) const; /** * Get the RomFS of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadRomFS(std::vector& buffer); + ResultStatus ReadRomFS(std::vector& buffer) const; private: @@ -199,15 +199,14 @@ private: * @param buffer Vector to read data into * @return ResultStatus result of function */ - ResultStatus LoadSectionExeFS(const char* name, std::vector& buffer); + ResultStatus LoadSectionExeFS(const char* name, std::vector& buffer) const; /** * Loads .code section into memory for booting * @return ResultStatus result of function */ - ResultStatus LoadExec(); + ResultStatus LoadExec() const; - File::IOFile file; std::string filename; bool is_loaded; -- cgit v1.2.3 From 2d734bb6c5cf1a428f8ce2a6d13955ee4ff872eb Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Jul 2014 13:20:40 -0400 Subject: Marked AppLoader_ELF, AppLoader_NCCH, and Archive_RomFS classes as "final" --- src/core/loader/elf.h | 2 +- src/core/loader/ncch.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index d3cbf414d..cec1167ca 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -13,7 +13,7 @@ namespace Loader { /// Loads an ELF/AXF file -class AppLoader_ELF : public AppLoader { +class AppLoader_ELF final : public AppLoader { public: AppLoader_ELF(const std::string& filename); ~AppLoader_ELF(); diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index c9a35228e..de89280ea 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -145,7 +145,7 @@ struct ExHeader_Header{ namespace Loader { /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) -class AppLoader_NCCH : public AppLoader { +class AppLoader_NCCH final : public AppLoader { public: AppLoader_NCCH(const std::string& filename); ~AppLoader_NCCH(); -- cgit v1.2.3 From 1099d83455153f9d81b10b54a788bc9fe91f33e9 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Jul 2014 13:25:30 -0400 Subject: Marked AppLoader_ELF, AppLoader_NCCH, and Archive_RomFS virtual functions as "override". --- src/core/loader/elf.h | 4 ++-- src/core/loader/ncch.h | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index cec1167ca..5ae88439a 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -16,13 +16,13 @@ namespace Loader { class AppLoader_ELF final : public AppLoader { public: AppLoader_ELF(const std::string& filename); - ~AppLoader_ELF(); + ~AppLoader_ELF() override; /** * Load the bootable file * @return ResultStatus result of function */ - ResultStatus Load(); + ResultStatus Load() override; private: std::string filename; diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index de89280ea..29b59aa11 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -148,48 +148,48 @@ namespace Loader { class AppLoader_NCCH final : public AppLoader { public: AppLoader_NCCH(const std::string& filename); - ~AppLoader_NCCH(); + ~AppLoader_NCCH() override; /** * Load the application * @return ResultStatus result of function */ - ResultStatus Load(); + ResultStatus Load() override; /** * Get the code (typically .code section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadCode(std::vector& buffer) const; + ResultStatus ReadCode(std::vector& buffer) const override; /** * Get the icon (typically icon section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadIcon(std::vector& buffer) const; + ResultStatus ReadIcon(std::vector& buffer) const override; /** * Get the banner (typically banner section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadBanner(std::vector& buffer) const; + ResultStatus ReadBanner(std::vector& buffer) const override; /** * Get the logo (typically logo section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadLogo(std::vector& buffer) const; + ResultStatus ReadLogo(std::vector& buffer) const override; /** * Get the RomFS of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadRomFS(std::vector& buffer) const; + ResultStatus ReadRomFS(std::vector& buffer) const override; private: -- cgit v1.2.3 From b70c4fb48ec32057e56d9c0373794670bddd4f34 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Jul 2014 20:32:06 -0400 Subject: NCCH: Updated ExeFS memory allocation to be safer. --- src/core/loader/loader.h | 1 + src/core/loader/ncch.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index c27b5b4b6..4ba10de52 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -32,6 +32,7 @@ enum class ResultStatus { ErrorNotLoaded, ErrorNotUsed, ErrorAlreadyLoaded, + ErrorMemoryAllocationFailed, }; /// Interface for loading an application diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index a82338904..ba27eb75a 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -157,7 +157,12 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector& // Section is compressed... if (i == 0 && is_compressed) { // Read compressed .code section... - std::unique_ptr temp_buffer(new u8[exefs_header.section[i].size]); + std::unique_ptr temp_buffer; + try { + temp_buffer.reset(new u8[exefs_header.section[i].size]); + } catch (std::bad_alloc&) { + return ResultStatus::ErrorMemoryAllocationFailed; + } file.ReadBytes(&temp_buffer[0], exefs_header.section[i].size); // Decompress .code section... -- cgit v1.2.3