From e6084363152edff610951ec81fda0add720a47e1 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:27:05 +0300 Subject: [PATCH] Sanity check: Assert .code is encrypted before setting normal key --- src/core/loader/ncch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index a8e50101..47d5a4c2 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -207,8 +207,8 @@ bool NCCH::loadFromHeader(Crypto::AESEngine &aesEngine, IOFile& file, const FSIn // All files in ExeFS use the same IV, though .code uses the secondary key for decryption // whereas .icon/.banner use the primary key. FSInfo info = exeFS; - if (secondaryKey.has_value() && info.encryptionInfo.has_value()) { - info.encryptionInfo->normalKey = secondaryKey.value(); + if (encrypted && secondaryKey.has_value() && info.encryptionInfo.has_value()) { + info.encryptionInfo->normalKey = *secondaryKey; } if (compressCode) {