Add support for XCI titlekey decryption

This commit is contained in:
sspacelynx 2021-02-28 18:13:54 +01:00 committed by ◱ Mark
parent 666df1eb43
commit 77d8d1bee1
3 changed files with 5 additions and 4 deletions

View File

@ -36,7 +36,7 @@ namespace skyline::loader {
continue;
try {
auto nca{vfs::NCA(secure->OpenFile(entry.name), keyStore)};
auto nca{vfs::NCA(secure->OpenFile(entry.name), keyStore, true)};
if (nca.contentType == vfs::NcaContentType::Program && nca.romFs != nullptr && nca.exeFs != nullptr)
programNca = std::move(nca);

View File

@ -14,7 +14,7 @@
namespace skyline::vfs {
using namespace loader;
NCA::NCA(std::shared_ptr<vfs::Backing> pBacking, std::shared_ptr<crypto::KeyStore> pKeyStore) : backing(std::move(pBacking)), keyStore(std::move(pKeyStore)) {
NCA::NCA(std::shared_ptr<vfs::Backing> pBacking, std::shared_ptr<crypto::KeyStore> pKeyStore, bool pUseKeyArea) : backing(std::move(pBacking)), keyStore(std::move(pKeyStore)), useKeyArea(pUseKeyArea) {
header = backing->Read<NcaHeader>();
if (header.magic != util::MakeMagic<u32>("NCA3")) {
@ -78,7 +78,7 @@ namespace skyline::vfs {
return rawBacking;
case NcaSectionEncryptionType::CTR:
case NcaSectionEncryptionType::BKTR: {
auto key{!rightsIdEmpty ? GetTitleKey() : GetKeyAreaKey(sectionHeader.encryptionType)};
auto key{!(rightsIdEmpty || useKeyArea) ? GetTitleKey() : GetKeyAreaKey(sectionHeader.encryptionType)};
std::array<u8, 0x10> ctr{};
u32 secureValueLE{__builtin_bswap32(sectionHeader.secureValue)};

View File

@ -173,6 +173,7 @@ namespace skyline {
std::shared_ptr<crypto::KeyStore> keyStore;
bool encrypted{false};
bool rightsIdEmpty;
bool useKeyArea;
void ReadPfs0(const NcaSectionHeader &sectionHeader, const NcaFsEntry &entry);
@ -193,7 +194,7 @@ namespace skyline {
std::shared_ptr<Backing> romFs; //!< The backing for this NCA's RomFS section
NcaContentType contentType; //!< The content type of the NCA
NCA(std::shared_ptr<vfs::Backing> backing, std::shared_ptr<crypto::KeyStore> keyStore);
NCA(std::shared_ptr<vfs::Backing> backing, std::shared_ptr<crypto::KeyStore> keyStore, bool useKeyArea = false);
};
}
}