2016-08-21 20:17:04 +02:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using SteamAuth;
|
2016-08-21 17:29:27 +02:00
|
|
|
using System;
|
2016-08-21 20:17:04 +02:00
|
|
|
using System.Collections.Generic;
|
2016-08-21 19:03:43 +02:00
|
|
|
using System.IO;
|
2016-08-21 20:17:04 +02:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2016-08-21 17:29:27 +02:00
|
|
|
|
2016-08-21 17:38:03 +02:00
|
|
|
public static class Program
|
2016-08-21 17:29:27 +02:00
|
|
|
{
|
2016-08-21 19:03:43 +02:00
|
|
|
const string defaultSteamGuardPath = "~/maFiles";
|
|
|
|
|
|
|
|
public static string SteamGuardPath { get; set; } = defaultSteamGuardPath;
|
2016-08-21 23:02:17 +02:00
|
|
|
public static Manifest Manifest { get; set; }
|
|
|
|
public static SteamGuardAccount[] SteamGuardAccounts { get; set; }
|
2016-08-22 01:24:23 +02:00
|
|
|
public static bool Verbose { get; set; } = false;
|
2016-08-21 19:03:43 +02:00
|
|
|
|
2016-08-21 17:38:03 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The main entry point for the application
|
|
|
|
/// </summary>
|
|
|
|
[STAThread]
|
|
|
|
public static void Main(string[] args)
|
2016-08-21 17:34:48 +02:00
|
|
|
{
|
2016-08-23 01:16:43 +02:00
|
|
|
string action = "generate-code";
|
|
|
|
|
2016-08-22 01:24:23 +02:00
|
|
|
string user = "";
|
|
|
|
|
|
|
|
// Parse cli arguments
|
2016-08-21 17:38:03 +02:00
|
|
|
if (args.Contains("--help") || args.Contains("-h"))
|
|
|
|
{
|
|
|
|
Console.WriteLine("steamguard-cli - v0.0");
|
|
|
|
Console.WriteLine();
|
2016-08-22 01:37:05 +02:00
|
|
|
Console.WriteLine("--help, -h Display this help message.");
|
|
|
|
Console.WriteLine("--verbose, -v Display some extra information when the program is running.");
|
|
|
|
Console.WriteLine("--user, -u Specify an account for which to generate a Steam Gaurd code.");
|
|
|
|
Console.WriteLine(" Otherwise, the first account will be selected.");
|
2016-08-21 19:03:43 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-22 01:24:23 +02:00
|
|
|
Verbose = args.Contains("-v") || args.Contains("--verbose");
|
2016-08-23 01:16:43 +02:00
|
|
|
// Actions
|
|
|
|
if (args.Contains("--generate-code"))
|
|
|
|
{
|
|
|
|
action = "generate-code";
|
|
|
|
}
|
|
|
|
else if (args.Contains("--encrypt"))
|
|
|
|
{
|
|
|
|
action = "encrypt";
|
|
|
|
}
|
|
|
|
else if (args.Contains("--decrypt"))
|
|
|
|
{
|
|
|
|
action = "decrypt";
|
|
|
|
}
|
|
|
|
else if (args.Contains("--setup"))
|
|
|
|
{
|
|
|
|
action = "setup";
|
|
|
|
}
|
|
|
|
// Misc
|
2016-08-22 01:24:23 +02:00
|
|
|
if (args.Contains("--user") || args.Contains("-u"))
|
|
|
|
{
|
|
|
|
int u = Array.IndexOf(args, "--user");
|
|
|
|
if (u == -1)
|
|
|
|
{
|
|
|
|
u = Array.IndexOf(args, "-u");
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
user = args[u + 1];
|
|
|
|
}
|
|
|
|
catch (IndexOutOfRangeException)
|
|
|
|
{
|
|
|
|
Console.WriteLine("error: Account name must be supplied after --user or -u.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Verbose) Console.WriteLine("Generating Steam Gaurd code for account \"{0}\"", user);
|
|
|
|
}
|
2016-08-21 19:03:43 +02:00
|
|
|
|
2016-08-22 01:24:23 +02:00
|
|
|
// Do some configure
|
2016-08-21 19:03:43 +02:00
|
|
|
SteamGuardPath = SteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME"));
|
|
|
|
if (!Directory.Exists(SteamGuardPath))
|
|
|
|
{
|
|
|
|
if (SteamGuardPath == defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")))
|
|
|
|
{
|
2016-08-22 01:24:23 +02:00
|
|
|
if (Verbose) Console.WriteLine("warn: {0} does not exist, creating...", SteamGuardPath);
|
2016-08-21 19:03:43 +02:00
|
|
|
Directory.CreateDirectory(SteamGuardPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("error: {0} does not exist.", SteamGuardPath);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-21 17:38:03 +02:00
|
|
|
}
|
2016-08-22 01:24:23 +02:00
|
|
|
if (Verbose) Console.WriteLine("maFiles path: {0}", SteamGuardPath);
|
|
|
|
|
2016-08-23 01:16:43 +02:00
|
|
|
// Perform desired action
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case "generate-code":
|
|
|
|
GenerateCode(user);
|
|
|
|
break;
|
|
|
|
case "encrypt":
|
|
|
|
break;
|
|
|
|
case "decrypt":
|
|
|
|
break;
|
|
|
|
case "setup":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Console.WriteLine("error: Unknown action: {0}", action);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GenerateCode(string user = "")
|
|
|
|
{
|
2016-08-22 01:24:23 +02:00
|
|
|
if (Verbose) Console.WriteLine("Aligning time...");
|
|
|
|
TimeAligner.AlignTime();
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
2016-08-22 21:51:37 +02:00
|
|
|
if (Manifest.Encrypted)
|
|
|
|
{
|
|
|
|
string passkey = Manifest.PromptForPassKey();
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts();
|
|
|
|
}
|
2016-08-22 01:24:23 +02:00
|
|
|
if (SteamGuardAccounts.Length == 0)
|
|
|
|
{
|
|
|
|
Console.WriteLine("error: No accounts read.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Verbose) Console.WriteLine("Selecting account...");
|
|
|
|
string code = "";
|
|
|
|
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
|
|
|
{
|
|
|
|
SteamGuardAccount account = SteamGuardAccounts[i];
|
|
|
|
if (user != "")
|
|
|
|
{
|
|
|
|
if (account.AccountName.ToLower() == user.ToLower())
|
|
|
|
{
|
|
|
|
if (Verbose) Console.WriteLine("Generating Code...");
|
|
|
|
code = account.GenerateSteamGuardCode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Verbose) Console.WriteLine("Generating Code for {0}...", account.AccountName);
|
|
|
|
code = account.GenerateSteamGuardCode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (code != "")
|
|
|
|
Console.WriteLine(code);
|
|
|
|
else
|
|
|
|
Console.WriteLine("error: No Steam accounts found in {0}", SteamGuardAccounts);
|
2016-08-21 17:34:48 +02:00
|
|
|
}
|
2016-08-21 17:29:27 +02:00
|
|
|
}
|