/// <summary> /// Takes one TCP packet as a byte array, filters it based on source/destination ports, and stores it for stream reassembly. /// </summary> /// <param name="buffer"></param> public unsafe void FilterAndStoreData(byte[] buffer) { // There is one TCP packet per buffer. if (buffer?.Length < sizeof(TCPHeader)) { Trace.WriteLine("TCPDecoder: Buffer length smaller than TCP header: Length=[" + (buffer?.Length ?? 0).ToString() + "].", "DEBUG-MACHINA"); return; } fixed(byte *ptr = buffer) { TCPHeader header = *(TCPHeader *)(ptr); if (_sourcePort != header.source_port || _destinationPort != header.destination_port) { return; } // if there is no data, we can discard the packet - this will likely be an ACK, but it shouldnt affect stream processing. if (buffer.Length - header.DataOffset == 0) { if ((header.flags & (byte)TCPFlags.SYN) == 0) { return; } } //TEMP debugging //Trace.WriteLine("TCPDecoder: TCP Sequence # " + header.SequenceNumber.ToString() + " received with " + (buffer.Length - header.DataOffset).ToString() + " bytes."); Packets.Add(buffer); } }
private void ParseBits() { var parser = new Parser(_bits); Packets.Add(parser.ParsedPacket); Ignored = _bits[parser.Consumed..];
/// <summary> /// Store a captured CAN packet /// </summary> /// <param name="TimeInMicroseconds">Time registered by PEAK device</param> /// <param name="CANId">Id of the packet</param> /// <param name="DataLength">Length of data</param> /// <param name="Data">Captured data</param> /// <returns>Reference to the packet</returns> Packet UpdatePackets(ulong TimeInMicroseconds, uint CANId, byte DataLength, byte[] Data) { Packet packet; if (overwriteLastPacket) { //Update packet list by overwriting last value packet = Packets.Find(x => x.Id == CANId); if (packet == null) { packet = new Packet(); Packets.Add(packet); } } else { //store as new values packet = new Packet(); Packets.Add(packet); } //add/update values packet.Microseconds = TimeInMicroseconds; packet.Id = CANId; packet.Length = DataLength; packet.Data = Data; //remember first packet for diff calc if (DiffPacket == null) { AddMessage(Feedback, "First packet received " + PacketToString(packet)); DiffPacket = Packet.Clone(packet); } return(packet); }
/// <summary> /// For designer only /// </summary> public SimpleTextCaptureViewModel() { RefreshCommand = new RelayCommand(Refresh); Packets.Add(new PacketViewModel(new byte[] { 1, 2, 3, 4, 5 })); Packets.Add(new PacketViewModel(new byte[] { 1, 2, 3, 4, 5 })); }
public void AddToPackets(PacketType type, byte[] data) { var packet = new Packet(type, data); Application.Current.Dispatcher.Invoke(delegate { Packets.Add(packet); }); var filterType = (PacketType)(SelectedPacketTypeIndex - 1); if (filterType == type || SelectedPacketTypeIndex == 0) { if (_filterOpCode > 0) { if (_filterOpCode == packet.OpCode) { Application.Current.Dispatcher.Invoke(delegate { FilteredPackets.Add(packet); }); } } else { Application.Current.Dispatcher.Invoke(delegate { FilteredPackets.Add(packet); }); } } }
public static void EnqueuePacket(Packet p) { lock (_Locker) { Packets.Add(p); } }
public void AddPacket(TelemetryPacket packet) { lock (syncLock) { Packets.Add(packet); //while (_packets.Any() && _packets.First().Distance < 0) // _packets.Remove(_packets.First()); } }
public void AddPacket(IOSCPacket packet) { if (packet == null) { throw new NullReferenceException(nameof(packet)); } Packets.Add(packet); }
public void PushPacket(Packet stream) { if (stream.peer != null) { lock (Packets) { Packets.Add(stream); } } }
private void Refresh() { //var output = new StringBuilder(); Packets.Clear(); //Create the reader using (var captureReader = new CaptureFileReader(_captureFilePath)) { var sample = captureReader.Read(); //Keep track of the last sample so we now how far apart they are Sample lastSample = null; var buffer = new List <byte>(); var captureTimerInfo = new CaptureTimerInfo(captureReader.StartTime, captureReader.TicksPerSecond); while (sample != null) { if (lastSample != null) { //Get the elapsed Ms var elapsedMs = captureTimerInfo.TicksToMilliseconds(sample.Ticks - lastSample.Ticks); if (elapsedMs >= _packetThreshold) { Packets.Add(new PacketViewModel(buffer.ToArray())); buffer.Clear(); } } //Add an item to the buffer buffer.Add(sample.Value); //Save this sample for next time lastSample = sample; //Get the next sample sample = captureReader.Read(); //See if we have any last bits... (might take this out) if (sample == null && buffer.Any()) { Packets.Add(new PacketViewModel(buffer.ToArray())); buffer.Clear(); } } } }
public MessageListResponse(Span <byte> data) { const int recordSize = 8; for (int i = 0; i <= data.Length - recordSize; i += recordSize) { Packets.Add(new PacketInfo { recordType = (PacketTypes)data[i], stationID = data[i + 1], timestamp = DateTimeOffset.FromUnixTimeSeconds(BitConverter.ToUInt32(data.Slice(i + 2))), address = BitConverter.ToUInt16(data.Slice(i + 6)) }); } }
private void PrinterControllerService_ReceivedData( object sender, PrinterControllerReceivedDataEventArgs e) { TerminalListBox.Dispatcher.Invoke(() => { Packets.Add(e.Packet); if (VisualTreeHelper.GetChildrenCount(TerminalListBox) > 0) { Border border = (Border)VisualTreeHelper.GetChild(TerminalListBox, 0); ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); scrollViewer.ScrollToBottom(); } }); }
public void Send(Packet packet) { var pType = packet.GetType(); if (NotifiedTypes.Add(pType)) { Packets.Add(new TypeRegistrationPacket() { FullTypeName = pType.AssemblyQualifiedName }); } Registry.Register(pType); Packets.Add(packet); }
public void ParseAllPackets() { try { while (HexDigits.Peek() != -1) { Packet p = ParsePaket(); Packets.Add(p); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Adds packet to list. /// </summary> /// <param name="packet">Packet to add.</param> public void AddPacket(UltimaPacket packet) { try { Count++; Packets.Add(packet); if (OnPacket != null) { OnPacket(packet); } } catch (Exception ex) { App.Window.ShowNotification(NotificationType.Error, ex); } }
private static void RegisterPackets() { Type mpPacketType = typeof(MPPacket); IEnumerable <Type> mpPacketTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(mpPacketType)); foreach (var type in mpPacketTypes) { MPPacket packet = (MPPacket)Activator.CreateInstance(type); int count = Packets.Count; Packets.Add(packet); if (count > byte.MaxValue) { throw new Exception($"Packet limit of {byte.MaxValue} reached!"); } byte id = (byte)count; ID[type] = id; } }
public FLVFile(Stream stream) { sourceStream = stream; Size = stream.Length; DataStream ds = new DataStream(stream); ds.BigEndian = true; ds.Unsecure = true; Header = new FLVHeader(ds); while (stream.Position < stream.Length) { BasePacket packet = PacketFactory.ReadPacket(ds); if (packet.PacketType == 0 && packet.PayloadSize == 0) { if (stream.Position < stream.Length) { Console.WriteLine("Zero data detected at {0}. Integrity is unrecoverable. Dropping the rest of stream ({1} bytes remains).", stream.Position, stream.Length - stream.Position); } break; } if (packet is MetadataPacket metadataPacket) { if (Metadata != null) { Console.WriteLine("Discarding duplicate metadata packet at: {0}", metadataPacket.Offset); continue; } Metadata = metadataPacket; } Packets.Add(packet); } }
public void BuildMessage(HeaderType messageType, byte[] lPayLoad) { var packet_size = 4096 - 8; Packets.Clear(); for (var lower = 0; lower < lPayLoad.Length; lower += packet_size) { var payloadSize = lPayLoad.Length - lower; if (payloadSize > packet_size) { payloadSize = packet_size; } // Create new TDS header var header = new TDSHeader(); header.Type = messageType; if (lPayLoad.Length - lower <= packet_size) { header.StatusBitMask = StatusBitMask.END_OF_MESSAGE; } else { header.StatusBitMask = StatusBitMask.NORMAL; } header.PayloadSize = payloadSize; var payload = new byte[payloadSize]; Array.Copy(lPayLoad, lower, payload, 0, payloadSize); // Create new TDS packet with new TDS header and payload var newPacket = new TDSPacket(header.Data, payload, payloadSize); // Add packet into message Packets.Add(newPacket); } }
public PESStream(MPEGTS.Packet pkt) { Continuity = pkt.Continuity; Packets.Add(pkt); }
public DeviceVm(Device device) { Device = device; Device.SnoopedPacket += (sender, packet) => Application.Current.Dispatcher.Invoke(() => Packets.Add(packet)); }
public TDSMessage(TDSPacket firtsPacket) { Packets.Add(firtsPacket); }
public Packet() { Packets.Add(this); }
public void AddHistory(Packet history) { Packets.Add(history); }
public Packet(string Name) { Packets.Add(this); name = Name; }