diff options
author | Lioncash <mathew1800@gmail.com> | 2018-07-19 05:25:07 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2018-07-19 05:45:22 +0200 |
commit | 9abc5763b6ade0f3e7e6b3542f45bb867a634bba (patch) | |
tree | 57cd9eb533d76cd5c9271863b6d37a6f61d83089 /src/core/file_sys/partition_filesystem.cpp | |
parent | Merge pull request #691 from lioncash/guard (diff) | |
download | yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar.gz yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar.bz2 yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar.lz yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar.xz yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.tar.zst yuzu-9abc5763b6ade0f3e7e6b3542f45bb867a634bba.zip |
Diffstat (limited to 'src/core/file_sys/partition_filesystem.cpp')
-rw-r--r-- | src/core/file_sys/partition_filesystem.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 15b1fb946..d4097a510 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -11,6 +11,11 @@ namespace FileSys { +bool PartitionFilesystem::Header::HasValidMagicValue() const { + return magic == Common::MakeMagic('H', 'F', 'S', '0') || + magic == Common::MakeMagic('P', 'F', 'S', '0'); +} + PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // At least be as large as the header if (file->GetSize() < sizeof(Header)) { @@ -20,19 +25,17 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // For cartridges, HFSs can get very large, so we need to calculate the size up to // the actual content itself instead of just blindly reading in the entire file. - Header pfs_header; if (sizeof(Header) != file->ReadObject(&pfs_header)) { status = Loader::ResultStatus::Error; return; } - if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && - pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { + if (!pfs_header.HasValidMagicValue()) { status = Loader::ResultStatus::ErrorInvalidFormat; return; } - bool is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); + is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); size_t metadata_size = @@ -40,27 +43,13 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // Actually read in now... std::vector<u8> file_data = file->ReadBytes(metadata_size); + const size_t total_size = file_data.size(); - if (file_data.size() != metadata_size) { - status = Loader::ResultStatus::Error; - return; - } - - size_t total_size = file_data.size(); - if (total_size < sizeof(Header)) { + if (total_size != metadata_size) { status = Loader::ResultStatus::Error; return; } - memcpy(&pfs_header, file_data.data(), sizeof(Header)); - if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && - pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { - status = Loader::ResultStatus::ErrorInvalidFormat; - return; - } - - is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); - size_t entries_offset = sizeof(Header); size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size); content_offset = strtab_offset + pfs_header.strtab_size; |