Browse Source

Loader: Refactored interface such that data is no longer stored by loader.

NCCH: Removed extra qualification ‘Loader::AppLoader_NCCH::’.
pull/15/merge
bunnei 12 years ago
parent
commit
d8da707bb9
  1. 54
      src/core/loader/loader.h
  2. 77
      src/core/loader/ncch.cpp
  3. 38
      src/core/loader/ncch.h

54
src/core/loader/loader.h

@ -48,60 +48,48 @@ public:
/** /**
* Get the code (typically .code section) of the application * 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<u8>& ReadCode(ResultStatus& error) const {
error = ResultStatus::ErrorNotImplemented;
return code;
virtual ResultStatus ReadCode(std::vector<u8>& buffer) {
return ResultStatus::ErrorNotImplemented;
} }
/** /**
* Get the icon (typically icon section) of the application * 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<u8>& ReadIcon(ResultStatus& error) const {
error = ResultStatus::ErrorNotImplemented;
return icon;
virtual ResultStatus ReadIcon(std::vector<u8>& buffer) {
return ResultStatus::ErrorNotImplemented;
} }
/** /**
* Get the banner (typically banner section) of the application * 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<u8>& ReadBanner(ResultStatus& error) const {
error = ResultStatus::ErrorNotImplemented;
return banner;
virtual ResultStatus ReadBanner(std::vector<u8>& buffer) {
return ResultStatus::ErrorNotImplemented;
} }
/** /**
* Get the logo (typically logo section) of the application * 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<u8>& ReadLogo(ResultStatus& error) const {
error = ResultStatus::ErrorNotImplemented;
return logo;
virtual ResultStatus ReadLogo(std::vector<u8>& 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<u8>& ReadRomFS(ResultStatus& error) const {
error = ResultStatus::ErrorNotImplemented;
return romfs;
virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) {
return ResultStatus::ErrorNotImplemented;
} }
protected:
std::vector<u8> code; ///< ExeFS .code section
std::vector<u8> icon; ///< ExeFS .icon section
std::vector<u8> banner; ///< ExeFS .banner section
std::vector<u8> logo; ///< ExeFS .logo section
std::vector<u8> romfs; ///< RomFs archive
}; };
/** /**

77
src/core/loader/ncch.cpp

@ -125,25 +125,22 @@ ResultStatus AppLoader_NCCH::LoadExec() {
if (!is_loaded) if (!is_loaded)
return ResultStatus::ErrorNotLoaded; return ResultStatus::ErrorNotLoaded;
ResultStatus res;
code = ReadCode(res);
if (ResultStatus::Success == res) {
std::vector<u8> code;
if (ResultStatus::Success == ReadCode(code)) {
Memory::WriteBlock(entry_point, &code[0], code.size()); Memory::WriteBlock(entry_point, &code[0], code.size());
Kernel::LoadExec(entry_point); 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.) * 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 name Name of section to read out of NCCH file
* @param buffer Vector to read data into * @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<u8>& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer,
ResultStatus& error) {
ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) {
// Iterate through the ExeFs archive until we find the .code file... // Iterate through the ExeFs archive until we find the .code file...
for (int i = 0; i < kMaxSections; i++) { for (int i = 0; i < kMaxSections; i++) {
// Load the specified section... // Load the specified section...
@ -169,20 +166,17 @@ const std::vector<u8>& AppLoader_NCCH::LoadSectionExeFS(const char* name, std::v
buffer.resize(decompressed_size); buffer.resize(decompressed_size);
if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0], if (!LZSS_Decompress(&temp_buffer[0], exefs_header.section[i].size, &buffer[0],
decompressed_size)) { decompressed_size)) {
error = ResultStatus::ErrorInvalidFormat;
return buffer;
return ResultStatus::ErrorInvalidFormat;
} }
// Section is uncompressed... // Section is uncompressed...
} else { } else {
buffer.resize(exefs_header.section[i].size); buffer.resize(exefs_header.section[i].size);
file.ReadBytes(&buffer[0], 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 * 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<u8>& AppLoader_NCCH::ReadCode(ResultStatus& error) {
return LoadSectionExeFS(".code", code, error);
ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) {
return LoadSectionExeFS(".code", buffer);
} }
/** /**
* Get the icon (typically icon section) of the application * 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<u8>& AppLoader_NCCH::ReadIcon(ResultStatus& error) {
return LoadSectionExeFS("icon", icon, error);
ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) {
return LoadSectionExeFS("icon", buffer);
} }
/** /**
* Get the banner (typically banner section) of the application * 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<u8>& AppLoader_NCCH::ReadBanner(ResultStatus& error) {
return LoadSectionExeFS("banner", banner, error);
ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) {
return LoadSectionExeFS("banner", buffer);
} }
/** /**
* Get the logo (typically logo section) of the application * 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<u8>& AppLoader_NCCH::ReadLogo(ResultStatus& error) {
return LoadSectionExeFS("logo", logo, error);
ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& 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<u8>& AppLoader_NCCH::ReadRomFS(ResultStatus& error) {
ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) {
// Check if the NCCH has a RomFS... // Check if the NCCH has a RomFS...
if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) { if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) {
u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000;
@ -295,18 +289,15 @@ const std::vector<u8>& AppLoader_NCCH::ReadRomFS(ResultStatus& error) {
INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset); INFO_LOG(LOADER, "RomFS offset: 0x%08X", romfs_offset);
INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size); INFO_LOG(LOADER, "RomFS size: 0x%08X", romfs_size);
romfs.resize(romfs_size);
buffer.resize(romfs_size);
file.Seek(romfs_offset, 0); 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 } // namespace Loader

38
src/core/loader/ncch.h

@ -158,38 +158,38 @@ public:
/** /**
* Get the code (typically .code section) of the application * 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<u8>& ReadCode(ResultStatus& error);
ResultStatus ReadCode(std::vector<u8>& buffer);
/** /**
* Get the icon (typically icon section) of the application * 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<u8>& ReadIcon(ResultStatus& error);
ResultStatus ReadIcon(std::vector<u8>& buffer);
/** /**
* Get the banner (typically banner section) of the application * 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<u8>& ReadBanner(ResultStatus& error);
ResultStatus ReadBanner(std::vector<u8>& buffer);
/** /**
* Get the logo (typically logo section) of the application * 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<u8>& ReadLogo(ResultStatus& error);
ResultStatus ReadLogo(std::vector<u8>& 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<u8>& ReadRomFS(ResultStatus& error);
ResultStatus ReadRomFS(std::vector<u8>& buffer);
private: private:
@ -197,11 +197,9 @@ private:
* Reads an application ExeFS section of an NCCH file into AppLoader (e.g. .code, .logo, etc.) * 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 name Name of section to read out of NCCH file
* @param buffer Vector to read data into * @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<u8>& LoadSectionExeFS(const char* name, std::vector<u8>& buffer,
ResultStatus& error);
ResultStatus LoadSectionExeFS(const char* name, std::vector<u8>& buffer);
/** /**
* Loads .code section into memory for booting * Loads .code section into memory for booting

Loading…
Cancel
Save