From cd1037857a98b90040098d8cb89def058831508c Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 2 Oct 2022 03:54:15 +0300 Subject: [PATCH] [NCCH] You guessed it, more parsing --- include/loader/ncch.hpp | 2 +- src/core/loader/ncch.cpp | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/loader/ncch.hpp b/include/loader/ncch.hpp index 186abd8f..9316eb33 100644 --- a/include/loader/ncch.hpp +++ b/include/loader/ncch.hpp @@ -15,7 +15,7 @@ struct NCCH { bool isNew3DS = false; bool initialized = false; - bool compressExeFS = false; + bool compressCode = false; // Shows whether the .code file in the ExeFS is compressed bool mountRomFS = false; bool encrypted = false; bool fixedCryptoKey = false; diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index c6c26134..aab26001 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -1,4 +1,4 @@ -#include +#include #include "loader/ncch.hpp" #include "memory.hpp" @@ -45,7 +45,7 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) { Helpers::panic("Encrypted NCSD file"); } - compressExeFS = (exheader[0xD] & 1) != 0; + compressCode = (exheader[0xD] & 1) != 0; stackSize = *(u32*)&exheader[0x1C]; bssSize = *(u32*)&exheader[0x3C]; } @@ -54,8 +54,8 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) { // Read ExeFS if (hasExeFS()) { - printf("ExeFS offset: %08llX, size: %08llX\n", exeFS.offset, exeFS.size); - auto exeFSOffset = fileOffset + exeFS.offset; + u64 exeFSOffset = fileOffset + exeFS.offset; // Offset of ExeFS in the file = exeFS offset + ncch offset + printf("ExeFS offset: %08llX, size: %08llX (Offset in file = %08llX)\n", exeFS.offset, exeFS.size, exeFSOffset); constexpr size_t exeFSHeaderSize = 0x200; u8 exeFSHeader[exeFSHeaderSize]; @@ -81,6 +81,16 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) { if (fileSize != 0) { printf("File %d. Name: %s, Size: %08X, Offset: %08X\n", file, name, fileSize, fileOffset); } + + if (std::strcmp(name, ".code") == 0) { + std::vector buff; + + if (compressCode) { + //Helpers::panic("Compressed .code file!"); + } else { + Helpers::panic("Uncompressed .code file!"); + } + } } } @@ -88,16 +98,15 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) { printf("RomFS offset: %08llX, size: %08llX\n", romFS.offset, romFS.size); } - if (stackSize != VirtualAddrs::DefaultStackSize) { + if (stackSize != 0 && stackSize != VirtualAddrs::DefaultStackSize) { Helpers::panic("Stack size != 0x4000"); } - if (compressExeFS) { - Helpers::panic("Compressed ExeFS"); - } - if (encrypted) { - Helpers::panic("Encrypted NCCH partition"); + if (hasExeFS()) + Helpers::panic("Encrypted NCCH partition with ExeFS"); + else + printf("Encrypted NCCH partition. Hopefully not required because it doesn't have an ExeFS. Skipped\n"); } initialized = true;