2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-05-21 19:19:15 +00:00
|
|
|
|
2014-11-14 02:28:27 +00:00
|
|
|
// DiscScrubber removes the garbage data from discs (currently Wii only) which
|
2009-05-21 19:19:15 +00:00
|
|
|
// is on the disc due to encryption
|
|
|
|
|
2014-11-14 02:28:27 +00:00
|
|
|
// It could be adapted to GameCube discs, but the gain is most likely negligible,
|
2009-05-21 19:19:15 +00: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 18:54:46 +00:00
|
|
|
#pragma once
|
2009-05-21 19:19:15 +00:00
|
|
|
|
2017-01-04 19:31:38 +00:00
|
|
|
#include <array>
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
2017-01-04 19:31:38 +00:00
|
|
|
#include <vector>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-05-21 19:19:15 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
namespace File
|
|
|
|
{
|
|
|
|
class IOFile;
|
|
|
|
}
|
2009-05-21 19:19:15 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2015-08-08 17:59:33 +00:00
|
|
|
class FileInfo;
|
2017-06-06 09:49:01 +00:00
|
|
|
class Volume;
|
2015-06-13 10:51:24 +00:00
|
|
|
struct Partition;
|
2017-01-04 19:31:38 +00:00
|
|
|
|
|
|
|
class DiscScrubber final
|
2009-05-21 19:19:15 +00:00
|
|
|
{
|
2017-01-04 19:31:38 +00:00
|
|
|
public:
|
|
|
|
DiscScrubber();
|
|
|
|
~DiscScrubber();
|
|
|
|
|
2019-03-30 15:20:45 +00:00
|
|
|
bool SetupScrub(const Volume* disc, int block_size);
|
2017-01-04 19:31:38 +00:00
|
|
|
size_t GetNextBlock(File::IOFile& in, u8* buffer);
|
2019-03-30 15:20:45 +00:00
|
|
|
bool CanBlockBeScrubbed(u64 offset) const;
|
2017-01-04 19:31:38 +00:00
|
|
|
|
|
|
|
private:
|
2017-01-04 20:39:27 +00:00
|
|
|
struct PartitionHeader final
|
2017-01-04 19:31:38 +00:00
|
|
|
{
|
2017-01-04 20:39:27 +00:00
|
|
|
u8* ticket[0x2a4];
|
|
|
|
u32 tmd_size;
|
|
|
|
u64 tmd_offset;
|
|
|
|
u32 cert_chain_size;
|
|
|
|
u64 cert_chain_offset;
|
2017-01-04 19:31:38 +00:00
|
|
|
// H3Size is always 0x18000
|
2017-01-04 20:39:27 +00:00
|
|
|
u64 h3_offset;
|
|
|
|
u64 data_offset;
|
|
|
|
u64 data_size;
|
2017-01-04 19:31:38 +00:00
|
|
|
// TMD would be here
|
2017-01-04 20:39:27 +00:00
|
|
|
u64 dol_offset;
|
|
|
|
u64 dol_size;
|
|
|
|
u64 fst_offset;
|
|
|
|
u64 fst_size;
|
|
|
|
u32 apploader_size;
|
|
|
|
u32 apploader_trailer_size;
|
2017-01-04 19:31:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void MarkAsUsed(u64 offset, u64 size);
|
|
|
|
void MarkAsUsedE(u64 partition_data_offset, u64 offset, u64 size);
|
2018-09-20 17:32:52 +00:00
|
|
|
u64 ToClusterOffset(u64 offset) const;
|
2015-06-13 10:51:24 +00:00
|
|
|
bool ReadFromVolume(u64 offset, u32& buffer, const Partition& partition);
|
|
|
|
bool ReadFromVolume(u64 offset, u64& buffer, const Partition& partition);
|
2017-01-04 19:31:38 +00:00
|
|
|
bool ParseDisc();
|
2015-06-13 10:51:24 +00:00
|
|
|
bool ParsePartitionData(const Partition& partition, PartitionHeader* header);
|
2015-08-08 17:59:33 +00:00
|
|
|
void ParseFileSystemData(u64 partition_data_offset, const FileInfo& directory);
|
2017-01-04 19:31:38 +00:00
|
|
|
|
2019-03-30 15:20:45 +00:00
|
|
|
const Volume* m_disc;
|
2017-01-04 19:31:38 +00:00
|
|
|
|
2017-01-04 20:39:27 +00: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 19:31:38 +00:00
|
|
|
};
|
2009-05-21 19:19:15 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace DiscIO
|