From 7c3de1fa12ee27309499c21af55239990dad3878 Mon Sep 17 00:00:00 2001 From: Ceiridge Date: Fri, 29 May 2020 15:11:48 +0200 Subject: [PATCH] Converted spaces to tabs --- .../CommandLineOptions.cs | 16 +- ChromeDevExtWarningPatcher/CustomCheckBox.cs | 38 +-- ChromeDevExtWarningPatcher/DllPatcher.cs | 110 +++---- .../InstallationFinder/Defaults/Brave.cs | 18 +- .../InstallationFinder/Defaults/Chrome.cs | 18 +- .../InstallationFinder/Defaults/CustomPath.cs | 24 +- .../InstallationFinder/Defaults/Edge.cs | 18 +- .../InstallationFinder/Installation.cs | 74 ++--- .../InstallationFinder/InstallationManager.cs | 32 +- ChromeDevExtWarningPatcher/PatcherGui.xaml.cs | 182 +++++----- .../Patches/BytePatch.cs | 40 +-- .../Patches/BytePatchManager.cs | 310 +++++++++--------- .../Patches/BytePatchPattern.cs | 56 ++-- ChromeDevExtWarningPatcher/Program.cs | 164 ++++----- 14 files changed, 550 insertions(+), 550 deletions(-) diff --git a/ChromeDevExtWarningPatcher/CommandLineOptions.cs b/ChromeDevExtWarningPatcher/CommandLineOptions.cs index eceaa08..262a7b5 100644 --- a/ChromeDevExtWarningPatcher/CommandLineOptions.cs +++ b/ChromeDevExtWarningPatcher/CommandLineOptions.cs @@ -2,14 +2,14 @@ using System.Collections.Generic; namespace ChromeDevExtWarningPatcher { - public class CommandLineOptions { - [Option("groups", Required = false, HelpText = "Set what patch groups you want to use. See patterns.xml to get the group ids (comma-seperated: 0,1,2)", Separator = ',')] - public IEnumerable Groups { get; set; } + public class CommandLineOptions { + [Option("groups", Required = false, HelpText = "Set what patch groups you want to use. See patterns.xml to get the group ids (comma-seperated: 0,1,2)", Separator = ',')] + public IEnumerable Groups { get; set; } - [Option('w', "noWait", Required = false, HelpText = "Disable the almost-pointless wait after finishing")] - public bool NoWait { get; set; } + [Option('w', "noWait", Required = false, HelpText = "Disable the almost-pointless wait after finishing")] + public bool NoWait { get; set; } - [Option("customPath", Required = false, HelpText = "Instead of automatically detecting and patching all chrome.dll files, define a custom Application-folder path (see README) (string in quotes is recommended)")] - public string CustomPath { get; set; } - } + [Option("customPath", Required = false, HelpText = "Instead of automatically detecting and patching all chrome.dll files, define a custom Application-folder path (see README) (string in quotes is recommended)")] + public string CustomPath { get; set; } + } } diff --git a/ChromeDevExtWarningPatcher/CustomCheckBox.cs b/ChromeDevExtWarningPatcher/CustomCheckBox.cs index 186b47b..6de7d34 100644 --- a/ChromeDevExtWarningPatcher/CustomCheckBox.cs +++ b/ChromeDevExtWarningPatcher/CustomCheckBox.cs @@ -2,28 +2,28 @@ using System.Windows.Media; namespace ChromeDevExtWarningPatcher { - class CustomCheckBox : CheckBox { - public int Group; + class CustomCheckBox : CheckBox { + public int Group; - public CustomCheckBox(string text, string tooltip, int group) : base() { - Content = text; - Foreground = BorderBrush = new SolidColorBrush(Color.FromRgb(202, 62, 71)); - Group = group; + public CustomCheckBox(string text, string tooltip, int group) : base() { + Content = text; + Foreground = BorderBrush = new SolidColorBrush(Color.FromRgb(202, 62, 71)); + Group = group; - if (tooltip != null) - ToolTip = tooltip; - } + if (tooltip != null) + ToolTip = tooltip; + } - public CustomCheckBox(GuiPatchGroupData patchGroupData) : this(patchGroupData.Name, patchGroupData.Tooltip, patchGroupData.Group) { - IsChecked = patchGroupData.Default; - } + public CustomCheckBox(GuiPatchGroupData patchGroupData) : this(patchGroupData.Name, patchGroupData.Tooltip, patchGroupData.Group) { + IsChecked = patchGroupData.Default; + } - public CustomCheckBox(string text) : this(text, null, -1) { } - } + public CustomCheckBox(string text) : this(text, null, -1) { } + } - struct GuiPatchGroupData { - public string Name, Tooltip; - public int Group; - public bool Default; - } + struct GuiPatchGroupData { + public string Name, Tooltip; + public int Group; + public bool Default; + } } diff --git a/ChromeDevExtWarningPatcher/DllPatcher.cs b/ChromeDevExtWarningPatcher/DllPatcher.cs index 22da1af..1ab89a2 100644 --- a/ChromeDevExtWarningPatcher/DllPatcher.cs +++ b/ChromeDevExtWarningPatcher/DllPatcher.cs @@ -3,59 +3,59 @@ using System.IO; namespace ChromeDevExtWarningPatcher { - class DllPatcher { - private string DllPath; - - public DllPatcher(string dllPath) { - DllPath = dllPath; - } - - public bool Patch(BytePatchPattern.WriteToLog log) { - FileInfo dllFile = new FileInfo(DllPath); - if (!dllFile.Exists) - throw new IOException("File not found"); - - byte[] raw = File.ReadAllBytes(dllFile.FullName); - log("Patching " + dllFile.FullName + "..."); - - FileInfo dllFileBackup = new FileInfo(dllFile.FullName + ".bck"); - if (!dllFileBackup.Exists) { - File.WriteAllBytes(dllFileBackup.FullName, raw); - log("Backupped to " + dllFileBackup.FullName); - } - - if (Program.bytePatchManager.PatchBytes(ref raw, IsImageX64(dllFile.FullName), log)) { - File.WriteAllBytes(dllFile.FullName, raw); - log("Patched and saved successfully " + dllFile.FullName); - return true; - } else { - log("Error trying to patch " + dllFile.FullName); - } - - return false; - } - - // 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; - } - } - } + class DllPatcher { + private string DllPath; + + public DllPatcher(string dllPath) { + DllPath = dllPath; + } + + public bool Patch(BytePatchPattern.WriteToLog log) { + FileInfo dllFile = new FileInfo(DllPath); + if (!dllFile.Exists) + throw new IOException("File not found"); + + byte[] raw = File.ReadAllBytes(dllFile.FullName); + log("Patching " + dllFile.FullName + "..."); + + FileInfo dllFileBackup = new FileInfo(dllFile.FullName + ".bck"); + if (!dllFileBackup.Exists) { + File.WriteAllBytes(dllFileBackup.FullName, raw); + log("Backupped to " + dllFileBackup.FullName); + } + + if (Program.bytePatchManager.PatchBytes(ref raw, IsImageX64(dllFile.FullName), log)) { + File.WriteAllBytes(dllFile.FullName, raw); + log("Patched and saved successfully " + dllFile.FullName); + return true; + } else { + log("Error trying to patch " + dllFile.FullName); + } + + return false; + } + + // 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; + } + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs index 3e7715b..2ee92c3 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs @@ -2,16 +2,16 @@ using System.IO; namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { - class Brave : Installation { - public Brave() : base("Brave") { } + class Brave : Installation { + public Brave() : base("Brave") { } - public override List FindDllFiles() { - List dllFiles = new List(); + public override List FindDllFiles() { + List dllFiles = new List(); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application"), "chrome.dll")); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\BraveSoftware\Brave-Browser\Application"), "chrome.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application"), "chrome.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\BraveSoftware\Brave-Browser\Application"), "chrome.dll")); - return dllFiles; - } - } + return dllFiles; + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs index b75a1f5..e266f94 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs @@ -2,16 +2,16 @@ using System.IO; namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { - class Chrome : Installation { - public Chrome() : base("Chrome") { } + class Chrome : Installation { + public Chrome() : base("Chrome") { } - public override List FindDllFiles() { - List dllFiles = new List(); + public override List FindDllFiles() { + List dllFiles = new List(); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\Google\Chrome\Application"), "chrome.dll")); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\Google\Chrome\Application"), "chrome.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\Google\Chrome\Application"), "chrome.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\Google\Chrome\Application"), "chrome.dll")); - return dllFiles; - } - } + return dllFiles; + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/CustomPath.cs b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/CustomPath.cs index af83def..38ccbd4 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/CustomPath.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/CustomPath.cs @@ -2,20 +2,20 @@ using System.IO; namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { - class CustomPath : Installation { - private string Path; + class CustomPath : Installation { + private string Path; - public CustomPath(string path) : base("CustomPath") { - Path = path; - } + public CustomPath(string path) : base("CustomPath") { + Path = path; + } - public override List FindDllFiles() { - List dllFiles = new List(); + public override List FindDllFiles() { + List dllFiles = new List(); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(Path), "chrome.dll")); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(Path), "msedge.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(Path), "chrome.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(Path), "msedge.dll")); - return dllFiles; - } - } + return dllFiles; + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs index 9c23e1b..442a933 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs @@ -2,16 +2,16 @@ using System.IO; namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { - class Edge : Installation { - public Edge() : base("Edge") { } + class Edge : Installation { + public Edge() : base("Edge") { } - public override List FindDllFiles() { - List dllFiles = new List(); + public override List FindDllFiles() { + List dllFiles = new List(); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application"), "msedge.dll")); - AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\Microsoft\Edge\Application"), "msedge.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application"), "msedge.dll")); + AddDllToList(dllFiles, GetLatestDll(new DirectoryInfo(@"C:\Program Files\Microsoft\Edge\Application"), "msedge.dll")); - return dllFiles; - } - } + return dllFiles; + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs b/ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs index efdecb4..6f38232 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs @@ -4,41 +4,41 @@ using System.Linq; namespace ChromeDevExtWarningPatcher.InstallationFinder { - abstract class Installation { - protected string Name; - - public Installation(string Name) { - this.Name = Name; - } - - public abstract List FindDllFiles(); - - protected static FileInfo GetLatestDll(DirectoryInfo versionsFolder, string dllName) { - if (!versionsFolder.Exists) - return null; - - List chromeVersions = new List(versionsFolder.EnumerateDirectories()); - chromeVersions = chromeVersions.OrderByDescending(dirInfo => GetUnixTime(dirInfo.LastWriteTime)).ToList(); - - foreach (DirectoryInfo chromeVersion in chromeVersions) { - if (chromeVersion.Name.Contains(".")) { - foreach (FileInfo file in chromeVersion.EnumerateFiles()) { - if (file.Name.Equals(dllName)) - return file; - } - } - } - return null; - } - - protected static void AddDllToList(List dllList, FileInfo latestDll) { - if (latestDll == null) - return; - dllList.Add(latestDll.FullName); - } - - private static double GetUnixTime(DateTime date) { - return (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; - } - } + abstract class Installation { + protected string Name; + + public Installation(string Name) { + this.Name = Name; + } + + public abstract List FindDllFiles(); + + protected static FileInfo GetLatestDll(DirectoryInfo versionsFolder, string dllName) { + if (!versionsFolder.Exists) + return null; + + List chromeVersions = new List(versionsFolder.EnumerateDirectories()); + chromeVersions = chromeVersions.OrderByDescending(dirInfo => GetUnixTime(dirInfo.LastWriteTime)).ToList(); + + foreach (DirectoryInfo chromeVersion in chromeVersions) { + if (chromeVersion.Name.Contains(".")) { + foreach (FileInfo file in chromeVersion.EnumerateFiles()) { + if (file.Name.Equals(dllName)) + return file; + } + } + } + return null; + } + + protected static void AddDllToList(List dllList, FileInfo latestDll) { + if (latestDll == null) + return; + dllList.Add(latestDll.FullName); + } + + private static double GetUnixTime(DateTime date) { + return (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; + } + } } diff --git a/ChromeDevExtWarningPatcher/InstallationFinder/InstallationManager.cs b/ChromeDevExtWarningPatcher/InstallationFinder/InstallationManager.cs index ab63b4e..8e7f27e 100644 --- a/ChromeDevExtWarningPatcher/InstallationFinder/InstallationManager.cs +++ b/ChromeDevExtWarningPatcher/InstallationFinder/InstallationManager.cs @@ -2,24 +2,24 @@ using System.Collections.Generic; namespace ChromeDevExtWarningPatcher.InstallationFinder { - class InstallationManager { - private List installationFinders = new List(); + class InstallationManager { + private List installationFinders = new List(); - public InstallationManager() { - installationFinders.Clear(); - installationFinders.Add(new Chrome()); - installationFinders.Add(new Brave()); - installationFinders.Add(new Edge()); - } + public InstallationManager() { + installationFinders.Clear(); + installationFinders.Add(new Chrome()); + installationFinders.Add(new Brave()); + installationFinders.Add(new Edge()); + } - public List FindAllChromiumInstallations() { - List installations = new List(); + public List FindAllChromiumInstallations() { + List installations = new List(); - foreach (Installation installation in installationFinders) { - installations.AddRange(installation.FindDllFiles()); - } + foreach (Installation installation in installationFinders) { + installations.AddRange(installation.FindDllFiles()); + } - return installations; - } - } + return installations; + } + } } diff --git a/ChromeDevExtWarningPatcher/PatcherGui.xaml.cs b/ChromeDevExtWarningPatcher/PatcherGui.xaml.cs index ce5ea44..35eaef2 100644 --- a/ChromeDevExtWarningPatcher/PatcherGui.xaml.cs +++ b/ChromeDevExtWarningPatcher/PatcherGui.xaml.cs @@ -7,95 +7,95 @@ using System.Windows.Media; namespace ChromeDevExtWarningPatcher { - public partial class PatcherGui : Window { - - public PatcherGui() { - InitializeComponent(); - } - - private void SelectFolderBtn_Click(object sender, RoutedEventArgs e) { - OpenFileDialog openFile = new OpenFileDialog(); - openFile.Title = "Select a chrome.dll"; - openFile.Filter = "chrome.dll/msedge.dll file (chrome.dll;msedge.dll)|chrome.dll;msedge.dll|Alternative chrome.dll file (*.dll)|*.dll|All files (*.*)|*.*"; - openFile.FilterIndex = 1; - openFile.CheckFileExists = openFile.CheckPathExists = openFile.AddExtension = true; - - if (openFile.ShowDialog(this) == true) { // No, I am not a noob, I have to do it like this and further below - AddChromiumInstallation(openFile.FileName); - } - } - - private void PatchBtn_Click(object sender, RoutedEventArgs e) { - Program.bytePatchManager.DisabledGroups.Clear(); - foreach (CustomCheckBox patchBox in PatchGroupList.Items) { - if (patchBox.IsChecked == false) - Program.bytePatchManager.DisabledGroups.Add(patchBox.Group); - } - - foreach (CheckBox installationBox in InstallationList.Items) { - if (installationBox.IsChecked == true) { - string path = installationBox.Content.ToString(); - - new Thread(() => { - try { - DllPatcher patcher = new DllPatcher(path); - if (patcher.Patch(Log)) { - installationBox.Dispatcher.Invoke(new Action(() => { - installationBox.Foreground = installationBox.BorderBrush = new SolidColorBrush(Color.FromRgb(72, 207, 133)); - })); - } - } catch (Exception ex) { - Log("Error while patching " + path + ":" + ex.Message); - } - }).Start(); - } - } - } - - private void CopyBtn_Click(object sender, RoutedEventArgs e) { - Clipboard.SetText(ConsoleBox.GetTotalTextRange().Text); - } - - protected override void OnInitialized(EventArgs e) { - base.OnInitialized(e); - - ConsoleBox.GetTotalTextRange().Text = ""; - - Log("Patcher gui initialized"); - Log("Searching for Chromium installations..."); - - foreach (string path in new InstallationFinder.InstallationManager().FindAllChromiumInstallations()) { - AddChromiumInstallation(path); - } - - foreach (GuiPatchGroupData patchGroup in Program.bytePatchManager.PatchGroups) { - PatchGroupList.Items.Add(new CustomCheckBox(patchGroup)); - } - } - - public void Log(string str) { - ConsoleBox.Dispatcher.Invoke(new Action(() => { - Paragraph logParagraph = new Paragraph(); - logParagraph.Inlines.Add(str); - - ConsoleBox.Document.Blocks.Add(logParagraph); - ConsoleBox.ScrollToEnd(); - })); - } - - private void AddChromiumInstallation(string chromeDll) { - CustomCheckBox installationBox = new CustomCheckBox(chromeDll); - installationBox.IsChecked = true; - installationBox.ToolTip = chromeDll; - - InstallationList.Items.Add(installationBox); - Log("Added Chromium installation at " + chromeDll); - } - } - - public static class RichTextBoxExtensions { - public static TextRange GetTotalTextRange(this RichTextBox richTextBox) { - return new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); - } - } + public partial class PatcherGui : Window { + + public PatcherGui() { + InitializeComponent(); + } + + private void SelectFolderBtn_Click(object sender, RoutedEventArgs e) { + OpenFileDialog openFile = new OpenFileDialog(); + openFile.Title = "Select a chrome.dll"; + openFile.Filter = "chrome.dll/msedge.dll file (chrome.dll;msedge.dll)|chrome.dll;msedge.dll|Alternative chrome.dll file (*.dll)|*.dll|All files (*.*)|*.*"; + openFile.FilterIndex = 1; + openFile.CheckFileExists = openFile.CheckPathExists = openFile.AddExtension = true; + + if (openFile.ShowDialog(this) == true) { // No, I am not a noob, I have to do it like this and further below + AddChromiumInstallation(openFile.FileName); + } + } + + private void PatchBtn_Click(object sender, RoutedEventArgs e) { + Program.bytePatchManager.DisabledGroups.Clear(); + foreach (CustomCheckBox patchBox in PatchGroupList.Items) { + if (patchBox.IsChecked == false) + Program.bytePatchManager.DisabledGroups.Add(patchBox.Group); + } + + foreach (CheckBox installationBox in InstallationList.Items) { + if (installationBox.IsChecked == true) { + string path = installationBox.Content.ToString(); + + new Thread(() => { + try { + DllPatcher patcher = new DllPatcher(path); + if (patcher.Patch(Log)) { + installationBox.Dispatcher.Invoke(new Action(() => { + installationBox.Foreground = installationBox.BorderBrush = new SolidColorBrush(Color.FromRgb(72, 207, 133)); + })); + } + } catch (Exception ex) { + Log("Error while patching " + path + ":" + ex.Message); + } + }).Start(); + } + } + } + + private void CopyBtn_Click(object sender, RoutedEventArgs e) { + Clipboard.SetText(ConsoleBox.GetTotalTextRange().Text); + } + + protected override void OnInitialized(EventArgs e) { + base.OnInitialized(e); + + ConsoleBox.GetTotalTextRange().Text = ""; + + Log("Patcher gui initialized"); + Log("Searching for Chromium installations..."); + + foreach (string path in new InstallationFinder.InstallationManager().FindAllChromiumInstallations()) { + AddChromiumInstallation(path); + } + + foreach (GuiPatchGroupData patchGroup in Program.bytePatchManager.PatchGroups) { + PatchGroupList.Items.Add(new CustomCheckBox(patchGroup)); + } + } + + public void Log(string str) { + ConsoleBox.Dispatcher.Invoke(new Action(() => { + Paragraph logParagraph = new Paragraph(); + logParagraph.Inlines.Add(str); + + ConsoleBox.Document.Blocks.Add(logParagraph); + ConsoleBox.ScrollToEnd(); + })); + } + + private void AddChromiumInstallation(string chromeDll) { + CustomCheckBox installationBox = new CustomCheckBox(chromeDll); + installationBox.IsChecked = true; + installationBox.ToolTip = chromeDll; + + InstallationList.Items.Add(installationBox); + Log("Added Chromium installation at " + chromeDll); + } + } + + public static class RichTextBoxExtensions { + public static TextRange GetTotalTextRange(this RichTextBox richTextBox) { + return new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); + } + } } diff --git a/ChromeDevExtWarningPatcher/Patches/BytePatch.cs b/ChromeDevExtWarningPatcher/Patches/BytePatch.cs index d87177c..ae0f7f3 100644 --- a/ChromeDevExtWarningPatcher/Patches/BytePatch.cs +++ b/ChromeDevExtWarningPatcher/Patches/BytePatch.cs @@ -1,29 +1,29 @@ using ChromeDevExtWarningPatcher.Patches; namespace ChromeDevExtWarningPatcher { - public class BytePatch { - public byte origByteX64, patchByteX64; - public int offsetX64, aoffsetX64; - public BytePatchPattern pattern; + public class BytePatch { + public byte origByteX64, patchByteX64; + public int offsetX64, aoffsetX64; + public BytePatchPattern pattern; - public byte origByteX86, patchByteX86; - public int offsetX86, aoffsetX86; + public byte origByteX86, patchByteX86; + public int offsetX86, aoffsetX86; - public int group; + public int group; - public BytePatch(BytePatchPattern pattern, byte origByteX64, byte patchByteX64, int offsetX64, int aoffsetX64, byte origByteX86, byte patchByteX86, int offsetX86, int aoffsetX86, int group) { - this.pattern = pattern; - this.origByteX64 = origByteX64; - this.patchByteX64 = patchByteX64; - this.offsetX64 = offsetX64; - this.aoffsetX64 = aoffsetX64; + public BytePatch(BytePatchPattern pattern, byte origByteX64, byte patchByteX64, int offsetX64, int aoffsetX64, byte origByteX86, byte patchByteX86, int offsetX86, int aoffsetX86, int group) { + this.pattern = pattern; + this.origByteX64 = origByteX64; + this.patchByteX64 = patchByteX64; + this.offsetX64 = offsetX64; + this.aoffsetX64 = aoffsetX64; - this.origByteX86 = origByteX86; - this.patchByteX86 = patchByteX86; - this.offsetX86 = offsetX86; - this.aoffsetX86 = aoffsetX86; + this.origByteX86 = origByteX86; + this.patchByteX86 = patchByteX86; + this.offsetX86 = offsetX86; + this.aoffsetX86 = aoffsetX86; - this.group = group; - } - } + this.group = group; + } + } } diff --git a/ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs b/ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs index 237fd8c..416d025 100644 --- a/ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs +++ b/ChromeDevExtWarningPatcher/Patches/BytePatchManager.cs @@ -9,159 +9,159 @@ using System.Xml.Linq; namespace ChromeDevExtWarningPatcher.Patches { - class BytePatchManager { - private List BytePatches = new List(); - private Dictionary BytePatterns = new Dictionary(); - - public List DisabledGroups = new List(); - public List PatchGroups = new List(); - - public delegate MessageBoxResult WriteLineOrMessageBox(string str, string title); - public BytePatchManager(WriteLineOrMessageBox log) { - BytePatches.Clear(); - BytePatterns.Clear(); - - XDocument xmlDoc = null; - string xmlFile = Program.DEBUG ? @"..\..\..\patterns.xml" : (Path.GetTempPath() + "chrome_patcher_patterns.xml"); - - try { - if (Program.DEBUG) - throw new Exception("Forcing to use local patterns.xml"); - - using (WebClient web = new WebClient()) { - string xmlStr; - xmlDoc = XDocument.Parse(xmlStr = web.DownloadString("https://raw.githubusercontent.com/Ceiridge/Chrome-Developer-Mode-Extension-Warning-Patcher/master/patterns.xml")); // Hardcoded defaults xml file; This makes quick fixes possible - - File.WriteAllText(xmlFile, xmlStr); - } - } catch (Exception ex) { - if (File.Exists(xmlFile)) { - xmlDoc = XDocument.Parse(File.ReadAllText(xmlFile)); - log("An error occurred trying to fetch the new patterns. The old cached version will be used instead. Expect patch errors.\n\n" + ex.Message, "Warning"); - } else { - log("An error occurred trying to fetch the new patterns. The program has to exit, as no cached version of this file has been found.\n\n" + ex.Message, "Error"); - Environment.Exit(1); - } - } - - - if (xmlDoc != null) { - // Comma culture setter from https://stackoverflow.com/questions/9160059/set-up-dot-instead-of-comma-in-numeric-values - CultureInfo customCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; - Thread.CurrentThread.CurrentCulture = customCulture; - - float newVersion = float.Parse(xmlDoc.Root.Attribute("version").Value); - Version myVersion = Assembly.GetCallingAssembly().GetName().Version; - - if (newVersion > float.Parse(myVersion.Major + "." + myVersion.Minor)) { - log("A new version of this patcher has been found.\nDownload it at:\nhttps://github.com/Ceiridge/Chrome-Developer-Mode-Extension-Warning-Patcher/releases", "New update available"); - } - - foreach (XElement pattern in xmlDoc.Root.Element("Patterns").Elements("Pattern")) { - BytePatchPattern patternClass = new BytePatchPattern(pattern.Attribute("name").Value); - - foreach (XElement patternList in pattern.Elements("BytePatternList")) { - bool isX64 = patternList.Attribute("type").Value.Equals("x64"); - - foreach (XElement bytePattern in patternList.Elements("BytePattern")) { - string[] unparsedBytes = bytePattern.Value.Split(' '); - byte[] patternBytesArr = new byte[unparsedBytes.Length]; - - for (int i = 0; i < unparsedBytes.Length; i++) { - string unparsedByte = unparsedBytes[i].Equals("?") ? "FF" : unparsedBytes[i]; - patternBytesArr[i] = Convert.ToByte(unparsedByte, 16); - } - (isX64 ? patternClass.AlternativePatternsX64 : patternClass.AlternativePatternsX86).Add(patternBytesArr); - } - } - BytePatterns.Add(patternClass.Name, patternClass); - } - - foreach (XElement patch in xmlDoc.Root.Element("Patches").Elements("Patch")) { - BytePatchPattern pattern = BytePatterns[patch.Attribute("pattern").Value]; - int group = int.Parse(patch.Attribute("group").Value); - - byte origX64 = 0, origX86 = 0, patchX64 = 0, patchX86 = 0; - int offsetX64 = 0, offsetX86 = 0, aoffsetX64 = -1, aoffsetX86 = -1; - - foreach (XElement patchData in patch.Elements("PatchData")) { - byte orig = Convert.ToByte(patchData.Attribute("orig").Value.Replace("0x", ""), 16); - byte patchB = Convert.ToByte(patchData.Attribute("patch").Value.Replace("0x", ""), 16); - int offset = Convert.ToInt32(patchData.Attribute("offset").Value.Replace("0x", ""), 16); - - XAttribute alternativeOffsetAttr = patchData.Attribute("alternativeOffset"); - int aoffset = alternativeOffsetAttr == null ? -1 : Convert.ToInt32(alternativeOffsetAttr.Value.Replace("0x", ""), 16); - - if (patchData.Attribute("type").Value.Equals("x64")) { - origX64 = orig; - patchX64 = patchB; - offsetX64 = offset; - aoffsetX64 = aoffset; - } else { - origX86 = orig; - patchX86 = patchB; - offsetX86 = offset; - aoffsetX86 = aoffset; - } - } - BytePatches.Add(new BytePatch(pattern, origX64, patchX64, offsetX64, aoffsetX64, origX86, patchX86, offsetX86, aoffsetX86, group)); - } - - foreach (XElement patchGroup in xmlDoc.Root.Element("GroupedPatches").Elements("GroupedPatch")) { - PatchGroups.Add(new GuiPatchGroupData { - Group = int.Parse(patchGroup.Attribute("group").Value), - Default = bool.Parse(patchGroup.Attribute("default").Value), - Name = patchGroup.Element("Name").Value, - Tooltip = patchGroup.Element("Tooltip").Value - }); - } - } - } - - public bool PatchBytes(ref byte[] raw, bool x64, BytePatchPattern.WriteToLog log) { - int patches = 0; - - foreach (BytePatch patch in BytePatches) { - if (DisabledGroups.Contains(patch.group)) { - patches++; - continue; - } - Tuple 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 (addr != -1) { - 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 - - REDO_CHECKS: - long index = addr + patchOffset; - byte sourceByte = raw[index]; - - log("Source byte of patch at " + patchOffset + ": " + sourceByte); - if (sourceByte == patchOrigByte) { - raw[index] = patchPatchByte; - log(index + " => " + patchPatchByte); - patches++; - } else { - int patchAlternativeOffset = x64 ? patch.aoffsetX64 : patch.aoffsetX86; - if (patchOffset != patchAlternativeOffset && patchAlternativeOffset != -1) { // if the first offset didn't work, try the next one - patchOffset = patchAlternativeOffset; - goto REDO_CHECKS; - } - - log("Source byte unexpected, should be " + patchOrigByte + "!"); - } - } else { - log("Couldn't find offset for a patch " + patch.pattern.Name); - } - } - - return patches == BytePatches.Count; - } - } + class BytePatchManager { + private List BytePatches = new List(); + private Dictionary BytePatterns = new Dictionary(); + + public List DisabledGroups = new List(); + public List PatchGroups = new List(); + + public delegate MessageBoxResult WriteLineOrMessageBox(string str, string title); + public BytePatchManager(WriteLineOrMessageBox log) { + BytePatches.Clear(); + BytePatterns.Clear(); + + XDocument xmlDoc = null; + string xmlFile = Program.DEBUG ? @"..\..\..\patterns.xml" : (Path.GetTempPath() + "chrome_patcher_patterns.xml"); + + try { + if (Program.DEBUG) + throw new Exception("Forcing to use local patterns.xml"); + + using (WebClient web = new WebClient()) { + string xmlStr; + xmlDoc = XDocument.Parse(xmlStr = web.DownloadString("https://raw.githubusercontent.com/Ceiridge/Chrome-Developer-Mode-Extension-Warning-Patcher/master/patterns.xml")); // Hardcoded defaults xml file; This makes quick fixes possible + + File.WriteAllText(xmlFile, xmlStr); + } + } catch (Exception ex) { + if (File.Exists(xmlFile)) { + xmlDoc = XDocument.Parse(File.ReadAllText(xmlFile)); + log("An error occurred trying to fetch the new patterns. The old cached version will be used instead. Expect patch errors.\n\n" + ex.Message, "Warning"); + } else { + log("An error occurred trying to fetch the new patterns. The program has to exit, as no cached version of this file has been found.\n\n" + ex.Message, "Error"); + Environment.Exit(1); + } + } + + + if (xmlDoc != null) { + // Comma culture setter from https://stackoverflow.com/questions/9160059/set-up-dot-instead-of-comma-in-numeric-values + CultureInfo customCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; + Thread.CurrentThread.CurrentCulture = customCulture; + + float newVersion = float.Parse(xmlDoc.Root.Attribute("version").Value); + Version myVersion = Assembly.GetCallingAssembly().GetName().Version; + + if (newVersion > float.Parse(myVersion.Major + "." + myVersion.Minor)) { + log("A new version of this patcher has been found.\nDownload it at:\nhttps://github.com/Ceiridge/Chrome-Developer-Mode-Extension-Warning-Patcher/releases", "New update available"); + } + + foreach (XElement pattern in xmlDoc.Root.Element("Patterns").Elements("Pattern")) { + BytePatchPattern patternClass = new BytePatchPattern(pattern.Attribute("name").Value); + + foreach (XElement patternList in pattern.Elements("BytePatternList")) { + bool isX64 = patternList.Attribute("type").Value.Equals("x64"); + + foreach (XElement bytePattern in patternList.Elements("BytePattern")) { + string[] unparsedBytes = bytePattern.Value.Split(' '); + byte[] patternBytesArr = new byte[unparsedBytes.Length]; + + for (int i = 0; i < unparsedBytes.Length; i++) { + string unparsedByte = unparsedBytes[i].Equals("?") ? "FF" : unparsedBytes[i]; + patternBytesArr[i] = Convert.ToByte(unparsedByte, 16); + } + (isX64 ? patternClass.AlternativePatternsX64 : patternClass.AlternativePatternsX86).Add(patternBytesArr); + } + } + BytePatterns.Add(patternClass.Name, patternClass); + } + + foreach (XElement patch in xmlDoc.Root.Element("Patches").Elements("Patch")) { + BytePatchPattern pattern = BytePatterns[patch.Attribute("pattern").Value]; + int group = int.Parse(patch.Attribute("group").Value); + + byte origX64 = 0, origX86 = 0, patchX64 = 0, patchX86 = 0; + int offsetX64 = 0, offsetX86 = 0, aoffsetX64 = -1, aoffsetX86 = -1; + + foreach (XElement patchData in patch.Elements("PatchData")) { + byte orig = Convert.ToByte(patchData.Attribute("orig").Value.Replace("0x", ""), 16); + byte patchB = Convert.ToByte(patchData.Attribute("patch").Value.Replace("0x", ""), 16); + int offset = Convert.ToInt32(patchData.Attribute("offset").Value.Replace("0x", ""), 16); + + XAttribute alternativeOffsetAttr = patchData.Attribute("alternativeOffset"); + int aoffset = alternativeOffsetAttr == null ? -1 : Convert.ToInt32(alternativeOffsetAttr.Value.Replace("0x", ""), 16); + + if (patchData.Attribute("type").Value.Equals("x64")) { + origX64 = orig; + patchX64 = patchB; + offsetX64 = offset; + aoffsetX64 = aoffset; + } else { + origX86 = orig; + patchX86 = patchB; + offsetX86 = offset; + aoffsetX86 = aoffset; + } + } + BytePatches.Add(new BytePatch(pattern, origX64, patchX64, offsetX64, aoffsetX64, origX86, patchX86, offsetX86, aoffsetX86, group)); + } + + foreach (XElement patchGroup in xmlDoc.Root.Element("GroupedPatches").Elements("GroupedPatch")) { + PatchGroups.Add(new GuiPatchGroupData { + Group = int.Parse(patchGroup.Attribute("group").Value), + Default = bool.Parse(patchGroup.Attribute("default").Value), + Name = patchGroup.Element("Name").Value, + Tooltip = patchGroup.Element("Tooltip").Value + }); + } + } + } + + public bool PatchBytes(ref byte[] raw, bool x64, BytePatchPattern.WriteToLog log) { + int patches = 0; + + foreach (BytePatch patch in BytePatches) { + if (DisabledGroups.Contains(patch.group)) { + patches++; + continue; + } + Tuple 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 (addr != -1) { + 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 + + REDO_CHECKS: + long index = addr + patchOffset; + byte sourceByte = raw[index]; + + log("Source byte of patch at " + patchOffset + ": " + sourceByte); + if (sourceByte == patchOrigByte) { + raw[index] = patchPatchByte; + log(index + " => " + patchPatchByte); + patches++; + } else { + int patchAlternativeOffset = x64 ? patch.aoffsetX64 : patch.aoffsetX86; + if (patchOffset != patchAlternativeOffset && patchAlternativeOffset != -1) { // if the first offset didn't work, try the next one + patchOffset = patchAlternativeOffset; + goto REDO_CHECKS; + } + + log("Source byte unexpected, should be " + patchOrigByte + "!"); + } + } else { + log("Couldn't find offset for a patch " + patch.pattern.Name); + } + } + + return patches == BytePatches.Count; + } + } } diff --git a/ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs b/ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs index 0f26ed6..9e55490 100644 --- a/ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs +++ b/ChromeDevExtWarningPatcher/Patches/BytePatchPattern.cs @@ -2,38 +2,38 @@ using System.Collections.Generic; namespace ChromeDevExtWarningPatcher.Patches { - public class BytePatchPattern { - public string Name; - public List AlternativePatternsX86 = new List(); - public List AlternativePatternsX64 = new List(); + public class BytePatchPattern { + public string Name; + public List AlternativePatternsX86 = new List(); + public List AlternativePatternsX64 = new List(); - public BytePatchPattern(string name) { - Name = name; - } + public BytePatchPattern(string name) { + Name = name; + } - public delegate void WriteToLog(string str); - public Tuple 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; + public delegate void WriteToLog(string str); + public Tuple 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; - for (int i = 0; i < raw.Length; i++) { - byte chromeByte = raw[i]; - byte expectedByte = pattern[patternIndex]; + 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 (expectedByte == 0xFF ? true : (chromeByte == expectedByte)) + patternIndex++; + else + patternIndex = 0; - if (patternIndex == pattern.Length) { - patternOffset = i - (patternIndex - 1); - log("Found pattern offset at " + patternOffset); - return new Tuple(patternOffset, pattern); - } - } - } + if (patternIndex == pattern.Length) { + patternOffset = i - (patternIndex - 1); + log("Found pattern offset at " + patternOffset); + return new Tuple(patternOffset, pattern); + } + } + } - return new Tuple(-1L, null); - } - } + return new Tuple(-1L, null); + } + } } diff --git a/ChromeDevExtWarningPatcher/Program.cs b/ChromeDevExtWarningPatcher/Program.cs index e2db699..feeca8a 100644 --- a/ChromeDevExtWarningPatcher/Program.cs +++ b/ChromeDevExtWarningPatcher/Program.cs @@ -11,86 +11,86 @@ // Ugly and uncommented code ahead namespace ChromeDevExtWarningPatcher { - class Program { - private static Application guiApp; - private static Window guiWindow; - public static BytePatchManager bytePatchManager; - - public const bool DEBUG = false; - - [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern bool FreeConsole(); - - [STAThread] - public static void Main(string[] args) { - if (args.Length == 0) { - FreeConsole(); - bytePatchManager = new BytePatchManager(MessageBox.Show); - guiApp = new Application(); - guiApp.Run(guiWindow = new PatcherGui()); - } else { - MainCmd(args); - } - } - - public static void MainCmd(string[] args) { - CommandLineOptions clOptions = null; - ParserResult result = Parser.Default.ParseArguments(args).WithParsed(options => { - clOptions = options; - }); - - if (result.Tag == ParserResultType.NotParsed) { - HelpText.AutoBuild(result); - return; - } - - if (clOptions == null) - return; - bytePatchManager = new BytePatchManager(CustomConsoleWrite); - - List applicationPaths = new List(); - List groups = new List(clOptions.Groups); - - if (groups.Count == 0) { - Console.WriteLine("Groups need to be defined. Use --help for help."); - return; - } - - if (clOptions.CustomPath != null && clOptions.CustomPath.Length > 0) { - if (!Directory.Exists(clOptions.CustomPath)) { - Console.WriteLine("CustomPath not found"); - return; - } - - applicationPaths.AddRange(new CustomPath(clOptions.CustomPath).FindDllFiles()); - } else { - applicationPaths.AddRange(new InstallationFinder.InstallationManager().FindAllChromiumInstallations()); - } - - foreach (GuiPatchGroupData patchData in bytePatchManager.PatchGroups) { - if (!groups.Contains(patchData.Group)) - bytePatchManager.DisabledGroups.Add(patchData.Group); - } - - if (applicationPaths.Count == 0) - Console.WriteLine("Error: No patchable dll file found!"); - - foreach (string path in applicationPaths) { - try { - DllPatcher patcher = new DllPatcher(path); - patcher.Patch(Console.WriteLine); - } catch (Exception ex) { - Console.WriteLine("Error while patching " + path + ":" + ex.Message); - } - } - - if (!clOptions.NoWait) - Thread.Sleep(5000); // Wait a bit to let the user see the result - } - - private static MessageBoxResult CustomConsoleWrite(string str, string arg2 = "") { - Console.WriteLine(str); - return MessageBoxResult.OK; - } - } + class Program { + private static Application guiApp; + private static Window guiWindow; + public static BytePatchManager bytePatchManager; + + public const bool DEBUG = false; + + [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] + private static extern bool FreeConsole(); + + [STAThread] + public static void Main(string[] args) { + if (args.Length == 0) { + FreeConsole(); + bytePatchManager = new BytePatchManager(MessageBox.Show); + guiApp = new Application(); + guiApp.Run(guiWindow = new PatcherGui()); + } else { + MainCmd(args); + } + } + + public static void MainCmd(string[] args) { + CommandLineOptions clOptions = null; + ParserResult result = Parser.Default.ParseArguments(args).WithParsed(options => { + clOptions = options; + }); + + if (result.Tag == ParserResultType.NotParsed) { + HelpText.AutoBuild(result); + return; + } + + if (clOptions == null) + return; + bytePatchManager = new BytePatchManager(CustomConsoleWrite); + + List applicationPaths = new List(); + List groups = new List(clOptions.Groups); + + if (groups.Count == 0) { + Console.WriteLine("Groups need to be defined. Use --help for help."); + return; + } + + if (clOptions.CustomPath != null && clOptions.CustomPath.Length > 0) { + if (!Directory.Exists(clOptions.CustomPath)) { + Console.WriteLine("CustomPath not found"); + return; + } + + applicationPaths.AddRange(new CustomPath(clOptions.CustomPath).FindDllFiles()); + } else { + applicationPaths.AddRange(new InstallationFinder.InstallationManager().FindAllChromiumInstallations()); + } + + foreach (GuiPatchGroupData patchData in bytePatchManager.PatchGroups) { + if (!groups.Contains(patchData.Group)) + bytePatchManager.DisabledGroups.Add(patchData.Group); + } + + if (applicationPaths.Count == 0) + Console.WriteLine("Error: No patchable dll file found!"); + + foreach (string path in applicationPaths) { + try { + DllPatcher patcher = new DllPatcher(path); + patcher.Patch(Console.WriteLine); + } catch (Exception ex) { + Console.WriteLine("Error while patching " + path + ":" + ex.Message); + } + } + + if (!clOptions.NoWait) + Thread.Sleep(5000); // Wait a bit to let the user see the result + } + + private static MessageBoxResult CustomConsoleWrite(string str, string arg2 = "") { + Console.WriteLine(str); + return MessageBoxResult.OK; + } + } } \ No newline at end of file