Enable nullable context and move WrapperFactory

This commit is contained in:
Matt Nadareski
2023-09-17 00:18:04 -04:00
parent c86b1251a3
commit 93ba88a35f
72 changed files with 616 additions and 96 deletions

View File

@@ -11,7 +11,11 @@ namespace BinaryObjectScanner.FileType
public class AACSMediaKeyBlock : IDetectable
{
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -23,22 +27,26 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// If the MKB file itself fails
try
{
// Create the wrapper
SabreTools.Serialization.Wrappers.AACSMediaKeyBlock mkb = SabreTools.Serialization.Wrappers.AACSMediaKeyBlock.Create(stream);
var mkb = SabreTools.Serialization.Wrappers.AACSMediaKeyBlock.Create(stream);
if (mkb == null)
return null;
// Derive the version, if possible
var typeAndVersion = mkb.Model.Records.FirstOrDefault(r => r.RecordType == SabreTools.Models.AACS.RecordType.TypeAndVersion);
var typeAndVersion = mkb.Model.Records?.FirstOrDefault(r => r?.RecordType == SabreTools.Models.AACS.RecordType.TypeAndVersion);
if (typeAndVersion == null)
return "AACS (Unknown Version)";
else
return $"AACS {(typeAndVersion as SabreTools.Models.AACS.TypeAndVersionRecord).VersionNumber}";
return $"AACS {(typeAndVersion as SabreTools.Models.AACS.TypeAndVersionRecord)?.VersionNumber}";
}
catch (Exception ex)
{

View File

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

View File

@@ -12,7 +12,11 @@ namespace BinaryObjectScanner.FileType
public class BFPK : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -24,12 +28,16 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
try
{
// Create the wrapper
SabreTools.Serialization.Wrappers.BFPK bfpk = SabreTools.Serialization.Wrappers.BFPK.Create(stream);
var bfpk = SabreTools.Serialization.Wrappers.BFPK.Create(stream);
if (bfpk == null)
return null;

View File

@@ -11,7 +11,11 @@ namespace BinaryObjectScanner.FileType
public class BSP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -23,12 +27,16 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
try
{
// Create the wrapper
SabreTools.Serialization.Wrappers.BSP bsp = SabreTools.Serialization.Wrappers.BSP.Create(stream);
var bsp = SabreTools.Serialization.Wrappers.BSP.Create(stream);
if (bsp == null)
return null;

View File

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

View File

@@ -19,13 +19,16 @@
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)'!='net48'">
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BinaryObjectScanner.Compression\BinaryObjectScanner.Compression.csproj" />
<ProjectReference Include="..\BinaryObjectScanner.GameEngine\BinaryObjectScanner.GameEngine.csproj" />
<ProjectReference Include="..\BinaryObjectScanner.Interfaces\BinaryObjectScanner.Interfaces.csproj" />
<ProjectReference Include="..\BinaryObjectScanner.Packer\BinaryObjectScanner.Packer.csproj" />
<ProjectReference Include="..\BinaryObjectScanner.Protection\BinaryObjectScanner.Protection.csproj" />
<ProjectReference Include="..\BinaryObjectScanner.Wrappers\BinaryObjectScanner.Wrappers.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -12,7 +12,11 @@ namespace BinaryObjectScanner.FileType
public class CFB : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -24,7 +28,11 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
try
{
@@ -49,7 +57,14 @@ 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
if (decoded == null)
return;
byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
// UTF-8 encoding of 0x4840.
@@ -84,7 +99,11 @@ namespace BinaryObjectScanner.FileType
}
/// <remarks>Adapted from LibMSI</remarks>
#if NET48
public static string DecodeStreamName(string input)
#else
public static string? DecodeStreamName(string input)
#endif
{
if (input == null)
return null;

View File

@@ -8,7 +8,6 @@ using System.Text;
using System.Threading.Tasks;
using BinaryObjectScanner.Interfaces;
using BinaryObjectScanner.Utilities;
using BinaryObjectScanner.Wrappers;
using SabreTools.Serialization.Wrappers;
namespace BinaryObjectScanner.FileType
@@ -44,7 +43,7 @@ namespace BinaryObjectScanner.FileType
if (contentCheckClasses == null)
contentCheckClasses = InitCheckClasses<IContentCheck>();
return contentCheckClasses;
return contentCheckClasses ?? Enumerable.Empty<IContentCheck>();
}
}
@@ -58,7 +57,7 @@ namespace BinaryObjectScanner.FileType
if (linearExecutableCheckClasses == null)
linearExecutableCheckClasses = InitCheckClasses<ILinearExecutableCheck>();
return linearExecutableCheckClasses;
return linearExecutableCheckClasses ?? Enumerable.Empty<ILinearExecutableCheck>();
}
}
@@ -72,7 +71,7 @@ namespace BinaryObjectScanner.FileType
if (msdosExecutableCheckClasses == null)
msdosExecutableCheckClasses = InitCheckClasses<IMSDOSExecutableCheck>();
return msdosExecutableCheckClasses;
return msdosExecutableCheckClasses ?? Enumerable.Empty<IMSDOSExecutableCheck>();
}
}
@@ -86,7 +85,7 @@ namespace BinaryObjectScanner.FileType
if (newExecutableCheckClasses == null)
newExecutableCheckClasses = InitCheckClasses<INewExecutableCheck>();
return newExecutableCheckClasses;
return newExecutableCheckClasses ?? Enumerable.Empty<INewExecutableCheck>();
}
}
@@ -100,7 +99,7 @@ namespace BinaryObjectScanner.FileType
if (portableExecutableCheckClasses == null)
portableExecutableCheckClasses = InitCheckClasses<IPortableExecutableCheck>();
return portableExecutableCheckClasses;
return portableExecutableCheckClasses ?? Enumerable.Empty<IPortableExecutableCheck>();
}
}
@@ -111,32 +110,56 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Cache for all IContentCheck types
/// </summary>
#if NET48
private static IEnumerable<IContentCheck> contentCheckClasses;
#else
private static IEnumerable<IContentCheck>? contentCheckClasses;
#endif
/// <summary>
/// Cache for all ILinearExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<ILinearExecutableCheck> linearExecutableCheckClasses;
#else
private static IEnumerable<ILinearExecutableCheck>? linearExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all IMSDOSExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<IMSDOSExecutableCheck> msdosExecutableCheckClasses;
#else
private static IEnumerable<IMSDOSExecutableCheck>? msdosExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all INewExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<INewExecutableCheck> newExecutableCheckClasses;
#else
private static IEnumerable<INewExecutableCheck>? newExecutableCheckClasses;
#endif
/// <summary>
/// Cache for all IPortableExecutableCheck types
/// </summary>
#if NET48
private static IEnumerable<IPortableExecutableCheck> portableExecutableCheckClasses;
#else
private static IEnumerable<IPortableExecutableCheck>? portableExecutableCheckClasses;
#endif
#endregion
/// <inheritdoc/>
#if NET48
public string Detect(string file, bool includeDebug)
#else
public string? Detect(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -148,7 +171,11 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Detect(Stream stream, string file, bool includeDebug)
#else
public string? Detect(Stream stream, string file, bool includeDebug)
#endif
{
// Try to create a wrapper for the proper executable type
var wrapper = WrapperFactory.CreateExecutableWrapper(stream);
@@ -203,7 +230,11 @@ namespace BinaryObjectScanner.FileType
/// <param name="stream">Stream to scan the contents of</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Set of protections in file, null on error</returns>
#if NET48
public ConcurrentDictionary<IContentCheck, string> RunContentChecks(string file, Stream stream, bool includeDebug)
#else
public ConcurrentDictionary<IContentCheck, string>? RunContentChecks(string? file, Stream stream, bool includeDebug)
#endif
{
// If we have an invalid file
if (string.IsNullOrWhiteSpace(file))
@@ -212,7 +243,11 @@ namespace BinaryObjectScanner.FileType
return null;
// Read the file contents
#if NET48
byte[] fileContent = null;
#else
byte[]? fileContent = null;
#endif
try
{
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
@@ -396,15 +431,23 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>()
=> InitCheckClasses<T>(typeof(GameEngine._DUMMY).Assembly)
.Concat(InitCheckClasses<T>(typeof(Packer._DUMMY).Assembly))
.Concat(InitCheckClasses<T>(typeof(Protection._DUMMY).Assembly));
#else
private static IEnumerable<T>? InitCheckClasses<T>()
#endif
=> InitCheckClasses<T>(typeof(GameEngine._DUMMY).Assembly) ?? Enumerable.Empty<T>()
.Concat(InitCheckClasses<T>(typeof(Packer._DUMMY).Assembly) ?? Enumerable.Empty<T>())
.Concat(InitCheckClasses<T>(typeof(Protection._DUMMY).Assembly) ?? Enumerable.Empty<T>());
/// <summary>
/// Initialize all implementations of a type
/// </summary>
#if NET48
private static IEnumerable<T> InitCheckClasses<T>(Assembly assembly)
#else
private static IEnumerable<T>? InitCheckClasses<T>(Assembly assembly)
#endif
{
return assembly.GetTypes()
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)

View File

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

View File

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

View File

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

View File

@@ -12,7 +12,11 @@ namespace BinaryObjectScanner.FileType
public class InstallShieldCAB : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -24,18 +28,39 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
// Get the name of the first cabinet file or header
#if NET48
string directory = Path.GetDirectoryName(file);
#else
string? directory = Path.GetDirectoryName(file);
#endif
string noExtension = Path.GetFileNameWithoutExtension(file);
string filenamePattern = Path.Combine(directory, noExtension);
filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
bool shouldScanCabinet = cabinetHeaderExists
? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
: file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
bool shouldScanCabinet;
if (directory == null)
{
string filenamePattern = noExtension;
filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
bool cabinetHeaderExists = File.Exists(filenamePattern + "1.hdr");
shouldScanCabinet = cabinetHeaderExists
? file.Equals(filenamePattern + "1.hdr", StringComparison.OrdinalIgnoreCase)
: file.Equals(filenamePattern + "1.cab", StringComparison.OrdinalIgnoreCase);
}
else
{
string filenamePattern = Path.Combine(directory, noExtension);
filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
shouldScanCabinet = cabinetHeaderExists
? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
: file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
}
// If we have anything but the first file
if (!shouldScanCabinet)

View File

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

View File

@@ -13,7 +13,11 @@ namespace BinaryObjectScanner.FileType
public class MPQ : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -26,7 +30,11 @@ namespace BinaryObjectScanner.FileType
// TODO: Add stream opening support
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
#if NET6_0_OR_GREATER
// Not supported for .NET 6.0 due to Windows DLL requirements

View File

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

View File

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

View File

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

View File

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

View File

@@ -12,7 +12,11 @@ namespace BinaryObjectScanner.FileType
public class PKZIP : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -24,7 +28,11 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
try
{
@@ -43,7 +51,13 @@ namespace BinaryObjectScanner.FileType
continue;
string tempFile = Path.Combine(tempPath, entry.Key);
Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
#if NET48
string directoryName = Path.GetDirectoryName(tempFile);
#else
string? directoryName = Path.GetDirectoryName(tempFile);
#endif
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)

View File

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

View File

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

View File

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

View File

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

View File

@@ -13,7 +13,11 @@ namespace BinaryObjectScanner.FileType
public class SGA : IExtractable
{
/// <inheritdoc/>
#if NET48
public string Extract(string file, bool includeDebug)
#else
public string? Extract(string file, bool includeDebug)
#endif
{
if (!File.Exists(file))
return null;
@@ -25,12 +29,16 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
#if NET48
public string Extract(Stream stream, string file, bool includeDebug)
#else
public string? Extract(Stream stream, string file, bool includeDebug)
#endif
{
try
{
// Create the wrapper
SabreTools.Serialization.Wrappers.SGA sga = SabreTools.Serialization.Wrappers.SGA.Create(stream);
var sga = SabreTools.Serialization.Wrappers.SGA.Create(stream);
if (sga == null)
return null;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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