diff options
| author | 2018-07-23 19:06:30 -0700 | |
|---|---|---|
| committer | 2018-07-23 19:06:30 -0700 | |
| commit | 10dd03dec5d43dc4486c313e7654b89c3bbe32a2 (patch) | |
| tree | 720918f2ce43b138b4c3918efab361fcb57bc579 /src/core/loader/nro.cpp | |
| parent | Merge pull request #781 from lioncash/decl (diff) | |
| parent | nro: Replace inclusion with a forward declaration (diff) | |
| download | yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.gz yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.xz yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.zip | |
Merge pull request #782 from lioncash/file
loader/nro: Minor changes
Diffstat (limited to 'src/core/loader/nro.cpp')
| -rw-r--r-- | src/core/loader/nro.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 44158655c..7d3ec2a76 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | 7 | ||
| 8 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 9 | #include "common/common_types.h" | ||
| 9 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 10 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| @@ -68,22 +69,27 @@ static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); | |||
| 68 | 69 | ||
| 69 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { | 70 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { |
| 70 | NroHeader nro_header{}; | 71 | NroHeader nro_header{}; |
| 71 | if (file->ReadObject(&nro_header) != sizeof(NroHeader)) | 72 | if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { |
| 72 | return; | 73 | return; |
| 74 | } | ||
| 73 | 75 | ||
| 74 | if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) { | 76 | if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) { |
| 75 | u64 offset = nro_header.file_size; | 77 | const u64 offset = nro_header.file_size; |
| 76 | AssetHeader asset_header{}; | 78 | AssetHeader asset_header{}; |
| 77 | if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) | 79 | if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) { |
| 78 | return; | 80 | return; |
| 81 | } | ||
| 79 | 82 | ||
| 80 | if (asset_header.format_version != 0) | 83 | if (asset_header.format_version != 0) { |
| 81 | LOG_WARNING(Loader, | 84 | LOG_WARNING(Loader, |
| 82 | "NRO Asset Header has format {}, currently supported format is 0. If " | 85 | "NRO Asset Header has format {}, currently supported format is 0. If " |
| 83 | "strange glitches occur with metadata, check NRO assets.", | 86 | "strange glitches occur with metadata, check NRO assets.", |
| 84 | asset_header.format_version); | 87 | asset_header.format_version); |
| 85 | if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) | 88 | } |
| 89 | |||
| 90 | if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) { | ||
| 86 | return; | 91 | return; |
| 92 | } | ||
| 87 | 93 | ||
| 88 | if (asset_header.nacp.size > 0) { | 94 | if (asset_header.nacp.size > 0) { |
| 89 | nacp = std::make_unique<FileSys::NACP>(std::make_shared<FileSys::OffsetVfsFile>( | 95 | nacp = std::make_unique<FileSys::NACP>(std::make_shared<FileSys::OffsetVfsFile>( |
| @@ -101,6 +107,8 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { | |||
| 101 | } | 107 | } |
| 102 | } | 108 | } |
| 103 | 109 | ||
| 110 | AppLoader_NRO::~AppLoader_NRO() = default; | ||
| 111 | |||
| 104 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { | 112 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { |
| 105 | // Read NSO header | 113 | // Read NSO header |
| 106 | NroHeader nro_header{}; | 114 | NroHeader nro_header{}; |
| @@ -130,8 +138,9 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { | |||
| 130 | // Build program image | 138 | // Build program image |
| 131 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); | 139 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 132 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); | 140 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); |
| 133 | if (program_image.size() != PageAlignSize(nro_header.file_size)) | 141 | if (program_image.size() != PageAlignSize(nro_header.file_size)) { |
| 134 | return {}; | 142 | return {}; |
| 143 | } | ||
| 135 | 144 | ||
| 136 | for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { | 145 | for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { |
| 137 | codeset->segments[i].addr = nro_header.segments[i].offset; | 146 | codeset->segments[i].addr = nro_header.segments[i].offset; |
| @@ -187,29 +196,37 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 187 | } | 196 | } |
| 188 | 197 | ||
| 189 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { | 198 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { |
| 190 | if (icon_data.empty()) | 199 | if (icon_data.empty()) { |
| 191 | return ResultStatus::ErrorNotUsed; | 200 | return ResultStatus::ErrorNotUsed; |
| 201 | } | ||
| 202 | |||
| 192 | buffer = icon_data; | 203 | buffer = icon_data; |
| 193 | return ResultStatus::Success; | 204 | return ResultStatus::Success; |
| 194 | } | 205 | } |
| 195 | 206 | ||
| 196 | ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { | 207 | ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { |
| 197 | if (nacp == nullptr) | 208 | if (nacp == nullptr) { |
| 198 | return ResultStatus::ErrorNotUsed; | 209 | return ResultStatus::ErrorNotUsed; |
| 210 | } | ||
| 211 | |||
| 199 | out_program_id = nacp->GetTitleId(); | 212 | out_program_id = nacp->GetTitleId(); |
| 200 | return ResultStatus::Success; | 213 | return ResultStatus::Success; |
| 201 | } | 214 | } |
| 202 | 215 | ||
| 203 | ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { | 216 | ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { |
| 204 | if (romfs == nullptr) | 217 | if (romfs == nullptr) { |
| 205 | return ResultStatus::ErrorNotUsed; | 218 | return ResultStatus::ErrorNotUsed; |
| 219 | } | ||
| 220 | |||
| 206 | dir = romfs; | 221 | dir = romfs; |
| 207 | return ResultStatus::Success; | 222 | return ResultStatus::Success; |
| 208 | } | 223 | } |
| 209 | 224 | ||
| 210 | ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { | 225 | ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { |
| 211 | if (nacp == nullptr) | 226 | if (nacp == nullptr) { |
| 212 | return ResultStatus::ErrorNotUsed; | 227 | return ResultStatus::ErrorNotUsed; |
| 228 | } | ||
| 229 | |||
| 213 | title = nacp->GetApplicationName(); | 230 | title = nacp->GetApplicationName(); |
| 214 | return ResultStatus::Success; | 231 | return ResultStatus::Success; |
| 215 | } | 232 | } |