Skip to content

Commit

Permalink
Fix: Added correct TLS encryption for accessing the patterns
Browse files Browse the repository at this point in the history
Also fixed some code style issues
  • Loading branch information
Ceiridge committed Jan 14, 2021
1 parent 263f725 commit 913947b
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 217 deletions.
2 changes: 2 additions & 0 deletions ChromeDevExtWarningPatcher/ChromeDevExtWarningPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
2 changes: 1 addition & 1 deletion ChromeDevExtWarningPatcher/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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,etc.)", Separator = ',')]
[Option("groups", Required = false, HelpText = "Set what patch groups you want to use. See patterns.xml to get the group ids (comma-separated: 0,1,2,etc.)", Separator = ',')]
public IEnumerable<int> Groups { get; set; }

[Option('w', "noWait", Required = false, HelpText = "Disable the almost-pointless wait after finishing")]
Expand Down
59 changes: 30 additions & 29 deletions ChromeDevExtWarningPatcher/CustomCheckBox.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace ChromeDevExtWarningPatcher {
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;

if (tooltip != null)
ToolTip = tooltip;
}

public CustomCheckBox(GuiPatchGroupData patchGroupData) : this(patchGroupData.Name, patchGroupData.Tooltip, patchGroupData.Group) {
IsChecked = patchGroupData.Default;
}

public CustomCheckBox(string text) : this(text, null, -1) { }
}

struct GuiPatchGroupData {
public string Name, Tooltip;
public int Group;
public bool Default;
}
}
using System.Windows.Controls;
using System.Windows.Media;

namespace ChromeDevExtWarningPatcher {
class CustomCheckBox : CheckBox {
public int Group;

public CustomCheckBox(string text, string tooltip, int group) {
this.Content = text;
this.Foreground = this.BorderBrush = new SolidColorBrush(Color.FromRgb(202, 62, 71));
this.Group = group;

if (tooltip != null) {
this.ToolTip = tooltip;
}
}

public CustomCheckBox(GuiPatchGroupData patchGroupData) : this(patchGroupData.Name, patchGroupData.Tooltip, patchGroupData.Group) {
this.IsChecked = patchGroupData.Default;
}

public CustomCheckBox(string text) : this(text, null, -1) { }
}

struct GuiPatchGroupData {
public string Name, Tooltip;
public int Group;
public bool Default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults {
class CustomPath : Installation {
private string Path;
private readonly string path;

public CustomPath(string path) : base("CustomPath") {
Path = path;
this.path = path;
}

public override List<InstallationPaths> FindInstallationPaths() {
List<InstallationPaths> dllFiles = new List<InstallationPaths>();

AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(Path), "chrome.dll", "chrome.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(Path), "msedge.dll", "msedge.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(Path), "chrome.dll", "brave.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(Path), "browser.dll", "browser.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(this.path), "chrome.dll", "chrome.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(this.path), "msedge.dll", "msedge.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(this.path), "chrome.dll", "brave.exe"));
AddDllAndExeToList(dllFiles, GetLatestDllAndExe(new DirectoryInfo(this.path), "browser.dll", "browser.exe"));

return dllFiles;
}
Expand Down
12 changes: 8 additions & 4 deletions ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ namespace ChromeDevExtWarningPatcher.InstallationFinder {
abstract class Installation {
protected string Name;

public Installation(string Name) {
this.Name = Name;
protected Installation(string name) {
this.Name = name;
}

public abstract List<InstallationPaths> FindInstallationPaths();

protected static InstallationPaths GetLatestDllAndExe(DirectoryInfo versionsFolder, string dllName, string exeName) {
if (!versionsFolder.Exists)
if (!versionsFolder.Exists) {
return new InstallationPaths();
}

InstallationPaths paths = new InstallationPaths();

List<DirectoryInfo> chromeVersions = new List<DirectoryInfo>(versionsFolder.EnumerateDirectories());
Expand All @@ -42,8 +44,10 @@ protected static InstallationPaths GetLatestDllAndExe(DirectoryInfo versionsFold
}

protected static void AddDllAndExeToList(List<InstallationPaths> pathList, InstallationPaths latestDllAndExe) {
if (latestDllAndExe.ChromeDllPath == null || latestDllAndExe.ChromeExePath == null)
if (latestDllAndExe.ChromeDllPath == null || latestDllAndExe.ChromeExePath == null) {
return;
}

pathList.Add(latestDllAndExe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

namespace ChromeDevExtWarningPatcher.InstallationFinder {
class InstallationManager {
private List<Installation> installationFinders = new List<Installation>();
private readonly List<Installation> installationFinders = new List<Installation>();

public InstallationManager() {
installationFinders.Clear();
installationFinders.Add(new Chrome());
installationFinders.Add(new Brave());
installationFinders.Add(new Edge());
installationFinders.Add(new Yandex());
this.installationFinders.Clear();
this.installationFinders.Add(new Chrome());
this.installationFinders.Add(new Brave());
this.installationFinders.Add(new Edge());
this.installationFinders.Add(new Yandex());
}

public List<InstallationPaths> FindAllChromiumInstallations() {
List<InstallationPaths> installations = new List<InstallationPaths>();

foreach (Installation installation in installationFinders) {
foreach (Installation installation in this.installationFinders) {
foreach (InstallationPaths paths in installation.FindInstallationPaths()) {
if (paths.Is64Bit()) { // force x64
installations.Add(paths);
Expand All @@ -31,19 +31,21 @@ public List<InstallationPaths> FindAllChromiumInstallations() {

// Taken from https://stackoverflow.com/questions/480696/how-to-find-if-a-native-dll-file-is-compiled-as-x64-or-x86
public static bool IsImageX64(string peFilePath) {
using (var stream = new FileStream(peFilePath, FileMode.Open, FileAccess.Read))
using (var reader = new BinaryReader(stream)) {
using (FileStream stream = new FileStream(peFilePath, FileMode.Open, FileAccess.Read))
using (BinaryReader reader = new BinaryReader(stream)) {
//check the MZ signature to ensure it's a valid Portable Executable image
if (reader.ReadUInt16() != 23117)
if (reader.ReadUInt16() != 23117) {
throw new BadImageFormatException("Not a valid Portable Executable image", peFilePath);
}

// 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)
if (reader.ReadUInt32() != 17744) {
throw new BadImageFormatException("Not a valid Portable Executable image", peFilePath);
}

// seek past the file header, then read the magic number from the optional header
stream.Seek(20, SeekOrigin.Current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ struct InstallationPaths {
public string ChromeDllPath, ChromeExePath;

public InstallationPaths(string chromeDllPath, string chromeExePath) {
ChromeDllPath = chromeDllPath;
ChromeExePath = chromeExePath;
this.ChromeDllPath = chromeDllPath;
this.ChromeExePath = chromeExePath;
}

public InstallationPaths(FileInfo chromeDll, FileInfo chromeExe) {
ChromeDllPath = chromeDll.FullName;
ChromeExePath = chromeExe.FullName;
this.ChromeDllPath = chromeDll.FullName;
this.ChromeExePath = chromeExe.FullName;
}

public bool Is64Bit() {
return InstallationManager.IsImageX64(ChromeDllPath) && InstallationManager.IsImageX64(ChromeExePath);
return InstallationManager.IsImageX64(this.ChromeDllPath) && InstallationManager.IsImageX64(this.ChromeExePath);
}
}
}
Loading

0 comments on commit 913947b

Please sign in to comment.