Ejemplo n.º 1
0
Archivo: MSN.cs Proyecto: SayHalou/ospy
        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();
        }
Ejemplo n.º 2
0
        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());
        }