Remove ApplyIPS from the class and header
This commit is contained in:
parent
92f8b71137
commit
896577044d
2 changed files with 47 additions and 48 deletions
|
@ -24,6 +24,53 @@ namespace FileSys {
|
||||||
static const int kMaxSections = 8; ///< Maximum number of sections (files) in an ExeFs
|
static const int kMaxSections = 8; ///< Maximum number of sections (files) in an ExeFs
|
||||||
static const int kBlockSize = 0x200; ///< Size of ExeFS blocks (in bytes)
|
static const int kBlockSize = 0x200; ///< Size of ExeFS blocks (in bytes)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to patch a buffer using an IPS
|
||||||
|
* @param ips Vector of the patches to apply
|
||||||
|
* @param buffer Vector to patch data into
|
||||||
|
*/
|
||||||
|
static void ApplyIPS(std::vector<u8>& ips, std::vector<u8>& buffer) {
|
||||||
|
u32 cursor = 5;
|
||||||
|
u32 patch_length = ips.size() - 3;
|
||||||
|
std::string ips_header(ips.begin(), ips.begin() + 5);
|
||||||
|
|
||||||
|
if (ips_header != "PATCH") {
|
||||||
|
LOG_INFO(Service_FS, "Attempted to load invalid IPS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (cursor < patch_length) {
|
||||||
|
std::string eof_check(ips.begin() + cursor, ips.begin() + cursor + 3);
|
||||||
|
|
||||||
|
if (eof_check == "EOF")
|
||||||
|
return;
|
||||||
|
|
||||||
|
u32 offset = ips[cursor] << 16 | ips[cursor + 1] << 8 | ips[cursor + 2];
|
||||||
|
std::size_t length = ips[cursor + 3] << 8 | ips[cursor + 4];
|
||||||
|
|
||||||
|
// check for an rle record
|
||||||
|
if (length == 0) {
|
||||||
|
length = ips[cursor + 5] << 8 | ips[cursor + 6];
|
||||||
|
|
||||||
|
if (buffer.size() < offset + length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < length; ++i)
|
||||||
|
buffer[offset + i] = ips[cursor + 7];
|
||||||
|
|
||||||
|
cursor += 8;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.size() < offset + length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::memcpy(&buffer[offset], &ips[cursor + 5], length);
|
||||||
|
cursor += length + 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the decompressed size of an LZSS compressed ExeFS file
|
* Get the decompressed size of an LZSS compressed ExeFS file
|
||||||
* @param buffer Buffer of compressed file
|
* @param buffer Buffer of compressed file
|
||||||
|
@ -534,48 +581,6 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
|
||||||
return Loader::ResultStatus::ErrorNotUsed;
|
return Loader::ResultStatus::ErrorNotUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NCCHContainer::ApplyIPS(std::vector<u8>& ips, std::vector<u8>& buffer) {
|
|
||||||
u32 cursor = 5;
|
|
||||||
u32 patch_length = ips.size() - 3;
|
|
||||||
std::string ips_header(ips.begin(), ips.begin() + 5);
|
|
||||||
|
|
||||||
if (ips_header != "PATCH") {
|
|
||||||
LOG_INFO(Service_FS, "Attempted to load invalid IPS");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (cursor < patch_length) {
|
|
||||||
std::string eof_check(ips.begin() + cursor, ips.begin() + cursor + 3);
|
|
||||||
|
|
||||||
if (eof_check == "EOF")
|
|
||||||
return;
|
|
||||||
|
|
||||||
u32 offset = ips[cursor] << 16 | ips[cursor + 1] << 8 | ips[cursor + 2];
|
|
||||||
std::size_t length = ips[cursor + 3] << 8 | ips[cursor + 4];
|
|
||||||
|
|
||||||
// check for an rle record
|
|
||||||
if (length == 0) {
|
|
||||||
length = ips[cursor + 5] << 8 | ips[cursor + 6];
|
|
||||||
|
|
||||||
if (buffer.size() < offset + length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (u32 i = 0; i < length; ++i)
|
|
||||||
buffer[offset + i] = ips[cursor + 7];
|
|
||||||
|
|
||||||
cursor += 8;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer.size() < offset + length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::memcpy(&buffer[offset], &ips[cursor + 5], length);
|
|
||||||
cursor += length + 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romfs_file) {
|
Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romfs_file) {
|
||||||
Loader::ResultStatus result = Load();
|
Loader::ResultStatus result = Load();
|
||||||
if (result != Loader::ResultStatus::Success)
|
if (result != Loader::ResultStatus::Success)
|
||||||
|
|
|
@ -294,12 +294,6 @@ public:
|
||||||
ExHeader_Header exheader_header;
|
ExHeader_Header exheader_header;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Attempts to patch a buffer using an IPS
|
|
||||||
* @param ips Vector of the patches to apply
|
|
||||||
* @param buffer Vector to patch data into
|
|
||||||
*/
|
|
||||||
static void ApplyIPS(std::vector<u8>& ips, std::vector<u8>& buffer);
|
|
||||||
bool has_header = false;
|
bool has_header = false;
|
||||||
bool has_exheader = false;
|
bool has_exheader = false;
|
||||||
bool has_exefs = false;
|
bool has_exefs = false;
|
||||||
|
|
Loading…
Reference in a new issue