Ejemplo n.º 1
0
        public void DisplayXML(string xmlData)
        {
            string prettyXml;
            XmlHighlighter highlighter = new XmlHighlighter(XmlHighlightColorScheme.DarkBlueScheme);

            XmlUtils.PrettyPrint(xmlData, out prettyXml, highlighter);

            richTextBox.Text = prettyXml;
            highlighter.HighlightRichTextBox(richTextBox);
        }
Ejemplo n.º 2
0
Archivo: MSN.cs Proyecto: SayHalou/ospy
        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();
        }
Ejemplo n.º 3
0
Archivo: XML.cs Proyecto: SayHalou/ospy
        public static void PrettyPrint(string xmlData, out string prettyXml, XmlHighlighter highlighter)
        {
            StringReader stringReader = new StringReader(xmlData);
            XmlTextReader reader = new XmlTextReader(stringReader);
            StringBuilder builder = new StringBuilder(xmlData.Length);
            string[] tokens;
            char[] nsSepChars = new char[] { ':' };

            int indent = 0;
            while (reader.Read())
            {
                int offset;

                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");

                        offset = builder.Length;
                        builder.Append("<");
                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_OPENING, offset, builder.Length - offset);

                        offset = builder.Length;
                        tokens = reader.Name.Split(nsSepChars, 2);
                        if (tokens.Length > 1)
                        {
                            builder.Append(tokens[0]);
                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_NAME, offset, builder.Length - offset);

                            offset = builder.Length;
                            builder.Append(":");
                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);

                            offset = builder.Length;
                            builder.Append(tokens[1]);
                        }
                        else
                        {
                            builder.Append(tokens[0]);
                        }

                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAME, offset, builder.Length - offset);

                        bool empty;
                        empty = reader.IsEmptyElement;

                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);

                            builder.Append(" ");

                            offset = builder.Length;

                            offset = builder.Length;
                            tokens = reader.Name.Split(nsSepChars, 2);
                            if (tokens.Length > 1)
                            {
                                builder.Append(tokens[0]);
                                if (highlighter != null)
                                    highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_KEY, offset, builder.Length - offset);

                                offset = builder.Length;
                                builder.Append(":");
                                if (highlighter != null)
                                    highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);

                                offset = builder.Length;
                                builder.Append(tokens[1]);
                            }
                            else
                            {
                                builder.Append(tokens[0]);
                            }

                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_KEY, offset, builder.Length - offset);

                            builder.Append("=\"");

                            offset = builder.Length;
                            builder.Append(reader.Value);
                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_VALUE, offset, builder.Length - offset);

                            builder.Append("\"");
                        }

                        offset = builder.Length;

                        if (empty)
                        {
                            builder.Append("/");
                        }
                        else
                        {
                            indent += 4;
                        }

                        builder.Append(">");
                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_CLOSING, offset, builder.Length - offset);

                        builder.Append("\n");

                        break;
                    case XmlNodeType.EndElement:
                        indent -= 4;

                        builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");

                        offset = builder.Length;
                        builder.Append("</");
                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_OPENING, offset, builder.Length - offset);

                        offset = builder.Length;
                        tokens = reader.Name.Split(nsSepChars, 2);
                        if (tokens.Length > 1)
                        {
                            builder.Append(tokens[0]);
                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_NAME, offset, builder.Length - offset);

                            offset = builder.Length;
                            builder.Append(":");
                            if (highlighter != null)
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);

                            offset = builder.Length;
                            builder.Append(tokens[1]);
                        }
                        else
                        {
                            builder.Append(tokens[0]);
                        }

                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAME, offset, builder.Length - offset);

                        offset = builder.Length;
                        builder.Append(">");
                        if (highlighter != null)
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_CLOSING, offset, builder.Length - offset);

                        builder.Append("\n");
                        break;
                    case XmlNodeType.Text:
                        builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");
                        builder.Append(reader.Value);
                        builder.Append("\n");
                        break;
                }
            }

            prettyXml = builder.ToString().TrimEnd(new char[] { '\n' });
        }
Ejemplo n.º 4
0
Archivo: XML.cs Proyecto: wyrover/ospy
        public static void PrettyPrint(string xmlData, out string prettyXml, XmlHighlighter highlighter)
        {
            StringReader  stringReader = new StringReader(xmlData);
            XmlTextReader reader       = new XmlTextReader(stringReader);
            StringBuilder builder      = new StringBuilder(xmlData.Length);

            string[] tokens;
            char[]   nsSepChars = new char[] { ':' };

            int indent = 0;

            while (reader.Read())
            {
                int offset;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");

                    offset = builder.Length;
                    builder.Append("<");
                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_OPENING, offset, builder.Length - offset);
                    }

                    offset = builder.Length;
                    tokens = reader.Name.Split(nsSepChars, 2);
                    if (tokens.Length > 1)
                    {
                        builder.Append(tokens[0]);
                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_NAME, offset, builder.Length - offset);
                        }

                        offset = builder.Length;
                        builder.Append(":");
                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);
                        }

                        offset = builder.Length;
                        builder.Append(tokens[1]);
                    }
                    else
                    {
                        builder.Append(tokens[0]);
                    }

                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_NAME, offset, builder.Length - offset);
                    }

                    bool empty;
                    empty = reader.IsEmptyElement;

                    for (int i = 0; i < reader.AttributeCount; i++)
                    {
                        reader.MoveToAttribute(i);

                        builder.Append(" ");

                        offset = builder.Length;

                        offset = builder.Length;
                        tokens = reader.Name.Split(nsSepChars, 2);
                        if (tokens.Length > 1)
                        {
                            builder.Append(tokens[0]);
                            if (highlighter != null)
                            {
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_KEY, offset, builder.Length - offset);
                            }

                            offset = builder.Length;
                            builder.Append(":");
                            if (highlighter != null)
                            {
                                highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);
                            }

                            offset = builder.Length;
                            builder.Append(tokens[1]);
                        }
                        else
                        {
                            builder.Append(tokens[0]);
                        }

                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_KEY, offset, builder.Length - offset);
                        }

                        builder.Append("=\"");

                        offset = builder.Length;
                        builder.Append(reader.Value);
                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_ATTRIBUTE_VALUE, offset, builder.Length - offset);
                        }

                        builder.Append("\"");
                    }

                    offset = builder.Length;

                    if (empty)
                    {
                        builder.Append("/");
                    }
                    else
                    {
                        indent += 4;
                    }

                    builder.Append(">");
                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_CLOSING, offset, builder.Length - offset);
                    }

                    builder.Append("\n");

                    break;

                case XmlNodeType.EndElement:
                    indent -= 4;

                    builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");

                    offset = builder.Length;
                    builder.Append("</");
                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_OPENING, offset, builder.Length - offset);
                    }

                    offset = builder.Length;
                    tokens = reader.Name.Split(nsSepChars, 2);
                    if (tokens.Length > 1)
                    {
                        builder.Append(tokens[0]);
                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_NAME, offset, builder.Length - offset);
                        }

                        offset = builder.Length;
                        builder.Append(":");
                        if (highlighter != null)
                        {
                            highlighter.AddToken(XmlHighlightContext.ELEMENT_NAMESPACE_SEPARATOR, offset, 1);
                        }

                        offset = builder.Length;
                        builder.Append(tokens[1]);
                    }
                    else
                    {
                        builder.Append(tokens[0]);
                    }

                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_NAME, offset, builder.Length - offset);
                    }

                    offset = builder.Length;
                    builder.Append(">");
                    if (highlighter != null)
                    {
                        highlighter.AddToken(XmlHighlightContext.ELEMENT_CLOSING, offset, builder.Length - offset);
                    }

                    builder.Append("\n");
                    break;

                case XmlNodeType.Text:
                    builder.AppendFormat("{0,-" + Convert.ToString(indent) + "}", "");
                    builder.Append(reader.Value);
                    builder.Append("\n");
                    break;
                }
            }

            prettyXml = builder.ToString().TrimEnd(new char[] { '\n' });
        }
Ejemplo n.º 5
0
        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;
        }