From 61c3cb8cf3c7b724c5db9f7ab984ff8a769b6b37 Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 9 Sep 2018 16:44:40 +0800 Subject: [PATCH] [nstool] Fix bug in UserSettings where NSO files were incorrectly identified as NACP. --- programs/nstool/source/UserSettings.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/programs/nstool/source/UserSettings.cpp b/programs/nstool/source/UserSettings.cpp index e9ad32e..5b837b0 100644 --- a/programs/nstool/source/UserSettings.cpp +++ b/programs/nstool/source/UserSettings.cpp @@ -626,7 +626,7 @@ FileType UserSettings::getFileTypeFromString(const std::string& type_str) FileType UserSettings::determineFileTypeFromFile(const std::string& path) { - static const size_t kMaxReadSize = 0x4000; + static const size_t kMaxReadSize = 0x5000; FileType file_type = FILE_INVALID; fnd::SimpleFile file; fnd::Vec scratch; @@ -640,6 +640,8 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path) // close file file.close(); + fnd::SimpleTextOutput::hxdStyleDump(scratch.data(), 0x100); + // _TYPE_PTR resolves to a pointer of type 'st' located at scratch.data() #define _TYPE_PTR(st) ((st*)(scratch.data())) #define _ASSERT_SIZE(sz) (scratch.size() >= (sz)) @@ -662,12 +664,6 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path) // test nca else if (determineValidNcaFromSample(scratch)) file_type = FILE_NCA; - // test cnmt - else if (determineValidCnmtFromSample(scratch)) - file_type = FILE_CNMT; - // test nacp - else if (determineValidNacpFromSample(scratch)) - file_type = FILE_NACP; // test nso else if (_ASSERT_SIZE(sizeof(nn::hac::sNsoHeader)) && _TYPE_PTR(nn::hac::sNsoHeader)->st_magic.get() == nn::hac::nso::kNsoStructMagic) file_type = FILE_NSO; @@ -683,6 +679,16 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path) // test hb asset else if (_ASSERT_SIZE(sizeof(nn::hac::sAssetHeader)) && _TYPE_PTR(nn::hac::sAssetHeader)->st_magic.get() == nn::hac::aset::kAssetStructMagic) file_type = FILE_HB_ASSET; + + // do heuristics + // test cnmt + else if (determineValidCnmtFromSample(scratch)) + file_type = FILE_CNMT; + // test nacp + else if (determineValidNacpFromSample(scratch)) + file_type = FILE_NACP; + + // else unrecognised else file_type = FILE_INVALID;