Skip to content
Extraits de code Groupes Projets
Valider 470023d5 rédigé par François De Keersmaeker's avatar François De Keersmaeker
Parcourir les fichiers

Rebuild each packet to fix timestamp bug

parent e3a6249e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -171,6 +171,13 @@ class Packet:
return len(self.packet.getlayer(layer))
def rebuild(self) -> None:
"""
Rebuild packet.
"""
self.packet = self.packet.__class__(bytes(self.packet))
def update_checksums(self) -> None:
"""
Update packet checksums, if needed.
......@@ -184,7 +191,7 @@ class Packet:
transport_layer.delfieldval("len")
if hasattr(transport_layer, "chksum"):
transport_layer.delfieldval("chksum")
self.packet = self.packet.__class__(bytes(self.packet))
self.rebuild()
def get_dict_log(self, field: str, old_value: str, new_value: str) -> dict:
......
......@@ -45,6 +45,16 @@ def must_edit_packet(i: int, packet_numbers: list, random_range: int) -> bool:
return is_specified or is_random
def rebuild_packet(packet: scapy.Packet) -> scapy.Packet:
"""
Rebuild a Scapy packet from its bytes representation.
:param packet: Scapy packet
:return: Rebuilt Scapy packet
"""
return packet.__class__(bytes(packet))
def tweak_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
"""
Main functionality of the program:
......@@ -90,7 +100,7 @@ def tweak_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers:
my_packet = Packet.init_packet(packet, i)
except ValueError:
# No supported protocol found in packet, skip it
new_packets.append(packet)
new_packets.append(rebuild_packet(packet))
pass
else:
d = my_packet.tweak()
......@@ -103,7 +113,7 @@ def tweak_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers:
# Packet won't be edited
# Go to next packet
i += 1
new_packets.append(packet)
new_packets.append(rebuild_packet(packet))
# Write output PCAP file
output_pcap = ""
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter