diff --git a/BinaryObjectScanner/BinaryObjectScanner.csproj b/BinaryObjectScanner/BinaryObjectScanner.csproj index 729d0226..6776bb6f 100644 --- a/BinaryObjectScanner/BinaryObjectScanner.csproj +++ b/BinaryObjectScanner/BinaryObjectScanner.csproj @@ -2,7 +2,7 @@ - net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 true false @@ -58,6 +58,11 @@ + + + + + @@ -69,13 +74,11 @@ - - diff --git a/BinaryObjectScanner/FileType/BFPK.cs b/BinaryObjectScanner/FileType/BFPK.cs index 41c103af..4fbd8014 100644 --- a/BinaryObjectScanner/FileType/BFPK.cs +++ b/BinaryObjectScanner/FileType/BFPK.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Compressors; using SharpCompress.Compressors.Deflate; #endif @@ -123,7 +123,7 @@ namespace BinaryObjectScanner.FileType { fs.Write(data, 0, compressedSize); } -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP else { MemoryStream ms = new MemoryStream(data); diff --git a/BinaryObjectScanner/FileType/BSP.cs b/BinaryObjectScanner/FileType/BSP.cs index 1af8a2ea..f4d49b07 100644 --- a/BinaryObjectScanner/FileType/BSP.cs +++ b/BinaryObjectScanner/FileType/BSP.cs @@ -109,7 +109,7 @@ namespace BinaryObjectScanner.FileType } // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path @@ -188,7 +188,7 @@ namespace BinaryObjectScanner.FileType string filename = $"{texture.Name}.bmp"; // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/BZip2.cs b/BinaryObjectScanner/FileType/BZip2.cs index 30def76e..cbc2aa79 100644 --- a/BinaryObjectScanner/FileType/BZip2.cs +++ b/BinaryObjectScanner/FileType/BZip2.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Compressors; using SharpCompress.Compressors.BZip2; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.FileType if (stream == null) return null; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/CFB.cs b/BinaryObjectScanner/FileType/CFB.cs index 76298517..71869db3 100644 --- a/BinaryObjectScanner/FileType/CFB.cs +++ b/BinaryObjectScanner/FileType/CFB.cs @@ -2,7 +2,9 @@ using System.IO; using System.Text; using BinaryObjectScanner.Interfaces; +#if NET40_OR_GREATER || NETCOREAPP using OpenMcdf; +#endif namespace BinaryObjectScanner.FileType { @@ -17,15 +19,17 @@ namespace BinaryObjectScanner.FileType if (!File.Exists(file)) return null; - using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Extract(fs, file, includeDebug); - } + using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); + return Extract(fs, file, includeDebug); } /// public string? Extract(Stream? stream, string file, bool includeDebug) { +#if NET20 || NET35 + // Not supported for .NET Framework 2.0 or .NET Framework 3.5 due to library support + return null; +#else try { // Create a temp output directory @@ -84,6 +88,7 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); return null; } +#endif } /// Adapted from LibMSI diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs index ef0b2727..42fb69c4 100644 --- a/BinaryObjectScanner/FileType/Executable.cs +++ b/BinaryObjectScanner/FileType/Executable.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -143,7 +145,11 @@ namespace BinaryObjectScanner.FileType return null; // Create the internal queue +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif // Only use generic content checks if we're in debug mode if (includeDebug) @@ -178,7 +184,7 @@ namespace BinaryObjectScanner.FileType protections.AddRange(subProtections.Values.ToArray()); } - return string.Join(";", protections); + return string.Join(";", [.. protections]); } #region Check Runners @@ -190,10 +196,14 @@ namespace BinaryObjectScanner.FileType /// Stream to scan the contents of /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public Dictionary? RunContentChecks(string? file, Stream stream, bool includeDebug) +#else public ConcurrentDictionary? RunContentChecks(string? file, Stream stream, bool includeDebug) +#endif { // If we have an invalid file - if (string.IsNullOrWhiteSpace(file)) + if (string.IsNullOrEmpty(file)) return null; else if (!File.Exists(file)) return null; @@ -202,7 +212,7 @@ namespace BinaryObjectScanner.FileType byte[] fileContent = []; try { -#if NET40 +#if NET20 || NET35 || NET40 using var br = new BinaryReader(stream, Encoding.Default); #else using var br = new BinaryReader(stream, Encoding.Default, true); @@ -218,26 +228,51 @@ namespace BinaryObjectScanner.FileType } // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary(); +#else var protections = new ConcurrentDictionary(); +#endif // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in ContentCheckClasses) +#else Parallel.ForEach(ContentCheckClasses, checkClass => +#endif { // Get the protection for the class, if possible var protection = checkClass.CheckContents(file!, fileContent, includeDebug); - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on game engines if (CheckIfGameEngine(checkClass) && !IncludeGameEngines) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on packers if (CheckIfPacker(checkClass) && !IncludePackers) +#if NET20 || NET35 + continue; +#else return; +#endif +#if NET20 || NET35 + protections[checkClass] = protection!; + } +#else protections.TryAdd(checkClass, protection!); }); +#endif return protections; } @@ -249,29 +284,58 @@ namespace BinaryObjectScanner.FileType /// Executable to scan /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public Dictionary RunLinearExecutableChecks(string file, Stream stream, LinearExecutable lex, bool includeDebug) +#else public ConcurrentDictionary RunLinearExecutableChecks(string file, Stream stream, LinearExecutable lex, bool includeDebug) +#endif { // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary(); +#else var protections = new ConcurrentDictionary(); +#endif // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in LinearExecutableCheckClasses) +#else Parallel.ForEach(LinearExecutableCheckClasses, checkClass => +#endif { // Get the protection for the class, if possible var protection = checkClass.CheckLinearExecutable(file, lex, includeDebug); - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on game engines if (CheckIfGameEngine(checkClass) && !IncludeGameEngines) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on packers if (CheckIfPacker(checkClass) && !IncludePackers) +#if NET20 || NET35 + continue; +#else return; +#endif +#if NET20 || NET35 + protections[checkClass] = protection!; + } +#else protections.TryAdd(checkClass, protection!); }); +#endif return protections; } @@ -283,29 +347,58 @@ namespace BinaryObjectScanner.FileType /// Executable to scan /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public Dictionary RunMSDOSExecutableChecks(string file, Stream stream, MSDOS mz, bool includeDebug) +#else public ConcurrentDictionary RunMSDOSExecutableChecks(string file, Stream stream, MSDOS mz, bool includeDebug) +#endif { // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary(); +#else var protections = new ConcurrentDictionary(); +#endif // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in MSDOSExecutableCheckClasses) +#else Parallel.ForEach(MSDOSExecutableCheckClasses, checkClass => +#endif { // Get the protection for the class, if possible var protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug); - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on game engines if (CheckIfGameEngine(checkClass) && !IncludeGameEngines) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on packers if (CheckIfPacker(checkClass) && !IncludePackers) +#if NET20 || NET35 + continue; +#else return; +#endif +#if NET20 || NET35 + protections[checkClass] = protection!; + } +#else protections.TryAdd(checkClass, protection!); }); +#endif return protections; } @@ -317,29 +410,58 @@ namespace BinaryObjectScanner.FileType /// Executable to scan /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public Dictionary RunNewExecutableChecks(string file, Stream stream, NewExecutable nex, bool includeDebug) +#else public ConcurrentDictionary RunNewExecutableChecks(string file, Stream stream, NewExecutable nex, bool includeDebug) +#endif { // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary(); +#else var protections = new ConcurrentDictionary(); +#endif // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in NewExecutableCheckClasses) +#else Parallel.ForEach(NewExecutableCheckClasses, checkClass => +#endif { // Get the protection for the class, if possible var protection = checkClass.CheckNewExecutable(file, nex, includeDebug); - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on game engines if (CheckIfGameEngine(checkClass) && !IncludeGameEngines) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on packers if (CheckIfPacker(checkClass) && !IncludePackers) +#if NET20 || NET35 + continue; +#else return; +#endif +#if NET20 || NET35 + protections[checkClass] = protection!; + } +#else protections.TryAdd(checkClass, protection!); }); +#endif return protections; } @@ -351,34 +473,63 @@ namespace BinaryObjectScanner.FileType /// Executable to scan /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public Dictionary RunPortableExecutableChecks(string file, Stream stream, PortableExecutable pex, bool includeDebug) +#else public ConcurrentDictionary RunPortableExecutableChecks(string file, Stream stream, PortableExecutable pex, bool includeDebug) +#endif { // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary(); +#else var protections = new ConcurrentDictionary(); +#endif // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in PortableExecutableCheckClasses) +#else Parallel.ForEach(PortableExecutableCheckClasses, checkClass => +#endif { // Get the protection for the class, if possible var protection = checkClass.CheckPortableExecutable(file, pex, includeDebug); - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on game engines if (CheckIfGameEngine(checkClass) && !IncludeGameEngines) +#if NET20 || NET35 + continue; +#else return; +#endif // If we are filtering on packers if (CheckIfPacker(checkClass) && !IncludePackers) +#if NET20 || NET35 + continue; +#else return; +#endif +#if NET20 || NET35 + protections[checkClass] = protection!; + } +#else protections.TryAdd(checkClass, protection!); }); +#endif return protections; } - #endregion +#endregion #region Initializers diff --git a/BinaryObjectScanner/FileType/GCF.cs b/BinaryObjectScanner/FileType/GCF.cs index 774e3622..ca6e5bc2 100644 --- a/BinaryObjectScanner/FileType/GCF.cs +++ b/BinaryObjectScanner/FileType/GCF.cs @@ -116,7 +116,7 @@ namespace BinaryObjectScanner.FileType var filename = file.Path; // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/GZIP.cs b/BinaryObjectScanner/FileType/GZIP.cs index 60397232..3fc19933 100644 --- a/BinaryObjectScanner/FileType/GZIP.cs +++ b/BinaryObjectScanner/FileType/GZIP.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.GZip; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.FileType if (stream == null) return null; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/InstallShieldArchiveV3.cs b/BinaryObjectScanner/FileType/InstallShieldArchiveV3.cs index eda9de97..0a85dce5 100644 --- a/BinaryObjectScanner/FileType/InstallShieldArchiveV3.cs +++ b/BinaryObjectScanner/FileType/InstallShieldArchiveV3.cs @@ -2,7 +2,9 @@ using System.IO; using System.Linq; using BinaryObjectScanner.Interfaces; +#if NET40_OR_GREATER || NETCOREAPP using UnshieldSharp.Archive; +#endif namespace BinaryObjectScanner.FileType { @@ -17,15 +19,17 @@ namespace BinaryObjectScanner.FileType if (!File.Exists(file)) return null; - using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Extract(fs, file, includeDebug); - } + using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); + return Extract(fs, file, includeDebug); } /// public string? Extract(Stream? stream, string file, bool includeDebug) { +#if NET20 || NET35 + // Not supported for .NET Framework 2.0 or .NET Framework 3.5 due to library support + return null; +#else try { // Create a temp output directory @@ -43,7 +47,7 @@ namespace BinaryObjectScanner.FileType Directory.CreateDirectory(directoryName); (byte[]? fileContents, string? error) = archive.Extract(cfile.FullPath!); - if (fileContents == null || !string.IsNullOrWhiteSpace(error)) + if (fileContents == null || !string.IsNullOrEmpty(error)) continue; using (FileStream fs = File.OpenWrite(tempFile)) @@ -64,6 +68,7 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); return null; } +#endif } } } diff --git a/BinaryObjectScanner/FileType/InstallShieldCAB.cs b/BinaryObjectScanner/FileType/InstallShieldCAB.cs index 9e9a9c6a..60e9ea21 100644 --- a/BinaryObjectScanner/FileType/InstallShieldCAB.cs +++ b/BinaryObjectScanner/FileType/InstallShieldCAB.cs @@ -2,7 +2,9 @@ using System.IO; using System.Text.RegularExpressions; using BinaryObjectScanner.Interfaces; +#if NET40_OR_GREATER || NETCOREAPP using UnshieldSharp.Cabinet; +#endif namespace BinaryObjectScanner.FileType { @@ -17,15 +19,17 @@ namespace BinaryObjectScanner.FileType if (!File.Exists(file)) return null; - using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Extract(fs, file, includeDebug); - } + using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); + return Extract(fs, file, includeDebug); } /// public string? Extract(Stream? stream, string file, bool includeDebug) { +#if NET20 || NET35 + // Not supported for .NET Framework 2.0 or .NET Framework 3.5 due to library support + return null; +#else // Get the name of the first cabinet file or header var directory = Path.GetDirectoryName(file); string noExtension = Path.GetFileNameWithoutExtension(file); @@ -98,6 +102,7 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); return null; } +#endif } } } diff --git a/BinaryObjectScanner/FileType/MPQ.cs b/BinaryObjectScanner/FileType/MPQ.cs index 55a571a5..bcc8038e 100644 --- a/BinaryObjectScanner/FileType/MPQ.cs +++ b/BinaryObjectScanner/FileType/MPQ.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NETFRAMEWORK && !NET40 +#if NETFRAMEWORK && !NET20 && !NET35 && !NET40 using StormLibSharp; #endif @@ -18,17 +18,15 @@ namespace BinaryObjectScanner.FileType if (!File.Exists(file)) return null; - using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Extract(fs, file, includeDebug); - } + using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); + return Extract(fs, file, includeDebug); } // TODO: Add stream opening support /// public string? Extract(Stream? stream, string file, bool includeDebug) { -#if NET40 || NETCOREAPP || NET5_0_OR_GREATER +#if NET20 || NET35 || NET40 || NETCOREAPP || NET5_0_OR_GREATER // Not supported for .NET Core and modern .NET due to Windows DLL requirements return null; #else @@ -38,7 +36,7 @@ namespace BinaryObjectScanner.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); - using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read)) + using (var mpqArchive = new MpqArchive(file, FileAccess.Read)) { // Try to open the listfile string? listfile = null; @@ -49,7 +47,7 @@ namespace BinaryObjectScanner.FileType return null; // Read the listfile in for processing - using (StreamReader sr = new StreamReader(listStream)) + using (var sr = new StreamReader(listStream)) { listfile = sr.ReadToEnd(); } diff --git a/BinaryObjectScanner/FileType/PAK.cs b/BinaryObjectScanner/FileType/PAK.cs index 441bb697..fe64aa7a 100644 --- a/BinaryObjectScanner/FileType/PAK.cs +++ b/BinaryObjectScanner/FileType/PAK.cs @@ -98,7 +98,7 @@ namespace BinaryObjectScanner.FileType var filename = directoryItem.ItemName; // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/PKZIP.cs b/BinaryObjectScanner/FileType/PKZIP.cs index c89283da..21d65fba 100644 --- a/BinaryObjectScanner/FileType/PKZIP.cs +++ b/BinaryObjectScanner/FileType/PKZIP.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.Zip; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.FileType if (stream == null) return null; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/Quantum.cs b/BinaryObjectScanner/FileType/Quantum.cs index d4d1b459..8e0a04cf 100644 --- a/BinaryObjectScanner/FileType/Quantum.cs +++ b/BinaryObjectScanner/FileType/Quantum.cs @@ -129,7 +129,7 @@ namespace BinaryObjectScanner.FileType // string filename = fileDescriptor.FileName; // // If we have an invalid output directory - // if (string.IsNullOrWhiteSpace(outputDirectory)) + // if (string.IsNullOrEmpty(outputDirectory)) // return false; // // Create the full output path diff --git a/BinaryObjectScanner/FileType/RAR.cs b/BinaryObjectScanner/FileType/RAR.cs index be5ccb70..84804518 100644 --- a/BinaryObjectScanner/FileType/RAR.cs +++ b/BinaryObjectScanner/FileType/RAR.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.Rar; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.FileType if (stream == null) return null; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/SGA.cs b/BinaryObjectScanner/FileType/SGA.cs index e0d8b8b9..fe3415a5 100644 --- a/BinaryObjectScanner/FileType/SGA.cs +++ b/BinaryObjectScanner/FileType/SGA.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using ICSharpCode.SharpZipLib.Zip.Compression; #endif @@ -167,7 +167,16 @@ namespace BinaryObjectScanner.FileType // Reverse and assemble the filename parentNames.Reverse(); +#if NET20 || NET35 + var parentNamesArray = parentNames.Cast().ToArray(); + filename = parentNamesArray[0]; + for (int i = 1; i < parentNamesArray.Length; i++) + { + filename = Path.Combine(filename, parentNamesArray[i]); + } +#else filename = Path.Combine(parentNames.Cast().ToArray()); +#endif // Get the file offset long fileOffset; @@ -224,7 +233,7 @@ namespace BinaryObjectScanner.FileType else { // Decompress the data -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP data = new byte[outputFileSize]; Inflater inflater = new Inflater(); inflater.SetInput(compressedData); @@ -235,7 +244,7 @@ namespace BinaryObjectScanner.FileType } // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/SevenZip.cs b/BinaryObjectScanner/FileType/SevenZip.cs index 18fa32b5..73554259 100644 --- a/BinaryObjectScanner/FileType/SevenZip.cs +++ b/BinaryObjectScanner/FileType/SevenZip.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.SevenZip; #endif @@ -28,7 +28,7 @@ namespace BinaryObjectScanner.FileType /// public string? Extract(Stream? stream, string file, bool includeDebug) { -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/TapeArchive.cs b/BinaryObjectScanner/FileType/TapeArchive.cs index 674d0527..3e87ad31 100644 --- a/BinaryObjectScanner/FileType/TapeArchive.cs +++ b/BinaryObjectScanner/FileType/TapeArchive.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.Tar; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.FileType if (stream == null) return null; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/Textfile.cs b/BinaryObjectScanner/FileType/Textfile.cs index 09b8d0d0..58fead44 100644 --- a/BinaryObjectScanner/FileType/Textfile.cs +++ b/BinaryObjectScanner/FileType/Textfile.cs @@ -17,10 +17,8 @@ namespace BinaryObjectScanner.FileType if (!File.Exists(file)) return null; - using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return Detect(fs, file, includeDebug); - } + using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); + return Detect(fs, file, includeDebug); } /// @@ -33,7 +31,7 @@ namespace BinaryObjectScanner.FileType { // Load the current file content var fileContent = string.Empty; -#if NET40 +#if NET20 || NET35 || 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)) @@ -123,7 +121,7 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); } - return string.Join(";", protections); + return string.Join(";", [.. protections]); } } } diff --git a/BinaryObjectScanner/FileType/VBSP.cs b/BinaryObjectScanner/FileType/VBSP.cs index ad904cf9..fbe7b7c1 100644 --- a/BinaryObjectScanner/FileType/VBSP.cs +++ b/BinaryObjectScanner/FileType/VBSP.cs @@ -107,7 +107,7 @@ namespace BinaryObjectScanner.FileType } // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/VPK.cs b/BinaryObjectScanner/FileType/VPK.cs index 5dbd0be7..6d7f4e59 100644 --- a/BinaryObjectScanner/FileType/VPK.cs +++ b/BinaryObjectScanner/FileType/VPK.cs @@ -112,7 +112,7 @@ namespace BinaryObjectScanner.FileType // Get the archive filename string archiveFileName = item.ArchiveFilenames[directoryItem.DirectoryEntry.ArchiveIndex]; - if (string.IsNullOrWhiteSpace(archiveFileName)) + if (string.IsNullOrEmpty(archiveFileName)) return false; // If the archive doesn't exist @@ -152,11 +152,11 @@ namespace BinaryObjectScanner.FileType // Create the filename string filename = $"{directoryItem.Name}.{directoryItem.Extension}"; - if (!string.IsNullOrWhiteSpace(directoryItem.Path)) + if (!string.IsNullOrEmpty(directoryItem.Path)) filename = Path.Combine(directoryItem.Path, filename); // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/WAD.cs b/BinaryObjectScanner/FileType/WAD.cs index 25dfb275..303ec1ee 100644 --- a/BinaryObjectScanner/FileType/WAD.cs +++ b/BinaryObjectScanner/FileType/WAD.cs @@ -98,7 +98,7 @@ namespace BinaryObjectScanner.FileType string filename = $"{lump.Name}.lmp"; // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/FileType/XZ.cs b/BinaryObjectScanner/FileType/XZ.cs index ce4aa70e..b851b435 100644 --- a/BinaryObjectScanner/FileType/XZ.cs +++ b/BinaryObjectScanner/FileType/XZ.cs @@ -1,7 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Compressors.Xz; #endif @@ -27,7 +27,7 @@ namespace BinaryObjectScanner.FileType /// public string? Extract(Stream? stream, string file, bool includeDebug) { -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP try { // Create a temp output directory diff --git a/BinaryObjectScanner/FileType/XZP.cs b/BinaryObjectScanner/FileType/XZP.cs index 2fa7ad9a..b650c2f9 100644 --- a/BinaryObjectScanner/FileType/XZP.cs +++ b/BinaryObjectScanner/FileType/XZP.cs @@ -108,7 +108,7 @@ namespace BinaryObjectScanner.FileType var filename = directoryItem.Name; // If we have an invalid output directory - if (string.IsNullOrWhiteSpace(outputDirectory)) + if (string.IsNullOrEmpty(outputDirectory)) return false; // Create the full output path diff --git a/BinaryObjectScanner/Handler.cs b/BinaryObjectScanner/Handler.cs index eb1c052d..8a673e98 100644 --- a/BinaryObjectScanner/Handler.cs +++ b/BinaryObjectScanner/Handler.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -48,21 +50,37 @@ namespace BinaryObjectScanner /// Path of the file or directory to check /// Scanner object to use for options and scanning /// Set of protections in file, null on error +#if NET20 || NET35 + public static Dictionary> HandlePathChecks(string path, IEnumerable? files) +#else public static ConcurrentDictionary> HandlePathChecks(string path, IEnumerable? files) +#endif { // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif // Preprocess the list of files files = files?.Select(f => f.Replace('\\', '/'))?.ToList(); // Iterate through all checks +#if NET20 || NET35 + foreach (var checkClass in PathCheckClasses) +#else Parallel.ForEach(PathCheckClasses, checkClass => +#endif { var subProtections = checkClass?.PerformCheck(path, files); if (subProtections != null) AppendToDictionary(protections, path, subProtections); +#if NET20 || NET35 + } +#else }); +#endif return protections; } @@ -79,7 +97,11 @@ namespace BinaryObjectScanner /// Stream to scan the contents of /// True to include debug data, false otherwise /// Set of protections in file, null on error +#if NET20 || NET35 + public static Queue? HandleDetectable(IDetectable impl, string fileName, Stream stream, bool includeDebug) +#else public static ConcurrentQueue? HandleDetectable(IDetectable impl, string fileName, Stream stream, bool includeDebug) +#endif { var protection = impl.Detect(stream, fileName, includeDebug); return ProcessProtectionString(protection); @@ -93,7 +115,11 @@ namespace BinaryObjectScanner /// Stream to scan the contents of /// Scanner object to use on extractable contents /// Set of protections in file, null on error +#if NET20 || NET35 + public static Dictionary>? HandleExtractable(IExtractable impl, string fileName, Stream? stream, Scanner scanner) +#else public static ConcurrentDictionary>? HandleExtractable(IExtractable impl, string fileName, Stream? stream, Scanner scanner) +#endif { // If the extractable file itself fails try @@ -135,14 +161,22 @@ namespace BinaryObjectScanner /// IPathCheck class representing the file type /// Path of the file or directory to check /// Set of protections in path, null on error +#if NET20 || NET35 + private static Queue? PerformCheck(this IPathCheck impl, string? path, IEnumerable? files) +#else private static ConcurrentQueue? PerformCheck(this IPathCheck impl, string? path, IEnumerable? files) +#endif { // If we have an invalid path - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return null; // Setup the output dictionary +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif // If we have a file path if (File.Exists(path)) @@ -193,14 +227,22 @@ namespace BinaryObjectScanner /// /// Protection string to process /// Set of protections parsed, null on error +#if NET20 || NET35 + private static Queue? ProcessProtectionString(string? protection) +#else private static ConcurrentQueue? ProcessProtectionString(string? protection) +#endif { // If we have an invalid protection string - if (string.IsNullOrWhiteSpace(protection)) + if (string.IsNullOrEmpty(protection)) return null; // Setup the output queue +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif // If we have an indicator of multiple protections if (protection!.Contains(";")) diff --git a/BinaryObjectScanner/Interfaces/IPathCheck.cs b/BinaryObjectScanner/Interfaces/IPathCheck.cs index a09846d2..4d081966 100644 --- a/BinaryObjectScanner/Interfaces/IPathCheck.cs +++ b/BinaryObjectScanner/Interfaces/IPathCheck.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; namespace BinaryObjectScanner.Interfaces @@ -17,7 +19,11 @@ namespace BinaryObjectScanner.Interfaces /// Path to check for protection indicators /// Enumerable of strings representing files in a directory /// This can do some limited content checking as well, but it's suggested to use a content check instead, if possible +#if NET20 || NET35 + Queue CheckDirectoryPath(string path, IEnumerable? files); +#else ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files); +#endif /// /// Check a file path for protections based on path name diff --git a/BinaryObjectScanner/Packer/ASPack.cs b/BinaryObjectScanner/Packer/ASPack.cs index 44cc5145..7215648a 100644 --- a/BinaryObjectScanner/Packer/ASPack.cs +++ b/BinaryObjectScanner/Packer/ASPack.cs @@ -29,7 +29,7 @@ namespace BinaryObjectScanner.Packer // { // var matchers = GenerateMatchers(); // var match = MatchUtil.GetFirstMatch(file, pex.EntryPointRaw, matchers, includeDebug); - // if (!string.IsNullOrWhiteSpace(match)) + // if (!string.IsNullOrEmpty(match)) // return match; // } @@ -42,7 +42,7 @@ namespace BinaryObjectScanner.Packer { var matchers = GenerateMatchers(); var match = MatchUtil.GetFirstMatch(file, adataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } diff --git a/BinaryObjectScanner/Packer/CExe.cs b/BinaryObjectScanner/Packer/CExe.cs index 2e2497a2..3c1c567f 100644 --- a/BinaryObjectScanner/Packer/CExe.cs +++ b/BinaryObjectScanner/Packer/CExe.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using ICSharpCode.SharpZipLib.Zip.Compression; #endif using SabreTools.Matching; @@ -44,7 +44,7 @@ namespace BinaryObjectScanner.Packer }; var match = MatchUtil.GetFirstMatch(file, pex.StubExecutableData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -90,7 +90,7 @@ namespace BinaryObjectScanner.Packer try { // Inflate the data into the buffer -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP Inflater inflater = new Inflater(); inflater.SetInput(payload); data = new byte[payload.Length * 4]; diff --git a/BinaryObjectScanner/Packer/InnoSetup.cs b/BinaryObjectScanner/Packer/InnoSetup.cs index 6612f7e6..c3785a28 100644 --- a/BinaryObjectScanner/Packer/InnoSetup.cs +++ b/BinaryObjectScanner/Packer/InnoSetup.cs @@ -18,7 +18,7 @@ namespace BinaryObjectScanner.Packer if (nex.Model.Stub?.Header?.Reserved2?[4] == 0x6E49 && nex.Model.Stub?.Header?.Reserved2?[5] == 0x6F6E) { string version = GetOldVersion(file, nex); - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return $"Inno Setup {version}"; return "Inno Setup (Unknown Version)"; diff --git a/BinaryObjectScanner/Packer/MicrosoftCABSFX.cs b/BinaryObjectScanner/Packer/MicrosoftCABSFX.cs index 4a9e6ffb..3f8fd590 100644 --- a/BinaryObjectScanner/Packer/MicrosoftCABSFX.cs +++ b/BinaryObjectScanner/Packer/MicrosoftCABSFX.cs @@ -69,7 +69,7 @@ namespace BinaryObjectScanner.Packer { // Check the internal versions var version = pex.GetInternalVersion(); - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return $"v{version}"; return string.Empty; diff --git a/BinaryObjectScanner/Packer/NSIS.cs b/BinaryObjectScanner/Packer/NSIS.cs index b0ad4a6f..8994911a 100644 --- a/BinaryObjectScanner/Packer/NSIS.cs +++ b/BinaryObjectScanner/Packer/NSIS.cs @@ -18,7 +18,7 @@ namespace BinaryObjectScanner.Packer return null; var description = pex.AssemblyDescription; - if (!string.IsNullOrWhiteSpace(description) && description!.StartsWith("Nullsoft Install System")) + if (!string.IsNullOrEmpty(description) && description!.StartsWith("Nullsoft Install System")) return $"NSIS {description.Substring("Nullsoft Install System".Length).Trim()}"; // Get the .data/DATA section strings, if they exist diff --git a/BinaryObjectScanner/Packer/WinRARSFX.cs b/BinaryObjectScanner/Packer/WinRARSFX.cs index 24eefc4e..46816d7f 100644 --- a/BinaryObjectScanner/Packer/WinRARSFX.cs +++ b/BinaryObjectScanner/Packer/WinRARSFX.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.Rar; using SharpCompress.Readers; @@ -47,7 +47,7 @@ namespace BinaryObjectScanner.Packer /// public string? Extract(Stream? stream, string file, bool includeDebug) { -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP 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. diff --git a/BinaryObjectScanner/Packer/WinZipSFX.cs b/BinaryObjectScanner/Packer/WinZipSFX.cs index 8a0dca9b..e61fe6fa 100644 --- a/BinaryObjectScanner/Packer/WinZipSFX.cs +++ b/BinaryObjectScanner/Packer/WinZipSFX.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.Zip; #endif @@ -31,7 +31,7 @@ namespace BinaryObjectScanner.Packer // Try to get a known version var version = GetNEHeaderVersion(nex); - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return $"WinZip SFX {version}"; return $"WinZip SFX Unknown Version (16-bit)"; @@ -49,7 +49,7 @@ namespace BinaryObjectScanner.Packer if (pex.Model.ExportTable?.ExportDirectoryTable != null) { var version = GetPEExportDirectoryVersion(pex); - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return $"WinZip SFX {version}"; } @@ -77,7 +77,7 @@ namespace BinaryObjectScanner.Packer /// public string? Extract(Stream? stream, string file, bool includeDebug) { -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP 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. diff --git a/BinaryObjectScanner/Progress.cs b/BinaryObjectScanner/Progress.cs index 062ab0da..80811e68 100644 --- a/BinaryObjectScanner/Progress.cs +++ b/BinaryObjectScanner/Progress.cs @@ -1,4 +1,4 @@ -#if NET40 +#if NET20 || NET35 || NET40 // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. diff --git a/BinaryObjectScanner/Protection/AegiSoft.cs b/BinaryObjectScanner/Protection/AegiSoft.cs index d7c56ca6..048b95d9 100644 --- a/BinaryObjectScanner/Protection/AegiSoft.cs +++ b/BinaryObjectScanner/Protection/AegiSoft.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -59,7 +61,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -67,7 +69,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/AlphaDVD.cs b/BinaryObjectScanner/Protection/AlphaDVD.cs index 6b61bbe9..226f6667 100644 --- a/BinaryObjectScanner/Protection/AlphaDVD.cs +++ b/BinaryObjectScanner/Protection/AlphaDVD.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -16,7 +18,11 @@ namespace BinaryObjectScanner.Protection public class AlphaDVD : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Bitpool.cs b/BinaryObjectScanner/Protection/Bitpool.cs index ff8d0e13..a13b129d 100644 --- a/BinaryObjectScanner/Protection/Bitpool.cs +++ b/BinaryObjectScanner/Protection/Bitpool.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -13,7 +15,11 @@ namespace BinaryObjectScanner.Protection public class Bitpool : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/ByteShield.cs b/BinaryObjectScanner/Protection/ByteShield.cs index bbbdc274..8d75a868 100644 --- a/BinaryObjectScanner/Protection/ByteShield.cs +++ b/BinaryObjectScanner/Protection/ByteShield.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -130,7 +132,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? 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. diff --git a/BinaryObjectScanner/Protection/CDDVDCops.cs b/BinaryObjectScanner/Protection/CDDVDCops.cs index 5a08a0f8..a50c7eb8 100644 --- a/BinaryObjectScanner/Protection/CDDVDCops.cs +++ b/BinaryObjectScanner/Protection/CDDVDCops.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using System.Text; @@ -162,7 +164,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, pex.StubExecutableData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -182,7 +184,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { // TODO: Original had "CDCOPS.DLL" required and all the rest in a combined OR var matchers = new List @@ -228,7 +234,7 @@ namespace BinaryObjectScanner.Protection if (fileContent == null) return null; -#if NET40 +#if NET20 || NET35 || NET40 byte[] versionBytes = new byte[4]; Array.Copy(fileContent, positions[0] + 15, versionBytes, 0, 4); char[] version = versionBytes.Select(b => (char)b).ToArray(); diff --git a/BinaryObjectScanner/Protection/CDGuard.cs b/BinaryObjectScanner/Protection/CDGuard.cs index 07659d81..f84bff21 100644 --- a/BinaryObjectScanner/Protection/CDGuard.cs +++ b/BinaryObjectScanner/Protection/CDGuard.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -55,7 +57,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/CDLock.cs b/BinaryObjectScanner/Protection/CDLock.cs index 5f85bdcb..d9095b2f 100644 --- a/BinaryObjectScanner/Protection/CDLock.cs +++ b/BinaryObjectScanner/Protection/CDLock.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -53,7 +55,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -61,7 +63,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/CDProtector.cs b/BinaryObjectScanner/Protection/CDProtector.cs index cf4e46c3..ce42c038 100644 --- a/BinaryObjectScanner/Protection/CDProtector.cs +++ b/BinaryObjectScanner/Protection/CDProtector.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -17,7 +19,11 @@ namespace BinaryObjectScanner.Protection public class CDProtector : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/CDX.cs b/BinaryObjectScanner/Protection/CDX.cs index 8e72af81..bfbddf46 100644 --- a/BinaryObjectScanner/Protection/CDX.cs +++ b/BinaryObjectScanner/Protection/CDX.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -8,7 +10,11 @@ namespace BinaryObjectScanner.Protection public class CDX : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { // TODO: Verify if these are OR or AND var matchers = new List diff --git a/BinaryObjectScanner/Protection/CenegaProtectDVD.cs b/BinaryObjectScanner/Protection/CenegaProtectDVD.cs index 7472dd18..add43b44 100644 --- a/BinaryObjectScanner/Protection/CenegaProtectDVD.cs +++ b/BinaryObjectScanner/Protection/CenegaProtectDVD.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -53,7 +55,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/ChosenBytesCodeLock.cs b/BinaryObjectScanner/Protection/ChosenBytesCodeLock.cs index 8385bd25..f9eeabc9 100644 --- a/BinaryObjectScanner/Protection/ChosenBytesCodeLock.cs +++ b/BinaryObjectScanner/Protection/ChosenBytesCodeLock.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -54,7 +56,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/CopyKiller.cs b/BinaryObjectScanner/Protection/CopyKiller.cs index d1ed11b2..a7411d54 100644 --- a/BinaryObjectScanner/Protection/CopyKiller.cs +++ b/BinaryObjectScanner/Protection/CopyKiller.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -30,7 +32,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? 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 diff --git a/BinaryObjectScanner/Protection/DVDCrypt.cs b/BinaryObjectScanner/Protection/DVDCrypt.cs index cab49777..3bddf13d 100644 --- a/BinaryObjectScanner/Protection/DVDCrypt.cs +++ b/BinaryObjectScanner/Protection/DVDCrypt.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -8,7 +10,11 @@ namespace BinaryObjectScanner.Protection public class DVDCrypt : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs b/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs index a0e991c3..a3bb83b4 100644 --- a/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs +++ b/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -10,9 +12,17 @@ namespace BinaryObjectScanner.Protection public class DVDMoviePROTECT : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif if (files == null) return protections; diff --git a/BinaryObjectScanner/Protection/Denuvo.cs b/BinaryObjectScanner/Protection/Denuvo.cs index d827a3c6..99aa6266 100644 --- a/BinaryObjectScanner/Protection/Denuvo.cs +++ b/BinaryObjectScanner/Protection/Denuvo.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -85,7 +87,7 @@ namespace BinaryObjectScanner.Protection }; // TODO: Re-enable all Entry Point checks after implementing - // if (pex.ContainsSection(".arch") || pex.ContainsSection(".srdata") || !string.IsNullOrWhiteSpace(MatchUtil.GetFirstMatch(file, pex.EntryPointRaw, timingMatchers, includeDebug))) + // if (pex.ContainsSection(".arch") || pex.ContainsSection(".srdata") || !string.IsNullOrEmpty(MatchUtil.GetFirstMatch(file, pex.EntryPointRaw, timingMatchers, includeDebug))) // { // if (pex.OH_Magic == OptionalHeaderType.PE32Plus) // { @@ -158,7 +160,7 @@ namespace BinaryObjectScanner.Protection // }; // var match = MatchUtil.GetFirstMatch(file, pex.EntryPointRaw, matchers, includeDebug); - // if (!string.IsNullOrWhiteSpace(match)) + // if (!string.IsNullOrEmpty(match)) // return match; // return "Denuvo (Unknown x64 Version)"; @@ -224,7 +226,7 @@ namespace BinaryObjectScanner.Protection // }; // var match = MatchUtil.GetFirstMatch(file, pex.EntryPointRaw, matchers, includeDebug); - // if (!string.IsNullOrWhiteSpace(match)) + // if (!string.IsNullOrEmpty(match)) // return match; // //// Check if steam_api64.dll present @@ -255,7 +257,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/DigiGuard.cs b/BinaryObjectScanner/Protection/DigiGuard.cs index 24c227e8..8cb5be8d 100644 --- a/BinaryObjectScanner/Protection/DigiGuard.cs +++ b/BinaryObjectScanner/Protection/DigiGuard.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -53,7 +55,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/DinamicMultimedia.cs b/BinaryObjectScanner/Protection/DinamicMultimedia.cs index ccd3d303..71312826 100644 --- a/BinaryObjectScanner/Protection/DinamicMultimedia.cs +++ b/BinaryObjectScanner/Protection/DinamicMultimedia.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Interfaces; @@ -22,7 +24,11 @@ namespace BinaryObjectScanner.Protection // https://www.gamecopyworld.com/games/pc_pc_calcio_2000.shtml // https://www.gamecopyworld.com/games/pc_pc_futbol_2000.shtml +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/DiscGuard.cs b/BinaryObjectScanner/Protection/DiscGuard.cs index eb77cfcf..66e9a9ca 100644 --- a/BinaryObjectScanner/Protection/DiscGuard.cs +++ b/BinaryObjectScanner/Protection/DiscGuard.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -128,7 +130,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, vbnData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } @@ -137,7 +139,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/EasyAntiCheat.cs b/BinaryObjectScanner/Protection/EasyAntiCheat.cs index 93f17798..43b4727d 100644 --- a/BinaryObjectScanner/Protection/EasyAntiCheat.cs +++ b/BinaryObjectScanner/Protection/EasyAntiCheat.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -80,7 +82,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? 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 diff --git a/BinaryObjectScanner/Protection/Engine32.cs b/BinaryObjectScanner/Protection/Engine32.cs index d6c24bbd..5c026ba3 100644 --- a/BinaryObjectScanner/Protection/Engine32.cs +++ b/BinaryObjectScanner/Protection/Engine32.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -51,7 +53,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/FreeLock.cs b/BinaryObjectScanner/Protection/FreeLock.cs index cc6d0f7b..1db30a85 100644 --- a/BinaryObjectScanner/Protection/FreeLock.cs +++ b/BinaryObjectScanner/Protection/FreeLock.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -15,7 +17,11 @@ namespace BinaryObjectScanner.Protection // TODO: Add an MS-DOS executable check for "FREELOCK.EXE". /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/GFWL.cs b/BinaryObjectScanner/Protection/GFWL.cs index 8969c4b4..eaa5bcbd 100644 --- a/BinaryObjectScanner/Protection/GFWL.cs +++ b/BinaryObjectScanner/Protection/GFWL.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -36,7 +38,11 @@ namespace BinaryObjectScanner.ProtectionType } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Gefest.cs b/BinaryObjectScanner/Protection/Gefest.cs index 8339e20e..a87ec7fb 100644 --- a/BinaryObjectScanner/Protection/Gefest.cs +++ b/BinaryObjectScanner/Protection/Gefest.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -39,7 +41,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/HexaLock.cs b/BinaryObjectScanner/Protection/HexaLock.cs index e250fc36..255a0d45 100644 --- a/BinaryObjectScanner/Protection/HexaLock.cs +++ b/BinaryObjectScanner/Protection/HexaLock.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -68,7 +70,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/ImpulseReactor.cs b/BinaryObjectScanner/Protection/ImpulseReactor.cs index 858bc5ec..5d40a4b9 100644 --- a/BinaryObjectScanner/Protection/ImpulseReactor.cs +++ b/BinaryObjectScanner/Protection/ImpulseReactor.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -54,7 +56,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/IndyVCD.cs b/BinaryObjectScanner/Protection/IndyVCD.cs index e964d459..56a2f428 100644 --- a/BinaryObjectScanner/Protection/IndyVCD.cs +++ b/BinaryObjectScanner/Protection/IndyVCD.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -12,7 +14,11 @@ namespace BinaryObjectScanner.Protection public class IndyVCD : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { // TODO: Verify if these are OR or AND var matchers = new List diff --git a/BinaryObjectScanner/Protection/JoWood.cs b/BinaryObjectScanner/Protection/JoWood.cs index 4161d06d..9b9bcc89 100644 --- a/BinaryObjectScanner/Protection/JoWood.cs +++ b/BinaryObjectScanner/Protection/JoWood.cs @@ -45,7 +45,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, dcrtextData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } @@ -73,7 +73,7 @@ namespace BinaryObjectScanner.Protection return null; int position = positions[0]; -#if NET40 +#if NET20 || NET35 || NET40 byte[] versionBytes = new byte[8]; Array.Copy(fileContent, position + 67, versionBytes, 0, 8); char[] version = versionBytes.Select(b => (char)b).ToArray(); diff --git a/BinaryObjectScanner/Protection/LabelGate.cs b/BinaryObjectScanner/Protection/LabelGate.cs index 93d130e5..f24b7ca7 100644 --- a/BinaryObjectScanner/Protection/LabelGate.cs +++ b/BinaryObjectScanner/Protection/LabelGate.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -49,15 +51,24 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { // All found to be present on at multiple albums with LabelGate CD2 (Redump entry 95010 and product ID SVWC-7185), the original version of LabelGate still needs to be investigated. new PathMatchSet(new List { +#if NET20 || NET35 + new PathMatch(Path.Combine(Path.Combine("BIN", "WIN32"), "MQ2SETUP.EXE").Replace("\\", "/"), useEndsWith: true), + new PathMatch(Path.Combine(Path.Combine("BIN", "WIN32"), "MQSTART.EXE").Replace("\\", "/"), useEndsWith: true), +#else new PathMatch(Path.Combine("BIN", "WIN32", "MQ2SETUP.EXE").Replace("\\", "/"), useEndsWith: true), new PathMatch(Path.Combine("BIN", "WIN32", "MQSTART.EXE").Replace("\\", "/"), useEndsWith: true), +#endif }, "LabelGate CD2 Media Player"), // All of these are also found present on all known LabelGate CD2 releases, though an additional file "RESERVED.DAT" is found in the same directory in at least one release (Product ID SVWC-7185) diff --git a/BinaryObjectScanner/Protection/LaserLok.cs b/BinaryObjectScanner/Protection/LaserLok.cs index 482e1ea0..157f4e8e 100644 --- a/BinaryObjectScanner/Protection/LaserLok.cs +++ b/BinaryObjectScanner/Protection/LaserLok.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -111,7 +113,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { @@ -169,7 +175,7 @@ namespace BinaryObjectScanner.Protection if (versionTwo) { int index = position + 14; -#if NET40 +#if NET20 || NET35 || NET40 byte[] temp = new byte[2]; Array.Copy(sectionContent, index, temp, 0, 2); day = new string(temp.Select(b => (char)b).ToArray()); @@ -190,7 +196,7 @@ namespace BinaryObjectScanner.Protection else { int index = position + 13; -#if NET40 +#if NET20 || NET35 || NET40 byte[] temp = new byte[2]; Array.Copy(sectionContent, index, temp, 0, 2); day = new string(temp.Select(b => (char)b).ToArray()); @@ -218,7 +224,7 @@ namespace BinaryObjectScanner.Protection if (sectionContent == null) return null; -#if NET40 +#if NET20 || NET35 || NET40 byte[] temp = new byte[4]; Array.Copy(sectionContent, position + 76, temp, 0, 4); return new string(temp.Select(b => (char)b).ToArray()); @@ -241,7 +247,7 @@ namespace BinaryObjectScanner.Protection private static string GetVersion16Bit(byte[] fileContent) { -#if NET40 +#if NET20 || NET35 || NET40 byte[] temp = new byte[7]; Array.Copy(fileContent, 71, temp, 0, 7); char[] version = temp.Select(b => (char)b).ToArray(); diff --git a/BinaryObjectScanner/Protection/Macrovision.CDilla.cs b/BinaryObjectScanner/Protection/Macrovision.CDilla.cs index ef6e97f8..6b13befe 100644 --- a/BinaryObjectScanner/Protection/Macrovision.CDilla.cs +++ b/BinaryObjectScanner/Protection/Macrovision.CDilla.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using SabreTools.Matching; @@ -148,7 +150,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + internal Queue CDillaCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue CDillaCheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs index 8162c64d..a260dd26 100644 --- a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs +++ b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -64,7 +66,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + internal Queue CactusDataShieldCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue CactusDataShieldCheckDirectoryPath(string path, IEnumerable? files) +#endif { // TODO: Verify if these are OR or AND var matchers = new List @@ -124,10 +130,10 @@ namespace BinaryObjectScanner.Protection // Find the version.txt file first var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); - if (!string.IsNullOrWhiteSpace(versionPath)) + if (!string.IsNullOrEmpty(versionPath)) { var version = GetCactusDataShieldInternalVersion(versionPath); - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return version!; } diff --git a/BinaryObjectScanner/Protection/Macrovision.RipGuard.cs b/BinaryObjectScanner/Protection/Macrovision.RipGuard.cs index eac74ec4..ae9c4155 100644 --- a/BinaryObjectScanner/Protection/Macrovision.RipGuard.cs +++ b/BinaryObjectScanner/Protection/Macrovision.RipGuard.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using SabreTools.Matching; @@ -36,7 +38,7 @@ namespace BinaryObjectScanner.Protection if (name?.Equals("rgasdev", StringComparison.OrdinalIgnoreCase) == true) return "RipGuard"; - if (!string.IsNullOrWhiteSpace(file) && File.Exists(file)) + if (!string.IsNullOrEmpty(file) && File.Exists(file)) { try { @@ -59,7 +61,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + internal Queue RipGuardCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue RipGuardCheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { @@ -74,10 +80,10 @@ namespace BinaryObjectScanner.Protection return MatchUtil.GetAllMatches(files, matchers, any: false); } - /// - internal string? RipGuardCheckFilePath(string path) - { - var matchers = new List + /// + internal string? RipGuardCheckFilePath(string path) + { + var matchers = new List { // Found in the Black Lagoon Season 1 DVD steelbook box set (Geneon ID 12970). new PathMatchSet(new PathMatch("G23YHWO1.EXE", useEndsWith: true), "RipGuard"), @@ -87,7 +93,7 @@ namespace BinaryObjectScanner.Protection new PathMatchSet(new PathMatch("9KMJ9G4I.EXE", useEndsWith: true), "RipGuard (Unconfirmed - Please report to us on GitHub)"), }; - return MatchUtil.GetFirstMatch(path, matchers, any: true); + return MatchUtil.GetFirstMatch(path, matchers, any: true); + } } } -} diff --git a/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs b/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs index c000baa6..f5f83035 100644 --- a/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs +++ b/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using System.Text; @@ -144,7 +146,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + internal Queue SafeCastCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue SafeCastCheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs index 2487d522..4687cab8 100644 --- a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs +++ b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -110,7 +112,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + internal Queue SafeDiscCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue SafeDiscCheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Macrovision.cs b/BinaryObjectScanner/Protection/Macrovision.cs index 0ef33ca4..bf699284 100644 --- a/BinaryObjectScanner/Protection/Macrovision.cs +++ b/BinaryObjectScanner/Protection/Macrovision.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -27,16 +29,16 @@ namespace BinaryObjectScanner.Protection // Run C-Dilla NE checks var cDilla = CDillaCheckNewExecutable(file, nex, includeDebug); - if (!string.IsNullOrWhiteSpace(cDilla)) + if (!string.IsNullOrEmpty(cDilla)) resultsList.Add(cDilla!); // Run SafeCast NE checks var safeCast = SafeCastCheckNewExecutable(file, nex, includeDebug); - if (!string.IsNullOrWhiteSpace(safeCast)) + if (!string.IsNullOrEmpty(safeCast)) resultsList.Add(safeCast!); if (resultsList != null && resultsList.Count > 0) - return string.Join(", ", resultsList); + return string.Join(", ", resultsList.ToArray()); return null; } @@ -73,7 +75,7 @@ namespace BinaryObjectScanner.Protection { // Check the header padding for protected sections. var sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, true); - if (!string.IsNullOrWhiteSpace(sectionMatch)) + if (!string.IsNullOrEmpty(sectionMatch)) { resultsList.Add(sectionMatch!); } @@ -81,7 +83,7 @@ namespace BinaryObjectScanner.Protection { // Get the .data section, if it exists, for protected sections. sectionMatch = CheckSectionForProtection(file, includeDebug, pex.GetFirstSectionStrings(".data"), pex.GetFirstSectionData(".data"), true); - if (!string.IsNullOrWhiteSpace(sectionMatch)) + if (!string.IsNullOrEmpty(sectionMatch)) resultsList.Add(sectionMatch!); } @@ -110,7 +112,7 @@ namespace BinaryObjectScanner.Protection { // Check the header padding for protected sections. var sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, false); - if (!string.IsNullOrWhiteSpace(sectionMatch)) + if (!string.IsNullOrEmpty(sectionMatch)) { resultsList.Add(sectionMatch!); } @@ -118,133 +120,173 @@ namespace BinaryObjectScanner.Protection { // Check the .data section, if it exists, for protected sections. sectionMatch = CheckSectionForProtection(file, includeDebug, pex.GetFirstSectionStrings(".data"), pex.GetFirstSectionData(".data"), false); - if (!string.IsNullOrWhiteSpace(sectionMatch)) + if (!string.IsNullOrEmpty(sectionMatch)) resultsList.Add(sectionMatch!); } } // Run Cactus Data Shield PE checks var match = CactusDataShieldCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Run C-Dilla PE checks match = CDillaCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Run RipGuard PE checks match = RipGuardCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Run SafeCast PE checks match = SafeCastCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Run SafeDisc PE checks match = SafeDiscCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Run FLEXnet PE checks match = FLEXnetCheckPortableExecutable(file, pex, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) resultsList.Add(match!); // Clean the result list resultsList = CleanResultList(resultsList); if (resultsList != null && resultsList.Count > 0) - return string.Join(", ", resultsList); + return string.Join(", ", resultsList.ToArray()); return null; } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { +#if NET20 || NET35 + var results = new Queue(); +#else var results = new ConcurrentQueue(); +#endif // Run Macrovision directory checks var macrovision = MacrovisionCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (macrovision != null && macrovision.Count > 0) +#else if (macrovision != null && !macrovision.IsEmpty) +#endif results.AddRange(macrovision); // Run Cactus Data Shield directory checks var cactusDataShield = CactusDataShieldCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (cactusDataShield != null && cactusDataShield.Count > 0) +#else if (cactusDataShield != null && !cactusDataShield.IsEmpty) +#endif results.AddRange(cactusDataShield); // Run C-Dilla directory checks var cDilla = CDillaCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (cDilla != null && cDilla.Count > 0) +#else if (cDilla != null && !cDilla.IsEmpty) +#endif results.AddRange(cDilla); // Run RipGuard directory checks var ripGuard = RipGuardCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (ripGuard != null && ripGuard.Count > 0) +#else if (ripGuard != null && !ripGuard.IsEmpty) +#endif results.AddRange(ripGuard); // Run SafeCast directory checks var safeCast = SafeCastCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (safeCast != null && safeCast.Count > 0) +#else if (safeCast != null && !safeCast.IsEmpty) +#endif results.AddRange(safeCast); // Run SafeDisc directory checks var safeDisc = SafeDiscCheckDirectoryPath(path, files); +#if NET20 || NET35 + if (safeDisc != null && safeDisc.Count > 0) +#else if (safeDisc != null && !safeDisc.IsEmpty) +#endif results.AddRange(safeDisc); if (results != null && results.Count > 0) return results; +#if NET20 || NET35 + return new Queue(); +#else return new ConcurrentQueue(); +#endif } /// public string? CheckFilePath(string path) { - List resultsList = new List(); + var resultsList = new List(); // Run Macrovision file checks var macrovision = MacrovisionCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(macrovision)) + if (!string.IsNullOrEmpty(macrovision)) resultsList.Add(macrovision!); // Run Cactus Data Shield file checks var cactusDataShield = CactusDataShieldCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(cactusDataShield)) + if (!string.IsNullOrEmpty(cactusDataShield)) resultsList.Add(cactusDataShield!); // Run C-Dilla file checks var cDilla = CDillaCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(cDilla)) + if (!string.IsNullOrEmpty(cDilla)) resultsList.Add(cDilla!); // Run RipGuard file checks var ripGuard = RipGuardCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(ripGuard)) + if (!string.IsNullOrEmpty(ripGuard)) resultsList.Add(ripGuard!); // Run SafeCast file checks var safeCast = SafeCastCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(safeCast)) + if (!string.IsNullOrEmpty(safeCast)) resultsList.Add(safeCast!); // Run SafeDisc file checks var safeDisc = SafeDiscCheckFilePath(path); - if (!string.IsNullOrWhiteSpace(safeDisc)) + if (!string.IsNullOrEmpty(safeDisc)) resultsList.Add(safeDisc!); if (resultsList != null && resultsList.Count > 0) - return string.Join(", ", resultsList); + return string.Join(", ", resultsList.ToArray()); return null; } /// +#if NET20 || NET35 + internal Queue MacrovisionCheckDirectoryPath(string path, IEnumerable? files) +#else internal ConcurrentQueue MacrovisionCheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/MediaCloQ.cs b/BinaryObjectScanner/Protection/MediaCloQ.cs index 11c635ae..f1c0fd60 100644 --- a/BinaryObjectScanner/Protection/MediaCloQ.cs +++ b/BinaryObjectScanner/Protection/MediaCloQ.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -37,7 +39,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/MediaMaxCD3.cs b/BinaryObjectScanner/Protection/MediaMaxCD3.cs index 42eeeb73..91081991 100644 --- a/BinaryObjectScanner/Protection/MediaMaxCD3.cs +++ b/BinaryObjectScanner/Protection/MediaMaxCD3.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -63,7 +65,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/NEACProtect.cs b/BinaryObjectScanner/Protection/NEACProtect.cs index 7ae8582d..3ada6f57 100644 --- a/BinaryObjectScanner/Protection/NEACProtect.cs +++ b/BinaryObjectScanner/Protection/NEACProtect.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -50,7 +52,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/OpenMG.cs b/BinaryObjectScanner/Protection/OpenMG.cs index f2aa6d8a..a9f35464 100644 --- a/BinaryObjectScanner/Protection/OpenMG.cs +++ b/BinaryObjectScanner/Protection/OpenMG.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Interfaces; @@ -64,7 +66,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { @@ -82,8 +88,8 @@ namespace BinaryObjectScanner.Protection // Always found together on OpenMG releases ("Touch" by Amerie, Redump entry 95010, and product ID SVWC-7185). new PathMatchSet(new List { - new PathMatch(Path.Combine("SDKHM.DLL").Replace("\\", "/"), useEndsWith: true), - new PathMatch(Path.Combine("SDKHM.EXE").Replace("\\", "/"), useEndsWith: true), + new FilePathMatch("SDKHM.DLL"), + new FilePathMatch("SDKHM.EXE"), }, "OpenMG"), }; diff --git a/BinaryObjectScanner/Protection/Origin.cs b/BinaryObjectScanner/Protection/Origin.cs index cd6330a7..5aa9d095 100644 --- a/BinaryObjectScanner/Protection/Origin.cs +++ b/BinaryObjectScanner/Protection/Origin.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -29,7 +31,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/PlayJ.cs b/BinaryObjectScanner/Protection/PlayJ.cs index a7967649..d0fe56a7 100644 --- a/BinaryObjectScanner/Protection/PlayJ.cs +++ b/BinaryObjectScanner/Protection/PlayJ.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -40,7 +42,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/ProtectDVDVideo.cs b/BinaryObjectScanner/Protection/ProtectDVDVideo.cs index bb117d10..d4834f0c 100644 --- a/BinaryObjectScanner/Protection/ProtectDVDVideo.cs +++ b/BinaryObjectScanner/Protection/ProtectDVDVideo.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -10,9 +12,17 @@ namespace BinaryObjectScanner.Protection public class ProtectDVDVideo : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif if (files == null) return protections; diff --git a/BinaryObjectScanner/Protection/ProtectDisc.cs b/BinaryObjectScanner/Protection/ProtectDisc.cs index 341d0072..45205002 100644 --- a/BinaryObjectScanner/Protection/ProtectDisc.cs +++ b/BinaryObjectScanner/Protection/ProtectDisc.cs @@ -32,7 +32,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, nthSectionData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -47,7 +47,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -80,7 +80,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, lastSectionData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } @@ -136,7 +136,7 @@ namespace BinaryObjectScanner.Protection int index = positions[0] - 12; // Version 6-7 with Build Number in plain text -#if NET40 +#if NET20 || NET35 || NET40 byte[] temp = new byte[4]; Array.Copy(fileContent, index, temp, 0, 4); if (temp.SequenceEqual(new byte[] { 0x0A, 0x0D, 0x0A, 0x0D })) @@ -147,7 +147,7 @@ namespace BinaryObjectScanner.Protection index = positions[0] - 12 - 6; // Version 7 -#if NET40 +#if NET20 || NET35 || NET40 temp = new byte[6]; Array.Copy(fileContent, index, temp, 0, 6); if (new string(temp.Select(b => (char)b).ToArray()) == "Henrik") @@ -176,7 +176,7 @@ namespace BinaryObjectScanner.Protection index -= 5; } -#if NET40 +#if NET20 || NET35 || NET40 temp = new byte[6]; Array.Copy(fileContent, index, temp, 0, 6); char[] arrBuild = temp.Select(b => (char)b).ToArray(); diff --git a/BinaryObjectScanner/Protection/RainbowSentinel.cs b/BinaryObjectScanner/Protection/RainbowSentinel.cs index 45a318d9..9564d995 100644 --- a/BinaryObjectScanner/Protection/RainbowSentinel.cs +++ b/BinaryObjectScanner/Protection/RainbowSentinel.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -97,7 +99,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/RingPROTECH.cs b/BinaryObjectScanner/Protection/RingPROTECH.cs index 26a136e0..64146e95 100644 --- a/BinaryObjectScanner/Protection/RingPROTECH.cs +++ b/BinaryObjectScanner/Protection/RingPROTECH.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -34,7 +36,11 @@ namespace BinaryObjectScanner.Protection // TODO: Confirm if these checks are only for ProRing or if they are also for older Ring PROTECH /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/SVKP.cs b/BinaryObjectScanner/Protection/SVKP.cs index 45fe83ee..14421410 100644 --- a/BinaryObjectScanner/Protection/SVKP.cs +++ b/BinaryObjectScanner/Protection/SVKP.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -51,17 +53,17 @@ namespace BinaryObjectScanner.Protection if (pex.EntryPointData.StartsWith(new byte?[] { 0x60, 0xEB, 0x03, 0xC7, 0x84, 0xE8, 0xEB, 0x03, - 0xC7, 0x84, 0x9A, 0xE8, 0x00, 0x00, 0x00, 0x00, + 0xC7, 0x84, 0x9A, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x81, 0xED, 0x10, 0x00, 0x00, 0x00, 0xEB, 0x03, 0xC7, 0x84, 0xE9, 0x64, 0xA0, 0x23, 0x00, 0x00, 0x00, 0xEB })) return "SVKP v1.051"; - + // Found in the SVKP 1.11 demo. if (pex.EntryPointData.StartsWith(new byte?[] { - 0x60, 0xE8, null, null, null, null, 0x5D, 0x81, + 0x60, 0xE8, null, null, null, null, 0x5D, 0x81, 0xED, 0x06, null, null, null, 0x64, 0xA0, 0x23 })) return "SVKP v1.11"; @@ -69,8 +71,8 @@ namespace BinaryObjectScanner.Protection // Found in the SVKP 1.32 demo and Redump entry 84122. if (pex.EntryPointData.StartsWith(new byte?[] { - 0x60, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x81, - 0xED, 0x06, 0x00, 0x00, 0x00, 0xEB, 0x05, 0xB8, + 0x60, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x81, + 0xED, 0x06, 0x00, 0x00, 0x00, 0xEB, 0x05, 0xB8, null, null, null, null, 0x64, 0xA0, 0x23 })) return "SVKP v1.3+"; @@ -90,7 +92,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/SafeLock.cs b/BinaryObjectScanner/Protection/SafeLock.cs index 4b28191b..b1438c6e 100644 --- a/BinaryObjectScanner/Protection/SafeLock.cs +++ b/BinaryObjectScanner/Protection/SafeLock.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -20,7 +22,11 @@ namespace BinaryObjectScanner.Protection public class SafeLock : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { // Technically all need to exist but some might be renamed var matchers = new List diff --git a/BinaryObjectScanner/Protection/SecuROM.cs b/BinaryObjectScanner/Protection/SecuROM.cs index a4d7ded9..38fd4b49 100644 --- a/BinaryObjectScanner/Protection/SecuROM.cs +++ b/BinaryObjectScanner/Protection/SecuROM.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using System.Text; @@ -65,7 +67,7 @@ namespace BinaryObjectScanner.Protection if (nthSection == null) continue; -#if NET40 || NET452 +#if NET20 || NET35 || NET40 || NET452 string nthSectionName = Encoding.UTF8.GetString(nthSection.Name ?? []).TrimEnd('\0'); #else string nthSectionName = Encoding.UTF8.GetString(nthSection.Name ?? Array.Empty()).TrimEnd('\0'); @@ -83,7 +85,7 @@ namespace BinaryObjectScanner.Protection }; var match = MatchUtil.GetFirstMatch(file, nthSectionData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } @@ -109,7 +111,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/SmartE.cs b/BinaryObjectScanner/Protection/SmartE.cs index 91ec91f7..30f0b7b3 100644 --- a/BinaryObjectScanner/Protection/SmartE.cs +++ b/BinaryObjectScanner/Protection/SmartE.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -29,7 +31,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/SoftLock.cs b/BinaryObjectScanner/Protection/SoftLock.cs index 6ddd6b82..66239c79 100644 --- a/BinaryObjectScanner/Protection/SoftLock.cs +++ b/BinaryObjectScanner/Protection/SoftLock.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -82,7 +84,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/SolidShield.cs b/BinaryObjectScanner/Protection/SolidShield.cs index 81a2862a..6f3ad8b8 100644 --- a/BinaryObjectScanner/Protection/SolidShield.cs +++ b/BinaryObjectScanner/Protection/SolidShield.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -66,7 +68,7 @@ namespace BinaryObjectScanner.ProtectionType }; var match = MatchUtil.GetFirstMatch(file, initData, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } } @@ -109,7 +111,11 @@ namespace BinaryObjectScanner.ProtectionType } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { @@ -150,7 +156,7 @@ namespace BinaryObjectScanner.ProtectionType int position = positions[0]; -#if NET40 +#if NET20 || NET35 || NET40 byte[] id1 = new byte[3]; Array.Copy(fileContent, position + 5, id1, 0, 3); byte[] id2 = new byte[4]; @@ -180,7 +186,7 @@ namespace BinaryObjectScanner.ProtectionType return null; int position = positions[0]; -#if NET40 +#if NET20 || NET35 || NET40 byte[] id1 = new byte[3]; Array.Copy(fileContent, position + 4, id1, 0, 3); byte[] id2 = new byte[4]; @@ -224,7 +230,7 @@ namespace BinaryObjectScanner.ProtectionType private static string GetInternalVersion(PortableExecutable pex) { var companyName = pex.CompanyName?.ToLowerInvariant(); - if (!string.IsNullOrWhiteSpace(companyName) && (companyName!.Contains("solidshield") || companyName.Contains("tages"))) + if (!string.IsNullOrEmpty(companyName) && (companyName!.Contains("solidshield") || companyName.Contains("tages"))) return pex.GetInternalVersion() ?? string.Empty; return string.Empty; diff --git a/BinaryObjectScanner/Protection/StarForce.cs b/BinaryObjectScanner/Protection/StarForce.cs index e22786e0..0f703336 100644 --- a/BinaryObjectScanner/Protection/StarForce.cs +++ b/BinaryObjectScanner/Protection/StarForce.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -100,7 +102,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Steam.cs b/BinaryObjectScanner/Protection/Steam.cs index 75b6b8e5..d0003fc5 100644 --- a/BinaryObjectScanner/Protection/Steam.cs +++ b/BinaryObjectScanner/Protection/Steam.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -41,7 +43,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/TZCopyProtection.cs b/BinaryObjectScanner/Protection/TZCopyProtection.cs index 8c92bc28..2b1a79a6 100644 --- a/BinaryObjectScanner/Protection/TZCopyProtection.cs +++ b/BinaryObjectScanner/Protection/TZCopyProtection.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -53,7 +55,11 @@ namespace BinaryObjectScanner.Protection public class TZCopyProtection : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Tages.cs b/BinaryObjectScanner/Protection/Tages.cs index d6b12db8..d66a3131 100644 --- a/BinaryObjectScanner/Protection/Tages.cs +++ b/BinaryObjectScanner/Protection/Tages.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Interfaces; @@ -54,7 +56,7 @@ namespace BinaryObjectScanner.ProtectionType }; var match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) + if (!string.IsNullOrEmpty(match)) return match; } @@ -62,7 +64,11 @@ namespace BinaryObjectScanner.ProtectionType } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/TivolaRingProtection.cs b/BinaryObjectScanner/Protection/TivolaRingProtection.cs index 8f73c03a..1d7cc322 100644 --- a/BinaryObjectScanner/Protection/TivolaRingProtection.cs +++ b/BinaryObjectScanner/Protection/TivolaRingProtection.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Interfaces; @@ -12,7 +14,11 @@ namespace BinaryObjectScanner.Protection public class TivolaRingProtection : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/Uplay.cs b/BinaryObjectScanner/Protection/Uplay.cs index ed619642..352639b4 100644 --- a/BinaryObjectScanner/Protection/Uplay.cs +++ b/BinaryObjectScanner/Protection/Uplay.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -44,7 +46,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/WMDS.cs b/BinaryObjectScanner/Protection/WMDS.cs index 0e07f2a5..4dd2194a 100644 --- a/BinaryObjectScanner/Protection/WMDS.cs +++ b/BinaryObjectScanner/Protection/WMDS.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -43,7 +45,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/WTMCDProtect.cs b/BinaryObjectScanner/Protection/WTMCDProtect.cs index f0d79bf0..993ec7e6 100644 --- a/BinaryObjectScanner/Protection/WTMCDProtect.cs +++ b/BinaryObjectScanner/Protection/WTMCDProtect.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Linq; using BinaryObjectScanner.Interfaces; @@ -51,7 +53,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/WinLock.cs b/BinaryObjectScanner/Protection/WinLock.cs index 32f9c551..d799d129 100644 --- a/BinaryObjectScanner/Protection/WinLock.cs +++ b/BinaryObjectScanner/Protection/WinLock.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -19,7 +21,11 @@ namespace BinaryObjectScanner.Protection public class WinLock : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/Protection/XCP.cs b/BinaryObjectScanner/Protection/XCP.cs index 8bfffecb..2ffc636f 100644 --- a/BinaryObjectScanner/Protection/XCP.cs +++ b/BinaryObjectScanner/Protection/XCP.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -41,9 +43,17 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { +#if NET20 || NET35 + var protections = new Queue(); +#else var protections = new ConcurrentQueue(); +#endif if (files == null) return protections; @@ -52,10 +62,10 @@ namespace BinaryObjectScanner.Protection || files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))) { var versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); - if (!string.IsNullOrWhiteSpace(versionDatPath)) + if (!string.IsNullOrEmpty(versionDatPath)) { var xcpVersion = GetDatVersion(versionDatPath); - if (!string.IsNullOrWhiteSpace(xcpVersion)) + if (!string.IsNullOrEmpty(xcpVersion)) protections.Enqueue(xcpVersion!); } else diff --git a/BinaryObjectScanner/Protection/Zzxzz.cs b/BinaryObjectScanner/Protection/Zzxzz.cs index 6e979dfb..e9cffbbe 100644 --- a/BinaryObjectScanner/Protection/Zzxzz.cs +++ b/BinaryObjectScanner/Protection/Zzxzz.cs @@ -1,4 +1,6 @@ +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Interfaces; @@ -10,11 +12,19 @@ namespace BinaryObjectScanner.Protection public class Zzxzz : IPathCheck { /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { +#if NET20 || NET35 + new PathMatchSet(Path.Combine(Path.Combine(path, "Zzxzz"), "Zzz.aze").Replace("\\", "/"), "Zzxzz"), +#else new PathMatchSet(Path.Combine(path, "Zzxzz", "Zzz.aze").Replace("\\", "/"), "Zzxzz"), +#endif new PathMatchSet($"Zzxzz/", "Zzxzz"), }; diff --git a/BinaryObjectScanner/Protection/nProtect.cs b/BinaryObjectScanner/Protection/nProtect.cs index 2e82ee15..61cc98c6 100644 --- a/BinaryObjectScanner/Protection/nProtect.cs +++ b/BinaryObjectScanner/Protection/nProtect.cs @@ -1,4 +1,6 @@ -using System.Collections.Concurrent; +#if NET40_OR_GREATER || NETCOREAPP +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -78,7 +80,11 @@ namespace BinaryObjectScanner.Protection } /// +#if NET20 || NET35 + public Queue CheckDirectoryPath(string path, IEnumerable? files) +#else public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable? files) +#endif { var matchers = new List { diff --git a/BinaryObjectScanner/ProtectionProgress.cs b/BinaryObjectScanner/ProtectionProgress.cs index cc81362a..594aab0f 100644 --- a/BinaryObjectScanner/ProtectionProgress.cs +++ b/BinaryObjectScanner/ProtectionProgress.cs @@ -3,7 +3,7 @@ /// /// Struct representing protection scanning progress /// -#if NET40 +#if NET20 || NET35 || NET40 public class ProtectionProgress : System.EventArgs #else public struct ProtectionProgress diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index b6a9cd83..ab41f7c8 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -1,5 +1,7 @@ using System; +#if NET40_OR_GREATER || NETCOREAPP using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.IO; using System.Linq; @@ -71,7 +73,7 @@ namespace BinaryObjectScanner this._fileProgress = fileProgress; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP // Register the codepages Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif @@ -84,7 +86,11 @@ namespace BinaryObjectScanner /// /// Path to scan /// Dictionary of list of strings representing the found protections +#if NET20 || NET35 + public Dictionary>? GetProtections(string path) +#else public ConcurrentDictionary>? GetProtections(string path) +#endif { return GetProtections(new List { path }); } @@ -93,7 +99,11 @@ namespace BinaryObjectScanner /// Scan the list of paths and get all found protections /// /// Dictionary of list of strings representing the found protections +#if NET20 || NET35 + public Dictionary>? GetProtections(List? paths) +#else public ConcurrentDictionary>? GetProtections(List? paths) +#endif { // If we have no paths, we can't scan if (paths == null || !paths.Any()) @@ -110,14 +120,22 @@ namespace BinaryObjectScanner string tempFilePathWithGuid = Path.Combine(tempFilePath, Guid.NewGuid().ToString()); // Loop through each path and get the returned values +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif foreach (string path in paths) { // Directories scan each internal file individually if (Directory.Exists(path)) { // Enumerate all files at first for easier access +#if NET20 || NET35 + var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories).ToList(); +#else var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories).ToList(); +#endif // Scan for path-detectable protections if (ScanPaths) @@ -154,7 +172,11 @@ namespace BinaryObjectScanner foreach (string key in fileProtections.Keys) { if (!protections.ContainsKey(key)) +#if NET20 || NET35 + protections[key] = new Queue(); +#else protections[key] = new ConcurrentQueue(); +#endif protections[key].AddRange(fileProtections[key]); } @@ -162,7 +184,7 @@ namespace BinaryObjectScanner // Checkpoint protections.TryGetValue(file, out var fullProtectionList); - var fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList) : null); + var fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList.ToArray()) : null); this._fileProgress?.Report(new ProtectionProgress(reportableFileName, (i + 1) / (float)files.Count, fullProtection ?? string.Empty)); } } @@ -192,7 +214,11 @@ namespace BinaryObjectScanner foreach (string key in fileProtections.Keys) { if (!protections.ContainsKey(key)) +#if NET20 || NET35 + protections[key] = new Queue(); +#else protections[key] = new ConcurrentQueue(); +#endif protections[key].AddRange(fileProtections[key]); } @@ -200,7 +226,7 @@ namespace BinaryObjectScanner // Checkpoint protections.TryGetValue(path, out var fullProtectionList); - var fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList) : null); + var fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList.ToArray()) : null); this._fileProgress?.Report(new ProtectionProgress(reportableFileName, 1, fullProtection ?? string.Empty)); } @@ -227,7 +253,11 @@ namespace BinaryObjectScanner /// /// Path to the file to scan /// Dictionary of list of strings representing the found protections +#if NET20 || NET35 + private Dictionary>? GetInternalProtections(string file) +#else private ConcurrentDictionary>? GetInternalProtections(string file) +#endif { // Quick sanity check before continuing if (!File.Exists(file)) @@ -243,7 +273,11 @@ namespace BinaryObjectScanner { if (IncludeDebug) Console.WriteLine(ex); +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif AppendToDictionary(protections, file, IncludeDebug ? ex.ToString() : "[Exception opening file, please try again]"); ClearEmptyKeys(protections); return protections; @@ -256,14 +290,22 @@ namespace BinaryObjectScanner /// Name of the source file of the stream, for tracking /// Stream to scan the contents of /// Dictionary of list of strings representing the found protections +#if NET20 || NET35 + private Dictionary>? GetInternalProtections(string fileName, Stream stream) +#else private ConcurrentDictionary>? GetInternalProtections(string fileName, Stream stream) +#endif { // Quick sanity check before continuing if (stream == null || !stream.CanRead || !stream.CanSeek) return null; // Initialize the protections found +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif // Get the extension for certain checks string extension = Path.GetExtension(fileName).ToLower().TrimStart('.'); @@ -321,7 +363,7 @@ namespace BinaryObjectScanner } var subProtection = detectable.Detect(stream, fileName, IncludeDebug); - if (!string.IsNullOrWhiteSpace(subProtection)) + if (!string.IsNullOrEmpty(subProtection)) { // If we have an indicator of multiple protections if (subProtection.Contains(';')) @@ -379,7 +421,11 @@ namespace BinaryObjectScanner /// Ideally, we wouldn't need to circumvent the proper handling of file types just for Executable, /// but due to the complexity of scanning, this is not currently possible. /// +#if NET20 || NET35 + private Dictionary>? ProcessExecutable(Executable executable, string fileName, Stream stream) +#else private ConcurrentDictionary>? ProcessExecutable(Executable executable, string fileName, Stream stream) +#endif { // Try to create a wrapper for the proper executable type var wrapper = WrapperFactory.CreateExecutableWrapper(stream); @@ -387,7 +433,11 @@ namespace BinaryObjectScanner return null; // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif // Only use generic content checks if we're in debug mode if (IncludeDebug) @@ -464,28 +514,48 @@ namespace BinaryObjectScanner /// Name of the source file of the stream, for tracking /// Stream to scan the contents of /// Set of protections found from extraction, null on error +#if NET20 || NET35 + private Dictionary>? HandleExtractableProtections(Dictionary.KeyCollection? classes, string fileName, Stream stream) +#else private ConcurrentDictionary>? HandleExtractableProtections(IEnumerable? classes, string fileName, Stream stream) +#endif { // If we have an invalid set of classes if (classes == null || !classes.Any()) return null; // Create the output dictionary +#if NET20 || NET35 + var protections = new Dictionary>(); +#else var protections = new ConcurrentDictionary>(); +#endif // If we have any extractable packers var extractables = classes.Where(c => c is IExtractable).Select(c => c as IExtractable); +#if NET20 || NET35 + foreach (var extractable in extractables) +#else Parallel.ForEach(extractables, extractable => +#endif { // If we have an invalid extractable somehow if (extractable == null) +#if NET20 || NET35 + continue; +#else return; +#endif // Get the protection for the class, if possible var extractedProtections = Handler.HandleExtractable(extractable, fileName, stream, this); if (extractedProtections != null) AppendToDictionary(protections, extractedProtections); +#if NET20 || NET35 + } +#else }); +#endif return protections; } diff --git a/BinaryObjectScanner/Utilities/Dictionary.cs b/BinaryObjectScanner/Utilities/Dictionary.cs index b9696e1c..3bf9000f 100644 --- a/BinaryObjectScanner/Utilities/Dictionary.cs +++ b/BinaryObjectScanner/Utilities/Dictionary.cs @@ -1,5 +1,9 @@ using System; +#if NET20 || NET35 +using System.Collections.Generic; +#else using System.Collections.Concurrent; +#endif using System.IO; using System.Linq; @@ -16,13 +20,21 @@ namespace BinaryObjectScanner.Utilities /// Dictionary to append to /// Key to add information to /// String value to add +#if NET20 || NET35 + public static void AppendToDictionary(Dictionary> original, string key, string value) +#else public static void AppendToDictionary(ConcurrentDictionary> original, string key, string value) +#endif { // If the value is empty, don't add it - if (string.IsNullOrWhiteSpace(value)) + if (string.IsNullOrEmpty(value)) return; +#if NET20 || NET35 + var values = new Queue(); +#else var values = new ConcurrentQueue(); +#endif values.Enqueue(value); AppendToDictionary(original, key, values); } @@ -32,18 +44,26 @@ namespace BinaryObjectScanner.Utilities /// /// Dictionary to append to /// Key to add information to - /// String value to add + /// String value array to add +#if NET20 || NET35 + public static void AppendToDictionary(Dictionary> original, string key, string[] values) +#else public static void AppendToDictionary(ConcurrentDictionary> original, string key, string[] values) +#endif { // If the dictionary is null, just return if (original == null) return; // Use a placeholder value if the key is null - key = key ?? "NO FILENAME"; + key ??= "NO FILENAME"; // Add the key if needed and then append the lists +#if NET20 || NET35 + original[key] ??= new Queue(); +#else original.TryAdd(key, new ConcurrentQueue()); +#endif original[key].AddRange(values); } @@ -53,17 +73,25 @@ namespace BinaryObjectScanner.Utilities /// Dictionary to append to /// Key to add information to /// String value to add +#if NET20 || NET35 + public static void AppendToDictionary(Dictionary> original, string key, Queue values) +#else public static void AppendToDictionary(ConcurrentDictionary> original, string key, ConcurrentQueue values) +#endif { // If the dictionary is null, just return if (original == null) return; // Use a placeholder value if the key is null - key = key ?? "NO FILENAME"; + key ??= "NO FILENAME"; // Add the key if needed and then append the lists +#if NET20 || NET35 + original[key] ??= new Queue(); +#else original.TryAdd(key, new ConcurrentQueue()); +#endif original[key].AddRange(values); } @@ -72,7 +100,11 @@ namespace BinaryObjectScanner.Utilities /// /// Dictionary to append to /// Dictionary to pull from +#if NET20 || NET35 + public static void AppendToDictionary(Dictionary> original, Dictionary> addition) +#else public static void AppendToDictionary(ConcurrentDictionary> original, ConcurrentDictionary> addition) +#endif { // If either dictionary is missing, just return if (original == null || addition == null) @@ -81,7 +113,11 @@ namespace BinaryObjectScanner.Utilities // Loop through each of the addition keys and add accordingly foreach (string key in addition.Keys) { +#if NET20 || NET35 + original[key] ??= new Queue(); +#else original.TryAdd(key, new ConcurrentQueue()); +#endif original[key].AddRange(addition[key]); } } @@ -90,7 +126,11 @@ namespace BinaryObjectScanner.Utilities /// Remove empty or null keys from a results dictionary /// /// Dictionary to clean +#if NET20 || NET35 + public static void ClearEmptyKeys(Dictionary> original) +#else public static void ClearEmptyKeys(ConcurrentDictionary> original) +#endif { // If the dictionary is missing, we can't do anything if (original == null) @@ -107,7 +147,11 @@ namespace BinaryObjectScanner.Utilities // If the key is empty, remove it if (original[key] == null || !original[key].Any()) +#if NET20 || NET35 + original.Remove(key); +#else original.TryRemove(key, out _); +#endif } } @@ -116,7 +160,11 @@ namespace BinaryObjectScanner.Utilities /// /// Dictionary to strip values from /// Path to strip from the keys +#if NET20 || NET35 + public static void PrependToKeys(Dictionary>? original, string pathToPrepend) +#else public static void PrependToKeys(ConcurrentDictionary>? original, string pathToPrepend) +#endif { // If the dictionary is missing, we can't do anything if (original == null) @@ -137,7 +185,11 @@ namespace BinaryObjectScanner.Utilities // Otherwise, get the new key name and transfer over string newKey = $"{pathToPrepend}{Path.DirectorySeparatorChar}{currentKey.Trim(Path.DirectorySeparatorChar)}"; original[newKey] = original[currentKey]; +#if NET20 || NET35 + original.Remove(currentKey); +#else original.TryRemove(currentKey, out _); +#endif } } @@ -146,7 +198,11 @@ namespace BinaryObjectScanner.Utilities /// /// Dictionary to strip values from /// Path to strip from the keys +#if NET20 || NET35 + public static void StripFromKeys(Dictionary>? original, string? pathToStrip) +#else public static void StripFromKeys(ConcurrentDictionary>? original, string? pathToStrip) +#endif { // If either is missing, we can't do anything if (original == null || string.IsNullOrEmpty(pathToStrip)) @@ -168,7 +224,11 @@ namespace BinaryObjectScanner.Utilities // Otherwise, get the new key name and transfer over string newKey = currentKey.Substring(pathToStrip!.Length); original[newKey] = original[currentKey]; +#if NET20 || NET35 + original.Remove(currentKey); +#else original.TryRemove(currentKey, out _); +#endif } } } diff --git a/BinaryObjectScanner/Utilities/Extensions.cs b/BinaryObjectScanner/Utilities/Extensions.cs index 39c16e26..b89e9a1d 100644 --- a/BinaryObjectScanner/Utilities/Extensions.cs +++ b/BinaryObjectScanner/Utilities/Extensions.cs @@ -1,4 +1,8 @@ +#if NET20 || NET35 +using System.Collections.Generic; +#else using System.Collections.Concurrent; +#endif namespace BinaryObjectScanner.Utilities { @@ -11,7 +15,11 @@ namespace BinaryObjectScanner.Utilities /// /// Queue to add data to /// Array to get data from +#if NET20 || NET35 + public static void AddRange(this Queue original, string[] values) +#else public static void AddRange(this ConcurrentQueue original, string[] values) +#endif { if (values == null || values.Length == 0) return; @@ -27,17 +35,28 @@ namespace BinaryObjectScanner.Utilities /// /// Queue to add data to /// Queue to get data from +#if NET20 || NET35 + public static void AddRange(this Queue original, Queue values) +#else public static void AddRange(this ConcurrentQueue original, ConcurrentQueue values) +#endif { - while (!values.IsEmpty) + if (values == null || values.Count == 0) + return; + + while (values.Count > 0) { +#if NET20 || NET35 + original.Enqueue(values.Dequeue()); +#else if (!values.TryDequeue(out var value)) return; original.Enqueue(value); +#endif } } - #endregion +#endregion } } \ No newline at end of file diff --git a/BinaryObjectScanner/Utilities/FileTypes.cs b/BinaryObjectScanner/Utilities/FileTypes.cs index fce31029..31b8bc7c 100644 --- a/BinaryObjectScanner/Utilities/FileTypes.cs +++ b/BinaryObjectScanner/Utilities/FileTypes.cs @@ -367,7 +367,7 @@ namespace BinaryObjectScanner.Utilities public static SupportedFileType GetFileType(string extension) { // If we have an invalid extension - if (string.IsNullOrWhiteSpace(extension)) + if (string.IsNullOrEmpty(extension)) return SupportedFileType.UNKNOWN; // Normalize the extension diff --git a/BinaryObjectScanner/Utilities/Hashing.cs b/BinaryObjectScanner/Utilities/Hashing.cs index 546fc744..1dfcb4c2 100644 --- a/BinaryObjectScanner/Utilities/Hashing.cs +++ b/BinaryObjectScanner/Utilities/Hashing.cs @@ -16,7 +16,7 @@ namespace BinaryObjectScanner.Utilities /// SHA1 hash as a string on success, null on error public static string? GetFileSHA1(string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return null; try diff --git a/Test/Extractor.cs b/Test/Extractor.cs index 0de39668..9a3b321c 100644 --- a/Test/Extractor.cs +++ b/Test/Extractor.cs @@ -3,10 +3,12 @@ using System.IO; using System.Linq; using System.Text; using BinaryObjectScanner.Utilities; +#if NET40_OR_GREATER || NETCOREAPP using OpenMcdf; +#endif using SabreTools.IO; using SabreTools.Serialization.Wrappers; -#if NET462_OR_GREATER +#if NET462_OR_GREATER || NETCOREAPP using SharpCompress.Archives; using SharpCompress.Archives.GZip; using SharpCompress.Archives.Rar; @@ -17,8 +19,10 @@ using SharpCompress.Compressors; using SharpCompress.Compressors.BZip2; using SharpCompress.Compressors.Xz; #endif +#if NET40_OR_GREATER || NETCOREAPP using UnshieldSharp.Archive; using UnshieldSharp.Cabinet; +#endif namespace Test { @@ -40,7 +44,11 @@ namespace Test } else if (Directory.Exists(path)) { +#if NET20 || NET35 + foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories)) +#else foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) +#endif { ExtractFile(file, outputDirectory); } @@ -76,40 +84,40 @@ namespace Test Console.WriteLine("Extracting 7-zip contents"); Console.WriteLine(); +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else // If the 7-zip file itself fails -#if NET462_OR_GREATER - try + try + { + using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream)) { - using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream)) + foreach (var entry in sevenZipFile.Entries) { - foreach (var entry in sevenZipFile.Entries) + // If an individual entry fails + try { - // If an individual entry fails - try - { - // If we have a directory, skip it - if (entry.IsDirectory) - continue; + // If we have a directory, skip it + if (entry.IsDirectory) + continue; - string tempFile = Path.Combine(outputDirectory, entry.Key); - entry.WriteToFile(tempFile); - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting 7-zip entry {entry.Key}: {ex}"); - Console.WriteLine(); - } + string tempFile = Path.Combine(outputDirectory, entry.Key); + entry.WriteToFile(tempFile); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting 7-zip entry {entry.Key}: {ex}"); + Console.WriteLine(); } } } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting 7-zip: {ex}"); - Console.WriteLine(); - } -#else - Console.WriteLine($"Extracting 7-zip not supported on this .NET version"); - Console.WriteLine(); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting 7-zip: {ex}"); + Console.WriteLine(); + } #endif } @@ -175,27 +183,27 @@ namespace Test Console.WriteLine("Extracting bzip2 contents"); Console.WriteLine(); -#if NET462_OR_GREATER - using (var bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true)) +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else + using (var bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true)) + { + // If an individual entry fails + try { - // If an individual entry fails - try + string tempFile = Path.Combine(outputDirectory, Guid.NewGuid().ToString()); + using (FileStream fs = File.OpenWrite(tempFile)) { - string tempFile = Path.Combine(outputDirectory, Guid.NewGuid().ToString()); - using (FileStream fs = File.OpenWrite(tempFile)) - { - bz2File.CopyTo(fs); - } - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting bzip2: {ex}"); - Console.WriteLine(); + bz2File.CopyTo(fs); } } -#else - Console.WriteLine($"Extracting bzip2 not supported on this .NET version"); - Console.WriteLine(); + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting bzip2: {ex}"); + Console.WriteLine(); + } + } #endif } @@ -206,6 +214,7 @@ namespace Test Console.WriteLine("Extracting CFB contents"); Console.WriteLine(); +#if NET45_OR_GREATER || NETCOREAPP // If the CFB file itself fails try { @@ -245,6 +254,7 @@ namespace Test Console.WriteLine($"Something went wrong extracting CFB: {ex}"); Console.WriteLine(); } +#endif } // GCF @@ -281,32 +291,32 @@ namespace Test Console.WriteLine("Extracting gzip contents"); Console.WriteLine(); -#if NET462_OR_GREATER - using (var zipFile = GZipArchive.Open(stream)) +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else + using (var zipFile = GZipArchive.Open(stream)) + { + foreach (var entry in zipFile.Entries) { - foreach (var entry in zipFile.Entries) + // If an individual entry fails + try { - // If an individual entry fails - try - { - // If we have a directory, skip it - if (entry.IsDirectory) - continue; + // If we have a directory, skip it + if (entry.IsDirectory) + continue; - string tempFile = Path.Combine(outputDirectory, entry.Key); - entry.WriteToFile(tempFile); - } + string tempFile = Path.Combine(outputDirectory, entry.Key); + entry.WriteToFile(tempFile); + } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting gzip entry {entry.Key}: {ex}"); - Console.WriteLine(); - } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting gzip entry {entry.Key}: {ex}"); + Console.WriteLine(); } } -#else - Console.WriteLine($"Extracting gzip not supported on this .NET version"); - Console.WriteLine(); + } #endif } @@ -317,6 +327,7 @@ namespace Test Console.WriteLine("Extracting InstallShield Archive V3 contents"); Console.WriteLine(); +#if NET40_OR_GREATER || NETCOREAPP // If the cab file itself fails try { @@ -332,7 +343,7 @@ namespace Test Directory.CreateDirectory(directoryName); (byte[]? fileContents, string? error) = archive.Extract(cfile.FullPath ?? string.Empty); - if (!string.IsNullOrWhiteSpace(error)) + if (!string.IsNullOrEmpty(error)) continue; if (fileContents != null && fileContents.Length > 0) @@ -353,6 +364,7 @@ namespace Test Console.WriteLine($"Something went wrong extracting InstallShield Archive V3: {ex}"); Console.WriteLine(); } +#endif } // IS-CAB archive @@ -362,6 +374,10 @@ namespace Test Console.WriteLine("Extracting IS-CAB contents"); Console.WriteLine(); +#if NET20 || NET35 || NET40 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else // If the cab file itself fails try { @@ -396,6 +412,7 @@ namespace Test Console.WriteLine($"Something went wrong extracting IS-CAB: {ex}"); Console.WriteLine(); } +#endif } // Microsoft Cabinet archive @@ -464,63 +481,63 @@ namespace Test } } -#if NETFRAMEWORK && !NET40 - // MoPaQ (MPQ) archive - else if (ft == SupportedFileType.MPQ) +#if NETFRAMEWORK && !NET20 && !NET35 && !NET40 + // MoPaQ (MPQ) archive + else if (ft == SupportedFileType.MPQ) + { + // Build the archive information + Console.WriteLine("Extracting MoPaQ contents"); + Console.WriteLine(); + + // If the MPQ file itself fails + try { - // Build the archive information - Console.WriteLine("Extracting MoPaQ contents"); - Console.WriteLine(); - - // If the MPQ file itself fails - try + using (var mpqArchive = new StormLibSharp.MpqArchive(file, FileAccess.Read)) { - using (var mpqArchive = new StormLibSharp.MpqArchive(file, FileAccess.Read)) + // Try to open the listfile + string? listfile = null; + StormLibSharp.MpqFileStream listStream = mpqArchive.OpenFile("(listfile)"); + + // If we can't read the listfile, we just return + if (!listStream.CanRead) { - // Try to open the listfile - string? listfile = null; - StormLibSharp.MpqFileStream listStream = mpqArchive.OpenFile("(listfile)"); + Console.WriteLine("Could not read the listfile, extraction halted!"); + Console.WriteLine(); + } - // If we can't read the listfile, we just return - if (!listStream.CanRead) + // Read the listfile in for processing + using (StreamReader sr = new StreamReader(listStream)) + { + listfile = sr.ReadToEnd(); + } + + // Split the listfile by newlines + string[] listfileLines = listfile.Replace("\r\n", "\n").Split('\n'); + + // Loop over each entry + foreach (string sub in listfileLines) + { + // If an individual entry fails + try { - Console.WriteLine("Could not read the listfile, extraction halted!"); + string tempFile = Path.Combine(outputDirectory, sub); + Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); + mpqArchive.ExtractFile(sub, tempFile); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting MoPaQ entry {sub}: {ex}"); Console.WriteLine(); } - - // Read the listfile in for processing - using (StreamReader sr = new StreamReader(listStream)) - { - listfile = sr.ReadToEnd(); - } - - // Split the listfile by newlines - string[] listfileLines = listfile.Replace("\r\n", "\n").Split('\n'); - - // Loop over each entry - foreach (string sub in listfileLines) - { - // If an individual entry fails - try - { - string tempFile = Path.Combine(outputDirectory, sub); - Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); - mpqArchive.ExtractFile(sub, tempFile); - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting MoPaQ entry {sub}: {ex}"); - Console.WriteLine(); - } - } } } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting MoPaQ: {ex}"); - Console.WriteLine(); - } } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting MoPaQ: {ex}"); + Console.WriteLine(); + } + } #endif // PAK @@ -584,41 +601,43 @@ namespace Test Console.WriteLine("Extracting PKZIP contents"); Console.WriteLine(); +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else // If the zip file itself fails -#if NET462_OR_GREATER - try + try + { + using (ZipArchive zipFile = ZipArchive.Open(stream)) { - using (ZipArchive zipFile = ZipArchive.Open(stream)) + foreach (var entry in zipFile.Entries) { - foreach (var entry in zipFile.Entries) + // If an individual entry fails + try { - // If an individual entry fails - try - { - // If we have a directory, skip it - if (entry.IsDirectory) - continue; + // If we have a directory, skip it + if (entry.IsDirectory) + continue; - string tempFile = Path.Combine(outputDirectory, entry.Key); - Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); - entry.WriteToFile(tempFile); - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting PKZIP entry {entry.Key}: {ex}"); - Console.WriteLine(); - } + string tempFile = Path.Combine(outputDirectory, entry.Key); + string? directoryName = Path.GetDirectoryName(tempFile); + if (directoryName != null) + Directory.CreateDirectory(directoryName); + entry.WriteToFile(tempFile); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting PKZIP entry {entry.Key}: {ex}"); + Console.WriteLine(); } } } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting PKZIP: {ex}"); - Console.WriteLine(); - } -#else - Console.WriteLine($"Extracting PKZIP not supported on this .NET version"); - Console.WriteLine(); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting PKZIP: {ex}"); + Console.WriteLine(); + } #endif } @@ -656,40 +675,40 @@ namespace Test Console.WriteLine("Extracting RAR contents"); Console.WriteLine(); +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else // If the rar file itself fails -#if NET462_OR_GREATER - try + try + { + using (RarArchive rarFile = RarArchive.Open(stream)) { - using (RarArchive rarFile = RarArchive.Open(stream)) + foreach (var entry in rarFile.Entries) { - foreach (var entry in rarFile.Entries) + // If an individual entry fails + try { - // If an individual entry fails - try - { - // If we have a directory, skip it - if (entry.IsDirectory) - continue; + // If we have a directory, skip it + if (entry.IsDirectory) + continue; - string tempFile = Path.Combine(outputDirectory, entry.Key); - entry.WriteToFile(tempFile); - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting RAR entry {entry.Key}: {ex}"); - Console.WriteLine(); - } + string tempFile = Path.Combine(outputDirectory, entry.Key); + entry.WriteToFile(tempFile); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting RAR entry {entry.Key}: {ex}"); + Console.WriteLine(); } } } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting RAR: {ex}"); - Console.WriteLine(); - } -#else - Console.WriteLine($"Extracting RAR not supported on this .NET version"); - Console.WriteLine(); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting RAR: {ex}"); + Console.WriteLine(); + } #endif } @@ -727,40 +746,40 @@ namespace Test Console.WriteLine("Extracting Tape Archive contents"); Console.WriteLine(); +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else // If the tar file itself fails -#if NET462_OR_GREATER - try + try + { + using (TarArchive tarFile = TarArchive.Open(stream)) { - using (TarArchive tarFile = TarArchive.Open(stream)) + foreach (var entry in tarFile.Entries) { - foreach (var entry in tarFile.Entries) + // If an individual entry fails + try { - // If an individual entry fails - try - { - // If we have a directory, skip it - if (entry.IsDirectory) - continue; + // If we have a directory, skip it + if (entry.IsDirectory) + continue; - string tempFile = Path.Combine(outputDirectory, entry.Key); - entry.WriteToFile(tempFile); - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting Tape Archive entry {entry.Key}: {ex}"); - Console.WriteLine(); - } + string tempFile = Path.Combine(outputDirectory, entry.Key); + entry.WriteToFile(tempFile); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting Tape Archive entry {entry.Key}: {ex}"); + Console.WriteLine(); } } } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting Tape Archive: {ex}"); - Console.WriteLine(); - } -#else - Console.WriteLine($"Extracting Tape Archive not supported on this .NET version"); - Console.WriteLine(); + } + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting Tape Archive: {ex}"); + Console.WriteLine(); + } #endif } @@ -852,27 +871,27 @@ namespace Test Console.WriteLine("Extracting xz contents"); Console.WriteLine(); -#if NET462_OR_GREATER - using (var xzFile = new XZStream(stream)) +#if NET20 || NET35 || NET40 || NET452 + Console.WriteLine("Extraction is not supported for this framework!"); + Console.WriteLine(); +#else + using (var xzFile = new XZStream(stream)) + { + // If an individual entry fails + try { - // If an individual entry fails - try + string tempFile = Path.Combine(outputDirectory, Guid.NewGuid().ToString()); + using (FileStream fs = File.OpenWrite(tempFile)) { - string tempFile = Path.Combine(outputDirectory, Guid.NewGuid().ToString()); - using (FileStream fs = File.OpenWrite(tempFile)) - { - xzFile.CopyTo(fs); - } - } - catch (Exception ex) - { - Console.WriteLine($"Something went wrong extracting xz: {ex}"); - Console.WriteLine(); + xzFile.CopyTo(fs); } } -#else - Console.WriteLine($"Extracting xz not supported on this .NET version"); - Console.WriteLine(); + catch (Exception ex) + { + Console.WriteLine($"Something went wrong extracting xz: {ex}"); + Console.WriteLine(); + } + } #endif } diff --git a/Test/Options.cs b/Test/Options.cs index 345319ab..f8b34387 100644 --- a/Test/Options.cs +++ b/Test/Options.cs @@ -270,7 +270,7 @@ namespace Test private static bool ValidateExtractionPath(Options options) { // Null or empty output path - if (string.IsNullOrWhiteSpace(options.OutputPath)) + if (string.IsNullOrEmpty(options.OutputPath)) { Console.WriteLine("Output directory required for extraction!"); Console.WriteLine(); diff --git a/Test/Protector.cs b/Test/Protector.cs index aa0e4277..ff0741ee 100644 --- a/Test/Protector.cs +++ b/Test/Protector.cs @@ -1,8 +1,13 @@ using System; +#if NET20 || NET35 +using System.Collections.Generic; +#else using System.Collections.Concurrent; +#endif using System.IO; using System.Linq; using BinaryObjectScanner; +using BinaryObjectScanner.Utilities; namespace Test { @@ -39,7 +44,11 @@ namespace Test /// /// File or directory path /// Dictionary of protections found, if any +#if NET20 || NET35 + private static void WriteProtectionResultFile(string path, Dictionary>? protections) +#else private static void WriteProtectionResultFile(string path, ConcurrentDictionary>? protections) +#endif { if (protections == null) { @@ -54,7 +63,7 @@ namespace Test if (protections[key] == null || !protections[key].Any()) continue; - string line = $"{key}: {string.Join(", ", protections[key].OrderBy(p => p))}"; + string line = $"{key}: {string.Join(", ", [.. protections[key].OrderBy(p => p)])}"; Console.WriteLine(line); sw.WriteLine(line); } diff --git a/Test/Test.csproj b/Test/Test.csproj index a7f73e2d..5a623772 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -1,7 +1,7 @@  - net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 Exe false @@ -15,15 +15,19 @@ - + + + + + + - \ No newline at end of file