-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👀 Implement auto ifeo binary validation
- Loading branch information
Showing
8 changed files
with
322 additions
and
67 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
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,136 @@ | ||
using Microsoft.Win32; | ||
using System; | ||
using System.IO; | ||
using System.Windows; | ||
using Microsoft.Toolkit.Uwp.Notifications; | ||
using System.Security.Cryptography; | ||
|
||
namespace GoAwayEdge.Common | ||
{ | ||
internal class Updater | ||
{ | ||
/// <summary> | ||
/// Initialize the current environment. | ||
/// </summary> | ||
/// <returns> | ||
/// Boolean status of the initialization. | ||
/// </returns> | ||
public static bool InitEnv() | ||
{ | ||
try | ||
{ | ||
// Get Ifeo-Path | ||
var key = Registry.LocalMachine.OpenSubKey( | ||
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\0"); | ||
if (key == null) | ||
{ | ||
Console.WriteLine("Registry key not found."); | ||
return false; | ||
} | ||
|
||
var IfeoBinaryPath = (string)key.GetValue("FilterFullPath"); | ||
if (IfeoBinaryPath == null) | ||
{ | ||
Console.WriteLine("FilterFullPath value not found."); | ||
return false; | ||
} | ||
|
||
FileConfiguration.EdgePath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge.exe"; | ||
FileConfiguration.IfeoPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge_ifeo.exe"; | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show($"Initialization failed!\n{ex.Message}", "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Error); | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Validates if the installed IFEO-Binary is identical with the Edge-Binary. | ||
/// </summary> | ||
/// <returns> | ||
/// Integer value if the Binary is identical, not identical or missing. | ||
/// 0 : true | ||
/// 1 : false | ||
/// 2 : missing | ||
/// </returns> | ||
public static int ValidateIfeoBinary() | ||
{ | ||
// Get Ifeo-Path | ||
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\0"); | ||
if (key == null) | ||
{ | ||
Console.WriteLine("Registry key not found."); | ||
return 2; | ||
} | ||
|
||
var IfeoBinaryPath = (string)key.GetValue("FilterFullPath"); | ||
if (IfeoBinaryPath == null) | ||
{ | ||
Console.WriteLine("FilterFullPath value not found."); | ||
return 2; | ||
} | ||
|
||
if (File.Exists(IfeoBinaryPath)) | ||
{ | ||
var EdgeBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge.exe"; | ||
IfeoBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge_ifeo.exe"; | ||
|
||
var edgeHash = CalculateMD5(EdgeBinaryPath); | ||
var ifeoHash = CalculateMD5(IfeoBinaryPath); | ||
#if DEBUG | ||
if (edgeHash != ifeoHash) | ||
MessageBox.Show($"The Edge Hash ({edgeHash}) and Ifeo Hash ({ifeoHash}) are not identical. Validation failed!", "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Warning); | ||
#endif | ||
|
||
return edgeHash != ifeoHash ? 1 : 0; | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"FilterFullPath does not exist: {IfeoBinaryPath}"); | ||
return 2; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Modifies the Ifeo Binary. | ||
/// </summary> | ||
public static void ModifyIfeoBinary(ModifyAction action) | ||
{ | ||
switch (action) | ||
{ | ||
case ModifyAction.Update: | ||
case ModifyAction.Create: | ||
{ | ||
try | ||
{ | ||
File.Copy(FileConfiguration.EdgePath, FileConfiguration.IfeoPath, true); | ||
new ToastContentBuilder() | ||
.AddText("Update successful") | ||
.AddText("The IFEO binary was successfully updated.") | ||
.Show(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show($"Update failed!\n{ex.Message}", "GoAwayEdge", MessageBoxButton.OK, | ||
MessageBoxImage.Error); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private static string CalculateMD5(string filename) | ||
{ | ||
using (var md5 = MD5.Create()) | ||
{ | ||
using (var stream = File.OpenRead(filename)) | ||
{ | ||
var hash = md5.ComputeHash(stream); | ||
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.