diff --git a/Source/Core/Core/IOS/Network/KD/NWC24DL.cpp b/Source/Core/Core/IOS/Network/KD/NWC24DL.cpp index 34c5e4d1d1..58776828e6 100644 --- a/Source/Core/Core/IOS/Network/KD/NWC24DL.cpp +++ b/Source/Core/Core/IOS/Network/KD/NWC24DL.cpp @@ -100,9 +100,9 @@ std::string NWC24Dl::GetVFFPath(u16 entry_index) const return fmt::format("/title/{0:08x}/{1:08x}/data/wc24dl.vff", lower_title_id, high_title_id); } -WC24PubkMod NWC24Dl::GetWC24PubkMod(u16 entry_index) const +std::optional NWC24Dl::GetWC24PubkMod(u16 entry_index) const { - WC24PubkMod pubkMod; + WC24PubkMod pubk_mod; const u32 lower_title_id = Common::swap32(m_data.entries[entry_index].low_title_id); const u32 high_title_id = Common::swap32(m_data.entries[entry_index].high_title_id); @@ -110,9 +110,13 @@ WC24PubkMod NWC24Dl::GetWC24PubkMod(u16 entry_index) const fmt::format("/title/{0:08x}/{1:08x}/data/wc24pubk.mod", lower_title_id, high_title_id); const auto file = m_fs->OpenFile(PID_KD, PID_KD, path, IOS::HLE::FS::Mode::Read); - file->Read(&pubkMod, 1); + if (!file) + return std::nullopt; - return pubkMod; + if (!file->Read(&pubk_mod, 1)) + return std::nullopt; + + return pubk_mod; } bool NWC24Dl::IsEncrypted(u16 entry_index) const diff --git a/Source/Core/Core/IOS/Network/KD/NWC24DL.h b/Source/Core/Core/IOS/Network/KD/NWC24DL.h index d6cbb8e9c8..6f5a05adae 100644 --- a/Source/Core/Core/IOS/Network/KD/NWC24DL.h +++ b/Source/Core/Core/IOS/Network/KD/NWC24DL.h @@ -37,7 +37,7 @@ public: std::string GetVFFContentName(u16 entry_index, std::optional subtask_id) const; std::string GetDownloadURL(u16 entry_index, std::optional subtask_id) const; std::string GetVFFPath(u16 entry_index) const; - WC24PubkMod GetWC24PubkMod(u16 entry_index) const; + std::optional GetWC24PubkMod(u16 entry_index) const; u64 GetNextDownloadTime(u16 record_index) const; u64 GetDownloadMargin(u16 entry_index) const; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index 833bc5707f..7e8ab1d53b 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -522,6 +522,14 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, const std::string content_name = m_dl_list.GetVFFContentName(entry_index, subtask_id); std::string url = m_dl_list.GetDownloadURL(entry_index, subtask_id); + if (content_name.empty()) + { + // If a content has an empty name it is meant to be saved to the mailbox. We do not support + // saving mail to the mailbox yet and as a result must skip these entries. + success = true; + return NWC24::WC24_OK; + } + // Reroute to custom server if enabled. const std::vector parts = SplitString(url, '/'); if (parts.size() < 3) @@ -588,11 +596,17 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, if (m_dl_list.IsEncrypted(entry_index)) { - NWC24::WC24PubkMod pubk_mod = m_dl_list.GetWC24PubkMod(entry_index); + std::optional pubk_mod = m_dl_list.GetWC24PubkMod(entry_index); + if (!pubk_mod) + { + ERROR_LOG_FMT(IOS_WC24, "Failed to get wc24pubk.mod for the current task."); + LogError(ErrorType::KD_Download, NWC24::WC24_ERR_FILE_OPEN); + return NWC24::WC24_ERR_FILE_OPEN; + } file_data = std::vector(response->size() - 320); - Common::AES::CryptOFB(pubk_mod.aes_key, wc24_file.iv, wc24_file.iv, temp_buffer.data(), + Common::AES::CryptOFB(pubk_mod->aes_key, wc24_file.iv, wc24_file.iv, temp_buffer.data(), file_data.data(), temp_buffer.size()); } else