VolumeWiiCrypted: Use constant naming style for constants
This commit is contained in:
parent
fb2098917b
commit
c96bcace2f
|
@ -60,26 +60,26 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
|
||||||
|
|
||||||
FileMon::FindFilename(_ReadOffset);
|
FileMon::FindFilename(_ReadOffset);
|
||||||
|
|
||||||
std::vector<u8> read_buffer(s_block_total_size);
|
std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE);
|
||||||
while (_Length > 0)
|
while (_Length > 0)
|
||||||
{
|
{
|
||||||
// Calculate block offset
|
// Calculate block offset
|
||||||
u64 Block = _ReadOffset / s_block_data_size;
|
u64 Block = _ReadOffset / BLOCK_DATA_SIZE;
|
||||||
u64 Offset = _ReadOffset % s_block_data_size;
|
u64 Offset = _ReadOffset % BLOCK_DATA_SIZE;
|
||||||
|
|
||||||
if (m_LastDecryptedBlockOffset != Block)
|
if (m_LastDecryptedBlockOffset != Block)
|
||||||
{
|
{
|
||||||
// Read the current block
|
// Read the current block
|
||||||
if (!m_pReader->Read(m_VolumeOffset + m_dataOffset + Block * s_block_total_size,
|
if (!m_pReader->Read(m_VolumeOffset + m_dataOffset + Block * BLOCK_TOTAL_SIZE,
|
||||||
s_block_total_size, read_buffer.data()))
|
BLOCK_TOTAL_SIZE, read_buffer.data()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Decrypt the block's data.
|
// Decrypt the block's data.
|
||||||
// 0x3D0 - 0x3DF in m_pBuffer will be overwritten,
|
// 0x3D0 - 0x3DF in m_pBuffer will be overwritten,
|
||||||
// but that won't affect anything, because we won't
|
// but that won't affect anything, because we won't
|
||||||
// use the content of m_pBuffer anymore after this
|
// use the content of m_pBuffer anymore after this
|
||||||
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, s_block_data_size,
|
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, BLOCK_DATA_SIZE,
|
||||||
&read_buffer[0x3D0], &read_buffer[s_block_header_size],
|
&read_buffer[0x3D0], &read_buffer[BLOCK_HEADER_SIZE],
|
||||||
m_LastDecryptedBlock);
|
m_LastDecryptedBlock);
|
||||||
m_LastDecryptedBlockOffset = Block;
|
m_LastDecryptedBlockOffset = Block;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the decrypted data
|
// Copy the decrypted data
|
||||||
u64 MaxSizeToCopy = s_block_data_size - Offset;
|
u64 MaxSizeToCopy = BLOCK_DATA_SIZE - Offset;
|
||||||
u64 CopySize = (_Length > MaxSizeToCopy) ? MaxSizeToCopy : _Length;
|
u64 CopySize = (_Length > MaxSizeToCopy) ? MaxSizeToCopy : _Length;
|
||||||
memcpy(_pBuffer, &m_LastDecryptedBlock[Offset], (size_t)CopySize);
|
memcpy(_pBuffer, &m_LastDecryptedBlock[Offset], (size_t)CopySize);
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,9 @@ public:
|
||||||
u64 GetRawSize() const override;
|
u64 GetRawSize() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const unsigned int s_block_header_size = 0x0400;
|
static constexpr unsigned int BLOCK_HEADER_SIZE = 0x0400;
|
||||||
static const unsigned int s_block_data_size = 0x7C00;
|
static constexpr unsigned int 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_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE;
|
||||||
|
|
||||||
std::unique_ptr<IBlobReader> m_pReader;
|
std::unique_ptr<IBlobReader> m_pReader;
|
||||||
std::unique_ptr<mbedtls_aes_context> m_AES_ctx;
|
std::unique_ptr<mbedtls_aes_context> m_AES_ctx;
|
||||||
|
@ -65,7 +65,7 @@ private:
|
||||||
u64 m_dataOffset;
|
u64 m_dataOffset;
|
||||||
|
|
||||||
mutable u64 m_LastDecryptedBlockOffset;
|
mutable u64 m_LastDecryptedBlockOffset;
|
||||||
mutable unsigned char m_LastDecryptedBlock[s_block_data_size];
|
mutable unsigned char m_LastDecryptedBlock[BLOCK_DATA_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue