Skip to content

Commit

Permalink
Preferring the original byte in the pattern over the given one
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed May 24, 2020
1 parent b7cb658 commit 1bf6423
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ public bool PatchBytes(ref byte[] raw, bool x64, BytePatchPattern.WriteToLog log
patches++;
continue;
}
long addr = patch.pattern.FindAddress(raw, x64, log);
Tuple<long, byte[]> addrPattern = patch.pattern.FindAddress(raw, x64, log);
long addr = addrPattern.Item1;
byte[] searchPattern = addrPattern.Item2;

int patchOffset = x64 ? patch.offsetX64 : patch.offsetX86;
byte patchOrigByte = x64 ? patch.origByteX64 : patch.origByteX86;
byte patchPatchByte = x64 ? patch.patchByteX64 : patch.patchByteX86;

if (patchOffset < searchPattern.Length && searchPattern[patchOffset] != 0xFF)
patchOrigByte = searchPattern[patchOffset]; // The patterns can sometimes start at different places (yes, I'm looking at you, Edge), so the byte in the pattern should be always preferred

if(addr != -1) {
REDO_CHECKS:
long index = addr + patchOffset;
Expand Down
6 changes: 3 additions & 3 deletions ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public BytePatchPattern(string name) {
}

public delegate void WriteToLog(string str);
public long FindAddress(byte[] raw, bool x64, WriteToLog log) {
public Tuple<long, byte[]> FindAddress(byte[] raw, bool x64, WriteToLog log) { // This returns the offset and pattern
foreach (byte[] pattern in (x64 ? AlternativePatternsX64 : AlternativePatternsX86)) {
int patternIndex = 0, patternOffset = 0;

Expand All @@ -30,12 +30,12 @@ public long FindAddress(byte[] raw, bool x64, WriteToLog log) {
if (patternIndex == pattern.Length) {
patternOffset = i - (patternIndex - 1);
log("Found pattern offset at " + patternOffset);
return patternOffset;
return new Tuple<long, byte[]>(patternOffset, pattern);
}
}
}

return -1L;
return new Tuple<long, byte[]>(-1L, null);
}
}
}

0 comments on commit 1bf6423

Please sign in to comment.