private void TXLoop()
        {
            uint slen = 0;

            while (true)
            {
                var txPacket = txBuffer.Take();
                if (!WinDivertMethods.WinDivertSend(handle, txPacket.Data, (uint)txPacket.Data.Length, ref txPacket.Addr, ref slen))
                {
                    continue;
                    Console.WriteLine("Send Failed");
                    Console.WriteLine(BitConverter.ToString(txPacket.Data).Replace("-", ""));
                }
            }
        }
Example #2
0
        private void Steg()
        {
            try
            {
                _stegPacket = true;
                int breakCount = 1;
                _stegPacketCount = 1;
                _stegTokenSource.Token.ThrowIfCancellationRequested();

                OnMessage(Resources.StegonographyInitializeMessage);
                unsafe
                {
                    _stegHandler = WinDivertMethods.WinDivertOpen(string.Format(Resources.Template_DestinationFilter, _port),
                                                                  WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0);

                    while (_stegPacketCount > 0)
                    {
                        byte[]             pack       = new byte[MaxBuff];
                        WINDIVERT_ADDRESS  addr       = new WINDIVERT_ADDRESS();
                        WINDIVERT_TCPHDR **packHeader = default(WINDIVERT_TCPHDR * *);
                        uint packetLen = 0;

                        if (
                            !WinDivertMethods.WinDivertRecv(_stegHandler, pack, (uint)pack.Length, ref addr,
                                                            ref packetLen))
                        {
                            continue;
                        }


                        WinDivertMethods.WinDivertHelperParsePacket(pack, packetLen, null, null, null, null, packHeader,
                                                                    null, null, null);


                        if (breakCount > 0)
                        {
                            OnMessage(Resources.SendLegalDataMessage);
                        }
                        else
                        {
                            OnMessage(Resources.StegonographyAddedMessage);
                            for (int i = 0; i < _stegWord.Length; i++)
                            {
                                pack[41 + i] = Convert.ToByte(_stegWord[i]);
                            }
                        }

                        if (!WinDivertMethods.WinDivertSend(_stegHandler, pack, packetLen, ref addr, IntPtr.Zero))
                        {
                            OnMessage(Resources.SendPacketError);
                        }
                        else
                        {
                            if (breakCount == 0)
                            {
                                _stegPacketCount--;
                            }
                            else
                            {
                                breakCount--;
                            }
                        }
                    }
                    WinDivertMethods.WinDivertClose(_stegHandler);
                }
                _stegPacket = false;
            }
            catch (Exception exp)
            {
                Console.WriteLine(Resources.ExceptionMessage, exp.Message);
            }
        }