Added support for uncompressed NSOs (#1374)
* Added support for uncompressed NSOs * Moved compressed section check to NsoHeader
This commit is contained in:
parent
8606995515
commit
1db1e013e0
|
@ -32,11 +32,18 @@ static_assert(sizeof(NsoSegmentHeader) == 0x10, "NsoSegmentHeader has incorrect
|
||||||
|
|
||||||
struct NsoHeader {
|
struct NsoHeader {
|
||||||
u32_le magic;
|
u32_le magic;
|
||||||
INSERT_PADDING_BYTES(0xc);
|
u32_le version;
|
||||||
|
INSERT_PADDING_WORDS(1);
|
||||||
|
u8 flags;
|
||||||
std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order)
|
std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order)
|
||||||
u32_le bss_size;
|
u32_le bss_size;
|
||||||
INSERT_PADDING_BYTES(0x1c);
|
INSERT_PADDING_BYTES(0x1c);
|
||||||
std::array<u32_le, 3> segments_compressed_size;
|
std::array<u32_le, 3> 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(sizeof(NsoHeader) == 0x6c, "NsoHeader has incorrect size.");
|
||||||
static_assert(std::is_trivially_copyable_v<NsoHeader>, "NsoHeader isn't trivially copyable.");
|
static_assert(std::is_trivially_copyable_v<NsoHeader>, "NsoHeader isn't trivially copyable.");
|
||||||
|
@ -105,9 +112,11 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) {
|
||||||
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(kernel, "");
|
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(kernel, "");
|
||||||
std::vector<u8> program_image;
|
std::vector<u8> program_image;
|
||||||
for (std::size_t i = 0; i < nso_header.segments.size(); ++i) {
|
for (std::size_t i = 0; i < nso_header.segments.size(); ++i) {
|
||||||
const std::vector<u8> compressed_data =
|
std::vector<u8> data =
|
||||||
file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset);
|
file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset);
|
||||||
std::vector<u8> 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.resize(nso_header.segments[i].location);
|
||||||
program_image.insert(program_image.end(), data.begin(), data.end());
|
program_image.insert(program_image.end(), data.begin(), data.end());
|
||||||
codeset->segments[i].addr = nso_header.segments[i].location;
|
codeset->segments[i].addr = nso_header.segments[i].location;
|
||||||
|
|
Reference in New Issue