From 0fd0cf689a4153daa2415972f60bed15d91faf2b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 13 Jan 2023 10:41:50 -0800 Subject: [PATCH] Add JSON serialization to wrappers (.NET 6) --- BurnOutSharp.Wrappers/AACSMediaKeyBlock.cs | 7 ++ BurnOutSharp.Wrappers/BDPlusSVM.cs | 7 ++ BurnOutSharp.Wrappers/BFPK.cs | 7 ++ BurnOutSharp.Wrappers/BSP.cs | 7 ++ BurnOutSharp.Wrappers/CFB.cs | 7 ++ BurnOutSharp.Wrappers/CIA.cs | 7 ++ .../ConcreteInterfaceSerializer.cs | 82 +++++++++++++ BurnOutSharp.Wrappers/GCF.cs | 7 ++ BurnOutSharp.Wrappers/LinearExecutable.cs | 7 ++ BurnOutSharp.Wrappers/MSDOS.cs | 7 ++ BurnOutSharp.Wrappers/MicrosoftCabinet.cs | 7 ++ BurnOutSharp.Wrappers/N3DS.cs | 7 ++ BurnOutSharp.Wrappers/NCF.cs | 7 ++ BurnOutSharp.Wrappers/NewExecutable.cs | 7 ++ BurnOutSharp.Wrappers/Nitro.cs | 7 ++ BurnOutSharp.Wrappers/PAK.cs | 7 ++ BurnOutSharp.Wrappers/PortableExecutable.cs | 7 ++ BurnOutSharp.Wrappers/Quantum.cs | 7 ++ BurnOutSharp.Wrappers/SGA.cs | 7 ++ BurnOutSharp.Wrappers/VBSP.cs | 7 ++ BurnOutSharp.Wrappers/VPK.cs | 7 ++ BurnOutSharp.Wrappers/WAD.cs | 7 ++ BurnOutSharp.Wrappers/WrapperBase.cs | 30 ++++- BurnOutSharp.Wrappers/XZP.cs | 7 ++ Test/Printer.cs | 115 +++++++++++++++++- Test/Program.cs | 16 ++- 26 files changed, 390 insertions(+), 7 deletions(-) create mode 100644 BurnOutSharp.Wrappers/ConcreteInterfaceSerializer.cs diff --git a/BurnOutSharp.Wrappers/AACSMediaKeyBlock.cs b/BurnOutSharp.Wrappers/AACSMediaKeyBlock.cs index d829f9bb..997adab9 100644 --- a/BurnOutSharp.Wrappers/AACSMediaKeyBlock.cs +++ b/BurnOutSharp.Wrappers/AACSMediaKeyBlock.cs @@ -268,6 +268,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_mediaKeyBlock, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/BDPlusSVM.cs b/BurnOutSharp.Wrappers/BDPlusSVM.cs index e16a1a1b..f9b00d73 100644 --- a/BurnOutSharp.Wrappers/BDPlusSVM.cs +++ b/BurnOutSharp.Wrappers/BDPlusSVM.cs @@ -126,6 +126,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_svm, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/BFPK.cs b/BurnOutSharp.Wrappers/BFPK.cs index 9ef99f47..5e31bd41 100644 --- a/BurnOutSharp.Wrappers/BFPK.cs +++ b/BurnOutSharp.Wrappers/BFPK.cs @@ -235,6 +235,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_archive, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/BSP.cs b/BurnOutSharp.Wrappers/BSP.cs index 32249d6c..9d43e3a7 100644 --- a/BurnOutSharp.Wrappers/BSP.cs +++ b/BurnOutSharp.Wrappers/BSP.cs @@ -215,6 +215,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/CFB.cs b/BurnOutSharp.Wrappers/CFB.cs index 344c2cf8..49e11c64 100644 --- a/BurnOutSharp.Wrappers/CFB.cs +++ b/BurnOutSharp.Wrappers/CFB.cs @@ -487,6 +487,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_binary, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/CIA.cs b/BurnOutSharp.Wrappers/CIA.cs index ec32a248..af4590a1 100644 --- a/BurnOutSharp.Wrappers/CIA.cs +++ b/BurnOutSharp.Wrappers/CIA.cs @@ -705,6 +705,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_cia, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/ConcreteInterfaceSerializer.cs b/BurnOutSharp.Wrappers/ConcreteInterfaceSerializer.cs new file mode 100644 index 00000000..d2091e2a --- /dev/null +++ b/BurnOutSharp.Wrappers/ConcreteInterfaceSerializer.cs @@ -0,0 +1,82 @@ +#if NET6_0_OR_GREATER +using System; +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace BurnOutSharp.Wrappers +{ + /// + /// Serializer class for abstract classes + /// + /// + internal class ConcreteAbstractSerializer : JsonConverterFactory + { + public override bool CanConvert(Type typeToConvert) => typeToConvert.IsAbstract; + + class ConcreteAbstractSerializerOfType : JsonConverter + { + static ConcreteAbstractSerializerOfType() + { + if (!typeof(TAbstract).IsAbstract && !typeof(TAbstract).IsInterface) + throw new NotImplementedException(string.Format("Concrete class {0} is not supported", typeof(TAbstract))); + } + + public override TAbstract? Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) => + throw new NotImplementedException(); + + public override void Write(System.Text.Json.Utf8JsonWriter writer, TAbstract value, System.Text.Json.JsonSerializerOptions options) => + JsonSerializer.Serialize(writer, value!, options); + } + + public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) => + (JsonConverter)Activator.CreateInstance( + typeof(ConcreteAbstractSerializerOfType<>).MakeGenericType(new Type[] { type }), + BindingFlags.Instance | BindingFlags.Public, + binder: null, + args: Array.Empty(), + culture: null).ThrowOnNull(); + } + + /// + /// Serializer class for interfaces + /// + /// + internal class ConcreteInterfaceSerializer : JsonConverterFactory + { + public override bool CanConvert(Type typeToConvert) => typeToConvert.IsInterface; + + class ConcreteInterfaceSerializerOfType : JsonConverter + { + static ConcreteInterfaceSerializerOfType() + { + if (!typeof(TInterface).IsAbstract && !typeof(TInterface).IsInterface) + throw new NotImplementedException(string.Format("Concrete class {0} is not supported", typeof(TInterface))); + } + + public override TInterface? Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) => + throw new NotImplementedException(); + + public override void Write(System.Text.Json.Utf8JsonWriter writer, TInterface value, System.Text.Json.JsonSerializerOptions options) => + JsonSerializer.Serialize(writer, value!, options); + } + + public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) => + (JsonConverter)Activator.CreateInstance( + typeof(ConcreteInterfaceSerializerOfType<>).MakeGenericType(new Type[] { type }), + BindingFlags.Instance | BindingFlags.Public, + binder: null, + args: Array.Empty(), + culture: null).ThrowOnNull(); + } + + /// + /// Extensions for generic object types + /// + /// + internal static class ObjectExtensions + { + public static T ThrowOnNull(this T? value) where T : class => value ?? throw new ArgumentNullException(); + } +} +#endif \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/GCF.cs b/BurnOutSharp.Wrappers/GCF.cs index 250a7df6..b5b76485 100644 --- a/BurnOutSharp.Wrappers/GCF.cs +++ b/BurnOutSharp.Wrappers/GCF.cs @@ -939,6 +939,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/LinearExecutable.cs b/BurnOutSharp.Wrappers/LinearExecutable.cs index 94694918..11388c31 100644 --- a/BurnOutSharp.Wrappers/LinearExecutable.cs +++ b/BurnOutSharp.Wrappers/LinearExecutable.cs @@ -991,6 +991,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_executable, _jsonSerializerOptions); + +#endif + #endregion #region REMOVE -- DO NOT USE diff --git a/BurnOutSharp.Wrappers/MSDOS.cs b/BurnOutSharp.Wrappers/MSDOS.cs index 6aa51320..01ce96a7 100644 --- a/BurnOutSharp.Wrappers/MSDOS.cs +++ b/BurnOutSharp.Wrappers/MSDOS.cs @@ -204,6 +204,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_executable, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs index 6e4a2817..9cc6737b 100644 --- a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs @@ -537,6 +537,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_cabinet, _jsonSerializerOptions); + +#endif + #endregion } } diff --git a/BurnOutSharp.Wrappers/N3DS.cs b/BurnOutSharp.Wrappers/N3DS.cs index 6977ca7a..dfef33eb 100644 --- a/BurnOutSharp.Wrappers/N3DS.cs +++ b/BurnOutSharp.Wrappers/N3DS.cs @@ -740,6 +740,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_cart, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/NCF.cs b/BurnOutSharp.Wrappers/NCF.cs index 212b792c..ae40be36 100644 --- a/BurnOutSharp.Wrappers/NCF.cs +++ b/BurnOutSharp.Wrappers/NCF.cs @@ -559,6 +559,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/NewExecutable.cs b/BurnOutSharp.Wrappers/NewExecutable.cs index 24989493..0c2e72b0 100644 --- a/BurnOutSharp.Wrappers/NewExecutable.cs +++ b/BurnOutSharp.Wrappers/NewExecutable.cs @@ -598,6 +598,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_executable, _jsonSerializerOptions); + +#endif + #endregion #region REMOVE -- DO NOT USE diff --git a/BurnOutSharp.Wrappers/Nitro.cs b/BurnOutSharp.Wrappers/Nitro.cs index e5ba7e3b..5cc408c8 100644 --- a/BurnOutSharp.Wrappers/Nitro.cs +++ b/BurnOutSharp.Wrappers/Nitro.cs @@ -610,6 +610,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_cart, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/PAK.cs b/BurnOutSharp.Wrappers/PAK.cs index b51c191c..6caf3a22 100644 --- a/BurnOutSharp.Wrappers/PAK.cs +++ b/BurnOutSharp.Wrappers/PAK.cs @@ -149,6 +149,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs index cac01dcc..500cb06b 100644 --- a/BurnOutSharp.Wrappers/PortableExecutable.cs +++ b/BurnOutSharp.Wrappers/PortableExecutable.cs @@ -2924,6 +2924,13 @@ namespace BurnOutSharp.Wrappers } } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_executable, _jsonSerializerOptions); + +#endif + #endregion #region Debug Data diff --git a/BurnOutSharp.Wrappers/Quantum.cs b/BurnOutSharp.Wrappers/Quantum.cs index 57023ada..fbac6b46 100644 --- a/BurnOutSharp.Wrappers/Quantum.cs +++ b/BurnOutSharp.Wrappers/Quantum.cs @@ -280,6 +280,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_archive, _jsonSerializerOptions); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/SGA.cs b/BurnOutSharp.Wrappers/SGA.cs index 89ad7c7a..95206eda 100644 --- a/BurnOutSharp.Wrappers/SGA.cs +++ b/BurnOutSharp.Wrappers/SGA.cs @@ -633,6 +633,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/VBSP.cs b/BurnOutSharp.Wrappers/VBSP.cs index a3097b81..19afce24 100644 --- a/BurnOutSharp.Wrappers/VBSP.cs +++ b/BurnOutSharp.Wrappers/VBSP.cs @@ -156,6 +156,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/VPK.cs b/BurnOutSharp.Wrappers/VPK.cs index 0d3cf0b0..a7124ac9 100644 --- a/BurnOutSharp.Wrappers/VPK.cs +++ b/BurnOutSharp.Wrappers/VPK.cs @@ -295,6 +295,13 @@ namespace BurnOutSharp.Wrappers } } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/WAD.cs b/BurnOutSharp.Wrappers/WAD.cs index 9c0b2c95..5aa56cc2 100644 --- a/BurnOutSharp.Wrappers/WAD.cs +++ b/BurnOutSharp.Wrappers/WAD.cs @@ -199,6 +199,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/BurnOutSharp.Wrappers/WrapperBase.cs b/BurnOutSharp.Wrappers/WrapperBase.cs index 5f37ba8f..fc091679 100644 --- a/BurnOutSharp.Wrappers/WrapperBase.cs +++ b/BurnOutSharp.Wrappers/WrapperBase.cs @@ -34,6 +34,25 @@ namespace BurnOutSharp.Wrappers /// This is only populated if is protected Stream _streamData = null; +#if NET6_0_OR_GREATER + + /// + /// JSON serializer options for output printing + /// + protected System.Text.Json.JsonSerializerOptions _jsonSerializerOptions + { + get + { + var serializer = new System.Text.Json.JsonSerializerOptions { IncludeFields = true }; + serializer.Converters.Add(new ConcreteAbstractSerializer()); + serializer.Converters.Add(new ConcreteInterfaceSerializer()); + serializer.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); + return serializer; + } + } + +#endif + #endregion #region Data @@ -264,10 +283,19 @@ namespace BurnOutSharp.Wrappers #region Printing /// - /// Pretty print the Executable information + /// Pretty print the item information /// public abstract void Print(); +#if NET6_0_OR_GREATER + + /// + /// Export the item information as JSON + /// + public abstract string ExportJSON(); + +#endif + #endregion } } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/XZP.cs b/BurnOutSharp.Wrappers/XZP.cs index 0ee9b748..9346a29c 100644 --- a/BurnOutSharp.Wrappers/XZP.cs +++ b/BurnOutSharp.Wrappers/XZP.cs @@ -295,6 +295,13 @@ namespace BurnOutSharp.Wrappers Console.WriteLine(); } +#if NET6_0_OR_GREATER + + /// + public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(_file, _jsonSerializerOptions); + +#endif + #endregion #region Extraction diff --git a/Test/Printer.cs b/Test/Printer.cs index 2f713253..3279c291 100644 --- a/Test/Printer.cs +++ b/Test/Printer.cs @@ -13,21 +13,22 @@ namespace Test /// Wrapper to print information for a single path /// /// File or directory path + /// Enable JSON output, if supported /// Enable debug output - public static void PrintPathInfo(string path, bool debug) + public static 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, debug); + PrintFileInfo(path, json, debug); } else if (Directory.Exists(path)) { foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) { - PrintFileInfo(file, debug); + PrintFileInfo(file, json, debug); } } else @@ -39,10 +40,15 @@ namespace Test /// /// Print information for a single file, if possible /// - private static void PrintFileInfo(string file, bool debug) + private static void PrintFileInfo(string file, bool json, bool debug) { Console.WriteLine($"Attempting to print info for {file}"); +#if NET6_0_OR_GREATER + // Setup the JSON output + string serializedData = null; +#endif + using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { // Read the first 8 bytes @@ -162,6 +168,11 @@ namespace Test // Print the AACS MKB info to screen mkb.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = mkb.ExportJSON(); +#endif } // BD+ SVM @@ -181,6 +192,11 @@ namespace Test // Print the BD+ SVM info to screen svm.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = svm.ExportJSON(); +#endif } // BFPK archive @@ -200,6 +216,11 @@ namespace Test // Print the BFPK info to screen bfpk.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = bfpk.ExportJSON(); +#endif } // BSP @@ -219,6 +240,11 @@ namespace Test // Print the BSP info to screen bsp.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = bsp.ExportJSON(); +#endif } // CFB @@ -238,6 +264,11 @@ namespace Test // Print the CFB to screen cfb.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = cfb.ExportJSON(); +#endif } // CIA @@ -257,6 +288,11 @@ namespace Test // Print the CIA info to screen cia.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = cia.ExportJSON(); +#endif } // GCF @@ -276,6 +312,11 @@ namespace Test // Print the GCF info to screen gcf.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = gcf.ExportJSON(); +#endif } // IS-CAB archive @@ -321,6 +362,11 @@ namespace Test // Print the cabinet info to screen cabinet.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = cabinet.ExportJSON(); +#endif } // N3DS @@ -340,6 +386,11 @@ namespace Test // Print the N3DS info to screen n3ds.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = n3ds.ExportJSON(); +#endif } // NCF @@ -359,6 +410,11 @@ namespace Test // Print the NCF info to screen ncf.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = ncf.ExportJSON(); +#endif } // Nitro @@ -378,6 +434,11 @@ namespace Test // Print the Nitro info to screen nitro.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = nitro.ExportJSON(); +#endif } // PAK @@ -397,6 +458,11 @@ namespace Test // Print the PAK info to screen pak.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = pak.ExportJSON(); +#endif } // Quantum @@ -416,6 +482,11 @@ namespace Test // Print the Quantum info to screen quantum.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = quantum.ExportJSON(); +#endif } // SGA @@ -435,6 +506,11 @@ namespace Test // Print the SGA info to screen sga.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = sga.ExportJSON(); +#endif } // VBSP @@ -454,6 +530,11 @@ namespace Test // Print the VBSP info to screen vbsp.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = vbsp.ExportJSON(); +#endif } // VPK @@ -473,6 +554,11 @@ namespace Test // Print the VPK info to screen vpk.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = vpk.ExportJSON(); +#endif } // WAD @@ -492,6 +578,11 @@ namespace Test // Print the WAD info to screen wad.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = wad.ExportJSON(); +#endif } // XZP @@ -511,6 +602,11 @@ namespace Test // Print the XZP info to screen xzp.Print(); + +#if NET6_0_OR_GREATER + // Assign the serialized data + serializedData = xzp.ExportJSON(); +#endif } // Everything else @@ -522,6 +618,17 @@ namespace Test return; } } + +#if NET6_0_OR_GREATER + + // If we have serialized data, write it out to a file + if (json && !string.IsNullOrEmpty(serializedData)) + { + // No-op for now + Console.WriteLine(serializedData); + } + +#endif } } } \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs index 9ea69c65..af9be401 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -18,7 +18,7 @@ namespace Test p.ProgressChanged += Protector.Changed; // Set initial values for scanner flags - bool debug = false, archives = true, contents = true, packers = true, paths = true, info = false, extract = false; + bool debug = false, archives = true, contents = true, json = false, packers = true, paths = true, info = false, extract = false; string outputPath = string.Empty; var inputPaths = new List(); @@ -52,6 +52,15 @@ namespace Test contents = false; break; +#if NET6_0_OR_GREATER + + case "-j": + case "--json": + json = true; + break; + +#endif + case "-np": case "--no-packers": packers = false; @@ -130,7 +139,7 @@ namespace Test foreach (string inputPath in inputPaths) { if (info) - Printer.PrintPathInfo(inputPath, debug); + Printer.PrintPathInfo(inputPath, json, debug); else if (extract) Extractor.ExtractPath(inputPath, outputPath); else @@ -158,6 +167,9 @@ namespace Test Console.WriteLine("-np, --no-packers Disable scanning for packers"); Console.WriteLine("-ns, --no-paths Disable scanning for path checks"); Console.WriteLine("-i, --info Print executable info"); +#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)"); }