diff options
| author | Leo Lam <leolino.lam@gmail.com> | 2017-07-04 13:46:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-04 13:46:18 +0200 |
| commit | e0b94b55b87ce3e0698564a87773afa04459957b (patch) | |
| tree | cc4b6996ca6056f82836f70cc5cbc74fd9353af7 /Source/Core/DiscIO/FileSystemGCWii.cpp | |
| parent | aa1d750f30f94e2c80ecc3e8ad9cc865e2076b78 (diff) | |
| parent | a59edfe8cf4c3dd9275058ca1acd88019a3f6abf (diff) | |
Merge pull request #5651 from JosJuice/new-disc-extraction
Use new format for disc extraction
Diffstat (limited to 'Source/Core/DiscIO/FileSystemGCWii.cpp')
| -rw-r--r-- | Source/Core/DiscIO/FileSystemGCWii.cpp | 169 |
1 files changed, 12 insertions, 157 deletions
diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 615a33888b..bbc89cfc15 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -18,6 +18,7 @@ #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" +#include "DiscIO/DiscExtractor.h" #include "DiscIO/FileSystemGCWii.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" @@ -194,13 +195,11 @@ FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partitio else return; - const std::optional<u32> fst_offset_unshifted = m_volume->ReadSwapped<u32>(0x424, m_partition); - const std::optional<u32> fst_size_unshifted = m_volume->ReadSwapped<u32>(0x428, m_partition); - if (!fst_offset_unshifted || !fst_size_unshifted) + const std::optional<u64> fst_offset = GetFSTOffset(*m_volume, m_partition); + const std::optional<u64> fst_size = GetFSTSize(*m_volume, m_partition); + if (!fst_offset || !fst_size) return; - const u64 fst_offset = static_cast<u64>(*fst_offset_unshifted) << m_offset_shift; - const u64 fst_size = static_cast<u64>(*fst_size_unshifted) << m_offset_shift; - if (fst_size < FST_ENTRY_SIZE) + if (*fst_size < FST_ENTRY_SIZE) { ERROR_LOG(DISCIO, "File system is too small"); return; @@ -209,7 +208,7 @@ FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partitio // 128 MiB is more than the total amount of RAM in a Wii. // No file system should use anywhere near that much. static const u32 ARBITRARY_FILE_SYSTEM_SIZE_LIMIT = 128 * 1024 * 1024; - if (fst_size > ARBITRARY_FILE_SYSTEM_SIZE_LIMIT) + if (*fst_size > ARBITRARY_FILE_SYSTEM_SIZE_LIMIT) { // Without this check, Dolphin can crash by trying to allocate too much // memory when loading a disc image with an incorrect FST size. @@ -219,8 +218,8 @@ FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partitio } // Read the whole FST - m_file_system_table.resize(fst_size); - if (!m_volume->Read(fst_offset, fst_size, m_file_system_table.data(), m_partition)) + m_file_system_table.resize(*fst_size); + if (!m_volume->Read(*fst_offset, *fst_size, m_file_system_table.data(), m_partition)) { ERROR_LOG(DISCIO, "Couldn't read file system table"); return; @@ -234,20 +233,20 @@ FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partitio return; } - if (FST_ENTRY_SIZE * m_root.GetSize() > fst_size) + if (FST_ENTRY_SIZE * m_root.GetSize() > *fst_size) { ERROR_LOG(DISCIO, "File system has too many entries for its size"); return; } - // If the FST's final byte isn't 0, CFileInfoGCWii::GetName() can read past the end - if (m_file_system_table[fst_size - 1] != 0) + // If the FST's final byte isn't 0, FileInfoGCWii::GetName() can read past the end + if (m_file_system_table[*fst_size - 1] != 0) { ERROR_LOG(DISCIO, "File system does not end with a null byte"); return; } - m_valid = m_root.IsValid(fst_size, m_root); + m_valid = m_root.IsValid(*fst_size, m_root); } FileSystemGCWii::~FileSystemGCWii() = default; @@ -330,148 +329,4 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(u64 disc_offset) const return nullptr; } -u64 FileSystemGCWii::ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size, - u64 offset_in_file) const -{ - if (!file_info || file_info->IsDirectory()) - return 0; - - if (offset_in_file >= file_info->GetSize()) - return 0; - - u64 read_length = std::min(max_buffer_size, file_info->GetSize() - offset_in_file); - - DEBUG_LOG(DISCIO, "Reading %" PRIx64 " bytes at %" PRIx64 " from file %s. Offset: %" PRIx64 - " Size: %" PRIx32, - read_length, offset_in_file, file_info->GetPath().c_str(), file_info->GetOffset(), - file_info->GetSize()); - - m_volume->Read(file_info->GetOffset() + offset_in_file, read_length, buffer, m_partition); - return read_length; -} - -bool FileSystemGCWii::ExportFile(const FileInfo* file_info, - const std::string& export_filename) const -{ - if (!file_info || file_info->IsDirectory()) - return false; - - u64 remaining_size = file_info->GetSize(); - u64 file_offset = file_info->GetOffset(); - - File::IOFile f(export_filename, "wb"); - if (!f) - return false; - - bool result = true; - - while (remaining_size) - { - // Limit read size to 128 MB - size_t read_size = (size_t)std::min(remaining_size, (u64)0x08000000); - - std::vector<u8> buffer(read_size); - - result = m_volume->Read(file_offset, read_size, &buffer[0], m_partition); - - if (!result) - break; - - f.WriteBytes(&buffer[0], read_size); - - remaining_size -= read_size; - file_offset += read_size; - } - - return result; -} - -bool FileSystemGCWii::ExportApploader(const std::string& export_folder) const -{ - std::optional<u32> apploader_size = m_volume->ReadSwapped<u32>(0x2440 + 0x14, m_partition); - const std::optional<u32> trailer_size = m_volume->ReadSwapped<u32>(0x2440 + 0x18, m_partition); - constexpr u32 header_size = 0x20; - if (!apploader_size || !trailer_size) - return false; - *apploader_size += *trailer_size + header_size; - DEBUG_LOG(DISCIO, "Apploader size -> %x", *apploader_size); - - std::vector<u8> buffer(*apploader_size); - if (m_volume->Read(0x2440, *apploader_size, buffer.data(), m_partition)) - { - std::string export_name(export_folder + "/apploader.img"); - - File::IOFile apploader_file(export_name, "wb"); - if (apploader_file) - { - apploader_file.WriteBytes(buffer.data(), *apploader_size); - return true; - } - } - - return false; -} - -std::optional<u64> FileSystemGCWii::GetBootDOLOffset() const -{ - std::optional<u32> offset = m_volume->ReadSwapped<u32>(0x420, m_partition); - return offset ? static_cast<u64>(*offset) << m_offset_shift : std::optional<u64>(); -} - -std::optional<u32> FileSystemGCWii::GetBootDOLSize(u64 dol_offset) const -{ - u32 dol_size = 0; - - // Iterate through the 7 code segments - for (u8 i = 0; i < 7; i++) - { - const std::optional<u32> offset = - m_volume->ReadSwapped<u32>(dol_offset + 0x00 + i * 4, m_partition); - const std::optional<u32> size = - m_volume->ReadSwapped<u32>(dol_offset + 0x90 + i * 4, m_partition); - if (!offset || !size) - return {}; - dol_size = std::max(*offset + *size, dol_size); - } - - // Iterate through the 11 data segments - for (u8 i = 0; i < 11; i++) - { - const std::optional<u32> offset = - m_volume->ReadSwapped<u32>(dol_offset + 0x1c + i * 4, m_partition); - const std::optional<u32> size = - m_volume->ReadSwapped<u32>(dol_offset + 0xac + i * 4, m_partition); - if (!offset || !size) - return {}; - dol_size = std::max(*offset + *size, dol_size); - } - - return dol_size; -} - -bool FileSystemGCWii::ExportDOL(const std::string& export_folder) const -{ - std::optional<u64> dol_offset = GetBootDOLOffset(); - if (!dol_offset) - return false; - std::optional<u32> dol_size = GetBootDOLSize(*dol_offset); - if (!dol_size) - return false; - - std::vector<u8> buffer(*dol_size); - if (m_volume->Read(*dol_offset, *dol_size, buffer.data(), m_partition)) - { - std::string export_name(export_folder + "/boot.dol"); - - File::IOFile dol_file(export_name, "wb"); - if (dol_file) - { - dol_file.WriteBytes(&buffer[0], *dol_size); - return true; - } - } - - return false; -} - } // namespace |
