protected void ClearState() { deviceLabel = ""; statusLabel = ""; subStatusLabel = ""; wizStatusLabel = ""; dataSet.Clear(); packetParser.Reset(); prevSelectedSlices = null; curNodeList = null; curPacketList = null; curSelBytes = new MemoryStream(); tmpEventList = new List<TCPEvent>(8); tmpPacketList = new List<IPPacket>(32); richTextBox.Clear(); propertyGrid.SelectedObject = null; }
private void UpdateDumpView() { // // Sort the selected packets // List<IPPacket> packets = new List<IPPacket>(); Dictionary<IPPacket, DataGridViewRow> packetToRow = new Dictionary<IPPacket, DataGridViewRow>(); foreach (DataGridViewRow row in dataGridView.SelectedRows) { if ((UInt32)row.Cells[msgTypeDataGridViewTextBoxColumn.Index].Value != Convert.ToUInt32(MessageType.MESSAGE_TYPE_PACKET)) continue; int index = (int)row.Cells[indexDataGridViewTextBoxColumn.Index].Value; IPPacket packet = packetParser.GetPacket(index); packets.Add(packet); packetToRow[packet] = row; } packets.Sort(); curLinesToPackets = new Dictionary<int, IPPacket>(packets.Count); curPacketList = packets; // // Iterate through the selected packets and add a raw dump // of each, and add each to the list of decoded packets // StringBuilder dump = new StringBuilder(512); int packetNo = 0; int lineNo = 0; string[] lines; foreach (IPPacket packet in packets) { if (packetNo > 0) { dump.Append("\n"); lineNo++; } int lineStart = lineNo; string linePrefix; switch (packet.Direction) { case PacketDirection.PACKET_DIRECTION_INCOMING: linePrefix = "<< "; break; case PacketDirection.PACKET_DIRECTION_OUTGOING: linePrefix = ">> "; break; default: linePrefix = ">< "; break; } dump.AppendFormat("{0}.¸¸.· #{1}\n", linePrefix, packet.Index); lineNo++; int nLines = 0; LineOffset[] lineOffsets = new LineOffset[0]; if (dumpDisplayMode == DisplayMode.HEX) { dump.Append(StaticUtils.ByteArrayToHexDump(packet.Bytes, linePrefix, out nLines)); dump.Append("\n"); } else { string str = StaticUtils.DecodeASCII(packet.Bytes); /* if (str.EndsWith("\r\n")) { str = str.Substring(0, str.Length - 2); } else if (str.EndsWith("\n")) { str = str.Substring(0, str.Length - 1); }*/ List<LineOffset> tmpList = new List<LineOffset>(1); int offset = 0; do { int p1 = str.IndexOf("\r\n", offset); int p2 = str.IndexOf("\n", offset); int pos; if (p1 >= 0 && p2 >= 0) { pos = Math.Min(p1, p2); } else { pos = (p1 >= 0) ? p1 : p2; } int termLen = (pos == p1) ? 2 : 1; if (pos == -1) { pos = str.Length; termLen = 0; } int length = pos - offset; string line = str.Substring(offset, length); tmpList.Add(new LineOffset(offset, length, termLen)); dump.AppendFormat("{0}{1}\n", linePrefix, line); nLines++; offset += pos - offset + termLen; } while (offset < str.Length); lineOffsets = tmpList.ToArray(); } for (int i = 0; i < nLines; i++) { curLinesToPackets[lineNo + i] = packet; } lineNo += nLines; packet.Tag = new PacketPosition(packetToRow[packet], lineStart, lineNo, lineOffsets); packetNo++; } richTextBox.Text = dump.ToString(); richTextBox.SelectAll(); richTextBox.SelectionColor = richTextBox.ForeColor; richTextBox.SelectionBackColor = richTextBox.BackColor; prevSelectedSlices = null; lines = richTextBox.Lines; Color colorIncoming = Color.FromArgb(138, 232, 153); Color colorOutgoing = Color.FromArgb(156, 183, 209); for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("<<")) { richTextBox.Select(richTextBox.GetFirstCharIndexFromLine(i), 2); richTextBox.SelectionColor = colorIncoming; } else if (lines[i].StartsWith(">>")) { richTextBox.Select(richTextBox.GetFirstCharIndexFromLine(i), 2); richTextBox.SelectionColor = colorOutgoing; } else if (lines[i].StartsWith("><")) { int index = richTextBox.GetFirstCharIndexFromLine(i); richTextBox.Select(index, 1); richTextBox.SelectionColor = colorIncoming; richTextBox.Select(index + 1, 1); richTextBox.SelectionColor = colorOutgoing; } } curNodeList = packetParser.GetTransactionsForPackets(packets); propertyGrid.SelectedObject = curNodeList; if (curNodeList.Count > 0) { UpdateDumpHighlighting(curNodeList[0].GetAllSlices().ToArray()); } }
public TransactionNodeList GetTransactionsForPackets(List<IPPacket> packets) { TransactionNodeList list = new TransactionNodeList(); List<TransactionNode> potentialNodes = new List<TransactionNode>(packets.Count); foreach (IPPacket packet in packets) { if (packetIndexToNodes.ContainsKey(packet.Index)) { potentialNodes.AddRange(packetIndexToNodes[packet.Index]); } } foreach (TransactionNode node in potentialNodes) { if (list.Contains(node)) continue; bool hasAll = true; foreach (PacketSlice slice in node.GetAllSlices()) { if (!packets.Contains(slice.Packet)) { hasAll = false; break; } } if (hasAll) list.PushNode(node); } list.PushedAllNodes(); return list; }