mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-22 06:45:03 +00:00
Simplify some directives
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BinaryObjectScanner.Interfaces;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)}";
|
||||
}
|
||||
|
||||
@@ -127,18 +127,10 @@ namespace BinaryObjectScanner.Protection
|
||||
public static string GetCactusDataShieldVersion(string firstMatchedString, IEnumerable<string> 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;
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -30,20 +30,12 @@ namespace BinaryObjectScanner.Protection
|
||||
var resultsList = new List<string>();
|
||||
|
||||
// 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<string> resultsList = new List<string>();
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -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)}";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)}";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user