From 168231cc9449a4346a7944793178a78833e5009b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 6 Sep 2025 10:56:36 -0400 Subject: [PATCH] Don't reinvent the wheel --- BinaryObjectScanner/FileType/NewExecutable.cs | 18 ++++---------- .../FileType/PortableExecutable.cs | 24 ++++++------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/BinaryObjectScanner/FileType/NewExecutable.cs b/BinaryObjectScanner/FileType/NewExecutable.cs index 11c36182..c1f8c102 100644 --- a/BinaryObjectScanner/FileType/NewExecutable.cs +++ b/BinaryObjectScanner/FileType/NewExecutable.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Data; using BinaryObjectScanner.Interfaces; -using SabreTools.Serialization.Wrappers; namespace BinaryObjectScanner.FileType { @@ -59,25 +58,16 @@ namespace BinaryObjectScanner.FileType /// public bool Extract(Stream? stream, string file, string outDir, bool includeDebug) { - // Create the wrapper - var wrapper = WrapperFactory.CreateExecutableWrapper(stream); - if (wrapper == null) - return false; - - // Only handle NE - if (wrapper is not SabreTools.Serialization.Wrappers.NewExecutable nex) - return false; - // Create the output directory Directory.CreateDirectory(outDir); // Extract all files bool extractAny = false; - if (new Packer.EmbeddedFile().CheckExecutable(file, nex, includeDebug) != null) - extractAny |= nex.ExtractFromOverlay(outDir, includeDebug); + if (new Packer.EmbeddedFile().CheckExecutable(file, _wrapper, includeDebug) != null) + extractAny |= _wrapper.ExtractFromOverlay(outDir, includeDebug); - if (new Packer.WiseInstaller().CheckExecutable(file, nex, includeDebug) != null) - extractAny |= nex.ExtractWise(outDir, includeDebug); + if (new Packer.WiseInstaller().CheckExecutable(file, _wrapper, includeDebug) != null) + extractAny |= _wrapper.ExtractWise(outDir, includeDebug); return extractAny; } diff --git a/BinaryObjectScanner/FileType/PortableExecutable.cs b/BinaryObjectScanner/FileType/PortableExecutable.cs index f0f72dce..0e93a258 100644 --- a/BinaryObjectScanner/FileType/PortableExecutable.cs +++ b/BinaryObjectScanner/FileType/PortableExecutable.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using BinaryObjectScanner.Data; using BinaryObjectScanner.Interfaces; -using SabreTools.Serialization.Wrappers; namespace BinaryObjectScanner.FileType { @@ -59,31 +58,22 @@ namespace BinaryObjectScanner.FileType /// public bool Extract(Stream? stream, string file, string outDir, bool includeDebug) { - // Create the wrapper - var wrapper = WrapperFactory.CreateExecutableWrapper(stream); - if (wrapper == null) - return false; - - // Only handle PE - if (wrapper is not SabreTools.Serialization.Wrappers.PortableExecutable pex) - return false; - // Create the output directory Directory.CreateDirectory(outDir); // Extract all files bool extractAny = false; - if (new Packer.CExe().CheckExecutable(file, pex, includeDebug) != null) - extractAny |= pex.ExtractCExe(outDir, includeDebug); + if (new Packer.CExe().CheckExecutable(file, _wrapper, includeDebug) != null) + extractAny |= _wrapper.ExtractCExe(outDir, includeDebug); - if (new Packer.EmbeddedFile().CheckExecutable(file, pex, includeDebug) != null) + if (new Packer.EmbeddedFile().CheckExecutable(file, _wrapper, includeDebug) != null) { - extractAny |= pex.ExtractFromOverlay(outDir, includeDebug); - extractAny |= pex.ExtractFromResources(outDir, includeDebug); + extractAny |= _wrapper.ExtractFromOverlay(outDir, includeDebug); + extractAny |= _wrapper.ExtractFromResources(outDir, includeDebug); } - if (new Packer.WiseInstaller().CheckExecutable(file, pex, includeDebug) != null) - extractAny |= pex.ExtractWise(outDir, includeDebug); + if (new Packer.WiseInstaller().CheckExecutable(file, _wrapper, includeDebug) != null) + extractAny |= _wrapper.ExtractWise(outDir, includeDebug); return extractAny; }