Fix verifying CFA NCCH images

This commit is contained in:
d0k3 2016-12-19 19:17:03 +01:00
parent 37e24c1825
commit b98bba9a6f

View File

@ -285,14 +285,21 @@ u32 VerifyNcchFile(const char* path, u32 offset, u32 size) {
// open file, get NCCH, ExeFS header
if (fx_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK)
return 1;
f_lseek(&file, offset);
if (GetNcchHeaders(&ncch, NULL, &exefs, &file) != 0) {
f_lseek(&file, offset);
if (GetNcchHeaders(&ncch, NULL, NULL, &file) != 0) {
if (!offset) ShowPrompt(false, "%s\nError: Not a NCCH file", pathstr);
fx_close(&file);
return 1;
}
f_lseek(&file, offset);
if (ncch.size_exefs && (GetNcchHeaders(&ncch, NULL, &exefs, &file) != 0)) {
if (!offset) ShowPrompt(false, "%s\nError: Bad ExeFS header", pathstr);
fx_close(&file);
return 1;
}
// size checks
if (!size) size = f_size(&file) - offset;
if ((f_size(&file) < offset) || (size < ncch.size * NCCH_MEDIA_UNIT)) {