I am trying to specify a new package format using scapy . The package has a list of elements, and the elements consist of "grouped fields". By "grouped fields" I mean a subsequence of fields of different types. The only way to create “grouped fields” that I know of in scapy is to use the Packet class and use FieldLenField / PacketListField to refer to the length of the sequence and the type of list members. Is that the way? Something like this:
from scapy.packet import Packet from scapy.fields import * class RepeatingGroupedSequence(Packet): name = "Simple group of two fields" fields_desc = [IntField('field1', 1), IntField('field2', 2)] class TopLayer(Packet): name = "Storage for Repeating Sequence" fields_desc = [FieldLenField("length", None, count_of='rep_seq'), PacketListField('rep_seq', None, RepeatingGroupedSequence, count_from = lambda pkt: pkt.length), ]
The problem with this approach is that the grouping structure is not preserved when the package is built. During assembly, the second instance of the RepeatedSequence treated as an unhandled body, even if the count field is 2. How do you add RepeatingSequences so that the structure is preserved during reassembly? Is there a way to group fields without using Packet as a storage type for lists?
source share