[VFS] Fix sketchy ReadMagic function...

Haven't been able to test yet though - hope it's reading in the correct endian!
This commit is contained in:
emoose 2020-01-11 19:04:31 +00:00 committed by illusion98
parent 79081ca272
commit 7eb5fa230a
2 changed files with 6 additions and 7 deletions

View File

@ -698,11 +698,9 @@ StfsContainerDevice::BlockHash StfsContainerDevice::STFSGetLevel0HashEntry(
return STFSGetLevelNHashEntry(map_ptr, block_index, 0, use_secondary_block);
}
const char* StfsContainerDevice::ReadMagic(const std::wstring& path) {
uint32_t StfsContainerDevice::ReadMagic(const std::wstring& path) {
auto map = MappedMemory::Open(path, MappedMemory::Mode::kRead, 0, 4);
auto magic_data = xe::load<uint32_t>(map->data());
auto magic_bytes = static_cast<char*>(static_cast<void*>(&magic_data));
return std::move(magic_bytes);
return xe::load_and_swap<uint32_t>(map->data());
}
bool StfsContainerDevice::ResolveFromFolder(const std::wstring& path) {
@ -728,8 +726,9 @@ bool StfsContainerDevice::ResolveFromFolder(const std::wstring& path) {
auto path = xe::join_paths(current_file.path, current_file.name);
auto magic = ReadMagic(path);
if (memcmp(magic, "LIVE", 4) == 0 || memcmp(magic, "PIRS", 4) == 0 ||
memcmp(magic, "CON ", 4) == 0) {
if (magic == XContentPackageType::kPackageTypeCon ||
magic == XContentPackageType::kPackageTypeLive ||
magic == XContentPackageType::kPackageTypePirs) {
local_path_ = xe::join_paths(current_file.path, current_file.name);
XELOGI("STFS Package found: %s", xe::to_string(local_path_).c_str());
return true;

View File

@ -448,7 +448,7 @@ class StfsContainerDevice : public Device {
const uint32_t kSTFSDataBlocksPerHashLevel[3] = {0xAA, 0x70E4, 0x4AF768};
const char* ReadMagic(const std::wstring& path);
uint32_t ReadMagic(const std::wstring& path);
bool ResolveFromFolder(const std::wstring& path);
Error MapFiles();