From 57a5531fbda05c5a75f30a4637498707f96c054b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 4 Nov 2024 14:58:21 -0500 Subject: [PATCH] Remove old Test executable; update docs --- .../{build_test.yml => build_programs.yml} | 4 +- .vscode/launch.json | 19 +- BinaryObjectScanner.sln | 6 - Coding Guide.md | 6 +- Developer Guide.md | 7 +- README.md | 4 +- Test/Extractor.cs | 415 ------------------ Test/Options.cs | 254 ----------- Test/Program.cs | 52 --- Test/Protector.cs | 70 --- Test/Test.csproj | 51 --- publish-nix.sh | 83 ---- publish-win.ps1 | 75 ---- 13 files changed, 28 insertions(+), 1018 deletions(-) rename .github/workflows/{build_test.yml => build_programs.yml} (96%) delete mode 100644 Test/Extractor.cs delete mode 100644 Test/Options.cs delete mode 100644 Test/Program.cs delete mode 100644 Test/Protector.cs delete mode 100644 Test/Test.csproj diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_programs.yml similarity index 96% rename from .github/workflows/build_test.yml rename to .github/workflows/build_programs.yml index 69a187c6..d016038d 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_programs.yml @@ -1,4 +1,4 @@ -name: Build Test +name: Build Programs on: push: @@ -10,7 +10,7 @@ jobs: strategy: matrix: - project: [ExtractionTool, ProtectionScan, Test] + project: [ExtractionTool, ProtectionScan] runtime: [win-x86, win-x64, win-arm64, linux-x64, linux-arm64, osx-x64] framework: [net8.0] #[net20, net35, net40, net452, net472, net48, netcoreapp3.1, net5.0, net6.0, net7.0, net8.0] conf: [Release, Debug] diff --git a/.vscode/launch.json b/.vscode/launch.json index edff32d3..57c2cdf4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,14 +5,27 @@ "version": "0.2.0", "configurations": [ { - "name": ".NET Core Launch (Test)", + "name": ".NET Core Launch (ProtectionScan)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/Test/bin/Debug/net8.0/Test.dll", + "program": "${workspaceFolder}/ProtectionScan/bin/Debug/net8.0/ProtectionScan.dll", "args": [], - "cwd": "${workspaceFolder}/Test", + "cwd": "${workspaceFolder}/ProtectionScan", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Launch (ExtractionTool)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/ExtractionTool/bin/Debug/net8.0/ExtractionTool.dll", + "args": [], + "cwd": "${workspaceFolder}/ExtractionTool", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "internalConsole", "stopAtEntry": false diff --git a/BinaryObjectScanner.sln b/BinaryObjectScanner.sln index 256be9e4..864db116 100644 --- a/BinaryObjectScanner.sln +++ b/BinaryObjectScanner.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.32407.343 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{88735BA2-778D-4192-8EB2-FFF6843719E2}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{68D10531-99CB-40B1-8912-73FA286C9433}" ProjectSection(SolutionItems) = preProject appveyor.yml = appveyor.yml @@ -28,10 +26,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {88735BA2-778D-4192-8EB2-FFF6843719E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {88735BA2-778D-4192-8EB2-FFF6843719E2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {88735BA2-778D-4192-8EB2-FFF6843719E2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {88735BA2-778D-4192-8EB2-FFF6843719E2}.Release|Any CPU.Build.0 = Release|Any CPU {341EA3F5-847C-4739-B86F-2B051FFE4EF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {341EA3F5-847C-4739-B86F-2B051FFE4EF2}.Debug|Any CPU.Build.0 = Debug|Any CPU {341EA3F5-847C-4739-B86F-2B051FFE4EF2}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Coding Guide.md b/Coding Guide.md index ca01eeae..6644b91b 100644 --- a/Coding Guide.md +++ b/Coding Guide.md @@ -364,7 +364,8 @@ This section contains information on project and class organization principles t | `BinaryObjectScanner/Interfaces` | One file per interface. | | `BinaryObjectScanner/Packer` | At least one file per packer type. Partial classes allowed. | | `BinaryObjectScanner/Protection` | At least one file per protection type. Partial classes allowed. | -| `Test` | All functionality lives in `Program.cs`. | +| `ExtractionTool` | All functionality lives in `Program.cs`. | +| `ProtectionScan` | All functionality lives in `Program.cs`. | If the project or directory you are looking for is not included in the above, please consider it to be outside the context of this document. @@ -380,6 +381,7 @@ This section contains information on in-code organization principles that depend | `BinaryObjectScanner/Interfaces` | Methods ordered alphabetically. | | `BinaryObjectScanner/Packer` | `IContentCheck` implementations, `ILinearExecutableCheck` implementations, `INewExecutableCheck` implementations, `IPortableExecutableCheck` implementations, `IPathCheck` implementations, `IExtractable` implementations, helper methods. | | `BinaryObjectScanner/Protection` | `IContentCheck` implementations, `ILinearExecutableCheck` implementations, `INewExecutableCheck` implementations, `IPortableExecutableCheck` implementations, `IPathCheck` implementations, `IExtractable` implementations, helper methods. | -| `Test` | New functionality should be added as a combination of a flag with a long and a short form, a new line in the help text, and a new method (if necessary). | +| `ExtractionTool` | New functionality should be added as a combination of a flag with a long and a short form, a new line in the help text, and a new method (if necessary). | +| `ProtectionScan` | New functionality should be added as a combination of a flag with a long and a short form, a new line in the help text, and a new method (if necessary). | If the project or directory you are looking for is not included in the above, please consider it to be outside the context of this document. diff --git a/Developer Guide.md b/Developer Guide.md index aa7e844c..8776173e 100644 --- a/Developer Guide.md +++ b/Developer Guide.md @@ -14,7 +14,8 @@ This is a guide for any developers who wish to research protections, implement n | `BinaryObjectScanner.Interfaces` | Namespace containing interface definitions for scanning and detection. | | `BinaryObjectScanner.Packer` | Namespace containing packer scanning definitions. | | `BinaryObjectScanner.Protection` | Namespace containing protection scanning definitions. | -| `Test` | Testing executable that allows for standalone testing of the library. Includes the ability to scan files for protection as well as output executable information. | +| `ExtractionTool` | Testing executable that allows for standalone testing of extraction features of the library. | +| `ProtectionScan` | Testing executable that allows for standalone testing of protection detection features of the library. | ## Researching Protections @@ -22,8 +23,8 @@ Researching copy protections and packers can be a massive undertaking. Some can | Tool / Method | Description | | --- | --- | -| `Test.exe --info [--json] ` | The `--info` option on the test executable is a really good way of getting started with investigation. The output of `--info` contains nearly all immediately parsable information from any executable that has a wrapper defined in `BinaryObjectScanner.Wrappers`. In general, the newer the executable format, the more information will be immediately available. For the most basic of protections and packers, this may be as far as you need to go for your research. Additionally, the `--json` flag allows for a formatted JSON output of the information for later parsing. This is only available in .NET 6+ builds. | -| `Test.exe [--debug] ` | Running `Test.exe` without any options runs the existing set of packer and protection checks. The output of this will be all detected packers and protections on the given file, with optional debug information where applicable. This is helpful in research because a protection you are investigating may be related to (or obscured by) another existing packer or protection. Having this information will make it easier to filter the results of `Test.exe --info ` as well. | +| `InfoPrint.exe [--json] ` | The `--info` option on the test executable is a really good way of getting started with investigation. The output of `InfoPrint` contains nearly all immediately parsable information from any executable that has a wrapper defined in `BinaryObjectScanner.Wrappers`. In general, the newer the executable format, the more information will be immediately available. For the most basic of protections and packers, this may be as far as you need to go for your research. Additionally, the `--json` flag allows for a formatted JSON output of the information for later parsing. This is only available in .NET 6+ builds. | +| `ProtectionScan.exe [--debug] ` | Running `ProtectionScan.exe` without any options runs the existing set of packer and protection checks. The output of this will be all detected packers and protections on the given file, with optional debug information where applicable. This is helpful in research because a protection you are investigating may be related to (or obscured by) another existing packer or protection. Having this information will make it easier to filter the results of `InfoPrint.exe ` as well. | | **Add and debug** | This starts getting into more serious territory. Creating a skeleton for the packer or protection that you want to add and then messing around in code is a great way to start seeing what sort of stuff the library can see that's not normally output. See the table below for extension properties and methods that you may use in addition to the models defined in `BinaryObjectScanner.Models`. | | **Hex Editor / External Programs** | As an advanced port of call, using a hex editor and external protection scanning programs (sometimes in conjunction) can help you get a better idea of the protection you're looking into. For example, **TheRogueArchivist** used that combination to narrow down the exact check for a very stubborn protection. | diff --git a/README.md b/README.md index b686318b..d55d68ea 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Binary Object Scanner [![Build status](https://ci.appveyor.com/api/projects/status/gmdft5bk1h8a1c31?svg=true)](https://ci.appveyor.com/project/mnadareski/BinaryObjectScanner) -[![Test Build](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_test.yml/badge.svg)](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_test.yml) +[![Program Build](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_programs.yml/badge.svg)](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_programs.yml) [![Nuget Pack](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_nupkg.yml/badge.svg)](https://github.com/SabreTools/BinaryObjectScanner/actions/workflows/build_nupkg.yml) -C# protection, packer, and archive scanning library. This currently compiles as a library so it can be used in any C# application. A reference application called `Test` is also included to demonstrate the abilities of the library. For an example of a program implementing the library, see [MPF](https://github.com/SabreTools/MPF). +C# protection, packer, and archive scanning library. This currently compiles as a library so it can be used in any C# application. Two reference applications called `ProtectionScan` and `ExtractionTool` are also included to demonstrate the abilities of the library. For an example of a program implementing the library, see [MPF](https://github.com/SabreTools/MPF). The following non-project libraries (or ports thereof) are used for file handling: diff --git a/Test/Extractor.cs b/Test/Extractor.cs deleted file mode 100644 index 041a91de..00000000 --- a/Test/Extractor.cs +++ /dev/null @@ -1,415 +0,0 @@ -using System; -using System.IO; -using SabreTools.IO.Extensions; -using SabreTools.Serialization.Wrappers; - -namespace Test -{ - internal static class Extractor - { - /// - /// Wrapper to extract data for a single path - /// - /// File or directory path - /// Output directory path - /// Enable including debug information - public static void ExtractPath(string path, string outputDirectory, bool includeDebug) - { - Console.WriteLine($"Checking possible path: {path}"); - - // Check if the file or directory exists - if (File.Exists(path)) - { - ExtractFile(path, outputDirectory, includeDebug); - } - else if (Directory.Exists(path)) - { - foreach (string file in IOExtensions.SafeEnumerateFiles(path, "*", SearchOption.AllDirectories)) - { - ExtractFile(file, outputDirectory, includeDebug); - } - } - else - { - Console.WriteLine($"{path} does not exist, skipping..."); - } - } - - /// - /// Print information for a single file, if possible - /// - private static void ExtractFile(string file, string outputDirectory, bool includeDebug) - { - Console.WriteLine($"Attempting to extract all files from {file}"); - using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - - // Get the extension for certain checks - string extension = Path.GetExtension(file).ToLower().TrimStart('.'); - - // Get the first 16 bytes for matching - byte[] magic = new byte[16]; - try - { - stream.Read(magic, 0, 16); - stream.Seek(0, SeekOrigin.Begin); - } - catch (Exception ex) - { - if (includeDebug) Console.WriteLine(ex); - return; - } - - // Get the file type - WrapperType ft = WrapperFactory.GetFileType(magic, extension); - - // Executables technically can be "extracted", but let's ignore that - // TODO: Support executables that include other stuff - - // 7-zip - if (ft == WrapperType.SevenZip) - { - // Build the archive information - Console.WriteLine("Extracting 7-zip contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var sevenZip = new BinaryObjectScanner.FileType.SevenZip(); - sevenZip.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // BFPK archive - else if (ft == WrapperType.BFPK) - { - // Build the BFPK information - Console.WriteLine("Extracting BFPK contents"); - Console.WriteLine(); - - // Extract using the FileType - var bfpk = new BinaryObjectScanner.FileType.BFPK(); - bfpk.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // BSP - else if (ft == WrapperType.BSP) - { - // Build the BSP information - Console.WriteLine("Extracting BSP contents"); - Console.WriteLine(); - - // Extract using the FileType - var bsp = new BinaryObjectScanner.FileType.BSP(); - bsp.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // bzip2 - else if (ft == WrapperType.BZip2) - { - // Build the bzip2 information - Console.WriteLine("Extracting bzip2 contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var bzip2 = new BinaryObjectScanner.FileType.BZip2(); - bzip2.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // CFB - else if (ft == WrapperType.CFB) - { - // Build the installer information - Console.WriteLine("Extracting CFB contents"); - Console.WriteLine(); - -#if NET20 || NET35 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var cfb = new BinaryObjectScanner.FileType.CFB(); - cfb.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // GCF - else if (ft == WrapperType.GCF) - { - // Build the GCF information - Console.WriteLine("Extracting GCF contents"); - Console.WriteLine(); - - // Extract using the FileType - var gcf = new BinaryObjectScanner.FileType.GCF(); - gcf.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // gzip - else if (ft == WrapperType.GZIP) - { - // Build the gzip information - Console.WriteLine("Extracting gzip contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var gzip = new BinaryObjectScanner.FileType.GZIP(); - gzip.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // InstallShield Archive V3 (Z) - else if (ft == WrapperType.InstallShieldArchiveV3) - { - // Build the InstallShield Archive V3 information - Console.WriteLine("Extracting InstallShield Archive V3 contents"); - Console.WriteLine(); - - // Extract using the FileType - var isav3 = new BinaryObjectScanner.FileType.InstallShieldArchiveV3(); - isav3.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // IS-CAB archive - else if (ft == WrapperType.InstallShieldCAB) - { - // Build the archive information - Console.WriteLine("Extracting IS-CAB contents"); - Console.WriteLine(); - - // Extract using the FileType - var iscab = new BinaryObjectScanner.FileType.InstallShieldCAB(); - iscab.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // Microsoft Cabinet archive - else if (ft == WrapperType.MicrosoftCAB) - { - // Build the cabinet information - Console.WriteLine("Extracting MS-CAB contents"); - Console.WriteLine(); - -#if NET20 || NET35 || !WIN - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var mscab = new BinaryObjectScanner.FileType.MicrosoftCAB(); - mscab.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // Microsoft LZ / LZ32 - else if (ft == WrapperType.MicrosoftLZ) - { - // Build the Microsoft LZ / LZ32 information - Console.WriteLine("Extracting Microsoft LZ / LZ32 contents"); - Console.WriteLine(); - - // Extract using the FileType - var lz = new BinaryObjectScanner.FileType.MicrosoftLZ(); - lz.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // MoPaQ (MPQ) archive - else if (ft == WrapperType.MoPaQ) - { - // Build the cabinet information - Console.WriteLine("Extracting MoPaQ contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || !WIN - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var mpq = new BinaryObjectScanner.FileType.MPQ(); - mpq.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // PAK - else if (ft == WrapperType.PAK) - { - // Build the archive information - Console.WriteLine("Extracting PAK contents"); - Console.WriteLine(); - - // Extract using the FileType - var pak = new BinaryObjectScanner.FileType.PAK(); - pak.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // PFF - else if (ft == WrapperType.PFF) - { - // Build the archive information - Console.WriteLine("Extracting PFF contents"); - Console.WriteLine(); - - // Extract using the FileType - var pff = new BinaryObjectScanner.FileType.PFF(); - pff.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // PKZIP - else if (ft == WrapperType.PKZIP) - { - // Build the archive information - Console.WriteLine("Extracting PKZIP contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var pkzip = new BinaryObjectScanner.FileType.PKZIP(); - pkzip.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // Quantum - else if (ft == WrapperType.Quantum) - { - // Build the archive information - Console.WriteLine("Extracting Quantum contents"); - Console.WriteLine(); - - // Extract using the FileType - var quantum = new BinaryObjectScanner.FileType.Quantum(); - quantum.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // RAR - else if (ft == WrapperType.RAR) - { - // Build the archive information - Console.WriteLine("Extracting RAR contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var rar = new BinaryObjectScanner.FileType.RAR(); - rar.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // SGA - else if (ft == WrapperType.SGA) - { - // Build the archive information - Console.WriteLine("Extracting SGA contents"); - Console.WriteLine(); - - // Extract using the FileType - var sga = new BinaryObjectScanner.FileType.SGA(); - sga.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // Tape Archive - else if (ft == WrapperType.TapeArchive) - { - // Build the archive information - Console.WriteLine("Extracting Tape Archive contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var tar = new BinaryObjectScanner.FileType.TapeArchive(); - tar.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // VBSP - else if (ft == WrapperType.VBSP) - { - // Build the archive information - Console.WriteLine("Extracting VBSP contents"); - Console.WriteLine(); - - // Extract using the FileType - var vbsp = new BinaryObjectScanner.FileType.VBSP(); - vbsp.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // VPK - else if (ft == WrapperType.VPK) - { - // Build the archive information - Console.WriteLine("Extracting VPK contents"); - Console.WriteLine(); - - // Extract using the FileType - var vpk = new BinaryObjectScanner.FileType.VPK(); - vpk.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // WAD - else if (ft == WrapperType.WAD) - { - // Build the archive information - Console.WriteLine("Extracting WAD contents"); - Console.WriteLine(); - - // Extract using the FileType - var wad = new BinaryObjectScanner.FileType.WAD(); - wad.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // xz - else if (ft == WrapperType.XZ) - { - // Build the xz information - Console.WriteLine("Extracting xz contents"); - Console.WriteLine(); - -#if NET20 || NET35 || NET40 || NET452 - Console.WriteLine("Extraction is not supported for this framework!"); - Console.WriteLine(); -#else - // Extract using the FileType - var xz = new BinaryObjectScanner.FileType.XZ(); - xz.Extract(stream, file, outputDirectory, includeDebug: true); -#endif - } - - // XZP - else if (ft == WrapperType.XZP) - { - // Build the archive information - Console.WriteLine("Extracting XZP contents"); - Console.WriteLine(); - - // Extract using the FileType - var xzp = new BinaryObjectScanner.FileType.XZP(); - xzp.Extract(stream, file, outputDirectory, includeDebug: true); - } - - // Everything else - else - { - Console.WriteLine("Not a supported extractable file format, skipping..."); - Console.WriteLine(); - return; - } - } - } -} \ No newline at end of file diff --git a/Test/Options.cs b/Test/Options.cs deleted file mode 100644 index 22203a30..00000000 --- a/Test/Options.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace Test -{ - /// - /// Set of options for the test executable - /// - internal sealed class Options - { - #region Properties - - /// - /// Enable debug output for relevant operations - /// - public bool Debug { get; private set; } = false; - - /// - /// Set of input paths to use for operations - /// - public List InputPaths { get; private set; } = []; - - #region Extraction - - /// - /// Perform archive extraction - /// - public bool EnableExtraction { get; private set; } = false; - - /// - /// Output path for archive extraction - /// - public string OutputPath { get; private set; } = string.Empty; - - #endregion - - #region Scanning - - /// - /// Perform protection scanning - /// - public bool EnableScanning { get; private set; } = false; - - /// - /// Scan archives during protection scanning - /// - public bool ScanArchives { get; private set; } = true; - - /// - /// Scan file contents during protection scanning - /// - public bool ScanContents { get; private set; } = true; - - /// - /// Scan game engines during protection scanning - /// - public bool ScanGameEngines { get; private set; } = true; - - /// - /// Scan packers during protection scanning - /// - public bool ScanPackers { get; private set; } = true; - - /// - /// Scan file paths during protection scanning - /// - public bool ScanPaths { get; private set; } = true; - - #endregion - - #endregion - - /// - /// Parse commandline arguments into an Options object - /// - public static Options? ParseOptions(string[] args) - { - // If we have invalid arguments - if (args == null || args.Length == 0) - return null; - - // Create an Options object - var options = new Options(); - - // Parse the features - int index = 0; - for (; index < args.Length; index++) - { - string arg = args[index]; - bool featureFound = false; - switch (arg) - { - case "-?": - case "-h": - case "--help": - return null; - - case "-x": - case "--extract": - options.EnableExtraction = true; - featureFound = true; - break; - - case "-s": - case "--scan": - options.EnableScanning = true; - featureFound = true; - break; - - default: - break; - } - - // If the flag wasn't a feature - if (!featureFound) - break; - } - - // Parse the options and paths - for (; index < args.Length; index++) - { - string arg = args[index]; - switch (arg) - { - case "-d": - case "--debug": - options.Debug = true; - break; - - #region Extraction - - case "-o": - case "--outdir": - options.OutputPath = index + 1 < args.Length ? args[++index] : string.Empty; - break; - - #endregion - - #region Scanning - - case "-na": - case "--no-archives": - options.ScanArchives = false; - break; - - case "-nc": - case "--no-contents": - options.ScanContents = false; - break; - - case "-ng": - case "--no-game-engines": - options.ScanGameEngines = false; - break; - - case "-np": - case "--no-packers": - options.ScanPackers = false; - break; - - case "-ns": - case "--no-paths": - options.ScanPaths = false; - break; - - #endregion - - default: - options.InputPaths.Add(arg); - break; - } - } - - // If we have no features set, enable protection scanning - if (!options.EnableExtraction && !options.EnableScanning) - options.EnableScanning = true; - - // Validate we have any input paths to work on - if (options.InputPaths.Count == 0) - { - Console.WriteLine("At least one path is required!"); - return null; - } - - // If we have extraction enabled, validate the path - if (options.EnableExtraction) - { - bool validPath = ValidateExtractionPath(options); - if (!validPath) - return null; - } - - return options; - } - - /// - /// Display help text - /// - public static void DisplayHelp() - { - Console.WriteLine("BinaryObjectScanner Test Program"); - Console.WriteLine(); - Console.WriteLine("test.exe file|directory ..."); - Console.WriteLine(); - Console.WriteLine("Features:"); - Console.WriteLine("-x, --extract Extract archive formats"); - Console.WriteLine("-s, --scan Enable protection scanning (default if none)"); - Console.WriteLine(); - Console.WriteLine("Common options:"); - Console.WriteLine("-?, -h, --help Display this help text and quit"); - Console.WriteLine("-d, --debug Enable debug mode"); - Console.WriteLine(); - Console.WriteLine("Extraction options:"); - Console.WriteLine("-o, --outdir [PATH] Set output path for extraction (required)"); - Console.WriteLine(); - Console.WriteLine("Scanning options:"); - Console.WriteLine("-nc, --no-contents Disable scanning for content checks"); - Console.WriteLine("-na, --no-archives Disable scanning archives"); - Console.WriteLine("-ng, --no-game-engines Disable scanning for game engines"); - Console.WriteLine("-np, --no-packers Disable scanning for packers"); - Console.WriteLine("-ns, --no-paths Disable scanning for path checks"); - } - - /// - /// Validate the extraction path - /// - private static bool ValidateExtractionPath(Options options) - { - // Null or empty output path - if (string.IsNullOrEmpty(options.OutputPath)) - { - Console.WriteLine("Output directory required for extraction!"); - Console.WriteLine(); - return false; - } - - // Malformed output path or invalid location - try - { - options.OutputPath = Path.GetFullPath(options.OutputPath); - Directory.CreateDirectory(options.OutputPath); - } - catch - { - Console.WriteLine("Output directory could not be created!"); - Console.WriteLine(); - return false; - } - - return true; - } - } -} \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs deleted file mode 100644 index a7083ecf..00000000 --- a/Test/Program.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using BinaryObjectScanner; - -namespace Test -{ - class Program - { - static void Main(string[] args) - { -#if NET462_OR_GREATER || NETCOREAPP - // Register the codepages - System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); -#endif - - // Create progress indicator - var fileProgress = new Progress(); - fileProgress.ProgressChanged += Protector.Changed; - - // Get the options from the arguments - var options = Options.ParseOptions(args); - - // If we have an invalid state - if (options == null) - { - Options.DisplayHelp(); - return; - } - - // Create scanner for all paths - var scanner = new Scanner( - options.ScanArchives, - options.ScanContents, - options.ScanGameEngines, - options.ScanPackers, - options.ScanPaths, - options.Debug, - fileProgress); - - // Loop through the input paths - foreach (string inputPath in options.InputPaths) - { - // Extraction - if (options.EnableExtraction) - Extractor.ExtractPath(inputPath, options.OutputPath, options.Debug); - - // Scanning - if (options.EnableScanning) - Protector.GetAndWriteProtections(scanner, inputPath); - } - } - } -} diff --git a/Test/Protector.cs b/Test/Protector.cs deleted file mode 100644 index 89f25096..00000000 --- a/Test/Protector.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using BinaryObjectScanner; - -namespace Test -{ - internal static class Protector - { - /// - /// Wrapper to get and log protections for a single path - /// - /// Scanner object to use - /// File or directory path - public static void GetAndWriteProtections(Scanner scanner, string path) - { - // An invalid path can't be scanned - if (!Directory.Exists(path) && !File.Exists(path)) - { - Console.WriteLine($"{path} does not exist, skipping..."); - return; - } - - try - { - var protections = scanner.GetProtections(path); - WriteProtectionResultFile(path, protections); - } - catch (Exception ex) - { - using var sw = new StreamWriter(File.OpenWrite($"exception-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt")); - sw.WriteLine(ex); - } - } - - /// - /// Write the protection results from a single path to file, if possible - /// - /// File or directory path - /// Dictionary of protections found, if any - private static void WriteProtectionResultFile(string path, ProtectionDictionary? protections) - { - if (protections == null) - { - Console.WriteLine($"No protections found for {path}"); - return; - } - - using var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt")); - foreach (string key in protections.Keys.OrderBy(k => k)) - { - // Skip over files with no protection - if (protections[key] == null || !protections[key].Any()) - continue; - - string line = $"{key}: {string.Join(", ", [.. protections[key].OrderBy(p => p)])}"; - Console.WriteLine(line); - sw.WriteLine(line); - } - } - - /// - /// Protection progress changed handler - /// - public static void Changed(object? source, ProtectionProgress value) - { - Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"); - } - } -} \ No newline at end of file diff --git a/Test/Test.csproj b/Test/Test.csproj deleted file mode 100644 index 4d8e4c35..00000000 --- a/Test/Test.csproj +++ /dev/null @@ -1,51 +0,0 @@ - - - - net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - Exe - false - false - latest - enable - true - true - - - - - win-x86;win-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 - - - net6.0;net7.0;net8.0 - - - - - $(DefineConstants);WIN - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/publish-nix.sh b/publish-nix.sh index 804b6199..99c866ef 100644 --- a/publish-nix.sh +++ b/publish-nix.sh @@ -146,45 +146,6 @@ if [ $NO_BUILD = false ]; then fi done done - - # Build Test - for FRAMEWORK in "${FRAMEWORKS[@]}"; do - for RUNTIME in "${RUNTIMES[@]}"; do - # Output the current build - echo "===== Build Test - $FRAMEWORK, $RUNTIME =====" - - # If we have an invalid combination of framework and runtime - if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then - echo "Skipped due to invalid combination" - continue - fi - fi - - # If we have Apple silicon but an unsupported framework - if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - if [ $RUNTIME = "osx-arm64" ]; then - echo "Skipped due to no Apple Silicon support" - continue - fi - fi - - # Only .NET 5 and above can publish to a single file - if [[ $(echo ${SINGLE_FILE_CAPABLE[@]} | fgrep -w $FRAMEWORK) ]]; then - # Only include Debug if building all - if [ $USE_ALL = true ]; then - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true - fi - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false - else - # Only include Debug if building all - if [ $USE_ALL = true ]; then - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT - fi - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false - fi - done - done fi # Only create archives if requested @@ -277,50 +238,6 @@ if [ $NO_ARCHIVE = false ]; then done done - # Create Test archives - for FRAMEWORK in "${FRAMEWORKS[@]}"; do - for RUNTIME in "${RUNTIMES[@]}"; do - # Output the current build - echo "===== Archive Test - $FRAMEWORK, $RUNTIME =====" - - # If we have an invalid combination of framework and runtime - if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then - echo "Skipped due to invalid combination" - continue - fi - fi - - # If we have Apple silicon but an unsupported framework - if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - if [ $RUNTIME = "osx-arm64" ]; then - echo "Skipped due to no Apple Silicon support" - continue - fi - fi - - # Only include Debug if building all - if [ $USE_ALL = true ]; then - cd $BUILD_FOLDER/Test/bin/Debug/${FRAMEWORK}/${RUNTIME}/publish/ - if [[ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' - elif [[ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' - else - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . - fi - fi - cd $BUILD_FOLDER/Test/bin/Release/${FRAMEWORK}/${RUNTIME}/publish/ - if [[ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' - elif [[ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' - else - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . - fi - done - done - # Reset the directory cd $BUILD_FOLDER fi diff --git a/publish-win.ps1 b/publish-win.ps1 index 1424b840..ec436f38 100644 --- a/publish-win.ps1 +++ b/publish-win.ps1 @@ -131,42 +131,6 @@ if (!$NO_BUILD.IsPresent) { } } } - - # Build Test - foreach ($FRAMEWORK in $FRAMEWORKS) { - foreach ($RUNTIME in $RUNTIMES) { - # Output the current build - Write-Host "===== Build Test - $FRAMEWORK, $RUNTIME =====" - - # If we have an invalid combination of framework and runtime - if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) { - Write-Host "Skipped due to invalid combination" - continue - } - - # If we have Apple silicon but an unsupported framework - if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') { - Write-Host "Skipped due to no Apple Silicon support" - continue - } - - # Only .NET 5 and above can publish to a single file - if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK) { - # Only include Debug if building all - if ($USE_ALL.IsPresent) { - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true - } - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false - } - else { - # Only include Debug if building all - if ($USE_ALL.IsPresent) { - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT - } - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false - } - } - } } # Only create archives if requested @@ -249,45 +213,6 @@ if (!$NO_ARCHIVE.IsPresent) { } } - # Create Test archives - foreach ($FRAMEWORK in $FRAMEWORKS) { - foreach ($RUNTIME in $RUNTIMES) { - # Output the current build - Write-Host "===== Archive Test - $FRAMEWORK, $RUNTIME =====" - - # If we have an invalid combination of framework and runtime - if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) { - Write-Host "Skipped due to invalid combination" - continue - } - - # If we have Apple silicon but an unsupported framework - if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') { - Write-Host "Skipped due to no Apple Silicon support" - continue - } - - # Only include Debug if building all - if ($USE_ALL.IsPresent) { - Set-Location -Path $BUILD_FOLDER\Test\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\ - if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) { - 7z a -tzip -x'!CascLib.dll' -x'!mspack.dll' -x'!StormLib.dll' $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * - } - else { - 7z a -tzip $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * - } - } - - Set-Location -Path $BUILD_FOLDER\Test\bin\Release\${FRAMEWORK}\${RUNTIME}\publish\ - if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) { - 7z a -tzip -x'!CascLib.dll' -x'!mspack.dll' -x'!StormLib.dll' $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip * - } - else { - 7z a -tzip $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip * - } - } - } - # Reset the directory Set-Location -Path $PSScriptRoot }