2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2009-05-21 21:19:15 +02:00
|
|
|
|
2014-11-14 03:28:27 +01:00
|
|
|
// DiscScrubber removes the garbage data from discs (currently Wii only) which
|
2009-05-21 21:19:15 +02:00
|
|
|
// is on the disc due to encryption
|
|
|
|
|
2014-11-14 03:28:27 +01:00
|
|
|
// It could be adapted to GameCube discs, but the gain is most likely negligible,
|
2009-05-21 21:19:15 +02:00
|
|
|
// and having 1:1 backups of discs is always nice when they are reasonably sized
|
|
|
|
|
|
|
|
// Note: the technique is inspired by Wiiscrubber, but much simpler - intentionally :)
|
|
|
|
|
2014-02-10 19:54:46 +01:00
|
|
|
#pragma once
|
2009-05-21 21:19:15 +02:00
|
|
|
|
2017-01-04 20:31:38 +01:00
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
2014-03-12 20:33:41 +01:00
|
|
|
#include <string>
|
2017-01-04 20:31:38 +01:00
|
|
|
#include <vector>
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-05-21 21:19:15 +02:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
namespace File
|
|
|
|
{
|
|
|
|
class IOFile;
|
|
|
|
}
|
2009-05-21 21:19:15 +02:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-01-04 20:31:38 +01:00
|
|
|
class IVolume;
|
|
|
|
|
|
|
|
class DiscScrubber final
|
2009-05-21 21:19:15 +02:00
|
|
|
{
|
2017-01-04 20:31:38 +01:00
|
|
|
public:
|
|
|
|
DiscScrubber();
|
|
|
|
~DiscScrubber();
|
|
|
|
|
|
|
|
bool SetupScrub(const std::string& filename, int block_size);
|
|
|
|
size_t GetNextBlock(File::IOFile& in, u8* buffer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct SPartitionHeader final
|
|
|
|
{
|
|
|
|
u8* Ticket[0x2a4];
|
|
|
|
u32 TMDSize;
|
|
|
|
u64 TMDOffset;
|
|
|
|
u32 CertChainSize;
|
|
|
|
u64 CertChainOffset;
|
|
|
|
// H3Size is always 0x18000
|
|
|
|
u64 H3Offset;
|
|
|
|
u64 DataOffset;
|
|
|
|
u64 DataSize;
|
|
|
|
// TMD would be here
|
|
|
|
u64 DOLOffset;
|
|
|
|
u64 DOLSize;
|
|
|
|
u64 FSTOffset;
|
|
|
|
u64 FSTSize;
|
|
|
|
u32 ApploaderSize;
|
|
|
|
u32 ApploaderTrailerSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SPartition final
|
|
|
|
{
|
|
|
|
u32 GroupNumber;
|
|
|
|
u32 Number;
|
|
|
|
u64 Offset;
|
|
|
|
u32 Type;
|
|
|
|
SPartitionHeader Header;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SPartitionGroup final
|
|
|
|
{
|
|
|
|
u32 numPartitions;
|
|
|
|
u64 PartitionsOffset;
|
|
|
|
std::vector<SPartition> PartitionsVec;
|
|
|
|
};
|
|
|
|
|
|
|
|
void MarkAsUsed(u64 offset, u64 size);
|
|
|
|
void MarkAsUsedE(u64 partition_data_offset, u64 offset, u64 size);
|
|
|
|
bool ReadFromVolume(u64 offset, u32& buffer, bool decrypt);
|
|
|
|
bool ReadFromVolume(u64 offset, u64& buffer, bool decrypt);
|
|
|
|
bool ParseDisc();
|
|
|
|
bool ParsePartitionData(SPartition& partition);
|
|
|
|
|
|
|
|
std::string m_Filename;
|
|
|
|
std::unique_ptr<IVolume> m_disc;
|
|
|
|
|
|
|
|
std::array<SPartitionGroup, 4> PartitionGroup{};
|
2009-05-21 21:19:15 +02:00
|
|
|
|
2017-01-04 20:31:38 +01:00
|
|
|
std::vector<u8> m_FreeTable;
|
|
|
|
u64 m_FileSize = 0;
|
|
|
|
u64 m_BlockCount = 0;
|
|
|
|
u32 m_BlockSize = 0;
|
|
|
|
bool m_isScrubbing = false;
|
|
|
|
};
|
2009-05-21 21:19:15 +02:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
} // namespace DiscIO
|