Wrapper-based extractables are now thinner

This commit is contained in:
Matt Nadareski
2025-09-06 11:48:32 -04:00
parent 00db772594
commit e87a0ff8ec
34 changed files with 124 additions and 284 deletions

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var bfpk = SabreTools.Serialization.Wrappers.BFPK.Create(stream);
if (bfpk == null)
return false;
// Extract all files
Directory.CreateDirectory(outDir);
bfpk.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,18 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var bsp = SabreTools.Serialization.Wrappers.BSP.Create(stream);
if (bsp == null)
return false;
// TODO: Introduce helper methods for all specialty lump types
// Loop through and extract all files
Directory.CreateDirectory(outDir);
bsp.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,20 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Handle invalid inputs
if (stream == null || stream.Length == 0)
return false;
// Create the wrapper
var bzip = SabreTools.Serialization.Wrappers.BZip2.Create(stream);
if (bzip == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
bzip.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var cfb = SabreTools.Serialization.Wrappers.CFB.Create(stream);
if (cfb == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
cfb.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -0,0 +1,51 @@
using System.IO;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Base class for all standard detectable/extractable types
/// </summary>
public abstract class DetectableExtractableBase : IDetectable, IExtractable
{
#region Constructors
public DetectableExtractableBase() { }
#endregion
#region IDetectable Implementations
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public abstract string? Detect(Stream stream, string file, bool includeDebug);
#endregion
#region IExtractable Implementations
/// <inheritdoc/>
public bool Extract(string file, string outDir, bool includeDebug)
{
if (!File.Exists(file))
return false;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Extract(fs, file, outDir, includeDebug);
}
/// <inheritdoc/>
public abstract bool Extract(Stream? stream, string file, string outDir, bool includeDebug);
#endregion
}
}

View File

@@ -0,0 +1,34 @@
using System;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Base class for all standard detectable/extractable types with a wrapper
/// </summary>
public abstract class DetectableExtractableBase<T> : DetectableExtractableBase, IDetectable<T>, IExtractable<T>
where T : IWrapper
{
#region Protected Instance Variables
/// <summary>
/// Wrapper representing the detectable/extractable
/// </summary>
protected T _wrapper { get; private set; }
#endregion
#region Constructors
public DetectableExtractableBase(T? wrapper)
{
if (wrapper == null)
throw new ArgumentNullException(nameof(wrapper));
_wrapper = wrapper;
}
#endregion
}
}

View File

@@ -11,7 +11,7 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Executable or library
/// </summary>
public abstract class Executable<T> : DetectableBase<T>
public abstract class Executable<T> : DetectableExtractableBase<T>
where T : WrapperBase
{
/// <inheritdoc/>

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var gcf = SabreTools.Serialization.Wrappers.GCF.Create(stream);
if (gcf == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
gcf.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var gcf = SabreTools.Serialization.Wrappers.GZip.Create(stream);
if (gcf == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
gcf.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var isv3 = SabreTools.Serialization.Wrappers.InstallShieldArchiveV3.Create(stream);
if (isv3 == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
isv3.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var iscab = SabreTools.Serialization.Wrappers.InstallShieldCabinet.Create(stream);
if (iscab == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
iscab.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var kwaj = SabreTools.Serialization.Wrappers.LZKWAJ.Create(stream);
if (kwaj == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
kwaj.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var qbasic = SabreTools.Serialization.Wrappers.LZQBasic.Create(stream);
if (qbasic == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
qbasic.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var szdd = SabreTools.Serialization.Wrappers.LZSZDD.Create(stream);
if (szdd == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
szdd.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -43,5 +43,8 @@ namespace BinaryObjectScanner.FileType
return string.Join(";", [.. protectionList]);
}
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug) => false;
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var mpq = SabreTools.Serialization.Wrappers.MoPaQ.Create(stream);
if (mpq == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
mpq.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -43,5 +43,8 @@ namespace BinaryObjectScanner.FileType
return string.Join(";", [.. protectionList]);
}
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug) => false;
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var mscab = SabreTools.Serialization.Wrappers.MicrosoftCabinet.Create(stream);
if (mscab == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
mscab.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -1,14 +1,13 @@
using System.Collections.Generic;
using System.IO;
using BinaryObjectScanner.Data;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// New executable (NE)
/// </summary>
public class NewExecutable : Executable<SabreTools.Serialization.Wrappers.NewExecutable>, IExtractable
public class NewExecutable : Executable<SabreTools.Serialization.Wrappers.NewExecutable>
{
/// <inheritdoc/>
public NewExecutable(SabreTools.Serialization.Wrappers.NewExecutable? wrapper) : base(wrapper) { }
@@ -46,12 +45,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
/// <remarks>Uses the already-generated wrapper</remarks>
public bool Extract(string file, string outDir, bool includeDebug)
=> Extract(null, file, outDir, includeDebug);
/// <inheritdoc/>
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the output directory
Directory.CreateDirectory(outDir);

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var pak = SabreTools.Serialization.Wrappers.PAK.Create(stream);
if (pak == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
pak.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var pff = SabreTools.Serialization.Wrappers.PFF.Create(stream);
if (pff == null)
return false;
// Extract all files
Directory.CreateDirectory(outDir);
pff.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var pkzip = SabreTools.Serialization.Wrappers.PKZIP.Create(stream);
if (pkzip == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
pkzip.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -1,14 +1,13 @@
using System.Collections.Generic;
using System.IO;
using BinaryObjectScanner.Data;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Portable executable (PE)
/// </summary>
public class PortableExecutable : Executable<SabreTools.Serialization.Wrappers.PortableExecutable>, IExtractable
public class PortableExecutable : Executable<SabreTools.Serialization.Wrappers.PortableExecutable>
{
/// <inheritdoc/>
public PortableExecutable(SabreTools.Serialization.Wrappers.PortableExecutable? wrapper) : base(wrapper) { }
@@ -46,12 +45,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
/// <remarks>Uses the already-generated wrapper</remarks>
public bool Extract(string file, string outDir, bool includeDebug)
=> Extract(null, file, outDir, includeDebug);
/// <inheritdoc/>
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the output directory
Directory.CreateDirectory(outDir);

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var qtm = SabreTools.Serialization.Wrappers.Quantum.Create(stream);
if (qtm == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
qtm.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,20 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Handle invalid inputs
if (stream == null || stream.Length == 0)
return false;
// Create the wrapper
var rar = SabreTools.Serialization.Wrappers.RAR.Create(stream);
if (rar == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
rar.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -9,7 +8,7 @@ namespace BinaryObjectScanner.FileType
/// StarForce Filesystem file
/// </summary>
/// <see href="https://forum.xentax.com/viewtopic.php?f=21&t=2084"/>
public class SFFS : DetectableBase, IExtractable
public class SFFS : DetectableExtractableBase
{
/// <inheritdoc/>
public override string? Detect(Stream stream, string file, bool includeDebug)
@@ -31,17 +30,7 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
public bool Extract(string file, string outDir, bool includeDebug)
{
if (!File.Exists(file))
return false;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Extract(fs, file, outDir, includeDebug);
}
/// <inheritdoc/>
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
return false;
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var sga = SabreTools.Serialization.Wrappers.SGA.Create(stream);
if (sga == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
sga.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,20 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Handle invalid inputs
if (stream == null || stream.Length == 0)
return false;
// Create the wrapper
var sevenZip = SabreTools.Serialization.Wrappers.SevenZip.Create(stream);
if (sevenZip == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
sevenZip.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var tar = SabreTools.Serialization.Wrappers.TapeArchive.Create(stream);
if (tar == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
tar.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,18 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var vbsp = SabreTools.Serialization.Wrappers.VBSP.Create(stream);
if (vbsp == null)
return false;
// TODO: Introduce helper methods for all specialty lump types
// Loop through and extract all files
Directory.CreateDirectory(outDir);
vbsp.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var vpk = SabreTools.Serialization.Wrappers.VPK.Create(stream);
if (vpk == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
vpk.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var wad = SabreTools.Serialization.Wrappers.WAD3.Create(stream);
if (wad == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
wad.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,20 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Handle invalid inputs
if (stream == null || stream.Length == 0)
return false;
// Create the wrapper
var xz = SabreTools.Serialization.Wrappers.XZ.Create(stream);
if (xz == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
xz.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}

View File

@@ -13,16 +13,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Create the wrapper
var xzp = SabreTools.Serialization.Wrappers.XZP.Create(stream);
if (xzp == null)
return false;
// Loop through and extract all files
Directory.CreateDirectory(outDir);
xzp.Extract(outDir, includeDebug);
return true;
return _wrapper.Extract(outDir, includeDebug);
}
}
}