From 689ed2a0ce95b743f73ae57cfb044cb4c100549f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 1 Oct 2017 16:45:18 +0200 Subject: [PATCH] [Cleanup] Move FindSignedTicket to IOS/ES For consistency and because NANDContentManager is going to be removed. --- Source/Core/Core/IOS/ES/ES.cpp | 2 +- Source/Core/Core/IOS/ES/ES.h | 1 + Source/Core/Core/IOS/ES/NandUtils.cpp | 14 ++++++++++++++ Source/Core/Core/IOS/ES/TitleManagement.cpp | 4 ++-- Source/Core/Core/IOS/ES/Views.cpp | 6 +++--- Source/Core/Core/IOS/WFS/WFSI.cpp | 2 +- Source/Core/Core/WiiUtils.cpp | 6 +++--- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 64fa54930e..eaefd60fef 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -684,7 +684,7 @@ ReturnCode ES::SetUpStreamKey(const u32 uid, const u8* ticket_view, const IOS::E // Find a signed ticket from the view. const u64 ticket_id = Common::swap64(&ticket_view[offsetof(IOS::ES::TicketView, ticket_id)]); const u64 title_id = Common::swap64(&ticket_view[offsetof(IOS::ES::TicketView, title_id)]); - const IOS::ES::TicketReader installed_ticket = DiscIO::FindSignedTicket(title_id); + const IOS::ES::TicketReader installed_ticket = FindSignedTicket(title_id); // Unlike the other "get ticket from view" function, this returns a FS error, not ES_NO_TICKET. if (!installed_ticket.IsValid()) return FS_ENOENT; diff --git a/Source/Core/Core/IOS/ES/ES.h b/Source/Core/Core/IOS/ES/ES.h index 41b3dbd559..e6287e6826 100644 --- a/Source/Core/Core/IOS/ES/ES.h +++ b/Source/Core/Core/IOS/ES/ES.h @@ -85,6 +85,7 @@ public: IOS::ES::TMDReader FindImportTMD(u64 title_id) const; IOS::ES::TMDReader FindInstalledTMD(u64 title_id) const; + IOS::ES::TicketReader FindSignedTicket(u64 title_id) const; // Get installed titles (in /title) without checking for TMDs at all. std::vector GetInstalledTitles() const; diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index b82d5daae4..a5afa0d571 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -50,6 +50,20 @@ IOS::ES::TMDReader ES::FindInstalledTMD(u64 title_id) const return FindTMD(title_id, Common::GetTMDFileName(title_id, Common::FROM_SESSION_ROOT)); } +IOS::ES::TicketReader ES::FindSignedTicket(u64 title_id) const +{ + const std::string path = Common::GetTicketFileName(title_id, Common::FROM_SESSION_ROOT); + File::IOFile ticket_file(path, "rb"); + if (!ticket_file) + return {}; + + std::vector signed_ticket(ticket_file.GetSize()); + if (!ticket_file.ReadBytes(signed_ticket.data(), signed_ticket.size())) + return {}; + + return IOS::ES::TicketReader{std::move(signed_ticket)}; +} + static bool IsValidPartOfTitleID(const std::string& string) { if (string.length() != 8) diff --git a/Source/Core/Core/IOS/ES/TitleManagement.cpp b/Source/Core/Core/IOS/ES/TitleManagement.cpp index d571465094..de2fad3bc8 100644 --- a/Source/Core/Core/IOS/ES/TitleManagement.cpp +++ b/Source/Core/Core/IOS/ES/TitleManagement.cpp @@ -220,7 +220,7 @@ ReturnCode ES::ImportTitleInit(Context& context, const std::vector& tmd_byte if (ret != IPC_SUCCESS) return ret; - const auto ticket = DiscIO::FindSignedTicket(context.title_import_export.tmd.GetTitleId()); + const auto ticket = FindSignedTicket(context.title_import_export.tmd.GetTitleId()); if (!ticket.IsValid()) return ES_NO_TICKET; @@ -528,7 +528,7 @@ ReturnCode ES::DeleteTicket(const u8* ticket_view) if (!CanDeleteTitle(title_id)) return ES_EINVAL; - auto ticket = DiscIO::FindSignedTicket(title_id); + auto ticket = FindSignedTicket(title_id); if (!ticket.IsValid()) return FS_ENOENT; diff --git a/Source/Core/Core/IOS/ES/Views.cpp b/Source/Core/Core/IOS/ES/Views.cpp index 08e0e1ed3b..8eb32ee326 100644 --- a/Source/Core/Core/IOS/ES/Views.cpp +++ b/Source/Core/Core/IOS/ES/Views.cpp @@ -49,7 +49,7 @@ IPCCommandResult ES::GetTicketViewCount(const IOCtlVRequest& request) u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); - const IOS::ES::TicketReader ticket = DiscIO::FindSignedTicket(TitleID); + const IOS::ES::TicketReader ticket = FindSignedTicket(TitleID); u32 view_count = ticket.IsValid() ? static_cast(ticket.GetNumberOfTickets()) : 0; if (ShouldReturnFakeViewsForIOSes(TitleID, m_title_context)) @@ -73,7 +73,7 @@ IPCCommandResult ES::GetTicketViews(const IOCtlVRequest& request) u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); u32 maxViews = Memory::Read_U32(request.in_vectors[1].address); - const IOS::ES::TicketReader ticket = DiscIO::FindSignedTicket(TitleID); + const IOS::ES::TicketReader ticket = FindSignedTicket(TitleID); if (ticket.IsValid()) { @@ -102,7 +102,7 @@ ReturnCode ES::GetV0TicketFromView(const u8* ticket_view, u8* ticket) const const u64 title_id = Common::swap64(&ticket_view[offsetof(IOS::ES::TicketView, title_id)]); const u64 ticket_id = Common::swap64(&ticket_view[offsetof(IOS::ES::TicketView, ticket_id)]); - const auto installed_ticket = DiscIO::FindSignedTicket(title_id); + const auto installed_ticket = FindSignedTicket(title_id); // TODO: when we get std::optional, check for presence instead of validity. // This is close enough, though. if (!installed_ticket.IsValid()) diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index a0d8610bde..d296045c7a 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -157,7 +157,7 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) Memory::CopyFromEmu(tmd_bytes.data(), tmd_addr, tmd_size); m_tmd.SetBytes(std::move(tmd_bytes)); - IOS::ES::TicketReader ticket = DiscIO::FindSignedTicket(m_tmd.GetTitleId()); + IOS::ES::TicketReader ticket = m_ios.GetES()->FindSignedTicket(m_tmd.GetTitleId()); if (!ticket.IsValid()) { return_error_code = -11028; diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index 63f50a1ea2..f59164472f 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -670,7 +670,7 @@ UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs, return UpdateResult::AlreadyUpToDate; const IOS::ES::TMDReader tmd = m_ios.GetES()->FindInstalledTMD(title.id); - const IOS::ES::TicketReader ticket = DiscIO::FindSignedTicket(title.id); + const IOS::ES::TicketReader ticket = m_ios.GetES()->FindSignedTicket(title.id); // Optional titles can be skipped if the ticket is present, even when the title isn't installed. if (attrs.test(16) && ticket.IsValid()) @@ -735,7 +735,7 @@ NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios) } // Check for incomplete title installs (missing ticket, TMD or contents). - const auto ticket = DiscIO::FindSignedTicket(title_id); + const auto ticket = es->FindSignedTicket(title_id); if (!IOS::ES::IsDiscTitle(title_id) && !ticket.IsValid()) { ERROR_LOG(CORE, "CheckNAND: Missing ticket for title %016" PRIx64, title_id); @@ -801,7 +801,7 @@ bool RepairNAND(IOS::HLE::Kernel& ios) const auto content_files = File::ScanDirectoryTree(content_dir, false).children; const bool has_no_tmd_but_contents = !es->FindInstalledTMD(title_id).IsValid() && !content_files.empty(); - if (has_no_tmd_but_contents || !DiscIO::FindSignedTicket(title_id).IsValid()) + if (has_no_tmd_but_contents || !es->FindSignedTicket(title_id).IsValid()) { const std::string title_dir = Common::GetTitlePath(title_id, Common::FROM_CONFIGURED_ROOT); File::DeleteDirRecursively(title_dir);