From 477356bd7762849a80a155a6400e57845147f4fd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 2 Dec 2024 01:59:23 -0500 Subject: [PATCH] Add content and NE tests for packers --- .../Packer/EXEStealthTests.cs | 13 ++++++++- .../Packer/InnoSetupTests.cs | 29 ++++++++++++++++++- .../Packer/WinZipSFXTests.cs | 27 +++++++++++++++++ .../Packer/WiseInstallerTests.cs | 27 +++++++++++++++++ BinaryObjectScanner/Packer/InnoSetup.cs | 8 ++++- BinaryObjectScanner/Packer/WiseInstaller.cs | 3 +- 6 files changed, 102 insertions(+), 5 deletions(-) diff --git a/BinaryObjectScanner.Test/Packer/EXEStealthTests.cs b/BinaryObjectScanner.Test/Packer/EXEStealthTests.cs index 6834c570..679bec35 100644 --- a/BinaryObjectScanner.Test/Packer/EXEStealthTests.cs +++ b/BinaryObjectScanner.Test/Packer/EXEStealthTests.cs @@ -6,6 +6,17 @@ namespace BinaryObjectScanner.Test.Packer { public class EXEStealthTests { + [Fact] + public void CheckContentsTest() + { + string file = "filename"; + byte[] fileContent = [0x01, 0x02, 0x03, 0x04]; + + var checker = new EXEStealth(); + string? actual = checker.CheckContents(file, fileContent, includeDebug: true); + Assert.Null(actual); + } + [Fact] public void CheckPortableExecutableTest() { @@ -18,7 +29,7 @@ namespace BinaryObjectScanner.Test.Packer string? actual = checker.CheckExecutable(file, pex, includeDebug: false); Assert.Null(actual); } - + [Fact] public void ExtractPortableExecutableTest() { diff --git a/BinaryObjectScanner.Test/Packer/InnoSetupTests.cs b/BinaryObjectScanner.Test/Packer/InnoSetupTests.cs index 5842e3fe..ced3f575 100644 --- a/BinaryObjectScanner.Test/Packer/InnoSetupTests.cs +++ b/BinaryObjectScanner.Test/Packer/InnoSetupTests.cs @@ -6,6 +6,19 @@ namespace BinaryObjectScanner.Test.Packer { public class InnoSetupTests { + [Fact] + public void CheckNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + + var checker = new InnoSetup(); + string? actual = checker.CheckExecutable(file, nex, includeDebug: false); + Assert.Null(actual); + } + [Fact] public void CheckPortableExecutableTest() { @@ -18,7 +31,21 @@ namespace BinaryObjectScanner.Test.Packer string? actual = checker.CheckExecutable(file, pex, includeDebug: false); Assert.Null(actual); } - + + [Fact] + public void ExtractNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + string outputDir = string.Empty; + + var checker = new InnoSetup(); + bool actual = checker.Extract(file, nex, outputDir, includeDebug: false); + Assert.False(actual); + } + [Fact] public void ExtractPortableExecutableTest() { diff --git a/BinaryObjectScanner.Test/Packer/WinZipSFXTests.cs b/BinaryObjectScanner.Test/Packer/WinZipSFXTests.cs index c33f10c0..c521e2c3 100644 --- a/BinaryObjectScanner.Test/Packer/WinZipSFXTests.cs +++ b/BinaryObjectScanner.Test/Packer/WinZipSFXTests.cs @@ -6,6 +6,19 @@ namespace BinaryObjectScanner.Test.Packer { public class WinZipSFXTests { + [Fact] + public void CheckNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + + var checker = new WinZipSFX(); + string? actual = checker.CheckExecutable(file, nex, includeDebug: false); + Assert.Null(actual); + } + [Fact] public void CheckPortableExecutableTest() { @@ -19,6 +32,20 @@ namespace BinaryObjectScanner.Test.Packer Assert.Null(actual); } + [Fact] + public void ExtractNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + string outputDir = string.Empty; + + var checker = new WinZipSFX(); + bool actual = checker.Extract(file, nex, outputDir, includeDebug: false); + Assert.False(actual); + } + [Fact] public void ExtractPortableExecutableTest() { diff --git a/BinaryObjectScanner.Test/Packer/WiseInstallerTests.cs b/BinaryObjectScanner.Test/Packer/WiseInstallerTests.cs index 8c5a7666..add51b15 100644 --- a/BinaryObjectScanner.Test/Packer/WiseInstallerTests.cs +++ b/BinaryObjectScanner.Test/Packer/WiseInstallerTests.cs @@ -6,6 +6,19 @@ namespace BinaryObjectScanner.Test.Packer { public class WiseInstallerTests { + [Fact] + public void CheckNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + + var checker = new WiseInstaller(); + string? actual = checker.CheckExecutable(file, nex, includeDebug: false); + Assert.Null(actual); + } + [Fact] public void CheckPortableExecutableTest() { @@ -19,6 +32,20 @@ namespace BinaryObjectScanner.Test.Packer Assert.Null(actual); } + [Fact] + public void ExtractNewExecutableTest() + { + string file = "filename"; + SabreTools.Models.NewExecutable.Executable model = new(); + Stream source = new MemoryStream(); + SabreTools.Serialization.Wrappers.NewExecutable nex = new(model, source); + string outputDir = string.Empty; + + var checker = new WiseInstaller(); + bool actual = checker.Extract(file, nex, outputDir, includeDebug: false); + Assert.False(actual); + } + [Fact] public void ExtractPortableExecutableTest() { diff --git a/BinaryObjectScanner/Packer/InnoSetup.cs b/BinaryObjectScanner/Packer/InnoSetup.cs index cee58470..43aa6a67 100644 --- a/BinaryObjectScanner/Packer/InnoSetup.cs +++ b/BinaryObjectScanner/Packer/InnoSetup.cs @@ -8,7 +8,7 @@ namespace BinaryObjectScanner.Packer { // TODO: Add extraction - https://github.com/dscharrer/InnoExtract // https://raw.githubusercontent.com/wolfram77web/app-peid/master/userdb.txt - public class InnoSetup : IExecutableCheck, + public class InnoSetup : IExtractableExecutable, IExtractableExecutable { /// @@ -52,6 +52,12 @@ namespace BinaryObjectScanner.Packer return null; } + /// + public bool Extract(string file, NewExecutable nex, string outDir, bool includeDebug) + { + return false; + } + /// public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug) { diff --git a/BinaryObjectScanner/Packer/WiseInstaller.cs b/BinaryObjectScanner/Packer/WiseInstaller.cs index 1ea836c7..a48d5bd0 100644 --- a/BinaryObjectScanner/Packer/WiseInstaller.cs +++ b/BinaryObjectScanner/Packer/WiseInstaller.cs @@ -71,10 +71,9 @@ namespace BinaryObjectScanner.Packer /// public bool Extract(string file, NewExecutable nex, string outDir, bool includeDebug) { - Directory.CreateDirectory(outDir); - try { + Directory.CreateDirectory(outDir); return Extractor.ExtractTo(file, outDir); } catch (Exception ex)