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) { | |||
| 124 | case FileType::CXI: | 124 | case FileType::CXI: |
| 125 | case FileType::CCI: | 125 | case FileType::CCI: |
| 126 | { | 126 | { |
| 127 | AppLoader_NCCH app_loader(std::move(file)); | 127 | AppLoader_NCCH app_loader(std::move(file), filename); |
| 128 | 128 | ||
| 129 | // Load application and RomFS | 129 | // Load application and RomFS |
| 130 | if (ResultStatus::Success == app_loader.Load()) { | 130 | 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: | |||
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | * Get the RomFS of the application | 101 | * Get the RomFS of the application |
| 102 | * @param buffer Reference to buffer to store data | 102 | * Since the RomFS can be huge, we return a file reference instead of copying to a buffer |
| 103 | * @param romfs_file The file containing the RomFS | ||
| 104 | * @param offset The offset the romfs begins on | ||
| 105 | * @param size The size of the romfs | ||
| 103 | * @return ResultStatus result of function | 106 | * @return ResultStatus result of function |
| 104 | */ | 107 | */ |
| 105 | virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const { | 108 | virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const { |
| 106 | return ResultStatus::ErrorNotImplemented; | 109 | return ResultStatus::ErrorNotImplemented; |
| 107 | } | 110 | } |
| 108 | 111 | ||
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 { | |||
| 299 | return LoadSectionExeFS("logo", buffer); | 299 | return LoadSectionExeFS("logo", buffer); |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { | 302 | ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const { |
| 303 | if (!file->IsOpen()) | 303 | if (!file->IsOpen()) |
| 304 | return ResultStatus::Error; | 304 | return ResultStatus::Error; |
| 305 | 305 | ||
| @@ -311,12 +311,17 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { | |||
| 311 | LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); | 311 | LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); |
| 312 | LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); | 312 | LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); |
| 313 | 313 | ||
| 314 | buffer.resize(romfs_size); | 314 | if (file->GetSize () < romfs_offset + romfs_size) |
| 315 | return ResultStatus::Error; | ||
| 315 | 316 | ||
| 316 | file->Seek(romfs_offset, SEEK_SET); | 317 | // We reopen the file, to allow its position to be independent from file's |
| 317 | if (file->ReadBytes(&buffer[0], romfs_size) != romfs_size) | 318 | romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb"); |
| 319 | if (!romfs_file->IsOpen()) | ||
| 318 | return ResultStatus::Error; | 320 | return ResultStatus::Error; |
| 319 | 321 | ||
| 322 | offset = romfs_offset; | ||
| 323 | size = romfs_size; | ||
| 324 | |||
| 320 | return ResultStatus::Success; | 325 | return ResultStatus::Success; |
| 321 | } | 326 | } |
| 322 | LOG_DEBUG(Loader, "NCCH has no RomFS"); | 327 | 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 { | |||
| 163 | /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) | 163 | /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) |
| 164 | class AppLoader_NCCH final : public AppLoader { | 164 | class AppLoader_NCCH final : public AppLoader { |
| 165 | public: | 165 | public: |
| 166 | AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { } | 166 | AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, const std::string& filepath) |
| 167 | : AppLoader(std::move(file)), filepath(filepath) { } | ||
| 167 | 168 | ||
| 168 | /** | 169 | /** |
| 169 | * Returns the type of the file | 170 | * Returns the type of the file |
| @@ -211,7 +212,7 @@ public: | |||
| 211 | * @param buffer Reference to buffer to store data | 212 | * @param buffer Reference to buffer to store data |
| 212 | * @return ResultStatus result of function | 213 | * @return ResultStatus result of function |
| 213 | */ | 214 | */ |
| 214 | ResultStatus ReadRomFS(std::vector<u8>& buffer) const override; | 215 | ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const override; |
| 215 | 216 | ||
| 216 | private: | 217 | private: |
| 217 | 218 | ||
| @@ -244,6 +245,8 @@ private: | |||
| 244 | NCCH_Header ncch_header; | 245 | NCCH_Header ncch_header; |
| 245 | ExeFs_Header exefs_header; | 246 | ExeFs_Header exefs_header; |
| 246 | ExHeader_Header exheader_header; | 247 | ExHeader_Header exheader_header; |
| 248 | |||
| 249 | std::string filepath; | ||
| 247 | }; | 250 | }; |
| 248 | 251 | ||
| 249 | } // namespace Loader | 252 | } // namespace Loader |