/// <summary> /// Load TCP Stream from WireShark TCPStreamFormat /// </summary> /// <param name="file">File</param> public static TcpStream FromFile(string file) { TcpStream tcp = new TcpStream(null); if (!string.IsNullOrEmpty(file)) { string[] sp = File.ReadAllLines(file); foreach (string line in sp) { string l = line.TrimStart().Replace(":", ""); ETcpEmisor em = line.StartsWith(" ") ? ETcpEmisor.A : ETcpEmisor.B; if (l.Length >= 9 && !l.Substring(0, 8).Contains(" ")) { // remove offset l = l.Substring(8, l.Length - 8).Trim(); } if (l.Length > 48) { l = l.Substring(0, 48); } l = l.Replace(" ", ""); byte[] data = HexHelper.FromHexString(l); if (tcp._Last == null) { tcp._Last = new TcpStreamMessage(data, em); tcp._InternalList.Add(tcp._Last); } else { // Check if its the same if (tcp._Last.Emisor == em) { tcp._Last.AddData(data); } else { // New Packet tcp._Last = new TcpStreamMessage(data, em); tcp._InternalList.Add(tcp._Last); } } } } return(tcp); }
public static TcpStream GetStream(List <TcpStream> streams, TcpHeader packet) { foreach (TcpStream stream in streams) { if (stream.IsSame(packet)) { stream.Add(packet); return(stream); } } if (packet.Data.Length == 0) { return(null); } TcpStream ret = new TcpStream(packet); streams.Add(ret); return(ret); }