Only some executables are extractable

This commit is contained in:
Matt Nadareski
2025-09-06 10:46:57 -04:00
parent 46feb3e568
commit 4d85ba2d31
5 changed files with 27 additions and 25 deletions

View File

@@ -11,25 +11,12 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Executable or library
/// </summary>
public abstract class Executable<T> : DetectableBase<T>, IExtractable
public abstract class Executable<T> : DetectableBase<T>
where T : WrapperBase
{
/// <inheritdoc/>
public Executable(T? wrapper) : base(wrapper) { }
/// <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);
#region Check Runners
/// <summary>

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using BinaryObjectScanner.Data;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
namespace BinaryObjectScanner.FileType
@@ -9,7 +9,7 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// New executable (NE)
/// </summary>
public class NewExecutable : Executable<SabreTools.Serialization.Wrappers.NewExecutable>
public class NewExecutable : Executable<SabreTools.Serialization.Wrappers.NewExecutable>, IExtractable
{
/// <inheritdoc/>
public NewExecutable(SabreTools.Serialization.Wrappers.NewExecutable? wrapper) : base(wrapper) { }
@@ -47,7 +47,17 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
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)
{
// Create the wrapper
var wrapper = WrapperFactory.CreateExecutableWrapper(stream);

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using BinaryObjectScanner.Data;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
namespace BinaryObjectScanner.FileType
@@ -8,7 +9,7 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Portable executable (PE)
/// </summary>
public class PortableExecutable : Executable<SabreTools.Serialization.Wrappers.PortableExecutable>
public class PortableExecutable : Executable<SabreTools.Serialization.Wrappers.PortableExecutable>, IExtractable
{
/// <inheritdoc/>
public PortableExecutable(SabreTools.Serialization.Wrappers.PortableExecutable? wrapper) : base(wrapper) { }
@@ -46,7 +47,17 @@ namespace BinaryObjectScanner.FileType
}
/// <inheritdoc/>
public override bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
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)
{
// Create the wrapper
var wrapper = WrapperFactory.CreateExecutableWrapper(stream);