From 60c6fbe9ccf167d90f332267375c00418e4abd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 15 Jun 2017 23:20:30 +0200 Subject: [PATCH 1/3] Add CommonTitles.h for common Wii title IDs --- Source/Core/Common/NandPaths.h | 3 --- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 3 ++- Source/Core/Core/Boot/Boot_WiiWAD.cpp | 7 ++++--- Source/Core/Core/CommonTitles.h | 20 +++++++++++++++++++ Source/Core/Core/Core.vcxproj | 1 + Source/Core/Core/Core.vcxproj.filters | 1 + .../Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp | 4 +++- Source/Core/Core/IOS/ES/ES.cpp | 7 ++++--- Source/Core/Core/IOS/ES/Formats.cpp | 7 ++++--- Source/Core/Core/IOS/ES/Views.cpp | 4 +++- Source/Core/Core/IOS/FS/FileIO.cpp | 3 ++- Source/Core/Core/IOS/IOS.cpp | 18 +++++++---------- Source/Core/Core/IOS/MIOS.cpp | 5 ++--- .../Core/Core/IOS/Network/KD/NetKDRequest.cpp | 3 ++- Source/Core/DolphinWX/FrameTools.cpp | 7 ++++--- Source/Core/DolphinWX/MainMenuBar.cpp | 3 ++- Source/UnitTests/Core/IOS/ES/FormatsTest.cpp | 6 +++--- 17 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 Source/Core/Core/CommonTitles.h diff --git a/Source/Core/Common/NandPaths.h b/Source/Core/Common/NandPaths.h index 87c7e8b50c..0a7738664c 100644 --- a/Source/Core/Common/NandPaths.h +++ b/Source/Core/Common/NandPaths.h @@ -10,9 +10,6 @@ #include "Common/CommonTypes.h" -static const u64 TITLEID_SYSMENU = 0x0000000100000002; -static const std::string TITLEID_SYSMENU_STRING = "0000000100000002"; - namespace Common { enum FromWhichRoot diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 0692a31f33..54beca3ce1 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -17,6 +17,7 @@ #include "Common/SettingsHandler.h" #include "Core/Boot/Boot.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HLE/HLE.h" @@ -230,7 +231,7 @@ bool CBoot::SetupWiiMemory(const DiscIO::Volume* volume, u64 ios_title_id) SettingsHandler gen; std::string serno; const std::string settings_file_path( - Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING); + Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + WII_SETTING); if (File::Exists(settings_file_path) && gen.Open(settings_file_path)) { serno = gen.GetValue("SERNO"); diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index b13a4e0e10..cb2f3e9c10 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -16,6 +16,7 @@ #include "Common/NandPaths.h" #include "Core/Boot/Boot.h" +#include "Core/CommonTitles.h" #include "Core/IOS/ES/ES.h" #include "Core/IOS/ES/Formats.h" #include "Core/IOS/FS/FileIO.h" @@ -46,8 +47,8 @@ static u32 StateChecksum(const StateFlags& flags) bool CBoot::Boot_WiiWAD(const std::string& _pFilename) { - std::string state_filename(Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + - WII_STATE); + std::string state_filename( + Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + WII_STATE); if (File::Exists(state_filename)) { @@ -89,7 +90,7 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename) // create data directory File::CreateFullPath(Common::GetTitleDataPath(titleID, Common::FROM_SESSION_ROOT)); - if (titleID == TITLEID_SYSMENU) + if (titleID == Titles::SYSTEM_MENU) IOS::HLE::CreateVirtualFATFilesystem(); // setup Wii memory diff --git a/Source/Core/Core/CommonTitles.h b/Source/Core/Core/CommonTitles.h new file mode 100644 index 0000000000..b3d07b6fb1 --- /dev/null +++ b/Source/Core/Core/CommonTitles.h @@ -0,0 +1,20 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include "Common/CommonTypes.h" + +namespace Titles +{ +constexpr u64 BOOT2 = 0x0000000100000001; + +constexpr u64 SYSTEM_MENU = 0x0000000100000002; + +// IOS used by the latest System Menu (4.3). Corresponds to IOS80. +constexpr u64 SYSTEM_MENU_IOS = 0x0000000100000050; + +constexpr u64 BC = 0x0000000100000100; +constexpr u64 MIOS = 0x0000000100000101; +} // namespace Titles diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index d587651c2b..193c73ae98 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -521,6 +521,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index c6e22c76af..bd15438132 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -895,6 +895,7 @@ + diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp index 15d8088267..5b2e1f8ea9 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp @@ -18,6 +18,7 @@ #include "Common/Logging/Log.h" #include "Common/NandPaths.h" #include "Common/StringUtil.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/CoreTiming.h" #include "Core/HW/EXI/EXI.h" @@ -160,7 +161,8 @@ void CEXIMemoryCard::SetupGciFolder(u16 sizeMb) const std::string& game_id = SConfig::GetInstance().GetGameID(); u32 CurrentGameId = 0; - if (game_id.length() >= 4 && game_id != "00000000" && game_id != TITLEID_SYSMENU_STRING) + if (game_id.length() >= 4 && game_id != "00000000" && + SConfig::GetInstance().GetTitleID() != Titles::SYSTEM_MENU) CurrentGameId = BE32((u8*)game_id.c_str()); const bool shift_jis = region == DiscIO::Region::NTSC_J; diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index a1a7d78054..e215e67570 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -21,6 +21,7 @@ #include "Common/NandPaths.h" #include "Common/ScopeGuard.h" #include "Common/StringUtil.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" @@ -196,7 +197,7 @@ static bool UpdateUIDAndGID(Kernel& kernel, const IOS::ES::TMDReader& tmd) static ReturnCode CheckIsAllowedToSetUID(const u32 caller_uid) { IOS::ES::UIDSys uid_map{Common::FromWhichRoot::FROM_SESSION_ROOT}; - const u32 system_menu_uid = uid_map.GetOrInsertUIDForTitle(TITLEID_SYSMENU); + const u32 system_menu_uid = uid_map.GetOrInsertUIDForTitle(Titles::SYSTEM_MENU); if (!system_menu_uid) return ES_SHORT_READ; return caller_uid == system_menu_uid ? IPC_SUCCESS : ES_EINVAL; @@ -241,7 +242,7 @@ bool ES::LaunchTitle(u64 title_id, bool skip_reload) // (supposedly when trying to re-open those files). DiscIO::NANDContentManager::Access().ClearCache(); - if (IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != TITLEID_SYSMENU) + if (IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != Titles::SYSTEM_MENU) return LaunchIOS(title_id); return LaunchPPCTitle(title_id, skip_reload); } @@ -256,7 +257,7 @@ bool ES::LaunchPPCTitle(u64 title_id, bool skip_reload) const DiscIO::NANDContentLoader& content_loader = AccessContentDevice(title_id); if (!content_loader.IsValid()) { - if (title_id == 0x0000000100000002) + if (title_id == Titles::SYSTEM_MENU) { PanicAlertT("Could not launch the Wii Menu because it is missing from the NAND.\n" "The emulated software will likely hang now."); diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 214fd8a31f..2a303b5d7f 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -24,6 +24,7 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "Common/Swap.h" +#include "Core/CommonTitles.h" #include "Core/IOS/Device.h" #include "Core/IOS/IOS.h" #include "Core/IOS/IOSC.h" @@ -47,7 +48,7 @@ bool IsDiscTitle(u64 title_id) bool IsChannel(u64 title_id) { - if (title_id == TITLEID_SYSMENU) + if (title_id == Titles::SYSTEM_MENU) return true; return IsTitleType(title_id, TitleType::Channel) || @@ -233,7 +234,7 @@ u64 TMDReader::GetIOSId() const DiscIO::Region TMDReader::GetRegion() const { - if (GetTitleId() == 0x0000000100000002) + if (GetTitleId() == Titles::SYSTEM_MENU) return DiscIO::GetSysMenuRegion(GetTitleVersion()); return DiscIO::RegionSwitchWii(static_cast(GetTitleId() & 0xff)); @@ -577,7 +578,7 @@ UIDSys::UIDSys(Common::FromWhichRoot root) if (m_entries.empty()) { - GetOrInsertUIDForTitle(TITLEID_SYSMENU); + GetOrInsertUIDForTitle(Titles::SYSTEM_MENU); } } diff --git a/Source/Core/Core/IOS/ES/Views.cpp b/Source/Core/Core/IOS/ES/Views.cpp index 5e16aeac34..a687419408 100644 --- a/Source/Core/Core/IOS/ES/Views.cpp +++ b/Source/Core/Core/IOS/ES/Views.cpp @@ -12,6 +12,7 @@ #include "Common/Logging/Log.h" #include "Common/NandPaths.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/Memmap.h" @@ -34,7 +35,8 @@ namespace Device // booted from the game list, though. static bool ShouldReturnFakeViewsForIOSes(u64 title_id, const TitleContext& context) { - const bool ios = IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != TITLEID_SYSMENU; + const bool ios = + IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != Titles::SYSTEM_MENU; const bool disc_title = context.active && IOS::ES::IsDiscTitle(context.tmd.GetTitleId()); return Core::WantsDeterminism() || (ios && SConfig::GetInstance().m_disc_booted_from_game_list && disc_title); diff --git a/Source/Core/Core/IOS/FS/FileIO.cpp b/Source/Core/Core/IOS/FS/FileIO.cpp index 71b41eec61..7ee063e7c6 100644 --- a/Source/Core/Core/IOS/FS/FileIO.cpp +++ b/Source/Core/Core/IOS/FS/FileIO.cpp @@ -16,6 +16,7 @@ #include "Common/File.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" +#include "Core/CommonTitles.h" #include "Core/HW/Memmap.h" #include "Core/IOS/IOS.h" @@ -40,7 +41,7 @@ void CreateVirtualFATFilesystem() { const int cdbSize = 0x01400000; const std::string cdbPath = - Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + "cdb.vff"; + Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + "cdb.vff"; if ((int)File::GetSize(cdbPath) < cdbSize) { // cdb.vff is a virtual Fat filesystem created on first launch of sysmenu diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index eecab887b8..d9d0e30453 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -19,6 +19,7 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" #include "Core/Boot/DolReader.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" @@ -173,11 +174,6 @@ void WriteReturnValue(s32 value, u32 address) Memory::Write_U32(static_cast(value), address); } -// IOS used by the latest System Menu (4.3). -constexpr u64 IOS80_TITLE_ID = 0x0000000100000050; -constexpr u64 BC_TITLE_ID = 0x0000000100000100; -constexpr u64 MIOS_TITLE_ID = 0x0000000100000101; - Kernel::Kernel() { // Until the Wii root and NAND path stuff is entirely managed by IOS and made non-static, @@ -218,7 +214,7 @@ EmulationKernel::EmulationKernel(u64 title_id) : Kernel(title_id) Core::InitializeWiiRoot(Core::WantsDeterminism()); - if (title_id == MIOS_TITLE_ID) + if (title_id == Titles::MIOS) { MIOS::Load(); return; @@ -319,10 +315,10 @@ bool Kernel::BootIOS(const u64 ios_title_id) // // Because we currently don't have boot1 and boot2, and BC is only ever used to launch MIOS // (indirectly via boot2), we can just launch MIOS when BC is launched. - if (ios_title_id == BC_TITLE_ID) + if (ios_title_id == Titles::BC) { NOTICE_LOG(IOS, "BC: Launching MIOS..."); - return BootIOS(MIOS_TITLE_ID); + return BootIOS(Titles::MIOS); } // Shut down the active IOS first before switching to the new one. @@ -595,7 +591,7 @@ void Kernel::DoState(PointerWrap& p) m_iosc.DoState(p); - if (m_title_id == MIOS_TITLE_ID) + if (m_title_id == Titles::MIOS) return; // We need to make sure all file handles are closed so IOS::HLE::Device::FS::DoState can @@ -686,13 +682,13 @@ void Init() }); // Start with IOS80 to simulate part of the Wii boot process. - s_ios = std::make_unique(IOS80_TITLE_ID); + s_ios = std::make_unique(Titles::SYSTEM_MENU_IOS); // On a Wii, boot2 launches the system menu IOS, which then launches the system menu // (which bootstraps the PPC). Bootstrapping the PPC results in memory values being set up. // This means that the constants in the 0x3100 region are always set up by the time // a game is launched. This is necessary because booting games from the game list skips // a significant part of a Wii's boot process. - SetupMemory(IOS80_TITLE_ID, MemorySetupType::Full); + SetupMemory(Titles::SYSTEM_MENU_IOS, MemorySetupType::Full); } void Shutdown() diff --git a/Source/Core/Core/IOS/MIOS.cpp b/Source/Core/Core/IOS/MIOS.cpp index b2a2ab0918..fc0e70541a 100644 --- a/Source/Core/Core/IOS/MIOS.cpp +++ b/Source/Core/Core/IOS/MIOS.cpp @@ -15,6 +15,7 @@ #include "Common/NandPaths.h" #include "Common/Swap.h" #include "Core/Boot/ElfReader.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/DSPEmulator.h" @@ -34,8 +35,6 @@ namespace HLE { namespace MIOS { -constexpr u64 MIOS_TITLE_ID = 0x0000000100000101; - // Source: https://wiibrew.org/wiki/ARM_Binaries struct ARMBinary final { @@ -92,7 +91,7 @@ u32 ARMBinary::GetElfSize() const static std::vector GetMIOSBinary() { const auto& loader = - DiscIO::NANDContentManager::Access().GetNANDLoader(MIOS_TITLE_ID, Common::FROM_SESSION_ROOT); + DiscIO::NANDContentManager::Access().GetNANDLoader(Titles::MIOS, Common::FROM_SESSION_ROOT); if (!loader.IsValid()) return {}; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index cbcf245fe9..9e68caba5d 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -14,6 +14,7 @@ #include "Common/NandPaths.h" #include "Common/SettingsHandler.h" +#include "Core/CommonTitles.h" #include "Core/HW/Memmap.h" #include "Core/IOS/Network/Socket.h" #include "Core/ec_wii.h" @@ -83,7 +84,7 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request) if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_INITIAL) { const std::string settings_file_path( - Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING); + Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + WII_SETTING); SettingsHandler gen; std::string area, model; bool got_settings = false; diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 007c6595db..5a798f70da 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -32,6 +32,7 @@ #include "Core/Boot/Boot.h" #include "Core/BootManager.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/CPU.h" @@ -1214,7 +1215,7 @@ void CFrame::OnShowCheatsWindow(wxCommandEvent& WXUNUSED(event)) void CFrame::OnLoadWiiMenu(wxCommandEvent& WXUNUSED(event)) { - BootGame(Common::GetTitleContentPath(TITLEID_SYSMENU, Common::FROM_CONFIGURED_ROOT)); + BootGame(Common::GetTitleContentPath(Titles::SYSTEM_MENU, Common::FROM_CONFIGURED_ROOT)); } void CFrame::OnInstallWAD(wxCommandEvent& event) @@ -1272,7 +1273,7 @@ void CFrame::OnUninstallWAD(wxCommandEvent&) return; } - if (title_id == TITLEID_SYSMENU) + if (title_id == Titles::SYSTEM_MENU) UpdateLoadWiiMenuItem(); } @@ -1503,7 +1504,7 @@ void CFrame::UpdateGUI() ->FindItem(IDM_LOAD_GC_IPL_EUR) ->Enable(!Initialized && File::Exists(SConfig::GetInstance().GetBootROMPath(EUR_DIR))); if (DiscIO::NANDContentManager::Access() - .GetNANDLoader(TITLEID_SYSMENU, Common::FROM_CONFIGURED_ROOT) + .GetNANDLoader(Titles::SYSTEM_MENU, Common::FROM_CONFIGURED_ROOT) .IsValid()) GetMenuBar()->FindItem(IDM_LOAD_WII_MENU)->Enable(!Initialized); diff --git a/Source/Core/DolphinWX/MainMenuBar.cpp b/Source/Core/DolphinWX/MainMenuBar.cpp index a3f2d08d96..c9bdb25289 100644 --- a/Source/Core/DolphinWX/MainMenuBar.cpp +++ b/Source/Core/DolphinWX/MainMenuBar.cpp @@ -8,6 +8,7 @@ #include #include "Common/CDUtils.h" +#include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/PowerPC/PowerPC.h" @@ -582,7 +583,7 @@ void MainMenuBar::RefreshWiiSystemMenuLabel() const auto* const item = FindItem(IDM_LOAD_WII_MENU); const auto& sys_menu_loader = DiscIO::NANDContentManager::Access().GetNANDLoader( - TITLEID_SYSMENU, Common::FROM_CONFIGURED_ROOT); + Titles::SYSTEM_MENU, Common::FROM_CONFIGURED_ROOT); if (sys_menu_loader.IsValid()) { diff --git a/Source/UnitTests/Core/IOS/ES/FormatsTest.cpp b/Source/UnitTests/Core/IOS/ES/FormatsTest.cpp index 4f76bbd51e..b431e26b63 100644 --- a/Source/UnitTests/Core/IOS/ES/FormatsTest.cpp +++ b/Source/UnitTests/Core/IOS/ES/FormatsTest.cpp @@ -6,14 +6,14 @@ #include +#include "Core/CommonTitles.h" #include "Core/IOS/ES/Formats.h" #include "TestBinaryData.h" TEST(ESFormats, TitleType) { - const u64 system_menu_title_id = 0x0000000100000002; - EXPECT_TRUE(IOS::ES::IsTitleType(system_menu_title_id, IOS::ES::TitleType::System)); - EXPECT_FALSE(IOS::ES::IsDiscTitle(system_menu_title_id)); + EXPECT_TRUE(IOS::ES::IsTitleType(Titles::SYSTEM_MENU, IOS::ES::TitleType::System)); + EXPECT_FALSE(IOS::ES::IsDiscTitle(Titles::SYSTEM_MENU)); const u64 ios59_title_id = 0x000000010000003b; EXPECT_TRUE(IOS::ES::IsTitleType(ios59_title_id, IOS::ES::TitleType::System)); From 860f07f5a14a53376b12b1f84b6a868e2693b27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 13 Jun 2017 00:52:53 +0200 Subject: [PATCH 2/3] IOS/ES: Expose GetDeviceId --- Source/Core/Core/IOS/ES/ES.cpp | 2 +- Source/Core/Core/IOS/ES/ES.h | 4 +++- Source/Core/Core/IOS/ES/Identity.cpp | 20 +++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index e215e67570..eac70ae1dd 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -423,7 +423,7 @@ IPCCommandResult ES::IOCtlV(const IOCtlVRequest& request) case IOCTL_ES_ADDTITLECANCEL: return ImportTitleCancel(*context, request); case IOCTL_ES_GETDEVICEID: - return GetConsoleID(request); + return GetDeviceId(request); case IOCTL_ES_OPENTITLECONTENT: return OpenTitleContent(context->uid, request); case IOCTL_ES_OPENCONTENT: diff --git a/Source/Core/Core/IOS/ES/ES.h b/Source/Core/Core/IOS/ES/ES.h index 0cb7deadef..b53a8780f5 100644 --- a/Source/Core/Core/IOS/ES/ES.h +++ b/Source/Core/Core/IOS/ES/ES.h @@ -132,6 +132,8 @@ public: ReturnCode DeleteSharedContent(const std::array& sha1) const; ReturnCode DeleteContent(u64 title_id, u32 content_id) const; + ReturnCode GetDeviceId(u32* device_id) const; + // Views ReturnCode GetV0TicketFromView(const u8* ticket_view, u8* ticket) const; ReturnCode GetTicketFromView(const u8* ticket_view, u8* ticket, u32* ticket_size) const; @@ -237,7 +239,7 @@ private: IPCCommandResult DeleteContent(const IOCtlVRequest& request); // Device identity and encryption - IPCCommandResult GetConsoleID(const IOCtlVRequest& request); + IPCCommandResult GetDeviceId(const IOCtlVRequest& request); IPCCommandResult GetDeviceCertificate(const IOCtlVRequest& request); IPCCommandResult CheckKoreaRegion(const IOCtlVRequest& request); IPCCommandResult Sign(const IOCtlVRequest& request); diff --git a/Source/Core/Core/IOS/ES/Identity.cpp b/Source/Core/Core/IOS/ES/Identity.cpp index eb58e9c656..9e24a78959 100644 --- a/Source/Core/Core/IOS/ES/Identity.cpp +++ b/Source/Core/Core/IOS/ES/Identity.cpp @@ -18,14 +18,24 @@ namespace HLE { namespace Device { -IPCCommandResult ES::GetConsoleID(const IOCtlVRequest& request) +ReturnCode ES::GetDeviceId(u32* device_id) const { - if (!request.HasNumberOfValidVectors(0, 1)) + const EcWii& ec = EcWii::GetInstance(); + *device_id = ec.GetNGID(); + INFO_LOG(IOS_ES, "GetDeviceId: %08X", *device_id); + return IPC_SUCCESS; +} + +IPCCommandResult ES::GetDeviceId(const IOCtlVRequest& request) +{ + if (!request.HasNumberOfValidVectors(0, 1) || request.io_vectors[0].size != sizeof(u32)) return GetDefaultReply(ES_EINVAL); - const EcWii& ec = EcWii::GetInstance(); - INFO_LOG(IOS_ES, "IOCTL_ES_GETDEVICEID %08X", ec.GetNGID()); - Memory::Write_U32(ec.GetNGID(), request.io_vectors[0].address); + u32 device_id; + const ReturnCode ret = GetDeviceId(&device_id); + if (ret != IPC_SUCCESS) + return GetDefaultReply(ret); + Memory::Write_U32(device_id, request.io_vectors[0].address); return GetDefaultReply(IPC_SUCCESS); } From 70828916e6e15d518c666a205f815c5f6f6a5e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 26 Jun 2017 15:28:33 +0200 Subject: [PATCH 3/3] IOS/ES: Refuse to launch the shop with default credentials Prevents... misusing the shop. We are not legally obliged to do this, but let's not make piracy any easier. --- Source/Core/Core/CommonTitles.h | 2 ++ Source/Core/Core/IOS/ES/ES.cpp | 17 +++++++++++++++++ Source/Core/Core/ec_wii.cpp | 7 +++---- Source/Core/Core/ec_wii.h | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/CommonTitles.h b/Source/Core/Core/CommonTitles.h index b3d07b6fb1..5b86db8f17 100644 --- a/Source/Core/Core/CommonTitles.h +++ b/Source/Core/Core/CommonTitles.h @@ -17,4 +17,6 @@ constexpr u64 SYSTEM_MENU_IOS = 0x0000000100000050; constexpr u64 BC = 0x0000000100000100; constexpr u64 MIOS = 0x0000000100000101; + +constexpr u64 SHOP = 0x0001000248414241; } // namespace Titles diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index eac70ae1dd..9cf025b8ae 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -26,6 +26,7 @@ #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" #include "Core/IOS/IOSC.h" +#include "Core/ec_wii.h" #include "DiscIO/NANDContentLoader.h" namespace IOS @@ -242,6 +243,22 @@ bool ES::LaunchTitle(u64 title_id, bool skip_reload) // (supposedly when trying to re-open those files). DiscIO::NANDContentManager::Access().ClearCache(); + u32 device_id; + if (title_id == Titles::SHOP && + (GetDeviceId(&device_id) != IPC_SUCCESS || device_id == DEFAULT_WII_DEVICE_ID)) + { + ERROR_LOG(IOS_ES, "Refusing to launch the shop channel with default device credentials"); + CriticalAlertT("You cannot use the Wii Shop Channel without using your own device credentials." + "\nPlease refer to the NAND usage guide for setup instructions: " + "https://dolphin-emu.org/docs/guides/nand-usage-guide/"); + + // Send the user back to the system menu instead of returning an error, which would + // likely make the system menu crash. Doing this is okay as anyone who has the shop + // also has the system menu installed, and this behaviour is consistent with what + // ES does when its DRM system refuses the use of a particular title. + return LaunchTitle(Titles::SYSTEM_MENU); + } + if (IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != Titles::SYSTEM_MENU) return LaunchIOS(title_id); return LaunchPPCTitle(title_id, skip_reload); diff --git a/Source/Core/Core/ec_wii.cpp b/Source/Core/Core/ec_wii.cpp index f58ad8e05e..28ffd0dabd 100644 --- a/Source/Core/Core/ec_wii.cpp +++ b/Source/Core/Core/ec_wii.cpp @@ -23,7 +23,6 @@ #include "Common/Logging/Log.h" #include "Common/Swap.h" -constexpr u32 default_NG_id = 0x0403AC68; constexpr u32 default_NG_key_id = 0x6AAB8C59; constexpr u8 default_NG_priv[] = { @@ -65,7 +64,7 @@ void MakeNGCert(u8* ng_cert_out, u32 NG_id, u32 NG_key_id, const u8* NG_priv, co char name[64]; if ((NG_id == 0) || (NG_key_id == 0) || (NG_priv == nullptr) || (NG_sig == nullptr)) { - NG_id = default_NG_id; + NG_id = DEFAULT_WII_DEVICE_ID; NG_key_id = default_NG_key_id; NG_priv = default_NG_priv; NG_sig = default_NG_sig; @@ -98,7 +97,7 @@ void MakeAPSigAndCert(u8* sig_out, u8* ap_cert_out, u64 title_id, u8* data, u32 if ((NG_id == 0) || (NG_priv == nullptr)) { NG_priv = default_NG_priv; - NG_id = default_NG_id; + NG_id = DEFAULT_WII_DEVICE_ID; } memset(ap_priv, 0, 0x1e); @@ -186,7 +185,7 @@ void EcWii::InitDefaults() { memset(&BootMiiKeysBin, 0, sizeof(BootMiiKeysBin)); - BootMiiKeysBin.ng_id = Common::swap32(default_NG_id); + BootMiiKeysBin.ng_id = Common::swap32(DEFAULT_WII_DEVICE_ID); BootMiiKeysBin.ng_key_id = Common::swap32(default_NG_key_id); memcpy(BootMiiKeysBin.ng_priv, default_NG_priv, sizeof(BootMiiKeysBin.ng_priv)); diff --git a/Source/Core/Core/ec_wii.h b/Source/Core/Core/ec_wii.h index 99b1bafeaf..eb4395a9a7 100644 --- a/Source/Core/Core/ec_wii.h +++ b/Source/Core/Core/ec_wii.h @@ -26,6 +26,8 @@ #include "Common/CommonTypes.h" +constexpr u32 DEFAULT_WII_DEVICE_ID = 0x0403AC68; + void MakeNGCert(u8* ng_cert_out, u32 NG_id, u32 NG_key_id, const u8* NG_priv, const u8* NG_sig); void MakeAPSigAndCert(u8* sig_out, u8* ap_cert_out, u64 title_id, u8* data, u32 data_size, const u8* NG_priv, u32 NG_id);