/// <summary> /// Edits a SGA file to either encrypt or decrypt the file /// </summary> /// <param name="account">Account to edit</param> /// <param name="secret">secret for the file</param> /// <returns></returns> public static bool DecryptSGAFile(SteamGuardAccount account) { /*First we find the file related to the account*/ FileInfo sgaFile = GetAccountFile(account); if (sgaFile != null) { if (!File.Exists(sgaFile.FullName)) { return(false); } /*Read the content of the file*/ string fileContent = File.ReadAllText(sgaFile.FullName); if (IsSGAFileEncrypted(account)) { /*If the file looks encrypted, decrypt and save the file if decryption worked*/ string decryptedText = Crypto.DecryptStringAES(fileContent); if (decryptedText.Length > 0) { File.WriteAllText(sgaFile.FullName, decryptedText); return(true); } } } return(false); }
/// <summary> /// Returns all accounts available in a list /// </summary> /// <returns>Returns list of accounts</returns> public static List <Config.LoadSteamGuardAccount> GetAllAccounts() { /*Locate the .SGA save files*/ var sgaList = new List <Config.LoadSteamGuardAccount>(); DirectoryInfo info = new DirectoryInfo(Path.Combine(Application.StartupPath, "SGAFiles")); FileInfo[] files = info.GetFiles("*.SGA"); foreach (FileInfo file in files) { bool skipDeserialize = false; try { string contentStr = File.ReadAllText(file.FullName); if (contentStr.Length > 0) { /*N1 way to determine if it's hashed*/ if (contentStr.EndsWith("=")) { /*If user skips password the secret will be empty, so don't bother with these accounts*/ if (Crypto.crySecret.Length > 0) { contentStr = Crypto.DecryptStringAES(contentStr); } else { skipDeserialize = true; } } /*Try to deserialize content to account class*/ var accountHolder = new Config.LoadSteamGuardAccount(); SteamGuardAccount account = null; if (!skipDeserialize) { /*We don't want to attempt to deserialize this string, but we still want to add the other information*/ account = JsonConvert.DeserializeObject <SteamGuardAccount>(contentStr); accountHolder.account = account; } /*Load the rest of information about the file*/ accountHolder.loaded = (account != null); accountHolder.filename = Path.GetFileNameWithoutExtension(file.Name); /*Add account holder to list that we will return*/ sgaList.Add(accountHolder); } } catch (Exception ex) { /*Whoops - what happend here?*/ MessageBox.Show(ex.ToString()); } } return(sgaList); }
/// <summary> /// Returns all accounts available in a list /// </summary> /// <returns>Returns list of accounts</returns> public static List <SteamGuardAccount> GetAllAccounts() { List <SteamGuardAccount> sgaList = new List <SteamGuardAccount>(); DirectoryInfo info = new DirectoryInfo(Path.Combine(Application.StartupPath, "SGAFiles")); FileInfo[] files = info.GetFiles("*.SGA"); foreach (FileInfo file in files) { try { string contentStr = File.ReadAllText(file.FullName); if (contentStr.Length > 0) { /*N1 way to determine if it's hashed*/ if (contentStr.EndsWith("=")) { if (Crypto.crySecret.Length > 0) { contentStr = Crypto.DecryptStringAES(contentStr); } else { continue; } } SteamGuardAccount account = JsonConvert.DeserializeObject <SteamGuardAccount>(contentStr); if (account != null) { sgaList.Add(account); } } else { /*String was returned empty*/ /*This means password (secret) was incorrect for the account*/ MessageBox.Show(string.Format("Could not open save for SteamID64: {0}", Path.GetFileNameWithoutExtension(file.Name)), "Wrong password"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } return(sgaList); }