|
@@ -21,7 +21,7 @@
|
|
|
#include "core/settings.h"
|
|
#include "core/settings.h"
|
|
|
|
|
|
|
|
namespace Loader {
|
|
namespace Loader {
|
|
|
-
|
|
|
|
|
|
|
+namespace {
|
|
|
struct MODHeader {
|
|
struct MODHeader {
|
|
|
u32_le magic;
|
|
u32_le magic;
|
|
|
u32_le dynamic_offset;
|
|
u32_le dynamic_offset;
|
|
@@ -33,6 +33,26 @@ struct MODHeader {
|
|
|
};
|
|
};
|
|
|
static_assert(sizeof(MODHeader) == 0x1c, "MODHeader has incorrect size.");
|
|
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 {
|
|
bool NSOHeader::IsSegmentCompressed(size_t segment_num) const {
|
|
|
ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num);
|
|
ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num);
|
|
|
return ((flags >> segment_num) & 1) != 0;
|
|
return ((flags >> segment_num) & 1) != 0;
|
|
@@ -53,25 +73,6 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) {
|
|
|
return FileType::NSO;
|
|
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,
|
|
std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
|
|
|
const FileSys::VfsFile& file, VAddr load_base,
|
|
const FileSys::VfsFile& file, VAddr load_base,
|
|
|
bool should_pass_arguments,
|
|
bool should_pass_arguments,
|