diff options
| author | 2021-04-27 12:05:34 -0400 | |
|---|---|---|
| committer | 2021-04-27 12:48:15 -0400 | |
| commit | 724c19a307f31ce1122fb8047c86d5a126d0860f (patch) | |
| tree | 605b89f42d7897aac46f06add54c34201d9354bd /src | |
| parent | Merge pull request #6246 from lioncash/shadow (diff) | |
| download | yuzu-724c19a307f31ce1122fb8047c86d5a126d0860f.tar.gz yuzu-724c19a307f31ce1122fb8047c86d5a126d0860f.tar.xz yuzu-724c19a307f31ce1122fb8047c86d5a126d0860f.zip | |
loader: Resolve instances of variable shadowing
Eliminates variable shadowing cases across all the loaders to bring us
closer to enabling variable shadowing as an error in core.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 40 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 6 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 13 | ||||
| -rw-r--r-- | src/core/loader/elf.h | 10 | ||||
| -rw-r--r-- | src/core/loader/kip.cpp | 12 | ||||
| -rw-r--r-- | src/core/loader/kip.h | 10 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 57 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 11 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 12 | ||||
| -rw-r--r-- | src/core/loader/nca.cpp | 39 | ||||
| -rw-r--r-- | src/core/loader/nca.h | 12 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 13 | ||||
| -rw-r--r-- | src/core/loader/nro.h | 14 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 22 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 16 | ||||
| -rw-r--r-- | src/core/loader/nsp.cpp | 53 | ||||
| -rw-r--r-- | src/core/loader/nsp.h | 18 | ||||
| -rw-r--r-- | src/core/loader/xci.cpp | 50 | ||||
| -rw-r--r-- | src/core/loader/xci.h | 18 |
19 files changed, 257 insertions, 169 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 4a10211f6..ed776fc49 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -24,10 +24,10 @@ namespace Loader { | |||
| 24 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file_, | 24 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file_, |
| 25 | bool override_update) | 25 | bool override_update) |
| 26 | : AppLoader(std::move(file_)), override_update(override_update) { | 26 | : AppLoader(std::move(file_)), override_update(override_update) { |
| 27 | const auto dir = file->GetContainingDirectory(); | 27 | const auto file_dir = file->GetContainingDirectory(); |
| 28 | 28 | ||
| 29 | // Title ID | 29 | // Title ID |
| 30 | const auto npdm = dir->GetFile("main.npdm"); | 30 | const auto npdm = file_dir->GetFile("main.npdm"); |
| 31 | if (npdm != nullptr) { | 31 | if (npdm != nullptr) { |
| 32 | const auto res = metadata.Load(npdm); | 32 | const auto res = metadata.Load(npdm); |
| 33 | if (res == ResultStatus::Success) | 33 | if (res == ResultStatus::Success) |
| @@ -37,7 +37,7 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys | |||
| 37 | // Icon | 37 | // Icon |
| 38 | FileSys::VirtualFile icon_file = nullptr; | 38 | FileSys::VirtualFile icon_file = nullptr; |
| 39 | for (const auto& language : FileSys::LANGUAGE_NAMES) { | 39 | for (const auto& language : FileSys::LANGUAGE_NAMES) { |
| 40 | icon_file = dir->GetFile("icon_" + std::string(language) + ".dat"); | 40 | icon_file = file_dir->GetFile("icon_" + std::string(language) + ".dat"); |
| 41 | if (icon_file != nullptr) { | 41 | if (icon_file != nullptr) { |
| 42 | icon_data = icon_file->ReadAllBytes(); | 42 | icon_data = icon_file->ReadAllBytes(); |
| 43 | break; | 43 | break; |
| @@ -46,7 +46,7 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys | |||
| 46 | 46 | ||
| 47 | if (icon_data.empty()) { | 47 | if (icon_data.empty()) { |
| 48 | // Any png, jpeg, or bmp file | 48 | // Any png, jpeg, or bmp file |
| 49 | const auto& files = dir->GetFiles(); | 49 | const auto& files = file_dir->GetFiles(); |
| 50 | const auto icon_iter = | 50 | const auto icon_iter = |
| 51 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { | 51 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { |
| 52 | return file->GetExtension() == "png" || file->GetExtension() == "jpg" || | 52 | return file->GetExtension() == "png" || file->GetExtension() == "jpg" || |
| @@ -57,9 +57,9 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys | |||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | // Metadata | 59 | // Metadata |
| 60 | FileSys::VirtualFile nacp_file = dir->GetFile("control.nacp"); | 60 | FileSys::VirtualFile nacp_file = file_dir->GetFile("control.nacp"); |
| 61 | if (nacp_file == nullptr) { | 61 | if (nacp_file == nullptr) { |
| 62 | const auto& files = dir->GetFiles(); | 62 | const auto& files = file_dir->GetFiles(); |
| 63 | const auto nacp_iter = | 63 | const auto nacp_iter = |
| 64 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { | 64 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { |
| 65 | return file->GetExtension() == "nacp"; | 65 | return file->GetExtension() == "nacp"; |
| @@ -200,17 +200,21 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect | |||
| 200 | LoadParameters{metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()}}; | 200 | LoadParameters{metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()}}; |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& dir) { | 203 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& out_dir) { |
| 204 | if (romfs == nullptr) | 204 | if (romfs == nullptr) { |
| 205 | return ResultStatus::ErrorNoRomFS; | 205 | return ResultStatus::ErrorNoRomFS; |
| 206 | dir = romfs; | 206 | } |
| 207 | |||
| 208 | out_dir = romfs; | ||
| 207 | return ResultStatus::Success; | 209 | return ResultStatus::Success; |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 210 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& buffer) { | 212 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& out_buffer) { |
| 211 | if (icon_data.empty()) | 213 | if (icon_data.empty()) { |
| 212 | return ResultStatus::ErrorNoIcon; | 214 | return ResultStatus::ErrorNoIcon; |
| 213 | buffer = icon_data; | 215 | } |
| 216 | |||
| 217 | out_buffer = icon_data; | ||
| 214 | return ResultStatus::Success; | 218 | return ResultStatus::Success; |
| 215 | } | 219 | } |
| 216 | 220 | ||
| @@ -219,10 +223,12 @@ ResultStatus AppLoader_DeconstructedRomDirectory::ReadProgramId(u64& out_program | |||
| 219 | return ResultStatus::Success; | 223 | return ResultStatus::Success; |
| 220 | } | 224 | } |
| 221 | 225 | ||
| 222 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& title) { | 226 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& out_title) { |
| 223 | if (name.empty()) | 227 | if (name.empty()) { |
| 224 | return ResultStatus::ErrorNoControl; | 228 | return ResultStatus::ErrorNoControl; |
| 225 | title = name; | 229 | } |
| 230 | |||
| 231 | out_title = name; | ||
| 226 | return ResultStatus::Success; | 232 | return ResultStatus::Success; |
| 227 | } | 233 | } |
| 228 | 234 | ||
| @@ -230,12 +236,12 @@ bool AppLoader_DeconstructedRomDirectory::IsRomFSUpdatable() const { | |||
| 230 | return false; | 236 | return false; |
| 231 | } | 237 | } |
| 232 | 238 | ||
| 233 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadNSOModules(Modules& modules) { | 239 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadNSOModules(Modules& out_modules) { |
| 234 | if (!is_loaded) { | 240 | if (!is_loaded) { |
| 235 | return ResultStatus::ErrorNotInitialized; | 241 | return ResultStatus::ErrorNotInitialized; |
| 236 | } | 242 | } |
| 237 | 243 | ||
| 238 | modules = this->modules; | 244 | out_modules = this->modules; |
| 239 | return ResultStatus::Success; | 245 | return ResultStatus::Success; |
| 240 | } | 246 | } |
| 241 | 247 | ||
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 3c968580f..c2b46e1bf 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -43,13 +43,13 @@ public: | |||
| 43 | 43 | ||
| 44 | LoadResult Load(Kernel::Process& process, Core::System& system) override; | 44 | LoadResult Load(Kernel::Process& process, Core::System& system) override; |
| 45 | 45 | ||
| 46 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 46 | ResultStatus ReadRomFS(FileSys::VirtualFile& out_dir) override; |
| 47 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 47 | ResultStatus ReadIcon(std::vector<u8>& out_buffer) override; |
| 48 | ResultStatus ReadProgramId(u64& out_program_id) override; | 48 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 49 | ResultStatus ReadTitle(std::string& title) override; | 49 | ResultStatus ReadTitle(std::string& title) override; |
| 50 | bool IsRomFSUpdatable() const override; | 50 | bool IsRomFSUpdatable() const override; |
| 51 | 51 | ||
| 52 | ResultStatus ReadNSOModules(Modules& modules) override; | 52 | ResultStatus ReadNSOModules(Modules& out_modules) override; |
| 53 | 53 | ||
| 54 | private: | 54 | private: |
| 55 | FileSys::ProgramMetadata metadata; | 55 | FileSys::ProgramMetadata metadata; |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index f4a339390..627c18c7e 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -364,21 +364,24 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const | |||
| 364 | 364 | ||
| 365 | namespace Loader { | 365 | namespace Loader { |
| 366 | 366 | ||
| 367 | AppLoader_ELF::AppLoader_ELF(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} | 367 | AppLoader_ELF::AppLoader_ELF(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) {} |
| 368 | 368 | ||
| 369 | FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) { | 369 | FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& elf_file) { |
| 370 | static constexpr u16 ELF_MACHINE_ARM{0x28}; | 370 | static constexpr u16 ELF_MACHINE_ARM{0x28}; |
| 371 | 371 | ||
| 372 | u32 magic = 0; | 372 | u32 magic = 0; |
| 373 | if (4 != file->ReadObject(&magic)) | 373 | if (4 != elf_file->ReadObject(&magic)) { |
| 374 | return FileType::Error; | 374 | return FileType::Error; |
| 375 | } | ||
| 375 | 376 | ||
| 376 | u16 machine = 0; | 377 | u16 machine = 0; |
| 377 | if (2 != file->ReadObject(&machine, 18)) | 378 | if (2 != elf_file->ReadObject(&machine, 18)) { |
| 378 | return FileType::Error; | 379 | return FileType::Error; |
| 380 | } | ||
| 379 | 381 | ||
| 380 | if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine) | 382 | if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine) { |
| 381 | return FileType::ELF; | 383 | return FileType::ELF; |
| 384 | } | ||
| 382 | 385 | ||
| 383 | return FileType::Error; | 386 | return FileType::Error; |
| 384 | } | 387 | } |
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 2067932c7..2b86c0b49 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h | |||
| @@ -20,11 +20,13 @@ public: | |||
| 20 | explicit AppLoader_ELF(FileSys::VirtualFile file); | 20 | explicit AppLoader_ELF(FileSys::VirtualFile file); |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * Returns the type of the file | 23 | * Identifies whether or not the given file is an ELF file. |
| 24 | * @param file open file | 24 | * |
| 25 | * @return FileType found, or FileType::Error if this loader doesn't know it | 25 | * @param elf_file The file to identify. |
| 26 | * | ||
| 27 | * @return FileType::ELF, or FileType::Error if the file is not an ELF file. | ||
| 26 | */ | 28 | */ |
| 27 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 29 | static FileType IdentifyType(const FileSys::VirtualFile& elf_file); |
| 28 | 30 | ||
| 29 | FileType GetFileType() const override { | 31 | FileType GetFileType() const override { |
| 30 | return IdentifyType(file); | 32 | return IdentifyType(file); |
diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 55e6de794..9b447da2a 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp | |||
| @@ -24,9 +24,9 @@ AppLoader_KIP::AppLoader_KIP(FileSys::VirtualFile file_) | |||
| 24 | 24 | ||
| 25 | AppLoader_KIP::~AppLoader_KIP() = default; | 25 | AppLoader_KIP::~AppLoader_KIP() = default; |
| 26 | 26 | ||
| 27 | FileType AppLoader_KIP::IdentifyType(const FileSys::VirtualFile& file) { | 27 | FileType AppLoader_KIP::IdentifyType(const FileSys::VirtualFile& in_file) { |
| 28 | u32_le magic{}; | 28 | u32_le magic{}; |
| 29 | if (file->GetSize() < sizeof(u32) || file->ReadObject(&magic) != sizeof(u32)) { | 29 | if (in_file->GetSize() < sizeof(u32) || in_file->ReadObject(&magic) != sizeof(u32)) { |
| 30 | return FileType::Error; | 30 | return FileType::Error; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| @@ -56,10 +56,10 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process, | |||
| 56 | return {kip->GetStatus(), {}}; | 56 | return {kip->GetStatus(), {}}; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | const auto get_kip_address_space_type = [](const auto& kip) { | 59 | const auto get_kip_address_space_type = [](const auto& kip_type) { |
| 60 | return kip.Is64Bit() | 60 | return kip_type.Is64Bit() |
| 61 | ? (kip.Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit | 61 | ? (kip_type.Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit |
| 62 | : FileSys::ProgramAddressSpaceType::Is36Bit) | 62 | : FileSys::ProgramAddressSpaceType::Is36Bit) |
| 63 | : FileSys::ProgramAddressSpaceType::Is32Bit; | 63 | : FileSys::ProgramAddressSpaceType::Is32Bit; |
| 64 | }; | 64 | }; |
| 65 | 65 | ||
diff --git a/src/core/loader/kip.h b/src/core/loader/kip.h index 14a85e295..2fe636f01 100644 --- a/src/core/loader/kip.h +++ b/src/core/loader/kip.h | |||
| @@ -22,11 +22,13 @@ public: | |||
| 22 | ~AppLoader_KIP() override; | 22 | ~AppLoader_KIP() override; |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * Returns the type of the file | 25 | * Identifies whether or not the given file is a KIP. |
| 26 | * @param file open file | 26 | * |
| 27 | * @return FileType found, or FileType::Error if this loader doesn't know it | 27 | * @param in_file The file to identify. |
| 28 | * | ||
| 29 | * @return FileType::KIP if found, or FileType::Error if unknown. | ||
| 28 | */ | 30 | */ |
| 29 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 31 | static FileType IdentifyType(const FileSys::VirtualFile& in_file); |
| 30 | 32 | ||
| 31 | FileType GetFileType() const override; | 33 | FileType GetFileType() const override; |
| 32 | 34 | ||
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index b2e5b13de..bf6db1ab1 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -152,21 +152,26 @@ public: | |||
| 152 | 152 | ||
| 153 | /** | 153 | /** |
| 154 | * Returns the type of this file | 154 | * Returns the type of this file |
| 155 | * | ||
| 155 | * @return FileType corresponding to the loaded file | 156 | * @return FileType corresponding to the loaded file |
| 156 | */ | 157 | */ |
| 157 | virtual FileType GetFileType() const = 0; | 158 | virtual FileType GetFileType() const = 0; |
| 158 | 159 | ||
| 159 | /** | 160 | /** |
| 160 | * Load the application and return the created Process instance | 161 | * Load the application and return the created Process instance |
| 162 | * | ||
| 161 | * @param process The newly created process. | 163 | * @param process The newly created process. |
| 162 | * @param system The system that this process is being loaded under. | 164 | * @param system The system that this process is being loaded under. |
| 165 | * | ||
| 163 | * @return The status result of the operation. | 166 | * @return The status result of the operation. |
| 164 | */ | 167 | */ |
| 165 | virtual LoadResult Load(Kernel::Process& process, Core::System& system) = 0; | 168 | virtual LoadResult Load(Kernel::Process& process, Core::System& system) = 0; |
| 166 | 169 | ||
| 167 | /** | 170 | /** |
| 168 | * Get the code (typically .code section) of the application | 171 | * Get the code (typically .code section) of the application |
| 169 | * @param buffer Reference to buffer to store data | 172 | * |
| 173 | * @param[out] buffer Reference to buffer to store data | ||
| 174 | * | ||
| 170 | * @return ResultStatus result of function | 175 | * @return ResultStatus result of function |
| 171 | */ | 176 | */ |
| 172 | virtual ResultStatus ReadCode(std::vector<u8>& buffer) { | 177 | virtual ResultStatus ReadCode(std::vector<u8>& buffer) { |
| @@ -175,7 +180,9 @@ public: | |||
| 175 | 180 | ||
| 176 | /** | 181 | /** |
| 177 | * Get the icon (typically icon section) of the application | 182 | * Get the icon (typically icon section) of the application |
| 178 | * @param buffer Reference to buffer to store data | 183 | * |
| 184 | * @param[out] buffer Reference to buffer to store data | ||
| 185 | * | ||
| 179 | * @return ResultStatus result of function | 186 | * @return ResultStatus result of function |
| 180 | */ | 187 | */ |
| 181 | virtual ResultStatus ReadIcon(std::vector<u8>& buffer) { | 188 | virtual ResultStatus ReadIcon(std::vector<u8>& buffer) { |
| @@ -186,7 +193,9 @@ public: | |||
| 186 | * Get the banner (typically banner section) of the application | 193 | * Get the banner (typically banner section) of the application |
| 187 | * In the context of NX, this is the animation that displays in the bottom right of the screen | 194 | * In the context of NX, this is the animation that displays in the bottom right of the screen |
| 188 | * when a game boots. Stored in GIF format. | 195 | * when a game boots. Stored in GIF format. |
| 189 | * @param buffer Reference to buffer to store data | 196 | * |
| 197 | * @param[out] buffer Reference to buffer to store data | ||
| 198 | * | ||
| 190 | * @return ResultStatus result of function | 199 | * @return ResultStatus result of function |
| 191 | */ | 200 | */ |
| 192 | virtual ResultStatus ReadBanner(std::vector<u8>& buffer) { | 201 | virtual ResultStatus ReadBanner(std::vector<u8>& buffer) { |
| @@ -197,7 +206,9 @@ public: | |||
| 197 | * Get the logo (typically logo section) of the application | 206 | * Get the logo (typically logo section) of the application |
| 198 | * In the context of NX, this is the static image that displays in the top left of the screen | 207 | * In the context of NX, this is the static image that displays in the top left of the screen |
| 199 | * when a game boots. Stored in JPEG format. | 208 | * when a game boots. Stored in JPEG format. |
| 200 | * @param buffer Reference to buffer to store data | 209 | * |
| 210 | * @param[out] buffer Reference to buffer to store data | ||
| 211 | * | ||
| 201 | * @return ResultStatus result of function | 212 | * @return ResultStatus result of function |
| 202 | */ | 213 | */ |
| 203 | virtual ResultStatus ReadLogo(std::vector<u8>& buffer) { | 214 | virtual ResultStatus ReadLogo(std::vector<u8>& buffer) { |
| @@ -206,7 +217,9 @@ public: | |||
| 206 | 217 | ||
| 207 | /** | 218 | /** |
| 208 | * Get the program id of the application | 219 | * Get the program id of the application |
| 209 | * @param out_program_id Reference to store program id into | 220 | * |
| 221 | * @param[out] out_program_id Reference to store program id into | ||
| 222 | * | ||
| 210 | * @return ResultStatus result of function | 223 | * @return ResultStatus result of function |
| 211 | */ | 224 | */ |
| 212 | virtual ResultStatus ReadProgramId(u64& out_program_id) { | 225 | virtual ResultStatus ReadProgramId(u64& out_program_id) { |
| @@ -216,19 +229,23 @@ public: | |||
| 216 | /** | 229 | /** |
| 217 | * Get the RomFS of the application | 230 | * Get the RomFS of the application |
| 218 | * Since the RomFS can be huge, we return a file reference instead of copying to a buffer | 231 | * Since the RomFS can be huge, we return a file reference instead of copying to a buffer |
| 219 | * @param file The directory containing the RomFS | 232 | * |
| 233 | * @param[out] out_file The directory containing the RomFS | ||
| 234 | * | ||
| 220 | * @return ResultStatus result of function | 235 | * @return ResultStatus result of function |
| 221 | */ | 236 | */ |
| 222 | virtual ResultStatus ReadRomFS(FileSys::VirtualFile& file) { | 237 | virtual ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) { |
| 223 | return ResultStatus::ErrorNotImplemented; | 238 | return ResultStatus::ErrorNotImplemented; |
| 224 | } | 239 | } |
| 225 | 240 | ||
| 226 | /** | 241 | /** |
| 227 | * Get the raw update of the application, should it come packed with one | 242 | * Get the raw update of the application, should it come packed with one |
| 228 | * @param file The raw update NCA file (Program-type | 243 | * |
| 244 | * @param[out] out_file The raw update NCA file (Program-type) | ||
| 245 | * | ||
| 229 | * @return ResultStatus result of function | 246 | * @return ResultStatus result of function |
| 230 | */ | 247 | */ |
| 231 | virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) { | 248 | virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) { |
| 232 | return ResultStatus::ErrorNotImplemented; | 249 | return ResultStatus::ErrorNotImplemented; |
| 233 | } | 250 | } |
| 234 | 251 | ||
| @@ -236,7 +253,8 @@ public: | |||
| 236 | * Get whether or not updates can be applied to the RomFS. | 253 | * Get whether or not updates can be applied to the RomFS. |
| 237 | * By default, this is true, however for formats where it cannot be guaranteed that the RomFS is | 254 | * By default, this is true, however for formats where it cannot be guaranteed that the RomFS is |
| 238 | * the base game it should be set to false. | 255 | * the base game it should be set to false. |
| 239 | * @return bool whether or not updatable. | 256 | * |
| 257 | * @return bool indicating whether or not the RomFS is updatable. | ||
| 240 | */ | 258 | */ |
| 241 | virtual bool IsRomFSUpdatable() const { | 259 | virtual bool IsRomFSUpdatable() const { |
| 242 | return true; | 260 | return true; |
| @@ -244,8 +262,9 @@ public: | |||
| 244 | 262 | ||
| 245 | /** | 263 | /** |
| 246 | * Gets the difference between the start of the IVFC header and the start of level 6 (RomFS) | 264 | * Gets the difference between the start of the IVFC header and the start of level 6 (RomFS) |
| 247 | * data. Needed for bktr patching. | 265 | * data. Needed for BKTR patching. |
| 248 | * @return IVFC offset for romfs. | 266 | * |
| 267 | * @return IVFC offset for RomFS. | ||
| 249 | */ | 268 | */ |
| 250 | virtual u64 ReadRomFSIVFCOffset() const { | 269 | virtual u64 ReadRomFSIVFCOffset() const { |
| 251 | return 0; | 270 | return 0; |
| @@ -253,7 +272,9 @@ public: | |||
| 253 | 272 | ||
| 254 | /** | 273 | /** |
| 255 | * Get the title of the application | 274 | * Get the title of the application |
| 256 | * @param title Reference to store the application title into | 275 | * |
| 276 | * @param[out] title Reference to store the application title into | ||
| 277 | * | ||
| 257 | * @return ResultStatus result of function | 278 | * @return ResultStatus result of function |
| 258 | */ | 279 | */ |
| 259 | virtual ResultStatus ReadTitle(std::string& title) { | 280 | virtual ResultStatus ReadTitle(std::string& title) { |
| @@ -262,7 +283,9 @@ public: | |||
| 262 | 283 | ||
| 263 | /** | 284 | /** |
| 264 | * Get the control data (CNMT) of the application | 285 | * Get the control data (CNMT) of the application |
| 265 | * @param control Reference to store the application control data into | 286 | * |
| 287 | * @param[out] control Reference to store the application control data into | ||
| 288 | * | ||
| 266 | * @return ResultStatus result of function | 289 | * @return ResultStatus result of function |
| 267 | */ | 290 | */ |
| 268 | virtual ResultStatus ReadControlData(FileSys::NACP& control) { | 291 | virtual ResultStatus ReadControlData(FileSys::NACP& control) { |
| @@ -271,10 +294,12 @@ public: | |||
| 271 | 294 | ||
| 272 | /** | 295 | /** |
| 273 | * Get the RomFS of the manual of the application | 296 | * Get the RomFS of the manual of the application |
| 274 | * @param file The raw manual RomFS of the game | 297 | * |
| 298 | * @param[out] out_file The raw manual RomFS of the game | ||
| 299 | * | ||
| 275 | * @return ResultStatus result of function | 300 | * @return ResultStatus result of function |
| 276 | */ | 301 | */ |
| 277 | virtual ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) { | 302 | virtual ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) { |
| 278 | return ResultStatus::ErrorNotImplemented; | 303 | return ResultStatus::ErrorNotImplemented; |
| 279 | } | 304 | } |
| 280 | 305 | ||
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 49028177b..f53c3a72c 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp | |||
| @@ -26,14 +26,14 @@ FileType IdentifyTypeImpl(const FileSys::NAX& nax) { | |||
| 26 | } | 26 | } |
| 27 | } // Anonymous namespace | 27 | } // Anonymous namespace |
| 28 | 28 | ||
| 29 | AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) | 29 | AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file_) |
| 30 | : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), | 30 | : AppLoader(file_), nax(std::make_unique<FileSys::NAX>(file_)), |
| 31 | nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {} | 31 | nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {} |
| 32 | 32 | ||
| 33 | AppLoader_NAX::~AppLoader_NAX() = default; | 33 | AppLoader_NAX::~AppLoader_NAX() = default; |
| 34 | 34 | ||
| 35 | FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { | 35 | FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& nax_file) { |
| 36 | const FileSys::NAX nax(file); | 36 | const FileSys::NAX nax(nax_file); |
| 37 | return IdentifyTypeImpl(nax); | 37 | return IdentifyTypeImpl(nax); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| @@ -41,8 +41,7 @@ FileType AppLoader_NAX::GetFileType() const { | |||
| 41 | return IdentifyTypeImpl(*nax); | 41 | return IdentifyTypeImpl(*nax); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::Process& process, | 44 | AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::Process& process, Core::System& system) { |
| 45 | [[maybe_unused]] Core::System& system) { | ||
| 46 | if (is_loaded) { | 45 | if (is_loaded) { |
| 47 | return {ResultStatus::ErrorAlreadyLoaded, {}}; | 46 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 48 | } | 47 | } |
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index a5b5e2ae1..68427c1cf 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h | |||
| @@ -23,15 +23,17 @@ class AppLoader_NCA; | |||
| 23 | /// Loads a NAX file | 23 | /// Loads a NAX file |
| 24 | class AppLoader_NAX final : public AppLoader { | 24 | class AppLoader_NAX final : public AppLoader { |
| 25 | public: | 25 | public: |
| 26 | explicit AppLoader_NAX(FileSys::VirtualFile file); | 26 | explicit AppLoader_NAX(FileSys::VirtualFile file_); |
| 27 | ~AppLoader_NAX() override; | 27 | ~AppLoader_NAX() override; |
| 28 | 28 | ||
| 29 | /** | 29 | /** |
| 30 | * Returns the type of the file | 30 | * Identifies whether or not the given file is a NAX file. |
| 31 | * @param file open file | 31 | * |
| 32 | * @return FileType found, or FileType::Error if this loader doesn't know it | 32 | * @param nax_file The file to identify. |
| 33 | * | ||
| 34 | * @return FileType::NAX, or FileType::Error if the file is not a NAX file. | ||
| 33 | */ | 35 | */ |
| 34 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 36 | static FileType IdentifyType(const FileSys::VirtualFile& nax_file); |
| 35 | 37 | ||
| 36 | FileType GetFileType() const override; | 38 | FileType GetFileType() const override; |
| 37 | 39 | ||
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index fa694de37..47e7a77a9 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp | |||
| @@ -21,12 +21,13 @@ AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_) | |||
| 21 | 21 | ||
| 22 | AppLoader_NCA::~AppLoader_NCA() = default; | 22 | AppLoader_NCA::~AppLoader_NCA() = default; |
| 23 | 23 | ||
| 24 | FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { | 24 | FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& nca_file) { |
| 25 | FileSys::NCA nca(file); | 25 | const FileSys::NCA nca(nca_file); |
| 26 | 26 | ||
| 27 | if (nca.GetStatus() == ResultStatus::Success && | 27 | if (nca.GetStatus() == ResultStatus::Success && |
| 28 | nca.GetType() == FileSys::NCAContentType::Program) | 28 | nca.GetType() == FileSys::NCAContentType::Program) { |
| 29 | return FileType::NCA; | 29 | return FileType::NCA; |
| 30 | } | ||
| 30 | 31 | ||
| 31 | return FileType::Error; | 32 | return FileType::Error; |
| 32 | } | 33 | } |
| @@ -67,43 +68,59 @@ AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::Process& process, Core::Sy | |||
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { | 70 | ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { |
| 70 | if (nca == nullptr) | 71 | if (nca == nullptr) { |
| 71 | return ResultStatus::ErrorNotInitialized; | 72 | return ResultStatus::ErrorNotInitialized; |
| 72 | if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) | 73 | } |
| 74 | |||
| 75 | if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) { | ||
| 73 | return ResultStatus::ErrorNoRomFS; | 76 | return ResultStatus::ErrorNoRomFS; |
| 77 | } | ||
| 78 | |||
| 74 | dir = nca->GetRomFS(); | 79 | dir = nca->GetRomFS(); |
| 75 | return ResultStatus::Success; | 80 | return ResultStatus::Success; |
| 76 | } | 81 | } |
| 77 | 82 | ||
| 78 | u64 AppLoader_NCA::ReadRomFSIVFCOffset() const { | 83 | u64 AppLoader_NCA::ReadRomFSIVFCOffset() const { |
| 79 | if (nca == nullptr) | 84 | if (nca == nullptr) { |
| 80 | return 0; | 85 | return 0; |
| 86 | } | ||
| 87 | |||
| 81 | return nca->GetBaseIVFCOffset(); | 88 | return nca->GetBaseIVFCOffset(); |
| 82 | } | 89 | } |
| 83 | 90 | ||
| 84 | ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { | 91 | ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { |
| 85 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) | 92 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { |
| 86 | return ResultStatus::ErrorNotInitialized; | 93 | return ResultStatus::ErrorNotInitialized; |
| 94 | } | ||
| 95 | |||
| 87 | out_program_id = nca->GetTitleId(); | 96 | out_program_id = nca->GetTitleId(); |
| 88 | return ResultStatus::Success; | 97 | return ResultStatus::Success; |
| 89 | } | 98 | } |
| 90 | 99 | ||
| 91 | ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) { | 100 | ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) { |
| 92 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) | 101 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { |
| 93 | return ResultStatus::ErrorNotInitialized; | 102 | return ResultStatus::ErrorNotInitialized; |
| 103 | } | ||
| 104 | |||
| 94 | const auto logo = nca->GetLogoPartition(); | 105 | const auto logo = nca->GetLogoPartition(); |
| 95 | if (logo == nullptr) | 106 | if (logo == nullptr) { |
| 96 | return ResultStatus::ErrorNoIcon; | 107 | return ResultStatus::ErrorNoIcon; |
| 108 | } | ||
| 109 | |||
| 97 | buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes(); | 110 | buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes(); |
| 98 | return ResultStatus::Success; | 111 | return ResultStatus::Success; |
| 99 | } | 112 | } |
| 100 | 113 | ||
| 101 | ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) { | 114 | ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) { |
| 102 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) | 115 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { |
| 103 | return ResultStatus::ErrorNotInitialized; | 116 | return ResultStatus::ErrorNotInitialized; |
| 117 | } | ||
| 118 | |||
| 104 | const auto logo = nca->GetLogoPartition(); | 119 | const auto logo = nca->GetLogoPartition(); |
| 105 | if (logo == nullptr) | 120 | if (logo == nullptr) { |
| 106 | return ResultStatus::ErrorNoIcon; | 121 | return ResultStatus::ErrorNoIcon; |
| 122 | } | ||
| 123 | |||
| 107 | buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes(); | 124 | buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes(); |
| 108 | return ResultStatus::Success; | 125 | return ResultStatus::Success; |
| 109 | } | 126 | } |
diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index 918792800..c9792f390 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h | |||
| @@ -23,15 +23,17 @@ class AppLoader_DeconstructedRomDirectory; | |||
| 23 | /// Loads an NCA file | 23 | /// Loads an NCA file |
| 24 | class AppLoader_NCA final : public AppLoader { | 24 | class AppLoader_NCA final : public AppLoader { |
| 25 | public: | 25 | public: |
| 26 | explicit AppLoader_NCA(FileSys::VirtualFile file); | 26 | explicit AppLoader_NCA(FileSys::VirtualFile file_); |
| 27 | ~AppLoader_NCA() override; | 27 | ~AppLoader_NCA() override; |
| 28 | 28 | ||
| 29 | /** | 29 | /** |
| 30 | * Returns the type of the file | 30 | * Identifies whether or not the given file is an NCA file. |
| 31 | * @param file open file | 31 | * |
| 32 | * @return FileType found, or FileType::Error if this loader doesn't know it | 32 | * @param nca_file The file to identify. |
| 33 | * | ||
| 34 | * @return FileType::NCA, or FileType::Error if the file is not an NCA file. | ||
| 33 | */ | 35 | */ |
| 34 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 36 | static FileType IdentifyType(const FileSys::VirtualFile& nca_file); |
| 35 | 37 | ||
| 36 | FileType GetFileType() const override { | 38 | FileType GetFileType() const override { |
| 37 | return IdentifyType(file); | 39 | return IdentifyType(file); |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 0115ed0c4..0597cfa60 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -72,7 +72,7 @@ struct AssetHeader { | |||
| 72 | }; | 72 | }; |
| 73 | static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); | 73 | static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); |
| 74 | 74 | ||
| 75 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { | 75 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) { |
| 76 | NroHeader nro_header{}; | 76 | NroHeader nro_header{}; |
| 77 | if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { | 77 | if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { |
| 78 | return; | 78 | return; |
| @@ -114,10 +114,10 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { | |||
| 114 | 114 | ||
| 115 | AppLoader_NRO::~AppLoader_NRO() = default; | 115 | AppLoader_NRO::~AppLoader_NRO() = default; |
| 116 | 116 | ||
| 117 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { | 117 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& nro_file) { |
| 118 | // Read NSO header | 118 | // Read NSO header |
| 119 | NroHeader nro_header{}; | 119 | NroHeader nro_header{}; |
| 120 | if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { | 120 | if (sizeof(NroHeader) != nro_file->ReadObject(&nro_header)) { |
| 121 | return FileType::Error; | 121 | return FileType::Error; |
| 122 | } | 122 | } |
| 123 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { | 123 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { |
| @@ -130,8 +130,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 130 | return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); | 130 | return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, | 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data) { |
| 134 | const std::string& name) { | ||
| 135 | if (data.size() < sizeof(NroHeader)) { | 134 | if (data.size() < sizeof(NroHeader)) { |
| 136 | return {}; | 135 | return {}; |
| 137 | } | 136 | } |
| @@ -200,8 +199,8 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, | |||
| 200 | return true; | 199 | return true; |
| 201 | } | 200 | } |
| 202 | 201 | ||
| 203 | bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file) { | 202 | bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& nro_file) { |
| 204 | return LoadNroImpl(process, file.ReadAllBytes(), file.GetName()); | 203 | return LoadNroImpl(process, nro_file.ReadAllBytes()); |
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process, Core::System& system) { | 206 | AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process, Core::System& system) { |
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index a82b66221..20bbaeb0e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -27,15 +27,17 @@ namespace Loader { | |||
| 27 | /// Loads an NRO file | 27 | /// Loads an NRO file |
| 28 | class AppLoader_NRO final : public AppLoader { | 28 | class AppLoader_NRO final : public AppLoader { |
| 29 | public: | 29 | public: |
| 30 | explicit AppLoader_NRO(FileSys::VirtualFile file); | 30 | explicit AppLoader_NRO(FileSys::VirtualFile file_); |
| 31 | ~AppLoader_NRO() override; | 31 | ~AppLoader_NRO() override; |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | * Returns the type of the file | 34 | * Identifies whether or not the given file is an NRO file. |
| 35 | * @param file open file | 35 | * |
| 36 | * @return FileType found, or FileType::Error if this loader doesn't know it | 36 | * @param nro_file The file to identify. |
| 37 | * | ||
| 38 | * @return FileType::NRO, or FileType::Error if the file is not an NRO file. | ||
| 37 | */ | 39 | */ |
| 38 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 40 | static FileType IdentifyType(const FileSys::VirtualFile& nro_file); |
| 39 | 41 | ||
| 40 | FileType GetFileType() const override { | 42 | FileType GetFileType() const override { |
| 41 | return IdentifyType(file); | 43 | return IdentifyType(file); |
| @@ -51,7 +53,7 @@ public: | |||
| 51 | bool IsRomFSUpdatable() const override; | 53 | bool IsRomFSUpdatable() const override; |
| 52 | 54 | ||
| 53 | private: | 55 | private: |
| 54 | bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file); | 56 | bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& nro_file); |
| 55 | 57 | ||
| 56 | std::vector<u8> icon_data; | 58 | std::vector<u8> icon_data; |
| 57 | std::unique_ptr<FileSys::NACP> nacp; | 59 | std::unique_ptr<FileSys::NACP> nacp; |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 0c83dd666..f671afe02 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -56,11 +56,11 @@ bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { | |||
| 56 | return ((flags >> segment_num) & 1) != 0; | 56 | return ((flags >> segment_num) & 1) != 0; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | AppLoader_NSO::AppLoader_NSO(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} | 59 | AppLoader_NSO::AppLoader_NSO(FileSys::VirtualFile file_) : AppLoader(std::move(file_)) {} |
| 60 | 60 | ||
| 61 | FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { | 61 | FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& in_file) { |
| 62 | u32 magic = 0; | 62 | u32 magic = 0; |
| 63 | if (file->ReadObject(&magic) != sizeof(magic)) { | 63 | if (in_file->ReadObject(&magic) != sizeof(magic)) { |
| 64 | return FileType::Error; | 64 | return FileType::Error; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| @@ -72,15 +72,15 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::System& system, | 74 | std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::System& system, |
| 75 | const FileSys::VfsFile& file, VAddr load_base, | 75 | const FileSys::VfsFile& nso_file, VAddr load_base, |
| 76 | bool should_pass_arguments, bool load_into_process, | 76 | bool should_pass_arguments, bool load_into_process, |
| 77 | std::optional<FileSys::PatchManager> pm) { | 77 | std::optional<FileSys::PatchManager> pm) { |
| 78 | if (file.GetSize() < sizeof(NSOHeader)) { | 78 | if (nso_file.GetSize() < sizeof(NSOHeader)) { |
| 79 | return std::nullopt; | 79 | return std::nullopt; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | NSOHeader nso_header{}; | 82 | NSOHeader nso_header{}; |
| 83 | if (sizeof(NSOHeader) != file.ReadObject(&nso_header)) { | 83 | if (sizeof(NSOHeader) != nso_file.ReadObject(&nso_header)) { |
| 84 | return std::nullopt; | 84 | return std::nullopt; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| @@ -92,8 +92,8 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S | |||
| 92 | Kernel::CodeSet codeset; | 92 | Kernel::CodeSet codeset; |
| 93 | Kernel::PhysicalMemory program_image; | 93 | Kernel::PhysicalMemory program_image; |
| 94 | for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { | 94 | for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { |
| 95 | std::vector<u8> data = | 95 | std::vector<u8> data = nso_file.ReadBytes(nso_header.segments_compressed_size[i], |
| 96 | file.ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); | 96 | nso_header.segments[i].offset); |
| 97 | if (nso_header.IsSegmentCompressed(i)) { | 97 | if (nso_header.IsSegmentCompressed(i)) { |
| 98 | data = DecompressSegment(data, nso_header.segments[i]); | 98 | data = DecompressSegment(data, nso_header.segments[i]); |
| 99 | } | 99 | } |
| @@ -136,7 +136,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S | |||
| 136 | pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.data(), | 136 | pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.data(), |
| 137 | program_image.data() + program_image.size()); | 137 | program_image.data() + program_image.size()); |
| 138 | 138 | ||
| 139 | pi_header = pm->PatchNSO(pi_header, file.GetName()); | 139 | pi_header = pm->PatchNSO(pi_header, nso_file.GetName()); |
| 140 | 140 | ||
| 141 | std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data()); | 141 | std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data()); |
| 142 | } | 142 | } |
| @@ -183,8 +183,8 @@ AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::Process& process, Core::Sy | |||
| 183 | Core::Memory::DEFAULT_STACK_SIZE}}; | 183 | Core::Memory::DEFAULT_STACK_SIZE}}; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | ResultStatus AppLoader_NSO::ReadNSOModules(Modules& modules) { | 186 | ResultStatus AppLoader_NSO::ReadNSOModules(Modules& out_modules) { |
| 187 | modules = this->modules; | 187 | out_modules = this->modules; |
| 188 | return ResultStatus::Success; | 188 | return ResultStatus::Success; |
| 189 | } | 189 | } |
| 190 | 190 | ||
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 3af461b5f..195149b55 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -71,27 +71,29 @@ static_assert(sizeof(NSOArgumentHeader) == 0x20, "NSOArgumentHeader has incorrec | |||
| 71 | /// Loads an NSO file | 71 | /// Loads an NSO file |
| 72 | class AppLoader_NSO final : public AppLoader { | 72 | class AppLoader_NSO final : public AppLoader { |
| 73 | public: | 73 | public: |
| 74 | explicit AppLoader_NSO(FileSys::VirtualFile file); | 74 | explicit AppLoader_NSO(FileSys::VirtualFile file_); |
| 75 | 75 | ||
| 76 | /** | 76 | /** |
| 77 | * Returns the type of the file | 77 | * Identifies whether or not the given file is a form of NSO file. |
| 78 | * @param file open file | 78 | * |
| 79 | * @return FileType found, or FileType::Error if this loader doesn't know it | 79 | * @param in_file The file to be identified. |
| 80 | * | ||
| 81 | * @return FileType::NSO if found, or FileType::Error if some other type of file. | ||
| 80 | */ | 82 | */ |
| 81 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 83 | static FileType IdentifyType(const FileSys::VirtualFile& in_file); |
| 82 | 84 | ||
| 83 | FileType GetFileType() const override { | 85 | FileType GetFileType() const override { |
| 84 | return IdentifyType(file); | 86 | return IdentifyType(file); |
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | static std::optional<VAddr> LoadModule(Kernel::Process& process, Core::System& system, | 89 | static std::optional<VAddr> LoadModule(Kernel::Process& process, Core::System& system, |
| 88 | const FileSys::VfsFile& file, VAddr load_base, | 90 | const FileSys::VfsFile& nso_file, VAddr load_base, |
| 89 | bool should_pass_arguments, bool load_into_process, | 91 | bool should_pass_arguments, bool load_into_process, |
| 90 | std::optional<FileSys::PatchManager> pm = {}); | 92 | std::optional<FileSys::PatchManager> pm = {}); |
| 91 | 93 | ||
| 92 | LoadResult Load(Kernel::Process& process, Core::System& system) override; | 94 | LoadResult Load(Kernel::Process& process, Core::System& system) override; |
| 93 | 95 | ||
| 94 | ResultStatus ReadNSOModules(Modules& modules) override; | 96 | ResultStatus ReadNSOModules(Modules& out_modules) override; |
| 95 | 97 | ||
| 96 | private: | 98 | private: |
| 97 | Modules modules; | 99 | Modules modules; |
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 928f64c8c..d7e590f1c 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp | |||
| @@ -21,11 +21,11 @@ | |||
| 21 | 21 | ||
| 22 | namespace Loader { | 22 | namespace Loader { |
| 23 | 23 | ||
| 24 | AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, | 24 | AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file_, |
| 25 | const Service::FileSystem::FileSystemController& fsc, | 25 | const Service::FileSystem::FileSystemController& fsc, |
| 26 | const FileSys::ContentProvider& content_provider, | 26 | const FileSys::ContentProvider& content_provider, |
| 27 | std::size_t program_index) | 27 | std::size_t program_index) |
| 28 | : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file, program_index)), | 28 | : AppLoader(file_), nsp(std::make_unique<FileSys::NSP>(file_, program_index)), |
| 29 | title_id(nsp->GetProgramTitleID()) { | 29 | title_id(nsp->GetProgramTitleID()) { |
| 30 | 30 | ||
| 31 | if (nsp->GetStatus() != ResultStatus::Success) { | 31 | if (nsp->GetStatus() != ResultStatus::Success) { |
| @@ -57,8 +57,8 @@ AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, | |||
| 57 | 57 | ||
| 58 | AppLoader_NSP::~AppLoader_NSP() = default; | 58 | AppLoader_NSP::~AppLoader_NSP() = default; |
| 59 | 59 | ||
| 60 | FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) { | 60 | FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& nsp_file) { |
| 61 | FileSys::NSP nsp(file); | 61 | const FileSys::NSP nsp(nsp_file); |
| 62 | 62 | ||
| 63 | if (nsp.GetStatus() == ResultStatus::Success) { | 63 | if (nsp.GetStatus() == ResultStatus::Success) { |
| 64 | // Extracted Type case | 64 | // Extracted Type case |
| @@ -121,67 +121,80 @@ AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::Process& process, Core::Sy | |||
| 121 | return result; | 121 | return result; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { | 124 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& out_file) { |
| 125 | return secondary_loader->ReadRomFS(file); | 125 | return secondary_loader->ReadRomFS(out_file); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { | 128 | u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { |
| 129 | return secondary_loader->ReadRomFSIVFCOffset(); | 129 | return secondary_loader->ReadRomFSIVFCOffset(); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& file) { | 132 | ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& out_file) { |
| 133 | if (nsp->IsExtractedType()) | 133 | if (nsp->IsExtractedType()) { |
| 134 | return ResultStatus::ErrorNoPackedUpdate; | 134 | return ResultStatus::ErrorNoPackedUpdate; |
| 135 | } | ||
| 135 | 136 | ||
| 136 | const auto read = | 137 | const auto read = |
| 137 | nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); | 138 | nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); |
| 138 | 139 | ||
| 139 | if (read == nullptr) | 140 | if (read == nullptr) { |
| 140 | return ResultStatus::ErrorNoPackedUpdate; | 141 | return ResultStatus::ErrorNoPackedUpdate; |
| 141 | const auto nca_test = std::make_shared<FileSys::NCA>(read); | 142 | } |
| 142 | 143 | ||
| 143 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) | 144 | const auto nca_test = std::make_shared<FileSys::NCA>(read); |
| 145 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) { | ||
| 144 | return nca_test->GetStatus(); | 146 | return nca_test->GetStatus(); |
| 147 | } | ||
| 145 | 148 | ||
| 146 | file = read; | 149 | out_file = read; |
| 147 | return ResultStatus::Success; | 150 | return ResultStatus::Success; |
| 148 | } | 151 | } |
| 149 | 152 | ||
| 150 | ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { | 153 | ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { |
| 151 | if (title_id == 0) | 154 | if (title_id == 0) { |
| 152 | return ResultStatus::ErrorNotInitialized; | 155 | return ResultStatus::ErrorNotInitialized; |
| 156 | } | ||
| 157 | |||
| 153 | out_program_id = title_id; | 158 | out_program_id = title_id; |
| 154 | return ResultStatus::Success; | 159 | return ResultStatus::Success; |
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | ResultStatus AppLoader_NSP::ReadIcon(std::vector<u8>& buffer) { | 162 | ResultStatus AppLoader_NSP::ReadIcon(std::vector<u8>& buffer) { |
| 158 | if (icon_file == nullptr) | 163 | if (icon_file == nullptr) { |
| 159 | return ResultStatus::ErrorNoControl; | 164 | return ResultStatus::ErrorNoControl; |
| 165 | } | ||
| 166 | |||
| 160 | buffer = icon_file->ReadAllBytes(); | 167 | buffer = icon_file->ReadAllBytes(); |
| 161 | return ResultStatus::Success; | 168 | return ResultStatus::Success; |
| 162 | } | 169 | } |
| 163 | 170 | ||
| 164 | ResultStatus AppLoader_NSP::ReadTitle(std::string& title) { | 171 | ResultStatus AppLoader_NSP::ReadTitle(std::string& title) { |
| 165 | if (nacp_file == nullptr) | 172 | if (nacp_file == nullptr) { |
| 166 | return ResultStatus::ErrorNoControl; | 173 | return ResultStatus::ErrorNoControl; |
| 174 | } | ||
| 175 | |||
| 167 | title = nacp_file->GetApplicationName(); | 176 | title = nacp_file->GetApplicationName(); |
| 168 | return ResultStatus::Success; | 177 | return ResultStatus::Success; |
| 169 | } | 178 | } |
| 170 | 179 | ||
| 171 | ResultStatus AppLoader_NSP::ReadControlData(FileSys::NACP& nacp) { | 180 | ResultStatus AppLoader_NSP::ReadControlData(FileSys::NACP& nacp) { |
| 172 | if (nacp_file == nullptr) | 181 | if (nacp_file == nullptr) { |
| 173 | return ResultStatus::ErrorNoControl; | 182 | return ResultStatus::ErrorNoControl; |
| 183 | } | ||
| 184 | |||
| 174 | nacp = *nacp_file; | 185 | nacp = *nacp_file; |
| 175 | return ResultStatus::Success; | 186 | return ResultStatus::Success; |
| 176 | } | 187 | } |
| 177 | 188 | ||
| 178 | ResultStatus AppLoader_NSP::ReadManualRomFS(FileSys::VirtualFile& file) { | 189 | ResultStatus AppLoader_NSP::ReadManualRomFS(FileSys::VirtualFile& out_file) { |
| 179 | const auto nca = | 190 | const auto nca = |
| 180 | nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::HtmlDocument); | 191 | nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::HtmlDocument); |
| 181 | if (nsp->GetStatus() != ResultStatus::Success || nca == nullptr) | 192 | if (nsp->GetStatus() != ResultStatus::Success || nca == nullptr) { |
| 182 | return ResultStatus::ErrorNoRomFS; | 193 | return ResultStatus::ErrorNoRomFS; |
| 183 | file = nca->GetRomFS(); | 194 | } |
| 184 | return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; | 195 | |
| 196 | out_file = nca->GetRomFS(); | ||
| 197 | return out_file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; | ||
| 185 | } | 198 | } |
| 186 | 199 | ||
| 187 | ResultStatus AppLoader_NSP::ReadBanner(std::vector<u8>& buffer) { | 200 | ResultStatus AppLoader_NSP::ReadBanner(std::vector<u8>& buffer) { |
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index d48d87f2c..1660f1b94 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h | |||
| @@ -26,18 +26,20 @@ class AppLoader_NCA; | |||
| 26 | /// Loads an XCI file | 26 | /// Loads an XCI file |
| 27 | class AppLoader_NSP final : public AppLoader { | 27 | class AppLoader_NSP final : public AppLoader { |
| 28 | public: | 28 | public: |
| 29 | explicit AppLoader_NSP(FileSys::VirtualFile file, | 29 | explicit AppLoader_NSP(FileSys::VirtualFile file_, |
| 30 | const Service::FileSystem::FileSystemController& fsc, | 30 | const Service::FileSystem::FileSystemController& fsc, |
| 31 | const FileSys::ContentProvider& content_provider, | 31 | const FileSys::ContentProvider& content_provider, |
| 32 | std::size_t program_index); | 32 | std::size_t program_index); |
| 33 | ~AppLoader_NSP() override; | 33 | ~AppLoader_NSP() override; |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * Returns the type of the file | 36 | * Identifies whether or not the given file is an NSP file. |
| 37 | * @param file open file | 37 | * |
| 38 | * @return FileType found, or FileType::Error if this loader doesn't know it | 38 | * @param nsp_file The file to identify. |
| 39 | * | ||
| 40 | * @return FileType::NSP, or FileType::Error if the file is not an NSP. | ||
| 39 | */ | 41 | */ |
| 40 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 42 | static FileType IdentifyType(const FileSys::VirtualFile& nsp_file); |
| 41 | 43 | ||
| 42 | FileType GetFileType() const override { | 44 | FileType GetFileType() const override { |
| 43 | return IdentifyType(file); | 45 | return IdentifyType(file); |
| @@ -45,14 +47,14 @@ public: | |||
| 45 | 47 | ||
| 46 | LoadResult Load(Kernel::Process& process, Core::System& system) override; | 48 | LoadResult Load(Kernel::Process& process, Core::System& system) override; |
| 47 | 49 | ||
| 48 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; | 50 | ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) override; |
| 49 | u64 ReadRomFSIVFCOffset() const override; | 51 | u64 ReadRomFSIVFCOffset() const override; |
| 50 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; | 52 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; |
| 51 | ResultStatus ReadProgramId(u64& out_program_id) override; | 53 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 52 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 54 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
| 53 | ResultStatus ReadTitle(std::string& title) override; | 55 | ResultStatus ReadTitle(std::string& title) override; |
| 54 | ResultStatus ReadControlData(FileSys::NACP& nacp) override; | 56 | ResultStatus ReadControlData(FileSys::NACP& nacp) override; |
| 55 | ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override; | 57 | ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) override; |
| 56 | 58 | ||
| 57 | ResultStatus ReadBanner(std::vector<u8>& buffer) override; | 59 | ResultStatus ReadBanner(std::vector<u8>& buffer) override; |
| 58 | ResultStatus ReadLogo(std::vector<u8>& buffer) override; | 60 | ResultStatus ReadLogo(std::vector<u8>& buffer) override; |
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index aaa250cea..0125ddf33 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp | |||
| @@ -20,11 +20,11 @@ | |||
| 20 | 20 | ||
| 21 | namespace Loader { | 21 | namespace Loader { |
| 22 | 22 | ||
| 23 | AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, | 23 | AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file_, |
| 24 | const Service::FileSystem::FileSystemController& fsc, | 24 | const Service::FileSystem::FileSystemController& fsc, |
| 25 | const FileSys::ContentProvider& content_provider, | 25 | const FileSys::ContentProvider& content_provider, |
| 26 | std::size_t program_index) | 26 | std::size_t program_index) |
| 27 | : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file, program_index)), | 27 | : AppLoader(file_), xci(std::make_unique<FileSys::XCI>(file_, program_index)), |
| 28 | nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { | 28 | nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { |
| 29 | if (xci->GetStatus() != ResultStatus::Success) { | 29 | if (xci->GetStatus() != ResultStatus::Success) { |
| 30 | return; | 30 | return; |
| @@ -43,8 +43,8 @@ AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, | |||
| 43 | 43 | ||
| 44 | AppLoader_XCI::~AppLoader_XCI() = default; | 44 | AppLoader_XCI::~AppLoader_XCI() = default; |
| 45 | 45 | ||
| 46 | FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) { | 46 | FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& xci_file) { |
| 47 | FileSys::XCI xci(file); | 47 | const FileSys::XCI xci(xci_file); |
| 48 | 48 | ||
| 49 | if (xci.GetStatus() == ResultStatus::Success && | 49 | if (xci.GetStatus() == ResultStatus::Success && |
| 50 | xci.GetNCAByType(FileSys::NCAContentType::Program) != nullptr && | 50 | xci.GetNCAByType(FileSys::NCAContentType::Program) != nullptr && |
| @@ -87,31 +87,33 @@ AppLoader_XCI::LoadResult AppLoader_XCI::Load(Kernel::Process& process, Core::Sy | |||
| 87 | return result; | 87 | return result; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { | 90 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& out_file) { |
| 91 | return nca_loader->ReadRomFS(file); | 91 | return nca_loader->ReadRomFS(out_file); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { | 94 | u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { |
| 95 | return nca_loader->ReadRomFSIVFCOffset(); | 95 | return nca_loader->ReadRomFSIVFCOffset(); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& file) { | 98 | ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& out_file) { |
| 99 | u64 program_id{}; | 99 | u64 program_id{}; |
| 100 | nca_loader->ReadProgramId(program_id); | 100 | nca_loader->ReadProgramId(program_id); |
| 101 | if (program_id == 0) | 101 | if (program_id == 0) { |
| 102 | return ResultStatus::ErrorXCIMissingProgramNCA; | 102 | return ResultStatus::ErrorXCIMissingProgramNCA; |
| 103 | } | ||
| 103 | 104 | ||
| 104 | const auto read = xci->GetSecurePartitionNSP()->GetNCAFile( | 105 | const auto read = xci->GetSecurePartitionNSP()->GetNCAFile( |
| 105 | FileSys::GetUpdateTitleID(program_id), FileSys::ContentRecordType::Program); | 106 | FileSys::GetUpdateTitleID(program_id), FileSys::ContentRecordType::Program); |
| 106 | 107 | if (read == nullptr) { | |
| 107 | if (read == nullptr) | ||
| 108 | return ResultStatus::ErrorNoPackedUpdate; | 108 | return ResultStatus::ErrorNoPackedUpdate; |
| 109 | const auto nca_test = std::make_shared<FileSys::NCA>(read); | 109 | } |
| 110 | 110 | ||
| 111 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) | 111 | const auto nca_test = std::make_shared<FileSys::NCA>(read); |
| 112 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) { | ||
| 112 | return nca_test->GetStatus(); | 113 | return nca_test->GetStatus(); |
| 114 | } | ||
| 113 | 115 | ||
| 114 | file = read; | 116 | out_file = read; |
| 115 | return ResultStatus::Success; | 117 | return ResultStatus::Success; |
| 116 | } | 118 | } |
| 117 | 119 | ||
| @@ -120,33 +122,41 @@ ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { | |||
| 120 | } | 122 | } |
| 121 | 123 | ||
| 122 | ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { | 124 | ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { |
| 123 | if (icon_file == nullptr) | 125 | if (icon_file == nullptr) { |
| 124 | return ResultStatus::ErrorNoControl; | 126 | return ResultStatus::ErrorNoControl; |
| 127 | } | ||
| 128 | |||
| 125 | buffer = icon_file->ReadAllBytes(); | 129 | buffer = icon_file->ReadAllBytes(); |
| 126 | return ResultStatus::Success; | 130 | return ResultStatus::Success; |
| 127 | } | 131 | } |
| 128 | 132 | ||
| 129 | ResultStatus AppLoader_XCI::ReadTitle(std::string& title) { | 133 | ResultStatus AppLoader_XCI::ReadTitle(std::string& title) { |
| 130 | if (nacp_file == nullptr) | 134 | if (nacp_file == nullptr) { |
| 131 | return ResultStatus::ErrorNoControl; | 135 | return ResultStatus::ErrorNoControl; |
| 136 | } | ||
| 137 | |||
| 132 | title = nacp_file->GetApplicationName(); | 138 | title = nacp_file->GetApplicationName(); |
| 133 | return ResultStatus::Success; | 139 | return ResultStatus::Success; |
| 134 | } | 140 | } |
| 135 | 141 | ||
| 136 | ResultStatus AppLoader_XCI::ReadControlData(FileSys::NACP& control) { | 142 | ResultStatus AppLoader_XCI::ReadControlData(FileSys::NACP& control) { |
| 137 | if (nacp_file == nullptr) | 143 | if (nacp_file == nullptr) { |
| 138 | return ResultStatus::ErrorNoControl; | 144 | return ResultStatus::ErrorNoControl; |
| 145 | } | ||
| 146 | |||
| 139 | control = *nacp_file; | 147 | control = *nacp_file; |
| 140 | return ResultStatus::Success; | 148 | return ResultStatus::Success; |
| 141 | } | 149 | } |
| 142 | 150 | ||
| 143 | ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& file) { | 151 | ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& out_file) { |
| 144 | const auto nca = xci->GetSecurePartitionNSP()->GetNCA(xci->GetProgramTitleID(), | 152 | const auto nca = xci->GetSecurePartitionNSP()->GetNCA(xci->GetProgramTitleID(), |
| 145 | FileSys::ContentRecordType::HtmlDocument); | 153 | FileSys::ContentRecordType::HtmlDocument); |
| 146 | if (xci->GetStatus() != ResultStatus::Success || nca == nullptr) | 154 | if (xci->GetStatus() != ResultStatus::Success || nca == nullptr) { |
| 147 | return ResultStatus::ErrorXCIMissingPartition; | 155 | return ResultStatus::ErrorXCIMissingPartition; |
| 148 | file = nca->GetRomFS(); | 156 | } |
| 149 | return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; | 157 | |
| 158 | out_file = nca->GetRomFS(); | ||
| 159 | return out_file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success; | ||
| 150 | } | 160 | } |
| 151 | 161 | ||
| 152 | ResultStatus AppLoader_XCI::ReadBanner(std::vector<u8>& buffer) { | 162 | ResultStatus AppLoader_XCI::ReadBanner(std::vector<u8>& buffer) { |
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 9f0ceb5ef..7ea8179af 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h | |||
| @@ -26,18 +26,20 @@ class AppLoader_NCA; | |||
| 26 | /// Loads an XCI file | 26 | /// Loads an XCI file |
| 27 | class AppLoader_XCI final : public AppLoader { | 27 | class AppLoader_XCI final : public AppLoader { |
| 28 | public: | 28 | public: |
| 29 | explicit AppLoader_XCI(FileSys::VirtualFile file, | 29 | explicit AppLoader_XCI(FileSys::VirtualFile file_, |
| 30 | const Service::FileSystem::FileSystemController& fsc, | 30 | const Service::FileSystem::FileSystemController& fsc, |
| 31 | const FileSys::ContentProvider& content_provider, | 31 | const FileSys::ContentProvider& content_provider, |
| 32 | std::size_t program_index); | 32 | std::size_t program_index); |
| 33 | ~AppLoader_XCI() override; | 33 | ~AppLoader_XCI() override; |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * Returns the type of the file | 36 | * Identifies whether or not the given file is an XCI file. |
| 37 | * @param file open file | 37 | * |
| 38 | * @return FileType found, or FileType::Error if this loader doesn't know it | 38 | * @param xci_file The file to identify. |
| 39 | * | ||
| 40 | * @return FileType::XCI, or FileType::Error if the file is not an XCI file. | ||
| 39 | */ | 41 | */ |
| 40 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 42 | static FileType IdentifyType(const FileSys::VirtualFile& xci_file); |
| 41 | 43 | ||
| 42 | FileType GetFileType() const override { | 44 | FileType GetFileType() const override { |
| 43 | return IdentifyType(file); | 45 | return IdentifyType(file); |
| @@ -45,14 +47,14 @@ public: | |||
| 45 | 47 | ||
| 46 | LoadResult Load(Kernel::Process& process, Core::System& system) override; | 48 | LoadResult Load(Kernel::Process& process, Core::System& system) override; |
| 47 | 49 | ||
| 48 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; | 50 | ResultStatus ReadRomFS(FileSys::VirtualFile& out_file) override; |
| 49 | u64 ReadRomFSIVFCOffset() const override; | 51 | u64 ReadRomFSIVFCOffset() const override; |
| 50 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; | 52 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; |
| 51 | ResultStatus ReadProgramId(u64& out_program_id) override; | 53 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 52 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 54 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
| 53 | ResultStatus ReadTitle(std::string& title) override; | 55 | ResultStatus ReadTitle(std::string& title) override; |
| 54 | ResultStatus ReadControlData(FileSys::NACP& control) override; | 56 | ResultStatus ReadControlData(FileSys::NACP& control) override; |
| 55 | ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override; | 57 | ResultStatus ReadManualRomFS(FileSys::VirtualFile& out_file) override; |
| 56 | 58 | ||
| 57 | ResultStatus ReadBanner(std::vector<u8>& buffer) override; | 59 | ResultStatus ReadBanner(std::vector<u8>& buffer) override; |
| 58 | ResultStatus ReadLogo(std::vector<u8>& buffer) override; | 60 | ResultStatus ReadLogo(std::vector<u8>& buffer) override; |