Improve integrity check validation code
This commit is contained in:
parent
9d2681ecc9
commit
fc6ada7e78
1 changed files with 14 additions and 29 deletions
|
@ -4,8 +4,8 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h"
|
||||
#include "common/alignment.h"
|
||||
#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
|
@ -15,19 +15,17 @@ constexpr inline u32 ILog2(u32 val)
|
|||
return static_cast<u32>((sizeof(u32) * 8) - 1 - std::countl_zero<u32>(val));
|
||||
}
|
||||
|
||||
void IntegrityVerificationStorage::Initialize(VirtualFile hs,
|
||||
VirtualFile ds,
|
||||
s64 verif_block_size,
|
||||
s64 upper_layer_verif_block_size,
|
||||
bool is_real_data)
|
||||
{
|
||||
// Validate preconditions.
|
||||
ASSERT(verif_block_size >= HashSize);
|
||||
void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size,
|
||||
s64 upper_layer_verif_block_size, bool is_real_data) {
|
||||
|
||||
// Set storages.
|
||||
m_hash_storage = hs;
|
||||
m_data_storage = ds;
|
||||
|
||||
// Validate preconditions.
|
||||
ASSERT(verif_block_size >= HashSize);
|
||||
ASSERT(m_data_storage != null);
|
||||
|
||||
// Set verification block sizes.
|
||||
m_verification_block_size = verif_block_size;
|
||||
m_verification_block_order = ILog2(static_cast<u32>(verif_block_size));
|
||||
|
@ -40,28 +38,20 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs,
|
|||
ASSERT(m_upper_layer_verification_block_size == 1ll << m_upper_layer_verification_block_order);
|
||||
|
||||
// Validate sizes.
|
||||
if (m_data_storage != nullptr) {
|
||||
s64 hash_size = m_hash_storage->GetSize();
|
||||
s64 data_size = m_data_storage->GetSize();
|
||||
ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size);
|
||||
} else {
|
||||
LOG_ERROR(Loader,
|
||||
"Failed to initialize integrity verification store. Game, update, or DLC may not "
|
||||
"work.");
|
||||
}
|
||||
s64 hash_size = m_hash_storage->GetSize();
|
||||
s64 data_size = m_data_storage->GetSize();
|
||||
ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size);
|
||||
|
||||
// Set data.
|
||||
m_is_real_data = is_real_data;
|
||||
}
|
||||
|
||||
void IntegrityVerificationStorage::Finalize()
|
||||
{
|
||||
void IntegrityVerificationStorage::Finalize() {
|
||||
m_hash_storage = VirtualFile();
|
||||
m_data_storage = VirtualFile();
|
||||
}
|
||||
|
||||
size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const
|
||||
{
|
||||
size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const {
|
||||
// Succeed if zero size.
|
||||
if (size == 0) {
|
||||
return size;
|
||||
|
@ -69,14 +59,9 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset
|
|||
|
||||
// Validate arguments.
|
||||
ASSERT(buffer != nullptr);
|
||||
ASSERT(m_data_storage != nullptr);
|
||||
|
||||
if (m_data_storage == nullptr) {
|
||||
LOG_ERROR(Loader,
|
||||
"Integrity verification store failed read operation. Game, update or DLC may not "
|
||||
"work.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Validate the offset.
|
||||
s64 data_size = m_data_storage->GetSize();
|
||||
ASSERT(offset <= static_cast<size_t>(data_size));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue