diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs index 05d39dbc..b31ee0b9 100644 --- a/BurnOutSharp/Utilities.cs +++ b/BurnOutSharp/Utilities.cs @@ -243,11 +243,36 @@ namespace BurnOutSharp #endregion - #region Version Finding + #region Protection + + /// + /// Get simple content matches for a given protection + /// + /// Byte array representing the file contents + /// Mapping of byte array to string for matching + /// True to include positional data, false otherwise + /// String representing the matched protection, null otherwise + public static string GetContentMatches(byte[] fileContent, Dictionary mappings, bool includePosition = false) + { + // If there's no mappings, we can't match + if (mappings == null || !mappings.Any()) + return null; + + // Loop through and try everything otherwise + foreach (var kvp in mappings) + { + if (fileContent.FirstPosition(kvp.Key, out int position)) + return kvp.Value + (includePosition ? $" (Index {position})" : string.Empty); + } + + return null; + } /// /// Get the file version as reported by the filesystem /// + /// File to check for version + /// Version string, null on error public static string GetFileVersion(string file) { if (file == null || !File.Exists(file)) @@ -265,6 +290,8 @@ namespace BurnOutSharp /// /// Get the assembly version as determined by an embedded assembly manifest /// + /// Byte array representing the file contents + /// Version string, null on error /// TODO: How do we find the manifest specifically better? public static string GetManifestVersion(byte[] fileContent) {