From 72eb16f9334461fb474b3484c227f1d0353ff5a7 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Tue, 15 Apr 2025 16:27:32 +0200 Subject: [PATCH] Fix ncch loader building wrong update title ID (#930) --- src/core/hle/service/am/am.cpp | 6 +++--- src/core/loader/ncch.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 50b5a6b25..3dc76067c 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -2104,7 +2104,7 @@ void Module::Interface::GetPatchTitleInfos(Kernel::HLERequestContext& ctx) { std::vector title_id_list; Result res{0}; - std::vector out; + std::vector out; Kernel::MappedBuffer* title_id_list_buffer; Kernel::MappedBuffer* title_info_out; }; @@ -2144,7 +2144,7 @@ void Module::Interface::GetPatchTitleInfos(Kernel::HLERequestContext& ctx) { return 0; } - async_data->out.resize(title_infos->second); + async_data->out.resize(title_infos->second / sizeof(TitleInfo)); memcpy(async_data->out.data(), title_infos->first, title_infos->second); return 0; }, @@ -2156,7 +2156,7 @@ void Module::Interface::GetPatchTitleInfos(Kernel::HLERequestContext& ctx) { rb.PushMappedBuffer(*async_data->title_info_out); } else { async_data->title_info_out->Write(async_data->out.data(), 0, - async_data->out.size()); + async_data->out.size() * sizeof(TitleInfo)); IPC::RequestBuilder rb(ctx, 1, 4); rb.Push(async_data->res); diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index a2ce7327e..9ecf64685 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -32,7 +32,7 @@ namespace Loader { using namespace Common::Literals; -static const u64 UPDATE_MASK = 0x0000000e00000000; +static constexpr u64 UPDATE_TID_HIGH = 0x0004000e00000000; FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { u32 magic; @@ -283,8 +283,9 @@ ResultStatus AppLoader_NCCH::Load(std::shared_ptr& process) { LOG_INFO(Loader, "Program ID: {}", program_id); - update_ncch.OpenFile(Service::AM::GetTitleContentPath(Service::FS::MediaType::SDMC, - ncch_program_id | UPDATE_MASK)); + u64 update_tid = (ncch_program_id & 0xFFFFFFFFULL) | UPDATE_TID_HIGH; + update_ncch.OpenFile( + Service::AM::GetTitleContentPath(Service::FS::MediaType::SDMC, update_tid)); result = update_ncch.Load(); if (result == ResultStatus::Success) { overlay_ncch = &update_ncch; @@ -371,8 +372,9 @@ ResultStatus AppLoader_NCCH::DumpRomFS(const std::string& target_path) { ResultStatus AppLoader_NCCH::DumpUpdateRomFS(const std::string& target_path) { u64 program_id; ReadProgramId(program_id); + u64 update_tid = (program_id & 0xFFFFFFFFULL) | UPDATE_TID_HIGH; update_ncch.OpenFile( - Service::AM::GetTitleContentPath(Service::FS::MediaType::SDMC, program_id | UPDATE_MASK)); + Service::AM::GetTitleContentPath(Service::FS::MediaType::SDMC, update_tid)); return update_ncch.DumpRomFS(target_path); }