From ef7b2237d9c2980fc8e1968ad68baafa6a41516e Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 23 Oct 2018 18:35:20 -0400 Subject: [PATCH] nro: Make LoadNro method accessible outside of apploader code. --- src/core/loader/nro.cpp | 21 +++++++++++++++------ src/core/loader/nro.h | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 243b499f2..bc8e402a8 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -127,18 +127,23 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { - // Read NSO header - NroHeader nro_header{}; - if (sizeof(NroHeader) != file.ReadObject(&nro_header)) { +/*static*/ bool AppLoader_NRO::LoadNro(const std::vector& data, const std::string& name, + VAddr load_base) { + + if (data.size() < sizeof(NroHeader)) { return {}; } + + // Read NSO header + NroHeader nro_header{}; + std::memcpy(&nro_header, data.data(), sizeof(NroHeader)); if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { return {}; } // Build program image - std::vector program_image = file.ReadBytes(PageAlignSize(nro_header.file_size)); + std::vector program_image(PageAlignSize(nro_header.file_size)); + std::memcpy(program_image.data(), data.data(), program_image.size()); if (program_image.size() != PageAlignSize(nro_header.file_size)) { return {}; } @@ -182,11 +187,15 @@ bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); // Register module with GDBStub - GDBStub::RegisterModule(file.GetName(), load_base, load_base); + GDBStub::RegisterModule(name, load_base, load_base); return true; } +bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { + return AppLoader_NRO::LoadNro(file.ReadAllBytes(), file.GetName(), load_base); +} + ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 50ee5a78a..3e6959302 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -40,6 +41,8 @@ public: ResultStatus ReadTitle(std::string& title) override; bool IsRomFSUpdatable() const override; + static bool LoadNro(const std::vector& data, const std::string& name, VAddr load_base); + private: bool LoadNro(const FileSys::VfsFile& file, VAddr load_base);