Permalink
Browse files

WiiSave: Merge Header and DataBinHeader to reduce noise

DataBinHeader is not used anywhere in the code other than via Header,
so let's merge them to reduce noise when accessing header fields
(currently we have to do header.hdr which looks silly).
  • Loading branch information...
leoetlino committed Jun 1, 2018
1 parent 2103778 commit 69abaf3ec4cd902cf3e51a0a6c8a4c117a8bf059
Showing with 11 additions and 16 deletions.
  1. +11 −16 Source/Core/Core/HW/WiiSave.cpp
@@ -63,19 +63,14 @@ enum
};
#pragma pack(push, 1)
struct DataBinHeader
struct Header
{
Common::BigEndianValue<u64> tid;
Common::BigEndianValue<u32> banner_size; // (0x72A0 or 0xF0A0, also seen 0xBAA0)
u8 permissions;
u8 unk1; // maybe permissions is a be16
std::array<u8, 0x10> md5; // md5 of plaintext header with md5 blanker applied
Common::BigEndianValue<u16> unk2;
};
struct Header
{
DataBinHeader hdr;
u8 banner[FULL_BNR_MAX];
};
static_assert(sizeof(Header) == 0xf0c0, "Header has an incorrect size");
@@ -163,10 +158,10 @@ class NandStorage final : public Storage
Header header{};
std::string banner_file_path = m_wii_title_path + "/banner.bin";
u32 banner_size = static_cast<u32>(File::GetSize(banner_file_path));
header.hdr.banner_size = banner_size;
header.hdr.tid = m_tid;
header.hdr.md5 = s_md5_blanker;
header.hdr.permissions = 0x3C;
header.banner_size = banner_size;
header.tid = m_tid;
header.md5 = s_md5_blanker;
header.permissions = 0x3C;
File::IOFile banner_file(banner_file_path, "rb");
if (!banner_file.ReadBytes(header.banner, banner_size))
@@ -176,7 +171,7 @@ class NandStorage final : public Storage
Md5 md5_calc;
mbedtls_md5(reinterpret_cast<const u8*>(&header), sizeof(Header), md5_calc.data());
header.hdr.md5 = std::move(md5_calc);
header.md5 = std::move(md5_calc);
return header;
}
@@ -218,7 +213,7 @@ class NandStorage final : public Storage
bool WriteHeader(const Header& header) override
{
File::IOFile banner_file(m_wii_title_path + "/banner.bin", "wb");
return banner_file.WriteBytes(header.banner, header.hdr.banner_size);
return banner_file.WriteBytes(header.banner, header.banner_size);
}
bool WriteBkHeader(const BkHeader& bk_header) override { return true; }
@@ -318,16 +313,16 @@ class DataBinStorage final : public Storage
std::array<u8, 0x10> iv = s_sd_initial_iv;
m_iosc.Decrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, iv.data(), reinterpret_cast<const u8*>(&header),
sizeof(Header), reinterpret_cast<u8*>(&header), IOS::PID_ES);
u32 banner_size = header.hdr.banner_size;
u32 banner_size = header.banner_size;
if ((banner_size < FULL_BNR_MIN) || (banner_size > FULL_BNR_MAX) ||
(((banner_size - BNR_SZ) % ICON_SZ) != 0))
{
ERROR_LOG(CONSOLE, "Not a Wii save or read failure for file header size %x", banner_size);
return {};
}
Md5 md5_file = header.hdr.md5;
header.hdr.md5 = s_md5_blanker;
Md5 md5_file = header.md5;
header.md5 = s_md5_blanker;
Md5 md5_calc;
mbedtls_md5(reinterpret_cast<const u8*>(&header), sizeof(Header), md5_calc.data());
if (md5_file != md5_calc)
@@ -531,7 +526,7 @@ bool Import(const std::string& data_bin_path, std::function<bool()> can_overwrit
ERROR_LOG(CORE, "WiiSave::Import: Failed to read header");
return false;
}
const auto nand = MakeNandStorage(ios.GetFS().get(), header->hdr.tid);
const auto nand = MakeNandStorage(ios.GetFS().get(), header->tid);
if (nand->SaveExists() && !can_overwrite())
return false;
return Copy(data_bin.get(), nand.get());

0 comments on commit 69abaf3

Please sign in to comment.