Merge pull request #3047 from Tilka/decompress_for_md5
DolphinWX: decompress discs to calculate MD5 hash
This commit is contained in:
commit
4c3dc0c1ae
|
@ -77,23 +77,19 @@ bool SectorReader::Read(u64 offset, u64 size, u8* out_ptr)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 toCopy = m_blocksize - positionInBlock;
|
|
||||||
if (toCopy >= remain)
|
|
||||||
{
|
|
||||||
const u8* data = GetBlockData(block);
|
const u8* data = GetBlockData(block);
|
||||||
if (!data)
|
if (!data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
u32 toCopy = m_blocksize - positionInBlock;
|
||||||
|
if (toCopy >= remain)
|
||||||
|
{
|
||||||
// Yay, we are done!
|
// Yay, we are done!
|
||||||
memcpy(out_ptr, data + positionInBlock, (size_t)remain);
|
memcpy(out_ptr, data + positionInBlock, (size_t)remain);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const u8* data = GetBlockData(block);
|
|
||||||
if (!data)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
memcpy(out_ptr, data + positionInBlock, toCopy);
|
memcpy(out_ptr, data + positionInBlock, toCopy);
|
||||||
out_ptr += toCopy;
|
out_ptr += toCopy;
|
||||||
remain -= toCopy;
|
remain -= toCopy;
|
||||||
|
|
|
@ -44,7 +44,7 @@ CISOFileReader* CISOFileReader::Create(const std::string& filename)
|
||||||
|
|
||||||
u64 CISOFileReader::GetDataSize() const
|
u64 CISOFileReader::GetDataSize() const
|
||||||
{
|
{
|
||||||
return GetRawSize();
|
return CISO_MAP_SIZE * m_block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 CISOFileReader::GetRawSize() const
|
u64 CISOFileReader::GetRawSize() const
|
||||||
|
|
|
@ -37,7 +37,11 @@ public:
|
||||||
static CISOFileReader* Create(const std::string& filename);
|
static CISOFileReader* Create(const std::string& filename);
|
||||||
|
|
||||||
BlobType GetBlobType() const override { return BlobType::CISO; }
|
BlobType GetBlobType() const override { return BlobType::CISO; }
|
||||||
|
|
||||||
|
// The CISO format does not save the original file size.
|
||||||
|
// This function returns an upper bound.
|
||||||
u64 GetDataSize() const override;
|
u64 GetDataSize() const override;
|
||||||
|
|
||||||
u64 GetRawSize() const override;
|
u64 GetRawSize() const override;
|
||||||
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ WbfsFileReader::WbfsFileReader(const std::string& filename)
|
||||||
m_wlba_table = new u16[m_blocks_per_disc];
|
m_wlba_table = new u16[m_blocks_per_disc];
|
||||||
m_files[0]->file.Seek(m_hd_sector_size + WII_DISC_HEADER_SIZE /*+ i * m_disc_info_size*/, SEEK_SET);
|
m_files[0]->file.Seek(m_hd_sector_size + WII_DISC_HEADER_SIZE /*+ i * m_disc_info_size*/, SEEK_SET);
|
||||||
m_files[0]->file.ReadBytes(m_wlba_table, m_blocks_per_disc * sizeof(u16));
|
m_files[0]->file.ReadBytes(m_wlba_table, m_blocks_per_disc * sizeof(u16));
|
||||||
|
for (size_t i = 0; i < m_blocks_per_disc; i++)
|
||||||
|
m_wlba_table[i] = Common::swap16(m_wlba_table[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
WbfsFileReader::~WbfsFileReader()
|
WbfsFileReader::~WbfsFileReader()
|
||||||
|
@ -49,6 +51,11 @@ WbfsFileReader::~WbfsFileReader()
|
||||||
delete[] m_wlba_table;
|
delete[] m_wlba_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 WbfsFileReader::GetDataSize() const
|
||||||
|
{
|
||||||
|
return WII_SECTOR_COUNT * WII_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
bool WbfsFileReader::OpenFiles(const std::string& filename)
|
bool WbfsFileReader::OpenFiles(const std::string& filename)
|
||||||
{
|
{
|
||||||
m_total_files = 0;
|
m_total_files = 0;
|
||||||
|
@ -81,37 +88,26 @@ bool WbfsFileReader::OpenFiles(const std::string& filename)
|
||||||
|
|
||||||
bool WbfsFileReader::ReadHeader()
|
bool WbfsFileReader::ReadHeader()
|
||||||
{
|
{
|
||||||
m_files[0]->file.Seek(4, SEEK_SET);
|
|
||||||
|
|
||||||
// Read hd size info
|
// Read hd size info
|
||||||
m_files[0]->file.ReadBytes(&m_hd_sector_count, 4);
|
m_files[0]->file.ReadBytes(&m_header, sizeof(WbfsHeader));
|
||||||
m_hd_sector_count = Common::swap32(m_hd_sector_count);
|
m_header.hd_sector_count = Common::swap32(m_header.hd_sector_count);
|
||||||
|
|
||||||
m_files[0]->file.ReadBytes(&m_hd_sector_shift, 1);
|
m_hd_sector_size = 1ull << m_header.hd_sector_shift;
|
||||||
m_hd_sector_size = 1ull << m_hd_sector_shift;
|
|
||||||
|
|
||||||
if (m_size != (m_hd_sector_count * m_hd_sector_size))
|
if (m_size != (m_header.hd_sector_count * m_hd_sector_size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Read wbfs cluster info
|
// Read wbfs cluster info
|
||||||
m_files[0]->file.ReadBytes(&m_wbfs_sector_shift, 1);
|
m_wbfs_sector_size = 1ull << m_header.wbfs_sector_shift;
|
||||||
m_wbfs_sector_size = 1ull << m_wbfs_sector_shift;
|
|
||||||
m_wbfs_sector_count = m_size / m_wbfs_sector_size;
|
m_wbfs_sector_count = m_size / m_wbfs_sector_size;
|
||||||
|
|
||||||
if (m_wbfs_sector_size < WII_SECTOR_SIZE)
|
if (m_wbfs_sector_size < WII_SECTOR_SIZE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_blocks_per_disc = (WII_SECTOR_COUNT * WII_SECTOR_SIZE) / m_wbfs_sector_size;
|
m_blocks_per_disc = (WII_SECTOR_COUNT * WII_SECTOR_SIZE + m_wbfs_sector_size - 1) / m_wbfs_sector_size;
|
||||||
m_disc_info_size = align(WII_DISC_HEADER_SIZE + m_blocks_per_disc * 2, m_hd_sector_size);
|
m_disc_info_size = align(WII_DISC_HEADER_SIZE + m_blocks_per_disc * sizeof(u16), m_hd_sector_size);
|
||||||
|
|
||||||
// Read disc table
|
return m_header.disc_table[0] != 0;
|
||||||
m_files[0]->file.Seek(2, SEEK_CUR);
|
|
||||||
m_files[0]->file.ReadBytes(m_disc_table, 500);
|
|
||||||
|
|
||||||
if (m_disc_table[0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
|
@ -122,7 +118,7 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
File::IOFile& data_file = SeekToCluster(offset, &read_size);
|
File::IOFile& data_file = SeekToCluster(offset, &read_size);
|
||||||
if (read_size == 0)
|
if (read_size == 0)
|
||||||
return false;
|
return false;
|
||||||
read_size = (read_size > nbytes) ? nbytes : read_size;
|
read_size = std::min(read_size, nbytes);
|
||||||
|
|
||||||
if (!data_file.ReadBytes(out_ptr, read_size))
|
if (!data_file.ReadBytes(out_ptr, read_size))
|
||||||
{
|
{
|
||||||
|
@ -140,10 +136,10 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
|
|
||||||
File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
||||||
{
|
{
|
||||||
u64 base_cluster = (offset >> m_wbfs_sector_shift);
|
u64 base_cluster = (offset >> m_header.wbfs_sector_shift);
|
||||||
if (base_cluster < m_blocks_per_disc)
|
if (base_cluster < m_blocks_per_disc)
|
||||||
{
|
{
|
||||||
u64 cluster_address = m_wbfs_sector_size * Common::swap16(m_wlba_table[base_cluster]);
|
u64 cluster_address = m_wbfs_sector_size * m_wlba_table[base_cluster];
|
||||||
u64 cluster_offset = offset & (m_wbfs_sector_size - 1);
|
u64 cluster_offset = offset & (m_wbfs_sector_size - 1);
|
||||||
u64 final_address = cluster_address + cluster_offset;
|
u64 final_address = cluster_address + cluster_offset;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,12 @@ public:
|
||||||
static WbfsFileReader* Create(const std::string& filename);
|
static WbfsFileReader* Create(const std::string& filename);
|
||||||
|
|
||||||
BlobType GetBlobType() const override { return BlobType::WBFS; }
|
BlobType GetBlobType() const override { return BlobType::WBFS; }
|
||||||
u64 GetDataSize() const override { return m_size; }
|
|
||||||
|
// The WBFS format does not save the original file size.
|
||||||
|
// This function returns a constant upper bound
|
||||||
|
// (the size of a double-layer Wii disc).
|
||||||
|
u64 GetDataSize() const override;
|
||||||
|
|
||||||
u64 GetRawSize() const override { return m_size; }
|
u64 GetRawSize() const override { return m_size; }
|
||||||
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
||||||
|
|
||||||
|
@ -48,15 +53,21 @@ private:
|
||||||
u64 m_size;
|
u64 m_size;
|
||||||
|
|
||||||
u64 m_hd_sector_size;
|
u64 m_hd_sector_size;
|
||||||
u8 m_hd_sector_shift;
|
|
||||||
u32 m_hd_sector_count;
|
|
||||||
|
|
||||||
u64 m_wbfs_sector_size;
|
u64 m_wbfs_sector_size;
|
||||||
u8 m_wbfs_sector_shift;
|
|
||||||
u64 m_wbfs_sector_count;
|
u64 m_wbfs_sector_count;
|
||||||
u64 m_disc_info_size;
|
u64 m_disc_info_size;
|
||||||
|
|
||||||
u8 m_disc_table[500];
|
#pragma pack(1)
|
||||||
|
struct WbfsHeader
|
||||||
|
{
|
||||||
|
char magic[4];
|
||||||
|
u32 hd_sector_count;
|
||||||
|
u8 hd_sector_shift;
|
||||||
|
u8 wbfs_sector_shift;
|
||||||
|
u8 padding[2];
|
||||||
|
u8 disc_table[500];
|
||||||
|
} m_header;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
u16* m_wlba_table;
|
u16* m_wlba_table;
|
||||||
u64 m_blocks_per_disc;
|
u64 m_blocks_per_disc;
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "Core/GeckoCodeConfig.h"
|
#include "Core/GeckoCodeConfig.h"
|
||||||
#include "Core/PatchEngine.h"
|
#include "Core/PatchEngine.h"
|
||||||
#include "Core/Boot/Boot.h"
|
#include "Core/Boot/Boot.h"
|
||||||
|
#include "DiscIO/Blob.h"
|
||||||
#include "DiscIO/Filesystem.h"
|
#include "DiscIO/Filesystem.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
#include "DiscIO/VolumeCreator.h"
|
#include "DiscIO/VolumeCreator.h"
|
||||||
|
@ -1237,8 +1238,8 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
|
||||||
u64 read_offset = 0;
|
u64 read_offset = 0;
|
||||||
mbedtls_md5_context ctx;
|
mbedtls_md5_context ctx;
|
||||||
|
|
||||||
File::IOFile file(OpenGameListItem.GetFileName(), "rb");
|
std::unique_ptr<DiscIO::IBlobReader> file(DiscIO::CreateBlobReader(OpenGameListItem.GetFileName()));
|
||||||
u64 game_size = file.GetSize();
|
u64 game_size = file->GetDataSize();
|
||||||
|
|
||||||
wxProgressDialog progressDialog(
|
wxProgressDialog progressDialog(
|
||||||
_("Computing MD5 checksum"),
|
_("Computing MD5 checksum"),
|
||||||
|
@ -1254,13 +1255,14 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
|
||||||
|
|
||||||
while(read_offset < game_size)
|
while(read_offset < game_size)
|
||||||
{
|
{
|
||||||
if (!progressDialog.Update((int)((double)read_offset / (double)game_size * 1000), _("Computing MD5 checksum")))
|
if (!progressDialog.Update((int)((double)read_offset / (double)game_size * 1000)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t read_size;
|
size_t read_size = std::min((u64)data.size(), game_size - read_offset);
|
||||||
file.ReadArray(&data[0], data.size(), &read_size);
|
if (!file->Read(read_offset, read_size, data.data()))
|
||||||
mbedtls_md5_update(&ctx, &data[0], read_size);
|
return;
|
||||||
|
|
||||||
|
mbedtls_md5_update(&ctx, data.data(), read_size);
|
||||||
read_offset += read_size;
|
read_offset += read_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue