-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Edge finder, removed command line args, added byte patches, add…
…ed alternative debug pattern, etc.
- Loading branch information
Showing
11 changed files
with
228 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using ChromeDevExtWarningPatcher.Patches; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ChromeDevExtWarningPatcher { | ||
class DllPatcher { | ||
private string DllPath; | ||
|
||
public DllPatcher(string dllPath) { | ||
DllPath = dllPath; | ||
} | ||
|
||
public void Patch(BytePatchPattern.WriteToLog log) { | ||
FileInfo dllFile = new FileInfo(DllPath); | ||
if (!dllFile.Exists) | ||
throw new IOException("File not found"); | ||
|
||
byte[] raw = File.ReadAllBytes(dllFile.FullName); | ||
|
||
if(Program.bytePatchManager.PatchBytes(ref raw, IsImageX64(dllFile.FullName), log)) { | ||
File.WriteAllBytes(dllFile.FullName, raw); | ||
log("Patched and saved successfully " + dllFile.FullName); | ||
} else { | ||
log("Error trying to patch " + dllFile.FullName); | ||
} | ||
} | ||
|
||
// Taken from https://stackoverflow.com/questions/480696/how-to-find-if-a-native-dll-file-is-compiled-as-x64-or-x86 | ||
private static bool IsImageX64(string dllFilePath) { | ||
using (var stream = new FileStream(dllFilePath, FileMode.Open, FileAccess.Read)) | ||
using (var reader = new BinaryReader(stream)) { | ||
//check the MZ signature to ensure it's a valid Portable Executable image | ||
if (reader.ReadUInt16() != 23117) | ||
throw new BadImageFormatException("Not a valid Portable Executable image", dllFilePath); | ||
|
||
// seek to, and read, e_lfanew then advance the stream to there (start of NT header) | ||
stream.Seek(0x3A, SeekOrigin.Current); | ||
stream.Seek(reader.ReadUInt32(), SeekOrigin.Begin); | ||
|
||
// Ensure the NT header is valid by checking the "PE\0\0" signature | ||
if (reader.ReadUInt32() != 17744) | ||
throw new BadImageFormatException("Not a valid Portable Executable image", dllFilePath); | ||
|
||
// seek past the file header, then read the magic number from the optional header | ||
stream.Seek(20, SeekOrigin.Current); | ||
ushort magicByte = reader.ReadUInt16(); | ||
return magicByte == 0x20B; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
ChromeDevExtWarningPatcher/BytePatch.cs → ...DevExtWarningPatcher/Patches/BytePatch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using ChromeDevExtWarningPatcher.Patches.Defaults; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ChromeDevExtWarningPatcher.Patches { | ||
class BytePatchManager { | ||
private List<BytePatch> BytePatches = new List<BytePatch>(); | ||
|
||
public List<Type> disabledTypes = new List<Type>(); | ||
|
||
public BytePatchManager() { | ||
BytePatches.Clear(); | ||
BytePatches.Add(new RemoveExtensionWarningPatch1()); | ||
BytePatches.Add(new RemoveExtensionWarningPatch2()); | ||
BytePatches.Add(new RemoveDebugWarningPatch()); | ||
BytePatches.Add(new RemoveElisionPatch()); | ||
} | ||
|
||
public bool PatchBytes(ref byte[] raw, bool x64, BytePatchPattern.WriteToLog log) { | ||
int patches = 0; | ||
|
||
foreach(BytePatch patch in BytePatches) { | ||
if (disabledTypes.Contains(patch.GetType())) { | ||
patches++; | ||
continue; | ||
} | ||
long addr = patch.pattern.FindAddress(raw, x64, log); | ||
|
||
if(addr != -1) { | ||
long index = addr + patch.offset; | ||
byte sourceByte = raw[index]; | ||
|
||
log("Source byte of patch at " + patch.offset + ": " + sourceByte); | ||
if (sourceByte == patch.origByte) { | ||
raw[index] = patch.patchByte; | ||
log(index + " => " + patch.patchByte); | ||
patches++; | ||
} else | ||
log("Source byte unexpected, should be " + patch.origByte + "!"); | ||
} else { | ||
log("Couldn't find offset for a patch " + patch.pattern.Name); | ||
} | ||
} | ||
|
||
return patches == BytePatches.Count; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ChromeDevExtWarningPatcher.Patches { | ||
public abstract class BytePatchPattern { | ||
public string Name; | ||
protected List<byte[]> AlternativePatternsX86 = new List<byte[]>(); | ||
protected List<byte[]> AlternativePatternsX64 = new List<byte[]>(); | ||
|
||
public BytePatchPattern(string name) { | ||
Name = name; | ||
} | ||
|
||
public delegate void WriteToLog(string str); | ||
public long FindAddress(byte[] raw, bool x64, WriteToLog log) { | ||
foreach (byte[] pattern in (x64 ? AlternativePatternsX64 : AlternativePatternsX86)) { | ||
int patternIndex = 0, patternOffset = 0; | ||
|
||
for (int i = 0; i < raw.Length; i++) { | ||
byte chromeByte = raw[i]; | ||
byte expectedByte = pattern[patternIndex]; | ||
|
||
if (expectedByte == 0xFF ? true : (chromeByte == expectedByte)) | ||
patternIndex++; | ||
else | ||
patternIndex = 0; | ||
|
||
if (patternIndex == pattern.Length) { | ||
patternOffset = i - (patternIndex - 1); | ||
log("Found pattern offset at " + patternOffset); | ||
return patternOffset; | ||
} | ||
} | ||
} | ||
|
||
return -1L; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace ChromeDevExtWarningPatcher.Patches.Defaults { | ||
public class RemoveExtensionWarningPatch1 : BytePatch { | ||
public RemoveExtensionWarningPatch1() : base(new RemoveExtensionWarningPattern(), 0x04, 0xFF, 22) { } | ||
} | ||
|
||
public class RemoveExtensionWarningPatch2 : BytePatch { | ||
public RemoveExtensionWarningPatch2() : base(new RemoveExtensionWarningPattern(), 0x08, 0xFF, 35) { } | ||
} | ||
|
||
public class RemoveDebugWarningPatch : BytePatch { | ||
public RemoveDebugWarningPatch() : base(new RemoveDebugWarningPattern(), 0x41, 0xC3, 0x00) { } | ||
} | ||
|
||
public class RemoveElisionPatch : BytePatch { | ||
public RemoveElisionPatch() : base(new RemoveElisionPattern(), 0x56, 0xC3, 0x00) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace ChromeDevExtWarningPatcher.Patches.Defaults { | ||
public class RemoveExtensionWarningPattern : BytePatchPattern { | ||
public RemoveExtensionWarningPattern() : base("Remove Extension Warning") { | ||
AlternativePatternsX64.Add(new byte[] { 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x89, 0xD6, 0x48, 0x89, 0xD1, 0xE8, 0xFF, 0xFF, 0xFF, 0xFF, 0x89, 0xC1 }); | ||
} | ||
} | ||
|
||
public class RemoveDebugWarningPattern : BytePatchPattern { | ||
public RemoveDebugWarningPattern() : base("Remove Debug Warning") { | ||
AlternativePatternsX64.Add(new byte[] { 0x41, 0x57, 0x41, 0x56, 0x41, 0x54, 0x56, 0x57, 0x53, 0x48, 0x81, 0xEC, 0xFF, 0xFF, 0xFF, 0xFF, 0x49, 0x89, 0xCC, 0x48, 0x8B, 0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x31, 0xE0, 0x48, 0x89, 0x84, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x8D, 0x4A, 0xFF }); | ||
AlternativePatternsX64.Add(new byte[] { 0x41, 0x57, 0x41, 0x56, 0x56, 0x57, 0x53, 0x48, 0x81, 0xEC, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x89, 0xCE, 0x48, 0x8B, 0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x31, 0xE0, 0x48, 0x89, 0x84, 0x24, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x8D, 0x4A, 0x08 }); | ||
} | ||
} | ||
|
||
public class RemoveElisionPattern : BytePatchPattern { | ||
public RemoveElisionPattern() : base("Remove Elision") { | ||
AlternativePatternsX64.Add(new byte[] { 0x56, 0x57, 0x53, 0x48, 0x83, 0xEC, 0x40, 0x48, 0x8B, 0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x31, 0xE0, 0x48, 0x89, 0x44, 0x24, 0xFF, 0xE8, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0x85, 0xC0, 0x74, 0x61 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters