Skip to content

Commit 1bf6423

Browse files
committed
Preferring the original byte in the pattern over the given one
1 parent b7cb658 commit 1bf6423

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,17 @@ public bool PatchBytes(ref byte[] raw, bool x64, BytePatchPattern.WriteToLog log
126126
patches++;
127127
continue;
128128
}
129-
long addr = patch.pattern.FindAddress(raw, x64, log);
129+
Tuple<long, byte[]> addrPattern = patch.pattern.FindAddress(raw, x64, log);
130+
long addr = addrPattern.Item1;
131+
byte[] searchPattern = addrPattern.Item2;
132+
130133
int patchOffset = x64 ? patch.offsetX64 : patch.offsetX86;
131134
byte patchOrigByte = x64 ? patch.origByteX64 : patch.origByteX86;
132135
byte patchPatchByte = x64 ? patch.patchByteX64 : patch.patchByteX86;
133136

137+
if (patchOffset < searchPattern.Length && searchPattern[patchOffset] != 0xFF)
138+
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
139+
134140
if(addr != -1) {
135141
REDO_CHECKS:
136142
long index = addr + patchOffset;

ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public BytePatchPattern(string name) {
1414
}
1515

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

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

38-
return -1L;
38+
return new Tuple<long, byte[]>(-1L, null);
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)