mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-04-21 21:54:13 +00:00
Write info outputs to file for easier use
This commit is contained in:
@@ -43,7 +43,7 @@ namespace BurnOutSharp.Wrappers
|
||||
{
|
||||
get
|
||||
{
|
||||
var serializer = new System.Text.Json.JsonSerializerOptions { IncludeFields = true };
|
||||
var serializer = new System.Text.Json.JsonSerializerOptions { IncludeFields = true, WriteIndented = true };
|
||||
serializer.Converters.Add(new ConcreteAbstractSerializer());
|
||||
serializer.Converters.Add(new ConcreteInterfaceSerializer());
|
||||
serializer.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
|
||||
|
||||
@@ -15,21 +15,22 @@ namespace Test
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="json">Enable JSON output, if supported</param>
|
||||
/// <param name="outputDirectory">Output directory path</param>
|
||||
/// <param name="debug">Enable debug output</param>
|
||||
public static void PrintPathInfo(string path, bool json, bool debug)
|
||||
public static void PrintPathInfo(string path, bool json, string outputDirectory, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
PrintFileInfo(path, json, debug);
|
||||
PrintFileInfo(path, json, outputDirectory, debug);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
PrintFileInfo(file, json, debug);
|
||||
PrintFileInfo(file, json, outputDirectory, debug);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -41,7 +42,7 @@ namespace Test
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
private static void PrintFileInfo(string file, bool json, bool debug)
|
||||
private static void PrintFileInfo(string file, bool json, string outputDirectory, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Attempting to print info for {file}");
|
||||
|
||||
@@ -252,15 +253,49 @@ namespace Test
|
||||
// If we have the JSON flag
|
||||
if (json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
Console.WriteLine(serializedData);
|
||||
|
||||
// Create the output filename
|
||||
string filename = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss}.json";
|
||||
|
||||
// If we have an output directory
|
||||
if (!string.IsNullOrWhiteSpace(outputDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
}
|
||||
|
||||
// Write the output data
|
||||
using (var sw = new StreamWriter(File.OpenWrite(filename)))
|
||||
{
|
||||
sw.WriteLine(serializedData);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// If we don't have the JSON flag
|
||||
if (!json)
|
||||
{
|
||||
// Create the output data
|
||||
StringBuilder builder = wrapper.PrettyPrint();
|
||||
Console.WriteLine(builder);
|
||||
|
||||
// Create the output filename
|
||||
string filename = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss}.txt";
|
||||
|
||||
// If we have an output directory
|
||||
if (!string.IsNullOrWhiteSpace(outputDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
}
|
||||
|
||||
// Write the output data
|
||||
using (var sw = new StreamWriter(File.OpenWrite(filename)))
|
||||
{
|
||||
sw.WriteLine(builder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Test
|
||||
foreach (string inputPath in inputPaths)
|
||||
{
|
||||
if (info)
|
||||
Printer.PrintPathInfo(inputPath, json, debug);
|
||||
Printer.PrintPathInfo(inputPath, json, outputPath, debug);
|
||||
else if (extract)
|
||||
Extractor.ExtractPath(inputPath, outputPath);
|
||||
else
|
||||
@@ -170,8 +170,8 @@ namespace Test
|
||||
#if NET6_0_OR_GREATER
|
||||
Console.WriteLine("-j, --json Print executable info as JSON");
|
||||
#endif
|
||||
Console.WriteLine("-x, --extract Extract archive formats");
|
||||
Console.WriteLine("-o, --outdir [PATH] Set output path for extraction (REQUIRED)");
|
||||
Console.WriteLine("-x, --extract Extract archive formats (Requires -o)");
|
||||
Console.WriteLine("-o, --outdir [PATH] Set output path for information and extraction");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Test
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}-exception.txt")))
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"exception-{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
|
||||
{
|
||||
sw.WriteLine(ex);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace Test
|
||||
return;
|
||||
}
|
||||
|
||||
using (var sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
|
||||
using (var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
|
||||
{
|
||||
foreach (string key in protections.Keys.OrderBy(k => k))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user