diff options
author | Lioncash <mathew1800@gmail.com> | 2019-03-22 19:00:01 +0100 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-03-22 20:25:53 +0100 |
commit | f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66 (patch) | |
tree | 17d294300c9d3e42b628bc50599e8decc2ad41d6 /src/core/loader | |
parent | loader/nso: Clean up use of magic constants (diff) | |
download | yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar.gz yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar.bz2 yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar.lz yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar.xz yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.tar.zst yuzu-f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/loader/nso.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index fc71ad189..381530add 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -21,7 +21,7 @@ #include "core/settings.h" namespace Loader { - +namespace { struct MODHeader { u32_le magic; u32_le dynamic_offset; @@ -33,6 +33,26 @@ struct MODHeader { }; static_assert(sizeof(MODHeader) == 0x1c, "MODHeader has incorrect size."); +std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, + const NSOSegmentHeader& header) { + std::vector<u8> uncompressed_data(header.size); + const int bytes_uncompressed = + LZ4_decompress_safe(reinterpret_cast<const char*>(compressed_data.data()), + reinterpret_cast<char*>(uncompressed_data.data()), + static_cast<int>(compressed_data.size()), header.size); + + ASSERT_MSG(bytes_uncompressed == static_cast<int>(header.size) && + bytes_uncompressed == static_cast<int>(uncompressed_data.size()), + "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); + + return uncompressed_data; +} + +constexpr u32 PageAlignSize(u32 size) { + return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; +} +} // Anonymous namespace + bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num); return ((flags >> segment_num) & 1) != 0; @@ -53,25 +73,6 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { return FileType::NSO; } -static std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, - const NSOSegmentHeader& header) { - std::vector<u8> uncompressed_data(header.size); - const int bytes_uncompressed = - LZ4_decompress_safe(reinterpret_cast<const char*>(compressed_data.data()), - reinterpret_cast<char*>(uncompressed_data.data()), - static_cast<int>(compressed_data.size()), header.size); - - ASSERT_MSG(bytes_uncompressed == static_cast<int>(header.size) && - bytes_uncompressed == static_cast<int>(uncompressed_data.size()), - "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); - - return uncompressed_data; -} - -static constexpr u32 PageAlignSize(u32 size) { - return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; -} - std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base, bool should_pass_arguments, |