From c2cabfba49d3653349d470fdc7fa576082f8a9a4 Mon Sep 17 00:00:00 2001 From: Archi Date: Sat, 11 Dec 2021 15:11:35 +0100 Subject: [PATCH] STD: Add additional safeguards against depot keys corruption --- .../GlobalCache.cs | 26 ++ .../Localization/Strings.Designer.cs | 338 +++++++----------- .../Localization/Strings.resx | 9 + 3 files changed, 165 insertions(+), 208 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs index 954bb37a2..babc4ddba 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs @@ -103,6 +103,8 @@ internal sealed class GlobalCache : SerializableFile { return result; } + ASF.ArchiLogger.LogGenericInfo(Localization.Strings.LoadingGlobalCache); + GlobalCache? globalCache; try { @@ -127,6 +129,16 @@ internal sealed class GlobalCache : SerializableFile { return null; } + ASF.ArchiLogger.LogGenericInfo(Localization.Strings.ValidatingGlobalCacheIntegrity); + + if (globalCache.DepotKeys.Values.Any(static depotKey => !IsValidDepotKey(depotKey))) { + ASF.ArchiLogger.LogGenericWarning(Localization.Strings.GlobalCacheIntegrityValidationFailed); + + globalCache = new GlobalCache(); + + Utilities.InBackground(globalCache.Save); + } + return globalCache; } @@ -243,6 +255,12 @@ internal sealed class GlobalCache : SerializableFile { string depotKey = Convert.ToHexString(depotKeyResult.DepotKey); + if (!IsValidDepotKey(depotKey)) { + ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(depotKey))); + + continue; + } + if (DepotKeys.TryGetValue(depotKeyResult.DepotID, out string? previousDepotKey) && (previousDepotKey == depotKey)) { continue; } @@ -304,4 +322,12 @@ internal sealed class GlobalCache : SerializableFile { Utilities.InBackground(Save); } + + private static bool IsValidDepotKey(string depotKey) { + if (string.IsNullOrEmpty(depotKey)) { + throw new ArgumentNullException(nameof(depotKey)); + } + + return (depotKey.Length == 64) && Utilities.IsValidHexadecimalText(depotKey); + } } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs index 1c8f33367..47457ada0 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,46 +11,32 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Strings() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization.Strings", typeof(Strings).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization.Strings", typeof(Strings).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,246 +45,183 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization { } } - /// - /// Looks up a localized string similar to Finished retrieving {0} app access tokens.. - /// - internal static string BotFinishedRetrievingAppAccessTokens { - get { - return ResourceManager.GetString("BotFinishedRetrievingAppAccessTokens", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finished retrieving {0} app infos.. - /// - internal static string BotFinishedRetrievingAppInfos { - get { - return ResourceManager.GetString("BotFinishedRetrievingAppInfos", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finished retrieving {0} depot keys.. - /// - internal static string BotFinishedRetrievingDepotKeys { - get { - return ResourceManager.GetString("BotFinishedRetrievingDepotKeys", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finished retrieving a total of {0} app access tokens.. - /// - internal static string BotFinishedRetrievingTotalAppAccessTokens { - get { - return ResourceManager.GetString("BotFinishedRetrievingTotalAppAccessTokens", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finished retrieving all depot keys for a total of {0} apps.. - /// - internal static string BotFinishedRetrievingTotalDepots { - get { - return ResourceManager.GetString("BotFinishedRetrievingTotalDepots", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to There are no apps that require a refresh on this bot instance.. - /// - internal static string BotNoAppsToRefresh { - get { - return ResourceManager.GetString("BotNoAppsToRefresh", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving {0} app access tokens.... - /// - internal static string BotRetrievingAppAccessTokens { - get { - return ResourceManager.GetString("BotRetrievingAppAccessTokens", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving {0} app infos.... - /// - internal static string BotRetrievingAppInfos { - get { - return ResourceManager.GetString("BotRetrievingAppInfos", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving {0} depot keys.... - /// - internal static string BotRetrievingDepotKeys { - get { - return ResourceManager.GetString("BotRetrievingDepotKeys", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving a total of {0} app access tokens.... - /// - internal static string BotRetrievingTotalAppAccessTokens { - get { - return ResourceManager.GetString("BotRetrievingTotalAppAccessTokens", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving all depots for a total of {0} apps.... - /// - internal static string BotRetrievingTotalDepots { - get { - return ResourceManager.GetString("BotRetrievingTotalDepots", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} could not be loaded, a fresh instance will be initialized.... - /// - internal static string FileCouldNotBeLoadedFreshInit { - get { - return ResourceManager.GetString("FileCouldNotBeLoadedFreshInit", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} is currently disabled according to your configuration. If you'd like to help SteamDB in data submission, please check out our wiki.. - /// - internal static string PluginDisabledInConfig { - get { - return ResourceManager.GetString("PluginDisabledInConfig", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} has been disabled due to a missing build token. - /// internal static string PluginDisabledMissingBuildToken { get { return ResourceManager.GetString("PluginDisabledMissingBuildToken", resourceCulture); } } - /// - /// Looks up a localized string similar to {0} has been initialized successfully, thank you in advance for your help. The first submission will happen in approximately {1} from now.. - /// + internal static string PluginDisabledInConfig { + get { + return ResourceManager.GetString("PluginDisabledInConfig", resourceCulture); + } + } + internal static string PluginInitializedAndEnabled { get { return ResourceManager.GetString("PluginInitializedAndEnabled", resourceCulture); } } - /// - /// Looks up a localized string similar to {0} initialized, the plugin will not resolve any of those: {1}.. - /// - internal static string PluginSecretListInitialized { + internal static string FileCouldNotBeLoadedFreshInit { get { - return ResourceManager.GetString("PluginSecretListInitialized", resourceCulture); + return ResourceManager.GetString("FileCouldNotBeLoadedFreshInit", resourceCulture); } } - /// - /// Looks up a localized string similar to The submission has failed due to too many requests sent, we'll try again in approximately {0} from now.. - /// - internal static string SubmissionFailedTooManyRequests { + internal static string BotNoAppsToRefresh { get { - return ResourceManager.GetString("SubmissionFailedTooManyRequests", resourceCulture); + return ResourceManager.GetString("BotNoAppsToRefresh", resourceCulture); } } - /// - /// Looks up a localized string similar to Submitting a total of registered apps/packages/depots: {0}/{1}/{2}.... - /// - internal static string SubmissionInProgress { + internal static string BotRetrievingTotalAppAccessTokens { get { - return ResourceManager.GetString("SubmissionInProgress", resourceCulture); + return ResourceManager.GetString("BotRetrievingTotalAppAccessTokens", resourceCulture); } } - /// - /// Looks up a localized string similar to Could not submit the data because there is no valid SteamID set that we could classify as a contributor. Consider setting up {0} property.. - /// - internal static string SubmissionNoContributorSet { + internal static string BotRetrievingAppAccessTokens { get { - return ResourceManager.GetString("SubmissionNoContributorSet", resourceCulture); + return ResourceManager.GetString("BotRetrievingAppAccessTokens", resourceCulture); + } + } + + internal static string BotFinishedRetrievingAppAccessTokens { + get { + return ResourceManager.GetString("BotFinishedRetrievingAppAccessTokens", resourceCulture); + } + } + + internal static string BotFinishedRetrievingTotalAppAccessTokens { + get { + return ResourceManager.GetString("BotFinishedRetrievingTotalAppAccessTokens", resourceCulture); + } + } + + internal static string BotRetrievingTotalDepots { + get { + return ResourceManager.GetString("BotRetrievingTotalDepots", resourceCulture); + } + } + + internal static string BotRetrievingAppInfos { + get { + return ResourceManager.GetString("BotRetrievingAppInfos", resourceCulture); + } + } + + internal static string BotFinishedRetrievingAppInfos { + get { + return ResourceManager.GetString("BotFinishedRetrievingAppInfos", resourceCulture); + } + } + + internal static string BotRetrievingDepotKeys { + get { + return ResourceManager.GetString("BotRetrievingDepotKeys", resourceCulture); + } + } + + internal static string BotFinishedRetrievingDepotKeys { + get { + return ResourceManager.GetString("BotFinishedRetrievingDepotKeys", resourceCulture); + } + } + + internal static string BotFinishedRetrievingTotalDepots { + get { + return ResourceManager.GetString("BotFinishedRetrievingTotalDepots", resourceCulture); } } - /// - /// Looks up a localized string similar to There is no new data to submit, everything is up-to-date.. - /// internal static string SubmissionNoNewData { get { return ResourceManager.GetString("SubmissionNoNewData", resourceCulture); } } - /// - /// Looks up a localized string similar to The data has been successfully submitted. The server has registered a total of new apps/packages/depots: {0} ({1} verified)/{2} ({3} verified)/{4} ({5} verified).. - /// + internal static string SubmissionNoContributorSet { + get { + return ResourceManager.GetString("SubmissionNoContributorSet", resourceCulture); + } + } + + internal static string SubmissionInProgress { + get { + return ResourceManager.GetString("SubmissionInProgress", resourceCulture); + } + } + + internal static string SubmissionFailedTooManyRequests { + get { + return ResourceManager.GetString("SubmissionFailedTooManyRequests", resourceCulture); + } + } + internal static string SubmissionSuccessful { get { return ResourceManager.GetString("SubmissionSuccessful", resourceCulture); } } - /// - /// Looks up a localized string similar to New apps: {0}. - /// internal static string SubmissionSuccessfulNewApps { get { return ResourceManager.GetString("SubmissionSuccessfulNewApps", resourceCulture); } } - /// - /// Looks up a localized string similar to New depots: {0}. - /// - internal static string SubmissionSuccessfulNewDepots { - get { - return ResourceManager.GetString("SubmissionSuccessfulNewDepots", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to New packages: {0}. - /// - internal static string SubmissionSuccessfulNewPackages { - get { - return ResourceManager.GetString("SubmissionSuccessfulNewPackages", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Verified apps: {0}. - /// internal static string SubmissionSuccessfulVerifiedApps { get { return ResourceManager.GetString("SubmissionSuccessfulVerifiedApps", resourceCulture); } } - /// - /// Looks up a localized string similar to Verified depots: {0}. - /// + internal static string SubmissionSuccessfulNewPackages { + get { + return ResourceManager.GetString("SubmissionSuccessfulNewPackages", resourceCulture); + } + } + + internal static string SubmissionSuccessfulVerifiedPackages { + get { + return ResourceManager.GetString("SubmissionSuccessfulVerifiedPackages", resourceCulture); + } + } + + internal static string SubmissionSuccessfulNewDepots { + get { + return ResourceManager.GetString("SubmissionSuccessfulNewDepots", resourceCulture); + } + } + internal static string SubmissionSuccessfulVerifiedDepots { get { return ResourceManager.GetString("SubmissionSuccessfulVerifiedDepots", resourceCulture); } } - /// - /// Looks up a localized string similar to Verified packages: {0}. - /// - internal static string SubmissionSuccessfulVerifiedPackages { + internal static string PluginSecretListInitialized { get { - return ResourceManager.GetString("SubmissionSuccessfulVerifiedPackages", resourceCulture); + return ResourceManager.GetString("PluginSecretListInitialized", resourceCulture); + } + } + + internal static string LoadingGlobalCache { + get { + return ResourceManager.GetString("LoadingGlobalCache", resourceCulture); + } + } + + internal static string ValidatingGlobalCacheIntegrity { + get { + return ResourceManager.GetString("ValidatingGlobalCacheIntegrity", resourceCulture); + } + } + + internal static string GlobalCacheIntegrityValidationFailed { + get { + return ResourceManager.GetString("GlobalCacheIntegrityValidationFailed", resourceCulture); } } } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx index 06d1a4683..64abba4a5 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx @@ -168,4 +168,13 @@ {0} initialized, the plugin will not resolve any of those: {1}. {0} will be replaced by the name of the config property (e.g. "SecretPackageIDs"), {1} will be replaced by list of the objects (IDs, numbers), separated by a comma + + Loading STD global cache... + + + Validating STD global cache integrity... + + + Failed to verify STD global cache integrity. This suggests a potential file/memory corruption, a fresh instance will be initialized instead. +