Binary dumping; not yet implemented

This commit is contained in:
KimLS 2024-10-18 15:49:49 -07:00
parent 999ccdcb19
commit d1c7c00f19
3 changed files with 5 additions and 74 deletions

View File

@ -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<CsvRow>();
var i = 0;
foreach (var p in c.Packets)
{
var row = new CsvRow();
row.Index = i++;
ReadOnlySpan<byte> 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<byte> data)
{
try

View File

@ -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; }

View File

@ -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\\"
}
}