示例#1
0
文件: MainForm.cs 项目: SayHalou/ospy
        private void messageTbl_RowChanged(object sender, DataRowChangeEventArgs e)
        {
            if (e.Action == DataRowAction.Add)
            {
                e.Row.BeginEdit();

                e.Row["Sender"] = String.Format("{0} [pid={1}, tid={2}]",
                                                e.Row["ProcessName"],
                                                e.Row["ProcessId"],
                                                e.Row["ThreadId"]);

                int index = (int) e.Row["Index"];
                DateTime timestamp = (DateTime) e.Row["Timestamp"];

                UInt32 resourceId = (UInt32) e.Row["ResourceId"];
                PacketDirection direction = (PacketDirection)((UInt32)e.Row["Direction"]);

                byte[] data = (byte[]) e.Row["Data"];
                string suffix = (data.Length > 1) ? "s" : "";

                IPEndpoint localEndpoint = new IPEndpoint((string) e.Row["LocalAddress"],
                                                          (UInt16) e.Row["LocalPort"]);
                IPEndpoint remoteEndpoint = new IPEndpoint((string)e.Row["PeerAddress"],
                                                           (UInt16)e.Row["PeerPort"]);

                if ((MessageType) ((UInt32) e.Row["MsgType"]) == MessageType.MESSAGE_TYPE_MESSAGE)
                {
                    MessageContext context = (MessageContext) ((UInt32) e.Row["MsgContext"]);
                    string s = "";

                    switch (context)
                    {
                        case MessageContext.MESSAGE_CTX_ACTIVESYNC_DEVICE:
                            s = "DeviceLabel = ";
                            break;
                        case MessageContext.MESSAGE_CTX_ACTIVESYNC_STATUS:
                            s = "StatusLabel = ";
                            break;
                        case MessageContext.MESSAGE_CTX_ACTIVESYNC_SUBSTATUS:
                            s = "SubStatusLabel = ";
                            break;
                        case MessageContext.MESSAGE_CTX_ACTIVESYNC_WZ_STATUS:
                            s = "WizardStatusLabel = ";
                            break;
                        case MessageContext.MESSAGE_CTX_SOCKET_CONNECTING:
                        case MessageContext.MESSAGE_CTX_SOCKET_CONNECTED:
                        case MessageContext.MESSAGE_CTX_SOCKET_DISCONNECTED:
                        case MessageContext.MESSAGE_CTX_SOCKET_RESET:
                        case MessageContext.MESSAGE_CTX_SOCKET_LISTENING:
                            SocketEventType evType;

                            switch (context)
                            {
                                case MessageContext.MESSAGE_CTX_SOCKET_CONNECTING:
                                    evType = SocketEventType.CONNECTING;
                                    break;
                                case MessageContext.MESSAGE_CTX_SOCKET_CONNECTED:
                                    if (direction == PacketDirection.PACKET_DIRECTION_INCOMING)
                                        evType = SocketEventType.CONNECTED_INBOUND;
                                    else
                                        evType = SocketEventType.CONNECTED_OUTBOUND;
                                    break;
                                case MessageContext.MESSAGE_CTX_SOCKET_DISCONNECTED:
                                    evType = SocketEventType.DISCONNECTED;
                                    break;
                                case MessageContext.MESSAGE_CTX_SOCKET_RESET:
                                    evType = SocketEventType.RESET;
                                    break;
                                case MessageContext.MESSAGE_CTX_SOCKET_LISTENING:
                                    evType = SocketEventType.LISTENING;
                                    break;
                                default:
                                    evType = SocketEventType.UNKNOWN;
                                    break;
                            }

                            TCPEvent ev = new TCPEvent(timestamp, resourceId, evType, localEndpoint, remoteEndpoint);
                            tmpEventList.Add(ev);

                            break;
                    }

                    if (s != "")
                        e.Row["Description"] = String.Format("{0}\"{1}\"", s, e.Row["Message"]);
                    else
                        e.Row["Description"] = e.Row["Message"];
                }
                else
                {
                    string msgPrefix = "";
                    if (localEndpoint.Address.Length > 0)
                    {
                        msgPrefix = String.Format("{0}: ", localEndpoint);
                    }

                    string msgSuffix = "";
                    if (remoteEndpoint.Address.Length > 0)
                    {
                        msgSuffix = String.Format(" {0} {1}",
                            (direction == PacketDirection.PACKET_DIRECTION_INCOMING) ? "from" : "to",
                            remoteEndpoint);
                    }

                    if (msgPrefix.Length > 0 && msgSuffix.Length > 0)
                    {
                        if (direction == PacketDirection.PACKET_DIRECTION_INCOMING)
                        {
                            e.Row["Description"] = String.Format("{0}Received {1} byte{2}{3}",
                                                                 msgPrefix, data.Length, suffix, msgSuffix);
                        }
                        else
                        {
                            e.Row["Description"] = String.Format("{0}Sent {1} byte{2}{3}",
                                                                 msgPrefix, data.Length, suffix, msgSuffix);
                        }
                    }
                    else
                    {
                        e.Row["Description"] = e.Row["Message"];
                    }

                    IPPacket pkt = new IPPacket(index, timestamp, resourceId, direction, localEndpoint, remoteEndpoint, data);
                    tmpPacketList.Add(pkt);
                }

                e.Row["BgColor"] = GetColorForASState(e.Row);

                e.Row.EndEdit();
            }
        }
示例#2
0
文件: TCPEvent.cs 项目: wyrover/ospy
        public int CompareTo(Object obj)
        {
            TCPEvent otherEvent = obj as TCPEvent;

            return(timestamp.CompareTo(otherEvent.timestamp));
        }
示例#3
0
 public void AddEvent(TCPEvent ev)
 {
     events.Add(ev);
 }
示例#4
0
        public static IPSession[] ExtractAllFrom(IPPacket[] packets, TCPEvent[] events, IProgressFeedback progress)
        {
            //
            // Find sessions
            //
            progress.ProgressUpdate("Identifying sessions", 0);

            Dictionary<UInt32, IPSession> sessionById = new Dictionary<UInt32, IPSession>();
            List<UInt32> sessionIds = new List<UInt32>();

            int i = 0;
            foreach (IPPacket p in packets)
            {
                UInt32 id = p.ResourceId;

                IPSession session;

                if (sessionById.ContainsKey(id))
                {
                    session = sessionById[id];
                }
                else
                {
                    session = new IPSession();
                    sessionById[id] = session;
                    sessionIds.Add(id);
                }

                session.AddPacket(p);
                i++;

                progress.ProgressUpdate("Identifying sessions",
                    (int) ((i / (float) packets.Length) * 100.0f));
            }

            //
            // Add the events to the appropriate sessions
            //

            // First off, sort them by timestamp
            Array.Sort(events);

            // Then match them with the sessions
            foreach (TCPEvent ev in events)
            {
                if (sessionById.ContainsKey(ev.ResourceId))
                    sessionById[ev.ResourceId].AddEvent(ev);
            }

            //
            // Build an ordered list of sessions
            //
            List<IPSession> result = new List<IPSession>();
            foreach (UInt32 id in sessionIds)
                result.Add(sessionById[id]);

            return result.ToArray();
        }