Advertisement
yasi04

Untitled

May 29th, 2024
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. from struct import unpack_from, calcsize
  2.  
  3.  
  4. def sub(data, delta, ty, sub_pos=">"):
  5.     dict_of_types = {
  6.         'float': 'f',
  7.         'double': 'd',
  8.         'char': 'c',
  9.         'int8': 'b',
  10.         'uint8': 'B',
  11.         'int16': 'h',
  12.         'uint16': 'H',
  13.         'int32': 'i',
  14.         'uint32': 'I',
  15.         'int64': 'q',
  16.         'uint64': 'Q'}
  17.     pat = dict_of_types[ty]
  18.     size = calcsize(sub_pos + pat)
  19.     res = unpack_from(sub_pos + pat, buffer=data, offset=delta)[0]
  20.     return res, delta + size
  21.  
  22.  
  23. def edit_d(buff, offs):
  24.     d1, offs = sub(buff, offs, 'int8')
  25.     d2, offs = sub(buff, offs, 'float')
  26.     d3 = []
  27.     for i in range(2):
  28.         not_so_res, offs = sub(buff, offs, 'double')
  29.         d3.append(not_so_res)
  30.     d4size, offs = sub(buff, offs, 'uint32')
  31.     d4offs, offs = sub(buff, offs, 'uint32')
  32.     d4 = []
  33.     for i in range(d4size):
  34.         not_so_res, d4offs = sub(buff, d4offs, 'int8')
  35.         d4.append(not_so_res)
  36.     d5, offs = sub(buff, offs, 'int32')
  37.     d6, offs = sub(buff, offs, 'int32')
  38.     return {"D1": d1, "D2": d2, "D3": d3, "D4": d4, "D5": d5, "D6": d6}, offs
  39.  
  40.  
  41. def edit_c(buff, offs):
  42.     c1, offs = sub(buff, offs, 'int16')
  43.     c2, offs = sub(buff, offs, 'int64')
  44.     c3, offs = sub(buff, offs, 'int64')
  45.     c4, offs = sub(buff, offs, 'int16')
  46.     return {"C1": c1, "C2": c2, "C3": c3, "C4": c4}, offs
  47.  
  48.  
  49. def edit_b(buff, offs):
  50.     b1 = []
  51.     for i in range(6):
  52.         not_so_res, offs = sub(buff, offs, 'char')
  53.         b1.append(not_so_res)
  54.     b2, offs = sub(buff, offs, 'uint16')
  55.     b3 = []
  56.     for i in range(4):
  57.         not_so_res, offs = edit_c(buff, offs)
  58.         b3.append(not_so_res)
  59.     b4, offs = edit_b(buff, offs)
  60.     b5, offs = sub(buff, offs, 'uint64')
  61.     b6, offs = sub(buff, offs, 'uint8')
  62.     b7, offs = sub(buff, offs, 'int32')
  63.     b8 = []
  64.     for i in range(2):
  65.         not_so_res, offs = sub(buff, offs, 'int64')
  66.         b8.append(not_so_res)
  67.     return {"B1": b1, "B2": b2, "B3": b3, "B4": b4, "B5": b5, "B6": b6, "B7": b7, "B8": b8}, offs
  68.  
  69.  
  70. def edit_a(buff, offs):
  71.     a1, offs = sub(buff, offs, 'float')
  72.     a2, offs = edit_b(buff, offs)
  73.     return {"A1": a1, "A2": a2}, offs
  74.  
  75.  
  76. def main(data):
  77.     res, offs = edit_a(data, 3)
  78.     return res
  79.  
  80.  
  81. q = main((b'NMI?E\xf0!cfiaeu*7\xcf\xb7\xdc\xba+Yq\x81\xfbZ\xf7\xba\xe5\xf4\x7fT{'
  82.         b'0\x90t\xdb\xb0R\x9d>\x8f\xb7\x90\x11\xff\x17\x87\x11s\xd8\x07\xe7'
  83.         b'\xa2\xbb\xcc\x8c\xbbrL\x14!\x8a\xb3^$\xfd\xa8\x13\x7ft\xff\x9428\x8fI'
  84.         b"u'\xcb\xc9\xc0\xae0\x8b\x10\x83[\x19\xc9\x1e\xe1>%\xcdv\xbd\xbf7\x8d\xd3"
  85.         b'?\xdd!\\\x90\x1d\x0b\xa0?\xed%\x80K\xdbZ"\x00\x00\x00\x03\x00\x00\x00\xa1'
  86.         b"r\x01U=\xc4\x86P{\xc5\xab\xdb~B\x85^\x95\xd3\xfcA/\xf4&z\xc5q,<\x93UX'DjcMk"
  87.         b'-\xf9\xfc\x1e'))
  88.  
  89. print(q)
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement