patch_manager: Dump NSO name with build ID

This commit is contained in:
Zach Hilman 2019-03-27 20:08:56 -04:00
parent 41d2565f29
commit 552d5071fa
4 changed files with 11 additions and 9 deletions

View File

@ -156,7 +156,7 @@ std::vector<VirtualFile> PatchManager::CollectPatches(const std::vector<VirtualD
return out; return out;
} }
std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso, const std::string& name) const {
if (nso.size() < sizeof(Loader::NSOHeader)) { if (nso.size() < sizeof(Loader::NSOHeader)) {
return nso; return nso;
} }
@ -172,18 +172,19 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const {
const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1);
if (Settings::values.dump_nso) { if (Settings::values.dump_nso) {
LOG_INFO(Loader, "Dumping NSO for build_id={}, title_id={:016X}", build_id, title_id); LOG_INFO(Loader, "Dumping NSO for name={}, build_id={}, title_id={:016X}", name, build_id,
title_id);
const auto dump_dir = Service::FileSystem::GetModificationDumpRoot(title_id); const auto dump_dir = Service::FileSystem::GetModificationDumpRoot(title_id);
if (dump_dir != nullptr) { if (dump_dir != nullptr) {
const auto nso_dir = GetOrCreateDirectoryRelative(dump_dir, "/nso"); const auto nso_dir = GetOrCreateDirectoryRelative(dump_dir, "/nso");
const auto file = nso_dir->CreateFile(fmt::format("{}.nso", build_id)); const auto file = nso_dir->CreateFile(fmt::format("{}-{}.nso", name, build_id));
file->Resize(nso.size()); file->Resize(nso.size());
file->WriteBytes(nso); file->WriteBytes(nso);
} }
} }
LOG_INFO(Loader, "Patching NSO for build_id={}", build_id); LOG_INFO(Loader, "Patching NSO for name={}, build_id={}", name, build_id);
const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id);
auto patch_dirs = load_dir->GetSubdirectories(); auto patch_dirs = load_dir->GetSubdirectories();

View File

@ -44,7 +44,7 @@ public:
// Currently tracked NSO patches: // Currently tracked NSO patches:
// - IPS // - IPS
// - IPSwitch // - IPSwitch
std::vector<u8> PatchNSO(const std::vector<u8>& nso) const; std::vector<u8> PatchNSO(const std::vector<u8>& nso, const std::string& name) const;
// Checks to see if PatchNSO() will have any effect given the NSO's build ID. // Checks to see if PatchNSO() will have any effect given the NSO's build ID.
// Used to prevent expensive copies in NSO loader. // Used to prevent expensive copies in NSO loader.

View File

@ -154,8 +154,7 @@ void WebBrowser::Execute() {
auto& frontend{Core::System::GetInstance().GetWebBrowser()}; auto& frontend{Core::System::GetInstance().GetWebBrowser()};
frontend.OpenPage( frontend.OpenPage(filename, [this] { UnpackRomFS(); }, [this] { Finalize(); });
filename, [this] { UnpackRomFS(); }, [this] { Finalize(); });
} }
void WebBrowser::UnpackRomFS() { void WebBrowser::UnpackRomFS() {

View File

@ -20,6 +20,8 @@
#include "core/memory.h" #include "core/memory.h"
#include "core/settings.h" #include "core/settings.h"
#pragma optimize("", off)
namespace Loader { namespace Loader {
namespace { namespace {
struct MODHeader { struct MODHeader {
@ -139,13 +141,13 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
// Apply patches if necessary // Apply patches if necessary
if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) { if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
std::vector<u8> pi_header(sizeof(NSOHeader) + program_image.size()); std::vector<u8> pi_header;
pi_header.insert(pi_header.begin(), reinterpret_cast<u8*>(&nso_header), pi_header.insert(pi_header.begin(), reinterpret_cast<u8*>(&nso_header),
reinterpret_cast<u8*>(&nso_header) + sizeof(NSOHeader)); reinterpret_cast<u8*>(&nso_header) + sizeof(NSOHeader));
pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.begin(), pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.begin(),
program_image.end()); program_image.end());
pi_header = pm->PatchNSO(pi_header); pi_header = pm->PatchNSO(pi_header, file.GetName());
std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.begin()); std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.begin());
} }