IOS/ES: Use FindInstalledTMD instead of content loader

Proper semantics.

IOS only cares about the TMD and nothing else, so we should use
FindInstalledTMD, instead of reading/parsing/decrypting a bunch of
useless stuff, which is slow *and* causes issues because of the cache.
This commit is contained in:
Léo Lam 2017-03-17 18:59:04 +01:00
parent 8984112501
commit 98e27ad9cb
3 changed files with 34 additions and 42 deletions

View File

@ -67,10 +67,10 @@ IPCCommandResult ES::GetStoredContentsCount(const IOCtlVRequest& request)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address);
const DiscIO::CNANDContentLoader& content_loader = AccessContentDevice(title_id); const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id);
if (!content_loader.IsValid()) if (!tmd.IsValid())
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(FS_ENOENT);
return GetStoredContentsCount(content_loader.GetTMD(), request); return GetStoredContentsCount(tmd, request);
} }
IPCCommandResult ES::GetStoredContents(const IOCtlVRequest& request) IPCCommandResult ES::GetStoredContents(const IOCtlVRequest& request)
@ -79,10 +79,10 @@ IPCCommandResult ES::GetStoredContents(const IOCtlVRequest& request)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address);
const DiscIO::CNANDContentLoader& content_loader = AccessContentDevice(title_id); const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id);
if (!content_loader.IsValid()) if (!tmd.IsValid())
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(FS_ENOENT);
return GetStoredContents(content_loader.GetTMD(), request); return GetStoredContents(tmd, request);
} }
IPCCommandResult ES::GetTMDStoredContentsCount(const IOCtlVRequest& request) IPCCommandResult ES::GetTMDStoredContentsCount(const IOCtlVRequest& request)
@ -146,17 +146,15 @@ IPCCommandResult ES::GetStoredTMDSize(const IOCtlVRequest& request)
if (!request.HasNumberOfValidVectors(1, 1)) if (!request.HasNumberOfValidVectors(1, 1))
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address);
const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id);
if (!tmd.IsValid())
if (!Loader.IsValid() || !Loader.GetTMD().IsValid())
return GetDefaultReply(FS_ENOENT); return GetDefaultReply(FS_ENOENT);
const u32 tmd_size = static_cast<u32>(Loader.GetTMD().GetRawTMD().size()); const u32 tmd_size = static_cast<u32>(tmd.GetRawTMD().size());
Memory::Write_U32(tmd_size, request.io_vectors[0].address); Memory::Write_U32(tmd_size, request.io_vectors[0].address);
INFO_LOG(IOS_ES, "IOCTL_ES_GETSTOREDTMDSIZE: title: %08x/%08x (view size %i)", INFO_LOG(IOS_ES, "GetStoredTMDSize: %u bytes for %016" PRIx64, tmd_size, title_id);
(u32)(TitleID >> 32), (u32)TitleID, tmd_size);
return GetDefaultReply(IPC_SUCCESS); return GetDefaultReply(IPC_SUCCESS);
} }
@ -166,22 +164,21 @@ IPCCommandResult ES::GetStoredTMD(const IOCtlVRequest& request)
if (!request.HasNumberOfValidVectors(2, 1)) if (!request.HasNumberOfValidVectors(2, 1))
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address);
// TODO: actually use this param in when writing to the outbuffer :/ const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id);
const u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address); if (!tmd.IsValid())
const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID);
if (!Loader.IsValid() || !Loader.GetTMD().IsValid())
return GetDefaultReply(FS_ENOENT); return GetDefaultReply(FS_ENOENT);
const std::vector<u8> raw_tmd = Loader.GetTMD().GetRawTMD(); // TODO: actually use this param in when writing to the outbuffer :/
const u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address);
const std::vector<u8> raw_tmd = tmd.GetRawTMD();
if (raw_tmd.size() != request.io_vectors[0].size) if (raw_tmd.size() != request.io_vectors[0].size)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
Memory::CopyToEmu(request.io_vectors[0].address, raw_tmd.data(), raw_tmd.size()); Memory::CopyToEmu(request.io_vectors[0].address, raw_tmd.data(), raw_tmd.size());
INFO_LOG(IOS_ES, "IOCTL_ES_GETSTOREDTMD: title: %08x/%08x (buffer size: %i)", INFO_LOG(IOS_ES, "GetStoredTMD: title %016" PRIx64 " (buffer size: %u)", title_id, MaxCount);
(u32)(TitleID >> 32), (u32)TitleID, MaxCount);
return GetDefaultReply(IPC_SUCCESS); return GetDefaultReply(IPC_SUCCESS);
} }

View File

@ -19,6 +19,7 @@
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
#include "Core/IOS/ES/NandUtils.h"
#include "Core/ec_wii.h" #include "Core/ec_wii.h"
#include "DiscIO/NANDContentLoader.h" #include "DiscIO/NANDContentLoader.h"
@ -403,13 +404,11 @@ IPCCommandResult ES::ExportTitleInit(const IOCtlVRequest& request)
if (m_export_title_context.valid) if (m_export_title_context.valid)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
const auto& content_loader = AccessContentDevice(Memory::Read_U64(request.in_vectors[0].address)); const auto tmd = IOS::ES::FindInstalledTMD(Memory::Read_U64(request.in_vectors[0].address));
if (!content_loader.IsValid()) if (!tmd.IsValid())
return GetDefaultReply(FS_ENOENT); return GetDefaultReply(FS_ENOENT);
if (!content_loader.GetTMD().IsValid())
return GetDefaultReply(ES_INVALID_TMD);
m_export_title_context.tmd = content_loader.GetTMD(); m_export_title_context.tmd = tmd;
const auto ticket = DiscIO::FindSignedTicket(m_export_title_context.tmd.GetTitleId()); const auto ticket = DiscIO::FindSignedTicket(m_export_title_context.tmd.GetTitleId());
if (!ticket.IsValid()) if (!ticket.IsValid())

View File

@ -14,6 +14,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
#include "Core/IOS/ES/NandUtils.h"
#include "DiscIO/NANDContentLoader.h" #include "DiscIO/NANDContentLoader.h"
namespace IOS namespace IOS
@ -96,16 +97,15 @@ IPCCommandResult ES::GetTMDViewSize(const IOCtlVRequest& request)
u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); u64 TitleID = Memory::Read_U64(request.in_vectors[0].address);
const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(TitleID);
if (!Loader.IsValid()) if (!tmd.IsValid())
return GetDefaultReply(FS_ENOENT); return GetDefaultReply(FS_ENOENT);
const u32 view_size = static_cast<u32>(Loader.GetTMD().GetRawView().size()); const u32 view_size = static_cast<u32>(tmd.GetRawView().size());
Memory::Write_U32(view_size, request.io_vectors[0].address); Memory::Write_U32(view_size, request.io_vectors[0].address);
INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x (view size %i)", (u32)(TitleID >> 32), INFO_LOG(IOS_ES, "GetTMDViewSize: %u bytes for title %016" PRIx64, view_size, TitleID);
(u32)TitleID, view_size);
return GetDefaultReply(IPC_SUCCESS); return GetDefaultReply(IPC_SUCCESS);
} }
@ -117,22 +117,18 @@ IPCCommandResult ES::GetTMDViews(const IOCtlVRequest& request)
u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); u64 TitleID = Memory::Read_U64(request.in_vectors[0].address);
u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address); u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address);
const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(TitleID);
INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x buffer size: %i", if (!tmd.IsValid())
(u32)(TitleID >> 32), (u32)TitleID, MaxCount);
if (!Loader.IsValid())
return GetDefaultReply(FS_ENOENT); return GetDefaultReply(FS_ENOENT);
const std::vector<u8> raw_view = Loader.GetTMD().GetRawView(); const std::vector<u8> raw_view = tmd.GetRawView();
if (raw_view.size() != request.io_vectors[0].size) if (raw_view.size() != request.io_vectors[0].size)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
Memory::CopyToEmu(request.io_vectors[0].address, raw_view.data(), raw_view.size()); Memory::CopyToEmu(request.io_vectors[0].address, raw_view.data(), raw_view.size());
INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWS: title: %08x/%08x (buffer size: %i)", (u32)(TitleID >> 32), INFO_LOG(IOS_ES, "GetTMDView: %u bytes for title %016" PRIx64, MaxCount, TitleID);
(u32)TitleID, MaxCount);
return GetDefaultReply(IPC_SUCCESS); return GetDefaultReply(IPC_SUCCESS);
} }