From f351280061635f455e783e07fa9616fb872de1c0 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 1 Dec 2018 12:40:43 +0400 Subject: [PATCH 1/3] WFSI: Implement IOCTL_WFSI_CHANGE_TITLE --- Source/Core/Core/IOS/WFS/WFSI.cpp | 28 ++++++++++++++++++++++++++++ Source/Core/Core/IOS/WFS/WFSI.h | 1 + Source/Core/Core/IOS/WFS/WFSSRV.cpp | 5 +++++ Source/Core/Core/IOS/WFS/WFSSRV.h | 1 + 4 files changed, 35 insertions(+) diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index 50eca7a2ac..0694ca0c42 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -18,6 +18,7 @@ #include "Core/HW/Memmap.h" #include "Core/IOS/ES/ES.h" #include "Core/IOS/ES/Formats.h" +#include "Core/IOS/IOS.h" #include "Core/IOS/WFS/WFSSRV.h" namespace @@ -308,6 +309,33 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) WARN_LOG(IOS_WFS, "IOCTL_WFSI_DELETE_TITLE: unimplemented"); break; + case IOCTL_WFSI_CHANGE_TITLE: + { + u64 title_id = Memory::Read_U64(request.buffer_in); + u16 group_id = Memory::Read_U16(request.buffer_in + 0x1C); + + // TODO: Handle permissions + SetCurrentTitleIdAndGroupId(title_id, group_id); + + // Change home directory + const std::string homedir_path = + StringFromFormat("/vol/%s/title/%s/%s/", m_device_name.c_str(), + m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); + const u16 homedir_path_len = static_cast(homedir_path.size()); + INFO_LOG(IOS_WFS, "IOCTL_WFSI_CHANGE_TITLE: %s (path_len: 0x%x)", homedir_path.c_str(), + homedir_path_len); + + return_error_code = -3; + if (homedir_path_len > 0x1FD) + break; + auto device = IOS::HLE::GetIOS()->GetDeviceByName("/dev/usb/wfssrv"); + if (!device) + break; + std::static_pointer_cast(device)->SetHomeDir(homedir_path); + return_error_code = IPC_SUCCESS; + break; + } + case IOCTL_WFSI_GET_VERSION: INFO_LOG(IOS_WFS, "IOCTL_WFSI_GET_VERSION"); Memory::Write_U32(0x20, request.buffer_out); diff --git a/Source/Core/Core/IOS/WFS/WFSI.h b/Source/Core/Core/IOS/WFS/WFSI.h index 949c075fbb..c862493775 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.h +++ b/Source/Core/Core/IOS/WFS/WFSI.h @@ -95,6 +95,7 @@ private: IOCTL_WFSI_FINALIZE_TITLE_INSTALL = 0x06, IOCTL_WFSI_DELETE_TITLE = 0x17, + IOCTL_WFSI_CHANGE_TITLE = 0x18, IOCTL_WFSI_GET_VERSION = 0x1b, diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index 352a7ef171..d09c91b0e4 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -383,6 +383,11 @@ s32 WFSSRV::Rename(std::string source, std::string dest) const return IPC_SUCCESS; } +void WFSSRV::SetHomeDir(const std::string& home_directory) +{ + m_home_directory = home_directory; +} + std::string WFSSRV::NormalizePath(const std::string& path) const { std::string expanded; diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.h b/Source/Core/Core/IOS/WFS/WFSSRV.h index 82bc00710e..ed27a6b726 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.h +++ b/Source/Core/Core/IOS/WFS/WFSSRV.h @@ -39,6 +39,7 @@ public: IPCCommandResult IOCtl(const IOCtlRequest& request) override; s32 Rename(std::string source, std::string dest) const; + void SetHomeDir(const std::string& home_dir); private: // WFS device name, e.g. msc01/msc02. From 5bb7cd251e7d3ea818a55f84601a6904a379786e Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 1 Dec 2018 18:22:54 +0400 Subject: [PATCH 2/3] WFSI: Handle PATCH_TYPE_2 properly in IOCTL_WFSI_FINALIZE_TITLE_INSTALL --- Source/Core/Core/IOS/WFS/WFSI.cpp | 66 ++++++++++++++++++++++--------- Source/Core/Core/IOS/WFS/WFSI.h | 1 + 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index 0694ca0c42..ac18c400c1 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -117,6 +117,15 @@ void WFSI::SetImportTitleIdAndGroupId(u64 tid, u16 gid) m_import_group_id_str = GroupIdStr(gid); } +void WFSI::FinalizePatchInstall() +{ + const std::string current_title_dir = + StringFromFormat("/vol/%s/title/%s/%s", m_device_name.c_str(), m_current_group_id_str.c_str(), + m_current_title_id_str.c_str()); + const std::string patch_dir = current_title_dir + "/_patch"; + File::CopyDir(WFS::NativePath(patch_dir), WFS::NativePath(current_title_dir), true); +} + IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) { s32 return_error_code = IPC_SUCCESS; @@ -258,7 +267,43 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) case IOCTL_WFSI_FINALIZE_TITLE_INSTALL: { std::string tmd_path; - if (m_patch_type == NOT_A_PATCH) + + switch (m_patch_type) + { + case PATCH_TYPE_2: + { + // Delete content's default.dol + const std::string title_content_dir = + StringFromFormat("/vol/%s/title/%s/%s/content/", m_device_name.c_str(), + m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); + File::Delete(WFS::NativePath(title_content_dir + "default.dol")); + + // Copy content's _default.dol to patch's directory + const std::string patch_dir = + StringFromFormat("/vol/%s/title/%s/%s/_patch/", m_device_name.c_str(), + m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); + const std::string patch_content_dir = patch_dir + "content/"; + File::CreateDir(WFS::NativePath(patch_dir)); + File::CreateDir(WFS::NativePath(patch_content_dir)); + File::Rename(WFS::NativePath(title_content_dir + "_default.dol"), + WFS::NativePath(patch_content_dir + "default.dol")); + + FinalizePatchInstall(); + [[fallthrough]]; + } + case PATCH_TYPE_1: + { + std::string patch_dir = + StringFromFormat("/vol/%s/title/%s/%s/_patch", m_device_name.c_str(), + m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); + File::DeleteDirRecursively(WFS::NativePath(patch_dir)); + + tmd_path = StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd", + m_device_name.c_str(), m_current_group_id_str.c_str(), + m_current_title_id_str.c_str(), m_import_title_id); + break; + } + case NOT_A_PATCH: { std::string title_install_dir = StringFromFormat("/vol/%s/_install/%s", m_device_name.c_str(), m_import_title_id_str.c_str()); @@ -270,17 +315,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) tmd_path = StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd", m_device_name.c_str(), m_import_group_id_str.c_str(), m_import_title_id_str.c_str(), m_import_title_id); + break; } - else - { - std::string patch_dir = - StringFromFormat("/vol/%s/title/%s/%s/_patch", m_device_name.c_str(), - m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); - File::DeleteDirRecursively(WFS::NativePath(patch_dir)); - - tmd_path = StringFromFormat("/vol/%s/title/%s/%s/meta/%016" PRIx64 ".tmd", - m_device_name.c_str(), m_current_group_id_str.c_str(), - m_current_title_id_str.c_str(), m_import_title_id); } File::IOFile tmd_file(WFS::NativePath(tmd_path), "wb"); @@ -292,13 +328,7 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request) { INFO_LOG(IOS_WFS, "IOCTL_WFSI_FINALIZE_PATCH_INSTALL"); if (m_patch_type != NOT_A_PATCH) - { - std::string current_title_dir = - StringFromFormat("/vol/%s/title/%s/%s", m_device_name.c_str(), - m_current_group_id_str.c_str(), m_current_title_id_str.c_str()); - std::string patch_dir = current_title_dir + "/_patch"; - File::CopyDir(WFS::NativePath(patch_dir), WFS::NativePath(current_title_dir), true); - } + FinalizePatchInstall(); break; } diff --git a/Source/Core/Core/IOS/WFS/WFSI.h b/Source/Core/Core/IOS/WFS/WFSI.h index c862493775..2434289bb7 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.h +++ b/Source/Core/Core/IOS/WFS/WFSI.h @@ -46,6 +46,7 @@ private: void SetCurrentTitleIdAndGroupId(u64 tid, u16 gid); void SetImportTitleIdAndGroupId(u64 tid, u16 gid); + void FinalizePatchInstall(); s32 CancelTitleImport(bool continue_install); s32 CancelPatchImport(bool continue_install); From 077597b028195a4f4b79b97fec14a28263f2b23d Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 1 Dec 2018 18:28:43 +0400 Subject: [PATCH 3/3] VersionInfo: Replace IOS59 v7021 with v9249 --- Source/Core/Core/IOS/VersionInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/VersionInfo.cpp b/Source/Core/Core/IOS/VersionInfo.cpp index 8ce125eee0..33557bc1f3 100644 --- a/Source/Core/Core/IOS/VersionInfo.cpp +++ b/Source/Core/Core/IOS/VersionInfo.cpp @@ -268,7 +268,7 @@ constexpr std::array ios_memory_values = { RAM_VENDOR, 0x93600000, 0x93620000, 0, }, { - 59, 0x3b1c21, 0x101811, MEM1_SIZE, + 59, 0x3b2421, 0x101811, MEM1_SIZE, MEM1_SIZE, MEM1_END, MEM1_ARENA_BEGIN, MEM1_ARENA_END, MEM2_SIZE, MEM2_SIZE, 0x93600000, MEM2_ARENA_BEGIN, 0x935E0000, 0x935E0000, 0x93600000, HOLLYWOOD_REVISION,