Exemplo n.º 1
0
 public CapturedPacketArgs(ulong identifier, long packetSize, int fragmentCounts, int fragmentIndex, FilteringLayer layer, NetPacketDirection direction)
 {
     Identifier     = identifier;
     PacketSize     = packetSize;
     FragmentCounts = fragmentCounts;
     FragmentIndex  = fragmentIndex;
     Layer          = layer;
     Direction      = direction;
 }
Exemplo n.º 2
0
        private async void InqueueIOCTLForFurtherNotification()
        {
            var outputBuffer = new byte[2000];

            var  inputBuffer = _shadowRegisterContext.SeralizeAppIdToByteArray();
            uint ioctlResult = 0;

            while (_isQueueingContinue)
            {
                try
                {
                    ioctlResult = await _shadowDevice.SendIOControlAsync(IOCTLs.IOCTLShadowDriverQueueNotification, inputBuffer, outputBuffer);
                }
                catch (NullReferenceException)
                {
                    _isQueueingContinue = false;
                    //throw new ShadowFilterException(0xC0090040);
                }
                catch (Exception)
                {
                    _isQueueingContinue = false;
                    //System.Diagnostics.Debug.WriteLine(exception.Message);
                }

                uint status = BitConverter.ToUInt32(outputBuffer, 0);

                if (status != 0)
                {
                    _isQueueingContinue = false;
                    //if (status != 1)
                    //{
                    //    HandleError(status);
                    //}
                }


                int currentIndex = sizeof(int);
                var packetSize   = BitConverter.ToInt64(outputBuffer, currentIndex);

#if DEBUG
                System.Diagnostics.Debug.WriteLine("Packet received, size is {0}.", packetSize);
#endif
                if (packetSize > 0)
                {
                    currentIndex += sizeof(long);
                    var identifier = BitConverter.ToUInt64(outputBuffer, currentIndex);
                    currentIndex += sizeof(ulong);
                    packetSize   -= sizeof(ulong);
                    var totalFragCount = BitConverter.ToInt32(outputBuffer, currentIndex);
                    currentIndex += sizeof(int);
                    packetSize   -= sizeof(int);
                    var fragIndex = BitConverter.ToInt32(outputBuffer, currentIndex);
                    currentIndex += sizeof(int);
                    packetSize   -= sizeof(int);
                    var offsetLength = BitConverter.ToUInt32(outputBuffer, currentIndex);
                    currentIndex += sizeof(uint);
                    packetSize   -= sizeof(uint);
                    FilteringLayer layer = (FilteringLayer)BitConverter.ToInt32(outputBuffer, currentIndex);
                    currentIndex += sizeof(FilteringLayer);
                    packetSize   -= sizeof(FilteringLayer);
                    NetPacketDirection direction = (NetPacketDirection)BitConverter.ToInt32(outputBuffer, currentIndex);
                    currentIndex += sizeof(NetPacketDirection);
                    packetSize   -= sizeof(NetPacketDirection);
                    byte[] packetBuffer = new byte[packetSize];
                    Array.Copy(outputBuffer, currentIndex, packetBuffer, 0, packetSize);
                    CapturedPacketArgs args = new CapturedPacketArgs(identifier, packetSize, totalFragCount, fragIndex, layer, direction);
                    if (_isFilteringStarted)
                    {
                        byte[] newPacket = PacketReceived?.Invoke(packetBuffer, args);

                        if (newPacket != null)
                        {
                            // Modify packet
                            PacketInjectionArgs injectArgs = new PacketInjectionArgs
                            {
                                AddrFamily    = IpAddrFamily.IPv4,
                                Direction     = args.Direction,
                                FragmentIndex = args.FragmentIndex,
                                Identifier    = args.Identifier,
                                Layer         = args.Layer,
                            };

                            try
                            {
                                await InjectPacketAsync(newPacket, injectArgs);
                            }
                            catch (Exception)
                            {
                                System.Diagnostics.Debug.WriteLine("Dfsdf");
                            }
                        }
                    }
                }
            }
            return;
        }