private byte[] Filter_PacketReceived(byte[] buffer, CapturedPacketArgs args) { NetPacketParser.EthernetPacket packet = new NetPacketParser.EthernetPacket(buffer); var netPacketViewModel = new NetPacketViewModel(packet, _packetIndex++); Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { NetPacketViewModels.Add(netPacketViewModel); }).AsTask(); return(null); }
private byte[] Filter_PacketReceived(byte[] buffer, CapturedPacketArgs args) { NetPacketViewModel netPacketViewModel = new(); for (int i = 0; i < buffer.Length; ++i) { netPacketViewModel.Content += NetPacketViewModel.HexTable[buffer[i]]; } this.Dispatcher.Invoke(() => { NetPacketViewModels.Add(netPacketViewModel); }, DispatcherPriority.Render); return(null); }
private byte[] Filter_PacketReceived(byte[] buffer, CapturedPacketArgs args) { NetPacketViewModel netPacketViewModel = new NetPacketViewModel(); for (int i = 0; i < buffer.Length; ++i) { netPacketViewModel.Content += buffer[i].ToString("X4") + " "; } NetPacketViewModels.Add(netPacketViewModel); byte[] modifiedBuffer = null; switch (args.Layer) { case FilteringLayer.NetworkLayer: IPAddress address; { switch (args.Direction) { case NetPacketDirection.Out: address = IPAddress.Parse("192.168.1.104"); address.GetAddressBytes().CopyTo(buffer, 16); modifiedBuffer = buffer; break; case NetPacketDirection.In: address = IPAddress.Parse("22.22.22.22"); address.GetAddressBytes().CopyTo(buffer, 12); buffer[10] = 0; buffer[11] = 0; var checkSumCalculateBytes = (buffer[0] & 0xf) * 4; var checkSum = CalculateChecksum(buffer, checkSumCalculateBytes); buffer[10] = (byte)((checkSum & 0xff00) >> 8); buffer[11] = (byte)(checkSum & 0xff); modifiedBuffer = buffer; break; } } break; } return(modifiedBuffer); }
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; }