|
@@ -17,18 +17,18 @@ from . import IPv4 as ip
|
|
|
'''PaddingGenerator
|
|
|
'''
|
|
|
|
|
|
-def add_padding(packet, bytes_padding = 0, user_padding=True, rnd = False):
|
|
|
+def add_padding(packet, bytes_padding:int = 0, user_padding:bool=True, rnd:bool = False):
|
|
|
'''
|
|
|
- Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes.
|
|
|
+ Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes, if called by the user.
|
|
|
:param packet: the packet that will be extended with the additional payload
|
|
|
- :param bytes_padding: the amount of bytes that will be appended to the packet
|
|
|
- :param user_padding: true, if the function add_padding is called from another class and the user
|
|
|
- sets the padding manually
|
|
|
- :param rnd: adds a random padding betwing 0 and bytes_adding, if true
|
|
|
+ :param bytes_padding: the amount of bytes that will be appended to the packet. Capped to 100,
|
|
|
+ if called by the user.
|
|
|
+ :param user_padding: true, if the function add_padding by the user and not within the code
|
|
|
+ :param rnd: adds a random padding between 0 and bytes_padding, if true
|
|
|
:return: the initial packet, extended with the wanted amount of bytes of padding
|
|
|
'''
|
|
|
|
|
|
- if(user_padding and bytes_padding > 100):
|
|
|
+ if(user_padding == True and bytes_padding > 100):
|
|
|
bytes_padding = 100
|
|
|
|
|
|
if (rnd is True):
|
|
@@ -38,13 +38,15 @@ def add_padding(packet, bytes_padding = 0, user_padding=True, rnd = False):
|
|
|
packet[Raw].load += Raw(load=payload).load
|
|
|
return packet
|
|
|
|
|
|
-def equal_length(list_of_packets, length = 0, padding = 0):
|
|
|
+def equal_length(list_of_packets:list, length:int = 0, padding:int = 0):
|
|
|
'''
|
|
|
- Equals the length of a given set of packets on the given length. If the given length is smaller than the largest
|
|
|
- packet, all the other packets are extended to the largest packet's length.
|
|
|
+ Equals the length of a given list of packets on the given length. If the given length is smaller than the largest
|
|
|
+ packet, all the other packets are extended to the largest packet's length. Add additional padding
|
|
|
+ afterwards to create realism.
|
|
|
:param list_of_packets: The given set of packet.
|
|
|
- :param length: The length each packet should have.
|
|
|
- :return: The set of extended packets.
|
|
|
+ :param length: The length each packet should have. Can be redundant, if the largest packet has more bytes
|
|
|
+ than length.
|
|
|
+ :return: The list of extended packets.
|
|
|
'''
|
|
|
|
|
|
largest_packet = length
|
|
@@ -56,8 +58,8 @@ def equal_length(list_of_packets, length = 0, padding = 0):
|
|
|
for packet in list_of_packets:
|
|
|
bytes_padding = largest_packet - len(packet)
|
|
|
if(bytes_padding > 0):
|
|
|
- add_padding(packet, bytes_padding, False, False)
|
|
|
- add_padding(packet, padding, False, True)
|
|
|
+ add_padding(packet, bytes_padding, False, False) #Add padding to extend to param:length
|
|
|
+ add_padding(packet, padding, False, True) #Add random additional padding to create realism
|
|
|
|
|
|
return list_of_packets
|
|
|
|