mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-09 02:16:46 +00:00
Get rid of code duplication
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BurnOutSharp.Models.BFPK;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BurnOutSharp.Models\BurnOutSharp.Models.csproj" />
|
||||
<ProjectReference Include="..\BurnOutSharp.Utilities\BurnOutSharp.Utilities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static byte ReadByte(this byte[] content, ref int offset)
|
||||
{
|
||||
return content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte array and increment the pointer to an array
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a char and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char ReadChar(this byte[] content, ref int offset)
|
||||
{
|
||||
return (char)content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this byte[] content, ref int offset, int count) => content.ReadChars(ref offset, count, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a short and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static short ReadInt16(this byte[] content, ref int offset)
|
||||
{
|
||||
short value = BitConverter.ToInt16(content, offset);
|
||||
offset += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ushort and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static ushort ReadUInt16(this byte[] content, ref int offset)
|
||||
{
|
||||
ushort value = BitConverter.ToUInt16(content, offset);
|
||||
offset += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a int and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static int ReadInt32(this byte[] content, ref int offset)
|
||||
{
|
||||
int value = BitConverter.ToInt32(content, offset);
|
||||
offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a uint and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static uint ReadUInt32(this byte[] content, ref int offset)
|
||||
{
|
||||
uint value = BitConverter.ToUInt32(content, offset);
|
||||
offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a long and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static long ReadInt64(this byte[] content, ref int offset)
|
||||
{
|
||||
long value = BitConverter.ToInt64(content, offset);
|
||||
offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ulong and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static ulong ReadUInt64(this byte[] content, ref int offset)
|
||||
{
|
||||
ulong value = BitConverter.ToUInt64(content, offset);
|
||||
offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
public static string ReadString(this byte[] content, ref int offset) => content.ReadString(ref offset, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
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<char> keyChars = new List<char>();
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte from the stream
|
||||
/// </summary>
|
||||
public static byte ReadByteValue(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
stream.Read(buffer, 0, 1);
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte array from the stream
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character from the stream
|
||||
/// </summary>
|
||||
public static char ReadChar(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
stream.Read(buffer, 0, 1);
|
||||
return (char)buffer[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array from the stream
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this Stream stream, int count) => stream.ReadChars(count, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array from the stream
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a short from the stream
|
||||
/// </summary>
|
||||
public static short ReadInt16(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[2];
|
||||
stream.Read(buffer, 0, 2);
|
||||
return BitConverter.ToInt16(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ushort from the stream
|
||||
/// </summary>
|
||||
public static ushort ReadUInt16(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[2];
|
||||
stream.Read(buffer, 0, 2);
|
||||
return BitConverter.ToUInt16(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an int from the stream
|
||||
/// </summary>
|
||||
public static int ReadInt32(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
stream.Read(buffer, 0, 4);
|
||||
return BitConverter.ToInt32(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a uint from the stream
|
||||
/// </summary>
|
||||
public static uint ReadUInt32(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
stream.Read(buffer, 0, 4);
|
||||
return BitConverter.ToUInt32(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a long from the stream
|
||||
/// </summary>
|
||||
public static long ReadInt64(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[8];
|
||||
stream.Read(buffer, 0, 8);
|
||||
return BitConverter.ToInt64(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ulong from the stream
|
||||
/// </summary>
|
||||
public static ulong ReadUInt64(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[8];
|
||||
stream.Read(buffer, 0, 8);
|
||||
return BitConverter.ToUInt64(buffer, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
public static string ReadString(this Stream stream) => stream.ReadString(Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
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<byte> tempBuffer = new List<byte>();
|
||||
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using BurnOutSharp.Models.MSDOS;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BurnOutSharp.Models.MicrosoftCabinet;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BurnOutSharp.Models.MoPaQ;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BurnOutSharp.Models.NewExecutable;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BurnOutSharp.Models.PortableExecutable;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
namespace BurnOutSharp.Builder
|
||||
{
|
||||
|
||||
80
BurnOutSharp.Matching/Extensions.cs
Normal file
80
BurnOutSharp.Matching/Extensions.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BurnOutSharp.Matching
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Find all positions of one array in another, if possible, if possible
|
||||
/// </summary>
|
||||
public static List<int> FindAllPositions(this byte[] stack, byte?[] needle, int start = 0, int end = -1)
|
||||
{
|
||||
// Get the outgoing list
|
||||
List<int> positions = new List<int>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the last position of one array in another, if possible
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See if a byte array starts with another
|
||||
/// </summary>
|
||||
public static bool StartsWith(this byte[] stack, byte?[] needle)
|
||||
{
|
||||
return stack.FirstPosition(needle, out int _, start: 0, end: 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See if a byte array ends with another
|
||||
/// </summary>
|
||||
public static bool EndsWith(this byte[] stack, byte?[] needle)
|
||||
{
|
||||
return stack.FirstPosition(needle, out int _, start: stack.Length - needle.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
BurnOutSharp.Utilities/BurnOutSharp.Utilities.csproj
Normal file
22
BurnOutSharp.Utilities/BurnOutSharp.Utilities.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
|
||||
<Title>BurnOutSharp.Utilities</Title>
|
||||
<AssemblyName>BurnOutSharp.Utilities</AssemblyName>
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
<Product>BurnOutSharp</Product>
|
||||
<Copyright>Copyright (c)2022 Matt Nadareski</Copyright>
|
||||
<RepositoryUrl>https://github.com/mnadareski/BurnOutSharp</RepositoryUrl>
|
||||
<Version>2.5</Version>
|
||||
<AssemblyVersion>2.5</AssemblyVersion>
|
||||
<FileVersion>2.5</FileVersion>
|
||||
<IncludeSource>true</IncludeSource>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
155
BurnOutSharp.Utilities/Dictionary.cs
Normal file
155
BurnOutSharp.Utilities/Dictionary.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace BurnOutSharp.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary manipulation methods
|
||||
/// </summary>
|
||||
public static class Dictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Append one result to a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="key">Key to add information to</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, string key, string value)
|
||||
{
|
||||
// If the value is empty, don't add it
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return;
|
||||
|
||||
var values = new ConcurrentQueue<string>();
|
||||
values.Enqueue(value);
|
||||
AppendToDictionary(original, key, values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append one result to a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="key">Key to add information to</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, string key, ConcurrentQueue<string> 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<string>());
|
||||
original[key].AddRange(values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append one results dictionary to another
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="addition">Dictionary to pull from</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, ConcurrentDictionary<string, ConcurrentQueue<string>> 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<string>());
|
||||
original[key].AddRange(addition[key]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove empty or null keys from a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to clean</param>
|
||||
public static void ClearEmptyKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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 _);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepend a parent path from dictionary keys, if possible
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to strip values from</param>
|
||||
/// <param name="pathToPrepend">Path to strip from the keys</param>
|
||||
public static void PrependToKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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 _);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip a parent path from dictionary keys, if possible
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to strip values from</param>
|
||||
/// <param name="pathToStrip">Path to strip from the keys</param>
|
||||
public static void StripFromKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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 _);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Add a range of values from one queue to another
|
||||
/// </summary>
|
||||
/// <param name="original">Queue to add data to</param>
|
||||
/// <param name="values">Queue to get data from</param>
|
||||
public static void AddRange(this ConcurrentQueue<string> original, ConcurrentQueue<string> values)
|
||||
{
|
||||
while (!values.IsEmpty)
|
||||
{
|
||||
if (!values.TryDequeue(out string value))
|
||||
return;
|
||||
|
||||
original.Enqueue(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Byte Array Reading
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte and increment the pointer to an array
|
||||
@@ -24,12 +44,24 @@ namespace BurnOutSharp.Tools
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an sbyte and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static sbyte ReadSByte(this byte[] content, ref int offset)
|
||||
{
|
||||
return (sbyte)content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a char and increment the pointer to an array
|
||||
/// </summary>
|
||||
@@ -38,24 +70,6 @@ namespace BurnOutSharp.Tools
|
||||
return (char)content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this byte[] content, ref int offset, int count) => content.ReadChars(ref offset, count, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a short and increment the pointer to an array
|
||||
/// </summary>
|
||||
@@ -146,81 +160,9 @@ namespace BurnOutSharp.Tools
|
||||
return new string(keyChars.ToArray()).TrimEnd('\0');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all positions of one array in another, if possible, if possible
|
||||
/// </summary>
|
||||
public static List<int> FindAllPositions(this byte[] stack, byte?[] needle, int start = 0, int end = -1)
|
||||
{
|
||||
// Get the outgoing list
|
||||
List<int> positions = new List<int>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the last position of one array in another, if possible
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See if a byte array starts with another
|
||||
/// </summary>
|
||||
public static bool StartsWith(this byte[] stack, byte?[] needle)
|
||||
{
|
||||
return stack.FirstPosition(needle, out int _, start: 0, end: 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See if a byte array ends with another
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte from the stream
|
||||
@@ -237,11 +179,25 @@ namespace BurnOutSharp.Tools
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an sbyte from the stream
|
||||
/// </summary>
|
||||
public static sbyte ReadSByte(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
stream.Read(buffer, 0, 1);
|
||||
return (sbyte)buffer[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character from the stream
|
||||
/// </summary>
|
||||
@@ -252,21 +208,6 @@ namespace BurnOutSharp.Tools
|
||||
return (char)buffer[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array from the stream
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this Stream stream, int count) => stream.ReadChars(count, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array from the stream
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a short from the stream
|
||||
/// </summary>
|
||||
@@ -337,13 +278,16 @@ namespace BurnOutSharp.Tools
|
||||
/// </summary>
|
||||
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<byte> tempBuffer = new List<byte>();
|
||||
|
||||
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);
|
||||
}
|
||||
53
BurnOutSharp.Utilities/Hashing.cs
Normal file
53
BurnOutSharp.Utilities/Hashing.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace BurnOutSharp.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Data hashing methods
|
||||
/// </summary>
|
||||
public static class Hashing
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the SHA1 hash of a file, if possible
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the file to be hashed</param>
|
||||
/// <returns>SHA1 hash as a string on success, null on error</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\BurnOutSharp.Utilities\BurnOutSharp.Utilities.csproj">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\BurnOutSharp.Wrappers\BurnOutSharp.Wrappers.csproj">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BurnOutSharp.Tools;
|
||||
using BurnOutSharp.Utilities;
|
||||
|
||||
/// <see href="https://interoperability.blob.core.windows.net/files/MS-MCI/%5bMS-MCI%5d.pdf"/>
|
||||
/// <see href="https://www.rfc-editor.org/rfc/rfc1951"/>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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("<PROTECTION-VENDOR>MediaMAX</PROTECTION-VENDOR>"))
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}";
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string> strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<PathMatchSet>
|
||||
{
|
||||
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<PathMatchSet>
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string, ConcurrentQueue<string>>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Append one result to a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="key">Key to add information to</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, string key, string value)
|
||||
{
|
||||
// If the value is empty, don't add it
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return;
|
||||
|
||||
var values = new ConcurrentQueue<string>();
|
||||
values.Enqueue(value);
|
||||
AppendToDictionary(original, key, values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append one result to a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="key">Key to add information to</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, string key, ConcurrentQueue<string> 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<string>());
|
||||
original[key].AddRange(values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append one results dictionary to another
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to append to</param>
|
||||
/// <param name="addition">Dictionary to pull from</param>
|
||||
public static void AppendToDictionary(ConcurrentDictionary<string, ConcurrentQueue<string>> original, ConcurrentDictionary<string, ConcurrentQueue<string>> 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<string>());
|
||||
original[key].AddRange(addition[key]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove empty or null keys from a results dictionary
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to clean</param>
|
||||
public static void ClearEmptyKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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 _);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepend a parent path from dictionary keys, if possible
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to strip values from</param>
|
||||
/// <param name="pathToPrepend">Path to strip from the keys</param>
|
||||
public static void PrependToKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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 _);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip a parent path from dictionary keys, if possible
|
||||
/// </summary>
|
||||
/// <param name="original">Dictionary to strip values from</param>
|
||||
/// <param name="pathToStrip">Path to strip from the keys</param>
|
||||
public static void StripFromKeys(ConcurrentDictionary<string, ConcurrentQueue<string>> 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
|
||||
|
||||
/// <summary>
|
||||
/// Add a range of values from one queue to another
|
||||
/// </summary>
|
||||
/// <param name="original">Queue to add data to</param>
|
||||
/// <param name="values">Queue to get data from</param>
|
||||
public static void AddRange(this ConcurrentQueue<string> original, ConcurrentQueue<string> values)
|
||||
{
|
||||
while (!values.IsEmpty)
|
||||
{
|
||||
if (!values.TryDequeue(out string value))
|
||||
return;
|
||||
|
||||
original.Enqueue(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Types
|
||||
|
||||
/// <summary>
|
||||
@@ -745,51 +577,6 @@ namespace BurnOutSharp.Tools
|
||||
|
||||
#endregion
|
||||
|
||||
#region Executable Information
|
||||
|
||||
/// <summary>
|
||||
/// Get the SHA1 hash of a file, if possible
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the file to be hashed</param>
|
||||
/// <returns>SHA1 hash as a string on success, null on error</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<ProjectReference Include="..\BurnOutSharp\BurnOutSharp.csproj" />
|
||||
<ProjectReference Include="..\BurnOutSharp.Builder\BurnOutSharp.Builder.csproj" />
|
||||
<ProjectReference Include="..\BurnOutSharp.Models\BurnOutSharp.Models.csproj" />
|
||||
<ProjectReference Include="..\BurnOutSharp.Utilities\BurnOutSharp.Utilities.csproj" />
|
||||
<ProjectReference Include="..\BurnOutSharp.Wrappers\BurnOutSharp.Wrappers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user