From 56aa3cc558ead7c0e23362df2ac96131140566f0 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Wed, 16 Aug 2017 03:36:53 +0200 Subject: [PATCH] WFSI: Implement both GET_TMD ioctls. --- Source/Core/Core/IOS/WFS/WFSI.cpp | 49 +++++++++++++++++++++++++++++++ Source/Core/Core/IOS/WFS/WFSI.h | 4 +++ 2 files changed, 53 insertions(+) diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index 20aea24975..cf8df1e8a6 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -4,6 +4,7 @@ #include "Core/IOS/WFS/WFSI.h" +#include #include #include #include @@ -248,6 +249,33 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) break; + case IOCTL_WFSI_GET_TMD: + { + u64 subtitle_id = Memory::Read_U64(request.buffer_in); + u32 address = Memory::Read_U32(request.buffer_in + 24); + INFO_LOG(IOS, "IOCTL_WFSI_GET_TMD: subtitle ID %016" PRIx64, subtitle_id); + + u32 tmd_size; + return_error_code = GetTmd(m_group_id, m_title_id, subtitle_id, address, &tmd_size); + Memory::Write_U32(tmd_size, request.buffer_out); + break; + } + + case IOCTL_WFSI_GET_TMD_ABSOLUTE: + { + u64 subtitle_id = Memory::Read_U64(request.buffer_in); + u32 address = Memory::Read_U32(request.buffer_in + 24); + u16 group_id = Memory::Read_U16(request.buffer_in + 36); + u32 title_id = Memory::Read_U32(request.buffer_in + 32); + INFO_LOG(IOS, "IOCTL_WFSI_GET_TMD_ABSOLUTE: tid %08x, gid %04x, subtitle ID %016" PRIx64, + title_id, group_id, subtitle_id); + + u32 tmd_size; + return_error_code = GetTmd(group_id, title_id, subtitle_id, address, &tmd_size); + Memory::Write_U32(tmd_size, request.buffer_out); + break; + } + case IOCTL_WFSI_SET_FST_BUFFER: { INFO_LOG(IOS, "IOCTL_WFSI_SET_FST_BUFFER: address %08x, size %08x", request.buffer_in, @@ -309,6 +337,27 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) return GetDefaultReply(return_error_code); } + +u32 WFSI::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32* size) const +{ + // TODO(wfs): This is using a separate copy of tid/gid in wfssrv. Why? + std::string path = + StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd", m_device_name.c_str(), + m_group_id_str.c_str(), m_title_id_str.c_str(), subtitle_id); + File::IOFile fp(WFS::NativePath(path), "rb"); + if (!fp) + { + WARN_LOG(IOS, "GetTmd: no such file or directory: %s", path.c_str()); + return WFSI_ENOENT; + } + if (address) + { + fp.ReadBytes(Memory::GetPointer(address), fp.GetSize()); + } + *size = fp.GetSize(); + return IPC_SUCCESS; +} + } // namespace Device } // namespace HLE } // namespace IOS diff --git a/Source/Core/Core/IOS/WFS/WFSI.h b/Source/Core/Core/IOS/WFS/WFSI.h index 24e942a01d..8945de1ce8 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.h +++ b/Source/Core/Core/IOS/WFS/WFSI.h @@ -44,6 +44,7 @@ public: IPCCommandResult IOCtl(const IOCtlRequest& request) override; private: + u32 GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32* size) const; std::string m_device_name; mbedtls_aes_context m_aes_ctx; @@ -84,6 +85,9 @@ private: IOCTL_WFSI_APPLY_TITLE_PROFILE = 0x89, + IOCTL_WFSI_GET_TMD = 0x8a, + IOCTL_WFSI_GET_TMD_ABSOLUTE = 0x8b, + IOCTL_WFSI_SET_FST_BUFFER = 0x8e, IOCTL_WFSI_LOAD_DOL = 0x90,