core: Detect and return error if GBA virtual console is loaded. (#6257)

This commit is contained in:
Steveice10 2023-01-23 01:51:57 -08:00 committed by GitHub
parent d704c6a3ac
commit 84e54a52a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 6 deletions

View file

@ -75,6 +75,7 @@ enum class ResultStatus {
ErrorAlreadyLoaded,
ErrorMemoryAllocationFailed,
ErrorEncrypted,
ErrorGbaTitle,
};
constexpr u32 MakeMagic(char a, char b, char c, char d) {

View file

@ -85,6 +85,11 @@ ResultStatus AppLoader_NCCH::LoadExec(std::shared_ptr<Kernel::Process>& process)
u64_le program_id;
if (ResultStatus::Success == ReadCode(code) &&
ResultStatus::Success == ReadProgramId(program_id)) {
if (IsGbaVirtualConsole(code)) {
LOG_ERROR(Loader, "Encountered unsupported GBA Virtual Console code section.");
return ResultStatus::ErrorGbaTitle;
}
std::string process_name = Common::StringFromFixedZeroTerminatedBuffer(
(const char*)overlay_ncch->exheader_header.codeset_info.name, 8);
@ -177,6 +182,12 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() {
}
}
bool AppLoader_NCCH::IsGbaVirtualConsole(const std::vector<u8>& code) {
const u32* gbaVcHeader = reinterpret_cast<const u32*>(code.data() + code.size() - 0x10);
return code.size() >= 0x10 && gbaVcHeader[0] == MakeMagic('.', 'C', 'A', 'A') &&
gbaVcHeader[1] == 1;
}
ResultStatus AppLoader_NCCH::Load(std::shared_ptr<Kernel::Process>& process) {
u64_le ncch_program_id;

View file

@ -78,6 +78,9 @@ private:
/// Reads the region lockout info in the SMDH and send it to CFG service
void ParseRegionLockoutInfo();
/// Detects whether the NCCH contains GBA Virtual Console.
bool IsGbaVirtualConsole(const std::vector<u8>& code);
FileSys::NCCHContainer base_ncch;
FileSys::NCCHContainer update_ncch;
FileSys::NCCHContainer* overlay_ncch;