mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #4883 from JosJuice/dvd-timing-address-translation-2
DVDInterface: Translate Wii partition offsets for timing purposes
This commit is contained in:
@ -37,6 +37,7 @@ public:
|
||||
|
||||
virtual bool GetTitleID(u64*) const { return false; }
|
||||
virtual std::vector<u8> GetTMD() const { return {}; }
|
||||
virtual u64 PartitionOffsetToRawOffset(u64 offset) const { return offset; }
|
||||
virtual std::string GetGameID() const = 0;
|
||||
virtual std::string GetMakerID() const = 0;
|
||||
virtual u16 GetRevision() const = 0;
|
||||
|
@ -60,26 +60,26 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
|
||||
|
||||
FileMon::FindFilename(_ReadOffset);
|
||||
|
||||
std::vector<u8> read_buffer(s_block_total_size);
|
||||
std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE);
|
||||
while (_Length > 0)
|
||||
{
|
||||
// Calculate block offset
|
||||
u64 Block = _ReadOffset / s_block_data_size;
|
||||
u64 Offset = _ReadOffset % s_block_data_size;
|
||||
u64 Block = _ReadOffset / BLOCK_DATA_SIZE;
|
||||
u64 Offset = _ReadOffset % BLOCK_DATA_SIZE;
|
||||
|
||||
if (m_LastDecryptedBlockOffset != Block)
|
||||
{
|
||||
// Read the current block
|
||||
if (!m_pReader->Read(m_VolumeOffset + m_dataOffset + Block * s_block_total_size,
|
||||
s_block_total_size, read_buffer.data()))
|
||||
if (!m_pReader->Read(m_VolumeOffset + m_dataOffset + Block * BLOCK_TOTAL_SIZE,
|
||||
BLOCK_TOTAL_SIZE, read_buffer.data()))
|
||||
return false;
|
||||
|
||||
// Decrypt the block's data.
|
||||
// 0x3D0 - 0x3DF in m_pBuffer will be overwritten,
|
||||
// but that won't affect anything, because we won't
|
||||
// use the content of m_pBuffer anymore after this
|
||||
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, s_block_data_size,
|
||||
&read_buffer[0x3D0], &read_buffer[s_block_header_size],
|
||||
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, BLOCK_DATA_SIZE,
|
||||
&read_buffer[0x3D0], &read_buffer[BLOCK_HEADER_SIZE],
|
||||
m_LastDecryptedBlock);
|
||||
m_LastDecryptedBlockOffset = Block;
|
||||
|
||||
@ -90,7 +90,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
|
||||
}
|
||||
|
||||
// Copy the decrypted data
|
||||
u64 MaxSizeToCopy = s_block_data_size - Offset;
|
||||
u64 MaxSizeToCopy = BLOCK_DATA_SIZE - Offset;
|
||||
u64 CopySize = (_Length > MaxSizeToCopy) ? MaxSizeToCopy : _Length;
|
||||
memcpy(_pBuffer, &m_LastDecryptedBlock[Offset], (size_t)CopySize);
|
||||
|
||||
@ -140,6 +140,12 @@ std::vector<u8> CVolumeWiiCrypted::GetTMD() const
|
||||
return buffer;
|
||||
}
|
||||
|
||||
u64 CVolumeWiiCrypted::PartitionOffsetToRawOffset(u64 offset) const
|
||||
{
|
||||
return m_VolumeOffset + m_dataOffset + (offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE) +
|
||||
(offset % BLOCK_DATA_SIZE);
|
||||
}
|
||||
|
||||
std::string CVolumeWiiCrypted::GetGameID() const
|
||||
{
|
||||
if (m_pReader == nullptr)
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override;
|
||||
bool GetTitleID(u64* buffer) const override;
|
||||
std::vector<u8> GetTMD() const override;
|
||||
u64 PartitionOffsetToRawOffset(u64 offset) const override;
|
||||
std::string GetGameID() const override;
|
||||
std::string GetMakerID() const override;
|
||||
u16 GetRevision() const override;
|
||||
@ -53,11 +54,11 @@ public:
|
||||
u64 GetSize() const override;
|
||||
u64 GetRawSize() const override;
|
||||
|
||||
private:
|
||||
static const unsigned int s_block_header_size = 0x0400;
|
||||
static const unsigned int s_block_data_size = 0x7C00;
|
||||
static const unsigned int s_block_total_size = s_block_header_size + s_block_data_size;
|
||||
static constexpr unsigned int BLOCK_HEADER_SIZE = 0x0400;
|
||||
static constexpr unsigned int BLOCK_DATA_SIZE = 0x7C00;
|
||||
static constexpr unsigned int BLOCK_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IBlobReader> m_pReader;
|
||||
std::unique_ptr<mbedtls_aes_context> m_AES_ctx;
|
||||
|
||||
@ -65,7 +66,7 @@ private:
|
||||
u64 m_dataOffset;
|
||||
|
||||
mutable u64 m_LastDecryptedBlockOffset;
|
||||
mutable unsigned char m_LastDecryptedBlock[s_block_data_size];
|
||||
mutable unsigned char m_LastDecryptedBlock[BLOCK_DATA_SIZE];
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user