From 44a3db21e4b7fe20ee2ed6253990f5981b3f12f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 14 Feb 2017 13:15:02 +0100 Subject: [PATCH] ES: Make sure the TMD and ticket are valid before use --- Source/Core/Core/IOS/ES/ES.cpp | 12 ++++++------ Source/Core/DiscIO/NANDContentLoader.cpp | 5 +++++ Source/Core/DiscIO/NANDContentLoader.h | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index a496837c63..57a430e7a3 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -186,7 +186,7 @@ u32 ES::OpenTitleContent(u32 CFD, u64 TitleID, u16 Index) { const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); - if (!Loader.IsValid()) + if (!Loader.IsValid() || !Loader.GetTicket().IsValid()) { WARN_LOG(IOS_ES, "ES: loader not valid for %" PRIx64, TitleID); return 0xffffffff; @@ -501,11 +501,11 @@ IPCCommandResult ES::GetTitleContents(const IOCtlVRequest& request) if (!rNANDContent.IsValid()) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - for (const auto& content : rNANDContent.GetContent()) + for (const auto& content : rNANDContent.GetTMD().GetContents()) { - const u16 index = content.m_metadata.index; - Memory::Write_U32(content.m_metadata.id, request.io_vectors[0].address + index * 4); - INFO_LOG(IOS_ES, "IOCTL_ES_GETTITLECONTENTS: Index %d: %08x", index, content.m_metadata.id); + const u16 index = content.index; + Memory::Write_U32(content.id, request.io_vectors[0].address + index * 4); + INFO_LOG(IOS_ES, "IOCTL_ES_GETTITLECONTENTS: Index %d: %08x", index, content.id); } return GetDefaultReply(IPC_SUCCESS); @@ -568,7 +568,7 @@ IPCCommandResult ES::ReadContent(const IOCtlVRequest& request) { const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(rContent.m_TitleID); // ContentLoader should never be invalid; rContent has been created by it. - if (ContentLoader.IsValid()) + if (ContentLoader.IsValid() && ContentLoader.GetTicket().IsValid()) { const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(rContent.m_Index); if (!pContent->m_Data->GetRange(rContent.m_Position, Size, pDest)) diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index 62e2e174cb..1204550fab 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -156,6 +156,11 @@ CNANDContentLoader::~CNANDContentLoader() { } +bool CNANDContentLoader::IsValid() const +{ + return m_Valid && m_tmd.IsValid(); +} + const SNANDContent* CNANDContentLoader::GetContentByIndex(int index) const { for (auto& Content : m_Content) diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h index e945e7dcb5..ca9b8fe78d 100644 --- a/Source/Core/DiscIO/NANDContentLoader.h +++ b/Source/Core/DiscIO/NANDContentLoader.h @@ -77,7 +77,7 @@ public: explicit CNANDContentLoader(const std::string& content_name); ~CNANDContentLoader(); - bool IsValid() const { return m_Valid; } + bool IsValid() const; void RemoveTitle() const; const SNANDContent* GetContentByIndex(int index) const; const IOS::ES::TMDReader& GetTMD() const { return m_tmd; }