warn if cia contend is encrypted

This commit is contained in:
B3n30 2020-03-15 17:54:13 +01:00
parent ad3c464e2d
commit ae4ba287d5
4 changed files with 84 additions and 4 deletions

View file

@ -133,8 +133,37 @@ Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 nc
return Loader::ResultStatus::Success;
}
Loader::ResultStatus NCCHContainer::LoadHeader() {
if (has_header)
return Loader::ResultStatus::Success;
if (!file.IsOpen()) {
return Loader::ResultStatus::Error;
}
// Reset read pointer in case this file has been read before.
file.Seek(ncch_offset, SEEK_SET);
if (file.ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header))
return Loader::ResultStatus::Error;
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
if (Loader::MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) {
LOG_DEBUG(Service_FS, "Only loading the first (bootable) NCCH within the NCSD file!");
ncch_offset += 0x4000;
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
}
// Verify we are loading the correct file type...
if (Loader::MakeMagic('N', 'C', 'C', 'H') != ncch_header.magic)
return Loader::ResultStatus::ErrorInvalidFormat;
has_header = true;
return Loader::ResultStatus::Success;
}
Loader::ResultStatus NCCHContainer::Load() {
LOG_INFO(Service_FS, "Loading NCCH from file {}", filepath);
if (is_loaded)
return Loader::ResultStatus::Success;
@ -697,7 +726,7 @@ Loader::ResultStatus NCCHContainer::ReadOverrideRomFS(std::shared_ptr<RomFSReade
}
Loader::ResultStatus NCCHContainer::ReadProgramId(u64_le& program_id) {
Loader::ResultStatus result = Load();
Loader::ResultStatus result = LoadHeader();
if (result != Loader::ResultStatus::Success)
return result;

View file

@ -210,6 +210,12 @@ public:
Loader::ResultStatus OpenFile(const std::string& filepath, u32 ncch_offset = 0);
/**
* Ensure NCCH header is loaded and ready for reading sections
* @return ResultStatus result of function
*/
Loader::ResultStatus LoadHeader();
/**
* Ensure ExeFS and exheader is loaded and ready for reading sections
* @return ResultStatus result of function