From d1c7c00f1958862bf2d76a70829a232185e72bd4 Mon Sep 17 00:00:00 2001 From: KimLS Date: Fri, 18 Oct 2024 15:49:49 -0700 Subject: [PATCH] Binary dumping; not yet implemented --- .../stream_parser/ConsoleHostedService.cs | 71 +------------------ .../ConsoleHostedServiceOptions.cs | 6 +- .../Properties/launchSettings.json | 2 +- 3 files changed, 5 insertions(+), 74 deletions(-) diff --git a/utils/stream_parser/stream_parser/ConsoleHostedService.cs b/utils/stream_parser/stream_parser/ConsoleHostedService.cs index 7779c1688..c635e360a 100644 --- a/utils/stream_parser/stream_parser/ConsoleHostedService.cs +++ b/utils/stream_parser/stream_parser/ConsoleHostedService.cs @@ -71,15 +71,10 @@ namespace StreamParser foreach(var c in _connections) { - if(o.Dump) + if(o.Text) { DumpConnectionToTextFile(c.Value, o.Output, o.Decrypt, o.DecompressOpcodes); } - - if(o.Csv) - { - DumpConnectionToCsvFile(c.Value, o.Output, o.Decrypt); - } } _applicationLifetime.StopApplication(); @@ -307,70 +302,6 @@ namespace StreamParser } } - private class CsvRow - { - public int Index { get; set; } - public string Direction { get; set; } - public string Opcode { get; set; } - public int Size { get; set; } - public string Data { get; set; } - } - - private void DumpConnectionToCsvFile(ParsedConnection c, string output, bool decrypt) - { - try - { - var path = output + string.Format("{0}-{1}.csv", c.ConnectionType.ToString().ToLower(), c.ConnectedTime.ToString("yyyyMMddHHmmssfff")); - if (File.Exists(path)) - { - File.Delete(path); - } - - var rows = new List(); - var i = 0; - foreach (var p in c.Packets) - { - var row = new CsvRow(); - row.Index = i++; - ReadOnlySpan data = p.Data; - row.Direction = p.Direction == Direction.ClientToServer ? "0" : "1"; - - switch (c.ConnectionType) - { - case ConnectionType.Chat: - { - row.Opcode = data[0].ToString(); - var gp = new GamePacket(data.Slice(1)); - row.Size = data.Length - 1; - row.Data = gp.ToModelString(512, false); - } - break; - default: - { - - row.Opcode = BitConverter.ToUInt16(data.Slice(0, 2)).ToString(); - var gp = new GamePacket(data.Slice(2)); - row.Size = data.Length - 2; - row.Data = gp.ToModelString(512, false); - } - break; - } - - rows.Add(row); - } - - using (var writer = new StreamWriter(path)) - using (var csv = new CsvHelper.CsvWriter(writer, CultureInfo.InvariantCulture)) - { - csv.WriteRecords(rows); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Error dumping connection {0} to csv file", c.ConnectedTime.ToString("s")); - } - } - private byte[] EQDecrypt(ReadOnlySpan data) { try diff --git a/utils/stream_parser/stream_parser/ConsoleHostedServiceOptions.cs b/utils/stream_parser/stream_parser/ConsoleHostedServiceOptions.cs index de560175d..d744e549d 100644 --- a/utils/stream_parser/stream_parser/ConsoleHostedServiceOptions.cs +++ b/utils/stream_parser/stream_parser/ConsoleHostedServiceOptions.cs @@ -12,10 +12,10 @@ namespace StreamParser public string Output { get; set; } [Option("text", Default = true, HelpText = "Dump connections to text files.")] - public bool Dump { get; set; } + public bool Text { get; set; } - [Option("csv", Default = false, HelpText = "Dump connections to csv files appropriate for building ML models.")] - public bool Csv { get; set; } + [Option("binary", Default = false, HelpText = "Dump connections to binary files.")] + public bool Binary { get; set; } [Option("decrypt", Default = false, HelpText = "Decrypt the \"Encrypted\" packets.")] public bool Decrypt { get; set; } diff --git a/utils/stream_parser/stream_parser/Properties/launchSettings.json b/utils/stream_parser/stream_parser/Properties/launchSettings.json index 894e77546..18f9da4e2 100644 --- a/utils/stream_parser/stream_parser/Properties/launchSettings.json +++ b/utils/stream_parser/stream_parser/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "stream_parser": { "commandName": "Project", - "commandLineArgs": "--input input/cap_login_to_zone_10_16_2024.pcap --output output_test/ --text --decrypt --decompress 16742 168 30346", + "commandLineArgs": "--input input/cap_login_to_zone_10_16_2024.pcap --output output_test/ --binary --decrypt --decompress 16742 168 30346", "workingDirectory": "E:\\Projects\\stream_parser\\stream_parser\\bin\\Debug\\net6.0\\" } }