// use this for testing outside of TraceMyNet public static void MainMethod(string[] args) { if (args == null || args.Length == 0) { Console.WriteLine("USAGE: BinaryFormatViewer <filename>"); return; } Stream stream = File.OpenRead(args[0]); BinaryFormatReader reader = new BinaryFormatReader(); reader.ReadAndDump(stream, Console.Out); stream.Close(); }
public void FormatData(IDataPacket[] dataPackets, RichTextBox richTextBox) { if (dataPackets == null || dataPackets.Length == 0) { return; } richTextBox.Clear(); ScatterGatherStream sgStream = new ScatterGatherStream(); DataDirection dir = dataPackets[0].Direction; Color color = dataPackets[0].Direction == DataDirection.Received ? Color.Purple : Color.Blue; BinaryFormatReader bfr = new BinaryFormatReader(); int dataCount = 0; for (int i = 0; i < dataPackets.Length; i++) { IDataPacket dataPacket = dataPackets[i]; if (dataPacket.Direction != dir) { if (dataCount > 0) { StringWriter writer = new StringWriter(); bfr.ReadAndDump(sgStream, writer); richTextBox.SelectionColor = color; richTextBox.AppendText(writer.ToString()); richTextBox.AppendText("\n----------------------------------------------\n"); } sgStream = new ScatterGatherStream(); dir = dataPacket.Direction; color = dir == DataDirection.Received ? Color.Purple : Color.Blue; dataCount = 0; } byte[] data = dataPacket.Data; if (data != null && data.Length > 0) { if (data[0] == 0x2E && data[1] == 0x4E && data[2] == 0x45 && data[3] == 0x54) { richTextBox.SelectionColor = color; richTextBox.AppendText("\nHeader For " + dir.ToString()); richTextBox.AppendText("\n----------------------------------------------\n"); } else { sgStream.Add(data); dataCount += data.Length; } } } }