Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from struct import unpack_from, calcsize
- def sub(data, delta, ty, sub_pos=">"):
- dict_of_types = {
- 'float': 'f',
- 'double': 'd',
- 'char': 'c',
- 'int8': 'b',
- 'uint8': 'B',
- 'int16': 'h',
- 'uint16': 'H',
- 'int32': 'i',
- 'uint32': 'I',
- 'int64': 'q',
- 'uint64': 'Q'}
- pat = dict_of_types[ty]
- size = calcsize(sub_pos + pat)
- res = unpack_from(sub_pos + pat, buffer=data, offset=delta)[0]
- return res, delta + size
- def edit_d(buff, offs):
- d1, offs = sub(buff, offs, 'int8')
- d2, offs = sub(buff, offs, 'float')
- d3 = []
- for i in range(2):
- not_so_res, offs = sub(buff, offs, 'double')
- d3.append(not_so_res)
- d4size, offs = sub(buff, offs, 'uint32')
- d4offs, offs = sub(buff, offs, 'uint32')
- d4 = []
- for i in range(d4size):
- not_so_res, d4offs = sub(buff, d4offs, 'int8')
- d4.append(not_so_res)
- d5, offs = sub(buff, offs, 'int32')
- d6, offs = sub(buff, offs, 'int32')
- return {"D1": d1, "D2": d2, "D3": d3, "D4": d4, "D5": d5, "D6": d6}, offs
- def edit_c(buff, offs):
- c1, offs = sub(buff, offs, 'int16')
- c2, offs = sub(buff, offs, 'int64')
- c3, offs = sub(buff, offs, 'int64')
- c4, offs = sub(buff, offs, 'int16')
- return {"C1": c1, "C2": c2, "C3": c3, "C4": c4}, offs
- def edit_b(buff, offs):
- b1 = []
- for i in range(6):
- not_so_res, offs = sub(buff, offs, 'char')
- b1.append(not_so_res)
- b2, offs = sub(buff, offs, 'uint16')
- b3 = []
- for i in range(4):
- not_so_res, offs = edit_c(buff, offs)
- b3.append(not_so_res)
- b4, offs = edit_b(buff, offs)
- b5, offs = sub(buff, offs, 'uint64')
- b6, offs = sub(buff, offs, 'uint8')
- b7, offs = sub(buff, offs, 'int32')
- b8 = []
- for i in range(2):
- not_so_res, offs = sub(buff, offs, 'int64')
- b8.append(not_so_res)
- return {"B1": b1, "B2": b2, "B3": b3, "B4": b4, "B5": b5, "B6": b6, "B7": b7, "B8": b8}, offs
- def edit_a(buff, offs):
- a1, offs = sub(buff, offs, 'float')
- a2, offs = edit_b(buff, offs)
- return {"A1": a1, "A2": a2}, offs
- def main(data):
- res, offs = edit_a(data, 3)
- return res
- q = main((b'NMI?E\xf0!cfiaeu*7\xcf\xb7\xdc\xba+Yq\x81\xfbZ\xf7\xba\xe5\xf4\x7fT{'
- b'0\x90t\xdb\xb0R\x9d>\x8f\xb7\x90\x11\xff\x17\x87\x11s\xd8\x07\xe7'
- b'\xa2\xbb\xcc\x8c\xbbrL\x14!\x8a\xb3^$\xfd\xa8\x13\x7ft\xff\x9428\x8fI'
- b"u'\xcb\xc9\xc0\xae0\x8b\x10\x83[\x19\xc9\x1e\xe1>%\xcdv\xbd\xbf7\x8d\xd3"
- b'?\xdd!\\\x90\x1d\x0b\xa0?\xed%\x80K\xdbZ"\x00\x00\x00\x03\x00\x00\x00\xa1'
- b"r\x01U=\xc4\x86P{\xc5\xab\xdb~B\x85^\x95\xd3\xfcA/\xf4&z\xc5q,<\x93UX'DjcMk"
- b'-\xf9\xfc\x1e'))
- print(q)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement