Skip to content

Commit

Permalink
Converted spaces to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed May 29, 2020
1 parent 73b9c01 commit 7c3de1f
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 550 deletions.
16 changes: 8 additions & 8 deletions ChromeDevExtWarningPatcher/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<int> 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; }
}
}
38 changes: 19 additions & 19 deletions ChromeDevExtWarningPatcher/CustomCheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
110 changes: 55 additions & 55 deletions ChromeDevExtWarningPatcher/DllPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
18 changes: 9 additions & 9 deletions ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FindDllFiles() {
List<string> dllFiles = new List<string>();
public override List<string> FindDllFiles() {
List<string> dllFiles = new List<string>();

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;
}
}
}
18 changes: 9 additions & 9 deletions ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FindDllFiles() {
List<string> dllFiles = new List<string>();
public override List<string> FindDllFiles() {
List<string> dllFiles = new List<string>();

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FindDllFiles() {
List<string> dllFiles = new List<string>();
public override List<string> FindDllFiles() {
List<string> dllFiles = new List<string>();

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;
}
}
}
18 changes: 9 additions & 9 deletions ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FindDllFiles() {
List<string> dllFiles = new List<string>();
public override List<string> FindDllFiles() {
List<string> dllFiles = new List<string>();

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;
}
}
}
74 changes: 37 additions & 37 deletions ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FindDllFiles();

protected static FileInfo GetLatestDll(DirectoryInfo versionsFolder, string dllName) {
if (!versionsFolder.Exists)
return null;

List<DirectoryInfo> chromeVersions = new List<DirectoryInfo>(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<String> 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<string> FindDllFiles();

protected static FileInfo GetLatestDll(DirectoryInfo versionsFolder, string dllName) {
if (!versionsFolder.Exists)
return null;

List<DirectoryInfo> chromeVersions = new List<DirectoryInfo>(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<String> 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;
}
}
}
Loading

0 comments on commit 7c3de1f

Please sign in to comment.