Created
December 13, 2018 11:46
-
-
Save Logxn/252ca68f020c1ac84b0ff6fcde50cfc4 to your computer and use it in GitHub Desktop.
AutoGuard - The easy way to login
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
using System; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Windows.Forms; | |
using SteamAuth; | |
using Microsoft.VisualBasic; | |
using Timer = System.Threading.Timer; | |
using System.Drawing; | |
namespace AutoGuard | |
{ | |
class Program | |
{ | |
private static IntPtr hwnd = IntPtr.Zero; | |
private static string sharedSecret; | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
[DllImport("user32.dll", SetLastError = false)] | |
static extern bool SetForegroundWindow(IntPtr hwnd); | |
static void Main(string[] args) | |
{ | |
Config(); | |
} | |
private static void Config() | |
{ | |
if(string.IsNullOrWhiteSpace(Properties.Settings.Default.shared_secret)) | |
{ | |
string input; | |
input = Interaction.InputBox("Please enter the shared_secret", "AutoGuard - Configuration"); | |
if (string.IsNullOrWhiteSpace(input)) return; | |
Properties.Settings.Default["shared_secret"] = input; | |
Properties.Settings.Default.Save(); | |
} | |
sharedSecret = Properties.Settings.Default.shared_secret; | |
bool created; | |
var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "HandleDie", out created); | |
bool signaled; | |
// Another instance of this process was already running. | |
// We will kill it now | |
if(!created) | |
{ | |
Console.WriteLine("[Info] - Autoguard already running. Killing other instance!"); | |
waitHandle.Set(); | |
Console.WriteLine("[Ok] - Process Killed!"); | |
} | |
var timer = new Timer(Tick, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); | |
NotifyIcon notifyIcon = new NotifyIcon(); | |
notifyIcon.Visible = true; | |
notifyIcon.Icon = SystemIcons.Application; | |
notifyIcon.BalloonTipText = "I am now running in the background"; | |
notifyIcon.BalloonTipTitle = "Auto Guard"; | |
notifyIcon.ShowBalloonTip(5000); | |
notifyIcon.Dispose(); | |
do | |
{ | |
signaled = waitHandle.WaitOne(TimeSpan.FromSeconds(5)); | |
} while (!signaled); | |
Console.WriteLine("I will die now."); | |
} | |
private static void Tick(object state) | |
{ | |
hwnd = FindWindow("vguiPopupWindow", "Steam Guard - Computerautorisierung erforderlich"); | |
if (hwnd != IntPtr.Zero) | |
{ | |
SetForegroundWindow(hwnd); | |
Thread.Sleep(1000); | |
Trigger(); | |
} | |
} | |
private static void Trigger() | |
{ | |
SteamGuardAccount sgAccount = new SteamGuardAccount(); | |
sgAccount.SharedSecret = sharedSecret; | |
var auth = sgAccount.GenerateSteamGuardCode(); | |
SendKeys.SendWait(auth); | |
SendKeys.SendWait("{ENTER}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment