using System; using System.IO; using System.Text.Json; using GeViSetEditor.Core.Parsers; namespace GeViSetEditor.CLI.Commands { /// /// Analyze binary structure to understand configuration format /// public static class AnalyzeStructureCommand { public static void Execute(string inputPath, string? outputReportPath = null) { if (!File.Exists(inputPath)) { Console.WriteLine($"ERROR: File not found: {inputPath}"); return; } try { // Read file byte[] data = File.ReadAllBytes(inputPath); Console.WriteLine($"Analyzing: {inputPath}"); Console.WriteLine($"File size: {data.Length:N0} bytes"); // Run analysis var analyzer = new AdvancedBinaryAnalyzer(); var report = analyzer.Analyze(data); // Show summary Console.WriteLine("\n=== Analysis Summary ==="); Console.WriteLine($"Header: '{report.Header}'"); Console.WriteLine($"Header ends at: {report.HeaderEndOffset} (0x{report.HeaderEndOffset:X})"); Console.WriteLine($"Sections identified: {report.Sections.Count}"); Console.WriteLine("\n=== Markers Found ==="); foreach (var marker in report.Markers) { Console.WriteLine($"{marker.Key}: {marker.Value.Count} occurrences"); } Console.WriteLine("\n=== Data Type Counts ==="); foreach (var type in report.DataTypeCounts) { Console.WriteLine($"{type.Key}: {type.Value}"); } // Export detailed report if requested if (!string.IsNullOrEmpty(outputReportPath)) { var options = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; string json = JsonSerializer.Serialize(report, options); File.WriteAllText(outputReportPath, json); Console.WriteLine($"\nDetailed report saved to: {outputReportPath}"); } Console.WriteLine("\n✓ Analysis complete!"); } catch (Exception ex) { Console.WriteLine($"\n✗ ERROR: {ex.Message}"); Console.WriteLine($"Stack trace:\n{ex.StackTrace}"); } } } }