diff --git a/BurnOutSharp.Builder/AbstractSyntaxNotationOne.cs b/BurnOutSharp.Builder/AbstractSyntaxNotationOne.cs
index 4db3e93a..8f9e960f 100644
--- a/BurnOutSharp.Builder/AbstractSyntaxNotationOne.cs
+++ b/BurnOutSharp.Builder/AbstractSyntaxNotationOne.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/BFPK.cs b/BurnOutSharp.Builder/BFPK.cs
index 30fccbed..8f6aa46b 100644
--- a/BurnOutSharp.Builder/BFPK.cs
+++ b/BurnOutSharp.Builder/BFPK.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Linq;
using BurnOutSharp.Models.BFPK;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/BurnOutSharp.Builder.csproj b/BurnOutSharp.Builder/BurnOutSharp.Builder.csproj
index 775c3c9b..a7ec458a 100644
--- a/BurnOutSharp.Builder/BurnOutSharp.Builder.csproj
+++ b/BurnOutSharp.Builder/BurnOutSharp.Builder.csproj
@@ -21,6 +21,7 @@
+
diff --git a/BurnOutSharp.Builder/Extensions.cs b/BurnOutSharp.Builder/Extensions.cs
index d156b4e6..21b5d8fb 100644
--- a/BurnOutSharp.Builder/Extensions.cs
+++ b/BurnOutSharp.Builder/Extensions.cs
@@ -4,294 +4,12 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
public static class Extensions
{
- #region Byte Arrays
-
- ///
- /// Read a byte and increment the pointer to an array
- ///
- public static byte ReadByte(this byte[] content, ref int offset)
- {
- return content[offset++];
- }
-
- ///
- /// Read a byte array and increment the pointer to an array
- ///
- public static byte[] ReadBytes(this byte[] content, ref int offset, int count)
- {
- // If there's an invalid byte count, don't do anything
- if (count <= 0)
- return null;
-
- byte[] buffer = new byte[count];
- Array.Copy(content, offset, buffer, 0, Math.Min(count, content.Length - offset));
- offset += count;
- return buffer;
- }
-
- ///
- /// Read a char and increment the pointer to an array
- ///
- public static char ReadChar(this byte[] content, ref int offset)
- {
- return (char)content[offset++];
- }
-
- ///
- /// Read a character array and increment the pointer to an array
- ///
- public static char[] ReadChars(this byte[] content, ref int offset, int count) => content.ReadChars(ref offset, count, Encoding.Default);
-
- ///
- /// Read a character array and increment the pointer to an array
- ///
- public static char[] ReadChars(this byte[] content, ref int offset, int count, Encoding encoding)
- {
- // TODO: Fix the code below to make it work with byte arrays and not streams
- return null;
-
- // byte[] buffer = new byte[count];
- // stream.Read(buffer, 0, count);
- // return encoding.GetString(buffer).ToCharArray();
- }
-
- ///
- /// Read a short and increment the pointer to an array
- ///
- public static short ReadInt16(this byte[] content, ref int offset)
- {
- short value = BitConverter.ToInt16(content, offset);
- offset += 2;
- return value;
- }
-
- ///
- /// Read a ushort and increment the pointer to an array
- ///
- public static ushort ReadUInt16(this byte[] content, ref int offset)
- {
- ushort value = BitConverter.ToUInt16(content, offset);
- offset += 2;
- return value;
- }
-
- ///
- /// Read a int and increment the pointer to an array
- ///
- public static int ReadInt32(this byte[] content, ref int offset)
- {
- int value = BitConverter.ToInt32(content, offset);
- offset += 4;
- return value;
- }
-
- ///
- /// Read a uint and increment the pointer to an array
- ///
- public static uint ReadUInt32(this byte[] content, ref int offset)
- {
- uint value = BitConverter.ToUInt32(content, offset);
- offset += 4;
- return value;
- }
-
- ///
- /// Read a long and increment the pointer to an array
- ///
- public static long ReadInt64(this byte[] content, ref int offset)
- {
- long value = BitConverter.ToInt64(content, offset);
- offset += 8;
- return value;
- }
-
- ///
- /// Read a ulong and increment the pointer to an array
- ///
- public static ulong ReadUInt64(this byte[] content, ref int offset)
- {
- ulong value = BitConverter.ToUInt64(content, offset);
- offset += 8;
- return value;
- }
-
- ///
- /// Read a null-terminated string from the stream
- ///
- public static string ReadString(this byte[] content, ref int offset) => content.ReadString(ref offset, Encoding.Default);
-
- ///
- /// Read a null-terminated string from the stream
- ///
- public static string ReadString(this byte[] content, ref int offset, Encoding encoding)
- {
- if (offset >= content.Length)
- return null;
-
- byte[] nullTerminator = encoding.GetBytes(new char[] { '\0' });
- int charWidth = nullTerminator.Length;
-
- List keyChars = new List();
- while (offset < content.Length)
- {
- char c = encoding.GetChars(content, offset, charWidth)[0];
- keyChars.Add(c);
- offset += charWidth;
-
- if (c == '\0')
- break;
- }
-
- return new string(keyChars.ToArray()).TrimEnd('\0');
- }
-
- #endregion
-
- #region Streams
-
- ///
- /// Read a byte from the stream
- ///
- public static byte ReadByteValue(this Stream stream)
- {
- byte[] buffer = new byte[1];
- stream.Read(buffer, 0, 1);
- return buffer[0];
- }
-
- ///
- /// Read a byte array from the stream
- ///
- public static byte[] ReadBytes(this Stream stream, int count)
- {
- // If there's an invalid byte count, don't do anything
- if (count <= 0)
- return null;
-
- byte[] buffer = new byte[count];
- stream.Read(buffer, 0, count);
- return buffer;
- }
-
- ///
- /// Read a character from the stream
- ///
- public static char ReadChar(this Stream stream)
- {
- byte[] buffer = new byte[1];
- stream.Read(buffer, 0, 1);
- return (char)buffer[0];
- }
-
- ///
- /// Read a character array from the stream
- ///
- public static char[] ReadChars(this Stream stream, int count) => stream.ReadChars(count, Encoding.Default);
-
- ///
- /// Read a character array from the stream
- ///
- public static char[] ReadChars(this Stream stream, int count, Encoding encoding)
- {
- byte[] buffer = new byte[count];
- stream.Read(buffer, 0, count);
- return encoding.GetString(buffer).ToCharArray();
- }
-
- ///
- /// Read a short from the stream
- ///
- public static short ReadInt16(this Stream stream)
- {
- byte[] buffer = new byte[2];
- stream.Read(buffer, 0, 2);
- return BitConverter.ToInt16(buffer, 0);
- }
-
- ///
- /// Read a ushort from the stream
- ///
- public static ushort ReadUInt16(this Stream stream)
- {
- byte[] buffer = new byte[2];
- stream.Read(buffer, 0, 2);
- return BitConverter.ToUInt16(buffer, 0);
- }
-
- ///
- /// Read an int from the stream
- ///
- public static int ReadInt32(this Stream stream)
- {
- byte[] buffer = new byte[4];
- stream.Read(buffer, 0, 4);
- return BitConverter.ToInt32(buffer, 0);
- }
-
- ///
- /// Read a uint from the stream
- ///
- public static uint ReadUInt32(this Stream stream)
- {
- byte[] buffer = new byte[4];
- stream.Read(buffer, 0, 4);
- return BitConverter.ToUInt32(buffer, 0);
- }
-
- ///
- /// Read a long from the stream
- ///
- public static long ReadInt64(this Stream stream)
- {
- byte[] buffer = new byte[8];
- stream.Read(buffer, 0, 8);
- return BitConverter.ToInt64(buffer, 0);
- }
-
- ///
- /// Read a ulong from the stream
- ///
- public static ulong ReadUInt64(this Stream stream)
- {
- byte[] buffer = new byte[8];
- stream.Read(buffer, 0, 8);
- return BitConverter.ToUInt64(buffer, 0);
- }
-
- ///
- /// Read a null-terminated string from the stream
- ///
- public static string ReadString(this Stream stream) => stream.ReadString(Encoding.Default);
-
- ///
- /// Read a null-terminated string from the stream
- ///
- public static string ReadString(this Stream stream, Encoding encoding)
- {
- if (stream.Position >= stream.Length)
- return null;
-
- byte[] nullTerminator = encoding.GetBytes(new char[] { '\0' });
- int charWidth = nullTerminator.Length;
-
- List tempBuffer = new List();
-
- byte[] buffer = new byte[charWidth];
- while (stream.Position < stream.Length && stream.Read(buffer, 0, charWidth) != 0 && !buffer.SequenceEqual(nullTerminator))
- {
- tempBuffer.AddRange(buffer);
- }
-
- return encoding.GetString(tempBuffer.ToArray());
- }
-
- #endregion
-
#region New Executable
///
diff --git a/BurnOutSharp.Builder/MSDOS.cs b/BurnOutSharp.Builder/MSDOS.cs
index b50d1344..8c7c46ed 100644
--- a/BurnOutSharp.Builder/MSDOS.cs
+++ b/BurnOutSharp.Builder/MSDOS.cs
@@ -1,5 +1,6 @@
using System.IO;
using BurnOutSharp.Models.MSDOS;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/MicrosoftCabinet.cs b/BurnOutSharp.Builder/MicrosoftCabinet.cs
index 974f9c25..42ac0f0c 100644
--- a/BurnOutSharp.Builder/MicrosoftCabinet.cs
+++ b/BurnOutSharp.Builder/MicrosoftCabinet.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Text;
using BurnOutSharp.Models.MicrosoftCabinet;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/MoPaQ.cs b/BurnOutSharp.Builder/MoPaQ.cs
index 943fd8ef..bcdb2645 100644
--- a/BurnOutSharp.Builder/MoPaQ.cs
+++ b/BurnOutSharp.Builder/MoPaQ.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using BurnOutSharp.Models.MoPaQ;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/NewExecutable.cs b/BurnOutSharp.Builder/NewExecutable.cs
index 74f7fef7..ae1a6ea2 100644
--- a/BurnOutSharp.Builder/NewExecutable.cs
+++ b/BurnOutSharp.Builder/NewExecutable.cs
@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using BurnOutSharp.Models.NewExecutable;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Builder/PortableExecutable.cs b/BurnOutSharp.Builder/PortableExecutable.cs
index 6da26a85..6a82309c 100644
--- a/BurnOutSharp.Builder/PortableExecutable.cs
+++ b/BurnOutSharp.Builder/PortableExecutable.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text;
using BurnOutSharp.Models.PortableExecutable;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Builder
{
diff --git a/BurnOutSharp.Matching/Extensions.cs b/BurnOutSharp.Matching/Extensions.cs
new file mode 100644
index 00000000..7a3f8511
--- /dev/null
+++ b/BurnOutSharp.Matching/Extensions.cs
@@ -0,0 +1,80 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace BurnOutSharp.Matching
+{
+ public static class Extensions
+ {
+ ///
+ /// Find all positions of one array in another, if possible, if possible
+ ///
+ public static List FindAllPositions(this byte[] stack, byte?[] needle, int start = 0, int end = -1)
+ {
+ // Get the outgoing list
+ List positions = new List();
+
+ // Initialize the loop variables
+ bool found = true;
+ int lastPosition = start;
+ var matcher = new ContentMatch(needle, end: end);
+
+ // Loop over and get all positions
+ while (found)
+ {
+ matcher.Start = lastPosition;
+ (found, lastPosition) = matcher.Match(stack, false);
+ if (found)
+ positions.Add(lastPosition);
+ }
+
+ return positions;
+ }
+
+ ///
+ /// Find the first position of one array in another, if possible
+ ///
+ public static bool FirstPosition(this byte[] stack, byte[] needle, out int position, int start = 0, int end = -1)
+ {
+ byte?[] nullableNeedle = needle != null ? needle.Select(b => (byte?)b).ToArray() : null;
+ return stack.FirstPosition(nullableNeedle, out position, start, end);
+ }
+
+ ///
+ /// Find the first position of one array in another, if possible
+ ///
+ public static bool FirstPosition(this byte[] stack, byte?[] needle, out int position, int start = 0, int end = -1)
+ {
+ var matcher = new ContentMatch(needle, start, end);
+ (bool found, int foundPosition) = matcher.Match(stack, false);
+ position = foundPosition;
+ return found;
+ }
+
+ ///
+ /// Find the last position of one array in another, if possible
+ ///
+ public static bool LastPosition(this byte[] stack, byte?[] needle, out int position, int start = 0, int end = -1)
+ {
+ var matcher = new ContentMatch(needle, start, end);
+ (bool found, int foundPosition) = matcher.Match(stack, true);
+ position = foundPosition;
+ return found;
+ }
+
+ ///
+ /// See if a byte array starts with another
+ ///
+ public static bool StartsWith(this byte[] stack, byte?[] needle)
+ {
+ return stack.FirstPosition(needle, out int _, start: 0, end: 1);
+ }
+
+ ///
+ /// See if a byte array ends with another
+ ///
+ public static bool EndsWith(this byte[] stack, byte?[] needle)
+ {
+ return stack.FirstPosition(needle, out int _, start: stack.Length - needle.Length);
+ }
+ }
+}
\ No newline at end of file
diff --git a/BurnOutSharp.Utilities/BurnOutSharp.Utilities.csproj b/BurnOutSharp.Utilities/BurnOutSharp.Utilities.csproj
new file mode 100644
index 00000000..37a76b27
--- /dev/null
+++ b/BurnOutSharp.Utilities/BurnOutSharp.Utilities.csproj
@@ -0,0 +1,22 @@
+
+
+
+ netstandard2.0;net6.0
+ BurnOutSharp.Utilities
+ BurnOutSharp.Utilities
+ Matt Nadareski
+ BurnOutSharp
+ Copyright (c)2022 Matt Nadareski
+ https://github.com/mnadareski/BurnOutSharp
+ 2.5
+ 2.5
+ 2.5
+ true
+ true
+
+
+
+ true
+
+
+
diff --git a/BurnOutSharp.Utilities/Dictionary.cs b/BurnOutSharp.Utilities/Dictionary.cs
new file mode 100644
index 00000000..31fd98b9
--- /dev/null
+++ b/BurnOutSharp.Utilities/Dictionary.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Concurrent;
+using System.IO;
+using System.Linq;
+
+namespace BurnOutSharp.Utilities
+{
+ ///
+ /// Dictionary manipulation methods
+ ///
+ public static class Dictionary
+ {
+ ///
+ /// Append one result to a results dictionary
+ ///
+ /// Dictionary to append to
+ /// Key to add information to
+ /// String value to add
+ public static void AppendToDictionary(ConcurrentDictionary> original, string key, string value)
+ {
+ // If the value is empty, don't add it
+ if (string.IsNullOrWhiteSpace(value))
+ return;
+
+ var values = new ConcurrentQueue();
+ values.Enqueue(value);
+ AppendToDictionary(original, key, values);
+ }
+
+ ///
+ /// Append one result to a results dictionary
+ ///
+ /// Dictionary to append to
+ /// Key to add information to
+ /// String value to add
+ public static void AppendToDictionary(ConcurrentDictionary> original, string key, ConcurrentQueue values)
+ {
+ // If the dictionary is null, just return
+ if (original == null)
+ return;
+
+ // Use a placeholder value if the key is null
+ key = key ?? "NO FILENAME";
+
+ // Add the key if needed and then append the lists
+ original.TryAdd(key, new ConcurrentQueue());
+ original[key].AddRange(values);
+ }
+
+ ///
+ /// Append one results dictionary to another
+ ///
+ /// Dictionary to append to
+ /// Dictionary to pull from
+ public static void AppendToDictionary(ConcurrentDictionary> original, ConcurrentDictionary> addition)
+ {
+ // If either dictionary is missing, just return
+ if (original == null || addition == null)
+ return;
+
+ // Loop through each of the addition keys and add accordingly
+ foreach (string key in addition.Keys)
+ {
+ original.TryAdd(key, new ConcurrentQueue());
+ original[key].AddRange(addition[key]);
+ }
+ }
+
+ ///
+ /// Remove empty or null keys from a results dictionary
+ ///
+ /// Dictionary to clean
+ public static void ClearEmptyKeys(ConcurrentDictionary> original)
+ {
+ // If the dictionary is missing, we can't do anything
+ if (original == null)
+ return;
+
+ // Get a list of all of the keys
+ var keys = original.Keys.ToList();
+
+ // Iterate and reset keys
+ for (int i = 0; i < keys.Count; i++)
+ {
+ // Get the current key
+ string key = keys[i];
+
+ // If the key is empty, remove it
+ if (original[key] == null || !original[key].Any())
+ original.TryRemove(key, out _);
+ }
+ }
+
+ ///
+ /// Prepend a parent path from dictionary keys, if possible
+ ///
+ /// Dictionary to strip values from
+ /// Path to strip from the keys
+ public static void PrependToKeys(ConcurrentDictionary> original, string pathToPrepend)
+ {
+ // If the dictionary is missing, we can't do anything
+ if (original == null)
+ return;
+
+ // Use a placeholder value if the path is null
+ pathToPrepend = (pathToPrepend ?? "ARCHIVE").TrimEnd(Path.DirectorySeparatorChar);
+
+ // Get a list of all of the keys
+ var keys = original.Keys.ToList();
+
+ // Iterate and reset keys
+ for (int i = 0; i < keys.Count; i++)
+ {
+ // Get the current key
+ string currentKey = keys[i];
+
+ // Otherwise, get the new key name and transfer over
+ string newKey = $"{pathToPrepend}{Path.DirectorySeparatorChar}{currentKey.Trim(Path.DirectorySeparatorChar)}";
+ original[newKey] = original[currentKey];
+ original.TryRemove(currentKey, out _);
+ }
+ }
+
+ ///
+ /// Strip a parent path from dictionary keys, if possible
+ ///
+ /// Dictionary to strip values from
+ /// Path to strip from the keys
+ public static void StripFromKeys(ConcurrentDictionary> original, string pathToStrip)
+ {
+ // If either is missing, we can't do anything
+ if (original == null || string.IsNullOrEmpty(pathToStrip))
+ return;
+
+ // Get a list of all of the keys
+ var keys = original.Keys.ToList();
+
+ // Iterate and reset keys
+ for (int i = 0; i < keys.Count; i++)
+ {
+ // Get the current key
+ string currentKey = keys[i];
+
+ // If the key doesn't start with the path, don't touch it
+ if (!currentKey.StartsWith(pathToStrip, StringComparison.OrdinalIgnoreCase))
+ continue;
+
+ // Otherwise, get the new key name and transfer over
+ string newKey = currentKey.Substring(pathToStrip.Length);
+ original[newKey] = original[currentKey];
+ original.TryRemove(currentKey, out _);
+ }
+ }
+ }
+}
diff --git a/BurnOutSharp/Tools/Extensions.cs b/BurnOutSharp.Utilities/Extensions.cs
similarity index 64%
rename from BurnOutSharp/Tools/Extensions.cs
rename to BurnOutSharp.Utilities/Extensions.cs
index 3cf34b53..fd44a235 100644
--- a/BurnOutSharp/Tools/Extensions.cs
+++ b/BurnOutSharp.Utilities/Extensions.cs
@@ -1,15 +1,35 @@
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
-using BurnOutSharp.Matching;
-namespace BurnOutSharp.Tools
+namespace BurnOutSharp.Utilities
{
- internal static class Extensions
+ public static class Extensions
{
- #region Byte Arrays
+ #region ConcurrentQueue
+
+ ///
+ /// Add a range of values from one queue to another
+ ///
+ /// Queue to add data to
+ /// Queue to get data from
+ public static void AddRange(this ConcurrentQueue original, ConcurrentQueue values)
+ {
+ while (!values.IsEmpty)
+ {
+ if (!values.TryDequeue(out string value))
+ return;
+
+ original.Enqueue(value);
+ }
+ }
+
+ #endregion
+
+ #region Byte Array Reading
///
/// Read a byte and increment the pointer to an array
@@ -24,12 +44,24 @@ namespace BurnOutSharp.Tools
///
public static byte[] ReadBytes(this byte[] content, ref int offset, int count)
{
+ // If there's an invalid byte count, don't do anything
+ if (count <= 0)
+ return null;
+
byte[] buffer = new byte[count];
Array.Copy(content, offset, buffer, 0, Math.Min(count, content.Length - offset));
offset += count;
return buffer;
}
+ ///
+ /// Read an sbyte and increment the pointer to an array
+ ///
+ public static sbyte ReadSByte(this byte[] content, ref int offset)
+ {
+ return (sbyte)content[offset++];
+ }
+
///
/// Read a char and increment the pointer to an array
///
@@ -38,24 +70,6 @@ namespace BurnOutSharp.Tools
return (char)content[offset++];
}
- ///
- /// Read a character array and increment the pointer to an array
- ///
- public static char[] ReadChars(this byte[] content, ref int offset, int count) => content.ReadChars(ref offset, count, Encoding.Default);
-
- ///
- /// Read a character array and increment the pointer to an array
- ///
- public static char[] ReadChars(this byte[] content, ref int offset, int count, Encoding encoding)
- {
- // TODO: Fix the code below to make it work with byte arrays and not streams
- return null;
-
- // byte[] buffer = new byte[count];
- // stream.Read(buffer, 0, count);
- // return encoding.GetString(buffer).ToCharArray();
- }
-
///
/// Read a short and increment the pointer to an array
///
@@ -146,81 +160,9 @@ namespace BurnOutSharp.Tools
return new string(keyChars.ToArray()).TrimEnd('\0');
}
- ///
- /// Find all positions of one array in another, if possible, if possible
- ///
- public static List FindAllPositions(this byte[] stack, byte?[] needle, int start = 0, int end = -1)
- {
- // Get the outgoing list
- List positions = new List();
-
- // Initialize the loop variables
- bool found = true;
- int lastPosition = start;
- var matcher = new ContentMatch(needle, end: end);
-
- // Loop over and get all positions
- while (found)
- {
- matcher.Start = lastPosition;
- (found, lastPosition) = matcher.Match(stack, false);
- if (found)
- positions.Add(lastPosition);
- }
-
- return positions;
- }
-
- ///
- /// Find the first position of one array in another, if possible
- ///
- public static bool FirstPosition(this byte[] stack, byte[] needle, out int position, int start = 0, int end = -1)
- {
- byte?[] nullableNeedle = needle != null ? needle.Select(b => (byte?)b).ToArray() : null;
- return stack.FirstPosition(nullableNeedle, out position, start, end);
- }
-
- ///
- /// Find the first position of one array in another, if possible
- ///
- public static bool FirstPosition(this byte[] stack, byte?[] needle, out int position, int start = 0, int end = -1)
- {
- var matcher = new ContentMatch(needle, start, end);
- (bool found, int foundPosition) = matcher.Match(stack, false);
- position = foundPosition;
- return found;
- }
-
- ///
- /// Find the last position of one array in another, if possible
- ///
- public static bool LastPosition(this byte[] stack, byte?[] needle, out int position, int start = 0, int end = -1)
- {
- var matcher = new ContentMatch(needle, start, end);
- (bool found, int foundPosition) = matcher.Match(stack, true);
- position = foundPosition;
- return found;
- }
-
- ///
- /// See if a byte array starts with another
- ///
- public static bool StartsWith(this byte[] stack, byte?[] needle)
- {
- return stack.FirstPosition(needle, out int _, start: 0, end: 1);
- }
-
- ///
- /// See if a byte array ends with another
- ///
- public static bool EndsWith(this byte[] stack, byte?[] needle)
- {
- return stack.FirstPosition(needle, out int _, start: stack.Length - needle.Length);
- }
-
#endregion
- #region Streams
+ #region Stream Reading
///
/// Read a byte from the stream
@@ -237,11 +179,25 @@ namespace BurnOutSharp.Tools
///
public static byte[] ReadBytes(this Stream stream, int count)
{
+ // If there's an invalid byte count, don't do anything
+ if (count <= 0)
+ return null;
+
byte[] buffer = new byte[count];
stream.Read(buffer, 0, count);
return buffer;
}
+ ///
+ /// Read an sbyte from the stream
+ ///
+ public static sbyte ReadSByte(this Stream stream)
+ {
+ byte[] buffer = new byte[1];
+ stream.Read(buffer, 0, 1);
+ return (sbyte)buffer[0];
+ }
+
///
/// Read a character from the stream
///
@@ -252,21 +208,6 @@ namespace BurnOutSharp.Tools
return (char)buffer[0];
}
- ///
- /// Read a character array from the stream
- ///
- public static char[] ReadChars(this Stream stream, int count) => stream.ReadChars(count, Encoding.Default);
-
- ///
- /// Read a character array from the stream
- ///
- public static char[] ReadChars(this Stream stream, int count, Encoding encoding)
- {
- byte[] buffer = new byte[count];
- stream.Read(buffer, 0, count);
- return encoding.GetString(buffer).ToCharArray();
- }
-
///
/// Read a short from the stream
///
@@ -337,13 +278,16 @@ namespace BurnOutSharp.Tools
///
public static string ReadString(this Stream stream, Encoding encoding)
{
+ if (stream.Position >= stream.Length)
+ return null;
+
byte[] nullTerminator = encoding.GetBytes(new char[] { '\0' });
int charWidth = nullTerminator.Length;
List tempBuffer = new List();
byte[] buffer = new byte[charWidth];
- while (stream.Read(buffer, 0, charWidth) != 0 && !buffer.SequenceEqual(nullTerminator))
+ while (stream.Position < stream.Length && stream.Read(buffer, 0, charWidth) != 0 && !buffer.SequenceEqual(nullTerminator))
{
tempBuffer.AddRange(buffer);
}
diff --git a/BurnOutSharp.Utilities/Hashing.cs b/BurnOutSharp.Utilities/Hashing.cs
new file mode 100644
index 00000000..d6ad25c4
--- /dev/null
+++ b/BurnOutSharp.Utilities/Hashing.cs
@@ -0,0 +1,53 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+
+namespace BurnOutSharp.Utilities
+{
+ ///
+ /// Data hashing methods
+ ///
+ public static class Hashing
+ {
+ ///
+ /// Get the SHA1 hash of a file, if possible
+ ///
+ /// Path to the file to be hashed
+ /// SHA1 hash as a string on success, null on error
+ public static string GetFileSHA1(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path))
+ return null;
+
+ try
+ {
+ SHA1 sha1 = SHA1.Create();
+ using (Stream fileStream = File.OpenRead(path))
+ {
+ byte[] buffer = new byte[32768];
+ while (true)
+ {
+ int bytesRead = fileStream.Read(buffer, 0, 32768);
+ if (bytesRead == 32768)
+ {
+ sha1.TransformBlock(buffer, 0, bytesRead, null, 0);
+ }
+ else
+ {
+ sha1.TransformFinalBlock(buffer, 0, bytesRead);
+ break;
+ }
+ }
+ }
+
+ string hash = BitConverter.ToString(sha1.Hash);
+ hash = hash.Replace("-", string.Empty);
+ return hash;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs
index b7263559..52a7541f 100644
--- a/BurnOutSharp.Wrappers/PortableExecutable.cs
+++ b/BurnOutSharp.Wrappers/PortableExecutable.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
+using BurnOutSharp.Utilities;
using static BurnOutSharp.Builder.Extensions;
namespace BurnOutSharp.Wrappers
diff --git a/BurnOutSharp.Wrappers/WrapperBase.cs b/BurnOutSharp.Wrappers/WrapperBase.cs
index d49af4a5..b37225ce 100644
--- a/BurnOutSharp.Wrappers/WrapperBase.cs
+++ b/BurnOutSharp.Wrappers/WrapperBase.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
-using static BurnOutSharp.Builder.Extensions;
+using BurnOutSharp.Utilities;
namespace BurnOutSharp.Wrappers
{
diff --git a/BurnOutSharp.sln b/BurnOutSharp.sln
index f7713a44..de3dd646 100644
--- a/BurnOutSharp.sln
+++ b/BurnOutSharp.sln
@@ -11,8 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
Coding Guide.md = Coding Guide.md
- LICENSE = LICENSE
Developer Guide.md = Developer Guide.md
+ LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnOutSharp.Matching", "Bu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "psxt001z", "psxt001z\psxt001z.csproj", "{D9574B47-0D6B-445A-97BF-272B5EF9AD3F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BurnOutSharp.Utilities", "BurnOutSharp.Utilities\BurnOutSharp.Utilities.csproj", "{3C1D1FE2-7E7C-4EC1-96B1-FE68B73282CD}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -84,6 +86,10 @@ Global
{D9574B47-0D6B-445A-97BF-272B5EF9AD3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9574B47-0D6B-445A-97BF-272B5EF9AD3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9574B47-0D6B-445A-97BF-272B5EF9AD3F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3C1D1FE2-7E7C-4EC1-96B1-FE68B73282CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3C1D1FE2-7E7C-4EC1-96B1-FE68B73282CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3C1D1FE2-7E7C-4EC1-96B1-FE68B73282CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3C1D1FE2-7E7C-4EC1-96B1-FE68B73282CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BurnOutSharp/BurnOutSharp.csproj b/BurnOutSharp/BurnOutSharp.csproj
index 4f70de2e..fce5bae6 100644
--- a/BurnOutSharp/BurnOutSharp.csproj
+++ b/BurnOutSharp/BurnOutSharp.csproj
@@ -65,6 +65,10 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs
index ab6b06c2..45df320c 100644
--- a/BurnOutSharp/FileType/BFPK.cs
+++ b/BurnOutSharp/FileType/BFPK.cs
@@ -1,11 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.IO;
-using System.Linq;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
-using SharpCompress.Compressors;
-using SharpCompress.Compressors.Deflate;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -60,7 +57,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs
index b9fca270..d6ebd8ed 100644
--- a/BurnOutSharp/FileType/BZip2.cs
+++ b/BurnOutSharp/FileType/BZip2.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Compressors;
using SharpCompress.Compressors.BZip2;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -65,7 +65,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs
index 9dae8144..c5e078c9 100644
--- a/BurnOutSharp/FileType/Executable.cs
+++ b/BurnOutSharp/FileType/Executable.cs
@@ -4,8 +4,8 @@ using System.IO;
using System.Text;
using System.Threading.Tasks;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -47,7 +47,7 @@ namespace BurnOutSharp.FileType
{
if (scanner.IncludeDebug) Console.WriteLine(ex);
- Utilities.AppendToDictionary(protections, file, "[Out of memory attempting to open]");
+ AppendToDictionary(protections, file, "[Out of memory attempting to open]");
return protections;
}
}
@@ -66,7 +66,7 @@ namespace BurnOutSharp.FileType
{
string protection = contentCheckClass.CheckContents(file, fileContent, scanner.IncludeDebug);
if (ShouldAddProtection(contentCheckClass, scanner.ScanPackers, protection))
- Utilities.AppendToDictionary(protections, file, protection);
+ AppendToDictionary(protections, file, protection);
// If we have an IScannable implementation
if (contentCheckClass is IScannable scannable)
@@ -74,8 +74,8 @@ namespace BurnOutSharp.FileType
if (file != null && !string.IsNullOrEmpty(protection))
{
var subProtections = scannable.Scan(scanner, null, file);
- Utilities.PrependToKeys(subProtections, file);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, file);
+ AppendToDictionary(protections, subProtections);
}
}
});
@@ -89,7 +89,7 @@ namespace BurnOutSharp.FileType
// Check using custom content checks first
string protection = contentCheckClass.CheckNewExecutable(file, nex, scanner.IncludeDebug);
if (ShouldAddProtection(contentCheckClass, scanner.ScanPackers, protection))
- Utilities.AppendToDictionary(protections, file, protection);
+ AppendToDictionary(protections, file, protection);
// If we have an IScannable implementation
if (contentCheckClass is IScannable scannable)
@@ -97,8 +97,8 @@ namespace BurnOutSharp.FileType
if (file != null && !string.IsNullOrEmpty(protection))
{
var subProtections = scannable.Scan(scanner, null, file);
- Utilities.PrependToKeys(subProtections, file);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, file);
+ AppendToDictionary(protections, subProtections);
}
}
});
@@ -112,7 +112,7 @@ namespace BurnOutSharp.FileType
// Check using custom content checks first
string protection = contentCheckClass.CheckPortableExecutable(file, pex, scanner.IncludeDebug);
if (ShouldAddProtection(contentCheckClass, scanner.ScanPackers, protection))
- Utilities.AppendToDictionary(protections, file, protection);
+ AppendToDictionary(protections, file, protection);
// If we have an IScannable implementation
if (contentCheckClass is IScannable scannable)
@@ -120,8 +120,8 @@ namespace BurnOutSharp.FileType
if (file != null && !string.IsNullOrEmpty(protection))
{
var subProtections = scannable.Scan(scanner, null, file);
- Utilities.PrependToKeys(subProtections, file);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, file);
+ AppendToDictionary(protections, subProtections);
}
}
});
diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs
index c2aa86be..65c29aa6 100644
--- a/BurnOutSharp/FileType/GZIP.cs
+++ b/BurnOutSharp/FileType/GZIP.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Archives;
using SharpCompress.Archives.GZip;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -69,7 +69,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
index 909ee265..638814fa 100644
--- a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
+++ b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
@@ -4,8 +4,8 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using UnshieldSharp.Archive;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -89,7 +89,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs
index c723fcf1..469b74e1 100644
--- a/BurnOutSharp/FileType/InstallShieldCAB.cs
+++ b/BurnOutSharp/FileType/InstallShieldCAB.cs
@@ -3,8 +3,8 @@ using System.Collections.Concurrent;
using System.IO;
using System.Text.RegularExpressions;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using UnshieldSharp.Cabinet;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -88,7 +88,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs
index 61033068..976272da 100644
--- a/BurnOutSharp/FileType/MPQ.cs
+++ b/BurnOutSharp/FileType/MPQ.cs
@@ -2,8 +2,8 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using StormLibSharp;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -84,7 +84,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/MSI.cs b/BurnOutSharp/FileType/MSI.cs
index 52dc5936..b7e1af1f 100644
--- a/BurnOutSharp/FileType/MSI.cs
+++ b/BurnOutSharp/FileType/MSI.cs
@@ -3,8 +3,8 @@ using System.Collections.Concurrent;
using System.IO;
using System.Text;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using OpenMcdf;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -84,7 +84,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.MSZIP.cs b/BurnOutSharp/FileType/MicrosoftCAB.MSZIP.cs
index 55951105..1bd29fb3 100644
--- a/BurnOutSharp/FileType/MicrosoftCAB.MSZIP.cs
+++ b/BurnOutSharp/FileType/MicrosoftCAB.MSZIP.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using BurnOutSharp.Tools;
+using BurnOutSharp.Utilities;
///
///
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs
index a228912d..f2fe638b 100644
--- a/BurnOutSharp/FileType/MicrosoftCAB.cs
+++ b/BurnOutSharp/FileType/MicrosoftCAB.cs
@@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
#if NETSTANDARD2_0
using WixToolset.Dtf.Compression;
using WixToolset.Dtf.Compression.Cab;
@@ -10,6 +9,7 @@ using WixToolset.Dtf.Compression.Cab;
using LibMSPackSharp;
using LibMSPackSharp.CABExtract;
#endif
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -105,7 +105,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
@@ -139,7 +139,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs
index c25c75b1..edc63a8a 100644
--- a/BurnOutSharp/FileType/PKZIP.cs
+++ b/BurnOutSharp/FileType/PKZIP.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -70,7 +70,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/PLJ.cs b/BurnOutSharp/FileType/PLJ.cs
index e4236043..2a3dbd82 100644
--- a/BurnOutSharp/FileType/PLJ.cs
+++ b/BurnOutSharp/FileType/PLJ.cs
@@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -32,9 +32,9 @@ namespace BurnOutSharp.FileType
byte[] magic = new byte[16];
stream.Read(magic, 0, 16);
- if (Utilities.GetFileType(magic) == SupportedFileType.PLJ)
+ if (Tools.Utilities.GetFileType(magic) == SupportedFileType.PLJ)
{
- Utilities.AppendToDictionary(protections, file, "PlayJ Audio File");
+ AppendToDictionary(protections, file, "PlayJ Audio File");
return protections;
}
}
diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs
index f9766613..cffa4145 100644
--- a/BurnOutSharp/FileType/RAR.cs
+++ b/BurnOutSharp/FileType/RAR.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -69,7 +69,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/SFFS.cs b/BurnOutSharp/FileType/SFFS.cs
index d5b39a2d..75313d24 100644
--- a/BurnOutSharp/FileType/SFFS.cs
+++ b/BurnOutSharp/FileType/SFFS.cs
@@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -33,9 +33,9 @@ namespace BurnOutSharp.FileType
byte[] magic = new byte[16];
stream.Read(magic, 0, 16);
- if (Utilities.GetFileType(magic) == SupportedFileType.SFFS)
+ if (Tools.Utilities.GetFileType(magic) == SupportedFileType.SFFS)
{
- Utilities.AppendToDictionary(protections, file, "StarForce Filesystem Container");
+ AppendToDictionary(protections, file, "StarForce Filesystem Container");
return protections;
}
}
diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs
index d7e9d921..b8230c82 100644
--- a/BurnOutSharp/FileType/SevenZip.cs
+++ b/BurnOutSharp/FileType/SevenZip.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Archives;
using SharpCompress.Archives.SevenZip;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -68,7 +68,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs
index 4ba79a73..67582182 100644
--- a/BurnOutSharp/FileType/TapeArchive.cs
+++ b/BurnOutSharp/FileType/TapeArchive.cs
@@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Archives;
using SharpCompress.Archives.Tar;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -69,7 +69,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/Textfile.cs b/BurnOutSharp/FileType/Textfile.cs
index 03e67eaa..c1f97f55 100644
--- a/BurnOutSharp/FileType/Textfile.cs
+++ b/BurnOutSharp/FileType/Textfile.cs
@@ -3,7 +3,7 @@ using System.Collections.Concurrent;
using System.IO;
using System.Text;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -42,57 +42,57 @@ namespace BurnOutSharp.FileType
// AegiSoft License Manager
// Found in "setup.ins" (Redump entry 73521/IA item "Nova_HoyleCasino99USA").
if (fileContent.Contains("Failed to load the AegiSoft License Manager install program."))
- Utilities.AppendToDictionary(protections, file, "AegiSoft License Manager");
+ AppendToDictionary(protections, file, "AegiSoft License Manager");
// CD-Key
if (fileContent.Contains("a valid serial number is required"))
- Utilities.AppendToDictionary(protections, file, "CD-Key / Serial");
+ AppendToDictionary(protections, file, "CD-Key / Serial");
else if (fileContent.Contains("serial number is located"))
- Utilities.AppendToDictionary(protections, file, "CD-Key / Serial");
+ AppendToDictionary(protections, file, "CD-Key / Serial");
// Freelock
// Found in "FILE_ID.DIZ" distributed with Freelock.
if (fileContent.Contains("FREELOCK 1.0"))
- Utilities.AppendToDictionary(protections, file, "Freelock 1.0");
+ AppendToDictionary(protections, file, "Freelock 1.0");
else if (fileContent.Contains("FREELOCK 1.2"))
- Utilities.AppendToDictionary(protections, file, "Freelock 1.2");
+ AppendToDictionary(protections, file, "Freelock 1.2");
else if (fileContent.Contains("FREELOCK 1.2a"))
- Utilities.AppendToDictionary(protections, file, "Freelock 1.2a");
+ AppendToDictionary(protections, file, "Freelock 1.2a");
else if (fileContent.Contains("FREELOCK 1.3"))
- Utilities.AppendToDictionary(protections, file, "Freelock 1.3");
+ AppendToDictionary(protections, file, "Freelock 1.3");
else if (fileContent.Contains("FREELOCK"))
- Utilities.AppendToDictionary(protections, file, "Freelock");
+ AppendToDictionary(protections, file, "Freelock");
// MediaCloQ
if (fileContent.Contains("SunnComm MediaCloQ"))
- Utilities.AppendToDictionary(protections, file, "MediaCloQ");
+ AppendToDictionary(protections, file, "MediaCloQ");
else if (fileContent.Contains("http://download.mediacloq.com/"))
- Utilities.AppendToDictionary(protections, file, "MediaCloQ");
+ AppendToDictionary(protections, file, "MediaCloQ");
else if (fileContent.Contains("http://www.sunncomm.com/mediacloq/"))
- Utilities.AppendToDictionary(protections, file, "MediaCloQ");
+ AppendToDictionary(protections, file, "MediaCloQ");
// MediaMax
if (fileContent.Contains("MediaMax technology"))
- Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
+ AppendToDictionary(protections, file, "MediaMax CD-3");
else if (fileContent.Contains("exclusive Cd3 technology"))
- Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
+ AppendToDictionary(protections, file, "MediaMax CD-3");
else if (fileContent.Contains("MediaMAX"))
- Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
+ AppendToDictionary(protections, file, "MediaMax CD-3");
else if (fileContent.Contains("MediaMax(tm)"))
- Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
+ AppendToDictionary(protections, file, "MediaMax CD-3");
// phenoProtect
if (fileContent.Contains("phenoProtect"))
- Utilities.AppendToDictionary(protections, file, "phenoProtect");
+ AppendToDictionary(protections, file, "phenoProtect");
// Rainbow Sentinel
// Found in "SENTW95.HLP" and "SENTINEL.HLP" in BA entry "Autodesk AutoCAD LT 98 (1998) (CD) [English] [Dutch]".
if (fileContent.Contains("Rainbow Sentinel Driver Help"))
- Utilities.AppendToDictionary(protections, file, "Rainbow Sentinel");
+ AppendToDictionary(protections, file, "Rainbow Sentinel");
// Found in "OEMSETUP.INF" in BA entry "Autodesk AutoCAD LT 98 (1998) (CD) [English] [Dutch]".
if (fileContent.Contains("Sentinel Driver Disk"))
- Utilities.AppendToDictionary(protections, file, "Rainbow Sentinel");
+ AppendToDictionary(protections, file, "Rainbow Sentinel");
// The full line from a sample is as follows:
//
@@ -102,15 +102,15 @@ namespace BurnOutSharp.FileType
// SecuROM
if (fileContent.Contains("SecuROM protected application"))
- Utilities.AppendToDictionary(protections, file, "SecuROM");
+ AppendToDictionary(protections, file, "SecuROM");
// Steam
if (fileContent.Contains("All use of the Program is governed by the terms of the Steam Agreement as described below."))
- Utilities.AppendToDictionary(protections, file, "Steam");
+ AppendToDictionary(protections, file, "Steam");
// XCP
if (fileContent.Contains("http://cp.sonybmg.com/xcp/"))
- Utilities.AppendToDictionary(protections, file, "XCP");
+ AppendToDictionary(protections, file, "XCP");
}
catch (Exception ex)
{
diff --git a/BurnOutSharp/FileType/Valve.cs b/BurnOutSharp/FileType/Valve.cs
index fba83142..81317a2d 100644
--- a/BurnOutSharp/FileType/Valve.cs
+++ b/BurnOutSharp/FileType/Valve.cs
@@ -2,9 +2,10 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
+using BurnOutSharp.Utilities;
using HLLib.Directory;
using HLLib.Packages;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -71,7 +72,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs
index df44620d..05ee84fb 100644
--- a/BurnOutSharp/FileType/XZ.cs
+++ b/BurnOutSharp/FileType/XZ.cs
@@ -2,8 +2,8 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using SharpCompress.Compressors.Xz;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
@@ -64,7 +64,7 @@ namespace BurnOutSharp.FileType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs b/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
index 2d8aa596..b51a2d19 100644
--- a/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
+++ b/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
@@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.PackerType
@@ -61,7 +60,7 @@ namespace BurnOutSharp.PackerType
return version;
// Check the internal versions
- version = Utilities.GetInternalVersion(pex);
+ version = Tools.Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
diff --git a/BurnOutSharp/PackerType/InstallAnywhere.cs b/BurnOutSharp/PackerType/InstallAnywhere.cs
index e79878bf..9ef1b717 100644
--- a/BurnOutSharp/PackerType/InstallAnywhere.cs
+++ b/BurnOutSharp/PackerType/InstallAnywhere.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.PackerType
@@ -51,7 +50,7 @@ namespace BurnOutSharp.PackerType
private string GetVersion(PortableExecutable pex)
{
// Check the internal versions
- string version = Utilities.GetInternalVersion(pex);
+ string version = Tools.Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
diff --git a/BurnOutSharp/PackerType/IntelInstallationFramework.cs b/BurnOutSharp/PackerType/IntelInstallationFramework.cs
index 30106cc7..9452800e 100644
--- a/BurnOutSharp/PackerType/IntelInstallationFramework.cs
+++ b/BurnOutSharp/PackerType/IntelInstallationFramework.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.PackerType
@@ -22,14 +21,14 @@ namespace BurnOutSharp.PackerType
if (name?.Equals("Intel(R) Installation Framework", StringComparison.OrdinalIgnoreCase) == true
|| name?.Equals("Intel Installation Framework", StringComparison.OrdinalIgnoreCase) == true)
{
- return $"Intel Installation Framework {Utilities.GetInternalVersion(pex)}";
+ return $"Intel Installation Framework {Tools.Utilities.GetInternalVersion(pex)}";
}
name = pex.ProductName;
if (name?.Equals("Intel(R) Installation Framework", StringComparison.OrdinalIgnoreCase) == true
|| name?.Equals("Intel Installation Framework", StringComparison.OrdinalIgnoreCase) == true)
{
- return $"Intel Installation Framework {Utilities.GetInternalVersion(pex)}";
+ return $"Intel Installation Framework {Tools.Utilities.GetInternalVersion(pex)}";
}
return null;
diff --git a/BurnOutSharp/PackerType/MicrosoftCABSFX.cs b/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
index 603c2c6f..9e40d23f 100644
--- a/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
+++ b/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.PackerType
@@ -71,7 +70,7 @@ namespace BurnOutSharp.PackerType
private string GetVersion(PortableExecutable pex)
{
// Check the internal versions
- string version = Utilities.GetInternalVersion(pex);
+ string version = Tools.Utilities.GetInternalVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return $"v{version}";
diff --git a/BurnOutSharp/PackerType/SetupFactory.cs b/BurnOutSharp/PackerType/SetupFactory.cs
index f5f901a2..caf3bba4 100644
--- a/BurnOutSharp/PackerType/SetupFactory.cs
+++ b/BurnOutSharp/PackerType/SetupFactory.cs
@@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.PackerType
@@ -66,7 +65,7 @@ namespace BurnOutSharp.PackerType
return version;
// Check the internal versions
- version = Utilities.GetInternalVersion(pex);
+ version = Tools.Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
diff --git a/BurnOutSharp/PackerType/WinRARSFX.cs b/BurnOutSharp/PackerType/WinRARSFX.cs
index f4b9adad..f1658c0c 100644
--- a/BurnOutSharp/PackerType/WinRARSFX.cs
+++ b/BurnOutSharp/PackerType/WinRARSFX.cs
@@ -3,10 +3,10 @@ using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.PackerType
{
@@ -87,7 +87,7 @@ namespace BurnOutSharp.PackerType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/PackerType/WinZipSFX.cs b/BurnOutSharp/PackerType/WinZipSFX.cs
index 291dffc0..143b0ce4 100644
--- a/BurnOutSharp/PackerType/WinZipSFX.cs
+++ b/BurnOutSharp/PackerType/WinZipSFX.cs
@@ -4,10 +4,10 @@ using System.IO;
using System.Linq;
using System.Text;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.PackerType
{
@@ -123,7 +123,7 @@ namespace BurnOutSharp.PackerType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/PackerType/WiseInstaller.cs b/BurnOutSharp/PackerType/WiseInstaller.cs
index be72d32c..1a51686d 100644
--- a/BurnOutSharp/PackerType/WiseInstaller.cs
+++ b/BurnOutSharp/PackerType/WiseInstaller.cs
@@ -5,9 +5,9 @@ using System.IO;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
using Wise = WiseUnpacker.WiseUnpacker;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.PackerType
{
@@ -104,7 +104,7 @@ namespace BurnOutSharp.PackerType
}
// Remove temporary path references
- Utilities.StripFromKeys(protections, tempPath);
+ StripFromKeys(protections, tempPath);
return protections;
}
diff --git a/BurnOutSharp/ProtectionType/ElectronicArts.cs b/BurnOutSharp/ProtectionType/ElectronicArts.cs
index 0547829e..f9456a3f 100644
--- a/BurnOutSharp/ProtectionType/ElectronicArts.cs
+++ b/BurnOutSharp/ProtectionType/ElectronicArts.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -19,20 +18,20 @@ namespace BurnOutSharp.ProtectionType
string name = pex.FileDescription;
if (name?.Contains("EReg MFC Application") == true)
- return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
+ return $"EA CdKey Registration Module {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.Contains("Registration code installer program") == true)
- return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
+ return $"EA CdKey Registration Module {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.Equals("EA DRM Helper", StringComparison.OrdinalIgnoreCase) == true)
- return $"EA DRM Protection {Utilities.GetInternalVersion(pex)}";
+ return $"EA DRM Protection {Tools.Utilities.GetInternalVersion(pex)}";
name = pex.InternalName;
if (name?.Equals("CDCode", StringComparison.Ordinal) == true)
- return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
+ return $"EA CdKey Registration Module {Tools.Utilities.GetInternalVersion(pex)}";
if (pex.FindDialogByTitle("About CDKey").Any())
- return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
+ return $"EA CdKey Registration Module {Tools.Utilities.GetInternalVersion(pex)}";
else if (pex.FindGenericResource("About CDKey").Any())
- return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
+ return $"EA CdKey Registration Module {Tools.Utilities.GetInternalVersion(pex)}";
// Get the .data/DATA section strings, if they exist
List strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
diff --git a/BurnOutSharp/ProtectionType/GFWL.cs b/BurnOutSharp/ProtectionType/GFWL.cs
index 0f818498..59bbea7c 100644
--- a/BurnOutSharp/ProtectionType/GFWL.cs
+++ b/BurnOutSharp/ProtectionType/GFWL.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -21,9 +20,9 @@ namespace BurnOutSharp.ProtectionType
string name = pex.FileDescription;
if (name?.StartsWith("Games for Windows - LIVE Zero Day Piracy Protection", StringComparison.OrdinalIgnoreCase) == true)
- return $"Games for Windows LIVE - Zero Day Piracy Protection Module {Utilities.GetInternalVersion(pex)}";
+ return $"Games for Windows LIVE - Zero Day Piracy Protection Module {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.StartsWith("Games for Windows", StringComparison.OrdinalIgnoreCase) == true)
- return $"Games for Windows LIVE {Utilities.GetInternalVersion(pex)}";
+ return $"Games for Windows LIVE {Tools.Utilities.GetInternalVersion(pex)}";
// Get the import directory table
if (pex.ImportTable?.ImportDirectoryTable != null)
diff --git a/BurnOutSharp/ProtectionType/ImpulseReactor.cs b/BurnOutSharp/ProtectionType/ImpulseReactor.cs
index fc6ba418..f6e61cec 100644
--- a/BurnOutSharp/ProtectionType/ImpulseReactor.cs
+++ b/BurnOutSharp/ProtectionType/ImpulseReactor.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -22,15 +21,15 @@ namespace BurnOutSharp.ProtectionType
string name = pex.FileDescription;
if (name?.Contains("ImpulseReactor Dynamic Link Library") == true)
- return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}";
+ return $"Impulse Reactor Core Module {Tools.Utilities.GetInternalVersion(pex)}";
name = pex.ProductName;
if (name?.Contains("ImpulseReactor Dynamic Link Library") == true)
- return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}";
+ return $"Impulse Reactor Core Module {Tools.Utilities.GetInternalVersion(pex)}";
name = pex.OriginalFilename;
if (name?.Contains("ReactorActivate.exe") == true)
- return $"Stardock Product Activation {Utilities.GetInternalVersion(pex)}";
+ return $"Stardock Product Activation {Tools.Utilities.GetInternalVersion(pex)}";
// TODO: Check for CVP* instead?
bool containsCheck = pex.ExportNameTable?.Any(s => s.StartsWith("CVPInitializeClient")) ?? false;
@@ -46,7 +45,7 @@ namespace BurnOutSharp.ProtectionType
}
if (containsCheck && containsCheck2)
- return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}";
+ return $"Impulse Reactor Core Module {Tools.Utilities.GetInternalVersion(pex)}";
else if (containsCheck && !containsCheck2)
return $"Impulse Reactor";
@@ -58,8 +57,8 @@ namespace BurnOutSharp.ProtectionType
{
var matchers = new List
{
- new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
- new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetInternalVersion, "Stardock Product Activation"),
+ new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Tools.Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
+ new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Tools.Utilities.GetInternalVersion, "Stardock Product Activation"),
};
return MatchUtil.GetAllMatches(files, matchers, any: true);
@@ -70,8 +69,8 @@ namespace BurnOutSharp.ProtectionType
{
var matchers = new List
{
- new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
- new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetInternalVersion, "Stardock Product Activation"),
+ new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Tools.Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
+ new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Tools.Utilities.GetInternalVersion, "Stardock Product Activation"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
diff --git a/BurnOutSharp/ProtectionType/Macrovision.SafeDisc.cs b/BurnOutSharp/ProtectionType/Macrovision.SafeDisc.cs
index 62632573..e4ff44c2 100644
--- a/BurnOutSharp/ProtectionType/Macrovision.SafeDisc.cs
+++ b/BurnOutSharp/ProtectionType/Macrovision.SafeDisc.cs
@@ -4,8 +4,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
+using BurnOutSharp.Utilities;
using BurnOutSharp.Wrappers;
+using static BurnOutSharp.Utilities.Hashing;
namespace BurnOutSharp.ProtectionType
{
@@ -378,7 +379,7 @@ namespace BurnOutSharp.ProtectionType
return string.Empty;
// The hash of the file CLCD16.dll is able to provide a broad version range that appears to be consistent, but it seems it was rarely updated so these checks are quite broad.
- string sha1 = Utilities.GetFileSHA1(firstMatchedString);
+ string sha1 = GetFileSHA1(firstMatchedString);
switch (sha1)
{
// Found in Redump entries 61731 and 66005.
@@ -402,7 +403,7 @@ namespace BurnOutSharp.ProtectionType
return string.Empty;
// The hash of the file CLCD32.dll so far appears to be a solid indicator of version for versions it was used with. It appears to have been updated with every release, unlike it's counterpart, CLCD16.dll.
- string sha1 = Utilities.GetFileSHA1(firstMatchedString);
+ string sha1 = GetFileSHA1(firstMatchedString);
switch (sha1)
{
// Found in Redump entry 66005.
@@ -502,7 +503,7 @@ namespace BurnOutSharp.ProtectionType
// The hash of every "CLOKSPL.EXE" correlates directly to a specific SafeDisc version.
- string sha1 = Utilities.GetFileSHA1(firstMatchedString);
+ string sha1 = GetFileSHA1(firstMatchedString);
switch (sha1)
{
// Found in Redump entry 66005.
@@ -650,7 +651,7 @@ namespace BurnOutSharp.ProtectionType
// There are occasionaly inconsistencies, even within the well detected version range. This seems to me to mostly happen with later (3.20+) games, and seems to me to be an example of the SafeDisc distribution becoming more disorganized with time.
// Particularly interesting inconsistencies will be noted below:
// Redump entry 73786 has an EXE with a scrubbed version, a DIAG.exe with a version of 4.60.000, and a copy of drvmgt.dll belonging to version 3.10.020. This seems like an accidental(?) distribution of older drivers, as this game was released 3 years after the use of 3.10.020.
- string sha1 = Utilities.GetFileSHA1(firstMatchedString);
+ string sha1 = GetFileSHA1(firstMatchedString);
switch (sha1)
{
// Found in Redump entries 29073 and 31149.
diff --git a/BurnOutSharp/ProtectionType/Macrovision.cs b/BurnOutSharp/ProtectionType/Macrovision.cs
index 6fe77315..633bcd9c 100644
--- a/BurnOutSharp/ProtectionType/Macrovision.cs
+++ b/BurnOutSharp/ProtectionType/Macrovision.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
+using BurnOutSharp.Utilities;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
diff --git a/BurnOutSharp/ProtectionType/OnlineRegistration.cs b/BurnOutSharp/ProtectionType/OnlineRegistration.cs
index ca1c7ffb..a7656eb7 100644
--- a/BurnOutSharp/ProtectionType/OnlineRegistration.cs
+++ b/BurnOutSharp/ProtectionType/OnlineRegistration.cs
@@ -1,6 +1,5 @@
using System;
using BurnOutSharp.Interfaces;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -18,7 +17,7 @@ namespace BurnOutSharp.ProtectionType
// TODO: Is this too broad in general?
string name = pex.InternalName;
if (name?.StartsWith("EReg", StringComparison.OrdinalIgnoreCase) == true)
- return $"Executable-Based Online Registration {Utilities.GetInternalVersion(pex)}";
+ return $"Executable-Based Online Registration {Tools.Utilities.GetInternalVersion(pex)}";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/SecuROM.cs b/BurnOutSharp/ProtectionType/SecuROM.cs
index 3f9a0709..7b9d096a 100644
--- a/BurnOutSharp/ProtectionType/SecuROM.cs
+++ b/BurnOutSharp/ProtectionType/SecuROM.cs
@@ -5,7 +5,6 @@ using System.Linq;
using System.Text;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -23,15 +22,15 @@ namespace BurnOutSharp.ProtectionType
string name = pex.FileDescription;
if (name?.Contains("SecuROM PA") == true)
- return $"SecuROM Product Activation v{Utilities.GetInternalVersion(pex)}";
+ return $"SecuROM Product Activation v{Tools.Utilities.GetInternalVersion(pex)}";
name = pex.OriginalFilename;
if (name?.Equals("paul_dll_activate_and_play.dll") == true)
- return $"SecuROM Product Activation v{Utilities.GetInternalVersion(pex)}";
+ return $"SecuROM Product Activation v{Tools.Utilities.GetInternalVersion(pex)}";
name = pex.ProductName;
if (name?.Contains("SecuROM Activate & Play") == true)
- return $"SecuROM Product Activation v{Utilities.GetInternalVersion(pex)}";
+ return $"SecuROM Product Activation v{Tools.Utilities.GetInternalVersion(pex)}";
// Get the matrosch section, if it exists
bool matroschSection = pex.ContainsSection("matrosch", exact: true);
diff --git a/BurnOutSharp/ProtectionType/SolidShield.cs b/BurnOutSharp/ProtectionType/SolidShield.cs
index 0e8b78e1..52debaec 100644
--- a/BurnOutSharp/ProtectionType/SolidShield.cs
+++ b/BurnOutSharp/ProtectionType/SolidShield.cs
@@ -5,7 +5,6 @@ using System.IO;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -26,10 +25,10 @@ namespace BurnOutSharp.ProtectionType
string name = pex.FileDescription;
if (name?.StartsWith("DVM Library", StringComparison.OrdinalIgnoreCase) == true)
- return $"SolidShield {Utilities.GetInternalVersion(pex)}";
+ return $"SolidShield {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.StartsWith("Solidshield Activation Library", StringComparison.OrdinalIgnoreCase) == true)
- return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
+ return $"SolidShield Core.dll {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.StartsWith("Activation Manager", StringComparison.OrdinalIgnoreCase) == true)
return $"SolidShield Activation Manager Module {GetInternalVersion(pex)}";
@@ -40,10 +39,10 @@ namespace BurnOutSharp.ProtectionType
name = pex.ProductName;
if (name?.StartsWith("Solidshield Activation Library", StringComparison.OrdinalIgnoreCase) == true)
- return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
+ return $"SolidShield Core.dll {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.StartsWith("Solidshield Library", StringComparison.OrdinalIgnoreCase) == true)
- return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
+ return $"SolidShield Core.dll {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.StartsWith("Activation Manager", StringComparison.OrdinalIgnoreCase) == true)
return $"SolidShield Activation Manager Module {GetInternalVersion(pex)}";
@@ -195,7 +194,7 @@ namespace BurnOutSharp.ProtectionType
{
string companyName = pex.CompanyName?.ToLowerInvariant();
if (!string.IsNullOrWhiteSpace(companyName) && (companyName.Contains("solidshield") || companyName.Contains("tages")))
- return Utilities.GetInternalVersion(pex);
+ return Tools.Utilities.GetInternalVersion(pex);
return null;
}
diff --git a/BurnOutSharp/ProtectionType/StarForce.cs b/BurnOutSharp/ProtectionType/StarForce.cs
index 1f010036..152081a3 100644
--- a/BurnOutSharp/ProtectionType/StarForce.cs
+++ b/BurnOutSharp/ProtectionType/StarForce.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -28,36 +27,36 @@ namespace BurnOutSharp.ProtectionType
string name = pex.LegalCopyright;
if (name?.StartsWith("(c) Protection Technology") == true) // (c) Protection Technology (StarForce)?
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
else if (name?.Contains("Protection Technology") == true) // Protection Technology (StarForce)?
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// TODO: Decide if internal name checks are safe to use.
name = pex.InternalName;
// Found in "protect.x64" and "protect.x86" in Redump entry 94805.
if (name?.Equals("CORE.ADMIN", StringComparison.Ordinal) == true)
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// These checks currently disabled due being possibly too generic:
// Found in "protect.dll" in Redump entry 94805.
// if (name?.Equals("CORE.DLL", StringComparison.Ordinal) == true)
- // return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ // return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
//
// Found in "protect.exe" in Redump entry 94805.
// if (name?.Equals("CORE.EXE", StringComparison.Ordinal) == true)
- // return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ // return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
//
// else if (name?.Equals("protect.exe", StringComparison.Ordinal) == true)
- // return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ // return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// Check the export name table
if (pex.ExportNameTable != null)
{
// TODO: Should we just check for "PSA_*" instead of a single entry?
if (pex.ExportNameTable.Any(s => s == "PSA_GetDiscLabel"))
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
}
// TODO: Find what fvinfo field actually maps to this
@@ -70,15 +69,15 @@ namespace BurnOutSharp.ProtectionType
// Found in "protect.exe" in Redump entry 94805.
if (name?.Contains("FrontLine Protection GUI Application") == true)
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// Found in "protect.dll" in Redump entry 94805.
if (name?.Contains("FrontLine Protection Library") == true)
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// Found in "protect.x64" and "protect.x86" in Redump entry 94805.
if (name?.Contains("FrontLine Helper") == true)
- return $"StarForce {Utilities.GetInternalVersion(pex)}";
+ return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
// TODO: Find a sample of this check.
if (name?.Contains("Protected Module") == true)
diff --git a/BurnOutSharp/ProtectionType/Steam.cs b/BurnOutSharp/ProtectionType/Steam.cs
index 2944c65b..dfe296b7 100644
--- a/BurnOutSharp/ProtectionType/Steam.cs
+++ b/BurnOutSharp/ProtectionType/Steam.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -23,7 +22,7 @@ namespace BurnOutSharp.ProtectionType
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client API"))
return "Steam";
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client Engine"))
- return $"Steam Client Engine {Utilities.GetInternalVersion(pex)}";
+ return $"Steam Client Engine {Tools.Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client Service"))
return "Steam";
diff --git a/BurnOutSharp/ProtectionType/Tages.cs b/BurnOutSharp/ProtectionType/Tages.cs
index dbbd466e..73c3435f 100644
--- a/BurnOutSharp/ProtectionType/Tages.cs
+++ b/BurnOutSharp/ProtectionType/Tages.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.IO;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -214,7 +213,7 @@ namespace BurnOutSharp.ProtectionType
private string GetVersion(PortableExecutable pex)
{
// Check the internal versions
- string version = Utilities.GetInternalVersion(pex);
+ string version = Tools.Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
diff --git a/BurnOutSharp/ProtectionType/nProtect.cs b/BurnOutSharp/ProtectionType/nProtect.cs
index fc802d13..e9013afe 100644
--- a/BurnOutSharp/ProtectionType/nProtect.cs
+++ b/BurnOutSharp/ProtectionType/nProtect.cs
@@ -1,9 +1,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
-using BurnOutSharp.Tools;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -44,37 +42,37 @@ namespace BurnOutSharp.ProtectionType
// Found in "GameGuard.des" in Redump entry 90526 and 99598.
if (name?.Contains("nProtect GameGuard Launcher") == true)
- return $"nProtect GameGuard ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect GameGuard ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkcrypt.dll" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Driver Support Dll") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkcrypt.sys" and "npkcusb.sys" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Driver") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkpdb.dll" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Program Database DLL") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
name = pex.ProductName;
// Found in "GameGuard.des" in Redump entry 90526 and 99598.
if (name?.Contains("nProtect GameGuard Launcher") == true)
- return $"nProtect GameGuard ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect GameGuard ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkcrypt.dll" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Driver Support Dll") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkcrypt.sys" and "npkcusb.sys" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Driver") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
// Found in "npkpdb.dll" in Redump entry 90526.
if (name?.Contains("nProtect KeyCrypt Program Database DLL") == true)
- return $"nProtect KeyCrypt ({Utilities.GetInternalVersion(pex)})";
+ return $"nProtect KeyCrypt ({Tools.Utilities.GetInternalVersion(pex)})";
return null;
}
diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs
index 4983eb2d..a8773b17 100644
--- a/BurnOutSharp/Scanner.cs
+++ b/BurnOutSharp/Scanner.cs
@@ -6,7 +6,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BurnOutSharp.FileType;
-using BurnOutSharp.Tools;
+using BurnOutSharp.Utilities;
+using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp
{
@@ -98,7 +99,7 @@ namespace BurnOutSharp
// Scan for path-detectable protections
var directoryPathProtections = GetDirectoryPathProtections(path, files);
- Utilities.AppendToDictionary(protections, directoryPathProtections);
+ AppendToDictionary(protections, directoryPathProtections);
// Scan each file in directory separately
for (int i = 0; i < files.Count; i++)
@@ -116,7 +117,7 @@ namespace BurnOutSharp
// Scan for path-detectable protections
var filePathProtections = GetFilePathProtections(file);
- Utilities.AppendToDictionary(protections, filePathProtections);
+ AppendToDictionary(protections, filePathProtections);
// Scan for content-detectable protections
var fileProtections = GetInternalProtections(file);
@@ -151,7 +152,7 @@ namespace BurnOutSharp
// Scan for path-detectable protections
var filePathProtections = GetFilePathProtections(path);
- Utilities.AppendToDictionary(protections, filePathProtections);
+ AppendToDictionary(protections, filePathProtections);
// Scan for content-detectable protections
var fileProtections = GetInternalProtections(path);
@@ -181,7 +182,7 @@ namespace BurnOutSharp
}
// Clear out any empty keys
- Utilities.ClearEmptyKeys(protections);
+ ClearEmptyKeys(protections);
// If we're in debug, output the elasped time to console
if (IncludeDebug)
@@ -268,8 +269,8 @@ namespace BurnOutSharp
if (IncludeDebug) Console.WriteLine(ex);
var protections = new ConcurrentDictionary>();
- Utilities.AppendToDictionary(protections, file, IncludeDebug ? ex.ToString() : "[Exception opening file, please try again]");
- Utilities.ClearEmptyKeys(protections);
+ AppendToDictionary(protections, file, IncludeDebug ? ex.ToString() : "[Exception opening file, please try again]");
+ ClearEmptyKeys(protections);
return protections;
}
}
@@ -310,16 +311,16 @@ namespace BurnOutSharp
}
// Get the file type either from magic number or extension
- SupportedFileType fileType = Utilities.GetFileType(magic);
+ SupportedFileType fileType = Tools.Utilities.GetFileType(magic);
if (fileType == SupportedFileType.UNKNOWN)
- fileType = Utilities.GetFileType(extension);
+ fileType = Tools.Utilities.GetFileType(extension);
// If we still got unknown, just return null
if (fileType == SupportedFileType.UNKNOWN)
return null;
// Create a scannable for the given file type
- var scannable = Utilities.CreateScannable(fileType);
+ var scannable = Tools.Utilities.CreateScannable(fileType);
if (scannable == null)
return null;
@@ -329,28 +330,28 @@ namespace BurnOutSharp
if (scannable is Executable)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ AppendToDictionary(protections, subProtections);
}
// PLJ
if (scannable is PLJ)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ AppendToDictionary(protections, subProtections);
}
// SFFS
if (scannable is SFFS)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ AppendToDictionary(protections, subProtections);
}
// Text-based files
if (scannable is Textfile)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ AppendToDictionary(protections, subProtections);
}
#endregion
@@ -364,112 +365,112 @@ namespace BurnOutSharp
if (scannable is SevenZip)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// BFPK archive
if (scannable is BFPK)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// BZip2
if (scannable is BZip2)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// GZIP
if (scannable is GZIP)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// InstallShield Archive V3 (Z)
if (fileName != null && scannable is InstallShieldArchiveV3)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// InstallShield Cabinet
if (fileName != null && scannable is InstallShieldCAB)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// Microsoft Cabinet
if (fileName != null && scannable is MicrosoftCAB)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// MSI
if (fileName != null && scannable is MSI)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// MPQ archive
if (fileName != null && scannable is MPQ)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// PKZIP archive (and derivatives)
if (scannable is PKZIP)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// RAR archive
if (scannable is RAR)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// Tape Archive
if (scannable is TapeArchive)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// Valve archive formats
if (fileName != null && scannable is Valve)
{
var subProtections = scannable.Scan(this, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
// XZ
if (scannable is XZ)
{
var subProtections = scannable.Scan(this, stream, fileName);
- Utilities.PrependToKeys(subProtections, fileName);
- Utilities.AppendToDictionary(protections, subProtections);
+ PrependToKeys(subProtections, fileName);
+ AppendToDictionary(protections, subProtections);
}
}
@@ -479,11 +480,11 @@ namespace BurnOutSharp
{
if (IncludeDebug) Console.WriteLine(ex);
- Utilities.AppendToDictionary(protections, fileName, IncludeDebug ? ex.ToString() : "[Exception opening file, please try again]");
+ AppendToDictionary(protections, fileName, IncludeDebug ? ex.ToString() : "[Exception opening file, please try again]");
}
// Clear out any empty keys
- Utilities.ClearEmptyKeys(protections);
+ ClearEmptyKeys(protections);
return protections;
}
diff --git a/BurnOutSharp/Tools/Utilities.cs b/BurnOutSharp/Tools/Utilities.cs
index 81125e4a..3e974cd8 100644
--- a/BurnOutSharp/Tools/Utilities.cs
+++ b/BurnOutSharp/Tools/Utilities.cs
@@ -1,182 +1,14 @@
using System;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Security.Cryptography;
using BurnOutSharp.Interfaces;
+using BurnOutSharp.Matching;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.Tools
{
internal static class Utilities
{
- #region Dictionary Manipulation
-
- ///
- /// Append one result to a results dictionary
- ///
- /// Dictionary to append to
- /// Key to add information to
- /// String value to add
- public static void AppendToDictionary(ConcurrentDictionary> original, string key, string value)
- {
- // If the value is empty, don't add it
- if (string.IsNullOrWhiteSpace(value))
- return;
-
- var values = new ConcurrentQueue();
- values.Enqueue(value);
- AppendToDictionary(original, key, values);
- }
-
- ///
- /// Append one result to a results dictionary
- ///
- /// Dictionary to append to
- /// Key to add information to
- /// String value to add
- public static void AppendToDictionary(ConcurrentDictionary> original, string key, ConcurrentQueue values)
- {
- // If the dictionary is null, just return
- if (original == null)
- return;
-
- // Use a placeholder value if the key is null
- key = key ?? "NO FILENAME";
-
- // Add the key if needed and then append the lists
- original.TryAdd(key, new ConcurrentQueue());
- original[key].AddRange(values);
- }
-
- ///
- /// Append one results dictionary to another
- ///
- /// Dictionary to append to
- /// Dictionary to pull from
- public static void AppendToDictionary(ConcurrentDictionary> original, ConcurrentDictionary> addition)
- {
- // If either dictionary is missing, just return
- if (original == null || addition == null)
- return;
-
- // Loop through each of the addition keys and add accordingly
- foreach (string key in addition.Keys)
- {
- original.TryAdd(key, new ConcurrentQueue());
- original[key].AddRange(addition[key]);
- }
- }
-
- ///
- /// Remove empty or null keys from a results dictionary
- ///
- /// Dictionary to clean
- public static void ClearEmptyKeys(ConcurrentDictionary> original)
- {
- // If the dictionary is missing, we can't do anything
- if (original == null)
- return;
-
- // Get a list of all of the keys
- var keys = original.Keys.ToList();
-
- // Iterate and reset keys
- for (int i = 0; i < keys.Count; i++)
- {
- // Get the current key
- string key = keys[i];
-
- // If the key is empty, remove it
- if (original[key] == null || !original[key].Any())
- original.TryRemove(key, out _);
- }
- }
-
- ///
- /// Prepend a parent path from dictionary keys, if possible
- ///
- /// Dictionary to strip values from
- /// Path to strip from the keys
- public static void PrependToKeys(ConcurrentDictionary> original, string pathToPrepend)
- {
- // If the dictionary is missing, we can't do anything
- if (original == null)
- return;
-
- // Use a placeholder value if the path is null
- pathToPrepend = (pathToPrepend ?? "ARCHIVE").TrimEnd(Path.DirectorySeparatorChar);
-
- // Get a list of all of the keys
- var keys = original.Keys.ToList();
-
- // Iterate and reset keys
- for (int i = 0; i < keys.Count; i++)
- {
- // Get the current key
- string currentKey = keys[i];
-
- // Otherwise, get the new key name and transfer over
- string newKey = $"{pathToPrepend}{Path.DirectorySeparatorChar}{currentKey.Trim(Path.DirectorySeparatorChar)}";
- original[newKey] = original[currentKey];
- original.TryRemove(currentKey, out _);
- }
- }
-
- ///
- /// Strip a parent path from dictionary keys, if possible
- ///
- /// Dictionary to strip values from
- /// Path to strip from the keys
- public static void StripFromKeys(ConcurrentDictionary> original, string pathToStrip)
- {
- // If either is missing, we can't do anything
- if (original == null || string.IsNullOrEmpty(pathToStrip))
- return;
-
- // Get a list of all of the keys
- var keys = original.Keys.ToList();
-
- // Iterate and reset keys
- for (int i = 0; i < keys.Count; i++)
- {
- // Get the current key
- string currentKey = keys[i];
-
- // If the key doesn't start with the path, don't touch it
- if (!currentKey.StartsWith(pathToStrip, StringComparison.OrdinalIgnoreCase))
- continue;
-
- // Otherwise, get the new key name and transfer over
- string newKey = currentKey.Substring(pathToStrip.Length);
- original[newKey] = original[currentKey];
- original.TryRemove(currentKey, out _);
- }
- }
-
- #endregion
-
- #region Concurrent Manipulation
-
- ///
- /// Add a range of values from one queue to another
- ///
- /// Queue to add data to
- /// Queue to get data from
- public static void AddRange(this ConcurrentQueue original, ConcurrentQueue values)
- {
- while (!values.IsEmpty)
- {
- if (!values.TryDequeue(out string value))
- return;
-
- original.Enqueue(value);
- }
- }
-
- #endregion
-
#region File Types
///
@@ -745,51 +577,6 @@ namespace BurnOutSharp.Tools
#endregion
- #region Executable Information
-
- ///
- /// Get the SHA1 hash of a file, if possible
- ///
- /// Path to the file to be hashed
- /// SHA1 hash as a string on success, null on error
- public static string GetFileSHA1(string path)
- {
- if (string.IsNullOrWhiteSpace(path))
- return null;
-
- try
- {
- SHA1 sha1 = SHA1.Create();
- using (Stream fileStream = File.OpenRead(path))
- {
- byte[] buffer = new byte[32768];
- while (true)
- {
- int bytesRead = fileStream.Read(buffer, 0, 32768);
- if (bytesRead == 32768)
- {
- sha1.TransformBlock(buffer, 0, bytesRead, null, 0);
- }
- else
- {
- sha1.TransformFinalBlock(buffer, 0, bytesRead);
- break;
- }
- }
- }
-
- string hash = BitConverter.ToString(sha1.Hash);
- hash = hash.Replace("-", string.Empty);
- return hash;
- }
- catch
- {
- return null;
- }
- }
-
- #endregion
-
#region Wrappers for Matchers
///
diff --git a/Test/Program.cs b/Test/Program.cs
index c6635817..c1ac4077 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -5,8 +5,8 @@ using System.IO;
using System.Linq;
using System.Text;
using BurnOutSharp;
+using BurnOutSharp.Utilities;
using BurnOutSharp.Wrappers;
-using static BurnOutSharp.Builder.Extensions;
namespace Test
{
diff --git a/Test/Test.csproj b/Test/Test.csproj
index d6975e23..203875b5 100644
--- a/Test/Test.csproj
+++ b/Test/Test.csproj
@@ -10,6 +10,7 @@
+