mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-01 12:15:03 -06:00
loader: Fix identifying zcci files when system files are not set up
This commit is contained in:
parent
2c8297c34c
commit
e2afe011ec
@ -261,15 +261,15 @@ AppLoader_THREEDSX::AppLoader_THREEDSX(Core::System& system_, FileUtil::IOFile&&
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile* file) {
|
FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile* file) {
|
||||||
u32 magic;
|
u32 magic{};
|
||||||
file->Seek(0, SEEK_SET);
|
|
||||||
if (1 != file->ReadArray<u32>(&magic, 1))
|
|
||||||
return FileType::Error;
|
|
||||||
|
|
||||||
if (MakeMagic('3', 'D', 'S', 'X') == magic ||
|
if (file->Seek(0, SEEK_SET) && 1 == file->ReadArray<u32>(&magic, 1)) {
|
||||||
(MakeMagic('Z', '3', 'D', 'S') == magic &&
|
if (MakeMagic('3', 'D', 'S', 'X') == magic ||
|
||||||
FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file) == MakeMagic('3', 'D', 'S', 'X')))
|
(MakeMagic('Z', '3', 'D', 'S') == magic &&
|
||||||
return FileType::THREEDSX;
|
FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file) ==
|
||||||
|
MakeMagic('3', 'D', 'S', 'X')))
|
||||||
|
return FileType::THREEDSX;
|
||||||
|
}
|
||||||
|
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -357,13 +357,12 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const
|
|||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
|
||||||
FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile* file) {
|
FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile* file) {
|
||||||
u32 magic;
|
u32 magic{};
|
||||||
file->Seek(0, SEEK_SET);
|
|
||||||
if (1 != file->ReadArray<u32>(&magic, 1))
|
|
||||||
return FileType::Error;
|
|
||||||
|
|
||||||
if (MakeMagic('\x7f', 'E', 'L', 'F') == magic)
|
if (file->Seek(0, SEEK_SET) && 1 == file->ReadArray<u32>(&magic, 1)) {
|
||||||
return FileType::ELF;
|
if (MakeMagic('\x7f', 'E', 'L', 'F') == magic)
|
||||||
|
return FileType::ELF;
|
||||||
|
}
|
||||||
|
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,35 +37,17 @@ static constexpr u64 UPDATE_TID_HIGH = 0x0004000e00000000;
|
|||||||
static constexpr u64 DLP_CHILD_TID_HIGH = 0x0004000100000000;
|
static constexpr u64 DLP_CHILD_TID_HIGH = 0x0004000100000000;
|
||||||
|
|
||||||
FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile* file) {
|
FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile* file) {
|
||||||
u32 magic;
|
u32 magic{};
|
||||||
file->Seek(0x100, SEEK_SET);
|
|
||||||
if (1 != file->ReadArray<u32>(&magic, 1))
|
|
||||||
return FileType::Error;
|
|
||||||
|
|
||||||
if (MakeMagic('N', 'C', 'S', 'D') == magic)
|
|
||||||
return FileType::CCI;
|
|
||||||
|
|
||||||
if (MakeMagic('N', 'C', 'C', 'H') == magic)
|
|
||||||
return FileType::CXI;
|
|
||||||
|
|
||||||
std::unique_ptr<FileUtil::IOFile> file_crypto = HW::UniqueData::OpenUniqueCryptoFile(
|
std::unique_ptr<FileUtil::IOFile> file_crypto = HW::UniqueData::OpenUniqueCryptoFile(
|
||||||
file->Filename(), "rb", HW::UniqueData::UniqueCryptoFileID::NCCH);
|
file->Filename(), "rb", HW::UniqueData::UniqueCryptoFileID::NCCH);
|
||||||
|
|
||||||
file_crypto->Seek(0x100, SEEK_SET);
|
// Check compressed NCCH file
|
||||||
if (1 != file_crypto->ReadArray<u32>(&magic, 1))
|
|
||||||
return FileType::Error;
|
|
||||||
|
|
||||||
if (MakeMagic('N', 'C', 'S', 'D') == magic)
|
|
||||||
return FileType::CCI;
|
|
||||||
|
|
||||||
if (MakeMagic('N', 'C', 'C', 'H') == magic)
|
|
||||||
return FileType::CXI;
|
|
||||||
|
|
||||||
std::optional<u32> magic_zstd = FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file);
|
std::optional<u32> magic_zstd = FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file);
|
||||||
if (!magic_zstd.has_value()) {
|
if (!magic_zstd.has_value()) {
|
||||||
|
// Handle compressed and crypto NCCH file
|
||||||
magic_zstd = FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file_crypto.get());
|
magic_zstd = FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file_crypto.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magic_zstd.has_value()) {
|
if (magic_zstd.has_value()) {
|
||||||
if (MakeMagic('N', 'C', 'S', 'D') == magic_zstd)
|
if (MakeMagic('N', 'C', 'S', 'D') == magic_zstd)
|
||||||
return FileType::CCI;
|
return FileType::CCI;
|
||||||
@ -74,6 +56,24 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile* file) {
|
|||||||
return FileType::CXI;
|
return FileType::CXI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check normal NCCH file
|
||||||
|
if (file->Seek(0x100, SEEK_SET) && 1 == file->ReadArray<u32>(&magic, 1)) {
|
||||||
|
if (MakeMagic('N', 'C', 'S', 'D') == magic)
|
||||||
|
return FileType::CCI;
|
||||||
|
|
||||||
|
if (MakeMagic('N', 'C', 'C', 'H') == magic)
|
||||||
|
return FileType::CXI;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check crypto NCCH file
|
||||||
|
if (file_crypto->Seek(0x100, SEEK_SET) && 1 == file_crypto->ReadArray<u32>(&magic, 1)) {
|
||||||
|
if (MakeMagic('N', 'C', 'S', 'D') == magic)
|
||||||
|
return FileType::CCI;
|
||||||
|
|
||||||
|
if (MakeMagic('N', 'C', 'C', 'H') == magic)
|
||||||
|
return FileType::CXI;
|
||||||
|
}
|
||||||
|
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user