private void dgPackets_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Lấy thông tin của gói tin đang được chọn trong DataGrid hiển thị chi tiết buffer
            PacketInfo packetInfo = (PacketInfo)dgPackets.SelectedItem;

            if (packetInfo != null)
            {
                tbxBuffer.Text = packetInfo.Buffer.Buffer;
                tbxDecode.Text = packetInfo.Buffer.Content;
                UpdateLayers(packetInfo.Layers);
            }
        }
Beispiel #2
0
        void wincap_OnReceivePacket(object sender, PacketHeader p, byte[] s)
        {
            if (p.Caplength >= p.Length)  // no point in trying to handle incomplete packets
            {
                PacketInfo data = new PacketInfo();

                data.Data       = s;
                data.TimeStamp  = p.TimeStamp;
                data.Length     = (uint)s.Length;
                data.StartIndex = 14;

                nrOfCapturedPackets++;

                if (DataReceived != null)
                {
                    DataReceived(data);
                }
            }
        }
Beispiel #3
0
        protected virtual void ThreadFunction()
        {
            running = true;

            try
            {
                while (running && file.Position < file.Length)
                {
                    uint        packetRecordLength = 0;
                    PACKET_ITEM PItem = new PACKET_ITEM();
                    switch (FileFormat)
                    {
                    case Format.WINPCAP:
                        PItem.Seconds       = Function.Get4BytesFromStream(file, Const.VALUE);
                        PItem.MicroSeconds  = Function.Get4BytesFromStream(file, Const.VALUE);
                        PItem.CaptureLength = Function.Get4BytesFromStream(file, Const.VALUE);
                        PItem.PacketLength  = Function.Get4BytesFromStream(file, Const.VALUE);
                        break;

                    case Format.XCP001:
                        ulong timestamp = Function.Get4BytesFromStream(file, Const.VALUE);

                        PItem.Seconds = (uint)(timestamp / 1000000000);
                        uint millseconds = (uint)((timestamp / 1000000) % 1000);
                        uint counter     = (uint)(timestamp % 1000);
                        PItem.MicroSeconds = millseconds * 1000 + counter;
                        file.Position     += 6;

                        PItem.CaptureLength = Function.Get2BytesFromStream(file, Const.VALUE);
                        PItem.PacketLength  = PItem.CaptureLength;
                        file.Position      += 16;
                        break;

                    case Format.XCP002:
                        ulong temp2 = Function.Get8BytesFromStream(file, Const.VALUE);
                        PItem.Seconds       = (uint)(temp2 / 1000000);
                        PItem.MicroSeconds  = (uint)(temp2 % 1000000);
                        PItem.CaptureLength = Function.Get2BytesFromStream(file, Const.VALUE);
                        PItem.PacketLength  = Function.Get2BytesFromStream(file, Const.VALUE);
                        file.Position      += 28;
                        break;

                    case Format.SUNSNOOP:
                        PItem.CaptureLength = Function.Get4BytesFromStream(file, Const.NORMAL);
                        PItem.PacketLength  = Function.Get4BytesFromStream(file, Const.NORMAL);
                        packetRecordLength  = Function.Get4BytesFromStream(file, Const.NORMAL);
                        uint  droppedPackets = Function.Get4BytesFromStream(file, Const.NORMAL);
                        ulong temp3          = Function.Get8BytesFromStream(file, Const.NORMAL);
                        PItem.Seconds      = (uint)(temp3 / 1000000);
                        PItem.MicroSeconds = (uint)(temp3 % 1000000);
                        break;
                    }

                    PacketInfo data = new PacketInfo();
                    data.Data = new byte[PItem.CaptureLength];

                    data.StartIndex = 14;  // skip MAC (6 bytes) x 2 + packet type (2 bytes)

                    file.Read(data.Data, 0, (int)PItem.CaptureLength);
                    data.TimeStamp = BaseTime + new TimeSpan((long)PItem.Seconds * 10000000 + (long)PItem.MicroSeconds * 10);
                    data.Length    = PItem.CaptureLength;

                    if (FileFormat == Format.SUNSNOOP)
                    {
                        file.Position += (packetRecordLength - PItem.CaptureLength - 24);
                    }

                    // Increases the progress bar's value based on the size of
                    // the file currently being read.
                    snifferObj.Invoke(snifferObj.IncrementStepInProgressHandler, new object[] { (int)data.Length });

                    OnDataReceived(data);
                }

                //Close the file after reading file
                file.Close();
            }
            catch (Exception e)
            {
                ErrorHandler(e.Message + "\r\n" + e.TargetSite + "\r\n" + e.StackTrace);
            }
            finally
            {
                bool stopped = tcp.TCPStopAnalyse();
                if (stopped)
                {
                    snifferObj.Invoke(snifferObj.UpdateUIControlsHandler);
                }
            }
        }
Beispiel #4
0
 protected void OnDataReceived(PacketInfo data)
 {
     DataReceived(data);
 }
 /// <summary>
 /// Cập nhật datagrid mỗi khi bắt được một gói tin, hàm này được gọi bởi một lớp bên ngoài nên phải dùng Dispatcher.Invoke
 /// </summary>
 /// <param name="packet"></param>
 private void UpdateDataGrid(PacketInfo packet)
 {
     Dispatcher.Invoke(() => dgPackets.Items.Add(packet));             // bắt được gói tin thì cập nhật vào list
     UpdateOthers();
 }