file_sys: Handle patch applying failures
This changes ApplyCodePatch to return a ResultStatus, which makes it possible to determine whether patch applying has failed. Previously, only a boolean was returned, and false was returned when no patch was found OR when a patch was found but applying it failed. This also changes AppLoader_NCCH to return an error if patching fails because the executable is likely to be left in an inconsistent state and we should not proceed booting in that case.
This commit is contained in:
@@ -507,20 +507,22 @@ Loader::ResultStatus NCCHContainer::LoadSectionExeFS(const char* name, std::vect
|
||||
return Loader::ResultStatus::ErrorNotUsed;
|
||||
}
|
||||
|
||||
bool NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const {
|
||||
Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const {
|
||||
const std::string override_ips = filepath + ".exefsdir/code.ips";
|
||||
|
||||
FileUtil::IOFile ips_file{override_ips, "rb"};
|
||||
if (!ips_file)
|
||||
return false;
|
||||
return Loader::ResultStatus::ErrorNotUsed;
|
||||
|
||||
std::vector<u8> ips(ips_file.GetSize());
|
||||
if (ips_file.ReadBytes(ips.data(), ips.size()) != ips.size())
|
||||
return false;
|
||||
return Loader::ResultStatus::Error;
|
||||
|
||||
LOG_INFO(Service_FS, "File {} patching code.bin", override_ips);
|
||||
Patch::ApplyIpsPatch(ips, code);
|
||||
return true;
|
||||
if (!Patch::ApplyIpsPatch(ips, code))
|
||||
return Loader::ResultStatus::Error;
|
||||
|
||||
return Loader::ResultStatus::Success;
|
||||
}
|
||||
|
||||
Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
|
||||
|
Reference in New Issue
Block a user