From f06c0f4553c3ffa473e11a9c67530e1842140811 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 17 Sep 2023 23:11:32 -0400 Subject: [PATCH] Simplify some directives --- BinaryObjectScanner.FileType/BFPK.cs | 6 +- BinaryObjectScanner.FileType/BSP.cs | 24 +----- BinaryObjectScanner.FileType/CFB.cs | 6 +- BinaryObjectScanner.FileType/Executable.cs | 36 ++------- BinaryObjectScanner.FileType/GCF.cs | 18 +---- .../InstallShieldArchiveV3.cs | 6 +- .../InstallShieldCAB.cs | 6 +- BinaryObjectScanner.FileType/MicrosoftCAB.cs | 12 +-- BinaryObjectScanner.FileType/PAK.cs | 18 +---- BinaryObjectScanner.FileType/PFF.cs | 6 +- BinaryObjectScanner.FileType/PKZIP.cs | 6 +- BinaryObjectScanner.FileType/Quantum.cs | 6 +- BinaryObjectScanner.FileType/SGA.cs | 24 +----- BinaryObjectScanner.FileType/Textfile.cs | 6 +- BinaryObjectScanner.FileType/VBSP.cs | 12 +-- BinaryObjectScanner.FileType/VPK.cs | 18 +---- BinaryObjectScanner.FileType/WAD.cs | 12 +-- BinaryObjectScanner.FileType/XZP.cs | 18 +---- BinaryObjectScanner.Packer/ASPack.cs | 6 +- .../AutoPlayMediaStudio.cs | 6 +- BinaryObjectScanner.Packer/MicrosoftCABSFX.cs | 1 - BinaryObjectScanner.Protection/DiscGuard.cs | 6 +- BinaryObjectScanner.Protection/Gefest.cs | 6 +- .../Macrovision.CactusDataShield.cs | 18 +---- .../Macrovision.RipGuard.cs | 6 +- .../Macrovision.SafeDisc.cs | 30 ++----- BinaryObjectScanner.Protection/Macrovision.cs | 78 ++++--------------- BinaryObjectScanner.Protection/ProtectDisc.cs | 6 +- BinaryObjectScanner.Protection/SolidShield.cs | 12 +-- BinaryObjectScanner.Protection/Sysiphus.cs | 6 +- BinaryObjectScanner.Protection/Tages.cs | 6 +- BinaryObjectScanner.Protection/XCP.cs | 12 +-- BinaryObjectScanner.Utilities/Extensions.cs | 6 +- .../WrapperFactory.cs | 6 +- 34 files changed, 75 insertions(+), 376 deletions(-) diff --git a/BinaryObjectScanner.FileType/BFPK.cs b/BinaryObjectScanner.FileType/BFPK.cs index 68d303c1..0adf5e6c 100644 --- a/BinaryObjectScanner.FileType/BFPK.cs +++ b/BinaryObjectScanner.FileType/BFPK.cs @@ -120,11 +120,7 @@ namespace BinaryObjectScanner.FileType using (FileStream fs = File.OpenWrite(filePath)) { // Read the data block -#if NET48 - byte[] data = item.ReadFromDataSource(offset, compressedSize); -#else - byte[]? data = item.ReadFromDataSource(offset, compressedSize); -#endif + var data = item.ReadFromDataSource(offset, compressedSize); if (data == null) return false; diff --git a/BinaryObjectScanner.FileType/BSP.cs b/BinaryObjectScanner.FileType/BSP.cs index 2af11ea8..b9251700 100644 --- a/BinaryObjectScanner.FileType/BSP.cs +++ b/BinaryObjectScanner.FileType/BSP.cs @@ -100,11 +100,7 @@ namespace BinaryObjectScanner.FileType return false; // Read the data -#if NET48 - byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#else - byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#endif + var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); if (data == null) return false; @@ -128,11 +124,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); @@ -196,11 +188,7 @@ namespace BinaryObjectScanner.FileType return false; // Read the data -#if NET48 - byte[] data = CreateTextureData(texture); -#else - byte[]? data = CreateTextureData(texture); -#endif + var data = CreateTextureData(texture); if (data == null) return false; @@ -215,11 +203,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/CFB.cs b/BinaryObjectScanner.FileType/CFB.cs index 807c2800..634fe987 100644 --- a/BinaryObjectScanner.FileType/CFB.cs +++ b/BinaryObjectScanner.FileType/CFB.cs @@ -57,11 +57,7 @@ namespace BinaryObjectScanner.FileType if (strData == null) return; -#if NET48 - string decoded = DecodeStreamName(e.Name).TrimEnd('\0'); -#else - string? decoded = DecodeStreamName(e.Name)?.TrimEnd('\0'); -#endif + var decoded = DecodeStreamName(e.Name)?.TrimEnd('\0'); if (decoded == null) return; diff --git a/BinaryObjectScanner.FileType/Executable.cs b/BinaryObjectScanner.FileType/Executable.cs index 0154ef32..ef7c0bac 100644 --- a/BinaryObjectScanner.FileType/Executable.cs +++ b/BinaryObjectScanner.FileType/Executable.cs @@ -243,11 +243,7 @@ namespace BinaryObjectScanner.FileType return null; // Read the file contents -#if NET48 - byte[] fileContent = null; -#else - byte[]? fileContent = null; -#endif + byte[] fileContent = new byte[0]; try { using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) @@ -270,11 +266,7 @@ namespace BinaryObjectScanner.FileType Parallel.ForEach(ContentCheckClasses, checkClass => { // Get the protection for the class, if possible -#if NET48 - string protection = checkClass.CheckContents(file, fileContent, includeDebug); -#else - string? protection = checkClass.CheckContents(file, fileContent, includeDebug); -#endif + var protection = checkClass.CheckContents(file, fileContent, includeDebug); if (string.IsNullOrWhiteSpace(protection)) return; @@ -308,11 +300,7 @@ namespace BinaryObjectScanner.FileType Parallel.ForEach(LinearExecutableCheckClasses, checkClass => { // Get the protection for the class, if possible -#if NET48 - string protection = checkClass.CheckLinearExecutable(file, lex, includeDebug); -#else - string? protection = checkClass.CheckLinearExecutable(file, lex, includeDebug); -#endif + var protection = checkClass.CheckLinearExecutable(file, lex, includeDebug); if (string.IsNullOrWhiteSpace(protection)) return; @@ -346,11 +334,7 @@ namespace BinaryObjectScanner.FileType Parallel.ForEach(MSDOSExecutableCheckClasses, checkClass => { // Get the protection for the class, if possible -#if NET48 - string protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug); -#else - string? protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug); -#endif + var protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug); if (string.IsNullOrWhiteSpace(protection)) return; @@ -384,11 +368,7 @@ namespace BinaryObjectScanner.FileType Parallel.ForEach(NewExecutableCheckClasses, checkClass => { // Get the protection for the class, if possible -#if NET48 - string protection = checkClass.CheckNewExecutable(file, nex, includeDebug); -#else - string? protection = checkClass.CheckNewExecutable(file, nex, includeDebug); -#endif + var protection = checkClass.CheckNewExecutable(file, nex, includeDebug); if (string.IsNullOrWhiteSpace(protection)) return; @@ -422,11 +402,7 @@ namespace BinaryObjectScanner.FileType Parallel.ForEach(PortableExecutableCheckClasses, checkClass => { // Get the protection for the class, if possible -#if NET48 - string protection = checkClass.CheckPortableExecutable(file, pex, includeDebug); -#else - string? protection = checkClass.CheckPortableExecutable(file, pex, includeDebug); -#endif + var protection = checkClass.CheckPortableExecutable(file, pex, includeDebug); if (string.IsNullOrWhiteSpace(protection)) return; diff --git a/BinaryObjectScanner.FileType/GCF.cs b/BinaryObjectScanner.FileType/GCF.cs index 6518e465..fab7b3f6 100644 --- a/BinaryObjectScanner.FileType/GCF.cs +++ b/BinaryObjectScanner.FileType/GCF.cs @@ -121,11 +121,7 @@ namespace BinaryObjectScanner.FileType } // Create the filename -#if NET48 - string filename = file.Path; -#else - string? filename = file.Path; -#endif + var filename = file.Path; // If we have an invalid output directory if (string.IsNullOrWhiteSpace(outputDirectory)) @@ -135,11 +131,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename ?? $"file{index}"); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); @@ -154,11 +146,7 @@ namespace BinaryObjectScanner.FileType for (int i = 0; i < dataBlockOffsets.Count; i++) { int readSize = (int)Math.Min(item.Model.DataBlockHeader?.BlockSize ?? 0, fileSize); -#if NET48 - byte[] data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize); -#else - byte[]? data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize); -#endif + var data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize); if (data == null) return false; diff --git a/BinaryObjectScanner.FileType/InstallShieldArchiveV3.cs b/BinaryObjectScanner.FileType/InstallShieldArchiveV3.cs index 724dc20b..7cf6efaa 100644 --- a/BinaryObjectScanner.FileType/InstallShieldArchiveV3.cs +++ b/BinaryObjectScanner.FileType/InstallShieldArchiveV3.cs @@ -46,11 +46,7 @@ namespace BinaryObjectScanner.FileType try { string tempFile = Path.Combine(tempPath, cfile.FullPath); -#if NET48 - string directoryName = Path.GetDirectoryName(tempFile); -#else - string? directoryName = Path.GetDirectoryName(tempFile); -#endif + var directoryName = Path.GetDirectoryName(tempFile); if (directoryName != null && !Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/InstallShieldCAB.cs b/BinaryObjectScanner.FileType/InstallShieldCAB.cs index 627de617..fa260de1 100644 --- a/BinaryObjectScanner.FileType/InstallShieldCAB.cs +++ b/BinaryObjectScanner.FileType/InstallShieldCAB.cs @@ -35,11 +35,7 @@ namespace BinaryObjectScanner.FileType #endif { // Get the name of the first cabinet file or header -#if NET48 - string directory = Path.GetDirectoryName(file); -#else - string? directory = Path.GetDirectoryName(file); -#endif + var directory = Path.GetDirectoryName(file); string noExtension = Path.GetFileNameWithoutExtension(file); bool shouldScanCabinet; diff --git a/BinaryObjectScanner.FileType/MicrosoftCAB.cs b/BinaryObjectScanner.FileType/MicrosoftCAB.cs index 8f21c93b..75d75b61 100644 --- a/BinaryObjectScanner.FileType/MicrosoftCAB.cs +++ b/BinaryObjectScanner.FileType/MicrosoftCAB.cs @@ -107,11 +107,7 @@ namespace BinaryObjectScanner.FileType if (dataBlock == null) continue; -#if NET48 - byte[] decompressed = new byte[dataBlock.UncompressedSize]; -#else - byte[]? decompressed = new byte[dataBlock.UncompressedSize]; -#endif + var decompressed = new byte[dataBlock.UncompressedSize]; switch (folder.CompressionType & SabreTools.Models.MicrosoftCabinet.CompressionType.MASK_TYPE) { case SabreTools.Models.MicrosoftCabinet.CompressionType.TYPE_NONE: @@ -192,11 +188,7 @@ namespace BinaryObjectScanner.FileType string fileName = Path.Combine(outputDirectory, file.Name ?? $"file{index}"); // Get the file data, if possible -#if NET48 - byte[] fileData = GetFileData(item, index); -#else - byte[]? fileData = GetFileData(item, index); -#endif + var fileData = GetFileData(item, index); if (fileData == null) return false; diff --git a/BinaryObjectScanner.FileType/PAK.cs b/BinaryObjectScanner.FileType/PAK.cs index 47d8b8ec..165cd87a 100644 --- a/BinaryObjectScanner.FileType/PAK.cs +++ b/BinaryObjectScanner.FileType/PAK.cs @@ -98,20 +98,12 @@ namespace BinaryObjectScanner.FileType return false; // Read the item data -#if NET48 - byte[] data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); -#else - byte[]? data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); -#endif + var data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); if (data == null) return false; // Create the filename -#if NET48 - string filename = directoryItem.ItemName; -#else - string? filename = directoryItem.ItemName; -#endif + var filename = directoryItem.ItemName; // If we have an invalid output directory if (string.IsNullOrWhiteSpace(outputDirectory)) @@ -121,11 +113,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename ?? $"file{index}"); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/PFF.cs b/BinaryObjectScanner.FileType/PFF.cs index ea869f8a..3ca2af7f 100644 --- a/BinaryObjectScanner.FileType/PFF.cs +++ b/BinaryObjectScanner.FileType/PFF.cs @@ -111,11 +111,7 @@ namespace BinaryObjectScanner.FileType using (FileStream fs = File.OpenWrite(filePath)) { // Read the data block -#if NET48 - byte[] data = item.ReadFromDataSource(offset, size); -#else - byte[]? data = item.ReadFromDataSource(offset, size); -#endif + var data = item.ReadFromDataSource(offset, size); if (data == null) return false; diff --git a/BinaryObjectScanner.FileType/PKZIP.cs b/BinaryObjectScanner.FileType/PKZIP.cs index ad8fd1ad..555a144d 100644 --- a/BinaryObjectScanner.FileType/PKZIP.cs +++ b/BinaryObjectScanner.FileType/PKZIP.cs @@ -51,11 +51,7 @@ namespace BinaryObjectScanner.FileType continue; string tempFile = Path.Combine(tempPath, entry.Key); -#if NET48 - string directoryName = Path.GetDirectoryName(tempFile); -#else - string? directoryName = Path.GetDirectoryName(tempFile); -#endif + var directoryName = Path.GetDirectoryName(tempFile); if (directoryName != null && !Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName); entry.WriteToFile(tempFile); diff --git a/BinaryObjectScanner.FileType/Quantum.cs b/BinaryObjectScanner.FileType/Quantum.cs index 08f04191..a5ee4380 100644 --- a/BinaryObjectScanner.FileType/Quantum.cs +++ b/BinaryObjectScanner.FileType/Quantum.cs @@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType // Read the entire compressed data int compressedDataOffset = (int)item.Model.CompressedDataOffset; int compressedDataLength = item.GetEndOfFile() - compressedDataOffset; -#if NET48 - byte[] compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength); -#else - byte[]? compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength); -#endif + var compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength); // TODO: Figure out decompression // - Single-file archives seem to work diff --git a/BinaryObjectScanner.FileType/SGA.cs b/BinaryObjectScanner.FileType/SGA.cs index c28cf38d..d5476e3c 100644 --- a/BinaryObjectScanner.FileType/SGA.cs +++ b/BinaryObjectScanner.FileType/SGA.cs @@ -136,11 +136,7 @@ namespace BinaryObjectScanner.FileType return false; // Create the filename -#if NET48 - string filename; -#else - string? filename; -#endif + var filename = string.Empty; switch (item.Model.Header?.MajorVersion) { case 4: @@ -158,11 +154,7 @@ namespace BinaryObjectScanner.FileType #endif // Get the parent directory -#if NET48 - object folder; -#else - object? folder; -#endif + var folder = default(object); switch (item.Model.Header?.MajorVersion) { #if NET48 @@ -240,11 +232,7 @@ namespace BinaryObjectScanner.FileType } // Read the compressed data directly -#if NET48 - byte[] compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize); -#else - byte[]? compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize); -#endif + var compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize); if (compressedData == null) return false; @@ -271,11 +259,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/Textfile.cs b/BinaryObjectScanner.FileType/Textfile.cs index 15b9d992..5ba0fdf1 100644 --- a/BinaryObjectScanner.FileType/Textfile.cs +++ b/BinaryObjectScanner.FileType/Textfile.cs @@ -40,11 +40,7 @@ namespace BinaryObjectScanner.FileType try { // Load the current file content -#if NET48 - string fileContent = null; -#else - string? fileContent = null; -#endif + var fileContent = string.Empty; using (var sr = new StreamReader(stream, Encoding.Default, true, 1024 * 1024, true)) { fileContent = sr.ReadToEnd(); diff --git a/BinaryObjectScanner.FileType/VBSP.cs b/BinaryObjectScanner.FileType/VBSP.cs index 47d4c78d..be917a7d 100644 --- a/BinaryObjectScanner.FileType/VBSP.cs +++ b/BinaryObjectScanner.FileType/VBSP.cs @@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType return false; // Read the data -#if NET48 - byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#else - byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#endif + var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); if (data == null) return false; @@ -126,11 +122,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/VPK.cs b/BinaryObjectScanner.FileType/VPK.cs index fd6e37e9..80156a84 100644 --- a/BinaryObjectScanner.FileType/VPK.cs +++ b/BinaryObjectScanner.FileType/VPK.cs @@ -100,11 +100,7 @@ namespace BinaryObjectScanner.FileType return false; // If we have an item with no archive -#if NET48 - byte[] data; -#else - byte[]? data; -#endif + var data = new byte[0]; if (directoryItem.DirectoryEntry.ArchiveIndex == SabreTools.Models.VPK.Constants.HL_VPK_NO_ARCHIVE) { if (directoryItem.PreloadData == null) @@ -132,11 +128,7 @@ namespace BinaryObjectScanner.FileType return false; // Try to open the archive -#if NET48 - Stream archiveStream = null; -#else - Stream? archiveStream = null; -#endif + var archiveStream = default(Stream); try { // Open the archive @@ -179,11 +171,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/WAD.cs b/BinaryObjectScanner.FileType/WAD.cs index 586043be..d69cabdb 100644 --- a/BinaryObjectScanner.FileType/WAD.cs +++ b/BinaryObjectScanner.FileType/WAD.cs @@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType return false; // Read the data -- TODO: Handle uncompressed lumps (see BSP.ExtractTexture) -#if NET48 - byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#else - byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); -#endif + var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length); if (data == null) return false; @@ -117,11 +113,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.FileType/XZP.cs b/BinaryObjectScanner.FileType/XZP.cs index 5dfd81fe..578c8be9 100644 --- a/BinaryObjectScanner.FileType/XZP.cs +++ b/BinaryObjectScanner.FileType/XZP.cs @@ -108,20 +108,12 @@ namespace BinaryObjectScanner.FileType return false; // Load the item data -#if NET48 - byte[] data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength); -#else - byte[]? data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength); -#endif + var data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength); if (data == null) return false; // Create the filename -#if NET48 - string filename = directoryItem.Name; -#else - string? filename = directoryItem.Name; -#endif + var filename = directoryItem.Name; // If we have an invalid output directory if (string.IsNullOrWhiteSpace(outputDirectory)) @@ -131,11 +123,7 @@ namespace BinaryObjectScanner.FileType filename = Path.Combine(outputDirectory, filename ?? $"file{index}"); // Ensure the output directory is created -#if NET48 - string directoryName = Path.GetDirectoryName(filename); -#else - string? directoryName = Path.GetDirectoryName(filename); -#endif + var directoryName = Path.GetDirectoryName(filename); if (directoryName != null) Directory.CreateDirectory(directoryName); diff --git a/BinaryObjectScanner.Packer/ASPack.cs b/BinaryObjectScanner.Packer/ASPack.cs index c8bcd67f..855a7ac8 100644 --- a/BinaryObjectScanner.Packer/ASPack.cs +++ b/BinaryObjectScanner.Packer/ASPack.cs @@ -39,13 +39,9 @@ namespace BinaryObjectScanner.Packer // Get the .adata* section, if it exists var adataSection = pex.GetFirstSection(".adata", exact: false); - if (adataSection != null) + if (adataSection?.Name != null) { -#if NET48 var adataSectionRaw = pex.GetFirstSectionData(Encoding.UTF8.GetString(adataSection.Name)); -#else - var adataSectionRaw = pex.GetFirstSectionData(Encoding.UTF8.GetString(adataSection.Name!)); -#endif if (adataSectionRaw != null) { var matchers = GenerateMatchers(); diff --git a/BinaryObjectScanner.Packer/AutoPlayMediaStudio.cs b/BinaryObjectScanner.Packer/AutoPlayMediaStudio.cs index 100d9e8f..d75c3281 100644 --- a/BinaryObjectScanner.Packer/AutoPlayMediaStudio.cs +++ b/BinaryObjectScanner.Packer/AutoPlayMediaStudio.cs @@ -66,11 +66,7 @@ namespace BinaryObjectScanner.Packer private string GetVersion(PortableExecutable pex) { // Check the product version explicitly -#if NET48 - string version = pex.ProductVersion; -#else - string? version = pex.ProductVersion; -#endif + var version = pex.ProductVersion; if (!string.IsNullOrEmpty(version)) return version; diff --git a/BinaryObjectScanner.Packer/MicrosoftCABSFX.cs b/BinaryObjectScanner.Packer/MicrosoftCABSFX.cs index 79fcb0e7..77a70cb7 100644 --- a/BinaryObjectScanner.Packer/MicrosoftCABSFX.cs +++ b/BinaryObjectScanner.Packer/MicrosoftCABSFX.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using BinaryObjectScanner.Interfaces; diff --git a/BinaryObjectScanner.Protection/DiscGuard.cs b/BinaryObjectScanner.Protection/DiscGuard.cs index bd51d538..c8cddabf 100644 --- a/BinaryObjectScanner.Protection/DiscGuard.cs +++ b/BinaryObjectScanner.Protection/DiscGuard.cs @@ -194,11 +194,7 @@ namespace BinaryObjectScanner.Protection private string GetVersion(PortableExecutable pex) { // Check the internal versions -#if NET48 - string version = pex.GetInternalVersion(); -#else - string? version = pex.GetInternalVersion(); -#endif + var version = pex.GetInternalVersion(); if (!string.IsNullOrEmpty(version)) return version; diff --git a/BinaryObjectScanner.Protection/Gefest.cs b/BinaryObjectScanner.Protection/Gefest.cs index 320a5a5d..d33ca758 100644 --- a/BinaryObjectScanner.Protection/Gefest.cs +++ b/BinaryObjectScanner.Protection/Gefest.cs @@ -34,11 +34,7 @@ namespace BinaryObjectScanner.Protection // Get the header padding strings, if it exists if (pex.HeaderPaddingStrings != null) { -#if NET48 - string match = pex.HeaderPaddingStrings.FirstOrDefault(s => s.Contains("Gefest Protection System")); -#else - string? match = pex.HeaderPaddingStrings.FirstOrDefault(s => s.Contains("Gefest Protection System")); -#endif + var match = pex.HeaderPaddingStrings.FirstOrDefault(s => s.Contains("Gefest Protection System")); if (match != null) return $"Gefest Protection System {GetVersion(match)}"; } diff --git a/BinaryObjectScanner.Protection/Macrovision.CactusDataShield.cs b/BinaryObjectScanner.Protection/Macrovision.CactusDataShield.cs index d3aa23b5..13e7dfd9 100644 --- a/BinaryObjectScanner.Protection/Macrovision.CactusDataShield.cs +++ b/BinaryObjectScanner.Protection/Macrovision.CactusDataShield.cs @@ -127,18 +127,10 @@ namespace BinaryObjectScanner.Protection public static string GetCactusDataShieldVersion(string firstMatchedString, IEnumerable files) { // Find the version.txt file first -#if NET48 - string versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); -#else - string? versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); -#endif + var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrWhiteSpace(versionPath)) { -#if NET48 - string version = GetCactusDataShieldInternalVersion(versionPath); -#else - string? version = GetCactusDataShieldInternalVersion(versionPath); -#endif + var version = GetCactusDataShieldInternalVersion(versionPath); if (!string.IsNullOrWhiteSpace(version)) return version; } @@ -159,11 +151,7 @@ namespace BinaryObjectScanner.Protection { using (var sr = new StreamReader(path, Encoding.Default)) { -#if NET48 - string line = sr.ReadLine(); -#else - string? line = sr.ReadLine(); -#endif + var line = sr.ReadLine(); if (line == null) return null; diff --git a/BinaryObjectScanner.Protection/Macrovision.RipGuard.cs b/BinaryObjectScanner.Protection/Macrovision.RipGuard.cs index b858a3a2..d80da811 100644 --- a/BinaryObjectScanner.Protection/Macrovision.RipGuard.cs +++ b/BinaryObjectScanner.Protection/Macrovision.RipGuard.cs @@ -49,11 +49,7 @@ namespace BinaryObjectScanner.Protection // So far, every seemingly-randomly named EXE on RipGuard discs have a consistent hash. if (fi.Length == 49_152) { -#if NET48 - string sha1 = GetFileSHA1(file); -#else - string? sha1 = GetFileSHA1(file); -#endif + var sha1 = GetFileSHA1(file); if (sha1 == "6A7B8545800E0AB252773A8CD0A2185CA2497938") return "RipGuard"; } diff --git a/BinaryObjectScanner.Protection/Macrovision.SafeDisc.cs b/BinaryObjectScanner.Protection/Macrovision.SafeDisc.cs index e3d9d845..396fd31f 100644 --- a/BinaryObjectScanner.Protection/Macrovision.SafeDisc.cs +++ b/BinaryObjectScanner.Protection/Macrovision.SafeDisc.cs @@ -308,11 +308,7 @@ namespace BinaryObjectScanner.Protection return string.Empty; // The hash of the file CLCD16.dll is able to provide a broad version range that appears to be consistent, but it seems it was rarely updated so these checks are quite broad. -#if NET48 - string sha1 = GetFileSHA1(firstMatchedString); -#else - string? sha1 = GetFileSHA1(firstMatchedString); -#endif + var sha1 = GetFileSHA1(firstMatchedString); switch (sha1) { // Found in Redump entries 61731 and 66005. @@ -336,11 +332,7 @@ namespace BinaryObjectScanner.Protection return string.Empty; // The hash of the file CLCD32.dll so far appears to be a solid indicator of version for versions it was used with. It appears to have been updated with every release, unlike its counterpart, CLCD16.dll. -#if NET48 - string sha1 = GetFileSHA1(firstMatchedString); -#else - string? sha1 = GetFileSHA1(firstMatchedString); -#endif + var sha1 = GetFileSHA1(firstMatchedString); switch (sha1) { // Found in Redump entry 66005. @@ -440,11 +432,7 @@ namespace BinaryObjectScanner.Protection // The hash of every "CLOKSPL.EXE" correlates directly to a specific SafeDisc version. -#if NET48 - string sha1 = GetFileSHA1(firstMatchedString); -#else - string? sha1 = GetFileSHA1(firstMatchedString); -#endif + var sha1 = GetFileSHA1(firstMatchedString); switch (sha1) { // Found in Redump entry 66005. @@ -592,11 +580,7 @@ namespace BinaryObjectScanner.Protection // There are occasionaly inconsistencies, even within the well detected version range. This seems to me to mostly happen with later (3.20+) games, and seems to me to be an example of the SafeDisc distribution becoming more disorganized with time. // Particularly interesting inconsistencies will be noted below: // Redump entry 73786 has an EXE with a scrubbed version, a DIAG.exe with a version of 4.60.000, and a copy of drvmgt.dll belonging to version 3.10.020. This seems like an accidental(?) distribution of older drivers, as this game was released 3 years after the use of 3.10.020. -#if NET48 - string sha1 = GetFileSHA1(firstMatchedString); -#else - string? sha1 = GetFileSHA1(firstMatchedString); -#endif + var sha1 = GetFileSHA1(firstMatchedString); switch (sha1) { // Found in Redump entry 102979. @@ -800,11 +784,7 @@ namespace BinaryObjectScanner.Protection private string GetSafeDiscDiagExecutableVersion(PortableExecutable pex) { // Different versions of this executable correspond to different SafeDisc versions. -#if NET48 - string version = pex.FileVersion; -#else - string? version = pex.FileVersion; -#endif + var version = pex.FileVersion; if (!string.IsNullOrEmpty(version)) { switch (version) diff --git a/BinaryObjectScanner.Protection/Macrovision.cs b/BinaryObjectScanner.Protection/Macrovision.cs index cda6019c..e8e4d8ef 100644 --- a/BinaryObjectScanner.Protection/Macrovision.cs +++ b/BinaryObjectScanner.Protection/Macrovision.cs @@ -30,20 +30,12 @@ namespace BinaryObjectScanner.Protection var resultsList = new List(); // Run C-Dilla NE checks -#if NET48 - string cDilla = CDillaCheckNewExecutable(file, nex, includeDebug); -#else - string? cDilla = CDillaCheckNewExecutable(file, nex, includeDebug); -#endif + var cDilla = CDillaCheckNewExecutable(file, nex, includeDebug); if (!string.IsNullOrWhiteSpace(cDilla)) resultsList.Add(cDilla); // Run SafeCast NE checks -#if NET48 - string safeCast = SafeCastCheckNewExecutable(file, nex, includeDebug); -#else - string? safeCast = SafeCastCheckNewExecutable(file, nex, includeDebug); -#endif + var safeCast = SafeCastCheckNewExecutable(file, nex, includeDebug); if (!string.IsNullOrWhiteSpace(safeCast)) resultsList.Add(safeCast); @@ -88,11 +80,7 @@ namespace BinaryObjectScanner.Protection if (stxt371Section || stxt774Section) { // Check the header padding for protected sections. -#if NET48 - string sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, true); -#else - string? sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, true); -#endif + var sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, true); if (!string.IsNullOrWhiteSpace(sectionMatch)) { resultsList.Add(sectionMatch); @@ -106,11 +94,7 @@ namespace BinaryObjectScanner.Protection } int entryPointIndex = pex.FindEntryPointSectionIndex(); -#if NET48 - string entryPointSectionName = pex.SectionNames[entryPointIndex]; -#else - string? entryPointSectionName = pex.SectionNames?[entryPointIndex]; -#endif + var entryPointSectionName = pex.SectionNames?[entryPointIndex]; switch (entryPointSectionName) { @@ -133,11 +117,7 @@ namespace BinaryObjectScanner.Protection else { // Check the header padding for protected sections. -#if NET48 - string sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, false); -#else - string? sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, false); -#endif + var sectionMatch = CheckSectionForProtection(file, includeDebug, pex.HeaderPaddingStrings, pex.HeaderPaddingData, false); if (!string.IsNullOrWhiteSpace(sectionMatch)) { resultsList.Add(sectionMatch); @@ -152,11 +132,7 @@ namespace BinaryObjectScanner.Protection } // Run Cactus Data Shield PE checks -#if NET48 - string match = CactusDataShieldCheckPortableExecutable(file, pex, includeDebug); -#else - string? match = CactusDataShieldCheckPortableExecutable(file, pex, includeDebug); -#endif + var match = CactusDataShieldCheckPortableExecutable(file, pex, includeDebug); if (!string.IsNullOrWhiteSpace(match)) resultsList.Add(match); @@ -244,56 +220,32 @@ namespace BinaryObjectScanner.Protection List resultsList = new List(); // Run Macrovision file checks -#if NET48 - string macrovision = MacrovisionCheckFilePath(path); -#else - string? macrovision = MacrovisionCheckFilePath(path); -#endif + var macrovision = MacrovisionCheckFilePath(path); if (!string.IsNullOrWhiteSpace(macrovision)) resultsList.Add(macrovision); // Run Cactus Data Shield file checks -#if NET48 - string cactusDataShield = CactusDataShieldCheckFilePath(path); -#else - string? cactusDataShield = CactusDataShieldCheckFilePath(path); -#endif + var cactusDataShield = CactusDataShieldCheckFilePath(path); if (!string.IsNullOrWhiteSpace(cactusDataShield)) resultsList.Add(cactusDataShield); // Run C-Dilla file checks -#if NET48 - string cDilla = CDillaCheckFilePath(path); -#else - string? cDilla = CDillaCheckFilePath(path); -#endif + var cDilla = CDillaCheckFilePath(path); if (!string.IsNullOrWhiteSpace(cDilla)) resultsList.Add(cDilla); // Run RipGuard file checks -#if NET48 - string ripGuard = RipGuardCheckFilePath(path); -#else - string? ripGuard = RipGuardCheckFilePath(path); -#endif + var ripGuard = RipGuardCheckFilePath(path); if (!string.IsNullOrWhiteSpace(ripGuard)) resultsList.Add(ripGuard); // Run SafeCast file checks -#if NET48 - string safeCast = SafeCastCheckFilePath(path); -#else - string? safeCast = SafeCastCheckFilePath(path); -#endif + var safeCast = SafeCastCheckFilePath(path); if (!string.IsNullOrWhiteSpace(safeCast)) resultsList.Add(safeCast); // Run SafeDisc file checks -#if NET48 - string safeDisc = SafeDiscCheckFilePath(path); -#else - string? safeDisc = SafeDiscCheckFilePath(path); -#endif + var safeDisc = SafeDiscCheckFilePath(path); if (!string.IsNullOrWhiteSpace(safeDisc)) resultsList.Add(safeDisc); @@ -437,11 +389,7 @@ namespace BinaryObjectScanner.Protection { // Different versions of this driver correspond to different SafeDisc versions. // TODO: Check if earlier versions of this driver contain the version string in a less obvious place. -#if NET48 - string version = pex.FileVersion; -#else - string? version = pex.FileVersion; -#endif + var version = pex.FileVersion; if (!string.IsNullOrEmpty(version)) { switch (version) diff --git a/BinaryObjectScanner.Protection/ProtectDisc.cs b/BinaryObjectScanner.Protection/ProtectDisc.cs index 4997c16d..5942377e 100644 --- a/BinaryObjectScanner.Protection/ProtectDisc.cs +++ b/BinaryObjectScanner.Protection/ProtectDisc.cs @@ -62,11 +62,7 @@ namespace BinaryObjectScanner.Protection var strs = pex.GetSectionStrings(sections.Length - 2); if (strs != null) { -#if NET48 - string str = strs.FirstOrDefault(s => s.Contains("VOB ProtectCD")); -#else - string? str = strs.FirstOrDefault(s => s.Contains("VOB ProtectCD")); -#endif + var str = strs.FirstOrDefault(s => s.Contains("VOB ProtectCD")); if (str != null) return $"VOB ProtectCD {GetOldVersion(str)}"; } diff --git a/BinaryObjectScanner.Protection/SolidShield.cs b/BinaryObjectScanner.Protection/SolidShield.cs index b40422e2..dd283fe6 100644 --- a/BinaryObjectScanner.Protection/SolidShield.cs +++ b/BinaryObjectScanner.Protection/SolidShield.cs @@ -87,11 +87,7 @@ namespace BurnOutSharp.ProtectionType var strs = pex.GetSectionStrings(i); if (strs != null) { -#if NET48 - string str = strs.FirstOrDefault(s => s.Contains("Solidshield ")); -#else - string? str = strs.FirstOrDefault(s => s.Contains("Solidshield ")); -#endif + var str = strs.FirstOrDefault(s => s.Contains("Solidshield ")); if (str != null) return $"SolidShield EXE Wrapper {str.Substring("Solidshield ".Length)}"; } @@ -207,11 +203,7 @@ namespace BurnOutSharp.ProtectionType private static string GetInternalVersion(PortableExecutable pex) { -#if NET48 - string companyName = pex.CompanyName?.ToLowerInvariant(); -#else - string? companyName = pex.CompanyName?.ToLowerInvariant(); -#endif + var companyName = pex.CompanyName?.ToLowerInvariant(); if (!string.IsNullOrWhiteSpace(companyName) && (companyName.Contains("solidshield") || companyName.Contains("tages"))) return pex.GetInternalVersion() ?? string.Empty; diff --git a/BinaryObjectScanner.Protection/Sysiphus.cs b/BinaryObjectScanner.Protection/Sysiphus.cs index 83f09780..11340d16 100644 --- a/BinaryObjectScanner.Protection/Sysiphus.cs +++ b/BinaryObjectScanner.Protection/Sysiphus.cs @@ -23,11 +23,7 @@ namespace BinaryObjectScanner.Protection var strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA"); if (strs != null) { -#if NET48 - string str = strs.FirstOrDefault(s => s.Contains("V SUHPISYS")); -#else - string? str = strs.FirstOrDefault(s => s.Contains("V SUHPISYS")); -#endif + var str = strs.FirstOrDefault(s => s.Contains("V SUHPISYS")); if (str != null) return $"Sysiphus {GetVersion(str)}"; } diff --git a/BinaryObjectScanner.Protection/Tages.cs b/BinaryObjectScanner.Protection/Tages.cs index e51574ef..0c2a8796 100644 --- a/BinaryObjectScanner.Protection/Tages.cs +++ b/BinaryObjectScanner.Protection/Tages.cs @@ -221,11 +221,7 @@ namespace BurnOutSharp.ProtectionType private string GetVersion(PortableExecutable pex) { // Check the internal versions -#if NET48 - string version = pex.GetInternalVersion(); -#else - string? version = pex.GetInternalVersion(); -#endif + var version = pex.GetInternalVersion(); if (!string.IsNullOrEmpty(version)) return version; diff --git a/BinaryObjectScanner.Protection/XCP.cs b/BinaryObjectScanner.Protection/XCP.cs index 96108d68..7a06a7e7 100644 --- a/BinaryObjectScanner.Protection/XCP.cs +++ b/BinaryObjectScanner.Protection/XCP.cs @@ -57,18 +57,10 @@ namespace BinaryObjectScanner.Protection if (files.Any(f => Path.GetFileName(f).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)) || files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))) { -#if NET48 - string versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); -#else - string? versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); -#endif + var versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrWhiteSpace(versionDatPath)) { -#if NET48 - string xcpVersion = GetDatVersion(versionDatPath); -#else - string? xcpVersion = GetDatVersion(versionDatPath); -#endif + var xcpVersion = GetDatVersion(versionDatPath); if (!string.IsNullOrWhiteSpace(xcpVersion)) protections.Enqueue(xcpVersion); } diff --git a/BinaryObjectScanner.Utilities/Extensions.cs b/BinaryObjectScanner.Utilities/Extensions.cs index c3672ef3..50391c7a 100644 --- a/BinaryObjectScanner.Utilities/Extensions.cs +++ b/BinaryObjectScanner.Utilities/Extensions.cs @@ -33,11 +33,7 @@ namespace BinaryObjectScanner.Utilities { while (!values.IsEmpty) { -#if NET48 - if (!values.TryDequeue(out string value)) -#else - if (!values.TryDequeue(out string? value)) -#endif + if (!values.TryDequeue(out var value)) return; original.Enqueue(value); diff --git a/BinaryObjectScanner.Utilities/WrapperFactory.cs b/BinaryObjectScanner.Utilities/WrapperFactory.cs index f8446368..92590e5d 100644 --- a/BinaryObjectScanner.Utilities/WrapperFactory.cs +++ b/BinaryObjectScanner.Utilities/WrapperFactory.cs @@ -89,11 +89,7 @@ namespace BinaryObjectScanner.Utilities // Try to read the executable info stream.Seek(msdos.Model.Header.NewExeHeaderAddr, SeekOrigin.Begin); -#if NET48 - byte[] magic = stream.ReadBytes(4); -#else - byte[]? magic = stream.ReadBytes(4); -#endif + var magic = stream.ReadBytes(4); // If we didn't get valid data at the offset if (magic == null)