Advertisement
Guest User

D2 packets reconstruct

a guest
Jan 22nd, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1.  def ParsePacket(self, packet_data, sender, action):
  2.         packet = Packet()
  3.         if self.reconstruct and not self.oldpacket == None and self.oldpacket.send == sender:            
  4.             new = packet_data
  5.             packet.RecvPacket(self.oldpacket.fullpacket + new, sender, action)
  6.             self.reconstruct = False
  7.             self.oldpacket = None
  8.         else:
  9.             packet.RecvPacket(packet_data, sender, action)
  10.    
  11.         if self.oldpacket != None and self.oldpacket.send != sender:
  12.             self.reconstruct = False
  13.             self.oldpacket = None
  14.        
  15.         while packet.len < len(packet.data):
  16.             extracted_data = packet.fullpacket[0 : packet.len + packet.size_len + 2 + (4 if sender else 0)]
  17.             goodPacket = Packet()
  18.             goodPacket.RecvPacket(extracted_data, sender, action)
  19.             goodPacket.Deserialize(Reader(goodPacket.data))
  20.                
  21.             nextdata = packet.fullpacket[packet.len + packet.size_len + 2 + (4 if sender else 0):]
  22.             packet = Packet()
  23.             if packet.RecvPacket(nextdata, sender, action) == False:
  24.                 self.oldpacket = packet
  25.                 self.reconstruct = True
  26.                 return
  27.             if packet.len == 0:
  28.                 packet.Deserialize(Reader(b""))
  29.                 data = packet.fullpacket[2 + (4 if sender else 0):]
  30.                 if len(data) > 0:
  31.                     packet = Packet()
  32.                     packet.RecvPacket(data, sender, action)
  33.                 else:
  34.                     return
  35.  
  36.         if len(packet.data) > packet.len:
  37.             print("[-] ERROR")
  38.         elif len(packet.data) == packet.len:
  39.             packet.action = action
  40.             packet.Deserialize(Reader(packet.data))              
  41.         else:
  42.             self.oldpacket = packet
  43.             self.reconstruct = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement