mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-04 05:35:49 +00:00
Remove Printer
This commit is contained in:
@@ -32,6 +32,8 @@ For the most recent stable build, download the latest release here: [Releases Pa
|
||||
|
||||
For the latest WIP build here: [Rolling Release](https://github.com/SabreTools/BinaryObjectScanner/releases/tag/rolling)
|
||||
|
||||
**NOTE**: If you used the executable information printing functionality in previous releases, that has been extracted as a separate program and included in the [SabreTools.Serialization repository](https://github.com/SabreTools/SabreTools.Serialization). It was formerly included there as a reference program but has since been renamed to **InfoPrint**. This was done to ensure that the latest information printing would be available instead of waiting for it to bubble up to BinaryObjectScanner.
|
||||
|
||||
## Compatibility Notes
|
||||
|
||||
Binary Object Scanner strives to have both full compatibility for scanning across .NET versions as well as across OSes. Unfortunately, this is not always the case. Please see the below list for known compatibility issues.
|
||||
|
||||
@@ -35,22 +35,6 @@ namespace Test
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Perform information printing
|
||||
/// </summary>
|
||||
public bool EnableInformation { get; private set; } = false;
|
||||
|
||||
#if NETCOREAPP3_1_OR_GREATER
|
||||
/// <summary>
|
||||
/// Enable JSON output
|
||||
/// </summary>
|
||||
public bool Json { get; private set; } = false;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scanning
|
||||
|
||||
/// <summary>
|
||||
@@ -118,12 +102,6 @@ namespace Test
|
||||
featureFound = true;
|
||||
break;
|
||||
|
||||
case "-i":
|
||||
case "--info":
|
||||
options.EnableInformation = true;
|
||||
featureFound = true;
|
||||
break;
|
||||
|
||||
case "-s":
|
||||
case "--scan":
|
||||
options.EnableScanning = true;
|
||||
@@ -159,20 +137,6 @@ namespace Test
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information
|
||||
|
||||
case "-j":
|
||||
case "--json":
|
||||
#if NET6_0_OR_GREATER
|
||||
options.Json = true;
|
||||
#else
|
||||
Console.WriteLine("JSON output not available in .NET Framework");
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scanning
|
||||
|
||||
case "-na":
|
||||
@@ -209,7 +173,7 @@ namespace Test
|
||||
}
|
||||
|
||||
// If we have no features set, enable protection scanning
|
||||
if (!options.EnableExtraction && !options.EnableInformation && !options.EnableScanning)
|
||||
if (!options.EnableExtraction && !options.EnableScanning)
|
||||
options.EnableScanning = true;
|
||||
|
||||
// Validate we have any input paths to work on
|
||||
@@ -241,7 +205,6 @@ namespace Test
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Features:");
|
||||
Console.WriteLine("-x, --extract Extract archive formats");
|
||||
Console.WriteLine("-i, --info Print executable info");
|
||||
Console.WriteLine("-s, --scan Enable protection scanning (default if none)");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Common options:");
|
||||
@@ -250,11 +213,6 @@ namespace Test
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Extraction options:");
|
||||
Console.WriteLine("-o, --outdir [PATH] Set output path for extraction (required)");
|
||||
#if NET6_0_OR_GREATER
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Information options:");
|
||||
Console.WriteLine("-j, --json Print executable info as JSON");
|
||||
#endif
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Scanning options:");
|
||||
Console.WriteLine("-nc, --no-contents Disable scanning for content checks");
|
||||
|
||||
153
Test/Printer.cs
153
Test/Printer.cs
@@ -1,153 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
using System.Text;
|
||||
#endif
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using SPrinter = SabreTools.Serialization.Printer;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
internal class Printer
|
||||
{
|
||||
#region Options
|
||||
|
||||
/// <inheritdoc cref="BinaryObjectScanner.Options.IncludeDebug"/>
|
||||
public bool IncludeDebug => _options?.IncludeDebug ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Options object for configuration
|
||||
/// </summary>
|
||||
private readonly BinaryObjectScanner.Options _options;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="includeDebug">Enable including debug information</param>
|
||||
public Printer(bool includeDebug)
|
||||
{
|
||||
_options = new BinaryObjectScanner.Options
|
||||
{
|
||||
IncludeDebug = includeDebug,
|
||||
};
|
||||
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// Register the codepages
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to print information for a single path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="json">Enable JSON output, if supported</param>
|
||||
/// <param name="debug">Enable debug output</param>
|
||||
public void PrintPathInfo(string path, bool json, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
PrintFileInfo(path, json, debug);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in IOExtensions.SafeEnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
PrintFileInfo(file, json, debug);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
private void PrintFileInfo(string file, bool json, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Attempting to print info for {file}");
|
||||
|
||||
try
|
||||
{
|
||||
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);
|
||||
|
||||
// Print out the file format
|
||||
Console.WriteLine($"File format found: {ft}");
|
||||
|
||||
// Setup the wrapper to print
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// If we don't have a wrapper
|
||||
if (wrapper == null)
|
||||
{
|
||||
Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the base info output name
|
||||
string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
// If we have the JSON flag
|
||||
if (json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
Console.WriteLine(serializedData);
|
||||
|
||||
// Write the output data
|
||||
using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
|
||||
jsw.WriteLine(serializedData);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the output data
|
||||
var builder = SPrinter.ExportStringBuilder(wrapper);
|
||||
if (builder == null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
}
|
||||
|
||||
// Write the output data
|
||||
Console.WriteLine(builder);
|
||||
using var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt"));
|
||||
sw.WriteLine(builder.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(debug ? ex : "[Exception opening file, please try again]");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,6 @@ namespace Test
|
||||
// Create extractor for all paths
|
||||
var extractor = new Extractor(options.Debug);
|
||||
|
||||
// Create printer for all paths
|
||||
var printer = new Printer(options.Debug);
|
||||
|
||||
// Create scanner for all paths
|
||||
var scanner = new Scanner(
|
||||
options.ScanArchives,
|
||||
@@ -49,14 +46,6 @@ namespace Test
|
||||
if (options.EnableExtraction)
|
||||
extractor.ExtractPath(inputPath, options.OutputPath);
|
||||
|
||||
// Information printing
|
||||
if (options.EnableInformation)
|
||||
#if NETFRAMEWORK
|
||||
printer.PrintPathInfo(inputPath, false, options.Debug);
|
||||
#else
|
||||
printer.PrintPathInfo(inputPath, options.Json, options.Debug);
|
||||
#endif
|
||||
|
||||
// Scanning
|
||||
if (options.EnableScanning)
|
||||
Protector.GetAndWriteProtections(scanner, inputPath);
|
||||
|
||||
Reference in New Issue
Block a user