VolumeWii: Change the format of partition maps

Having a separate map for each type of data is a bit unnecessary.
This commit is contained in:
JosJuice 2017-07-04 16:08:12 +02:00
parent e0b94b55b8
commit 333b6d99d2
2 changed files with 24 additions and 21 deletions

View File

@ -107,10 +107,8 @@ VolumeWii::VolumeWii(std::unique_ptr<BlobReader> reader)
// We've read everything. Time to store it! (The reason we don't store anything // We've read everything. Time to store it! (The reason we don't store anything
// earlier is because we want to be able to skip adding the partition if an error occurs.) // earlier is because we want to be able to skip adding the partition if an error occurs.)
const Partition partition(partition_offset); const Partition partition(partition_offset);
m_partition_types[partition] = *partition_type; m_partitions.emplace(partition, PartitionDetails{std::move(aes_context), std::move(ticket),
m_partition_keys[partition] = std::move(aes_context); std::move(tmd), *partition_type});
m_partition_tickets[partition] = std::move(ticket);
m_partition_tmds[partition] = std::move(tmd);
if (m_game_partition == PARTITION_NONE && *partition_type == 0) if (m_game_partition == PARTITION_NONE && *partition_type == 0)
m_game_partition = partition; m_game_partition = partition;
} }
@ -127,10 +125,10 @@ bool VolumeWii::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, const Partition
return m_pReader->Read(_ReadOffset, _Length, _pBuffer); return m_pReader->Read(_ReadOffset, _Length, _pBuffer);
// Get the decryption key for the partition // Get the decryption key for the partition
auto it = m_partition_keys.find(partition); auto it = m_partitions.find(partition);
if (it == m_partition_keys.end()) if (it == m_partitions.end())
return false; return false;
mbedtls_aes_context* aes_context = it->second.get(); mbedtls_aes_context* aes_context = it->second.key.get();
std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE); std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE);
while (_Length > 0) while (_Length > 0)
@ -177,7 +175,7 @@ bool VolumeWii::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, const Partition
std::vector<Partition> VolumeWii::GetPartitions() const std::vector<Partition> VolumeWii::GetPartitions() const
{ {
std::vector<Partition> partitions; std::vector<Partition> partitions;
for (const auto& pair : m_partition_keys) for (const auto& pair : m_partitions)
partitions.push_back(pair.first); partitions.push_back(pair.first);
return partitions; return partitions;
} }
@ -189,8 +187,8 @@ Partition VolumeWii::GetGamePartition() const
std::optional<u32> VolumeWii::GetPartitionType(const Partition& partition) const std::optional<u32> VolumeWii::GetPartitionType(const Partition& partition) const
{ {
auto it = m_partition_types.find(partition); auto it = m_partitions.find(partition);
return it != m_partition_types.end() ? it->second : std::optional<u32>(); return it != m_partitions.end() ? it->second.type : std::optional<u32>();
} }
std::optional<u64> VolumeWii::GetTitleID(const Partition& partition) const std::optional<u64> VolumeWii::GetTitleID(const Partition& partition) const
@ -203,14 +201,14 @@ std::optional<u64> VolumeWii::GetTitleID(const Partition& partition) const
const IOS::ES::TicketReader& VolumeWii::GetTicket(const Partition& partition) const const IOS::ES::TicketReader& VolumeWii::GetTicket(const Partition& partition) const
{ {
auto it = m_partition_tickets.find(partition); auto it = m_partitions.find(partition);
return it != m_partition_tickets.end() ? it->second : INVALID_TICKET; return it != m_partitions.end() ? it->second.ticket : INVALID_TICKET;
} }
const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const
{ {
auto it = m_partition_tmds.find(partition); auto it = m_partitions.find(partition);
return it != m_partition_tmds.end() ? it->second : INVALID_TMD; return it != m_partitions.end() ? it->second.tmd : INVALID_TMD;
} }
u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition) u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition)
@ -338,10 +336,10 @@ u64 VolumeWii::GetRawSize() const
bool VolumeWii::CheckIntegrity(const Partition& partition) const bool VolumeWii::CheckIntegrity(const Partition& partition) const
{ {
// Get the decryption key for the partition // Get the decryption key for the partition
auto it = m_partition_keys.find(partition); auto it = m_partitions.find(partition);
if (it == m_partition_keys.end()) if (it == m_partitions.end())
return false; return false;
mbedtls_aes_context* aes_context = it->second.get(); mbedtls_aes_context* aes_context = it->second.key.get();
// Get partition data size // Get partition data size
u32 partSizeDiv4; u32 partSizeDiv4;

View File

@ -64,11 +64,16 @@ public:
static constexpr unsigned int BLOCK_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE; static constexpr unsigned int BLOCK_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE;
private: private:
struct PartitionDetails
{
std::unique_ptr<mbedtls_aes_context> key;
IOS::ES::TicketReader ticket;
IOS::ES::TMDReader tmd;
u32 type;
};
std::unique_ptr<BlobReader> m_pReader; std::unique_ptr<BlobReader> m_pReader;
std::map<Partition, u32> m_partition_types; std::map<Partition, PartitionDetails> m_partitions;
std::map<Partition, std::unique_ptr<mbedtls_aes_context>> m_partition_keys;
std::map<Partition, IOS::ES::TicketReader> m_partition_tickets;
std::map<Partition, IOS::ES::TMDReader> m_partition_tmds;
Partition m_game_partition; Partition m_game_partition;
mutable u64 m_last_decrypted_block; mutable u64 m_last_decrypted_block;