diff options
Diffstat (limited to 'src/core/loader')
-rw-r--r-- | src/core/loader/loader.cpp | 2 | ||||
-rw-r--r-- | src/core/loader/loader.h | 7 | ||||
-rw-r--r-- | src/core/loader/ncch.cpp | 13 | ||||
-rw-r--r-- | src/core/loader/ncch.h | 7 |
4 files changed, 20 insertions, 9 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 2e450fce4..b6549daf2 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -124,7 +124,7 @@ ResultStatus LoadFile(const std::string& filename) { case FileType::CXI: case FileType::CCI: { - AppLoader_NCCH app_loader(std::move(file)); + AppLoader_NCCH app_loader(std::move(file), filename); // Load application and RomFS if (ResultStatus::Success == app_loader.Load()) { diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 52bbf35b8..ff298222b 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -99,10 +99,13 @@ public: /** * Get the RomFS of the application - * @param buffer Reference to buffer to store data + * Since the RomFS can be huge, we return a file reference instead of copying to a buffer + * @param romfs_file The file containing the RomFS + * @param offset The offset the romfs begins on + * @param size The size of the romfs * @return ResultStatus result of function */ - virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const { + virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const { return ResultStatus::ErrorNotImplemented; } diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 87603d198..2bf1a6a26 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -299,7 +299,7 @@ ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const { return LoadSectionExeFS("logo", buffer); } -ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { +ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const { if (!file->IsOpen()) return ResultStatus::Error; @@ -311,12 +311,17 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); - buffer.resize(romfs_size); + if (file->GetSize () < romfs_offset + romfs_size) + return ResultStatus::Error; - file->Seek(romfs_offset, SEEK_SET); - if (file->ReadBytes(&buffer[0], romfs_size) != romfs_size) + // We reopen the file, to allow its position to be independent from file's + romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb"); + if (!romfs_file->IsOpen()) return ResultStatus::Error; + offset = romfs_offset; + size = romfs_size; + return ResultStatus::Success; } LOG_DEBUG(Loader, "NCCH has no RomFS"); diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 29e39d2c0..d180e77ed 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -163,7 +163,8 @@ namespace Loader { /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) class AppLoader_NCCH final : public AppLoader { public: - AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { } + AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, const std::string& filepath) + : AppLoader(std::move(file)), filepath(filepath) { } /** * Returns the type of the file @@ -211,7 +212,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadRomFS(std::vector<u8>& buffer) const override; + ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const override; private: @@ -244,6 +245,8 @@ private: NCCH_Header ncch_header; ExeFs_Header exefs_header; ExHeader_Header exheader_header; + + std::string filepath; }; } // namespace Loader |