2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2009-05-21 13:19:15 -06:00
|
|
|
|
2014-11-13 19:28:27 -07:00
|
|
|
// DiscScrubber removes the garbage data from discs (currently Wii only) which
|
2009-05-21 13:19:15 -06:00
|
|
|
// is on the disc due to encryption
|
|
|
|
|
2014-11-13 19:28:27 -07:00
|
|
|
// It could be adapted to GameCube discs, but the gain is most likely negligible,
|
2009-05-21 13:19:15 -06: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 11:54:46 -07:00
|
|
|
#pragma once
|
2009-05-21 13:19:15 -06:00
|
|
|
|
2017-01-04 12:31:38 -07:00
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2017-01-04 12:31:38 -07:00
|
|
|
#include <vector>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-05-21 13:19:15 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
namespace File
|
|
|
|
{
|
|
|
|
class IOFile;
|
|
|
|
}
|
2009-05-21 13:19:15 -06:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-01-04 12:31:38 -07:00
|
|
|
class IVolume;
|
|
|
|
|
|
|
|
class DiscScrubber final
|
2009-05-21 13:19:15 -06:00
|
|
|
{
|
2017-01-04 12:31:38 -07:00
|
|
|
public:
|
|
|
|
DiscScrubber();
|
|
|
|
~DiscScrubber();
|
|
|
|
|
|
|
|
bool SetupScrub(const std::string& filename, int block_size);
|
|
|
|
size_t GetNextBlock(File::IOFile& in, u8* buffer);
|
|
|
|
|
|
|
|
private:
|
2017-01-04 13:39:27 -07:00
|
|
|
struct PartitionHeader final
|
2017-01-04 12:31:38 -07:00
|
|
|
{
|
2017-01-04 13:39:27 -07:00
|
|
|
u8* ticket[0x2a4];
|
|
|
|
u32 tmd_size;
|
|
|
|
u64 tmd_offset;
|
|
|
|
u32 cert_chain_size;
|
|
|
|
u64 cert_chain_offset;
|
2017-01-04 12:31:38 -07:00
|
|
|
// H3Size is always 0x18000
|
2017-01-04 13:39:27 -07:00
|
|
|
u64 h3_offset;
|
|
|
|
u64 data_offset;
|
|
|
|
u64 data_size;
|
2017-01-04 12:31:38 -07:00
|
|
|
// TMD would be here
|
2017-01-04 13:39:27 -07:00
|
|
|
u64 dol_offset;
|
|
|
|
u64 dol_size;
|
|
|
|
u64 fst_offset;
|
|
|
|
u64 fst_size;
|
|
|
|
u32 apploader_size;
|
|
|
|
u32 apploader_trailer_size;
|
2017-01-04 12:31:38 -07:00
|
|
|
};
|
|
|
|
|
2017-01-04 13:39:27 -07:00
|
|
|
struct Partition final
|
2017-01-04 12:31:38 -07:00
|
|
|
{
|
2017-01-04 13:39:27 -07:00
|
|
|
u32 group_number;
|
|
|
|
u32 number;
|
|
|
|
u64 offset;
|
|
|
|
u32 type;
|
|
|
|
PartitionHeader header;
|
2017-01-04 12:31:38 -07:00
|
|
|
};
|
|
|
|
|
2017-01-04 13:39:27 -07:00
|
|
|
struct PartitionGroup final
|
2017-01-04 12:31:38 -07:00
|
|
|
{
|
2017-01-04 13:39:27 -07:00
|
|
|
u32 num_partitions;
|
|
|
|
u64 partitions_offset;
|
|
|
|
std::vector<Partition> partitions;
|
2017-01-04 12:31:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
2017-01-04 13:39:27 -07:00
|
|
|
bool ParsePartitionData(Partition& partition);
|
2017-01-04 12:31:38 -07:00
|
|
|
|
2017-01-04 13:39:27 -07:00
|
|
|
std::string m_filename;
|
2017-01-04 12:31:38 -07:00
|
|
|
std::unique_ptr<IVolume> m_disc;
|
|
|
|
|
2017-01-04 13:39:27 -07:00
|
|
|
std::array<PartitionGroup, 4> m_partition_group{};
|
2009-05-21 13:19:15 -06:00
|
|
|
|
2017-01-04 13:39:27 -07:00
|
|
|
std::vector<u8> m_free_table;
|
|
|
|
u64 m_file_size = 0;
|
|
|
|
u64 m_block_count = 0;
|
|
|
|
u32 m_block_size = 0;
|
|
|
|
bool m_is_scrubbing = false;
|
2017-01-04 12:31:38 -07:00
|
|
|
};
|
2009-05-21 13:19:15 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
} // namespace DiscIO
|