J'ai atteint la prochaine situation, j'ai besoin de définir une nouvelle couche de protocole dans Scapy et l'un des champs a une taille variable (1,2,3 ou 4 octets) qui dépend de la taille de l'autre couche spécifique. Telle est la situation:Scapy - Référencement de plusieurs champs d'un FieldLenField
class newLayer(Packet):
name = "newLayer fixed header"
fields_desc = [
ByteField("msgtype",0),
# Some other fields ...
FieldLenField("length", XXX), # length of newLayer_specific layer
# This field can be 1,2,3 or 4 bytes long depending
# on the length of the variable header
]
class newLayer_specific(Packet):
name = "variable header"
fields_desc = [
FieldLenField("length2","field1"), # This field is always 2 bytes long
StrLenField("field1","",length_from = lambda pkt:pkt.length2),
StrLenField("field2","", length_from = lambda pkt:pkt.underlayer.length - pkt.length - 2)
# 2 is because the length of the length2 field
bind_layers(newLayer, newLayer_specific, msgtype=1)
Je sais ne pas comment je peux faire référence à la taille de la couche newLayer_specific
du champ length
de la couche newLayer
Toute suggestion? Merci d'avance.
Beaucoup de grâce Pierre les deux solutions fonctionnent correctement, les connaissances génial! – somarhs