Ejemplo n.º 1
0
        private void ZipReader(IReader reader, DataSource dataSource)
        {
            //try
            {
                while (reader.MoveToNextEntry())
                {
                    if (!reader.Entry.IsDirectory)
                    {
                        if (reader.Entry.Key != dataSource.ArchiveKey)
                        {
                            continue;
                        }
                        var memstream = new MemoryStream();
                        using (var entryStream = reader.OpenEntryStream())
                        {
                            entryStream.CopyTo(memstream);
                            memstream.Position = 0;
                        }

                        if (dataSource.ArchiveSourceType == SourceType.PCAP)
                        {
                            pcapReader.ReadStream(memstream);
                        }

                        if (dataSource.ArchiveSourceType == SourceType.PCAPNG)
                        {
                            pcapngReader.ReadStream(memstream);
                        }
                    }
                }
            }
            //catch(Exception e)
            {
            }
        }
Ejemplo n.º 2
0
        private void PeekReader(IReader reader, FileInfo finfo)
        {
            //try
            {
                while (reader.MoveToNextEntry())
                {
                    if (!reader.Entry.IsDirectory)
                    {
                        var readbytes = new byte[4];
                        using (var entryStream = reader.OpenEntryStream())
                        {
                            entryStream.Read(readbytes, 0, 4);

                            var dsource = new DataSource
                            {
                                FileInfo   = finfo,
                                SourceType = SourceType.Zip,
                                ArchiveKey = reader.Entry.Key
                            };


                            if (IsPCAP(readbytes))
                            {
                                var memstream = MemStream(readbytes, entryStream);

                                var pcapreader      = new PCAPReader();
                                var fileReadObjects = pcapreader.ReadStream(memstream);
                                var first           = (PCAPBlock)fileReadObjects.First().ReadObject;
                                var last            = (PCAPBlock)fileReadObjects.Last().ReadObject;
                                dsource.StartTime         = first.DateTime;
                                dsource.EndTime           = last.DateTime;
                                dsource.Packets           = fileReadObjects.Count();
                                dsource.ArchiveSourceType = SourceType.PCAP;
                                UpdateList(dsource);
                            }

                            if (IsPCAPNG(readbytes))
                            {
                                var memstream = MemStream(readbytes, entryStream);

                                var pcapngreader    = new PCAPNGReader();
                                var fileReadObjects = pcapngreader.ReadStream(memstream);
                                var first           = (PCAPNGBlock)fileReadObjects.First().ReadObject;
                                var last            = (PCAPNGBlock)fileReadObjects.Last().ReadObject;
                                dsource.StartTime         = first.Timestamp;
                                dsource.EndTime           = last.Timestamp;
                                dsource.Packets           = fileReadObjects.Count();
                                dsource.ArchiveSourceType = SourceType.PCAPNG;
                                UpdateList(dsource);
                            }
                        }
                    }
                }
            }
            //catch(Exception e)
            {
            }
        }