Compare commits

...

15 Commits
2.9.0 ... 3.0.1

Author SHA1 Message Date
Matt Nadareski
b0d49f52a5 Bump version 2023-11-20 12:16:53 -05:00
Matt Nadareski
6f9bcc2111 Fix multiple invocation bug
This bug arose when all of the libraries were consoliated into the same library for better packaging. Each set of classes was being instantiated 3 times as a result.
2023-11-18 20:55:32 -05:00
Matt Nadareski
0fb0ecd28a Update ST libraries for bugfixes 2023-11-15 12:54:32 -05:00
Matt Nadareski
6194d88aec Correct the excludes 2023-11-15 11:26:00 -05:00
Matt Nadareski
b02c3121fe Use official package for IProgress 2023-11-15 00:24:47 -05:00
Matt Nadareski
580db0cb65 Minor tweaks to reduce warnings 2023-11-14 23:48:35 -05:00
Matt Nadareski
6bcdc0e3c6 Bump version 2023-11-14 16:16:08 -05:00
Matt Nadareski
9b4fd91717 Update build scripts 2023-11-14 16:13:49 -05:00
Matt Nadareski
9421249b8e Support ancient .NET 2023-11-14 16:10:10 -05:00
Matt Nadareski
e823cbaee5 Expand supported RIDs 2023-11-08 22:51:47 -05:00
Matt Nadareski
c34618554b Update project comment 2023-11-08 12:08:22 -05:00
Matt Nadareski
6ab7b4a004 Enable latest language version 2023-11-08 11:59:50 -05:00
Matt Nadareski
5b6bf3b73e Rename to BinaryObjectScanner 2023-11-08 11:37:27 -05:00
Matt Nadareski
2a30a13f5f Omit submodule code for modern .NET 2023-10-27 00:58:03 -04:00
Matt Nadareski
3c05a112ca Remove DLLs from modern .NET builds 2023-10-27 00:55:31 -04:00
173 changed files with 711 additions and 2158 deletions

View File

@@ -2,29 +2,28 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<Version>2.9.0</Version>
<TargetFrameworks>net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> --> <!-- Can't be enabled because of external code -->
<Version>3.0.1</Version>
<!-- Package Properties -->
<PackageId>BurnOutSharp</PackageId> <!-- Temporary until official renaming -->
<Authors>Matt Nadareski</Authors>
<Description>Protection scanning library</Description>
<Copyright>Copyright (c)2018-2023 Matt Nadareski</Copyright>
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
<RepositoryUrl>https://github.com/mnadareski/BurnOutSharp</RepositoryUrl>
<RepositoryUrl>https://github.com/SabreTools/BinaryObjectScanner</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>protection copy-protection scanning packer</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)'!='net48'">
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- These are needed for dealing with submodules -->
<PropertyGroup>
<!-- Exclude certain parts of external modules for .NET Framework 4.5.2 and above -->
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net4`)) AND !$(TargetFramework.StartsWith(`net40`))">
<DefaultItemExcludes>
$(DefaultItemExcludes);
**\AssemblyInfo.cs;
@@ -33,8 +32,16 @@
</DefaultItemExcludes>
</PropertyGroup>
<!-- Exclude all external modules for .NET Framework 4.0, .NET Core and modern .NET -->
<PropertyGroup Condition="!$(TargetFramework.StartsWith(`net4`)) OR $(TargetFramework.StartsWith(`net40`))">
<DefaultItemExcludes>
$(DefaultItemExcludes);
_EXTERNAL\**;
</DefaultItemExcludes>
</PropertyGroup>
<!-- These are needed for dealing with native Windows DLLs -->
<ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`)) AND !$(TargetFramework.StartsWith(`net40`))">
<Content Include="*.dll">
<Pack>true</Pack>
<PackagePath>contentFiles;content</PackagePath>
@@ -49,19 +56,26 @@
<ItemGroup>
<PackageReference Include="OpenMcdf" Version="2.3.0" />
<PackageReference Include="SabreTools.Compression" Version="0.1.1" />
<PackageReference Include="SabreTools.IO" Version="1.1.1" />
<PackageReference Include="SabreTools.Matching" Version="1.1.1" />
<PackageReference Include="SabreTools.Models" Version="1.1.5" />
<PackageReference Include="SabreTools.Serialization" Version="1.1.7" />
<PackageReference Include="SabreTools.Compression" Version="0.2.0" />
<PackageReference Include="SabreTools.IO" Version="1.2.0" />
<PackageReference Include="SabreTools.Matching" Version="1.2.0" />
<PackageReference Include="SabreTools.Models" Version="1.2.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.2.1" />
<PackageReference Include="UnshieldSharp" Version="1.7.0" />
<PackageReference Include="WiseUnpacker" Version="1.2.0" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith(`net40`))">
<PackageReference Include="Microsoft.Bcl" Version="1.1.10" />
</ItemGroup>
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))">
<PackageReference Include="SharpCompress" Version="0.34.1" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="UnshieldSharp" Version="1.6.9" />
<PackageReference Include="WiseUnpacker" Version="1.0.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net48'">
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`)) AND !$(TargetFramework.StartsWith(`net40`))">
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

View File

@@ -8,24 +8,20 @@ namespace BinaryObjectScanner
/// <summary>
/// Create an instance of a detectable based on file type
/// </summary>
#if NET48
public static IDetectable CreateDetectable(SupportedFileType fileType)
#else
public static IDetectable? CreateDetectable(SupportedFileType fileType)
#endif
{
switch (fileType)
{
case SupportedFileType.AACSMediaKeyBlock: return new BinaryObjectScanner.FileType.AACSMediaKeyBlock();
case SupportedFileType.BDPlusSVM: return new BinaryObjectScanner.FileType.BDPlusSVM();
//case SupportedFileType.CIA: return new BinaryObjectScanner.FileType.CIA();
case SupportedFileType.Executable: return new BinaryObjectScanner.FileType.Executable();
case SupportedFileType.LDSCRYPT: return new BinaryObjectScanner.FileType.LDSCRYPT();
//case SupportedFileType.N3DS: return new BinaryObjectScanner.FileType.N3DS();
//case SupportedFileType.Nitro: return new BinaryObjectScanner.FileType.Nitro();
case SupportedFileType.PLJ: return new BinaryObjectScanner.FileType.PLJ();
case SupportedFileType.SFFS: return new BinaryObjectScanner.FileType.SFFS();
case SupportedFileType.Textfile: return new BinaryObjectScanner.FileType.Textfile();
case SupportedFileType.AACSMediaKeyBlock: return new FileType.AACSMediaKeyBlock();
case SupportedFileType.BDPlusSVM: return new FileType.BDPlusSVM();
//case SupportedFileType.CIA: return new FileType.CIA();
case SupportedFileType.Executable: return new FileType.Executable();
case SupportedFileType.LDSCRYPT: return new FileType.LDSCRYPT();
//case SupportedFileType.N3DS: return new FileType.N3DS();
//case SupportedFileType.Nitro: return new FileType.Nitro();
case SupportedFileType.PLJ: return new FileType.PLJ();
case SupportedFileType.SFFS: return new FileType.SFFS();
case SupportedFileType.Textfile: return new FileType.Textfile();
default: return null;
}
}
@@ -33,44 +29,40 @@ namespace BinaryObjectScanner
/// <summary>
/// Create an instance of an extractable based on file type
/// </summary>
#if NET48
public static IExtractable CreateExtractable(SupportedFileType fileType)
#else
public static IExtractable? CreateExtractable(SupportedFileType fileType)
#endif
{
switch (fileType)
{
case SupportedFileType.BFPK: return new BinaryObjectScanner.FileType.BFPK();
case SupportedFileType.BSP: return new BinaryObjectScanner.FileType.BSP();
case SupportedFileType.BZip2: return new BinaryObjectScanner.FileType.BZip2();
case SupportedFileType.CFB: return new BinaryObjectScanner.FileType.CFB();
//case SupportedFileType.CIA: return new BinaryObjectScanner.FileType.CIA();
case SupportedFileType.GCF: return new BinaryObjectScanner.FileType.GCF();
case SupportedFileType.GZIP: return new BinaryObjectScanner.FileType.GZIP();
case SupportedFileType.InstallShieldArchiveV3: return new BinaryObjectScanner.FileType.InstallShieldArchiveV3();
case SupportedFileType.InstallShieldCAB: return new BinaryObjectScanner.FileType.InstallShieldCAB();
case SupportedFileType.MicrosoftCAB: return new BinaryObjectScanner.FileType.MicrosoftCAB();
case SupportedFileType.MicrosoftLZ: return new BinaryObjectScanner.FileType.MicrosoftLZ();
case SupportedFileType.MPQ: return new BinaryObjectScanner.FileType.MPQ();
//case SupportedFileType.N3DS: return new BinaryObjectScanner.FileType.N3DS();
//case SupportedFileType.NCF: return new BinaryObjectScanner.FileType.NCF();
//case SupportedFileType.Nitro: return new BinaryObjectScanner.FileType.Nitro();
case SupportedFileType.PAK: return new BinaryObjectScanner.FileType.PAK();
case SupportedFileType.PFF: return new BinaryObjectScanner.FileType.PFF();
case SupportedFileType.PKZIP: return new BinaryObjectScanner.FileType.PKZIP();
//case SupportedFileType.PLJ: return new BinaryObjectScanner.FileType.PLJ();
//case SupportedFileType.Quantum: return new BinaryObjectScanner.FileType.Quantum();
case SupportedFileType.RAR: return new BinaryObjectScanner.FileType.RAR();
case SupportedFileType.SevenZip: return new BinaryObjectScanner.FileType.SevenZip();
case SupportedFileType.SFFS: return new BinaryObjectScanner.FileType.SFFS();
case SupportedFileType.SGA: return new BinaryObjectScanner.FileType.SGA();
case SupportedFileType.TapeArchive: return new BinaryObjectScanner.FileType.TapeArchive();
case SupportedFileType.VBSP: return new BinaryObjectScanner.FileType.VBSP();
case SupportedFileType.VPK: return new BinaryObjectScanner.FileType.VPK();
case SupportedFileType.WAD: return new BinaryObjectScanner.FileType.WAD();
case SupportedFileType.XZ: return new BinaryObjectScanner.FileType.XZ();
case SupportedFileType.XZP: return new BinaryObjectScanner.FileType.XZP();
case SupportedFileType.BFPK: return new FileType.BFPK();
case SupportedFileType.BSP: return new FileType.BSP();
case SupportedFileType.BZip2: return new FileType.BZip2();
case SupportedFileType.CFB: return new FileType.CFB();
//case SupportedFileType.CIA: return new FileType.CIA();
case SupportedFileType.GCF: return new FileType.GCF();
case SupportedFileType.GZIP: return new FileType.GZIP();
case SupportedFileType.InstallShieldArchiveV3: return new FileType.InstallShieldArchiveV3();
case SupportedFileType.InstallShieldCAB: return new FileType.InstallShieldCAB();
case SupportedFileType.MicrosoftCAB: return new FileType.MicrosoftCAB();
case SupportedFileType.MicrosoftLZ: return new FileType.MicrosoftLZ();
case SupportedFileType.MPQ: return new FileType.MPQ();
//case SupportedFileType.N3DS: return new FileType.N3DS();
//case SupportedFileType.NCF: return new FileType.NCF();
//case SupportedFileType.Nitro: return new FileType.Nitro();
case SupportedFileType.PAK: return new FileType.PAK();
case SupportedFileType.PFF: return new FileType.PFF();
case SupportedFileType.PKZIP: return new FileType.PKZIP();
//case SupportedFileType.PLJ: return new FileType.PLJ();
//case SupportedFileType.Quantum: return new FileType.Quantum();
case SupportedFileType.RAR: return new FileType.RAR();
case SupportedFileType.SevenZip: return new FileType.SevenZip();
case SupportedFileType.SFFS: return new FileType.SFFS();
case SupportedFileType.SGA: return new FileType.SGA();
case SupportedFileType.TapeArchive: return new FileType.TapeArchive();
case SupportedFileType.VBSP: return new FileType.VBSP();
case SupportedFileType.VPK: return new FileType.VPK();
case SupportedFileType.WAD: return new FileType.WAD();
case SupportedFileType.XZ: return new FileType.XZ();
case SupportedFileType.XZP: return new FileType.XZP();
default: return null;
}
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class AACSMediaKeyBlock : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// If the MKB file itself fails
try

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class BDPlusSVM : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// If the BD+ file itself fails
try

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Compressors;
using SharpCompress.Compressors.Deflate;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class BFPK : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +26,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -56,7 +50,7 @@ namespace BinaryObjectScanner.FileType
return null;
}
}
/// <summary>
/// Extract all files from the BFPK to an output directory
/// </summary>
@@ -129,12 +123,14 @@ namespace BinaryObjectScanner.FileType
{
fs.Write(data, 0, compressedSize);
}
#if NET462_OR_GREATER
else
{
MemoryStream ms = new MemoryStream(data);
ZlibStream zs = new ZlibStream(ms, CompressionMode.Decompress);
zs.CopyTo(fs);
}
#endif
}
return true;

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class BSP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -229,11 +221,7 @@ namespace BinaryObjectScanner.FileType
/// </summary>
/// <param name="texture">Texture object to format</param>
/// <returns>Byte array representing the texture as a bitmap</returns>
#if NET48
private static byte[] CreateTextureData(SabreTools.Models.BSP.Texture texture)
#else
private static byte[]? CreateTextureData(SabreTools.Models.BSP.Texture texture)
#endif
{
// If there's no palette data
if (texture.PaletteData == null || texture.PaletteData.Length == 0)

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Compressors;
using SharpCompress.Compressors.BZip2;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class BZip2 : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,15 +26,12 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
if (stream == null)
return null;
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -59,6 +54,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class CFB : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -95,11 +87,7 @@ namespace BinaryObjectScanner.FileType
}
/// <remarks>Adapted from LibMSI</remarks>
#if NET48
public static string DecodeStreamName(string input)
#else
public static string? DecodeStreamName(string input)
#endif
{
if (input == null)
return null;

View File

@@ -110,56 +110,32 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Cache for all IContentCheck types
/// </summary>
#if NET48
private static IEnumerable<IContentCheck> contentCheckClasses;
#else
private static IEnumerable<IContentCheck>? contentCheckClasses;
#endif
/// <summary>
/// Cache for all ILinearExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<ILinearExecutableCheck> linearExecutableCheckClasses;
#else
private static IEnumerable<ILinearExecutableCheck>? linearExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all IMSDOSExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<IMSDOSExecutableCheck> msdosExecutableCheckClasses;
#else
private static IEnumerable<IMSDOSExecutableCheck>? msdosExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all INewExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<INewExecutableCheck> newExecutableCheckClasses;
#else
private static IEnumerable<INewExecutableCheck>? newExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all IPortableExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<IPortableExecutableCheck> portableExecutableCheckClasses;
#else
private static IEnumerable<IPortableExecutableCheck>? portableExecutableCheckClasses;
#endif
#endregion
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -171,11 +147,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// Try to create a wrapper for the proper executable type
var wrapper = WrapperFactory.CreateExecutableWrapper(stream);
@@ -230,11 +202,7 @@ namespace BinaryObjectScanner.FileType
/// <param name="stream">Stream to scan the contents of</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Set of protections in file, null on error</returns>
#if NET48
public ConcurrentDictionary<IContentCheck, string> RunContentChecks(string file, Stream stream, bool includeDebug)
#else
public ConcurrentDictionary<IContentCheck, string>? RunContentChecks(string? file, Stream stream, bool includeDebug)
#endif
{
// If we have an invalid file
if (string.IsNullOrWhiteSpace(file))
@@ -246,7 +214,11 @@ namespace BinaryObjectScanner.FileType
byte[] fileContent = new byte[0];
try
{
#if NET40
using (BinaryReader br = new BinaryReader(stream, Encoding.Default))
#else
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
#endif
{
fileContent = br.ReadBytes((int)stream.Length);
if (fileContent == null)
@@ -266,7 +238,7 @@ namespace BinaryObjectScanner.FileType
Parallel.ForEach(ContentCheckClasses, checkClass =>
{
// Get the protection for the class, if possible
var protection = checkClass.CheckContents(file, fileContent, includeDebug);
var protection = checkClass.CheckContents(file!, fileContent, includeDebug);
if (string.IsNullOrWhiteSpace(protection))
return;
@@ -278,7 +250,7 @@ namespace BinaryObjectScanner.FileType
if (CheckIfPacker(checkClass) && !IncludePackers)
return;
protections.TryAdd(checkClass, protection);
protections.TryAdd(checkClass, protection!);
});
return protections;
@@ -312,7 +284,7 @@ namespace BinaryObjectScanner.FileType
if (CheckIfPacker(checkClass) && !IncludePackers)
return;
protections.TryAdd(checkClass, protection);
protections.TryAdd(checkClass, protection!);
});
return protections;
@@ -346,7 +318,7 @@ namespace BinaryObjectScanner.FileType
if (CheckIfPacker(checkClass) && !IncludePackers)
return;
protections.TryAdd(checkClass, protection);
protections.TryAdd(checkClass, protection!);
});
return protections;
@@ -380,7 +352,7 @@ namespace BinaryObjectScanner.FileType
if (CheckIfPacker(checkClass) && !IncludePackers)
return;
protections.TryAdd(checkClass, protection);
protections.TryAdd(checkClass, protection!);
});
return protections;
@@ -414,7 +386,7 @@ namespace BinaryObjectScanner.FileType
if (CheckIfPacker(checkClass) && !IncludePackers)
return;
protections.TryAdd(checkClass, protection);
protections.TryAdd(checkClass, protection!);
});
return protections;
@@ -427,35 +399,21 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>()
#else
private static IEnumerable<T>? InitCheckClasses<T>()
#endif
=> InitCheckClasses<T>(typeof(GameEngine._DUMMY).Assembly) ?? Enumerable.Empty<T>()
.Concat(InitCheckClasses<T>(typeof(Packer._DUMMY).Assembly) ?? Enumerable.Empty<T>())
.Concat(InitCheckClasses<T>(typeof(Protection._DUMMY).Assembly) ?? Enumerable.Empty<T>());
private static IEnumerable<T>? InitCheckClasses<T>() =>
InitCheckClasses<T>(typeof(Handler).Assembly) ?? Enumerable.Empty<T>();
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>(Assembly assembly)
#else
private static IEnumerable<T>? InitCheckClasses<T>(Assembly assembly)
#endif
{
return assembly.GetTypes()?
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)?
#if NET48
.Select(t => (T)Activator.CreateInstance(t))
#else
.Select(t => (T?)Activator.CreateInstance(t))
#endif
.Cast<T>() ?? Array.Empty<T>();
.Cast<T>() ?? [];
}
#endregion
#endregion
#region Helpers

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class GCF : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.GZip;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class GZIP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,15 +26,12 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
if (stream == null)
return null;
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -70,6 +65,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class InstallShieldArchiveV3 : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -45,13 +37,13 @@ namespace BinaryObjectScanner.FileType
{
try
{
string tempFile = Path.Combine(tempPath, cfile.FullPath);
string tempFile = Path.Combine(tempPath, cfile.FullPath!);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
(byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
if (!string.IsNullOrWhiteSpace(error))
(byte[]? fileContents, string? error) = archive.Extract(cfile.FullPath!);
if (fileContents == null || !string.IsNullOrWhiteSpace(error))
continue;
using (FileStream fs = File.OpenWrite(tempFile))

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class InstallShieldCAB : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
// Get the name of the first cabinet file or header
var directory = Path.GetDirectoryName(file);
@@ -68,7 +60,10 @@ namespace BinaryObjectScanner.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
InstallShieldCabinet cabfile = InstallShieldCabinet.Open(file);
var cabfile = InstallShieldCabinet.Open(file);
if (cabfile == null)
return null;
for (int i = 0; i < cabfile.FileCount; i++)
{
try
@@ -80,8 +75,8 @@ namespace BinaryObjectScanner.FileType
string tempFile;
try
{
string filename = cabfile.FileName(i);
tempFile = Path.Combine(tempPath, filename);
string? filename = cabfile.FileName(i);
tempFile = Path.Combine(tempPath, filename ?? string.Empty);
}
catch
{

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class LDSCRYPT : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,7 +1,7 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET48
#if NETFRAMEWORK && !NET40
using StormLibSharp;
#endif
@@ -13,11 +13,7 @@ namespace BinaryObjectScanner.FileType
public class MPQ : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -30,14 +26,10 @@ namespace BinaryObjectScanner.FileType
// TODO: Add stream opening support
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
#if NET6_0_OR_GREATER
// Not supported for .NET 6.0 due to Windows DLL requirements
#if NET40 || NETCOREAPP || NET5_0_OR_GREATER
// Not supported for .NET Core and modern .NET due to Windows DLL requirements
return null;
#else
try
@@ -49,7 +41,7 @@ namespace BinaryObjectScanner.FileType
using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
{
// Try to open the listfile
string listfile = null;
string? listfile = null;
MpqFileStream listStream = mpqArchive.OpenFile("(listfile)");
// If we can't read the listfile, we just return

View File

@@ -13,11 +13,7 @@ namespace BinaryObjectScanner.FileType
public class MicrosoftCAB : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -29,11 +25,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class MicrosoftLZ : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class PAK : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class PFF : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class PKZIP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,15 +26,12 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
if (stream == null)
return null;
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -73,6 +68,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class PLJ : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class Quantum : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class RAR : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,15 +26,12 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
if (stream == null)
return null;
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -70,6 +65,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class SFFS : IExtractable, IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
try
{
@@ -51,11 +43,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -67,11 +55,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using ICSharpCode.SharpZipLib.Zip.Compression;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -13,11 +15,7 @@ namespace BinaryObjectScanner.FileType
public class SGA : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -29,11 +27,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -118,11 +112,7 @@ namespace BinaryObjectScanner.FileType
return false;
// Get the files
#if NET48
object file;
#else
object? file;
#endif
switch (item.Model.Header?.MajorVersion)
{
case 4: file = (item.Model.Directory as SabreTools.Models.SGA.Directory4)?.Files?[index]; break;
@@ -147,27 +137,16 @@ namespace BinaryObjectScanner.FileType
}
// Loop through and get all parent directories
#if NET48
var parentNames = new List<string> { filename };
#else
var parentNames = new List<string?> { filename };
#endif
// Get the parent directory
var folder = default(object);
switch (item.Model.Header?.MajorVersion)
{
#if NET48
case 4: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory4)?.Folders?.FirstOrDefault(f => index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 5: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory5)?.Folders?.FirstOrDefault(f => index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 6: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory6)?.Folders?.FirstOrDefault(f => index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 7: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory7)?.Folders?.FirstOrDefault(f => index >= f.FileStartIndex && index <= f.FileEndIndex); break;
#else
case 4: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory4)?.Folders?.FirstOrDefault(f => f != null && index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 5: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory5)?.Folders?.FirstOrDefault(f => f != null && index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 6: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory6)?.Folders?.FirstOrDefault(f => f != null && index >= f.FileStartIndex && index <= f.FileEndIndex); break;
case 7: folder = (item.Model.Directory as SabreTools.Models.SGA.Directory7)?.Folders?.FirstOrDefault(f => f != null && index >= f.FileStartIndex && index <= f.FileEndIndex); break;
#endif
default: return false;
}
@@ -245,10 +224,14 @@ namespace BinaryObjectScanner.FileType
else
{
// Decompress the data
#if NET462_OR_GREATER
data = new byte[outputFileSize];
Inflater inflater = new Inflater();
inflater.SetInput(compressedData);
inflater.Inflate(data);
#else
data = new byte[outputFileSize];
#endif
}
// If we have an invalid output directory

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.SevenZip;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class SevenZip : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,12 +26,9 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -67,6 +62,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -1,8 +1,10 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Tar;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -12,11 +14,7 @@ namespace BinaryObjectScanner.FileType
public class TapeArchive : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,15 +26,12 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
if (stream == null)
return null;
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -70,6 +65,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class Textfile : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// Files can be protected in multiple ways
var protections = new List<string>();
@@ -41,7 +33,11 @@ namespace BinaryObjectScanner.FileType
{
// Load the current file content
var fileContent = string.Empty;
#if NET40
using (var sr = new StreamReader(stream, Encoding.Default, true, 1024 * 1024))
#else
using (var sr = new StreamReader(stream, Encoding.Default, true, 1024 * 1024, true))
#endif
{
fileContent = sr.ReadToEnd();
}

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class VBSP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.FileType
public class VPK : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -28,11 +24,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.FileType
public class WAD : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,11 +22,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,7 +1,9 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using SharpCompress.Compressors.Xz;
#endif
namespace BinaryObjectScanner.FileType
{
@@ -11,11 +13,7 @@ namespace BinaryObjectScanner.FileType
public class XZ : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,12 +25,9 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
#if NET462_OR_GREATER
try
{
// Create a temp output directory
@@ -55,6 +50,9 @@ namespace BinaryObjectScanner.FileType
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.FileType
public class XZP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -27,11 +23,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -18,11 +18,7 @@ namespace BinaryObjectScanner.GameEngine
public class RenderWare : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -1,7 +0,0 @@
namespace BinaryObjectScanner.GameEngine
{
/// <summary>
/// This class exists for reflection purposes and should not be used
/// </summary>
public sealed class _DUMMY { }
}

View File

@@ -18,11 +18,7 @@ namespace BinaryObjectScanner
/// <summary>
/// Cache for all IPathCheck types
/// </summary>
#if NET48
public static IEnumerable<IPathCheck> PathCheckClasses
#else
public static IEnumerable<IPathCheck?> PathCheckClasses
#endif
{
get
{
@@ -40,11 +36,7 @@ namespace BinaryObjectScanner
/// <summary>
/// Cache for all IPathCheck types
/// </summary>
#if NET48
private static IEnumerable<IPathCheck> pathCheckClasses;
#else
private static IEnumerable<IPathCheck?>? pathCheckClasses;
#endif
#endregion
@@ -56,11 +48,7 @@ namespace BinaryObjectScanner
/// <param name="path">Path of the file or directory to check</param>
/// <param name="scanner">Scanner object to use for options and scanning</param>
/// <returns>Set of protections in file, null on error</returns>
#if NET48
public static ConcurrentDictionary<string, ConcurrentQueue<string>> HandlePathChecks(string path, IEnumerable<string> files)
#else
public static ConcurrentDictionary<string, ConcurrentQueue<string>> HandlePathChecks(string path, IEnumerable<string>? files)
#endif
{
// Create the output dictionary
var protections = new ConcurrentDictionary<string, ConcurrentQueue<string>>();
@@ -91,11 +79,7 @@ namespace BinaryObjectScanner
/// <param name="stream">Stream to scan the contents of</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Set of protections in file, null on error</returns>
#if NET48
public static ConcurrentQueue<string> HandleDetectable(IDetectable impl, string fileName, Stream stream, bool includeDebug)
#else
public static ConcurrentQueue<string>? HandleDetectable(IDetectable impl, string fileName, Stream stream, bool includeDebug)
#endif
{
var protection = impl.Detect(stream, fileName, includeDebug);
return ProcessProtectionString(protection);
@@ -109,11 +93,7 @@ namespace BinaryObjectScanner
/// <param name="stream">Stream to scan the contents of</param>
/// <param name="scanner">Scanner object to use on extractable contents</param>
/// <returns>Set of protections in file, null on error</returns>
#if NET48
public static ConcurrentDictionary<string, ConcurrentQueue<string>> HandleExtractable(IExtractable impl, string fileName, Stream stream, Scanner scanner)
#else
public static ConcurrentDictionary<string, ConcurrentQueue<string>>? HandleExtractable(IExtractable impl, string fileName, Stream? stream, Scanner scanner)
#endif
{
// If the extractable file itself fails
try
@@ -155,11 +135,7 @@ namespace BinaryObjectScanner
/// <param name="impl">IPathCheck class representing the file type</param>
/// <param name="path">Path of the file or directory to check</param>
/// <returns>Set of protections in path, null on error</returns>
#if NET48
private static ConcurrentQueue<string> PerformCheck(this IPathCheck impl, string path, IEnumerable<string> files)
#else
private static ConcurrentQueue<string>? PerformCheck(this IPathCheck impl, string? path, IEnumerable<string>? files)
#endif
{
// If we have an invalid path
if (string.IsNullOrWhiteSpace(path))
@@ -171,7 +147,7 @@ namespace BinaryObjectScanner
// If we have a file path
if (File.Exists(path))
{
var protection = impl.CheckFilePath(path);
var protection = impl.CheckFilePath(path!);
var subProtections = ProcessProtectionString(protection);
if (subProtections != null)
protections.AddRange(subProtections);
@@ -180,7 +156,7 @@ namespace BinaryObjectScanner
// If we have a directory path
if (Directory.Exists(path) && files?.Any() == true)
{
var subProtections = impl.CheckDirectoryPath(path, files);
var subProtections = impl.CheckDirectoryPath(path!, files);
if (subProtections != null)
protections.AddRange(subProtections);
}
@@ -195,33 +171,17 @@ namespace BinaryObjectScanner
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>()
#else
private static IEnumerable<T?> InitCheckClasses<T>()
#endif
{
return InitCheckClasses<T>(typeof(GameEngine._DUMMY).Assembly)
.Concat(InitCheckClasses<T>(typeof(Packer._DUMMY).Assembly))
.Concat(InitCheckClasses<T>(typeof(Protection._DUMMY).Assembly));
}
private static IEnumerable<T?> InitCheckClasses<T>() =>
InitCheckClasses<T>(typeof(Handler).Assembly);
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>(Assembly assembly)
#else
private static IEnumerable<T?> InitCheckClasses<T>(Assembly assembly)
#endif
{
return assembly.GetTypes()?
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)?
#if NET48
.Select(t => (T)Activator.CreateInstance(t)) ?? Array.Empty<T>();
#else
.Select(t => (T?)Activator.CreateInstance(t)) ?? Array.Empty<T>();
#endif
.Select(t => (T?)Activator.CreateInstance(t)) ?? [];
}
#endregion
@@ -233,11 +193,7 @@ namespace BinaryObjectScanner
/// </summary>
/// <param name="protection">Protection string to process</param>
/// <returns>Set of protections parsed, null on error</returns>
#if NET48
private static ConcurrentQueue<string> ProcessProtectionString(string protection)
#else
private static ConcurrentQueue<string>? ProcessProtectionString(string? protection)
#endif
{
// If we have an invalid protection string
if (string.IsNullOrWhiteSpace(protection))
@@ -247,7 +203,7 @@ namespace BinaryObjectScanner
var protections = new ConcurrentQueue<string>();
// If we have an indicator of multiple protections
if (protection.Contains(";"))
if (protection!.Contains(";"))
{
var splitProtections = protection.Split(';');
protections.AddRange(splitProtections);

View File

@@ -12,10 +12,6 @@
/// <param name="fileContent">Byte array representing the file contents</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>String containing any protections found in the file</returns>
#if NET48
string CheckContents(string file, byte[] fileContent, bool includeDebug);
#else
string? CheckContents(string file, byte[] fileContent, bool includeDebug);
#endif
}
}

View File

@@ -14,11 +14,7 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Detected file or protection type, null on error</returns>
/// <remarks>Ideally, this should just point to the other detect implementation.</remarks>
#if NET48
string Detect(string file, bool includeDebug);
#else
string? Detect(string file, bool includeDebug);
#endif
/// <summary>
/// Check if a stream is detected as this file type
@@ -27,10 +23,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="file">Path to the input file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Detected file or protection type, null on error</returns>
#if NET48
string Detect(Stream stream, string file, bool includeDebug);
#else
string? Detect(Stream stream, string file, bool includeDebug);
#endif
}
}

View File

@@ -16,11 +16,7 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
/// <remarks>Ideally, this should just point to the other extract implementation.</remarks>
#if NET48
string Extract(string file, bool includeDebug);
#else
string? Extract(string file, bool includeDebug);
#endif
/// <summary>
/// Extract a stream to a temporary path, if possible
@@ -29,10 +25,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="file">Path to the input file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
#if NET48
string Extract(Stream stream, string file, bool includeDebug);
#else
string? Extract(Stream? stream, string file, bool includeDebug);
#endif
}
}

View File

@@ -14,10 +14,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="lex">LinearExecutable representing the read-in file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>String containing any protections found in the file</returns>
#if NET48
string CheckLinearExecutable(string file, LinearExecutable lex, bool includeDebug);
#else
string? CheckLinearExecutable(string file, LinearExecutable lex, bool includeDebug);
#endif
}
}

View File

@@ -14,10 +14,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="mz">MSDOS representing the read-in file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>String containing any protections found in the file</returns>
#if NET48
string CheckMSDOSExecutable(string file, MSDOS mz, bool includeDebug);
#else
string? CheckMSDOSExecutable(string file, MSDOS mz, bool includeDebug);
#endif
}
}

View File

@@ -14,10 +14,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="nex">NewExecutable representing the read-in file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>String containing any protections found in the file</returns>
#if NET48
string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug);
#else
string? CheckNewExecutable(string file, NewExecutable nex, bool includeDebug);
#endif
}
}

View File

@@ -17,21 +17,13 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="path">Path to check for protection indicators</param>
/// <param name="files">Enumerable of strings representing files in a directory</param>
/// <remarks>This can do some limited content checking as well, but it's suggested to use a content check instead, if possible</remarks>
#if NET48
ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files);
#else
ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files);
#endif
/// <summary>
/// Check a file path for protections based on path name
/// </summary>
/// <param name="path">Path to check for protection indicators</param>
/// <remarks>This can do some limited content checking as well, but it's suggested to use a content check instead, if possible</remarks>
#if NET48
string CheckFilePath(string path);
#else
string? CheckFilePath(string path);
#endif
}
}

View File

@@ -14,10 +14,6 @@ namespace BinaryObjectScanner.Interfaces
/// <param name="pex">PortableExecutable representing the read-in file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>String containing any protections found in the file</returns>
#if NET48
string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug);
#else
string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug);
#endif
}
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class ASPack : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -55,11 +51,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -71,11 +63,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class AdvancedInstaller : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -34,11 +30,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -50,11 +42,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class Armadillo : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -46,11 +42,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -62,11 +54,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class AutoPlayMediaStudio : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -38,11 +34,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -54,11 +46,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}
@@ -68,12 +56,12 @@ namespace BinaryObjectScanner.Packer
// Check the product version explicitly
var version = pex.ProductVersion;
if (!string.IsNullOrEmpty(version))
return version;
return version!;
// Check the internal versions
version = pex.GetInternalVersion();
if (!string.IsNullOrEmpty(version))
return version;
return version!;
return "(Unknown Version)";
}

View File

@@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER
using ICSharpCode.SharpZipLib.Zip.Compression;
#endif
using SabreTools.Matching;
using SabreTools.Serialization.Wrappers;
@@ -15,11 +17,7 @@ namespace BinaryObjectScanner.Packer
public class CExe : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -54,11 +52,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -70,11 +64,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -100,6 +90,7 @@ namespace BinaryObjectScanner.Packer
try
{
// Inflate the data into the buffer
#if NET462_OR_GREATER
Inflater inflater = new Inflater();
inflater.SetInput(payload);
data = new byte[payload.Length * 4];
@@ -107,6 +98,9 @@ namespace BinaryObjectScanner.Packer
// Trim the buffer to the proper size
data = new ReadOnlySpan<byte>(data, 0, read).ToArray();
#else
data = null;
#endif
}
catch
{

View File

@@ -13,11 +13,7 @@ namespace BinaryObjectScanner.Packer
public class EXEStealth : IContentCheck, IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
#else
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
#endif
{
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
@@ -42,11 +38,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -83,11 +75,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -99,11 +87,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -14,11 +14,7 @@ namespace BinaryObjectScanner.Packer
public class EmbeddedExecutable : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -33,11 +29,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -49,11 +41,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class GenteeInstaller : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -37,11 +33,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -53,11 +45,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -13,11 +13,7 @@ namespace BinaryObjectScanner.Packer
public class HyperTechCrackProof : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -36,11 +32,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -52,11 +44,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.Packer
public class InnoSetup : IExtractable, INewExecutableCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#else
public string? CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#endif
{
// Check for "Inno" in the reserved words
if (nex.Model.Stub?.Header?.Reserved2?[4] == 0x6E49 && nex.Model.Stub?.Header?.Reserved2?[5] == 0x6F6E)
@@ -32,11 +28,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -62,11 +54,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -78,11 +66,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.Packer
public class InstallAnywhere : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -33,11 +29,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -49,11 +41,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}
@@ -63,7 +51,7 @@ namespace BinaryObjectScanner.Packer
// Check the internal versions
var version = pex.GetInternalVersion();
if (!string.IsNullOrEmpty(version))
return version;
return version!;
return "(Unknown Version)";
}

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.Packer
{
//TODO: Add exact version detection for Windows builds, make sure versions before 3.X are detected as well, and detect the Mac builds.
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -35,11 +31,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -51,11 +43,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -9,11 +9,7 @@ namespace BinaryObjectScanner.Packer
public class IntelInstallationFramework : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -38,11 +34,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -54,11 +46,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class MicrosoftCABSFX : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -52,11 +48,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -68,11 +60,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.Packer
public class NSIS : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -22,7 +18,7 @@ namespace BinaryObjectScanner.Packer
return null;
var description = pex.AssemblyDescription;
if (!string.IsNullOrWhiteSpace(description) && description.StartsWith("Nullsoft Install System"))
if (!string.IsNullOrWhiteSpace(description) && description!.StartsWith("Nullsoft Install System"))
return $"NSIS {description.Substring("Nullsoft Install System".Length).Trim()}";
// Get the .data/DATA section strings, if they exist
@@ -37,11 +33,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -53,11 +45,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -18,11 +18,7 @@ namespace BinaryObjectScanner.Packer
{
// TODO: Find samples of NeoLite 1.X.
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -41,11 +37,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
// TODO: Add extraction
if (!File.Exists(file))
@@ -58,11 +50,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -9,11 +9,7 @@ namespace BinaryObjectScanner.Packer
public class PECompact : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -46,11 +42,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -62,11 +54,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -9,11 +9,7 @@ namespace BinaryObjectScanner.Packer
public class PEtite : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -29,11 +25,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -45,11 +37,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Packer
public class SetupFactory : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -43,11 +39,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -59,11 +51,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}
@@ -73,12 +61,12 @@ namespace BinaryObjectScanner.Packer
// Check the product version explicitly
var version = pex.ProductVersion;
if (!string.IsNullOrEmpty(version))
return version;
return version!;
// Check the internal versions
version = pex.GetInternalVersion();
if (!string.IsNullOrEmpty(version))
return version;
return version!;
return "(Unknown Version)";
}

View File

@@ -9,11 +9,7 @@ namespace BinaryObjectScanner.Packer
public class SevenZipSFX : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -50,11 +46,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -66,11 +58,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -9,11 +9,7 @@ namespace BinaryObjectScanner.Packer
public class Shrinker : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -30,11 +26,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -46,11 +38,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -17,11 +17,7 @@ namespace BinaryObjectScanner.Packer
private static readonly Regex _upxVersionMatch = new Regex(@"^([0-9]\.[0-9]{2})$", RegexOptions.Compiled);
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -68,11 +64,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -84,11 +76,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -3,20 +3,18 @@ using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
using SharpCompress.Readers;
#endif
namespace BinaryObjectScanner.Packer
{
public class WinRARSFX : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -35,11 +33,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -51,12 +45,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
#if NET462_OR_GREATER
try
{
// Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
@@ -93,6 +84,9 @@ namespace BinaryObjectScanner.Packer
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
}
}

View File

@@ -4,19 +4,17 @@ using System.Linq;
using System.Text;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
#if NET462_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
#endif
namespace BinaryObjectScanner.Packer
{
public class WinZipSFX : IExtractable, INewExecutableCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#else
public string? CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#endif
{
// If the resident-name table doesnt exist
if (nex.Model.ResidentNameTable == null)
@@ -40,11 +38,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -69,11 +63,7 @@ namespace BinaryObjectScanner.Packer
// TODO: Find a way to generically detect 2.X versions and improve exact version detection for SFX PE versions bundled with WinZip 11+
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -85,12 +75,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
#if NET462_OR_GREATER
try
{
// Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
@@ -127,6 +114,9 @@ namespace BinaryObjectScanner.Packer
if (includeDebug) Console.WriteLine(ex);
return null;
}
#else
return null;
#endif
}
/// <summary>
@@ -134,11 +124,7 @@ namespace BinaryObjectScanner.Packer
/// </summary>
/// TODO: Reduce the checks to only the ones that differ between versions
/// TODO: Research to see if the versions are embedded elsewhere in these files
#if NET48
private string GetNEHeaderVersion(NewExecutable nex)
#else
private string? GetNEHeaderVersion(NewExecutable nex)
#endif
{
#region 2.0 Variants
@@ -696,11 +682,7 @@ namespace BinaryObjectScanner.Packer
/// Get the version from the PE export directory table value combinations
/// </summary>
/// TODO: Research to see if the versions are embedded elsewhere in these files
#if NET48
private string GetPEExportDirectoryVersion(PortableExecutable pex)
#else
private string? GetPEExportDirectoryVersion(PortableExecutable pex)
#endif
{
string sfxFileName = pex.Model.ExportTable?.ExportDirectoryTable?.Name ?? string.Empty;
uint sfxTimeDateStamp = pex.Model.ExportTable?.ExportDirectoryTable?.TimeDateStamp ?? uint.MaxValue;

View File

@@ -14,11 +14,7 @@ namespace BinaryObjectScanner.Packer
public class WiseInstaller : IExtractable, INewExecutableCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#else
public string? CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#endif
{
// If we match a known header
if (MatchesNEVersion(nex) != null)
@@ -44,11 +40,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -81,11 +73,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -97,11 +85,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
try
{
@@ -129,11 +113,7 @@ namespace BinaryObjectScanner.Packer
/// </summary>
/// <param name="nex">New executable to check</param>
/// <returns>True if it matches a known version, false otherwise</returns>
#if NET48
private FormatProperty MatchesNEVersion(NewExecutable nex)
#else
private FormatProperty? MatchesNEVersion(NewExecutable nex)
#endif
{
// TODO: Offset is _not_ the EXE header address, rather where the data starts. Fix this.
switch (nex.Model.Stub?.Header?.NewExeHeaderAddr)
@@ -190,11 +170,7 @@ namespace BinaryObjectScanner.Packer
/// </summary>
/// <param name="pex">Portable executable to check</param>
/// <returns>True if it matches a known version, false otherwise</returns>
#if NET48
private FormatProperty GetPEFormat(PortableExecutable pex)
#else
private FormatProperty? GetPEFormat(PortableExecutable pex)
#endif
{
if (pex.OverlayAddress == 0x6e00
&& pex.GetFirstSection(".text")?.VirtualSize == 0x3cf4
@@ -241,11 +217,7 @@ namespace BinaryObjectScanner.Packer
/// <param name="file">Path to the input file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>True if it matches a known version, false otherwise</returns>
#if NET48
private string ExtractNewExecutable(NewExecutable nex, string file, bool includeDebug)
#else
private string? ExtractNewExecutable(NewExecutable nex, string file, bool includeDebug)
#endif
{
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
@@ -284,11 +256,7 @@ namespace BinaryObjectScanner.Packer
/// <param name="file">Path to the input file</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>True if it matches a known version, false otherwise</returns>
#if NET48
private string ExtractPortableExecutable(PortableExecutable pex, string file, bool includeDebug)
#else
private string? ExtractPortableExecutable(PortableExecutable pex, string file, bool includeDebug)
#endif
{
try
{

View File

@@ -1,7 +0,0 @@
namespace BinaryObjectScanner.Packer
{
/// <summary>
/// This class exists for reflection purposes and should not be used
/// </summary>
public sealed class _DUMMY { }
}

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.Packer
public class dotFuscator : IExtractable, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -33,11 +29,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -49,11 +41,7 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream? stream, string file, bool includeDebug)
#endif
{
return null;
}

View File

@@ -0,0 +1,110 @@
#if NET40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Threading;
using System.Diagnostics;
namespace System
{
/// <summary>
/// Provides an IProgress{T} that invokes callbacks for each reported progress value.
/// </summary>
/// <typeparam name="T">Specifies the type of the progress report value.</typeparam>
/// <remarks>
/// Any handler provided to the constructor or event handlers registered with
/// the <see cref="ProgressChanged"/> event are invoked through a
/// <see cref="SynchronizationContext"/> instance captured
/// when the instance is constructed. If there is no current SynchronizationContext
/// at the time of construction, the callbacks will be invoked on the ThreadPool.
/// </remarks>
/// <see href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Progress.cs"/>
public class Progress<T> : IProgress<T> where T : EventArgs
{
/// <summary>The synchronization context captured upon construction. This will never be null.</summary>
private readonly SynchronizationContext _synchronizationContext;
/// <summary>The handler specified to the constructor. This may be null.</summary>
private readonly Action<T>? _handler;
/// <summary>A cached delegate used to post invocation to the synchronization context.</summary>
private readonly SendOrPostCallback _invokeHandlers;
/// <summary>Initializes the <see cref="Progress{T}"/>.</summary>
public Progress()
{
// Capture the current synchronization context.
// If there is no current context, we use a default instance targeting the ThreadPool.
_synchronizationContext = SynchronizationContext.Current ?? ProgressStatics.DefaultContext;
Debug.Assert(_synchronizationContext != null);
_invokeHandlers = new SendOrPostCallback(InvokeHandlers);
}
/// <summary>Initializes the <see cref="Progress{T}"/> with the specified callback.</summary>
/// <param name="handler">
/// A handler to invoke for each reported progress value. This handler will be invoked
/// in addition to any delegates registered with the <see cref="ProgressChanged"/> event.
/// Depending on the <see cref="SynchronizationContext"/> instance captured by
/// the <see cref="Progress{T}"/> at construction, it's possible that this handler instance
/// could be invoked concurrently with itself.
/// </param>
/// <exception cref="ArgumentNullException">The <paramref name="handler"/> is null (<see langword="Nothing" /> in Visual Basic).</exception>
public Progress(Action<T> handler) : this()
{
if (handler == null)
throw new ArgumentNullException(nameof(handler));
_handler = handler;
}
/// <summary>Raised for each reported progress value.</summary>
/// <remarks>
/// Handlers registered with this event will be invoked on the
/// <see cref="SynchronizationContext"/> captured when the instance was constructed.
/// </remarks>
public event EventHandler<T>? ProgressChanged;
/// <summary>Reports a progress change.</summary>
/// <param name="value">The value of the updated progress.</param>
protected virtual void OnReport(T value)
{
// If there's no handler, don't bother going through the sync context.
// Inside the callback, we'll need to check again, in case
// an event handler is removed between now and then.
Action<T>? handler = _handler;
EventHandler<T>? changedEvent = ProgressChanged;
if (handler != null || changedEvent != null)
{
// Post the processing to the sync context.
// (If T is a value type, it will get boxed here.)
_synchronizationContext.Post(_invokeHandlers, value);
}
}
/// <summary>Reports a progress change.</summary>
/// <param name="value">The value of the updated progress.</param>
void IProgress<T>.Report(T value) { OnReport(value); }
/// <summary>Invokes the action and event callbacks.</summary>
/// <param name="state">The progress value.</param>
private void InvokeHandlers(object? state)
{
T value = (T)state!;
Action<T>? handler = _handler;
EventHandler<T>? changedEvent = ProgressChanged;
handler?.Invoke(value);
changedEvent?.Invoke(this, value);
}
}
/// <summary>Holds static values for <see cref="Progress{T}"/>.</summary>
/// <remarks>This avoids one static instance per type T.</remarks>
internal static class ProgressStatics
{
/// <summary>A default synchronization context that targets the ThreadPool.</summary>
internal static readonly SynchronizationContext DefaultContext = new SynchronizationContext();
}
}
#endif

View File

@@ -11,11 +11,7 @@ namespace BinaryObjectScanner.Protection
public class ActiveMARK : IContentCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
#else
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
#endif
{
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
@@ -38,11 +34,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -20,11 +20,7 @@ namespace BinaryObjectScanner.Protection
public class AegiSoft : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -71,11 +67,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -88,15 +80,11 @@ namespace BinaryObjectScanner.Protection
// These files are "Asc001.dll", "Asc002.dll", "Asc003.dll", "Asc005.dll", and "Asc006.exe" (Found in Redump entry 73521/IA item "Nova_HoyleCasino99USA").
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -16,26 +16,18 @@ namespace BinaryObjectScanner.Protection
public class AlphaDVD : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("PlayDVD.exe", useEndsWith: true), "Alpha-DVD (Unconfirmed - Please report to us on Github)"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -44,11 +44,7 @@ namespace BinaryObjectScanner.Protection
public class AlphaROM : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// TODO: Add support for detecting Alpha-ROM found in older games made with the RealLive engine.
// TODO: Add version detection for Alpha-ROM.

View File

@@ -13,11 +13,7 @@ namespace BinaryObjectScanner.Protection
public class Bitpool : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -38,15 +34,11 @@ namespace BinaryObjectScanner.Protection
}, "Bitpool"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -41,11 +41,7 @@ namespace BinaryObjectScanner.Protection
public class ByteShield : IPortableExecutableCheck, IPathCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -134,11 +130,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
// TODO: Investigate reference to "bbz650.tmp" in "Byteshield.dll" (Redump entry 6236)
// Files with the ".bbz" extension are associated with ByteShield, but the extenstion is known to be used in other places as well.
@@ -148,15 +140,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("Byteshield.ini", useEndsWith: true), "ByteShield"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
// TODO: Investigate reference to "bbz650.tmp" in "Byteshield.dll" (Redump entry 6236)
// Files with the ".bbz" extension are associated with ByteShield, but the extenstion is known to be used in other places as well.

View File

@@ -6,11 +6,7 @@ namespace BinaryObjectScanner.Protection
public class CDCheck : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -67,11 +67,7 @@ namespace BinaryObjectScanner.Protection
{
// TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games".
/// <inheritdoc/>
#if NET48
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
#else
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
#endif
{
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
@@ -101,11 +97,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#else
public string? CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
#endif
{
// TODO: Don't read entire file
var data = nex.ReadArbitraryRange();
@@ -149,11 +141,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -194,11 +182,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
// TODO: Original had "CDCOPS.DLL" required and all the rest in a combined OR
var matchers = new List<PathMatchSet>
@@ -215,15 +199,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch(".Qz", matchExact: true, useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -242,17 +222,19 @@ namespace BinaryObjectScanner.Protection
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
#if NET48
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
#else
public static string? GetVersion(string file, byte[]? fileContent, List<int> positions)
#endif
{
// If we have no content
if (fileContent == null)
return null;
#if NET40
byte[] versionBytes = new byte[4];
Array.Copy(fileContent, positions[0] + 15, versionBytes, 0, 4);
char[] version = versionBytes.Select(b => (char)b).ToArray();
#else
char[] version = new ArraySegment<byte>(fileContent, positions[0] + 15, 4).Select(b => (char)b).ToArray();
#endif
if (version[0] == 0x00)
return string.Empty;

View File

@@ -24,11 +24,7 @@ namespace BinaryObjectScanner.Protection
public class CDGuard : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -59,11 +55,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -71,15 +63,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("cdguard.dll", useEndsWith: true), "CD-Guard Copy Protection System"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -7,11 +7,7 @@ namespace BinaryObjectScanner.Protection
public class CDKey : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -27,11 +27,7 @@ namespace BinaryObjectScanner.Protection
public class CDLock : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -65,11 +61,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -81,15 +73,11 @@ namespace BinaryObjectScanner.Protection
// There is also a "$$$$$$$$.$$$" file present on some discs, but it isn't known if this is directly related to CD-Lock (Redump entries 37788 and 43221).
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -17,11 +17,7 @@ namespace BinaryObjectScanner.Protection
public class CDProtector : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -39,15 +35,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("Track#1 - Track#2 Cd-Protector.wav", useEndsWith: true), "CD-Protector"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -8,11 +8,7 @@ namespace BinaryObjectScanner.Protection
public class CDSHiELDSE : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -8,11 +8,7 @@ namespace BinaryObjectScanner.Protection
public class CDX : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
// TODO: Verify if these are OR or AND
var matchers = new List<PathMatchSet>
@@ -22,15 +18,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("CHKCDXNT.DLL", useEndsWith: true), "CD-X (Unconfirmed - Please report to us on Github)"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -8,11 +8,7 @@ namespace BinaryObjectScanner.Protection
public class CactusDataShield : IContentCheck
{
/// <inheritdoc/>
#if NET48
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
#else
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
#endif
{
// TODO: Limit these checks to Mac binaries
// TODO: Obtain a sample to find where this string is in a typical executable

View File

@@ -15,11 +15,7 @@ namespace BinaryObjectScanner.Protection
public class CengaProtectDVD : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -57,11 +53,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -70,15 +62,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("cenega.dll", useEndsWith: true), "Cenega ProtectDVD"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -13,7 +13,7 @@ namespace BinaryObjectScanner.Protection
/// It requires the use of a registration code that is unique to each individual user (https://web.archive.org/web/20031210093259/http://www.chosenbytes.com/codemain.php).
/// As an advertising point, ChosenBytes apparently held a contest with a cash prize to see if a protected file could be cracked (https://web.archive.org/web/20031106163334/http://www.chosenbytes.com/challenge.php).
///
/// Previous versions of BurnOutSharp incorrectly reported this DRM as "CodeLock / CodeLok / CopyLok". It was later discovered that due to the similar names, two entirely different DRM were erroneously lumped together.
/// Previous versions of BinaryObjectScanner incorrectly reported this DRM as "CodeLock / CodeLok / CopyLok". It was later discovered that due to the similar names, two entirely different DRM were erroneously lumped together.
/// Not only is "CodeLok / CopyLok" an entirely separate form of DRM, but "CodeLock" (as opposed to "Code-Lock") appears to refer specifically to another unrelated DRM (https://web.archive.org/web/20031106033758/http://www.codelock.co.nz/).
/// Also not to be confused with https://www.youtube.com/watch?v=AHqdgk0uJyc.
///
@@ -23,11 +23,7 @@ namespace BinaryObjectScanner.Protection
public class ChosenBytesCodeLock : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -58,11 +54,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -73,15 +65,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("Code-Lock Wizard.exe", useEndsWith: true), "ChosenBytes Code-Lock"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -8,11 +8,7 @@ namespace BinaryObjectScanner.Protection
public class CopyKiller : IContentCheck, IPathCheck
{
/// <inheritdoc/>
#if NET48
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
#else
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
#endif
{
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
@@ -34,11 +30,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
// TODO: The following checks are overly broad and should be refined
// TODO: Look into .PFF files as an indicator. At least one disc has those oversized files
@@ -47,15 +39,11 @@ namespace BinaryObjectScanner.Protection
//new PathMatchSet(new PathMatch("Autorun.dat", useEndsWith: true), "CopyKiller"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
// TODO: The following checks are overly broad and should be refined
// TODO: Look into .PFF files as an indicator. At least one disc has those oversized files

View File

@@ -14,7 +14,7 @@ namespace BinaryObjectScanner.Protection
/// At least one disc with CopyLok appears to contain an excerpt of the poem "Jabberwocky" by Lewis Carroll in the raw sector data (http://forum.redump.org/post/54050/#p54050).
/// According to the Readme for poxylok (https://gf.wiretarget.com/copylok.htm), some version of Gangsters 2 may have this protection.
///
/// Previous versions of BurnOutSharp incorrectly reported this DRM as "CodeLock / CodeLok / CopyLok". It was later discovered that due to the similar names, two entirely different DRM were erroneously lumped together.
/// Previous versions of BinaryObjectScanner incorrectly reported this DRM as "CodeLock / CodeLok / CopyLok". It was later discovered that due to the similar names, two entirely different DRM were erroneously lumped together.
/// "CodeLock" (in this case actually referring to "Code-Lock") is an entirely separate form of DRM, with the existing check now getting used separately.
/// Also not to be confused with https://en.wikipedia.org/wiki/Rob_Northen_copylock.
///
@@ -23,11 +23,7 @@ namespace BinaryObjectScanner.Protection
public class CopyLok : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.Protection
public class CrypKey : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -12,11 +12,7 @@ namespace BinaryObjectScanner.Protection
public class Cucko : IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;

View File

@@ -8,26 +8,18 @@ namespace BinaryObjectScanner.Protection
public class DVDCrypt : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("DvdCrypt.pdb", useEndsWith: true), "DVD Crypt (Unconfirmed - Please report to us on Github)"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -10,11 +10,7 @@ namespace BinaryObjectScanner.Protection
public class DVDMoviePROTECT : IPathCheck
{
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var protections = new ConcurrentQueue<string>();
if (files == null)
@@ -42,11 +38,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
return null;
}

View File

@@ -31,11 +31,7 @@ namespace BinaryObjectScanner.Protection
// https://www.pcgamingwiki.com/wiki/Denuvo#Redeem.exe
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -259,11 +255,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -278,15 +270,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("Denuvo Anti-Cheat Installer.exe", useEndsWith: true), "Denuvo Anti-Cheat"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: false);
return MatchUtil.GetAllMatches(files, matchers, any: false);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -27,11 +27,7 @@ namespace BinaryObjectScanner.Protection
public class DigiGuard : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -57,11 +53,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -71,15 +63,11 @@ namespace BinaryObjectScanner.Protection
// There are at least two additional specifically named DecryptWrap files, "DecryptWrapTW2000.exe" and "DecryptWrapTW2KCode.exe" in IA item "Nova_DellBigWIGDVD_USA"/Redump entry 108588.
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -22,11 +22,7 @@ namespace BinaryObjectScanner.Protection
// https://www.gamecopyworld.com/games/pc_pc_calcio_2000.shtml
// https://www.gamecopyworld.com/games/pc_pc_futbol_2000.shtml
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -42,15 +38,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch(Path.Combine("XCONTROL", "COMPSCO._01").Replace("\\", "/"), useEndsWith: true), "Dinamic Multimedia Protection/LockBlocks [Check disc for 2 physical rings]"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{

View File

@@ -38,11 +38,7 @@ namespace BinaryObjectScanner.Protection
{
// TODO: Add checks for the game executables, which seem likely to contain some kind of indicators that can be checked for. The game executables all seem to import "Ord(1)" from one of the varying DLLs present.
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -141,11 +137,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -171,15 +163,11 @@ namespace BinaryObjectScanner.Protection
}, "DiscGuard"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: false);
return MatchUtil.GetAllMatches(files, matchers, any: false);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
var matchers = new List<PathMatchSet>
{
@@ -200,31 +188,27 @@ namespace BinaryObjectScanner.Protection
// Check the internal versions
var version = pex.GetInternalVersion();
if (!string.IsNullOrEmpty(version))
return version;
return version!;
return "(Unknown Version)";
}
/// <inheritdoc/>
#if NET48
private string GetVersion(string file, byte[] fileContent, List<int> positions)
#else
private string? GetVersion(string file, byte[]? fileContent, List<int> positions)
#endif
{
// If we have no content
if (fileContent == null)
return null;
// Check the internal versions
string version = GetInternalVersion(file, Array.Empty<string>());
string version = GetInternalVersion(file);
if (!string.IsNullOrEmpty(version))
return version;
return string.Empty;
}
private string GetInternalVersion(string firstMatchedString, IEnumerable<string> files)
private string GetInternalVersion(string firstMatchedString)
{
try
{

View File

@@ -22,11 +22,7 @@ namespace BinaryObjectScanner.Protection
{
// TODO: Add support for detecting older versions, especially versions made before Easy Anti-Cheat was purchased by Epic Games.
/// <inheritdoc/>
#if NET48
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#else
public string? CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
#endif
{
// Get the sections from the executable, if possible
var sections = pex.Model.SectionTable;
@@ -35,17 +31,17 @@ namespace BinaryObjectScanner.Protection
var name = pex.FileDescription;
// Found in "VideoHorrorSociety.exe" ("Video Horror Society", Patch 1.0.70309, Steam).
if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat Bootstrapper (EOS)"))
if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat Bootstrapper (EOS)"))
return "Easy Anti-Cheat (EOS Version)";
// Found in "EasyAntiCheat_EOS_Setup.exe" ("Video Horror Society", Patch 1.0.70309, Steam) and "EasyAntiCheat_EOS.exe", which is found installed in "Program Files (x86)\EasyAntiCheat_EOS".
else if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat Service (EOS)"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat Service (EOS)"))
return "Easy Anti-Cheat (EOS Version)";
// These two generic checks are both general enough to detect the majority of files known to contain Easy Anti-Cheat, as well as specific enough to avoid false positives.
else if (!string.IsNullOrEmpty(name) && name.Contains("EasyAntiCheat"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("EasyAntiCheat"))
return "Easy Anti-Cheat";
else if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat"))
return "Easy Anti-Cheat";
// For documentation, known exact File Descriptions and their associated files are listed below:
@@ -61,17 +57,17 @@ namespace BinaryObjectScanner.Protection
name = pex.ProductName;
// Found in multiple files, including "VideoHorrorSociety.exe" ("Video Horror Society", Patch 1.0.70309, Steam) and "start_protected_game.exe" ("VRChat", Version 2022.2.2p2, Oculus).
if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat Bootstrapper (EOS)"))
if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat Bootstrapper (EOS)"))
return "Easy Anti-Cheat (EOS Version)";
// Found in multiple files, including "EasyAntiCheat_EOS_Setup.exe" ("Video Horror Society", Patch 1.0.70309, Steam; "VRChat", Version 2022.2.2p2, Oculus) and "EasyAntiCheat.exe", which is found installed in "Program Files (x86)\EasyAntiCheat_EOS".
else if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat Service (EOS)"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat Service (EOS)"))
return "Easy Anti-Cheat (EOS Version)";
// These two generic checks are both general enough to detect the majority of files known to contain Easy Anti-Cheat, as well as specific enough to avoid false positives.
else if (!string.IsNullOrEmpty(name) && name.Contains("EasyAntiCheat"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("EasyAntiCheat"))
return "Easy Anti-Cheat";
else if (!string.IsNullOrEmpty(name) && name.Contains("Easy Anti-Cheat"))
else if (!string.IsNullOrEmpty(name) && name!.Contains("Easy Anti-Cheat"))
return "Easy Anti-Cheat";
// For documentation, known exact Product Names and their associated files are listed below:
@@ -84,11 +80,7 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
#if NET48
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
#else
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string>? files)
#endif
{
// TODO: Search for the presence of the folder "EasyAntiCheat" specifically, which is present in every checked version so far.
var matchers = new List<PathMatchSet>
@@ -131,15 +123,11 @@ namespace BinaryObjectScanner.Protection
new PathMatchSet(new PathMatch("easyanticheat_x64.so", useEndsWith: true), "Easy Anti-Cheat"),
};
return MatchUtil.GetAllMatches(files ?? System.Array.Empty<string>(), matchers, any: true);
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
#if NET48
public string CheckFilePath(string path)
#else
public string? CheckFilePath(string path)
#endif
{
// TODO: Search for the presence of the folder "EasyAntiCheat" specifically, which is present in every checked version so far.
var matchers = new List<PathMatchSet>

Some files were not shown because too many files have changed in this diff Show More