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:
parent
e0b94b55b8
commit
333b6d99d2
|
@ -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
|
||||
// earlier is because we want to be able to skip adding the partition if an error occurs.)
|
||||
const Partition partition(partition_offset);
|
||||
m_partition_types[partition] = *partition_type;
|
||||
m_partition_keys[partition] = std::move(aes_context);
|
||||
m_partition_tickets[partition] = std::move(ticket);
|
||||
m_partition_tmds[partition] = std::move(tmd);
|
||||
m_partitions.emplace(partition, PartitionDetails{std::move(aes_context), std::move(ticket),
|
||||
std::move(tmd), *partition_type});
|
||||
if (m_game_partition == PARTITION_NONE && *partition_type == 0)
|
||||
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);
|
||||
|
||||
// Get the decryption key for the partition
|
||||
auto it = m_partition_keys.find(partition);
|
||||
if (it == m_partition_keys.end())
|
||||
auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
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);
|
||||
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> partitions;
|
||||
for (const auto& pair : m_partition_keys)
|
||||
for (const auto& pair : m_partitions)
|
||||
partitions.push_back(pair.first);
|
||||
return partitions;
|
||||
}
|
||||
|
@ -189,8 +187,8 @@ Partition VolumeWii::GetGamePartition() const
|
|||
|
||||
std::optional<u32> VolumeWii::GetPartitionType(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partition_types.find(partition);
|
||||
return it != m_partition_types.end() ? it->second : std::optional<u32>();
|
||||
auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? it->second.type : std::optional<u32>();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
auto it = m_partition_tickets.find(partition);
|
||||
return it != m_partition_tickets.end() ? it->second : INVALID_TICKET;
|
||||
auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? it->second.ticket : INVALID_TICKET;
|
||||
}
|
||||
|
||||
const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partition_tmds.find(partition);
|
||||
return it != m_partition_tmds.end() ? it->second : INVALID_TMD;
|
||||
auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? it->second.tmd : INVALID_TMD;
|
||||
}
|
||||
|
||||
u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition)
|
||||
|
@ -338,10 +336,10 @@ u64 VolumeWii::GetRawSize() const
|
|||
bool VolumeWii::CheckIntegrity(const Partition& partition) const
|
||||
{
|
||||
// Get the decryption key for the partition
|
||||
auto it = m_partition_keys.find(partition);
|
||||
if (it == m_partition_keys.end())
|
||||
auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
mbedtls_aes_context* aes_context = it->second.get();
|
||||
mbedtls_aes_context* aes_context = it->second.key.get();
|
||||
|
||||
// Get partition data size
|
||||
u32 partSizeDiv4;
|
||||
|
|
|
@ -64,11 +64,16 @@ public:
|
|||
static constexpr unsigned int BLOCK_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE;
|
||||
|
||||
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::map<Partition, u32> m_partition_types;
|
||||
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;
|
||||
std::map<Partition, PartitionDetails> m_partitions;
|
||||
Partition m_game_partition;
|
||||
|
||||
mutable u64 m_last_decrypted_block;
|
||||
|
|
Loading…
Reference in New Issue