Skip to content

Commit

Permalink
Revert "Allow KernelPatcher::findAndReplaceWithMask to have differe…
Browse files Browse the repository at this point in the history
…nt find/repl size"

This reverts commit 09e2db5.
  • Loading branch information
PMheart committed Jul 10, 2023
1 parent 29e991a commit 1827e19
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Lilu/Sources/kern_patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,15 +649,8 @@ bool KernelPatcher::findPattern(const void *pattern, const void *patternMask, si
}

bool KernelPatcher::findAndReplaceWithMask(void *data, size_t dataSize, const void *find, size_t findSize, const void *findMask, size_t findMaskSize, const void *replace, size_t replaceSize, const void *replaceMask, size_t replaceMaskSize, size_t count, size_t skip) {
if (dataSize < findSize) {
SYSLOG("patcher", "data size must not exceed find size!");
return false;
}
if (findSize < replaceSize) {
SYSLOG("patcher", "find size must be larger or equivalent to repl size!");
return false;
}

if (dataSize < findSize) return false;

uint8_t *d = (uint8_t *) data;
const uint8_t *repl = (const uint8_t *) replace;
const uint8_t *replMsk = (const uint8_t *) replaceMask;
Expand Down Expand Up @@ -689,8 +682,7 @@ bool KernelPatcher::findAndReplaceWithMask(void *data, size_t dataSize, const vo
if (replaceMask == nullptr) {
lilu_os_memcpy(&d[dataOffset], replace, replaceSize);
} else {
// as replace can be shorter than find, we only replace up to the possibly shorter bytes.
for (size_t i = 0; i < replaceSize; i++)
for (size_t i = 0; i < findSize; i++)
d[dataOffset + i] = (d[dataOffset + i] & ~replMsk[i]) | (repl[i] & replMsk[i]);
}

Expand All @@ -699,7 +691,7 @@ bool KernelPatcher::findAndReplaceWithMask(void *data, size_t dataSize, const vo
}

replCount++;
dataOffset += findSize;
dataOffset += replaceSize;

// check replace count if requested
if (count > 0) {
Expand Down

0 comments on commit 1827e19

Please sign in to comment.