private HTTPMessage ParseNode(TransactionNode httpNode, bool isRequest) { IPPacket pkt = httpNode.Slices[0].Packet; HTTPMessage msg = new HTTPMessage(httpNode.Index, pkt.Direction, pkt.Timestamp); if (isRequest) { msg.HeadlineText = String.Format("{0} {1} {2}", httpNode["Verb"], httpNode["Argument"], httpNode["Protocol"]); } else { msg.HeadlineText = String.Format("{0} {1}", httpNode["Protocol"], httpNode["Result"]); } TransactionNode headersNode = httpNode.FindChild("Headers", false); if (headersNode != null) { foreach (string name in headersNode.FieldNames) { msg.AddHeaderField(name, headersNode.Fields[name]); } } TransactionNode bodyNode = httpNode.FindChild("Body", false); if (bodyNode != null) { if (bodyNode.Fields.ContainsKey("XML")) { string body; XmlHighlighter highlighter = new XmlHighlighter(XmlHighlightColorScheme.VisualizationScheme); XmlUtils.PrettyPrint((string)bodyNode["XML"], out body, highlighter); msg.BodyText = body; highlighter.HighlightRichTextBox(msg.BodyBox); } else if (bodyNode.Fields.ContainsKey("HTML")) { msg.BodyText = (string)bodyNode["HTML"]; } else if (bodyNode.Fields.ContainsKey("Raw")) { msg.SetBodyFromPreviewData((byte[])bodyNode.Fields["Raw"], 512); } else { msg.BodyText = String.Format("{0} unhandled", bodyNode.FieldNames[0]); } } return(msg); }
public override VisualTransaction[] GetTransactions(IPSession session) { List <MSNSessionMessage> messages = new List <MSNSessionMessage>(); Dictionary <UInt32, MSNP2PMessage> messageFromId = new Dictionary <UInt32, MSNP2PMessage>(); foreach (TransactionNode node in session.Nodes) { if (node.Name.StartsWith("MSN")) { TransactionNode chunk = node.FindChild("MSNP2PMessageChunk"); if (chunk != null) { MSNP2PMessage msg; TransactionNode headers = chunk.FindChild("Headers"); UInt32 msgID = (UInt32)headers.Fields["MessageID"]; UInt32 chunkSize = (UInt32)headers.Fields["ChunkSize"]; if (messageFromId.ContainsKey(msgID)) { msg = messageFromId[msgID]; } else { PacketDirection direction = headers.GetSlicesForFieldPath("SessionID")[0].Packet.Direction; UInt32 sessionID = (UInt32)headers.Fields["SessionID"]; UInt32 flags = (UInt32)headers.Fields["Flags"]; UInt64 dataOffset = (UInt64)headers.Fields["DataOffset"]; UInt64 dataSize = (UInt64)headers.Fields["DataSize"]; UInt32 ackedMsgID = (UInt32)headers.Fields["AckedMsgID"]; UInt32 prevAckedMsgID = (UInt32)headers.Fields["PrevAckedMsgID"]; UInt64 ackedDataSize = (UInt64)headers.Fields["AckedDataSize"]; msg = new MSNP2PMessage(chunk.Index, direction, chunk.StartTime, msgID, sessionID, flags, dataOffset, dataSize, ackedMsgID, prevAckedMsgID, ackedDataSize); messages.Add(msg); messageFromId[msgID] = msg; } int maxPreview = 4096; if (msg.Flags == 0x20) { maxPreview = 131072; } if (chunkSize > 0 && msg.Transferred < (ulong)maxPreview) { TransactionNode content = chunk.FindChild("Content"); //string fieldName = (msg.SessionID != 0) ? "Raw" : "MSNSLP"; byte[] bytes = (byte[])content.Fields[content.FieldNames[0]]; int n = bytes.Length; int max = maxPreview - (int)msg.Transferred; if (n > max) { n = max; } msg.PreviewData.Write(bytes, 0, bytes.Length); } msg.EndTime = chunk.EndTime; msg.Transferred += chunkSize; } else { TransactionNode bodyNode = node.FindChild("Payload"); if (bodyNode != null && bodyNode.Fields.ContainsKey("MSNSLP")) { MSNSLPMessage msg = new MSNSLPMessage(bodyNode.Index, bodyNode.GetSlicesForFieldPath("MSNSLP")[0].Packet.Direction, bodyNode.StartTime, (string)bodyNode["MSNSLP"]); messages.Add(msg); } } } } return(messages.ToArray()); }
public override VisualTransaction[] GetTransactions(IPSession session) { List <VisualTransaction> messages = new List <VisualTransaction>(); char[] bodyTrimChars = new char[] { '\r', '\n' }; foreach (TransactionNode node in session.Nodes) { if (node.Name == "MSNSBCommand") { IPPacket pkt = node.Slices[0].Packet; VisualTransaction vt = new VisualTransaction(node.Index, pkt.Direction, pkt.Timestamp); string headline = (string)node["Command"]; if (node.Fields.ContainsKey("Arguments")) { headline += " " + (string)node["Arguments"]; } vt.HeadlineText = headline; XmlHighlighter highlighter = null; TransactionNode payloadNode = node.FindChild("Payload", false); if (payloadNode != null) { string body = ""; if (payloadNode.Fields.ContainsKey("XML")) { highlighter = new XmlHighlighter(XmlHighlightColorScheme.VisualizationScheme); XmlUtils.PrettyPrint((string)payloadNode["XML"], out body, highlighter); } else if (payloadNode.Fields.ContainsKey("Text")) { body = (string)payloadNode["Text"]; } else if (payloadNode.Fields.ContainsKey("MSNSLP")) { body = (string)payloadNode["MSNSLP"]; } else if (payloadNode.FindChild("Headers") != null) { TransactionNode headersNode = payloadNode.FindChild("Headers"); vt.HeaderRowsPerCol = Int32.MaxValue; foreach (string name in headersNode.Fields.Keys) { vt.AddHeaderField(name, headersNode.Fields[name].ToString()); } TransactionNode bodyNode = payloadNode.FindChild("Body"); if (bodyNode != null) { body = bodyNode.Fields[bodyNode.FieldNames[0]].ToString(); body = body.TrimEnd(bodyTrimChars); } } else { body = String.Format("Unhandled payload format: {0}", (payloadNode.FieldNames.Count > 0) ? payloadNode.FieldNames[0] : payloadNode.Children[0].Name); } vt.BodyText = body; if (highlighter != null) { highlighter.HighlightRichTextBox(vt.BodyBox); } } messages.Add(vt); } } return(messages.ToArray()); }
private HTTPMessage ParseNode(TransactionNode httpNode, bool isRequest) { IPPacket pkt = httpNode.Slices[0].Packet; HTTPMessage msg = new HTTPMessage(httpNode.Index, pkt.Direction, pkt.Timestamp); if (isRequest) { msg.HeadlineText = String.Format("{0} {1} {2}", httpNode["Verb"], httpNode["Argument"], httpNode["Protocol"]); } else { msg.HeadlineText = String.Format("{0} {1}", httpNode["Protocol"], httpNode["Result"]); } TransactionNode headersNode = httpNode.FindChild("Headers", false); if (headersNode != null) { foreach (string name in headersNode.FieldNames) { msg.AddHeaderField(name, headersNode.Fields[name]); } } TransactionNode bodyNode = httpNode.FindChild("Body", false); if (bodyNode != null) { if (bodyNode.Fields.ContainsKey("XML")) { string body; XmlHighlighter highlighter = new XmlHighlighter(XmlHighlightColorScheme.VisualizationScheme); XmlUtils.PrettyPrint((string)bodyNode["XML"], out body, highlighter); msg.BodyText = body; highlighter.HighlightRichTextBox(msg.BodyBox); } else if (bodyNode.Fields.ContainsKey("HTML")) { msg.BodyText = (string)bodyNode["HTML"]; } else if (bodyNode.Fields.ContainsKey("Raw")) { msg.SetBodyFromPreviewData((byte[])bodyNode.Fields["Raw"], 512); } else { msg.BodyText = String.Format("{0} unhandled", bodyNode.FieldNames[0]); } } return msg; }