From ca0b5755c0ed582b044d24fe0998eaa21cf77907 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sun, 13 Aug 2023 18:20:46 +0300 Subject: [PATCH] Format --- include/loader/ncch.hpp | 123 ++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/include/loader/ncch.hpp b/include/loader/ncch.hpp index 68eb4da5..7f0ff37f 100644 --- a/include/loader/ncch.hpp +++ b/include/loader/ncch.hpp @@ -2,83 +2,84 @@ #include #include #include -#include "io_file.hpp" -#include "helpers.hpp" + #include "crypto/aes_engine.hpp" +#include "helpers.hpp" +#include "io_file.hpp" #include "services/region_codes.hpp" struct NCCH { - struct EncryptionInfo { - Crypto::AESKey normalKey; - Crypto::AESKey initialCounter; - }; + struct EncryptionInfo { + Crypto::AESKey normalKey; + Crypto::AESKey initialCounter; + }; - struct FSInfo { // Info on the ExeFS/RomFS - u64 offset = 0; - u64 size = 0; - u64 hashRegionSize = 0; - std::optional encryptionInfo; - }; + struct FSInfo { // Info on the ExeFS/RomFS + u64 offset = 0; + u64 size = 0; + u64 hashRegionSize = 0; + std::optional encryptionInfo; + }; - // Descriptions for .text, .data and .rodata sections - struct CodeSetInfo { - u32 address = 0; - u32 pageCount = 0; - u32 size = 0; + // Descriptions for .text, .data and .rodata sections + struct CodeSetInfo { + u32 address = 0; + u32 pageCount = 0; + u32 size = 0; - // Extract the code set info from the relevant header data - void extract(const u8* headerEntry) { - address = *(u32*)&headerEntry[0]; - pageCount = *(u32*)&headerEntry[4]; - size = *(u32*)&headerEntry[8]; - } - }; + // Extract the code set info from the relevant header data + void extract(const u8 *headerEntry) { + address = *(u32 *)&headerEntry[0]; + pageCount = *(u32 *)&headerEntry[4]; + size = *(u32 *)&headerEntry[8]; + } + }; - u64 partitionIndex = 0; - u64 fileOffset = 0; + u64 partitionIndex = 0; + u64 fileOffset = 0; - bool isNew3DS = false; - bool initialized = false; - bool compressCode = false; // Shows whether the .code file in the ExeFS is compressed - bool mountRomFS = false; - bool encrypted = false; - bool fixedCryptoKey = false; - bool seedCrypto = false; - u8 secondaryKeySlot = 0; + bool isNew3DS = false; + bool initialized = false; + bool compressCode = false; // Shows whether the .code file in the ExeFS is compressed + bool mountRomFS = false; + bool encrypted = false; + bool fixedCryptoKey = false; + bool seedCrypto = false; + u8 secondaryKeySlot = 0; - static constexpr u64 mediaUnit = 0x200; - u64 size = 0; // Size of NCCH converted to bytes - u32 stackSize = 0; - u32 bssSize = 0; - u32 exheaderSize = 0; + static constexpr u64 mediaUnit = 0x200; + u64 size = 0; // Size of NCCH converted to bytes + u32 stackSize = 0; + u32 bssSize = 0; + u32 exheaderSize = 0; - FSInfo exheaderInfo; - FSInfo exeFS; - FSInfo romFS; - CodeSetInfo text, data, rodata; + FSInfo exheaderInfo; + FSInfo exeFS; + FSInfo romFS; + CodeSetInfo text, data, rodata; - // Contents of the .code file in the ExeFS - std::vector codeFile; - // Contains of the cart's save data - std::vector saveData; - // The cart region. Only the CXI's region matters to us. Necessary to get past region locking + // Contents of the .code file in the ExeFS + std::vector codeFile; + // Contains of the cart's save data + std::vector saveData; + // The cart region. Only the CXI's region matters to us. Necessary to get past region locking std::optional region = std::nullopt; - // Returns true on success, false on failure - // Partition index/offset/size must have been set before this - bool loadFromHeader(Crypto::AESEngine &aesEngine, IOFile& file, const FSInfo &info); + // Returns true on success, false on failure + // Partition index/offset/size must have been set before this + bool loadFromHeader(Crypto::AESEngine &aesEngine, IOFile &file, const FSInfo &info); - bool hasExtendedHeader() { return exheaderSize != 0; } - bool hasExeFS() { return exeFS.size != 0; } - bool hasRomFS() { return romFS.size != 0; } - bool hasCode() { return codeFile.size() != 0; } - bool hasSaveData() { return saveData.size() != 0; } + bool hasExtendedHeader() { return exheaderSize != 0; } + bool hasExeFS() { return exeFS.size != 0; } + bool hasRomFS() { return romFS.size != 0; } + bool hasCode() { return codeFile.size() != 0; } + bool hasSaveData() { return saveData.size() != 0; } - // Parse SMDH for region info and such. Returns false on failure, true on success - bool parseSMDH(const std::vector& smdh); + // Parse SMDH for region info and such. Returns false on failure, true on success + bool parseSMDH(const std::vector &smdh); - std::pair getPrimaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY); - std::pair getSecondaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY); + std::pair getPrimaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY); + std::pair getSecondaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY); - std::pair readFromFile(IOFile& file, const FSInfo &info, u8 *dst, std::size_t offset, std::size_t size); + std::pair readFromFile(IOFile &file, const FSInfo &info, u8 *dst, std::size_t offset, std::size_t size); }; \ No newline at end of file