Merge pull request #12199 from noahpistilli/kd-hotfix
IOS/KD: Fix crash with KD Scheduler
This commit is contained in:
commit
f8445782bf
|
@ -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);
|
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<WC24PubkMod> 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 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);
|
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);
|
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);
|
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
|
bool NWC24Dl::IsEncrypted(u16 entry_index) const
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
std::string GetVFFContentName(u16 entry_index, std::optional<u8> subtask_id) const;
|
std::string GetVFFContentName(u16 entry_index, std::optional<u8> subtask_id) const;
|
||||||
std::string GetDownloadURL(u16 entry_index, std::optional<u8> subtask_id) const;
|
std::string GetDownloadURL(u16 entry_index, std::optional<u8> subtask_id) const;
|
||||||
std::string GetVFFPath(u16 entry_index) const;
|
std::string GetVFFPath(u16 entry_index) const;
|
||||||
WC24PubkMod GetWC24PubkMod(u16 entry_index) const;
|
std::optional<WC24PubkMod> GetWC24PubkMod(u16 entry_index) const;
|
||||||
|
|
||||||
u64 GetNextDownloadTime(u16 record_index) const;
|
u64 GetNextDownloadTime(u16 record_index) const;
|
||||||
u64 GetDownloadMargin(u16 entry_index) const;
|
u64 GetDownloadMargin(u16 entry_index) const;
|
||||||
|
|
|
@ -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);
|
const std::string content_name = m_dl_list.GetVFFContentName(entry_index, subtask_id);
|
||||||
std::string url = m_dl_list.GetDownloadURL(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.
|
// Reroute to custom server if enabled.
|
||||||
const std::vector<std::string> parts = SplitString(url, '/');
|
const std::vector<std::string> parts = SplitString(url, '/');
|
||||||
if (parts.size() < 3)
|
if (parts.size() < 3)
|
||||||
|
@ -588,11 +596,17 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index,
|
||||||
|
|
||||||
if (m_dl_list.IsEncrypted(entry_index))
|
if (m_dl_list.IsEncrypted(entry_index))
|
||||||
{
|
{
|
||||||
NWC24::WC24PubkMod pubk_mod = m_dl_list.GetWC24PubkMod(entry_index);
|
std::optional<NWC24::WC24PubkMod> 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<u8>(response->size() - 320);
|
file_data = std::vector<u8>(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());
|
file_data.data(), temp_buffer.size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue