aboutsummaryrefslogtreecommitdiff
path: root/src/core/loader/ncch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader/ncch.cpp')
-rw-r--r--src/core/loader/ncch.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 1e5501e6d..4d23656ec 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -24,7 +24,7 @@ static const int kBlockSize = 0x200; ///< Size of ExeFS blocks (in bytes)
* @param size Size of compressed buffer
* @return Size of decompressed buffer
*/
-u32 LZSS_GetDecompressedSize(u8* buffer, u32 size) {
+static u32 LZSS_GetDecompressedSize(u8* buffer, u32 size) {
u32 offset_size = *(u32*)(buffer + size - 4);
return offset_size + size;
}
@@ -37,7 +37,7 @@ u32 LZSS_GetDecompressedSize(u8* buffer, u32 size) {
* @param decompressed_size Size of decompressed buffer
* @return True on success, otherwise false
*/
-bool LZSS_Decompress(u8* compressed, u32 compressed_size, u8* decompressed, u32 decompressed_size) {
+static bool LZSS_Decompress(u8* compressed, u32 compressed_size, u8* decompressed, u32 decompressed_size) {
u8* footer = compressed + compressed_size - 8;
u32 buffer_top_and_bottom = *(u32*)footer;
u32 out = decompressed_size;
@@ -118,7 +118,7 @@ AppLoader_NCCH::~AppLoader_NCCH() {
* @return ResultStatus result of function
*/
ResultStatus AppLoader_NCCH::LoadExec() const {
- if (!is_loaded)
+ if (!is_loaded)
return ResultStatus::ErrorNotLoaded;
std::vector<u8> code;
@@ -140,13 +140,13 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
// Iterate through the ExeFs archive until we find the .code file...
FileUtil::IOFile file(filename, "rb");
if (file.IsOpen()) {
+ LOG_DEBUG(Loader, "%d sections:", kMaxSections);
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);
+ LOG_DEBUG(Loader, "%d - offset: 0x%08X, size: 0x%08X, name: %s", i,
+ exefs_header.section[i].offset, exefs_header.section[i].size,
+ exefs_header.section[i].name);
s64 section_offset = (exefs_header.section[i].offset + exefs_offset +
sizeof(ExeFs_Header)+ncch_offset);
@@ -181,11 +181,11 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
}
}
} else {
- ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str());
+ LOG_ERROR(Loader, "Unable to read file %s!", filename.c_str());
return ResultStatus::Error;
}
return ResultStatus::ErrorNotUsed;
-}
+}
/**
* Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
@@ -194,7 +194,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
* @return True on success, otherwise false
*/
ResultStatus AppLoader_NCCH::Load() {
- INFO_LOG(LOADER, "Loading NCCH file %s...", filename.c_str());
+ LOG_INFO(Loader, "Loading NCCH file %s...", filename.c_str());
if (is_loaded)
return ResultStatus::ErrorAlreadyLoaded;
@@ -205,12 +205,12 @@ ResultStatus AppLoader_NCCH::Load() {
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
if (0 == memcmp(&ncch_header.magic, "NCSD", 4)) {
- WARN_LOG(LOADER, "Only loading the first (bootable) NCCH within the NCSD file!");
+ LOG_WARNING(Loader, "Only loading the first (bootable) NCCH within the NCSD file!");
ncch_offset = 0x4000;
file.Seek(ncch_offset, 0);
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
}
-
+
// Verify we are loading the correct file type...
if (0 != memcmp(&ncch_header.magic, "NCCH", 4))
return ResultStatus::ErrorInvalidFormat;
@@ -222,17 +222,17 @@ ResultStatus AppLoader_NCCH::Load() {
is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1;
entry_point = exheader_header.codeset_info.text.address;
- INFO_LOG(LOADER, "Name: %s", exheader_header.codeset_info.name);
- INFO_LOG(LOADER, "Code compressed: %s", is_compressed ? "yes" : "no");
- INFO_LOG(LOADER, "Entry point: 0x%08X", entry_point);
+ LOG_INFO(Loader, "Name: %s", exheader_header.codeset_info.name);
+ LOG_DEBUG(Loader, "Code compressed: %s", is_compressed ? "yes" : "no");
+ LOG_DEBUG(Loader, "Entry point: 0x%08X", entry_point);
// Read ExeFS...
exefs_offset = ncch_header.exefs_offset * kBlockSize;
u32 exefs_size = ncch_header.exefs_size * kBlockSize;
- INFO_LOG(LOADER, "ExeFS offset: 0x%08X", exefs_offset);
- INFO_LOG(LOADER, "ExeFS size: 0x%08X", exefs_size);
+ LOG_DEBUG(Loader, "ExeFS offset: 0x%08X", exefs_offset);
+ LOG_DEBUG(Loader, "ExeFS size: 0x%08X", exefs_size);
file.Seek(exefs_offset + ncch_offset, 0);
file.ReadBytes(&exefs_header, sizeof(ExeFs_Header));
@@ -243,7 +243,7 @@ ResultStatus AppLoader_NCCH::Load() {
return ResultStatus::Success;
} else {
- ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str());
+ LOG_ERROR(Loader, "Unable to read file %s!", filename.c_str());
}
return ResultStatus::Error;
}
@@ -297,8 +297,8 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
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);
+ LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
+ LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
buffer.resize(romfs_size);
@@ -307,12 +307,16 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
return ResultStatus::Success;
}
- NOTICE_LOG(LOADER, "RomFS unused");
+ LOG_DEBUG(Loader, "NCCH has no RomFS");
return ResultStatus::ErrorNotUsed;
} else {
- ERROR_LOG(LOADER, "Unable to read file %s!", filename.c_str());
+ LOG_ERROR(Loader, "Unable to read file %s!", filename.c_str());
}
return ResultStatus::Error;
}
+u64 AppLoader_NCCH::GetProgramId() const {
+ return *reinterpret_cast<u64 const*>(&ncch_header.program_id[0]);
+}
+
} // namespace Loader