Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IOS/KD: Implement NWC24_CHECK_MAIL_NOW
- Loading branch information
1 parent
f2b8baa
commit 34abdf4
Showing
16 changed files
with
518 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include <mbedtls/hmac_drbg.h> | ||
|
||
#include "Common/Crypto/HMAC.h" | ||
#include "Common/ScopeGuard.h" | ||
|
||
namespace Common::HMAC | ||
{ | ||
bool HMACWithSHA1(const u8* key, const size_t key_len, const u8* msg, const size_t msg_len, u8* out) | ||
{ | ||
mbedtls_md_context_t ctx; | ||
Common::ScopeGuard guard{[&ctx] { mbedtls_md_free(&ctx); }}; | ||
mbedtls_md_init(&ctx); | ||
if (mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), 1)) | ||
return false; | ||
|
||
if (mbedtls_md_hmac_starts(&ctx, key, key_len) || mbedtls_md_hmac_update(&ctx, msg, msg_len) || | ||
mbedtls_md_hmac_finish(&ctx, out)) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace Common::HMAC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "Common/CommonTypes.h" | ||
|
||
namespace Common::HMAC | ||
{ | ||
bool HMACWithSHA1(const u8* key, const size_t key_len, const u8* msg, const size_t msg_len, | ||
u8* out); | ||
} // namespace Common::HMAC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "Common/CommonTypes.h" | ||
|
||
namespace IOS::HLE::NWC24::Mail | ||
{ | ||
constexpr u32 MAIL_LIST_MAGIC = 0x57635466; // WcTf | ||
|
||
#pragma pack(push, 1) | ||
struct MailListHeader final | ||
{ | ||
u32 magic; // 'WcTf' 0x57635466 | ||
u32 version; // 4 in Wii Menu 4.x | ||
u32 number_of_mail; | ||
u32 total_entries; | ||
u32 total_size_of_messages; | ||
u32 filesize; | ||
u32 next_entry_id; | ||
u32 next_entry_offset; | ||
u32 unk2; | ||
u32 vff_free_space; | ||
u8 unk3[48]; | ||
char mail_flag[40]; | ||
}; | ||
|
||
struct MultipartEntry final | ||
{ | ||
u32 offset; | ||
u32 size; | ||
}; | ||
|
||
struct MailListEntry final | ||
{ | ||
u32 id; | ||
u32 flag; | ||
u32 msg_size; | ||
u32 app_id; | ||
u32 header_length; | ||
u32 tag; | ||
u32 wii_cmd; | ||
// Never validated | ||
u32 crc32; | ||
u64 from_friend_code; | ||
u32 minutes_since_1900; | ||
u32 padding; | ||
u8 always_1; | ||
u8 number_of_multipart_entries; | ||
u16 app_group; | ||
u32 packed_from; | ||
u32 packed_to; | ||
u32 packed_subject; | ||
u32 packed_charset; | ||
u32 packed_transfer_encoding; | ||
u32 message_offset; | ||
// Set to message_length if content transfer encoding is not base64. | ||
u32 encoded_length; | ||
MultipartEntry multipart_entries[2]; | ||
u32 multipart_sizes[2]; | ||
u32 multipart_content_types[2]; | ||
u32 message_length; | ||
u32 dwc_id; | ||
u32 always_0x80000000; | ||
u32 padding3; | ||
}; | ||
|
||
#pragma pack(pop) | ||
} // namespace IOS::HLE::NWC24::Mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "Core/IOS/Network/KD/Mail/WC24Send.h" | ||
#include "Core/IOS/FS/FileSystem.h" | ||
#include "Core/IOS/Uids.h" | ||
|
||
namespace IOS::HLE::NWC24::Mail | ||
{ | ||
constexpr const char SEND_LIST_PATH[] = "/" WII_WC24CONF_DIR "/mbox" | ||
"/wc24send.ctl"; | ||
|
||
WC24SendList::WC24SendList(std::shared_ptr<FS::FileSystem> fs) : m_fs{std::move(fs)} | ||
{ | ||
ReadSendList(); | ||
} | ||
|
||
void WC24SendList::ReadSendList() | ||
{ | ||
const auto file = m_fs->OpenFile(PID_KD, PID_KD, SEND_LIST_PATH, FS::Mode::Read); | ||
if (!file || !file->Read(&m_data, 1)) | ||
return; | ||
|
||
const s32 file_error = CheckSendList(); | ||
if (!file_error) | ||
ERROR_LOG_FMT(IOS_WC24, "There is an error in the Send List for WC24 mail"); | ||
} | ||
|
||
void WC24SendList::WriteSendList() const | ||
{ | ||
constexpr FS::Modes public_modes{FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite}; | ||
m_fs->CreateFullPath(PID_KD, PID_KD, SEND_LIST_PATH, 0, public_modes); | ||
const auto file = m_fs->CreateAndOpenFile(PID_KD, PID_KD, SEND_LIST_PATH, public_modes); | ||
|
||
if (!file || !file->Write(&m_data, 1)) | ||
ERROR_LOG_FMT(IOS_WC24, "Failed to open or write WC24 Send list file"); | ||
} | ||
|
||
bool WC24SendList::CheckSendList() const | ||
{ | ||
// 'WcTf' magic | ||
if (Common::swap32(m_data.header.magic) != MAIL_LIST_MAGIC) | ||
{ | ||
ERROR_LOG_FMT(IOS_WC24, "Send List magic mismatch ({} != {})", | ||
Common::swap32(m_data.header.magic), MAIL_LIST_MAGIC); | ||
return false; | ||
} | ||
|
||
if (Common::swap32(m_data.header.version) != 4) | ||
{ | ||
ERROR_LOG_FMT(IOS_WC24, "Send List version mismatch"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
std::string_view WC24SendList::GetMailFlag() const | ||
{ | ||
return {m_data.header.mail_flag}; | ||
} | ||
} // namespace IOS::HLE::NWC24::Mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include <string_view> | ||
|
||
#include "Common/CommonPaths.h" | ||
#include "Common/CommonTypes.h" | ||
#include "Common/Logging/Log.h" | ||
#include "Common/Swap.h" | ||
#include "Core/IOS/Network/KD/Mail/MailCommon.h" | ||
#include "Core/IOS/Network/KD/NWC24Config.h" | ||
|
||
namespace IOS::HLE | ||
{ | ||
namespace FS | ||
{ | ||
class FileSystem; | ||
} | ||
namespace NWC24::Mail | ||
{ | ||
|
||
constexpr const char SEND_BOX_PATH[] = "/" WII_WC24CONF_DIR "/mbox" | ||
"/wc24send.mbx"; | ||
class WC24SendList final | ||
{ | ||
public: | ||
explicit WC24SendList(std::shared_ptr<FS::FileSystem> fs); | ||
|
||
void ReadSendList(); | ||
bool CheckSendList() const; | ||
void WriteSendList() const; | ||
|
||
std::string_view GetMailFlag() const; | ||
|
||
private: | ||
static constexpr u32 MAX_ENTRIES = 127; | ||
|
||
#pragma pack(push, 1) | ||
struct SendList final | ||
{ | ||
MailListHeader header; | ||
MailListEntry entries[MAX_ENTRIES]; | ||
}; | ||
#pragma pack(pop) | ||
|
||
SendList m_data; | ||
std::shared_ptr<FS::FileSystem> m_fs; | ||
}; | ||
} // namespace NWC24::Mail | ||
} // namespace IOS::HLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.