Ejemplo n.º 1
0
        private void loadPcapContent(BinaryReader binaryReader, bool dontList)
        {
            PcapHeader pcapHeader = PcapHeader.read(binaryReader);

            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
            {
                curPacket++;

                if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position < 16)
                {
                    //MessageBox.Show("Stream cut short (packet " + curPacket + "), stopping read: " + (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position));
                    break;
                }

                PcapRecordHeader recordHeader = PcapRecordHeader.read(binaryReader);

                if (recordHeader.inclLen > 50000)
                {
                    //MessageBox.Show("Enormous packet (packet " + curPacket + "), stopping read: " + recordHeader.inclLen);
                    break;
                }

                // Make sure there's enough room for an ethernet header
                if (recordHeader.inclLen < 14)
                {
                    binaryReader.BaseStream.Position += recordHeader.inclLen;
                    continue;
                }

                if (readPacketRecordData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, curPacket, dontList) == 2)
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private static List <PacketRecord> loadPcapContent(BinaryReader binaryReader, ref bool abort)
        {
            List <PacketRecord> results = new List <PacketRecord>();

            /*PcapHeader pcapHeader = */
            PcapHeader.read(binaryReader);

            int curPacket = 0;

            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
            {
                if (abort)
                {
                    break;
                }

                curPacket++;

                if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position < 16)
                {
                    //MessageBox.Show("Stream cut short (packet " + curPacket + "), stopping read: " + (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position));
                    break;
                }

                PcapRecordHeader recordHeader = PcapRecordHeader.read(binaryReader);

                if (recordHeader.inclLen > 50000)
                {
                    //MessageBox.Show("Enormous packet (packet " + curPacket + "), stopping read: " + recordHeader.inclLen);
                    break;
                }

                // Make sure there's enough room for an ethernet header
                if (recordHeader.inclLen < 14)
                {
                    binaryReader.BaseStream.Position += recordHeader.inclLen;
                    continue;
                }

                var packetRecord = readPacketRecordData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, curPacket);

                if (packetRecord == null)
                {
                    break;
                }

                results.Add(packetRecord);
            }

            return(results);
        }
Ejemplo n.º 3
0
        private static List <PacketRecord> loadPcapPacketRecords(BinaryReader binaryReader, bool asMessages, ref bool abort)
        {
            List <PacketRecord> results = new List <PacketRecord>();

            /*PcapHeader pcapHeader = */
            PcapHeader.read(binaryReader);

            int curPacket = 0;

            Dictionary <ulong, PacketRecord> incompletePacketMap = new Dictionary <ulong, PacketRecord>();

            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
            {
                if (abort)
                {
                    break;
                }

                PcapRecordHeader recordHeader;
                try
                {
                    recordHeader = readPcapRecordHeader(binaryReader, curPacket);

                    if (recordHeader == null)
                    {
                        continue;
                    }
                }
                catch (InvalidDataException e)
                {
                    break;
                }

                long packetStartPos = binaryReader.BaseStream.Position;

                try
                {
                    if (asMessages)
                    {
                        if (!readMessageData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, results, incompletePacketMap))
                        {
                            break;
                        }
                    }
                    else
                    {
                        var packetRecord = readPacketData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, curPacket);

                        if (packetRecord == null)
                        {
                            break;
                        }

                        results.Add(packetRecord);
                    }

                    curPacket++;
                }
                catch (Exception e)
                {
                    binaryReader.BaseStream.Position += recordHeader.inclLen - (binaryReader.BaseStream.Position - packetStartPos);
                }
            }

            return(results);
        }