Beispiel #1
0
 public IPPacket(int index,
                 UInt32 resourceId,
                 PacketDirection direction,
                 IPEndpoint localEndpoint,
                 IPEndpoint remoteEndpoint,
                 byte[] bytes)
 {
     Initialize(index, DateTime.Now, resourceId, direction, localEndpoint, remoteEndpoint, bytes);
 }
Beispiel #2
0
 public TCPEvent(DateTime timestamp, UInt32 resourceId, SocketEventType type,
     IPEndpoint localEndpoint, IPEndpoint remoteEndpoint)
 {
     this.timestamp = timestamp;
     this.resourceId = resourceId;
     this.type = type;
     this.localEndpoint = localEndpoint;
     this.remoteEndpoint = remoteEndpoint;
 }
Beispiel #3
0
 private void Initialize(int index,
                         DateTime timestamp,
                         UInt32 resourceId,
                         PacketDirection direction,
                         IPEndpoint localEndpoint,
                         IPEndpoint remoteEndpoint,
                         byte[] bytes)
 {
     this.index          = index;
     this.timestamp      = timestamp;
     this.resourceId     = resourceId;
     this.direction      = direction;
     this.localEndpoint  = localEndpoint;
     this.remoteEndpoint = remoteEndpoint;
     this.bytes          = bytes;
 }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            PacketStream stream = new PacketStream();

            IPEndpoint localEndpoint = new IPEndpoint("169.254.2.2", 27516);
            IPEndpoint remoteEndpoint = new IPEndpoint("169.254.2.1", 1056);

            int n = 1;

            IPPacket p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                                      NewArrayIncremental(6, 10));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(3, 35));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(1, 60));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(1, 200));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(3, 210));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(1, 70));
            stream.AppendPacket(p);

            p = new IPPacket(n++, 1, PacketDirection.PACKET_DIRECTION_OUTGOING, localEndpoint, remoteEndpoint,
                             NewArrayIncremental(1, 80));
            stream.AppendPacket(p);

            Debug.Assert(stream.Position == 0, "Position != 0");
            Debug.Assert(stream.Length == 16, "Length != 16");

            byte[] buf = new byte[stream.Length];
            Debug.Assert(stream.Read(buf, 0, 16) == 16, "Read() != 16");
            byte[] expectedBytes = new byte[] { 10, 11, 12, 13, 14, 15,
                                                35, 36, 37,
                                                60,
                                                200,
                                                210, 211, 212,
                                                70,
                                                80 };

            Debug.Assert(CompareByteArrays(buf, expectedBytes), "Content after first read is not as expected");

            Debug.Assert(stream.Position == 16, "Position != 16");

            Debug.Assert(stream.Read(buf, 0, 10) == 0, "Read at offset 16 doesn't return 0");

            stream.Seek(-1, SeekOrigin.Current);
            Debug.Assert(stream.Read(buf, 2, 100) == 1, "Read at offset 15 doesn't return 1");

            Debug.Assert(buf[2] == 80, "Byte at offset 15 isn't 80");

            stream.Seek(-16, SeekOrigin.Current);
            Debug.Assert(stream.Position == 0, "Position != 0 after reverse seek");

            stream.Position = 9;
            Debug.Assert(stream.Read(buf, 1, 1) == 1, "Read at Position=9 didn't yield 1 byte");
            Debug.Assert(buf[1] == 60, "buf[1] != 60");

            stream.Position = 13;
            Debug.Assert(stream.Read(buf, 5, 4) == 3, "Read at Position=13 didn't yield 3 bytes");
            Debug.Assert(buf[5] == 212, "buf[5] != 212");
            Debug.Assert(buf[6] == 70, "buf[5] != 70");
            Debug.Assert(buf[7] == 80, "buf[5] != 80");

            System.Console.WriteLine("All tests passed");
            System.Console.ReadKey();
        }
Beispiel #6
0
 public VisualSession(IPSession session)
 {
     localEndpoint = session.LocalEndpoint;
     remoteEndpoint = session.RemoteEndpoint;
     transactions = new List<VisualTransaction>();
 }