2019-03-21 22:04:56 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-03-26 16:22:18 +00:00
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
2019-03-21 22:04:56 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-03-30 11:45:00 +00:00
|
|
|
#include <mbedtls/md5.h>
|
|
|
|
#include <mbedtls/sha1.h>
|
|
|
|
|
2019-03-21 22:04:56 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2019-03-30 15:20:45 +00:00
|
|
|
#include "DiscIO/DiscScrubber.h"
|
2019-03-21 22:04:56 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
|
|
|
|
// To be used as follows:
|
|
|
|
//
|
|
|
|
// VolumeVerifier verifier(volume);
|
|
|
|
// verifier.Start();
|
|
|
|
// while (verifier.GetBytesProcessed() != verifier.GetTotalBytes())
|
|
|
|
// verifier.Process();
|
|
|
|
// verifier.Finish();
|
|
|
|
// auto result = verifier.GetResult();
|
|
|
|
//
|
|
|
|
// Start, Process and Finish may take some time to run.
|
|
|
|
//
|
|
|
|
// GetResult() can be called before the processing is finished, but the result will be incomplete.
|
|
|
|
|
|
|
|
namespace IOS::ES
|
|
|
|
{
|
2019-03-30 16:42:31 +00:00
|
|
|
struct Content;
|
2019-03-21 22:04:56 +00:00
|
|
|
class SignedBlobReader;
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace IOS::ES
|
2019-03-21 22:04:56 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
class FileInfo;
|
|
|
|
|
|
|
|
class VolumeVerifier final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Severity
|
|
|
|
{
|
|
|
|
None, // Only used internally
|
|
|
|
Low,
|
|
|
|
Medium,
|
|
|
|
High,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Problem
|
|
|
|
{
|
|
|
|
Severity severity;
|
|
|
|
std::string text;
|
|
|
|
};
|
|
|
|
|
2019-03-30 11:45:00 +00:00
|
|
|
template <typename T>
|
|
|
|
struct Hashes
|
|
|
|
{
|
|
|
|
T crc32;
|
|
|
|
T md5;
|
|
|
|
T sha1;
|
|
|
|
};
|
|
|
|
|
2019-03-21 22:04:56 +00:00
|
|
|
struct Result
|
|
|
|
{
|
2019-03-30 11:45:00 +00:00
|
|
|
Hashes<std::vector<u8>> hashes;
|
2019-03-21 22:04:56 +00:00
|
|
|
std::string summary_text;
|
|
|
|
std::vector<Problem> problems;
|
|
|
|
};
|
|
|
|
|
2019-03-30 11:45:00 +00:00
|
|
|
VolumeVerifier(const Volume& volume, Hashes<bool> hashes_to_calculate);
|
2019-03-21 22:04:56 +00:00
|
|
|
void Start();
|
|
|
|
void Process();
|
|
|
|
u64 GetBytesProcessed() const;
|
|
|
|
u64 GetTotalBytes() const;
|
|
|
|
void Finish();
|
|
|
|
const Result& GetResult() const;
|
|
|
|
|
|
|
|
private:
|
2019-03-26 16:22:18 +00:00
|
|
|
struct BlockToVerify
|
|
|
|
{
|
|
|
|
Partition partition;
|
|
|
|
u64 offset;
|
|
|
|
u64 block_index;
|
|
|
|
};
|
|
|
|
|
2019-03-21 22:04:56 +00:00
|
|
|
void CheckPartitions();
|
|
|
|
bool CheckPartition(const Partition& partition); // Returns false if partition should be ignored
|
2019-03-26 16:22:18 +00:00
|
|
|
std::string GetPartitionName(std::optional<u32> type) const;
|
2019-03-21 22:04:56 +00:00
|
|
|
void CheckCorrectlySigned(const Partition& partition, const std::string& error_text);
|
|
|
|
bool IsDebugSigned() const;
|
|
|
|
bool ShouldHaveChannelPartition() const;
|
|
|
|
bool ShouldHaveInstallPartition() const;
|
|
|
|
bool ShouldHaveMasterpiecePartitions() const;
|
|
|
|
bool ShouldBeDualLayer() const;
|
|
|
|
void CheckDiscSize();
|
|
|
|
u64 GetBiggestUsedOffset();
|
|
|
|
u64 GetBiggestUsedOffset(const FileInfo& file_info) const;
|
|
|
|
void CheckMisc();
|
2019-03-30 11:45:00 +00:00
|
|
|
void SetUpHashing();
|
2019-03-30 16:42:31 +00:00
|
|
|
bool CheckContentIntegrity(const IOS::ES::Content& content);
|
2019-03-21 22:04:56 +00:00
|
|
|
|
|
|
|
void AddProblem(Severity severity, const std::string& text);
|
|
|
|
|
|
|
|
const Volume& m_volume;
|
|
|
|
Result m_result;
|
|
|
|
bool m_is_tgc;
|
|
|
|
bool m_is_datel;
|
|
|
|
bool m_is_not_retail;
|
|
|
|
|
2019-03-30 11:45:00 +00:00
|
|
|
Hashes<bool> m_hashes_to_calculate;
|
|
|
|
bool m_calculating_any_hash;
|
|
|
|
unsigned long m_crc32_context;
|
|
|
|
mbedtls_md5_context m_md5_context;
|
|
|
|
mbedtls_sha1_context m_sha1_context;
|
|
|
|
|
2019-03-30 15:20:45 +00:00
|
|
|
DiscScrubber m_scrubber;
|
2019-03-30 16:42:31 +00:00
|
|
|
std::vector<u64> m_content_offsets;
|
|
|
|
u16 m_content_index = 0;
|
2019-03-26 16:22:18 +00:00
|
|
|
std::vector<BlockToVerify> m_blocks;
|
|
|
|
size_t m_block_index = 0; // Index in m_blocks, not index in a specific partition
|
|
|
|
std::map<Partition, size_t> m_block_errors;
|
2019-03-30 15:20:45 +00:00
|
|
|
std::map<Partition, size_t> m_unused_block_errors;
|
2019-03-26 16:22:18 +00:00
|
|
|
|
2019-03-21 22:04:56 +00:00
|
|
|
bool m_started;
|
|
|
|
bool m_done;
|
|
|
|
u64 m_progress;
|
|
|
|
u64 m_max_progress;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace DiscIO
|