2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
#include "DiscIO/VolumeWii.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
|
2015-04-21 09:24:13 +00:00
|
|
|
#include <algorithm>
|
2017-06-26 21:38:58 +00:00
|
|
|
#include <array>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
2020-01-25 13:03:11 +00:00
|
|
|
#include <future>
|
2015-04-09 15:44:53 +00:00
|
|
|
#include <map>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <memory>
|
2017-06-04 08:33:14 +00:00
|
|
|
#include <optional>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <string>
|
2020-01-25 13:03:11 +00:00
|
|
|
#include <thread>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <utility>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <vector>
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2020-01-23 15:47:49 +00:00
|
|
|
#include <mbedtls/aes.h>
|
|
|
|
#include <mbedtls/sha1.h>
|
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
#include "Common/Align.h"
|
2016-10-30 22:39:12 +00:00
|
|
|
#include "Common/Assert.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-09-19 04:17:41 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "Common/Swap.h"
|
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2017-06-17 10:37:30 +00:00
|
|
|
#include "DiscIO/DiscExtractor.h"
|
2021-09-19 20:00:13 +00:00
|
|
|
#include "DiscIO/DiscUtils.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2017-08-02 16:16:56 +00:00
|
|
|
#include "DiscIO/FileSystemGCWii.h"
|
2015-04-10 21:18:41 +00:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2017-11-02 16:05:45 +00:00
|
|
|
#include "DiscIO/WiiSaveBanner.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
VolumeWii::VolumeWii(std::unique_ptr<BlobReader> reader)
|
2018-05-30 06:37:13 +00:00
|
|
|
: m_reader(std::move(reader)), m_game_partition(PARTITION_NONE),
|
2017-06-07 11:16:02 +00:00
|
|
|
m_last_decrypted_block(UINT64_MAX)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2018-05-30 06:37:13 +00:00
|
|
|
ASSERT(m_reader);
|
2016-10-30 22:39:12 +00:00
|
|
|
|
2018-05-30 06:37:13 +00:00
|
|
|
m_encrypted = m_reader->ReadSwapped<u32>(0x60) == u32(0);
|
Reimplement support for unencrypted Wii discs
You may want to read the PR #2047 comments before reading this.
Dolphin attempts to support an unencrypted type of Wii discs
that apparently is identified by a 4-byte integer at 0x60
being non-zero. I don't know what discs (if any) would be
using that format, so I haven't been able to test Dolphin's
support for it, but it has probably been broken for a while.
The old implementation is very short but also strange.
In CreateVolumeFromFilename, we read a 4-byte integer from
0x60, and if it's non-zero, we create a CVolumeGC object
instead of a CVolumeWiiCrypted object. This might seem like
it makes no sense, but it presumably worked in the past
because IsVolumeWiiDisc used to check the volume type by
reading the magic word for Wii straight from the disc,
meaning that CVolumeGC objects representing unencrypted Wii
discs would be treated as Wii discs by pretty much all of
Dolphin's code except for the volume implementation code.
(It wasn't possible to simply use CVolumeWiiCrypted, because
that class only handled encrypted discs, like the name says.)
However, that stopped working as intended because of ace0607.
And furthermore, bb93336 made it even more broken by making
parts of Dolphin expect that data read from Wii discs needed
to be decrypted (rather than the volume implementation
implicitly deciding whether to decrypt when Read was called).
Disclaimer: Like I said before, I haven't been able to test
any of this because I don't have any discs that use this
unencrypted Wii disc format, so this is all theoretical.
Later, PR #2047 tried to remove Dolphin's support for
the unencrypted Wii disc format because seemingly no
discs used it, but the PR got closed without being merged.
At the end of that PR, I said that I would make a new PR
with a better implementation for the format after PR #2353
was merged. Now that PR #2353 is merged (two years later...)
and PR #5521 is merged, the new implementation was easy to
make, and here it is!
Untested.
2017-06-05 12:54:37 +00:00
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
for (u32 partition_group = 0; partition_group < 4; ++partition_group)
|
|
|
|
{
|
2017-06-04 08:33:14 +00:00
|
|
|
const std::optional<u32> number_of_partitions =
|
2018-05-30 06:37:13 +00:00
|
|
|
m_reader->ReadSwapped<u32>(0x40000 + (partition_group * 8));
|
2017-06-04 08:33:14 +00:00
|
|
|
if (!number_of_partitions)
|
2015-06-13 10:51:24 +00:00
|
|
|
continue;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-06-07 09:49:34 +00:00
|
|
|
const std::optional<u64> partition_table_offset =
|
|
|
|
ReadSwappedAndShifted(0x40000 + (partition_group * 8) + 4, PARTITION_NONE);
|
|
|
|
if (!partition_table_offset)
|
2015-06-13 10:51:24 +00:00
|
|
|
continue;
|
2014-05-29 10:38:39 +00:00
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
for (u32 i = 0; i < number_of_partitions; i++)
|
|
|
|
{
|
2017-06-07 09:49:34 +00:00
|
|
|
const std::optional<u64> partition_offset =
|
|
|
|
ReadSwappedAndShifted(*partition_table_offset + (i * 8), PARTITION_NONE);
|
|
|
|
if (!partition_offset)
|
2015-06-13 10:51:24 +00:00
|
|
|
continue;
|
2017-06-07 09:49:34 +00:00
|
|
|
|
|
|
|
const Partition partition(*partition_offset);
|
2015-06-13 10:51:24 +00:00
|
|
|
|
2017-06-20 19:51:40 +00:00
|
|
|
const std::optional<u32> partition_type =
|
2018-05-30 06:37:13 +00:00
|
|
|
m_reader->ReadSwapped<u32>(*partition_table_offset + (i * 8) + 4);
|
2017-06-20 19:51:40 +00:00
|
|
|
if (!partition_type)
|
|
|
|
continue;
|
2015-06-13 10:51:24 +00:00
|
|
|
|
2017-06-24 16:42:36 +00:00
|
|
|
// If this is the game partition, set m_game_partition
|
2017-06-20 19:51:40 +00:00
|
|
|
if (m_game_partition == PARTITION_NONE && *partition_type == 0)
|
2017-06-09 16:39:30 +00:00
|
|
|
m_game_partition = partition;
|
2017-06-24 16:42:36 +00:00
|
|
|
|
|
|
|
auto get_ticket = [this, partition]() -> IOS::ES::TicketReader {
|
|
|
|
std::vector<u8> ticket_buffer(sizeof(IOS::ES::Ticket));
|
2018-05-30 06:37:13 +00:00
|
|
|
if (!m_reader->Read(partition.offset, ticket_buffer.size(), ticket_buffer.data()))
|
2017-06-24 16:42:36 +00:00
|
|
|
return INVALID_TICKET;
|
|
|
|
return IOS::ES::TicketReader{std::move(ticket_buffer)};
|
|
|
|
};
|
|
|
|
|
|
|
|
auto get_tmd = [this, partition]() -> IOS::ES::TMDReader {
|
2021-09-19 20:00:13 +00:00
|
|
|
const std::optional<u32> tmd_size =
|
|
|
|
m_reader->ReadSwapped<u32>(partition.offset + WII_PARTITION_TMD_SIZE_ADDRESS);
|
|
|
|
const std::optional<u64> tmd_address = ReadSwappedAndShifted(
|
|
|
|
partition.offset + WII_PARTITION_TMD_OFFSET_ADDRESS, PARTITION_NONE);
|
2017-06-24 16:42:36 +00:00
|
|
|
if (!tmd_size || !tmd_address)
|
|
|
|
return INVALID_TMD;
|
|
|
|
if (!IOS::ES::IsValidTMDSize(*tmd_size))
|
|
|
|
{
|
|
|
|
// This check is normally done by ES in ES_DiVerify, but that would happen too late
|
|
|
|
// (after allocating the buffer), so we do the check here.
|
2021-03-20 10:50:00 +00:00
|
|
|
ERROR_LOG_FMT(DISCIO, "Invalid TMD size");
|
2017-06-24 16:42:36 +00:00
|
|
|
return INVALID_TMD;
|
|
|
|
}
|
|
|
|
std::vector<u8> tmd_buffer(*tmd_size);
|
2018-05-30 06:37:13 +00:00
|
|
|
if (!m_reader->Read(partition.offset + *tmd_address, *tmd_size, tmd_buffer.data()))
|
2017-06-24 16:42:36 +00:00
|
|
|
return INVALID_TMD;
|
|
|
|
return IOS::ES::TMDReader{std::move(tmd_buffer)};
|
|
|
|
};
|
|
|
|
|
2019-03-21 22:04:44 +00:00
|
|
|
auto get_cert_chain = [this, partition]() -> std::vector<u8> {
|
2021-09-19 20:00:13 +00:00
|
|
|
const std::optional<u32> size =
|
|
|
|
m_reader->ReadSwapped<u32>(partition.offset + WII_PARTITION_CERT_CHAIN_SIZE_ADDRESS);
|
|
|
|
const std::optional<u64> address = ReadSwappedAndShifted(
|
|
|
|
partition.offset + WII_PARTITION_CERT_CHAIN_OFFSET_ADDRESS, PARTITION_NONE);
|
2019-03-21 22:04:44 +00:00
|
|
|
if (!size || !address)
|
|
|
|
return {};
|
|
|
|
std::vector<u8> cert_chain(*size);
|
|
|
|
if (!m_reader->Read(partition.offset + *address, *size, cert_chain.data()))
|
|
|
|
return {};
|
|
|
|
return cert_chain;
|
|
|
|
};
|
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
auto get_h3_table = [this, partition]() -> std::vector<u8> {
|
|
|
|
if (!m_encrypted)
|
|
|
|
return {};
|
2021-09-19 20:00:13 +00:00
|
|
|
const std::optional<u64> h3_table_offset = ReadSwappedAndShifted(
|
|
|
|
partition.offset + WII_PARTITION_H3_OFFSET_ADDRESS, PARTITION_NONE);
|
2019-03-26 16:22:18 +00:00
|
|
|
if (!h3_table_offset)
|
|
|
|
return {};
|
2021-09-19 20:00:13 +00:00
|
|
|
std::vector<u8> h3_table(WII_PARTITION_H3_SIZE);
|
|
|
|
if (!m_reader->Read(partition.offset + *h3_table_offset, WII_PARTITION_H3_SIZE,
|
|
|
|
h3_table.data()))
|
2019-03-26 16:22:18 +00:00
|
|
|
return {};
|
|
|
|
return h3_table;
|
|
|
|
};
|
|
|
|
|
2017-06-24 16:42:36 +00:00
|
|
|
auto get_key = [this, partition]() -> std::unique_ptr<mbedtls_aes_context> {
|
|
|
|
const IOS::ES::TicketReader& ticket = *m_partitions[partition].ticket;
|
|
|
|
if (!ticket.IsValid())
|
|
|
|
return nullptr;
|
2020-01-23 15:47:49 +00:00
|
|
|
const std::array<u8, AES_KEY_SIZE> key = ticket.GetTitleKey();
|
2017-06-24 16:42:36 +00:00
|
|
|
std::unique_ptr<mbedtls_aes_context> aes_context = std::make_unique<mbedtls_aes_context>();
|
|
|
|
mbedtls_aes_setkey_dec(aes_context.get(), key.data(), 128);
|
|
|
|
return aes_context;
|
|
|
|
};
|
|
|
|
|
2017-08-02 16:16:56 +00:00
|
|
|
auto get_file_system = [this, partition]() -> std::unique_ptr<FileSystem> {
|
|
|
|
auto file_system = std::make_unique<FileSystemGCWii>(this, partition);
|
|
|
|
return file_system->IsValid() ? std::move(file_system) : nullptr;
|
|
|
|
};
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
auto get_data_offset = [this, partition]() -> u64 {
|
|
|
|
return ReadSwappedAndShifted(partition.offset + 0x2b8, PARTITION_NONE).value_or(0);
|
|
|
|
};
|
|
|
|
|
2017-06-24 16:42:36 +00:00
|
|
|
m_partitions.emplace(
|
|
|
|
partition, PartitionDetails{Common::Lazy<std::unique_ptr<mbedtls_aes_context>>(get_key),
|
|
|
|
Common::Lazy<IOS::ES::TicketReader>(get_ticket),
|
2017-08-02 16:16:56 +00:00
|
|
|
Common::Lazy<IOS::ES::TMDReader>(get_tmd),
|
2019-03-21 22:04:44 +00:00
|
|
|
Common::Lazy<std::vector<u8>>(get_cert_chain),
|
2019-03-26 16:22:18 +00:00
|
|
|
Common::Lazy<std::vector<u8>>(get_h3_table),
|
2017-08-02 16:16:56 +00:00
|
|
|
Common::Lazy<std::unique_ptr<FileSystem>>(get_file_system),
|
2018-05-22 20:39:52 +00:00
|
|
|
Common::Lazy<u64>(get_data_offset), *partition_type});
|
2015-06-13 10:51:24 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-29 10:38:39 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
VolumeWii::~VolumeWii()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-30 06:37:13 +00:00
|
|
|
bool VolumeWii::Read(u64 offset, u64 length, u8* buffer, const Partition& partition) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-06-13 10:51:24 +00:00
|
|
|
if (partition == PARTITION_NONE)
|
2018-05-30 06:37:13 +00:00
|
|
|
return m_reader->Read(offset, length, buffer);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-07-04 14:08:12 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
if (it == m_partitions.end())
|
2015-06-13 10:51:24 +00:00
|
|
|
return false;
|
2018-05-22 20:39:52 +00:00
|
|
|
const PartitionDetails& partition_details = it->second;
|
|
|
|
|
2020-08-29 13:12:02 +00:00
|
|
|
const u64 partition_data_offset = partition.offset + *partition_details.data_offset;
|
|
|
|
if (m_reader->SupportsReadWiiDecrypted(offset, length, partition_data_offset))
|
|
|
|
return m_reader->ReadWiiDecrypted(offset, length, buffer, partition_data_offset);
|
2019-12-27 21:04:51 +00:00
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
if (!m_encrypted)
|
|
|
|
{
|
2018-05-30 06:37:13 +00:00
|
|
|
return m_reader->Read(partition.offset + *partition_details.data_offset + offset, length,
|
|
|
|
buffer);
|
2018-05-22 20:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mbedtls_aes_context* aes_context = partition_details.key->get();
|
2017-06-24 16:42:36 +00:00
|
|
|
if (!aes_context)
|
|
|
|
return false;
|
2015-06-13 10:51:24 +00:00
|
|
|
|
2017-02-10 15:56:40 +00:00
|
|
|
std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE);
|
2018-05-30 06:37:13 +00:00
|
|
|
while (length > 0)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-04-21 09:17:39 +00:00
|
|
|
// Calculate offsets
|
2018-05-22 20:39:52 +00:00
|
|
|
u64 block_offset_on_disc = partition.offset + *partition_details.data_offset +
|
2018-05-30 06:37:13 +00:00
|
|
|
offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE;
|
|
|
|
u64 data_offset_in_block = offset % BLOCK_DATA_SIZE;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-04-21 09:17:39 +00:00
|
|
|
if (m_last_decrypted_block != block_offset_on_disc)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-01-26 14:59:25 +00:00
|
|
|
// Read the current block
|
2018-05-30 06:37:13 +00:00
|
|
|
if (!m_reader->Read(block_offset_on_disc, BLOCK_TOTAL_SIZE, read_buffer.data()))
|
2015-01-26 14:59:25 +00:00
|
|
|
return false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-04-14 09:40:32 +00:00
|
|
|
// Decrypt the block's data
|
|
|
|
DecryptBlockData(read_buffer.data(), m_last_decrypted_block_data, aes_context);
|
2015-04-21 09:17:39 +00:00
|
|
|
m_last_decrypted_block = block_offset_on_disc;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-26 14:59:25 +00:00
|
|
|
// Copy the decrypted data
|
2018-05-30 06:37:13 +00:00
|
|
|
u64 copy_size = std::min(length, BLOCK_DATA_SIZE - data_offset_in_block);
|
|
|
|
memcpy(buffer, &m_last_decrypted_block_data[data_offset_in_block],
|
2015-04-21 09:24:13 +00:00
|
|
|
static_cast<size_t>(copy_size));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-26 14:59:25 +00:00
|
|
|
// Update offsets
|
2018-05-30 06:37:13 +00:00
|
|
|
length -= copy_size;
|
|
|
|
buffer += copy_size;
|
|
|
|
offset += copy_size;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-26 14:59:25 +00:00
|
|
|
return true;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
bool VolumeWii::IsEncryptedAndHashed() const
|
|
|
|
{
|
|
|
|
return m_encrypted;
|
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::vector<Partition> VolumeWii::GetPartitions() const
|
2010-01-14 07:19:10 +00:00
|
|
|
{
|
2015-06-13 10:51:24 +00:00
|
|
|
std::vector<Partition> partitions;
|
2017-07-04 14:08:12 +00:00
|
|
|
for (const auto& pair : m_partitions)
|
2015-06-13 10:51:24 +00:00
|
|
|
partitions.push_back(pair.first);
|
|
|
|
return partitions;
|
2010-01-14 07:19:10 +00:00
|
|
|
}
|
2014-12-03 09:54:09 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Partition VolumeWii::GetGamePartition() const
|
2015-06-13 10:51:24 +00:00
|
|
|
{
|
|
|
|
return m_game_partition;
|
|
|
|
}
|
|
|
|
|
2017-06-20 19:51:40 +00:00
|
|
|
std::optional<u32> VolumeWii::GetPartitionType(const Partition& partition) const
|
|
|
|
{
|
2017-07-04 14:08:12 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
return it != m_partitions.end() ? it->second.type : std::optional<u32>();
|
2017-06-20 19:51:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::optional<u64> VolumeWii::GetTitleID(const Partition& partition) const
|
2015-06-13 10:51:24 +00:00
|
|
|
{
|
2017-05-20 16:58:12 +00:00
|
|
|
const IOS::ES::TicketReader& ticket = GetTicket(partition);
|
|
|
|
if (!ticket.IsValid())
|
2017-06-03 19:29:08 +00:00
|
|
|
return {};
|
|
|
|
return ticket.GetTitleId();
|
2015-06-13 10:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
const IOS::ES::TicketReader& VolumeWii::GetTicket(const Partition& partition) const
|
2017-02-26 16:26:08 +00:00
|
|
|
{
|
2017-07-04 14:08:12 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
2017-06-24 16:42:36 +00:00
|
|
|
return it != m_partitions.end() ? *it->second.ticket : INVALID_TICKET;
|
2017-02-26 16:26:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const
|
2010-09-08 00:20:19 +00:00
|
|
|
{
|
2017-07-04 14:08:12 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
2017-06-24 16:42:36 +00:00
|
|
|
return it != m_partitions.end() ? *it->second.tmd : INVALID_TMD;
|
2010-09-08 00:20:19 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2019-03-21 22:04:44 +00:00
|
|
|
const std::vector<u8>& VolumeWii::GetCertificateChain(const Partition& partition) const
|
|
|
|
{
|
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
return it != m_partitions.end() ? *it->second.cert_chain : INVALID_CERT_CHAIN;
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:16:56 +00:00
|
|
|
const FileSystem* VolumeWii::GetFileSystem(const Partition& partition) const
|
|
|
|
{
|
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
return it != m_partitions.end() ? it->second.file_system->get() : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
u64 VolumeWii::EncryptedPartitionOffsetToRawOffset(u64 offset, const Partition& partition,
|
|
|
|
u64 partition_data_offset)
|
2017-02-10 17:57:58 +00:00
|
|
|
{
|
2015-06-13 10:51:24 +00:00
|
|
|
if (partition == PARTITION_NONE)
|
|
|
|
return offset;
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
return partition.offset + partition_data_offset + (offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE) +
|
2017-02-10 17:57:58 +00:00
|
|
|
(offset % BLOCK_DATA_SIZE);
|
|
|
|
}
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition) const
|
|
|
|
{
|
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
if (it == m_partitions.end())
|
|
|
|
return offset;
|
|
|
|
const u64 data_offset = *it->second.data_offset;
|
|
|
|
|
|
|
|
if (!m_encrypted)
|
|
|
|
return partition.offset + data_offset + offset;
|
|
|
|
|
|
|
|
return EncryptedPartitionOffsetToRawOffset(offset, partition, data_offset);
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:49:06 +00:00
|
|
|
std::string VolumeWii::GetGameTDBID(const Partition& partition) const
|
|
|
|
{
|
|
|
|
return GetGameID(partition);
|
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Region VolumeWii::GetRegion() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2020-06-04 18:33:52 +00:00
|
|
|
return RegionCodeToRegion(m_reader->ReadSwapped<u32>(0x4E000));
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeWii::GetLongNames() const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2017-11-02 20:05:37 +00:00
|
|
|
std::vector<char16_t> names(NAMES_TOTAL_CHARS);
|
|
|
|
names.resize(ReadFile(*this, GetGamePartition(), "opening.bnr",
|
|
|
|
reinterpret_cast<u8*>(names.data()), NAMES_TOTAL_BYTES, 0x5C));
|
|
|
|
return ReadWiiNames(names);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
std::vector<u32> VolumeWii::GetBanner(u32* width, u32* height) const
|
2015-12-03 16:29:59 +00:00
|
|
|
{
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
2017-06-03 19:29:08 +00:00
|
|
|
const std::optional<u64> title_id = GetTitleID(GetGamePartition());
|
|
|
|
if (!title_id)
|
2015-12-03 16:29:59 +00:00
|
|
|
return std::vector<u32>();
|
|
|
|
|
2017-11-02 16:05:45 +00:00
|
|
|
return WiiSaveBanner(*title_id).GetBanner(width, height);
|
2015-12-03 16:29:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Platform VolumeWii::GetVolumeType() const
|
2015-01-17 12:21:02 +00:00
|
|
|
{
|
2018-03-31 12:04:13 +00:00
|
|
|
return Platform::WiiDisc;
|
2015-01-17 12:21:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 12:51:13 +00:00
|
|
|
bool VolumeWii::IsDatelDisc() const
|
|
|
|
{
|
|
|
|
return m_game_partition == PARTITION_NONE;
|
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
BlobType VolumeWii::GetBlobType() const
|
2015-09-26 13:24:29 +00:00
|
|
|
{
|
2018-05-30 06:37:13 +00:00
|
|
|
return m_reader->GetBlobType();
|
2015-09-26 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
u64 VolumeWii::GetSize() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2018-05-30 06:37:13 +00:00
|
|
|
return m_reader->GetDataSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2009-02-22 13:59:06 +00:00
|
|
|
|
2019-03-21 21:20:23 +00:00
|
|
|
bool VolumeWii::IsSizeAccurate() const
|
|
|
|
{
|
|
|
|
return m_reader->IsDataSizeAccurate();
|
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
u64 VolumeWii::GetRawSize() const
|
2013-04-09 17:58:56 +00:00
|
|
|
{
|
2018-05-30 06:37:13 +00:00
|
|
|
return m_reader->GetRawSize();
|
2013-04-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 12:11:00 +00:00
|
|
|
const BlobReader& VolumeWii::GetBlobReader() const
|
|
|
|
{
|
|
|
|
return *m_reader;
|
|
|
|
}
|
|
|
|
|
2020-06-07 20:58:03 +00:00
|
|
|
std::array<u8, 20> VolumeWii::GetSyncHash() const
|
|
|
|
{
|
|
|
|
mbedtls_sha1_context context;
|
|
|
|
mbedtls_sha1_init(&context);
|
|
|
|
mbedtls_sha1_starts_ret(&context);
|
|
|
|
|
|
|
|
// Disc header
|
|
|
|
ReadAndAddToSyncHash(&context, 0, 0x80, PARTITION_NONE);
|
|
|
|
|
|
|
|
// Region code
|
|
|
|
ReadAndAddToSyncHash(&context, 0x4E000, 4, PARTITION_NONE);
|
|
|
|
|
|
|
|
// The data offset of the game partition - an important factor for disc drive timings
|
|
|
|
const u64 data_offset = PartitionOffsetToRawOffset(0, GetGamePartition());
|
|
|
|
mbedtls_sha1_update_ret(&context, reinterpret_cast<const u8*>(&data_offset), sizeof(data_offset));
|
|
|
|
|
|
|
|
// TMD
|
|
|
|
AddTMDToSyncHash(&context, GetGamePartition());
|
|
|
|
|
|
|
|
// Game partition contents
|
|
|
|
AddGamePartitionToSyncHash(&context);
|
|
|
|
|
|
|
|
std::array<u8, 20> hash;
|
|
|
|
mbedtls_sha1_finish_ret(&context, hash.data());
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
bool VolumeWii::CheckH3TableIntegrity(const Partition& partition) const
|
2012-05-04 10:49:10 +00:00
|
|
|
{
|
2019-03-26 16:22:18 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
if (it == m_partitions.end())
|
|
|
|
return false;
|
|
|
|
const PartitionDetails& partition_details = it->second;
|
|
|
|
|
|
|
|
const std::vector<u8>& h3_table = *partition_details.h3_table;
|
2021-09-19 20:00:13 +00:00
|
|
|
if (h3_table.size() != WII_PARTITION_H3_SIZE)
|
2019-03-26 16:22:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const IOS::ES::TMDReader& tmd = *partition_details.tmd;
|
|
|
|
if (!tmd.IsValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const std::vector<IOS::ES::Content> contents = tmd.GetContents();
|
|
|
|
if (contents.size() != 1)
|
2018-05-22 20:39:52 +00:00
|
|
|
return false;
|
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
std::array<u8, 20> h3_table_sha1;
|
2019-06-08 00:57:02 +00:00
|
|
|
mbedtls_sha1_ret(h3_table.data(), h3_table.size(), h3_table_sha1.data());
|
2019-03-26 16:22:18 +00:00
|
|
|
return h3_table_sha1 == contents[0].sha1;
|
|
|
|
}
|
|
|
|
|
2021-03-07 12:48:51 +00:00
|
|
|
bool VolumeWii::CheckBlockIntegrity(u64 block_index, const u8* encrypted_data,
|
2019-08-05 11:58:27 +00:00
|
|
|
const Partition& partition) const
|
2019-03-26 16:22:18 +00:00
|
|
|
{
|
2017-07-04 14:08:12 +00:00
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
if (it == m_partitions.end())
|
2015-06-13 10:51:24 +00:00
|
|
|
return false;
|
2018-05-22 20:39:52 +00:00
|
|
|
const PartitionDetails& partition_details = it->second;
|
2019-03-26 16:22:18 +00:00
|
|
|
|
2020-01-23 15:47:49 +00:00
|
|
|
if (block_index / BLOCKS_PER_GROUP * SHA1_SIZE >= partition_details.h3_table->size())
|
2019-03-26 16:22:18 +00:00
|
|
|
return false;
|
|
|
|
|
2018-05-22 20:39:52 +00:00
|
|
|
mbedtls_aes_context* aes_context = partition_details.key->get();
|
2017-06-24 16:42:36 +00:00
|
|
|
if (!aes_context)
|
|
|
|
return false;
|
2015-06-13 10:51:24 +00:00
|
|
|
|
2020-01-30 20:29:11 +00:00
|
|
|
HashBlock hashes;
|
2021-03-07 12:48:51 +00:00
|
|
|
DecryptBlockHashes(encrypted_data, &hashes, aes_context);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
u8 cluster_data[BLOCK_DATA_SIZE];
|
2021-03-07 12:48:51 +00:00
|
|
|
DecryptBlockData(encrypted_data, cluster_data, aes_context);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
for (u32 hash_index = 0; hash_index < 31; ++hash_index)
|
|
|
|
{
|
|
|
|
u8 h0_hash[SHA1_SIZE];
|
2019-06-08 00:57:02 +00:00
|
|
|
mbedtls_sha1_ret(cluster_data + hash_index * 0x400, 0x400, h0_hash);
|
2020-01-30 20:29:11 +00:00
|
|
|
if (memcmp(h0_hash, hashes.h0[hash_index], SHA1_SIZE))
|
2012-05-04 10:49:10 +00:00
|
|
|
return false;
|
2019-03-26 16:22:18 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
u8 h1_hash[SHA1_SIZE];
|
2020-01-30 20:29:11 +00:00
|
|
|
mbedtls_sha1_ret(reinterpret_cast<u8*>(hashes.h0), sizeof(hashes.h0), h1_hash);
|
|
|
|
if (memcmp(h1_hash, hashes.h1[block_index % 8], SHA1_SIZE))
|
2019-03-26 16:22:18 +00:00
|
|
|
return false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
u8 h2_hash[SHA1_SIZE];
|
2020-01-30 20:29:11 +00:00
|
|
|
mbedtls_sha1_ret(reinterpret_cast<u8*>(hashes.h1), sizeof(hashes.h1), h2_hash);
|
|
|
|
if (memcmp(h2_hash, hashes.h2[block_index / 8 % 8], SHA1_SIZE))
|
2019-03-26 16:22:18 +00:00
|
|
|
return false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
u8 h3_hash[SHA1_SIZE];
|
2020-01-30 20:29:11 +00:00
|
|
|
mbedtls_sha1_ret(reinterpret_cast<u8*>(hashes.h2), sizeof(hashes.h2), h3_hash);
|
2019-03-26 16:22:18 +00:00
|
|
|
if (memcmp(h3_hash, partition_details.h3_table->data() + block_index / 64 * SHA1_SIZE, SHA1_SIZE))
|
|
|
|
return false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2012-05-04 10:49:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-05 11:58:27 +00:00
|
|
|
bool VolumeWii::CheckBlockIntegrity(u64 block_index, const Partition& partition) const
|
|
|
|
{
|
|
|
|
auto it = m_partitions.find(partition);
|
|
|
|
if (it == m_partitions.end())
|
|
|
|
return false;
|
|
|
|
const PartitionDetails& partition_details = it->second;
|
|
|
|
const u64 cluster_offset =
|
|
|
|
partition.offset + *partition_details.data_offset + block_index * BLOCK_TOTAL_SIZE;
|
|
|
|
|
|
|
|
std::vector<u8> cluster(BLOCK_TOTAL_SIZE);
|
|
|
|
if (!m_reader->Read(cluster_offset, cluster.size(), cluster.data()))
|
|
|
|
return false;
|
2021-03-07 12:48:51 +00:00
|
|
|
return CheckBlockIntegrity(block_index, cluster.data(), partition);
|
2019-08-05 11:58:27 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
bool VolumeWii::HashGroup(const std::array<u8, BLOCK_DATA_SIZE> in[BLOCKS_PER_GROUP],
|
|
|
|
HashBlock out[BLOCKS_PER_GROUP],
|
|
|
|
const std::function<bool(size_t block)>& read_function)
|
2020-01-23 15:47:49 +00:00
|
|
|
{
|
2020-01-25 13:03:11 +00:00
|
|
|
std::array<std::future<void>, BLOCKS_PER_GROUP> hash_futures;
|
2020-04-15 19:15:08 +00:00
|
|
|
bool success = true;
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < BLOCKS_PER_GROUP; ++i)
|
|
|
|
{
|
2020-04-15 19:15:08 +00:00
|
|
|
if (read_function && success)
|
|
|
|
success = read_function(i);
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
hash_futures[i] = std::async(std::launch::async, [&in, &out, &hash_futures, success, i]() {
|
2020-01-25 13:03:11 +00:00
|
|
|
const size_t h1_base = Common::AlignDown(i, 8);
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
if (success)
|
2020-01-25 13:03:11 +00:00
|
|
|
{
|
|
|
|
// H0 hashes
|
|
|
|
for (size_t j = 0; j < 31; ++j)
|
2020-04-15 19:15:08 +00:00
|
|
|
mbedtls_sha1_ret(in[i].data() + j * 0x400, 0x400, out[i].h0[j]);
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
// H0 padding
|
2020-04-15 19:15:08 +00:00
|
|
|
std::memset(out[i].padding_0, 0, sizeof(HashBlock::padding_0));
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
// H1 hash
|
2020-04-15 19:15:08 +00:00
|
|
|
mbedtls_sha1_ret(reinterpret_cast<u8*>(out[i].h0), sizeof(HashBlock::h0),
|
|
|
|
out[h1_base].h1[i - h1_base]);
|
2020-01-25 13:03:11 +00:00
|
|
|
}
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
if (i % 8 == 7)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < 7; ++j)
|
|
|
|
hash_futures[h1_base + j].get();
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
if (success)
|
2020-01-25 13:03:11 +00:00
|
|
|
{
|
|
|
|
// H1 padding
|
2020-04-15 19:15:08 +00:00
|
|
|
std::memset(out[h1_base].padding_1, 0, sizeof(HashBlock::padding_1));
|
2020-01-25 13:03:11 +00:00
|
|
|
|
|
|
|
// H1 copies
|
|
|
|
for (size_t j = 1; j < 8; ++j)
|
2020-04-15 19:15:08 +00:00
|
|
|
std::memcpy(out[h1_base + j].h1, out[h1_base].h1, sizeof(HashBlock::h1));
|
2020-01-25 13:03:11 +00:00
|
|
|
|
|
|
|
// H2 hash
|
2020-04-15 19:15:08 +00:00
|
|
|
mbedtls_sha1_ret(reinterpret_cast<u8*>(out[i].h1), sizeof(HashBlock::h1),
|
|
|
|
out[0].h2[h1_base / 8]);
|
2020-01-25 13:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == BLOCKS_PER_GROUP - 1)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < 7; ++j)
|
|
|
|
hash_futures[j * 8 + 7].get();
|
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
if (success)
|
2020-01-25 13:03:11 +00:00
|
|
|
{
|
|
|
|
// H2 padding
|
2020-04-15 19:15:08 +00:00
|
|
|
std::memset(out[0].padding_2, 0, sizeof(HashBlock::padding_2));
|
2020-01-25 13:03:11 +00:00
|
|
|
|
|
|
|
// H2 copies
|
|
|
|
for (size_t j = 1; j < BLOCKS_PER_GROUP; ++j)
|
2020-04-15 19:15:08 +00:00
|
|
|
std::memcpy(out[j].h2, out[0].h2, sizeof(HashBlock::h2));
|
2020-01-25 13:03:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-01-23 15:47:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
// Wait for all the async tasks to finish
|
|
|
|
hash_futures.back().get();
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VolumeWii::EncryptGroup(
|
|
|
|
u64 offset, u64 partition_data_offset, u64 partition_data_decrypted_size,
|
|
|
|
const std::array<u8, AES_KEY_SIZE>& key, BlobReader* blob,
|
|
|
|
std::array<u8, GROUP_TOTAL_SIZE>* out,
|
|
|
|
const std::function<void(HashBlock hash_blocks[BLOCKS_PER_GROUP])>& hash_exception_callback)
|
|
|
|
{
|
|
|
|
std::vector<std::array<u8, BLOCK_DATA_SIZE>> unencrypted_data(BLOCKS_PER_GROUP);
|
|
|
|
std::vector<HashBlock> unencrypted_hashes(BLOCKS_PER_GROUP);
|
|
|
|
|
|
|
|
const bool success =
|
|
|
|
HashGroup(unencrypted_data.data(), unencrypted_hashes.data(), [&](size_t block) {
|
|
|
|
if (offset + (block + 1) * BLOCK_DATA_SIZE <= partition_data_decrypted_size)
|
|
|
|
{
|
|
|
|
if (!blob->ReadWiiDecrypted(offset + block * BLOCK_DATA_SIZE, BLOCK_DATA_SIZE,
|
|
|
|
unencrypted_data[block].data(), partition_data_offset))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unencrypted_data[block].fill(0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!success)
|
2020-01-25 13:03:11 +00:00
|
|
|
return false;
|
2020-01-23 15:47:49 +00:00
|
|
|
|
2020-01-27 15:12:56 +00:00
|
|
|
if (hash_exception_callback)
|
|
|
|
hash_exception_callback(unencrypted_hashes.data());
|
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
const unsigned int threads =
|
|
|
|
std::min(BLOCKS_PER_GROUP, std::max<unsigned int>(1, std::thread::hardware_concurrency()));
|
|
|
|
|
|
|
|
std::vector<std::future<void>> encryption_futures(threads);
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
mbedtls_aes_context aes_context;
|
|
|
|
mbedtls_aes_setkey_enc(&aes_context, key.data(), 128);
|
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
for (size_t i = 0; i < threads; ++i)
|
2020-01-23 15:47:49 +00:00
|
|
|
{
|
2020-01-25 13:03:11 +00:00
|
|
|
encryption_futures[i] = std::async(
|
|
|
|
std::launch::async,
|
|
|
|
[&unencrypted_data, &unencrypted_hashes, &aes_context, &out](size_t start, size_t end) {
|
2020-07-31 23:17:23 +00:00
|
|
|
for (size_t j = start; j < end; ++j)
|
2020-01-25 13:03:11 +00:00
|
|
|
{
|
2020-07-31 23:17:23 +00:00
|
|
|
u8* out_ptr = out->data() + j * BLOCK_TOTAL_SIZE;
|
2020-01-25 13:03:11 +00:00
|
|
|
|
|
|
|
u8 iv[16] = {};
|
|
|
|
mbedtls_aes_crypt_cbc(&aes_context, MBEDTLS_AES_ENCRYPT, BLOCK_HEADER_SIZE, iv,
|
2020-07-31 23:17:23 +00:00
|
|
|
reinterpret_cast<u8*>(&unencrypted_hashes[j]), out_ptr);
|
2020-01-25 13:03:11 +00:00
|
|
|
|
|
|
|
std::memcpy(iv, out_ptr + 0x3D0, sizeof(iv));
|
|
|
|
mbedtls_aes_crypt_cbc(&aes_context, MBEDTLS_AES_ENCRYPT, BLOCK_DATA_SIZE, iv,
|
2020-07-31 23:17:23 +00:00
|
|
|
unencrypted_data[j].data(), out_ptr + BLOCK_HEADER_SIZE);
|
2020-01-25 13:03:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
i * BLOCKS_PER_GROUP / threads, (i + 1) * BLOCKS_PER_GROUP / threads);
|
2020-01-23 15:47:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 13:03:11 +00:00
|
|
|
for (std::future<void>& future : encryption_futures)
|
|
|
|
future.get();
|
|
|
|
|
2020-01-23 15:47:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-15 19:15:08 +00:00
|
|
|
void VolumeWii::DecryptBlockHashes(const u8* in, HashBlock* out, mbedtls_aes_context* aes_context)
|
|
|
|
{
|
|
|
|
std::array<u8, 16> iv;
|
|
|
|
iv.fill(0);
|
|
|
|
mbedtls_aes_crypt_cbc(aes_context, MBEDTLS_AES_DECRYPT, sizeof(HashBlock), iv.data(), in,
|
|
|
|
reinterpret_cast<u8*>(out));
|
|
|
|
}
|
|
|
|
|
2020-04-14 09:40:32 +00:00
|
|
|
void VolumeWii::DecryptBlockData(const u8* in, u8* out, mbedtls_aes_context* aes_context)
|
|
|
|
{
|
|
|
|
std::array<u8, 16> iv;
|
|
|
|
std::copy(&in[0x3d0], &in[0x3e0], iv.data());
|
|
|
|
mbedtls_aes_crypt_cbc(aes_context, MBEDTLS_AES_DECRYPT, BLOCK_DATA_SIZE, iv.data(),
|
|
|
|
&in[BLOCK_HEADER_SIZE], out);
|
|
|
|
}
|
|
|
|
|
2019-03-21 22:04:44 +00:00
|
|
|
} // namespace DiscIO
|