Skip to content

Commit

Permalink
🛫 Version 1.1.0
Browse files Browse the repository at this point in the history
Merge pull request #5 from valnoxy/dev
  • Loading branch information
valnoxy authored Jul 11, 2023
2 parents f7456d1 + cf2e13a commit f8b4386
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 169 deletions.
2 changes: 2 additions & 0 deletions GoAwayEdge/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
<ResourceDictionary Source="/GoAwayEdge;component/Localization/ResourceDictionary.xaml"/>
<ResourceDictionary Source="/GoAwayEdge;component/Localization/ResourceDictionary.de-DE.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
90 changes: 65 additions & 25 deletions GoAwayEdge/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
using System.Text;
using System.Web;
using System.Windows;
using Microsoft.Win32;

namespace GoAwayEdge
{
/// <summary>
/// Interaktionslogik für App.xaml
/// </summary>
public partial class App : Application
public partial class App
{
private static string? _url;
private static SearchEngine _engine = SearchEngine.Google; // Fallback
Expand All @@ -34,15 +35,15 @@ public void Application_Startup(object sender, StartupEventArgs e)
if (IsAdministrator() == false)
{
// Restart program and run as admin
var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName;
var exeName = Process.GetCurrentProcess().MainModule?.FileName;
if (exeName != null)
{
var startInfo = new ProcessStartInfo(exeName)
{
Verb = "runas",
UseShellExecute = true
};
System.Diagnostics.Process.Start(startInfo);
Process.Start(startInfo);
}
Application.Current.Shutdown();
return;
Expand All @@ -60,7 +61,7 @@ public void Application_Startup(object sender, StartupEventArgs e)

#if DEBUG
Clipboard.SetText(argumentJoin);
MessageBox.Show("The following args was redirected (copied to clipboard):\n\n" + argumentJoin, "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show("The following args are redirected (copied to the clipboard):\n\n" + argumentJoin, "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information);
#endif
Output.WriteLine("Command line args:\n\n" + argumentJoin + "\n", ConsoleColor.Gray);

Expand All @@ -74,11 +75,11 @@ public void Application_Startup(object sender, StartupEventArgs e)
}
if (arg.Contains("--update"))
{
var statusEnv = Common.Updater.InitEnv();
var statusEnv = Updater.InitEnv();
if (statusEnv == false) Environment.Exit(1);

// Validate IFEO bínary
var binaryStatus = Common.Updater.ValidateIfeoBinary();
var binaryStatus = Updater.ValidateIfeoBinary();
switch (binaryStatus)
{
case 0: // validated
Expand All @@ -90,7 +91,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
if (result == MessageBoxResult.Yes)
{
// Restart program and run as admin
var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName;
var exeName = Process.GetCurrentProcess().MainModule?.FileName;
if (exeName != null)
{
var startInfo = new ProcessStartInfo(exeName)
Expand All @@ -99,7 +100,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
UseShellExecute = true,
Arguments = "--update"
};
System.Diagnostics.Process.Start(startInfo);
Process.Start(startInfo);
}
Application.Current.Shutdown();
return;
Expand All @@ -115,7 +116,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
if (result == MessageBoxResult.Yes)
{
// Restart program and run as admin
var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName;
var exeName = Process.GetCurrentProcess().MainModule?.FileName;
if (exeName != null)
{
var startInfo = new ProcessStartInfo(exeName)
Expand All @@ -124,7 +125,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
UseShellExecute = true,
Arguments = "--update"
};
System.Diagnostics.Process.Start(startInfo);
Process.Start(startInfo);
}
Application.Current.Shutdown();
return;
Expand Down Expand Up @@ -153,15 +154,22 @@ public void Application_Startup(object sender, StartupEventArgs e)
"Yandex" => SearchEngine.Yandex,
"Ecosia" => SearchEngine.Ecosia,
"Ask" => SearchEngine.Ask,
"Qwant" => SearchEngine.Qwant,
"Custom" => SearchEngine.Custom,
_ => SearchEngine.Google // Fallback search engine
};
}

if (e.Args.Length != 2 || !arg.Contains("msedge.exe")) continue; // Opens Edge normally

if (!args.Contains("--profile-directory") && !ContainsParsedData(args) && args.Length != 2) continue; // Start Edge (default browser on this system)

#if DEBUG
MessageBox.Show("Microsoft Edge will now start normally via IFEO application.", "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information);
#endif

var parsedArgs = args.Skip(2);
var p = new Process();
p.StartInfo.FileName = "msedge_ifeo.exe";
p.StartInfo.Arguments = "";
p.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge_ifeo.exe";
p.StartInfo.Arguments = string.Join(" ", parsedArgs);
p.StartInfo.UseShellExecute = true;
p.StartInfo.RedirectStandardOutput = false;
p.Start();
Expand All @@ -171,9 +179,11 @@ public void Application_Startup(object sender, StartupEventArgs e)
// Open URL in default browser
if (_url != null)
{
var parsed = ParsingUrl(_url);
var parsed = ParseUrl(_url);
Output.WriteLine("Opening URL in default browser:\n\n" + parsed + "\n", ConsoleColor.Gray);

#if DEBUG
MessageBox.Show("Opening URL in default browser:\n\n" + parsed + "\n", "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information);
#endif
var p = new Process();
p.StartInfo.FileName = parsed;
p.StartInfo.Arguments = "";
Expand All @@ -185,7 +195,20 @@ public void Application_Startup(object sender, StartupEventArgs e)
Environment.Exit(0);
}

private static string ParsingUrl(string encodedUrl)
private static bool ContainsParsedData(IEnumerable<string> args)
{
var contains = false;
var engineUrl = DefineEngine(_engine);

foreach (var arg in args)
{
if (arg.Contains(engineUrl))
contains = true;
}
return contains;
}

private static string ParseUrl(string encodedUrl)
{
// Remove URI handler with url argument prefix
encodedUrl = encodedUrl[encodedUrl.IndexOf("http", StringComparison.Ordinal)..];
Expand All @@ -207,21 +230,38 @@ private static string ParsingUrl(string encodedUrl)
// Replace Search Engine
encodedUrl = encodedUrl.Replace("https://www.bing.com/search?q=", DefineEngine(_engine));

Uri uri = new(encodedUrl.ToString());
#if DEBUG
MessageBox.Show("New Uri: " + encodedUrl, "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information);
#endif
var uri = new Uri(encodedUrl);
return uri.ToString();
}

private static string DefineEngine(SearchEngine engine)
{
string customQueryUrl = null!;
try
{
var key = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\0", false);
customQueryUrl = (string)key?.GetValue("CustomQueryUrl")!;
}
catch
{
// ignored
}

return engine switch
{
SearchEngine.Google => "https://www.google.com/search?q=",
SearchEngine.Bing => "https://www.bing.com/search?q=",
SearchEngine.DuckDuckGo => "https://duckduckgo.com/?q=",
SearchEngine.DuckDuckGo => "https://duckduckgo.com/?q=}",
SearchEngine.Yahoo => "https://search.yahoo.com/search?p=",
SearchEngine.Yandex => "https://yandex.com/search/?text=",
SearchEngine.Ecosia => "https://www.ecosia.org/search?q=",
SearchEngine.Ask => "https://www.ask.com/web?q=",
SearchEngine.Qwant => "https://qwant.com/?q=",
SearchEngine.Custom => customQueryUrl,
_ => "https://www.google.com/search?q="
};
}
Expand All @@ -236,9 +276,6 @@ private static string DecodeUrlString(string url)

private static string DotSlash(string url)
{
//url = url.Replace("%3A", ":");
//url = url.Replace("%2F", "/");

string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
Expand All @@ -247,13 +284,16 @@ private static string DotSlash(string url)
{
var uri = new Uri(url);
var query = HttpUtility.ParseQueryString(uri.Query).Get("url");
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(query));
if (decoded != null)
if (query != null)
{
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(query));
return decoded;
}
}
catch {;}
catch
{
// ignored
}

return url;
}
Expand Down
5 changes: 4 additions & 1 deletion GoAwayEdge/Common/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ internal enum SearchEngine
Yahoo,
Yandex,
Ecosia,
Ask
Ask,
Qwant,
Custom
}

internal enum EdgeChannel
Expand All @@ -24,6 +26,7 @@ internal class Configuration
public static EdgeChannel Channel { get; set; }
public static SearchEngine Search { get; set; }
public static bool Uninstall { get; set; }
public static string CustomQueryUrl { get; set; }
}

internal enum ModifyAction
Expand Down
35 changes: 15 additions & 20 deletions GoAwayEdge/Common/Updater.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Microsoft.Win32;
using System;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.Win32;
using System.IO;
using System.Windows;
using Microsoft.Toolkit.Uwp.Notifications;
using System.Security.Cryptography;
using System.Windows;

namespace GoAwayEdge.Common
{
Expand Down Expand Up @@ -65,20 +64,20 @@ public static int ValidateIfeoBinary()
return 2;
}

var IfeoBinaryPath = (string)key.GetValue("FilterFullPath");
if (IfeoBinaryPath == null)
var ifeoBinaryPath = (string)key.GetValue("FilterFullPath");
if (ifeoBinaryPath == null)
{
Console.WriteLine("FilterFullPath value not found.");
return 2;
}

if (File.Exists(IfeoBinaryPath))
if (File.Exists(ifeoBinaryPath))
{
var EdgeBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge.exe";
IfeoBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge_ifeo.exe";
var edgeBinaryPath = Path.GetDirectoryName(ifeoBinaryPath) + "\\msedge.exe";
ifeoBinaryPath = Path.GetDirectoryName(ifeoBinaryPath) + "\\msedge_ifeo.exe";

var edgeHash = CalculateMD5(EdgeBinaryPath);
var ifeoHash = CalculateMD5(IfeoBinaryPath);
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);
Expand All @@ -88,7 +87,7 @@ public static int ValidateIfeoBinary()
}
else
{
Console.WriteLine($"FilterFullPath does not exist: {IfeoBinaryPath}");
Console.WriteLine($"FilterFullPath does not exist: {ifeoBinaryPath}");
return 2;
}
}
Expand Down Expand Up @@ -123,14 +122,10 @@ public static void ModifyIfeoBinary(ModifyAction action)

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();
}
}
using var md5 = MD5.Create();
using var stream = File.OpenRead(filename);
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
12 changes: 11 additions & 1 deletion GoAwayEdge/GoAwayEdge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@
<AssemblyName>GoAwayEdge</AssemblyName>
<Company>Exploitox</Company>
<Authors>valnoxy</Authors>
<Version>1.0.2.26</Version>
<Version>1.1.0.38</Version>
<Copyright>Copyright (c) 2018 - 2023 Exploitox. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/valnoxy/GoAwayEdge</PackageProjectUrl>
<RepositoryUrl>https://github.com/valnoxy/GoAwayEdge</RepositoryUrl>
<StartupObject>GoAwayEdge.App</StartupObject>
<ApplicationIcon>GoAwayEdge.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<Page Remove="Localization\ResourceDictionary.de-DE.xaml" />
<Page Remove="Localization\ResourceDictionary.xaml" />
</ItemGroup>

<ItemGroup>
<Content Include="GoAwayEdge.ico" />
</ItemGroup>

<ItemGroup>
<Resource Include="Localization\ResourceDictionary.de-DE.xaml" />
<Resource Include="Localization\ResourceDictionary.xaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
Expand Down
6 changes: 6 additions & 0 deletions GoAwayEdge/GoAwayEdge.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<Page Update="App.xaml">
<SubType>Designer</SubType>
</Page>
<Resource Update="Localization\ResourceDictionary.de-DE.xaml">
<SubType>Designer</SubType>
</Resource>
<Resource Update="Localization\ResourceDictionary.xaml">
<SubType>Designer</SubType>
</Resource>
<Page Update="Pages\Installation.xaml">
<SubType>Designer</SubType>
</Page>
Expand Down
Loading

0 comments on commit f8b4386

Please sign in to comment.