Ejemplo n.º 1
0
        private static bool readNetworkHeaders(BinaryReader binaryReader)
        {
            EthernetHeader ethernetHeader = EthernetHeader.read(binaryReader);

            // Skip non-IP packets
            if (ethernetHeader.proto != 8)
            {
                throw new InvalidDataException();
            }

            IpHeader ipHeader = IpHeader.read(binaryReader);

            // Skip non-UDP packets
            if (ipHeader.proto != 17)
            {
                throw new InvalidDataException();
            }

            UdpHeader udpHeader = UdpHeader.read(binaryReader);

            bool isSend = (udpHeader.dPort >= 9000 && udpHeader.dPort <= 9013);
            bool isRecv = (udpHeader.sPort >= 9000 && udpHeader.sPort <= 9013);

            // Skip non-AC-port packets
            if (!isSend && !isRecv)
            {
                throw new InvalidDataException();
            }

            return(isSend);
        }
Ejemplo n.º 2
0
        private int readPacketRecordData(BinaryReader binaryReader, long len, uint tsSec, long curPacket, bool dontList)
        {
            // Begin reading headers
            long packetStartPos = binaryReader.BaseStream.Position;

            EthernetHeader ethernetHeader = EthernetHeader.read(binaryReader);

            // Skip non-IP packets
            if (ethernetHeader.proto != 8)
            {
                binaryReader.BaseStream.Position += len - (binaryReader.BaseStream.Position - packetStartPos);
                return(1);
            }

            IpHeader ipHeader = IpHeader.read(binaryReader);

            // Skip non-UDP packets
            if (ipHeader.proto != 17)
            {
                binaryReader.BaseStream.Position += len - (binaryReader.BaseStream.Position - packetStartPos);
                return(1);
            }

            UdpHeader udpHeader = UdpHeader.read(binaryReader);

            bool isSend = (udpHeader.dPort >= 9000 && udpHeader.dPort <= 9013);
            bool isRecv = (udpHeader.sPort >= 9000 && udpHeader.sPort <= 9013);

            // Skip non-AC-port packets
            if (!isSend && !isRecv)
            {
                binaryReader.BaseStream.Position += len - (binaryReader.BaseStream.Position - packetStartPos);
                return(1);
            }

            long headersSize = binaryReader.BaseStream.Position - packetStartPos;

            // Begin reading non-header packet content
            StringBuilder packetHeadersStr = new StringBuilder();
            StringBuilder packetTypeStr    = new StringBuilder();

            PacketRecord packet = new PacketRecord();

            packet.index     = records.Count;
            packet.isSend    = isSend;
            packet.tsSec     = tsSec;
            packet.netPacket = new NetPacket();
            packet.data      = binaryReader.ReadBytes((int)(len - headersSize));
            packet.extraInfo = "";
            BinaryReader packetReader = new BinaryReader(new MemoryStream(packet.data));

            try {
                ProtoHeader pHeader = ProtoHeader.read(packetReader);

                readOptionalHeaders(packet, pHeader.header_, packetHeadersStr, packetReader);

                if (packetReader.BaseStream.Position == packetReader.BaseStream.Length)
                {
                    packetTypeStr.Append("<Header Only>");
                }

                uint HAS_FRAGS_MASK = 0x4; // See SharedNet::SplitPacketData
                if ((pHeader.header_ & HAS_FRAGS_MASK) != 0)
                {
                    bool first = true;
                    while (packetReader.BaseStream.Position != packetReader.BaseStream.Length)
                    {
                        if (!first)
                        {
                            packetTypeStr.Append(" + ");
                        }
                        readPacket(packet, packetTypeStr, packetReader);
                        first = false;
                    }
                }

                if (packetReader.BaseStream.Position != packetReader.BaseStream.Length)
                {
                    packet.extraInfo = "Didnt read entire packet! " + packet.extraInfo;
                }
            } catch (OutOfMemoryException e) {
                //MessageBox.Show("Out of memory (packet " + curPacket + "), stopping read: " + e);
                return(2);
            } catch (Exception e) {
                packet.extraInfo += "EXCEPTION: " + e.Message + " " + e.StackTrace;
            }
            packet.packetHeadersStr = packetHeadersStr.ToString();
            packet.packetTypeStr    = packetTypeStr.ToString();

            records.Add(packet);

            if (!dontList)
            {
                ListViewItem newItem = new ListViewItem(packet.index.ToString());
                newItem.SubItems.Add(packet.isSend ? "Send" : "Recv");
                newItem.SubItems.Add(packet.tsSec.ToString());
                newItem.SubItems.Add(packet.packetHeadersStr);
                newItem.SubItems.Add(packet.packetTypeStr);
                newItem.SubItems.Add(packet.data.Length.ToString());
                newItem.SubItems.Add(packet.extraInfo);
                listItems.Add(newItem);
            }

            return(0);
        }