From 1db1e013e0f8f3383e486d4f47d88d1bdb6e2769 Mon Sep 17 00:00:00 2001 From: David <25727384+ogniK5377@users.noreply.github.com> Date: Fri, 21 Sep 2018 14:39:30 +1000 Subject: [PATCH] Added support for uncompressed NSOs (#1374) * Added support for uncompressed NSOs * Moved compressed section check to NsoHeader --- src/core/loader/nso.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 3c6306818b..78a4438c47 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -32,11 +32,18 @@ static_assert(sizeof(NsoSegmentHeader) == 0x10, "NsoSegmentHeader has incorrect struct NsoHeader { u32_le magic; - INSERT_PADDING_BYTES(0xc); + u32_le version; + INSERT_PADDING_WORDS(1); + u8 flags; std::array segments; // Text, RoData, Data (in that order) u32_le bss_size; INSERT_PADDING_BYTES(0x1c); std::array segments_compressed_size; + + bool IsSegmentCompressed(size_t segment_num) const { + ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num); + return ((flags >> segment_num) & 1); + } }; static_assert(sizeof(NsoHeader) == 0x6c, "NsoHeader has incorrect size."); static_assert(std::is_trivially_copyable_v, "NsoHeader isn't trivially copyable."); @@ -105,9 +112,11 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { Kernel::SharedPtr codeset = Kernel::CodeSet::Create(kernel, ""); std::vector program_image; for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { - const std::vector compressed_data = + std::vector data = file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); - std::vector data = DecompressSegment(compressed_data, nso_header.segments[i]); + if (nso_header.IsSegmentCompressed(i)) { + data = DecompressSegment(data, nso_header.segments[i]); + } program_image.resize(nso_header.segments[i].location); program_image.insert(program_image.end(), data.begin(), data.end()); codeset->segments[i].addr = nso_header.segments[i].location;