code "from struct import unpack def main(data): d = 'Q6hHh' c = '>fH' b = 'IIHQd{D}{D}qHIB'.replace('{D}', d) a = '{B}BhQbq'.replace('{B}', b) format = '>xxxx{A}'.replace('{A}', a) obj = unpack(format, data[:113]) (c_size, c_addr) = (obj[0], obj[1]) B = {'B1': [], 'B2': obj[2], 'B3': obj[3], 'B4': obj[4], 'B5': [], 'B6': obj[23], 'B7': [], 'B8': obj[26]} (b7_size, b7_addr) = (obj[24], obj[25]) for i in range(b7_size): index = b7_addr + i * 2 b7_obj = unpack('>h', data[index:index + 2])[0] B['B7'].append(b7_obj) for i in range(c_size): index = c_addr + i * 6 c_obj = unpack(c, data[index:index + 6]) C = {'C1': c_obj[0], 'C2': c_obj[1]} B['B1'].append(C) for i in range(2): start = 5 + i * 9 D = {'D1': obj[start], 'D2': list(obj[start + 1:start + 7]), 'D3': obj[start + 7], 'D4': obj[start + 8]} B['B5'].append(D) A = {'A1': B, 'A2': obj[27], 'A3': obj[28], 'A4': obj[29], 'A5': obj[30], 'A6': obj[31]} return A" "from struct import * def main(B): a = [*unpack_from('h', y[ad + sd * i:ad + sd + sd * i])) if sd == 4: c = sum(struct.unpack('>i', y[ad + sd * i:ad + sd + sd * i])) C14.append(c) return C14 def main(y): d = {} db = {} dc1 = {} dc2 = {} dd1 = {} dd2 = {} y_ = struct.unpack('>I', y[3:7]) a = sum(y_) A2 = sum(struct.unpack('>f', y[7:11])) A3 = struct.unpack('>HH', y[11:15]) B1 = struct.unpack('>8s', y[a:a + 8]) for it in B1: a_ = str(it) a_ = a_.replace(""b'"", '') a_ = a_.replace(""'"", '') db['B1'] = a_ db['B2'] = sum(struct.unpack('>b', y[a + 8:a + 9])) db['B3'] = sum(struct.unpack('>H', y[a + 9:a + 11])) (a, b) = A3 C11 = struct.unpack('>H', y[a:a + 2]) C12 = sum(struct.unpack('>B', y[a + 2:a + 3])) C13 = sum(struct.unpack('>H', y[a + 3:a + 5])) C14 = struct.unpack('>HH', y[a + 5:a + 9]) (s, ad) = C14 C14 = mass(y, ad, s, 2) C21 = struct.unpack('>H', y[b:b + 2]) C22 = sum(struct.unpack('>B', y[b + 2:b + 3])) C23 = sum(struct.unpack('>H', y[b + 3:b + 5])) C24 = struct.unpack('>HH', y[b + 5:b + 9]) (s, ad) = C24 C24 = mass(y, ad, s, 2) a = sum(C11) (d11, d12, d13) = struct.unpack('>BBB', y[a:a + 3]) dd1['D1'] = [d11, d12, d13] D12 = struct.unpack('>HI', y[a + 3:a + 9]) (s, ad) = D12 dd1['D2'] = mass(y, ad, s, 4) dd1['D3'] = sum(struct.unpack('>f', y[a + 9:a + 13])) dd1['D4'] = sum(struct.unpack('>q', y[a + 13:a + 21])) dd1['D5'] = sum(struct.unpack('>I', y[a + 21:a + 25])) dd1['D6'] = sum(struct.unpack('>Q', y[a + 25:a + 33])) a = sum(C21) (d21, d22, d23) = D21 = struct.unpack('>BBB', y[a:a + 3]) dd2['D1'] = [d21, d22, d23] D22 = struct.unpack('>HI', y[a + 3:a + 9]) (s, ad) = D22 dd2['D2'] = mass(y, ad, s, 4) dd2['D3'] = sum(struct.unpack('>f', y[a + 9:a + 13])) dd2['D4'] = sum(struct.unpack('>q', y[a + 13:a + 21])) dd2['D5'] = sum(struct.unpack('>I', y[a + 21:a + 25])) dd2['D6'] = sum(struct.unpack('>Q', y[a + 25:a + 33])) dc1['C1'] = dd1 dc1['C2'] = C12 dc1['C3'] = C13 dc1['C4'] = C14 dc2['C1'] = dd2 dc2['C2'] = C22 dc2['C3'] = C23 dc2['C4'] = C24 d['A1'] = db d['A2'] = A2 a = [dc1, dc2] d['A3'] = a return d" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 78 and a_adr != 2: break a = {f'A{i}': None for i in range(1, 5)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('IdbdQHdi{fsymbols}ddddddbBfffQIHhhhhhHhhQ', binars[5:]) A1 = res[0] B1 = res[1] B2 = res[2] B3 = res[3] B4 = res[4] D1_0 = res[8 + fcount] D2_0 = res[9 + fcount] D1_1 = res[10 + fcount] D2_1 = res[11 + fcount] D1_2 = res[12 + fcount] D2_2 = res[13 + fcount] C2 = res[14 + fcount] C3 = res[15 + fcount] C4 = list(res[16 + fcount:19 + fcount]) C5 = res[19 + fcount] E1 = [res[x + 8] for x in range(fcount)] E2 = [res[x + 22 + fcount] for x in range(5)] E3 = res[27 + fcount] E4 = res[28 + fcount] E5 = res[29 + fcount] E6 = res[30 + fcount] B6 = res[6] B7 = res[7] tree = {'A1': A1, 'A2': {'B1': B1, 'B2': B2, 'B3': B3, 'B4': B4, 'B5': {'C1': [{'D1': D1_0, 'D2': D2_0}, {'D1': D1_1, 'D2': D2_1}, {'D1': D1_2, 'D2': D2_2}], 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5, 'C6': {'E1': E1, 'E2': E2, 'E3': E3, 'E4': E4, 'E5': E5, 'E6': E6}}, 'B6': B6, 'B7': B7}} return tree" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('d', bytes, offset=4)[0] count = struct.unpack_from('H', bytes, offset=12)[0] address_b = struct.unpack_from('I', bytes, offset=14)[0] dict['A2'] = [] for i in range(count): B_dict = {} (B_dict['B1'], B_dict['B2']) = struct.unpack_from('hb', bytes, offset=address_b + i * 3) dict['A2'].append(B_dict) count_c = struct.unpack_from('H', bytes, offset=18)[0] address_c = struct.unpack_from('H', bytes, offset=20)[0] C_dict = {} C_dict['C1'] = struct.unpack_from(str(count_c) + 's', bytes, offset=address_c)[0].decode() dict['A3'] = C_dict C_dict['C2'] = struct.unpack_from('I', bytes, offset=22)[0] (C_dict['C3'], C_dict['C4'], C_dict['C5']) = struct.unpack_from('3f', bytes, offset=26) C_dict['C6'] = struct.unpack_from('h', bytes, offset=38)[0] address_e = struct.unpack_from('I', bytes, offset=40)[0] D_dict = {} dict['A4'] = D_dict D_dict['D1'] = {} D_dict['D2'] = struct.unpack_from('b', bytes, offset=44)[0] D_dict['D3'] = struct.unpack_from('I', bytes, offset=45)[0] count_d = struct.unpack_from('I', bytes, offset=49)[0] address_d = struct.unpack_from('H', bytes, offset=53)[0] D_dict['D4'] = [] for i in range(count_d): D_dict['D4'].append(struct.unpack_from('h', bytes, offset=address_d + i * 2)[0]) E_dict = {} count_e = struct.unpack_from('H', bytes, offset=address_e)[0] address_ee = struct.unpack_from('H', bytes, offset=address_e + 2)[0] E_dict['E1'] = [] D_dict['D1'] = E_dict for i in range(count_e): E_dict['E1'].append(struct.unpack_from('I', bytes, offset=address_ee + i * 4)[0]) E_dict['E2'] = [] E_dict['E2'].append(struct.unpack_from('3b', bytes, offset=address_e + 4)[0]) E_dict['E2'].append(struct.unpack_from('3b', bytes, offset=address_e + 4)[1]) E_dict['E2'].append(struct.unpack_from('3b', bytes, offset=address_e + 4)[2]) E_dict['E3'] = struct.unpack_from('H', bytes, address_e + 7)[0] E_dict['E4'] = struct.unpack_from('B', bytes, address_e + 9)[0] return dict" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('>6s', bytes, offset=5)[0].decode() dict['A2'] = struct.unpack_from('>f', bytes, offset=11)[0] address_b = struct.unpack_from('>H', bytes, offset=15)[0] address_c = struct.unpack_from('>8I', bytes, offset=address_b) address_d = struct.unpack_from('>I', bytes, offset=address_b + 32)[0] dict_b = {} dict['A3'] = dict_b dict_b['B1'] = [] for i in range(len(address_c)): dict_c = {} (dict_c['C1'], dict_c['C2']) = struct.unpack_from('>2f', bytes, offset=address_c[i]) dict_b['B1'].append(dict_c) dict_d = {} dict_b['B2'] = dict_d count_d = struct.unpack_from('>I', bytes, offset=address_d)[0] address_dd = struct.unpack_from('>H', bytes, offset=address_d + 4)[0] dict_d['D1'] = [] dict_d['D1'].append(struct.unpack_from('>Q', bytes, offset=address_dd)[0]) dict_d['D1'].append(struct.unpack_from('>Q', bytes, offset=address_dd + 8)[0]) dict_d['D2'] = struct.unpack_from('>I', bytes, offset=address_d + 6)[0] dict_d['D3'] = struct.unpack_from('>d', bytes, offset=address_d + 10)[0] dict_d['D4'] = struct.unpack_from('>B', bytes, offset=address_d + 18)[0] count_dd = struct.unpack_from('>I', bytes, offset=address_d + 19)[0] address_ddd = struct.unpack_from('>I', bytes, offset=address_d + 23)[0] dict_d['D5'] = [] for i in range(count_dd): dict_d['D5'].append(struct.unpack_from('>q', bytes, offset=address_ddd + 8 * i)[0]) return dict" "import struct def main(bytes): dict = {} dict['A1'] = [] address_b = list(struct.unpack_from('>2H', bytes, offset=5)) for i in range(2): B_dict = {} B_dict['B1'] = struct.unpack_from('>d', bytes, offset=address_b[i])[0] B_dict['B2'] = ''.join(map(lambda k: k.decode(), struct.unpack_from('>5c', bytes, offset=address_b[i] + 8))) address_c = struct.unpack_from('>L', bytes, offset=address_b[i] + 13)[0] C_dict = {} C_dict['C1'] = struct.unpack_from('>h', bytes, offset=address_c)[0] C_dict['C2'] = struct.unpack_from('>L', bytes, offset=address_c + 2)[0] C_dict['C3'] = struct.unpack_from('>L', bytes, offset=address_c + 6)[0] B_dict['B3'] = C_dict count = struct.unpack_from('>L', bytes, offset=address_b[i] + 17)[0] address = struct.unpack_from('>h', bytes, offset=address_b[i] + 21)[0] B_dict['B4'] = [] for j in range(count): B_dict['B4'].append(struct.unpack_from('>l', bytes, offset=address + j * 4)[0]) D_dict = {} D_dict['D1'] = struct.unpack_from('>H', bytes, offset=address_b[i] + 23)[0] D_dict['D2'] = struct.unpack_from('>q', bytes, offset=address_b[i] + 25)[0] count = struct.unpack_from('>H', bytes, offset=address_b[i] + 33)[0] address = struct.unpack_from('>L', bytes, offset=address_b[i] + 35)[0] D_dict['D3'] = [] for j in range(count): D_dict['D3'].append(struct.unpack_from('>b', bytes, offset=address + j)[0]) D_dict['D4'] = struct.unpack_from('>f', bytes, offset=address_b[i] + 39)[0] D_dict['D5'] = struct.unpack_from('>H', bytes, offset=address_b[i] + 43)[0] D_dict['D6'] = [] for j in range(8): D_dict['D6'].append(struct.unpack_from('>B', bytes, offset=address_b[i] + 45 + j)[0]) B_dict['B5'] = D_dict B_dict['B6'] = struct.unpack_from('>B', bytes, offset=address_b[i] + 53)[0] B_dict['B7'] = struct.unpack_from('>L', bytes, offset=address_b[i] + 54)[0] dict['A1'].append(B_dict) dict['A2'] = struct.unpack_from('>b', bytes, offset=9)[0] return dict" "import struct def get_array(b: bytes, size: int, addr: int, type: str) -> list: type_sz = struct.calcsize(type) return list(struct.unpack(f'>{size}{type}', b[addr:addr + size * type_sz])) def get_struct(b: bytes, s: struct.Struct, addr: int) -> tuple: return s.unpack(b[addr:addr + s.size]) def main(b: bytes) -> dict: signature = bytes([121, 87, 75, 65]) a_start = b.find(signature) + len(signature) a_struct = struct.Struct('>IIqBqIHhfibII') a_unpacked = get_struct(b, a_struct, a_start) g_unpacked = a_unpacked[5:11] g1 = get_array(b, g_unpacked[0], g_unpacked[1], 'b') g_unpacked = (g1,) + g_unpacked[2:] a7 = get_array(b, a_unpacked[-2], a_unpacked[-1], 'I') b_struct = struct.Struct('>fIqddfqdH') b_unpacked = get_struct(b, b_struct, a_unpacked[0]) c_unpacked = b_unpacked[1:5] d_struct = struct.Struct('>IdqfIfIIH') d_unpacked = get_struct(b, d_struct, b_unpacked[-1]) e_unpacked = d_unpacked[:2] d3 = d_unpacked[3:7] d3 = [d3[:2], d3[2:]] d4 = get_array(b, d_unpacked[7], d_unpacked[8], 'f') d_unpacked = (e_unpacked, d_unpacked[2], d3, d4) b_unpacked = (b_unpacked[0], c_unpacked) + b_unpacked[5:8] + (d_unpacked,) a_unpacked = (b_unpacked,) + a_unpacked[1:5] + (g_unpacked, a7) return {'A1': {'B1': b_unpacked[0], 'B2': {f'C{i + 1}': v for (i, v) in enumerate(c_unpacked)}, 'B3': b_unpacked[2], 'B4': b_unpacked[3], 'B5': b_unpacked[4], 'B6': {'D1': {f'E{i + 1}': v for (i, v) in enumerate(e_unpacked)}, 'D2': d_unpacked[1], 'D3': [{f'F{i + 1}': v for (i, v) in enumerate(f)} for f in d_unpacked[2]], 'D4': d_unpacked[3]}}, 'A2': a_unpacked[1], 'A3': a_unpacked[2], 'A4': a_unpacked[3], 'A5': a_unpacked[4], 'A6': {f'G{i + 1}': v for (i, v) in enumerate(g_unpacked)}, 'A7': a7}" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('h', bytes, offset=3)[0] dict['A2'] = struct.unpack_from('Q', bytes, offset=5)[0] dict['A3'] = struct.unpack_from('B', bytes, offset=13)[0] countA = struct.unpack_from('H', bytes, offset=14)[0] addressA = struct.unpack_from('I', bytes, offset=16)[0] dict['A4'] = struct.unpack_from(str(countA) + 's', bytes, offset=addressA)[0].decode() dict['A5'] = [] for j in range(2): dictB = {} addressC = struct.unpack_from('I', bytes, offset=20 + 7 * j)[0] dictC = {} dictB['B1'] = dictC dictC['C1'] = struct.unpack_from('I', bytes, offset=addressC)[0] countC = struct.unpack_from('H', bytes, offset=addressC + 4)[0] addressCC = struct.unpack_from('H', bytes, offset=addressC + 6)[0] dictC['C2'] = [] for i in range(countC): dictC['C2'].append(struct.unpack_from('H', bytes, offset=addressCC + 2 * i)[0]) dictC['C3'] = struct.unpack_from('b', bytes, offset=addressC + 8)[0] countC = struct.unpack_from('I', bytes, offset=addressC + 9)[0] addressCC = struct.unpack_from('H', bytes, offset=addressC + 13)[0] dictC['C4'] = [] for i in range(countC): dictC['C4'].append(struct.unpack_from('i', bytes, offset=addressCC + 4 * i)[0]) dictC['C5'] = struct.unpack_from('I', bytes, offset=addressC + 15)[0] dictD = {} dictB['B2'] = dictD addressD = struct.unpack_from('H', bytes, offset=24 + 7 * j)[0] dictD['D1'] = struct.unpack_from('I', bytes, offset=addressD)[0] dictD['D2'] = struct.unpack_from('B', bytes, offset=addressD + 4)[0] dictD['D3'] = [] for i in range(2): dictD['D3'].append(struct.unpack_from('B', bytes, offset=addressD + 5 + i)[0]) dictB['B3'] = struct.unpack_from('b', bytes, offset=26 + 7 * j)[0] dict['A5'].append(dictB) return dict" "import struct def unpackC(string): c = struct.unpack('>BdfI', string) return {'C1': c[0], 'C2': c[1], 'C3': c[2], 'C4': c[3]} def main(string): res = {} (a1, a2, a3, a4) = struct.unpack_from('>H19s64sQ', string, 3) structureB = '>17s17s17shBhBbQ2s' b = struct.unpack_from(structureB, string, a1) res['A1'] = {'B1': [unpackC(b[0]), unpackC(b[1]), unpackC(b[2])], 'B2': b[3], 'B3': b[4], 'B4': b[5], 'B5': b[6], 'B6': b[7], 'B7': b[8], 'B8': b[9].decode('ascii')} structureD = '>IIfbHHbb' structureE = '>QdIIddddd' d = struct.unpack(structureD, a2) res['A2'] = {'D1': d[0], 'D2': d[1], 'D3': d[2], 'D4': d[3], 'D5': d[4], 'D6': d[5], 'D7': [d[6], d[7]]} e = struct.unpack(structureE, a3) res['A3'] = {'E1': e[0], 'E2': e[1], 'E3': e[2], 'E4': e[3], 'E5': [e[4], e[5], e[6], e[7], e[8]]} res['A4'] = a4 return res" "from struct import unpack def main(arg): a = 'Bh'] + [FORMAT_B] * 6 + ['Hb', FORMAT_D, 'h']) LENGTH_A = struct.calcsize(FORMAT_A) LENGTH_B = struct.calcsize(FORMAT_B) LENGTH_C = struct.calcsize(FORMAT_C) LENGTH_D = struct.calcsize(FORMAT_D) TRIGGER_SEQUENCE = b'GRYD' def main(given_bytes): sidx = given_bytes.find(TRIGGER_SEQUENCE) sls = sidx + len(TRIGGER_SEQUENCE) sleidx = sidx + len(TRIGGER_SEQUENCE) + LENGTH_A strb = given_bytes[sls:sleidx] unp = struct.unpack(FORMAT_A, strb) strsb = [] for idx in range(6): bs = 2 + idx * len(FORMAT_B) fas = unp[bs + 5] faf = ''.join(['>'] + ['f'] * fas) fal = struct.calcsize(faf) faas = unp[bs + 6] faae = faas + fal struct_b = {'B1': [unp[bs], unp[bs + 1], unp[bs + 2], unp[bs + 3]], 'B2': unp[bs + 4], 'B3': list(struct.unpack(faf, given_bytes[faas:faae]))} strsb.append(struct_b) sds = 2 + 6 * len(FORMAT_B) + 2 sd = {'D1': unp[sds], 'D2': unp[sds + 1], 'D3': unp[sds + 2], 'D4': unp[sds + 3], 'D5': unp[sds + 4], 'D6': unp[sds + 5], 'D7': unp[sds + 6]} scf = '>' + FORMAT_C scl = struct.calcsize(scf) scas = unp[2 + 6 * len(FORMAT_B)] scae = scas + scl unsc = struct.unpack(scf, given_bytes[scas:scae]) ias = unsc[1] iaf = ''.join(['>'] + ['h'] * ias) ial = struct.calcsize(iaf) iaas = unsc[2] iaae = unsc[2] + ial unpacked_int16_arr = struct.unpack(iaf, given_bytes[iaas:iaae]) sc = {'C1': unsc[0], 'C2': list(unpacked_int16_arr), 'C3': unsc[3], 'C4': unsc[4]} struct_a = {'A1': unp[0], 'A2': unp[1], 'A3': strsb, 'A4': sc, 'A5': unp[2 + 6 * len(FORMAT_B) + 1], 'A6': sd, 'A7': unp[2 + 6 * len(FORMAT_B) + 9]} return struct_a" "from struct import * def get_bstruct(x, offset): offset = unpack_from('I', x, offset)[0] result = {'B1': unpack_from('h', x, offset)[0], 'B2': unpack_from('b', x, offset + 2)[0], 'B3': unpack_from('H', x, offset + 3)[0], 'B4': unpack_from('B', x, offset + 5)[0]} return result def get_cstruct(x, offset): offset = unpack_from('I', x, offset)[0] result = {'C1': unpack_from('b', x, offset)[0], 'C2': unpack_from('B', x, offset + 1)[0], 'C3': get_dstruct(x, offset + 2), 'C4': unpack_from('q', x, offset + 10)[0]} offset += 18 result['C5'] = array_help([], 8, 2, x, offset, 'H') result['C6'] = unpack_from('i', x, offset + 16)[0] offset += 20 result['C7'] = array_help([], 4, 4, x, offset, 'i') result['C8'] = {'E1': unpack_from('b', x, offset + 16)[0], 'E2': unpack_from('q', x, offset + 17)[0], 'E3': unpack_from('H', x, offset + 25)[0], 'E4': unpack_from('d', x, offset + 27)[0], 'E5': unpack_from('h', x, offset + 35)[0]} return result def get_dstruct(x, offset): size = unpack_from('I', x, offset)[0] offset = unpack_from('I', x, offset + 4)[0] result = [] for i in range(size): result.append(dstruct(x, offset)) offset += 10 return result def dstruct(x, offset): result = {'D1': unpack_from('B', x, offset)[0]} array_size = unpack_from('H', x, offset + 1)[0] array_offset = unpack_from('I', x, offset + 3)[0] result['D2'] = array_help([], array_size, 2, x, array_offset, 'h') result['D3'] = unpack_from('b', x, offset + 7)[0] result['D4'] = unpack_from('H', x, offset + 8)[0] return result def array_help(array, size, inc, x, offset, formation): for i in range(size): array.append(unpack_from(formation, x, offset)[0]) offset += inc return array def main(x): array = [] offset = 33 result = {'A1': get_bstruct(x, 5), 'A2': get_cstruct(x, 9), 'A3': unpack_from('I', x, 13)[0], 'A4': unpack_from('Q', x, 17)[0], 'A5': unpack_from('q', x, 25)[0], 'A6': array_help(array, 3, 2, x, offset, 'h'), 'A7': unpack_from('B', x, offset + 6)[0], 'A8': unpack_from('d', x, offset + 7)[0]} return result" "import struct class Base: def __init__(self, name, struct_f): self.name = name self.struct_f = struct_f @staticmethod def _u(f_f, b_str, o): field_size = struct.calcsize(f_f) content = b_str[o:o + field_size] return (struct.unpack('>' + f_f, content), o + field_size) def _g(self, b_str, o=0): f = {} counter = 1 for struct_f in self.struct_f: f_name = self.name + str(counter) if isinstance(struct_f, (tuple, list)): (a_s_s, a_p_s, a_t) = struct_f if type(a_s_s) == str: ((a_s,), o) = self._u(a_s_s, b_str, o) else: a_s = a_s_s if isinstance(a_t, Base): f[f_name] = [] for _ in range(a_s): ((a_p,), o) = self._u(a_p_s, b_str, o) arr_field = a_t._g(b_str, a_p)[0] f[f_name].append(arr_field) if len(f[f_name]) == 1: f[f_name] = f[f_name][0] else: ((a_p,), o) = self._u(a_p_s, b_str, o) arr = self._u(str(a_s) + a_t, b_str, a_p)[0] if len(arr) > 1: f[f_name] = list(arr) else: f[f_name] = str(arr[0], 'utf-8') elif isinstance(struct_f, Base): (f[f_name], o) = struct_f._g(b_str, o) else: (u_field, o) = self._u(struct_f, b_str, o) if len(u_field) > 1: f[f_name] = list(u_field) else: f[f_name] = u_field[0] counter += 1 return (f, o) def get_struct(self, b_str, o=0): return self._g(b_str, o)[0] class A(Base): def __init__(self): super().__init__('A', ['i', 'b', 'd', B(), C()]) class B(Base): def __init__(self): super().__init__('B', ['q', 'h', 'i', ['H', 'I', 's']]) class C(Base): def __init__(self): super().__init__('C', ['B', [2, 'H', D()], 'H', 'H', 'f']) class D(Base): def __init__(self): super().__init__('D', ['q', 'd', 'b', '7B', 'H', 'b', 'Q', '4b']) def main(b_str): start_seq = b'WAF' return A().get_struct(b_str, len(start_seq))" "import struct SIGNATURE = bytes([119, 83, 66, 90]) ORDER = '<' def get_array_pattern(size, type_s): pattern = ORDER + type_s * size return pattern def calcsize(pattern): return struct.calcsize(ORDER + pattern) def create_dict(name: str, structure: tuple) -> dict: dictionary = dict() for i in range(len(structure)): dictionary.update({name + str(i + 1): structure[i]}) return dictionary def f(byte_str: bytes) -> dict: begin = byte_str.find(SIGNATURE) A_pattern = '4sBHI%dsH' B_pattern = 'IIh' C_pattern = 'II' D_pattern = 'I%ds' E_pattern = 'iHHI' F_pattern = 'BIHI' D_pattern = D_pattern % calcsize(F_pattern) A_pattern = A_pattern % calcsize(D_pattern) A_pos = [begin + len(SIGNATURE), begin + len(SIGNATURE) + calcsize(A_pattern)] A = struct.unpack(ORDER + A_pattern, byte_str[A_pos[0]:A_pos[1]]) A = create_dict('A', A) A['A1'] = A['A1'].decode() B_pos = [A['A3'], A['A3'] + calcsize(B_pattern)] B = struct.unpack(ORDER + B_pattern, byte_str[B_pos[0]:B_pos[1]]) C_arr_size = B[0] elem_size = calcsize(C_pattern) Cs = list() for i in range(C_arr_size): arr_pos = (B[1] + elem_size * i, B[1] + elem_size * (i + 1)) C = struct.unpack(ORDER + C_pattern, byte_str[arr_pos[0]:arr_pos[1]]) Cs.append(create_dict('C', C)) B = create_dict('B', [Cs, B[2]]) D = struct.unpack(ORDER + D_pattern, A['A5']) E_pos = [D[0], D[0] + calcsize(E_pattern)] E = struct.unpack(ORDER + E_pattern, byte_str[E_pos[0]:E_pos[1]]) int_arr_size = E[1] elem_size = 8 int_arr_pos = (E[2], E[2] + elem_size * int_arr_size) int_arr = struct.unpack(ORDER + 'q' * int_arr_size, byte_str[int_arr_pos[0]:int_arr_pos[1]]) E = create_dict('E', (E[0], list(int_arr), E[3])) F = struct.unpack(ORDER + F_pattern, D[1]) int_arr_size = F[2] elem_size = 4 int_arr_pos = (F[3], F[3] + elem_size * int_arr_size) int_arr = struct.unpack(ORDER + 'l' * int_arr_size, byte_str[int_arr_pos[0]:int_arr_pos[1]]) F = create_dict('F', [F[0], F[1], list(int_arr)]) D = create_dict('D', [E, F]) A['A3'] = B A['A5'] = D return A def main(x): return f(x)" "import struct def calcsize(pattern): return struct.calcsize('<' + pattern) def create_dict(name: str, structure: tuple) -> dict: dictionary = dict() for i in range(len(structure)): dictionary.update({name + str(i + 1): structure[i]}) return dictionary def main(byte_str): ORDER = '<' begin = 0 A_pattern = 'Iq%dsq' B_pattern = '%ds40sh' C_pattern = 'IH6s' D_pattern = 'i32sff' A_pattern = A_pattern % calcsize(D_pattern) B_pattern = B_pattern % (6 * calcsize(C_pattern)) A_pos = [begin + 3, begin + 3 + calcsize(A_pattern)] A = struct.unpack(ORDER + A_pattern, byte_str[A_pos[0]:A_pos[1]]) A = create_dict('A', A) B_pos = [A['A1'], A['A1'] + calcsize(B_pattern)] B = struct.unpack(ORDER + B_pattern, byte_str[B_pos[0]:B_pos[1]]) C_arr_size = 6 elem_size = calcsize(C_pattern) Cs = list() for i in range(C_arr_size): arr_pos = (elem_size * i, elem_size * (i + 1)) C = struct.unpack(ORDER + C_pattern, B[0][arr_pos[0]:arr_pos[1]]) int_arr_size = C[0] int_elem_size = 1 int_arr_pos = (C[1], C[1] + int_elem_size * int_arr_size) int_arr0 = struct.unpack(ORDER + 'b' * int_arr_size, byte_str[int_arr_pos[0]:int_arr_pos[1]]) int_arr_size = 3 int_elem_size = 2 int_arr_pos = (0, int_elem_size * int_arr_size) int_arr1 = struct.unpack(ORDER + 'h' * int_arr_size, C[2][int_arr_pos[0]:int_arr_pos[1]]) Cs.append(create_dict('C', [list(int_arr0), list(int_arr1)])) float_arr_size = 5 elem_size = 8 double_arr_pos = (0, elem_size * float_arr_size) double_arr = struct.unpack(ORDER + 'd' * float_arr_size, B[1][double_arr_pos[0]:double_arr_pos[1]]) B = create_dict('B', [Cs, list(double_arr), B[2]]) D = struct.unpack(ORDER + D_pattern, A['A3']) float_arr_size = 8 elem_size = 4 float_arr_pos = (0, elem_size * float_arr_size) float_arr = struct.unpack(ORDER + 'f' * float_arr_size, D[1][float_arr_pos[0]:float_arr_pos[1]]) D = create_dict('D', [D[0], list(float_arr), D[2], D[3]]) A['A1'] = B A['A3'] = D return A" "import struct def main(data): start_A = 4 a = struct.unpack_from('>q2Ib4fHQ', data, start_A) (len_b, start_B) = (a[1], a[2]) Bs = [] for i in range(len_b): Bs.append(struct.unpack_from('>bHHiq5cI', data, start_B)) start_B += struct.calcsize('>bHHiq5cI') starts_C = [] for b in Bs: starts_C.append(b[2]) Cs = [] for start_C in starts_C: Cs.append(struct.unpack_from('>Iq2f2bhd', data, start_C)) start_D = a[-2] d = struct.unpack_from('>6HBH', data, start_D) D = {'D1': list(d[:6]), 'D2': d[6], 'D3': d[7]} C = [] for c in Cs: temp_c = {} for i in range(1, 9): temp_c.setdefault('C' + str(i), c[i - 1]) C.append(temp_c) B = [] for i in range(len(Bs)): temp_b = {} temp_b.setdefault('B1', Bs[i][0]) temp_b.setdefault('B2', Bs[i][1]) temp_b.setdefault('B3', C[i]) temp_b.setdefault('B4', Bs[i][3]) temp_b.setdefault('B5', Bs[i][4]) temp_b.setdefault('B6', b''.join(Bs[i][5:10]).decode('utf-8')) temp_b.setdefault('B7', Bs[i][10]) B.append(temp_b) A = {'A1': a[0], 'A2': B, 'A3': a[3], 'A4': list(a[4:8]), 'A5': D, 'A6': a[-1]} return A" "def toFloat(x, a): return (1 - (x[a + 0] >> 7 << 1)) * 2 ** (((x[a + 0] & 127) << 1) + (x[a + 1] >> 7) - ((1 << 7) - 1)) * (1 + (((x[a + 1] & 127) << 16) + (x[a + 2] << 8) + x[a + 3]) / 2 ** 23) def toDouble(x, a): return (1 - (x[a] >> 7 << 1)) * 2 ** (((x[a] & 127) << 4) + (x[a + 1] >> 4) - ((1 << 10) - 1)) * (1 + (((x[a + 1] & 15) << 48) + (x[a + 2] << 40) + (x[a + 3] << 32) + (x[a + 4] << 24) + (x[a + 5] << 16) + (x[a + 6] << 8) + x[a + 7]) / (1 << 52)) def toUInt(x, n, a): res = 0 for i in range(0, n): res |= x[a + i] << 8 * (n - 1 - i) return res def toInt(x, n, a): res = (x[a] & 127) << 8 * (n - 1) for i in range(1, n): res |= x[a + i] << 8 * (n - 1 - i) return res - (1 << 8 * n - 1) * (x[a] >> 7) def main(x): b = toUInt(x, 2, 20) c = [] for i in range(toUInt(x, 2, b + 14), toUInt(x, 2, b + 14) + (toUInt(x, 2, b + 12) << 2), 4): c.append(toUInt(x, 4, i)) y = {'A1': toUInt(x, 2, 5), 'A2': toUInt(x, 1, 7), 'A3': toDouble(x, 8), 'A4': toUInt(x, 4, 16), 'A5': {'B1': toInt(x, 2, b), 'B2': '', 'B3': toUInt(x, 4, b + 8), 'B4': [], 'B5': {'D1': toInt(x, 4, b + 16), 'D2': toInt(x, 4, b + 20), 'D3': toFloat(x, b + 24), 'D4': [toUInt(x, 2, b + 28), toUInt(x, 2, b + 30), toUInt(x, 2, b + 32), toUInt(x, 2, b + 34)], 'D5': [toInt(x, 8, b + 36), toInt(x, 8, b + 44), toInt(x, 8, b + 52), toInt(x, 8, b + 60)], 'D6': toInt(x, 1, b + 68)}, 'B6': [], 'B7': toInt(x, 2, b + 77)}, 'A6': toUInt(x, 8, 22)} for i in range(toUInt(x, 4, b + 4), toUInt(x, 4, b + 4) + toUInt(x, 2, b + 2)): y['A5']['B2'] += chr(x[i]) for i in c: y['A5']['B4'].append({'C1': toUInt(x, 8, i), 'C2': toInt(x, 2, i + 8)}) for i in range(toUInt(x, 4, b + 73), toUInt(x, 4, b + 73) + (toUInt(x, 4, b + 69) << 2), 4): y['A5']['B6'].append(toFloat(x, i)) return y" "from struct import unpack_from from typing import Any, Callable class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read_uint64(self) -> int: return self.read('Q', 8)[0] def read_int64(self) -> int: return self.read('q', 8)[0] def read_uint32(self) -> int: return self.read('I', 4)[0] def read_int32(self) -> int: return self.read('i', 4)[0] def read_uint16(self) -> int: return self.read('H', 2)[0] def read_int16(self) -> int: return self.read('h', 2)[0] def read_uint8(self) -> int: return self.read('B', 1)[0] def read_int8(self) -> int: return self.read('b', 1)[0] def read_float(self) -> float: return self.read('f', 4)[0] def read_char(self): return self.read('c', 1)[0] def read(self, pattern: str, size: int): data = unpack_from(pattern, self.source, self.offset) self.offset += size return data def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e1 = reader.read_uint32() e2 = reader.read_int16() e3 = reader.read_int64() e4 = reader.read_uint32() e5 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) e6 = reader.read_int16() return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6) def read_d(reader: BinaryReader): d1 = reader.read_uint16() d2 = reader.read_int32() d3 = reader.read_uint64() return dict(D1=d1, D2=d2, D3=d3) def read_c(reader: BinaryReader): c1 = reader.read_uint64() c2 = reader.read_uint32() c3 = reader.read_int16() c4 = [reader.read_uint16(), reader.read_uint16()] return dict(C1=c1, C2=c2, C3=c3, C4=c4) def read_b(reader: BinaryReader): b1 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: read_c(reader), structure_size=18) b2 = read_d(reader) b3 = reader.read_int8() return dict(B1=b1, B2=b2, B3=b3) def read_a(reader: BinaryReader): a1 = reader.read_float() a2 = reader.read_uint64() a3 = read_b(reader) a4 = ''.join(read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode('ascii'))) a5 = read_e(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5) def main(source): reader = BinaryReader(source) reader.read('cccc', 4) return read_a(reader)" "from pprint import pprint from typing import List import struct def main(data: bytes) -> dict: if data[:5] != b'OYKF\x9d': raise SyntaxError() fmt = ' dict: fmt = ' dict: fmt = ' dict: fmt = ' List[float]: fmt = '<' + cfmt * count size = struct.calcsize(fmt) return list(struct.unpack(fmt, data[offset:offset + size]))" "import struct def main(b): (A, B, C, D) = (dict(), dict(), dict(), dict()) address_C = struct.unpack('>h', bytes(b[3:5]))[0] A['A2'] = [] C['C1'] = struct.unpack('>L', bytes(b[address_C:address_C + 4]))[0] address_D = struct.unpack('>L', bytes(b[address_C + 4:address_C + 8]))[0] (D['D1'], D['D2'], D['D3']) = struct.unpack('>BHl', bytes(b[address_D:address_D + 7])) (C['C3'], C['C4'], C['C5'], C['C6'], C['C7'], C['C8']) = struct.unpack('>f7sHhLl', bytes(b[address_C + 8:address_C + 31])) (C['C2'], C['C4']) = (dict(sorted(D.items(), key=lambda x: x[0])), C['C4'].decode('utf-8')) B['B1'] = dict(sorted(C.items(), key=lambda x: x[0])) (B['B2'], B['B3'], B['B4'], B['B5'], B['B6']) = struct.unpack('>2qBlh', bytes(b[5:28])) count_E = struct.unpack('>H', bytes(b[28:30]))[0] start_E = struct.unpack('>L', bytes(b[30:34]))[0] A['A1'] = dict(sorted(B.items(), key=lambda x: x[0])) for i in range(start_E, start_E + 16 * count_E, 16): (E, F) = (dict(), dict()) (E['E1'], E['E2'], E['E3']) = struct.unpack('>hQh', bytes(b[i:i + 12])) adress_F = struct.unpack('>l', bytes(b[i + 12:i + 16]))[0] F['F1'] = [j for j in struct.unpack('>2h', bytes(b[adress_F:adress_F + 4]))] (F['F2'], F['F3']) = struct.unpack('>lq', bytes(b[adress_F + 4:adress_F + 16])) F['F4'] = [j for j in struct.unpack('>6b', bytes(b[adress_F + 16:adress_F + 22]))] E['E4'] = dict(sorted(F.items(), key=lambda x: x[0])) A['A2'].append(dict(sorted(E.items(), key=lambda x: x[0]))) return dict(sorted(A.items(), key=lambda x: x[0]))" "from struct import unpack class A: def __init__(self, s): self.s = s self.current = 4 self.current_s = 0 def unpack_by_pattern(self, pat, length): def ret(): r = unpack(pat, self.s[self.current:self.current + length]) self.current += length return r[0] return ret def unpack_by_pattern_struct(self, pat, length): def ret(): r = unpack(pat, self.s[self.current_s:self.current_s + length]) self.current_s += length return r[0] return ret def A1(self): def B(): B1 = self.unpack_by_pattern(' list: arr_format = '!' + ''.join(['b' for _ in range(size)]) arr_bytesize = calcsize(arr_format) d4code = self.__code[offset:][:arr_bytesize] pack = unpack(arr_format, d4code) return list(pack) def __init__(self, code: bytes, offset: int): self.__code = code self.__offset = offset d_code = code[self.__offset:][:self.LEN_BYTES] self.__pack = struct.unpack(self.FORMAT, d_code) pack = self.__pack self.__D1 = pack[0] self.__D2 = pack[1] self.__D3 = pack[2] d4size = pack[3] d4ref = pack[4] self.__D4 = self.__get_d4(d4ref, d4size) self.__D5: list = list(pack[5:]) def get_pack(self) -> tuple: return self.__pack def __repr__(self): return repr(self.get_dict()) def get_dict(self) -> dict: dic = {'D1': self.__D1, 'D2': self.__D2, 'D3': self.__D3, 'D4': self.__D4, 'D5': self.__D5} return dic class C: FORMAT = '!d H l' LEN_BYTES = calcsize(FORMAT) def __init__2(self, code: bytes): if len(code) != self.LEN_BYTES: pass self.__pack = struct.unpack(self.FORMAT, code) pack = self.__pack self.__C1 = pack[0] self.__C2 = pack[1] self.__C3 = pack[2] def __init__(self, c1, c2, c3): self.__C1 = c1 self.__C2 = c2 self.__C3 = c3 def get_pack(self) -> tuple: return self.__pack def __repr__(self): return repr(self.get_dict()) def get_dict(self) -> dict: dic = {'C1': self.__C1, 'C2': self.__C2, 'C3': self.__C3} return dic class B: FORMAT = '!H dHq HHHHH I d i H' LEN_BYTES = calcsize(FORMAT) def __get_b7(self, offset: int) -> D: return D(self.__code, offset) def __init__(self, code: bytes, offset: int): self.__code = code self.__offset = offset b_code = code[self.__offset:][:self.LEN_BYTES] self.__pack = struct.unpack(self.FORMAT, b_code) pack = self.__pack self.__B1 = pack[0] (b2c1, b2c2, b2c3) = pack[1:4] self.__B2 = C(b2c1, b2c2, b2c3) self.__B3: list = list(pack[4:9]) self.__B4 = pack[9] self.__B5 = pack[10] self.__B6 = pack[11] b7ref = pack[12] self.__B7 = self.__get_b7(b7ref) def get_pack(self) -> tuple: return self.__pack def __repr__(self): return str(self.get_dict()) def get_dict(self) -> dict: dic = {'B1': self.__B1, 'B2': self.__B2, 'B3': self.__B3, 'B4': self.__B4, 'B5': self.__B5, 'B6': self.__B6, 'B7': self.__B7} return dic class A: FORMAT = '!qHfIHHI' LEN_BYTES = calcsize(FORMAT) START_BYTES = b'SWL' def __get_a4(self, offset: int, size: int) -> str: arr_format = '!' + ''.join(['c' for _ in range(size)]) arr_bytesize = calcsize(arr_format) a4code = self.__code[offset:][:arr_bytesize] return a4code.decode('utf-8') def __get_a5(self, offset: int, size: int): a5: list[B] = list() bsize = B.LEN_BYTES for i in range(size): a5.append(B(self.__code, offset + i * bsize)) return a5 def __init__(self, code: bytes): self.__code = code start_offset = code.find(self.START_BYTES) self.__offset = start_offset + len(self.START_BYTES) a_code = code[self.__offset:][:self.LEN_BYTES] self.__pack = struct.unpack(self.FORMAT, a_code) self.__A1: int = self.__pack[0] self.__A2: int = self.__pack[1] self.__A3: float = self.__pack[2] a4size: int = self.__pack[3] a4ref: int = self.__pack[4] self.__A4: str = self.__get_a4(a4ref, a4size) a5size: int = self.__pack[5] a5ref: int = self.__pack[6] self.__A5 = self.__get_a5(a5ref, a5size) def get_pack(self) -> tuple: return self.__pack def __repr__(self): return str(self.get_dict()) def __str__(self): return repr(self) def get_dict(self) -> dict: dic = {'A1': self.__A1, 'A2': self.__A2, 'A3': self.__A3, 'A4': self.__A4, 'A5': self.__A5} return dic def main(code: bytes) -> dict: return A(code).get_dict()" "from struct import unpack from binascii import unhexlify def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 75: break a = {'A1': None, 'A2': None, 'A3': None, 'A4': None} b = {'B1': None, 'B2': None, 'B3': None, 'B4': None, 'B5': None} d = {'D1': None, 'D2': None, 'D3': None, 'D4': None, 'D5': None} temp = unpack('3I', x[4:16]) for i in range(0, 3): result['A1'].append({'B1': struct.unpack('>B', x[y[i]:y[i] + 1])[0], 'B2': struct.unpack('>H', x[y[i] + 1:y[i] + 3])[0], 'B3': struct.unpack('>i', x[y[i] + 3:y[i] + 7])[0]}) result['A2'] = struct.unpack('>I', x[16:20])[0] A3len = struct.unpack('>I', x[20:24]) A3link = struct.unpack('>H', x[24:26]) result['A3'] = [] for i in range(0, A3len[0]): result['A3'].append({'C1': struct.unpack('>h', x[A3link[0] + 7 * i:A3link[0] + 2 + 7 * i])[0], 'C2': struct.unpack('>B', x[A3link[0] + 2 + 7 * i:A3link[0] + 3 + 7 * i])[0], 'C3': struct.unpack('>i', x[A3link[0] + 3 + 7 * i:A3link[0] + 7 + 7 * i])[0]}) A4 = struct.unpack('>H', x[26:28]) D1len = struct.unpack('>H', x[A4[0]:A4[0] + 2]) D1link = struct.unpack('>I', x[A4[0] + 2:A4[0] + 6]) result['A4'] = {} result['A4']['D1'] = [] for i in range(0, D1len[0]): result['A4']['D1'].append(struct.unpack('>h', x[D1link[0] + 2 * i:D1link[0] + 2 + 2 * i])[0]) result['A4']['D2'] = struct.unpack('>f', x[A4[0] + 6:A4[0] + 10])[0] result['A4']['D3'] = struct.unpack('>f', x[A4[0] + 10:A4[0] + 14])[0] result['A5'] = {'E1': [], 'E2': struct.unpack('>B', x[44:45])[0], 'E3': struct.unpack('>i', x[45:49])[0], 'E4': struct.unpack('>Q', x[49:57])[0], 'E5': struct.unpack('>b', x[57:58])[0]} for i in range(0, 8): result['A5']['E1'].append(struct.unpack('>H', x[28 + i * 2:30 + i * 2])[0]) result['A6'] = struct.unpack('>h', x[58:60])[0] result['A7'] = [] A7len = struct.unpack('>H', x[60:62])[0] A7link = struct.unpack('>H', x[62:64])[0] for i in range(0, A7len): result['A7'].append(struct.unpack('>H', x[A7link + i * 2:A7link + 2 + i * 2])[0]) result['A8'] = struct.unpack('>q', x[64:72])[0] return result" "from pprint import pprint from struct import unpack, calcsize field_to_pattern = {'A1': '>Q', 'A2': '>d', 'A3': '>h', 'A4': '>H', 'B1': '>8s', 'B2': '>f', 'A5s': '>I', 'A5a': '>I', 'Ca': '>I', 'C1': '>I', 'C2': '>i', 'C3': '>Q', 'A6': '>B', 'D1': '>H', 'D2': '>H', 'D3': '>B', 'D4': '>H', 'D5': '>Q', 'D7': '>I', 'D8': '>H', 'E1': '>q', 'E2': '>Q', 'E3': '>H', 'E4': '>H', 'E5': '>7s', 'F1': '>i', 'F2': '>q', 'F3': '>b', 'G1': '>f', 'G2': '>I', 'G3': '>H'} def get_current_data_and_end(data, begin, field): end = begin + calcsize(field_to_pattern[field]) return [data[begin:end], end] def set_field_with_returning_end(data, begin, field, struct): (currentData, end) = get_current_data_and_end(data, begin, field) struct[field] = unpack(field_to_pattern[field], currentData)[0] return end def main(data): result = {} begin = 5 end = calcsize(field_to_pattern['A1']) + begin currentData = data[begin:end] result['A1'] = unpack(field_to_pattern['A1'], currentData)[0] begin = end end = calcsize(field_to_pattern['A2']) + begin currentData = data[begin:end] result['A2'] = unpack(field_to_pattern['A2'], currentData)[0] begin = end end = calcsize(field_to_pattern['A3']) + begin currentData = data[begin:end] result['A3'] = unpack(field_to_pattern['A3'], currentData)[0] begin = end end = calcsize(field_to_pattern['A4']) + begin currentData = data[begin:end] a_begin = end b = {} begin = unpack(field_to_pattern['A4'], currentData)[0] end = begin + calcsize(field_to_pattern['B1']) currentData = data[begin:end] b['B1'] = unpack(field_to_pattern['B1'], currentData)[0].decode('utf-8') begin = end end = begin + calcsize(field_to_pattern['B2']) currentData = data[begin:end] b['B2'] = unpack(field_to_pattern['B2'], currentData)[0] result['A4'] = b begin = a_begin (currentData, end) = get_current_data_and_end(data, begin, 'A5s') c_arr_size = unpack(field_to_pattern['A5s'], currentData)[0] begin = end (currentData, end) = get_current_data_and_end(data, begin, 'A5a') c_arr_address = unpack(field_to_pattern['A5a'], currentData)[0] a_begin = end begin = c_arr_address c_addresses = [] for i in range(c_arr_size): (currentData, end) = get_current_data_and_end(data, begin, 'Ca') c_addr = unpack(field_to_pattern['Ca'], currentData)[0] c_addresses.append(c_addr) begin = end c_structures = [] for c_addr in c_addresses: c_struct = {} begin = set_field_with_returning_end(data, c_addr, 'C1', c_struct) begin = set_field_with_returning_end(data, begin, 'C2', c_struct) begin = set_field_with_returning_end(data, begin, 'C3', c_struct) c_structures.append(c_struct) result['A5'] = c_structures begin = a_begin begin = set_field_with_returning_end(data, begin, 'A6', result) d = {} begin = set_field_with_returning_end(data, begin, 'D1', d) d_begin = begin e = {} begin = d['D1'] begin = set_field_with_returning_end(data, begin, 'E1', e) begin = set_field_with_returning_end(data, begin, 'E2', e) begin = set_field_with_returning_end(data, begin, 'E3', e) begin = set_field_with_returning_end(data, begin, 'E4', e) int_arr = [] for i in range(7): end = begin + calcsize('>b') currentData = data[begin:end] int_arr.append(unpack('b', currentData)[0]) begin = end e['E5'] = int_arr d['D1'] = e begin = d_begin begin = set_field_with_returning_end(data, begin, 'D2', d) begin = set_field_with_returning_end(data, begin, 'D3', d) begin = set_field_with_returning_end(data, begin, 'D4', d) begin = set_field_with_returning_end(data, begin, 'D5', d) f = {} begin = set_field_with_returning_end(data, begin, 'F1', f) begin = set_field_with_returning_end(data, begin, 'F2', f) begin = set_field_with_returning_end(data, begin, 'F3', f) d['D6'] = f begin = set_field_with_returning_end(data, begin, 'D7', d) arr_size = d['D7'] begin = set_field_with_returning_end(data, begin, 'D7', d) arr_address = d['D7'] arr = [] d_begin = begin begin = arr_address for i in range(arr_size): end = begin + calcsize('>h') currentData = data[begin:end] element = unpack('>h', currentData)[0] arr.append(element) begin = end d['D7'] = arr begin = d_begin begin = set_field_with_returning_end(data, begin, 'D8', d) g_start = d['D8'] g = {} begin = g_start begin = set_field_with_returning_end(data, begin, 'G1', g) begin = set_field_with_returning_end(data, begin, 'G2', g) arr_size = g['G2'] begin = set_field_with_returning_end(data, begin, 'G2', g) arr_address = g['G2'] g_begin = begin begin = arr_address arr = [] for i in range(arr_size): end = begin + calcsize('>b') currentData = data[begin:end] element = unpack('>b', currentData)[0] arr.append(element) begin = end g['G2'] = arr begin = g_begin begin = set_field_with_returning_end(data, begin, 'G3', g) d['D8'] = g result['A7'] = d return result" "import struct def main(address): new_dict = {} string = '=5xb3IL3IHdbbbdbdhBbbbdbdhBbbbdbdhBb' string += 'Q' * address[22] + 'd' * address[30] new_struct = struct.unpack(string, address) new_dict['A1'] = new_struct[0] new_dict['A2'] = [{}, {}, {}] new_dict['A2'][0]['B1'] = new_struct[11] new_dict['A2'][0]['B2'] = [{}, {}] new_dict['A2'][0]['B2'][0]['C1'] = new_struct[12] new_dict['A2'][0]['B2'][0]['C2'] = new_struct[13] new_dict['A2'][0]['B2'][1]['C1'] = new_struct[14] new_dict['A2'][0]['B2'][1]['C2'] = new_struct[15] new_dict['A2'][0]['B3'] = new_struct[16] new_dict['A2'][0]['B4'] = new_struct[17] new_dict['A2'][0]['B5'] = new_struct[18] new_dict['A2'][1]['B1'] = new_struct[19] new_dict['A2'][1]['B2'] = [{}, {}] new_dict['A2'][1]['B2'][0]['C1'] = new_struct[20] new_dict['A2'][1]['B2'][0]['C2'] = new_struct[21] new_dict['A2'][1]['B2'][1]['C1'] = new_struct[22] new_dict['A2'][1]['B2'][1]['C2'] = new_struct[23] new_dict['A2'][1]['B3'] = new_struct[24] new_dict['A2'][1]['B4'] = new_struct[25] new_dict['A2'][1]['B5'] = new_struct[26] new_dict['A2'][2]['B1'] = new_struct[27] new_dict['A2'][2]['B2'] = [{}, {}] new_dict['A2'][2]['B2'][0]['C1'] = new_struct[28] new_dict['A2'][2]['B2'][0]['C2'] = new_struct[29] new_dict['A2'][2]['B2'][1]['C1'] = new_struct[30] new_dict['A2'][2]['B2'][1]['C2'] = new_struct[31] new_dict['A2'][2]['B3'] = new_struct[32] new_dict['A2'][2]['B4'] = new_struct[33] new_dict['A2'][2]['B5'] = new_struct[34] new_dict['A3'] = new_struct[4] new_dict['A4'] = {'D1': [], 'D2': []} new_dict['A4']['D1'] = [i for i in new_struct[35:35 + address[22]]] new_dict['A4']['D2'] = [i for i in new_struct[35 + address[22]:]] new_dict['A5'] = new_struct[9] new_dict['A6'] = new_struct[10] return new_dict" "import struct def funcA(p): r = dict() r['A1'] = struct.unpack('B', p[3:4])[0] a2size = struct.unpack('h', p[4:6])[0] a2addr = struct.unpack('h', p[6:8])[0] t = struct.unpack(str(a2size) + 's', p[a2addr:a2addr + a2size])[0].decode() r['A2'] = t baddr = struct.unpack('h', p[8:10])[0] r['A3'] = funcB(p, baddr) r['A4'] = struct.unpack('i', p[10:14])[0] a5size = struct.unpack('h', p[14:16])[0] a5addr = struct.unpack('I', p[16:20])[0] r['A5'] = list(struct.unpack(str(a5size) + 'b', p[a5addr:a5addr + a5size])) r['A6'] = funcE(p[20:]) return r def funcB(p, baddr): r = dict() r['B1'] = struct.unpack('I', p[baddr:baddr + 4])[0] r['B2'] = struct.unpack('q', p[baddr + 4:baddr + 12])[0] caddrlist = struct.unpack('4I', p[baddr + 12:baddr + 28]) r['B3'] = list() for caddr in caddrlist: r['B3'].append(funcC(p, caddr)) r['B4'] = funcD(p, baddr + 28) return r def funcC(p, caddr): r = dict() r['C1'] = list(struct.unpack('6b', p[caddr:caddr + 6])) r['C2'] = struct.unpack('i', p[caddr + 6:caddr + 10])[0] return r def funcD(p, daddr): r = dict() r['D1'] = struct.unpack('f', p[daddr:daddr + 4])[0] d2size = struct.unpack('H', p[daddr + 4:daddr + 6])[0] d2addr = struct.unpack('H', p[daddr + 6:daddr + 8])[0] r['D2'] = list(struct.unpack(str(d2size) + 'b', p[d2addr:d2addr + d2size])) return r def funcE(p): r = dict() r['E1'] = struct.unpack('B', p[:1])[0] r['E2'] = struct.unpack('B', p[1:2])[0] r['E3'] = struct.unpack('Q', p[2:10])[0] r['E4'] = struct.unpack('Q', p[10:18])[0] return r def main(pack): return funcA(pack)" "import struct def main(data): start_A = 4 a = struct.unpack_from('>fdi3I', data, start_A) (len_b, start_B) = (a[3], a[4]) start_E = a[5] Bs = [] for i in range(len_b): Bs.append(struct.unpack_from('>Q2IQHB', data, start_B)) start_B += struct.calcsize('>Q2IQHB') starts_C = [] D = [] for b in Bs: temp_d = {} temp_d.setdefault('D1', b[3]) temp_d.setdefault('D2', b[4]) D.append(temp_d) starts_C.append(b[1]) Cs = [] for start_C in starts_C: Cs.append(struct.unpack_from('>3B3H2If', data, start_C)) mas16 = [] for c in Cs: mas16.append(struct.unpack_from('>{}H'.format(c[6]), data, c[7])) C = [] for i in range(len(Cs)): temp_c = {} temp_c.setdefault('C1', list(Cs[i][0:3])) temp_c.setdefault('C2', list(Cs[i][3:6])) temp_c.setdefault('C3', list(mas16[i])) temp_c.setdefault('C4', Cs[i][-1]) C.append(temp_c) Es = struct.unpack_from('>dHIqfH', data, start_E) B = [] for i in range(len(Bs)): temp_b = {} temp_b.setdefault('B1', Bs[i][0]) temp_b.setdefault('B2', C[i]) temp_b.setdefault('B3', Bs[i][2]) temp_b.setdefault('B4', D[i]) temp_b.setdefault('B5', Bs[i][5]) B.append(temp_b) E = {'E1': Es[0], 'E2': Es[1], 'E3': Es[2], 'E4': Es[3], 'E5': Es[4], 'E6': Es[5]} A = {'A1': a[0], 'A2': a[1], 'A3': a[2], 'A4': B, 'A5': E} return A" "def give_bits_of_number(n): result = [] for i in range(8): result.append(n % 2) n //= 2 result.reverse() return result def give_bits_of_number_advanced(n): result = [] while n != 0: result.append(n % 2) n //= 2 result.reverse() return result def from_bytes_to_bits(b): result = [] for e in b: bits_of_number = give_bits_of_number(e) for bit in bits_of_number: result.append(bit) return result def bits_into_signed_number(b): sign = b[0] result = 0 for i in range(1, len(b)): result *= 2 if sign == 0: result += b[i] else: result += 1 - b[i] result *= 1 if sign == 0 else -1 result -= 0 if sign == 0 else 1 return result def bits_into_unsigned_number(b): result = 0 for i in range(len(b)): result *= 2 result += b[i] return result def bits_into_float(b): sign = b[0] exponent = b[1:9] mantis = b[9:] power = bits_into_unsigned_number(exponent) - 127 result = 1 * 2 ** power for i in range(len(mantis)): result += mantis[i] * 2 ** (power - i - 1) result *= 1 if sign == 0 else -1 return result def get_slice(x, start, length): return x[start * 8:(start + length) * 8] def create_c_structure_array(x, length, address): result = [] for i in range(length): result.append(create_c_structure(x, address + i * 2)) return result def create_char_array(x, length, address): result = '' for i in range(length): result += chr(bits_into_unsigned_number(get_slice(x, address + i, 1))) return result def create_int_array(x, length, address): result = [] for i in range(length): result.append(bits_into_unsigned_number(get_slice(x, address + i * 4, 4))) return result def create_b_structure(x, address): result = dict() result['B1'] = bits_into_unsigned_number(get_slice(x, address, 8)) result['B2'] = bits_into_signed_number(get_slice(x, address + 8, 4)) result['B3'] = create_char_array(x, 5, address + 12) result['B4'] = create_c_structure_array(x, bits_into_unsigned_number(get_slice(x, address + 17, 2)), bits_into_unsigned_number(get_slice(x, address + 19, 4))) return result def create_c_structure(x, address): result = dict() result['C1'] = bits_into_signed_number(get_slice(x, address, 1)) result['C2'] = bits_into_unsigned_number(get_slice(x, address + 1, 1)) return result def create_d_structure(x, address): result = dict() result['D1'] = bits_into_signed_number(get_slice(x, address, 1)) result['D2'] = bits_into_float(get_slice(x, address + 1, 4)) result['D3'] = bits_into_signed_number(get_slice(x, address + 5, 8)) result['D4'] = bits_into_signed_number(get_slice(x, address + 13, 4)) result['D5'] = bits_into_unsigned_number(get_slice(x, address + 17, 2)) result['D6'] = bits_into_signed_number(get_slice(x, address + 19, 2)) result['D7'] = bits_into_signed_number(get_slice(x, address + 21, 1)) return result def main(b): x = from_bytes_to_bits(b) result = dict() result['A1'] = create_b_structure(x, bits_into_unsigned_number(get_slice(x, 5, 2))) result['A2'] = create_char_array(x, bits_into_unsigned_number(get_slice(x, 7, 4)), bits_into_unsigned_number(get_slice(x, 11, 4))) result['A3'] = bits_into_signed_number(get_slice(x, 15, 4)) result['A4'] = create_d_structure(x, bits_into_unsigned_number(get_slice(x, 19, 2))) result['A5'] = bits_into_signed_number(get_slice(x, 21, 2)) result['A6'] = bits_into_unsigned_number(get_slice(x, 23, 1)) result['A7'] = create_int_array(x, 6, 24) return result a1 = b'\xdeIBNP\x004\x00\x00\x00\x06\x00\x00\x00K\xdf\xb0\xca\x15\x00Q\x0fw\xcc\x0e\xb4?\xb1\xa2J\x19\xc3D\xa1r\xa0\x969;\x12\x18p\xdamt\x00\xb4#\xf2\x0b\x05\xa8\xbc\xf9\x9e\xda\xd2v\x05\xbf\xc40\x8d\x03yayhu\x00\x02\x00\x00\x000nepvzy\xc7\xbf/\xe2\xf1\x90\x8c\xbd\xdb\xack?\xa4C9\xcf|\x1dO\x8fc\x14' a2 = b'\xdeIBNP\x004\x00\x00\x00\x06\x00\x00\x00K\xf1\x06\x13\x14\x00Q\xaa\x1f\x80\xa5\xde\x814\xffoV\xcbI\xf6\x9b6\xb5\xb26\x9c\xfa\t+G\xc6_\x11G\xde)\xce\x8fI]\x97""\xca\xc1\x97\t\x9c:\x1cIH', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{f1[0]}B', data[f1[1]:f1[1] + f1[0]])) d2 = struct.unpack('>I', data[pointer + 6:pointer + 6 + 4])[0] f3 = struct.unpack('>HH', data[pointer + 10:pointer + 10 + 4]) d3 = list(struct.unpack(f'>{f3[0]}I', data[f3[1]:f3[1] + f3[0] * 4])) d4 = list(struct.unpack(f'>4h', data[pointer + 14:pointer + 14 + 4 * 2])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): return {'C1': struct.unpack('>b', data[pointer:pointer + 1])[0], 'C2': struct.unpack('>h', data[pointer + 1:pointer + 3])[0]} def parse_b(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) b1 = list() for i in range(f1[0]): b1.append(parse_c(data, f1[1] + i * 3)) (b2, b3) = struct.unpack('>iH', data[pointer + 6:pointer + 12]) f4 = struct.unpack('>I', data[pointer + 12:pointer + 16]) b4 = parse_d(data, f4[0]) (b5, b6, b7, b8) = struct.unpack('>dQif', data[pointer + 16:pointer + 16 + 24]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def parse_a(data, pointer): a1 = ''.join([c.decode(encoding='ascii') for c in struct.unpack('>8c', data[pointer:pointer + 8])]) a2 = parse_b(data, pointer + 8) return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 5)" "from struct import unpack def main(data): d = 'BIdHIf' c = 'qiIHIqq{D}IHQ'.replace('{D}', d) b = 'bh' a = '>xxxxH{B}{B}{B}{B}{B}hii{C}'.replace('{B}', b).replace('{C}', c) obj = unpack(a, data[:106]) (array_size, array_addr) = (obj[24], obj[25]) array = [] for i in range(array_size): array.append(unpack('>h', data[array_addr:array_addr + 2])[0]) array_addr += 2 D = {'D1': obj[21], 'D2': obj[22], 'D3': obj[23], 'D4': array, 'D5': obj[26]} (char_size, char_addr) = (obj[17], obj[18]) format = '>' + str(char_size) + 's' char = unpack(format, data[char_addr:char_addr + char_size]) (array1_size, array1_addr) = (obj[27], obj[28]) array1 = [] for i in range(array1_size): array1.append(unpack('>H', data[array1_addr:array1_addr + 2])[0]) array1_addr += 2 C = {'C1': obj[14], 'C2': obj[15], 'C3': obj[16], 'C4': char[0].decode('utf-8'), 'C5': [obj[19], obj[20]], 'C6': D, 'C7': array1, 'C8': obj[-1]} A = {'A1': obj[0], 'A2': [], 'A3': obj[11], 'A4': obj[12], 'A5': obj[13], 'A6': C} start = 1 for i in range(5): B = {'B1': obj[start], 'B2': obj[start + 1]} A['A2'].append(B) start = start + 2 return A" "from struct import unpack def main(data): d = '>hIHI' c = 'HIiiiiii' b = 'HbQI' a = '>xxxxb3s{B}B{C}h'.replace('{B}', b).replace('{C}', c) obj = unpack(a, data[:56]) C = {'C1': [], 'C2': [obj[9], obj[10], obj[11], obj[12], obj[13], obj[14]]} (d_size, d_addr) = (obj[7], obj[8]) for i in range(d_size): index = d_addr + i * 12 d_obj = unpack(d, data[index:index + 12]) (arr_size, arr_addr) = (d_obj[1], d_obj[2]) arr_obj = [] for i in range(arr_size): arr_index = arr_addr + i * 4 arr_obj.append(unpack('>i', data[arr_index:arr_index + 4])[0]) D = {'D1': d_obj[0], 'D2': arr_obj, 'D3': d_obj[3]} C['C1'].append(D) B = {'B1': obj[2], 'B2': obj[3], 'B3': obj[4], 'B4': obj[5]} A = {'A1': obj[0], 'A2': obj[1].decode('utf-8'), 'A3': B, 'A4': obj[6], 'A5': C, 'A6': obj[-1]} return A" "import struct as st now = 5 passed = 0 def D(a): global now D = {} new_now = st.unpack('IHQq', b[:al]) a1 = (aa[0], aa[1]) a2 = aa[2] a3 = aa[3] cl = al + 6 cc = s.unpack('>HHh', b[al:cl]) c1 = cc[0] c2 = cc[1] c3 = cc[2] al2 = cl + 20 aa2 = s.unpack('>IIqI', b[cl:al2]) aa5 = (aa2[0], aa2[1]) a6 = aa2[2] a7 = aa2[3] a5l = aa5[0] a5d = aa5[1] - off a5 = s.unpack(f'>{a5l}s', b[a5d:a5d + a5l])[0] bar = [] bal = s.calcsize('>H') bsz = a1[0] bad = a1[1] - off ba = s.unpack(f'>{bsz}H', b[bad:bad + bsz * bal]) bln = s.calcsize('>IHHd') for i in ba: j = i - off bb = s.unpack('>IHHd', b[j:j + bln]) arl = bb[1] ard = bb[2] - off ss = s.unpack(f'>{arl}s', b[ard:ard + arl])[0] bar.append((bb, ss)) da = a7 - off dl = s.calcsize('HIB') dd = s.unpack('>HIB', b[da:da + dl]) d2 = dd[2] drs = dd[0] drd = dd[1] - off drl = s.calcsize('b') dar = s.unpack(f'>{drs}b', b[drd:drd + drs * drl]) c = {'A1': [], 'A2': a2, 'A3': a3, 'A4': {'C1': c1, 'C2': c2, 'C3': c3}, 'A5': str(a5)[2:-1], 'A6': a6, 'A7': {'D1': [], 'D2': d2}} for i in bar: c.get('A1').append({'B1': i[0][0], 'B2': str(i[1])[2:-1], 'B3': i[0][3]}) for i in dar: c.get('A7').get('D1').append(i) return c" "from struct import unpack def main(file): a_adr = 4 a = {f'A{i}': None for i in range(1, 5)} a['A1'] = unpack('>f', file[a_adr:a_adr + 4])[0] c = 'ibi' d = 'I8iiiI2bh' e = 'bfhHH' b = f'>i{c}H{d}{d}{e}Iiq' off = 146 res = unpack(b, file[a_adr + 4:a_adr + off + 4]) le = unpack(f'<{res[38]}B', file[res[39]:res[39] + res[38]]) a['A2'] = {'B1': res[0], 'B2': {'C1': res[1], 'C2': res[2], 'C3': res[3]}, 'B3': res[4], 'B4': [{'D1': res[5], 'D2': [res[6], res[7], res[8], res[9], res[10], res[11], res[12], res[13]], 'D3': res[14], 'D4': res[15], 'D5': res[16], 'D6': [res[17], res[18]], 'D7': res[19]}, {'D1': res[20], 'D2': [res[21], res[22], res[23], res[24], res[25], res[26], res[27], res[28]], 'D3': res[29], 'D4': res[30], 'D5': res[31], 'D6': [res[32], res[33]], 'D7': res[34]}], 'B5': {'E1': res[35], 'E2': res[36], 'E3': res[37], 'E4': list(le)}, 'B6': res[40], 'B7': res[41], 'B8': res[42]} a['A3'] = unpack('>H', file[a_adr + off + 4:a_adr + off + 4 + 2])[0] a['A4'] = unpack('>q', file[a_adr + off + 2 + 4:a_adr + off + 2 + 4 + 8])[0] return a" "import struct as s def main(data): B1 = s.unpack('H', data[address:address + 2])[0], 'D2': struct.unpack('>H', data[address + 2:address + 4])[0], 'D3': struct.unpack('>B', data[address + 4:address + 5])[0]} def read_e_structure(data, address): return {'E1': struct.unpack('>h', data[address:address + 2])[0], 'E2': struct.unpack('>d', data[address + 2:address + 10])[0], 'E3': struct.unpack('>h', data[address + 10:address + 12])[0], 'E4': list(struct.unpack('>4I', data[address + 12:address + 28])), 'E5': list(struct.unpack('>5i', data[address + 28:address + 48])), 'E6': struct.unpack('>f', data[address + 48:address + 52])[0], 'E7': struct.unpack('>f', data[address + 52:address + 56])[0], 'E8': struct.unpack('>d', data[address + 56:address + 64])[0]} def read_c_structure(data, address): c2_upk = data[address + 8:address + 10] return {'C1': struct.unpack('>d', data[address:address + 8])[0], 'C2': read_d_structure(data, struct.unpack('>H', c2_upk)[0]), 'C3': struct.unpack('>H', data[address + 10:address + 12])[0], 'C4': struct.unpack('>q', data[address + 12:address + 20])[0], 'C5': read_e_structure(data, address + 20), 'C6': struct.unpack('>H', data[address + 84:address + 86])[0], 'C7': struct.unpack('>q', data[address + 86:address + 94])[0], 'C8': struct.unpack('>H', data[address + 94:address + 96])[0]} def read_b_structure(data, address): b1_upk = data[address:address + 4] return {'B1': struct.unpack('>4s', b1_upk)[0].decode('ascii'), 'B2': struct.unpack('>H', data[address + 4:address + 6])[0]} def main(data): a1 = [] for b_index in range(0, 5): a1.append(read_b_structure(data, 4 + b_index * 6)) a2 = struct.unpack('>d', data[34:42])[0] a3 = read_c_structure(data, struct.unpack('>H', data[42:44])[0]) out_dict = {'A1': a1, 'A2': a2, 'A3': a3} return out_dict" "from struct import * class A: def __init__(self, address): self.address = address self.f = '<3IidH' self.b_obj = [] self.par_2 = 0 self.par_3 = 0.0 self.c_obj = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.b_obj = [B(tmp[0]), B(tmp[1]), B(tmp[2])] for b in self.b_obj: b.set(inp) self.par_2 = tmp[3] self.par_3 = tmp[4] address_c = tmp[5] self.c_obj = C(address_c) self.c_obj.set(inp) def __dict__(self): return {'A1': [x.__dict__() for x in self.b_obj], 'A2': self.par_2, 'A3': self.par_3, 'A4': self.c_obj.__dict__()} class B: def __init__(self, address): self.address = address self.f = '2IQ') c2 = C(self.address) self.c_obj.append(c2) c2.set(inp) self.address += calcsize('>2IQ') self.f = '>7sIH5hQ' s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_3 = str(tmp[0]) self.par_3 = self.par_3[2:len(self.par_3) - 1] self.par_4 = get_list(inp, tmp[1], tmp[2], 'uint64') self.par_5 = list(tmp[3:8]) self.par_6 = tmp[8] def __dict__(self): return {'A1': self.b_obj.__dict__(), 'A2': [x.__dict__() for x in self.c_obj], 'A3': self.par_3, 'A4': self.par_4, 'A5': self.par_5, 'A6': self.par_6} class B: def __init__(self, address): self.address = address self.f = '>bBQHh' self.B1 = 0 self.B2 = 0 self.B3 = 0 self.B4 = 0 self.B5 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.B1 = tmp[0] self.B2 = tmp[1] self.B3 = tmp[2] self.B4 = tmp[3] self.B5 = tmp[4] def __dict__(self): return {'B1': self.B1, 'B2': self.B2, 'B3': self.B3, 'B4': self.B4, 'B5': self.B5} class C: def __init__(self, address): self.address = address self.f = '>2IQ' self.par_1 = 0 self.d_obj = 0 self.par_3 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] self.d_obj = D(tmp[1]) self.d_obj.set(inp) self.par_3 = tmp[2] def __dict__(self): return {'C1': self.par_1, 'C2': self.d_obj.__dict__(), 'C3': self.par_3} class D: def __init__(self, address): self.address = address self.f = '>bHIfi2Qf' self.D1 = 0 self.D2 = 0 self.D3 = 0.0 self.D4 = 0 self.D5 = 0 self.D6 = 0 self.D7 = 0.0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.D1 = tmp[0] self.D2 = get_list(inp, tmp[1], tmp[2], 'int8') self.D3 = tmp[3] self.D4 = tmp[4] self.D5 = tmp[5] self.D6 = tmp[6] self.D7 = tmp[7] def __dict__(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3, 'D4': self.D4, 'D5': self.D5, 'D6': self.D6, 'D7': self.D7} def get_list(inp, size, address, t): type_names = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char': 's'} mask = '>%d%s' % (size, type_names[t]) s = address + calcsize(mask) return list(unpack(mask, inp[address:s])) def main(inp: bin): a = A(3) a.set(inp) return a.__dict__()" "import struct def main(data): A = {} (*s, A1_uint32_size, A1_uint32_adress, A2_int8, A3_uint16_adress_B) = struct.unpack_from('<4cIIbH', data) A1_str = struct.unpack_from(str(A1_uint32_size) + 's', data, offset=A1_uint32_adress) A['A1'] = A1_str[0].decode('UTF-8') A['A2'] = A2_int8 (B1, B2, B3) = struct.unpack_from('q5sb', data, offset=A3_uint16_adress_B) A['A3'] = {'B1': B1, 'B2': B2.decode('UTF-8'), 'B3': B3} structs_C = struct.unpack_from('QqQqQqQqQq', data, offset=15) list_C = [{'C1': C1, 'C2': C2} for (C1, C2) in zip(structs_C[::2], structs_C[1::2])] A['A4'] = list_C (*D, A6_uint64) = struct.unpack_from('<7B8HhQ', data, offset=95) (D1, D2, D3) = (D[:7], D[7:15], D[-1]) A['A5'] = {'D1': list(D1), 'D2': list(D2), 'D3': D3} A['A6'] = A6_uint64 return A" "import struct def main(bytes): e_struct = struct.Struct('>HIHH8B3d') d_struct = struct.Struct('>QQd') c_struct = struct.Struct('>II') b_struct = struct.Struct(f'>qIqB7s2H{e_struct.size}s') a_struct = struct.Struct(f'>fh{b_struct.size}sQ') res = dict() a = a_struct.unpack_from(bytes, 3) res['A1'] = a[0] res['A2'] = a[1] b = b_struct.unpack_from(a[2]) b_res = dict() b_res['B1'] = b[0] c = c_struct.unpack_from(bytes, b[1]) c_res = dict() c_res['C1'] = c[0] c_res['C2'] = c[1] b_res['B2'] = c_res b_res['B3'] = b[2] b_res['B4'] = b[3] b_res['B5'] = b[4].decode('utf-8') arr_struct = struct.Struct(f'>{b[5]}I') arr = arr_struct.unpack_from(bytes, b[6]) d_res = list() for i in arr: d_dict = dict() d = d_struct.unpack_from(bytes, i) d_dict['D1'] = d[0] d_dict['D2'] = d[1] d_dict['D3'] = d[2] d_res.append(d_dict) b_res['B6'] = d_res e = e_struct.unpack_from(b[7]) e_res = dict() e_res['E1'] = e[0] e_res['E2'] = e[1] e_res['E3'] = e[2] e_res['E4'] = e[3] e_arr1 = list() for i in range(4, 12): e_arr1.append(e[i]) e_res['E5'] = e_arr1 e_arr2 = list() for i in range(12, 15): e_arr2.append(e[i]) e_res['E6'] = e_arr2 b_res['B7'] = e_res res['A3'] = b_res res['A4'] = a[3] return res" "import struct def main(data): arrSizeA = struct.unpack_from('>I', data, offset=115)[0] arrSizeD = struct.unpack_from('>I', data, offset=122)[0] arrA = list(struct.unpack_from('>' + str(arrSizeA) + 'i', data, offset=128)) arrD = list(struct.unpack_from('>' + str(arrSizeD) + 'i', data, offset=128 + arrSizeA * 4)) r = struct.unpack_from('>HiBQfqqiBQfqqfIBqbBIBqbBIiIHBIH' + str(arrSizeA + arrSizeD) + 'i', data, offset=5) return {'A1': r[0], 'A2': [{'B1': {'C1': r[1], 'C2': r[2], 'C3': r[3]}, 'B2': r[4], 'B3': r[5], 'B4': r[6]}, {'B1': {'C1': r[7], 'C2': r[8], 'C3': r[9]}, 'B2': r[10], 'B3': r[11], 'B4': r[12]}], 'A3': r[13], 'A4': {'D1': [{'E1': r[14], 'E2': r[15], 'E3': r[16], 'E4': r[17], 'E5': r[18]}, {'E1': r[19], 'E2': r[20], 'E3': r[21], 'E4': r[22], 'E5': r[23]}], 'D2': r[24], 'D3': r[25], 'D4': arrA}, 'A5': r[28], 'A6': arrD}" "import struct def main(data): struct_d = struct.Struct('>BIQ') struct_c = struct.Struct('>5Hbd') struct_b = struct.Struct('>3si2H2H') struct_a = struct.Struct(f'>{struct_b.size}sdih3IBH') res = dict() a = struct_a.unpack_from(data, 5) dict_b = dict() b = struct_b.unpack_from(a[0]) dict_b['B1'] = b[0].decode('utf-8') dict_b['B2'] = b[1] arr1_struct = struct.Struct(f'>{b[2]}H') arr1 = arr1_struct.unpack_from(data, b[3]) c_list = list() for i in arr1: c_dict = dict() c = struct_c.unpack_from(data, i) c1_tmp = list() for j in range(0, 5): c1_tmp.append(c[j]) c_dict['C1'] = c1_tmp c_dict['C2'] = c[5] c_dict['C3'] = c[6] c_list.append(c_dict) dict_b['B3'] = c_list arr2_struct = struct.Struct(f'>{b[4]}f') arr2 = arr2_struct.unpack_from(data, b[5]) b4_list = list() for i in arr2: b4_list.append(i) dict_b['B4'] = b4_list res['A1'] = dict_b res['A2'] = a[1] res['A3'] = a[2] res['A4'] = a[3] a5_list = list() for i in range(4, 7): a5_list.append(a[i]) res['A5'] = a5_list res['A6'] = a[7] dict_d = dict() d = struct_d.unpack_from(data, a[8]) dict_d['D1'] = d[0] dict_d['D2'] = d[1] dict_d['D3'] = d[2] res['A7'] = dict_d return res" "import struct def main(data): ans = {'A1': '', 'A2': {'B1': '', 'B2': {'C1': '', 'C2': ''}, 'B3': '', 'B4': ''}, 'A3': '', 'A4': '', 'A5': '', 'A6': ''} data1 = data[5:] a = 66 b = 16 c = 6 d = 15 a_str = data1[0:a] obj = struct.unpack('>HHQQQ8Ifh', a_str) adress_a1 = obj[1] size_a1 = obj[0] ans['A1'] = data1[adress_a1 - 5:adress_a1 - 5 + size_a1].decode('utf-8') ans['A3'] = obj[4] ans['A5'] = obj[-2] ans['A6'] = obj[-1] ans['A2']['B1'] = obj[2] b2 = struct.unpack('>H5cB', struct.pack('>Q', obj[3])) ans['A2']['B3'] = (b2[1] + b2[2] + b2[3] + b2[4] + b2[5]).decode('utf-8') ans['A2']['B4'] = b2[-1] adress_c = b2[0] struct_c = struct.unpack('>HI', data1[adress_c - 5:adress_c - 5 + c]) ans['A2']['B2']['C1'] = struct_c[0] ans['A2']['B2']['C2'] = struct_c[1] adress_d = obj[5:13] d_list = [] for i in range(8): d_dict = {'D1': 0, 'D2': 0, 'D3': [0, 0, 0, 0, 0, 0, 0], 'D4': 0} d_res = data1[adress_d[i] - 5:adress_d[i] - 5 + d] d_res = struct.unpack('>HH7BI', d_res) d_dict['D1'] = d_res[0] d_dict['D2'] = d_res[1] d_dict['D3'] = list(d_res[2:9]) d_dict['D4'] = d_res[-1] d_list.append(d_dict) ans['A4'] = d_list return ans" "import struct def main(x): address_struct_B = struct.unpack('>H', x[3:5])[0] B1 = str(struct.unpack('>6s', x[address_struct_B:address_struct_B + 6]))[3:9] address_struct_C = struct.unpack('>H', x[address_struct_B + 6:address_struct_B + 8])[0] D1 = struct.unpack('>d', x[address_struct_C:address_struct_C + 8])[0] D2_list_len = struct.unpack('>2L', x[address_struct_C + 8:address_struct_C + 16])[0] D2_list_address = struct.unpack('>2L', x[address_struct_C + 8:address_struct_C + 16])[1] D2 = list(struct.unpack('>' + str(D2_list_len) + 'f', x[D2_list_address:D2_list_address + D2_list_len * 4])) D3 = struct.unpack('>b', x[address_struct_C + 16:address_struct_C + 17])[0] D4 = struct.unpack('>b', x[address_struct_C + 17:address_struct_C + 18])[0] D5 = struct.unpack('>f', x[address_struct_C + 18:address_struct_C + 22])[0] D6 = struct.unpack('>B', x[address_struct_C + 22:address_struct_C + 23])[0] C2 = struct.unpack('>L', x[address_struct_C + 23:address_struct_C + 27])[0] C3 = struct.unpack('>Q', x[address_struct_C + 27:address_struct_C + 35])[0] B3 = struct.unpack('>h', x[address_struct_B + 8:address_struct_B + 10])[0] E1_1 = struct.unpack('>H', x[5:7])[0] E1_2_len = struct.unpack('>IH', x[7:13])[0] E1_2_address = struct.unpack('>IH', x[7:13])[1] E1_2 = list(struct.unpack('>' + str(E1_2_len) + 'h', x[E1_2_address:E1_2_address + E1_2_len * 2])) E2_1 = struct.unpack('>H', x[13:15])[0] E2_2_len = struct.unpack('>IH', x[15:21])[0] E2_2_address = struct.unpack('>IH', x[15:21])[1] E2_2 = list(struct.unpack('>' + str(E2_2_len) + 'h', x[E2_2_address:E2_2_address + E2_2_len * 2])) slov_D = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5, 'D6': D6} slov_C = {'C1': slov_D, 'C2': C2, 'C3': C3} slov_B = {'B1': B1, 'B2': slov_C, 'B3': B3} slov_E_1 = {'E1': E1_1, 'E2': E1_2} slov_E_2 = {'E1': E2_1, 'E2': E2_2} t = [] t.append(slov_E_1) t.append(slov_E_2) slov_A = {'A1': slov_B, 'A2': t} return slov_A" "import struct def funcA(p): r = dict() r['A1'] = struct.unpack('>q', p[4:12])[0] r['A2'] = struct.unpack('>d', p[12:20])[0] r['A3'] = funcB(p, 20) s = struct.unpack('>H', p[42:44])[0] a = struct.unpack('>H', p[44:46])[0] r['A4'] = '' for i in range(s): r['A4'] += struct.unpack('>' + str(s) + 'c', p[a:a + s])[0].decode() a += 1 r['A5'] = struct.unpack('>B', p[46:47])[0] caddr = struct.unpack('>I', p[47:51])[0] t1 = funcC(p, caddr) caddr = struct.unpack('>I', p[51:55])[0] t2 = funcC(p, caddr) caddr = struct.unpack('>I', p[55:59])[0] t3 = funcC(p, caddr) r['A6'] = [t1, t2, t3] r['A7'] = funcD(p, 59) r['A8'] = list(struct.unpack('>' + str(3) + 'B', p[76:79])) return r def funcB(p, index): r = dict() r['B1'] = struct.unpack('>b', p[index:index + 1])[0] r['B2'] = struct.unpack('>i', p[index + 1:index + 5])[0] r['B3'] = struct.unpack('>d', p[index + 5:index + 13])[0] a4size = struct.unpack('>L', p[index + 13:index + 17])[0] a4adrr = struct.unpack('>L', p[index + 17:index + 21])[0] r['B4'] = list(struct.unpack('>' + str(a4size) + 'H', p[a4adrr:a4adrr + a4size * 2])) r['B5'] = struct.unpack('>b', p[index + 21:index + 22])[0] return r def funcC(p, index): r = dict() r['C1'] = struct.unpack('>I', p[index:index + 4])[0] r['C2'] = struct.unpack('>h', p[index + 4:index + 6])[0] r['C3'] = struct.unpack('>B', p[index + 6:index + 7])[0] r['C4'] = struct.unpack('>Q', p[index + 7:index + 15])[0] return r def funcD(p, index): r = dict() r['D1'] = struct.unpack('>L', p[index:index + 4])[0] size = struct.unpack('>L', p[index + 4:index + 8])[0] adrr = struct.unpack('>L', p[index + 8:index + 12])[0] r['D2'] = list(struct.unpack('>' + str(size) + 'Q', p[adrr:adrr + size * 8])) r['D3'] = struct.unpack('>i', p[index + 12:index + 16])[0] r['D4'] = struct.unpack('>b', p[index + 16:index + 17])[0] return r def main(pack): return funcA(pack)" "import struct def main(data): A = struct.unpack_from('>IfbdHHIIIHI', data, offset=4) A5 = list(struct.unpack_from('>' + str(A[4]) + 'c', data, offset=A[5])) for i in range(len(A5)): A5[i] = A5[i].decode('utf-8') A5 = ''.join(A5) A6 = list(struct.unpack_from('>' + str(A[6]) + 'i', data, offset=A[7])) A7 = list(struct.unpack_from('>' + str(A[8]) + 'b', data, offset=A[9])) B = struct.unpack_from('>fHIQ', data, offset=A[0]) C = struct.unpack_from('>HIIHHIB', data, offset=B[2]) C1 = struct.unpack_from('>' + str(C[0]) + 'I', data, offset=C[1]) C2 = list(struct.unpack_from('>' + str(C[2]) + 'q', data, offset=C[3])) D = [] for i in range(len(C1)): tempTuple = struct.unpack_from('>bqH', data, offset=C1[i]) tempDict = {} for j in range(len(tempTuple)): tempDict['D' + str(j + 1)] = tempTuple[j] D.append(tempDict) return {'A1': {'B1': B[0], 'B2': B[1], 'B3': {'C1': D, 'C2': C2, 'C3': C[4], 'C4': C[5], 'C5': C[6]}, 'B4': B[3]}, 'A2': A[1], 'A3': A[2], 'A4': A[3], 'A5': A5, 'A6': A6, 'A7': A7, 'A8': A[10]}" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.uint32) b2 = reader.read(Types.double) return dict(B1=b1, B2=b2) def readC(reader): c1 = reader.read(Types.double) c2 = reader.read(Types.uint8) c3 = reader.read(Types.int8) c4 = reader.read(Types.uint8) c5 = readD(reader.copy(reader.read(Types.uint16))) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def readD(reader): d1 = reader.read(Types.float) d2 = reader.read(Types.int8) d3 = reader.read(Types.int64) size4 = reader.read(Types.uint32) adress4 = reader.read(Types.uint32) d4 = reader.copy(offset=adress4).readWithSize(Types.int8, size4) d5 = reader.read(Types.double) d6 = reader.read(Types.float) d7 = reader.read(Types.double) d8 = reader.readWithSize(Types.uint16, 6) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8) def readE(reader): e1 = reader.read(Types.float) e2 = reader.read(Types.uint64) e3 = reader.read(Types.uint32) e4 = reader.read(Types.int32) return dict(E1=e1, E2=e2, E3=e3, E4=e4) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = readB(BinaryReader(offset=reader.read(Types.uint16), buffer=buffer)) a2 = reader.read(Types.uint16) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint16) tempA3 = reader.copy(adress3).readWithSize(Types.char, size3) a3 = b''.join(tempA3).decode('ASCII') a4 = reader.read(Types.uint16) a5 = reader.read(Types.int8) size6 = reader.read(Types.uint16) adress6 = reader.read(Types.uint16) a6 = [] cReader = BinaryReader(offset=adress6, buffer=buffer) for i in range(0, size6): a6.append(readC(cReader)) adress7 = reader.read(Types.uint32) a7 = readE(reader.copy(offset=adress7)) a8 = reader.readWithSize(Types.uint8, 3) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "import struct def structD(data: bytes): uint16Arr = [] for i in range(0, 4, 1): (a,) = struct.unpack('>H', data[44 + i * 2:44 + (i + 1) * 2]) uint16Arr.append(a) (ui32_1,) = struct.unpack('>I', data[52:56]) (uint64,) = struct.unpack('>Q', data[56:64]) (uint8,) = struct.unpack('>B', data[64:65]) (ui32_2,) = struct.unpack('>I', data[65:69]) return {'D1': uint16Arr, 'D2': ui32_1, 'D3': uint64, 'D4': uint8, 'D5': ui32_2} def structC(data: bytes, address: int): buff = address (int64_1,) = struct.unpack('>q', data[buff:buff + 8]) buff += 8 (int64_2,) = struct.unpack('>q', data[buff:buff + 8]) buff += 8 (int32,) = struct.unpack('>i', data[buff:buff + 4]) buff += 4 int32Arr = [] for i in range(0, 4, 1): (a,) = struct.unpack('>i', data[buff + i * 4:buff + (i + 1) * 4]) int32Arr.append(a) buff += 16 (double,) = struct.unpack('>d', data[buff:buff + 8]) return {'C1': int64_1, 'C2': int64_2, 'C3': int32, 'C4': int32Arr, 'C5': double} def structB(data: bytes): (float,) = struct.unpack('>f', data[8:12]) (uint64,) = struct.unpack('>Q', data[12:20]) charArr = '' for i in range(0, 5, 1): (a,) = struct.unpack('>c', data[20 + i:21 + i]) charArr += chr(a[0]) (uint8,) = struct.unpack('>B', data[25:26]) (int16,) = struct.unpack('>h', data[26:28]) return {'B1': float, 'B2': uint64, 'B3': charArr, 'B4': uint8, 'B5': int16} def structA(data: bytes): (int32,) = struct.unpack('>i', data[4:8]) strB = structB(data) charArr = '' for i in range(0, 3, 1): (a,) = struct.unpack('>c', data[28 + i:29 + i]) charArr += chr(a[0]) (int64,) = struct.unpack('>q', data[31:39]) (ui16CStructAdress_1,) = struct.unpack('>H', data[39:41]) (ui16CStructAdress_2,) = struct.unpack('>H', data[41:43]) structCArray = [] structCArray.append(structC(data, ui16CStructAdress_1)) structCArray.append(structC(data, ui16CStructAdress_2)) (uint8,) = struct.unpack('>B', data[43:44]) strD = structD(data) (int8,) = struct.unpack('>b', data[69:70]) return {'A1': int32, 'A2': strB, 'A3': charArr, 'A4': int64, 'A5': structCArray, 'A6': uint8, 'A7': strD, 'A8': int8} def main(bytesSequence): return structA(bytesSequence)" "import struct SIGNATURE = bytes([83, 76, 77, 239]) ORDER = '<' def get_array_pattern(size, type_s): pattern = ORDER + type_s * size return pattern def calcsize(pattern): return struct.calcsize(ORDER + pattern) def create_dict(name: str, structure: tuple) -> dict: dictionary = dict() for i in range(len(structure)): dictionary.update({name + str(i + 1): structure[i]}) return dictionary def f(byte_str: bytes) -> dict: begin = byte_str.find(SIGNATURE) assert begin >= 0 A_pattern = 'IhHbIIIB' B_pattern = 'iI5sdH' C_pattern = 'h%dsHIqII' D_pattern = 'iHI' C_pattern = C_pattern % calcsize(D_pattern) A_pos = [begin + len(SIGNATURE), begin + len(SIGNATURE) + calcsize(A_pattern)] A = struct.unpack(ORDER + A_pattern, byte_str[A_pos[0]:A_pos[1]]) B_pos = [A[0], A[0] + calcsize(B_pattern)] B = struct.unpack(ORDER + B_pattern, byte_str[B_pos[0]:B_pos[1]]) B = create_dict('B', B) B['B3'] = B['B3'].decode() elem_size = 2 C_addr_arr_size = A[5] C_addr_arr_pos = [A[6], A[6] + elem_size * C_addr_arr_size] C_addr_arr = struct.unpack(ORDER + 'H' * C_addr_arr_size, byte_str[C_addr_arr_pos[0]:C_addr_arr_pos[1]]) Cs = list() for i in range(C_addr_arr_size): C = struct.unpack(ORDER + C_pattern, byte_str[C_addr_arr[i]:C_addr_arr[i] + calcsize(C_pattern)]) D = struct.unpack(ORDER + D_pattern, C[1]) ushortD_arr_size = D[1] elem_size = 2 ushortD_arr_pos = (D[2], D[2] + elem_size * ushortD_arr_size) ushortD_arr = struct.unpack(ORDER + 'H' * ushortD_arr_size, byte_str[ushortD_arr_pos[0]:ushortD_arr_pos[1]]) D = create_dict('D', [D[0], list(ushortD_arr)]) byte_arr_size = C[2] byte_elem_size = 1 byte_arr_pos = (C[3], C[3] + byte_elem_size * byte_arr_size) byte_arr = struct.unpack(ORDER + 'b' * byte_arr_size, byte_str[byte_arr_pos[0]:byte_arr_pos[1]]) ushort_arr_size = C[5] ushort_elem_size = 2 ushort_arr_pos = (C[6], C[6] + ushort_elem_size * ushort_arr_size) ushort_arr = struct.unpack(ORDER + 'H' * ushort_arr_size, byte_str[ushort_arr_pos[0]:ushort_arr_pos[1]]) Cs.append(create_dict('C', [C[0], D, list(byte_arr), C[4], list(ushort_arr)])) A = create_dict('A', [B, A[1], A[2], A[3], A[4], Cs, A[7]]) return A def main(x): return f(x)" "import struct import pprint import re def parse_e(data, pointer): e1 = struct.unpack('>B', data[pointer:pointer + 1])[0] f2 = struct.unpack('>II', data[pointer + 1:pointer + 9]) e2 = list(struct.unpack(f'>{f2[0]}H', data[f2[1]:f2[1] + f2[0] * 2])) return {'E1': e1, 'E2': e2} def parse_d(data, pointer): d1 = struct.unpack('>I', data[pointer:pointer + 4])[0] f2 = struct.unpack('>IH', data[pointer + 4:pointer + 10]) d2 = list(struct.unpack(f'>{f2[0]}H', data[f2[1]:f2[1] + 4])) (d3, d4) = struct.unpack('>dB', data[pointer + 10:pointer + 19]) d5 = parse_e(data, pointer + 19) d6 = struct.unpack('>B', data[pointer + 28:pointer + 29])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): (c1, c2) = struct.unpack('>ff', data[pointer:pointer + 8]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) b1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + 2]))) b1 = b1.replace(""'"", '') b1 = b1[1::2] b2 = parse_c(data, pointer + 4) (b3, b4) = struct.unpack('>HI', data[pointer + 12:pointer + 18]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>7I', data[pointer:pointer + 28]) a1 = list() for i in range(7): a1.append(parse_b(data, f1[i])) (a2, a3) = struct.unpack('>hI', data[pointer + 28:pointer + 34]) a4 = parse_d(data, pointer + 34) a5 = struct.unpack('>Q', data[pointer + 63:pointer + 71])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "import struct def A(inp, offset): size = 17 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>IfB3HH', buffer) ans = {} ans['A1'] = B(inp, res[0]) ans['A2'] = res[1] ans['A3'] = res[2] ans['A4'] = [E(inp, res[3]), E(inp, res[4]), E(inp, res[5])] ans['A5'] = F(inp, res[6]) return ans def B(inp, offset): ans = {} ans['B1'] = C(inp, offset) offset = offset + 11 size = 26 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>iidbbII', buffer) ans['B2'] = res[0] ans['B3'] = res[1] ans['B4'] = res[2] ans['B5'] = res[3] ans['B6'] = res[4] tmp = [] for i in range(0, res[5]): tmp.append(D(inp, res[6] + i * 16)) ans['B7'] = tmp return ans def C(inp, offset): ans = {} size = 11 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>BHIf', buffer) ans['C1'] = res[0] tmp = '' for i in range(0, res[1]): buffer = inp[res[2] + i:] buffer = buffer[:1] tmp += struct.unpack('>c', buffer)[0].decode('UTF-8') ans['C2'] = tmp ans['C3'] = res[3] return ans def D(inp, offset): ans = {} size = 16 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>QQ', buffer) ans['D1'] = res[0] ans['D2'] = res[1] return ans def E(inp, offset): ans = {} size = 8 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>fI', buffer) ans['E1'] = res[0] ans['E2'] = res[1] return ans def F(inp, offset): ans = {} size = 52 buffer = inp[offset:] buffer = buffer[:size] res = struct.unpack('>7ffh5Hq', buffer) ans['F1'] = [res[0], res[1], res[2], res[3], res[4], res[5], res[6]] ans['F2'] = res[7] ans['F3'] = res[8] ans['F4'] = [res[9], res[10], res[11], res[12], res[13]] ans['F5'] = res[14] return ans def main(data): return A(data, 4)" "import struct def main(data): f_st = struct.Struct('H', data[pointer:pointer + 2])[0], 'D2': struct.unpack('>d', data[pointer + 2:pointer + 10])[0]} def parse_c(data, pointer): return {'C1': struct.unpack('>B', data[pointer:pointer + 1])[0], 'C2': list(struct.unpack(f'>8b', data[pointer + 1:pointer + 9])), 'C3': struct.unpack('>Q', data[pointer + 9:pointer + 17])[0], 'C4': struct.unpack('>H', data[pointer + 17:pointer + 19])[0], 'C5': struct.unpack('>B', data[pointer + 19:pointer + 20])[0]} def parse_b(data, pointer): b1 = list() for i in range(3): b1.append(parse_c(data, pointer + i * 20)) b2 = parse_d(data, pointer + 60) b3 = struct.unpack('>b', data[pointer + 70:pointer + 71])[0] return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): a1 = ''.join(map(str, struct.unpack('>6c', data[pointer:pointer + 6]))) a1 = a1.replace(""'"", '') a1 = a1[1::2] a2 = struct.unpack('>f', data[pointer + 6:pointer + 10])[0] a3 = parse_b(data, pointer + 10) f4 = struct.unpack('>HH', data[pointer + 81:pointer + 85]) a4 = list(struct.unpack(f'>{f4[0]}i', data[f4[1]:f4[1] + f4[0] * 4])) a5 = struct.unpack('>q', data[pointer + 85:pointer + 93])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "import struct def main(bytes): f_struct = struct.Struct('>3hbq') e_struct = struct.Struct('>dQ') d_struct = struct.Struct('>ih3I') c_struct = struct.Struct('>Bh') b_struct = struct.Struct(f'>I3IfHI{e_struct.size}s') a_struct = struct.Struct(f'>HqqI{f_struct.size}s3iid') res = dict() a = a_struct.unpack_from(bytes, 4) b_dict = dict() b = b_struct.unpack_from(bytes, a[0]) b_dict['B1'] = b[0] c_list = list() for i in range(3): c_dict = dict() c = c_struct.unpack_from(bytes, b[i + 1]) c_dict['C1'] = c[0] c_dict['C2'] = c[1] c_list.append(c_dict) b_dict['B2'] = c_list b_dict['B3'] = b[4] b_dict['B4'] = b[5] d_dict = dict() d = d_struct.unpack_from(bytes, b[6]) d_dict['D1'] = d[0] d_dict['D2'] = d[1] d_dict['D3'] = [d[2], d[3], d[4]] b_dict['B5'] = d_dict e_dict = dict() e = e_struct.unpack_from(b[7]) e_dict['E1'] = e[0] e_dict['E2'] = e[1] b_dict['B6'] = e_dict res['A1'] = b_dict res['A2'] = a[1] res['A3'] = a[2] res['A4'] = a[3] f_dict = dict() f = f_struct.unpack_from(a[4]) f_dict['F1'] = [f[0], f[1], f[2]] f_dict['F2'] = f[3] f_dict['F3'] = f[4] res['A5'] = f_dict res['A6'] = [a[5], a[6], a[7]] res['A7'] = a[8] res['A8'] = a[9] return res" "import struct def main(data): d_struct = struct.Struct('>2bI') c_struct = struct.Struct('>if') b_struct = struct.Struct(f'>{c_struct.size * 5}sd2IQQQHI') a_struct = struct.Struct('>dI8I') res = dict() a = a_struct.unpack_from(data, 4) res['A1'] = a[0] b_dict = dict() b = b_struct.unpack_from(data, a[1]) c_list = list() for i in range(5): c_dict = dict() c = c_struct.unpack_from(b[0], c_struct.size * i) c_dict['C1'] = c[0] c_dict['C2'] = c[1] c_list.append(c_dict) b_dict['B1'] = c_list b_dict['B2'] = b[1] arr_struct = struct.Struct(f'>{b[2]}H') arr = arr_struct.unpack_from(data, b[3]) d_list = list() for i in arr: d_dict = dict() d = d_struct.unpack_from(data, i) d_dict['D1'] = [d[0], d[1]] d_dict['D2'] = d[2] d_list.append(d_dict) b_dict['B3'] = d_list b_dict['B4'] = b[4] b_dict['B5'] = b[5] b_dict['B6'] = b[6] b_dict['B7'] = b[7] b_dict['B8'] = b[8] res['A2'] = b_dict res['A3'] = [a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]] return res" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('>Ii', data[pointer:pointer + 8]) f3 = struct.unpack('>HH', data[pointer + 8:pointer + 12]) e3 = list(struct.unpack(f'>{f3[0]}H', data[f3[1]:f3[1] + f3[0] * 2])) (e4, e5) = struct.unpack('>fQ', data[pointer + 12:pointer + 24]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def parse_d(data, pointer): (d1, d2) = struct.unpack('>iI', data[pointer:pointer + 8]) (d3, d4) = struct.unpack('>fd', data[pointer + 8:pointer + 20]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) c1 = parse_d(data, f1[0]) (c2, c3) = struct.unpack('>qQ', data[pointer + 4:pointer + 20]) c4 = parse_e(data, pointer + 20) c5 = list(struct.unpack('>3f', data[pointer + 44:pointer + 56])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = ''.join(map(str, struct.unpack('>8c', data[pointer:pointer + 8]))) b1 = b1.replace(""'"", '') b1 = b1[1::2] (b2, b3) = struct.unpack('>ih', data[pointer + 8:pointer + 14]) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) f2 = struct.unpack('>H', data[pointer + 2:pointer + 4]) a1 = list() a1.append(parse_b(data, f1[0])) a1.append(parse_b(data, f2[0])) a2 = parse_c(data, pointer + 4) return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_e(data, pointer): e1 = struct.unpack('>B', data[pointer:pointer + 1])[0] e2 = list(struct.unpack('>8i', data[pointer + 1:pointer + 33])) e3 = struct.unpack('>Q', data[pointer + 33:pointer + 41])[0] e4 = struct.unpack('>i', data[pointer + 41:pointer + 45])[0] return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def parse_d(data, pointer): d1 = list(struct.unpack('>5f', data[pointer:pointer + 20])) d2 = struct.unpack('>f', data[pointer + 20:pointer + 24]) return {'D1': d1, 'D2': d2[0]} def parse_c(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) c1 = parse_d(data, f1[0]) c2 = struct.unpack('>d', data[pointer + 2:pointer + 10])[0] f3 = struct.unpack('>HH', data[pointer + 10:pointer + 14]) c3 = list(struct.unpack(f'>{f3[0]}I', data[f3[1]:f3[1] + f3[0] * 4])) (c4, c5, c6) = struct.unpack('>hqQ', data[pointer + 14:pointer + 32]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): b1 = struct.unpack('>B', data[pointer:pointer + 1]) b2 = ''.join(map(str, struct.unpack('>3c', data[pointer + 1:pointer + 4]))) b2 = b2.replace(""'"", '') b2 = b2[1::2] b3 = struct.unpack('>b', data[pointer + 4:pointer + 5]) return {'B1': b1[0], 'B2': b2, 'B3': b3[0]} def parse_a(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) a1 = list() for i in range(f1[0]): f2 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) a1.append(parse_b(data, f2[0])) (a2, a3) = struct.unpack('>qH', data[pointer + 6:pointer + 16]) f4 = struct.unpack('>I', data[pointer + 16:pointer + 20]) a4 = parse_c(data, f4[0]) (a5, a6) = struct.unpack('>Hf', data[pointer + 20:pointer + 26]) f7 = struct.unpack('>I', data[pointer + 26:pointer + 30]) a7 = parse_e(data, f7[0]) a8 = struct.unpack('>I', data[pointer + 30:pointer + 34]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8[0]} def main(data): return parse_a(data, 5)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def parse_A(data, ofs): (C1, ofs) = parse('int8', data, ofs) (C2, ofs) = parse('uint16', data, ofs) (C3, ofs) = parse('uint32', data, ofs) (D1, C3) = parse('int64', data, C3) (D2, C3) = parse('uint32', data, C3) C3 = dict(D1=D1, D2=D2) (C4, ofs) = parse('uint32', data, ofs) (E1, C4) = parse('int8', data, C4) (F1, C4) = parse('uint16', data, C4) (F2, C4) = parse('uint16', data, C4) E2 = dict(F1=F1, F2=F2) E3 = [] for i in range(3): (h, C4) = parse('float', data, C4) E3.append(h) (E4, C4) = parse('uint32', data, C4) (E5, C4) = parse('float', data, C4) C4 = dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5) (C5, ofs) = parse('uint8', data, ofs) C = dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5) (B2, ofs) = parse('uint16', data, ofs) (B3_size, ofs) = parse('uint32', data, ofs) (B3_adr, ofs) = parse('uint32', data, ofs) B3 = [] G = [] for i in range(B3_size): (G1_size, B3_adr) = parse('uint32', data, B3_adr) (G1_adr, B3_adr) = parse('uint16', data, B3_adr) G1 = [] for i in range(G1_size): (b, G1_adr) = parse('int8', data, G1_adr) G1.append(b) (G2_size, B3_adr) = parse('uint32', data, B3_adr) (G2_adr, B3_adr) = parse('uint16', data, B3_adr) G2 = [] for i in range(G2_size): (b, G2_adr) = parse('int8', data, G2_adr) G2.append(b) (G3, B3_adr) = parse('double', data, B3_adr) (G4, B3_adr) = parse('int64', data, B3_adr) B3.append(dict(G1=G1, G2=G2, G3=G3, G4=G4)) (B4, ofs) = parse('double', data, ofs) A1 = dict(B1=C, B2=B2, B3=B3, B4=B4) (A2, ofs) = parse('uint32', data, ofs) (A3, ofs) = parse('uint8', data, ofs) (A4, ofs) = parse('float', data, ofs) (A5, ofs) = parse('int16', data, ofs) (A6, ofs) = parse('uint32', data, ofs) (H1, A6) = parse('uint32', data, A6) (H2, A6) = parse('uint32', data, A6) (H3, A6) = parse('uint16', data, A6) (H4, A6) = parse('int64', data, A6) A6 = dict(H1=H1, H2=H2, H3=H3, H4=H4) (A7, ofs) = parse('int64', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7) def main(data): return parse_A(data, 3)" "import struct def main(x): a1 = struct.unpack('H', x[3:5])[0] B1 = struct.unpack('>q', x[addr_B:addr_B + 8])[0] len_B2 = struct.unpack('>2L', x[addr_B + 8:addr_B + 16])[0] addr_B2 = struct.unpack('>2L', x[addr_B + 8:addr_B + 16])[1] B2 = str(struct.unpack('>' + str(len_B2) + 's', x[addr_B2:addr_B2 + len_B2]))[3:3 + len_B2] B3 = struct.unpack('>H', x[addr_B + 16:addr_B + 18])[0] B4 = struct.unpack('>H', x[addr_B + 18:addr_B + 20])[0] B5 = struct.unpack('>B', x[addr_B + 20:addr_B + 21])[0] B6 = struct.unpack('>B', x[addr_B + 21:addr_B + 22])[0] C1_D1_1 = struct.unpack('>f', x[5:9])[0] C1_D2_1 = struct.unpack('>B', x[9:10])[0] C1_D3_1 = struct.unpack('>Q', x[10:18])[0] C1_D4_1 = struct.unpack('>H', x[18:20])[0] C1_D1_2 = struct.unpack('>f', x[20:24])[0] C1_D2_2 = struct.unpack('>B', x[24:25])[0] C1_D3_2 = struct.unpack('>Q', x[25:33])[0] C1_D4_2 = struct.unpack('>H', x[33:35])[0] C2 = struct.unpack('>f', x[35:39])[0] A3 = struct.unpack('>q', x[39:47])[0] A4_len = struct.unpack('>H', x[47:49])[0] A4_addr = struct.unpack('>L', x[49:53])[0] A4 = str(struct.unpack('>' + str(A4_len) + 's', x[A4_addr:A4_addr + A4_len])[0])[2:2 + A4_len] A5_len = struct.unpack('>L', x[53:57])[0] A5_addr = struct.unpack('>H', x[57:59])[0] A5 = list(struct.unpack('>' + str(A5_len) + 'L', x[A5_addr:A5_addr + 4 * A5_len])) A6 = struct.unpack('>f', x[59:63])[0] A7 = struct.unpack('>i', x[63:67])[0] slov_B = {'B1': B1, 'B2': B2, 'B3': B3, 'B4': B4, 'B5': B5, 'B6': B6} slov_D_1 = {'D1': C1_D1_1, 'D2': C1_D2_1, 'D3': C1_D3_1, 'D4': C1_D4_1} slov_D_2 = {'D1': C1_D1_2, 'D2': C1_D2_2, 'D3': C1_D3_2, 'D4': C1_D4_2} t = [] t.append(slov_D_1) t.append(slov_D_2) slov_C = {'C1': t, 'C2': C2} slov_A = {'A1': slov_B, 'A2': slov_C, 'A3': A3, 'A4': A4, 'A5': A5, 'A6': A6, 'A7': A7} return slov_A" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) ""\ndef parse_A(data, ofs):\n C1, ofs = parse('int8', data, ofs)\n C2, ofs = parse('uint16', data, ofs)\n C3, ofs = parse('uint32', data, ofs)\n D1, C3 = parse('int64', data, C3)\n D2, C3 = parse('uint32', data, C3)\n C3 = dict(D1=D1, D2=D2)\n C4, ofs = parse('uint32', data, ofs)\n E1, C4 = parse('int8', data, C4)\n F1, C4 = parse('uint16', data, C4)\n F2, C4 = parse('uint16', data, C4)\n E2 = dict(F1=F1, F2=F2)\n E3 = []\n for i in range(3):\n h, C4 = parse('float', data, C4)\n E3.append(h)\n E4, C4 = parse('uint32', data, C4)\n E5, C4 = parse('float', data, C4)\n C4 = dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5)\n C5, ofs = parse('uint8', data, ofs)\n C = dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5)\n B2, ofs = parse('uint16', data, ofs)\n B3_size, ofs = parse('uint32', data, ofs)\n B3_adr, ofs = parse('uint32', data, ofs)\n B3 = []\n G = []\n for i in range(B3_size):\n G1_size, B3_adr = parse('uint32', data, B3_adr)\n G1_adr, B3_adr = parse('uint16', data, B3_adr)\n G1 = []\n for i in range(G1_size):\n b, G1_adr = parse('int8', data, G1_adr)\n G1.append(b)\n\n G2_size, B3_adr = parse('uint32', data, B3_adr)\n G2_adr, B3_adr = parse('uint16', data, B3_adr)\n G2 = []\n for i in range(G2_size):\n b, G2_adr = parse('int8', data, G2_adr)\n G2.append(b)\n G3, B3_adr = parse('double', data, B3_adr)\n G4, B3_adr = parse('int64', data, B3_adr)\n B3.append(dict(G1=G1, G2=G2, G3=G3, G4=G4))\n\n B4, ofs = parse('double', data, ofs)\n A1 = dict(B1=C, B2=B2, B3=B3, B4=B4)\n A2, ofs = parse('uint32', data, ofs)\n A3, ofs = parse('uint8', data, ofs)\n A4, ofs = parse('float', data, ofs)\n A5, ofs = parse('int16', data, ofs)\n A6, ofs = parse('uint32', data, ofs)\n H1, A6 = parse('uint32', data, A6)\n H2, A6 = parse('uint32', data, A6)\n H3, A6 = parse('uint16', data, A6)\n H4, A6 = parse('int64', data, A6)\n return dict(\n A1=A1,\n A2=A2,\n A3=A3,\n A4=A4,\n A5=A5\n )\n"" def parse_A(data, ofs): (A1_size, ofs) = parse('uint32', data, ofs) (A1_adr, ofs) = parse('uint32', data, ofs) s = '' for _ in range(A1_size): (g, A1_adr) = parse('char', data, A1_adr) s += g.decode() A1 = s (A2_adr, ofs) = parse('uint16', data, ofs) (B1, A2_adr) = parse('uint64', data, A2_adr) (B2_size, A2_adr) = parse('uint16', data, A2_adr) (B2_adr, A2_adr) = parse('uint32', data, A2_adr) C = [] for i in range(B2_size): (u, B2_adr) = parse('uint32', data, B2_adr) k = u C1 = [] for _ in range(3): (d, k) = parse('int16', data, k) C1.append(d) (C2, k) = parse('uint64', data, k) (C3, k) = parse('float', data, k) C.append(dict(C1=C1, C2=C2, C3=C3)) B2 = C (B3, A2_adr) = parse('uint16', data, A2_adr) (D1, B3) = parse('int8', data, B3) (D2, B3) = parse('uint8', data, B3) (D3, B3) = parse('uint8', data, B3) (D4, B3) = parse('int8', data, B3) B3 = dict(D1=D1, D2=D2, D3=D3, D4=D4) (B4, A2_adr) = parse('uint16', data, A2_adr) A2 = dict(B1=B1, B2=B2, B3=B3, B4=B4) (A3, ofs) = parse('uint8', data, ofs) (A4, ofs) = parse('double', data, ofs) (A5_adr, ofs) = parse('uint16', data, ofs) (E1, A5_adr) = parse('uint32', data, A5_adr) E2 = [] for _ in range(7): (l, A5_adr) = parse('float', data, A5_adr) E2.append(l) (E3_size, A5_adr) = parse('uint32', data, A5_adr) (E3_adr, A5_adr) = parse('uint16', data, A5_adr) E3 = [] for i in range(E3_size): (j, E3_adr) = parse('uint8', data, E3_adr) E3.append(j) (E4, A5_adr) = parse('uint32', data, A5_adr) (E5, A5_adr) = parse('double', data, A5_adr) (E6, A5_adr) = parse('float', data, A5_adr) A5 = dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5) def main(data): return parse_A(data, 5)" "import struct def parse_array(data, size, typ, offset): n = struct.calcsize(typ) return list(struct.unpack(f'<{size}{typ}', data[offset:offset + size * n])) def parse_array_struct_c(data, size, offset): arr = list() for count in range(size): arr.append(parse_c(data, offset + count * 12)) return arr def parse_d(data, offset): d1 = parse_array(data, 2, 'b', offset) d2 = struct.unpack('3\xe7A>\x1d\xa8\n\xbf\x01\xbe\xc8\xbe\xa3\x976\xbf/\xab_?@\xa8e\xbf\x17\x0e\xd4<\x9e\x00\x00\x00,e\x8b\\\xeb+\x16\x1fojhlgt\x05\x00\x81\x00\x00\x005*\x1c\xbd\x8e\xb1\x91.GV\xb2=\xa0\x06\xc8\xdc\xa9\xb8\xce\\\xc4Qn\xb4\xc1\xf7\xdd\xda\nbL\xd0:\x93' main(inp_1)" "import struct from struct import * def main(data): res = dict() b_struct = struct.Struct('d6fqHI') c_struct = struct.Struct('HqHHqib') d_struct = struct.Struct('2HihBH') a_struct = struct.Struct(f'{arr_len}{type}', data[offset:offset + arr_len * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = parse_array(data, offset, 'B', 3) result['D2'] = struct.unpack('>d', data[offset + 3:offset + 3 + 8])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>Q', data[offset:offset + 8])[0] result['C2'] = parse_array(data, offset + 8, 'h', 2) result['C3'] = struct.unpack('>i', data[offset + 12:offset + 12 + 4])[0] result['C4'] = struct.unpack('>h', data[offset + 16:offset + 16 + 2])[0] result['C5'] = struct.unpack('>i', data[offset + 18:offset + 18 + 4])[0] return result def parse_b(data, offset): result = dict() result['B1'] = parse_c(data, offset) result['B2'] = struct.unpack('>b', data[offset + 22:offset + 22 + 1])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>I', data[offset:offset + 4])[0] (a2_size, a2_addr) = struct.unpack('>IH', data[offset + 4:offset + 4 + 6]) a2_b_addrs = parse_array(data, a2_addr, 'H', a2_size) result['A2'] = [parse_b(data, addr) for addr in a2_b_addrs] result['A3'] = ''.join([x.decode('ascii') for x in parse_array(data, offset + 10, 'c', 3)]) result['A4'] = parse_d(data, struct.unpack('>I', data[offset + 13:offset + 13 + 4])[0]) result['A5'] = struct.unpack('>I', data[offset + 17:offset + 17 + 4])[0] result['A6'] = struct.unpack('>Q', data[offset + 21:offset + 21 + 8])[0] result['A7'] = struct.unpack('>b', data[offset + 29:offset + 29 + 1])[0] return result def main(data): return parse_a(data, 5)" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() (d1_size, d1_addr) = struct.unpack('>HI', data[offset:offset + 6]) result['D1'] = parse_array(data, d1_addr, 'B', d1_size) result['D2'] = parse_array(data, offset + 6, 'd', 5) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['C2'] = struct.unpack('>I', data[offset + 1:offset + 1 + 4])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['B2'] = parse_c(data, offset + 1) result['B3'] = struct.unpack('>i', data[offset + 6:offset + 6 + 4])[0] result['B4'] = struct.unpack('>H', data[offset + 10:offset + 10 + 2])[0] result['B5'] = struct.unpack('>b', data[offset + 12:offset + 12 + 1])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>q', data[offset:offset + 8])[0] result['A2'] = ''.join([c.decode() for c in parse_array(data, offset + 8, 'c', 6)]) (a3_size, a3_addr) = struct.unpack('>HI', data[offset + 14:offset + 14 + 6]) b_addrs = parse_array(data, a3_addr, 'H', a3_size) result['A3'] = [parse_b(data, addr) for addr in b_addrs] (result['A4'], result['A5'], result['A6'], result['A7']) = struct.unpack('>HbiB', data[offset + 20:offset + 20 + 8]) result['A8'] = parse_d(data, offset + 28) return result def main(data): return parse_a(data, 4)" "import struct def main(x): result = {} result['A1'] = struct.unpack('xxx' + gen_a() def main(arg): d = type_dict total = gen_total() obj = unpack(total, arg[:59]) a_dict = {'A1': {'B1': {'C1': obj[0], 'C2': obj[1], 'C3': obj[2], 'C4': obj[3], 'C5': []}, 'B2': obj[6], 'B3': obj[7], 'B4': obj[8], 'B5': []}, 'A2': obj[11], 'A3': obj[12], 'A4': [], 'A5': obj[15]} first_c_struct_c5_size = obj[4] first_c_struct_c5_addr = obj[5] first_c_struct_c5_total = '>' + first_c_struct_c5_size * gen_d() first_c_struct_c5 = unpack(first_c_struct_c5_total, arg[first_c_struct_c5_addr:first_c_struct_c5_addr + 62]) second_c5_struct_c7_size = first_c_struct_c5[11] second_c5_struct_c7_addr = first_c_struct_c5[12] second_c5_struct_c7_total = '>' + second_c5_struct_c7_size * d['int8'] second_c5_struct_c7_c2 = unpack(second_c5_struct_c7_total, arg[second_c5_struct_c7_addr:second_c5_struct_c7_addr + second_c5_struct_c7_size]) listOf = [] for i in range(second_c5_struct_c7_size): listOf.append(second_c5_struct_c7_c2[i]) third_c_struct_c2_size = first_c_struct_c5[24] third_c_struct_c2_addr = first_c_struct_c5[25] third_c_struct_c2_total = '>' + third_c_struct_c2_size * d['int8'] third_c_struct_c2_c2 = unpack(third_c_struct_c2_total, arg[third_c_struct_c2_addr:third_c_struct_c2_addr + third_c_struct_c2_size]) listOfof = [] for i in range(third_c_struct_c2_size): listOfof.append(third_c_struct_c2_c2[i]) d_dict = {'D1': first_c_struct_c5[0], 'D2': first_c_struct_c5[1], 'D3': first_c_struct_c5[2], 'D4': [first_c_struct_c5[3], first_c_struct_c5[4], first_c_struct_c5[5], first_c_struct_c5[6], first_c_struct_c5[7], first_c_struct_c5[8]], 'D5': first_c_struct_c5[9], 'D6': first_c_struct_c5[10], 'D7': listOf} d2_dict = {'D1': first_c_struct_c5[13], 'D2': first_c_struct_c5[14], 'D3': first_c_struct_c5[15], 'D4': [first_c_struct_c5[16], first_c_struct_c5[17], first_c_struct_c5[18], first_c_struct_c5[19], first_c_struct_c5[20], first_c_struct_c5[21]], 'D5': first_c_struct_c5[22], 'D6': first_c_struct_c5[23], 'D7': listOfof} a_dict['A1']['B1']['C5'].append(d_dict) a_dict['A1']['B1']['C5'].append(d2_dict) first_b_struct_size = obj[9] first_b_struct_addr = obj[10] first_b_struct_c2_total = '>' + first_b_struct_size * d['float'] first_b_struct_c2 = unpack(first_b_struct_c2_total, arg[first_b_struct_addr:first_b_struct_addr + first_b_struct_size * 4]) listOf = [] for i in range(first_b_struct_size): listOf.append(first_b_struct_c2[i]) a_dict['A1']['B5'] = listOf first_a_struct_size = obj[13] first_a_struct_addr = obj[14] first_a_struct_c2_total = '>' + first_a_struct_size * d['int16'] first_a_struct_c2 = unpack(first_a_struct_c2_total, arg[first_a_struct_addr:first_a_struct_addr + first_a_struct_size * 4]) listOf = [] for i in range(first_a_struct_size): listOf.append(first_a_struct_c2[i]) a_dict['A4'] = listOf return a_dict" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3) = struct.unpack('>hBI', data[pointer:pointer + 7]) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>Bbh', data[pointer:pointer + 4]) f4 = struct.unpack('>HI', data[pointer + 4:pointer + 10]) d4 = list(struct.unpack(f'>{f4[0]}h', data[f4[1]:f4[1] + f4[0] * 2])) (d5, d6) = struct.unpack('>IH', data[pointer + 10:pointer + 16]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) c1 = list(struct.unpack(f'>{f1[0]}B', data[f1[1]:f1[1] + f1[0]])) c2 = struct.unpack('>Q', data[pointer + 8:pointer + 16])[0] f3 = struct.unpack('>HH', data[pointer + 16:pointer + 20]) c3 = list(struct.unpack(f'>{f3[0]}q', data[f3[1]:f3[1] + f3[0] * 8])) c4 = struct.unpack('>I', data[pointer + 20:pointer + 24])[0] f5 = struct.unpack('>H', data[pointer + 24:pointer + 26]) c5 = parse_d(data, f5[0]) c6 = struct.unpack('>h', data[pointer + 26:pointer + 28])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>hBH', data[pointer:pointer + 5]) f4 = struct.unpack('>II', data[pointer + 5:pointer + 13]) b4 = ''.join(map(str, struct.unpack(f'>{f4[0]}c', data[f4[1]:f4[1] + f4[0] * 1]))) b4 = b4.replace(""'"", '') b4 = b4[1::2] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): a1 = struct.unpack('>H', data[pointer:pointer + 2])[0] a2 = list() for i in range(7): a2.append(parse_b(data, pointer + 2 + i * 13)) pointer1 = pointer + 2 + i * 13 a3 = struct.unpack('>H', data[pointer1 + 13:pointer1 + 15])[0] a4 = parse_c(data, pointer1 + 15) a5 = struct.unpack('>Q', data[pointer1 + 43:pointer1 + 51])[0] f6 = struct.unpack('>H', data[pointer1 + 51:pointer1 + 53]) a6 = parse_e(data, f6[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 4)" "import struct def parse_array(data, size, typ, offset): n = struct.calcsize(typ) return list(struct.unpack(f'>{size}{typ}', data[offset:offset + size * n])) def parse_array_struct_b(data, size, offset): arr = list() for count in range(size): arr.append(parse_b(data, offset + count * 51)) return arr def parse_d(data, offset): d1 = parse_array(data, 3, 'b', offset) d2 = struct.unpack('>B', data[offset + 3:offset + 3 + 1])[0] d3 = struct.unpack('>B', data[offset + 4:offset + 4 + 1])[0] d4 = struct.unpack('>i', data[offset + 5:offset + 5 + 4])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, offset): c1 = struct.unpack('>d', data[offset:offset + 8])[0] c2 = struct.unpack('>B', data[offset + 8:offset + 8 + 1])[0] c3 = struct.unpack('>i', data[offset + 9:offset + 9 + 4])[0] c4 = struct.unpack('>f', data[offset + 13:offset + 13 + 4])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, offset): b1 = parse_array(data, 6, 's', offset) b1 = b1[0].decode() b2 = parse_array(data, 8, 'h', offset + 6) b3 = struct.unpack('>Q', data[offset + 22:offset + 22 + 8])[0] b4 = parse_c(data, offset + 30) b5_offset = struct.unpack('>I', data[offset + 47:offset + 47 + 4])[0] b5 = parse_d(data, b5_offset) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_a(data, offset): a1 = struct.unpack('>H', data[offset:offset + 2])[0] a2 = struct.unpack('>i', data[offset + 2:offset + 2 + 4])[0] a3 = struct.unpack('>Q', data[offset + 6:offset + 6 + 8])[0] a4 = struct.unpack('>b', data[offset + 14:offset + 14 + 1])[0] a5 = struct.unpack('>i', data[offset + 15:offset + 15 + 4])[0] a6 = struct.unpack('>I', data[offset + 19:offset + 19 + 4])[0] a7 = parse_array_struct_b(data, 2, offset + 23) a8 = struct.unpack('>I', data[offset + 125:offset + 125 + 4])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 3) inp_1 = b'EGI\\\xfdI\xcc\x02HH\tg\xac\x01\xae\xf0\xd1\xca\xbe(S=\xd8\xfc\xae\xb2kjakvwy\xc7\x19\x12\xca\xa8Q\x19\t\xf0a@\xbe\xfc\x11\r\xfcQ\xc9\xa9)\xa3\xb1\x0b\xbf\xe8rr7\\\xc1t\t-\xc1P\xe2\xbfCh\xd2\x00\x00\x00\x84xbdgqv&\xdc\x1a\xe5\x9e\xb4\xff\xe8\xee\xa5\x16\xc2\xc6\x95\xef\x1b/\xfd\x94:q\xa0p\x12?\xba%\xda*\x8au\x90\x85\xbb\xc5\x8e\xe4>\xdc\xe6}\x00\x00\x00\x8d\x92U\x83V+4\x06\xd1\xcf\xdfO\x12H7\x90\xa9y\nbd\xfc\x97' inp_2 = b'EGI\x12ZZw\xb00n\x1e\xe5\xde\xa6\xa5\xae\nv\x9a\x97\xe1\x19\x80\xa9-DcnwqjtE\xf7p\x93,\x15#\x1e\x95=\xddE.V\xfe\xcaST\xe3U\x0cE\xa8j?\xe1\x94\x16c\x1f\x18\xde`\x05\xb7I\xe5\xbd\xdc\x95\x12\x00\x00\x00\x84ygsozd<\xa0\xf9\xc3\xaaf\x9b\xbd%9\x03\x1b|\xfd\xe3x\xc3\xe4\x14\x96[|o\xb0\xbf\xc9\x14\x88\r/$`\xb16\x12\xb7\xd2=\x81Z/\x00\x00\x00\x8d\xa2\xbf\xea?\xafcb\xd0:\xd5\xc5\xf6M\x03)\x02\xe9J\xa7)\x01F' main(inp_1) main(inp_2)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: a1 = struct_b(offset) offset += 1 + 8 + 4 + 8 + 8 + 4 + 4 + 2 + 2 + 4 [a2] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [a3] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [a4] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [a5] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'A1': a1, 'A2': a2, 'A3': struct_f(a3), 'A4': a4, 'A5': a5} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 b2 = struct_c(offset) offset += 8 + 4 + 8 + 8 + 4 + 4 [b3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [b4] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [b5] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 return {'B1': b1, 'B2': b2, 'B3': struct_e(b3), 'B4': b4, 'B5': b5} def struct_c(offset: int) -> dict: [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 c1 = list(struct.unpack('> ' + str(length1) + 'I', binary[link_str:link_str + length1 * 4])) [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 c2 = list(struct.unpack('> ' + str(length1) + 'b', binary[link_str:link_str + length1])) [c3] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [c4] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 c5 = list(struct.unpack('> ' + str(length1) + 'f', binary[link_str:link_str + length1 * 4])) [c6] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 return {'C1': [struct_d(i) for i in c1], 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [d3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'D1': d1, 'D2': d2, 'D3': d3} def struct_e(offset: int) -> dict: [e1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [e2] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 [e3] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [e4] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def struct_f(offset: int) -> dict: [f1] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 f2 = list(struct.unpack('> ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) [f3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 return {'F1': f1, 'F2': f2, 'F3': f3} return struct_a(3)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: le = 10 a1 = [struct_b(offset + i * le) for i in range(4)] offset += le * 4 [a2] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 a3 = struct_d(offset) offset += 52 [a4] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'A1': a1, 'A2': struct_c(a2), 'A3': a3, 'A4': a4} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [b2] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [b3] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 return {'B1': b1, 'B2': b2, 'B3': b3} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [c2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 c3 = list(struct.unpack('> ' + str(length1) + 'c', binary[link_str:link_str + length1])) c3 = [i.decode('UTF-8') for i in c3] [c4] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 return {'C1': c1, 'C2': c2, 'C3': ''.join(c3), 'C4': c4} def struct_d(offset: int) -> dict: d1 = struct_e(offset) offset += 6 [d2] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [d3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 d4 = list(struct.unpack('> ' + str(length1) + 'b', binary[link_str:link_str + length1])) [d5] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 d6 = list(struct.unpack('> ' + str(length1) + 'Q', binary[link_str:link_str + length1 * 8])) d7 = list(struct.unpack('> 2i', binary[offset:offset + 8])) offset += 8 d8 = struct_f(offset) offset += 13 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def struct_e(offset: int) -> dict: [e1] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [e2] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 return {'E1': e1, 'E2': e2} def struct_f(offset: int) -> dict: [f1] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [f2] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [f3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 return {'F1': f1, 'F2': f2, 'F3': f3} return struct_a(4)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = 'Q' int64 = 'q' uint32 = 'I' int32 = 'i' uint16 = 'H' int16 = 'h' uint8 = 'B' int8 = 'b' float = 'f' char = 'c' double = 'd' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_c1(reader): reader = BinaryReader(source=reader.source, offset=reader.read(Primitive.uint32)) return read_d(reader) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.int8), D2=reader.read(Primitive.int64), D3=reader.read(Primitive.double)) def read_c(reader: BinaryReader): return dict(C1=read_c1(reader), C2=reader.read(Primitive.double), C3=reader.read(Primitive.int16), C4=reader.read(Primitive.uint64), C5=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.int64), structure_size=8), C6=reader.read(Primitive.int16), C7=reader.read(Primitive.uint32), C8=[reader.read(Primitive.int64), reader.read(Primitive.int64), reader.read(Primitive.int64)]) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.uint8), B2=reader.read(Primitive.uint8), B3=''.join([reader.read(Primitive.char).decode('ascii'), reader.read(Primitive.char).decode('ascii')])) def read_a(reader: BinaryReader): return dict(A1=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: read_b(reader), structure_size=4), A2=read_c(reader)) def main(source): return read_a(BinaryReader(source, offset=5))" "import struct def main(b): dict = {} dict['A1'] = struct.unpack_from('III')]) offset_ += struct.calcsize('>III') offset_ = b_link a1_arr = [] for i in range(b_size): (num, offset_) = parse_b(data, offset_) a1_arr.append(num) result['A1'] = a1_arr (result['A2'], offset_) = parse_c(data, 45) return result def parse_b(data, offset): result = {} offset_ = offset result['B1'] = struct.unpack('b', data[offset_:offset_ + struct.calcsize('>b')])[0] offset_ += struct.calcsize('>b') result['B2'] = struct.unpack('B', data[offset_:offset_ + struct.calcsize('>B')])[0] offset_ += struct.calcsize('>B') return (result, offset_) def parse_c(data, offset): result = {} offset_ = offset (result['C1'], offset_) = parse_array(data, offset_, 'd', 2) (result['C2'], offset_) = parse_array(data, offset_, 'l', 8) (result['C3'], offset_) = parse_d(data, offset_) result['C4'] = parse_e(data, 20)[0] offset_ = 103 result['C5'] = struct.unpack('>B', data[offset_:offset_ + struct.calcsize('>B')])[0] offset_ += struct.calcsize('>B') result['C6'] = struct.unpack('>q', data[offset_:offset_ + struct.calcsize('>q')])[0] offset_ += struct.calcsize('>q') return (result, offset_) def parse_d(data, offset): result = {} offset_ = offset result['D1'] = struct.unpack('>f', data[offset_:offset_ + struct.calcsize('>f')])[0] offset_ += struct.calcsize('>f') result['D2'] = struct.unpack('>f', data[offset_:offset_ + struct.calcsize('>f')])[0] offset_ += struct.calcsize('>f') return (result, offset_) def parse_e(data, offset): result = {} offset_ = offset result['E1'] = struct.unpack('>b', data[offset_:offset_ + struct.calcsize('>b')])[0] offset_ = offset_ + struct.calcsize('>b') result['E2'] = struct.unpack('>q', data[offset_:offset_ + struct.calcsize('>q')])[0] offset_ = offset_ + struct.calcsize('>q') (result['E3'], offset_) = parse_array(data, offset_, 'L', 4) return (result, offset_) def parse_array(data, offset, type, len): return (list(struct.unpack(f'>{len}{type}', data[offset:offset + struct.calcsize(f'>{len}{type}')])), offset + struct.calcsize(f'>{len}{type}'))" "import struct def parse_a(data, offset): a1 = struct.unpack('' + PATTERN_D.lstrip('>') * array_length, raw_data, address), d_length) d_array = [{}] * array_length for d_index in range(array_length): d_array[d_index] = {'D1': list(data[d_index][0:4]), 'D2': data[d_index][4]} return d_array def parse_e(raw_data): data = unpack(PATTERN_E, raw_data) return {'E1': list(data[0:8]), 'E2': data[8], 'E3': list(data[9:15]), 'E4': data[15], 'E5': data[16]} def main(raw_data): return parse_a(raw_data)" "import struct def main(x): a1 = struct.unpack('>H', x[4:6])[0] b1 = struct.unpack('>b', x[6:7])[0] pos1 = struct.unpack('>H', x[9:11])[0] b2 = [] for i in range(0, struct.unpack('>H', x[7:9])[0]): pos2 = struct.unpack('>I', x[pos1:pos1 + 4])[0] c1 = struct.unpack('>d', x[pos2:pos2 + 8])[0] c2 = list(struct.unpack('>3H', x[pos2 + 8:pos2 + 14])) c3 = struct.unpack('>q', x[pos2 + 14:pos2 + 22])[0] d1 = list(struct.unpack('>6B', x[pos2 + 22:pos2 + 28])) d2 = struct.unpack('>b', x[pos2 + 28:pos2 + 29])[0] d3 = struct.unpack('>I', x[pos2 + 29:pos2 + 33])[0] c4 = {'D1': d1, 'D2': d2, 'D3': d3} c4 = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} b2.append(c4) pos1 += 4 a2 = {'B1': b1, 'B2': b2} a3 = struct.unpack('>b', x[11:12])[0] a4 = list(struct.unpack('>6f', x[12:36])) a5 = struct.unpack('>i', x[36:40])[0] di = struct.unpack('>H', x[40:42])[0] dis = '>' + str(di) + 'B' pos1 = struct.unpack('>I', x[42:46])[0] a6 = list(struct.unpack(dis, x[pos1:pos1 + di])) a7 = struct.unpack('>d', x[46:54])[0] f = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} return f" "import struct def createDict(data): A1 = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_f(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack('>IH', data[offset:offset + 6]) result['F1'] = parse_array(data, f1_addr, 'B', f1_size) result['F2'] = struct.unpack('>H', data[offset + 6:offset + 6 + 2])[0] result['F3'] = struct.unpack('>q', data[offset + 8:offset + 8 + 8])[0] result['F4'] = struct.unpack('>I', data[offset + 16:offset + 16 + 4])[0] return result def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>d', data[offset:offset + 8])[0] (e2_size, e2_addr) = struct.unpack('>HH', data[offset + 8:offset + 8 + 4]) result['E2'] = parse_array(data, e2_addr, 'i', e2_size) return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['D2'] = struct.unpack('>f', data[offset + 1:offset + 1 + 4])[0] result['D3'] = struct.unpack('>d', data[offset + 5:offset + 5 + 8])[0] result['D4'] = struct.unpack('>I', data[offset + 13:offset + 13 + 4])[0] (d5_size, d5_addr) = struct.unpack('>II', data[offset + 17:offset + 17 + 8]) result['D5'] = parse_array(data, d5_addr, 'h', d5_size) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>i', data[offset:offset + 4])[0] result['C2'] = struct.unpack('>H', data[offset + 4:offset + 4 + 2])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>f', data[offset:offset + 4])[0] offset += 4 result['B2'] = [] for i in range(8): result['B2'].append(parse_c(data, offset)) offset += 6 (b3_size, b3_addr) = struct.unpack('>HI', data[offset:offset + 6]) result['B3'] = ''.join([c.decode() for c in parse_array(data, b3_addr, 'c', b3_size)]) result['B4'] = parse_d(data, offset + 6) return result def parse_a(data, offset): result = dict() a1_addr = struct.unpack('>I', data[offset:offset + 4])[0] result['A1'] = parse_b(data, a1_addr) result['A2'] = parse_e(data, offset + 4) offset = 4 + 1 + 4 * 4 (result['A3'], result['A4']) = struct.unpack('>HB', data[offset:offset + 3]) a5_addr = struct.unpack('>I', data[offset + 3:offset + 3 + 4])[0] result['A5'] = parse_f(data, a5_addr) (result['A6'], result['A7'], result['A8']) = struct.unpack('>HfI', data[offset + 7:offset + 7 + 10]) return result def main(data): return parse_a(data, 5)" "import struct def main(data): return struct_a_parse(data, 4) def unpack_char(data, offset): data = struct.unpack('<3s', data[offset:offset + 3]) data = data[0] data = data.decode('utf-8') return (data, offset + 3) def unpack_uint(data, offset, bytes_num): if bytes_num == 1: data = struct.unpack(' H', x[start:start + 2])[0] return {'D1': struct.unpack('> q', x[start:start + 8])[0], 'D2': struct.unpack('> f', x[start + 8:start + 12])[0], 'D3': struct.unpack('> f', x[start + 12:start + 16])[0], 'D4': struct.unpack('> B', x[start + 16:start + 17])[0]} def u16u32i8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> L', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + size]) return list(a) def u32u32i16(x, start): size = struct.unpack('> L', x[start:start + 4])[0] add = struct.unpack('> L', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'h' * size, x[add:add + 2 * size]) return list(a) def u16u16i16(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'h' * size, x[add:add + 2 * size]) return list(a) def C(x, start): return {'C1': u32u32i16(x, start), 'C2': u16u32i8(x, start + 8), 'C3': struct.unpack('> f', x[start + 14:start + 18])[0], 'C4': u16u16i16(x, start + 18), 'C5': struct.unpack('> q', x[start + 22:start + 30])[0], 'C6': struct.unpack('> l', x[start + 30:start + 34])[0]} def B(x, start): return {'B1': [C(x, start + 4), C(x, start + 38)], 'B2': struct.unpack('> q', x[start + 72:start + 80])[0], 'B3': struct.unpack('> H', x[start + 80:start + 82])[0], 'B4': struct.unpack('> d', x[start + 82:start + 90])[0]} def u16u16u16(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def A(x, start): return {'A1': struct.unpack('> h', x[start:start + 2])[0], 'A2': struct.unpack('> d', x[start + 2:start + 10])[0], 'A3': struct.unpack('> f', x[start + 10:start + 14])[0], 'A4': struct.unpack('> d', x[start + 14:start + 22])[0], 'A5': u16u16u16(x, start + 22), 'A6': B(x, 26), 'A7': D(x, 116)} def main(x): return A(x, 4)" "import struct def main(data): a1 = struct.unpack('f', bytes, offset=5)[0] dict_b = {} dict['A2'] = dict_b dict_b['B1'] = struct.unpack_from('>Q', bytes, offset=9)[0] address_c = struct.unpack_from('>H', bytes, offset=17)[0] size_d = struct.unpack_from('>I', bytes, offset=address_c)[0] address_d = struct.unpack_from('>H', bytes, offset=address_c + 4)[0] arr_d = struct.unpack_from('>' + str(size_d) + 'I', bytes, offset=address_d) dict_c = {} dict_d = [] dict_b['B2'] = dict_c dict_b['B3'] = struct.unpack_from('>f', bytes, offset=19)[0] dict_c['C1'] = dict_d k = 0 for j in range(size_d): dict_dd = {} dict_dd['D1'] = struct.unpack_from('>q', bytes, offset=arr_d[j])[0] dict_dd['D2'] = struct.unpack_from('>f', bytes, offset=arr_d[j] + 8)[0] dict_dd['D3'] = [] for i in range(2): k += 1 dict_d1 = struct.unpack_from('>b', bytes, offset=arr_d[j] + 12 + i)[0] dict_dd['D3'].append(dict_d1) dict_dd['D4'] = struct.unpack_from('>d', bytes, offset=arr_d[j] + 14)[0] dict_d.append(dict_dd) size_C = address_c + 6 dict_c['C2'] = struct.unpack_from('>f', bytes, offset=size_C)[0] dict_c['C3'] = struct.unpack_from('>I', bytes, offset=size_C + 4)[0] dict_c['C4'] = struct.unpack_from('>B', bytes, offset=size_C + 8)[0] dict_c['C5'] = struct.unpack_from('>H', bytes, offset=size_C + 9)[0] dict_c['C6'] = struct.unpack_from('>f', bytes, offset=size_C + 11)[0] size_C += 11 size_c7 = struct.unpack_from('>H', bytes, offset=size_C + 4)[0] address_c7 = struct.unpack_from('>I', bytes, offset=size_C + 6)[0] dict_c7 = [] dict_c['C7'] = dict_c7 for i in range(size_c7): dict_c7 = struct.unpack_from('>H', bytes, offset=address_c7 + i * 2)[0] dict_c['C7'].append(dict_c7) dict['A3'] = struct.unpack_from('>i', bytes, offset=23)[0] dict_a4 = [] dict['A4'] = dict_a4 for i in range(3): dict_a4 = struct.unpack_from('>f', bytes, offset=27 + i * 4)[0] dict['A4'].append(dict_a4) dict['A5'] = struct.unpack_from('>f', bytes, offset=39)[0] return dict" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') arr = getNext(data, temp, length, f'>{length}s')[0].decode('ascii') A['A1'] = arr (A['A2'], iterator) = getNext(data, iterator, 2, '>h') A['A3'] = [] (temp, iterator) = getB(data, iterator) A['A3'].append(temp) (temp, iterator) = getB(data, iterator) A['A3'].append(temp) (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') arr = getNextArr(data, temp, length, f'>{length}b')[0] A['A4'] = arr (A['A5'], iterator) = getD(data, iterator) (A['A6'], iterator) = getNext(data, iterator, 4, '>f') return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 4, '>f') (temp, iterator) = getNext(data, iterator, 4, '>I') B['B2'] = getC(data, temp)[0] return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 4, '>f') (C['C2'], iterator) = getNext(data, iterator, 4, '>I') (C['C3'], iterator) = getNextArr(data, iterator, 1 * 7, '>7b') (C['C4'], iterator) = getNext(data, iterator, 8, '>d') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 2, '>H') (D['D2'], iterator) = getNext(data, iterator, 2, '>H') (D['D3'], iterator) = getNext(data, iterator, 4, '>f') (D['D4'], iterator) = getNext(data, iterator, 4, '>f') (D['D5'], iterator) = getNext(data, iterator, 8, '>q') (D['D6'], iterator) = getNextArr(data, iterator, 4 * 6, '>6I') (D['D7'], iterator) = getNext(data, iterator, 4, '>I') (D['D8'], iterator) = getNext(data, iterator, 4, '>I') return (D, iterator) def main(data): return getA(data, 4)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A1'] = [] for i in range(length): (b, temp) = getB(data, temp) A['A1'].append(b) (A['A2'], iterator) = getNext(data, iterator, 2, '>H') (A['A3'], iterator) = getC(data, iterator) return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 4, '>f') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') B['B2'] = getNext(data, temp, length, f'>{length}s')[0] B['B2'] = B['B2'].decode('ascii') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 4, '>I') (C['C2'], iterator) = getD(data, iterator) (C['C3'], iterator) = getNext(data, iterator, 8, '>q') (C['C4'], iterator) = getNext(data, iterator, 4, '>i') (temp, iterator) = getNext(data, iterator, 4, '>I') C['C5'] = getE(data, temp)[0] return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNextArr(data, iterator, 1 * 7, '>7B') (D['D2'], iterator) = getNext(data, iterator, 4, '>I') (D['D3'], iterator) = getNext(data, iterator, 2, '>H') return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 4, '>f') (E['E2'], iterator) = getNext(data, iterator, 4, '>I') (E['E3'], iterator) = getNext(data, iterator, 2, '>H') (E['E4'], iterator) = getNext(data, iterator, 8, '>q') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') E['E5'] = getNextArr(data, temp, length * 2, f'>{length}h')[0] (E['E6'], iterator) = getNext(data, iterator, 2, '>h') (E['E7'], iterator) = getNext(data, iterator, 2, '>h') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') E['E8'] = getNextArr(data, temp, length, f'>{length}B')[0] return (E, iterator) def main(data): return getA(data, 4)" "from struct import unpack_from def main(bytes): answer = {} A1 = unpack_from('q', bytes, offset=3)[0] A2 = unpack_from('h', bytes, offset=11)[0] A31 = unpack_from('H', bytes, offset=13)[0] A32 = unpack_from('I', bytes, offset=15)[0] A3 = [] for i in range(A31): A3.append(unpack_from('c', bytes, offset=A32 + i)[0]) A4 = unpack_from('q', bytes, offset=19)[0] A5 = unpack_from('H', bytes, offset=27)[0] A6 = unpack_from('h', bytes, offset=29)[0] A7 = unpack_from('I', bytes, offset=31)[0] address_b = unpack_from('I', bytes, offset=35)[0] address_c = unpack_from('H', bytes, offset=address_b)[0] size_d = unpack_from('H', bytes, offset=address_b + 2)[0] adress_array_adresses_d = unpack_from('I', bytes, offset=address_b + 4)[0] B3 = unpack_from('h', bytes, offset=address_b + 8)[0] E1 = [] for i in range(3): E1.append(unpack_from('h', bytes, offset=address_b + 10 + i * 2)[0]) E2 = unpack_from('b', bytes, offset=address_b + 10 + 6)[0] B5 = unpack_from('b', bytes, offset=address_b + 10 + 6 + 1)[0] C1 = unpack_from('f', bytes, offset=address_c)[0] C2 = unpack_from('h', bytes, offset=address_c + 4)[0] C3 = unpack_from('d', bytes, offset=address_c + 6)[0] C4 = unpack_from('d', bytes, offset=address_c + 14)[0] C5 = unpack_from('Q', bytes, offset=address_c + 22)[0] C6 = unpack_from('B', bytes, offset=address_c + 30)[0] addresses_d = list(unpack_from(str(size_d) + 'I', bytes, offset=adress_array_adresses_d)) D = [] for address_d in addresses_d: D1 = unpack_from('I', bytes, offset=address_d)[0] D2 = unpack_from('B', bytes, offset=address_d + 4)[0] D3 = [] for i in range(7): D3.append(unpack_from('b', bytes, offset=address_d + 5 + i)[0]) D4 = unpack_from('B', bytes, offset=address_d + 5 + 7)[0] D_i = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4} D.append(D_i) answer['A1'] = A1 answer['A2'] = A2 answer['A3'] = ''.join(map(lambda k: k.decode(), A3)) answer['A4'] = A4 answer['A5'] = A5 answer['A6'] = A6 answer['A7'] = A7 answer['A8'] = {'B1': {'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5, 'C6': C6}, 'B2': D, 'B3': B3, 'B4': {'E1': E1, 'E2': E2}, 'B5': B5} return answer" "import struct def uint32uint16uint32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def uint16uint32uint32(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('> Q', x[start:start + 8])[0], 'D2': uint32uint16uint32(x, start + 8), 'D3': struct.unpack('> d', x[start + 14:start + 22])[0], 'D4': struct.unpack('> H', x[start + 22:start + 24])[0], 'D5': struct.unpack('> I', x[start + 24:start + 28])[0], 'D6': struct.unpack('> b', x[start + 28:start + 29])[0]} def C(x, start): return {'C1': [D(x, start), D(x, start + 29)], 'C2': uint16uint32uint32(x, start + 58), 'C3': struct.unpack('> q', x[start + 64:start + 72])[0]} def addressC(x, start): return struct.unpack('> I', x[start:start + 4])[0] def B(x, start): return {'B1': C(x, addressC(x, start)), 'B2': struct.unpack('> b', x[start + 4:start + 5])[0], 'B3': struct.unpack('> I', x[start + 5:start + 9])[0], 'B4': struct.unpack('> d', x[start + 9:start + 17])[0], 'B5': [struct.unpack('> H', x[start + 17:start + 19])[0], struct.unpack('> H', x[start + 19:start + 21])[0], struct.unpack('> H', x[start + 21:start + 23])[0], struct.unpack('> H', x[start + 23:start + 25])[0]], 'B6': struct.unpack('> d', x[start + 25:start + 33])[0]} def A(x, start): return {'A1': B(x, start), 'A2': struct.unpack('> H', x[start + 33:start + 35])[0], 'A3': struct.unpack('> I', x[start + 35:start + 39])[0], 'A4': struct.unpack('> H', x[start + 39:start + 41])[0]} def main(x): return A(x, 5)" "import struct def D(x, start): return {'D1': [struct.unpack('< h', x[start:start + 2])[0], struct.unpack('< h', x[start + 2:start + 4])[0], struct.unpack('< h', x[start + 4:start + 6])[0]], 'D2': struct.unpack('< B', x[start + 6:start + 7])[0], 'D3': struct.unpack('< f', x[start + 7:start + 11])[0], 'D4': struct.unpack('< I', x[start + 11:start + 15])[0]} def startD(x, start): start = struct.unpack('< H', x[start:start + 2])[0] return start def u32u16i32(x, start): size = struct.unpack('< I', x[start:start + 4])[0] add = struct.unpack('< H', x[start + 4:start + 6])[0] a = struct.unpack('< ' + 'i' * size, x[add:add + 4 * size]) return list(a) def C(x, start): return {'C1': u32u16i32(x, start), 'C2': struct.unpack('< Q', x[start + 6:start + 14])[0]} def B(x, start): return {'B1': struct.unpack('< H', x[start:start + 2])[0], 'B2': [C(x, start + 2), C(x, start + 16), C(x, start + 30), C(x, start + 44)]} def startB(x, start): start = struct.unpack('< I', x[start:start + 4])[0] return start def u16u32f(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< I', x[start + 2:start + 6])[0] a = struct.unpack('< ' + 'f' * size, x[add:add + 4 * size]) return list(a) def A(x, start): return {'A1': struct.unpack('< h', x[start:start + 2])[0], 'A2': B(x, startB(x, start + 2)), 'A3': struct.unpack('< I', x[start + 6:start + 10])[0], 'A4': struct.unpack('< d', x[start + 10:start + 18])[0], 'A5': struct.unpack('< b', x[start + 18:start + 19])[0], 'A6': u16u32f(x, start + 19), 'A7': D(x, startD(x, start + 25))} def main(x): return A(x, 5)" "from struct import unpack_from def main(bytes): B1 = unpack_from('B', bytes, offset=4)[0] B2 = unpack_from('q', bytes, offset=4 + 1)[0] size_c = unpack_from('H', bytes, offset=5 + 8)[0] addresses_array_address_c = unpack_from('H', bytes, offset=13 + 2)[0] addresses_c = list(unpack_from(str(size_c) + 'H', bytes, offset=addresses_array_address_c)) C = [] for i in addresses_c: C1 = unpack_from('i', bytes, offset=i)[0] C2 = unpack_from('d', bytes, offset=i + 4)[0] C.append({'C1': C1, 'C2': C2}) B4 = unpack_from('B', bytes, offset=15 + 2)[0] B5 = ''.join(map(lambda k: k.decode(), unpack_from('6c', bytes, offset=17 + 1))) B6 = unpack_from('i', bytes, offset=18 + 6)[0] B7 = unpack_from('H', bytes, offset=24 + 4)[0] A2 = unpack_from('d', bytes, offset=28 + 2)[0] D1 = unpack_from('Q', bytes, offset=30 + 8)[0] D2 = unpack_from('f', bytes, offset=38 + 8)[0] E11 = unpack_from('I', bytes, offset=46 + 4)[0] E12 = unpack_from('H', bytes, offset=50 + 4)[0] E1 = [] for i in range(E11): E1.append(unpack_from('H', bytes, offset=E12 + i * 2)[0]) E2 = list(unpack_from('6I', bytes, offset=54 + 2)) D4 = unpack_from('q', bytes, offset=56 + 24)[0] D5 = unpack_from('H', bytes, offset=80 + 8)[0] D6 = unpack_from('B', bytes, offset=88 + 2)[0] A4 = unpack_from('d', bytes, offset=90 + 1)[0] A5 = unpack_from('d', bytes, offset=91 + 8)[0] A6 = unpack_from('B', bytes, offset=99 + 8)[0] A7 = unpack_from('Q', bytes, offset=107 + 1)[0] answer = {'A1': {'B1': B1, 'B2': B2, 'B3': C, 'B4': B4, 'B5': B5, 'B6': B6, 'B7': B7}, 'A2': A2, 'A3': {'D1': D1, 'D2': D2, 'D3': {'E1': E1, 'E2': E2}, 'D4': D4, 'D5': D5, 'D6': D6}, 'A4': A4, 'A5': A5, 'A6': A6, 'A7': A7} return answer" "import struct def E(data, start): adress = struct.unpack('>I', data[start:start + 4])[0] e1 = struct.unpack('>Q', data[adress:adress + 8])[0] size = struct.unpack('>H', data[adress + 8:adress + 10])[0] adress += 10 add = struct.unpack('>H', data[adress:adress + 2])[0] e2 = list(struct.unpack('>' + 'l' * size, data[add:add + 4 * size])) return {'E1': e1, 'E2': e2} def C(data, start): c1 = struct.unpack('>I', data[start:start + 4])[0] start += 4 result = [] for d_address in struct.unpack('>3H', data[start:start + 6]): d1 = struct.unpack('>q', data[d_address:d_address + 8])[0] d2 = list(struct.unpack('>4l', data[d_address + 8:d_address + 24])) result.append({'D1': d1, 'D2': d2}) result = {'C1': c1, 'C2': result} return result def B(data, start): result = [] adress = struct.unpack('>I', data[start:start + 4])[0] b1 = struct.unpack('>d', data[adress:adress + 8])[0] start += 4 adress += 8 b2 = C(data, adress) adress += 10 b3 = list(struct.unpack('>6b', data[adress:adress + 6])) b4 = struct.unpack('>B', data[adress + 6:adress + 7])[0] adress += 7 b5 = E(data, adress) adress += 4 b6 = struct.unpack('>q', data[adress:adress + 8])[0] b7 = struct.unpack('>f', data[adress + 8:adress + 12])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def main(data): start = 0 while hex(data[start]) != '0x51' and hex(data[start]) != '0x56' and (hex(data[start]) != '0x4e') and (hex(data[start]) != '0x5a') and (hex(data[start]) != '0x20'): start += 1 start += 5 a1 = struct.unpack('>q', data[start:start + 8])[0] a2 = struct.unpack('>h', data[start + 8:start + 10])[0] start += 10 a3 = B(data, start) out_dict = {'A1': a1, 'A2': a2, 'A3': a3} return out_dict" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): a1 = reader.read(Types.uint16) a2_offset = reader.read(Types.uint16) a2 = read_a2(a2_offset, reader.source) a3_size = reader.read(Types.uint16) a3_offset = reader.read(Types.uint32) a3 = read_a3(a3_offset, a3_size, reader.source) a4 = read_a4(reader) a5 = reader.read(Types.int16) a6 = reader.read(Types.int64) a7 = reader.read(Types.uint8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def b(reader: BinaryReader): b1_offset = reader.read(Types.uint32) b1 = read_b1(b1_offset, reader.source) b2 = reader.read(Types.float) b3 = reader.read(Types.uint16) b4 = reader.read(Types.int8) b5_size = reader.read(Types.uint16) b5_offset = reader.read(Types.uint16) b5 = read_b5(b5_offset, b5_size, reader.source) b6 = reader.read(Types.uint16) b7 = reader.read(Types.int8) b8 = reader.read(Types.int32) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8) def c(reader: BinaryReader): c1 = reader.read(Types.int8) c2 = reader.read(Types.int32) c3_size = reader.read(Types.uint32) c3_offset = reader.read(Types.uint32) c3 = read_c3(c3_offset, c3_size, reader.source) c4 = reader.read(Types.int32) return dict(C1=c1, C2=c2, C3=c3, C4=c4) def d(reader: BinaryReader): d1 = reader.read(Types.int16) d2 = reader.read(Types.uint8) d3 = reader.read(Types.int32) return dict(D1=d1, D2=d2, D3=d3) def read_a2(offset, source): reader = BinaryReader(offset, source) return b(reader) def read_a3(offset, size, source): res = '' reader = BinaryReader(offset, source) while reader.offset < offset + size: res += str(reader.read(Types.char).decode('ascii')) return res def read_a4(reader): res = [reader.read(Types.uint64), reader.read(Types.uint64)] return res def read_b1(offset, source): reader = BinaryReader(offset, source) return c(reader) def read_b5(offset, size, source): res = [] reader = BinaryReader(offset, source) while reader.offset < offset + size * 2: d_offset = reader.read(Types.uint16) d_reader = BinaryReader(d_offset, source) res.append(d(d_reader)) return res def read_c3(offset, size, source): res = '' reader = BinaryReader(offset, source) while reader.offset < offset + size: res += str(reader.read(Types.char).decode('ascii')) return res def main(source): reader = BinaryReader(offset=4, source=source) return a(reader)" "import struct def D(data, start): d1 = struct.unpack('>d', data[start:start + 8])[0] d2 = struct.unpack('>d', data[start + 8:start + 16])[0] size = struct.unpack('>L', data[start + 16:start + 20])[0] add = struct.unpack('>H', data[start + 20:start + 22])[0] d3 = list(struct.unpack('>' + 'B' * size, data[add:add + size])) d4 = struct.unpack('>Q', data[start + 22:start + 30])[0] d5 = struct.unpack('>h', data[start + 30:start + 32])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def C(data, start): size = struct.unpack('>H', data[start:start + 2])[0] add = struct.unpack('>H', data[start + 2:start + 4])[0] result = [] for i in range(0, size - 1): for d_address in struct.unpack('>' + 'L' * size, data[add:add + 4 * size]): c1 = struct.unpack('>L', data[d_address:d_address + 4])[0] c2 = struct.unpack('>B', data[d_address + 4:d_address + 5])[0] c3 = list(struct.unpack('>3d', data[d_address + 5:d_address + 29])) c4 = struct.unpack('>B', data[d_address + 29:d_address + 30])[0] c5 = struct.unpack('>L', data[d_address + 30:d_address + 34])[0] c6 = struct.unpack('>q', data[d_address + 34:d_address + 42])[0] result.append({'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6}) return result def B(data, start): b1 = struct.unpack('>5s', data[start:start + 5])[0].decode('ascii') b2 = struct.unpack('>d', data[start + 5:start + 13])[0] size = struct.unpack('>H', data[start + 13:start + 15])[0] add = struct.unpack('>H', data[start + 15:start + 17])[0] b3 = list(struct.unpack('>' + 's' * size, data[add:add + 1 * size])) b3_str = b''.join(b3).decode('ascii') b4 = struct.unpack('>h', data[start + 17:start + 19])[0] b5 = struct.unpack('>I', data[start + 19:start + 23])[0] return {'B1': b1, 'B2': b2, 'B3': b3_str, 'B4': b4, 'B5': b5} def main(data): start = 0 while hex(data[start]) != '0x48' and hex(data[start]) != '0x49' and (hex(data[start]) != '0x5a'): start += 1 start += 3 a1 = B(data, start) start += 23 a2 = struct.unpack('>b', data[start:start + 1])[0] a3 = struct.unpack('>I', data[start + 1:start + 5])[0] a4 = struct.unpack('>H', data[start + 5:start + 7])[0] start += 7 a5 = C(data, start) start += 4 a6 = struct.unpack('>B', data[start:start + 1])[0] adress = struct.unpack('>L', data[start + 1:start + 5])[0] a7 = D(data, adress) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7}" "from struct import unpack_from def main(bytes): A_offset = 4 A_dict = {} B_size = 1 B_addresses_struct = list(unpack_from('<' + str(B_size) + 'H', bytes, offset=A_offset)) A_offset += 2 * B_size A_dict['A1'] = [] B_offset = B_addresses_struct[0] B_dict = {} C_size = 5 C_addresses_struct = list(unpack_from('<' + str(C_size) + 'H', bytes, offset=B_offset)) B_offset += 2 * C_size B_dict['B1'] = [] C_offset = C_addresses_struct[0] C_dict = {} C_dict['C1'] = unpack_from(' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a2 = list(struct.unpack('< 3H', binary[offset:offset + 3 * 2])) offset += 6 [a3] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a4 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1])) a4 = [i.decode('UTF-8') for i in a4] [a5] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'A1': a1, 'A2': [struct_b(i) for i in a2], 'A3': a3, 'A4': ''.join(a4), 'A5': struct_c(a5)} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [b2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [b3] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 return {'B1': b1, 'B2': b2, 'B3': b3} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [c2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 return {'C1': struct_d(c1), 'C2': struct_e(c2)} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 d2 = list(struct.unpack('< 7Q', binary[offset:offset + 7 * 8])) offset += 7 * 8 [d3] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'D1': d1, 'D2': d2, 'D3': d3} def struct_e(offset: int) -> dict: [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 e1 = list(struct.unpack('< ' + str(length1) + 'q', binary[link_str:link_str + length1 * 8])) [e2] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [e3] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 return {'E1': e1, 'E2': e2, 'E3': e3} return struct_a(4)" "import struct def parse_array(data, offset, type, arr_len): return list(struct.unpack(f'>{arr_len}{type}', data[offset:offset + arr_len * struct.calcsize(type)])) def parse_a(data, offset): result = dict() result['A1'] = ''.join([x.decode('ascii') for x in parse_array(data, offset, 'c', 5)]) result['A2'] = struct.unpack('>h', data[offset + 5:offset + 5 + 2])[0] address = struct.unpack('>I', data[offset + 7:offset + 7 + 4])[0] result['A3'] = parse_b(data, address) result['A4'] = parse_d(data, offset + 11) address = struct.unpack('>H', data[offset + 11 + 14:offset + 11 + 14 + 2])[0] result['A5'] = parse_e(data, address) return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>L', data[offset:offset + 4])[0] result['B2'] = struct.unpack('>H', data[offset + 4:offset + 4 + 2])[0] result['B3'] = struct.unpack('>i', data[offset + 6:offset + 6 + 4])[0] (arr_size, arr_addr) = struct.unpack('>HI', data[offset + 10:offset + 10 + 6]) lst = list() for i in range(arr_size): lst.append(parse_c(data, arr_addr + i * 14)) result['B4'] = lst result['B5'] = parse_array(data, offset + 16, 'B', 4) result['B6'] = struct.unpack('>Q', data[offset + 20:offset + 20 + 8])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>Q', data[offset + 2:offset + 2 + 8])[0] result['C3'] = struct.unpack('>I', data[offset + 10:offset + 10 + 4])[0] return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>b', data[offset:offset + 1])[0] result['D2'] = struct.unpack('>h', data[offset + 1:offset + 1 + 2])[0] (a2_size, a2_addr) = struct.unpack('>HH', data[offset + 3:offset + 3 + 4]) result['D3'] = parse_array(data, a2_addr, 'i', a2_size) result['D4'] = struct.unpack('>h', data[offset + 7:offset + 7 + 2])[0] result['D5'] = parse_array(data, offset + 7 + 2, 'b', 5) return result def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>i', data[offset:offset + 4])[0] result['E2'] = struct.unpack('>b', data[offset + 4:offset + 4 + 1])[0] result['E3'] = struct.unpack('>h', data[offset + 5:offset + 5 + 2])[0] return result def main(var): return parse_a(var, 4)" "import struct def main(data: bytes): B_struct = struct.Struct('>biQI') C_struct = struct.Struct(f'>2fBBIHQQ5qIIQBHI') A_struct = struct.Struct(f'>II2fBBIHQQ5qIIQBHI') A = A_struct.unpack(data[4:A_struct.size + 4]) output = dict() output['A1'] = [] for address in range(A[1], A[1] + B_struct.size * A[0], B_struct.size): B = B_struct.unpack(data[address:address + B_struct.size]) output['A1'].append({f'B{num}': value for (num, value) in enumerate(B, 1)}) A2 = output['A2'] = dict() B = A[2:9] b_s = struct.Struct('>b') A2['C1'] = {'D1': [B[0], B[1]], 'D2': B[2], 'D3': B[3], 'D4': [b_s.unpack_from(data, offset)[0] for offset in range(B[5], B[5] + b_s.size * B[4], b_s.size)], 'D5': B[6]} A2['C2'] = A[9] A2['C3'] = [A[i] for i in range(10, 15)] for i in range(0, 4): A2[f'C{4 + i}'] = A[15 + i] b_s = struct.Struct('>B') A2['C8'] = [b_s.unpack_from(data, offset)[0] for offset in range(A[20], A[20] + b_s.size * A[19], b_s.size)] return output" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): a1 = b(reader) a2 = reader.read(Types.int32) a3 = reader.read(Types.uint16) a4 = reader.read(Types.uint64) a5 = reader.read(Types.uint32) a6 = reader.read(Types.int8) a7 = reader.read(Types.int8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def b(reader: BinaryReader): b11 = reader.read(Types.uint16) b12 = reader.read(Types.uint32) b1 = masser_b1(b11, b12, reader.source) b21 = reader.read(Types.uint32) b22 = reader.read(Types.uint16) b2 = masser_b2(b21, b22, reader.source) b3 = reader.read(Types.int32) b41 = reader.read(Types.uint32) b4 = d(b41, reader.source) b5 = reader.read(Types.uint16) b6 = reader.read(Types.float) b7 = reader.read(Types.int8) b8 = reader.read(Types.float) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8) def c(reader: BinaryReader): c1 = reader.read(Types.int8) c2 = reader.read(Types.int8) c3 = reader.read(Types.float) c4 = reader.read(Types.float) c51 = reader.read(Types.uint32) c52 = reader.read(Types.uint32) c5 = masser_c5(c51, c52, reader.source) c6 = reader.read(Types.int16) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6) def d(offset, source): reader = BinaryReader(offset, source) d1 = reader.read(Types.int16) d2 = [reader.read(Types.float), reader.read(Types.float), reader.read(Types.float), reader.read(Types.float), reader.read(Types.float), reader.read(Types.float), reader.read(Types.float)] d3 = reader.read(Types.int8) return dict(D1=d1, D2=d2, D3=d3) def masser_b1(size, offset, source): rez = '' read = BinaryReader(offset, source) while read.offset < offset + size: rez += str(read.read(Types.char).decode('ascii')) return rez def masser_b2(size, offset, source): rez = [] read = BinaryReader(offset, source) while read.offset < offset + size * 16: rez.append(c(read)) return rez def masser_c5(size, offset, source): rez = [] read = BinaryReader(offset, source) while read.offset < offset + size * 8: rez.append(read.read(Types.uint64)) return rez def main(source): reader = BinaryReader(offset=5, source=source) g = a(reader) return g" "from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 27 return result def parse_d(data, offset): result = dict() result['D1'] = un('>b', data[offset:offset + 1])[0] result['D2'] = un('>B', data[offset + 1:offset + 2])[0] result['D3'] = un('>H', data[offset + 2:offset + 4])[0] result['D4'] = un('>f', data[offset + 4:offset + 8])[0] result['D5'] = un('>f', data[offset + 8:offset + 12])[0] return result def parse_c(data, offset): result = dict() result['C1'] = un('>H', data[offset:offset + 2])[0] (c2_size, c2_addr) = un('>IH', data[offset + 2:offset + 8]) result['C2'] = parse_array(data, c2_addr, 'b', c2_size) result['C3'] = un('>d', data[offset + 8:offset + 16])[0] (c4_size, c4_addr) = un('>HI', data[offset + 16:offset + 22]) result['C4'] = parse_array(data, c4_addr, 'b', c4_size) result['C5'] = un('>B', data[offset + 22:offset + 23])[0] result['C6'] = un('>i', data[offset + 23:offset + 27])[0] return result def parse_b(data, offset): result = dict() result['B1'] = un('>b', data[offset:offset + 1])[0] result['B2'] = un('>i', data[offset + 1:offset + 5])[0] result['B3'] = ''.join((x.decode('ascii') for x in parse_array(data, offset + 5, 'c', 5))) (b4_size, b4_addr) = un('>HI', data[offset + 10:offset + 16]) result['B4'] = parse_structure_array(data, b4_addr, b4_size) result['B5'] = parse_d(data, offset + 16) result['B6'] = un('>Q', data[offset + 28:offset + 36])[0] return result def parse_a(data, offset): result = dict() result['A1'] = un('>f', data[offset:offset + 4])[0] result['A2'] = parse_b(data, offset + 4) result['A3'] = un('>b', data[offset + 40:offset + 41])[0] return result def main(data): return parse_a(data, 5)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.uint32) size2 = reader.read(Types.uint16) adress2 = reader.read(Types.uint32) a2 = [] cReader = BinaryReader(offset=adress2, buffer=buffer) for i in range(0, size2): a2.append(readB(cReader)) a3 = reader.read(Types.float) a4 = reader.read(Types.int64) a5 = readD(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5) def readB(reader): b1 = readC(reader) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint16) tempA2 = reader.copy(adress2).readWithSize(Types.char, size2) b2 = b''.join(tempA2).decode('ASCII') size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint16) b3 = reader.copy(offset=adress3).readWithSize(Types.int32, size3) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.int32) c2 = reader.read(Types.int16) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.int16) size2 = reader.read(Types.uint16) adress2 = reader.read(Types.uint32) d2 = reader.copy(offset=adress2).readWithSize(Types.int64, size2) d3 = reader.read(Types.uint8) return dict(D1=d1, D2=d2, D3=d3)" "from struct import unpack def main(binary_data): start_from = [int(i) for i in [172, 86, 76, 79, 84]] idx = [(i, i + len(start_from)) for i in range(len(binary_data)) if [int(i) for i in binary_data[i:i + len(start_from)]] == start_from][0][1] def struct_a(index): response = {} [a1] = unpack('>I', binary_data[index:index + 4]) index += 4 [a2] = unpack('>i', binary_data[index:index + 4]) index += 4 response['A1'] = a1 response['A2'] = a2 (response['A3'], index) = struct_b(index) [address_c] = unpack('>I', binary_data[index:index + 4]) index += 4 response['A4'] = struct_c(address_c) return response def struct_b(index): response = {} (size, address) = unpack('>II', binary_data[index:index + 8]) b1 = list(unpack('>{}h'.format(size), binary_data[address:address + 2 * size])) index += 8 response['B1'] = b1 [b2] = unpack('>q', binary_data[index:index + 8]) index += 8 response['B2'] = b2 return (response, index) def struct_c(index): response = {} d_size = 6 c1_tmp = [struct_d(index + i * 16) for i in range(d_size)] response['C1'] = [i[0] for i in c1_tmp] index = [i[1] for i in c1_tmp][d_size - 1] (c2, c3, c4) = unpack('>hiH', binary_data[index:index + 8]) index += 8 (size, address) = unpack('>II', binary_data[index:index + 8]) c5 = list(unpack('>{}b'.format(size), binary_data[address:address + 1 * size])) index += 8 response['C2'] = c2 response['C3'] = c3 response['C4'] = c4 response['C5'] = c5 return response def struct_d(index): response = {} (size, address) = unpack('>II', binary_data[index:index + 8]) d1 = list(unpack('>{}h'.format(size), binary_data[address:address + 2 * size])) index += 8 response['D1'] = d1 (d2, d3, d4) = unpack('>HiH', binary_data[index:index + 8]) index += 8 response['D2'] = d2 response['D3'] = d3 response['D4'] = d4 return (response, index) return struct_a(idx)" "from struct import calcsize, unpack_from from enum import Enum class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): A1 = (reader.read(Types.char) + reader.read(Types.char)).decode('ascii') A2 = reader.read(Types.uint8) A3 = reader.read(Types.int32) A41 = reader.read(Types.uint32) A4 = b(A41, reader.source) A5 = e(reader) A6 = reader.read(Types.uint8) A7 = reader.read(Types.int16) A81 = reader.read(Types.uint32) A82 = reader.read(Types.uint32) A8 = make_array_f(A81, A82, reader.source) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8) def b(offset, source): reader = BinaryReader(offset, source) B1 = reader.read(Types.uint64) B2 = reader.read(Types.double) B3 = c(reader) B4 = reader.read(Types.int32) return dict(B1=B1, B2=B2, B3=B3, B4=B4) def c(reader: BinaryReader): C1 = reader.read(Types.uint64) C2 = reader.read(Types.uint8) C3 = reader.read(Types.uint32) C31 = reader.read(Types.uint16) C4 = d(C31, reader.source) C5 = reader.read(Types.int32) return dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5) def d(offset, source): reader = BinaryReader(offset, source) D1 = reader.read(Types.int8) D2 = reader.read(Types.int16) return dict(D1=D1, D2=D2) def e(reader: BinaryReader): E1 = reader.read(Types.uint16) E2 = reader.read(Types.int8) E31 = reader.read(Types.uint16) E32 = reader.read(Types.uint16) E3 = make_array_char(E31, E32, reader.source) return dict(E1=E1, E2=E2, E3=E3) def f(offset, source): reader = BinaryReader(offset, source) F1 = reader.read(Types.uint32) F21 = reader.read(Types.uint16) F22 = reader.read(Types.uint16) F2 = make_array_uint8(F21, F22, reader.source) F3 = reader.read(Types.uint8) return dict(F1=F1, F2=F2, F3=F3) def make_array_char(size, offset, source): result = '' reader = BinaryReader(offset, source) while reader.offset < offset + size: result += str(reader.read(Types.char).decode('ascii')) return result def make_array_uint8(size, offset, source): result = [] reader = BinaryReader(offset, source) while reader.offset < offset + size: result.append(reader.read(Types.uint8)) return result def make_array_f(size, offset, source): result = [] reader = BinaryReader(offset, source) while reader.offset < offset + size * 2: offset_f = reader.read(Types.uint16) result.append(f(offset_f, reader.source)) return result def main(source): reader = BinaryReader(offset=4, source=source) result = a(reader) return result" "from struct import * import re GA = '' def gb(n): try_str = '' i = 0 for symbol in GA[2:-1]: try_str += symbol if not (re.match('\\\\x..', try_str) or re.match('\\\\[^x]', try_str) or (try_str != '\\' and len(try_str) == 1)): continue if i == n: return bytes(try_str, encoding='raw_unicode_escape').decode('unicode_escape').encode('raw_unicode_escape') try_str = '' i += 1 def u(f, start): s = b'' for i in range(calcsize(f)): s += gb(start + i) return unpack(f, s)[0] def main(a): global GA GA = str(a) b_a = u('H', 5) e_a = u('H', 7) g_a = u('H', 9) e4_a = u('I', e_a + 14) g3_arr = [] g3_l = u('H', g_a + 6) g3_a = u('H', g_a + 8) for i in range(g3_l): g3_arr.append(u('Q', g3_a + i * 8)) e2_arr = [] e2_l = u('H', e_a + 8) e2_a = u('H', e_a + 10) for i in range(e2_l): e2_arr.append(u('B', e2_a + i * 1)) c3_arr = [] c3_l = u('H', b_a + 18) c3_a = u('I', b_a + 20) for i in range(c3_l): c3_arr.append(u('I', c3_a + i * 4)) c2_arr = [] c2_l = u('I', b_a + 10) c2_a = u('I', b_a + 14) for i in range(c2_l): c2_arr.append({'D1': u('b', c2_a + i * 7), 'D2': u('H', c2_a + i * 7 + 1), 'D3': u('f', c2_a + i * 7 + 3)}) r = {'A1': {'B1': u('h', b_a), 'B2': {'C1': u('d', b_a + 2), 'C2': c2_arr, 'C3': c3_arr, 'C4': u('f', b_a + 24), 'C5': u('H', b_a + 28)}, 'B3': u('B', b_a + 30), 'B4': u('d', b_a + 31)}, 'A2': {'E1': u('d', e_a), 'E2': e2_arr, 'E3': u('h', e_a + 12), 'E4': {'F1': u('h', e4_a), 'F2': u('h', e4_a + 2), 'F3': u('h', e4_a + 4), 'F4': u('f', e4_a + 6), 'F5': u('b', e4_a + 10)}}, 'A3': {'G1': u('h', g_a), 'G2': u('f', g_a + 2), 'G3': g3_arr}} return r" "from struct import unpack_from def main(bytes): A_offset = 3 A_dict = {} A_dict['A1'] = unpack_from('I', bytes, offset=5)[0] A2 = unpack_from('>q', bytes, offset=9)[0] A3 = [] for i in range(5): A3.append(unpack_from('>c', bytes, offset=17 + i)[0].decode()) A3 = ''.join(A3) A4 = unpack_from('>H', bytes, offset=22)[0] size_array_uint8 = unpack_from('>H', bytes, offset=24)[0] address_array_unit8 = unpack_from('>I', bytes, offset=26)[0] A5 = [] for i in range(size_array_uint8): A5.append(unpack_from('>B', bytes, offset=address_array_unit8 + i)[0]) A6 = unpack_from('>Q', bytes, offset=30)[0] B1 = unpack_from('>Q', bytes, offset=address_b)[0] B2 = unpack_from('>d', bytes, offset=address_b + 8)[0] C1 = unpack_from('>B', bytes, offset=address_b + 16)[0] C2 = unpack_from('>b', bytes, offset=address_b + 17)[0] size_array_addresses_d = unpack_from('>H', bytes, offset=address_b + 18)[0] address_array_addresses_d = unpack_from('>H', bytes, offset=address_b + 20)[0] address_d = [] for i in range(size_array_addresses_d): address_d.append(unpack_from('>I', bytes, offset=address_array_addresses_d + i * 4)[0]) B4 = [] for address in address_d: address_e = unpack_from('>H', bytes, offset=address)[0] E1 = unpack_from('>b', bytes, offset=address_e)[0] E2 = unpack_from('>f', bytes, offset=address_e + 1)[0] D2 = [] for i in range(5): D2.append(unpack_from('>B', bytes, offset=address + 2 + i)[0]) answer_d = {'D1': {'E1': E1, 'E2': E2}, 'D2': D2} B4.append(answer_d) answer = {'A1': {'B1': B1, 'B2': B2, 'B3': {'C1': C1, 'C2': C2}, 'B4': B4}, 'A2': A2, 'A3': A3, 'A4': A4, 'A5': A5, 'A6': A6} return answer" "import struct def main(data): structure = dict() structure_a = struct.unpack('=bQIIHHHd', data[4:35]) structure['A1'] = structure_a[0] structure['A2'] = structure_a[1] structure['A3'] = dict() structure['A4'] = dict() structure['A5'] = structure_a[4] structure['A6'] = [structure_a[5], structure_a[6]] structure['A7'] = structure_a[7] address_b = structure_a[2] structure_b = struct.unpack('=IIIi', data[address_b:address_b + 16]) structure['A3']['B1'] = '' for i in range(structure_b[0]): start = structure_b[1] + i symbol = struct.unpack('=c', data[start:start + 1])[0].decode('utf-8') structure['A3']['B1'] += symbol structure['A3']['B2'] = dict() structure['A3']['B3'] = structure_b[3] address_c = structure_b[2] structure_c = struct.unpack('=fibB', data[address_c:address_c + 10]) structure['A3']['B2']['C1'] = structure_c[0] structure['A3']['B2']['C2'] = structure_c[1] structure['A3']['B2']['C3'] = structure_c[2] structure['A3']['B2']['C4'] = structure_c[3] structure['A4'] = dict() address_d = structure_a[3] structure_d = struct.unpack('=QHQ', data[address_d:address_d + 18]) structure['A4']['D1'] = structure_d[0] structure['A4']['D2'] = structure_d[1] structure['A4']['D3'] = structure_d[2] structure['A4']['D4'] = [] for i in range(5): structure['A4']['D4'].append(dict()) start = address_d + 10 * i structure_e = struct.unpack('=IHI', data[start + 18:start + 28]) structure['A4']['D4'][i]['E1'] = [] start = structure_e[1] finish = structure_e[1] + structure_e[0] e_massive_structure = struct.unpack(f'={structure_e[0]}b', data[start:finish]) structure['A4']['D4'][i]['E1'] = list(e_massive_structure) structure['A4']['D4'][i]['E2'] = structure_e[2] return structure" "from struct import unpack_from def main(bytes): A_offset = 4 A_dict = {} A_dict['A1'] = [] B_offset = A_offset B_dict = {} B_dict['B1'] = unpack_from('>B', bytes, offset=B_offset)[0] B_offset += 1 B_dict['B2'] = [] C_offset = B_offset C_dict = {} C_dict['C1'] = unpack_from('>q', bytes, offset=C_offset)[0] C_offset += 8 C_dict['C2'] = [] D_offset = C_offset D_dict = {} some_size = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D1'] = list(unpack_from('>' + str(some_size) + 'h', bytes, offset=some_address)) D_dict['D2'] = unpack_from('>b', bytes, offset=D_offset)[0] D_offset += 1 some_size = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D3'] = list(unpack_from('>' + str(some_size) + 'd', bytes, offset=some_address)) D_dict['D4'] = unpack_from('>b', bytes, offset=D_offset)[0] D_offset += 1 C_dict['C2'].append(D_dict) C_offset = D_offset D_offset = C_offset D_dict = {} some_size = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D1'] = list(unpack_from('>' + str(some_size) + 'h', bytes, offset=some_address)) D_dict['D2'] = unpack_from('>b', bytes, offset=D_offset)[0] D_offset += 1 some_size = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D3'] = list(unpack_from('>' + str(some_size) + 'd', bytes, offset=some_address)) D_dict['D4'] = unpack_from('>b', bytes, offset=D_offset)[0] D_offset += 1 C_dict['C2'].append(D_dict) C_offset = D_offset B_dict['B2'].append(C_dict) B_offset = C_offset B_dict['B2'] = B_dict['B2'][0] A_dict['A1'].append(B_dict) A_offset = B_offset A_dict['A1'] = A_dict['A1'][0] A_dict['A2'] = unpack_from('>h', bytes, offset=A_offset)[0] A_offset += 2 A_dict['A3'] = unpack_from('>I', bytes, offset=A_offset)[0] A_offset += 4 A_dict['A4'] = unpack_from('>b', bytes, offset=A_offset)[0] A_offset += 1 A_dict['A5'] = unpack_from('>H', bytes, offset=A_offset)[0] A_offset += 2 A_dict['A6'] = unpack_from('>b', bytes, offset=A_offset)[0] A_offset += 1 A_dict['A7'] = unpack_from('>d', bytes, offset=A_offset)[0] A_offset += 8 A_dict['A8'] = [] E_offset = A_offset E_dict = {} E_dict['E1'] = unpack_from('>I', bytes, offset=E_offset)[0] E_offset += 4 some_size = unpack_from('>I', bytes, offset=E_offset)[0] E_offset += 4 some_address = unpack_from('>H', bytes, offset=E_offset)[0] E_offset += 2 E_dict['E2'] = list(unpack_from('>' + str(some_size) + 'B', bytes, offset=some_address)) A_dict['A8'].append(E_dict) A_offset = E_offset A_dict['A8'] = A_dict['A8'][0] return A_dict" "import struct def main(data): structure = dict() structure_a = struct.unpack('=bdH', data[3:14]) structure['A1'] = structure_a[0] structure['A2'] = structure_a[1] structure['A3'] = structure_a[2] structure['A4'] = [] start = 14 for i in range(3): structure['A4'].append(dict()) structure_b = struct.unpack('=ddb', data[start:start + 17]) start += 17 structure['A4'][i]['B1'] = structure_b[0] structure['A4'][i]['B2'] = structure_b[1] structure['A4'][i]['B3'] = structure_b[2] structure['A5'] = struct.unpack('=5s', data[start:start + 5])[0].decode('utf-8') structure_a = struct.unpack('=II', data[start + 5:start + 13]) structure['A6'] = dict() structure['A7'] = structure_a[1] address_c = structure_a[0] structure_c = struct.unpack('=BHIH', data[address_c:address_c + 9]) structure['A6']['C1'] = structure_c[0] start = structure_c[2] finish = structure_c[2] + 2 * structure_c[1] structure['A6']['C2'] = list(struct.unpack(f'={structure_c[1]}H', data[start:finish])) address_d = structure_c[3] structure_d = struct.unpack('=B4HIIbqdHQ', data[address_d:address_d + 44]) structure['A6']['C3'] = dict() structure['A6']['C3']['D1'] = structure_d[0] structure['A6']['C3']['D2'] = list(structure_d[1:5]) start = structure_d[6] finish = structure_d[6] + 2 * structure_d[5] structure['A6']['C3']['D3'] = list(struct.unpack(f'={structure_d[5]}H', data[start:finish])) structure['A6']['C3']['D4'] = structure_d[7] structure['A6']['C3']['D5'] = structure_d[8] structure['A6']['C3']['D6'] = structure_d[9] structure['A6']['C3']['D7'] = structure_d[10] structure['A6']['C3']['D8'] = structure_d[11] return structure" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('iH', data[pointer:pointer + 6])) f33 = struct.unpack('>II', data[pointer + 6:pointer + 14]) f3 = list(struct.unpack(f'>{f33[0]}H', data[f33[1]:f33[1] + f33[0] * 2])) return {'F1': f1, 'F2': f2, 'F3': f3} def parse_e(data, pointer): (e1, e2, e3) = list(struct.unpack('>fIQ', data[pointer:pointer + 16])) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2) = list(struct.unpack('>hd', data[pointer:pointer + 10])) f3 = struct.unpack('>I', data[pointer + 10:pointer + 14]) d3 = parse_e(data, f3[0]) (d4, d5) = list(struct.unpack('>HB', data[pointer + 14:pointer + 17])) f6 = struct.unpack('>HI', data[pointer + 17:pointer + 23]) d6 = list(struct.unpack(f'>{f6[0]}d', data[f6[1]:f6[1] + f6[0] * 8])) d7 = struct.unpack('>q', data[pointer + 23:pointer + 31])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def parse_c(data, pointer): (c1, c2) = list(struct.unpack('>bB', data[pointer:pointer + 2])) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = parse_c(data, pointer) (b2, b3) = list(struct.unpack('>Bd', data[pointer + 2:pointer + 11])) f4 = struct.unpack('>II', data[pointer + 11:pointer + 19]) b4 = ''.join(map(str, struct.unpack(f'>{f4[0]}c', data[f4[1]:f4[1] + f4[0]]))) b4 = b4.replace(""'"", '') b4 = b4[1::2] (b5, b6) = list(struct.unpack('>BH', data[pointer + 19:pointer + 22])) b7 = parse_d(data, pointer + 22) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) a1 = parse_b(data, f1[0]) a2 = list() for i in range(5): a2.append(parse_f(data, pointer + 2 + 14 * i)) return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 4)" "import struct def main(s): f_struct = struct.Struct('>IH2IIHbHi') e_struct = struct.Struct('>bIB') d_struct = struct.Struct('>qHBq') c_struct = struct.Struct('>2Iq') b_struct = struct.Struct(f'>I{e_struct.size}sfI') a_struct = struct.Struct('>dH2H') res = dict() a = a_struct.unpack_from(s, 3) res['A1'] = a[0] b_dict = dict() b = b_struct.unpack_from(s, a[1]) c_dict = dict() c = c_struct.unpack_from(s, b[0]) d_arr_struct = struct.Struct(f'>{c[0]}I') d_arr = d_arr_struct.unpack_from(s, c[1]) d_list = list() for i in d_arr: d = d_struct.unpack_from(s, i) d_dict = dict() d_dict['D1'] = d[0] d_dict['D2'] = d[1] d_dict['D3'] = d[2] d_dict['D4'] = d[3] d_list.append(d_dict) c_dict['C1'] = d_list c_dict['C2'] = c[2] b_dict['B1'] = c_dict e_dict = dict() e = e_struct.unpack_from(b[1]) e_dict['E1'] = e[0] f_dict = dict() f = f_struct.unpack_from(s, e[1]) f_arr1_struct = struct.Struct(f'>{f[0]}B') f_arr2_struct = struct.Struct(f'>{f[2]}b') f_arr3_struct = struct.Struct(f'>{f[4]}B') f_arr1 = f_arr1_struct.unpack_from(s, f[1]) f_arr2 = f_arr2_struct.unpack_from(s, f[3]) f_arr3 = f_arr3_struct.unpack_from(s, f[5]) f_dict['F1'] = list(f_arr1) f_dict['F2'] = list(f_arr2) f_dict['F3'] = list(f_arr3) f_dict['F4'] = f[6] f_dict['F5'] = f[7] f_dict['F6'] = f[8] e_dict['E2'] = f_dict e_dict['E3'] = e[2] b_dict['B2'] = e_dict b_dict['B3'] = b[2] b_dict['B4'] = b[3] res['A2'] = b_dict a_arr_struct = struct.Struct(f'>{a[2]}h') a_arr = a_arr_struct.unpack_from(s, a[3]) res['A3'] = list(a_arr) return res" "import struct def main(data): data = bytearray(data) class D: format = '>fffhHqhiBf' size = 35 def __init__(self, data, start=0): unpacked = struct.unpack(self.format, data[start:start + self.size]) self.struct = {'D1': [unpacked[i] for i in range(3)], 'D2': unpacked[3], 'D3': unpacked[4], 'D4': unpacked[5], 'D5': unpacked[6], 'D6': unpacked[7], 'D7': unpacked[8], 'D8': unpacked[9]} class C: format = '>ffffffffHH' size = 36 def __init__(self, data, start=0): unpacked = struct.unpack(self.format, data[start:start + self.size]) self.struct = {'C1': [unpacked[i] for i in range(8)], 'C2': unpacked[8], 'C3': unpacked[9]} class B: format = '>dqHHLbq' size = 33 def __init__(self, data, start=0): unpacked = struct.unpack(self.format, data[start:start + self.size]) self.struct = {'B1': unpacked[0], 'B2': unpacked[1], 'B3': unpacked[2], 'B4': [C(data, unpacked[4] + C.size * i).struct for i in range(unpacked[3])], 'B5': unpacked[5], 'B6': unpacked[6]} class A: format = '>ccbHHI' size = 11 def __init__(self, data, start=0): unpacked = struct.unpack(self.format, data[start:start + self.size]) self.struct = {'A1': str(unpacked[0].decode() + unpacked[1].decode()), 'A2': unpacked[2], 'A3': B(data, unpacked[3]).struct, 'A4': unpacked[4], 'A5': D(data, unpacked[5]).struct} if data[:5] == b'uJYFY': a = A(data, 5) return a.struct" "import struct def D(x, i): return {'D1': struct.unpack('> f', x[i:i + 4])[0], 'D2': struct.unpack('> B', x[i + 4:i + 5])[0], 'D3': struct.unpack('>H', x[i + 5:i + 7])[0], 'D4': struct.unpack('> h', x[i + 7:i + 9])[0]} def C(x, i): size = struct.unpack('> I', x[i:i + 4])[0] address = struct.unpack('> I', x[i + 4:i + 8])[0] c1 = struct.unpack('> ' + 'h' * size, x[address:address + 2 * size]) return {'C1': [D(x, addressD(x, address + j * 2)) for j in range(0, size)], 'C2': struct.unpack('> B', x[i + 8:i + 9])[0], 'C3': struct.unpack('> b', x[i + 9:i + 10])[0], 'C4': E(x, addressE(x, i + 10)), 'C5': F(x, addressE(x, i + 14)), 'C6': struct.unpack('>Q', x[i + 18:i + 26])[0], 'C7': struct.unpack('>I', x[i + 26:i + 30])[0]} def addressE(x, i): return struct.unpack('> I', x[i:i + 4])[0] def addressD(x, i): return struct.unpack('> H', x[i:i + 2])[0] def B(x, i): return {'B1': struct.unpack('> I', x[i:i + 4])[0], 'B2': struct.unpack('> d', x[i + 4:i + 12])[0]} def addressC(x, i): return struct.unpack('> H', x[i:i + 2])[0] def A(x, i): return {'A1': B(x, i), 'A2': struct.unpack('>4s', x[i + 12:i + 16])[0].decode('ascii'), 'A3': struct.unpack('> f', x[i + 16:i + 20])[0], 'A4': struct.unpack('>I', x[i + 20:i + 24])[0], 'A5': C(x, addressC(x, i + 24))} def S_u16Add_u32Ar_i16(x, i): size = struct.unpack('> H', x[i:i + 2])[0] address = struct.unpack('> I', x[i + 2:i + 6])[0] a = struct.unpack('> ' + 'h' * size, x[address:address + 2 * size]) return list(a) def E(x, i): return {'E1': struct.unpack('> h', x[i:i + 2])[0], 'E2': S_u16Add_u32Ar_i16(x, i + 2), 'E3': struct.unpack('> B', x[i + 8:i + 9])[0], 'E4': struct.unpack('> h', x[i + 9:i + 11])[0], 'E5': struct.unpack('> q', x[i + 11:i + 19])[0], 'E6': struct.unpack('> d', x[i + 19:i + 27])[0], 'E7': list(struct.unpack('> 8b', x[i + 27:i + 35]))} def F(x, i): return {'F1': struct.unpack('>Q', x[i:i + 8])[0], 'F2': struct.unpack('>I', x[i + 8:i + 12])[0], 'F3': struct.unpack('> B', x[i + 12:i + 13])[0], 'F4': S_u32Add_u16Ar_float(x, i + 13)} def S_u32Add_u16Ar_float(x, i): size = struct.unpack('> L', x[i:i + 4])[0] address = struct.unpack('> H', x[i + 4:i + 6])[0] a = struct.unpack('> ' + 'f' * size, x[address:address + 4 * size]) return list(a) def main(x): return A(x, 4)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.double), E2=reader.read(Primitive.uint16), E3=reader.read(Primitive.int8), E4=reader.read(Primitive.uint64), E5=reader.read(Primitive.int32), E6=read_array(reader, 1, reader.offset, lambda reader: reader.read(Primitive.int8), structure_size=8, toSum=True)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.uint32), D2=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.uint16), structure_size=7, toSum=True), D3=reader.read(Primitive.uint16)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.int32), C2=reader.read(Primitive.uint16), C3=reader.read(Primitive.int32), C4=reader.read(Primitive.float)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int16), B2=read_c(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), B3=''.join(read_array(reader, 1, reader.offset, lambda reader: reader.read(Primitive.char).decode('ascii'), structure_size=8, toSum=True)), B4=reader.read(Primitive.uint32), B5=reader.read(Primitive.uint16)) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.int8), A2=read_b(reader), A3=reader.read(Primitive.uint8), A4=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: read_d(reader), structure_size=20, toSum=False), A5=read_e(reader), A6=reader.read(Primitive.int16), A7=reader.read(Primitive.double), A8=reader.read(Primitive.uint64)) def main(source): return read_a(BinaryReader(source, offset=5))" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint64), structure_size=8), D2=reader.read(Primitive.uint8), D3=reader.read(Primitive.int16)) def read_c(reader: BinaryReader): return dict(C1=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), C2=read_array(reader, 8, reader.offset, lambda reader: reader.read(Primitive.int8), structure_size=1, toSum=True), C3=reader.read(Primitive.uint64)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int64), B2=reader.read(Primitive.int16), B3=reader.read(Primitive.uint16), B4=reader.read(Primitive.uint8), B5=[read_array(reader, 4, reader.read(Primitive.uint32), lambda reader: read_c(reader), structure_size=1)[0] for i in range(2)]) def read_a(reader: BinaryReader): return dict(A1=read_b(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), A2=reader.read(Primitive.uint32), A3=read_array(reader, 3, reader.offset, lambda reader: reader.read(Primitive.int64), structure_size=8, toSum=True)) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def A(x, i): size = struct.unpack('> H', x[i + 3:i + 5])[0] add = struct.unpack('> H', x[i + 5:i + 7])[0] a3 = '' for j in range(0, size): a3 += struct.unpack('> ' + 'c' * size, x[add:add + size])[j].decode('ascii') return {'A1': struct.unpack('> b', x[i:i + 1])[0], 'A2': struct.unpack('> H', x[i + 1:i + 3])[0], 'A3': a3, 'A4': B(x, address16(x, i + 7)), 'A5': [C(x, i + 9), C(x, i + 23)], 'A6': list(struct.unpack('> 3q', x[i + 37:i + 61])), 'A7': struct.unpack('> b', x[i + 61:i + 62])[0]} def B(x, i): return {'B1': struct.unpack('> d', x[i:i + 8])[0], 'B2': struct.unpack('> b', x[i + 8:i + 9])[0], 'B3': struct.unpack('> Q', x[i + 9:i + 17])[0], 'B4': struct.unpack('> B', x[i + 17:i + 18])[0]} def address16(x, i): return struct.unpack('> H', x[i:i + 2])[0] def C(x, i): return {'C1': D(x, address16(x, i)), 'C2': struct.unpack('> q', x[i + 2:i + 10])[0], 'C3': u16u16u32(x, i + 10)} def D(x, i): return {'D1': struct.unpack('> f', x[i:i + 4])[0], 'D2': struct.unpack('> f', x[i + 4:i + 8])[0]} def u16u16u32(x, i): size = struct.unpack('> H', x[i:i + 2])[0] add = struct.unpack('> H', x[i + 2:i + 4])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def main(x): return A(x, 3)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = list(struct.unpack('>QB', data[pointer:pointer + 9])) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): c1 = list() c1.append(parse_d(data, pointer)) c1.append(parse_d(data, pointer + 9)) (c2, c3, c4) = list(struct.unpack('>qiI', data[pointer + 18:pointer + 34])) f5 = struct.unpack('>HI', data[pointer + 34:pointer + 40]) c5 = list(struct.unpack(f'>{f5[0]}b', data[f5[1]:f5[1] + f5[0]])) c6 = struct.unpack('>B', data[pointer + 40:pointer + 41])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): b1 = parse_c(data, pointer) f2 = struct.unpack('>II', data[pointer + 41:pointer + 49]) b2 = list(struct.unpack(f'>{f2[0]}H', data[f2[1]:f2[1] + f2[0] * 2])) b3 = struct.unpack('>b', data[pointer + 49:pointer + 50])[0] b4 = list(struct.unpack('>6b', data[pointer + 50:pointer + 56])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): a1 = struct.unpack('>H', data[pointer:pointer + 2])[0] f2 = struct.unpack('>H', data[pointer + 2:pointer + 4]) a2 = parse_b(data, f2[0]) return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_e(data, pointer): e1 = list(struct.unpack('>8b', data[pointer:pointer + 8])) (e2, e3) = list(struct.unpack('>Bf', data[pointer + 8:pointer + 13])) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2) = list(struct.unpack('>Bq', data[pointer:pointer + 9])) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2, c3) = list(struct.unpack('>bfI', data[pointer:pointer + 9])) c4 = list(struct.unpack('>6I', data[pointer + 9:pointer + 33])) c5 = struct.unpack('>H', data[pointer + 33:pointer + 35])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = ''.join(map(str, struct.unpack('<7c', data[pointer:pointer + 7]))) b1 = b1.replace(""'"", '') b1 = b1[1::2] b2 = struct.unpack('>q', data[pointer + 7:pointer + 15])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = list() f2 = struct.unpack('>I', data[pointer + 15:pointer + 19]) f22 = struct.unpack('>I', data[pointer + 19:pointer + 23]) a2.append(parse_c(data, f2[0])) a2.append(parse_c(data, f22[0])) (a3, a4, a5) = list(struct.unpack('>fHq', data[pointer + 23:pointer + 37])) a6 = parse_d(data, pointer + 37) a7 = parse_e(data, pointer + 46) a8 = struct.unpack('>q', data[pointer + 59:pointer + 67])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 4)" "import struct def F(data, start): f1 = struct.unpack('>h', data[start:start + 2])[0] f2 = struct.unpack('>i', data[start + 2:start + 6])[0] f3 = struct.unpack('>h', data[start + 6:start + 8])[0] return {'F1': f1, 'F2': f2, 'F3': f3} def E(data, start): e1 = struct.unpack('>H', data[start:start + 2])[0] e2 = struct.unpack('>Q', data[start + 2:start + 10])[0] return {'E1': e1, 'E2': e2} def D(data, start): add_e = struct.unpack('>H', data[start:start + 2])[0] start += 2 d1 = E(data, add_e) d2 = struct.unpack('>b', data[start:start + 1])[0] d3 = struct.unpack('>q', data[start + 1:start + 9])[0] d4 = struct.unpack('>B', data[start + 9:start + 10])[0] add_f = struct.unpack('>H', data[start + 10:start + 12])[0] start += 12 d5 = F(data, add_f) d6 = struct.unpack('>i', data[start:start + 4])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def B(data, start): b1 = struct.unpack('>q', data[start:start + 8])[0] b2 = struct.unpack('>Q', data[start + 8:start + 16])[0] b3 = struct.unpack('>d', data[start + 16:start + 24])[0] b4 = struct.unpack('>b', data[start + 24:start + 25])[0] b5 = struct.unpack('>I', data[start + 25:start + 29])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def C(data, address, size): start = address result = [] for i in range(0, size): c1 = D(data, start) start += 18 c2 = struct.unpack('>q', data[start:start + 8])[0] c3 = struct.unpack('>d', data[start + 8:start + 16])[0] c4 = list(struct.unpack('>5s', data[start + 16:start + 21])) c4_str = b''.join(c4).decode('ascii') c5 = list(struct.unpack('>6b', data[start + 21:start + 27])) start += 27 result.append({'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4_str, 'C5': c5}) return result def main(data): start = 0 while hex(data[start]) != '0xb' and hex(data[start]) != '0x42' and (hex(data[start]) != '0x4f') and (hex(data[start]) != '0x43') and (hex(data[start]) != '0x4a'): start += 1 start += 5 a1 = B(data, start) start += 29 size_c = struct.unpack('>I', data[start:start + 4])[0] adress_c = struct.unpack('>H', data[start + 4:start + 6])[0] start += 6 a2 = C(data, adress_c, size_c) a3 = struct.unpack('>I', data[start:start + 4])[0] a4 = list(struct.unpack('>3h', data[start + 4:start + 10])) a5 = struct.unpack('>b', data[start + 10:start + 11])[0] out_dict = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} return out_dict" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3, e4) = list(struct.unpack(' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 a2 = struct_b(offset) offset += 2 + 2 + 4 + 4 + 2 + 1 + 4 + 2 [a3] = struct.unpack('> b', binary[offset:offset + 1]) return {'A1': a1, 'A2': a2, 'A3': a3} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [b2] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 b3 = list(struct.unpack('> ' + str(length1) + 'H', binary[link_str:link_str + length1 * 2])) [b4] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [b5] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [b6] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [b7] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'B1': b1, 'B2': b2, 'B3': [struct_c(i) for i in b3], 'B4': b4, 'B5': b5, 'B6': b6, 'B7': struct_d(b7)} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [c2] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [c3] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 [c4] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 d3 = list(struct.unpack('> ' + str(length1) + 'B', binary[link_str:link_str + length1 * 1])) d4 = struct_f(offset) offset += 2 + 4 + 16 + 8 + 16 + 1 + 8 return {'D1': d1, 'D2': struct_e(d2), 'D3': d3, 'D4': d4} def struct_e(offset: int) -> dict: e1 = list(struct.unpack('> ' + str(7) + 'H', binary[offset:offset + 7 * 2])) offset += 7 * 2 [e2] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [e3] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [e4] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def struct_f(offset: int) -> dict: [f1] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [f2] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 f3 = list(struct.unpack('> 4I', binary[offset:offset + 4 * 4])) offset += 16 [f4] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 f5 = list(struct.unpack('> 2q', binary[offset:offset + 2 * 8])) offset += 16 [f6] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [f7] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7} return struct_a(4) dic = main(b'VZEU\t\x85\n\xee\x99\x00\x00\x00\x02\x00\x00\x00;\xd3R\xa4\xcf3s\x85\x00d\x05J{z\x01J\x9e\xe0Q>{\x0b\x00\x1b\x00+\xfb;\xb4\x90le\xcft4\\\x9e\xefh\xc2{\xc1\xaez\x10K\xed\xfd\xd39\x9d\xf7r\x1aH>x\xb7\x80\xdfa\xd7U\x92g\xdb\xd0\x00\x00\x00?\x00\x00\x00\x03\x00a\xeaR\xb7\xbcF\x95Ny\x15\xca\x00F\xf8`\xc5Z\xe2\x0b|\x84]\xf1\xbfN\xa2j\x10S`\x00\x11\xe1\xa1\x12sl\xd1\xb1\xbd\x01\xe3Z\x1eW\xc4t\xbf\x8b""-f\x1a(9g')" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [a2] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 le = 4 + 4 + 8 a3 = [struct_d(offset + i * le) for i in range(3)] offset += (4 + 4 + 8) * 3 [a4] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'A1': struct_b(a1), 'A2': a2, 'A3': a3, 'A4': a4} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [b2] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [b3] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [b4] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [b5] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 return {'B1': b1, 'B2': struct_c(b2), 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 c2 = list(struct.unpack('> 7c', binary[offset:offset + 7 * 1])) offset += 7 * 1 c2 = [i.decode('UTF-8') for i in c2] return {'C1': c1, 'C2': ''.join(c2)} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 d3 = list(struct.unpack('> ' + str(length1) + 'H', binary[link_str:link_str + length1 * 2])) return {'D1': struct_e(d1), 'D2': struct_f(d2), 'D3': d3} def struct_e(offset: int) -> dict: [e1] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [e2] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 return {'E1': e1, 'E2': e2} def struct_f(offset: int) -> dict: f1 = list(struct.unpack('> 2b', binary[offset:offset + 2 * 1])) offset += 2 * 1 [f2] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 [f3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 return {'F1': f1, 'F2': f2, 'F3': f3} return struct_a(4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_C(data, ofs): (C1, ofs) = parse('uint64', data, ofs) (C2, ofs) = parse('int32', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('float', data, ofs) (B2, ofs) = parse('double', data, ofs) (B3_size, ofs) = parse('uint32', data, ofs) (B3_adr, ofs) = parse('uint32', data, ofs) B3 = '' for i in range(B3_size): (has, B3_adr) = parse('char', data, B3_adr) B3 += has.decode() (B4, ofs) = parse('uint32', data, ofs) B5 = '' for _ in range(2): (has, ofs) = parse('char', data, ofs) B5 += has.decode() (B6, ofs) = parse('uint16', data, ofs) (B6, h) = struct_C(data, B6) (B7, ofs) = parse('double', data, ofs) (B8, ofs) = parse('int8', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6, B7=B7, B8=B8), ofs) def struct_D(data, ofs): D1 = [] for _ in range(2): (b, ofs) = parse('uint16', data, ofs) D1.append(b) D2 = [] for _ in range(3): (b, ofs) = parse('float', data, ofs) D2.append(b) (D3, ofs) = parse('int8', data, ofs) (D4, ofs) = parse('int32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def parse_main(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = parse('uint64', data, ofs) A3 = [] for _ in range(4): (has, ofs) = struct_D(data, ofs) A3.append(has) (A4, ofs) = parse('uint8', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4) def main(data): return parse_main(data, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint16', data, ofs) (E2, ofs) = parse('double', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) C2 = [] for _ in range(2): (u, ofs) = struct_D(data, ofs) C2.append(u) (C3, ofs) = parse('double', data, ofs) (C4, ofs) = struct_E(data, ofs) (C5, ofs) = parse('uint16', data, ofs) C5 = struct_F(data, C5) (C6, ofs) = struct_G(data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int16', data, ofs) (B2, ofs) = parse('double', data, ofs) (B3, ofs) = struct_C(data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int64', data, ofs) (D2, ofs) = parse('int16', data, ofs) (D3, ofs) = parse('uint16', data, ofs) (D4, ofs) = parse('uint32', data, ofs) (D5, ofs) = parse('uint8', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def parse_main(data, ofs): (A1, ofs) = parse('int64', data, ofs) (A2, ofs) = parse('uint32', data, ofs) (A2, hut) = struct_B(data, A2) (A3, ofs) = parse('uint16', data, ofs) (A4, ofs) = parse('int64', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4) def main(data): return parse_main(data, 4)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [a2] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [a3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 a4 = struct_f(offset) offset += 4 + 4 + 1 + 4 [a5] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'A1': struct_b(a1), 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [b2] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [b3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'B1': b1, 'B2': b2, 'B3': struct_c(b3)} def struct_c(offset: int) -> dict: (size, str_offset) = struct.unpack('> I I', binary[offset:offset + 8]) c1 = [struct_d(str_offset + i * (4 + 12 + 2 + 6)) for i in range(size)] offset += 8 c2 = struct_e(offset) offset += 6 [c3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [c4] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 (size, address) = struct.unpack('> H H', binary[offset:offset + 4]) c5 = list(struct.unpack('>' + str(size) + 'B', binary[address:address + size])) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 d2 = list(struct.unpack('> 3i', binary[offset:offset + 12])) offset += 12 [d3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 (size, address) = struct.unpack('> I H', binary[offset:offset + 6]) d4 = list(struct.unpack('>' + str(size) + 'h', binary[address:address + 2 * size])) offset += 6 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def struct_e(offset: int) -> dict: [e1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [e2] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [e3] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 return {'E1': e1, 'E2': e2, 'E3': e3} def struct_f(offset: int) -> dict: [f1] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [f2] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [f3] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [f4] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4} return struct_a(4)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack('>QdHQ', data[pointer:pointer + 26]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): c1 = list(struct.unpack('>7b', data[pointer:pointer + 7])) c2 = struct.unpack('>d', data[pointer + 7:pointer + 15])[0] f3 = struct.unpack('>HH', data[pointer + 15:pointer + 19]) c3 = list(struct.unpack(f'>{f3[0]}f', data[f3[1]:f3[1] + f3[0] * 4])) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>bqB', data[pointer:pointer + 10]) f4 = struct.unpack('>HH', data[pointer + 10:pointer + 14]) b4 = list(struct.unpack(f'>{f4[0]}h', data[f4[1]:f4[1] + f4[0] * 2])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, f1[0]) a2 = struct.unpack('>B', data[pointer + 4:pointer + 5])[0] f3 = struct.unpack('>IH', data[pointer + 5:pointer + 11]) a3 = list() for i in range(f3[0]): f33 = struct.unpack('>I', data[f3[1] + 4 * i:f3[1] + 4 + 4 * i]) a3.append(parse_c(data, f33[0])) (a4, a5) = struct.unpack('>hB', data[pointer + 11:pointer + 14]) f6 = struct.unpack('>I', data[pointer + 14:pointer + 18]) a6 = parse_d(data, f6[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 4)" "from struct import * class Types: (int8, uint8) = ('b', 'B') (int16, uint16) = ('h', 'H') (int32, uint32) = ('i', 'I') float = 'f' B_STRUCT_ARRAY_SIZE = 4 C_STRUCT_POINTERS_ARRAY_SIZE = 4 def main(buffer): A1_size = unpack(Types.uint16, buffer[4:6])[0] A1_address = unpack(Types.uint16, buffer[6:8])[0] A2 = unpack(Types.int32, buffer[8:12])[0] A3_size = unpack(Types.uint32, buffer[12:16])[0] A3_address = unpack(Types.uint16, buffer[16:18])[0] A4 = unpack(Types.float, buffer[18:22])[0] A1 = list() for i in range(A1_size): shift = A1_address + i * B_STRUCT_ARRAY_SIZE B1 = unpack(Types.int16, buffer[shift:shift + 2])[0] B2 = unpack(Types.int16, buffer[shift + 2:shift + 4])[0] A1.append({'B1': B1, 'B2': B2}) A3 = list() for i in range(A3_size): shift = A3_address + i * C_STRUCT_POINTERS_ARRAY_SIZE address = unpack(Types.uint32, buffer[shift:shift + 4])[0] C1_address = unpack(Types.uint16, buffer[address:address + 2])[0] C2 = unpack(Types.int32, buffer[address + 2:address + 6])[0] C3 = unpack(Types.int32, buffer[address + 6:address + 10])[0] C4 = unpack(Types.int8, buffer[address + 10:address + 11])[0] C5_size = unpack(Types.uint32, buffer[address + 11:address + 15])[0] C5_address = unpack(Types.uint16, buffer[address + 15:address + 17])[0] C6 = list() for j in range(3): shift = address + 17 + j C6.append(unpack(Types.uint8, buffer[shift:shift + 1])[0]) C1 = dict() C1['D1'] = unpack(Types.uint16, buffer[C1_address:C1_address + 2])[0] C1['D2'] = unpack(Types.int32, buffer[C1_address + 2:C1_address + 6])[0] C1['D3'] = unpack(Types.int8, buffer[C1_address + 6:C1_address + 7])[0] C5 = list() for j in range(C5_size): shift = C5_address + j * 4 C5.append(unpack(Types.uint32, buffer[shift:shift + 4])[0]) A3.append({'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5, 'C6': C6}) return {'A1': A1, 'A2': A2, 'A3': A3, 'A4': A4}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint16', data, ofs) (E2, ofs) = parse('double', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = parse('int8', data, ofs) (C2, ofs) = parse('uint32', data, ofs) (C3_size, ofs) = parse('uint16', data, ofs) (C3_adr, ofs) = parse('uint32', data, ofs) C3 = [] for _ in range(C3_size): (h, C3_adr) = parse('int16', data, C3_adr) C3.append(h) (C4, ofs) = parse('float', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint32', data, ofs) B1 = '' for _ in range(B1_size): (has, B1_adr) = parse('char', data, B1_adr) B1 += has.decode() (B2, ofs) = parse('int8', data, ofs) (B3, ofs) = parse('double', data, ofs) (B4, ofs) = parse('int64', data, ofs) (B5, ofs) = parse('int64', data, ofs) (B6_size, ofs) = parse('uint32', data, ofs) (B6_adr, ofs) = parse('uint32', data, ofs) B6 = '' for _ in range(B6_size): (has, B6_adr) = parse('char', data, B6_adr) B6 += has.decode() return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) (D2, ofs) = parse('uint64', data, ofs) return (dict(D1=D1, D2=D2), ofs) def parse_main(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = parse('float', data, ofs) (A3_size, ofs) = parse('uint16', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) A3 = [] for i in range(A3_size): (g, A3_adr) = parse('uint32', data, A3_adr) (j, k) = struct_C(data, g) A3.append(j) (A4, ofs) = parse('uint8', data, ofs) (A5_adr, ofs) = parse('uint16', data, ofs) (A5, ofs) = struct_D(data, A5_adr) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5) def main(data): return parse_main(data, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int64', data, ofs) (E2, ofs) = parse('int8', data, ofs) (E3, ofs) = parse('double', data, ofs) (E4, ofs) = parse('uint32', data, ofs) (E5, ofs) = parse('float', data, ofs) (E6, ofs) = parse('uint8', data, ofs) (E7, ofs) = parse('int64', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) (C2_size, ofs) = parse('uint32', data, ofs) (C2_adr, ofs) = parse('uint16', data, ofs) C2 = [] for _ in range(C2_size): (h, C2_adr) = parse('int8', data, C2_adr) C2.append(h) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) (B2_size, ofs) = parse('uint16', data, ofs) (B2_adr, ofs) = parse('uint32', data, ofs) B2 = [] for _ in range(B2_size): (has, B2_adr) = struct_C(data, B2_adr) B2.append(has) (B3, ofs) = parse('int8', data, ofs) (B4, ofs) = parse('int32', data, ofs) (B5, ofs) = parse('uint64', data, ofs) (B6, ofs) = parse('float', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint64', data, ofs) (D2_size, ofs) = parse('uint16', data, ofs) (D2_adr, ofs) = parse('uint16', data, ofs) D2 = [] for _ in range(D2_size): (has, D2_adr) = parse('uint64', data, D2_adr) D2.append(has) return (dict(D1=D1, D2=D2), ofs) def parse_main(data, ofs): (A1, ofs) = parse('uint8', data, ofs) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, lok) = struct_B(data, A2_adr) (A3, ofs) = parse('int64', data, ofs) (A4_size, ofs) = parse('uint32', data, ofs) (A4_adr, ofs) = parse('uint16', data, ofs) A4 = '' for _ in range(A4_size): (has, A4_adr) = parse('char', data, A4_adr) A4 += has.decode() (A5, ofs) = parse('uint8', data, ofs) (A6, ofs) = struct_D(data, ofs) (A7, ofs) = struct_E(data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7) def main(data): return parse_main(data, 3)" "import struct import pprint def parse_f(data, pointer): f1 = struct.unpack('>B', data[pointer:pointer + 1])[0] f2 = list(struct.unpack('>3d', data[pointer + 1:pointer + 25])) f3 = struct.unpack('>H', data[pointer + 25:pointer + 27])[0] f4 = list(struct.unpack('>8H', data[pointer + 27:pointer + 43])) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4} def parse_e(data, pointer): (e1, e2) = struct.unpack('>Qf', data[pointer:pointer + 12]) e3 = parse_f(data, pointer + 12) (e4, e5) = struct.unpack('>Id', data[pointer + 55:pointer + 67]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def parse_d(data, pointer): (d1, d2) = struct.unpack('>Ih', data[pointer:pointer + 6]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>dib', data[pointer:pointer + 13]) f4 = struct.unpack('>IH', data[pointer + 13:pointer + 19]) c4 = list() for i in range(f4[0]): f44 = struct.unpack('>I', data[f4[1] + 4 * i:f4[1] + 4 + 4 * i]) c4.append(parse_d(data, f44[0])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): (b1, b2, b3, b4, b5) = struct.unpack('>bIBdi', data[pointer:pointer + 18]) b6 = parse_c(data, pointer + 18) b7 = struct.unpack('>b', data[pointer + 37:pointer + 38])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): a1 = parse_b(data, pointer) f2 = struct.unpack('>II', data[pointer + 38:pointer + 46]) a2 = ''.join(map(str, struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0]]))) a2 = a2.replace(""'"", '') a2 = a2[1::2] a3 = parse_e(data, pointer + 46) (a4, a5, a6, a7) = struct.unpack('>dBfB', data[pointer + 113:pointer + 127]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 5)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 54: break a = {f'A{i}': None for i in range(1, 3)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 6)} e = {f'E{i}': None for i in range(1, 3)} temp = unpack('>fBQqQdHL5b7QLL', file[a_adr:a_adr + 112]) (a['A1'], *b_struct, a['A3']) = temp (b['B1'], b['B2'], *c_struct, b['B4']) = b_struct (c['C1'], c['C2'], c['C3'], d_size, d_adr, *e_struct) = c_struct c['C4'] = [] (e['E1'], e['E2']) = (list(e_struct[0:5]), list(e_struct[5:12])) (d_addr_1, d_addr_2) = unpack(f'>{d_size}H', file[d_adr:d_adr + 4]) temp = unpack(f'>3hLqh', file[d_addr_1:d_addr_1 + 20]) c['C4'].append({'D1': list(temp[0:3]), 'D2': temp[3], 'D3': temp[4], 'D4': temp[5]}) temp = unpack(f'>3hLqh', file[d_addr_2:d_addr_2 + 20]) c['C4'].append({'D1': list(temp[0:3]), 'D2': temp[3], 'D3': temp[4], 'D4': temp[5]}) a['A2'] = b b['B3'] = c c['C5'] = e return a" "from struct import unpack def parse_1(a, b, file, b_addrs): for addr in b_addrs: temp = unpack('>BbHHH', file[addr:addr + 8]) (b['B1'], b['B2'], b['B3'], ch_size, ch_addr) = temp temp = unpack(f'>{ch_size}c', file[ch_addr:ch_addr + ch_size]) b['B4'] = ''.join((str(e, 'utf8') for e in temp)) a['A2'].append(b.copy()) def parse_2(d, d3_values): for value in d3_values: d['D3'].append(value) def parse_3(c, c4_values): for value in c4_values: c['C4'].append(value) def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 218: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>f4LhLQhf5h', file[a_adr:a_adr + 50]) a['A1'] = temp[0] a['A2'] = list() b_addrs = temp[1:5] (a['A3'], c_addr, a['A5'], a['A6'], a['A7']) = temp[5:10] a['A8'] = list(temp[10:]) parse_1(a, b, file, b_addrs) temp = unpack('>bqdb7L6Ll', file[c_addr:c_addr + 74]) (c['C1'], c['C2'], d['D1'], d['D2']) = temp[0:4] d3_values = temp[4:11] d['D3'] = [] c['C4'] = [] parse_2(d, d3_values) c4_values = temp[11:17] parse_3(c, c4_values) c['C5'] = temp[-1] c['C3'] = d a['A4'] = c return a" "from struct import unpack def parse(d, temp): for value in temp[17:25]: d['D5'].append(value) def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 73: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 7)} temp = unpack('{e[0]}H', file[e[1]:e[1] + e[0] * 2]) c['C1'] = list(temp) c['C2'] = e[2] a['A3'].append(c.copy()) def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 99: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>lLLHLQLQB', file[a_adr:a_adr + 39]) (a['A1'], b_adr, c_size, c_adr, a['A4'], a['A5'], d_adr, a['A7'], a['A8']) = temp temp = unpack('>8cH', file[b_adr:b_adr + 10]) (*ch_arr, b['B2']) = temp b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A3'] = [] temp = unpack(f"">{c_size * 'HLl'}"", file[c_adr:c_adr + c_size * 10]) parse(temp, a, c, file) temp = unpack('>5BdH', file[d_adr:d_adr + 15]) (*d1_arr, d['D2'], d['D3']) = temp d['D1'] = [e for e in d1_arr] a['A2'] = b a['A6'] = d return a" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 65: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 7)} c = {f'C{i}': None for i in range(1, 7)} d = {f'D{i}': None for i in range(1, 5)} temp = unpack('>HLb4LQbL8hbBHLdL', file[a_adr:a_adr + 72]) (b['B1'], b['B2'], b['B3'], *c_struct, b['B5'], uint32_size, uint32_adr, a['A2'], a['A3']) = temp d_adrs = c_struct[0:4] (c['C2'], c['C3'], c['C4'], *c5, c['C6']) = c_struct[4:] c['C5'] = [e for e in c5] temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) b['B6'] = list(temp) c['C1'] = [] for d_adr in d_adrs: temp = unpack('>hLLHb', file[d_adr:d_adr + 13]) (d['D1'], f_arr_size, f_arr_adr, d['D3'], d['D4']) = temp temp = unpack(f'>{f_arr_size}f', file[f_arr_adr:f_arr_adr + f_arr_size * 4]) d['D2'] = list(temp) c['C1'].append(d.copy()) a['A1'] = b b['B4'] = c return a" "import struct SIGNATURE = bytes([79, 77, 66, 244]) ORDER = '<' def get_array_pattern(size, type_s): pattern = ORDER + type_s * size return pattern def calcsize(pattern): return struct.calcsize(ORDER + pattern) def create_dict(name: str, structure: tuple) -> dict: dictionary = dict() for i in range(len(structure)): dictionary.update({name + str(i + 1): structure[i]}) return dictionary def f(byte_str: bytes) -> dict: begin = byte_str.find(SIGNATURE) assert begin >= 0 A_pattern = 'hb{0}sB{1}s' B_pattern = 'fq3s' C_pattern = '{0}sQf4hdB2h' D_pattern = 'dBqBH7Ii' C_pattern = C_pattern.format(calcsize(D_pattern)) A_pattern = A_pattern.format(calcsize(B_pattern) * 4, calcsize(C_pattern)) A_pos = [begin + len(SIGNATURE), begin + len(SIGNATURE) + calcsize(A_pattern)] A = struct.unpack(ORDER + A_pattern, byte_str[A_pos[0]:A_pos[1]]) A = create_dict('A', A) B_arr = [] for i in range(0, 4): B = struct.unpack(ORDER + B_pattern, A['A3'][calcsize(B_pattern) * i:calcsize(B_pattern) * (i + 1)]) B = [B[0], B[1], B[2].decode('utf-8')] B_arr.append(B) A['A3'] = [create_dict('B', B_arr[0]), create_dict('B', B_arr[1]), create_dict('B', B_arr[2]), create_dict('B', B_arr[3])] C1 = A['A5'] C1 = C1[0:calcsize(D_pattern)] C1 = struct.unpack(ORDER + D_pattern, C1) D6 = [] for i in C1[5:12]: D6.append(i) C1 = {'D1': C1[0], 'D2': C1[1], 'D3': C1[2], 'D4': C1[3], 'D5': C1[4], 'D6': D6, 'D7': C1[12]} A5 = struct.unpack(ORDER + C_pattern, A['A5']) A66 = [] for i in A5[9:11]: A66.append(i) C44 = [] for i in A5[3:7]: C44.append(i) A['A5'] = create_dict('C', [A5[0], A5[1], A5[2], C44, A5[7], A5[8], A66]) A['A5']['C1'] = C1 return A def main(x): return f(x)" "from struct import unpack def main(file): a_adr = 0 for (i, byte) in enumerate(file): a_adr += 1 if byte == 83 and i != 1: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>LQBhHHHHLh', file[a_adr:a_adr + 29]) (b_adr, a['A2'], a['A3'], a['A4'], c_adr, d_adrs_size, d_adrs_adr, int16_size, int16_adr, a['A8']) = temp temp = unpack('>lh', file[b_adr:b_adr + 6]) (b['B1'], b['B2']) = temp temp = unpack('>5b2c', file[c_adr:c_adr + 7]) c['C1'] = list(temp[0:5]) c['C2'] = ''.join((str(e, 'utf8') for e in temp[5:7])) d_adrs = unpack(f'>{d_adrs_size}L', file[d_adrs_adr:d_adrs_adr + d_adrs_size * 4]) a['A6'] = [] for d_adr in d_adrs: temp = unpack('>dQd', file[d_adr:d_adr + 24]) (d['D1'], d['D2'], d['D3']) = temp a['A6'].append(d.copy()) temp = unpack(f'>{int16_size}h', file[int16_adr:int16_adr + int16_size * 2]) a['A7'] = list(temp) a['A1'] = b a['A5'] = c return a" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 205: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 6)} temp = unpack('BhHq6cHLL', file[a_adr:a_adr + 29]) (a['A1'], a['A2'], a['A3'], a['A4'], *ch_arr, b_arr_size, b_arr_adr, c_adr) = temp a['A5'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A6'] = [] b_adrs = unpack(f'>{b_arr_size}H', file[b_arr_adr:b_arr_adr + b_arr_size * 2]) for b_adr in b_adrs: temp = unpack('>qhb', file[b_adr:b_adr + 11]) (b['B1'], b['B2'], b['B3']) = temp a['A6'].append(b.copy()) temp = unpack('>l8b3bQb3hHfqbdHL', file[c_adr:c_adr + 59]) c['C1'] = temp[0] d['D1'] = list(temp[1:9]) d['D2'] = list(temp[9:12]) (d['D3'], e['E1'], *e2, e['E3'], e['E4'], e['E5'], c['C4'], c['C5'], c['C6'], c['C7']) = temp[12:] e['E2'] = list(e2) c['C2'] = d c['C3'] = e a['A7'] = c return a" "from struct import unpack def parse(c, d_arr_size, d_arr_adr, d, file): c['C5'] = [] temp = unpack(f""<{d_arr_size * 'dlhLLL'}"", file[d_arr_adr:d_arr_adr + d_arr_size * 26]) d_structs = [] temp_arr = [] count = 0 for i in range(0, len(temp)): temp_arr.append(temp[i]) count += 1 if count == 6: d_structs.append(temp_arr) temp_arr = [] count = 0 for d_struct in d_structs: (d['D1'], d['D2'], d['D3'], d['D4'], arr_size, arr_adr) = d_struct temp = unpack(f'<{arr_size}h', file[arr_adr:arr_adr + arr_size * 2]) d['D5'] = list(temp) c['C5'].append(d.copy()) def main(file): a_adr = 0 for (i, byte) in enumerate(file): a_adr += 1 if byte == 66 and i != 1: break a = {f'A{i}': None for i in range(1, 6)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 7)} d = {f'D{i}': None for i in range(1, 6)} temp = unpack('<2cQHlHHL', file[a_adr:a_adr + 24]) (*ch_arr, b['B1'], b['B2'], a['A3'], c_adr, d_arr_size, d_arr_adr) = temp a['A1'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A5'] = list(unpack(f'<{d_arr_size}d', file[d_arr_adr:d_arr_adr + d_arr_size * 8])) temp = unpack(' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 le = 2 + 2 + 8 + 4 + 8 a2 = [struct_b(link_str + i * le) for i in range(length1)] [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a3 = list(struct.unpack('< ' + str(length1) + 'Q', binary[link_str:link_str + length1 * 8])) a4 = struct_d(offset) offset += 4 + 2 + 4 [a5] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [a6] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [a7] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 a8 = list(struct.unpack('< 2h', binary[offset:offset + 2 * 2])) offset += 2 * 2 return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [b2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 b3 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1])) b3 = [i.decode('UTF-8') for i in b3] [b4] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 b5 = list(struct.unpack('< 4h', binary[offset:offset + 4 * 2])) offset += 4 * 2 return {'B1': struct_c(b1), 'B2': b2, 'B3': ''.join(b3), 'B4': b4, 'B5': b5} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [c2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [c3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d3] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3} return struct_a(4)" "import struct def create_c_structures(data, address): result = [] for c_address in struct.unpack('>7I', data[address:address + 28]): c1 = list(struct.unpack('>2B', data[c_address:c_address + 2])) c2 = struct.unpack('>I', data[c_address + 2:c_address + 6])[0] result.append({'C1': c1, 'C2': c2}) return result def main(data): a1 = struct.unpack('>4s', data[5:9])[0].decode('ascii') a2 = struct.unpack('>h', data[9:11])[0] b1 = struct.unpack('>I', data[11:15])[0] b2 = struct.unpack('>b', data[15:16])[0] b3 = struct.unpack('>h', data[16:18])[0] b4 = create_c_structures(data, 18) d1 = list(struct.unpack('>7f', data[46:74])) d2 = struct.unpack('>I', data[74:78])[0] d3 = list(struct.unpack('>2d', data[78:94])) d4 = struct.unpack('>B', data[94:95])[0] out_dict = {'A1': a1, 'A2': a2, 'A3': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4}, 'A4': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}} return out_dict" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = 'Q' int64 = 'q' uint32 = 'I' int32 = 'i' uint16 = 'H' int16 = 'h' uint8 = 'B' int8 = 'b' float = 'f' double = 'd' char = 'c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.int32), D2=reader.read(Primitive.uint8), D3=reader.read(Primitive.uint16), D4=read_array(reader, 6, reader.offset, lambda reader: reader.read(Primitive.uint8), structure_size=1, toSum=True)) def read_c(reader: BinaryReader): return dict(C1=''.join(read_array(reader, 8, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1, toSum=True)), C2=reader.read(Primitive.int8), C3=reader.read(Primitive.uint64), C4=reader.read(Primitive.int32), C5=reader.read(Primitive.uint8), C6=reader.read(Primitive.int16), C7=reader.read(Primitive.float)) def read_b(reader: BinaryReader): return dict(B1=read_c(reader), B2=reader.read(Primitive.float), B3=''.join(read_array(reader, 5, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1, toSum=True)), B4=reader.read(Primitive.int32)) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.int16), A2=read_b(reader), A3=reader.read(Primitive.float), A4=[read_d(BinaryReader(reader.source, offset=i)) for i in read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.uint16), structure_size=2)], A5=reader.read(Primitive.int32), A6=reader.read(Primitive.double)) def main(source): return read_a(BinaryReader(source, offset=5))" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>QdI', data[pointer:pointer + 20]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): c1 = list(struct.unpack('>4q', data[pointer:pointer + 32])) f2 = struct.unpack('>HH', data[pointer + 32:pointer + 36]) c2 = list(struct.unpack(f'>{f2[0]}h', data[f2[1]:f2[1] + f2[0] * 2])) (c3, c4) = struct.unpack('>dH', data[pointer + 36:pointer + 46]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): (b1, b2) = struct.unpack('>bf', data[pointer:pointer + 5]) return {'B1': b1, 'B2': b2} def parse_a(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) a1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0]]))) a1 = a1.replace(""'"", '') a1 = a1[1::2] a2 = struct.unpack('>B', data[pointer + 8:pointer + 9])[0] f3 = struct.unpack('>HI', data[pointer + 9:pointer + 15]) a3 = ''.join(map(str, struct.unpack(f'>{f3[0]}c', data[f3[1]:f3[1] + f3[0]]))) a3 = a3.replace(""'"", '') a3 = a3[1::2] a4 = struct.unpack('>b', data[pointer + 15:pointer + 16])[0] a5 = list() a5.append(parse_b(data, pointer + 16)) a5.append(parse_b(data, pointer + 21)) a6 = parse_c(data, pointer + 26) a7 = parse_d(data, pointer + 72) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 4)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): offset = reader.read(Types.uint16) a1 = b(offset, reader.source) a2 = reader.read(Types.int64) a3 = masser_a3(5, reader) a4 = reader.read(Types.uint8) return dict(A1=a1, A2=a2, A3=a3, A4=a4) def b(offset, source): reader = BinaryReader(offset, source) b1 = masser_b(2, reader) b2 = (reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char)).decode('ascii') b3 = reader.read(Types.double) reader.offset = reader.read(Types.uint32) b4 = d(reader) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def c(reader: BinaryReader): c1 = reader.read(Types.float) c2 = reader.read(Types.float) return dict(C1=c1, C2=c2) def d(reader: BinaryReader): size = reader.read(Types.uint32) offset = reader.read(Types.uint32) d1 = masser_d1(size, offset, reader.source) d2 = reader.read(Types.uint32) d3 = masser_d3(2, reader.offset, reader.source) return dict(D1=d1, D2=d2, D3=d3) def masser_a3(size, reader: BinaryReader): offset = reader.offset rez = [] while reader.offset < offset + size * 2: rez.append(reader.read(Types.int16)) return rez def masser_d1(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 8: rez.append(reader.read(Types.int64)) return rez def masser_d3(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 2: rez.append(reader.read(Types.uint16)) return rez def masser_b(size, reader: BinaryReader): offset = reader.offset rez = [] while reader.offset < offset + size * 8: rez.append(c(reader)) return rez def masser_c(size, offset, source): rez = '' read = BinaryReader(offset, source) while read.offset < offset + size: rez += str(read.read(Types.char).decode('ascii')) return rez def main(source): reader = BinaryReader(offset=5, source=source) return a(reader)" "import struct from enum import Enum class Types(Enum): uint8 = '>B' uint16 = '>H' uint32 = '>I' uint64 = '>Q' int8 = '>b' int16 = '>h' int32 = '>i' int64 = '>q' float = '>f' double = '>d' class BinaryReader: def __init__(self, source, offset): self.source = source self.offset = offset def read(self, pattern): value = struct.unpack_from(pattern.value, self.source, self.offset) self.offset += struct.calcsize(pattern.value) return value[0] def read_a(reader: BinaryReader): a1 = read_b(BinaryReader(reader.source, reader.read(Types.uint32))) a2 = reader.read(Types.int64) a3 = [] a3_size = reader.read(Types.uint32) a3_address = reader.read(Types.uint16) a3_reader = BinaryReader(reader.source, a3_address) for _ in range(a3_size): a3.append(a3_reader.read(Types.uint16)) a4 = reader.read(Types.uint32) a5 = reader.read(Types.double) a6 = reader.read(Types.uint8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6) def read_b(reader: BinaryReader): b1 = [] b1_size = reader.read(Types.uint16) b1_address_reader = BinaryReader(reader.source, reader.read(Types.uint32)) for _ in range(b1_size): b1.append(read_c(BinaryReader(reader.source, b1_address_reader.read(Types.uint16)))) b2 = read_d(reader) b3 = reader.read(Types.float) return dict(B1=b1, B2=b2, B3=b3) def read_c(reader: BinaryReader): c1 = reader.read(Types.int32) c2 = reader.read(Types.uint8) return dict(C1=c1, C2=c2) def read_d(reader: BinaryReader): d1 = reader.read(Types.int32) d2 = reader.read(Types.int32) d3 = reader.read(Types.uint8) d4 = [] d4_size = reader.read(Types.uint32) d4_address = reader.read(Types.uint16) d4_reader = BinaryReader(reader.source, d4_address) for _ in range(d4_size): d4.append(d4_reader.read(Types.uint16)) d5 = [] d5_size = reader.read(Types.uint32) d5_address = reader.read(Types.uint32) d5_reader = BinaryReader(reader.source, d5_address) for _ in range(d5_size): d5.append(d5_reader.read(Types.uint64)) d6 = reader.read(Types.uint32) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6) def main(data): reader = BinaryReader(data, offset=5) return read_a(reader)" "import struct def decode(form, s): while True: if len(s) == 0: return None try: ans = struct.unpack(form, s) return ans except struct.error as e: s = s[:-1] def get_segment(size, address, ss, type_size=1): return ss[address:address + size * type_size] def build(m, d, e, ss): res = dict() b = dict() c = dict() d_list = [] e_dict = dict() for i in d: d_dict = dict() d_dict['D1'] = i[0] size = i[1] address = i[2] s = get_segment(size, address, ss, 4) d_dict['D2'] = list(decode(f'>{size}i', s)) d_dict['D3'] = i[3] d_dict['D4'] = i[4] d_list.append(d_dict) size = e[0] address = e[1] s = get_segment(size, address, ss, 2) arr_1 = list(decode(f'>{size}H', s)) size = e[3] address = e[4] s = get_segment(size, address, ss, 1) arr_2 = list(decode(f'>{size}B', s)) e_dict['E1'] = arr_1 e_dict['E2'] = e[2] e_dict['E3'] = arr_2 e_dict['E4'] = e[5] e_dict['E5'] = e[6] c['C1'] = m[6] c['C2'] = m[7] c['C3'] = d_list c['C4'] = e_dict c['C5'] = m[11] c['C6'] = m[12] c['C7'] = m[13] b['B1'] = m[4] b['B2'] = m[5] b['B3'] = c b['B4'] = m[14] b['B5'] = list(m[15:23]) b['B6'] = m[23] res['A1'] = b res['A2'] = m[24] res['A3'] = m[25] res['A4'] = m[26] return res def main(ss): s = ss m = decode('>4cqiBd3L2h2i8b2iBb', s) size = m[8] address_arr_d = m[9] address_e = m[10] s = get_segment(size, address_arr_d, ss, 4) addresses_d = decode(f'>{size}I', s) d = [] for address in addresses_d: s = get_segment(26, address, ss) d.append(decode('>qIHId', s)) s = get_segment(32, address_e, ss) e = decode('>IIdHHfd', s) return build(m, d, e, ss)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): size = reader.read(Types.uint16) offset = reader.read(Types.uint16) a1 = masser_a1(size, offset, reader.source) a2 = masser_a2(2, reader) a3 = reader.read(Types.int32) size = reader.read(Types.uint32) offset = reader.read(Types.uint16) a4 = masser_a4(size, offset, reader.source) a5 = reader.read(Types.int16) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5) def masser_a1(size, offset, source): reader = BinaryReader(offset, source) rez = '' while reader.offset < offset + size: rez += str(reader.read(Types.char).decode('ascii')) return rez def masser_a2(size, reader: BinaryReader): offset = reader.offset rez = [] while reader.offset < offset + size * 9: rez.append(b(reader)) return rez def masser_a4(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 2: rez.append(reader.read(Types.int16)) return rez def b(reader: BinaryReader): b1 = reader.read(Types.uint8) offset = reader.read(Types.uint16) b2 = c(offset, reader.source) b3 = reader.read(Types.uint32) offset = reader.read(Types.uint16) b4 = d(offset, reader.source) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def c(offset, source): reader = BinaryReader(offset, source) size = reader.read(Types.uint16) offset = reader.read(Types.uint16) c1 = masser_c4(size, offset, reader.source) c2 = reader.read(Types.int16) c3 = reader.read(Types.int32) c4 = reader.read(Types.int32) c5 = reader.read(Types.uint16) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def masser_c4(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 4: rez.append(reader.read(Types.uint32)) return rez def d(offset, source): reader = BinaryReader(offset, source) d1 = reader.read(Types.int64) d2 = reader.read(Types.uint8) d3 = reader.read(Types.double) return dict(D1=d1, D2=d2, D3=d3) def masser_a4(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 2: rez.append(reader.read(Types.int16)) return rez def masser_d3(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 2: rez.append(reader.read(Types.uint16)) return rez def masser_c(size, offset, source): rez = '' read = BinaryReader(offset, source) while read.offset < offset + size: rez += str(read.read(Types.char).decode('ascii')) return rez def main(source): reader = BinaryReader(offset=3, source=source) return a(reader)" "import struct from enum import Enum class Types(Enum): uint8 = 'I', data[start:start + 4])[0] add = struct.unpack('>I', data[start + 4:start + 8])[0] a = struct.unpack('>' + 'B' * size, data[add:add + size]) return list(a) def uint32uint32uint32(data, start): size = struct.unpack('>I', data[start:start + 4])[0] add = struct.unpack('>I', data[start + 4:start + 8])[0] a = struct.unpack('>' + 'I' * size, data[add:add + 4 * size]) return a def create_b_structures(data, address): result = [] for b_address in struct.unpack('>3H', data[address:address + 6]): b1 = struct.unpack('>b', data[b_address:b_address + 1])[0] b2 = list(uint32uint32uint32(data, b_address + 1)) result.append({'B1': b1, 'B2': b2}) return result def main(data): a1 = struct.unpack('>H', data[4:6])[0] a2 = uint32uint32uint8(data, 6) a3 = create_b_structures(data, 14) c1 = [struct.unpack('>I', data[20:24])[0], struct.unpack('>I', data[24:28])[0], struct.unpack('>I', data[28:32])[0], struct.unpack('>I', data[32:36])[0], struct.unpack('>I', data[36:40])[0], struct.unpack('>I', data[40:44])[0]] c2 = struct.unpack('>I', data[44:48])[0] c3 = struct.unpack('>d', data[48:56])[0] c4 = struct.unpack('>f', data[56:60])[0] c5 = struct.unpack('>Q', data[60:68])[0] a5 = struct.unpack('>I', data[68:72])[0] a6 = struct.unpack('>I', data[72:76])[0] d1 = struct.unpack('>B', data[a6:a6 + 1])[0] d2 = struct.unpack('>h', data[a6 + 1:a6 + 3])[0] d3 = struct.unpack('>H', data[a6 + 3:a6 + 5])[0] d4 = struct.unpack('>H', data[a6 + 5:a6 + 7])[0] d5 = struct.unpack('>f', data[a6 + 7:a6 + 11])[0] d6 = [struct.unpack('>H', data[a6 + 11:a6 + 13])[0], struct.unpack('>H', data[a6 + 13:a6 + 15])[0]] a7 = struct.unpack('>d', data[76:84])[0] a8 = struct.unpack('>f', data[84:88])[0] out_dict = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5}, 'A5': a5, 'A6': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6}, 'A7': a7, 'A8': a8} return out_dict" "import struct def main(data): start_A = 5 b = struct.unpack_from('>dbH', data, start_A) a = struct.unpack_from('>dbHBhH3IHb', data, start_A) start_D = a[7] size_arr_char = a[5] addr_arr_char = a[6] A4 = struct.unpack_from('>' + 'c' * size_arr_char, data, addr_arr_char) A4 = b''.join(A4).decode('utf-8') start_C = b[2] c = struct.unpack_from('>i2HIbi', data, start_C) size_arr_char = c[2] addr_arr_char = c[3] C3 = struct.unpack_from('>' + 'c' * size_arr_char, data, addr_arr_char) C3 = b''.join(C3).decode('utf-8') d = struct.unpack_from('>f2Bb', data, start_D) D = {} D.setdefault('D1', d[0]) D.setdefault('D2', d[1]) D.setdefault('D3', d[2]) D.setdefault('D4', d[3]) (len_e, start_E) = (a[8], a[9]) Es = [] for i in range(len_e): es = struct.unpack_from('>f2qH7h', data, start_E) es5 = list(es[4:]) es = list(es[:4]) es.append(es5) Es.append(es) start_E += struct.calcsize('>f2qH7h') C = {} C.setdefault('C1', c[0]) C.setdefault('C2', c[1]) C.setdefault('C3', C3) C.setdefault('C4', c[4]) C.setdefault('C5', c[5]) B = {} B.setdefault('B1', b[0]) B.setdefault('B2', b[1]) B.setdefault('B3', C) A6 = [] for i in range(len_e): temp_e = {} temp_e.setdefault('E1', Es[i][0]) temp_e.setdefault('E2', Es[i][1]) temp_e.setdefault('E3', Es[i][2]) temp_e.setdefault('E4', Es[i][3]) temp_e.setdefault('E5', Es[i][4]) A6.append(temp_e) A = {'A1': B, 'A2': a[3], 'A3': a[4], 'A4': A4, 'A5': D, 'A6': A6, 'A7': a[-1]} return A" "import struct import pprint def parse_d(data, pointer): f1 = struct.unpack('{ar}{ty}', d[of:of + ar * struct.calcsize(ty)])) def par_a(d, of): result = dict() result['A1'] = par_b(d, struct.unpack('>H', d[of:of + struct.calcsize('>H')])[0]) of += struct.calcsize('>H') result['A2'] = par_c(d, struct.unpack('>I', d[of:of + struct.calcsize('>I')])[0]) of += struct.calcsize('>I') result['A3'] = struct.unpack('>B', d[of:of + struct.calcsize('>B')])[0] of += struct.calcsize('>B') result['A4'] = struct.unpack('>I', d[of:of + struct.calcsize('>I')])[0] of += struct.calcsize('>I') result['A5'] = par_g(d, of) return result def par_b(d, offset): result = dict() result['B1'] = struct.unpack('>d', d[offset:offset + struct.calcsize('>d')])[0] offset += struct.calcsize('>d') result['B2'] = struct.unpack('>f', d[offset:offset + struct.calcsize('>f')])[0] return result def par_c(d, of): result = dict() result['C1'] = struct.unpack('>i', d[of:of + struct.calcsize('>i')])[0] of += struct.calcsize('>i') result['C2'] = par_d(d, struct.unpack('>I', d[of:of + struct.calcsize('>I')])[0]) of += struct.calcsize('>I') result['C3'] = struct.unpack('>b', d[of:of + struct.calcsize('>b')])[0] return result def par_d(d, of): result = dict() result['D1'] = struct.unpack('>f', d[of:of + struct.calcsize('>f')])[0] of += struct.calcsize('>f') result['D2'] = struct.unpack('>d', d[of:of + struct.calcsize('>d')])[0] of += struct.calcsize('>d') result['D3'] = [par_e(d, of + 26 * x) for x in range(2)] of += 52 result['D4'] = parse_array(d, of, 'H', 4) of += 8 result['D5'] = par_f(d, struct.unpack('>I', d[of:of + struct.calcsize('>I')])[0]) of += struct.calcsize('>I') result['D6'] = struct.unpack('>i', d[of:of + struct.calcsize('>i')])[0] return result def par_e(d, of): result = dict() s = struct.calcsize('>I') + struct.calcsize('>H') (size, addr) = struct.unpack('>IH', d[of:of + s]) result['E1'] = parse_array(d, addr, 'b', size) of += struct.calcsize('>I') + struct.calcsize('>H') result['E2'] = struct.unpack('>d', d[of:of + struct.calcsize('>d')])[0] of += struct.calcsize('>d') result['E3'] = struct.unpack('>b', d[of:of + struct.calcsize('>b')])[0] of += struct.calcsize('>b') result['E4'] = struct.unpack('>h', d[of:of + struct.calcsize('>h')])[0] of += struct.calcsize('>h') result['E5'] = struct.unpack('>d', d[of:of + struct.calcsize('>d')])[0] of += struct.calcsize('>d') result['E6'] = struct.unpack('>B', d[of:of + struct.calcsize('>B')])[0] return result def par_f(data, of): result = dict() result['F1'] = struct.unpack('>f', data[of:of + struct.calcsize('>f')])[0] of += struct.calcsize('>f') result['F2'] = struct.unpack('>b', data[of:of + struct.calcsize('>b')])[0] of += struct.calcsize('>b') result['F3'] = struct.unpack('>i', data[of:of + struct.calcsize('>i')])[0] of += struct.calcsize('>i') (size, addr) = struct.unpack('>HI', data[of:of + 2 + 4]) result['F4'] = parse_array(data, addr, 'B', size) of += 6 result['F5'] = parse_array(data, of, 'B', 8) of += 8 result['F6'] = struct.unpack('>q', data[of:of + struct.calcsize('>q')])[0] of += struct.calcsize('>q') result['F7'] = struct.unpack('>h', data[of:of + struct.calcsize('>h')])[0] return result def par_g(data, of): result = dict() result['G1'] = struct.unpack('>f', data[of:of + struct.calcsize('>f')])[0] of += struct.calcsize('>f') result['G2'] = struct.unpack('>H', data[of:of + struct.calcsize('>H')])[0] of += struct.calcsize('>H') result['G3'] = struct.unpack('>f', data[of:of + struct.calcsize('>f')])[0] of += struct.calcsize('>f') result['G4'] = struct.unpack('>f', data[of:of + struct.calcsize('>f')])[0] of += struct.calcsize('>f') result['G5'] = struct.unpack('>d', data[of:of + struct.calcsize('>d')])[0] return result" "import struct def main(data): ans = {'A1': [{'B1': '', 'B2': '', 'B3': ''}, {'B1': '', 'B2': '', 'B3': ''}], 'A2': '', 'A3': {'C1': '', 'C2': ''}, 'A4': {'D1': '', 'D2': ''}, 'A5': '', 'A6': {'E1': ['', '', ''], 'E2': ''}} data1 = data[3:] a = 20 b = 24 c = 3 d = 10 e = 14 a_str = data1[0:a] obj = struct.unpack('>IIBBHIccH', a_str) adress_a1 = obj[1] size_a1 = obj[0] ans['A2'] = obj[2] ans['A3'] = {'C1': obj[3], 'C2': obj[4]} ans['A5'] = (obj[6] + obj[7]).decode('utf-8') d_struct = data1[obj[5] - 3:obj[5] - 3 + d] d_struct = struct.unpack('>Qcc', d_struct) ans['A4'] = {'D1': d_struct[0], 'D2': (d_struct[1] + d_struct[2]).decode('utf-8')} offset = 3 adress_array_a1 = data1[adress_a1 - offset:adress_a1 - offset + 4 * size_a1] adress_array_a1 = struct.unpack(f'>{size_a1}I', adress_array_a1) a1_array = [] for i in range(size_a1): struct_b = data1[adress_array_a1[i] - offset:adress_array_a1[i] - offset + b] struct_b = struct.unpack('>QQd', struct_b) b_dict = {'B1': struct_b[0], 'B2': struct_b[1], 'B3': struct_b[2]} a1_array.append(b_dict) ans['A1'] = a1_array e_struct = data1[obj[-1] - 3:obj[-1] - 3 + e] e_struct = struct.unpack('>IHq', e_struct) e_array = data1[e_struct[1] - offset:e_struct[1] - offset + e_struct[0] * 2] e_array = list(struct.unpack(f'>{e_struct[0]}H', e_array)) ans['A6'] = {'E1': e_array, 'E2': e_struct[2]} return ans" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('3c5sdH', data) A['A1'] = A1_char_array.decode('UTF-8') A['A2'] = A2_double (B1, B2) = struct.unpack_from('>H2s', data, offset=A3_uint16_adress_B) (C1, C2) = struct.unpack_from('>hB', data, offset=B1) A['A3'] = {'B1': {'C1': C1, 'C2': C2}, 'B2': B2.decode('UTF-8')} (A4_uint32, A5_int64) = struct.unpack_from('>Iq', data, offset=18) A['A4'] = A4_uint32 A['A5'] = A5_int64 adress_array_D = struct.unpack_from('>HH', data, offset=30) listA6 = [] arraysD = [struct.unpack_from('>hqBBBBiiiiiH', data, offset=adress_array_D[0]), struct.unpack_from('>hqBBBBiiiiiH', data, offset=adress_array_D[1])] listA6 = ({'D1': arraysD[0][:1][0], 'D2': arraysD[0][1:2][0], 'D3': list(arraysD[0][2:6]), 'D4': list(arraysD[0][6:11]), 'D5': arraysD[0][11:12][0]}, {'D1': arraysD[1][:1][0], 'D2': arraysD[1][1:2][0], 'D3': list(arraysD[1][2:6]), 'D4': list(arraysD[1][6:11]), 'D5': arraysD[1][11:12][0]}) A['A6'] = list(listA6) A7_float = struct.unpack_from('>f', data, offset=34) A['A7'] = A7_float[0] return A" "import struct def uint32uint32uint32(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('I', s[pointer + 4:pointer + 8])[0] a = struct.unpack('I' * size, s[add:add + 4 * size]) return list(a) def uint32uint32float(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('I', s[pointer + 4:pointer + 8])[0] a = struct.unpack('f' * size, s[add:add + 8 * size]) return list(a) def create_d_structures(s, pointer): result = [] for d_address in struct.unpack('2H', s[pointer:pointer + 4]): d1 = struct.unpack('I', s[d_address:d_address + 4])[0] d2 = struct.unpack('d', s[d_address + 4:d_address + 12])[0] result.append({'D1': d1, 'D2': d2}) return result def main(s): a1 = struct.unpack('i', s[5:9])[0] b1 = struct.unpack('H', s[9:11])[0] b2 = struct.unpack('H', s[11:13])[0] c1 = struct.unpack('H', s[b2:b2 + 2])[0] c2 = create_d_structures(s, b2 + 2) c3 = uint32uint32uint32(s, b2 + 6) c4 = struct.unpack('i', s[b2 + 14:b2 + 18])[0] c5 = uint32uint32uint32(s, b2 + 18) c6 = struct.unpack('Q', s[b2 + 26:b2 + 34])[0] a3 = struct.unpack('I', s[13:17])[0] a4 = struct.unpack('H', s[17:19])[0] e1 = struct.unpack('Q', s[19:27])[0] e2 = struct.unpack('d', s[27:35])[0] e3 = struct.unpack('B', s[35:36])[0] e4 = uint32uint32float(s, 36) e5 = struct.unpack('q', s[44:52])[0] a6 = struct.unpack('I', s[52:56])[0] out_dict = {'A1': a1, 'A2': {'B1': b1, 'B2': {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6}}, 'A3': a3, 'A4': a4, 'A5': {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5}, 'A6': a6} return out_dict" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('IH', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{f1[0]}q', data[f1[1]:f1[1] + f1[0] * 8])) (d2, d3, d4) = struct.unpack('>BHH', data[pointer + 6:pointer + 11]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>dhih', data[pointer:pointer + 16]) f5 = struct.unpack('>3H', data[pointer + 16:pointer + 22]) c5 = list() for i in range(3): c5.append(parse_d(data, f5[i])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = parse_c(data, pointer) f2 = struct.unpack('>HH', data[pointer + 22:pointer + 26]) b2 = list(struct.unpack(f'>{f2[0]}f', data[f2[1]:f2[1] + f2[0] * 4])) (b3, b4) = struct.unpack('>HB', data[pointer + 26:pointer + 29]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): (a1, a2) = struct.unpack('>hQ', data[pointer:pointer + 10]) a3 = parse_b(data, pointer + 10) a4 = list(struct.unpack('>2d', data[pointer + 39:pointer + 55])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_d(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) d1 = list(struct.unpack(f'>{f1[0]}d', data[f1[1]:f1[1] + f1[0] * 8])) (d2, d3, d4, d5, d6, d7, d8) = struct.unpack('>fHfBHQH', data[pointer + 8:pointer + 31]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def parse_c(data, pointer): (c1, c2) = struct.unpack('>BB', data[pointer:pointer + 2]) c3 = list(struct.unpack('>4H', data[pointer + 2:pointer + 10])) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) b1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0]]))) b1 = b1.replace(""'"", '') b1 = b1[1::2] b2 = parse_c(data, pointer + 8) return {'B1': b1, 'B2': b2} def parse_a(data, pointer): f1 = struct.unpack('>2I', data[pointer:pointer + 8]) a1 = list() for i in range(2): a1.append(parse_b(data, f1[i])) (a2, a3) = struct.unpack('>BH', data[pointer + 8:pointer + 11]) a4 = parse_d(data, pointer + 11) a5 = struct.unpack('>b', data[pointer + 42:pointer + 43])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 85: break index = a_adr a = {f'A{i}': None for i in range(1, 9)} a['A1'] = ''.join((chr(i) for i in file[index:index + 3])) index += 3 a['A2'] = unpack('>i', file[index:index + 4])[0] index += 4 a['A3'] = unpack('>H', file[index:index + 2])[0] index += 2 (a['A4'], index) = struct_b(index, file) a['A5'] = unpack('>d', file[index:index + 8])[0] index += 8 (size, address) = unpack('>LL', file[index:index + 8]) a['A6'] = [struct_e(i, file, size, address + i * 9) for i in range(0, size)] index += 8 a['A7'] = unpack('>B', file[index:index + 1])[0] index += 1 a['A8'] = list(unpack('>7H', file[index:index + 14])) index += 14 return a def struct_b(index, file): b = {f'B{i}': None for i in range(1, 8)} b['B1'] = unpack('>i', file[index:index + 4])[0] index += 4 b['B2'] = unpack('>q', file[index:index + 8])[0] index += 8 (b['B3'], index) = struct_c(index, file) b['B4'] = unpack('>q', file[index:index + 8])[0] index += 8 b['B5'] = unpack('>H', file[index:index + 2])[0] index += 2 (b['B6'], index) = struct_d(index, file) b['B7'] = unpack('>b', file[index:index + 1])[0] index += 1 return (b, index) def struct_c(index, file): c = {f'C{i}': None for i in range(1, 3)} c['C1'] = unpack('>b', file[index:index + 1])[0] index += 1 (size, address) = unpack('>LL', file[index:index + 8]) c['C2'] = list(unpack(f'>{size}B', file[address:address + 1 * size])) index += 8 return (c, index) def struct_d(index, file): d = {f'D{i}': None for i in range(1, 4)} d['D1'] = unpack('>L', file[index:index + 4])[0] index += 4 d['D2'] = unpack('>b', file[index:index + 1])[0] index += 1 d['D3'] = unpack('>q', file[index:index + 8])[0] index += 8 return (d, index) def struct_e(index, file, size, address): e = {f'E{i}': None for i in range(1, 3)} e['E1'] = unpack('>B', file[address:address + 1])[0] address += 1 e['E2'] = unpack('>d', file[address:address + 8])[0] address += 8 return e" "import struct def main(d): a = {'A1': None, 'A2': [], 'A3': None, 'A4': {}, 'A5': None, 'A6': {}} razb(a, d) return a def razb(a, d): a['A1'] = struct.unpack('>d', d[4:12])[0] a1r = struct.unpack('>I', d[12:16])[0] a1a = struct.unpack('>I', d[16:20])[0] for i in range(a1r): a['A2'].append(struct.unpack('>h', d[a1a + i * 2:a1a + 2 + i * 2])[0]) a['A3'] = struct.unpack('>I', d[20:24])[0] a['A4'] = {'B1': None, 'B2': {}} a['A4']['B1'] = struct.unpack('>Q', d[24:32])[0] a['A4']['B2']['C1'] = struct.unpack('>H', d[32:34])[0] a['A4']['B2']['C2'] = struct.unpack('>I', d[34:38])[0] a['A5'] = struct.unpack('>d', d[38:46])[0] a6a = struct.unpack('>H', d[46:48])[0] D = {'D1': [], 'D2': []} d1r = struct.unpack('>H', d[a6a:a6a + 2])[0] d1a = struct.unpack('>I', d[a6a + 2:a6a + 6])[0] E = [] for i in range(d1r): Ee = {'E1': [], 'E2': None} Ee['E1'].append(struct.unpack('>B', d[d1a + i * 6:d1a + 1 + i * 6])[0]) Ee['E1'].append(struct.unpack('>B', d[d1a + 1 + i * 6:d1a + 2 + i * 6])[0]) Ee['E2'] = struct.unpack('>I', d[d1a + 2 + i * 6:d1a + 6 + i * 6])[0] E.append(Ee) D['D1'] = E d2r = struct.unpack('>H', d[a6a + 6:a6a + 8])[0] d2a = struct.unpack('>I', d[a6a + 8:a6a + 12])[0] for i in range(d2r): D['D2'].append(struct.unpack('>q', d[d2a + i * 8:d2a + 8 + i * 8])[0]) D['D3'] = struct.unpack('>Q', d[a6a + 12:a6a + 20])[0] D['D4'] = struct.unpack('>h', d[a6a + 20:a6a + 22])[0] a['A6'] = D" "import struct def main(x): a1 = struct.unpack('>d', x[4:12])[0] b1 = struct.unpack('>f', x[12:16])[0] b2 = str(struct.unpack('>2s', x[16:18])[0])[2:-1] a2 = {'B1': b1, 'B2': b2} a3 = struct.unpack('>q', x[18:26])[0] pos1 = struct.unpack('>H', x[30:32])[0] a4 = [] for i in range(0, struct.unpack('>I', x[26:30])[0]): pos2 = struct.unpack('>H', x[pos1:pos1 + 2])[0] c1 = struct.unpack('>I', x[pos2:pos2 + 4])[0] c2 = list(struct.unpack('>3H', x[pos2 + 4:pos2 + 10])) c = {'C1': c1, 'C2': c2} a4.append(c) pos1 += 2 pos1 = struct.unpack('>H', x[32:34])[0] d1 = struct.unpack('>H', x[pos1:pos1 + 2])[0] di = struct.unpack('>I', x[pos1 + 2:pos1 + 6])[0] dis = '>' + str(di) + 'd' pos2 = struct.unpack('>I', x[pos1 + 6:pos1 + 10])[0] d2 = list(struct.unpack(dis, x[pos2:pos2 + di * 8])) d3 = struct.unpack('>d', x[pos1 + 10:pos1 + 18])[0] d4 = struct.unpack('>q', x[pos1 + 18:pos1 + 26])[0] di = struct.unpack('>I', x[pos1 + 26:pos1 + 30])[0] dis = '>' + str(di) + 'b' pos2 = struct.unpack('>H', x[pos1 + 30:pos1 + 32])[0] d5 = list(struct.unpack(dis, x[pos2:pos2 + di])) a5 = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} a6 = struct.unpack('>f', x[34:38])[0] a7 = struct.unpack('>B', x[38:39])[0] d = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} return d" "from struct import unpack_from def main(bytes): size_array_b = unpack_from('>H', bytes, offset=4)[0] address_array_b = unpack_from('>I', bytes, offset=6)[0] address_c = unpack_from('>H', bytes, offset=10)[0] A3 = unpack_from('>B', bytes, offset=12)[0] A4 = unpack_from('>d', bytes, offset=13)[0] address_d = unpack_from('>H', bytes, offset=address_c)[0] C2 = [] for i in range(3): C2.append(unpack_from('>I', bytes, offset=address_c + 2 + 4 * i)[0]) C3 = unpack_from('>f', bytes, offset=address_c + 14)[0] D1 = unpack_from('>f', bytes, offset=address_d)[0] D2 = unpack_from('>Q', bytes, offset=address_d + 4)[0] D3 = unpack_from('>b', bytes, offset=address_d + 12)[0] D4 = unpack_from('>d', bytes, offset=address_d + 13)[0] size_array_uint8 = unpack_from('>I', bytes, offset=address_d + 21)[0] address_array_uint8 = unpack_from('>I', bytes, offset=address_d + 25)[0] D5 = [] for i in range(size_array_uint8): D5.append(unpack_from('>B', bytes, offset=address_array_uint8 + i)[0]) D6 = unpack_from('>I', bytes, offset=address_d + 29)[0] A1 = [] for i in range(size_array_b): address_b = address_array_b + i * 16 size_array_char = unpack_from('>I', bytes, offset=address_b)[0] address_array_char = unpack_from('>H', bytes, offset=address_b + 4)[0] B1 = [] for j in range(size_array_char): B1.append(unpack_from('>c', bytes, offset=address_array_char + j)[0].decode()) B1 = ''.join(B1) B2 = unpack_from('>Q', bytes, offset=address_b + 6)[0] B3 = unpack_from('>H', bytes, offset=address_b + 14)[0] B = {'B1': B1, 'B2': B2, 'B3': B3} A1.append(B) answer = {'A1': A1, 'A2': {'C1': {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5, 'D6': D6}, 'C2': C2, 'C3': C3}, 'A3': A3, 'A4': A4} return answer" "import struct def main(data): A = struct.unpack_from('>hBHIq', data, offset=5) B = struct.unpack_from('>IdiB2IHbB4hBiH', data, offset=A[3]) B6 = list(struct.unpack_from('>4h', data, offset=B[5])) C = struct.unpack_from('>3IqhQI7hBh3H', data, offset=B[0]) D = [] for i in range(3): tempTuple = struct.unpack_from('>bB', data, offset=C[i]) tempDict = {} for j in range(len(tempTuple)): tempDict['D' + str(j + 1)] = tempTuple[j] D.append(tempDict) F2 = list(struct.unpack_from('>' + str(C[16]) + 'Q', data, offset=C[17])) G4 = list(struct.unpack_from('>' + str(B[4]) + 'I', data, offset=B[5])) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': {'B1': {'C1': D, 'C2': C[3], 'C3': C[4], 'C4': C[5], 'C5': C[6], 'C6': {'E1': [C[7], C[8], C[9], C[10], C[11], C[12], C[13]], 'E2': C[14]}, 'C7': {'F1': C[15], 'F2': F2, 'F3': C[18]}}, 'B2': {'G1': B[1], 'G2': B[2], 'G3': B[3], 'G4': G4}, 'B3': B[6], 'B4': B[7], 'B5': B[8], 'B6': [B[9], B[10], B[11], B[12]], 'B7': {'H1': B[13], 'H2': B[14], 'H3': B[15]}}, 'A5': A[4]}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int8', data, ofs) (E2, ofs) = parse('int64', data, ofs) (E3, ofs) = parse('uint32', data, ofs) (E4, ofs) = parse('double', data, ofs) (E5, ofs) = parse('int64', data, ofs) (E6_size, ofs) = parse('uint32', data, ofs) (E6_adr, ofs) = parse('uint32', data, ofs) E6 = [] for _ in range(E6_size): (h, E6_adr) = parse('float', data, E6_adr) E6.append(h) (E7, ofs) = parse('int64', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = struct_D(data, ofs) (C2_size, ofs) = parse('uint32', data, ofs) (C2_adr, ofs) = parse('uint16', data, ofs) C2 = [] for _ in range(C2_size): (h, C2_adr) = parse('uint8', data, C2_adr) C2.append(h) (C3, ofs) = parse('int32', data, ofs) (C4, ofs) = parse('uint64', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int64', data, ofs) (B2, ofs) = parse('int64', data, ofs) (B3, ofs) = parse('int8', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_D(data, ofs): (D1_size, ofs) = parse('uint32', data, ofs) (D1_adr, ofs) = parse('uint32', data, ofs) (D2_size, ofs) = parse('uint32', data, ofs) (D2_adr, ofs) = parse('uint32', data, ofs) D1 = [] D2 = [] for _ in range(D1_size): (has, D1_adr) = struct_E(data, D1_adr) D1.append(has) for _ in range(D2_size): (has, D2_adr) = parse('int8', data, D2_adr) D2.append(has) (D3, ofs) = parse('int32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def parse_main(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = parse('int32', data, ofs) (A3, ofs) = struct_C(data, ofs) (A4, ofs) = parse('int64', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4) def main(data): return parse_main(data, 4)" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('<3b', data[pointer:pointer + 3])) (d2, d3, d4, d5) = struct.unpack('HIHHHHHbhBHbIHhhhhhBl', a_str) size_a1 = obj[0] adress_a1 = obj[1] array_a1 = data1[adress_a1 - offset:adress_a1 - offset + size_a1] array_a1 = struct.unpack(f'>{size_a1}c', array_a1) ara = '' for i in range(len(array_a1)): ara += array_a1[i].decode('utf-8') ans['A1'] = ara adress_a2 = obj[2] b_struct = data1[adress_a2 - offset:adress_a2 - offset + b] b_struct = struct.unpack('>6cf', b_struct) b1 = (b_struct[0] + b_struct[1] + b_struct[2] + b_struct[3] + b_struct[4] + b_struct[5]).decode('utf-8') ans['A2']['B1'] = b1 ans['A2']['B2'] = b_struct[-1] a3_dict = [] for i in range(3, 6): ara = {} adress_a3 = obj[i] c_struct = data1[adress_a3 - offset:adress_a3 - offset + c] c_struct = struct.unpack('>Id', c_struct) ara['C1'] = c_struct[0] ara['C2'] = c_struct[1] a3_dict.append(ara) ans['A3'] = a3_dict ans['A4'] = obj[6] ans['A5']['D1'] = obj[7] ans['A5']['D2'] = obj[8] ans['A5']['D3'] = obj[9] ans['A6']['E1'] = obj[10] ans['A6']['E2'] = obj[11] ans['A6']['E4'] = obj[14] ans['A6']['E5'] = obj[15] ans['A6']['E6'] = [obj[16], obj[17], obj[18]] ans['A6']['E7'] = obj[19] ans['A6']['E8'] = obj[20] size_e3 = obj[12] adress_e3 = obj[13] e_struct = data1[adress_e3 - offset:adress_e3 - offset + 2 * size_e3] e_struct = list(struct.unpack(f'>{size_e3}H', e_struct)) ans['A6']['E3'] = e_struct return ans" "import struct def uint16uint32int16(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('> ' + 'h' * size, s[add:add + 2 * size]) return list(a) def create_c_structures(s, pointer): result = [] for c_address in struct.unpack('>3H', s[pointer:pointer + 6]): c1 = struct.unpack('>d', s[c_address:c_address + 8])[0] c2 = struct.unpack('>q', s[c_address + 8:c_address + 16])[0] result.append({'C1': c1, 'C2': c2}) return result def main(s): a1 = struct.unpack('>b', s[4:5])[0] a2 = struct.unpack('>Q', s[5:13])[0] a3 = str(struct.unpack('>5s', s[13:18])[0])[2:7] a4 = struct.unpack('>i', s[18:22])[0] a5 = struct.unpack('>I', s[22:26])[0] b1 = struct.unpack('>i', s[26:30])[0] b2 = struct.unpack('>I', s[30:34])[0] b3 = create_c_structures(s, 34) b4 = struct.unpack('>I', s[40:44])[0] d1 = struct.unpack('>f', s[b4:b4 + 4])[0] d2 = [struct.unpack('>I', s[b4 + 4:b4 + 8])[0], struct.unpack('>I', s[b4 + 8:b4 + 12])[0], struct.unpack('>I', s[b4 + 12:b4 + 16])[0], struct.unpack('>I', s[b4 + 16:b4 + 20])[0]] d3 = struct.unpack('>H', s[b4 + 20:b4 + 22])[0] d4 = struct.unpack('>f', s[b4 + 22:b4 + 26])[0] d5 = uint16uint32int16(s, b4 + 26) d6 = struct.unpack('>B', s[b4 + 32:b4 + 33])[0] d7 = struct.unpack('>f', s[b4 + 33:b4 + 37])[0] b5 = struct.unpack('>d', s[44:52])[0] b6 = struct.unpack('>q', s[52:60])[0] b7 = struct.unpack('>I', s[60:64])[0] b8 = struct.unpack('>I', s[64:68])[0] a7 = struct.unpack('>b', s[68:69])[0] out_dict = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7}, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8}, 'A7': a7} return out_dict" "import struct def uint32uint16uint32(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('H', s[pointer + 4:pointer + 6])[0] a = struct.unpack('I' * size, s[add:add + 4 * size]) return list(a) def uint16uint16uint32(s, pointer): size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('I' * size, s[add:add + 4 * size]) return list(a) def uint32uint32char(s, pointer): buff = '' size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('I', s[pointer + 4:pointer + 8])[0] a = struct.unpack('c' * size, s[add:add + 1 * size]) for i in a: buff += str(i)[2:3] return buff def create_b_structures(s, pointer): result = [] for b_address in struct.unpack('2I', s[pointer:pointer + 8]): b1 = uint32uint32char(s, b_address) b2 = struct.unpack('Q', s[b_address + 8:b_address + 16])[0] b3 = struct.unpack('d', s[b_address + 16:b_address + 24])[0] b4 = struct.unpack('I', s[b_address + 24:b_address + 28])[0] b5 = [struct.unpack('d', s[b_address + 28:b_address + 36])[0], struct.unpack('d', s[b_address + 36:b_address + 44])[0]] b6 = struct.unpack('B', s[b_address + 44:b_address + 45])[0] b7 = struct.unpack('q', s[b_address + 45:b_address + 53])[0] result.append({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7}) return result def main(s): a1 = struct.unpack('b', s[5:6])[0] a2 = create_b_structures(s, 6) c1 = struct.unpack('i', s[14:18])[0] c2 = struct.unpack('i', s[18:22])[0] c3 = struct.unpack('b', s[22:23])[0] c4 = struct.unpack('d', s[23:31])[0] c5 = struct.unpack('i', s[31:35])[0] a4 = struct.unpack('f', s[35:39])[0] a5 = struct.unpack('q', s[39:47])[0] a6 = struct.unpack('I', s[47:51])[0] d1 = uint32uint16uint32(s, a6) d2 = uint16uint16uint32(s, a6 + 6) d3 = struct.unpack('q', s[a6 + 10:a6 + 18])[0] out_dict = {'A1': a1, 'A2': a2, 'A3': {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5}, 'A4': a4, 'A5': a5, 'A6': {'D1': d1, 'D2': d2, 'D3': d3}} return out_dict" "import struct def structD(data, pointer): (int16,) = struct.unpack('>h', data[pointer:pointer + 2]) (double,) = struct.unpack('>d', data[pointer + 2:pointer + 10]) return {'D1': int16, 'D2': double} def structC(data, pointer): strD = structD(data, pointer) f2 = struct.unpack('>HH', data[pointer + 10:pointer + 14]) c2 = list(struct.unpack(f'>{f2[0]}b', data[f2[1]:f2[1] + f2[0] * 1])) f3 = struct.unpack('>IH', data[pointer + 14:pointer + 20]) c3 = list(struct.unpack(f'>{f3[0]}b', data[f3[1]:f3[1] + f3[0] * 1])) c4 = list(struct.unpack('>6b', data[pointer + 20:pointer + 26])) return {'C1': strD, 'C2': c2, 'C3': c3, 'C4': c4} def structB(data, pointer): (int16_b,) = struct.unpack('>h', data[pointer:pointer + 2]) (uint32_b,) = struct.unpack('>I', data[pointer + 2:pointer + 6]) strC = structC(data, pointer + 6) (int16v2_b,) = struct.unpack('>h', data[pointer + 32:pointer + 34]) return {'B1': int16_b, 'B2': uint32_b, 'B3': strC, 'B4': int16v2_b} def structA(data, pointer): (int64_a,) = struct.unpack('>q', data[pointer:pointer + 8]) (array_a,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) (array_a_2,) = struct.unpack('>H', data[pointer + 10:pointer + 12]) structBArray = [] structBArray.append(structB(data, array_a)) structBArray.append(structB(data, array_a_2)) (uint8_a,) = struct.unpack('>B', data[pointer + 12:pointer + 13]) (ui32_2_a,) = struct.unpack('>I', data[pointer + 13:pointer + 17]) return {'A1': int64_a, 'A2': structBArray, 'A3': uint8_a, 'A4': ui32_2_a} def main(data): return structA(data, 5)" "import struct as st def main(x): return a(x, 4) def a(x, start): return {'A1': st.unpack('> b', x[start:start + 1])[0], 'A2': st.unpack('> f', x[start + 1:start + 5])[0], 'A3': st.unpack('> Q', x[start + 5:start + 13])[0], 'A4': st.unpack('> b', x[start + 13:start + 14])[0], 'A5': b(x, start + 14), 'A6': d(x, start + 40), 'A7': st.unpack('> h', x[start + 74:start + 76])[0], 'A8': st.unpack('> H', x[start + 76:start + 78])[0]} def b(x, start): return {'B1': st.unpack('> f', x[start:start + 4])[0], 'B2': st.unpack('> h', x[start + 4:start + 6])[0], 'B3': st.unpack('> Q', x[start + 6:start + 14])[0], 'B4': st.unpack('> h', x[start + 14:start + 16])[0], 'B5': c(x, address_c(x, start + 16)), 'B6': st.unpack('> Q', x[start + 18:start + 26])[0]} def address_c(x, start): return st.unpack('> H', x[start:start + 2])[0] def c(x, start): return {'C1': st.unpack('> H', x[start:start + 2])[0], 'C2': uint16_uint16_char(x, start + 2), 'C3': st.unpack('> H', x[start + 6:start + 8])[0], 'C4': st.unpack('> B', x[start + 8:start + 9])[0]} def uint16_uint16_char(x, start): size = st.unpack('> H', x[start:start + 2])[0] address = st.unpack('> H', x[start + 2:start + 4])[0] arr = st.unpack('> ' + 'c' * size, x[address:address + 1 * size]) s = '' for symbol in arr: s += str(symbol)[2] return s def d(x, start): return {'D1': st.unpack('> H', x[start:start + 2])[0], 'D2': [e(x, address_e(x, start + 2)), e(x, address_e(x, start + 6)), e(x, address_e(x, start + 10)), e(x, address_e(x, start + 14))], 'D3': st.unpack('> b', x[start + 18:start + 19])[0], 'D4': uint32_uint32_int8(x, start + 19), 'D5': uint16_uint32_int16(x, start + 27), 'D6': st.unpack('> b', x[start + 33:start + 34])[0]} def uint32_uint32_int8(x, start): size = st.unpack('> I', x[start:start + 4])[0] address = st.unpack('> I', x[start + 4:start + 8])[0] arr = st.unpack('> ' + 'b' * size, x[address:address + 1 * size]) return list(arr) def uint16_uint32_int16(x, start): size = st.unpack('> H', x[start:start + 2])[0] address = st.unpack('> I', x[start + 2:start + 6])[0] arr = st.unpack('> ' + 'h' * size, x[address:address + 2 * size]) return list(arr) def address_e(x, start): return st.unpack('> I', x[start:start + 4])[0] def e(x, start): return {'E1': uint16_uint32_uint8(x, start), 'E2': st.unpack('> I', x[start + 6:start + 10])[0], 'E3': st.unpack('> I', x[start + 10:start + 14])[0]} def uint16_uint32_uint8(x, start): size = st.unpack('> H', x[start:start + 2])[0] address = st.unpack('> I', x[start + 2:start + 6])[0] arr = st.unpack('> ' + 'B' * size, x[address:address + 1 * size]) return list(arr)" "import struct def main(x): offset = 3 ans = A(x, offset) return ans def A(x, offset): ans = {'A1': 0, 'A2': None, 'A3': 0.0, 'A4': 0, 'A5': []} size = 57 buffer = x[offset:offset + size] obj = struct.unpack('4cQdIHIIhbHHib', data) B3_str = struct.unpack_from(str(b3u3s) + 's', data, offset=b3u1a) B['B1'] = b1u4 B['B2'] = b2d B['B3'] = B3_str[0].decode('UTF-8') sC = struct.unpack_from('>' + 'H' * b43s, data, offset=b43a) c1_x = [] for o in range(0, b43s): tupl = {} buff = struct.unpack_from('>Hf', data, offset=sC[o]) tupl['C1'] = buff[0] tupl['C2'] = buff[1] c1_x.append(tupl) B['B4'] = c1_x B['B5'] = b51 B['B6'] = b68 A['A1'] = B pattern = 'HIbHH' * a2us scC = struct.unpack_from('>' + pattern, data, offset=a2ua) A2 = [] for i in range(0, a2us): tupl = {} ofs = scC[i * 5 + 1] pat = '>' + 'H' * scC[i * 5] p = struct.unpack_from(pat, data, offset=ofs) tupl['D1'] = list(p) tupl['D2'] = scC[i * 5 + 2] tupl['D3'] = [scC[i * 5 + 3], scC[i * 5 + 4]] A2.append(tupl) A['A2'] = A2 A['A3'] = ia3 A['A4'] = ba4 return A" "from pprint import pprint from struct import unpack from random import * type_dict = {'char': 'c', 'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's'} def gen_d(): d = type_dict return d['double'] + d['int64'] + d['uint8'] + 3 * d['int8'] + d['int16'] def gen_c(): d = type_dict return d['int16'] + d['double'] + d['int8'] def gen_b(): d = type_dict return d['uint16'] + d['uint16'] + d['uint32'] + d['uint16'] + gen_d() + 2 * d['uint8'] def gen_a(): d = type_dict return d['uint32'] + d['double'] + d['int16'] + d['uint32'] + d['float'] def gen_total(): d = type_dict return '>xxx' + gen_a() def main(arg): if len(arg) == 84: te = 3 elif len(arg) == 94: te = 2 elif len(arg) == 95: te = 3 elif len(arg) == 105: te = 2 elif len(arg) == 106: te = 3 else: te = 2 d = type_dict total = gen_total() obj = unpack(total, arg[:25]) a_dict = {'A1': obj[0], 'A2': obj[1], 'A3': obj[2], 'A4': [], 'A5': obj[4]} first_addr = obj[3] first_struct_total = '>' + gen_b() first_struct = unpack(first_struct_total, arg[first_addr:first_addr + 40]) third_size = first_struct[0] third_addr = first_struct[1] third_t = '>' + third_size * gen_c() t = unpack(third_t, arg[third_addr:third_addr + third_size * 11]) list_new = [] for i in range(third_size): c_dict = {'C1': t[0 + 3 * i], 'C2': t[1 + 3 * i], 'C3': t[2 + 3 * i]} list_new.append(c_dict) second_size = first_struct[2] second_addr = first_struct[3] second_st = '>' + second_size * d['char'] second_struct = unpack(second_st, arg[second_addr:second_addr + te]) listof = [] string = '' for i in range(second_size): listof.append(second_struct[i]) for i in listof: string += i.decode() b_dict = {'B1': list_new, 'B2': string, 'B3': {'D1': first_struct[4], 'D2': first_struct[5], 'D3': first_struct[6], 'D4': [first_struct[7], first_struct[8], first_struct[9]], 'D5': first_struct[10]}, 'B4': [first_struct[11], first_struct[12]]} a_dict['A4'] = b_dict return a_dict" "from struct import unpack, unpack_from def read_A(buf, start): a1 = unpack_from('f', buf, start)[0] b_address = [unpack_from('H', buf, start + 4 + i * 2)[0] for i in range(8)] chr_sz = int(unpack_from('I', buf, start + 20)[0]) chr_address = unpack_from('I', buf, start + 24)[0] a3 = ''.join([x.decode() for x in unpack_from(chr_sz * 'c', buf, chr_address)]) c_address = unpack_from('H', buf, start + 28)[0] return (a1, b_address, a3, c_address) def read_B(buf, address): b1 = unpack_from('b', buf, address)[0] b2 = unpack_from('h', buf, address + 1)[0] return {'B1': b1, 'B2': b2} def read_C(buf, start): c1 = unpack_from('d', buf, start)[0] c2 = unpack_from('I', buf, start + 8)[0] d_address = start + 12 d_offset = 38 c4 = list(unpack_from('H' * 4, buf, d_address + d_offset)) c5 = unpack_from('I', buf, d_address + d_offset + 8)[0] return (c1, c2, d_address, c4, c5) def read_D(buf, start): d1 = unpack_from('b', buf, start)[0] d2 = unpack_from('B', buf, start + 1)[0] d3 = unpack_from('i', buf, start + 2)[0] d4 = list(unpack_from('f' * 4, buf, start + 6)) d5 = unpack_from('q', buf, start + 22)[0] d6 = unpack_from('q', buf, start + 30)[0] return (d1, d2, d3, d4, d5, d6) def main(inp): (a1, b_arr_address, a3, c_address) = read_A(inp, 4) (c1, c2, d_address, c4, c5) = read_C(inp, c_address) (d1, d2, d3, d4, d5, d6) = read_D(inp, d_address) res = {'A1': a1, 'A2': [read_B(inp, b_address) for b_address in b_arr_address], 'A3': a3, 'A4': {'C1': c1, 'C2': c2, 'C3': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6}, 'C4': c4, 'C5': c5}} return res" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('III', buffer) ans['A1'] = B(x, obj[0]) ans['A2'] = D(x, obj[2], obj[1]) return ans def B(x, offset): ans = {'B1': 0, 'B2': 0.0, 'B3': None} size = 20 buffer = x[offset:offset + size] obj = struct.unpack('>ifdf', buffer) ans['B1'] = obj[0] ans['B2'] = obj[1] ans['B3'] = C(x, offset + 8) return ans def C(x, offset): ans = {'C1': 0.0, 'C2': 0.0} size = 12 buffer = x[offset:offset + size] obj = struct.unpack('>df', buffer) ans['C1'] = obj[0] ans['C2'] = obj[1] return ans def D(x, offset, count): ans = {'D1': [], 'D2': [], 'D3': 0.0, 'D4': None, 'D5': 0} size = 21 tmp = [] for i in range(count): buffer = x[offset:offset + size] obj = struct.unpack('>HHIHdHB', buffer) sizeD1 = obj[0] adressD1 = obj[1] arrayD1 = x[adressD1:adressD1 + sizeD1 * 2] ans['D1'] = list(struct.unpack(f'>{sizeD1}H', arrayD1)) sizeD2 = obj[2] adressD2 = obj[3] arrayD2 = x[adressD2:adressD2 + sizeD2] ans['D2'] = list(struct.unpack(f'>{sizeD2}B', arrayD2)) ans['D3'] = obj[4] ans['D4'] = E(x, obj[5]) ans['D5'] = obj[6] tmp.append(ans) ans = {} offset += size return tmp def E(x, offset): ans = {'E1': [], 'E2': 0} size = 10 buffer = x[offset:offset + size] obj = struct.unpack('>IHi', buffer) sizeE = obj[0] adressE = obj[1] arrayE = x[adressE:adressE + sizeE * 8] ans['E1'] = list(struct.unpack(f'>{sizeE}Q', arrayE)) ans['E2'] = obj[2] return ans" "import struct def structD(data, pointer): (d1,) = struct.unpack('>Q', data[pointer:pointer + 8]) (d2,) = struct.unpack('>Q', data[pointer + 8:pointer + 16]) (d3,) = struct.unpack('>q', data[pointer + 16:pointer + 24]) f4 = struct.unpack('>IH', data[pointer + 24:pointer + 30]) d4 = list(struct.unpack(f'>{f4[0]}h', data[f4[1]:f4[1] + f4[0] * 2])) (d5,) = struct.unpack('>h', data[pointer + 30:pointer + 32]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def structC(data, pointer): (c1,) = struct.unpack('>b', data[pointer:pointer + 1]) (c2,) = struct.unpack('>q', data[pointer + 1:pointer + 9]) (c3,) = struct.unpack('>I', data[pointer + 9:pointer + 13]) (c4,) = struct.unpack('>i', data[pointer + 13:pointer + 17]) (c5,) = struct.unpack('>I', data[pointer + 17:pointer + 21]) (c6,) = struct.unpack('>q', data[pointer + 21:pointer + 29]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) (b2,) = struct.unpack('>B', data[pointer + 1:pointer + 2]) b3 = ''.join(map(str, struct.unpack('>8c', data[pointer + 2:pointer + 10]))) b3 = b3.replace(""'"", '') b3 = b3[1::2] (b4,) = struct.unpack('>Q', data[pointer + 10:pointer + 18]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def structA(data, pointer): (a1,) = struct.unpack('>Q', data[pointer:pointer + 8]) a2 = structB(data, pointer + 8) f3 = struct.unpack('>IH', data[pointer + 26:pointer + 32]) a3 = struct.unpack(f'>{f3[0]}c', data[f3[1]:f3[1] + f3[0] * 1]) char3 = '' for i in range(len(a3)): char3 += chr(a3[i][0]) f4 = struct.unpack('>HH', data[pointer + 34:pointer + 38]) a4 = list() x4 = structC(data, f4[0]) a4.append(x4) x4 = structC(data, f4[0] + 29) a4.append(x4) (a5,) = struct.unpack('>f', data[pointer + 36:pointer + 40]) a6 = structD(data, pointer + 40) (a7,) = struct.unpack('>d', data[pointer + 40 + 32:pointer + 72 + 8]) (a8,) = struct.unpack('>H', data[pointer + 40 + 40:pointer + 72 + 10]) return {'A1': a1, 'A2': a2, 'A3': char3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return structA(data, 5)" "import struct def uint16uint32int8(data, start): size = struct.unpack('>H', data[start:start + 2])[0] add = struct.unpack('>I', data[start + 2:start + 6])[0] a = struct.unpack('>' + 'b' * size, data[add:add + 1 * size]) return list(a) def uint16uint16int32(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>H', x[start + 2:start + 4])[0] a = struct.unpack('>' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint16uint32int16(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>I', x[start + 2:start + 6])[0] a = struct.unpack('>' + 'h' * size, x[add:add + 2 * size]) return list(a) def create_d_structures(data, address): d1 = uint16uint32int8(data, address) d2 = list(struct.unpack('>3H', data[address + 6:address + 12])) d3 = uint16uint16int32(data, address + 12) d4 = struct.unpack('>B', data[address + 16:address + 17])[0] d5 = struct.unpack('>h', data[address + 17:address + 19])[0] d6 = struct.unpack('>d', data[address + 19:address + 27])[0] d7 = struct.unpack('>f', data[address + 27:address + 31])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def create_d(data, address): c3 = [] c3.append(create_d_structures(data, address + 9)) c3.append(create_d_structures(data, address + 40)) c3.append(create_d_structures(data, address + 71)) return c3 def main(data): b1 = struct.unpack('>I', data[4:8])[0] b2 = struct.unpack('>b', data[8:9])[0] b3 = struct.unpack('>H', data[9:11])[0] c1 = struct.unpack('>d', data[b3:b3 + 8])[0] c2 = struct.unpack('>B', data[b3 + 8:b3 + 9])[0] c3 = create_d(data, b3) c4 = struct.unpack('>f', data[b3 + 102:b3 + 106])[0] c5 = struct.unpack('>i', data[b3 + 106:b3 + 110])[0] c6 = struct.unpack('>i', data[b3 + 110:b3 + 114])[0] a2 = uint16uint32int16(data, 11) a3 = struct.unpack('>i', data[17:21])[0] out_dict = {'A1': {'B1': b1, 'B2': b2, 'B3': {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6}}, 'A2': a2, 'A3': a3} return out_dict" "import struct def main(data): A = struct.unpack_from('lHLLLlqQ', raw_data[adress_b:adress_b + 38]) (b['B1'], size_ui32_arr, adress_ui32_arr, b['B3'], adress_c, b['B5'], b['B6'], b['B7']) = data_b buf_data = unpack(f'>{size_ui32_arr}L', raw_data[adress_ui32_arr:adress_ui32_arr + size_ui32_arr * 4]) b['B2'] = list(buf_data) c = {f'C{i}': None for i in range(1, 4)} data_c = unpack('>qHH', raw_data[adress_c:adress_c + 12]) (c['C1'], c['C2'], c['C3']) = data_c b['B4'] = c a = {f'A{i}': None for i in range(1, 9)} data_a = unpack('>LHhhhhbLqLLb', raw_data[adress_b + 38:adress_b + 38 + 36]) buf = [0, 0, 0, 0] (size_d_str, adress_d, buf[0], buf[1], buf[2], buf[3], a['A4'], a['A5'], a['A6'], size_ui16_arr, address_ui16_arr, a['A8']) = data_a a['A3'] = buf a['A1'] = b buf_data = unpack(f'>{size_ui16_arr}H', raw_data[address_ui16_arr:address_ui16_arr + size_ui16_arr * 2]) a['A7'] = list(buf_data) a['A2'] = parse_d(adress_d, size_d_str, raw_data) return a def parse_d(adress, size, raw_data): arr = [] for i in range(0, size): d = {f'D{i}': None for i in range(1, 4)} data_d = unpack('>Bf', raw_data[adress:adress + 5]) (d['D1'], d['D2']) = data_d e_adress = adress + 5 e = {f'E{i}': None for i in range(1, 4)} data_e = unpack('>BhHL', raw_data[e_adress:e_adress + 9]) (e['E1'], e['E2'], double_arr_size, double_arr_adress) = data_e buf_data = unpack(f'>{double_arr_size}d', raw_data[double_arr_adress:double_arr_adress + double_arr_size * 8]) e['E3'] = list(buf_data) d['D3'] = e arr.append(d) adress = e_adress + 9 return arr" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 79: break a = {f'A{i}': None for i in range(1, 7)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 3)} temp = unpack('<8cHH2HdbBf', file[a_adr:a_adr + 30]) (*ch_arr, b_str_size, b_str_adr) = temp[0:10] (*a['A3'], a['A4'], a['A5'], d['D1'], d['D2']) = temp[10:] a['A1'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A2'] = [] b_adrs = unpack(f'<{b_str_size}H', file[b_str_adr:b_str_adr + b_str_size * 2]) for b_adr in b_adrs: temp = unpack('<4BbQbhh', file[b_adr:b_adr + 18]) (*b['B1'], c['C1'], c['C2'], c['C3'], c['C4'], c['C5']) = temp b['B2'] = c.copy() a['A2'].append(b.copy()) a['A6'] = d return a" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 a2 = struct_b(offset) offset += 4 + 4 + 8 + 8 + 1 + 2 + 4 [a3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 le = 8 * 4 + 2 + 8 a4 = [struct_e(link_str + i * le) for i in range(length1)] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [b2] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [b3] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [b4] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [b5] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [b6] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [b7] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': struct_c(b6), 'B7': struct_d(b7)} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [c2] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [c3] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [c4] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(offset: int) -> dict: d1 = list(struct.unpack('> 6c', binary[offset:offset + 6 * 1])) offset += 6 * 1 d1 = [i.decode('UTF-8') for i in d1] [d2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [d3] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 d4 = list(struct.unpack('> ' + str(length1) + 'B', binary[link_str:link_str + length1 * 1])) return {'D1': ''.join(d1), 'D2': d2, 'D3': d3, 'D4': d4} def struct_e(offset: int) -> dict: e1 = list(struct.unpack('> 8f', binary[offset:offset + 8 * 4])) offset += 8 * 4 [e2] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [e3] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'E1': e1, 'E2': e2, 'E3': e3} return struct_a(4)" "from struct import unpack, calcsize PATTERN_A = ' H', x[start + 8:start + 10])[0], 'A3': st.unpack('> I', x[start + 10:start + 14])[0], 'A4': st.unpack('> Q', x[start + 14:start + 22])[0], 'A5': [st.unpack('> f', x[start + 22:start + 26])[0], st.unpack('> f', x[start + 26:start + 30])[0], st.unpack('> f', x[start + 30:start + 34])[0], st.unpack('> f', x[start + 34:start + 38])[0], st.unpack('> f', x[start + 38:start + 42])[0], st.unpack('> f', x[start + 42:start + 46])[0]], 'A6': st.unpack('> d', x[start + 46:start + 54])[0], 'A7': uint32_uint16_uint16(x, start + 54)} def b(x, start): return {'B1': c(x, start), 'B2': d(x, start + 15), 'B3': st.unpack('> H', x[start + 47:start + 49])[0]} def c(x, start): return {'C1': st.unpack('> B', x[start:start + 1])[0], 'C2': st.unpack('> f', x[start + 1:start + 5])[0], 'C3': st.unpack('> B', x[start + 5:start + 6])[0], 'C4': st.unpack('> b', x[start + 6:start + 7])[0], 'C5': st.unpack('> f', x[start + 7:start + 11])[0], 'C6': st.unpack('> i', x[start + 11:start + 15])[0]} def d(x, start): return {'D1': [st.unpack('> H', x[start:start + 2])[0], st.unpack('> H', x[start + 2:start + 4])[0], st.unpack('> H', x[start + 4:start + 6])[0], st.unpack('> H', x[start + 6:start + 8])[0], st.unpack('> H', x[start + 8:start + 10])[0], st.unpack('> H', x[start + 10:start + 12])[0], st.unpack('> H', x[start + 12:start + 14])[0]], 'D2': st.unpack('> I', x[start + 14:start + 18])[0], 'D3': st.unpack('> f', x[start + 18:start + 22])[0], 'D4': st.unpack('> h', x[start + 22:start + 24])[0], 'D5': uint32_uint32_int16(x, start + 24)} def uint32_uint32_int16(x, start): size = st.unpack('> I', x[start:start + 4])[0] address = st.unpack('> I', x[start + 4:start + 8])[0] arr = st.unpack('> ' + 'h' * size, x[address:address + 2 * size]) return list(arr) def address_b(x, start): return st.unpack('> I', x[start:start + 4])[0] def uint32_uint16_uint16(x, start): size = st.unpack('> I', x[start:start + 4])[0] address = st.unpack('> H', x[start + 4:start + 6])[0] arr = st.unpack('> ' + 'H' * size, x[address:address + 2 * size]) return list(arr)" "import struct as st def a(x, start): return {'A1': b(x, start), 'A2': str(st.unpack('< c', x[start + 17:start + 18])[0])[2] + str(st.unpack('< c', x[start + 18:start + 19])[0])[2] + str(st.unpack('< c', x[start + 19:start + 20])[0])[2] + str(st.unpack('< c', x[start + 20:start + 21])[0])[2] + str(st.unpack('< c', x[start + 21:start + 22])[0])[2] + str(st.unpack('< c', x[start + 22:start + 23])[0])[2], 'A3': d(x, address_d(x, start + 23)), 'A4': st.unpack('< I', x[start + 27:start + 31])[0], 'A5': st.unpack('< i', x[start + 31:start + 35])[0], 'A6': st.unpack('< q', x[start + 35:start + 43])[0], 'A7': st.unpack('< d', x[start + 43:start + 51])[0]} def b(x, start): return {'B1': [c(x, address_c(x, start)), c(x, address_c(x, start + 4)), c(x, address_c(x, start + 8)), c(x, address_c(x, start + 12))], 'B2': st.unpack('< B', x[start + 16:start + 17])[0]} def c(x, start): return {'C1': st.unpack('< h', x[start:start + 2])[0], 'C2': st.unpack('< f', x[start + 2:start + 6])[0], 'C3': [st.unpack('< B', x[start + 6:start + 7])[0], st.unpack('< B', x[start + 7:start + 8])[0], st.unpack('< B', x[start + 8:start + 9])[0]]} def d(x, start): return {'D1': [st.unpack('< h', x[start:start + 2])[0], st.unpack('< h', x[start + 2:start + 4])[0], st.unpack('< h', x[start + 4:start + 6])[0], st.unpack('< h', x[start + 6:start + 8])[0], st.unpack('< h', x[start + 8:start + 10])[0], st.unpack('< h', x[start + 10:start + 12])[0], st.unpack('< h', x[start + 12:start + 14])[0], st.unpack('< h', x[start + 14:start + 16])[0]], 'D2': uint16_uint32_int16(x, start + 16)} def address_c(x, start): return st.unpack('< I', x[start:start + 4])[0] def address_d(x, start): return st.unpack('< I', x[start:start + 4])[0] def uint16_uint32_int16(x, start): size = st.unpack('< H', x[start:start + 2])[0] address = st.unpack('< I', x[start + 2:start + 6])[0] arr = st.unpack('< ' + 'h' * size, x[address:address + 2 * size]) return list(arr) def main(x): return a(x, 5)" "import struct def main(data): result = {} addresses = struct.unpack('>3H', data[4:4 + 6]) b1 = struct.unpack('>qQh', data[addresses[0]:addresses[0] + 18]) b2 = struct.unpack('>qQh', data[addresses[1]:addresses[1] + 18]) b3 = struct.unpack('>qQh', data[addresses[2]:addresses[2] + 18]) result['A1'] = [{'B1': b1[0], 'B2': b1[1], 'B3': b1[2]}, {'B1': b2[0], 'B2': b2[1], 'B3': b2[2]}, {'B1': b3[0], 'B2': b3[1], 'B3': b3[2]}] value = struct.unpack('>B', data[10:11]) result['A2'] = value[0] value = struct.unpack('>h', data[11:13]) result['A3'] = value[0] value = struct.unpack('>i', data[13:17]) result['A4'] = value[0] value = struct.unpack('>4c', data[17:21]) result['A5'] = (value[0] + value[1] + value[2] + value[3]).decode('utf-8') value = struct.unpack('>I', data[21:25]) result['A6'] = {'C1': value[0]} value = struct.unpack('>i', data[25:29]) result['A6']['C2'] = value[0] values = {} value = struct.unpack('>i', data[29:33]) values['D1'] = value[0] value = struct.unpack('>Q', data[33:41]) values['D2'] = value[0] size = struct.unpack('>I', data[41:45]) address = struct.unpack('>I', data[45:49]) size = size[0] address = address[0] floats = [] for i in range(size): f = struct.unpack('>f', data[address:address + 4]) floats.append(f[0]) address = address + 4 values['D3'] = floats result['A6']['C3'] = values value = struct.unpack('>B', data[49:50]) result['A6']['C3']['D4'] = value[0] value = struct.unpack('>q', data[50:58]) result['A6']['C3']['D5'] = value[0] size = struct.unpack('>I', data[58:62]) address = struct.unpack('>I', data[62:66]) size = size[0] address = address[0] floats = [] for i in range(size): f = struct.unpack('>f', data[address:address + 4]) floats.append(f[0]) address = address + 4 result['A6']['C3']['D6'] = floats value = struct.unpack('>I', data[66:70]) result['A7'] = value[0] return result" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u16u16i32(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'i' * size, s[add:add + 4 * size]) return list(arr) def u16u32f(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>I', s[start.a:start + 4])[0] arr = unpack('>' + 'f' * size, s[add:add + 4 * size]) return list(arr) def u16u16u8(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'B' * size, s[add:add + size * 1]) return list(arr) def E(s, start): start = Counter(start) return {'E1': unpack('>H', s[start.a:start + 2])[0], 'E2': unpack('>f', s[start.a:start + 4])[0], 'E3': [unpack('>B', s[start.a:start + 1])[0] for i in range(5)], 'E4': unpack('>H', s[start.a:start + 2])[0]} def D(s, start): start = Counter(start) return {'D1': unpack('>B', s[start.a:start + 1])[0], 'D2': u16u16u8(s, start), 'D3': E(s, unpack('>I', s[start.a:start + 4])[0])} def C(s, start): return {'C1': unpack('>d', s[start.a:start + 8])[0], 'C2': unpack('>b', s[start.a:start + 1])[0], 'C3': unpack('>I', s[start.a:start + 4])[0], 'C4': [D(s, unpack('>I', s[start.a:start + 4])[0]), D(s, unpack('>I', s[start.a:start + 4])[0])], 'C5': unpack('>H', s[start.a:start + 2])[0], 'C6': unpack('>h', s[start.a:start + 2])[0], 'C7': unpack('>Q', s[start.a:start + 8])[0], 'C8': u16u32f(s, start)} def B(s, start): return {'B1': unpack('>Q', s[start.a:start + 8])[0], 'B2': unpack('>i', s[start.a:start + 4])[0], 'B3': unpack('>i', s[start.a:start + 4])[0]} def A(s, start): return {'A1': unpack('>I', s[start.a:start + 4])[0], 'A2': unpack('>h', s[start.a:start + 2])[0], 'A3': B(s, start), 'A4': C(s, start), 'A5': u16u16i32(s, start), 'A6': unpack('>i', s[start.a:start + 4])[0], 'A7': unpack('>B', s[start.a:start + 1])[0], 'A8': unpack('>Q', s[start.a:start + 8])[0]} def main(s): start = Counter(4) return A(s, start)" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): e1 = [] for _ in range(0, 6): (val, offs) = parse(buf, offs, 'uint16') e1.append(val) e2 = [] for _ in range(0, 3): (val, offs) = parse(buf, offs, 'uint32') e2.append(val) return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) (c2, offs) = parse(buf, offs, 'int32') (c3_size, offs) = parse(buf, offs, 'uint32') (c3_offs, offs) = parse(buf, offs, 'uint32') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse_e(buf, c3_offs) c3.append(val) (c4, offs) = parse(buf, offs, 'int8') (c5_size, offs) = parse(buf, offs, 'uint16') (c5_offs, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'int16') c5.append(val) (c6, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2, offs) = parse_c(buf, offs) (b3, offs) = parse(buf, offs, 'int16') (b4, offs) = parse(buf, offs, 'float') (b5, offs) = parse(buf, offs, 'double') (b6, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse(buf, offs, 'int64') (a4, offs) = parse(buf, offs, 'int8') (a5, offs) = parse(buf, offs, 'int16') (a6_offs, offs) = parse(buf, offs, 'uint32') (val, a6_offs) = parse_b(buf, a6_offs) a6 = val (a7, offs) = parse(buf, offs, 'uint64') (a8, offs) = parse(buf, offs, 'uint16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def main(x): A1 = struct.unpack('>H', x[5:7])[0] A2 = str(str(struct.unpack('>5s', x[7:12]))[3:8]) A3 = struct.unpack('>B', x[12:13])[0] mass_addr_struct_C = struct.unpack('>3L', x[13:25]) A4_B1_C1_1_len = struct.unpack('>H', x[mass_addr_struct_C[0]:mass_addr_struct_C[0] + 2])[0] A4_B1_C1_1_addr = struct.unpack('>L', x[mass_addr_struct_C[0] + 2:mass_addr_struct_C[0] + 6])[0] A4_B1_C1_1_mass = list(struct.unpack('>' + str(A4_B1_C1_1_len) + 'Q', x[A4_B1_C1_1_addr:A4_B1_C1_1_addr + 8 * A4_B1_C1_1_len])) A4_B1_C2_1 = struct.unpack('>L', x[mass_addr_struct_C[0] + 6:mass_addr_struct_C[0] + 6 + 4])[0] A4_B1_C1_2_len = struct.unpack('>H', x[mass_addr_struct_C[1]:mass_addr_struct_C[1] + 2])[0] A4_B1_C1_2_addr = struct.unpack('>L', x[mass_addr_struct_C[1] + 2:mass_addr_struct_C[1] + 6])[0] A4_B1_C1_2_mass = list(struct.unpack('>' + str(A4_B1_C1_2_len) + 'Q', x[A4_B1_C1_2_addr:A4_B1_C1_2_addr + 8 * A4_B1_C1_2_len])) A4_B1_C2_2 = struct.unpack('>L', x[mass_addr_struct_C[1] + 6:mass_addr_struct_C[1] + 6 + 4])[0] A4_B1_C1_3_len = struct.unpack('>H', x[mass_addr_struct_C[2]:mass_addr_struct_C[2] + 2])[0] A4_B1_C1_3_addr = struct.unpack('>L', x[mass_addr_struct_C[2] + 2:mass_addr_struct_C[2] + 6])[0] A4_B1_C1_3_mass = list(struct.unpack('>' + str(A4_B1_C1_3_len) + 'Q', x[A4_B1_C1_3_addr:A4_B1_C1_3_addr + 8 * A4_B1_C1_3_len])) A4_B1_C2_3 = struct.unpack('>L', x[mass_addr_struct_C[2] + 6:mass_addr_struct_C[2] + 6 + 4])[0] B2 = struct.unpack('>h', x[25:27])[0] B3_len = struct.unpack('>H', x[27:29])[0] B3_addr = struct.unpack('>H', x[29:31])[0] B3_mass = list(struct.unpack('>' + str(B3_len) + 'd', x[B3_addr:B3_addr + B3_len * 8])) B4 = struct.unpack('>d', x[31:39])[0] B5 = struct.unpack('>h', x[39:41])[0] B6 = struct.unpack('>B', x[41:42])[0] D1 = struct.unpack('>B', x[42:43])[0] D2 = struct.unpack('>q', x[43:51])[0] D3 = struct.unpack('>Q', x[51:59])[0] D4 = struct.unpack('>d', x[59:67])[0] D5_len = struct.unpack('>L', x[67:71])[0] D5_addr = struct.unpack('>H', x[71:73])[0] D5_mass = list(struct.unpack('>' + str(D5_len) + 'B', x[D5_addr:D5_addr + 1 * D5_len])) A6 = struct.unpack('>B', x[73:74])[0] mass_slov_B1 = [] slow_C_1 = {'C1': A4_B1_C1_1_mass, 'C2': A4_B1_C2_1} slow_C_2 = {'C1': A4_B1_C1_2_mass, 'C2': A4_B1_C2_2} slow_C_3 = {'C1': A4_B1_C1_3_mass, 'C2': A4_B1_C2_3} mass_slov_B1.append(slow_C_1) mass_slov_B1.append(slow_C_2) mass_slov_B1.append(slow_C_3) slow_B = {'B1': mass_slov_B1, 'B2': B2, 'B3': B3_mass, 'B4': B4, 'B5': B5, 'B6': B6} slow_D = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5_mass} slow_A = {'A1': A1, 'A2': A2, 'A3': A3, 'A4': slow_B, 'A5': slow_D, 'A6': A6} return slow_A" "import struct def parse_array(data, offset, data_type, length): return list(struct.unpack(f'>{length}{data_type}', data[offset:offset + length * struct.calcsize(data_type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['D2'] = parse_array(data, offset + 1, 'd', 3) result['D3'] = struct.unpack('>q', data[offset + 25:offset + 25 + 8])[0] result['D4'] = struct.unpack('>b', data[offset + 33:offset + 33 + 1])[0] result['D5'] = struct.unpack('>h', data[offset + 34:offset + 34 + 2])[0] result['D6'] = parse_array(data, offset + 36, 'i', 8) result['D7'] = struct.unpack('>I', data[offset + 68:offset + 68 + 4])[0] result['D8'] = struct.unpack('>B', data[offset + 72:offset + 72 + 1])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['C2'] = struct.unpack('>B', data[offset + 1:offset + 1 + 1])[0] result['C3'] = struct.unpack('>H', data[offset + 2:offset + 2 + 2])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>q', data[offset:offset + 8])[0] (b2_size, b2_address) = struct.unpack('>HH', data[offset + 8:offset + 8 + 4]) c_addresses = parse_array(data, b2_address, 'I', b2_size) result['B2'] = [parse_c(data, addr) for addr in c_addresses] result['B3'] = struct.unpack('>f', data[offset + 12:offset + 12 + 4])[0] result['B4'] = struct.unpack('>I', data[offset + 16:offset + 16 + 4])[0] result['B5'] = parse_d(data, offset + 20) result['B6'] = struct.unpack('>i', data[offset + 93:offset + 93 + 4])[0] result['B7'] = struct.unpack('>Q', data[offset + 97:offset + 97 + 8])[0] result['B8'] = parse_array(data, offset + 105, 'H', 4) return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['A2'] = parse_b(data, offset + 2) result['A3'] = struct.unpack('>i', data[offset + 115:offset + 115 + 4])[0] return result def main(data): return parse_a(data, 3)" "import struct def G(data: bytes): (first,) = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int32') a2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'char') a2.append(val.decode()) (a3, offs) = parse_b(buf, offs) (a4, offs) = parse(buf, offs, 'uint8') (a5, offs) = parse(buf, offs, 'uint8') (a6_addr, offs) = parse(buf, offs, 'uint32') (a6, a6_offs) = parse_c(buf, a6_addr) a7 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) a7.append(val) (a8, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_addr, offs) = parse(buf, offs, 'uint32') b1 = [] b1_offs = b1_addr for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'uint8') b1.append(val) (b2, offs) = parse(buf, offs, 'uint64') (b3, offs) = parse(buf, offs, 'float') (b4, offs) = parse(buf, offs, 'uint64') (b5, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'int16') (d3_size, offs) = parse(buf, offs, 'uint16') (d3_addr, offs) = parse(buf, offs, 'uint16') d3 = [] d3_offs = d3_addr for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'float') d3.append(val) (d4, offs) = parse(buf, offs, 'int8') (d5_size, offs) = parse(buf, offs, 'uint16') (d5_addr, offs) = parse(buf, offs, 'uint32') d5 = [] d5_offs = d5_addr for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'int16') d5.append(val) (d6, offs) = parse(buf, offs, 'int32') (d7, offs) = parse(buf, offs, 'int32') (d8, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') a2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'char') a2.append(val.decode()) (a3, offs) = parse(buf, offs, 'int8') a4 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a4.append(val) (a5_offs, offs) = parse(buf, offs, 'uint32') (a5, offs1) = parse_d(buf, a5_offs) (a6, offs) = parse(buf, offs, 'int64') (a7_size, offs) = parse(buf, offs, 'uint32') (a7_offs, offs) = parse(buf, offs, 'uint16') a7 = [] for _ in range(a7_size): (val, a7_offs) = parse(buf, a7_offs, 'int8') a7.append(val) return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse_c(buf, offs) (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') c2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int16') c2.append(val) (c3, offs) = parse(buf, offs, 'int64') (c4, offs) = parse(buf, offs, 'float') c5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') c5.append(val) (c6, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def uint16uint16uint8(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] a = struct.unpack('< ' + 'B' * size, x[add:add + 1 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('< i', x[start:start + 4])[0], 'D2': struct.unpack('< H', x[start + 4:start + 6])[0], 'D3': uint16uint16uint8(x, start + 6), 'D4': struct.unpack('< b', x[start + 10:start + 11])[0]} def C(x, start): return {'C1': struct.unpack('< B', x[start:start + 1])[0], 'C2': struct.unpack('< q', x[start + 1:start + 9])[0], 'C3': struct.unpack('< i', x[start + 9:start + 13])[0]} def addressC(x, start): return struct.unpack('< H', x[start:start + 2])[0] def addressB(x, start): return struct.unpack('< H', x[start:start + 2])[0] def B(x, start): ch = struct.unpack('< ' + 'c' * 4, x[start:start + 4]) s = '' for symbol in ch: s += str(symbol)[2] return {'B1': s, 'B2': struct.unpack('< B', x[start + 4:start + 5])[0], 'B3': struct.unpack('< B', x[start + 5:start + 6])[0], 'B4': struct.unpack('< i', x[start + 6:start + 10])[0], 'B5': C(x, addressC(x, start + 10))} def uint16uint32char(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< I', x[start + 2:start + 6])[0] a = struct.unpack('< ' + 'c' * size, x[add:add + 1 * size]) s = '' for symbol in a: s += str(symbol)[2] return s def A(x, start): return {'A1': uint16uint32char(x, start), 'A2': B(x, addressB(x, start + 6)), 'A3': struct.unpack('< Q', x[start + 8:start + 16])[0], 'A4': [D(x, start + 16), D(x, start + 27), D(x, start + 38), D(x, start + 49), D(x, start + 60), D(x, start + 71), D(x, start + 82), D(x, start + 93)]} def main(x): return A(x, 5)" "import struct def createDict(data): B1 = struct.unpack(' 1: y = [] for i in range(arr_len): y.append(struct.unpack('< ' + self.t_dict[c_type]['f'], self.x[adr + i * size:adr + (i + 1) * size])[0]) else: y = struct.unpack('< ' + self.t_dict[c_type]['f'], self.x[adr:adr + size])[0] return y def unpack_at_adr_of_size(self, arr_len_type, adr_type, c_type, temp=False): arr_len = self.unpack(arr_len_type, temp=temp) adr = self.unpack(adr_type, temp=temp) size = self.t_dict[c_type]['size'] y = [] for i in range(arr_len): y.append(struct.unpack('< ' + self.t_dict[c_type]['f'], self.x[adr + i * size:adr + (i + 1) * size])[0]) return y def unpack_C_at_adr_of_size(self, arr_len_type, adr_type, c_type): addresses = self.unpack_at_adr_of_size(arr_len_type, adr_type, c_type) return [self.C(adr) for adr in addresses] def E(self): y = {'E1': self.unpack('int64'), 'E2': self.unpack_at_adr_of_size('uint32', 'uint16', 'uint8'), 'E3': self.unpack('int8'), 'E4': self.unpack('int32')} return y def D(self, adr): if adr: self.temp_cur = adr y = {'D1': self.unpack('float', temp=bool(adr)), 'D2': self.unpack('int16', temp=bool(adr)), 'D3': self.unpack_at_adr_of_size('uint16', 'uint32', 'int8', temp=bool(adr)), 'D4': self.unpack('int16', temp=bool(adr))} return y def C(self, adr=None): if adr: self.temp_cur = adr y = {'C1': self.unpack('uint16', temp=bool(adr)), 'C2': self.unpack('float', temp=bool(adr)), 'C3': self.unpack('uint16', temp=bool(adr))} return y def B(self): y = {'B1': self.unpack('int16'), 'B2': self.unpack('uint8'), 'B3': self.unpack_C_at_adr_of_size('uint16', 'uint32', 'uint32'), 'B4': self.unpack('uint8'), 'B5': self.unpack('double'), 'B6': self.D(self.unpack('uint16')), 'B7': self.E(), 'B8': self.unpack('int64')} return y def A(self): y = {'A1': self.B(), 'A2': self.unpack('uint8', 7), 'A3': self.unpack('float')} return y def main(x): unpacker = Unpacker(x, 4) return unpacker.A()" "from struct import * from struct import calcsize as cs from struct import unpack as up def main(p): si = 3 a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 7)} tmp = list(up(' reader.offset: return read(reader) def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e1 = reader.read_uint32() e2 = reader.read_int16() e3 = reader.read_int64() e4 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint16(), structure_size=2) e5 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_int8()) e6 = reader.read_uint64() return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6) def read_d(reader: BinaryReader): d1 = reader.read_uint32() d2 = reader.read_int32() return dict(D1=d1, D2=d2) def read_c(reader: BinaryReader): c1 = reader.read_int32() c2 = read_d(reader) c3 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode('ascii'))) c4 = read_hu(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_e(reader)) c5 = reader.read_int64() return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def read_b(reader: BinaryReader): b1 = reader.read_uint16() b2 = reader.read_double() b3 = reader.read_uint16() return dict(B1=b1, B2=b2, B3=b3) def read_a(reader: BinaryReader): a1 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=9) a2 = reader.read_double() a3 = reader.read_uint16() a4 = reader.read_float() a5 = reader.read_uint64() a6 = reader.read_int8() a7 = read_c(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('{arr_len}{type}',\n data[offset:\n offset +\n arr_len * struct.calcsize(type)]))\n"" def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'uint64') (d3, offs) = parse(buf, offs, 'double') (d4, offs) = parse(buf, offs, 'int64') d5 = [] for _ in range(0, 7): (val, offs) = parse(buf, offs, 'int32') d5.append(val) (d6_size, offs) = parse(buf, offs, 'uint32') (d6_offs, offs) = parse(buf, offs, 'uint32') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'uint16') d6.append(val) (d7, offs) = parse(buf, offs, 'int64') (d8, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_b(buf, offs): b1 = [] for _ in range(0, 7): (val, offs) = parse(buf, offs, 'char') b1.append(val.decode()) (b2, offs) = parse(buf, offs, 'uint64') (b3_size, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint16') b3 = [] for _ in range(b3_size): (b3_c_addr, b3_offs) = parse(buf, b3_offs, 'uint32') (val, b3_c_addr) = parse_c(buf, b3_c_addr) b3.append(val) (b4, offs) = parse(buf, offs, 'float') (b5, offs) = parse(buf, offs, 'int64') (b6, offs) = parse_d(buf, offs) b7 = [] for _ in range(0, 8): (val, offs) = parse(buf, offs, 'int16') b7.append(val) return (dict(B1=''.join(b1), B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2_offs, offs) = parse(buf, offs, 'uint16') (val, a2_offs) = parse_b(buf, a2_offs) a2 = val (a3, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import pprint def parse_e(data, pointer): e1 = list(struct.unpack('>5B', data[pointer:pointer + 5])) e2 = struct.unpack('>d', data[pointer + 5:pointer + 13])[0] f3 = struct.unpack('>II', data[pointer + 13:pointer + 21]) e3 = list(struct.unpack(f'>{f3[0]}f', data[f3[1]:f3[1] + f3[0] * 4])) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): d1 = parse_e(data, pointer) (d2, d3) = struct.unpack('>hq', data[pointer + 21:pointer + 31]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>bfId', data[pointer:pointer + 17]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): b1 = struct.unpack('>f', data[pointer:pointer + 4])[0] f2 = struct.unpack('>H', data[pointer + 4:pointer + 6]) b2 = parse_c(data, f2[0]) return {'B1': b1, 'B2': b2} def parse_a(data, pointer): (a1, a2, a3) = struct.unpack('>qhh', data[pointer:pointer + 12]) f4 = struct.unpack('>HI', data[pointer + 12:pointer + 18]) a4 = ''.join(map(str, struct.unpack(f'>{f4[0]}c', data[f4[1]:f4[1] + f4[0]]))) a4 = a4.replace(""'"", '')[1::2] a5 = list() for i in range(3): a5.append(parse_b(data, pointer + 18 + 6 * i)) f6 = struct.unpack('>H', data[pointer + 36:pointer + 38]) a6 = parse_d(data, f6[0]) (a7, a8) = struct.unpack('>Bd', data[pointer + 38:pointer + 47]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 4)" "from struct import unpack type_dict = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's'} def gen_f(): d = type_dict return d['uint32'] + d['uint16'] + d['uint16'] def gen_e(): d = type_dict return 7 * d['float'] + d['int16'] def gen_d(): d = type_dict return d['uint32'] + d['uint16'] + d['int32'] def gen_c(): d = type_dict return 3 * d['uint16'] + d['int16'] + d['uint16'] + d['int32'] + d['uint32'] def gen_b(): d = type_dict return d['int32'] + d['float'] + d['uint64'] + d['uint32'] + d['int64'] def gen_a(): d = type_dict return d['int32'] + gen_b() + d['uint16'] def gen_total(): return 'i 6B h', data[self.shift:self.shift + unpack_size]) self.shift += unpack_size self.m['D1'] = raw[0] self.m['D2'] = list(raw[1:7]) self.m['D3'] = raw[7] class C: m: Dict shift: int def __init__(self, data: ByteString, start: int): self.m = dict() self.shift = start unpack_size = 4 + 1 + 4 raw = struct.unpack('>I b I', data[self.shift:self.shift + unpack_size]) self.shift += unpack_size d_addr = raw[0] d = D(data, d_addr) self.m['C1'] = d.m self.m['C2'] = raw[1] self.m['C3'] = raw[2] class B: m: Dict shift: int def __init__(self, data: ByteString, start: int): self.m = dict() self.shift = start unpack_size = 8 + 3 * 2 + 2 + 2 + 4 raw = struct.unpack('>q 3H HH i', data[self.shift:self.shift + unpack_size]) self.shift += unpack_size self.m['B1'] = raw[0] c_addr_arr = raw[1:4] self.m['B2'] = list() self.m['B2'].append(C(data, c_addr_arr[0]).m) self.m['B2'].append(C(data, c_addr_arr[1]).m) self.m['B2'].append(C(data, c_addr_arr[2]).m) (uint16_size, uint16_addr) = (raw[4], raw[5]) unpack_size = uint16_size * 2 self.m['B3'] = list(struct.unpack(f'> {uint16_size}H', data[uint16_addr:uint16_addr + unpack_size])) self.m['B4'] = raw[6] class A: m: Dict shift: int def __init__(self, data: ByteString, start: int): self.m = dict() self.shift = start unpack_size = 4 + 4 raw = struct.unpack('>fI', data[self.shift:self.shift + unpack_size]) self.shift += unpack_size self.m['A1'] = raw[0] self.m['A2'] = raw[1] b = B(data, self.shift) self.m['A3'] = b.m self.shift = b.shift unpack_size = 1 + 8 + 2 + 2 raw = struct.unpack('>bdHH', data[self.shift:self.shift + unpack_size]) self.shift += unpack_size self.m['A4'] = raw[0] self.m['A5'] = raw[1] (int32_size, int32_addr) = (raw[2], raw[3]) unpack_size = int32_size * 4 self.m['A6'] = list(struct.unpack(f'> {int32_size}i', data[int32_addr:int32_addr + unpack_size])) def main(data: ByteString) -> Dict: return A(data, 4).m" "import struct def main(x): offset = 5 ans = A(x, offset) return ans def A(x, offset): ans = {} size = 114 buffer = x[offset:offset + size] obj = struct.unpack('B', bytes, 4)[0] dict['A2'] = struct.unpack_from('>q', bytes, 5)[0] dictB = {} dict['A3'] = dictB dictB['B1'] = struct.unpack_from('>B', bytes, 13)[0] address_C = struct.unpack_from('>H', bytes, 14)[0] dictC = {} dictB['B2'] = dictC dictC['C1'] = [] for i in range(3): dictC['C1'].append(struct.unpack_from('>I', bytes, address_C + 4 * i)[0]) dictC['C2'] = struct.unpack_from('>I', bytes, address_C + 12)[0] dictC['C3'] = struct.unpack_from('>i', bytes, address_C + 16)[0] dictC['C4'] = struct.unpack_from('>f', bytes, address_C + 20)[0] dictC['C5'] = struct.unpack_from('>b', bytes, address_C + 24)[0] dictD = {} dictC['C6'] = dictD dictD['D1'] = struct.unpack_from('>H', bytes, address_C + 25)[0] dictD['D2'] = struct.unpack_from('>h', bytes, address_C + 27)[0] dictD['D3'] = [] for i in range(4): dictD['D3'].append(struct.unpack_from('>I', bytes, address_C + 29 + 4 * i)[0]) dictB['B3'] = struct.unpack_from('>h', bytes, 16)[0] dictB['B4'] = struct.unpack_from('>h', bytes, 18)[0] dict['A4'] = struct.unpack_from('>i', bytes, 20)[0] dictE = [] address_E = [] dict['A5'] = dictE for i in range(2): dictE.append({}) address_E.append(struct.unpack_from('>h', bytes, 24 + 2 * i)[0]) dictE[i]['E1'] = [] for j in range(4): dictE[i]['E1'].append(struct.unpack_from('>b', bytes, address_E[i] + j)[0]) dictE[i]['E2'] = struct.unpack_from('>h', bytes, address_E[i] + 4)[0] dictE[i]['E3'] = struct.unpack_from('>i', bytes, address_E[i] + 6)[0] dict['A6'] = struct.unpack_from('>Q', bytes, 28)[0] return dict" "import struct def A(x, i): return {'A1': [B(x, i), B(x, i + 13)], 'A2': struct.unpack('> d', x[i + 26:i + 34])[0], 'A3': C(x, i + 34), 'A4': struct.unpack('> b', x[i + 119:i + 120])[0]} def B(x, i): return {'B1': struct.unpack('> d', x[i:i + 8])[0], 'B2': struct.unpack('> f', x[i + 8:i + 12])[0], 'B3': struct.unpack('> b', x[i + 12:i + 13])[0]} def C(x, i): return {'C1': D(x, struct.unpack('> H', x[i:i + 2])[0]), 'C2': struct.unpack('> b', x[i + 2:i + 3])[0], 'C3': E(x, i + 3), 'C4': list(struct.unpack('> 7I', x[i + 45:i + 73])), 'C5': struct.unpack('> I', x[i + 73:i + 77])[0], 'C6': struct.unpack('> Q', x[i + 77:i + 85])[0]} def D(x, i): return {'D1': struct.unpack('> I', x[i:i + 4])[0], 'D2': struct.unpack('> q', x[i + 4:i + 12])[0], 'D3': struct.unpack('> H', x[i + 12:i + 14])[0], 'D4': struct.unpack('> i', x[i + 14:i + 18])[0], 'D5': struct.unpack('> B', x[i + 18:i + 19])[0]} def E(x, i): return {'E1': struct.unpack('> d', x[i:i + 8])[0], 'E2': struct.unpack('> B', x[i + 8:i + 9])[0], 'E3': list(struct.unpack('> 6B', x[i + 9:i + 15])), 'E4': struct.unpack('> I', x[i + 15:i + 19])[0], 'E5': struct.unpack('> h', x[i + 19:i + 21])[0], 'E6': list(struct.unpack('> 5B', x[i + 21:i + 26])), 'E7': struct.unpack('> q', x[i + 26:i + 34])[0], 'E8': struct.unpack('> Q', x[i + 34:i + 42])[0]} def main(x): return A(x, 3)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (temp, iterator) = getNext(data, iterator, 2, 'i') (A['A2'], iterator) = getB(data, iterator) (A['A3'], iterator) = getNext(data, iterator, 8, '>d') return A def getB(data, iterator): B = {} B['B1'] = [] for i in range(2): (temp, iterator) = getNext(data, iterator, 4, '>I') b = getC(data, temp)[0] B['B1'].append(b) (temp, iterator) = getNext(data, iterator, 4, '>I') B['B2'] = getE(data, temp)[0] (B['B3'], iterator) = getNext(data, iterator, 8, '>d') (temp, iterator) = getNext(data, iterator, 4, '>I') B['B4'] = getF(data, temp)[0] return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 4, '>i') (C['C2'], iterator) = getNext(data, iterator, 2, '>H') (C['C3'], iterator) = getNext(data, iterator, 4, '>f') (temp, iterator) = getNext(data, iterator, 4, '>I') C['C4'] = getD(data, temp)[0] return (C, iterator) def getD(data, iterator): D = {} (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') D['D1'] = getNextArr(data, temp, length, f'>{length}B')[0] (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') D['D2'] = getNextArr(data, temp, length * 2, f'>{length}h')[0] (D['D3'], iterator) = getNext(data, iterator, 8, '>q') (D['D4'], iterator) = getNext(data, iterator, 1, '>B') return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 8, '>Q') (E['E2'], iterator) = getNext(data, iterator, 8, '>d') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') E['E3'] = getNextArr(data, temp, length * 4, f'>{length}i')[0] (E['E4'], iterator) = getNext(data, iterator, 4, '>f') return (E, iterator) def getF(data, iterator): F = {} (F['F1'], iterator) = getNext(data, iterator, 8, '>q') (F['F2'], iterator) = getNext(data, iterator, 8, '>q') (F['F3'], iterator) = getNextArr(data, iterator, 8 * 2, '>2d') (F['F4'], iterator) = getNext(data, iterator, 8, '>d') (F['F5'], iterator) = getNext(data, iterator, 8, '>Q') return (F, iterator) def main(data): return getA(data, 4)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getB(data, iterator) (A['A2'], iterator) = getNext(data, iterator, 8, '>q') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A3'] = getC(data, temp)[0] (A['A4'], iterator) = getE(data, iterator) return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 4, '>i') (B['B2'], iterator) = getNext(data, iterator, 4, '>f') return (B, iterator) def getC(data, iterator): C = {} C['C1'] = [] for i in range(2): (temp, iterator) = getNext(data, iterator, 4, '>I') c = getD(data, temp)[0] C['C1'].append(c) (C['C2'], iterator) = getNext(data, iterator, 8, '>q') (C['C3'], iterator) = getNext(data, iterator, 2, '>h') (C['C4'], iterator) = getNext(data, iterator, 8, '>d') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 1, '>B') (D['D2'], iterator) = getNext(data, iterator, 4, '>i') (D['D3'], iterator) = getNext(data, iterator, 4, '>i') return (D, iterator) def getE(data, iterator): E = {} (temp, iterator) = getNext(data, iterator, 2, '>H') E['E1'] = getF(data, temp)[0] (E['E2'], iterator) = getNext(data, iterator, 8, '>q') (E['E3'], iterator) = getNext(data, iterator, 4, '>f') (E['E4'], iterator) = getNext(data, iterator, 1 * 3, '>3s') E['E4'] = E['E4'].decode('ascii') (E['E5'], iterator) = getG(data, iterator) return (E, iterator) def getF(data, iterator): F = {} (F['F1'], iterator) = getNext(data, iterator, 1, '>B') (F['F2'], iterator) = getNext(data, iterator, 4, '>f') return (F, iterator) def getG(data, iterator): G = {} (G['G1'], iterator) = getNext(data, iterator, 8, '>q') (G['G2'], iterator) = getNextArr(data, iterator, 4 * 2, '>2i') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') G['G3'] = getNextArr(data, temp, length * 8, f'>{length}q')[0] (G['G4'], iterator) = getNext(data, iterator, 8, '>q') return (G, iterator) def main(data): return getA(data, 5)" "import struct import pprint def parse_f(data, pointer): (f1, f2) = struct.unpack('I', bytes, 4)[0] address_A1 = struct.unpack_from('>H', bytes, 8)[0] dict['A1'] = struct.unpack_from('>' + str(size_A1) + 's', bytes, address_A1)[0].decode() dict['A2'] = struct.unpack_from('>I', bytes, 10)[0] size_B = struct.unpack_from('>I', bytes, 14)[0] address_B = struct.unpack_from('>I', bytes, 18)[0] dict['A3'] = [] B = 58 for i in range(size_B): dictB = {} dict['A3'].append(dictB) dictB['B1'] = struct.unpack_from('>f', bytes, address_B + B * i)[0] dictB['B2'] = struct.unpack_from('>Q', bytes, address_B + 4 + B * i)[0] dictB['B3'] = struct.unpack_from('>i', bytes, address_B + 12 + B * i)[0] dictC = {} dictB['B4'] = dictC dictC['C1'] = [] for j in range(3): dictC['C1'].append(struct.unpack_from('>B', bytes, address_B + 16 + j + B * i)[0]) dictC['C2'] = struct.unpack_from('>Q', bytes, address_B + 19 + B * i)[0] dictB['B5'] = struct.unpack_from('>I', bytes, address_B + 27 + B * i)[0] dictD = {} dictB['B6'] = dictD dictD['D1'] = struct.unpack_from('>f', bytes, address_B + 31 + B * i)[0] dictD['D2'] = struct.unpack_from('>H', bytes, address_B + 35 + B * i)[0] dictD['D3'] = struct.unpack_from('>Q', bytes, address_B + 37 + B * i)[0] dictD['D4'] = struct.unpack_from('>i', bytes, address_B + 45 + B * i)[0] dictB['B7'] = [] dictB['B8'] = [] for j in range(3): dictB['B7'].append(struct.unpack_from('>B', bytes, address_B + 49 + j + B * i)[0]) for j in range(3): dictB['B8'].append(struct.unpack_from('>H', bytes, address_B + 52 + 2 * j + B * i)[0]) return dict" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack('H', s, base_address)[0]) base_address += 2 for i in range(4): d_a2[i].setdefault('B1', struct.unpack_from('>B', s, base_address)[0]) base_address += 1 d_a2[i].setdefault('B2', struct.unpack_from('>q', s, base_address)[0]) base_address += 8 d_a2[i].setdefault('B3', struct.unpack_from('>i', s, base_address)[0]) base_address += 4 d.setdefault('A2', d_a2) d_a3.setdefault('C1', struct.unpack_from('>Hi', s, base_address)[0]) d_a3.setdefault('C2', struct.unpack_from('>Hi', s, base_address)[1]) base_address += 6 new_lenght = struct.unpack_from('>H', s, base_address)[0] base_address += 2 new_address = struct.unpack_from('>i', s, base_address)[0] base_address += 4 for i in range(new_lenght): d_d1.append(struct.unpack_from('>B', s, new_address)[0]) new_address += 1 d_c3.setdefault('D1', d_d1) d_c3.setdefault('D2', struct.unpack_from('>q', s, base_address)[0]) base_address += 8 new_lenght = struct.unpack_from('>H', s, base_address)[0] base_address += 2 new_address = struct.unpack_from('>H', s, base_address)[0] base_address += 2 for i in range(new_lenght): d_d3.append(struct.unpack_from('>I', s, new_address)[0]) new_address += 4 d_c3.setdefault('D3', d_d3) d_c3.setdefault('D4', struct.unpack_from('>d', s, base_address)[0]) base_address += 8 d_c3.setdefault('D5', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 d_a3.setdefault('C3', d_c3) d_a3.setdefault('C4', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 d_a3.setdefault('C5', struct.unpack_from('>q', s, base_address)[0]) base_address += 8 new_address = struct.unpack_from('>H', s, base_address) new_address = new_address[0] base_address += 2 d_c6.setdefault('E1', struct.unpack_from('>h', s, new_address)[0]) new_address += 2 d_c6.setdefault('E2', struct.unpack_from('>B', s, new_address)[0]) new_address += 1 d_c6.setdefault('E3', struct.unpack_from('>i', s, new_address)[0]) new_address += 4 d_c6.setdefault('E4', struct.unpack_from('>f', s, new_address)[0]) new_address += 4 d_c6.setdefault('E5', struct.unpack_from('>H', s, new_address)[0]) new_address += 2 d_c6.setdefault('E6', struct.unpack_from('>d', s, new_address)[0]) new_address += 8 for i in range(5): d_e7.append(struct.unpack_from('>h', s, new_address)[0]) new_address += 2 d_c6.setdefault('E7', d_e7) d_a3.setdefault('C6', d_c6) d.setdefault('A3', d_a3) d.setdefault('A4', struct.unpack_from('>q', s, base_address)[0]) return d" "import struct def main(data): A = struct.unpack_from('>HQH5dq', data, offset=5) B = struct.unpack_from('>HI6I', data, offset=A[0]) B1 = list(struct.unpack_from('>' + str(B[0]) + 'f', data, offset=B[1])) C2_first = list(struct.unpack_from('>' + str(B[3]) + 'b', data, offset=B[4])) C2_second = list(struct.unpack_from('>' + str(B[6]) + 'b', data, offset=B[7])) return {'A1': {'B1': B1, 'B2': [{'C1': B[2], 'C2': C2_first}, {'C1': B[5], 'C2': C2_second}]}, 'A2': {'D1': A[1], 'D2': A[2], 'D3': [A[3], A[4], A[5], A[6], A[7]], 'D4': A[8]}}" "import struct def uint32uint32uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint16uint32uint8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + size]) return list(a) def uint16uint16char(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'c' * size, x[add:add + size]) s = '' for symbol in a: s += str(symbol)[2] return s def d_structure(x, start): return {'D1': struct.unpack('> i', x[start:start + 4])[0], 'D2': struct.unpack('> q', x[start + 4:start + 12])[0], 'D3': uint32uint32uint64(x, start + 12), 'D4': struct.unpack('> Q', x[start + 20:start + 28])[0], 'D5': [struct.unpack('> H', x[start + 28:start + 30])[0], struct.unpack('> H', x[start + 30:start + 32])[0], struct.unpack('> H', x[start + 32:start + 34])[0], struct.unpack('> H', x[start + 34:start + 36])[0], struct.unpack('> H', x[start + 36:start + 38])[0], struct.unpack('> H', x[start + 38:start + 40])[0], struct.unpack('> H', x[start + 40:start + 42])[0]], 'D6': struct.unpack('> f', x[start + 42:start + 46])[0], 'D7': struct.unpack('> i', x[start + 46:start + 50])[0], 'D8': struct.unpack('> f', x[start + 50:start + 54])[0]} def c_structure(x, start): return {'C1': struct.unpack('> f', x[start:start + 4])[0], 'C2': struct.unpack('> f', x[start + 4:start + 8])[0]} def c_structure_address(x, start): return struct.unpack('> H', x[start:start + 2])[0] def b_structure(x, start): return {'B1': uint16uint16char(x, start), 'B2': struct.unpack('> b', x[start + 4:start + 5])[0], 'B3': c_structure(x, c_structure_address(x, start + 5)), 'B4': uint16uint32uint8(x, start + 7), 'B5': struct.unpack('> B', x[start + 13:start + 14])[0]} def a_structure(x, start): return {'A1': struct.unpack('> i', x[start:start + 4])[0], 'A2': struct.unpack('> Q', x[start + 4:start + 12])[0], 'A3': struct.unpack('> d', x[start + 12:start + 20])[0], 'A4': struct.unpack('> H', x[start + 20:start + 22])[0], 'A5': [b_structure(x, start + 22), b_structure(x, start + 36)], 'A6': d_structure(x, start + 50), 'A7': struct.unpack('> f', x[start + 104:start + 108])[0], 'A8': struct.unpack('> Q', x[start + 108:start + 116])[0]} def main(x): return a_structure(x, 4)" "import struct def main(byte_stack): dict_for_return = {} dict_for_return['A1'] = struct.unpack_from('>q', byte_stack, offset=3)[0] size_char = struct.unpack_from('>I', byte_stack, offset=11)[0] address_char = struct.unpack_from('>H', byte_stack, offset=15)[0] dict_for_return['A2'] = struct.unpack_from('>' + str(size_char) + 's', byte_stack, offset=address_char)[0].decode() address_B = struct.unpack_from('>H', byte_stack, offset=17)[0] dict_b = {} dict_for_return['A3'] = dict_b dict_for_return['A4'] = struct.unpack_from('>q', byte_stack, offset=19)[0] dict_for_return['A5'] = struct.unpack_from('>Q', byte_stack, offset=27)[0] size_char = struct.unpack_from('>H', byte_stack, offset=address_B)[0] address_char = struct.unpack_from('>I', byte_stack, offset=address_B + 2)[0] dict_b['B1'] = [] for i in range(size_char): newdict = {} newdict['C1'] = struct.unpack_from('>H', byte_stack, offset=address_char)[0] address_char += 2 newdict['C2'] = struct.unpack_from('>f', byte_stack, offset=address_char)[0] address_char += 4 dict_b['B1'].append(newdict) dict_d = {} dict_b['B2'] = dict_d dict_d['D1'] = struct.unpack_from('>b', byte_stack, offset=address_B + 6)[0] size_char = struct.unpack_from('>H', byte_stack, offset=address_B + 7)[0] address_char = struct.unpack_from('>I', byte_stack, offset=address_B + 9)[0] dict_d['D2'] = [] for i in range(size_char): dict_d['D2'].append(struct.unpack_from('>I', byte_stack, offset=address_char)[0]) address_char += 4 dict_b['B3'] = struct.unpack_from('>Q', byte_stack, offset=address_B + 13)[0] dict_b['B4'] = struct.unpack_from('>b', byte_stack, offset=address_B + 21)[0] size_char = struct.unpack_from('>I', byte_stack, offset=address_B + 22)[0] address_char = struct.unpack_from('>I', byte_stack, offset=address_B + 26)[0] dict_b['B5'] = [] for i in range(size_char): dict_b['B5'].append(struct.unpack_from('>i', byte_stack, offset=address_char)[0]) address_char += 4 dict_b['B6'] = struct.unpack_from('>H', byte_stack, offset=address_B + 30)[0] dict_b['B7'] = [] dict_b['B7'].append(struct.unpack_from('>B', byte_stack, address_B + 32)[0]) dict_b['B7'].append(struct.unpack_from('>B', byte_stack, address_B + 33)[0]) dict_b['B8'] = struct.unpack_from('>Q', byte_stack, address_B + 34)[0] return dict_for_return" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int32', data, ofs) (E2_size, ofs) = parse('uint16', data, ofs) (E2_adr, ofs) = parse('uint16', data, ofs) E2 = [] for i in range(E2_size): (t, E2_adr) = parse('uint64', data, E2_adr) E2.append(t) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): C1 = '' for i in range(4): (lop, ofs) = parse('char', data, ofs) C1 += lop.decode() (C2, ofs) = parse('int32', data, ofs) (C3, ofs) = parse('int8', data, ofs) (C4, ofs) = parse('float', data, ofs) (C5, ofs) = parse('int32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) (B2, ofs) = parse('int32', data, ofs) return (dict(B1=B1, B2=B2), ofs) def struct_D(data, ofs): (D1, ofs) = parse('float', data, ofs) (D2_size, ofs) = parse('uint32', data, ofs) (D2_adr, ofs) = parse('uint32', data, ofs) D2 = [] for _ in range(D2_size): (has, D2_adr) = struct_E(data, D2_adr) D2.append(has) (D3, ofs) = parse('uint16', data, ofs) (D4_size, ofs) = parse('uint16', data, ofs) (D4_adr, ofs) = parse('uint16', data, ofs) D4 = [] for _ in range(D4_size): (has, D4_adr) = parse('uint32', data, D4_adr) D4.append(has) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def parse_main(data, ofs): (A1, ofs) = parse('uint64', data, ofs) (A2, ofs) = struct_B(data, ofs) (A3, ofs) = parse('float', data, ofs) (A4, ofs) = parse('int8', data, ofs) (A5, ofs) = struct_C(data, ofs) (A6_adr, ofs) = parse('uint32', data, ofs) (A6, o) = struct_D(data, A6_adr) (A7, ofs) = parse('uint64', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7) def main(data): return parse_main(data, 4)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 76: break a = {f'A{i}': None for i in range(1, 6)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 5)} d = {f'D{i}': None for i in range(1, 8)} temp = unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(3): (val, a2_offs) = parse_b(buf, a2_offs) a2.append(val) offs += calcsize('>H') * 2 (a3, offs) = parse_c(buf, offs) (a4, offs) = parse_d(buf, offs) a5 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') a5.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2, offs) = parse(buf, offs, 'float') (b3, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): c1 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'char') c1.append(val.decode()) (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse(buf, offs, 'float') (c5_size, offs) = parse(buf, offs, 'uint16') (c5_offs, offs) = parse(buf, offs, 'uint32') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'uint16') c5.append(val) return (dict(C1=''.join(c1), C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'int64') (d5, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a1_offs, offs) = parse(buf, offs, 'uint16') (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'double') (a3, offs) = parse(buf, offs, 'int64') (a4, offs) = parse(buf, offs, 'int16') (a5, offs) = parse(buf, offs, 'uint16') (a6, offs) = parse_d(buf, offs) (a7, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') b2.append(val.decode()) (b3, offs) = parse(buf, offs, 'int16') (b4, offs) = parse(buf, offs, 'uint64') (b5, offs) = parse_c(buf, offs) return (dict(B1=b1, B2=''.join(b2), B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): c1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'float') c1.append(val) (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'int8') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def F(data: bytes): (one,) = struct.unpack('>d', data[60:68]) (sz,) = struct.unpack('>I', data[68:72]) (address,) = struct.unpack('>H', data[72:74]) two = [] for i in range(sz): (buff,) = struct.unpack('>f', data[address:address + 4]) two.append(buff) address += 4 (sz,) = struct.unpack('>H', data[74:76]) (address,) = struct.unpack('>H', data[76:78]) three = [] for i in range(sz): (buff,) = struct.unpack('>d', data[address:address + 8]) three.append(buff) address += 8 (four,) = struct.unpack('>B', data[78:79]) (five,) = struct.unpack('>B', data[79:80]) return {'F1': one, 'F2': two, 'F3': three, 'F4': four, 'F5': five} def E(data: bytes, address: int): one = [] for i in range(5): (buff,) = struct.unpack('>f', data[address:address + 4]) one.append(buff) address += 4 (two,) = struct.unpack('>h', data[address:address + 2]) return {'E1': one, 'E2': two} def D(data: bytes, address: int): (one,) = struct.unpack('>i', data[address:address + 4]) (two,) = struct.unpack('>B', data[address + 4:address + 5]) (three,) = struct.unpack('>h', data[address + 5:address + 7]) return {'D1': one, 'D2': two, 'D3': three} def C(data: bytes, address: int): (one,) = struct.unpack('>q', data[address:address + 8]) (two,) = struct.unpack('>i', data[address + 8:address + 12]) return {'C1': one, 'C2': two} def B(data: bytes): (one,) = struct.unpack('>f', data[12:16]) (two,) = struct.unpack('>q', data[16:24]) (three,) = struct.unpack('>h', data[24:26]) (four,) = struct.unpack('>b', data[26:27]) (address,) = struct.unpack('>H', data[27:29]) five = C(data, address) six = [] a = 29 for i in range(3): buff = D(data, a) six.append(buff) a += 7 (seven,) = struct.unpack('>d', data[50:58]) (address,) = struct.unpack('>H', data[58:60]) eight = E(data, address) return {'B1': one, 'B2': two, 'B3': three, 'B4': four, 'B5': five, 'B6': six, 'B7': seven, 'B8': eight} def A(data: bytes): (one,) = struct.unpack('>d', data[4:12]) two = B(data) three = F(data) (four,) = struct.unpack('>b', data[80:81]) (five,) = struct.unpack('>h', data[81:83]) return {'A1': one, 'A2': two, 'A3': three, 'A4': four, 'A5': five} def main(bytesSequence): return A(bytesSequence)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2, offs) = parse(buf, offs, 'uint64') (b3, offs) = parse(buf, offs, 'uint32') (b4, offs) = parse(buf, offs, 'uint64') (b5, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int8') (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint32') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse_d(buf, c4_offs) c4.append(val) c5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'float') c5.append(val) (c6_size, offs) = parse(buf, offs, 'uint16') (c6_offs, offs) = parse(buf, offs, 'uint32') c6 = [] for _ in range(c6_size): (val, c6_offs) = parse(buf, c6_offs, 'int8') c6.append(val) (c7_size, offs) = parse(buf, offs, 'uint32') (c7_offs, offs) = parse(buf, offs, 'uint32') c7 = [] for _ in range(c7_size): (val, c7_offs) = parse(buf, c7_offs, 'int16') c7.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'int32') (d3, offs) = parse(buf, offs, 'float') (d4, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import io def main(d): dt = io.BytesIO(d) def sign(data): if data.read(4) == b'CJR\xbd': return 0 return -1 def A(data): dict2 = {'A1': B(data)} data = io.BytesIO(d) data.read(62) dict2['A2'] = F(struct.unpack('xxxx' + gen_a() def main(arg): d = type_dict total = gen_total() obj = unpack(total, arg[:38]) a_dict = {'A1': obj[0], 'A2': obj[1], 'A3': {}, 'A4': obj[3], 'A5': obj[4], 'A6': []} b_struct_addr = obj[2] b_obj = unpack('>' + gen_b(), arg[b_struct_addr:b_struct_addr + 64]) first_c_struct_c5_size = b_obj[6] first_c_struct_c5_addr = b_obj[7] first_c_struct_c5_total = '>' + first_c_struct_c5_size * gen_d() first_c_struct_c5 = unpack(first_c_struct_c5_total, arg[first_c_struct_c5_addr:first_c_struct_c5_addr + first_c_struct_c5_size * 9]) b_dict = {'B1': b_obj[0], 'B2': b_obj[1], 'B3': {'C1': b_obj[2], 'C2': b_obj[3], 'C3': b_obj[4], 'C4': b_obj[5], 'C5': [], 'C6': b_obj[8]}, 'B4': [b_obj[9], b_obj[10], b_obj[11]], 'B5': [b_obj[12], b_obj[13], b_obj[14], b_obj[15], b_obj[16], b_obj[17], b_obj[18], b_obj[19]], 'B6': b_obj[20], 'B7': b_obj[21], 'B8': b_obj[22]} for i in range(first_c_struct_c5_size): second_c5_struct_c7_size = first_c_struct_c5[0 + i * 5] second_c5_struct_c7_addr = first_c_struct_c5[1 + i * 5] second_c5_struct_c7_total = '>' + second_c5_struct_c7_size * d['uint8'] second_c5_struct_c7_c2 = unpack(second_c5_struct_c7_total, arg[second_c5_struct_c7_addr:second_c5_struct_c7_addr + second_c5_struct_c7_size]) listOf = [] for j in range(second_c5_struct_c7_size): listOf.append(second_c5_struct_c7_c2[j]) d_dict = {'D1': listOf, 'D2': first_c_struct_c5[2 + i * 5], 'D3': first_c_struct_c5[3 + i * 5], 'D4': first_c_struct_c5[4 + i * 5]} b_dict['B3']['C5'].append(d_dict) a_dict['A3'] = b_dict first_a_struct_size = obj[5] first_a_struct_addr = obj[6] first_a_struct_c2_total = '>' + first_a_struct_size * d['uint8'] first_a_struct_c2 = unpack(first_a_struct_c2_total, arg[first_a_struct_addr:first_a_struct_addr + first_a_struct_size * 4]) listOf = [] for i in range(first_a_struct_size): listOf.append(first_a_struct_c2[i]) a_dict['A6'] = listOf return a_dict" "import struct from enum import Enum class Types(Enum): uint8 = 'H', data[start:start + 2])[0] add = struct.unpack('>I', data[start + 2:start + 6])[0] e = struct.unpack('>' + 'b' * size, data[add:add + 1 * size]) return list(e) def uint32uint32int8(data, start): size = struct.unpack('>I', data[start:start + 4])[0] add = struct.unpack('>I', data[start + 4:start + 8])[0] e = struct.unpack('>' + 'b' * size, data[add:add + 1 * size]) return list(e) def create_c(data, address): c = [] size = struct.unpack('>H', data[address:address + 2])[0] add = struct.unpack('>H', data[address + 2:address + 4])[0] q = struct.unpack('>' + 'H' * size, data[add:add + 2 * size]) for c_address in q: c1 = struct.unpack('>b', data[c_address:c_address + 1])[0] c2 = list(struct.unpack('>2b', data[c_address + 1:c_address + 3])) c.append({'C1': c1, 'C2': c2}) return c def main(data): a1 = struct.unpack('>I', data[4:8])[0] a2 = list(struct.unpack('>3i', data[8:20])) a3 = struct.unpack('>I', data[20:24])[0] b1 = create_c(data, a1) d1 = struct.unpack('>h', data[a1 + 4:a1 + 6])[0] d2 = struct.unpack('>I', data[a1 + 6:a1 + 10])[0] d3 = struct.unpack('>I', data[a1 + 10:a1 + 14])[0] d4 = struct.unpack('>i', data[a1 + 14:a1 + 18])[0] b3 = struct.unpack('>I', data[a1 + 18:a1 + 22])[0] e1 = uint16uint32int8(data, b3) e2 = struct.unpack('>d', data[b3 + 6:b3 + 14])[0] e3 = struct.unpack('>I', data[b3 + 14:b3 + 18])[0] e4 = uint32uint32int8(data, b3 + 18) e5 = struct.unpack('>I', data[b3 + 26:b3 + 30])[0] e6 = struct.unpack('>h', data[b3 + 30:b3 + 32])[0] f1 = struct.unpack('>I', data[a3:a3 + 4])[0] f2 = struct.unpack('>Q', data[a3 + 4:a3 + 12])[0] f3 = struct.unpack('>f', data[a3 + 12:a3 + 16])[0] f4 = struct.unpack('>i', data[a3 + 16:a3 + 20])[0] f5 = struct.unpack('>I', data[a3 + 20:a3 + 24])[0] out_dict = {'A1': {'B1': b1, 'B2': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}, 'B3': {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6}}, 'A2': a2, 'A3': {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5}} return out_dict" "import struct format = {'A': {'1': 'b', '2': 'h', '3': 'H', '4': ['H', 'H'], '5': ['H', 'I'], '6': 'strD', '7': 'h', '8': ['I', 'H']}, 'B': {'1': 'd', '2': ['I', 'H'], '3': 'H'}, 'C': {'1': 'f', '2': 'd'}, 'D': {'1': 'Q', '2': 'B', '3': 'd', '4': 'h', '5': 'B', '6': 'B', '7': 'f', '8': 'B'}} def structA(data): adr = 4 a1 = struct.unpack('>' + format['A']['1'], data[adr:adr + 1])[0] adr = adr + 1 a2 = struct.unpack('>' + format['A']['2'], data[adr:adr + 2])[0] adr = adr + 2 (adr_b,) = struct.unpack('>H', data[adr:adr + 2]) a3 = structB(data, adr_b) adr = adr + 2 size_arr_char = struct.unpack('>' + format['A']['4'][0], data[adr:adr + 2])[0] adr = adr + 2 adr_arr_char = struct.unpack('>' + format['A']['4'][1], data[adr:adr + 2])[0] adr = adr + 2 a4_tuple = struct.unpack('>' + str(size_arr_char) + 'c', data[adr_arr_char:adr_arr_char + size_arr_char]) a4 = '' for i in range(len(a4_tuple)): a4 += chr(a4_tuple[i][0]) size_arr_str_c = struct.unpack('>' + format['A']['5'][0], data[adr:adr + 2])[0] adr = adr + 2 adr_arr_str_c = struct.unpack('>' + format['A']['5'][1], data[adr:adr + 4])[0] adr = adr + 4 end_adr_arr_str_c = adr_arr_str_c + 12 * size_arr_str_c a5 = list() while adr_arr_str_c != end_adr_arr_str_c: a5.append(structC(data, adr_arr_str_c)) adr_arr_str_c = adr_arr_str_c + 12 a6 = structD(data, adr) adr = adr + 26 (a7,) = struct.unpack('>' + format['A']['7'], data[adr:adr + 2]) adr = adr + 2 size_arr_uint_8 = struct.unpack('>' + format['A']['8'][0], data[adr:adr + 4])[0] adr = adr + 4 adr_arr_uint_8 = struct.unpack('>' + format['A']['8'][1], data[adr:adr + 2])[0] adr = adr + 2 a8 = [] t8 = struct.unpack('>' + str(size_arr_uint_8) + 'B', data[adr_arr_uint_8:adr_arr_uint_8 + size_arr_uint_8]) for i in t8: a8.append(i) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def structB(data, pointer): (b1,) = struct.unpack('>' + format['B']['1'], data[pointer:pointer + 8]) pointer = pointer + 8 array_char = struct.unpack('>IH', data[pointer:pointer + 6]) pointer = pointer + 6 b2_tuple = struct.unpack('>' + str(array_char[0]) + 'c', data[array_char[1]:array_char[1] + array_char[0]]) b2 = '' for i in range(len(b2_tuple)): b2 += chr(b2_tuple[i][0]) (b3,) = struct.unpack('>' + format['B']['3'], data[pointer:pointer + 2]) return {'B1': b1, 'B2': b2, 'B3': b3} def structC(data, pointer): (c1,) = struct.unpack('>' + format['C']['1'], data[pointer:pointer + 4]) pointer = pointer + 4 (c2,) = struct.unpack('>' + format['C']['2'], data[pointer:pointer + 8]) return {'C1': c1, 'C2': c2} def structD(data, pointer): (d1,) = struct.unpack('>' + format['D']['1'], data[pointer:pointer + 8]) pointer = pointer + 8 (d2,) = struct.unpack('>' + format['D']['2'], data[pointer:pointer + 1]) pointer = pointer + 1 (d3,) = struct.unpack('>' + format['D']['3'], data[pointer:pointer + 8]) pointer = pointer + 8 (d4,) = struct.unpack('>' + format['D']['4'], data[pointer:pointer + 2]) pointer = pointer + 2 (d5,) = struct.unpack('>' + format['D']['5'], data[pointer:pointer + 1]) pointer = pointer + 1 (d6,) = struct.unpack('>' + format['D']['6'], data[pointer:pointer + 1]) pointer = pointer + 1 (d7,) = struct.unpack('>' + format['D']['7'], data[pointer:pointer + 4]) pointer = pointer + 4 (d8,) = struct.unpack('>' + format['D']['8'], data[pointer:pointer + 1]) pointer = pointer + 1 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def main(data): return structA(data)" "import struct import io def main(d): dt = io.BytesIO(d) def A(data): data.read(3) ans = struct.unpack('>bIb', data.read(struct.calcsize('>bIb'))) dict1 = {'A1': ans[0], 'A2': B(ans[1]), 'A3': ans[2]} return dict1 def B(address): data = io.BytesIO(d) data.read(address) res = struct.unpack('>q', data.read(struct.calcsize('>q'))) dict1 = {'B1': res[0]} arr = [] for i in range(4): arr.append(C(data)) res = struct.unpack('>BI', data.read(struct.calcsize('>BI'))) dict1['B2'] = arr dict1['B3'] = res[0] dict1['B4'] = res[1] return dict1 def ARR(size, address): data = io.BytesIO(d) data.read(address) arr = [] for i in range(size): arr.append(struct.unpack('>b', data.read(struct.calcsize('>b')))[0]) return arr def C(data): res = struct.unpack('>bHHHb', data.read(struct.calcsize('>bHHHb'))) dict1 = {'C1': res[0], 'C2': D(res[1]), 'C3': ARR(res[2], res[3]), 'C4': res[4]} return dict1 def D(address): data = io.BytesIO(d) data.read(address) res = struct.unpack('>IIhhhhh', data.read(struct.calcsize('>IIhhhhh'))) arr = [res[3], res[4], res[5], res[6]] dict2 = {'D1': ARRfloat(res[0], res[1]), 'D2': res[2], 'D3': arr} return dict2 def ARRfloat(size, address): data = io.BytesIO(d) data.read(address) arr = [] for i in range(size): arr.append(struct.unpack('>f', data.read(struct.calcsize('>f')))[0]) return arr return A(dt)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_g(reader: BinaryReader): return dict(G1=reader.read(Primitive.uint64), G2=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.double), structure_size=8, toSum=True), G3=reader.read(Primitive.uint8), G4=reader.read(Primitive.int16), G5=reader.read(Primitive.int32), G6=reader.read(Primitive.uint32)) def read_f(reader: BinaryReader): return dict(F1=reader.read(Primitive.uint16), F2=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int32), structure_size=4), F3=reader.read(Primitive.uint16)) def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.uint32), E2=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint16), structure_size=2), E3=reader.read(Primitive.int8)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.double), D2=reader.read(Primitive.uint64)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.int8), C2=reader.read(Primitive.int32), C3=reader.read(Primitive.uint8)) def read_b(reader: BinaryReader): return dict(B1=[read_c(BinaryReader(reader.source, offset=i)) for i in read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint16), structure_size=2)], B2=[read_d(BinaryReader(reader.source, offset=i)) for i in read_array(reader, 4, reader.offset, lambda reader: reader.read(Primitive.uint16), structure_size=2, toSum=True)], B3=reader.read(Primitive.uint16), B4=read_e(reader), B5=read_f(BinaryReader(reader.source, offset=reader.read(Primitive.uint32)))) def read_a(reader: BinaryReader): return dict(A1=read_b(reader), A2=read_g(BinaryReader(reader.source, offset=reader.read(Primitive.uint32)))) def main(source): return read_a(BinaryReader(source, offset=4))" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse_b(buf, offs) (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = parse_d(buf, a4_offs) (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4[0], A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse(buf, offs, 'uint16') (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4_addresses = [] for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'uint16') b4_addresses.append(val) b4 = [] for i in b4_addresses: (val, b4_offs) = parse_c(buf, i) b4.append(val) (b5, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') c2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') c2.append(val) (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = parse_e(buf, d1_offs) (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'float') d2.append(val) return (dict(D1=d1[0], D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int64') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'int8') (e4_size, offs) = parse(buf, offs, 'uint16') (e4_offs, offs) = parse(buf, offs, 'uint16') e4 = [] for _ in range(e4_size): (val, e4_offs) = parse(buf, e4_offs, 'double') e4.append(val) (e5, offs) = parse(buf, offs, 'int64') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def parse_array(data, size, typ, offset): n = struct.calcsize(typ) return list(struct.unpack(f'<{size}{typ}', data[offset:offset + size * n])) def parse_array_struct_d(data, addresses): arr = list() for count in range(len(addresses)): arr.append(parse_d(data, addresses[count])) return arr def parse_e(data, offset): e1 = parse_array(data, 5, 'i', offset) (e2_size, e2_offset) = struct.unpack('\x9a\xb2^:2\x050Y\\\xd6Ca\x92\x8c\xcfE/\xae\xf4\xe7q_c\x97\x8f'\xbd>*\xf6\xf5\x10\xcd\xef\xf1Ah\x1duZ\x15\x00\x00\x00(\x00\x00\x00K]\xa0\x16\x8fI\x06\xd8H$\x81 \xbb\x1bY(\x02\x00;\x00\xfaux\x13\\\x18\x03O\xfb\xa53\xea|I\xc1\xb0\rrA\xde\x04\x00\x00\x00C\x00\x00\x00\x9c\xd1\xfe(\x90\x1d/o\x98\x8b\xba\xed\xfc\x16\xdb\xbfMS\x00\x00\x00"" main(inp_1)" "from struct import unpack def main(data): d = 'h') (A['A2'], iterator) = getNext(data, iterator, 8, '>q') (A['A3'], iterator) = getNext(data, iterator, 8, '>q') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A4'] = getB(data, temp)[0] (A['A5'], iterator) = getNext(data, iterator, 8, '>q') return A def getB(data, iterator): B = {} B['B1'] = [] for i in range(7): (d, iterator) = getC(data, iterator) B['B1'].append(d) (B['B2'], iterator) = getNext(data, iterator, 2, '>h') (B['B3'], iterator) = getNext(data, iterator, 4, '>f') (temp, iterator) = getNext(data, iterator, 2, '>H') B['B4'] = getE(data, temp)[0] return (B, iterator) def getC(data, iterator): C = {} (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') C['C1'] = getNextArr(data, temp, length, f'>{length}B')[0] (C['C2'], iterator) = getD(data, iterator) return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 1, '>b') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') D['D2'] = getNextArr(data, temp, length, f'>{length}B')[0] return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 4, '>i') (E['E2'], iterator) = getNext(data, iterator, 1, '>b') (E['E3'], iterator) = getNext(data, iterator, 1, '>b') (E['E4'], iterator) = getNext(data, iterator, 1, '>B') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') E['E5'] = getNextArr(data, temp, length * 4, f'>{length}f')[0] (E['E6'], iterator) = getNext(data, iterator, 4, '>I') (E['E7'], iterator) = getNext(data, iterator, 4, '>I') (E['E8'], iterator) = getNext(data, iterator, 4, '>f') return (E, iterator) def main(data): return getA(data, 5)" "from struct import unpack def main(data): d = 'Qbbbbb' c = '>iif{D}dIHHq'.replace('{D}', d) b = 'fb' a = '>xxxxx{B}IIHHb'.replace('{B}', b) obj = unpack(a, data[:23]) B = {'B1': obj[0], 'B2': obj[1]} itog = [] for i in range(2): array_addr = obj[i + 2] array = [] for j in range(len(unpack(c, data[array_addr:array_addr + 49]))): array.append(unpack(c, data[array_addr:array_addr + 49])[j]) D = {'D1': array[3], 'D2': [array[4], array[5], array[6], array[7], array[8]]} (i_array_size, i_array_addr) = (array[10], array[11]) i_array = [] for k in range(i_array_size): i_array.append(unpack('>h', data[i_array_addr:i_array_addr + 2])[0]) i_array_addr += 2 mas = [*i_array] C = {'C1': array[0], 'C2': array[1], 'C3': array[2], 'C4': D, 'C5': array[9], 'C6': mas, 'C7': array[12], 'C8': array[13]} itog.append(C) (array_size, array_addr) = (obj[4], obj[5]) array = [] for i in range(array_size): array.append(unpack('>H', data[array_addr:array_addr + 2])[0]) array_addr += 2 A = {'A1': B, 'A2': itog, 'A3': array, 'A4': obj[6]} return A" "import struct def main(bytes): dict = {} dict['A1'] = [] for i in range(2): address_B = struct.unpack_from('>H', bytes, 5 + 2 * i)[0] dictB = {} dict['A1'].append(dictB) dictB['B1'] = struct.unpack_from('>b', bytes, address_B)[0] dictB['B2'] = struct.unpack_from('>i', bytes, address_B + 1)[0] dictB['B3'] = struct.unpack_from('>h', bytes, address_B + 5)[0] dictB['B4'] = struct.unpack_from('>b', bytes, address_B + 7)[0] address_C = struct.unpack_from('>I', bytes, address_B + 8)[0] dictC = {} dictB['B5'] = dictC dictC['C1'] = struct.unpack_from('>i', bytes, address_C)[0] dictC['C2'] = [] size_C2 = struct.unpack_from('>H', bytes, address_C + 4)[0] address_C2 = struct.unpack_from('>H', bytes, address_C + 6)[0] for j in range(size_C2): dictC['C2'].append(struct.unpack_from('>d', bytes, address_C2 + 8 * j)[0]) dictC['C3'] = struct.unpack_from('>I', bytes, address_C + 8)[0] dictD = {} dictC['C4'] = dictD address_D = struct.unpack_from('>I', bytes, address_C + 12)[0] dictD['D1'] = struct.unpack_from('>B', bytes, address_D)[0] dictD['D2'] = struct.unpack_from('>Q', bytes, address_D + 1)[0] dictD['D3'] = struct.unpack_from('>H', bytes, address_D + 9)[0] dictD['D4'] = [] for j in range(3): dictD['D4'].append(struct.unpack_from('>b', bytes, address_D + 11 + j)[0]) dictB['B6'] = struct.unpack_from('>h', bytes, address_B + 12)[0] dictB['B7'] = struct.unpack_from('>f', bytes, address_B + 14)[0] dict['A2'] = [] for i in range(7): dict['A2'].append(struct.unpack_from('>H', bytes, 9 + 2 * i)[0]) dict['A3'] = struct.unpack_from('>Q', bytes, 23)[0] return dict" "import struct def struct_a(x): size_B = struct.unpack('IbbHQHI', buffer) ans['A1'] = obj[0] ans['A2'] = obj[1] ans['A3'] = obj[2] ans['A4'] = B(x, obj[3]) ans['A5'] = obj[4] sizeA = obj[5] adressA = obj[6] arrayA = x[adressA:adressA + sizeA * 8] ans['A6'] = list(struct.unpack(f'>{sizeA}Q', arrayA)) return ans def B(x, offset): ans = {'B1': 0, 'B2': [], 'B3': None} size = 8 buffer = x[offset:offset + size] obj = struct.unpack('>q', buffer) ans['B1'] = obj[0] offset += 8 tmp = [] for i in range(4): tmp.append(C(x, offset + 15 * i)) ans['B2'] = tmp ans['B3'] = D(x, offset + 15 * 4) return ans def C(x, offset): ans = {'C1': 0, 'C2': 0.0, 'C3': 0.0, 'C4': 0, 'C5': 0} size = 15 buffer = x[offset:offset + size] obj = struct.unpack('>HffBi', buffer) ans['C1'] = obj[0] ans['C2'] = obj[1] ans['C3'] = obj[2] ans['C4'] = obj[3] ans['C5'] = obj[4] return ans def D(x, offset): ans = {'D1': 0, 'D2': 0.0, 'D3': 0, 'D4': None, 'D5': None} size = 14 buffer = x[offset:offset + size] obj = struct.unpack('>qfh', buffer) ans['D1'] = obj[0] ans['D2'] = obj[1] ans['D3'] = obj[2] ans['D4'] = E(x, offset + 14) ans['D5'] = F(x, offset + 14 + 27) return ans def E(x, offset): ans = {'E1': 0, 'E2': 0.0, 'E3': 0, 'E4': [], 'E5': [], 'E6': 0, 'E7': 0} size = 27 buffer = x[offset:offset + size] obj = struct.unpack('>BdhHHHIih', buffer) ans['E1'] = obj[0] ans['E2'] = obj[1] ans['E3'] = obj[2] sizeE1 = obj[3] adressE1 = obj[4] arrayE1 = x[adressE1:adressE1 + sizeE1] ans['E4'] = list(struct.unpack(f'>{sizeE1}B', arrayE1)) sizeE2 = obj[5] adressE2 = obj[6] arrayE2 = x[adressE2:adressE2 + sizeE2] ans['E5'] = list(struct.unpack(f'>{sizeE2}B', arrayE2)) ans['E6'] = obj[7] ans['E7'] = obj[8] return ans def F(x, offset): ans = {'F1': 0, 'F2': 0} size = 10 buffer = x[offset:offset + size] obj = struct.unpack('>hQ', buffer) ans['F1'] = obj[0] ans['F2'] = obj[1] return ans" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int32', data, ofs) (E2_size, ofs) = parse('uint16', data, ofs) (E2_adr, ofs) = parse('uint16', data, ofs) E2 = [] for i in range(E2_size): (t, E2_adr) = parse('uint64', data, E2_adr) E2.append(t) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = parse('int32', data, ofs) (C2, ofs) = parse('uint64', data, ofs) (C3, ofs) = parse('uint16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint8', data, ofs) B2 = '' for i in range(6): (g, ofs) = parse('char', data, ofs) B2 += g.decode() (B3, ofs) = parse('uint64', data, ofs) B4 = '' for i in range(3): (g, ofs) = parse('char', data, ofs) B4 += g.decode() return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) D2 = [] for i in range(3): (g, ofs) = parse('int32', data, ofs) D2.append(g) (D3, ofs) = parse('int64', data, ofs) D4 = [] for i in range(4): (g, ofs) = parse('int32', data, ofs) D4.append(g) (D5, ofs) = parse('uint64', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def parse_main(data, ofs): (A1, ofs) = parse('int8', data, ofs) (A2, ofs) = struct_B(data, ofs) (A3_size, ofs) = parse('uint16', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) A3 = [] for i in range(A3_size): (k, A3_adr) = struct_C(data, A3_adr) A3.append(k) (A4, ofs) = struct_D(data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4) def main(data): return parse_main(data, 5)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1_size, ofs) = parse('uint32', data, ofs) (E1_adr, ofs) = parse('uint16', data, ofs) E1 = [] for i in range(E1_size): (t, E1_adr) = parse('int16', data, E1_adr) E1.append(t) E2 = [] for i in range(5): (t, ofs) = parse('int16', data, ofs) E2.append(t) (E3, ofs) = parse('int16', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('float', data, ofs) (F2, ofs) = parse('int64', data, ofs) (F3, ofs) = parse('uint16', data, ofs) (F4, ofs) = parse('int8', data, ofs) (F5, ofs) = parse('uint16', data, ofs) F6 = [] for _ in range(8): (has, ofs) = parse('int8', data, ofs) F6.append(has) return dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6) def struct_C(data, ofs): (C1, ofs) = parse('uint64', data, ofs) (C2, ofs) = parse('uint64', data, ofs) (C3, ofs) = parse('int8', data, ofs) (C4, ofs) = parse('int8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint32', data, ofs) B2 = [] (B2_size, ofs) = parse('uint32', data, ofs) (B2_adr, ofs) = parse('uint32', data, ofs) for i in range(B2_size): (C_adr, B2_adr) = parse('uint16', data, B2_adr) (t, op) = struct_C(data, C_adr) B2.append(t) (B3, ofs) = parse('int64', data, ofs) (B4, ofs) = parse('uint32', data, ofs) (B5, ofs) = parse('int64', data, ofs) (B6, ofs) = struct_D(data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2_adr, ofs) = parse('uint32', data, ofs) (D2, lop) = struct_E(data, D2_adr) (D3, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def parse_main(data, ofs): (A1, ofs) = parse('int16', data, ofs) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, lop) = struct_B(data, A2_adr) (A3, ofs) = parse('uint64', data, ofs) A4 = [] for i in range(4): (k, ofs) = parse('uint32', data, ofs) A4.append(k) return dict(A1=A1, A2=A2, A3=A3, A4=A4) def main(data): return parse_main(data, 4)" "from struct import * G = '4cqdHHHHi', data) (b1_int32, b1_int16, b1_float, b1_uint16) = struct.unpack_from('>ihfQ', data, structB_address1) (b2_int32, b2_int16, b2_float, b2_uint16) = struct.unpack_from('>ihfQ', data, structB_address2) (d_uint8, d_int32, d_uint32_address_E, d_uint32_address_H) = struct.unpack_from('>Biii', data, structD_address) (i_flaot, i_uint16) = struct.unpack_from('>fH', data, structI_address) (e_uint64, e_uint32_address_F, e_uint16_address_G) = struct.unpack_from('>QIH', data, d_uint32_address_E) (h_uint64, h_uint8) = struct.unpack_from('>QB', data, d_uint32_address_H) (massive_uint32_size, massive_uint32_address, f_uint16, f_float, f_uint32, massive_uint64_1, massive_uint64_2) = struct.unpack_from('>IIHfIQQ', data, e_uint32_address_F) massive_str_1 = 'I' * massive_uint32_size f_massive_unPack = list(struct.unpack_from('>' + massive_str_1, data, massive_uint32_address)) (g_int8, massive_float_uint16_size, massive_float_uint16_address, g_int32, g_double) = struct.unpack_from('>bHHid', data, e_uint16_address_G) massive_str = 'f' * massive_float_uint16_size g_massive_unPack = list(struct.unpack_from('>' + massive_str, data, massive_float_uint16_address)) ret = {} ret['A1'] = _int64 ret['A2'] = _double ret['A3'] = _uShort ret_structB_1 = {} ret_structB_1['B1'] = b1_int32 ret_struct_B_1_struct_C = {} ret_struct_B_1_struct_C['C1'] = b1_int16 ret_struct_B_1_struct_C['C2'] = b1_float ret_struct_B_1_struct_C['C3'] = b1_uint16 ret_structB_1['B2'] = ret_struct_B_1_struct_C ret_structB_2 = {} ret_structB_2['B1'] = b2_int32 ret_struct_B_2_struct_C = {} ret_struct_B_2_struct_C['C1'] = b2_int16 ret_struct_B_2_struct_C['C2'] = b2_float ret_struct_B_2_struct_C['C3'] = b2_uint16 ret_structB_2['B2'] = ret_struct_B_2_struct_C ret['A4'] = [ret_structB_1, ret_structB_2] ret_structD = {} ret_structD['D1'] = d_uint8 ret_structD['D2'] = d_int32 ret_structD_structE = {} ret_structD_structE['E1'] = e_uint64 ret_structD_structE_structF = {} ret_structD_structE_structF['F1'] = f_massive_unPack ret_structD_structE_structF['F2'] = f_uint16 ret_structD_structE_structF['F3'] = f_float ret_structD_structE_structF['F4'] = f_uint32 ret_structD_structE_structF['F5'] = [massive_uint64_1, massive_uint64_2] ret_structD_structE['E2'] = ret_structD_structE_structF ret_structD_structE_structG = {} ret_structD_structE_structG['G1'] = g_int8 ret_structD_structE_structG['G2'] = g_massive_unPack ret_structD_structE_structG['G3'] = g_int32 ret_structD_structE_structG['G4'] = g_double ret_structD_structE['E3'] = ret_structD_structE_structG ret_structD['D3'] = ret_structD_structE ret_structD_structH = {} ret_structD_structH['H1'] = h_uint64 ret_structD_structH['H2'] = h_uint8 ret_structD['D4'] = ret_structD_structH ret['A5'] = ret_structD ret_I = {} ret_I['I1'] = i_flaot ret_I['I2'] = i_uint16 ret['A6'] = ret_I return ret" "import struct class IntMut: def __init__(self, val: int): self.__val = val def __int__(self) -> int: return self.__val def __add__(self, other: int): self.__val += other return self def a(x, start: IntMut) -> dict: return {'A1': b(x, start), 'A2': struct.unpack('< f', x[int(start):int(start + 4)])[0], 'A3': struct.unpack('< h', x[int(start):int(start + 2)])[0], 'A4': struct.unpack('< f', x[int(start):int(start + 4)])[0], 'A5': struct.unpack('< H', x[int(start):int(start + 2)])[0], 'A6': struct.unpack('< b', x[int(start):int(start + 1)])[0], 'A7': uint32uint32uint8(x, start)} def uint32uint32uint8(x, start: IntMut) -> list: size = struct.unpack('< I', x[int(start):int(start + 4)])[0] add = struct.unpack('< I', x[int(start):int(start + 4)])[0] return list(struct.unpack('< ' + 'B' * size, x[add:add + 1 * size])) def b(x, start: IntMut) -> dict: return {'B1': uint32uint32uint16c(x, start), 'B2': uint32uint16char(x, start), 'B3': struct.unpack('< h', x[int(start):int(start + 2)])[0], 'B4': d(x, start), 'B5': struct.unpack('< d', x[int(start):int(start + 8)])[0]} def uint32uint32uint16c(x, start: IntMut) -> list: size = struct.unpack('< I', x[int(start):int(start + 4)])[0] add = struct.unpack('< I', x[int(start):int(start + 4)])[0] return [c(x, IntMut(i)) for i in struct.unpack('< ' + 'H' * size, x[add:add + 2 * size])] def uint32uint16char(x, start: IntMut) -> str: size = struct.unpack('< I', x[int(start):int(start + 4)])[0] add = struct.unpack('< H', x[int(start):int(start + 2)])[0] res = '' for i in struct.unpack('< ' + 'c' * size, x[add:add + 1 * size]): res += str(i).replace(""b'"", '').replace(""'"", '') return res def c(x, start: IntMut) -> dict: return {'C1': struct.unpack('< I', x[int(start):int(start + 4)])[0], 'C2': struct.unpack('< Q', x[int(start):int(start + 8)])[0], 'C3': struct.unpack('< Q', x[int(start):int(start + 8)])[0]} def d(x, start: IntMut) -> dict: return {'D1': struct.unpack('< i', x[int(start):int(start + 4)])[0], 'D2': uint16uint16int8(x, start), 'D3': struct.unpack('< f', x[int(start):int(start + 4)])[0], 'D4': struct.unpack('< q', x[int(start):int(start + 8)])[0], 'D5': struct.unpack('< Q', x[int(start):int(start + 8)])[0]} def uint16uint16int8(x, start: IntMut) -> list: size = struct.unpack('< H', x[int(start):int(start + 2)])[0] add = struct.unpack('< H', x[int(start):int(start + 2)])[0] return list(struct.unpack('< ' + 'b' * size, x[add:add + 1 * size])) def main(data: bytes) -> dict: return a(data, IntMut(5))" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int16') (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse_f(buf, offs) (a5, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'float') (b3_offs, offs) = parse(buf, offs, 'uint32') b3 = [] (val, b3_offs) = parse_e(buf, b3_offs) b3.append(val) (b3_offs, offs) = parse(buf, offs, 'uint32') (val, b3_offs) = parse_e(buf, b3_offs) b3.append(val) (b4, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse_d(buf, offs) (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint32') (e1_offs, offs) = parse(buf, offs, 'uint16') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'int32') e1.append(val) (e2, offs) = parse(buf, offs, 'int16') (e3_size, offs) = parse(buf, offs, 'uint16') (e3_offs, offs) = parse(buf, offs, 'uint16') e3 = [] for _ in range(e3_size): (val, e3_offs) = parse(buf, e3_offs, 'int16') e3.append(val) (e4, offs) = parse(buf, offs, 'uint16') (e5, offs) = parse(buf, offs, 'float') (e6, offs) = parse(buf, offs, 'int8') (e7, offs) = parse(buf, offs, 'int32') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int32') (f2, offs) = parse(buf, offs, 'uint64') (f3, offs) = parse(buf, offs, 'uint64') return (dict(F1=f1, F2=f2, F3=f3), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def main(data): A = struct.unpack_from('>d2Ihd4cb3QHqb3If', data, offset=5) B1 = list(struct.unpack_from('>' + str(A[1]) + 'c', data, offset=A[2])) for i in range(len(B1)): B1[i] = B1[i].decode('utf-8') B1 = ''.join(B1) B4 = '' for i in range(4): B4 += A[i + 5].decode('utf-8') D = [] for i in range(3): D.append(struct.unpack_from('>5Bhbh2q', data, offset=A[i + 16])) return {'A1': A[0], 'A2': {'B1': B1, 'B2': A[3], 'B3': A[4], 'B4': B4, 'B5': A[9], 'B6': A[10], 'B7': {'C1': A[11], 'C2': A[12], 'C3': A[13]}, 'B8': A[14]}, 'A3': A[15], 'A4': [{'D1': [D[0][0], D[0][1], D[0][2], D[0][3], D[0][4]], 'D2': D[0][5], 'D3': D[0][6], 'D4': D[0][7], 'D5': [D[0][8], D[0][9]]}, {'D1': [D[1][0], D[1][1], D[1][2], D[1][3], D[1][4]], 'D2': D[1][5], 'D3': D[1][6], 'D4': D[1][7], 'D5': [D[1][8], D[1][9]]}, {'D1': [D[2][0], D[2][1], D[2][2], D[2][3], D[2][4]], 'D2': D[2][5], 'D3': D[2][6], 'D4': D[2][7], 'D5': [D[2][8], D[2][9]]}], 'A5': A[19]}" "import struct def main(x): A2 = struct.unpack('>L', x[12:16])[0] A1_list_address_B = struct.unpack('>L', x[8:12])[0] A1_list_len = struct.unpack('>L', x[4:8])[0] C1 = str(struct.unpack('>3s', x[16:19]))[3:6] C2 = struct.unpack('>q', x[19:27])[0] C3_list_len = struct.unpack('>L', x[27:31])[0] C3_list_address = struct.unpack('>H', x[31:33])[0] C3 = [] for i in range(0, C3_list_len): C3.append(struct.unpack('>H', x[C3_list_address:C3_list_address + 2])[0]) C3_list_address += 2 C4 = list(struct.unpack('>3H', x[33:39])) A4 = struct.unpack('>H', x[39:41])[0] A5_struct_address_D = struct.unpack('>H', x[41:43])[0] A1 = [] for i in range(0, A1_list_len): slov_A1 = {'B1': struct.unpack('>B', x[A1_list_address_B:A1_list_address_B + 1])[0], 'B2': struct.unpack('>h', x[A1_list_address_B + 1:A1_list_address_B + 3])[0]} A1_list_address_B += 3 A1.append(slov_A1) D1 = struct.unpack('>h', x[A5_struct_address_D:A5_struct_address_D + 2])[0] D2 = struct.unpack('>f', x[A5_struct_address_D + 2:A5_struct_address_D + 6])[0] D3_list_len = struct.unpack('>L', x[A5_struct_address_D + 6:A5_struct_address_D + 10])[0] D3_list_address = struct.unpack('>L', x[A5_struct_address_D + 10:A5_struct_address_D + 14])[0] D4 = struct.unpack('>d', x[A5_struct_address_D + 14:A5_struct_address_D + 22])[0] D5 = struct.unpack('>H', x[A5_struct_address_D + 22:A5_struct_address_D + 24])[0] D3 = [] for i in range(0, D3_list_len): D3.append(struct.unpack('>q', x[D3_list_address:D3_list_address + 8])[0]) D3_list_address += 8 slov_A5 = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5} slov_A3 = {'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4} slov_A = {'A1': A1, 'A2': A2, 'A3': slov_A3, 'A4': A4, 'A5': slov_A5} return slov_A" "from struct import unpack_from def main(bytes): A1 = unpack_from('h', bytes, offset=4)[0] addresses_b = [] for i in range(3): addresses_b.append(unpack_from('H', bytes, offset=6 + i * 2)[0]) address_c = unpack_from('H', bytes, offset=12)[0] B = [] for address in addresses_b: B1 = unpack_from('f', bytes, offset=address)[0] B2 = unpack_from('i', bytes, offset=address + 4)[0] B3 = [] for i in range(6): B3.append(unpack_from('c', bytes, offset=address + 8 + i)[0].decode()) B3 = ''.join(B3) B.append({'B1': B1, 'B2': B2, 'B3': B3}) C1 = unpack_from('i', bytes, offset=address_c)[0] D1 = unpack_from('Q', bytes, offset=address_c + 4)[0] size_array_uint64 = unpack_from('H', bytes, offset=address_c + 12)[0] address_array_uint64 = unpack_from('I', bytes, offset=address_c + 14)[0] D2 = [] for i in range(size_array_uint64): D2.append(unpack_from('Q', bytes, offset=address_array_uint64 + i * 8)[0]) D3 = unpack_from('B', bytes, offset=address_c + 18)[0] D4 = unpack_from('I', bytes, offset=address_c + 19)[0] C3 = unpack_from('q', bytes, offset=address_c + 23)[0] address_e = unpack_from('I', bytes, offset=address_c + 31)[0] size_array_int32 = unpack_from('I', bytes, offset=address_e)[0] address_array_int32 = unpack_from('I', bytes, offset=address_e + 4)[0] E1 = [] for i in range(size_array_int32): E1.append(unpack_from('i', bytes, offset=address_array_int32 + i * 4)[0]) E2 = unpack_from('d', bytes, offset=address_e + 8)[0] E3 = unpack_from('f', bytes, offset=address_e + 16)[0] E4 = unpack_from('f', bytes, offset=address_e + 20)[0] E5 = [] for i in range(2): E5.append(unpack_from('B', bytes, offset=address_e + 24 + i)[0]) E6 = unpack_from('B', bytes, offset=address_e + 26)[0] E7 = unpack_from('H', bytes, offset=address_e + 27)[0] answer = {'A1': A1, 'A2': B, 'A3': {'C1': C1, 'C2': {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4}, 'C3': C3, 'C4': {'E1': E1, 'E2': E2, 'E3': E3, 'E4': E4, 'E5': E5, 'E6': E6, 'E7': E7}}} return answer" "from struct import * FMT = dict(char='H', bytes, offset=4)[0] B2 = unpack_from('>h', bytes, offset=6)[0] B3 = unpack_from('>b', bytes, offset=8)[0] address_e = unpack_from('>H', bytes, offset=9)[0] B5 = unpack_from('>d', bytes, offset=11)[0] A2 = unpack_from('>q', bytes, offset=19)[0] C1 = unpack_from('>i', bytes, offset=address_c)[0] size_array_addresses_d = unpack_from('>H', bytes, offset=address_c + 4)[0] address_array_addresses_d = unpack_from('>I', bytes, offset=address_c + 6)[0] C3 = unpack_from('>q', bytes, offset=address_c + 10)[0] addresses_d = [] for i in range(size_array_addresses_d): addresses_d.append(unpack_from('>H', bytes, offset=address_array_addresses_d + i * 2)[0]) D = [] for address in addresses_d: D1 = unpack_from('>I', bytes, offset=address)[0] D2 = [] for i in range(2): D2.append(unpack_from('>b', bytes, offset=address + 4 + i)[0]) D3 = unpack_from('>b', bytes, offset=address + 6)[0] D4 = [] for i in range(3): D4.append(unpack_from('>h', bytes, offset=address + 7 + i * 2)[0]) D5 = unpack_from('>f', bytes, offset=address + 13)[0] D.append({'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5}) E1 = unpack_from('>h', bytes, offset=address_e)[0] E2 = unpack_from('>H', bytes, offset=address_e + 2)[0] E3 = [] for i in range(5): E3.append(unpack_from('>B', bytes, offset=address_e + 4 + i)[0]) E4 = unpack_from('>B', bytes, offset=address_e + 9)[0] answer = {'A1': {'B1': {'C1': C1, 'C2': D, 'C3': C3}, 'B2': B2, 'B3': B3, 'B4': {'E1': E1, 'E2': E2, 'E3': E3, 'E4': E4}, 'B5': B5}, 'A2': A2} return answer" "import struct def main(byte_stack): dict_for_return = {} dict_b = {} address_b = struct.unpack_from('>H', byte_stack, offset=4)[0] dict_for_return['A1'] = dict_b dict_for_return['A2'] = struct.unpack_from('>I', byte_stack, offset=6)[0] dict_for_return['A3'] = struct.unpack_from('>H', byte_stack, offset=10)[0] dict_for_return['A4'] = struct.unpack_from('>H', byte_stack, offset=12)[0] dict_for_return['A5'] = [] dict_for_return['A5'].append(struct.unpack_from('>I', byte_stack, 14)[0]) dict_for_return['A5'].append(struct.unpack_from('>I', byte_stack, 18)[0]) dict_for_return['A5'].append(struct.unpack_from('>I', byte_stack, 22)[0]) dict_for_return['A6'] = struct.unpack_from('>Q', byte_stack, offset=26)[0] dict_for_return['A7'] = struct.unpack_from('>I', byte_stack, offset=34)[0] dict_b['B1'] = struct.unpack_from('>H', byte_stack, offset=address_b)[0] size_c = struct.unpack_from('>H', byte_stack, offset=address_b + 2)[0] address_c = struct.unpack_from('>H', byte_stack, offset=address_b + 4)[0] dict_b['B2'] = [] for i in range(size_c): dict_c = {} size_uint16 = struct.unpack_from('>I', byte_stack, offset=address_c)[0] address_c += 4 address_uint16 = struct.unpack_from('>H', byte_stack, offset=address_c)[0] address_c += 2 dict_c['C1'] = [] for y in range(size_uint16): dict_c['C1'].append(struct.unpack_from('>H', byte_stack, address_uint16)[0]) address_uint16 += 2 dict_c['C2'] = struct.unpack_from('>H', byte_stack, offset=address_c)[0] address_c += 2 dict_b['B2'].append(dict_c) dict_b['B3'] = struct.unpack_from('>B', byte_stack, offset=address_b + 6)[0] address_d = struct.unpack_from('>I', byte_stack, offset=address_b + 7)[0] dict_d = {} dict_b['B4'] = dict_d address_e = struct.unpack_from('>I', byte_stack, offset=address_b + 11)[0] dict_e = {} dict_b['B5'] = dict_e dict_b['B6'] = struct.unpack_from('>i', byte_stack, offset=address_b + 15)[0] dict_d['D1'] = struct.unpack_from('>i', byte_stack, offset=address_d)[0] dict_d['D2'] = struct.unpack_from('>i', byte_stack, offset=address_d + 4)[0] dict_d['D3'] = struct.unpack_from('>B', byte_stack, offset=address_d + 8)[0] dict_d['D4'] = struct.unpack_from('>h', byte_stack, offset=address_d + 9)[0] size_int32 = struct.unpack_from('>H', byte_stack, offset=address_e)[0] address_int32 = struct.unpack_from('>I', byte_stack, offset=address_e + 2)[0] dict_e['E1'] = [] for z in range(size_int32): dict_e['E1'].append(struct.unpack_from('>i', byte_stack, offset=address_int32)[0]) address_int32 += 4 dict_e['E2'] = struct.unpack_from('>h', byte_stack, offset=address_e + 6)[0] dict_e['E3'] = struct.unpack_from('>H', byte_stack, offset=address_e + 8)[0] return dict_for_return" "from struct import unpack_from def main(bytes): A1 = unpack_from('B', bytes, offset=4)[0] A2 = unpack_from('H', bytes, offset=5)[0] B1 = unpack_from('h', bytes, offset=7)[0] size_array_int16 = unpack_from('H', bytes, offset=9)[0] address_array_int16 = unpack_from('H', bytes, offset=11)[0] B2 = [] for i in range(size_array_int16): B2.append(unpack_from('h', bytes, offset=address_array_int16 + 2 * i)[0]) B3 = unpack_from('d', bytes, offset=13)[0] B4 = unpack_from('h', bytes, offset=21)[0] B5 = unpack_from('B', bytes, offset=23)[0] B6 = unpack_from('b', bytes, offset=24)[0] address_c = unpack_from('I', bytes, offset=25)[0] B8 = unpack_from('h', bytes, offset=29)[0] address_d = unpack_from('H', bytes, offset=address_c)[0] C2 = unpack_from('H', bytes, offset=address_c + 2)[0] C3 = unpack_from('i', bytes, offset=address_c + 4)[0] D1 = unpack_from('d', bytes, offset=address_d)[0] D2 = unpack_from('B', bytes, offset=address_d + 8)[0] D3 = unpack_from('q', bytes, offset=address_d + 9)[0] D4 = unpack_from('f', bytes, offset=address_d + 17)[0] D5 = unpack_from('B', bytes, offset=address_d + 21)[0] D6 = unpack_from('I', bytes, offset=address_d + 22)[0] D7 = unpack_from('B', bytes, offset=address_d + 26)[0] size_array_uint32 = unpack_from('I', bytes, offset=address_d + 27)[0] address_array_uint32 = unpack_from('H', bytes, offset=address_d + 31)[0] D8 = [] for i in range(size_array_uint32): D8.append(unpack_from('B', bytes, offset=address_array_uint32 + i)[0]) A4 = unpack_from('H', bytes, offset=31)[0] A5 = unpack_from('Q', bytes, offset=33)[0] size_array_addresses_e = unpack_from('H', bytes, offset=41)[0] address_array_addresses_e = unpack_from('H', bytes, offset=43)[0] addresses_e = [] for i in range(size_array_addresses_e): addresses_e.append(unpack_from('H', bytes, offset=address_array_addresses_e + i * 2)[0]) E = [] for address in addresses_e: E1 = unpack_from('Q', bytes, offset=address)[0] E2 = [] for i in range(3): E2.append(unpack_from('B', bytes, offset=address + 8 + i)[0]) E3 = unpack_from('f', bytes, offset=address + 11)[0] E4 = unpack_from('H', bytes, offset=address + 15)[0] E5 = unpack_from('i', bytes, offset=address + 17)[0] E6 = [] for i in range(4): E6.append(unpack_from('B', bytes, offset=address + 21 + i)[0]) E.append({'E1': E1, 'E2': E2, 'E3': E3, 'E4': E4, 'E5': E5, 'E6': E6}) A7 = unpack_from('H', bytes, offset=45)[0] answer = {'A1': A1, 'A2': A2, 'A3': {'B1': B1, 'B2': B2, 'B3': B3, 'B4': B4, 'B5': B5, 'B6': B6, 'B7': {'C1': {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5, 'D6': D6, 'D7': D7, 'D8': D8}, 'C2': C2, 'C3': C3}, 'B8': B8}, 'A4': A4, 'A5': A5, 'A6': E, 'A7': A7} return answer" "import struct SIZE_D = 4 + 2 + 1 + 8 SIZE_C = 4 * 2 + 1 + 1 + 2 SIZE_B = 4 + 4 + 4 * 7 + 8 + 4 SIZE_A = SIZE_B + 8 + 8 def parse_d(sequence, offset): d_sequence = sequence[offset:offset + SIZE_D] d = struct.unpack('' + FMT[it], buf, offs)[0], offs + calcsize(FMT[it])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse(buf, offs, 'double') (a4_offs, offs) = parse(buf, offs, 'uint16') (a4, a4_offs) = parse_b(buf, a4_offs) (a5, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_c(buf, b2_offs) (b3, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse_d(buf, c2_offs) c2.append(val) (c3, offs) = parse(buf, offs, 'float') (c4, offs) = parse(buf, offs, 'double') (c5_size, offs) = parse(buf, offs, 'uint32') (c5_offs, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'uint32') c5.append(val) c6 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') c6.append(val) tmp = map(str, c5) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): d1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int16') d1.append(val) (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'int32') (d4, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def uint32uint32uint8(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('I', s[pointer + 4:pointer + 8])[0] a = struct.unpack('B' * size, s[add:add + 1 * size]) return list(a) def uint32uint16uint8(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('H', s[pointer + 4:pointer + 6])[0] a = struct.unpack('B' * size, s[add:add + 1 * size]) return list(a) def create_c_structures(s, pointer): result = [] for c_address in struct.unpack('2I', s[pointer:pointer + 8]): c1 = struct.unpack('h', s[c_address:c_address + 2])[0] c2 = uint32uint16uint8(s, c_address + 2) c3 = struct.unpack('q', s[c_address + 8:c_address + 16])[0] c4 = struct.unpack('H', s[c_address + 16:c_address + 18])[0] c5 = struct.unpack('H', s[c_address + 18:c_address + 20])[0] result.append({'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': {'D1': struct.unpack('H', s[c5:c5 + 2])[0], 'D2': struct.unpack('Q', s[c5 + 2:c5 + 10])[0], 'D3': uint32uint32uint8(s, c5 + 10)}}) return result def main(s): a1 = struct.unpack('H', s[4:6])[0] b1 = struct.unpack('H', s[a1:a1 + 2])[0] b2 = create_c_structures(s, a1 + 2) b3 = struct.unpack('B', s[a1 + 10:a1 + 11])[0] b4 = struct.unpack('H', s[a1 + 11:a1 + 13])[0] e1 = struct.unpack('f', s[b4:b4 + 4])[0] e2 = struct.unpack('q', s[b4 + 4:b4 + 12])[0] e3 = [struct.unpack('B', s[b4 + 12:b4 + 13])[0], struct.unpack('B', s[b4 + 13:b4 + 14])[0], struct.unpack('B', s[b4 + 14:b4 + 15])[0], struct.unpack('B', s[b4 + 15:b4 + 16])[0], struct.unpack('B', s[b4 + 16:b4 + 17])[0], struct.unpack('B', s[b4 + 17:b4 + 18])[0], struct.unpack('B', s[b4 + 18:b4 + 19])[0], struct.unpack('B', s[b4 + 19:b4 + 20])[0]] e4 = struct.unpack('h', s[b4 + 20:b4 + 22])[0] e5 = [struct.unpack('f', s[b4 + 22:b4 + 26])[0], struct.unpack('f', s[b4 + 26:b4 + 30])[0], struct.unpack('f', s[b4 + 30:b4 + 34])[0], struct.unpack('f', s[b4 + 34:b4 + 38])[0], struct.unpack('f', s[b4 + 38:b4 + 42])[0], struct.unpack('f', s[b4 + 42:b4 + 46])[0], struct.unpack('f', s[b4 + 46:b4 + 50])[0], struct.unpack('f', s[b4 + 50:b4 + 54])[0]] e6 = struct.unpack('f', s[b4 + 54:b4 + 58])[0] b5 = struct.unpack('I', s[a1 + 13:a1 + 17])[0] b6 = struct.unpack('Q', s[a1 + 17:a1 + 25])[0] a2 = struct.unpack('q', s[6:14])[0] a3 = struct.unpack('q', s[14:22])[0] a4 = struct.unpack('b', s[22:23])[0] a5 = struct.unpack('q', s[23:31])[0] out_dict = {'A1': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6}, 'B5': b5, 'B6': b6}, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} return out_dict" "import struct from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 6 return result def parse_d(data, offset): result = dict() result['D1'] = un('>f', data[offset:offset + 4])[0] result['D2'] = un('>b', data[offset + 4:offset + 5])[0] result['D3'] = un('>Q', data[offset + 5:offset + 13])[0] return result def parse_c(data, offset): result = dict() result['C1'] = un('>f', data[offset:offset + 4])[0] result['C2'] = un('>h', data[offset + 4:offset + 6])[0] return result def parse_b(data, offset): result = dict() (b1_size, b1_addr) = un('>HI', data[offset:offset + 6]) result['B1'] = parse_structure_array(data, b1_addr, b1_size) result['B2'] = parse_d(data, offset + 6) result['B3'] = un('>h', data[offset + 19:offset + 21])[0] result['B4'] = ''.join((x.decode('ascii') for x in parse_array(data, offset + 21, 'c', 5))) result['B5'] = un('>Q', data[offset + 26:offset + 34])[0] (b6_size, b6_addr) = un('>HI', data[offset + 34:offset + 40]) result['B6'] = parse_array(data, b6_addr, 'h', b6_size) result['B7'] = parse_array(data, offset + 40, 'f', 2) result['B8'] = un('>i', data[offset + 48:offset + 52])[0] return result def parse_a(data, offset): result = dict() result['A1'] = un('>i', data[offset:offset + 4])[0] result['A2'] = un('>b', data[offset + 4:offset + 5])[0] result['A3'] = parse_b(data, struct.unpack('>I', data[offset + 5:offset + 9])[0]) result['A4'] = un('>Q', data[offset + 9:offset + 17])[0] result['A5'] = parse_array(data, offset + 17, 'q', 2) return result def main(data): return parse_a(data, 4)" "import struct def main(data): ans = {'A1': 0, 'A2': {'B1': [{'C1': 0, 'C2': 0, 'C3': 0}, {'C1': 0.0, 'C2': -0, 'C3': 0}, {'C1': -0.0, 'C2': -0, 'C3': 0}, {'C1': 0.0, 'C2': -0, 'C3': -0}, {'C1': 0.0, 'C2': -0, 'C3': 0}], 'B2': '', 'B3': [0, 0], 'B4': 0, 'B5': 0, 'B6': 0, 'B7': {'D1': 0, 'D2': 0, 'D3': -0, 'D4': [-0.0, 0.0], 'D5': 0}, 'B8': 0}, 'A3': 0} data1 = data[5:] a = 14 b = 33 c = 16 d = 33 offset = 5 a_str = data1[0:a] a_str = struct.unpack('>QIh', a_str) ans['A1'] = a_str[0] ans['A3'] = a_str[-1] b_adress = a_str[1] b_str = data1[b_adress - offset:b_adress - offset + b] b_str = struct.unpack('>HHccccIHbIqHI', b_str) c_array_size = b_str[0] c_array_adress = b_str[1] c_array = data1[c_array_adress - offset:c_array_adress - offset + c_array_size * c] c_array = struct.unpack(f"">{c_array_size * 'fiq'}"", c_array) c_list = [] for i in range(2, len(c_array), 3): c_list.append({'C1': c_array[i - 2], 'C2': c_array[i - 1], 'C3': c_array[i]}) ans['A2']['B1'] = c_list ans['A2']['B2'] = (b_str[2] + b_str[3] + b_str[4] + b_str[5]).decode('utf-8') b3_size = b_str[6] b3_adress = b_str[7] b3_str = data1[b3_adress - offset:b3_adress - offset + b3_size * 4] b3_str = struct.unpack(f'>{b3_size}I', b3_str) ans['A2']['B3'] = list(b3_str) ans['A2']['B4'] = b_str[8] ans['A2']['B5'] = b_str[9] ans['A2']['B6'] = b_str[10] d_adress = b_str[11] d_str = data1[d_adress - offset:d_adress - offset + d] d_str = struct.unpack('>qbiddI', d_str) ans['A2']['B7']['D1'] = d_str[0] ans['A2']['B7']['D2'] = d_str[1] ans['A2']['B7']['D3'] = d_str[2] ans['A2']['B7']['D4'] = [d_str[3], d_str[4]] ans['A2']['B7']['D5'] = d_str[5] ans['A2']['B8'] = b_str[-1] return ans" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): E1 = [] for i in range(4): (E, ofs) = parse('uint16', data, ofs) E1.append(E) (E2, ofs) = parse('int8', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('uint64', data, ofs) (F2, ofs) = parse('int16', data, ofs) (F3, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2, F3=F3), ofs) def struct_C(data, ofs): (C1_adr, ofs) = parse('uint32', data, ofs) (C1, lop) = struct_D(data, C1_adr) (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint32', data, ofs) C2 = [] for i in range(C2_size): (v, C2_adr) = struct_E(data, C2_adr) C2.append(v) (C3, ofs) = parse('uint32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) (B2, ofs) = parse('int8', data, ofs) (B3, ofs) = parse('uint8', data, ofs) (B4, ofs) = parse('uint32', data, ofs) (B5, ofs) = parse('int64', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) (D2, ofs) = parse('int32', data, ofs) (D3, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def parse_main(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = struct_C(data, ofs) (A3, ofs) = struct_F(data, ofs) A4 = '' for i in range(7): (g, ofs) = parse('char', data, ofs) A4 += g.decode() A5 = [] for i in range(5): (g, ofs) = parse('uint8', data, ofs) A5.append(g) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5) def main(data): return parse_main(data, 5)" "from struct import calcsize, unpack from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack(f'<{pattern}', self.source[self.offset:self.offset + size]) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_uint16() d2 = reader.read_uint64() return dict(D1=d1, D2=d2) def read_c(reader: BinaryReader): c1 = reader.read_double() c2 = reader.read_int64() return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): x = '' for i in range(8): x += reader.read_char().decode('ascii') b1 = x b2 = reader.read_int64() b3 = read_c(reader) b4 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_uint64(), structure_size=8) b5 = reader.read_int32() b6 = reader.read_int64() return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6) def read_a(reader: BinaryReader): a1 = reader.read_uint16() a2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=50) a3 = read_d(reader) a4 = [reader.read_int32(), reader.read_int32()] return dict(A1=a1, A2=a2, A3=a3, A4=a4) def main(source): reader = BinaryReader(source) reader.read('ccc') return read_a(reader)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [a2] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'A1': struct_b(a1), 'A2': a2} def struct_b(offset: int) -> dict: le = 2 + 5 * 4 + 1 b1 = [struct_c(offset + i * le) for i in range(3)] offset += (2 + 5 * 4 + 1) * 3 [b2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [b3] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 b4 = struct_d(offset) offset += 6 + 6 + 2 + 4 + 4 [b5] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 c2 = list(struct.unpack('< 5I', binary[offset:offset + 5 * 4])) offset += 5 * 4 [c3] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(offset: int) -> dict: [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 d1 = list(struct.unpack('< ' + str(length1) + 'q', binary[link_str:link_str + length1 * 8])) [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 d2 = list(struct.unpack('< ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) [d3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d4] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [d5] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} return struct_a(5)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int16') (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint16') (a4, a4_offs) = parse_b(buf, a4_offs) (a5, offs) = parse(buf, offs, 'int8') (a6, offs) = parse(buf, offs, 'double') (a7_offs, offs) = parse(buf, offs, 'uint16') (a7, a7_offs) = parse_d(buf, a7_offs) (a8, offs) = parse_f(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') b2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int16') b2.append(val) b3 = [] for _ in range(2): (b3_offs, offs) = parse(buf, offs, 'uint16') (val, b3_offs) = parse_c(buf, b3_offs) b3.append(val) (b4, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint16') (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): d1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint64') (d3, offs) = parse_e(buf, offs) (d4, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint8') (e2, offs) = parse(buf, offs, 'int64') e3 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint16') e3.append(val) (e4, offs) = parse(buf, offs, 'int32') (e5, offs) = parse(buf, offs, 'float') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'double') (f2, offs) = parse(buf, offs, 'uint64') (f3, offs) = parse(buf, offs, 'uint16') (f4, offs) = parse(buf, offs, 'uint16') (f5, offs) = parse(buf, offs, 'int64') return (dict(F1=f1, F2=f2, F3=f3, F4=f4, F5=f5), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = unpack('>H', buf[offs:offs + 2])[0] (a2, offs) = parse_b(buf, offs + 2) offs += 4 a3 = unpack('>f', buf[offs + 4:offs + 8])[0] offs += 8 f4 = unpack('>II', buf[offs:offs + 8]) for i in range(f4[0]): a4 = ''.join(map(str, unpack(f'>{f4[0]}c', buf[f4[1]:f4[1] + 2]))) a4 = a4.replace(""'b"", '', 1) a4 = a4.replace(""'"", '') a4 = a4.replace('b', '', 1) (a5, offs) = parse_d(buf, offs) a6 = unpack('>Q', buf[offs:offs + 8])[0] return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): b1 = unpack('>i', buf[offs:offs + 4])[0] offs += 4 b2 = unpack('>B', buf[offs:offs + 1])[0] offs += 1 b3 = ' '.join(map(str, unpack('>5c', buf[offs:offs + 5]))) offs += 5 b3 = b3.replace(""' "", '') b3 = b3.replace(""b'"", '') b3 = b3.replace(""'"", '') f1 = unpack('>II', buf[offs:offs + 8]) b4 = list() for i in range(f1[0]): f2 = unpack('>H', buf[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) b4.append(parse_c(buf, f2[0])) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): c1 = unpack('>b', buf[offs:offs + 1])[0] c2 = unpack('>d', buf[offs + 1:offs + 9])[0] c3 = unpack('>b', buf[offs + 9:offs + 10])[0] return dict(C1=c1, C2=c2, C3=c3) def parse_d(buf, offs): offs += 8 d1 = unpack('>Q', buf[offs:offs + 8])[0] f2 = unpack('>IH', buf[offs + 8:offs + 14]) d2 = list(unpack(f'>{f2[0]}B', buf[f2[1]:f2[1] + f2[0] + 7])) d3 = unpack('>I', buf[offs + 14:offs + 18])[0] d4 = list(unpack('>7h', buf[offs + 18:offs + 32])) d5 = unpack('>I', buf[offs + 32:offs + 36])[0] d6 = unpack('>f', buf[offs + 36:offs + 40])[0] d7 = unpack('>h', buf[offs + 40:offs + 42])[0] d8 = unpack('>Q', buf[offs + 42:offs + 50])[0] offs += 50 return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct import pprint def parse_g(data, pointer): (g1, g2, g3) = struct.unpack('>fqq', data[pointer:pointer + 20]) g4 = list(struct.unpack('>2B', data[pointer + 20:pointer + 22])) return {'G1': g1, 'G2': g2, 'G3': g3, 'G4': g4} def parse_f(data, pointer): ff1 = struct.unpack('>II', data[pointer:pointer + 8]) f1 = list(struct.unpack(f'>{ff1[0]}H', data[ff1[1]:ff1[1] + ff1[0] * 2])) f2 = struct.unpack('>H', data[pointer + 8:pointer + 10])[0] return {'F1': f1, 'F2': f2} def parse_e(data, pointer): (e1, e2, e3) = struct.unpack('>dbI', data[pointer:pointer + 13]) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack('>bHBQ', data[pointer:pointer + 12]) f5 = struct.unpack('>HI', data[pointer + 12:pointer + 18]) d5 = ''.join(map(str, struct.unpack(f'>{f5[0]}c', data[f5[1]:f5[1] + f5[0]]))) d5 = d5.replace(""'"", '')[1::2] f6 = struct.unpack('>H', data[pointer + 18:pointer + 20]) d6 = parse_e(data, f6[0]) f7 = struct.unpack('>II', data[pointer + 20:pointer + 28]) d7 = list() for i in range(f7[0]): f77 = struct.unpack('>H', data[f7[1] + i * 2:f7[1] + 2 + i * 2]) d7.append(parse_f(data, f77[0])) d8 = struct.unpack('>H', data[pointer + 28:pointer + 30])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def parse_c(data, pointer): (c1, c2) = struct.unpack('>fH', data[pointer:pointer + 6]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2, b3, b4, b5, b6) = struct.unpack('>QbfdQq', data[pointer:pointer + 37]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) a1 = parse_b(data, f1[0]) a2 = parse_c(data, pointer + 2) (a3, a4, a5) = struct.unpack('>qHh', data[pointer + 8:pointer + 20]) (f6, f7) = struct.unpack('>HH', data[pointer + 20:pointer + 24]) a6 = parse_d(data, f6) a7 = parse_g(data, f7) a8 = struct.unpack('>B', data[pointer + 24:pointer + 25])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 3)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) a2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') a2.append(val.decode()) a3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') a3.append(val) (a4, offs) = parse(buf, offs, 'uint8') (a5_offs, offs) = parse(buf, offs, 'uint16') (a5, a5_offs) = parse_d(buf, a5_offs) (a6, offs) = parse(buf, offs, 'uint64') (a7, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse_c(buf, offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'int16') c3 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint8') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int8', data, ofs) (E2, ofs) = parse('int32', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('int64', data, ofs) C2 = '' for i in range(2): (v, ofs) = parse('char', data, ofs) C2 += v.decode() return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1_adr, ofs) = parse('uint32', data, ofs) (B1, lop) = struct_C(data, B1_adr) (B2, ofs) = parse('uint32', data, ofs) (B3, ofs) = parse('double', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_D(data, ofs): (D1_size, ofs) = parse('uint32', data, ofs) (D1_adr, ofs) = parse('uint16', data, ofs) D1 = [] for i in range(D1_size): (adr, D1_adr) = parse('uint16', data, D1_adr) (r, lop) = struct_E(data, adr) D1.append(r) (D2, ofs) = parse('int16', data, ofs) (D3, ofs) = parse('int8', data, ofs) (D4, ofs) = parse('uint8', data, ofs) D5 = [] for _ in range(8): (r, ofs) = parse('uint16', data, ofs) D5.append(r) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def parse_main(data, ofs): (A1, ofs) = parse('float', data, ofs) (A2, ofs) = parse('int64', data, ofs) (A3_adr, ofs) = parse('uint16', data, ofs) (A3, lop) = struct_B(data, A3_adr) (A4, ofs) = parse('uint64', data, ofs) (A5, ofs) = parse('int64', data, ofs) (A6, ofs) = struct_D(data, ofs) A7 = [] for i in range(5): (g, ofs) = parse('uint16', data, ofs) A7.append(g) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7) def main(data): return parse_main(data, 5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getB(data, iterator) (A['A2'], iterator) = getNext(data, iterator, 2, '{length}s')[0] B['B1'] = B['B1'].decode('ascii') (B['B2'], iterator) = getNext(data, iterator, 4, 'HI', data[pointer:pointer + 6]) f2 = struct.unpack('>II', data[pointer + 6:pointer + 14]) e1 = list(struct.unpack(f'>{f1[0]}b', data[f1[1]:f1[1] + f1[0]])) e2 = list(struct.unpack(f'>{f2[0]}b', data[f2[1]:f2[1] + f2[0]])) (e3, e4, e5) = struct.unpack('>qIB', data[pointer + 14:pointer + 27]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def parse_d(data, pointer): d1 = struct.unpack('>b', data[pointer:pointer + 1])[0] f2 = struct.unpack('>2H', data[pointer + 1:pointer + 5]) d2 = list() d2.append(parse_e(data, f2[0])) d2.append(parse_e(data, f2[1])) d3 = struct.unpack('>H', data[pointer + 5:pointer + 7])[0] return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2) = struct.unpack('>Hd', data[pointer:pointer + 10]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>iQb', data[pointer:pointer + 13]) b4 = parse_c(data, pointer + 13) b5 = struct.unpack('>Q', data[pointer + 23:pointer + 31])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_a(data, pointer): (a1, a2) = struct.unpack('>iq', data[pointer:pointer + 12]) f3 = struct.unpack('>HH', data[pointer + 12:pointer + 16]) a3 = ''.join(map(str, struct.unpack(f'>{f3[0]}c', data[f3[1]:f3[1] + f3[0]]))) a3 = a3.replace(""'"", '')[1::2] a4 = struct.unpack('>H', data[pointer + 16:pointer + 18])[0] (f5, f6) = struct.unpack('>HH', data[pointer + 18:pointer + 22]) a5 = parse_b(data, f5) a6 = parse_d(data, f6) a7 = list(struct.unpack('>8h', data[pointer + 22:pointer + 38])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('<2h', data[pointer:pointer + 4])) d2 = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['E2'] = parse_array(data, offset + 1, 2, 'h') result['E3'] = struct.unpack('>B', data[offset + 5:offset + 5 + 1])[0] result['E4'] = struct.unpack('>d', data[offset + 6:offset + 14])[0] result['E5'] = struct.unpack('>q', data[offset + 14:offset + 22])[0] return result def parse_d(data, offset): result = dict() f1_addr = struct.unpack('>I', data[offset:offset + 4])[0] result['D1'] = parse_e(data, f1_addr) (f2_size, f2_addr) = struct.unpack('>II', data[offset + 4:offset + 12]) result['D2'] = parse_array(data, f2_addr, f2_size, 'b') result['D3'] = struct.unpack('>Q', data[offset + 12:offset + 20])[0] result['D4'] = struct.unpack('>i', data[offset + 20:offset + 24])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>B', data[offset + 2:offset + 3])[0] result['C3'] = struct.unpack('>f', data[offset + 3:offset + 7])[0] result['C4'] = struct.unpack('>f', data[offset + 7:offset + 11])[0] return result def parse_b(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack('>II', data[offset:offset + 8]) f1_arr = parse_array(data, f1_addr, f1_size, 'I') f1 = list() for addr in f1_arr: f1.append(parse_c(data, addr)) result['B1'] = f1 result['B2'] = struct.unpack('>i', data[offset + 8:offset + 12])[0] result['B3'] = struct.unpack('>H', data[offset + 12:offset + 14])[0] f4_addr = struct.unpack('>I', data[offset + 14:offset + 18])[0] result['B4'] = parse_d(data, f4_addr) result['B5'] = struct.unpack('>f', data[offset + 18:offset + 22])[0] result['B6'] = struct.unpack('>i', data[offset + 22:offset + 26])[0] result['B7'] = struct.unpack('>I', data[offset + 26:offset + 30])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>f', data[offset:offset + 4])[0] result['A2'] = parse_b(data, offset + 4) result['A3'] = struct.unpack('>q', data[offset + 34:offset + 42])[0] (f4_size, f4_addr) = struct.unpack('>IH', data[offset + 42:offset + 48]) result['A4'] = parse_array(data, f4_addr, f4_size, 'H') result['A5'] = struct.unpack('>Q', data[offset + 48:offset + 56])[0] return result def main(data): return parse_a(data, 5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (temp, iterator) = getNext(data, iterator, 2, '>H') A['A1'] = getB(data, temp)[0] (A['A2'], iterator) = getD(data, iterator) return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNextArr(data, iterator, 4 * 8, '>8f') B['B2'] = [] for i in range(2): (b, iterator) = getC(data, iterator) B['B2'].append(b) (B['B3'], iterator) = getNext(data, iterator, 4, '>f') return (B, iterator) def getC(data, iterator): C = {} (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') C['C1'] = getNextArr(data, temp, length * 4, f'>{length}i')[0] (C['C2'], iterator) = getNext(data, iterator, 4, '>I') (C['C3'], iterator) = getNextArr(data, iterator, 4 * 4, '>4I') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 4, '>f') (D['D2'], iterator) = getNext(data, iterator, 4, '>f') (D['D3'], iterator) = getNext(data, iterator, 8, '>Q') return (D, iterator) def main(data): return getA(data, 4)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('HdidIb', data[4:31]) current = 31 A = {'A1': var[0], 'A2': var[1], 'A3': var[2], 'A4': var[3], 'A5': var[4], 'A6': var[5]} current = var[0] var = struct.unpack('>Bhq', data[current:current + 11]) current += 11 A['A1'] = {'B1': var[0], 'B2': var[1], 'B3': var[2], 'B4': [], 'B5': [], 'B6': 0, 'B7': []} for i in range(8): var = struct.unpack('>i', data[current + i * 8:current + 4 + i * 8]) C = {'C1': var[0]} var = struct.unpack('>hh', data[current + 4 + i * 8:current + 8 + i * 8]) C.update({'C2': [var[0], var[1]]}) A['A1']['B4'].append(C) current += 64 var = struct.unpack('>HL', data[current:current + 6]) current += 6 addr = var[1] for i in range(var[0]): var = struct.unpack('>B', data[addr + i:addr + i + 1]) A['A1']['B5'].append(var[0]) var = struct.unpack('>HLH', data[current:current + 8]) current += 8 A['A1']['B6'] = var[0] addr = var[2] for i in range(var[1]): var = struct.unpack('>B', data[addr + i:addr + i + 1]) A['A1']['B7'].append(var[0]) current = A['A5'] var = struct.unpack('>LHLqBhQ', data[current:current + 29]) D = {'D1': var[0], 'D2': [], 'D3': var[3], 'D4': var[4], 'D5': var[5], 'D6': var[6]} addr = var[2] for i in range(var[1]): var = struct.unpack('>i', data[addr + i * 4:addr + i * 4 + 4]) D['D2'].append(var[0]) A['A5'] = D return A" "import struct def main(binary: bytes) -> dict: def struct_a(index: int) -> dict: (size, address) = struct.unpack('> H H', binary[index:index + 4]) a1 = ''.join([chr(i) for i in binary[address:address + size]]) index += 4 a2 = list(struct.unpack('> 3H', binary[index:index + 6])) index += 6 (s, add) = struct.unpack('> I I', binary[index:index + 8]) a3 = list(struct.unpack('>' + str(s) + 'h', binary[add:add + 2 * s])) index += 8 [a4] = struct.unpack('> I', binary[index:index + 4]) index += 4 return {'A1': a1, 'A2': [struct_b(i) for i in a2], 'A3': a3, 'A4': struct_e(a4)} def struct_b(index: int) -> dict: b1 = struct_c(index) index += 8 b2 = struct_d(index) index += 9 [b3] = struct.unpack('> q', binary[index:index + 8]) index += 8 [b4] = struct.unpack('> H', binary[index:index + 2]) index += 2 (s, add) = struct.unpack('> I H', binary[index:index + 6]) b5 = list(struct.unpack('>' + str(s) + 'i', binary[add:add + 4 * s])) index += 6 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(index: int) -> dict: [c1] = struct.unpack('> f', binary[index:index + 4]) index += 4 [c2] = struct.unpack('> I', binary[index:index + 4]) index += 4 return {'C1': c1, 'C2': c2} def struct_d(index: int) -> dict: [d1] = struct.unpack('> d', binary[index:index + 8]) index += 8 [d2] = struct.unpack('> B', binary[index:index + 1]) index += 1 return {'D1': d1, 'D2': d2} def struct_e(index: int) -> dict: e1 = list(struct.unpack('> 3b', binary[index:index + 3])) index += 3 [e2] = struct.unpack('> f', binary[index:index + 4]) index += 4 [e3] = struct.unpack('> B', binary[index:index + 1]) index += 1 return {'E1': e1, 'E2': e2, 'E3': e3} return struct_a(4)" "import struct def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack('B') (A['A2'], iterator) = getNext(data, iterator, 4, '>i') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A3'] = getNext(data, temp, length, f'>{length}s')[0] A['A3'] = A['A3'].decode('ascii') (A['A4'], iterator) = getNext(data, iterator, 4, '>i') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A5'] = [] for i in range(length): (b, temp) = getNext(data, temp, 4, '>I') c = getB(data, b)[0] A['A5'].append(c) (A['A6'], iterator) = getNextArr(data, iterator, 4 * 5, '>5i') (A['A7'], iterator) = getD(data, iterator) (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A8'] = getNextArr(data, temp, length * 8, f'>{length}d')[0] return A def getB(data, iterator): B = {} (temp, iterator) = getNext(data, iterator, 4, '>I') B['B1'] = getC(data, temp)[0] (B['B2'], iterator) = getNext(data, iterator, 8, '>Q') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 8, '>d') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') C['C2'] = getNextArr(data, temp, length, f'>{length}b')[0] return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 2, '>H') (D['D2'], iterator) = getNext(data, iterator, 2, '>h') (D['D3'], iterator) = getNext(data, iterator, 4, '>i') return (D, iterator) def main(data): return getA(data, 4)" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('>Q', bytes, 4)[0] dict['A2'] = struct.unpack_from('>f', bytes, 12)[0] dict['A3'] = struct.unpack_from('>I', bytes, 16)[0] dict['A4'] = struct.unpack_from('>8s', bytes, 20)[0].decode() dictB = {} dict['A5'] = dictB address_B = struct.unpack_from('>i', bytes, 28)[0] dictB['B1'] = struct.unpack_from('>f', bytes, address_B)[0] dictB['B2'] = [] for i in range(3): dictC = {} dictB['B2'].append(dictC) address_C = struct.unpack_from('>H', bytes, address_B + 4 + 2 * i)[0] dictC['C1'] = struct.unpack_from('>Q', bytes, address_C)[0] dictC['C2'] = struct.unpack_from('>d', bytes, address_C + 8)[0] dictC['C3'] = [] for j in range(2): dictC['C3'].append(struct.unpack_from('>h', bytes, address_C + 16 + 2 * j)[0]) dictD = {} dictB['B3'] = dictD dictD['D1'] = [] address_D = struct.unpack_from('>H', bytes, address_B + 10)[0] for i in range(7): dictD['D1'].append(struct.unpack_from('>i', bytes, address_D + 4 * i)[0]) dictD['D2'] = struct.unpack_from('>Q', bytes, address_D + 28)[0] dictD['D3'] = struct.unpack_from('>I', bytes, address_D + 36)[0] dict['A6'] = struct.unpack_from('>h', bytes, 32)[0] return dict" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 1 * 2, '<2s') A['A1'] = A['A1'].decode('ascii') (A['A2'], iterator) = getNext(data, iterator, 1, 'b', data[pointer:pointer + 1])[0] d2 = list(struct.unpack('>3Q', data[pointer + 1:pointer + 25])) d3 = struct.unpack('>Q', data[pointer + 25:pointer + 33])[0] return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>IIhI', data[pointer:pointer + 14]) c5 = list(struct.unpack('>4I', data[pointer + 14:pointer + 30])) c6 = struct.unpack('>b', data[pointer + 30:pointer + 31])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) b1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + i * 2:f1[1] + 2 + i * 2]) b1.append(parse_c(data, f11[0])) b2 = parse_d(data, pointer + 6) b3 = list(struct.unpack('>4d', data[pointer + 39:pointer + 71])) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): a1 = struct.unpack('>h', data[pointer:pointer + 2])[0] a2 = ''.join(map(str, struct.unpack('>7c', data[pointer + 2:pointer + 9]))) a2 = a2.replace(""'"", '')[1::2] a3 = parse_b(data, pointer + 9) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): d1 = ''.join(map(str, struct.unpack('<2c', data[pointer:pointer + 2]))) d1 = d1.replace(""'"", '')[1::2] (d2, d3, d4, d5, d6) = struct.unpack('qHbI', data[pointer:pointer + 15]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def parse_d(data, pointer): (d1, d2) = struct.unpack('>iH', data[pointer:pointer + 6]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) c1 = list() for i in range(f1[0]): c1.append(parse_d(data, f1[1] + i * 6)) (c2, c3) = struct.unpack('>bh', data[pointer + 4:pointer + 7]) c4 = list(struct.unpack('>4I', data[pointer + 7:pointer + 23])) c5 = list(struct.unpack('>5f', data[pointer + 23:pointer + 43])) (c6, c7) = struct.unpack('>bh', data[pointer + 43:pointer + 46]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def parse_b(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) b1 = parse_c(data, f1[0]) f2 = struct.unpack('>IH', data[pointer + 2:pointer + 8]) b2 = list(struct.unpack(f'>{f2[0]}B', data[f2[1]:f2[1] + f2[0]])) return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = struct.unpack('>d', data[pointer:pointer + 8])[0] f2 = struct.unpack('>I', data[pointer + 8:pointer + 12]) a2 = parse_b(data, f2[0]) (a3, a4) = struct.unpack('>qB', data[pointer + 12:pointer + 21]) a5 = parse_e(data, pointer + 21) f6 = struct.unpack('>HH', data[pointer + 36:pointer + 40]) a6 = list(struct.unpack(f'>{f6[0]}B', data[f6[1]:f6[1] + f6[0]])) a7 = struct.unpack('>H', data[pointer + 40:pointer + 42])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 5)" "from typing import Any, Callable from struct import * class BinaryReader: def get_offset(self): return self.offset def set_specoffset(self, offset): self.specoffset = offset def __init__(self, source, offset=0): self.offset = offset self.source = source self.specoffset = 0 def read_uint64(self): return self.read('>Q') def read_int64(self): return self.read('>q') def read_uint32(self): return self.read('>I') def read_int32(self): return self.read('>i') def read_uint16(self): return self.read('>H') def read_int16(self): return self.read('>h') def read_uint8(self): return self.read('>B') def read_int8(self): return self.read('>b') def read_float(self): return self.read('>f') def read_char(self): return self.read('>c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_by_adress(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.specoffset) self.specoffset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) values = [] for i in range(size): values.append(read(reader)) if i == 10: break return values def read_d(reader: BinaryReader, offset): reader.set_specoffset(offset) d1 = reader.read_by_adress('>q') d2 = read_array(source=reader.source, size=reader.read_by_adress('>I'), address=reader.read_by_adress('>I'), read=lambda reader: reader.read_int32()) return dict(D1=d1, D2=d2) def read_c(reader: BinaryReader): f1 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_uint32()) c1 = list() for i in range(len(f1)): temp = read_d(reader, f1[i]) c1.append(temp) c2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_int64()) c3 = reader.read_uint32() return dict(C1=c1, C2=c2, C3=c3) def read_b(reader: BinaryReader): b1 = reader.read_int8() b2 = reader.read_int32() b3 = reader.read_int64() b4 = read_c(reader) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_a(reader: BinaryReader): a1 = read_b(reader) a2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_int8()) a3 = reader.read_uint32() return dict(A1=a1, A2=a2, A3=a3) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '<' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): value = self.read(_pattern) res.append(value) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): sizeb1 = reader.read(Types.uint16) adressb1 = reader.read(Types.uint16) b1 = [] adressReader = BinaryReader(offset=adressb1, buffer=reader.buffer) for i in range(0, sizeb1): innerAddress = adressReader.read(Types.uint16) innerReader = BinaryReader(offset=innerAddress, buffer=reader.buffer) c = readC(innerReader) b1.append(c) b2 = reader.read(Types.double) b3 = reader.read(Types.int16) b4 = reader.read(Types.int8) b5 = readD(reader) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5) def readC(reader): c1 = reader.read(Types.uint16) c2 = reader.read(Types.int32) c3 = reader.read(Types.int16) c4 = reader.read(Types.uint16) return dict(C1=c1, C2=c2, C3=c3, C4=c4) def readD(reader): d1 = reader.read(Types.float) sized2 = reader.read(Types.uint32) adressd2 = reader.read(Types.uint16) d2 = reader.copy(offset=adressd2).readWithSize(Types.uint16, sized2) d3 = reader.readWithSize(Types.uint8, 5) d4 = reader.read(Types.uint16) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def readE(reader): e1 = reader.read(Types.int32) e2 = reader.read(Types.int8) e3 = reader.read(Types.uint16) return dict(E1=e1, E2=e2, E3=e3) def readF(reader): f1 = reader.read(Types.uint16) f2 = reader.read(Types.float) f3 = reader.read(Types.uint64) return dict(F1=f1, F2=f2, F3=f3) def main(buffer): reader = BinaryReader(offset=3, buffer=buffer) a1 = reader.readWithSize(Types.int32, 7) a2 = readB(BinaryReader(offset=reader.read(Types.uint32), buffer=buffer)) a3 = reader.read(Types.uint64) a4 = readE(BinaryReader(offset=reader.read(Types.uint32), buffer=buffer)) a5 = reader.read(Types.int8) a6 = readF(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "from enum import Enum from struct import unpack_from, calcsize class BinaryReader: def __init__(self, offset, foxUwU): self.offset = offset self.foxUwU = foxUwU def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.foxUwU, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.foxUwU, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.foxUwU) class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' def main(foxUwU): reader = BinaryReader(offset=4, foxUwU=foxUwU) a11 = b(reader.copy(reader.read(Types.uint32))) a12 = b(reader.copy(reader.read(Types.uint32))) a1 = [a11, a12] a2 = reader.read(Types.int16) h = 0 a3 = c(BinaryReader(offset=reader.read(Types.uint16), foxUwU=foxUwU)) a4 = reader.read(Types.double) return dict(A1=a1, A2=a2, A3=a3, A4=a4) def b(reader: BinaryReader): b1 = reader.read(Types.int64) b2 = reader.read(Types.uint8) return dict(B1=b1, B2=b2) def c(reader: BinaryReader): c1 = reader.read(Types.uint64) c2 = reader.read(Types.uint8) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint16) tempC3 = reader.copy(offset=adress3).readWithSize(Types.char, size3) c3 = b''.join(tempC3).decode('ASCII') c4 = reader.read(Types.int64) c5 = reader.read(Types.double) c6 = reader.readWithSize(Types.uint64, 3) c7 = d(reader) c8 = reader.read(Types.int16) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8) def d(reader: BinaryReader): d1 = reader.read(Types.int8) d2 = reader.read(Types.float) d3 = reader.read(Types.uint8) d4 = reader.read(Types.uint32) d5 = reader.read(Types.int16) d6 = reader.readWithSize(Types.uint16, 2) d7 = reader.readWithSize(Types.uint64, 2) d8 = reader.read(Types.int16) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8)" "from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 27 return result def parse_d(data, offset): result = dict() (d1_size, d1_addr) = un('>HI', data[offset:offset + 6]) result['D1'] = parse_array(data, d1_addr, 'f', d1_size) result['D2'] = un('>d', data[offset + 6:offset + 14])[0] result['D3'] = un('>H', data[offset + 14:offset + 16])[0] result['D4'] = un('>i', data[offset + 16:offset + 20])[0] result['D5'] = un('>q', data[offset + 20:offset + 28])[0] result['D6'] = parse_array(data, offset + 28, 'q', 2) return result def parse_c(data, offset): result = dict() result['C1'] = un('>i', data[offset:offset + 4])[0] result['C2'] = parse_d(data, un('>I', data[offset + 4:offset + 8])[0]) (c3_size, c3_addr) = un('>HH', data[offset + 8:offset + 12]) result['C3'] = parse_array(data, c3_addr, 'B', c3_size) return result def parse_b(data, offset): result = dict() result['B1'] = un('>d', data[offset:offset + 8])[0] result['B2'] = un('>d', data[offset + 8:offset + 16])[0] return result def parse_a(data, offset): result = dict() result['A1'] = un('>Q', data[offset:offset + 8])[0] (f1_size, f1_addr) = un('>HI', data[offset + 8:offset + 14]) f1_arr = parse_array(data, f1_addr, 'I', f1_size) f1 = list() for addr in f1_arr: f1.append(parse_b(data, addr)) result['A2'] = f1 result['A3'] = un('>q', data[offset + 14:offset + 22])[0] result['A4'] = parse_c(data, un('>H', data[offset + 22:offset + 24])[0]) return result def main(data): return parse_a(data, 5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 4, '>i') (A['A2'], iterator) = getNext(data, iterator, 4, '>i') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A3'] = [] for i in range(length): (b, temp) = getNext(data, temp, 2, '>H') c = getB(data, b)[0] A['A3'].append(c) (length, iterator) = getNext(data, iterator, 2, '>H') (tem, iterator) = getNext(data, iterator, 4, '>I') A['A4'] = [] for i in range(length): (b, tem) = getNext(data, tem, 4, '>I') d = getC(data, b)[0] A['A4'].append(d) (A['A5'], iterator) = getD(data, iterator) return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 4, '>I') (B['B2'], iterator) = getNext(data, iterator, 8, '>Q') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') B['B3'] = getNext(data, temp, length, f'>{length}s')[0] B['B3'] = B['B3'].decode('ascii') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 2, '>h') (C['C2'], iterator) = getNext(data, iterator, 8, '>d') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 8, '>q') (D['D2'], iterator) = getNext(data, iterator, 2, '>h') (D['D3'], iterator) = getNext(data, iterator, 2, '>H') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') D['D4'] = getNextArr(data, temp, length * 2, f'>{length}h')[0] (D['D5'], iterator) = getNext(data, iterator, 4, '>f') (D['D6'], iterator) = getNext(data, iterator, 8, '>Q') (D['D7'], iterator) = getNext(data, iterator, 8, '>Q') (D['D8'], iterator) = getNext(data, iterator, 4, '>I') return (D, iterator) def main(data): return getA(data, 4)" "import struct def main(data): A = struct.unpack_from('>IH3f', data, offset=4) B = struct.unpack_from('>2HiIHQdqBdHIq2fqi', data, offset=A[1]) B1 = struct.unpack_from('>' + B[0] * 'Bf2H', data, offset=B[1]) B3 = list(struct.unpack_from('>' + str(B[3]) + 'h', data, offset=B[4])) C_list = [] for i in range(B[0]): C3 = list(struct.unpack_from('>' + str(B1[i * 4 + 2]) + 'b', data, offset=B1[i * 4 + 3])) C_list.append({'C1': B1[i * 4], 'C2': B1[i * 4 + 1], 'C3': C3}) D5 = list(struct.unpack_from('>' + str(B[10]) + 'H', data, offset=B[11])) return {'A1': A[0], 'A2': {'B1': C_list, 'B2': B[2], 'B3': B3, 'B4': B[5], 'B5': {'D1': B[6], 'D2': B[7], 'D3': B[8], 'D4': B[9], 'D5': D5, 'D6': B[12], 'D7': B[13]}, 'B6': B[14], 'B7': B[15], 'B8': B[16]}, 'A3': A[2], 'A4': A[3], 'A5': A[4]}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint8', data, ofs) (E2, ofs) = parse('int8', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('double', data, ofs) (C2, ofs) = parse('int16', data, ofs) (C3, ofs) = parse('uint16', data, ofs) (C4, ofs) = parse('uint64', data, ofs) (C5_adr, ofs) = parse('uint32', data, ofs) (C5, lop) = struct_D(data, C5_adr) (C6, ofs) = parse('uint64', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6), ofs) def struct_B(data, ofs): (B1, ofs) = parse('double', data, ofs) (B2, ofs) = struct_C(data, ofs) (B3, ofs) = parse('int64', data, ofs) (B4_size, ofs) = parse('uint32', data, ofs) (B4_adr, ofs) = parse('uint16', data, ofs) B4 = [] for i in range(B4_size): (E, B4_adr) = struct_E(data, B4_adr) B4.append(E) (B5, ofs) = parse('uint16', data, ofs) B6 = [] for i in range(2): (lop, ofs) = parse('uint64', data, ofs) B6.append(lop) (B7, ofs) = parse('double', data, ofs) (B8, ofs) = parse('int16', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6, B7=B7, B8=B8), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int16', data, ofs) (D2, ofs) = parse('uint8', data, ofs) (D3, ofs) = parse('uint64', data, ofs) D4 = [] for _ in range(7): (r, ofs) = parse('uint64', data, ofs) D4.append(r) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def parse_main(data, ofs): (A1, ofs) = parse('uint16', data, ofs) (A2, ofs) = parse('uint8', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) (A3, lop) = struct_B(data, A3_adr) (A4, ofs) = parse('int16', data, ofs) (A5, ofs) = parse('uint8', data, ofs) A6 = [] for i in range(7): (g, ofs) = parse('uint8', data, ofs) A6.append(g) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6) def main(data): return parse_main(data, 3)" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3) = struct.unpack('HH', data[pointer:pointer + 4]) d1 = list(struct.unpack(f'>{f1[0]}h', data[f1[1]:f1[1] + f1[0] * 2])) d2 = struct.unpack('>d', data[pointer + 4:pointer + 12])[0] f3 = struct.unpack('>IH', data[pointer + 12:pointer + 18]) d3 = list(struct.unpack(f'>{f3[0]}b', data[f3[1]:f3[1] + f3[0]])) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) c1 = parse_d(data, f1[0]) c2 = struct.unpack('>d', data[pointer + 2:pointer + 10])[0] return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2) = struct.unpack('>IH', data[pointer:pointer + 6]) f3 = struct.unpack('>IH', data[pointer + 6:pointer + 12]) b3 = list() for i in range(f3[0]): b3.append(parse_c(data, f3[1] + i * 10)) (b4, b5, b6, b7, b8) = struct.unpack('>dBdbH', data[pointer + 12:pointer + 32]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def parse_a(data, pointer): a1 = struct.unpack('>h', data[pointer:pointer + 2])[0] f2 = struct.unpack('>I', data[pointer + 2:pointer + 6]) a2 = parse_b(data, f2[0]) (a3, a4, a5) = struct.unpack('>BqB', data[pointer + 6:pointer + 16]) a6 = list(struct.unpack('>5Q', data[pointer + 16:pointer + 56])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 3)" "import struct as s def main(_b): if _b[:3] != b'BWL': exit() tmp1 = 19 tmp2 = 27 sd1 = s.unpack('>i', _b[69:73])[0] d1of = s.unpack('>i', _b[73:77])[0] d3of = s.unpack('>H', _b[85:87])[0] values = '' tree = {'A1': {'B1': s.unpack('>h', _b[3:5])[0], 'B2': s.unpack('>d', _b[5:13])[0], 'B3': s.unpack('>H', _b[13:15])[0], 'B4': s.unpack('>H', _b[15:17])[0], 'B5': s.unpack('>h', _b[17:19])[0], 'B6': [{'C1': s.unpack('>d', _b[tmp1 + i * 10:tmp1 + i * 10 + 8])[0], 'C2': s.unpack('>H', _b[tmp2 + i * 10:tmp2 + i * 10 + 2])[0]} for i in range(5)]}, 'A2': {'D1': b''.join([s.unpack('>c', _b[d1of + i:d1of + i + 1])[0] for i in range(sd1)]).decode('utf-8'), 'D2': [s.unpack('>H', _b[77 + i * 2:79 + i * 2])[0] for i in range(4)], 'D3': {'E1': s.unpack('>b', _b[d3of:d3of + 1])[0], 'E2': s.unpack('>q', _b[d3of + 1:d3of + 9])[0], 'E3': s.unpack('>h', _b[d3of + 9:d3of + 11])[0], 'E4': s.unpack('>Q', _b[d3of + 11:d3of + 19])[0], 'E5': s.unpack('>q', _b[d3of + 19:d3of + 27])[0]}, 'D4': s.unpack('>b', _b[87:88])[0], 'D5': [s.unpack('>B', _b[88 + i * 1:89 + i * 1])[0] for i in range(8)], 'D6': s.unpack('>L', _b[96:100])[0], 'D7': s.unpack('>l', _b[100:104])[0], 'D8': [s.unpack('>f', _b[104 + i * 4:108 + i * 4])[0] for i in range(8)]}, 'A3': s.unpack('>b', _b[136:137])[0]} return tree" "from struct import unpack_from def main(bytes): address_b = unpack_from('H', bytes, offset=4)[0] address_e = unpack_from('H', bytes, offset=6)[0] A3 = unpack_from('B', bytes, offset=8)[0] A4 = unpack_from('h', bytes, offset=9)[0] B1 = unpack_from('q', bytes, offset=address_b)[0] size_array_char = unpack_from('I', bytes, offset=address_b + 8)[0] address_array_char = unpack_from('H', bytes, offset=address_b + 12)[0] C1 = [] for i in range(size_array_char): C1.append(unpack_from('c', bytes, offset=address_array_char + i)[0].decode()) C1 = ''.join(C1) C2 = unpack_from('H', bytes, offset=address_b + 14)[0] C3 = unpack_from('i', bytes, offset=address_b + 16)[0] addresses_d = [] for i in range(2): addresses_d.append(unpack_from('H', bytes, offset=address_b + 20 + i * 2)[0]) D = [] for address in addresses_d: D1 = unpack_from('h', bytes, offset=address)[0] size_array_int8 = unpack_from('I', bytes, offset=address + 2)[0] address_array_int8 = unpack_from('I', bytes, offset=address + 6)[0] D2 = [] for i in range(size_array_int8): D2.append(unpack_from('b', bytes, address_array_int8 + i)[0]) D3 = [] for i in range(3): D3.append(unpack_from('q', bytes, offset=address + 10 + i * 8)[0]) D4 = unpack_from('i', bytes, offset=address + 34)[0] D5 = unpack_from('H', bytes, offset=address + 38)[0] D.append({'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5}) E1 = unpack_from('b', bytes, offset=address_e)[0] E2 = unpack_from('I', bytes, offset=address_e + 1)[0] E3 = unpack_from('B', bytes, offset=address_e + 5)[0] E4 = unpack_from('B', bytes, offset=address_e + 6)[0] answer = {'A1': {'B1': B1, 'B2': {'C1': C1, 'C2': C2, 'C3': C3}, 'B3': D}, 'A2': {'E1': E1, 'E2': E2, 'E3': E3, 'E4': E4}, 'A3': A3, 'A4': A4} return answer" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint8', data, ofs) (E2, ofs) = parse('int8', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('float', data, ofs) (C2, ofs) = parse('double', data, ofs) (C3, ofs) = struct_D(data, ofs) (C4, ofs) = parse('float', data, ofs) (C5, ofs) = parse('float', data, ofs) C6 = [] for i in range(6): (C, ofs) = parse('int8', data, ofs) C6.append(C) (C7, ofs) = parse('int8', data, ofs) (C8, ofs) = parse('uint32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7, C8=C8), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint16', data, ofs) (B2, ofs) = parse('double', data, ofs) (B3, ofs) = parse('uint64', data, ofs) B4 = [] for i in range(2): (E, ofs) = struct_C(data, ofs) B4.append(E) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_D(data, ofs): (D1_size, ofs) = parse('int16', data, ofs) (D1_adr, ofs) = parse('int16', data, ofs) D1 = [] for i in range(D1_size): (hop, D1_adr) = parse('int32', data, D1_adr) D1.append(hop) (D2, ofs) = parse('uint32', data, ofs) (D3, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def parse_main(data, ofs): (A1_adr, ofs) = parse('uint32', data, ofs) (A1, pot) = struct_B(data, A1_adr) (A2_size, ofs) = parse('uint16', data, ofs) (A2_adr, ofs) = parse('uint32', data, ofs) A2 = [] for i in range(A2_size): (lop, A2_adr) = parse('int8', data, A2_adr) A2.append(lop) return dict(A1=A1, A2=A2) def main(data): return parse_main(data, 4)" "import struct def create_c_structures(data, address): result = [] for c_address in struct.unpack('>7H', data[address:address + 14]): c1 = struct.unpack('>B', data[c_address:c_address + 1])[0] c2 = list(struct.unpack('>i', data[c_address + 1:c_address + 5])) result.append({'C1': c1, 'C2': c2[0]}) return result def create_b_structures(data, address): result = [] for b_address in struct.unpack('>I', data[address:address + 4]): b1 = struct.unpack('>d', data[b_address:b_address + 8])[0] b2 = struct.unpack('>I', data[b_address + 8:b_address + 8 + 4])[0] b3 = struct.unpack('>Q', data[b_address + 8 + 4:b_address + 8 + 4 + 8])[0] b4 = struct.unpack('>b', data[b_address + 8 + 4 + 8:b_address + 8 + 4 + 8 + 1])[0] b5 = struct.unpack('>q', data[b_address + 8 + 4 + 8 + 1:b_address + 8 + 4 + 8 + 1 + 8])[0] b6 = create_c_structures(data, b_address + 8 + 4 + 8 + 1 + 8) result.append({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6}) return result def create_d_structures(data, address): result = [] for d_address in struct.unpack('>H', data[address:address + 2]): d1 = struct.unpack('>Q', data[d_address:d_address + 8])[0] d2 = struct.unpack('>H', data[d_address + 8:d_address + 8 + 2])[0] d3 = struct.unpack('>h', data[d_address + 8 + 2:d_address + 8 + 2 + 2])[0] d4 = list(struct.unpack('>3B', data[d_address + 8 + 2 + 2:d_address + 8 + 2 + 2 + 3])) d5 = struct.unpack('>i', data[d_address + 8 + 2 + 2 + 3:d_address + 8 + 2 + 2 + 3 + 4])[0] d6 = struct.unpack('>Q', data[d_address + 8 + 2 + 2 + 3 + 4:d_address + 8 + 2 + 2 + 3 + 4 + 8])[0] result.append({'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6}) return result def main(data): a1 = struct.unpack('>8s', data[5:13])[0].decode('ascii') a2 = create_b_structures(data, 13) a3 = struct.unpack('>B', data[13 + 4:13 + 4 + 1])[0] a4 = create_d_structures(data, 13 + 4 + 1) a5 = struct.unpack('>d', data[13 + 4 + 1 + 2:13 + 4 + 1 + 2 + 8])[0] a6 = struct.unpack('>I', data[13 + 4 + 1 + 2 + 8:13 + 4 + 1 + 2 + 8 + 4])[0] a7 = list(struct.unpack('>2Q', data[13 + 4 + 1 + 2 + 8 + 4:13 + 4 + 1 + 2 + 8 + 4 + 16])) out_dict = {'A1': a1, 'A2': a2[0], 'A3': a3, 'A4': a4[0], 'A5': a5, 'A6': a6, 'A7': a7} return out_dict" "import struct def main(data): return struct_a_parse(data, 5) def unpack_uint(data, offset, bytes_num): if bytes_num == 1: data = struct.unpack('>B', data[offset:offset + bytes_num]) elif bytes_num == 2: data = struct.unpack('>H', data[offset:offset + bytes_num]) elif bytes_num == 4: data = struct.unpack('>L', data[offset:offset + bytes_num]) elif bytes_num == 8: data = struct.unpack('>Q', data[offset:offset + bytes_num]) data = data[0] return (data, offset + bytes_num) def unpack_float(data, offset): data = struct.unpack('>f', data[offset:offset + 4]) data = data[0] return (data, offset + 4) def unpack_int(data, offset, bytes_num): if bytes_num == 1: data = struct.unpack('>b', data[offset:offset + bytes_num]) elif bytes_num == 2: data = struct.unpack('>h', data[offset:offset + bytes_num]) elif bytes_num == 4: data = struct.unpack('>i', data[offset:offset + bytes_num]) elif bytes_num == 8: data = struct.unpack('>q', data[offset:offset + bytes_num]) data = data[0] return (data, offset + bytes_num) def unpack_list(data, size, offset, type_size, type_int): result = [] for i in range(size): if type_int == 'u': result.append(unpack_uint(data, offset, type_size)[0]) offset = unpack_uint(data, offset, type_size)[1] elif type_int == 'i': result.append(unpack_int(data, offset, type_size)[0]) offset = unpack_int(data, offset, type_size)[1] return result def unpack_c_list(data, size, offset): result = [] for i in range(size): result.append(struct_c_parse(data, unpack_uint(data, offset, 2)[0])) offset = unpack_uint(data, offset, 2)[1] return result def struct_a_parse(data, offset): result = {} (result['A1'], offset) = unpack_int(data, offset, 1) (result['A2'], offset) = unpack_int(data, offset, 8) (result['A3'], offset) = struct_b_parse(data, offset) result['A4'] = unpack_list(data, 3, offset, 8, 'u') return result def struct_b_parse(data, offset): result = {} result['B1'] = unpack_c_list(data, unpack_uint(data, offset, 2)[0], unpack_uint(data, unpack_uint(data, offset, 2)[1], 2)[0]) result['B2'] = struct_d_parse(data, unpack_uint(data, unpack_uint(data, unpack_uint(data, offset, 2)[1], 2)[1], 2)[0]) offset = unpack_uint(data, unpack_uint(data, unpack_uint(data, offset, 2)[1], 2)[1], 2)[1] (result['B3'], offset) = unpack_int(data, offset, 4) (result['B4'], offset) = unpack_uint(data, offset, 4) (result['B5'], offset) = unpack_uint(data, offset, 2) (result['B6'], offset) = unpack_float(data, offset) return (result, offset) def struct_c_parse(data, offset): result = {} (result['C1'], offset) = unpack_uint(data, offset, 2) result['C2'] = unpack_list(data, unpack_uint(data, offset, 4)[0], unpack_uint(data, unpack_uint(data, offset, 4)[1], 2)[0], 1, 'i') offset = unpack_uint(data, unpack_uint(data, offset, 4)[1], 2)[1] (result['C3'], offset) = unpack_uint(data, offset, 1) return result def struct_d_parse(data, offset): result = {} (result['D1'], offset) = unpack_int(data, offset, 1) (result['D2'], offset) = unpack_int(data, offset, 2) (result['D3'], offset) = unpack_int(data, offset, 4) (result['D4'], offset) = unpack_uint(data, offset, 8) result['D5'] = unpack_list(data, unpack_uint(data, offset, 2)[0], unpack_uint(data, unpack_uint(data, offset, 2)[1], 2)[0], 2, 'u') return result" "import struct def main(data): return struct_a_parse(data, 3) def unpack_char(data, offset): data = struct.unpack('<3s', data[offset:offset + 3]) data = data[0] data = data.decode('utf-8') return (data, offset + 3) def unpack_uint(data, offset, bytes_num): if bytes_num == 1: data = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a1_offs, offs) = parse(buf, offs, 'uint16') (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a1_offs, offs) = parse(buf, offs, 'uint16') (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'double') (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'char') b4.append(val.decode()) (b5, offs) = parse(buf, offs, 'uint32') (b6_offs, offs) = parse(buf, offs, 'uint16') (b6, b6_offs) = parse_c(buf, b6_offs) (b7, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3, B4=''.join(b4), B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'uint16') c1.append(val) (c2, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint32') d2.append(val) d3 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') d3.append(val) return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): return parse_a(data, 4) def parse_a(data, offset): result = {} result['A1'] = struct.unpack('>Q', data[offset:offset + struct.calcsize('>Q')])[0] offset += struct.calcsize('>Q') result['A2'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') result['A3'] = struct.unpack('>I', data[offset:offset + struct.calcsize('>I')])[0] offset += struct.calcsize('>I') result['A4'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') result['A5'] = struct.unpack('>l', data[offset:offset + struct.calcsize('>l')])[0] offset += struct.calcsize('>l') addr = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] offset += struct.calcsize('>H') result['A6'] = parse_b(data, addr) result['A7'] = struct.unpack('>b', data[offset:offset + struct.calcsize('b')])[0] return result def parse_b(data, offset): result = {} arr = [] for i in range(0, 7): arr.append(parse_c(data, offset)) offset += 6 result['B1'] = arr size = struct.unpack('>I', data[offset:offset + struct.calcsize('>I')])[0] offset += struct.calcsize('>I') addr = struct.unpack('>I', data[offset:offset + struct.calcsize('>I')])[0] offset += struct.calcsize('>I') result['B2'] = b''.join(struct.unpack(f'>{size}c', data[addr:addr + struct.calcsize(f'>{size}c')])).decode('ascii') addr += struct.calcsize('>c') * size result['B3'] = parse_d(data, addr) offset += 2 result['B4'] = struct.unpack('>q', data[offset:offset + struct.calcsize('>q')])[0] offset += struct.calcsize('>q') result['B5'] = parse_array(data, offset, 'Q', 4)[0] offset += struct.calcsize('>Q') * 4 result['B6'] = struct.unpack('>f', data[offset:offset + struct.calcsize('>f')])[0] offset += struct.calcsize('>f') result['B7'] = struct.unpack('>f', data[offset:offset + struct.calcsize('>f')])[0] offset += struct.calcsize('>f') result['B8'] = parse_array(data, offset, 'B', 4)[0] return result def parse_c(data, offset): result = {} result['C1'] = struct.unpack('>L', data[offset:offset + struct.calcsize('>L')])[0] offset += struct.calcsize('>L') result['C2'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') result['C3'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') return result def parse_d(data, offset): result = {} result['D1'] = struct.unpack('>l', data[offset:offset + struct.calcsize('>l')])[0] offset += struct.calcsize('>l') result['D2'] = parse_array(data, offset, 'h', 2)[0] offset += struct.calcsize('h') * 2 result['D3'] = struct.unpack('>q', data[offset:offset + struct.calcsize('>q')])[0] offset += struct.calcsize('>q') result['D4'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') result['D5'] = struct.unpack('>d', data[offset:offset + struct.calcsize('>d')])[0] offset += struct.calcsize('>d') return result def parse_array(data, offset, type, len): return (list(struct.unpack(f'>{len}{type}', data[offset:offset + struct.calcsize(f'>{len}{type}')])), offset + struct.calcsize(f'>{len}{type}'))" "from struct import unpack def parse_arrays(arr): count = 0 parsed = [] for _ in range(0, 2): a = [] for i in range(0, 5): a.append(arr[count + i]) count += 5 parsed.append(a) return parsed def parse_scam(d, b, parsed_arrays): for arr in parsed_arrays: (d['D1'], d['D2'], d['D3'], d['D4'], d['D5']) = arr b['B3'].append(d.copy()) def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 43: break a = {f'A{i}': None for i in range(1, 7)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 6)} e = {f'E{i}': None for i in range(1, 6)} temp = unpack('>fqH4cBL', file[a_adr:a_adr + 23]) (a['A1'], a['A2'], b_adr, *ch_arr, a['A5'], e_adr) = temp a['A4'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack('>7cLhhLLdfhLLdfl', file[b_adr:b_adr + 61]) (*ch_arr, c['C1'], c['C2']) = temp[0:9] b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) b['B4'] = temp[-1] d_str_arr = temp[9:19] parsed_arrays = parse_arrays(d_str_arr) b['B3'] = [] parse_scam(d, b, parsed_arrays) b['B2'] = c temp = unpack('>BQbQ2h', file[e_adr:e_adr + 22]) (e['E1'], e['E2'], e['E3'], e['E4'], *arr) = temp e['E5'] = list(arr) a['A3'] = b a['A6'] = e return a" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('>' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(data=data, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e_1 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) e_2 = reader.read_double() e_3 = reader.read_int8() return dict(E1=e_1, E2=e_2, E3=e_3) def read_d(reader: BinaryReader): d_1 = reader.read_int16() d_2 = reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') d_3 = reader.read_double() d_4 = reader.read_int16() return dict(D1=d_1, D2=d_2, D3=d_3, D4=d_4) def read_c(reader: BinaryReader): c_1 = read_d(reader) c_2 = [read_e(reader), read_e(reader), read_e(reader), read_e(reader), read_e(reader), read_e(reader), read_e(reader), read_e(reader)] c_3 = reader.read_uint8() c_4 = [reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8()] return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4) def read_b(reader: BinaryReader): b_1 = reader.read_uint16() b_2 = reader.read_uint64() b_3 = reader.read_int32() b_4 = reader.read_uint8() b_5 = reader.read_uint16() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4, B5=b_5) def read_a(reader: BinaryReader): a_1 = read_b(reader) a_2 = reader.read_float() a_3 = read_c(reader) a_4 = reader.read_uint32() a_5 = reader.read_int8() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "from struct import unpack as un from struct import calcsize as calc def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * calc(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 14 return result def parse_d(data, offset): result = {} result['D1'] = un('>B', data[offset:offset + 1])[0] result['D2'] = parse_array(data, offset + 1, 'f', 6) return result def parse_c(data, offset): result = {} result['C1'] = un('>H', data[offset:offset + 2])[0] result['C2'] = un('>I', data[offset + 2:offset + 6])[0] result['C3'] = parse_array(data, offset + 6, 'I', 2) return result def parse_b(data, offset): result = dict() result['B1'] = un('>H', data[offset:offset + 2])[0] result['B2'] = un('>b', data[offset + 2:offset + 3])[0] result['B3'] = un('>Q', data[offset + 3:offset + 11])[0] return result def parse_a(data, offset): result = dict() (a1_size, a1_addr) = un('>II', data[offset:offset + 8]) a1_arr = parse_array(data, a1_addr, 'H', a1_size) a1 = [] for addr in a1_arr: a1.append(parse_b(data, addr)) result['A1'] = a1 result['A2'] = parse_structure_array(data, offset + 8, 3) result['A3'] = un('>d', data[offset + 50:offset + 58])[0] result['A4'] = parse_d(data, offset + 58) result['A5'] = un('>b', data[offset + 83:offset + 84])[0] return result def main(data): return parse_a(data, 4)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 72: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 7)} c = {f'C{i}': None for i in range(1, 8)} d = {f'D{i}': None for i in range(1, 7)} temp = unpack('L', b[t:t + 4]) t += 4 addrC = buff[0] - 5 buff = struct.unpack('>2H', b[addrC:addrC + 4]) addrC += 4 sizeDaddr = buff[0] addrDaddr = buff[1] - 5 Daddr = [] for i in range(sizeDaddr): Daddr.append(struct.unpack('>L', b[addrDaddr:addrDaddr + 4])[0]) addrDaddr += 4 for addr in Daddr: addr -= 5 buff = struct.unpack('>d2H3f2dl', b[addr:addr + 44]) tmp = [] sizeTmp = buff[1] addrTmp = buff[2] - 5 for i in range(sizeTmp): tmp.append(struct.unpack('>B', b[addrTmp:addrTmp + 1])[0]) addrTmp += 1 D.append({'D1': buff[0], 'D2': tmp, 'D3': buff[3], 'D4': [buff[4], buff[5]], 'D5': [buff[6], buff[7]], 'D6': buff[8]}) C['C1'] = D buff = struct.unpack('>2LH', b[addrC:addrC + 10]) addrC += 10 E['E1'] = buff[0] tmp = [] sizeTmp = buff[1] addrTmp = buff[2] - 5 for i in range(sizeTmp): tmp.append(struct.unpack('>f', b[addrTmp:addrTmp + 4])[0]) addrTmp += 4 E['E2'] = tmp C['C2'] = E buff = struct.unpack('>2LQdH', b[addrC:addrC + 26]) C['C3'] = buff[0] C['C4'] = buff[1] C['C5'] = buff[2] C['C6'] = buff[3] addrF = buff[4] - 5 buff = struct.unpack('>dBbL', b[addrF:addrF + 14]) F['F1'] = buff[0] F['F2'] = buff[1] F['F3'] = buff[2] F['F4'] = buff[3] C['C7'] = F B['B1'] = C buff = struct.unpack('>L', b[t:t + 4]) t += 4 B['B2'] = buff[0] buff = struct.unpack('>H2B', b[t:t + 4]) A['A1'] = B A['A2'] = buff[0] A['A3'] = buff[1] A['A4'] = buff[2] return A" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 86: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 9)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 7)} temp = unpack(' 0: temp = arr[BYTE_INDEX] BYTE_INDEX += 1 num = num << 8 num = num ^ temp count -= 1 return num class structE: def fill_struct(self, b): global BYTE_INDEX self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_size_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(self.size): arr.append(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_arr_int8(arr) BYTE_INDEX = STOP_INDEX self.set_int8(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_uint32(self, num): self.E1 = num def set_size_uint32(self, size): self.size = size def set_arr_int8(self, arr): self.E2 = arr def set_int8(self, num): self.E3 = num def get_cort(self): return {'E1': self.E1, 'E2': self.E2, 'E3': self.E3} class structD: def fill_struct(self, b): global BYTE_INDEX arr1 = [] for i in range(4): arr1.append(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_arr_int8_size4_1(arr1) self.set_int32(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) arr2 = [] for i in range(4): arr2.append(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_arr_int8_size4_2(arr2) return self def set_arr_int8_size4_1(self, arr): self.D1 = arr def set_int32(self, num): self.D2 = num def set_arr_int8_size4_2(self, arr): self.D3 = arr def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_int64(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_size_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer all_structs_D = [] for i in range(self.size): pointer2 = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX2 = BYTE_INDEX BYTE_INDEX = pointer2 all_structs_D.append(structD().fill_struct(b)) BYTE_INDEX = STOP_INDEX2 BYTE_INDEX = STOP_INDEX self.set_arr_uint16_of_uint32_struct_d(all_structs_D) self.set_struct_e(structE().fill_struct(b)) return self def set_int64(self, num): self.C1 = num def set_size_uint16(self, num): self.size = num def set_arr_uint16_of_uint32_struct_d(self, arr): self.C2 = arr def set_struct_e(self, E): self.C3 = E def get_cort(self): arr = [] for i in self.C2: arr.append(i.get_cort()) return {'C1': self.C1, 'C2': arr, 'C3': self.C3.get_cort()} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_int8_1(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_int16(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int8_2(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_int8_1(self, num): self.B1 = num def set_uint32(self, num): self.B2 = num def set_int16(self, num): self.B3 = num def set_int8_2(self, num): self.B4 = num def get_cort(self): return {'B1': self.B1, 'B2': self.B2, 'B3': self.B3, 'B4': self.B4} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_struct_b(structB().fill_struct(b)) self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_uint64(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_struct_c(structC().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) return self def set_uint8(self, num): self.A1 = num def set_struct_b(self, B): self.A2 = B def set_double(self, num): self.A3 = num def set_uint64(self, num): self.A4 = num def set_struct_c(self, C): self.A5 = C def set_uint32(self, num): self.A6 = num def get_cort(self): return {'A1': self.A1, 'A2': self.A2.get_cort(), 'A3': self.A3, 'A4': self.A4, 'A5': self.A5.get_cort(), 'A6': self.A6} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct from enum import Enum class Types(Enum): uint8 = 'i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_E1(arr) self.set_E2(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) size = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr1 = [] for i in range(size): arr1.append(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_E3(arr1) BYTE_INDEX = STOP_INDEX return self def set_E1(self, a): self.E1 = a def set_E2(self, a): self.E2 = a def set_E3(self, a): self.E3 = a def get_cort(self): return {'E1': self.E1, 'E2': self.E2, 'E3': self.E3} class structD: def fill_struct(self, b): global BYTE_INDEX self.set_D1(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_D2(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) size = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_D3(arr) BYTE_INDEX = STOP_INDEX self.set_D4(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_D5(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) return self def set_D1(self, a): self.D1 = a def set_D2(self, a): self.D2 = a def set_D3(self, a): self.D3 = a def set_D4(self, a): self.D4 = a def set_D5(self, a): self.D5 = a def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3, 'D4': self.D4, 'D5': self.D5} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_C1(structD().fill_struct(b)) self.set_C2(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_C3(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_C1(self, a): self.C1 = a def set_C2(self, a): self.C2 = a def set_C3(self, a): self.C3 = a def get_cort(self): return {'C1': self.C1.get_cort(), 'C2': self.C2, 'C3': self.C3} class structB: def fill_struct(self, b): global BYTE_INDEX arr_C = [] for i in range(2): arr_C.append(structC().fill_struct(b)) self.set_B1(arr_C) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr_uint8 = [] for i in range(size): arr_uint8.append(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B2(arr_uint8) BYTE_INDEX = STOP_INDEX self.set_B3(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_B4(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_B5(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_B6(structE().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_B7(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_B1(self, a): self.B1 = a def set_B2(self, a): self.B2 = a def set_B3(self, a): self.B3 = a def set_B4(self, a): self.B4 = a def set_B5(self, a): self.B5 = a def set_B6(self, a): self.B6 = a def set_B7(self, a): self.B7 = a def get_cort(self): arr = [] for i in self.B1: arr.append(i.get_cort()) return {'B1': arr, 'B2': self.B2, 'B3': self.B3, 'B4': self.B4, 'B5': self.B5, 'B6': self.B6.get_cort(), 'B7': self.B7} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_A1(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_A2(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_A3(structB().fill_struct(b)) BYTE_INDEX = STOP_INDEX return self def set_A1(self, a): self.A1 = a def set_A2(self, a): self.A2 = a def set_A3(self, a): self.A3 = a def get_cort(self): return {'A1': self.A1, 'A2': self.A2, 'A3': self.A3.get_cort()} def main(h): global BYTE_INDEX BYTE_INDEX = 5 A = structA() A.fill_struct(h) return A.get_cort()" "from struct import unpack type_dict = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's'} def str_a(): d = type_dict return d['uint8'] + d['uint32'] + d['uint16'] + d['uint16'] + str_d() + d['int64'] + d['uint16'] def str_b(): d = type_dict return d['double'] + d['int16'] + d['int64'] def str_c(): d = type_dict return d['double'] + d['int32'] + d['uint16'] def str_d(): d = type_dict return d['float'] + d['uint8'] + d['double'] def str_e(): d = type_dict return 6 * d['char[]'] + d['float'] + d['uint16'] + d['int16'] + d['uint16'] + d['uint16'] + d['uint32'] + d['uint32'] def str_f(): d = type_dict return d['uint16'] + d['uint16'] + d['int16'] def total(): return 'H', data[point:point + 2])[0] point += 2 d['D2'] = unpack('>Q', data[point:point + 8])[0] point += 8 d['D3'] = list(unpack('>3I', data[point:point + 12])) point += 12 return (d, point) def structC(data, point): c = {} c['C1'] = unpack('>d', data[point:point + 8])[0] point += 8 c['C2'] = unpack('>B', data[point:point + 1])[0] point += 1 c['C3'] = unpack('>d', data[point:point + 8])[0] point += 8 c['C4'] = unpack('>f', data[point:point + 4])[0] point += 4 c['C5'] = unpack('>h', data[point:point + 2])[0] point += 2 c['C6'] = unpack('>f', data[point:point + 4])[0] point += 4 return c def structB(data, point): b = {} b['B1'] = unpack('>Q', data[point:point + 8])[0] point += 8 b['B2'] = unpack('>d', data[point:point + 8])[0] point += 8 b['B3'] = unpack('>d', data[point:point + 8])[0] point += 8 b['B4'] = str(unpack('>6s', data[point:point + 6])[0])[2:-1] point += 6 return b def main(data): a = {} point = 5 p1 = unpack('>I', data[point:point + 4])[0] point += 4 b = structB(data, p1) a['A1'] = b p1 = unpack('>H', data[point:point + 2])[0] point += 2 c = structC(data, p1) a['A2'] = c a['A3'] = list(unpack('>3Q', data[point:point + 24])) point += 24 a['A4'] = unpack('>i', data[point:point + 4])[0] point += 4 a['A5'] = unpack('>d', data[point:point + 8])[0] point += 8 a['A6'] = [] for i in range(2): d = structD(data, point) a['A6'].append(d[0]) point = d[1] a['A7'] = unpack('>Q', data[point:point + 8])[0] point += 8 return a" "import struct def structE(data, adr): (uint64,) = struct.unpack('HH', data[pointer:pointer + 4]) d1 = list(struct.unpack(f'>{f1[0]}Q', data[f1[1]:f1[1] + f1[0] * 8])) d2 = struct.unpack('>f', data[pointer + 4:pointer + 8])[0] f3 = struct.unpack('>HH', data[pointer + 8:pointer + 12]) d3 = list(struct.unpack(f'>{f3[0]}I', data[f3[1]:f3[1] + f3[0] * 4])) f4 = struct.unpack('>II', data[pointer + 12:pointer + 20]) d4 = list(struct.unpack(f'>{f4[0]}B', data[f4[1]:f4[1] + f4[0]])) (d5, d6) = struct.unpack('>hH', data[pointer + 20:pointer + 24]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): (c1, c2) = struct.unpack('>HI', data[pointer:pointer + 6]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = struct.unpack('>Q', data[pointer:pointer + 8])[0] b2 = ''.join(map(str, struct.unpack('>4c', data[pointer + 8:pointer + 12]))) b2 = b2.replace(""'"", '')[1::2] (b3, b4) = struct.unpack('>hH', data[pointer + 12:pointer + 16]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>I', data[f1[1] + 4 * i:f1[1] + 4 + 4 * i]) a1.append(parse_b(data, f11[0])) f2 = struct.unpack('>H', data[pointer + 6:pointer + 8]) a2 = parse_c(data, f2[0]) f3 = struct.unpack('>H', data[pointer + 8:pointer + 10]) a3 = parse_d(data, f3[0]) a4 = struct.unpack('>q', data[pointer + 10:pointer + 18])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 3)" "import struct def structD(data, pointer): (d1,) = struct.unpack('>B', data[pointer:pointer + 1]) (d2,) = struct.unpack('>b', data[pointer + 1:pointer + 2]) (d3,) = struct.unpack('>q', data[pointer + 2:pointer + 10]) return {'D1': d1, 'D2': d2, 'D3': d3} def structC(data, pointer): c1 = list(struct.unpack('>8B', data[pointer:pointer + 8])) (c2,) = struct.unpack('>B', data[pointer + 8:pointer + 9]) (c3,) = struct.unpack('>f', data[pointer + 9:pointer + 13]) (c4,) = struct.unpack('>b', data[pointer + 13:pointer + 14]) c5 = list(struct.unpack('>6i', data[pointer + 14:pointer + 38])) (c6,) = struct.unpack('>H', data[pointer + 38:pointer + 40]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def structB(data, pointer): (b1,) = struct.unpack('>b', data[pointer:pointer + 1]) b2 = list(struct.unpack('>7c', data[pointer + 1:pointer + 8])) char_b2 = '' for i in range(len(b2)): char_b2 += chr(b2[i][0]) arr_adr_c = struct.unpack('>IH', data[pointer + 8:pointer + 14]) arr = [] adr_c = struct.unpack('>2I', data[arr_adr_c[1]:arr_adr_c[1] + arr_adr_c[0] * 4]) f3 = structC(data, adr_c[0]) arr.append(f3) f3 = structC(data, adr_c[0] + 40) arr.append(f3) b3 = arr (b4,) = struct.unpack('>H', data[pointer + 14:pointer + 16]) (b5,) = struct.unpack('>I', data[pointer + 16:pointer + 20]) return {'B1': b1, 'B2': char_b2, 'B3': b3, 'B4': b4, 'B5': b5} def structA(data, pointer): (a1,) = struct.unpack('>Q', data[pointer:pointer + 8]) (f2,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) a2 = structB(data, f2) a3 = list(struct.unpack('>7i', data[pointer + 10:pointer + 38])) (a4,) = struct.unpack('>Q', data[pointer + 38:pointer + 46]) (f5,) = struct.unpack('>I', data[pointer + 46:pointer + 50]) a5 = structD(data, f5) (a6,) = struct.unpack('>i', data[pointer + 50:pointer + 54]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return structA(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'char') a2.append(val.decode()) (a3_offs, _offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(1): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) for _ in range(1): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) a4 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int32') a4.append(val) a4.pop(0) (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse_c(buf, offs) (a7, offs) = parse(buf, offs, 'int8') (a8_offs, offs) = parse(buf, offs, 'uint32') (a8, offs) = parse_d(buf, a8_offs) return (dict(A1=''.join(a1), A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint64') (b2, offs) = parse(buf, offs, 'float') (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'uint16') (c5, offs) = parse(buf, offs, 'int8') (c6, offs) = parse(buf, offs, 'uint8') (c7, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'uint8') (d4, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('>Q') def read_int64(self): return self.read('>q') def read_uint32(self): return self.read('>I') def read_int32(self): return self.read('>i') def read_uint16(self): return self.read('>H') def read_int16(self): return self.read('>h') def read_uint8(self): return self.read('>B') def read_int8(self): return self.read('>b') def read_float(self): return self.read('>f') def read_char(self): return self.read('>c') def read_double(self): return self.read('>d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e1 = [reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float()] e2 = [reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float()] e3 = reader.read_int64() e4 = reader.read_uint32() return dict(E1=e1, E2=e2, E3=e3, E4=e4) def read_d(reader: BinaryReader): d1 = read_e(reader) d2 = reader.read_float() return dict(D1=d1, D2=d2) def read_c(reader: BinaryReader): c1 = reader.read_uint8() c2 = reader.read_double() c3 = reader.read_uint64() c4 = reader.read_int32() c5 = [reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8()] return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def read_b(reader: BinaryReader): b1 = [read_c(reader), read_c(reader)] b2 = reader.read_uint16() b3 = reader.read_int16() return dict(B1=b1, B2=b2, B3=b3) def read_a(reader: BinaryReader): a1 = read_b(reader) a2 = reader.read_int64() a3 = reader.read_float() a4 = reader.read_uint16() a5 = reader.read_uint64() a6 = reader.read_int32() a7 = reader.read_float() a8 = read_d(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "import struct from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 6 return result def parse_f(data, offset): result = dict() result['F1'] = un('>q', data[offset:offset + 8])[0] result['F2'] = un('>I', data[offset + 8:offset + 12])[0] return result def parse_e(data, offset): result = dict() result['E1'] = un('>H', data[offset:offset + 2])[0] result['E2'] = un('>f', data[offset + 2:offset + 6])[0] (e3_size, e3_addr) = un('>HH', data[offset + 6:offset + 10]) result['E3'] = parse_array(data, e3_addr, 'Q', e3_size) result['E4'] = un('>i', data[offset + 10:offset + 14])[0] return result def parse_d(data, offset): result = dict() result['D1'] = un('>q', data[offset:offset + 8])[0] result['D2'] = un('>I', data[offset + 8:offset + 12])[0] result['D3'] = parse_e(data, offset + 12) result['D4'] = parse_array(data, offset + 26, 'B', 2) result['D5'] = un('>f', data[offset + 28:offset + 32])[0] result['D6'] = un('>i', data[offset + 32:offset + 36])[0] result['D7'] = un('>f', data[offset + 36:offset + 40])[0] return result def parse_c(data, offset): result = dict() result['C1'] = un('>f', data[offset:offset + 4])[0] result['C2'] = un('>i', data[offset + 4:offset + 8])[0] result['C3'] = un('>i', data[offset + 8:offset + 12])[0] result['C4'] = un('>B', data[offset + 12:offset + 13])[0] result['C5'] = un('>i', data[offset + 13:offset + 17])[0] return result def parse_b(data, offset): result = dict() (b1_size, b1_addr) = un('>HI', data[offset:offset + 6]) b1_arr = parse_array(data, b1_addr, 'I', b1_size) b1 = list() for addr in b1_arr: b1.append(parse_c(data, addr)) result['B1'] = b1 result['B2'] = un('>b', data[offset + 6:offset + 7])[0] return result def parse_a(data, offset): result = dict() (a1_size, a1_addr) = un('>HI', data[offset:offset + 6]) a1 = [] a1 = ''.join((x.decode('ascii') for x in parse_array(data, a1_addr, 'c', a1_size))) result['A1'] = a1 result['A2'] = un('>H', data[offset + 6:offset + 8])[0] result['A3'] = parse_b(data, offset + 8) result['A4'] = parse_d(data, offset + 15) result['A5'] = parse_f(data, struct.unpack('>I', data[offset + 55:offset + 59])[0]) result['A6'] = parse_array(data, offset + 59, 'h', 5) return result def main(data): return parse_a(data, 4)" "import struct def get_b3(data): indices = [struct.unpack('>I', data[18 + i:22 + i])[0] for i in range(0, 20, 4)] b3 = [] for i in indices: b3.append({'C1': struct.unpack('>B', data[i:i + 1])[0], 'C2': struct.unpack('>q', data[i + 1:i + 9])[0], 'C3': struct.unpack('>h', data[i + 9:i + 11])[0]}) return b3 def get_b4(data): index = struct.unpack('>I', data[38:42])[0] e2 = struct.unpack('>B', data[index:index + 1])[0] length = struct.unpack('>I', data[index + 1:index + 5])[0] address = struct.unpack('>I', data[index + 5:index + 9])[0] b4 = {'D1': e2, 'D2': list((struct.unpack('>h', data[address + i:address + i + 2])[0] for i in range(0, length * 2, 2)))} return b4 def get_b6(data): length = struct.unpack('>H', data[43:45])[0] address = struct.unpack('>I', data[45:49])[0] return list((struct.unpack('>Q', data[address + i:address + i + 8])[0] for i in range(0, length * 8, 8))) def main(data): b1 = struct.unpack('>6s', data[4:10])[0].decode('UTF-8') b2 = struct.unpack('>Q', data[10:18])[0] b3 = get_b3(data) b4 = get_b4(data) b5 = struct.unpack('>b', data[42:43])[0] b6 = get_b6(data) a2 = struct.unpack('>H', data[49:51])[0] a3 = list(struct.unpack('>4b', data[51:55])) result = {'A1': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6}, 'A2': a2, 'A3': a3} return result" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_d(buf, offs): d1 = [] for _ in range(0, 2): (val, offs) = parse(buf, offs, 'float') d1.append(val) d2 = [] for _ in range(0, 2): (val, offs) = parse(buf, offs, 'uint16') d2.append(val) (d3, offs) = parse(buf, offs, 'int8') (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse(buf, offs, 'uint8') (d6_size, offs) = parse(buf, offs, 'uint16') (d6_offs, offs) = parse(buf, offs, 'uint16') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'uint32') d6.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'int8') (c3_size, offs) = parse(buf, offs, 'uint16') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'uint8') c3.append(val) (c4, offs) = parse(buf, offs, 'uint8') (c5, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2_offs, offs) = parse(buf, offs, 'uint32') (val, b2_offs) = parse_c(buf, b2_offs) b2 = val (b3, offs) = parse(buf, offs, 'int32') (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (b4_d_addr, b4_offs) = parse(buf, b4_offs, 'uint16') (val, b4_d_addr) = parse_d(buf, b4_d_addr) b4.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): A = struct.unpack_from('<2Hh3HId3QHIf', data, offset=4) A1 = struct.unpack_from('<' + 'Ih' * A[0], data, offset=A[1]) B_list = [] for i in range(A[0]): B_list.append({'B1': A1[i * 2], 'B2': A1[i * 2 + 1]}) C7 = list(struct.unpack_from('<' + str(A[11]) + 'b', data, offset=A[12])) D = struct.unpack_from('Q', data[pointer:pointer + 8]) (e2,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) e3 = list(struct.unpack('>3Q', data[pointer + 10:pointer + 34])) (e4,) = struct.unpack('>q', data[pointer + 34:pointer + 42]) f5 = struct.unpack('>IH', data[pointer + 42:pointer + 48]) e5 = list(struct.unpack(f'>{f5[0]}B', data[f5[1]:f5[1] + f5[0] * 1])) (e6,) = struct.unpack('>H', data[pointer + 48:pointer + 50]) (e7,) = struct.unpack('>B', data[pointer + 50:pointer + 51]) (e8,) = struct.unpack('>h', data[pointer + 51:pointer + 53]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7, 'E8': e8} def structD(data, pointer): (d1,) = struct.unpack('>b', data[pointer:pointer + 1]) (d2,) = struct.unpack('>Q', data[pointer + 1:pointer + 9]) return {'D1': d1, 'D2': d2} def structC(data, pointer): c1 = ''.join(map(str, struct.unpack('>3c', data[pointer:pointer + 3]))) c1 = c1.replace(""'"", '') c1 = c1[1::2] (c2,) = struct.unpack('>f', data[pointer + 3:pointer + 7]) (c3,) = struct.unpack('>B', data[pointer + 7:pointer + 8]) return {'C1': c1, 'C2': c2, 'C3': c3} def structB(data, pointer): b1 = structC(data, pointer) (b2,) = struct.unpack('>q', data[pointer + 8:pointer + 16]) (b3,) = struct.unpack('>b', data[pointer + 16:pointer + 17]) (f4_1,) = struct.unpack('>H', data[pointer + 17:pointer + 19]) (f4_2,) = struct.unpack('>H', data[pointer + 19:pointer + 21]) (f4_3,) = struct.unpack('>H', data[pointer + 21:pointer + 23]) b4 = [structD(data, f4_1), structD(data, f4_2), structD(data, f4_3)] (b5,) = struct.unpack('>h', data[pointer + 23:pointer + 25]) (f6,) = struct.unpack('>I', data[pointer + 25:pointer + 29]) b6 = strucktE(data, f6) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def structA(data, pointer): (a1,) = struct.unpack('>B', data[pointer:pointer + 1]) (a2,) = struct.unpack('>B', data[pointer + 1:pointer + 2]) (a3,) = struct.unpack('>f', data[pointer + 2:pointer + 6]) (a4,) = struct.unpack('>Q', data[pointer + 6:pointer + 14]) a5 = structB(data, pointer + 14) a6 = list(struct.unpack('>4q', data[pointer + 43:pointer + 75])) (a7,) = struct.unpack('>b', data[pointer + 75:pointer + 76]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return structA(data, 4)" "from pprint import pprint import struct pointer = 5 def structA(data): A = {} global pointer A['A1'] = struct.unpack('>i', data[pointer:pointer + 4])[0] pointer += 4 A['A2'] = [] for i in range(3): A['A2'].append(structB(data)) size = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 address = struct.unpack('>I', data[pointer:pointer + 4])[0] pointer += 4 A['A3'] = [] for i in range(size): A['A3'].append(struct.unpack('>h', data[address + i * 2:address + i * 2 + 2])[0]) pointer += 2 * size return A def structB(data): B = {} global pointer B['B1'] = '' for i in range(7): B['B1'] += struct.unpack('>c', data[pointer + i:pointer + 1 + i])[0].decode('ascii') pointer += 7 B['B2'] = struct.unpack('>f', data[pointer:pointer + 4])[0] pointer += 4 B['B3'] = structC(data) B['B4'] = struct.unpack('>f', data[pointer:pointer + 4])[0] pointer += 4 B['B5'] = struct.unpack('>B', data[pointer:pointer + 1])[0] pointer += 1 address = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 B['B6'] = structD(data, address) return B def structC(data): C = {} global pointer C['C1'] = struct.unpack('>d', data[pointer:pointer + 8])[0] pointer += 8 C['C2'] = struct.unpack('>Q', data[pointer:pointer + 8])[0] pointer += 8 C['C3'] = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 return C def structD(data, address): D = {} D['D1'] = struct.unpack('>I', data[address:address + 4])[0] address += 4 D['D2'] = struct.unpack('>B', data[address:address + 1])[0] address += 1 D['D3'] = struct.unpack('>h', data[address:address + 2])[0] address += 2 D['D4'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 D['D5'] = [] for i in range(2): D['D5'].append(struct.unpack('>h', data[address + i * 2:address + 2 + i * 2])[0]) address += 2 * 2 D['D6'] = struct.unpack('>h', data[address:address + 2])[0] address += 2 D['D7'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 return D def main(data): return structA(data)" "import struct from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'<{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 16 return result def parse_d(data, offset): result = dict() (d1_size, d1_addr) = un('H', s[pointer:pointer + 2])[0] add = struct.unpack('>H', s[pointer + 2:pointer + 4])[0] for i in range(0, size): c1 = struct.unpack('>f', s[add:add + 4])[0] c2 = struct.unpack('>B', s[add + 4:add + 5])[0] result.append({'C1': c1, 'C2': c2}) add += 5 return result def create_b_structure(s, pointer): result = [] for i in range(0, 2): b1 = struct.unpack('>d', s[pointer:pointer + 8])[0] b2 = uint16uint16_in_C_structure(s, pointer + 8) b3 = struct.unpack('>H', s[pointer + 12:pointer + 14])[0] b4 = struct.unpack('>b', s[pointer + 14:pointer + 15])[0] b5 = [struct.unpack('>I', s[pointer + 15:pointer + 19])[0], struct.unpack('>I', s[pointer + 19:pointer + 23])[0], struct.unpack('>I', s[pointer + 23:pointer + 27])[0], struct.unpack('>I', s[pointer + 27:pointer + 31])[0]] result.append({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5}) pointer += 31 return result def main(s): a2 = struct.unpack('>H', s[67:69])[0] out_dict = {'A1': create_b_structure(s, 5), 'A2': {'D1': struct.unpack('>q', s[a2:a2 + 8])[0], 'D2': struct.unpack('>b', s[a2 + 8:a2 + 9])[0]}, 'A3': [struct.unpack('>h', s[69:71])[0], struct.unpack('>h', s[71:73])[0], struct.unpack('>h', s[73:75])[0], struct.unpack('>h', s[75:77])[0]], 'A4': struct.unpack('>b', s[77:78])[0], 'A5': struct.unpack('>f', s[78:82])[0], 'A6': struct.unpack('>h', s[82:84])[0], 'A7': struct.unpack('>i', s[84:88])[0]} return out_dict" "import struct def main(data): A = struct.unpack_from('>bBId2qqdqdqdqdH', data, offset=3) B = struct.unpack_from('>B8cqi', data, offset=A[2]) B2 = '' for i in range(6): B2 += B[i + 1].decode('utf-8') B3 = '' for i in range(2): B3 += B[i + 7].decode('utf-8') D = struct.unpack_from('>IHq', data, offset=A[14]) D1 = list(struct.unpack_from('>' + str(D[0]) + 'I', data, offset=D[1])) return {'A1': A[0], 'A2': A[1], 'A3': {'B1': B[0], 'B2': B2, 'B3': B3, 'B4': B[9], 'B5': B[10]}, 'A4': A[3], 'A5': A[4], 'A6': A[5], 'A7': [{'C1': A[6], 'C2': A[7]}, {'C1': A[8], 'C2': A[9]}, {'C1': A[10], 'C2': A[11]}, {'C1': A[12], 'C2': A[13]}], 'A8': {'D1': D1, 'D2': D[2]}}" "import struct def main(data): A = struct.unpack_from('qq', data[pointer:pointer + 16]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): c1 = struct.unpack('>f', data[pointer:pointer + 4])[0] f2 = struct.unpack('>II', data[pointer + 4:pointer + 12]) c2 = list(struct.unpack(f'{f2[0]}B', data[f2[1]:f2[1] + f2[0]])) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = list() for i in range(5): b1.append(parse_c(data, pointer + i * 12)) b2 = struct.unpack('>i', data[pointer + 60:pointer + 64])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) a1.append(parse_b(data, f11[0])) (a2, a3) = struct.unpack('>bq', data[pointer + 6:pointer + 15]) a4 = parse_d(data, pointer + 15) a5 = struct.unpack('>i', data[pointer + 31:pointer + 35])[0] a6 = list(struct.unpack('>4H', data[pointer + 35:pointer + 43])) a7 = struct.unpack('>b', data[pointer + 43:pointer + 44])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_f(data, pointer): (f1, f2, f3, f4, f5) = struct.unpack('>qHIqd', data[pointer:pointer + 30]) f6 = list(struct.unpack('>7q', data[pointer + 30:pointer + 86])) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6} def parse_e(data, pointer): (e1, e2) = struct.unpack('>Ib', data[pointer:pointer + 5]) return {'E1': e1, 'E2': e2} def parse_d(data, pointer): (d1, d2) = struct.unpack('>dH', data[pointer:pointer + 10]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): c1 = struct.unpack('>h', data[pointer:pointer + 2])[0] c2 = parse_d(data, pointer + 2) c3 = struct.unpack('>i', data[pointer + 12:pointer + 16])[0] return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): b1 = list() for i in range(3): b1.append(parse_c(data, pointer + i * 16)) b2 = struct.unpack('>f', data[pointer + 48:pointer + 52])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = struct.unpack('>I', data[pointer + 52:pointer + 56])[0] a3 = parse_e(data, pointer + 56) f4 = struct.unpack('>IH', data[pointer + 61:pointer + 67]) a4 = ''.join(map(str, struct.unpack(f'{f4[0]}c', data[f4[1]:f4[1] + f4[0]]))) a4 = a4.replace(""'"", '')[1::2] f5 = struct.unpack('>IH', data[pointer + 67:pointer + 73]) a5 = ''.join(map(str, struct.unpack(f'>{f5[0]}c', data[f5[1]:f5[1] + f5[0]]))) a5 = a5.replace(""'"", '')[1::2] a6 = parse_f(data, pointer + 73) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 5)" "import struct def uint16uint16uint8(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] a = struct.unpack('< ' + 'B' * size, x[add:add + 1 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('< q', x[start:start + 8])[0], 'D2': struct.unpack('< I', x[start + 8:start + 12])[0], 'D3': struct.unpack('< f', x[start + 12:start + 16])[0]} def C(x, start): return {'C1': struct.unpack('< H', x[start:start + 2])[0], 'C2': struct.unpack('< d', x[start + 2:start + 10])[0], 'C3': list(struct.unpack('< 2b', x[start + 10:start + 12])), 'C4': uint16uint16uint8(x, start + 12)} def addressC(x, start): return struct.unpack('< I', x[start:start + 4])[0] def addressD(x, start): return struct.unpack('< I', x[start:start + 4])[0] def B(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] return {'B1': [C(x, addressC(x, add + j * 4)) for j in range(0, size)], 'B2': D(x, addressD(x, start + 4)), 'B3': list(struct.unpack('8h', x[start + 8:start + 24])), 'B4': struct.unpack('< d', x[start + 24:start + 32])[0], 'B5': struct.unpack('< i', x[start + 32:start + 36])[0], 'B6': struct.unpack('< B', x[start + 36:start + 37])[0]} def A(x, start): return {'A1': struct.unpack('< 4s', x[start:start + 4])[0].decode('ascii'), 'A2': struct.unpack('< d', x[start + 4:start + 12])[0], 'A3': struct.unpack('< I', x[start + 12:start + 16])[0], 'A4': struct.unpack('< q', x[start + 16:start + 24])[0], 'A5': struct.unpack('< I', x[start + 24:start + 28])[0], 'A6': struct.unpack('< Q', x[start + 28:start + 36])[0], 'A7': B(x, start + 36), 'A8': struct.unpack('< B', x[start + 73:start + 74])[0]} def main(x): return A(x, 5)" "import math import re import struct AFORMAT = '>HHdB' BFORMAT = '>Hb' CFORMAT = '>II6BqIhIH5ihd' CF = '>II6Bq' DFORMAT = '>IhIH5ih' def unpack_a(raw_data): size = struct.calcsize(AFORMAT) data = struct.unpack(AFORMAT, raw_data[5:size + 5]) b_struct_size = data[0] b_struct_address = data[1] a1 = unpack_b_array(raw_data, b_struct_address, b_struct_size) a2 = data[2] a3 = data[3] return {'A1': a1, 'A2': a2, 'A3': a3} def unpack_b_array(raw_data, address, amount): size = struct.calcsize(BFORMAT) result = [] for i in range(amount): ranger = raw_data[:address + size * (i + 1)] data = struct.unpack_from(BFORMAT, ranger, address + size * i) c_address = data[0] b1 = unpack_c(raw_data, c_address) b2 = data[1] result.append({'B1': b1, 'B2': b2}) return result def unpack_c(raw_data, address): size = struct.calcsize(CFORMAT) data = struct.unpack_from(CFORMAT, raw_data[:address + size], address) array_size = data[0] array_address = data[1] c1 = unpack_a8_array(raw_data, array_address, array_size) c2 = list(data[2:8]) c3 = data[8] c4 = unpack_d(raw_data, address + struct.calcsize(CF)) c5 = data[-1] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def unpack_d(raw_data, address): size = struct.calcsize(DFORMAT) data = struct.unpack_from(DFORMAT, raw_data[:address + size], address) d1 = data[0] d2 = data[1] array_size = data[2] array_address = data[3] d3 = unpack_a16_array(raw_data, array_address, array_size) d4 = list(data[4:9]) d5 = data[9] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def unpack_a8_array(raw_data, address, size): format = '>' + str(size) + 'b' return list(struct.unpack_from(format, raw_data[:address + size], address)) def unpack_a16_array(raw_data, address, amount): format = '>' + str(amount) + 'h' size = struct.calcsize(format) return list(struct.unpack_from(format, raw_data[:address + size], address)) def main(raw_data): return unpack_a(raw_data)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2_size, offs) = parse(buf, offs, 'uint16') (a2_offs, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse_e(buf, a2_offs) a2.append(val) (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'int16') a3.append(val) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2, offs) = parse(buf, offs, 'int32') b3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'char') b3.append(val.decode()) return (dict(B1=b1, B2=b2, B3=''.join(b3)), offs) def parse_c(buf, offs): (c1_offs, offs) = parse(buf, offs, 'uint16') (c1, c1_offs) = parse_d(buf, c1_offs) (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse(buf, offs, 'int16') (c4, offs) = parse(buf, offs, 'uint32') (c5, offs) = parse(buf, offs, 'int16') (c6, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'int32') (d4, offs) = parse(buf, offs, 'int64') (d5, offs) = parse(buf, offs, 'uint8') (d6_size, offs) = parse(buf, offs, 'uint16') (d6_offs, offs) = parse(buf, offs, 'uint16') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'int64') d6.append(val) (d7, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int8') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'int64') (e4, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u32u16u32B(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = list(unpack('>' + 'I' * size, s[add:add + size * 4])) Barr = [] for b in arr: Barr.append(B(s, b)) return Barr def D(s, start): return {'D1': unpack('>i', s[start.a:start + 4])[0], 'D2': unpack('>b', s[start.a:start + 1])[0]} def C(s, start): return {'C1': list(unpack('>BB', s[start.a:start + 2])), 'C2': list(unpack('>IIIIII', s[start.a:start + 24])), 'C3': unpack('>h', s[start.a:start + 2])[0], 'C4': D(s, start)} def B(s, start): start = Counter(start) return {'B1': C(s, start), 'B2': unpack('>q', s[start.a:start + 8])[0], 'B3': unpack('>i', s[start.a:start + 4])[0]} def A(s, start): return {'A1': unpack('>q', s[start.a:start + 8])[0], 'A2': u32u16u32B(s, start), 'A3': list(unpack('>hhh', s[start.a:start + 6])), 'A4': list(unpack('>BBBBBBBB', s[start.a:start + 8]))} def main(s): start = Counter(5) return A(s, start)" "import struct def main(data): A = struct.unpack_from('>B2HIB', data, offset=4) B = struct.unpack_from('>' + A[1] * '2iHIH2IHq', data, offset=A[2]) B_list = [] for i in range(A[1]): C2 = list(struct.unpack_from('>' + str(B[i * 9 + 2]) + 'b', data, offset=B[i * 9 + 3])) C5 = list(struct.unpack_from('>' + str(B[i * 9 + 6]) + 'i', data, offset=B[i * 9 + 7])) D = struct.unpack_from('>3HhQ', data, offset=B[i * 9 + 5]) B_list.append({'B1': {'C1': [B[i * 9], B[i * 9 + 1]], 'C2': C2, 'C3': B[i * 9 + 4], 'C4': {'D1': [D[0], D[1], D[2]], 'D2': D[3], 'D3': D[4]}, 'C5': C5}, 'B2': B[i * 9 + 8]}) return {'A1': A[0], 'A2': B_list, 'A3': A[3], 'A4': A[4]}" "from struct import * def get_list(inp, size, address, t): type_names = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char': 's'} mask = '<%d%s' % (size, type_names[t]) s = address + calcsize(mask) return list(unpack(mask, inp[address:s])) class A: def __init__(self, address): self.address = address self.f = '<3qHhHI' self.par_1 = 0 self.par_2 = 0 self.par_3 = 0 self.b_obj = 0 self.par_5 = 0 self.par_6 = [] def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] self.par_2 = tmp[1] self.par_3 = tmp[2] self.b_obj = B(tmp[3]) self.b_obj.set(inp) self.par_5 = tmp[4] self.par_6 = get_list(inp, tmp[5], tmp[6], 'int8') def __dict__(self): return {'A1': self.par_1, 'A2': self.par_2, 'A3': self.par_3, 'A4': self.b_obj.__dict__(), 'A5': self.par_5, 'A6': self.par_6} class B: def __init__(self, address): self.address = address self.B1 = [] self.B2 = [] def set(self, inp): s = self.address c_1 = C(s) c_1.set(inp) s = c_1.end_struct c_2 = C(s) c_2.set(inp) s = c_2.end_struct self.B1 = [c_1, c_2] self.B2 = get_list(inp, 3, s, 'int64') def __dict__(self): return {'B1': [x.__dict__() for x in self.B1], 'B2': self.B2} class C: def __init__(self, address): self.address = address self.f = ' I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = [] for i in range(size): a.append(E(x, add + i * 11)) return a def uint16uint16char(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] return str(x[add:add + size])[2:-1] def E(x, start): return {'E1': [struct.unpack('> B', x[start:start + 1])[0], struct.unpack('> B', x[start + 1:start + 2])[0]], 'E2': struct.unpack('> q', x[start + 2:start + 10])[0], 'E3': struct.unpack('> b', x[start + 10:start + 11])[0]} def D(x, start): return {'D1': struct.unpack('> B', x[start:start + 1])[0], 'D2': [struct.unpack('> i', x[start + 1:start + 5])[0], struct.unpack('> i', x[start + 5:start + 9])[0], struct.unpack('> i', x[start + 9:start + 13])[0]]} def C(x, start): return {'C1': uint16uint16char(x, start), 'C2': struct.unpack('> d', x[start + 4:start + 12])[0]} def B(x, start): return {'B1': C(x, start), 'B2': D(x, start + 12), 'B3': struct.unpack('> d', x[start + 25:start + 33])[0]} def A(x, start): return {'A1': struct.unpack('> i', x[start:start + 4])[0], 'A2': B(x, start + 4), 'A3': uint32uint16e(x, start + 37), 'A4': struct.unpack('> B', x[start + 43:start + 44])[0]} def main(x): return A(x, 4)" "import struct def main(data): return parse_a(data, 5) def parse_a(data, offset): result = {} result['A1'] = struct.unpack('>d', data[offset:offset + struct.calcsize('>d')])[0] offset += struct.calcsize('>d') result['A2'] = struct.unpack('>Q', data[offset:offset + struct.calcsize('>Q')])[0] offset += struct.calcsize('>Q') result['A3'] = parse_b(data, offset) offset += 58 addr = struct.unpack('>I', data[offset:offset + struct.calcsize('>L')])[0] result['A4'] = parse_e(data, addr) return result def parse_b(data, offset): result = {} result['B1'] = b''.join(struct.unpack('>4c', data[offset:offset + struct.calcsize('>4c')])).decode('ascii') offset += struct.calcsize('>4c') result['B2'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') addr = struct.unpack('>I', data[offset:offset + struct.calcsize('>I')])[0] offset += struct.calcsize('>I') result['B3'] = parse_c(data, addr) arr = [] for i in range(0, 6): arr.append(parse_d(data, offset)) offset += 8 result['B4'] = arr result['B5'] = struct.unpack('>B', data[offset:offset + struct.calcsize('>B')])[0] offset += struct.calcsize('>B') return result def parse_c(data, offset): result = {} result['C1'] = struct.unpack('>Q', data[offset:offset + struct.calcsize('>Q')])[0] offset += struct.calcsize('>Q') result['C2'] = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] offset += struct.calcsize('>H') return result def parse_d(data, offset): result = {} result['D1'] = parse_array(data, offset, 'B', 2) offset += struct.calcsize('>2B') result['D2'] = parse_array(data, offset, 'B', 6) offset += struct.calcsize('>6B') return result def parse_e(data, offset): result = {} result['E1'] = struct.unpack('>Q', data[offset:offset + struct.calcsize('>Q')])[0] offset += struct.calcsize('>Q') result['E2'] = struct.unpack('>h', data[offset:offset + struct.calcsize('>h')])[0] offset += struct.calcsize('>h') return result def parse_array(data, offset, type, len): return list(struct.unpack(f'>{len}{type}', data[offset:offset + struct.calcsize(f'>{len}{type}')]))" "import struct def main(data): A = struct.unpack_from('BIIfb', data1) ans['A1'] = a_str[0] ans['A4'] = a_str[-2] ans['A5'] = a_str[-1] adress_b = a_str[1] b_str = find(adress_b, b, '>fBhHIiIHQ', data1) ans['A2']['B1']['C1'] = b_str[0] ans['A2']['B1']['C2'] = b_str[1] ans['A2']['B2'] = b_str[2] d_array = [] array_adress_d = find(b_str[4], b_str[3] * 2, f'>{b_str[3]}H', data1) for adress_d in array_adress_d: d_array.append(find(adress_d, d, '>id5I2b', data1)) d_list = [] for i in d_array: d_dict = {'D1': i[0], 'D2': i[1], 'D3': list(i[2:7]), 'D4': list(i[7:])} d_list.append(d_dict) ans['A2']['B3'] = d_list ans['A2']['B4'] = {'E1': b_str[-4], 'E2': b_str[-3], 'E3': b_str[-2], 'E4': b_str[-1]} f_struct = find(a_str[2], f, '>fHIII', data1) f4 = find(f_struct[4], f_struct[3] * 4, f'>{f_struct[3]}i', data1) ans['A3'] = {'F1': f_struct[0], 'F2': f_struct[1], 'F3': f_struct[2], 'F4': list(f4)} return ans" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, it): return (unpack_from('>' + FMT[it], buf, offs)[0], offs + calcsize(FMT[it])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') (a2, offs) = parse(buf, offs, 'float') (a3, offs) = parse(buf, offs, 'double') (a4, offs) = parse_b(buf, offs) (a5, offs) = parse_e(buf, offs) (a6, offs) = parse(buf, offs, 'int32') (a7, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (b2_offso, b2_offs) = parse(buf, b2_offs, 'uint32') (val, b2_offso) = parse_c(buf, b2_offso) b2.append(val) (b3, offs) = parse(buf, offs, 'float') b4 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'char') b4.append(val.decode()) (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint16') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'uint8') b5.append(val) (b6_offs, offs) = parse(buf, offs, 'uint16') (b6, b6_offs) = parse_d(buf, b6_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=''.join(b4), B5=b5, B6=b6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'int16') d2.append(val) (d3, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int64') (e2, offs) = parse(buf, offs, 'int32') (e3, offs) = parse(buf, offs, 'uint32') (e4, offs) = parse(buf, offs, 'int32') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(data): return parse_a(data, 4) def parse_a(data, offset): result = {} (result['A1'], result['A2']) = struct.unpack('{size}c', data[addr:addr + struct.calcsize(f'>{size}c')])).decode('ascii') offset += struct.calcsize(f'>{size}c') return result def parse_c(data, offset): result = {} result['C1'] = struct.unpack('{len}{type}', data[offset:offset + struct.calcsize(f'>{len}{type}')]))" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, it): return (unpack_from('>' + FMT[it], buf, offs)[0], offs + calcsize(FMT[it])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint64') (a3, offs) = parse_d(buf, offs) (a4, offs) = parse(buf, offs, 'int16') (a5, offs) = parse(buf, offs, 'uint8') (a6, offs) = parse(buf, offs, 'int32') (a7, offs) = parse(buf, offs, 'float') (a8, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse_c(buf, offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'uint64') (c3_size, offs) = parse(buf, offs, 'uint32') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'char') c3.append(val.decode()) return (dict(C1=c1, C2=c2, C3=''.join(c3)), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') d2 = [] for _ in range(2): (val, offs) = parse_e(buf, offs) d2.append(val) return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): e1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int16') e1.append(val) (e2, offs) = parse(buf, offs, 'int8') e3 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int64') e3.append(val) (e4, offs) = parse(buf, offs, 'int32') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(x): A1 = str(struct.unpack('>5s', x[5:10]))[3:8] A2_address_struct_B = struct.unpack('>L', x[10:14])[0] A3 = struct.unpack('>L', x[14:18])[0] A4 = struct.unpack('>h', x[18:20])[0] A5 = struct.unpack('>l', x[20:24])[0] A6_list_len = struct.unpack('>L', x[24:28])[0] A6_list_address = struct.unpack('>L', x[28:32])[0] D1 = struct.unpack('>B', x[32:33])[0] D2 = struct.unpack('>f', x[33:37])[0] D3 = struct.unpack('>q', x[37:45])[0] A7 = {'D1': D1, 'D2': D2, 'D3': D3} A6 = [] for i in range(0, A6_list_len): A6.append(struct.unpack('>b', x[A6_list_address:A6_list_address + 1])[0]) A6_list_address += 1 B1_list_len_struct_C = struct.unpack('>L', x[A2_address_struct_B:A2_address_struct_B + 4])[0] B1_list_address_struct_C = struct.unpack('>L', x[A2_address_struct_B + 4:A2_address_struct_B + 8])[0] B1 = [] B2 = struct.unpack('>H', x[A2_address_struct_B + 8:A2_address_struct_B + 10])[0] for i in range(0, B1_list_len_struct_C): C1 = struct.unpack('>L', x[B1_list_address_struct_C:B1_list_address_struct_C + 4])[0] temp_num = B1_list_address_struct_C C2 = [] for j in range(0, 8): C2.append(struct.unpack('>B', x[temp_num + 4:temp_num + 5])[0]) temp_num += 1 C3 = struct.unpack('>f', x[B1_list_address_struct_C + 12:B1_list_address_struct_C + 16])[0] C4 = struct.unpack('>b', x[B1_list_address_struct_C + 16:B1_list_address_struct_C + 17])[0] C5 = struct.unpack('>q', x[B1_list_address_struct_C + 17:B1_list_address_struct_C + 25])[0] C6 = struct.unpack('>l', x[B1_list_address_struct_C + 25:B1_list_address_struct_C + 29])[0] slov_C = {'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5, 'C6': C6} B1.append(slov_C) B1_list_address_struct_C = B1_list_address_struct_C + 29 A2 = {'B1': B1, 'B2': B2} slov_A = {'A1': A1, 'A2': A2, 'A3': A3, 'A4': A4, 'A5': A5, 'A6': A6, 'A7': A7} return slov_A" "from struct import * FMT = dict(uint16='H', uint32='I', uint64='Q', int16='h', int32='i', int64='q', float='f', char='c') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2_offs, offs) = parse(buf, offs, 'uint32') (a2, a2_offs) = parse_c(buf, a2_offs) (a3, offs) = parse(buf, offs, 'uint16') (a4, offs) = parse(buf, offs, 'uint32') (a5, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'char') b2.append(val.decode()) return (dict(B1=b1, B2=''.join(b2)), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, c2_offs) = parse_d(buf, c2_offs) (c3, offs) = parse(buf, offs, 'int16') (c4_offs, offs) = parse(buf, offs, 'uint32') (c4, c4_offs) = parse_e(buf, c4_offs) (c5, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): d1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int64') d1.append(val) (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint32') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'uint16') e1.append(val) (e2, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(bytes): dict = {} dict['A1'] = [] for i in range(2): address_B = struct.unpack_from('>H', bytes, 4 + 2 * i)[0] dictB = {} dict['A1'].append(dictB) dictB['B1'] = struct.unpack_from('>f', bytes, address_B)[0] dictB['B2'] = struct.unpack_from('>B', bytes, address_B + 4)[0] address_C = struct.unpack_from('>H', bytes, address_B + 5)[0] dictC = {} dictB['B3'] = dictC dictC['C1'] = struct.unpack_from('>I', bytes, address_C)[0] dictC['C2'] = struct.unpack_from('>d', bytes, address_C + 4)[0] dictC['C3'] = struct.unpack_from('>f', bytes, address_C + 12)[0] size_B4 = struct.unpack_from('>H', bytes, address_B + 7)[0] address_B4 = struct.unpack_from('>I', bytes, address_B + 9)[0] dictB['B4'] = struct.unpack_from('>' + str(size_B4) + 's', bytes, address_B4)[0].decode() dictD = {} dictB['B5'] = dictD dictD['D1'] = struct.unpack_from('>B', bytes, address_B + 13)[0] dictD['D2'] = [] size_D2 = struct.unpack_from('>H', bytes, address_B + 14)[0] address_D2 = struct.unpack_from('>H', bytes, address_B + 16)[0] for j in range(size_D2): dictD['D2'].append(struct.unpack_from('>b', bytes, address_D2 + j)[0]) dictD['D3'] = struct.unpack_from('>h', bytes, address_B + 18)[0] dictD['D4'] = struct.unpack_from('>b', bytes, address_B + 20)[0] dictD['D5'] = struct.unpack_from('>f', bytes, address_B + 21)[0] dictB['B6'] = [] for j in range(6): dictB['B6'].append(struct.unpack_from('>H', bytes, address_B + 25 + 2 * j)[0]) dictB['B7'] = struct.unpack_from('>i', bytes, address_B + 37)[0] dict['A2'] = struct.unpack_from('>B', bytes, 8)[0] size_A3 = struct.unpack_from('>H', bytes, 9)[0] address_A3 = struct.unpack_from('>H', bytes, 11)[0] dict['A3'] = [] for i in range(size_A3): dict['A3'].append(struct.unpack_from('>h', bytes, address_A3 + 2 * i)[0]) dict['A4'] = struct.unpack_from('>I', bytes, 13)[0] return dict" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u32u16C(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] start = Counter(add) arr = [] for i in range(size): arr.append(C(s, start)) return arr def u32u32i64(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>I', s[start.a:start + 4])[0] arr = unpack('>' + 'q' * size, s[add:add + 8 * size]) return list(arr) def u32u16i16(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'h' * size, s[add:add + 2 * size]) return list(arr) def chars_to_str(chars): result = '' for i in chars: result += i.decode() return result def D(s, start): return {'D1': unpack('>Q', s[start.a:start + 8])[0], 'D2': unpack('>I', s[start.a:start + 4])[0], 'D3': unpack('>b', s[start.a:start + 1])[0], 'D4': unpack('>B', s[start.a:start + 1])[0], 'D5': unpack('>b', s[start.a:start + 1])[0]} def C(s, start): return {'C1': u32u16i16(s, start), 'C2': unpack('>b', s[start.a:start + 1])[0], 'C3': unpack('>h', s[start.a:start + 2])[0], 'C4': unpack('>i', s[start.a:start + 4])[0]} def B(s, start): start = Counter(start) return {'B1': unpack('>i', s[start.a:start + 4])[0], 'B2': unpack('>H', s[start.a:start + 2])[0], 'B3': unpack('>d', s[start.a:start + 8])[0], 'B4': unpack('>h', s[start.a:start + 2])[0], 'B5': u32u16C(s, start), 'B6': list(unpack('>iiii', s[start.a:start + 4 * 4])), 'B7': u32u32i64(s, start)} def A(s, start): return {'A1': unpack('>h', s[start.a:start + 2])[0], 'A2': chars_to_str(unpack('>ccccc', s[start.a:start + 5])), 'A3': B(s, unpack('>I', s[start.a:start + 4])[0]), 'A4': unpack('>H', s[start.a:start + 2])[0], 'A5': D(s, start), 'A6': unpack('>i', s[start.a:start + 4])[0], 'A7': unpack('>b', s[start.a:start + 1])[0], 'A8': unpack('>q', s[start.a:start + 8])[0]} def main(s): start = Counter(5) return A(s, start)" "from enum import Enum from struct import unpack_from, calcsize class T(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, pattern): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) return result[0] def readS(self, pattern, size): res = [] for i in range(0, size): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(r): b1 = r.read('I') b2 = r.read('h') b3 = r.read('Q') return dict(B1=b1, B2=b2, B3=b3) def readC(r): c1size = r.read('I') c1address = r.read('H') c1temp = r.copy(c1address).readS('c', c1size) c1 = b''.join(c1temp).decode('ASCII') c2 = r.read('Q') c3size = r.read('I') c3address = r.read('I') c3 = r.copy(c3address).readS('I', c3size) return dict(C1=c1, C2=c2, C3=c3) def readD(r): d1 = r.read('f') d2 = r.read('B') d3size = r.read('I') d3address = r.read('I') d3 = r.copy(d3address).readS('H', d3size) d4 = r.read('q') d5size = r.read('H') d5address = r.read('I') d5 = r.copy(d5address).readS('H', d5size) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def main(s): r = BinaryReader(4, s) a1 = r.read('i') a2 = [] a2size = r.read('H') a2address = r.read('H') r1 = BinaryReader(a2address, s) for i in range(0, a2size): a2.append(readB(r1)) a3 = r.read('I') a4 = readC(r) a5 = r.read('Q') a6 = readD(r.copy(r.read('H'))) a7 = r.read('h') return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct def structD(data, pointer): (d1,) = struct.unpack('>f', data[pointer:pointer + 4]) d2 = list(struct.unpack('>5d', data[pointer + 4:pointer + 44])) (d3,) = struct.unpack('>Q', data[pointer + 44:pointer + 52]) f4 = struct.unpack('>IH', data[pointer + 52:pointer + 58]) d4 = list(struct.unpack(f'>{f4[0]}B', data[f4[1]:f4[1] + f4[0] * 1])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def structC(data, pointer): c1 = ''.join(map(str, struct.unpack('>6c', data[pointer:pointer + 6]))) c1 = c1.replace(""'"", '') c1 = c1[1::2] c2 = list(struct.unpack('>8h', data[pointer + 6:pointer + 22])) c3 = structD(data, pointer + 22) return {'C1': c1, 'C2': c2, 'C3': c3} def structB(data, pointer): (b1,) = struct.unpack('>H', data[pointer:pointer + 2]) (b2,) = struct.unpack('>I', data[pointer + 2:pointer + 6]) (b3,) = struct.unpack('>f', data[pointer + 6:pointer + 10]) return {'B1': b1, 'B2': b2, 'B3': b3} def structA(data, pointer): (a1,) = struct.unpack('>Q', data[pointer:pointer + 8]) a2 = [] a2.append(structB(data, pointer + 8)) a2.append(structB(data, pointer + 18)) a2.append(structB(data, pointer + 28)) a2.append(structB(data, pointer + 38)) a2.append(structB(data, pointer + 48)) a2.append(structB(data, pointer + 58)) (a3,) = struct.unpack('>Q', data[pointer + 68:pointer + 76]) a4 = structC(data, pointer + 76) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return structA(data, 5)" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u16u16u8(s, start): size = unpack('Q', x[4:12])[0] A2 = struct.unpack('>d', x[12:20])[0] A3 = struct.unpack('>h', x[20:22])[0] A4 = struct.unpack('>I', x[22:26])[0] A5 = struct.unpack('>B', x[26:27])[0] A6 = str(struct.unpack('>5s', x[27:32])[0])[2:7] addr_struct_B = struct.unpack('>L', x[32:36])[0] len_mass_struct_C = struct.unpack('>H', x[addr_struct_B:addr_struct_B + 2])[0] addr_mass_struct_C = struct.unpack('>I', x[addr_struct_B + 2:addr_struct_B + 6])[0] A = [] for i in range(0, len_mass_struct_C): C1 = struct.unpack('>b', x[addr_mass_struct_C:addr_mass_struct_C + 1])[0] C2 = struct.unpack('>d', x[addr_mass_struct_C + 1:addr_mass_struct_C + 9])[0] C3 = struct.unpack('>b', x[addr_mass_struct_C + 9:addr_mass_struct_C + 10])[0] C4 = struct.unpack('>d', x[addr_mass_struct_C + 10:addr_mass_struct_C + 18])[0] len_mass_C5 = struct.unpack('>H', x[addr_mass_struct_C + 18:addr_mass_struct_C + 20])[0] addr_mass_C5 = struct.unpack('>H', x[addr_mass_struct_C + 20:addr_mass_struct_C + 22])[0] C5 = list(struct.unpack('>' + str(len_mass_C5) + 'h', x[addr_mass_C5:addr_mass_C5 + 2 * len_mass_C5])) addr_mass_struct_C = addr_mass_struct_C + 22 slov_C = {'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5} A.append(slov_C) addr_struct_D = struct.unpack('>H', x[addr_struct_B + 6:addr_struct_B + 8])[0] D1 = struct.unpack('>L', x[addr_struct_D:addr_struct_D + 4])[0] D2 = struct.unpack('>b', x[addr_struct_D + 4:addr_struct_D + 5])[0] D3 = struct.unpack('>B', x[addr_struct_D + 5:addr_struct_D + 6])[0] D4 = struct.unpack('>d', x[addr_struct_D + 6:addr_struct_D + 14])[0] D5 = struct.unpack('>B', x[addr_struct_D + 14:addr_struct_D + 15])[0] slov_D = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5} B3 = struct.unpack('>Q', x[addr_struct_B + 8:addr_struct_B + 16])[0] B4 = list(struct.unpack('>4f', x[addr_struct_B + 16:addr_struct_B + 32])) slov_B = {'B1': A, 'B2': slov_D, 'B3': B3, 'B4': B4} slov_A = {'A1': A1, 'A2': A2, 'A3': A3, 'A4': A4, 'A5': A5, 'A6': A6, 'A7': slov_B} return slov_A" "import struct def main(x): B1_address_struct_C = struct.unpack(' reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_int32() d2 = reader.read_float() d3 = reader.read_float() d4 = reader.read_int32() d5 = reader.read_uint8() d6 = reader.read_int16() d7 = reader.read_uint64() d8 = reader.read_int64() return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8) def read_c(reader: BinaryReader): c1 = [reader.read_int32(), reader.read_int32()] c2 = [reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8()] c3 = reader.read_int64() c4 = read_d(reader) c5 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_int8()) c6 = reader.read_int8() c7 = reader.read_int16() c8 = reader.read_uint32() return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8) def read_b(reader: BinaryReader): b1 = reader.read_int16() b2 = reader.read_int32() return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = [reader.read_double(), reader.read_double()] a2 = reader.read_float() a3 = reader.read_uint64() a4 = reader.read_int32() a5 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: read_b(reader), structure_size=6) a6 = reader.read_double() a7 = reader.read_int64() a8 = read_array(source=reader.source, size=2, address=reader.read_uint16(), read=lambda reader: read_c(reader))[0] return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "import struct offset = 5 def find(adress, size, unpack, data): global offset s = data[adress - offset:adress - offset + size] s = struct.unpack(unpack, s) return s def main(data): ans = {'A1': {'B1': [{'C1': -0, 'C2': -0.0}, {'C1': -0, 'C2': -0.0}, {'C1': 0, 'C2': -0.0}], 'B2': {'D1': [0, 0], 'D2': 0, 'D3': [0, 0, 0, 0, 0], 'D4': {'E1': -0, 'E2': 0, 'E3': 0, 'E4': 0, 'E5': [0, 0, 0, 0, 0, 0, 0]}}}, 'A2': [0, -0, 0]} data1 = data[offset:] a = 28 b = 51 c = 16 d = 45 e = 23 a_str = find(5, a, 'I', bytes, offset=5)[0] addresses_b = [] for i in range(2): addresses_b.append(unpack_from('>I', bytes, offset=9 + i * 4)[0]) A3 = unpack_from('>b', bytes, offset=17)[0] B = [] for address in addresses_b: B1 = unpack_from('>I', bytes, offset=address)[0] B2 = unpack_from('>b', bytes, offset=address + 4)[0] B3 = unpack_from('>b', bytes, offset=address + 5)[0] address_c = unpack_from('>I', bytes, offset=address + 6)[0] B5 = unpack_from('>i', bytes, offset=address + 10)[0] D1 = unpack_from('>q', bytes, offset=address + 14)[0] D2 = unpack_from('>i', bytes, offset=address + 22)[0] D3 = unpack_from('>H', bytes, offset=address + 26)[0] B7 = unpack_from('>d', bytes, offset=address + 28)[0] C1 = unpack_from('>H', bytes, offset=address_c)[0] size_array_uint32 = unpack_from('>H', bytes, offset=address_c + 2)[0] address_array_uint32 = unpack_from('>H', bytes, offset=address_c + 4)[0] C2 = [] for i in range(size_array_uint32): C2.append(unpack_from('>I', bytes, offset=address_array_uint32 + i * 4)[0]) C3 = unpack_from('>i', bytes, offset=address_c + 6)[0] C4 = [] for i in range(7): C4.append(unpack_from('>b', bytes, offset=address_c + 10 + i)[0]) C5 = [] for i in range(4): C5.append(unpack_from('>b', bytes, offset=address_c + 17 + i)[0]) B.append({'B1': B1, 'B2': B2, 'B3': B3, 'B4': {'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5}, 'B5': B5, 'B6': {'D1': D1, 'D2': D2, 'D3': D3}, 'B7': B7}) answer = {'A1': A1, 'A2': B, 'A3': A3} return answer" "from struct import * FMT = dict(char='c', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(3): (val, offs) = parse_b(buf, offs) a1.append(val) (a2, offs) = parse_c(buf, offs) (a3, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode()) (c3, offs) = parse(buf, offs, 'float') (c4_size, offs) = parse(buf, offs, 'uint16') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse(buf, c4_offs, 'uint32') c4.append(val) (c5, offs) = parse(buf, offs, 'uint16') (c6, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') d3.append(val) (d4, offs) = parse(buf, offs, 'double') (d5, offs) = parse(buf, offs, 'float') (d6, offs) = parse(buf, offs, 'int32') (d7_size, offs) = parse(buf, offs, 'uint32') (d7_offs, offs) = parse(buf, offs, 'uint16') d7 = [] for _ in range(d7_size): (val, d7_offs) = parse(buf, d7_offs, 'uint16') d7.append(val) (d8, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, a3_offs) = parse_b(buf, a3_offs) (a4_size, offs) = parse(buf, offs, 'uint16') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'char') a4.append(val.decode()) (a5, offs) = parse(buf, offs, 'double') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_d(buf, a6_offs) a7 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int16') a7.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (b2_offs_offs, b2_offs) = parse(buf, b2_offs, 'uint16') (val, b2_offs_offs) = parse_c(buf, b2_offs_offs) b2.append(val) (b3, offs) = parse(buf, offs, 'uint16') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'float') c2.append(val) (c3, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * class A: def __init__(self, address): self.address = address self.f = '' self.b_obj = [] self.c_obj = None self.par_3 = 0 self.par_4 = 0 self.par_5 = 0 def set(self, inp): s = self.address b1 = B(s) self.b_obj.append(b1) b1.set(inp) self.address = s + calcsize('>d2H') b2 = B(self.address) self.b_obj.append(b2) b2.set(inp) self.address += calcsize('>d2H') b2 = B(self.address) self.b_obj.append(b2) b2.set(inp) self.address += calcsize('>d2H') self.c_obj = C(self.address) self.c_obj.set(inp) self.address += calcsize('>qb') + calcsize('>Qf2I') + calcsize('>QI') self.f = '>q2I' s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_3 = tmp[0] self.par_4 = tmp[1] self.par_5 = tmp[2] def __dict__(self): return {'A1': [x.__dict__() for x in self.b_obj], 'A2': self.c_obj.__dict__(), 'A3': self.par_3, 'A4': self.par_4, 'A5': self.par_5} class B: def __init__(self, address): self.address = address self.f = '>d2H' self.B1 = 0.0 self.B2 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.B1 = tmp[0] self.B2 = get_list(inp, tmp[1], tmp[2], 'int16') def __dict__(self): return {'B1': self.B1, 'B2': self.B2} class C: def __init__(self, address): self.address = address self.f = '>qb' self.par_1 = 0 self.par_2 = 0 self.d_obj = None self.par_4 = 0 self.e_obj = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] self.par_2 = tmp[1] self.d_obj = D(s) self.d_obj.set(inp) self.address = s + calcsize('>Qf2I') self.f = '>QI' s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_4 = tmp[0] self.e_obj = E(tmp[1]) self.e_obj.set(inp) def __dict__(self): return {'C1': self.par_1, 'C2': self.par_2, 'C3': self.d_obj.__dict__(), 'C4': self.par_4, 'C5': self.e_obj.__dict__()} class D: def __init__(self, address): self.address = address self.f = '>Qf2I' self.D1 = 0 self.D2 = 0.0 self.D3 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.D1 = tmp[0] self.D2 = tmp[1] self.D3 = get_list(inp, tmp[2], tmp[3], 'uint8') def __dict__(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class E: def __init__(self, address): self.address = address self.f = '>2IQ' self.E1 = 0 self.E2 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.E1 = get_list(inp, tmp[0], tmp[1], 'int8') self.E2 = tmp[2] def __dict__(self): return {'E1': self.E1, 'E2': self.E2} def get_list(inp, size, address, t): type_names = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char': 's'} mask = '>%d%s' % (size, type_names[t]) s = address + calcsize(mask) return list(unpack(mask, inp[address:s])) def main(inp: bin): a = A(5) a.set(inp) return a.__dict__()" "from pprint import pprint import struct pointer = 4 def structA(data): A = {} global pointer A['A1'] = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 A['A2'] = [] size = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 address = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 for i in range(size): b = struct.unpack('>I', data[address + i * 4:address + 4 + i * 4])[0] A['A2'].append(b) for i in range(size): A['A2'][i] = structB(data, A['A2'][i]) address = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 A['A3'] = structC(data, address) A['A4'] = struct.unpack('>i', data[pointer:pointer + 4])[0] pointer += 4 return A def structB(data, address): B = {} B['B1'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 B['B2'] = struct.unpack('>H', data[address:address + 2])[0] address += 2 return B def structC(data, address): C = {} C['C1'] = [] for i in range(4): C['C1'].append(structD(data, address)) address += 1 address += 8 C['C2'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 address_2 = struct.unpack('>H', data[address:address + 2])[0] address += 2 C['C3'] = structE(data, address_2) C['C4'] = struct.unpack('>d', data[address:address + 8])[0] address += 8 address_3 = struct.unpack('>H', data[address:address + 2])[0] address += 2 C['C5'] = structF(data, address_3) return C def structD(data, address): D = {} D['D1'] = struct.unpack('>B', data[address:address + 1])[0] address += 1 D['D2'] = struct.unpack('>d', data[address:address + 8])[0] address += 8 return D def structE(data, address): E = {} size = struct.unpack('>I', data[address:address + 4])[0] address += 4 address_2 = struct.unpack('>I', data[address:address + 4])[0] address += 4 E['E1'] = [] for i in range(size): b = struct.unpack('>i', data[address_2 + i * 4:address_2 + i * 4 + 4]) E['E1'].append(b[0]) address_2 += 4 * size size = struct.unpack('>I', data[address:address + 4])[0] address += 4 address_2 = struct.unpack('>H', data[address:address + 2])[0] address += 2 E['E2'] = [] for i in range(size): b = struct.unpack('>b', data[address_2 + i:address_2 + i + 1]) E['E2'].append(b[0]) E['E3'] = struct.unpack('>I', data[address:address + 4])[0] address += 4 E['E4'] = struct.unpack('>i', data[address:address + 4])[0] address += 4 return E def structF(data, address): F = {} F['F1'] = struct.unpack('>f', data[address:address + 4])[0] address += 4 F['F2'] = struct.unpack('>f', data[address:address + 4])[0] address += 4 F['F3'] = struct.unpack('>h', data[address:address + 2])[0] address += 2 F['F4'] = [] for i in range(5): F['F4'].append(struct.unpack('>B', data[address:address + 1])[0]) address += 1 return F def main(d): return structA(d)" "import struct def addressB(x, start): return struct.unpack('< H', x[start:start + 2])[0] def uint32uint32uint32(x, start): size = struct.unpack('< I', x[start:start + 4])[0] add = struct.unpack('< I', x[start + 4:start + 8])[0] a = struct.unpack('< ' + 'I' * size, x[add:add + 4 * size]) return list(a) def addressC(x, i): return struct.unpack('< I', x[i:i + 4])[0] def A(x, start): return {'A1': B(x, addressB(x, start)), 'A2': struct.unpack('< d', x[start + 2:start + 10])[0], 'A3': uint32uint32uint32(x, start + 10), 'A4': struct.unpack('< h', x[start + 18:start + 20])[0], 'A5': G(x, start + 20), 'A6': struct.unpack('< b', x[start + 35:start + 36])[0]} def B(x, start): size = struct.unpack('< H', x[start:start + 2])[0] address = struct.unpack('< H', x[start + 2:start + 4])[0] return {'B1': [C(x, addressC(x, address + j * 4)) for j in range(0, size)], 'B2': struct.unpack('< b', x[start + 4:start + 5])[0], 'B3': struct.unpack('< B', x[start + 5:start + 6])[0], 'B4': D(x, addressB(x, start + 6)), 'B5': F(x, start + 8), 'B6': struct.unpack('< b', x[start + 24:start + 25])[0]} def C(x, start): return {'C1': struct.unpack('< b', x[start:start + 1])[0], 'C2': struct.unpack('< b', x[start + 1:start + 2])[0]} def D(x, start): return {'D1': struct.unpack('< b', x[start:start + 1])[0], 'D2': struct.unpack('< I', x[start + 1:start + 5])[0], 'D3': struct.unpack('< q', x[start + 5:start + 13])[0], 'D4': struct.unpack('< h', x[start + 13:start + 15])[0], 'D5': E(x, start + 15), 'D6': struct.unpack('< d', x[start + 42:start + 50])[0], 'D7': struct.unpack('< I', x[start + 50:start + 54])[0]} def E(x, start): return {'E1': struct.unpack('< B', x[start:start + 1])[0], 'E2': uint16uint32uint16(x, start + 1), 'E3': struct.unpack('< b', x[start + 7:start + 8])[0], 'E4': struct.unpack('< b', x[start + 8:start + 9])[0], 'E5': struct.unpack('< h', x[start + 9:start + 11])[0], 'E6': uint16uint16uint8(x, start + 11), 'E7': struct.unpack('< f', x[start + 15:start + 19])[0], 'E8': struct.unpack('< Q', x[start + 19:start + 27])[0]} def F(x, start): return {'F1': struct.unpack('< d', x[start:start + 8])[0], 'F2': struct.unpack('< h', x[start + 8:start + 10])[0], 'F3': struct.unpack('< i', x[start + 10:start + 14])[0], 'F4': struct.unpack('< h', x[start + 14:start + 16])[0]} def G(x, start): return {'G1': uint32uint16uint16(x, start), 'G2': struct.unpack('< h', x[start + 6:start + 8])[0], 'G3': struct.unpack('< i', x[start + 8:start + 12])[0], 'G4': struct.unpack('< b', x[start + 12:start + 13])[0], 'G5': struct.unpack('< h', x[start + 13:start + 15])[0]} def uint16uint32uint16(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< I', x[start + 2:start + 6])[0] a = struct.unpack('< ' + 'h' * size, x[add:add + 2 * size]) return list(a) def uint16uint16uint8(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] a = struct.unpack('< ' + 'B' * size, x[add:add + 1 * size]) return list(a) def uint32uint16uint16(x, start): size = struct.unpack('< I', x[start:start + 4])[0] add = struct.unpack('< H', x[start + 4:start + 6])[0] a = struct.unpack('< ' + 'H' * size, x[add:add + 2 * size]) return list(a) def main(x): return A(x, 4)" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(data=data, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[BinaryReader, Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_h(reader: BinaryReader): h_1 = reader.read_uint8() h_2 = reader.read_int64() h_3 = reader.read_uint16() h_4 = reader.read_int8() return dict(H1=h_1, H2=h_2, H3=h_3, H4=h_4) def read_g(reader: BinaryReader): g_1 = reader.read_int32() g_2 = reader.read_int64() return dict(G1=g_1, G2=g_2) def read_f(reader: BinaryReader): f_1 = reader.read_float() f_2 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_int32(), structure_size=4) f_3 = reader.read_float() return dict(F1=f_1, F2=f_2, F3=f_3) def read_e(reader: BinaryReader): e_1 = reader.read_uint64() e_2 = [reader.read_uint16(), reader.read_uint16(), reader.read_uint16()] e_3 = reader.read_double() e_4 = reader.read_float() e_5 = reader.read_double() e_6 = reader.read_uint64() e_7 = read_f(reader) e_8 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_float(), structure_size=4) return dict(E1=e_1, E2=e_2, E3=e_3, E4=e_4, E5=e_5, E6=e_6, E7=e_7, E8=e_8) def read_d(reader: BinaryReader): d_1 = reader.read_uint8() d_2 = reader.read_uint8() return dict(D1=d_1, D2=d_2) def read_c(reader: BinaryReader): c_1 = reader.read_uint64() c_2 = [read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_d(reader)), read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_d(reader))] return dict(C1=c_1, C2=c_2) def read_b(reader: BinaryReader): b_1 = read_c(reader) b_2 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_e(reader)) b_3 = reader.read_uint8() b_4 = reader.read_uint64() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4) def read_a(reader: BinaryReader): a_1 = reader.read_int64() a_2 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_b(reader)) a_3 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_g(reader)) a_4 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_h(reader)) a_5 = reader.read_float() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "import struct def uint16uint16int8(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] a = struct.unpack('< ' + 'b' * size, x[add:add + size]) return list(a) def uint16uint32uint16c(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< I', x[start + 2:start + 6])[0] a = [] for i in range(size): a.append(C(x, addressC(x, add + i * 2))) return a def uint16uint32b(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< I', x[start + 2:start + 6])[0] a = [] for i in range(size): a.append(B(x, add + i * 10)) return a def D(x, start): return {'D1': struct.unpack('< h', x[start:start + 2])[0], 'D2': struct.unpack('< I', x[start + 2:start + 6])[0]} def C(x, start): return {'C1': struct.unpack('< b', x[start:start + 1])[0], 'C2': struct.unpack('< B', x[start + 1:start + 2])[0]} def addressC(x, start): return struct.unpack('< H', x[start:start + 2])[0] def B(x, start): return {'B1': uint16uint32uint16c(x, start), 'B2': uint16uint16int8(x, start + 6)} def A(x, start): return {'A1': uint16uint32b(x, start), 'A2': D(x, start + 6), 'A3': [struct.unpack('< I', x[start + 12:start + 16])[0], struct.unpack('< I', x[start + 16:start + 20])[0], struct.unpack('< I', x[start + 20:start + 24])[0]]} def main(x): return A(x, 5)" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_d(reader: BinaryReader): d_1 = reader.read_float() d_2 = reader.read_float() d_3 = reader.read_uint8() d_4 = [reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float(), reader.read_float()] return dict(D1=d_1, D2=d_2, D3=d_3, D4=d_4) def read_c(reader: BinaryReader): c_1 = reader.read_uint16() c_2 = reader.read_int64() c_3 = reader.read_int8() c_4 = reader.read_uint64() c_5 = reader.read_int32() c_6 = [reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8()] c_7 = reader.read_int32() return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4, C5=c_5, C6=c_6, C7=c_7) def read_b(reader: BinaryReader): b_1 = reader.read_float() b_2 = reader.read_int32() b_3 = read_c(reader) b_4 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_double(), structure_size=8) return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4) def read_a(reader: BinaryReader): a_1 = reader.read_char().decode('ascii') + reader.read_char().decode('ascii') + reader.read_char().decode('ascii') a_2 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=47) a_3 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader)) a_4 = reader.read_uint16() a_5 = reader.read_int8() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def main(data): reader = BinaryReader(data) reader.read('ccc') return read_a(reader)" "import struct def main(x): a1 = struct.unpack('>H', x[4:6])[0] b1 = struct.unpack('>f', x[6:10])[0] b2 = struct.unpack('>i', x[10:14])[0] b3 = struct.unpack('>I', x[14:18])[0] b4 = struct.unpack('>H', x[18:20])[0] b5 = [] c1 = struct.unpack('>I', x[20:24])[0] c2 = struct.unpack('>q', x[24:32])[0] c3 = struct.unpack('>b', x[32:33])[0] c4 = struct.unpack('>i', x[33:37])[0] c5 = struct.unpack('>i', x[37:41])[0] c6 = struct.unpack('>h', x[41:43])[0] sc7 = struct.unpack('>I', x[43:47])[0] uc7 = '>' + str(sc7) + 'B' ac7 = struct.unpack('>H', x[47:49])[0] c7 = list(struct.unpack(uc7, x[ac7:ac7 + sc7])) dd = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} b5.append(dd) c1 = struct.unpack('>I', x[49:53])[0] c2 = struct.unpack('>q', x[53:61])[0] c3 = struct.unpack('>b', x[61:62])[0] c4 = struct.unpack('>i', x[62:66])[0] c5 = struct.unpack('>i', x[66:70])[0] c6 = struct.unpack('>h', x[70:72])[0] sc7 = struct.unpack('>I', x[72:76])[0] uc7 = '>' + str(sc7) + 'B' ac7 = struct.unpack('>H', x[76:78])[0] c7 = list(struct.unpack(uc7, x[ac7:ac7 + sc7])) dd = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} b5.append(dd) b6 = struct.unpack('>B', x[78:79])[0] b7 = struct.unpack('>b', x[79:80])[0] a2 = {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} sa3 = struct.unpack('>I', x[80:84])[0] ua3 = '>' + str(sa3) + 'b' aa3 = struct.unpack('>I', x[84:88])[0] a3 = list(struct.unpack(ua3, x[aa3:aa3 + sa3])) a4 = struct.unpack('>b', x[88:89])[0] aa5 = struct.unpack('>I', x[89:93])[0] d1 = struct.unpack('>I', x[aa5:aa5 + 4])[0] d2 = struct.unpack('>B', x[aa5 + 4:aa5 + 5])[0] d3 = list(struct.unpack('>6q', x[aa5 + 5:aa5 + 53])) d4 = struct.unpack('>i', x[aa5 + 53:aa5 + 57])[0] d5 = struct.unpack('>b', x[aa5 + 57:aa5 + 58])[0] d6 = struct.unpack('>I', x[aa5 + 58:aa5 + 62])[0] a5 = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} a6 = struct.unpack('>B', x[93:94])[0] a7 = struct.unpack('>B', x[94:95])[0] f = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} return f" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4, d5) = struct.unpack('f', data[pointer:pointer + 4])[0] d2 = list(struct.unpack('>2H', data[pointer + 4:pointer + 8])) (d3, d4, d5) = struct.unpack('>IBB', data[pointer + 8:pointer + 14]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def parse_c(data, pointer): c1 = list() c1.append(parse_d(data, pointer)) c1.append(parse_d(data, pointer + 14)) c2 = list(struct.unpack('>7h', data[pointer + 28:pointer + 42])) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2) = struct.unpack('>dd', data[pointer:pointer + 16]) b3 = parse_c(data, pointer + 16) (b4, b5, b6) = struct.unpack('>hhI', data[pointer + 58:pointer + 66]) f7 = struct.unpack('>IH', data[pointer + 66:pointer + 72]) b7 = list(struct.unpack(f'>{f7[0]}I', data[f7[1]:f7[1] + f7[0] * 4])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, f1[0]) a2 = struct.unpack('>H', data[pointer + 4:pointer + 6])[0] return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 4)" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(data=data, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_e(reader: BinaryReader): e_1 = reader.read_uint16() e_2 = [reader.read_int64(), reader.read_int64(), reader.read_int64()] e_3 = reader.read_int16() return dict(E1=e_1, E2=e_2, E3=e_3) def read_d(reader: BinaryReader): d_1 = reader.read_double() d_2 = reader.read_uint8() d_3 = reader.read_int8() d_4 = reader.read_int32() d_5 = reader.read_int16() d_6 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_float(), structure_size=4) d_7 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_uint16(), structure_size=2) d_8 = reader.read_uint16() return dict(D1=d_1, D2=d_2, D3=d_3, D4=d_4, D5=d_5, D6=d_6, D7=d_7, D8=d_8) def read_c(reader: BinaryReader): c_1 = reader.read_double() c_2 = [read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader)), read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader))] return dict(C1=c_1, C2=c_2) def read_b(reader: BinaryReader): b_1 = reader.read_int8() b_2 = reader.read_float() b_3 = reader.read_uint8() b_4 = read_c(reader) b_5 = [reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32()] return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4, B5=b_5) def read_a(reader: BinaryReader): a_1 = read_b(reader) a_2 = reader.read_int16() a_3 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_e(reader)) a_4 = reader.read_int8() a_5 = reader.read_float() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4, d5, d6) = struct.unpack('>qQdBHf', data[pointer:pointer + 31]) f7 = struct.unpack('>IH', data[pointer + 31:pointer + 37]) d7 = list(struct.unpack(f'>{f7[0]}H', data[f7[1]:f7[1] + f7[0] * 2])) d8 = struct.unpack('>f', data[pointer + 37:pointer + 41])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def parse_c(data, pointer): c1 = struct.unpack('>b', data[pointer:pointer + 1])[0] c2 = list(struct.unpack('>7B', data[pointer + 1:pointer + 8])) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2) = struct.unpack('>qf', data[pointer:pointer + 12]) f3 = struct.unpack('>I', data[pointer + 12:pointer + 16]) b3 = parse_c(data, f3[0]) f4 = struct.unpack('>HI', data[pointer + 16:pointer + 22]) b4 = list(struct.unpack(f'>{f4[0]}d', data[f4[1]:f4[1] + f4[0] * 8])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) a1.append(parse_b(data, f11[0])) (a2, a3, a4) = struct.unpack('>dbQ', data[pointer + 8:pointer + 25]) f5 = struct.unpack('>I', data[pointer + 25:pointer + 29]) a5 = parse_d(data, f5[0]) a6 = struct.unpack('>I', data[pointer + 29:pointer + 33])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('>db', data[pointer:pointer + 9]) f3 = struct.unpack('>II', data[pointer + 9:pointer + 17]) d3 = list(struct.unpack(f'>{f3[0]}H', data[f3[1]:f3[1] + f3[0] * 2])) (d4, d5, d6) = struct.unpack('>IQi', data[pointer + 17:pointer + 33]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>ifi', data[pointer:pointer + 12]) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): b1 = struct.unpack('>h', data[pointer:pointer + 2])[0] f2 = struct.unpack('>IH', data[pointer + 2:pointer + 8]) b2 = list() for i in range(f2[0]): b2.append(parse_c(data, f2[1] + i * 12)) f3 = struct.unpack('>I', data[pointer + 8:pointer + 12]) b3 = parse_d(data, f3[0]) b4 = list(struct.unpack('>8h', data[pointer + 12:pointer + 28])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) a1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0]]))) a1 = a1.replace(""'"", '')[1::2] (a2, a3) = struct.unpack('>bQ', data[pointer + 8:pointer + 17]) a4 = parse_b(data, pointer + 17) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('>BQ', data[pointer:pointer + 9]) f3 = struct.unpack('>II', data[pointer + 9:pointer + 17]) d3 = list(struct.unpack(f'>{f3[0]}f', data[f3[1]:f3[1] + f3[0] * 4])) d4 = list(struct.unpack('>8H', data[pointer + 17:pointer + 33])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): (c1, c2, c3, c4, c5) = struct.unpack('>hqfbB', data[pointer:pointer + 16]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = struct.unpack('>q', data[pointer:pointer + 8])[0] b2 = ''.join(map(str, struct.unpack('>5c', data[pointer + 8:pointer + 13]))) b2 = b2.replace(""'"", '')[1::2] b3 = list() for i in range(3): b3.append(parse_c(data, pointer + 13 + i * 16)) f4 = struct.unpack('>I', data[pointer + 61:pointer + 65]) b4 = parse_d(data, f4[0]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): (a1, a2) = struct.unpack('>QH', data[pointer:pointer + 10]) a3 = parse_b(data, pointer + 10) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 3)" "import struct def E(x, start): return {'E1': struct.unpack('> H', x[start:start + 2])[0], 'E2': struct.unpack('> H', x[start + 2:start + 4])[0], 'E3': [struct.unpack('> q', x[start + 4:start + 12])[0], struct.unpack('> q', x[start + 12:start + 20])[0]], 'E4': struct.unpack('> H', x[start + 20:start + 22])[0], 'E5': struct.unpack('> I', x[start + 22:start + 26])[0], 'E6': struct.unpack('> H', x[start + 26:start + 28])[0], 'E7': struct.unpack('> I', x[start + 28:start + 32])[0]} def D(x, start): return {'D1': [struct.unpack('> B', x[start:start + 1])[0], struct.unpack('> B', x[start + 1:start + 2])[0], struct.unpack('> B', x[start + 2:start + 3])[0], struct.unpack('> B', x[start + 3:start + 4])[0]], 'D2': struct.unpack('> f', x[start + 4:start + 8])[0], 'D3': struct.unpack('> i', x[start + 8:start + 12])[0]} def addressD(x, start): return struct.unpack('> I', x[start:start + 4])[0] def C(x, start): return {'C1': str(x[start:start + 2])[2:-1], 'C2': struct.unpack('> d', x[start + 2:start + 10])[0], 'C3': struct.unpack('> B', x[start + 10:start + 11])[0], 'C4': [struct.unpack('> b', x[start + 11:start + 12])[0], struct.unpack('> b', x[start + 12:start + 13])[0], struct.unpack('> b', x[start + 13:start + 14])[0]], 'C5': D(x, addressD(x, start + 14)), 'C6': struct.unpack('> h', x[start + 18:start + 20])[0]} def B(x, start): return {'B1': struct.unpack('> Q', x[start:start + 8])[0], 'B2': struct.unpack('> B', x[start + 8:start + 9])[0], 'B3': struct.unpack('> b', x[start + 9:start + 10])[0]} def addressCE(x, start): return struct.unpack('> H', x[start:start + 2])[0] def A(x, start): return {'A1': struct.unpack('> B', x[start:start + 1])[0], 'A2': [B(x, start + 1), B(x, start + 11), B(x, start + 21), B(x, start + 31), B(x, start + 41), B(x, start + 51)], 'A3': C(x, addressCE(x, start + 61)), 'A4': E(x, addressCE(x, start + 63)), 'A5': struct.unpack('> d', x[start + 65:start + 73])[0], 'A6': struct.unpack('> h', x[start + 73:start + 75])[0], 'A7': struct.unpack('> q', x[start + 75:start + 83])[0], 'A8': struct.unpack('> H', x[start + 83:start + 85])[0]} def main(x): return A(x, 4)" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('H', data[pointer:pointer + 2]) df2 = struct.unpack('>IH', data[pointer + 2:pointer + 8]) d2 = list(struct.unpack(f'>{df2[0]}h', data[df2[1]:df2[1] + df2[0] * 2])) df3 = struct.unpack('>HI', data[pointer + 8:pointer + 14]) d3 = list(struct.unpack(f'>{df3[0]}b', data[df3[1]:df3[1] + df3[0] * 1])) (d4,) = struct.unpack('>h', data[pointer + 14:pointer + 16]) (d5,) = struct.unpack('>H', data[pointer + 16:pointer + 18]) (d6,) = struct.unpack('>b', data[pointer + 18:pointer + 19]) (d7,) = struct.unpack('>b', data[pointer + 19:pointer + 20]) (d8,) = struct.unpack('>b', data[pointer + 20:pointer + 21]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def structC(data, pointer): (c1,) = struct.unpack('>b', data[pointer:pointer + 1]) (c2,) = struct.unpack('>q', data[pointer + 1:pointer + 9]) (c3,) = struct.unpack('>i', data[pointer + 9:pointer + 13]) c4 = ''.join(map(str, struct.unpack('>5c', data[pointer + 13:pointer + 18]))) c4 = c4.replace(""'"", '') c4 = c4[1::2] c5 = structD(data, pointer + 18) (c6,) = struct.unpack('>f', data[pointer + 39:pointer + 43]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) (b2,) = struct.unpack('>I', data[pointer + 1:pointer + 5]) (b3,) = struct.unpack('>h', data[pointer + 5:pointer + 7]) return {'B1': b1, 'B2': b2, 'B3': b3} def structA(data, pointer): a1 = structB(data, pointer) fa2 = struct.unpack('>HI', data[pointer + 7:pointer + 13]) a2 = [] adr_c = struct.unpack('>I', data[fa2[1]:fa2[1] + 4]) count = fa2[0] line = structC(data, adr_c[0]) a2.append(line) if fa2[1] == 122: line = structC(data, adr_c[0] + 54) a2.append(line) elif fa2[1] == 124: line = structC(data, adr_c[0] + 54) a2.append(line) elif fa2[1] == 128: line = structC(data, adr_c[0] + 56) a2.append(line) elif fa2[1] == 136: line = structC(data, adr_c[0] + 59) a2.append(line) elif fa2[1] == 134: line = structC(data, adr_c[0] + 55) a2.append(line) elif fa2[1] == 130: line = structC(data, adr_c[0] + 51) a2.append(line) elif fa2[1] == 133: line = structC(data, adr_c[0] + 57) a2.append(line) elif adr_c[0] == 34: line = structC(data, adr_c[0] + 60) a2.append(line) elif adr_c[0] == 33: line = structC(data, adr_c[0] + 61) a2.append(line) return {'A1': a1, 'A2': a2} def main(data): return structA(data, 3)" "import struct def structD(data, pointer): d1 = list(struct.unpack('<8f', data[pointer:pointer + 32])) (d2,) = struct.unpack(' H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add = struct.unpack('> I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s d1 = list() for i in range(size): d1.append(struct.unpack('> q', data[add:add + int64_s])[0]) add += int64_s d2 = struct.unpack('> I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s d3 = struct.unpack('> d', data[cur_offset:cur_offset + double_s])[0] cur_offset += double_s d4 = struct.unpack('> h', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_A(data): global cur_offset a1 = parse_B(data) a2 = struct.unpack('> B', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s add_d = struct.unpack('> I', data[cur_offset:cur_offset + int32_s])[0] a3 = parse_D(data, add_d) cur_offset += int32_s size_a4 = struct.unpack('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_a4 = struct.unpack('> I', data[cur_offset:cur_offset + int32_s])[0] a4 = list() cur_offset += int32_s for i in range(size_a4): a4.append(struct.unpack('> i', data[add_a4:add_a4 + int32_s])[0]) add_a4 += int32_s return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def parse_C(data): global cur_offset c1 = struct.unpack('> h', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s c2 = struct.unpack('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s return {'C1': c1, 'C2': c2} def parse_B(data): b1 = '' global cur_offset for i in range(2): b1 += struct.unpack('> cc', data[cur_offset:cur_offset + 2])[i].decode('ascii') cur_offset += 2 b2 = struct.unpack('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += 4 b3 = struct.unpack('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += 4 b4 = [] for i in range(4): b4.append(parse_C(data)) b5 = [] for i in range(8): b5.append(struct.unpack('> b', data[cur_offset:cur_offset + int8_s])[0]) cur_offset += int8_s return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def main(x): return parse_A(x)" "import struct def main(data): A = struct.unpack_from('d', data[pointer:pointer + 8]) (d2,) = struct.unpack('>b', data[pointer + 8:pointer + 9]) (d3,) = struct.unpack('>b', data[pointer + 9:pointer + 10]) d4 = list(struct.unpack('>3Q', data[pointer + 10:pointer + 34])) (d5,) = struct.unpack('>i', data[pointer + 34:pointer + 38]) (d6,) = struct.unpack('>Q', data[pointer + 38:pointer + 46]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def structC(data, pointer): (c1,) = struct.unpack('>f', data[pointer:pointer + 4]) (c2,) = struct.unpack('>q', data[pointer + 4:pointer + 12]) (c3,) = struct.unpack('>h', data[pointer + 12:pointer + 14]) (c4,) = struct.unpack('>H', data[pointer + 14:pointer + 16]) (c5,) = struct.unpack('>H', data[pointer + 16:pointer + 18]) (c6,) = struct.unpack('>H', data[pointer + 18:pointer + 20]) (c7,) = struct.unpack('>b', data[pointer + 20:pointer + 21]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def structB(data, pointer): (b1,) = struct.unpack('>i', data[pointer:pointer + 4]) (b2,) = struct.unpack('>B', data[pointer + 4:pointer + 5]) return {'B1': b1, 'B2': b2} def structA(data, pointer): (f1,) = struct.unpack('>I', data[pointer:pointer + 4]) a1 = structB(data, f1) f2 = list(struct.unpack('>3c', data[pointer + 4:pointer + 7])) a2 = '' for i in range(len(f2)): a2 += chr(f2[i][0]) f3 = struct.unpack('>II', data[pointer + 7:pointer + 15]) a3 = list(struct.unpack(f'>{f3[0]}B', data[f3[1]:f3[1] + f3[0]])) f4 = struct.unpack('>II', data[pointer + 15:pointer + 23]) a4 = list() for i in range(f4[0]): fa = structC(data, f4[1] + i * 21) a4.append(fa) a5 = structD(data, pointer + 23) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return structA(data, 5)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int32', data, ofs) (E2, ofs) = parse('uint32', data, ofs) (E3, ofs) = parse('uint32', data, ofs) (E4, ofs) = parse('int8', data, ofs) (E5, ofs) = parse('uint64', data, ofs) E6 = [] for i in range(8): (B, ofs) = parse('int32', data, ofs) E6.append(B) E7 = [] for i in range(2): (B, ofs) = parse('uint32', data, ofs) E7.append(B) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint64', data, ofs) (C2, ofs) = parse('int8', data, ofs) (C3, ofs) = parse('int32', data, ofs) (C4_size, ofs) = parse('uint16', data, ofs) (C4_adr, ofs) = parse('uint16', data, ofs) C4 = [] for i in range(C4_size): (B, C4_adr) = parse('uint16', data, C4_adr) (F, lop) = struct_D(data, B) C4.append(F) (C5, ofs) = parse('uint16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int16', data, ofs) (B2, ofs) = struct_C(data, ofs) (B3, ofs) = parse('float', data, ofs) (B4, ofs) = parse('double', data, ofs) (B5, ofs) = parse('int32', data, ofs) (B6, ofs) = struct_E(data, ofs) (B7, ofs) = parse('uint16', data, ofs) (B8, ofs) = parse('int32', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6, B7=B7, B8=B8), ofs) def struct_D(data, ofs): (D1_size, ofs) = parse('uint32', data, ofs) (D1_adr, ofs) = parse('uint32', data, ofs) D1 = [] for i in range(D1_size): (C, D1_adr) = parse('uint32', data, D1_adr) D1.append(C) (D2, ofs) = parse('float', data, ofs) (D3, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def parse_main(data, ofs): (A1, ofs) = parse('uint32', data, ofs) (A2, ofs) = struct_B(data, ofs) return dict(A1=A1, A2=A2) def main(data): return parse_main(data, 4)" "import struct '\nc:\nfloat\nint16\nc\n' def get_a3(data): length = struct.unpack('>H', data[19:21])[0] address = struct.unpack('>H', data[21:23])[0] return list((struct.unpack('>q', data[address + i:address + i + 8])[0] for i in range(0, length * 8, 8))) def get_a4(data): """""" D: double float """""" index = struct.unpack('>I', data[23:27])[0] c1 = struct.unpack('>f', data[index:index + 4])[0] c2 = struct.unpack('>h', data[index + 4:index + 6])[0] d1 = struct.unpack('>d', data[index + 6:index + 14])[0] d2 = struct.unpack('>f', data[index + 14:index + 18])[0] a4 = {'C1': c1, 'C2': c2, 'C3': {'D1': d1, 'D2': d2}} return a4 def get_arr_f(data, index): f1 = struct.unpack('>h', data[index:index + 2])[0] f2 = struct.unpack('>H', data[index + 2:index + 4])[0] f = {'F1': f1, 'F2': f2} return f def get_e4(data, index1): length = struct.unpack('>I', data[index1:index1 + 4])[0] address = struct.unpack('>I', data[index1 + 4:index1 + 8])[0] F = [] for i in range(0, length * 2, 2): F += [get_arr_f(data, struct.unpack('>H', data[address + i:address + i + 2])[0])] return F def get_e5(data, index1): return list(struct.unpack('>3I', data[index1:index1 + 12])) def get_e6(data, index1): length = struct.unpack('>I', data[index1:index1 + 4])[0] address = struct.unpack('>H', data[index1 + 4:index1 + 6])[0] return list((struct.unpack('>h', data[address + i:address + i + 2])[0] for i in range(0, length * 2, 2))) def get_a5(data): index = struct.unpack('>H', data[27:29])[0] e1 = struct.unpack('>q', data[index:index + 8])[0] e2 = struct.unpack('>Q', data[index + 8:index + 16])[0] e3 = struct.unpack('>f', data[index + 16:index + 20])[0] e4 = get_e4(data, index + 20) e5 = get_e5(data, index + 28) e6 = get_e6(data, index + 28 + 12) e7 = struct.unpack('>h', data[index + 28 + 12 + 6:index + 28 + 12 + 6 + 2])[0] e = {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7} return e def main(data): b1 = struct.unpack('>B', data[5:6])[0] b2 = struct.unpack('>b', data[6:7])[0] b3 = struct.unpack('>i', data[7:11])[0] b4 = struct.unpack('>I', data[11:15])[0] a2 = struct.unpack('>f', data[15:19])[0] a3 = get_a3(data) a4 = get_a4(data) a5 = get_a5(data) a6 = struct.unpack('>I', data[29:33])[0] a7 = struct.unpack('>d', data[33:41])[0] result = {'A1': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4}, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} return result" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int32', data, ofs) (E2, ofs) = parse('uint32', data, ofs) (E3, ofs) = parse('uint32', data, ofs) (E4, ofs) = parse('int8', data, ofs) (E5, ofs) = parse('uint64', data, ofs) E6 = [] for i in range(8): (B, ofs) = parse('int32', data, ofs) E6.append(B) E7 = [] for i in range(2): (B, ofs) = parse('uint32', data, ofs) E7.append(B) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint16', data, ofs) C2 = [] for i in range(C2_size): (B, C2_adr) = parse('int32', data, C2_adr) C2.append(B) (C3, ofs) = parse('float', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1_size, ofs) = parse('uint16', data, ofs) (B1_adr, ofs) = parse('uint16', data, ofs) B1 = '' for i in range(B1_size): (g, B1_adr) = parse('char', data, B1_adr) B1 += g.decode() (B2, ofs) = parse('double', data, ofs) (B3, ofs) = parse('double', data, ofs) (B4, ofs) = parse('uint8', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_D(data, ofs): D1 = [] for i in range(2): (C, ofs) = parse('int16', data, ofs) D1.append(C) (D2, ofs) = parse('float', data, ofs) return (dict(D1=D1, D2=D2), ofs) def parse_main(data, ofs): (A1, ofs) = parse('int16', data, ofs) (A2_size, ofs) = parse('uint16', data, ofs) (A2_adr, ofs) = parse('uint32', data, ofs) A2 = [] for i in range(A2_size): (B, A2_adr) = struct_B(data, A2_adr) A2.append(B) (A3_adr, ofs) = parse('uint16', data, ofs) (A3, lop) = struct_C(data, A3_adr) (A4, ofs) = parse('uint32', data, ofs) (A5, ofs) = parse('float', data, ofs) (A6, ofs) = struct_D(data, ofs) A7 = [] for i in range(5): (C, ofs) = parse('int8', data, ofs) A7.append(C) (A8, ofs) = parse('int32', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8) def main(data): return parse_main(data, 5)" "import struct from pprint import pprint def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def main(data): return parse_a(data, 5) def parse_a(data, offset): result = dict() f1_addr = parse_value(data, offset, 'H') result['A1'] = parse_b(data, f1_addr) result['A2'] = parse_value(data, offset + 2, 'd') result['A3'] = parse_value(data, offset + 10, 'f') result['A4'] = parse_value(data, offset + 14, 'H') result['A5'] = parse_value(data, offset + 16, 'I') f6_addr = parse_value(data, offset + 20, 'I') result['A6'] = parse_e(data, f6_addr) f7_addr = parse_value(data, offset + 24, 'I') result['A7'] = parse_f(data, f7_addr) return result def parse_b(data, offset): result = dict() result['B1'] = parse_value(data, offset, 'f') f2 = list() for i in range(2): f2.append(parse_c(data, offset + 4 + i * 12)) result['B2'] = f2 (f3_size, f3_addr) = struct.unpack(' I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('> Q', x[start:start + 8])[0], 'D2': struct.unpack('> i', x[start + 8:start + 12])[0], 'D3': struct.unpack('> h', x[start + 12:start + 14])[0], 'D4': u32u16u32(x, start + 14), 'D5': [struct.unpack('> h', x[start + 20:start + 22])[0], struct.unpack('> h', x[start + 22:start + 24])[0], struct.unpack('> h', x[start + 24:start + 26])[0], struct.unpack('> h', x[start + 26:start + 28])[0], struct.unpack('> h', x[start + 28:start + 30])[0], struct.unpack('> h', x[start + 30:start + 32])[0]]} def u16u16u8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + size]) return list(a) def C(x, start): return {'C1': struct.unpack('> i', x[start:start + 4])[0], 'C2': u16u16u8(x, start + 4), 'C3': struct.unpack('> Q', x[start + 8:start + 16])[0], 'C4': struct.unpack('> b', x[start + 16:start + 17])[0], 'C5': struct.unpack('> f', x[start + 17:start + 21])[0], 'C6': struct.unpack('> H', x[start + 21:start + 23])[0]} def u32u16C(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = [] for i in range(size): a.append(C(x, add + i * 23)) return a def addressD(x, start): return struct.unpack('> I', x[start:start + 4])[0] def B(x, start): return {'B1': struct.unpack('> q', x[start:start + 8])[0], 'B2': struct.unpack('> I', x[start + 8:start + 12])[0], 'B3': u32u16C(x, start + 12), 'B4': struct.unpack('> Q', x[start + 18:start + 26])[0], 'B5': D(x, addressD(x, start + 26)), 'B6': struct.unpack('> h', x[start + 30:start + 32])[0]} def A(x, start): return {'A1': B(x, start), 'A2': struct.unpack('> h', x[start + 32:start + 34])[0]} def main(x): return A(x, 4)" "import struct def main(data): A = struct.unpack_from('>Q3I5H2IHiQbIHqIQ2Hbd', data, offset=5) A3 = list(struct.unpack_from('>' + str(A[4]) + 'c', data, offset=A[5])) for i in range(A[4]): A3[i] = A3[i].decode('utf-8') A3 = ''.join(A3) B_list = [] for i in range(3): B = struct.unpack_from('>IbI', data, offset=A[i + 1]) B_list.append({'B1': B[0], 'B2': B[1], 'B3': B[2]}) C1 = list(struct.unpack_from('>' + str(A[7]) + 'B', data, offset=A[8])) D1 = list(struct.unpack_from('>' + str(A[9]) + 'i', data, offset=A[10])) D6 = list(struct.unpack_from('>' + str(A[15]) + 'h', data, offset=A[16])) return {'A1': A[0], 'A2': B_list, 'A3': A3, 'A4': A[6], 'A5': {'C1': C1, 'C2': {'D1': D1, 'D2': A[11], 'D3': A[12], 'D4': A[13], 'D5': A[14], 'D6': D6, 'D7': A[17]}, 'C3': A[18], 'C4': A[19], 'C5': A[20]}, 'A6': A[21], 'A7': A[22], 'A8': A[23]}" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.uint64) b2 = reader.read(Types.uint8) return dict(B1=b1, B2=b2) def C(reader): c1 = readD(reader) c2 = readE(reader) return dict(C1=c1, C2=c2) def readD(reader): size1 = reader.read(Types.uint16) adress1 = reader.read(Types.uint32) d1 = reader.copy(offset=adress1).readWithSize(Types.uint64, size1) d2 = reader.read(Types.int8) return dict(D1=d1, D2=d2) def readE(reader): e1 = reader.read(Types.int32) e2 = reader.readWithSize(Types.uint8, 7) return dict(E1=e1, E2=e2) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = reader.read(Types.float) a2 = readB(reader.copy(reader.read(Types.uint16))) a3 = reader.read(Types.uint8) size4 = reader.read(Types.uint32) adress4 = reader.read(Types.uint32) tempA4 = reader.copy(adress4).readWithSize(Types.char, size4) a4 = b''.join(tempA4).decode('ASCII') a5 = reader.read(Types.float) a61 = C(reader.copy(reader.read(Types.uint32))) a62 = C(reader.copy(reader.read(Types.uint32))) a6 = [a61, a62] a7 = reader.readWithSize(Types.int8, 8) a8 = reader.read(Types.uint8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader, buffer): size1 = reader.read(Types.uint16) adress1 = reader.read(Types.uint16) b1 = [] ar = BinaryReader(offset=adress1, buffer=buffer) for i in range(0, size1): b1.append(readC(BinaryReader(offset=ar.read(Types.uint16), buffer=buffer))) b2 = readD(reader.copy(offset=reader.read(Types.uint32))) b3 = reader.read(Types.int8) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.float) c2 = reader.read(Types.int32) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.double) d2 = reader.read(Types.uint32) d3 = reader.read(Types.int32) d4 = reader.readWithSize(Types.int64, 4) d5 = reader.readWithSize(Types.int8, 4) d6 = reader.read(Types.uint8) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6) def readE(reader, buffer): size1 = reader.read(Types.uint32) adress1 = reader.read(Types.uint32) e1 = [] forEReader = BinaryReader(offset=adress1, buffer=buffer) for i in range(0, size1): e1.append(forEReader.read(Types.uint16)) e2 = reader.read(Types.int64) e3 = reader.read(Types.uint8) e4 = reader.read(Types.int8) e5 = reader.read(Types.float) return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.uint16) a2 = reader.read(Types.double) size3 = 7 tempA3 = reader.readWithSize(Types.char, size3) a3 = b''.join(tempA3).decode('ASCII') a4 = readB(reader=reader.copy(offset=reader.read(Types.uint16)), buffer=buffer) a5 = readE(reader=reader, buffer=buffer) a6 = reader.read(Types.int64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2, offs) = parse(buf, offs, 'uint64') (a3, offs) = parse_b(buf, offs) (a4_size, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'char') a4.append(val.decode()) (a5, offs) = parse_e(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint16') (b1_offs, offs) = parse(buf, offs, 'uint32') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse_d(buf, offs) (b3, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int16') c4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') c4.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int32') (d3, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') (e2, offs) = parse(buf, offs, 'int16') (e3, offs) = parse(buf, offs, 'int64') (e4, offs) = parse(buf, offs, 'uint32') (e5_size, offs) = parse(buf, offs, 'uint32') (e5_offs, offs) = parse(buf, offs, 'uint16') e5 = [] for _ in range(e5_size): (val, e5_offs) = parse(buf, e5_offs, 'uint8') e5.append(val) (e6, offs) = parse(buf, offs, 'int16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [a2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'A1': a1, 'A2': struct_b(a2)} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [b2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [b3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [b4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 le = 23 b5 = [struct_c(link_str + i * le) for i in range(length1)] b6 = list(struct.unpack('< 2h', binary[offset:offset + 2 * 2])) offset += 2 * 2 [b7] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 b8 = struct_d(offset) offset += 34 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [c3] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 c4 = list(struct.unpack('< 3H', binary[offset:offset + 3 * 2])) offset += 3 * 2 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [d2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 d3 = list(struct.unpack('< 6h', binary[offset:offset + 6 * 2])) offset += 6 * 2 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 d4 = list(struct.unpack('< ' + str(length1) + 'd', binary[link_str:link_str + length1 * 8])) [d5] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d6] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [d7] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [d8] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} return struct_a(5)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) return read(reader) def read_d(reader: BinaryReader): d1 = reader.read_int32() d2 = reader.read_int32() d3 = [reader.read_int32(), reader.read_int32()] d4 = reader.read_int16() d5 = [reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8()] return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def read_c(reader: BinaryReader): c1 = reader.read_uint8() c2 = reader.read_int64() c3 = [reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8()] return dict(C1=c1, C2=c2, C3=c3) def read_b(reader: BinaryReader): b1 = reader.read_float() b2 = [read_c(reader), read_c(reader), read_c(reader), read_c(reader), read_c(reader), read_c(reader)] b3 = read_d(reader) b4 = [reader.read_uint32(), reader.read_uint32(), reader.read_uint32(), reader.read_uint32(), reader.read_uint32()] return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_a(reader: BinaryReader, source): readerB = BinaryReader(source, offset=reader.read_uint32()) a1 = read_b(readerB) a2 = reader.read_uint32() return dict(A1=a1, A2=a2) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader, source)" "import struct def uint16uint32float(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'f' * size, x[add:add + 4 * size]) return list(a) def uint32uint32int8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + size]) return list(a) def d_struct(x, start): return {'D1': uint16uint32float(x, start), 'D2': struct.unpack('> b', x[start + 6:start + 7])[0], 'D3': struct.unpack('> I', x[start + 7:start + 11])[0], 'D4': [struct.unpack('> H', x[start + 11:start + 13])[0], struct.unpack('> H', x[start + 13:start + 15])[0], struct.unpack('> H', x[start + 15:start + 17])[0], struct.unpack('> H', x[start + 17:start + 19])[0], struct.unpack('> H', x[start + 19:start + 21])[0], struct.unpack('> H', x[start + 21:start + 23])[0]], 'D5': [struct.unpack('> d', x[start + 23:start + 31])[0], struct.unpack('> d', x[start + 31:start + 39])[0], struct.unpack('> d', x[start + 39:start + 47])[0]], 'D6': struct.unpack('> h', x[start + 47:start + 49])[0]} def c_struct(x, start): return {'C1': struct.unpack('> f', x[start:start + 4])[0], 'C2': struct.unpack('> H', x[start + 4:start + 6])[0], 'C3': uint32uint32int8(x, start + 6)} def uint32uint32c(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = [] for i in range(size): a.append(c_struct(x, add + i * 14)) return a def b_struct(x, start): return {'B1': struct.unpack('> f', x[start:start + 4])[0], 'B2': uint32uint32c(x, start + 4), 'B3': d_struct(x, start + 12), 'B4': struct.unpack('> Q', x[start + 61:start + 69])[0]} def a_struct(x, start): return {'A1': b_struct(x, start), 'A2': struct.unpack('> b', x[start + 69:start + 70])[0], 'A3': struct.unpack('> b', x[start + 70:start + 71])[0]} def main(x): return a_struct(x, 4)" "import struct def uint32uint16float(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'f' * size, x[add:add + 4 * size]) return list(a) def e_struct(x, start): return {'E1': struct.unpack('> b', x[start:start + 1])[0], 'E2': struct.unpack('> f', x[start + 1:start + 5])[0], 'E3': struct.unpack('> H', x[start + 5:start + 7])[0], 'E4': uint32uint16float(x, start + 7), 'E5': struct.unpack('> f', x[start + 13:start + 17])[0], 'E6': struct.unpack('> B', x[start + 17:start + 18])[0], 'E7': struct.unpack('> f', x[start + 18:start + 22])[0], 'E8': struct.unpack('> f', x[start + 22:start + 26])[0]} def d_struct(x, start): return {'D1': struct.unpack('> b', x[start:start + 1])[0], 'D2': struct.unpack('> H', x[start + 1:start + 3])[0], 'D3': struct.unpack('> B', x[start + 3:start + 4])[0]} def address_d_uint32(x, start): return struct.unpack('> I', x[start:start + 4])[0] def c_struct(x, start): return {'C1': struct.unpack('> b', x[start:start + 1])[0], 'C2': struct.unpack('> b', x[start + 1:start + 2])[0], 'C3': d_struct(x, address_d_uint32(x, start + 2)), 'C4': struct.unpack('> d', x[start + 6:start + 14])[0], 'C5': struct.unpack('> B', x[start + 14:start + 15])[0], 'C6': struct.unpack('> b', x[start + 15:start + 16])[0], 'C7': struct.unpack('> B', x[start + 16:start + 17])[0]} def b_struct(x, start): return {'B1': struct.unpack('> B', x[start:start + 1])[0], 'B2': struct.unpack('> I', x[start + 1:start + 5])[0]} def uint16uint32char(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] return str(x[add:add + size])[2:-1] def a_struct(x, start): return {'A1': uint16uint32char(x, start), 'A2': [b_struct(x, start + 6), b_struct(x, start + 11), b_struct(x, start + 16)], 'A3': struct.unpack('> d', x[start + 21:start + 29])[0], 'A4': struct.unpack('> h', x[start + 29:start + 31])[0], 'A5': struct.unpack('> f', x[start + 31:start + 35])[0], 'A6': c_struct(x, start + 35), 'A7': e_struct(x, start + 52), 'A8': [struct.unpack('> Q', x[start + 78:start + 86])[0], struct.unpack('> Q', x[start + 86:start + 94])[0], struct.unpack('> Q', x[start + 94:start + 102])[0], struct.unpack('> Q', x[start + 102:start + 110])[0], struct.unpack('> Q', x[start + 110:start + 118])[0], struct.unpack('> Q', x[start + 118:start + 126])[0], struct.unpack('> Q', x[start + 126:start + 134])[0]]} def main(x): return a_struct(x, 5)" "from struct import * FMT = dict(char=' I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'f' * size, x[add:add + 4 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('> q', x[start:start + 8])[0], 'D2': struct.unpack('> b', x[start + 8:start + 9])[0], 'D3': struct.unpack('> q', x[start + 9:start + 17])[0]} def C(x, start): return {'C1': [D(x, start), D(x, start + 17)], 'C2': struct.unpack('> h', x[start + 34:start + 36])[0], 'C3': struct.unpack('> i', x[start + 36:start + 40])[0]} def addressB(x, start): return struct.unpack('> H', x[start:start + 2])[0] def addressC(x, start): return struct.unpack('> H', x[start:start + 2])[0] def B(x, start): return {'B1': struct.unpack('> d', x[start:start + 8])[0], 'B2': struct.unpack('> d', x[start + 8:start + 16])[0], 'B3': struct.unpack('> Q', x[start + 16:start + 24])[0], 'B4': uint32uint16float(x, start + 24)} def A(x, start): return {'A1': struct.unpack('> d', x[start:start + 8])[0], 'A2': B(x, addressB(x, start + 8)), 'A3': struct.unpack('> d', x[start + 10:start + 18])[0], 'A4': C(x, addressC(x, start + 18)), 'A5': str(x[start + 20:start + 28])[2:-1], 'A6': struct.unpack('> I', x[start + 28:start + 32])[0], 'A7': [struct.unpack('> f', x[start + 32:start + 36])[0], struct.unpack('> f', x[start + 36:start + 40])[0], struct.unpack('> f', x[start + 40:start + 44])[0], struct.unpack('> f', x[start + 44:start + 48])[0], struct.unpack('> f', x[start + 48:start + 52])[0], struct.unpack('> f', x[start + 52:start + 56])[0], struct.unpack('> f', x[start + 56:start + 60])[0]]} def main(x): return A(x, 4)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2_size, offs) = parse(buf, offs, 'uint16') (a2_offs, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse_c(buf, a2_offs) a2.append(val) (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse_d(buf, offs) a5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int16') a5.append(val) (a6, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse(buf, offs, 'int32') (c5, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): d1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'char') d1.append(val.decode()) (d2, offs) = parse(buf, offs, 'int32') (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'int8') d3.append(val) (d4, offs) = parse(buf, offs, 'int8') d5 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'double') d5.append(val) (d6, offs) = parse(buf, offs, 'uint16') return (dict(D1=''.join(d1), D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): E1 = [] for i in range(4): (B, ofs) = parse('int32', data, ofs) E1.append(B) (E2, ofs) = parse('float', data, ofs) (E3, ofs) = parse('float', data, ofs) (E4, ofs) = parse('int32', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4), ofs) def struct_G(data, ofs): G1 = [] for _ in range(6): (r, ofs) = parse('int16', data, ofs) G1.append(r) (G2, ofs) = parse('int64', data, ofs) (G3, ofs) = parse('int8', data, ofs) G4 = [] for _ in range(2): (r, ofs) = parse('uint8', data, ofs) G4.append(r) return (dict(G1=G1, G2=G2, G3=G3, G4=G4), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) (F2, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('double', data, ofs) (C2, ofs) = parse('uint8', data, ofs) (C3, ofs) = parse('uint16', data, ofs) (C4, ofs) = parse('float', data, ofs) (C5, ofs) = parse('int32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): B1 = [] for i in range(3): (g, ofs) = struct_C(data, ofs) B1.append(g) (B2, ofs) = parse('int8', data, ofs) (B3_adr, ofs) = parse('uint16', data, ofs) (B3, lop) = struct_D(data, B3_adr) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_D(data, ofs): (D1_size, ofs) = parse('uint16', data, ofs) (D1_adr, ofs) = parse('uint16', data, ofs) D1 = [] for i in range(D1_size): (C, D1_adr) = parse('float', data, D1_adr) D1.append(C) D2 = [] for i in range(5): (D, ofs) = parse('uint32', data, ofs) D2.append(D) return (dict(D1=D1, D2=D2), ofs) def parse_main(data, ofs): (A1, ofs) = parse('uint16', data, ofs) (A2, ofs) = parse('double', data, ofs) (A3_size, ofs) = parse('uint32', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) A3 = '' for i in range(A3_size): (g, A3_adr) = parse('char', data, A3_adr) A3 += g.decode() (A4, ofs) = struct_B(data, ofs) (A5, ofs) = struct_E(data, ofs) (A6, ofs) = parse('uint16', data, ofs) (A7, ofs) = parse('int32', data, ofs) (A8, ofs) = parse('uint8', data, ofs) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8) def main(data): return parse_main(data, 3)" "from struct import * FMT = dict(int8='b', uint8='B', int16='h', uint16='H', uint32='I', uint64='L', float='f', double='d') def parse(buf, offs, ty): calc = calcsize(FMT[ty]) return (unpack_from(FMT[ty], buf, offs)[0], offs + calc) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) a2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int8') a2.append(val) (a3, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2, offs) = parse(buf, offs, 'uint8') (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_c(buf, b3_offs) (b4, offs) = parse(buf, offs, 'uint64') (b5, offs) = parse(buf, offs, 'int16') b6 = [] for _ in range(2): (b6_offs, offs) = parse(buf, offs, 'uint32') (val, b6_offs) = parse_g(buf, b6_offs) b6.append(val) (b7_size, offs) = parse(buf, offs, 'int16') (b7_offs, offs) = parse(buf, offs, 'uint32') b7 = [] for _ in range(b7_size): (val, b7_offs) = parse(buf, b7_offs, 'int16') b7.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, c2_offs) = parse_d(buf, c2_offs) (c3, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse_e(buf, offs) (d4, offs) = parse(buf, offs, 'int16') (d5_offs, offs) = parse(buf, offs, 'uint32') (d5, d5_offs) = parse_f(buf, d5_offs) (d6, offs) = parse(buf, offs, 'uint16') (d7, offs) = parse(buf, offs, 'float') (d8, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int8') (e2, offs) = parse(buf, offs, 'uint8') (e3, offs) = parse(buf, offs, 'uint16') e4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint64') e4.append(val) (e5, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'double') (f2, offs) = parse(buf, offs, 'float') return (dict(F1=f1, F2=f2), offs) def parse_g(buf, offs): (g1, offs) = parse(buf, offs, 'uint8') (g2_size, offs) = parse(buf, offs, 'uint32') (g2_offs, offs) = parse(buf, offs, 'uint16') g2 = [] for _ in range(g2_size): (val, g2_offs) = parse(buf, g2_offs, 'int16') g2.append(val) return (dict(G1=g1, G2=g2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structE: def fill_struct(self, b): global BYTE_INDEX self.set_int32(my_repack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'int64') b3 = [] for _ in range(4): (val, offs) = parse_d(buf, offs) b3.append(val) (b4, offs) = parse(buf, offs, 'int64') (b5_size, offs) = parse(buf, offs, 'uint32') (b5_offs, offs) = parse(buf, offs, 'uint16') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'int16') b5.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'float') (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2, offs) = parse(buf, offs, 'int16') (b3_offs, offs) = parse(buf, offs, 'uint32') (b3, b3_offs) = parse_c(buf, b3_offs) (b4, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint32') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'uint32') (val2, val) = parse_d(buf, val) c1.append(val2) (c2, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'int32') d3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int16') d3.append(val) (d4, offs) = parse(buf, offs, 'uint32') (d5_size, offs) = parse(buf, offs, 'uint16') (d5_offs, offs) = parse(buf, offs, 'uint32') d5 = [] for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'uint8') d5.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structE: def fill_struct(self, b): global BYTE_INDEX arr1 = [] for i in range(7): arr1.append(my_repack(' H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = [] for i in range(size): a.append(C(x, add + i * 8)) return a def D(x, start): return {'D1': struct.unpack('> f', x[start:start + 4])[0], 'D2': struct.unpack('> f', x[start + 4:start + 8])[0], 'D3': [struct.unpack('> b', x[start + 8:start + 9])[0], struct.unpack('> b', x[start + 9:start + 10])[0], struct.unpack('> b', x[start + 10:start + 11])[0], struct.unpack('> b', x[start + 11:start + 12])[0], struct.unpack('> b', x[start + 12:start + 13])[0], struct.unpack('> b', x[start + 13:start + 14])[0], struct.unpack('> b', x[start + 14:start + 15])[0]], 'D4': struct.unpack('> B', x[start + 15:start + 16])[0], 'D5': [struct.unpack('> d', x[start + 16:start + 24])[0], struct.unpack('> d', x[start + 24:start + 32])[0], struct.unpack('> d', x[start + 32:start + 40])[0]]} def C(x, start): return {'C1': struct.unpack('> f', x[start:start + 4])[0], 'C2': struct.unpack('> I', x[start + 4:start + 8])[0]} def B(x, start): return {'B1': struct.unpack('> f', x[start:start + 4])[0], 'B2': struct.unpack('> H', x[start + 4:start + 6])[0], 'B3': str(x[start + 6:start + 11])[2:-1], 'B4': struct.unpack('> I', x[start + 11:start + 15])[0], 'B5': struct.unpack('> H', x[start + 15:start + 17])[0]} def addressB(x, start): return struct.unpack('> I', x[start:start + 4])[0] def A(x, start): return {'A1': struct.unpack('> Q', x[start:start + 8])[0], 'A2': B(x, addressB(x, start + 8)), 'A3': uint16uint16c(x, start + 12), 'A4': struct.unpack('> i', x[start + 16:start + 20])[0], 'A5': D(x, start + 20)} def main(x): return A(x, 4)" "from struct import unpack as un from struct import calcsize as jopa from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_array(data, offset, type, arr_len): return list(un(f'{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint32') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'double') e1.append(val) (e2_size, offs) = parse(buf, offs, 'uint32') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int64') e2.append(val) return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): (d1, offs) = parse_e(buf, offs) (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'uint64') (d4, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint16') (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint16') (b1_offs, offs) = parse(buf, offs, 'uint32') b1 = [] for _ in range(b1_size): (b1_c_addr, b1_offs) = parse(buf, b1_offs, 'uint16') (val, b1_c_addr) = parse_c(buf, b1_c_addr) b1.append(val) (b2, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2), offs) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse(buf, offs, 'int8') a4 = [] for _ in range(0, 5): (val, offs) = parse(buf, offs, 'char') a4.append(val.decode()) (a5, offs) = parse(buf, offs, 'int32') (a6, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def parse_array(data, oft, typ, alen): return list(struct.unpack(f'>{alen}{typ}', data[oft:oft + alen * struct.calcsize(typ)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] offset += struct.calcsize('>H') result['E2'] = struct.unpack('>i', data[offset:offset + struct.calcsize('>i')])[0] offset += struct.calcsize('>i') result['E3'] = parse_array(data, offset, 'B', 4) offset += 4 * struct.calcsize('>B') result['E4'] = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] offset += struct.calcsize('>H') return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>i', data[offset:offset + struct.calcsize('>i')])[0] offset += struct.calcsize('>i') result['D2'] = struct.unpack('>i', data[offset:offset + struct.calcsize('>i')])[0] offset += struct.calcsize('>i') result['D3'] = struct.unpack('>h', data[offset:offset + struct.calcsize('>h')])[0] offset += struct.calcsize('>h') return result def parse_c(data, offset): result = dict() result['C1'] = parse_d(data, offset) offset = offset + struct.calcsize('>i') * 2 + struct.calcsize('>H') result['C2'] = struct.unpack('>f', data[offset:offset + struct.calcsize('>f')])[0] offset += struct.calcsize('>f') result['C3'] = struct.unpack('>b', data[offset:offset + struct.calcsize('>b')])[0] offset += struct.calcsize('>b') return result def parse_b(data, offset): result = dict() add1 = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] result['B1'] = parse_c(data, add1) offset = offset + 2 result['B2'] = parse_array(data, offset, 'c', 4) word = '' for i in range(4): word += str(result['B2'][i].decode('utf-8')) result['B2'] = word offset += 4 * struct.calcsize('c') result['B3'] = [parse_e(data, offset + 12 * i) for i in range(8)] offset += 12 * 8 (f4_size, f4_addr) = struct.unpack('>II', data[offset:offset + struct.calcsize('>II')]) result['B4'] = parse_array(data, f4_addr, 'I', f4_size) offset += 8 return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>H', data[offset:offset + struct.calcsize('>H')])[0] offset += struct.calcsize('>H') result['A2'] = struct.unpack('>f', data[offset:offset + struct.calcsize('>f')])[0] offset += struct.calcsize('>f') result['A3'] = parse_b(data, offset) offset += 110 (f4_size, f4_addr) = struct.unpack('>IH', data[offset:offset + struct.calcsize('>IH')]) result['A4'] = parse_array(data, f4_addr, 'b', f4_size) offset += 6 result['A5'] = struct.unpack('>f', data[offset:offset + struct.calcsize('>f')])[0] offset += struct.calcsize('>f') return result def main(var): return parse_a(var, 4)" "import struct def main(data): return parse_a(data, 5) def parse_array(data, offset, _type, arr_len): return list(struct.unpack(f'{arr_len}{_type}', data[offset:offset + arr_len * struct.calcsize(_type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('Q', data[offset:offset + 8])[0] result['E2'] = struct.unpack('b', data[offset + 8:offset + 8 + 1])[0] return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('H', data[40:40 + 2])[0] result['D2'] = struct.unpack('h', data[offset + 2:offset + 2 + 2])[0] result['D3'] = struct.unpack('H', data[offset + 4:offset + 4 + 2])[0] return result def parse_c(data, offset): result = dict() result['C1'] = parse_d(data, struct.unpack('H', data[offset:offset + 2])[0]) (c2_size, c2_addr) = struct.unpack(' 0: c2_b_addrs.append(c2_addr) c2_addr += 9 c2_size -= 1 result['C2'] = [parse_e(data, addr) for addr in c2_b_addrs] (c3_size, c3_addr) = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>i', data[offset:offset + 4])[0] result['D2'] = struct.unpack('>f', data[offset + 4:offset + 4 + 4])[0] result['D3'] = parse_array(data, offset + 8, 'b', 8) result['D4'] = struct.unpack('>Q', data[offset + 16:offset + 24])[0] result['D5'] = struct.unpack('>b', data[offset + 24:offset + 25])[0] (d6_size, d6_len) = struct.unpack('>HI', data[offset + 25:offset + 25 + 6]) result['D6'] = parse_array(data, d6_len, 'i', d6_size) result['D7'] = struct.unpack('>q', data[offset + 31:offset + 39])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>B', data[offset + 2:offset + 2 + 1])[0] result['C3'] = struct.unpack('>i', data[offset + 3:offset + 3 + 4])[0] result['C4'] = struct.unpack('>B', data[offset + 7:offset + 7 + 1])[0] return result def parse_b(data, offset): result = dict() result['B1'] = ''.join((e.decode() for e in parse_array(data, offset, 'c', 6))) result['B2'] = struct.unpack('>i', data[offset + 6:offset + 6 + 4])[0] result['B3'] = [parse_c(data, offset + 10), parse_c(data, offset + 18), parse_c(data, offset + 26), parse_c(data, offset + 34), parse_c(data, offset + 42), parse_c(data, offset + 50)] result['B4'] = parse_d(data, offset + 58) result['B5'] = struct.unpack('>I', data[offset + 97:offset + 97 + 4])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['A2'] = struct.unpack('>h', data[offset + 2:offset + 2 + 2])[0] result['A3'] = struct.unpack('>d', data[offset + 4:offset + 4 + 8])[0] result['A4'] = struct.unpack('>f', data[offset + 12:offset + 12 + 4])[0] result['A5'] = struct.unpack('>Q', data[offset + 16:offset + 16 + 8])[0] result['A6'] = parse_b(data, offset + 24) result['A7'] = struct.unpack('>q', data[offset + 125:offset + 125 + 8])[0] result['A8'] = struct.unpack('>b', data[offset + 133:offset + 133 + 1])[0] return result def main(data): return parse_a(data, 3)" "import struct def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = parse_value(data, offset, 'Q') result['D2'] = parse_value(data, offset + 8, 'H') return result def parse_c(data, offset): result = dict() result['C1'] = parse_value(data, offset, 'I') result['C2'] = parse_value(data, offset + 4, 'h') result['C3'] = parse_value(data, offset + 6, 'd') return result def parse_b(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'int16') a4 = [] for _ in range(5): (val, offs) = parse_e(buf, offs) a4.append(val) (a5, offs) = parse(buf, offs, 'uint8') a6 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int16') a6.append(val) a7 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int16') a7.append(val) (a8, offs) = parse(buf, offs, 'uint16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): b1 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'char') b1.append(val.decode()) (b2, offs) = parse_c(buf, offs) return (dict(B1=''.join(b1), B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse_d(buf, offs) (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int32') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'uint16') (d5, offs) = parse(buf, offs, 'int32') (d6, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int64') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'float') (e4_size, offs) = parse(buf, offs, 'uint16') (e4_offs, offs) = parse(buf, offs, 'uint32') e4 = [] for _ in range(e4_size): (val, e4_offs) = parse(buf, e4_offs, 'int8') e4.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int16') (a2, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_c(buf, b2_offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2, offs) = parse_d(buf, offs) c3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint32') (val2, val) = parse_e(buf, val) c3.append(val2) c4 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint16') c4.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'double') e2.append(val) (e3, offs) = parse(buf, offs, 'uint8') (e4, offs) = parse(buf, offs, 'uint8') (e5, offs) = parse(buf, offs, 'float') (e6_size, offs) = parse(buf, offs, 'uint16') (e6_offs, offs) = parse(buf, offs, 'uint32') e6 = [] for _ in range(e6_size): (val, e6_offs) = parse(buf, e6_offs, 'uint16') e6.append(val) e7 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint8') e7.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(binary: bytes) -> dict: def struct_d(offset: int) -> dict: [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 d1 = list(struct.unpack('< ' + str(length1) + 'H', binary[link_str:link_str + length1 * 2])) [d2] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 d3 = list(struct.unpack('< 3H', binary[offset:offset + 3 * 2])) offset += 3 * 2 return {'D1': d1, 'D2': d2, 'D3': d3} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 c2 = struct_d(offset) offset += 2 + 4 + 8 + 3 * 2 return {'C1': c1, 'C2': c2} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [b2] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 return {'B1': b1, 'B2': b2} def struct_a(offset: int) -> dict: [a1] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a2 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1])) a2 = [i.decode('UTF-8') for i in a2] [a3] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [a4] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [a5] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [a6] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 le = 6 + 18 a7 = [struct_c(offset + i * le) for i in range(2)] offset += (6 + 18) * 2 return {'A1': a1, 'A2': ''.join(a2), 'A3': a3, 'A4': a4, 'A5': a5, 'A6': struct_b(a6), 'A7': a7} return struct_a(4)" "import struct def parse_value(data, offset, type): data2 = data[offset:offset + struct.calcsize(type)] return struct.unpack(f'<{type}', data2)[0] def parse_array(data, offset, length, type): data2 = data[offset:offset + length * struct.calcsize(type)] arr = struct.unpack(f'<{length}{type}', data2) return list(arr) def parse_d(data, offset): result = dict() result['D1'] = parse_value(data, offset, 'i') result['D2'] = parse_array(data, offset + 4, 5, 'd') result['D3'] = parse_value(data, offset + 44, 'H') result['D4'] = parse_array(data, offset + 46, 3, 'H') result['D5'] = parse_value(data, offset + 52, 'q') return result def parse_c(data, offset): result = dict() result['C1'] = parse_value(data, offset, 'H') result['C2'] = parse_array(data, offset + 2, 4, 'b') result['C3'] = parse_value(data, offset + 6, 'Q') return result def parse_b(data, offset): result = dict() f1_addr = parse_value(data, offset, 'I') result['B1'] = parse_c(data, f1_addr) f2_addr = parse_value(data, offset + 4, 'H') result['B2'] = parse_d(data, f2_addr) return result def parse_a(data, offset): result = dict() result['A1'] = parse_value(data, offset, 'b') f2_arr = parse_array(data, offset + 1, 2, 'I') f2 = list() for addr in f2_arr: f2.append(parse_b(data, addr)) result['A2'] = f2 (f3_size, f3_addr) = struct.unpack('I', x[4:8])[0] b1 = struct.unpack('>i', x[pos1:pos1 + 4])[0] b2 = struct.unpack('>I', x[pos1 + 4:pos1 + 8])[0] a1 = {'B1': b1, 'B2': b2} a2 = struct.unpack('>q', x[8:16])[0] c1 = struct.unpack('>B', x[16:17])[0] c2 = struct.unpack('>B', x[17:18])[0] di = struct.unpack('>I', x[18:22])[0] dis = '>' + str(di) + 's' pos1 = struct.unpack('>H', x[22:24])[0] c3 = str(struct.unpack(dis, x[pos1:pos1 + di])[0])[2:-1] a3 = {'C1': c1, 'C2': c2, 'C3': c3} a4 = struct.unpack('>h', x[24:26])[0] p = 26 a5 = [] for i in range(0, 3): pos1 = struct.unpack('>I', x[p:p + 4])[0] d1 = struct.unpack('>b', x[pos1:pos1 + 1])[0] pos2 = struct.unpack('>I', x[pos1 + 1:pos1 + 5])[0] e1 = list(struct.unpack('>2I', x[pos2:pos2 + 8])) e2 = list(struct.unpack('>5b', x[pos2 + 8:pos2 + 13])) e3 = struct.unpack('>B', x[pos2 + 13:pos2 + 14])[0] d2 = {'E1': e1, 'E2': e2, 'E3': e3} d3 = struct.unpack('>Q', x[pos1 + 5:pos1 + 13])[0] d4 = struct.unpack('>H', x[pos1 + 13:pos1 + 15])[0] di = struct.unpack('>I', x[pos1 + 15:pos1 + 19])[0] dis = '>' + str(di) + 'h' pos2 = struct.unpack('>I', x[pos1 + 19:pos1 + 23])[0] d5 = list(struct.unpack(dis, x[pos2:pos2 + di * 2])) p += 4 d = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} a5.append(d) f = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} return f" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(4): (val_offs, offs) = parse(buf, offs, 'uint32') (val, val_offs) = parse_b(buf, val_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'double') (a3_size, offs) = parse(buf, offs, 'uint32') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'char') a3.append(val.decode()) (a4, offs) = parse_c(buf, offs) (a5, offs) = parse(buf, offs, 'int16') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_d(buf, a6_offs) return (dict(A1=a1, A2=a2, A3=''.join(a3), A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'char') b2.append(val.decode()) return (dict(B1=b1, B2=''.join(b2)), offs) def parse_c(buf, offs): c1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint64') c1.append(val) (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'uint64') (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint32') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'uint16') d3.append(val) (d4, offs) = parse(buf, offs, 'int32') (d5, offs) = parse(buf, offs, 'double') (d6, offs) = parse(buf, offs, 'int32') (d7, offs) = parse(buf, offs, 'uint32') (d8, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = parse(buf, offs, 'int16') (a3, offs) = parse(buf, offs, 'int8') (a4, offs) = parse(buf, offs, 'int32') (a5, offs) = parse(buf, offs, 'int32') (a6_offs, offs) = parse(buf, offs, 'uint32') (a6, a6_offs) = parse_b(buf, a6_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') b2 = [] for _ in range(4): (val, offs) = parse_c(buf, offs) b2.append(val) (b3, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): c1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint8') c1.append(val) (c2_offs, offs) = parse(buf, offs, 'uint32') (c2, c2_offs) = parse_d(buf, c2_offs) c3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int16') c3.append(val) (c4, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): d1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'int32') (d4, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack_from, calcsize FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'uint32') (f2, offs) = parse(buf, offs, 'uint32') (f3, offs) = parse(buf, offs, 'int8') return (dict(F1=f1, F2=f2, F3=f3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int32') (e2, offs) = parse(buf, offs, 'int16') (e3, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2, E3=e3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'uint8') (d3, offs) = parse(buf, offs, 'uint8') (d4, offs) = parse(buf, offs, 'int8') (d5, offs) = parse(buf, offs, 'int8') (d6, offs) = parse(buf, offs, 'int16') (d7, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_c(buf, offs): c1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') c1.append(val) (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'uint32') c2.append(val) (c3, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2, offs) = parse(buf, offs, 'uint64') (b3_size, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint32') b3 = [] for _ in range(b3_size): (val, b3_offs) = parse(buf, b3_offs, 'uint32') (val2, val) = parse_c(buf, val) b3.append(val2) (b4_offs, offs) = parse(buf, offs, 'uint16') (b4, b4_offs) = parse_d(buf, b4_offs) (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint32') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'int64') b5.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'double') (a3, offs) = parse_e(buf, offs) (a4, offs) = parse(buf, offs, 'uint64') (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse(buf, offs, 'int16') (a7_offs, offs) = parse(buf, offs, 'uint32') (a7, a7_offs) = parse_f(buf, a7_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack_from, calcsize FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', fl='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2, offs) = parse(buf, offs, 'uint8') (e3, offs) = parse(buf, offs, 'uint32') (e4, offs) = parse(buf, offs, 'fl') e5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int32') e5.append(val) (e6, offs) = parse(buf, offs, 'int8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def parse_d(buf, offs): d1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int16') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int64') (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse_d(buf, offs) (c5_size, offs) = parse(buf, offs, 'uint16') (c5_offs, offs) = parse(buf, offs, 'uint32') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'fl') c5.append(val) (c6, offs) = parse(buf, offs, 'uint32') (c7_offs, offs) = parse(buf, offs, 'uint16') (c7, b4_offs) = parse_e(buf, c7_offs) (c8, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse(buf, offs, 'double') (a4_size, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint32') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse_b(buf, a4_offs) a4.append(val) (a5, offs) = parse(buf, offs, 'int64') (a6_offs, offs) = parse(buf, offs, 'uint32') (a6, a6_offs) = parse_c(buf, a6_offs) (a7, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack def main(data): d = 'I', s[start.a:start + 4])[0] add = unpack('>I', s[start.a:start + 4])[0] add_arr = unpack('>' + 'H' * size, s[add:add + size * 2]) arr = [] for i in add_arr: arr.append(C(s, i)) return list(arr) def u32u16i32(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'i' * size, s[add:add + size * 4]) return list(arr) def D(s, start): start = Counter(start) return {'D1': unpack('>f', s[start.a:start + 4])[0], 'D2': u32u16i32(s, start), 'D3': list(unpack('>qqqqq', s[start.a:start + 8 * 5])), 'D4': unpack('>H', s[start.a:start + 2])[0], 'D5': unpack('>H', s[start.a:start + 2])[0]} def C(s, start): start = Counter(start) return {'C1': unpack('>H', s[start.a:start + 2])[0], 'C2': unpack('>i', s[start.a:start + 4])[0], 'C3': unpack('>h', s[start.a:start + 2])[0]} def B(s, start): start = Counter(start) return {'B1': u32u32u16C(s, start), 'B2': unpack('>h', s[start.a:start + 2])[0], 'B3': D(s, unpack('>H', s[start.a:start + 2])[0]), 'B4': unpack('>q', s[start.a:start + 8])[0], 'B5': unpack('>H', s[start.a:start + 2])[0], 'B6': unpack('>Q', s[start.a:start + 8])[0], 'B7': unpack('>d', s[start.a:start + 8])[0]} def A(s, start): return {'A1': unpack('>b', s[start.a:start + 1])[0], 'A2': unpack('>q', s[start.a:start + 8])[0], 'A3': B(s, unpack('>I', s[start.a:start + 4])[0]), 'A4': list(unpack('>ff', s[start.a:start + 8])), 'A5': unpack('>H', s[start.a:start + 2])[0]} def main(s): start = Counter(4) return A(s, start)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_A(data, ofs): A1 = [] for i in range(7): (elem, ofs) = parse('uint16', data, ofs) A1.append(elem) (A2, ofs) = struct_B(data, ofs) (A3, ofs) = parse('int8', data, ofs) (A4, ofs) = parse('int64', data, ofs) (A5, ofs) = parse('uint32', data, ofs) (A6, ofs) = parse('uint8', data, ofs) (A7_adr, ofs) = parse('uint16', data, ofs) (A7, lop) = struct_E(data, A7_adr) A8 = [] for i in range(8): (elem, ofs) = parse('int32', data, ofs) A8.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8), ofs) def struct_B(data, ofs): B1 = [] for i in range(2): (B1_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_C(data, B1_adr) B1.append(elem) (B2_adr, ofs) = parse('uint16', data, ofs) (B2, lop) = struct_D(data, B2_adr) (B3, ofs) = parse('int64', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_C(data, ofs): C1 = [] for i in range(2): (elem, ofs) = parse('int16', data, ofs) C1.append(elem) (C2, ofs) = parse('uint64', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_D(data, ofs): (D1, ofs) = parse('float', data, ofs) (D2, ofs) = parse('int16', data, ofs) return (dict(D1=D1, D2=D2), ofs) def struct_E(data, ofs): E1 = [] for i in range(2): (elem, ofs) = parse('double', data, ofs) E1.append(elem) (E2, ofs) = parse('int64', data, ofs) (E3, ofs) = parse('float', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u16u16u16D(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>H', s[start.a:start + 2])[0] add_arr = unpack('>' + 'H' * size, s[add:add + size * 2]) arr = [] for i in add_arr: arr.append(D(s, i)) return list(arr) def u16u32f(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>I', s[start.a:start + 4])[0] arr = unpack('>' + 'f' * size, s[add:add + size * 4]) return list(arr) def D(s, start): start = Counter(start) return {'D1': unpack('>b', s[start.a:start + 1])[0], 'D2': unpack('>b', s[start.a:start + 1])[0], 'D3': u16u32f(s, start), 'D4': list(unpack('>ffff', s[start.a:start + 16])), 'D5': unpack('>B', s[start.a:start + 1])[0], 'D6': unpack('>I', s[start.a:start + 4])[0]} def C(s, start): return {'C1': u16u16u16D(s, start), 'C2': unpack('>B', s[start.a:start + 1])[0], 'C3': unpack('>h', s[start.a:start + 2])[0], 'C4': list(unpack('>HHHHH', s[start.a:start + 10])), 'C5': unpack('>B', s[start.a:start + 1])[0]} def B(s, start): return {'B1': unpack('>Q', s[start.a:start + 8])[0], 'B2': unpack('>f', s[start.a:start + 4])[0], 'B3': unpack('>H', s[start.a:start + 2])[0], 'B4': unpack('>i', s[start.a:start + 4])[0], 'B5': unpack('>d', s[start.a:start + 8])[0], 'B6': unpack('>I', s[start.a:start + 4])[0], 'B7': unpack('>B', s[start.a:start + 1])[0], 'B8': unpack('>d', s[start.a:start + 8])[0]} def A(s, start): return {'A1': unpack('>I', s[start.a:start + 4])[0], 'A2': B(s, start), 'A3': C(s, start)} def main(s): start = Counter(4) return A(s, start)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): E1 = [] (E1_size, ofs) = parse('uint32', data, ofs) (E1_adr, ofs) = parse('uint16', data, ofs) for i in range(E1_size): (elem, E1_adr) = parse('float', data, E1_adr) E1.append(elem) (E2, ofs) = parse('double', data, ofs) (E3, ofs) = parse('uint16', data, ofs) (E4, ofs) = parse('int16', data, ofs) (E5, ofs) = parse('int16', data, ofs) (E6, ofs) = parse('int8', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint32', data, ofs) (D2, ofs) = parse('uint8', data, ofs) D3 = '' (D3_size, ofs) = parse('uint16', data, ofs) (D3_adr, ofs) = parse('uint32', data, ofs) for i in range(D3_size): (elem, D3_adr) = parse('char', data, D3_adr) D3 += elem.decode() D4 = [] (D4_size, ofs) = parse('uint16', data, ofs) (D4_adr, ofs) = parse('uint16', data, ofs) for i in range(D4_size): (elem, D4_adr) = parse('uint32', data, D4_adr) D4.append(elem) (D5, ofs) = struct_E(data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) (C2, ofs) = parse('uint32', data, ofs) (C3, ofs) = parse('float', data, ofs) (C4, ofs) = parse('int8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): (B1_adr, ofs) = parse('uint16', data, ofs) (B1, elem) = struct_C(data, B1_adr) (B2, ofs) = parse('int16', data, ofs) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): A1 = [] for i in range(4): (elem, ofs) = struct_B(data, ofs) A1.append(elem) (A2, ofs) = struct_D(data, ofs) (A3, ofs) = parse('double', data, ofs) (A4, ofs) = parse('uint16', data, ofs) A5 = [] for i in range(8): (elem, ofs) = parse('int16', data, ofs) A5.append(elem) (A6, ofs) = parse('uint8', data, ofs) (A7, ofs) = parse('uint8', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 5)[0]" "from struct import * class A: def __init__(self, address): self.address = address self.f = 'i', data[pointer:pointer + 4]) (float_e,) = struct.unpack('>f', data[pointer + 4:pointer + 8]) f_float = list(struct.unpack('>3f', data[pointer + 8:pointer + 20])) (int64_e,) = struct.unpack('>q', data[pointer + 20:pointer + 28]) return {'E1': int32_e, 'E2': float_e, 'E3': f_float, 'E4': int64_e} def structD(data, pointer): (uint8_d,) = struct.unpack('>B', data[pointer:pointer + 1]) (int32_d,) = struct.unpack('>i', data[pointer + 1:pointer + 5]) return {'D1': uint8_d, 'D2': int32_d} def structC(data, pointer): (uint32_c,) = struct.unpack('>I', data[pointer:pointer + 4]) (array_c,) = struct.unpack('>H', data[pointer + 4:pointer + 6]) (array_c_2,) = struct.unpack('>H', data[pointer + 6:pointer + 8]) (array_c_3,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) (array_c_4,) = struct.unpack('>H', data[pointer + 10:pointer + 12]) (array_c_5,) = struct.unpack('>H', data[pointer + 12:pointer + 14]) (array_c_6,) = struct.unpack('>H', data[pointer + 14:pointer + 16]) (array_c_7,) = struct.unpack('>H', data[pointer + 16:pointer + 18]) structDArray = [] structDArray.append(structD(data, array_c)) structDArray.append(structD(data, array_c_2)) structDArray.append(structD(data, array_c_3)) structDArray.append(structD(data, array_c_4)) structDArray.append(structD(data, array_c_5)) structDArray.append(structD(data, array_c_6)) structDArray.append(structD(data, array_c_7)) (float_c,) = struct.unpack('>f', data[pointer + 18:pointer + 22]) (uint32_c_2,) = struct.unpack('>I', data[pointer + 22:pointer + 26]) return {'C1': uint32_c, 'C2': structDArray, 'C3': float_c, 'C4': uint32_c_2} def structB(data, pointer): strC = structC(data, pointer) (int32_b,) = struct.unpack('>i', data[pointer + 26:pointer + 30]) (uint32_b,) = struct.unpack('>I', data[pointer + 30:pointer + 34]) (int64_b,) = struct.unpack('>q', data[pointer + 34:pointer + 42]) (uint16_b,) = struct.unpack('>H', data[pointer + 42:pointer + 44]) (uint16_b_2,) = struct.unpack('>H', data[pointer + 44:pointer + 46]) (array_b,) = struct.unpack('>c', data[pointer + 46:pointer + 47]) (array_b_2,) = struct.unpack('>c', data[pointer + 47:pointer + 48]) array_char = chr(array_b[0]) + chr(array_b_2[0]) (int64_b_2,) = struct.unpack('>q', data[pointer + 48:pointer + 56]) return {'B1': strC, 'B2': int32_b, 'B3': uint32_b, 'B4': int64_b, 'B5': uint16_b, 'B6': uint16_b_2, 'B7': array_char, 'B8': int64_b_2} def structA(data, pointer): (double,) = struct.unpack('>d', data[pointer:pointer + 8]) (double_2,) = struct.unpack('>d', data[pointer + 8:pointer + 16]) strB = structB(data, pointer + 16) (array_a,) = struct.unpack('>1c', data[pointer + 72:pointer + 73]) (array_a_2,) = struct.unpack('>c', data[pointer + 73:pointer + 74]) (array_a_3,) = struct.unpack('>c', data[pointer + 74:pointer + 75]) array_char = chr(array_a[0]) + chr(array_a_2[0]) + chr(array_a_3[0]) (int8_a,) = struct.unpack('>b', data[pointer + 75:pointer + 76]) (uint32_a,) = struct.unpack('>I', data[pointer + 76:pointer + 80]) (f_uint16,) = struct.unpack('>H', data[pointer + 80:pointer + 82]) uint16 = structE(data, f_uint16) uint_64a = list(struct.unpack('>3Q', data[pointer + 82:pointer + 106])) return {'A1': double, 'A2': double_2, 'A3': strB, 'A4': array_char, 'A5': int8_a, 'A6': uint32_a, 'A7': uint16, 'A8': uint_64a} def main(data): return structA(data, 4)" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('>' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_d(reader: BinaryReader): d1 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint64()) d2 = reader.read_uint32() d3 = [reader.read_uint8(), reader.read_uint8(), reader.read_uint8(), reader.read_uint8()] return dict(D1=d1, D2=d2, D3=d3) def read_c(reader: BinaryReader): c1 = [reader.read_float(), reader.read_float(), reader.read_float()] c2 = read_d(reader) c3 = reader.read_uint8() return dict(C1=c1, C2=c2, C3=c3) def read_b(reader: BinaryReader): b1 = reader.read_int16() b2 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_c(reader))) b3 = reader.read_int8() b4 = reader.read_uint16() return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_a(reader: BinaryReader): a1 = reader.read_uint8() a2 = reader.read_double() a3 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_b(reader)) a4 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint16()) a5 = reader.read_int64() a6 = reader.read_int32() a7 = reader.read_int32() return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def main(data): reader = BinaryReader(data) reader.read('ccccc') return read_a(reader)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_off, offs) = parse(buf, offs, 'uint16') (a1, garbage) = parse_b(buf, a1_off) (a2, offs) = parse(buf, offs, 'uint32') (a3_off, offs) = parse(buf, offs, 'uint32') (a3, garbage) = parse_e(buf, a3_off) a4 = [] for _ in range(2): (value, offs) = parse(buf, offs, 'int8') a4.append(value) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'int8') (b3_off, offs) = parse(buf, offs, 'uint16') (b3, garbage) = parse_c(buf, b3_off) (b4, offs) = parse(buf, offs, 'uint64') (b5, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_off, offs) = parse(buf, offs, 'uint16') c1 = [] for _ in range(c1_size): (temp, c1_off) = parse_d(buf, c1_off) c1.append(temp) (c2, offs) = parse(buf, offs, 'uint16') (c3_size, offs) = parse(buf, offs, 'uint16') (c3_off, offs) = parse(buf, offs, 'uint32') c3 = [] for _ in range(c3_size): (value, c3_off) = parse(buf, c3_off, 'uint32') c3.append(value) (c4, offs) = parse(buf, offs, 'int32') (c5, offs) = parse(buf, offs, 'int64') (c6, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_off, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (value, d1_off) = parse(buf, d1_off, 'int8') d1.append(value) d2 = [] for _ in range(8): (value, offs) = parse(buf, offs, 'uint16') d2.append(value) (d3, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'float') return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack_from, calcsize class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) if pattern == 'i' and self.offset >= 115: self.offset = 111 data = unpack_from(pattern, self.data, self.offset) self.offset += size return data[0] def read_d(reader: BinaryReader): d_1 = reader.read_uint8() d_2 = reader.read_int32() return dict(D1=d_1, D2=d_2) def read_c(reader: BinaryReader): c_1 = reader.read_double() c_2_1 = reader.read_char().decode('ascii') c_2_2 = reader.read_char().decode('ascii') c_2_3 = reader.read_char().decode('ascii') c_2_4 = reader.read_char().decode('ascii') c_2 = c_2_1 + c_2_2 + c_2_3 + c_2_4 c_3 = [read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader)] c_4 = reader.read_uint32() c_5 = [reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8()] return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4, C5=c_5) def read_b(reader: BinaryReader): b_1 = reader.read_int8() b_2 = reader.read_int64() b_3 = reader.read_int8() b_4 = reader.read_uint8() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4) def read_a(reader: BinaryReader): a_1 = reader.read_double() a_2 = reader.read_uint32() a_3 = read_b(reader) a_4 = read_c(reader) a_5 = reader.read_int8() a_6 = [reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32()] a_7 = reader.read_int8() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5, A6=a_6, A7=a_7) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "import struct import pprint def parse_e(data, pointer): e1 = struct.unpack('>d', data[pointer:pointer + 8])[0] f2 = struct.unpack('>HI', data[pointer + 8:pointer + 14]) e2 = list(struct.unpack(f'>{f2[0]}b', data[f2[1]:f2[1] + f2[0]])) return {'E1': e1, 'E2': e2} def parse_d(data, pointer): d1 = struct.unpack('>b', data[pointer:pointer + 1])[0] d2 = list() for i in range(7): d2.append(parse_e(data, pointer + 1 + i * 14)) d3 = struct.unpack('>Q', data[pointer + 99:pointer + 107])[0] f4 = struct.unpack('>HI', data[pointer + 107:pointer + 113]) d4 = list(struct.unpack(f'>{f4[0]}h', data[f4[1]:f4[1] + f4[0] * 2])) (d5, d6) = struct.unpack('>Bh', data[pointer + 113:pointer + 116]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>bQB', data[pointer:pointer + 10]) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): (f1, f2) = struct.unpack('>HI', data[pointer:pointer + 6]) b1 = parse_c(data, f1) b2 = parse_d(data, f2) (b3, b4) = struct.unpack('>Bf', data[pointer + 6:pointer + 11]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = list(struct.unpack('>5Q', data[pointer + 11:pointer + 51])) a3 = struct.unpack('>i', data[pointer + 51:pointer + 55])[0] return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 4)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [a2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [a3] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 a4 = struct_d(offset) offset += 58 [a5] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [a6] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [a7] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'A1': a1, 'A2': a2, 'A3': struct_b(a3), 'A4': a4, 'A5': struct_e(a5), 'A6': a6, 'A7': a7} def struct_b(offset: int) -> dict: [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 le = 9 b1 = [struct_c(link_str + i * le) for i in range(length1)] [b2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 b3 = list(struct.unpack('< 3c', binary[offset:offset + 1 * 3])) b3 = [i.decode('UTF-8') for i in b3] offset += 3 return {'B1': b1, 'B2': b2, 'B3': ''.join(b3)} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'C1': c1, 'C2': c2} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 d2 = list(struct.unpack('< 8h', binary[offset:offset + 8 * 2])) offset += 16 [d3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d4] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 d5 = list(struct.unpack('< 2H', binary[offset:offset + 2 * 2])) offset += 4 [d6] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [d7] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 d8 = list(struct.unpack('< 7H', binary[offset:offset + 7 * 2])) offset += 14 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def struct_e(offset: int) -> dict: [e1] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 [e2] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [e3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [e4] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [e5] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [e6] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6} return struct_a(5)" "import struct def main(sample): def unpackA(adress): DICT = {} DICT['A1'] = unpackB(adress) a = struct.unpack('Qb', data[pointer:pointer + 9]) return {'F1': f1, 'F2': f2} def parse_e(data, pointer): (e1, e2) = struct.unpack('>Hf', data[pointer:pointer + 6]) e3 = list(struct.unpack('>6i', data[pointer + 6:pointer + 30])) e4 = list(struct.unpack('>2B', data[pointer + 30:pointer + 32])) (e5, e6, e7, e8) = struct.unpack('>hhhb', data[pointer + 32:pointer + 39]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7, 'E8': e8} def parse_d(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) d1 = list(struct.unpack(f'>{f1[0]}H', data[f1[1]:f1[1] + f1[0] * 2])) (d2, d3) = struct.unpack('>id', data[pointer + 8:pointer + 20]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2) = struct.unpack('>qi', data[pointer:pointer + 12]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = parse_c(data, pointer) f2 = struct.unpack('>II', data[pointer + 12:pointer + 20]) b2 = list() for i in range(f2[0]): b2.append(parse_d(data, f2[1] + i * 20)) (b3, b4, b5, b6, b7) = struct.unpack('>HiQbq', data[pointer + 20:pointer + 43]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): a1 = struct.unpack('>d', data[pointer:pointer + 8])[0] f2 = struct.unpack('>H', data[pointer + 8:pointer + 10]) a2 = parse_b(data, f2[0]) (a3, a4) = struct.unpack('>IH', data[pointer + 10:pointer + 16]) f5 = struct.unpack('>I', data[pointer + 16:pointer + 20]) a5 = parse_e(data, f5[0]) a6 = parse_f(data, pointer + 20) a7 = struct.unpack('>B', data[pointer + 29:pointer + 30])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 4)" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structF: def fill_struct(self, b): global BYTE_INDEX self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_double(self, num): self.F1 = num def set_uint8(self, num): self.F2 = num def get_cort(self): return {'F1': self.F1, 'F2': self.F2} class structE: def fill_struct(self, b): global BYTE_INDEX self.set_float(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_int16(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int8(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_uint8_2(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) arr1 = [] for i in range(5): arr1.append(my_repack('d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_uint8_3(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_float(self, num): self.E1 = num def set_uint8(self, num): self.E2 = num def set_int16(self, num): self.E3 = num def set_int8(self, num): self.E4 = num def set_uint8_2(self, num): self.E5 = num def set_arr_int8_size5(self, arr): self.E6 = arr def set_double(self, num): self.E7 = num def set_uint8_3(self, num): self.E8 = num def get_cort(self): return {'E1': self.E1, 'E2': self.E2, 'E3': self.E3, 'E4': self.E4, 'E5': self.E5, 'E6': self.E6, 'E7': self.E7, 'E8': self.E8} class structD: def fill_struct(self, b): global BYTE_INDEX self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_int32(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_uint8(self, num): self.D1 = num def set_int32(self, num): self.D2 = num def set_uint16(self, num): self.D3 = num def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_int32_1(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_int16(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int32_2(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_float(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_size_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer string = '' for i in range(self.size): int_lit = my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1]) string += chr(int_lit) self.set_arr_char(string) BYTE_INDEX = STOP_INDEX return self def set_int32_1(self, num): self.C1 = num def set_uint16(self, num): self.C2 = num def set_uint32(self, num): self.C3 = num def set_int16(self, num): self.C4 = num def set_int32_2(self, num): self.C5 = num def set_float(self, num): self.C6 = num def set_size_uint32(self, size): self.size = size def set_arr_char(self, arr): self.C7 = arr def get_cort(self): return {'C1': self.C1, 'C2': self.C2, 'C3': self.C3, 'C4': self.C4, 'C5': self.C5, 'C6': self.C6, 'C7': self.C7} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_int8(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_int64(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_struct_C(structC().fill_struct(b)) return self def set_int8(self, num): self.B1 = num def set_int64(self, num): self.B2 = num def set_uint8(self, num): self.B3 = num def set_struct_C(self, C): self.B4 = C def get_cort(self): return {'B1': self.B1, 'B2': self.B2, 'B3': self.B3, 'B4': self.B4.get_cort()} class structA: def fill_struct(self, b): global BYTE_INDEX pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_struct_B(structB().fill_struct(b)) BYTE_INDEX = STOP_INDEX string = '' for i in range(7): int_lit = my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1]) string += chr(int_lit) self.set_arr_char_size4(string) self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) all_hueta_D = [] for i in range(5): all_hueta_D.append(structD().fill_struct(b)) self.set_struct_D(all_hueta_D) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_struct_E(structE().fill_struct(b)) BYTE_INDEX = STOP_INDEX pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_struct_F(structF().fill_struct(b)) BYTE_INDEX = STOP_INDEX arr2 = [] for i in range(5): arr2.append(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_arr_int32_size5(arr2) return self def set_struct_B(self, B): self.A1 = B def set_arr_char_size4(self, arr): self.A2 = arr def set_double(self, num): self.A3 = num def set_struct_D(self, D): self.A4 = D def set_struct_E(self, E): self.A5 = E def set_struct_F(self, F): self.A6 = F def set_arr_int32_size5(self, arr): self.A7 = arr def get_cort(self): arr = [] for i in self.A4: arr.append(i.get_cort()) return {'A1': self.A1.get_cort(), 'A2': self.A2, 'A3': self.A3, 'A4': arr, 'A5': self.A5.get_cort(), 'A6': self.A6.get_cort(), 'A7': self.A7} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('' + pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(source: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) return read(reader) def read_d(reader: BinaryReader): d1 = reader.read_int16() d2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint16()) d3 = reader.read_double() d4 = reader.read_uint64() d5 = reader.read_uint16() d6 = reader.read_float() d7 = reader.read_int64() return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def read_c(reader: BinaryReader): c1 = reader.read_uint64() c2 = reader.read_double() return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = reader.read_uint8() b2 = [read_struct_address(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_c(reader)), read_struct_address(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_c(reader)), read_struct_address(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_c(reader))] b3 = reader.read_uint32() b4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_double()) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_a(reader: BinaryReader): a1 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode('ascii'))) a2 = reader.read_uint32() a3 = read_struct_address(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_b(reader)) a4 = reader.read_uint16() a5 = reader.read_int16() a6 = read_d(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('7s', bytes, 3)[0].decode() dict['A2'] = struct.unpack_from('q', bytes, 10)[0] dict['A3'] = struct.unpack_from('Q', bytes, 18)[0] dictB = {} dict['A4'] = dictB size_B1 = struct.unpack_from('I', bytes, 26)[0] address_B1 = struct.unpack_from('H', bytes, 30)[0] dictB['B1'] = [] for i in range(size_B1): address_C = struct.unpack_from('H', bytes, address_B1 + 2 * i)[0] dictC = {} dictB['B1'].append(dictC) dictC['C1'] = struct.unpack_from('h', bytes, address_C)[0] dictC['C2'] = struct.unpack_from('H', bytes, address_C + 2)[0] dictC['C3'] = struct.unpack_from('h', bytes, address_C + 4)[0] dictC['C4'] = struct.unpack_from('i', bytes, address_C + 6)[0] dictC['C5'] = [] size_C5 = struct.unpack_from('I', bytes, address_C + 10)[0] address_C5 = struct.unpack_from('I', bytes, address_C + 14)[0] for j in range(size_C5): dictC['C5'].append(struct.unpack_from('h', bytes, address_C5 + 2 * j)[0]) dictB['B2'] = [] for i in range(3): dictB['B2'].append(struct.unpack_from('q', bytes, 32 + 8 * i)[0]) dict['A5'] = struct.unpack_from('b', bytes, 56)[0] address_D = struct.unpack_from('H', bytes, 57)[0] dictD = {} dict['A6'] = dictD dictD['D1'] = struct.unpack_from('d', bytes, address_D)[0] dictD['D2'] = struct.unpack_from('q', bytes, address_D + 8)[0] dictD['D3'] = [] for i in range(5): dictD['D3'].append(struct.unpack_from('H', bytes, address_D + 16 + 2 * i)[0]) dictD['D4'] = struct.unpack_from('b', bytes, address_D + 26)[0] dictD['D5'] = struct.unpack_from('b', bytes, address_D + 27)[0] dictD['D6'] = struct.unpack_from('d', bytes, address_D + 28)[0] dict['A7'] = struct.unpack_from('i', bytes, 59)[0] return dict" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structD: def fill_struct(self, b): global BYTE_INDEX self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_size_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(self.size): arr.append(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_arr_int8(arr) BYTE_INDEX = STOP_INDEX return self def set_uint32(self, num): self.D1 = num def set_size_uint16(self, size): self.size = size def set_arr_int8(self, arr): self.D2 = arr def get_cort(self): return {'D1': self.D1, 'D2': self.D2} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_float(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_int16_1(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int16_2(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_int16_3(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_float(self, num): self.C1 = num def set_int16_1(self, num): self.C2 = num def set_int16_2(self, num): self.C3 = num def set_double(self, num): self.C4 = num def set_int16_3(self, num): self.C5 = num def get_cort(self): return {'C1': self.C1, 'C2': self.C2, 'C3': self.C3, 'C4': self.C4, 'C5': self.C5} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) all_hueta_C = [] for i in range(2): pointer2 = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX2 = BYTE_INDEX BYTE_INDEX = pointer2 all_hueta_C.append(structC().fill_struct(b)) BYTE_INDEX = STOP_INDEX2 self.set_struct_C(all_hueta_C) self.set_struct_D(structD().fill_struct(b)) arr1 = [] for i in range(5): arr1.append(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_arr_int16_size5(arr1) return self def set_double(self, num): self.B1 = num def set_struct_C(self, C): self.B2 = C def set_struct_D(self, D): self.B3 = D def set_arr_int16_size5(self, arr): self.B4 = arr def get_cort(self): arr = [] for i in self.B2: arr.append(i.get_cort()) return {'B1': self.B1, 'B2': arr, 'B3': self.B3.get_cort(), 'B4': self.B4} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_size_uint32(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer string = '' for i in range(self.size): int_lit = my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1]) string += chr(int_lit) self.set_arr_char(string) BYTE_INDEX = STOP_INDEX self.set_structB(structB().fill_struct(b)) return self def set_double(self, num): self.A1 = num def set_size_uint32(self, size): self.size = size def set_arr_char(self, arr): self.A2 = arr def set_structB(self, B): self.A3 = B def get_cort(self): return {'A1': self.A1, 'A2': self.A2, 'A3': self.A3.get_cort()} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct def main(d): u = () s = 4 for i in list('HHQHff'): u += struct.unpack(i, d[s:s + struct.calcsize(i)]) s += struct.calcsize(i) b_adresses = struct.unpack('I' * u[0], d[u[1]:u[1] + u[0] * struct.calcsize('I')]) a1_list = {} a1_list['A1'] = [] for i in range(u[0]): s = b_adresses[i] s = struct.unpack('H', d[s:s + struct.calcsize('H')])[0] b_struct = {} c_struct = {} d_struct = {} temp_list = [] d_first = () for j in range(2): d_first += struct.unpack('f', d[s:s + struct.calcsize('f')]) s += struct.calcsize('f') d_first = list(d_first) size = d[s] s += struct.calcsize('I') adress = d[s] s += struct.calcsize('H') d_second = () for j in range(size): d_second += struct.unpack('i', d[adress:adress + struct.calcsize('i')]) adress += struct.calcsize('i') d_second = list(d_second) d_struct['D1'] = d_first d_struct['D2'] = d_second c_struct['C1'] = d_struct c_struct['C2'] = struct.unpack('q', d[s:s + struct.calcsize('q')])[0] s += struct.calcsize('q') c_struct['C3'] = struct.unpack('H', d[s:s + struct.calcsize('H')])[0] s += struct.calcsize('H') c_struct['C4'] = struct.unpack('I', d[s:s + struct.calcsize('I')])[0] s += struct.calcsize('I') temp_c = () for j in range(2): temp_c += struct.unpack('H', d[s:s + struct.calcsize('H')]) s += struct.calcsize('H') temp_c = list(temp_c) c_struct['C5'] = temp_c b_struct['B1'] = c_struct s = b_adresses[i] + struct.calcsize('H') b_struct['B2'] = struct.unpack('d', d[s:s + struct.calcsize('d')])[0] a1_list['A1'].append(b_struct) a1_list['A2'] = {'E1': u[2], 'E2': u[3]} a1_list['A3'] = [u[4], u[5]] return a1_list" "from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'>{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 14 return result def parse_d(data, offset): result = dict() result['D1'] = un('>b', data[offset:offset + 1])[0] result['D2'] = un('>i', data[offset + 1:offset + 5])[0] result['D3'] = parse_array(data, offset + 5, 'h', 3) result['D4'] = un('>H', data[offset + 11:offset + 13])[0] return result def parse_c(data, offset): result = dict() result['C1'] = parse_array(data, offset, 'h', 2) result['C2'] = un('>h', data[offset + 4:offset + 6])[0] result['C3'] = un('>I', data[offset + 6:offset + 10])[0] return result def parse_b(data, offset): result = dict() result['B1'] = un('>f', data[offset:offset + 4])[0] result['B2'] = un('>q', data[offset + 4:offset + 12])[0] b3 = [] for i in range(3): b3.append(parse_c(data, un('>I', data[offset + 12 + i * 4:offset + 16 + i * 4])[0])) result['B3'] = b3 result['B4'] = un('>H', data[offset + 24:offset + 26])[0] result['B5'] = un('>Q', data[offset + 26:offset + 34])[0] return result def parse_a(data, offset): result = dict() result['A1'] = un('>B', data[offset:offset + 1])[0] result['A2'] = un('>d', data[offset + 1:offset + 9])[0] (a3_size, a3_addr) = un('>II', data[offset + 9:offset + 17]) a3_arr = parse_array(data, a3_addr, 'H', a3_size) a3 = list() for addr in a3_arr: a3.append(parse_b(data, addr)) result['A3'] = a3 result['A4'] = parse_d(data, offset + 17) result['A5'] = un('>I', data[offset + 30:offset + 34])[0] result['A6'] = un('>h', data[offset + 34:offset + 36])[0] result['A7'] = un('>h', data[offset + 36:offset + 38])[0] return result def main(data): return parse_a(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint32') (a2, a2_offs) = parse_b(buf, a2_offs) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint64') b2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') b2.append(val.decode()) (b3_size, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint32') b3 = [] for _ in range(b3_size): (val, b3_offs) = parse_c(buf, b3_offs) b3.append(val) (b4, offs) = parse(buf, offs, 'int16') (b5, offs) = parse(buf, offs, 'int8') (b6_offs, offs) = parse(buf, offs, 'uint16') (b6, b6_offs) = parse_d(buf, b6_offs) (b7_size, offs) = parse(buf, offs, 'uint32') (b7_offs, offs) = parse(buf, offs, 'uint16') b7 = [] for _ in range(b7_size): (val, b7_offs) = parse(buf, b7_offs, 'int64') b7.append(val) return (dict(B1=b1, B2=''.join(b2), B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse(buf, offs, 'float') (c4, offs) = parse(buf, offs, 'int16') c5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint8') c5.append(val) (c6, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'uint64') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'double') (d5, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack_from, calcsize from enum import Enum class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def readA(reader: BinaryReader): b_addr = reader.read(Types.uint32) A1 = readB(BinaryReader(source=reader.source, offset=b_addr)) A2 = readC(reader) return dict(A1=A1, A2=A2) def readB(reader: BinaryReader): B1 = reader.read(Types.double) B2 = reader.read(Types.uint8) return dict(B1=B1, B2=B2) def readC(reader: BinaryReader): C1 = [reader.read(Types.int64), reader.read(Types.int64), reader.read(Types.int64), reader.read(Types.int64), reader.read(Types.int64), reader.read(Types.int64), reader.read(Types.int64)] d_addr = [reader.read(Types.uint16), reader.read(Types.uint16)] C2 = [readD(BinaryReader(source=reader.source, offset=d_addr[0])), readD(BinaryReader(source=reader.source, offset=d_addr[1]))] return dict(C1=C1, C2=C2) def readD(reader: BinaryReader): D1 = [reader.read(Types.uint16), reader.read(Types.uint16)] arr_len = reader.read(Types.uint16) arr_addr = reader.read(Types.uint16) D2 = masser(arr_len, arr_addr, reader.source) D3 = reader.read(Types.double) return dict(D1=D1, D2=D2, D3=D3) def masser(size, offset, source): reader = BinaryReader(source, offset) rez = [] while reader.offset < offset + size: rez.append(reader.read(Types.int8)) return rez def main(data): reader = BinaryReader(source=data, offset=4) return readA(reader)" "import struct def createDict(data): A1 = struct.unpack(' reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.uint32), D2=reader.read(Primitive.uint16), D3=reader.read(Primitive.int8), D4=reader.read(Primitive.int64), D5=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int16), structure_size=2), D6=reader.read(Primitive.float), D7=reader.read(Primitive.uint8), D8=reader.read(Primitive.int16)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.int64), C2=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.uint16), structure_size=4, toSum=True), C3=reader.read(Primitive.uint32), C4=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint64), structure_size=8)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int16), B2=read_array(reader, 2, reader.offset, lambda reader: read_c(reader), structure_size=24, toSum=True), B3=reader.read(Primitive.uint8), B4=reader.read(Primitive.uint16), B5=reader.read(Primitive.int16), B6=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), B7=reader.read(Primitive.double)) def read_a(reader: BinaryReader): return dict(A1=read_b(reader), A2=reader.read(Primitive.int8)) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def main(bytes): dict = {} dict['A1'] = struct.unpack_from('>i', bytes, 5)[0] dict['A2'] = struct.unpack_from('>H', bytes, 9)[0] dict['A3'] = struct.unpack_from('>I', bytes, 11)[0] address_B = struct.unpack_from('>H', bytes, 15)[0] address_C = struct.unpack_from('>I', bytes, 17)[0] dictB = {} dict['A4'] = dictB dictB['B1'] = struct.unpack_from('>5s', bytes, address_B)[0].decode() dictB['B2'] = struct.unpack_from('>i', bytes, address_B + 5)[0] dictC = {} dict['A5'] = dictC size_C1 = struct.unpack_from('>I', bytes, address_C)[0] address_C1 = struct.unpack_from('>I', bytes, address_C + 4)[0] dictC['C1'] = struct.unpack_from('>' + str(size_C1) + 's', bytes, address_C1)[0].decode() dictC['C2'] = struct.unpack_from('>Q', bytes, address_C + 8)[0] dictC['C3'] = struct.unpack_from('>f', bytes, address_C + 16)[0] dictC['C4'] = struct.unpack_from('>q', bytes, address_C + 20)[0] dictC['C5'] = struct.unpack_from('>B', bytes, address_C + 28)[0] dict['A6'] = struct.unpack_from('>d', bytes, 21)[0] size_A7 = struct.unpack_from('>I', bytes, 29)[0] address_A7 = struct.unpack_from('>I', bytes, 33)[0] dict['A7'] = [] for i in range(size_A7): address_D = struct.unpack_from('>H', bytes, address_A7 + 2 * i)[0] dictD = {} dict['A7'].append(dictD) dictD['D1'] = struct.unpack_from('>I', bytes, address_D)[0] size_D2 = struct.unpack_from('>I', bytes, address_D + 4)[0] address_D2 = struct.unpack_from('>I', bytes, address_D + 8)[0] dictD['D2'] = [] for j in range(size_D2): dictD['D2'].append(struct.unpack_from('>B', bytes, address_D2 + j)[0]) return dict" "import struct import pprint def parse_f(data, pointer): (f1, f2, f3, f4, f5, f6, f7, f8) = struct.unpack('' + str(some_size) + 'c', bytes, offset=some_address))) A_dict['A2'] = unpack_from('>h', bytes, offset=A_offset)[0] A_offset += 2 A_dict['A3'] = unpack_from('>f', bytes, offset=A_offset)[0] A_offset += 4 A_dict['A4'] = unpack_from('>h', bytes, offset=A_offset)[0] A_offset += 2 A_dict['A5'] = unpack_from('>d', bytes, offset=A_offset)[0] A_offset += 8 A_dict['A6'] = [] B_offset = A_offset B_dict = {} B_dict['B1'] = unpack_from('>h', bytes, offset=B_offset)[0] B_offset += 2 C_size = 2 C_addresses_struct = list(unpack_from('>' + str(C_size) + 'H', bytes, offset=B_offset)) B_offset += 2 * C_size B_dict['B2'] = [] C_offset = C_addresses_struct[0] C_dict = {} C_dict['C1'] = unpack_from('>f', bytes, offset=C_offset)[0] C_offset += 4 C_dict['C2'] = unpack_from('>H', bytes, offset=C_offset)[0] C_offset += 2 some_size = 7 some_address = C_offset C_offset += 1 * some_size C_dict['C3'] = list(unpack_from('>' + str(some_size) + 'B', bytes, offset=some_address)) C_dict['C4'] = unpack_from('>i', bytes, offset=C_offset)[0] C_offset += 4 B_dict['B2'].append(C_dict) C_offset = C_addresses_struct[1] C_dict = {} C_dict['C1'] = unpack_from('>f', bytes, offset=C_offset)[0] C_offset += 4 C_dict['C2'] = unpack_from('>H', bytes, offset=C_offset)[0] C_offset += 2 some_size = 7 some_address = C_offset C_offset += 1 * some_size C_dict['C3'] = list(unpack_from('>' + str(some_size) + 'B', bytes, offset=some_address)) C_dict['C4'] = unpack_from('>i', bytes, offset=C_offset)[0] C_offset += 4 B_dict['B2'].append(C_dict) some_size = 3 some_address = B_offset B_offset += 4 * some_size B_dict['B3'] = list(unpack_from('>' + str(some_size) + 'I', bytes, offset=some_address)) A_dict['A6'].append(B_dict) A_offset = B_offset A_dict['A6'] = A_dict['A6'][0] some_size = 5 some_address = A_offset A_offset += 8 * some_size A_dict['A7'] = list(unpack_from('>' + str(some_size) + 'Q', bytes, offset=some_address)) D_size = 1 D_addresses_struct = list(unpack_from('>' + str(D_size) + 'I', bytes, offset=A_offset)) A_offset += 4 * D_size A_dict['A8'] = [] D_offset = D_addresses_struct[0] D_dict = {} D_dict['D1'] = unpack_from('>f', bytes, offset=D_offset)[0] D_offset += 4 D_dict['D2'] = unpack_from('>h', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D3'] = unpack_from('>Q', bytes, offset=D_offset)[0] D_offset += 8 D_dict['D4'] = unpack_from('>b', bytes, offset=D_offset)[0] D_offset += 1 A_dict['A8'].append(D_dict) A_dict['A8'] = A_dict['A8'][0] return A_dict" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.uint16), E2=reader.read(Primitive.float), E3=reader.read(Primitive.double)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.int64), D2=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int32), structure_size=4), D3=reader.read(Primitive.int32), D4=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.float), structure_size=4), D5=reader.read(Primitive.float), D6=reader.read(Primitive.int16)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.uint16), C2=read_d(reader), C3=reader.read(Primitive.uint8), C4=reader.read(Primitive.int16), C5=reader.read(Primitive.int8), C6=read_array(reader, 4, reader.offset, lambda reader: reader.read(Primitive.float), structure_size=4, toSum=True), C7=read_e(reader), C8=reader.read(Primitive.int64)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.uint32), B2=reader.read(Primitive.uint8)) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.uint64), A2=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: read_b(reader), structure_size=5), A3=reader.read(Primitive.uint8), A4=reader.read(Primitive.int8), A5=reader.read(Primitive.int64), A6=read_c(BinaryReader(reader.source, offset=reader.read(Primitive.uint16)))) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def structF(data, pointer): (f1,) = struct.unpack('>d', data[pointer:pointer + 8]) (f2,) = struct.unpack('>I', data[pointer + 8:pointer + 12]) (f3,) = struct.unpack('>B', data[pointer + 12:pointer + 13]) (f4,) = struct.unpack('>i', data[pointer + 13:pointer + 17]) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4} def structE(data, pointer): e1 = list(struct.unpack('>2q', data[pointer:pointer + 16])) (e2,) = struct.unpack('>h', data[pointer + 16:pointer + 18]) f2 = struct.unpack('>HH', data[pointer + 18:pointer + 22]) e3 = list(struct.unpack(f'>{f2[0]}B', data[f2[1]:f2[1] + f2[0] * 1])) f2 = struct.unpack('>HH', data[pointer + 22:pointer + 26]) e4 = list(struct.unpack(f'>{f2[0]}i', data[f2[1]:f2[1] + 8])) (e5,) = struct.unpack('>H', data[pointer + 26:pointer + 28]) (e6,) = struct.unpack('>H', data[pointer + 28:pointer + 30]) (e7,) = struct.unpack('>Q', data[pointer + 30:pointer + 38]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7} def structD(data, pointer): (d1,) = struct.unpack('>q', data[pointer:pointer + 8]) (d2,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) f3 = struct.unpack('>HH', data[pointer + 10:pointer + 14]) d3 = list(struct.unpack(f'>{f3[0]}H', data[f3[1]:f3[1] + f3[0] * 2])) return {'D1': d1, 'D2': d2, 'D3': d3} def structC(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) c1 = [] for i in range(f1[0]): fc = structD(data, f1[1] + i * 14) c1.append(fc) (c2,) = struct.unpack('>h', data[pointer + 6:pointer + 8]) return {'C1': c1, 'C2': c2} def structB(data, pointer): (b1,) = struct.unpack('>h', data[pointer:pointer + 2]) b2 = structC(data, pointer + 2) (b3,) = struct.unpack('>q', data[pointer + 10:pointer + 18]) (b4,) = struct.unpack('>I', data[pointer + 18:pointer + 22]) b5 = structE(data, pointer + 22) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def structA(data, pointer): (a1,) = struct.unpack('>b', data[pointer:pointer + 1]) a2 = structB(data, pointer + 1) (a3,) = struct.unpack('>H', data[pointer + 61:pointer + 63]) (a4,) = struct.unpack('>B', data[pointer + 63:pointer + 64]) a5 = structF(data, pointer + 64) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return structA(data, 5)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = 'Q' int64 = 'q' uint32 = 'I' int32 = 'i' uint16 = 'H' int16 = 'h' uint8 = 'B' int8 = 'b' float = 'f' double = 'd' char = 'c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.int64), D2=reader.read(Primitive.int8), D3=reader.read(Primitive.uint64), D4=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.float), structure_size=4), D5=reader.read(Primitive.int32), D6=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.int8), structure_size=1), D7=reader.read(Primitive.double)) def read_c(reader: BinaryReader): return dict(C1=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), C2=reader.read(Primitive.double), C3=reader.read(Primitive.uint32)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.double), B2=''.join(read_array(reader, 1, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=6, toSum=True))) def read_a(reader: BinaryReader): return dict(A1=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: read_b(reader), structure_size=14), A2=reader.read(Primitive.uint8), A3=reader.read(Primitive.uint16), A4=reader.read(Primitive.float), A5=read_c(reader)) def main(source): return read_a(BinaryReader(source, offset=5))" "import struct def main(data): A = struct.unpack_from('H', s[start.a:start + 2])[0] add = unpack('>I', s[start.a:start + 4])[0] arr = unpack('>' + 'I' * size, s[add:add + 4 * size]) return list(arr) def chartoStr(chars): res = '' for i in chars: res += i.decode() return res def E(s, start): start = Counter(start) return {'E1': unpack('BBBBBB', s[start.a:start + 6])), 'D2': unpack('>B', s[start.a:start + 1])[0]} def C(s, start): start = Counter(start) return {'C1': unpack('>f', s[start.a:start + 4])[0], 'C2': unpack('>B', s[start.a:start + 1])[0], 'C3': unpack('>i', s[start.a:start + 4])[0], 'C4': unpack('>b', s[start.a:start + 1])[0]} def B(s, start): start = Counter(start) return {'B1': [C(s, unpack('>H', s[start.a:start + 2])[0]) for _ in range(8)], 'B2': chartoStr(unpack('>ccccc', s[start.a:start + 5])), 'B3': unpack('>b', s[start.a:start + 1])[0], 'B4': D(s, unpack('>H', s[start.a:start + 2])[0]), 'B5': unpack('>H', s[start.a:start + 2])[0], 'B6': u16u32u32(s, start)} def A(s, start): return {'A1': unpack('>i', s[start.a:start + 4])[0], 'A2': B(s, unpack('>I', s[start.a:start + 4])[0])} def main(s): start = Counter(4) return A(s, start)" "import struct def structA(data, pointer): (a1,) = struct.unpack('h', data[pointer:pointer + 2]) (double_e,) = struct.unpack('>d', data[pointer + 2:pointer + 10]) return {'E1': int16_e, 'E2': double_e} def structD(data, pointer): (int32_d,) = struct.unpack('>i', data[pointer:pointer + 4]) f2 = struct.unpack('>2H', data[pointer + 4:pointer + 8]) a2 = list(struct.unpack(f'>{f2[0]}H', data[f2[1]:f2[1] + f2[0] * 2])) (uint8_d,) = struct.unpack('>B', data[pointer + 8:pointer + 9]) return {'D1': int32_d, 'D2': a2, 'D3': uint8_d} def structC(data, pointer): (float_c,) = struct.unpack('>f', data[pointer:pointer + 4]) (uint64_c,) = struct.unpack('>Q', data[pointer + 4:pointer + 12]) (array_c,) = struct.unpack('>c', data[pointer + 12:pointer + 13]) (array_c_2,) = struct.unpack('>c', data[pointer + 13:pointer + 14]) (array_c_3,) = struct.unpack('>c', data[pointer + 14:pointer + 15]) (array_c_4,) = struct.unpack('>c', data[pointer + 15:pointer + 16]) (array_c_5,) = struct.unpack('>c', data[pointer + 16:pointer + 17]) (array_c_6,) = struct.unpack('>c', data[pointer + 17:pointer + 18]) (array_c_7,) = struct.unpack('>c', data[pointer + 18:pointer + 19]) array_char = '' array_char += chr(array_c[0]) + chr(array_c_2[0]) array_char += chr(array_c_3[0]) + chr(array_c_4[0]) array_char += chr(array_c_5[0]) + chr(array_c_6[0]) array_char += chr(array_c_7[0]) f1 = struct.unpack('>2H', data[pointer + 19:pointer + 23]) c1 = [] count = f1[0] for i in range(count): f3 = structD(data, f1[1] + i * 9) c1.append(f3) (uint8_c,) = struct.unpack('>B', data[pointer + 23:pointer + 24]) (uint16_c,) = struct.unpack('>H', data[pointer + 24:pointer + 26]) return {'C1': float_c, 'C2': uint64_c, 'C3': array_char, 'C4': c1, 'C5': uint8_c, 'C6': uint16_c} def structB(data, pointer): (int8_b,) = struct.unpack('>b', data[pointer:pointer + 1]) (int64_b,) = struct.unpack('>q', data[pointer + 1:pointer + 9]) return {'B1': int8_b, 'B2': int64_b} def structA(data, pointer): (uint8_a,) = struct.unpack('>B', data[pointer:pointer + 1]) (f_uint32,) = struct.unpack('>I', data[pointer + 1:pointer + 5]) uint32 = structB(data, f_uint32) (int16_a,) = struct.unpack('>h', data[pointer + 5:pointer + 7]) (float_a,) = struct.unpack('>f', data[pointer + 7:pointer + 11]) strC = structC(data, pointer + 11) f2 = struct.unpack('>HI', data[pointer + 37:pointer + 43]) a2 = list(struct.unpack(f'>{f2[0]}h', data[f2[1]:f2[1] + f2[0] * 2])) (f_uint32,) = struct.unpack('>I', data[pointer + 43:pointer + 47]) uint32_a = structE(data, f_uint32) return {'A1': uint8_a, 'A2': uint32, 'A3': int16_a, 'A4': float_a, 'A5': strC, 'A6': a2, 'A7': uint32_a} def main(data): return structA(data, 3)" "from struct import * def unpackSimple(packed_data, type_of, current_offset): return (unpack_from(type_of, packed_data, current_offset)[0], current_offset + calcsize(type_of)) def unpackA(packed_data, current_offset): (A1, current_offset) = unpackB(packed_data, current_offset) (A2, current_offset) = unpackSimple(packed_data, '>I', current_offset) return (dict(A1=A1, A2=A2), current_offset) def unpackB(packed_data, current_offset): (B1, current_offset) = unpackSimple(packed_data, '>H', current_offset) B2 = [] for i in range(8): (c, current_offset) = unpackSimple(packed_data, '>c', current_offset) B2.append(c.decode()) (B3, current_offset) = unpackSimple(packed_data, '>d', current_offset) B4 = [] (B4_size, current_offset) = unpackSimple(packed_data, '>H', current_offset) (B4_adress, current_offset) = unpackSimple(packed_data, '>H', current_offset) for i in range(B4_size): (C_adress, B4_adress) = unpackSimple(packed_data, '>I', B4_adress) B4.append(unpackC(packed_data, C_adress)[0]) B5 = [] for i in range(2): (d, current_offset) = unpackSimple(packed_data, '>d', current_offset) B5.append(d) (B6, current_offset) = unpackSimple(packed_data, '>Q', current_offset) (B7, current_offset) = unpackSimple(packed_data, '>d', current_offset) (B8_adress, current_offset) = unpackSimple(packed_data, '>H', current_offset) B8 = unpackD(packed_data, B8_adress)[0] return (dict(B1=B1, B2=''.join(B2), B3=B3, B4=B4, B5=B5, B6=B6, B7=B7, B8=B8), current_offset) def unpackC(packed_data, current_offset): (C1, current_offset) = unpackSimple(packed_data, '>H', current_offset) C2 = [] for i in range(3): (i16, current_offset) = unpackSimple(packed_data, '>h', current_offset) C2.append(i16) (C3, current_offset) = unpackSimple(packed_data, '>f', current_offset) return (dict(C1=C1, C2=C2, C3=C3), current_offset) def unpackD(packed_data, current_offset): (D1, current_offset) = unpackSimple(packed_data, '>i', current_offset) (D2, current_offset) = unpackSimple(packed_data, '>i', current_offset) (D3, current_offset) = unpackSimple(packed_data, '>I', current_offset) (D4, current_offset) = unpackSimple(packed_data, '>d', current_offset) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), current_offset) def main(packed_data): return unpackA(packed_data, 5)[0]" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structE: def fill_struct(self, b): global BYTE_INDEX self.set_int32_1(my_repack(' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [a2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 return {'A1': struct_b(a1), 'A2': a2} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [b2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [b3] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [b4] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [b5] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [b6] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 b7 = [struct_c(offset), struct_c(offset + 16)] offset += 2 * 16 b8 = struct_f(offset) offset += 38 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [c3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [c4] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [c5] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'C1': c1, 'C2': struct_d(c2), 'C3': struct_e(c3), 'C4': c4, 'C5': c5} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [d2] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [d3] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 return {'D1': d1, 'D2': d2, 'D3': d3} def struct_e(offset: int) -> dict: [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 e1 = list(struct.unpack('< ' + str(length1) + 'I', binary[link_str:link_str + length1 * 4])) [e2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'E1': e1, 'E2': e2} def struct_f(offset: int) -> dict: [f1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [f2] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 [f3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [f4] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 f5 = list(struct.unpack('< 2I', binary[offset:offset + 2 * 4])) offset += 2 * 4 [f6] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 f7 = list(struct.unpack('< ' + str(length1) + 'Q', binary[link_str:link_str + length1 * 8])) [f8] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7, 'F8': f8} return struct_a(5)" "import struct def main(data): return struct_a_parse(data, 4) def unpack_char(data, size, offset): data = struct.unpack('<%ds' % size, data[offset:offset + size]) data = data[0] data = data.decode('utf-8') return (data, offset + size) def unpack_uint(data, offset, bytes_num): if bytes_num == 1: data = struct.unpack('H', bytes, offset=4 + i * 2)[0]) B2 = unpack_from('>d', bytes, offset=10)[0] B3 = unpack_from('>Q', bytes, offset=18)[0] B4 = unpack_from('>q', bytes, offset=26)[0] C = [] for address in addresses_c: C1 = unpack_from('>H', bytes, offset=address)[0] size_array_uint16 = unpack_from('>H', bytes, offset=address + 2)[0] address_array_uint16 = unpack_from('>H', bytes, offset=address + 4)[0] C2 = [] for i in range(size_array_uint16): C2.append(unpack_from('>H', bytes, offset=address_array_uint16 + i * 2)[0]) C3 = unpack_from('>i', bytes, offset=address + 6)[0] C4 = unpack_from('>I', bytes, offset=address + 10)[0] C5 = unpack_from('>H', bytes, offset=address + 14)[0] C.append({'C1': C1, 'C2': C2, 'C3': C3, 'C4': C4, 'C5': C5}) D = [] for i in range(2): D1 = unpack_from('>b', bytes, offset=34 + i * 22)[0] D2 = [] for j in range(7): D2.append(unpack_from('>h', bytes, offset=35 + j * 2 + i * 22)[0]) D3 = unpack_from('>f', bytes, offset=49 + i * 22)[0] D4 = unpack_from('>b', bytes, offset=53 + i * 22)[0] D5 = unpack_from('>H', bytes, offset=54 + i * 22)[0] D.append({'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5}) A3 = unpack_from('>f', bytes, offset=78)[0] A4 = unpack_from('>f', bytes, offset=82)[0] A5 = unpack_from('>I', bytes, offset=86)[0] answer = {'A1': {'B1': C, 'B2': B2, 'B3': B3, 'B4': B4}, 'A2': D, 'A3': A3, 'A4': A4, 'A5': A5} return answer" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, it): return (unpack_from('>' + FMT[it], buf, offs)[0], offs + calcsize(FMT[it])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint64') (a2_offs, offs) = parse(buf, offs, 'uint32') (a2, a2_offs) = parse_b(buf, a2_offs) (a3, offs) = parse(buf, offs, 'int32') a4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'char') a4.append(val.decode()) (a5_size, offs) = parse(buf, offs, 'uint32') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse_c(buf, a5_offs) a5.append(val) (a6, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') b2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'char') b2.append(val.decode()) (b3, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=''.join(b2), B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int8') (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'uint16') (c6, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'uint8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'uint32') (d4, offs) = parse(buf, offs, 'uint32') (d5, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct from pprint import pprint from typing import List def main(data: bytes): if data[:4] != b'QMY\x18': raise SyntaxError() format = '>IHHi' size = struct.calcsize(format) (A11, A12, A2, A3) = struct.unpack(format, data[4:4 + size]) return dict(A1=parse_arr(data, A12, 'I', A11), A2=parse_b(data, A2), A3=A3) def parse_arr(data: bytes, offset: int, cfmt: str, count: int): fmt = '>' + cfmt * count size = struct.calcsize(fmt) return list(struct.unpack(fmt, data[offset:offset + size])) def parse_arr_c(data, count, offset): fmt = '>' + 'bII' list_c = list() size = struct.calcsize(fmt) for i in range(count): list_c.append(parse_c(data, offset + size * i)) return list_c def parse_b(data, offset): fmt = '>IHh BBB' size = struct.calcsize(fmt) (B1, B2, B3, B4, *arr) = struct.unpack(fmt, data[offset:offset + size]) return dict(B1=parse_arr_c(data, B1, B2), B2=B3, B3={'D1': B4, 'D2': arr}) def parse_c(data, offset): fmt = '>bII' size = struct.calcsize(fmt) (C1, C21, C22) = struct.unpack(fmt, data[offset:offset + size]) return dict(C1=C1, C2=parse_arr(data, C22, 'I', C21))" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse(buf, offs, 'int16') (a3, offs) = parse_b(buf, offs) (a4, offs) = parse(buf, offs, 'double') (a5, offs) = parse_c(buf, offs) (a6, offs) = parse(buf, offs, 'int8') (a7, offs) = parse(buf, offs, 'int32') (a8_size, offs) = parse(buf, offs, 'uint16') (a8_offs, offs) = parse(buf, offs, 'uint32') a8 = [] for _ in range(a8_size): (val, a8_offs) = parse(buf, a8_offs, 'float') a8.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse(buf, offs, 'uint8') (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint16') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'double') b4.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'int32') (c3, offs) = parse(buf, offs, 'int16') (c4, offs) = parse(buf, offs, 'uint8') c5 = [] for _ in range(2): (c5_offs, offs) = parse(buf, offs, 'uint32') (val, c5_offs) = parse_d(buf, c5_offs) c5.append(val) c6 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') c6.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint64') (d3, offs) = parse(buf, offs, 'int8') (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse(buf, offs, 'uint8') (d6, offs) = parse(buf, offs, 'uint16') (d7, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable from pprint import pprint class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_uint16() d2 = reader.read_int16() d3 = reader.read_float() d4 = reader.read_uint16() d5 = reader.read_int8() d6 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_float(), structure_size=4) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6) def read_c(reader: BinaryReader): c1 = reader.read_float() c2 = reader.read_uint32() c3 = reader.read_uint64() c4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint8()) c5 = reader.read_int32() return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def read_b(reader: BinaryReader): b1 = reader.read_float() x = '' for i in range(6): x += reader.read_char().decode('ascii') b2 = x x = '' for i in range(6): x += reader.read_char().decode('ascii') b3 = x b4 = reader.read_float() return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_a(reader: BinaryReader): a1 = reader.read_float() a2 = read_b(reader) a3 = [read_array(source=reader.source, size=4, address=reader.read_uint32(), read=lambda reader: read_c(reader))[0] for i in range(3)] a4 = read_d(reader) a5 = reader.read_uint64() return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "from struct import unpack def find_starting_address(file): address = 0 for byte in file: address += 1 if byte == 68: break return address def main(file): a_adr = find_starting_address(file) a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 9)} c = {f'C{i}': None for i in range(1, 6)} e = {f'E{i}': None for i in range(1, 6)} temp = unpack('lHLbBQBLb', file[a_adr:a_adr + 26]) (a['A1'], c_str_size, c_str_adr, b['B2'], b['B3'], b['B4'], b['B5'], d_adr, a['A3']) = temp temp = unpack('>4LHH3H', file[d_adr:d_adr + 32]) d['D1'] = list(temp[0:4]) (uint32_size, uint32_adr) = temp[4:6] d['D3'] = list(temp[6:]) temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) d['D2'] = list(temp) c_strs = unpack(f'>{c_str_size}L', file[c_str_adr:c_str_adr + c_str_size * 4]) b['B1'] = [] for c_str in c_strs: temp = unpack('>lHb', file[c_str:c_str + 7]) (c['C1'], c['C2'], c['C3']) = temp b['B1'].append(c.copy()) a['A2'] = b b['B6'] = d return a" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>BIq', data[pointer:pointer + 13]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): c1 = struct.unpack('>f', data[pointer:pointer + 4])[0] f2 = struct.unpack('>I', data[pointer + 4:pointer + 8]) c2 = parse_d(data, f2[0]) c3 = ''.join(map(str, struct.unpack('>8c', data[pointer + 8:pointer + 16]))) c3 = c3.replace(""'"", '')[1::2] f4 = struct.unpack('>HH', data[pointer + 16:pointer + 20]) f5 = struct.unpack('>IH', data[pointer + 20:pointer + 26]) c4 = list(struct.unpack(f'>{f4[0]}H', data[f4[1]:f4[1] + f4[0] * 2])) c5 = list(struct.unpack(f'>{f5[0]}I', data[f5[1]:f5[1] + f5[0] * 4])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): (b1, b2, b3, b4) = struct.unpack('>bfBi', data[pointer:pointer + 10]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): a1 = list() for i in range(3): a1.append(parse_b(data, pointer + i * 10)) f2 = struct.unpack('>H', data[pointer + 30:pointer + 32]) a2 = parse_c(data, f2[0]) (a3, a4, a5, a6, a7) = struct.unpack('>ddfbB', data[pointer + 32:pointer + 54]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 3)" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>d', data[offset:offset + 8])[0] result['E2'] = struct.unpack('>Q', data[offset + 8:offset + 8 + 8])[0] return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>h', data[offset:offset + 2])[0] (d2_size, d2_address) = struct.unpack('>HI', data[offset + 2:offset + 2 + 6]) result['D2'] = parse_array(data, d2_address, 'b', d2_size) result['D3'] = struct.unpack('>I', data[offset + 8:offset + 8 + 4])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['C2'] = struct.unpack('>I', data[offset + 1:offset + 1 + 4])[0] result['C3'] = parse_array(data, offset + 5, 'b', 7) result['C4'] = struct.unpack('>b', data[offset + 12:offset + 12 + 1])[0] result['C5'] = struct.unpack('>f', data[offset + 13:offset + 13 + 4])[0] result['C6'] = struct.unpack('>H', data[offset + 17:offset + 17 + 2])[0] return result def parse_b(data, offset): result = dict() (b1_size, b1_addr) = struct.unpack('>II', data[offset:offset + 8]) result['B1'] = ''.join([str(c, 'utf-8') for c in parse_array(data, b1_addr, 'c', b1_size)]) result['B2'] = parse_c(data, offset + 8) result['B3'] = struct.unpack('>i', data[offset + 27:offset + 27 + 4])[0] result['B4'] = struct.unpack('>f', data[offset + 31:offset + 31 + 4])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>i', data[offset:offset + 4])[0] b_addresses = parse_array(data, offset + 4, 'I', 3) result['A2'] = [parse_b(data, addr) for addr in b_addresses] result['A3'] = parse_d(data, offset + 16) result['A4'] = struct.unpack('>I', data[offset + 28:offset + 28 + 4])[0] result['A5'] = parse_e(data, offset + 32) result['A6'] = struct.unpack('>Q', data[offset + 48:offset + 48 + 8])[0] result['A7'] = struct.unpack('>d', data[offset + 56:offset + 56 + 8])[0] return result def main(data): return parse_a(data, 5)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 a2 = struct_b(offset) offset += 4 + 8 + 8 + 4 + 10 + 8 + 8 + 2 + 1 + 8 [a3] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 return {'A1': a1, 'A2': a2, 'A3': a3} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 b2 = list(struct.unpack('< ' + str(length1) + 'I', binary[link_str:link_str + length1 * 4])) [b3] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 b4 = struct_e(offset) offset += 4 + 10 + 8 + 8 + 2 + 1 [b5] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'B1': b1, 'B2': [struct_c(i) for i in b2], 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [c2] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [c3] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [c4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [c5] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [c6] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'C1': struct_d(c1), 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [d2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [d3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def struct_e(offset: int) -> dict: [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 e1 = list(struct.unpack('< ' + str(length1) + 'H', binary[link_str:link_str + length1 * 2])) e2 = struct_f(offset) offset += 6 + 4 [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 e3 = list(struct.unpack('< ' + str(length1) + 'B', binary[link_str:link_str + length1 * 1])) [e4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [e5] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [e6] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6} def struct_f(offset: int) -> dict: [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 f1 = list(struct.unpack('< ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) [f2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'F1': f1, 'F2': f2} return struct_a(4)" "import struct def main(x): f = dict() f['A1'] = struct.unpack('>d', x[4:12])[0] pos1 = struct.unpack('>I', x[12:16])[0] pos2 = struct.unpack('>I', x[pos1:pos1 + 4])[0] pos3 = struct.unpack('>I', x[pos2 + 2:pos2 + 6])[0] c1 = [] for i in range(0, struct.unpack('>H', x[pos2:pos2 + 2])[0]): d = dict() pos4 = struct.unpack('>H', x[pos3:pos3 + 2])[0] d['D1'] = struct.unpack('>B', x[pos4:pos4 + 1])[0] d['D2'] = struct.unpack('>h', x[pos4 + 1:pos4 + 3])[0] d['D3'] = struct.unpack('>b', x[pos4 + 3:pos4 + 4])[0] pos3 += 2 c1.append(d) c2 = struct.unpack('>B', x[pos2 + 6:pos2 + 7])[0] c3 = struct.unpack('>b', x[pos2 + 7:pos2 + 8])[0] c4 = list(struct.unpack('>8H', x[pos2 + 8:pos2 + 24])) c5 = struct.unpack('>i', x[pos2 + 24:pos2 + 28])[0] b1 = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} b2 = struct.unpack('>Q', x[pos1 + 4:pos1 + 12])[0] b3 = struct.unpack('>Q', x[pos1 + 12:pos1 + 20])[0] f['A2'] = {'B1': b1, 'B2': b2, 'B3': b3} pos1 = struct.unpack('>H', x[16:18])[0] e1 = struct.unpack('>I', x[pos1:pos1 + 4])[0] di = struct.unpack('>H', x[pos1 + 4:pos1 + 6])[0] dis = '>' + str(di) + 'B' pos2 = struct.unpack('>I', x[pos1 + 6:pos1 + 10])[0] e2 = list(struct.unpack(dis, x[pos2:pos2 + di])) di = struct.unpack('>I', x[pos1 + 10:pos1 + 14])[0] dis = '>' + str(di) + 'f' pos2 = struct.unpack('>H', x[pos1 + 14:pos1 + 16])[0] e3 = list(struct.unpack(dis, x[pos2:pos2 + di * 4])) f['A3'] = {'E1': e1, 'E2': e2, 'E3': e3} pos1 = struct.unpack('>H', x[18:20])[0] f1 = struct.unpack('>b', x[pos1:pos1 + 1])[0] f2 = struct.unpack('>I', x[pos1 + 1:pos1 + 5])[0] f3 = struct.unpack('>B', x[pos1 + 5:pos1 + 6])[0] f['A4'] = {'F1': f1, 'F2': f2, 'F3': f3} g1 = struct.unpack('>f', x[20:24])[0] g2 = struct.unpack('>d', x[24:32])[0] g3 = struct.unpack('>H', x[32:34])[0] g4 = struct.unpack('>Q', x[34:42])[0] g5 = struct.unpack('>b', x[42:43])[0] g6 = struct.unpack('>q', x[43:51])[0] f['A5'] = {'G1': g1, 'G2': g2, 'G3': g3, 'G4': g4, 'G5': g5, 'G6': g6} di = struct.unpack('>H', x[51:53])[0] dis = '>' + str(di) + 'i' pos1 = struct.unpack('>I', x[53:57])[0] f['A6'] = list(struct.unpack(dis, x[pos1:pos1 + di * 4])) return f" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [a2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 le = 4 + 4 + 11 + 2 + 2 + 20 a3 = [struct_b(offset + i * le) for i in range(2)] offset += (4 + 4 + 11 + 2 + 2 + 20) * 2 return {'A1': a1, 'A2': a2, 'A3': a3} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [b2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 b3 = struct_d(offset) offset += 1 + 4 + 6 [b4] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [b5] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 b6 = struct_e(offset) offset += 8 + 4 + 8 return {'B1': b1, 'B2': struct_c(b2), 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [c3] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [d2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 d3 = list(struct.unpack('< ' + str(length1) + 'b', binary[link_str:link_str + length1 * 1])) return {'D1': d1, 'D2': d2, 'D3': d3} def struct_e(offset: int) -> dict: [e1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 e2 = list(struct.unpack('< ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 e3 = list(struct.unpack('< ' + str(length1) + 'b', binary[link_str:link_str + length1 * 1])) return {'E1': e1, 'E2': e2, 'E3': e3} return struct_a(5)" "from struct import * def parseMin(buf, ty, beg): return (unpack_from(ty, buf, beg)[0], beg + calcsize(ty)) def parseA(buf, beg): (A1, beg) = parseMin(buf, '>i', beg) (A2, beg) = parseMin(buf, '>Q', beg) A3 = [] for i in range(2): (b, beg) = parseB(buf, beg) A3.append(b) (A4, beg) = parseC(buf, beg) A5 = [] for i in range(6): (i8, beg) = parseMin(buf, '>b', beg) A5.append(i8) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), beg) def parseB(buf, beg): B1 = [] for i in range(8): (c, beg) = parseMin(buf, '>c', beg) B1.append(c.decode()) (B2, beg) = parseMin(buf, '>B', beg) return (dict(B1=''.join(B1), B2=B2), beg) def parseC(buf, beg): (C1, beg) = parseD(buf, beg) (C2_adress, beg) = parseMin(buf, '>I', beg) (C2, C2_adress) = parseE(buf, C2_adress) return (dict(C1=C1, C2=C2), beg) def parseD(buf, beg): (D1, beg) = parseMin(buf, '>i', beg) (D2, beg) = parseMin(buf, '>h', beg) (D3, beg) = parseMin(buf, '>i', beg) return (dict(D1=D1, D2=D2, D3=D3), beg) def parseE(buf, beg): E1 = [] (E1_size, beg) = parseMin(buf, '>I', beg) (E1_adress, beg) = parseMin(buf, '>H', beg) for i in range(E1_size): (u16, E1_adress) = parseMin(buf, '>H', E1_adress) E1.append(u16) (E2, beg) = parseMin(buf, '>f', beg) (E3, beg) = parseMin(buf, '>H', beg) (E4, beg) = parseMin(buf, '>f', beg) E5 = [] for i in range(6): (u32, beg) = parseMin(buf, '>I', beg) E5.append(u32) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5), beg) def main(buf): return parseA(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '>' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int32') (a2, offs) = parse(buf, offs, 'float') (a3, offs) = parse_b(buf, offs) (a4_size, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint32') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'double') a4.append(val) (a5, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse(buf, offs, 'int32') (b3, offs) = parse(buf, offs, 'uint8') (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse_c(buf, b4_offs) b4.append(val) (b5, offs) = parse_d(buf, offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') c2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'int32') d1.append(val) d2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'double') a3 = '' for _ in range(2): (val, offs) = parse(buf, offs, 'char') a3 = a3 + val.decode() (temp, offs) = parse(buf, offs, 'uint16') a4 = parse_d(buf, temp)[0] return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'uint8') (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint16') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse_c(buf, b4_offs) b4.append(val) b5 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int8') b5.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint16') (c2, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int64') d1.append(val) (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int32') (a3, offs) = parse(buf, offs, 'int8') (a4, offs) = parse(buf, offs, 'float') a5 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'char') a5.append(val.decode()) a6 = [] for _ in range(6): (val, offs) = parse_d(buf, offs) a6.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=''.join(a5), A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint64') (b2, offs) = parse(buf, offs, 'int32') (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'int32') (b5, offs) = parse(buf, offs, 'float') (b6_offs, offs) = parse(buf, offs, 'uint16') (b6, b6_offs) = parse_c(buf, b6_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode()) (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'float') (c5, offs) = parse(buf, offs, 'int8') (c6, offs) = parse(buf, offs, 'uint32') (c7, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): d1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'float') d1.append(val) (d2, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(binary: bytes) -> dict: def struct_a(index: int) -> dict: a1 = struct_b(index) index += 30 [a2] = struct.unpack('> B', binary[index:index + 1]) index += 1 [a3] = struct.unpack('> b', binary[index:index + 1]) index += 1 return {'A1': a1, 'A2': a2, 'A3': a3} def struct_b(index: int) -> dict: (s, offset) = struct.unpack('> H I', binary[index:index + 6]) b1 = [struct_c(offset + i * 21) for i in range(s)] index += 6 (s1, add) = struct.unpack('> I H', binary[index:index + 6]) b2 = list(struct.unpack('>' + str(s1) + 'b', binary[add:add + s1])) index += 6 [b3] = struct.unpack('> H', binary[index:index + 2]) index += 2 (s2, add2) = struct.unpack('> I I', binary[index:index + 8]) b4 = list(struct.unpack('>' + str(s2) + 'i', binary[add2:add2 + 4 * s2])) index += 8 [b5] = struct.unpack('> Q', binary[index:index + 8]) index += 8 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(index: int) -> dict: c1 = list(struct.unpack('> 4B', binary[index:index + 4])) index += 4 [c2] = struct.unpack('> I', binary[index:index + 4]) index += 4 [c3] = struct.unpack('> I', binary[index:index + 4]) index += 4 [c4] = struct.unpack('> H', binary[index:index + 2]) index += 2 [c5] = struct.unpack('> B', binary[index:index + 1]) index += 1 (s, add) = struct.unpack('> I H', binary[index:index + 6]) c6 = list(struct.unpack('>' + str(s) + 'h', binary[add:add + 2 * s])) index += 6 return {'C1': c1, 'C2': struct_d(c2), 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def struct_d(index: int) -> dict: [d1] = struct.unpack('> H', binary[index:index + 2]) index += 2 [d2] = struct.unpack('> h', binary[index:index + 2]) index += 2 [d3] = struct.unpack('> b', binary[index:index + 1]) index += 1 [d4] = struct.unpack('> h', binary[index:index + 2]) index += 2 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} return struct_a(5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') (a3, a3_offs) = parse_b(buf, a3_offs) a4 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint64') a4.append(val) (a5, offs) = parse(buf, offs, 'uint16') (a6, offs) = parse(buf, offs, 'double') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'int32') b4 = '' for _ in range(6): (val, offs) = parse(buf, offs, 'char') b4 += val.decode() (b5, offs) = parse(buf, offs, 'int32') (b6_size, offs) = parse(buf, offs, 'uint32') (b6_offs, offs) = parse(buf, offs, 'uint32') b6 = [] for _ in range(b6_size): (val, b6_offs) = parse_c(buf, b6_offs) b6.append(val) (b7_offs, offs) = parse(buf, offs, 'uint32') (b7, b7_offs) = parse_d(buf, b7_offs) (b8, offs) = parse(buf, offs, 'uint16') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'uint64') (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'int32') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * def parse(buf, ty, beg): return (unpack_from(ty, buf, beg)[0], beg + calcsize(ty)) def parseA(buf, beg): A1 = [] (A1_size, beg) = parse(buf, 'I', beg) (A1_adress, beg) = parse(buf, 'I', beg) for i in range(A1_size): (b, A1_adress) = parseB(buf, A1_adress) A1.append(b) (A2, beg) = parse(buf, 'q', beg) (A3, beg) = parse(buf, 'i', beg) (A4, beg) = parseC(buf, beg) (A5, beg) = parse(buf, 'i', beg) (A6, beg) = parse(buf, 'h', beg) A7 = [] for i in range(4): (i32, beg) = parse(buf, 'i', beg) A7.append(i32) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), beg) def parseB(buf, beg): B1 = [] for i in range(5): (c, beg) = parse(buf, 'c', beg) B1.append(c.decode()) (B2, beg) = parse(buf, 'H', beg) return (dict(B1=''.join(B1), B2=B2), beg) def parseC(buf, beg): (C1_adress, beg) = parse(buf, 'H', beg) (C1, C1_adress) = parseD(buf, C1_adress) (C2, beg) = parseE(buf, beg) return (dict(C1=C1, C2=C2), beg) def parseD(buf, beg): (D1, beg) = parse(buf, 'h', beg) D2 = [] (D2_size, beg) = parse(buf, 'H', beg) (D2_adress, beg) = parse(buf, 'I', beg) for i in range(D2_size): (d, D2_adress) = parse(buf, 'd', D2_adress) D2.append(d) (D3, beg) = parse(buf, 'h', beg) (D4, beg) = parse(buf, 'Q', beg) (D5, beg) = parse(buf, 'h', beg) (D6, beg) = parse(buf, 'd', beg) (D7, beg) = parse(buf, 'b', beg) (D8, beg) = parse(buf, 'i', beg) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6, D7=D7, D8=D8), beg) def parseE(buf, beg): E1 = [] (E1_size, beg) = parse(buf, 'I', beg) (E1_adress, beg) = parse(buf, 'I', beg) for i in range(E1_size): (i8, E1_adress) = parse(buf, 'b', E1_adress) E1.append(i8) (E2, beg) = parse(buf, 'f', beg) (E3, beg) = parse(buf, 'q', beg) (E4, beg) = parse(buf, 'B', beg) (E5, beg) = parse(buf, 'H', beg) (E6, beg) = parse(buf, 'I', beg) (E7, beg) = parse(buf, 'f', beg) (E8, beg) = parse(buf, 'H', beg) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7, E8=E8), beg) def main(buf): return parseA(buf, 5)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def un_pack(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def unpack_a(buf, offs): (a1, offs) = unpack_b(buf, offs) (a2, offs) = un_pack(buf, offs, 'uint32') (a3, offs) = un_pack(buf, offs, 'int64') (a4_offset, offs) = un_pack(buf, offs, 'uint16') a4 = unpack_d(buf, a4_offset) return ({'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4}, offs) def unpack_b(buf, offs): (b1, offs) = un_pack(buf, offs, 'int16') (b2, offs) = un_pack(buf, offs, 'uint8') b3 = [] for _ in range(4): (c_offset, offs) = un_pack(buf, offs, 'uint16') (c, _) = unpack_c(buf, c_offset) b3.append(c) return ({'B1': b1, 'B2': b2, 'B3': b3}, offs) def unpack_c(buf, offs): (c1_size, offs) = un_pack(buf, offs, 'uint16') (c1_offs, offs) = un_pack(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = un_pack(buf, c1_offs, 'int16') c1.append(val) (c2_size, offs) = un_pack(buf, offs, 'uint32') (c2_offs, offs) = un_pack(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = un_pack(buf, c2_offs, 'uint16') c2.append(val) (c3, offs) = un_pack(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3), offs) def unpack_d(buf, offs): d1 = [] for _ in range(2): (val, offs) = un_pack(buf, offs, 'int64') d1.append(val) (d2, offs) = un_pack(buf, offs, 'uint16') return dict(D1=d1, D2=d2) def main(buffer): return unpack_a(buffer, 5)[0]" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): e1 = [] for _ in range(0, 6): (val, offs) = parse(buf, offs, 'uint16') e1.append(val) e2 = [] for _ in range(0, 3): (val, offs) = parse(buf, offs, 'uint32') e2.append(val) return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int16') (d3, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_c(buf, offs): c1 = [] for i in range(0, 6): (val, offs) = parse(buf, offs, 'int8') c1.append(val) (c2, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'char') b2.append(val.decode()) (b3, offs) = parse(buf, offs, 'int8') (b4, offs) = parse(buf, offs, 'int8') (b5, offs) = parse(buf, offs, 'int16') (b6, offs) = parse_c(buf, offs) (b7, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=''.join(b2), B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'int8') a2.append(val) (a3, offs) = parse(buf, offs, 'int32') (a4, offs) = parse_d(buf, offs) (a5, offs) = parse(buf, offs, 'int8') (a6, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def structA(data, pointer): (a1,) = struct.unpack('>q', data[pointer:pointer + 8]) f2 = struct.unpack('>I', data[pointer + 8:pointer + 12]) a2 = structB(data, f2[0]) f3 = struct.unpack('>HH', data[pointer + 12:pointer + 16]) a3 = [] for i in range(f3[0]): x = structE(data, f3[1] + i * 15) a3.append(x) f4 = struct.unpack('>HH', data[pointer + 16:pointer + 20]) a4 = list(struct.unpack(f'>{f4[0]}f', data[f4[1]:f4[1] + f4[0] * 4])) (a5,) = struct.unpack('>H', data[pointer + 20:pointer + 22]) (a6,) = struct.unpack('>B', data[pointer + 22:pointer + 23]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def structB(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) b1 = list(struct.unpack(f'>{f1[0]}d', data[f1[1]:f1[1] + f1[0] * 8])) b2 = structC(data, pointer + 4) return {'B1': b1, 'B2': b2} def structC(data, pointer): (c1,) = struct.unpack('>B', data[pointer:pointer + 1]) (f2,) = struct.unpack('>H', data[pointer + 1:pointer + 3]) c2 = structD(data, f2) (c3,) = struct.unpack('>f', data[pointer + 3:pointer + 7]) return {'C1': c1, 'C2': c2, 'C3': c3} def structD(data, pointer): (d1,) = struct.unpack('>H', data[pointer:pointer + 2]) (d2,) = struct.unpack('>H', data[pointer + 2:pointer + 4]) (d3,) = struct.unpack('>I', data[pointer + 4:pointer + 8]) return {'D1': d1, 'D2': d2, 'D3': d3} def structE(data, pointer): (e1,) = struct.unpack('>B', data[pointer:pointer + 1]) (e2,) = struct.unpack('>Q', data[pointer + 1:pointer + 9]) f3 = struct.unpack('>HI', data[pointer + 9:pointer + 15]) e3 = list(struct.unpack(f'>{f3[0]}B', data[f3[1]:f3[1] + f3[0]])) return {'E1': e1, 'E2': e2, 'E3': e3} def main(data): return structA(data, 5)" "from struct import * def parse(buf, ty, beg): return (unpack_from(ty, buf, beg)[0], beg + calcsize(ty)) def parseA(buf, beg): (A1, beg) = parse(buf, 'B', beg) (A2, beg) = parse(buf, 'B', beg) (A3, beg) = parse(buf, 'I', beg) (A4_adress, beg) = parse(buf, 'I', beg) (A4, A4_adress) = parseB(buf, A4_adress) (A5, beg) = parse(buf, 'd', beg) (A6, beg) = parseC(buf, beg) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), beg) def parseB(buf, beg): (B1, beg) = parse(buf, 'q', beg) (B2, beg) = parse(buf, 'f', beg) return (dict(B1=B1, B2=B2), beg) def parseC(buf, beg): C1 = [] for i in range(6): (u8, beg) = parse(buf, 'B', beg) C1.append(u8) (C2, beg) = parse(buf, 'H', beg) (C3, beg) = parse(buf, 'h', beg) (C4, beg) = parse(buf, 'b', beg) C5 = [] for i in range(3): (C5_adress, beg) = parse(buf, 'H', beg) C5.append(parseD(buf, C5_adress)[0]) (C6_adress, beg) = parse(buf, 'I', beg) (C6, C6_adress) = parseE(buf, C6_adress) C7 = [] for i in range(2): (u64, beg) = parse(buf, 'Q', beg) C7.append(u64) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), beg) def parseD(buf, beg): D1 = [] (D1_size, beg) = parse(buf, 'H', beg) (D1_adress, beg) = parse(buf, 'H', beg) for i in range(D1_size): (i32, D1_adress) = parse(buf, 'i', D1_adress) D1.append(i32) D2 = [] for i in range(4): (u16, beg) = parse(buf, 'H', beg) D2.append(u16) return (dict(D1=D1, D2=D2), beg) def parseE(buf, beg): (E1, beg) = parse(buf, 'i', beg) (E2, beg) = parse(buf, 'h', beg) return (dict(E1=E1, E2=E2), beg) def main(buf): return parseA(buf, 4)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 86: break a = {'A1': None, 'A2': None, 'A3': None, 'A4': None, 'A5': None, 'A6': None, 'A7': None} b = {'B1': None, 'B2': None, 'B3': None, 'B4': None, 'B5': None, 'B6': None} c = {'C1': None, 'C2': None, 'C3': None} temp = unpack('>LqBQLLhB3Hq', file[a_adr:a_adr + 46]) (b_adr, c['C1'], c['C2'], c['C3'], mas_size, mas_adr, a['A4'], a['A5'], *d_adrs, a['A7']) = temp temp = unpack('>%sq' % mas_size, file[mas_adr:mas_adr + mas_size * 8]) a['A3'] = list(temp) temp = unpack('>hiBHHbl', file[b_adr:b_adr + 16]) (b['B1'], b['B2'], b['B3'], mas_size, mas_adr, b['B5'], b['B6']) = temp temp = unpack('>%sc' % mas_size, file[mas_adr:mas_adr + mas_size]) s = '' for el in temp: s += el.decode('utf8') b['B4'] = s a['A6'] = [] for d_adr in d_adrs: temp = unpack('>HLLH', file[d_adr:d_adr + 12]) (mas_size1, mas_adr1, mas_size2, mas_adr2) = temp d1 = list(unpack('>%sb' % mas_size1, file[mas_adr1:mas_adr1 + mas_size1])) d2 = list(unpack('>%sb' % mas_size2, file[mas_adr2:mas_adr2 + mas_size2])) a['A6'].append({'D1': d1, 'D2': d2}) a['A1'] = b a['A2'] = c return a" "import struct def convert(s): new = '' for x in s: new += x return new def main(data): (*d, address_structB, address_structC, int8, massive_uint16_1, massive_uint16_2, massive_uint16_3, massive_uint16_4, massive_uint16_5, uint32, int64, int32) = struct.unpack_from('>5cHIbHHHHHIqh', data) (B_float, B_int16, B_int64) = struct.unpack_from('>fhq', data, address_structB) structEpattern = 'BQqHdbbbbbbbbB' * 2 (C_int16, C_uint32, address_structD, C_int8, E1_uint8, E1_uint64, E1_int64, E1_uint16, E1_double, E1_massive_int8_1, E1_massive_int8_2, E1_massive_int8_3, E1_massive_int8_4, E1_massive_int8_5, E1_massive_int8_6, E1_massive_int8_7, E1_massive_int8_8, E1_uint8_2, E2_uint8, E2_uint64, E2_int64, E2_uint16, E2_double, E2_massive_int8_1, E2_massive_int8_2, E2_massive_int8_3, E2_massive_int8_4, E2_massive_int8_5, E2_massive_int8_6, E2_massive_int8_7, E2_massive_int8_8, E2_uint8_2, C_uint16) = struct.unpack_from('>hIIb' + structEpattern + 'H', data, address_structC) (D_uint16, massive_char_size, massive_char_adress) = struct.unpack_from('>HII', data, address_structD) chars_massive = struct.unpack_from('>' + 'c' * massive_char_size, data, massive_char_adress) string_intoCharMassive = convert([t.decode('UTF-8') for t in chars_massive]) ret = {} ret_struct_B = {} ret_struct_B['B1'] = B_float ret_struct_B['B2'] = B_int16 ret_struct_B['B3'] = B_int64 ret['A1'] = ret_struct_B ret_struct_C = {} ret_struct_C['C1'] = C_int16 ret_struct_C['C2'] = C_uint32 ret_struct_C_structD = {} ret_struct_C_structD['D1'] = D_uint16 ret_struct_C_structD['D2'] = string_intoCharMassive ret_struct_C['C3'] = ret_struct_C_structD ret_struct_C['C4'] = C_int8 ret_struct_C_structE_1 = {} ret_struct_C_structE_1['E1'] = E1_uint8 ret_struct_C_structE_1['E2'] = E1_uint64 ret_struct_C_structE_1['E3'] = E1_int64 ret_struct_C_structE_1['E4'] = E1_uint16 ret_struct_C_structE_1['E5'] = E1_double ret_struct_C_structE_1['E6'] = [E1_massive_int8_1, E1_massive_int8_2, E1_massive_int8_3, E1_massive_int8_4, E1_massive_int8_5, E1_massive_int8_6, E1_massive_int8_7, E1_massive_int8_8] ret_struct_C_structE_1['E7'] = E1_uint8_2 ret_struct_C_structE_2 = {} ret_struct_C_structE_2['E1'] = E2_uint8 ret_struct_C_structE_2['E2'] = E2_uint64 ret_struct_C_structE_2['E3'] = E2_int64 ret_struct_C_structE_2['E4'] = E2_uint16 ret_struct_C_structE_2['E5'] = E2_double ret_struct_C_structE_2['E6'] = [E2_massive_int8_1, E2_massive_int8_2, E2_massive_int8_3, E2_massive_int8_4, E2_massive_int8_5, E2_massive_int8_6, E2_massive_int8_7, E2_massive_int8_8] ret_struct_C_structE_2['E7'] = E2_uint8_2 ret_struct_C['C5'] = [ret_struct_C_structE_1, ret_struct_C_structE_2] ret_struct_C['C6'] = C_uint16 ret['A2'] = ret_struct_C ret['A3'] = int8 ret['A4'] = [massive_uint16_1, massive_uint16_2, massive_uint16_3, massive_uint16_4, massive_uint16_5] ret['A5'] = uint32 ret['A6'] = int64 ret['A7'] = int32 return ret" "import struct def structA(data, pointer): (a1,) = struct.unpack('{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 42 return result def parse_d(data, offset): result = dict() result['D1'] = un('>h', data[offset:offset + 2])[0] (d2_size, d2_addr) = un('>IH', data[offset + 2:offset + 8]) result['D2'] = parse_array(data, d2_addr, 'f', d2_size) result['D3'] = un('>I', data[offset + 8:offset + 12])[0] return result def parse_c(data, offset): result = dict() result['C1'] = un('>B', data[offset:offset + 1])[0] result['C2'] = parse_array(data, offset + 1, 'I', 8) (c3_size, c3_addr) = un('>IH', data[offset + 33:offset + 39]) result['C3'] = parse_array(data, c3_addr, 'I', c3_size) result['C4'] = un('>b', data[offset + 39:offset + 40])[0] result['C5'] = un('>H', data[offset + 40:offset + 42])[0] return result def parse_b(data, offset): result = dict() result['B1'] = un('>h', data[offset:offset + 2])[0] result['B2'] = un('>B', data[offset + 2:offset + 3])[0] result['B3'] = un('>d', data[offset + 3:offset + 11])[0] result['B4'] = un('>f', data[offset + 11:offset + 15])[0] result['B5'] = parse_structure_array(data, offset + 15, 2) result['B6'] = parse_d(data, struct.unpack('>I', data[offset + 99:offset + 103])[0]) result['B7'] = un('>I', data[offset + 103:offset + 107])[0] return result def parse_a(data, offset): result = dict() result['A1'] = un('>d', data[offset:offset + 8])[0] (a2_size, a2_addr) = un('>HH', data[offset + 8:offset + 12]) a2 = [] a2 = ''.join((x.decode('ascii') for x in parse_array(data, a2_addr, 'c', a2_size))) result['A2'] = a2 result['A3'] = un('>f', data[offset + 12:offset + 16])[0] result['A4'] = un('>B', data[offset + 16:offset + 17])[0] result['A5'] = parse_b(data, offset + 17) return result def main(data): return parse_a(data, 5)" "from struct import unpack def main(file): signature = bytes([207, 70, 82, 66, 75]) a_adr = file.find(signature) + len(signature) a = {f'A{i}': None for i in range(1, 6)} temp = unpack('<7sLLdB', file[a_adr:a_adr + 24]) a['A1'] = str(temp[0], 'utf8') (b_adr, d_adr, a['A4'], a['A5']) = temp[1:] b = {f'B{i}': None for i in range(1, 8)} temp = unpack('4cIHQiHHHHHdI', data1) ans['A1'] = (a_str[0] + a_str[1] + a_str[2] + a_str[3]).decode('utf-8') ans['A2'] = a_str[4] b_str = find(a_str[5], b, '>qbQhibB', data1) ans['A3'] = {'B1': b_str[0], 'B2': b_str[1], 'B3': b_str[2], 'B4': b_str[3], 'B5': b_str[4], 'B6': b_str[5], 'B7': b_str[6]} ans['A4'] = a_str[6] ans['A5'] = a_str[7] c_list = [] for adress in a_str[8:11]: c_str = find(adress, c, '>QQQIH', data1) c_dict = {'C1': c_str[0], 'C2': c_str[1], 'C3': c_str[2], 'C4': list(find(c_str[4], c_str[3] * 2, f'>{c_str[3]}h', data1))} c_list.append(c_dict) ans['A6'] = c_list ans['A7'] = {'D1': list(find(a_str[-3], a_str[-4], a_str[-4] * 'B', data1)), 'D2': a_str[-2], 'D3': a_str[-1]} return ans" "import struct def main(binary: bytes) -> dict: def struct_a(index: int) -> dict: a1 = list(struct.unpack('> 2H', binary[index:index + 4])) index += 4 [a2] = struct.unpack('> H', binary[index:index + 2]) index += 2 a3 = struct_c(index) index += 32 [a4] = struct.unpack('> b', binary[index:index + 1]) index += 1 a5 = list(struct.unpack('> 7f', binary[index:index + 28])) index += 28 [a6] = struct.unpack('> I', binary[index:index + 4]) index += 4 return {'A1': [struct_b(i) for i in a1], 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': struct_f(a6)} def struct_b(index: int) -> dict: [b1] = struct.unpack('> b', binary[index:index + 1]) index += 1 [b2] = struct.unpack('> B', binary[index:index + 1]) index += 1 return {'B1': b1, 'B2': b2} def struct_c(index: int) -> dict: [c1] = struct.unpack('> b', binary[index:index + 1]) index += 1 [c2] = struct.unpack('> b', binary[index:index + 1]) index += 1 c3 = struct_d(index) index += 30 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(index: int) -> dict: [d1] = struct.unpack('> Q', binary[index:index + 8]) index += 8 d2 = struct_e(index) index += 22 return {'D1': d1, 'D2': d2} def struct_e(index: int) -> dict: (s, add) = struct.unpack('> H I', binary[index:index + 6]) e1 = list(struct.unpack('>' + str(s) + 'I', binary[add:add + 4 * s])) index += 6 [e2] = struct.unpack('> Q', binary[index:index + 8]) index += 8 (s2, add2) = struct.unpack('> I I', binary[index:index + 8]) e3 = list(struct.unpack('>' + str(s2) + 'B', binary[add2:add2 + s2])) index += 8 return {'E1': e1, 'E2': e2, 'E3': e3} def struct_f(index: int) -> dict: [f1] = struct.unpack('> d', binary[index:index + 8]) index += 8 [f2] = struct.unpack('> i', binary[index:index + 4]) index += 4 [f3] = struct.unpack('> h', binary[index:index + 2]) index += 2 [f4] = struct.unpack('> Q', binary[index:index + 8]) index += 8 [f5] = struct.unpack('> Q', binary[index:index + 8]) index += 8 f6 = list(struct.unpack('> 3H', binary[index:index + 6])) index += 6 [f7] = struct.unpack('> d', binary[index:index + 8]) index += 8 [f8] = struct.unpack('> q', binary[index:index + 8]) index += 8 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7, 'F8': f8} return struct_a(5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (length, iterator) = getNext(data, iterator, 2, 'fHLfh', file[a_adr:a_adr + 16]) (a['A1'], a['A2'], b_adr, a['A4'], a['A5']) = temp temp = unpack('>QqHLQ', file[b_adr:b_adr + 30]) (b['B1'], b['B2'], c_adr, e_adr, b['B5']) = temp temp = unpack('>BHhdBdhdBdhdBdLL2hh', file[c_adr:c_adr + 74]) (c['C1'], c['C2'], *d_strs) = temp[0:14] (floar_arr_size, float_arr_adr, *int16_arr, c['C6']) = temp[14:] c['C5'] = list(int16_arr) temp = unpack(f'>{floar_arr_size}f', file[float_arr_adr:float_arr_adr + floar_arr_size * 4]) c['C4'] = list(temp) temp = unpack('>8Bd', file[e_adr:e_adr + 16]) (*e['E1'], e['E2']) = temp c['C3'] = [] (d['D1'], d['D2'], d['D3'], d['D4']) = d_strs[0:4] c['C3'].append(d.copy()) (d['D1'], d['D2'], d['D3'], d['D4']) = d_strs[4:8] c['C3'].append(d.copy()) (d['D1'], d['D2'], d['D3'], d['D4']) = d_strs[8:12] c['C3'].append(d.copy()) a['A3'] = b b['B3'] = c b['B4'] = e return a" "import struct def structE(data, pointer): (array_e_1,) = struct.unpack('>I', data[pointer:pointer + 4]) (array_e_2,) = struct.unpack('>I', data[pointer + 4:pointer + 8]) array_e = [] array_e.append(array_e_1) array_e.append(array_e_2) (int8_e,) = struct.unpack('>b', data[pointer + 8:pointer + 9]) (uint16_e,) = struct.unpack('>H', data[pointer + 9:pointer + 11]) (int8_e_2,) = struct.unpack('>b', data[pointer + 11:pointer + 12]) (uint16_e_2,) = struct.unpack('>H', data[pointer + 12:pointer + 14]) return {'E1': array_e, 'E2': int8_e, 'E3': uint16_e, 'E4': int8_e_2, 'E5': uint16_e_2} def structD(data, pointer): (uint8_d,) = struct.unpack('>B', data[pointer:pointer + 1]) (uint32_d,) = struct.unpack('>I', data[pointer + 1:pointer + 5]) (int32_d,) = struct.unpack('>i', data[pointer + 5:pointer + 9]) (int32_d_2,) = struct.unpack('>i', data[pointer + 9:pointer + 13]) (uint64_d,) = struct.unpack('>Q', data[pointer + 13:pointer + 21]) return {'D1': uint8_d, 'D2': uint32_d, 'D3': int32_d, 'D4': int32_d_2, 'D5': uint64_d} def structC(data, pointer): (float_c,) = struct.unpack('>f', data[pointer:pointer + 4]) (uint64_c,) = struct.unpack('>Q', data[pointer + 4:pointer + 12]) (f_uint16,) = struct.unpack('>H', data[pointer + 12:pointer + 14]) uint16 = structD(data, f_uint16) return {'C1': float_c, 'C2': uint64_c, 'C3': uint16} def structB(data, pointer): (array_b,) = struct.unpack('>c', data[pointer:pointer + 1]) (array_b_2,) = struct.unpack('>c', data[pointer + 1:pointer + 2]) (array_b_3,) = struct.unpack('>c', data[pointer + 2:pointer + 3]) (array_b_4,) = struct.unpack('>c', data[pointer + 3:pointer + 4]) (array_b_5,) = struct.unpack('>c', data[pointer + 4:pointer + 5]) (array_b_6,) = struct.unpack('>c', data[pointer + 5:pointer + 6]) (array_b_7,) = struct.unpack('>c', data[pointer + 6:pointer + 7]) array_char = '' array_char += chr(array_b[0]) + chr(array_b_2[0]) array_char += chr(array_b_3[0]) + chr(array_b_4[0]) array_char += chr(array_b_5[0]) + chr(array_b_6[0]) array_char += chr(array_b_7[0]) (int16_b,) = struct.unpack('>h', data[pointer + 7:pointer + 9]) (f_uint16,) = struct.unpack('>H', data[pointer + 9:pointer + 11]) uint16 = structC(data, f_uint16) (uint8_b,) = struct.unpack('>B', data[pointer + 11:pointer + 12]) f1 = struct.unpack('>HI', data[pointer + 12:pointer + 18]) e1 = [] count = f1[0] for i in range(count): f3 = structE(data, f1[1] + i * 14) e1.append(f3) f2 = struct.unpack('>HH', data[pointer + 18:pointer + 22]) b2 = list(struct.unpack(f'>{f2[0]}f', data[f2[1]:f2[1] + f2[0] * 4])) return {'B1': array_char, 'B2': int16_b, 'B3': uint16, 'B4': uint8_b, 'B5': e1, 'B6': b2} def structA(data, pointer): (int8_a,) = struct.unpack('>b', data[pointer:pointer + 1]) (int8_a_2,) = struct.unpack('>b', data[pointer + 1:pointer + 2]) strB = structB(data, pointer + 2) return {'A1': int8_a, 'A2': int8_a_2, 'A3': strB} def main(data): return structA(data, 4)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [a2] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 a3 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1 * 1])) a3 = [i.decode('UTF-8') for i in a3] [a4] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 a5 = struct_b(offset) offset += 4 + 4 + 1 + 8 + 8 + 3 * 2 + 2 + 2 + 4 + 2 [a6] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [a7] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [a8] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 return {'A1': a1, 'A2': a2, 'A3': ''.join(a3), 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def struct_b(offset: int) -> dict: [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 le = 1 + 1 + 8 + 2 + 1 + 4 b1 = [struct_c(link_str + i * le) for i in range(length1)] b2 = struct_d(offset) offset += 4 + 4 + 1 + 8 + 8 + 3 * 2 + 2 + 2 return {'B1': b1, 'B2': b2} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [c3] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [c4] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [c5] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [c6] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [d3] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [d4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [d5] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 d6 = list(struct.unpack('< 3H', binary[offset:offset + 3 * 2])) offset += 3 * 2 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 d7 = list(struct.unpack('< ' + str(length1) + 'I', binary[link_str:link_str + length1 * 4])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} return struct_a(4)" "import struct def main(x): A1 = struct.unpack(' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 le = 4 + 8 + 5 + 2 + 8 + 1 + 4 + 2 + 4 + 8 a2 = [struct_b(link_str + i * le) for i in range(length1)] [a3] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 return {'A1': a1, 'A2': a2, 'A3': struct_e(a3)} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [b2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 b3 = list(struct.unpack('> 5c', binary[offset:offset + 5 * 1])) offset += 5 * 1 b3 = [i.decode('UTF-8') for i in b3] [b4] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 b5 = struct_d(offset) offset += 8 + 1 + 4 + 2 + 4 [b6] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 return {'B1': b1, 'B2': b2, 'B3': ''.join(b3), 'B4': struct_c(b4), 'B5': b5, 'B6': b6} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [c2] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'C1': c1, 'C2': c2} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [d2] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [d3] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 [d4] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [d5] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def struct_e(offset: int) -> dict: [e1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [e2] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [e3] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [e4] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [e5] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 e6 = list(struct.unpack('> 2H', binary[offset:offset + 2 * 2])) offset += 2 * 2 [length1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 e7 = list(struct.unpack('> ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) [e8] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7, 'E8': e8} return struct_a(5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, type): return (unpack_from(FMT[type], buf, offs)[0], offs + calcsize(FMT[type])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse(buf, offs, 'uint8') return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse_c(buf, offs) (b3, offs) = parse(buf, offs, 'uint32') (b4, offs) = parse(buf, offs, 'uint16') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): c1 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) c1.append(val) c2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int16') c2.append(val) (c3, offs) = parse(buf, offs, 'float') c4 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'float') c4.append(val) (c5, offs) = parse(buf, offs, 'uint16') (c6, offs) = parse(buf, offs, 'int64') (c7, offs) = parse(buf, offs, 'double') c8 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint16') c8.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct from enum import Enum class Types(Enum): uint8 = ' dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [a2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 a3 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1 * 1])) a3 = [i.decode('UTF-8') for i in a3] [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a4 = list(struct.unpack('< ' + str(length1) + 'H', binary[link_str:link_str + length1 * 2])) a5 = struct_d(offset) offset += 14 return {'A1': a1, 'A2': a2, 'A3': ''.join(a3), 'A4': [struct_b(i) for i in a4], 'A5': a5} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 [b2] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 b3 = struct_c(offset) offset += 29 return {'B1': b1, 'B2': b2, 'B3': b3} def struct_c(offset: int) -> dict: [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 c1 = list(struct.unpack('< ' + str(length1) + 'i', binary[link_str:link_str + length1 * 4])) [c2] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [c3] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [c4] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [c5] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 c6 = list(struct.unpack('< 7H', binary[offset:offset + 7 * 2])) offset += 7 * 2 [c7] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [d2] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [d3] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3} return struct_a(5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} A['A1'] = [] for i in range(3): (a, iterator) = getB(data, iterator) A['A1'].append(a) (A['A2'], iterator) = getNext(data, iterator, 8, 'B', data[pointer:pointer + 1]) (float_d,) = struct.unpack('>f', data[pointer + 1:pointer + 5]) return {'D1': uint8_d, 'D2': float_d} def structC(data, pointer): array_float = [] f1 = struct.unpack('>HI', data[pointer:pointer + 6]) c1 = list(struct.unpack(f'>{f1[0]}f', data[f1[1]:f1[1] + f1[0] * 4])) for i in range(len(c1)): array_float.append(c1[i]) (float_c,) = struct.unpack('>f', data[pointer + 6:pointer + 10]) (float_c_2,) = struct.unpack('>f', data[pointer + 10:pointer + 14]) strD = structD(data, pointer + 14) return {'C1': array_float, 'C2': float_c, 'C3': float_c_2, 'C4': strD} def structB(data, pointer): (f_uint32,) = struct.unpack('>I', data[pointer:pointer + 4]) uint32_c = structC(data, f_uint32) (float_b,) = struct.unpack('>f', data[pointer + 4:pointer + 8]) (uint32_b,) = struct.unpack('>I', data[pointer + 8:pointer + 12]) (int8_b,) = struct.unpack('>b', data[pointer + 12:pointer + 13]) (int8_b_2,) = struct.unpack('>b', data[pointer + 13:pointer + 14]) return {'B1': uint32_c, 'B2': float_b, 'B3': uint32_b, 'B4': int8_b, 'B5': int8_b_2} def structA(data, pointer): (uint8_a,) = struct.unpack('>B', data[pointer:pointer + 1]) (uint32_a,) = struct.unpack('>I', data[pointer + 1:pointer + 5]) (int16_a,) = struct.unpack('>h', data[pointer + 5:pointer + 7]) structBArray = [] structBArray.append(structB(data, pointer + 7)) structBArray.append(structB(data, pointer + 21)) structBArray.append(structB(data, pointer + 35)) a_array = list(struct.unpack('>5B', data[pointer + 49:pointer + 54])) (int16_a_2,) = struct.unpack('>h', data[pointer + 54:pointer + 56]) (int8_a,) = struct.unpack('>b', data[pointer + 56:pointer + 57]) arr_a = list(struct.unpack('>3h', data[pointer + 57:pointer + 63])) return {'A1': uint8_a, 'A2': uint32_a, 'A3': int16_a, 'A4': structBArray, 'A5': a_array, 'A6': int16_a_2, 'A7': int8_a, 'A8': arr_a} def main(data): return structA(data, 5)" "import struct def uint16uint32int32(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'i' * size, s[add:add + 4 * size]) return list(a) def struct_c(s, pointer): return {'C1': struct.unpack('>b', s[pointer:pointer + 1])[0], 'C2': struct.unpack('>H', s[pointer + 1:pointer + 3])[0], 'C3': struct.unpack('>f', s[pointer + 3:pointer + 7])[0], 'C4': struct.unpack('>b', s[pointer + 7:pointer + 8])[0]} def create_b_structure(s, pointer): result = [] for i in range(0, 2): b1 = str(struct.unpack('>2s', s[pointer:pointer + 2])[0])[2:4] b2 = struct_c(s, pointer + 2) b3 = struct.unpack('>I', s[pointer + 10:pointer + 14])[0] b4 = struct.unpack('>d', s[pointer + 14:pointer + 22])[0] b5 = list(struct.unpack('>5h', s[pointer + 22:pointer + 32])) b6 = struct.unpack('>i', s[pointer + 32:pointer + 36])[0] result.append({'B1': b1, 'B2': b2, 'B3': {'D1': struct.unpack('>B', s[b3:b3 + 1])[0], 'D2': struct.unpack('>f', s[b3 + 1:b3 + 5])[0], 'D3': uint16uint32int32(s, b3 + 5), 'D4': struct.unpack('>h', s[b3 + 11:b3 + 13])[0], 'D5': struct.unpack('>h', s[b3 + 13:b3 + 15])[0], 'D6': struct.unpack('>Q', s[b3 + 15:b3 + 23])[0], 'D7': struct.unpack('>i', s[b3 + 23:b3 + 27])[0]}, 'B4': b4, 'B5': b5, 'B6': b6}) pointer += 36 return result def main(s): out_dict = {'A1': struct.unpack('>i', s[4:8])[0], 'A2': struct.unpack('>B', s[8:9])[0], 'A3': create_b_structure(s, 9), 'A4': struct.unpack('>f', s[81:85])[0], 'A5': struct.unpack('>I', s[85:89])[0]} return out_dict" "from struct import * FMT = dict(int8='b', uint8='B', int16='h', int32='i', int64='q', uint16='H', uint32='I', uint64='L', float='f', double='d', char='c') def parse(buf, offs, ty): calc = calcsize(FMT[ty]) return (unpack_from(FMT[ty], buf, offs)[0], offs + calc) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'int32') (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, a3_offs) = parse_b(buf, a3_offs) (a4, offs) = parse_d(buf, offs) (a5, offs) = parse(buf, offs, 'int8') (a6, offs) = parse(buf, offs, 'float') return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): b1 = [] for _ in range(7): (b1_offs, offs) = parse(buf, offs, 'uint16') (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'float') b2.append(val) (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'float') (b5, offs) = parse(buf, offs, 'double') (b6, offs) = parse(buf, offs, 'int32') (b7, offs) = parse(buf, offs, 'float') (b8, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'uint8') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') d1.append(val) (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack class Counter: def __init__(self, a=0): if type(a) != int: raise TypeError(type(a)) self.a = a def __add__(self, other): self.a += other return self.a def u16u16char(s, start): size = unpack('>H', s[start.a:start + 2])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'c' * size, s[add:add + size * 1]) s = '' for i in arr: s += i.decode() return s def u32u16i16(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = unpack('>' + 'h' * size, s[add:add + size * 2]) return list(arr) def u32u16C(s, start): size = unpack('>I', s[start.a:start + 4])[0] add = unpack('>H', s[start.a:start + 2])[0] arr = [] start = Counter(add) for i in range(size): arr.append(C(s, start)) return arr def D(s, start): start = Counter(start) return {'D1': list(unpack('>' + 'd' * 7, s[start.a:start + 8 * 7])), 'D2': unpack('>i', s[start.a:start + 4])[0], 'D3': unpack('>b', s[start.a:start + 1])[0], 'D4': u32u16i16(s, start), 'D5': unpack('>q', s[start.a:start + 8])[0], 'D6': unpack('>H', s[start.a:start + 2])[0]} def C(s, start): return {'C1': list(unpack('>' + 'h' * 4, s[start.a:start + 2 * 4])), 'C2': unpack('>d', s[start.a:start + 8])[0]} def B(s, start): start = Counter(start) return {'B1': unpack('>d', s[start.a:start + 8])[0], 'B2': unpack('>f', s[start.a:start + 4])[0], 'B3': u16u16char(s, start), 'B4': unpack('>i', s[start.a:start + 4])[0]} def A(s, start): return {'A1': B(s, unpack('>H', s[start.a:start + 2])[0]), 'A2': unpack('>H', s[start.a:start + 2])[0], 'A3': unpack('>b', s[start.a:start + 1])[0], 'A4': u32u16C(s, start), 'A5': unpack('>I', s[start.a:start + 4])[0], 'A6': D(s, unpack('>H', s[start.a:start + 2])[0])} def main(s): start = Counter(3) return A(s, start)" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['D2'] = struct.unpack('>i', data[offset + 2:offset + 2 + 4])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>B', data[offset + 2:offset + 2 + 1])[0] result['C3'] = struct.unpack('>b', data[offset + 3:offset + 3 + 1])[0] return result def parse_b(data, offset): result = dict() c_address = struct.unpack('>H', data[offset:offset + 2])[0] result['B1'] = parse_c(data, c_address) result['B2'] = ''.join([str(c, 'utf-8') for c in parse_array(data, offset + 2, 'c', 8)]) result['B3'] = struct.unpack('>f', data[offset + 10:offset + 10 + 4])[0] d_addresses = parse_array(data, offset + 14, 'H', 8) result['B4'] = [parse_d(data, addr) for addr in d_addresses] result['B5'] = struct.unpack('>d', data[offset + 30:offset + 30 + 8])[0] (b6_size, b6_addr) = struct.unpack('>HH', data[offset + 38:offset + 38 + 4]) result['B6'] = parse_array(data, b6_addr, 'H', b6_size) return result def parse_a(data, offset): result = dict() result['A1'] = parse_b(data, offset) (a2_size, a2_addr) = struct.unpack('>IH', data[offset + 42:offset + 42 + 6]) result['A2'] = parse_array(data, a2_addr, 'f', a2_size) result['A3'] = struct.unpack('>f', data[offset + 48:offset + 48 + 4])[0] return result def main(data): return parse_a(data, 4)" "from struct import unpack def main(f): signature = bytes([81, 88, 74]) a_adr = f.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(8)} temp = unpack('>Q', f[a_adr:a_adr + 8]) b = {'B1': temp[0], 'B2': []} for i in range(2): c = {f'C{i + 1}': None for i in range(3)} temp = unpack('>iI5i', f[a_adr + 8 + i * 28:a_adr + 8 + (i + 1) * 28]) (c['C1'], d_adr, *c['C3']) = temp d = {f'D{i + 1}': None for i in range(5)} temp = unpack('>HHb2BHi', f[d_adr:d_adr + 13]) (arr_size, arr_adr, d['D2'], num1, num2, d['D4'], d['D5']) = temp d['D3'] = [num1, num2] temp = unpack(f'>{arr_size}b', f[arr_adr:arr_adr + arr_size]) d['D1'] = list(temp) c['C2'] = d b['B2'].append(c) a['A1'] = b temp = unpack('>dfq3Ih', f[a_adr + 64:a_adr + 64 + 34]) (a['A2'], a['A3'], a['A4'], a['A5'], a['A6'], e_adr, a['A8']) = temp e = {f'E{i + 1}': None for i in range(4)} temp = unpack('>f7bQb', f[e_adr:e_adr + 20]) (e['E1'], *e['E2'], e['E3'], e['E4']) = temp a['A7'] = e return a" "import struct def main(bs): magic_bytes = b'uQBMW' A = struct.Struct('> HH IH H B II HH h') B = struct.Struct('> H I b B') D = struct.Struct('> 5b H h i d') a = A.unpack_from(bs, len(magic_bytes)) a_array = list(struct.unpack_from(f'> {a[0]}H', bs, a[1])) b_structs_array = [] for offset in a_array: b_structs_array.append(B.unpack_from(bs, offset)) c_array = b''.join(struct.unpack_from(f'> {a[2]}c', bs, a[3])).decode() d = D.unpack_from(bs, a[4]) e_array1 = list(struct.unpack_from(f'> {a[6]}B', bs, a[7])) e_array2 = list(struct.unpack_from(f'> {a[8]}i', bs, a[9])) resolved = {'A1': [{'B1': e[0], 'B2': e[1], 'B3': e[2], 'B4': e[3]} for e in b_structs_array], 'A2': {'C1': c_array, 'C2': {'D1': list(d[:5]), 'D2': d[5], 'D3': d[6], 'D4': d[7], 'D5': d[8]}}, 'A3': a[5], 'A4': {'E1': e_array1, 'E2': e_array2, 'E3': a[-1]}} return resolved" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '>' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a2.append(val) (a3, offs) = parse(buf, offs, 'int16') (a4, offs) = parse(buf, offs, 'int16') (a5_size, offs) = parse(buf, offs, 'uint16') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'uint16') a5.append(val) (a6, offs) = parse(buf, offs, 'int64') (a7, offs) = parse(buf, offs, 'uint64') (a8, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint16') (b1, b1_offs) = parse_c(buf, b1_offs) b2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint8') b2.append(val) (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2, offs) = parse_d(buf, offs) (c3, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): d1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'double') d1.append(val) d2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int8') d2.append(val) (d3, offs) = parse(buf, offs, 'double') (d4, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from enum import Enum from struct import unpack_from, calcsize class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, pattern): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) return result[0] def readS(self, pattern, size): res = [] for i in range(0, size): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(r): b1 = r.read('Q') b2 = r.read('Q') b3 = r.readS('c', 4) b3 = b''.join(b3).decode('ASCII') b4 = r.read('I') b5 = [] for i in range(0, 3): b5.append(readC(r)) b6 = readD(r.copy(r.read('H'))) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6) def readC(r): c1 = r.read('B') c2 = r.read('f') c3 = r.read('h') return dict(C1=c1, C2=c2, C3=c3) def readD(r): d1 = r.read('d') d2 = r.readS('q', 4) d3 = r.read('H') return dict(D1=d1, D2=d2, D3=d3) def readE(r): e1 = r.read('i') e2 = r.read('b') e3 = r.read('q') e4 = r.read('b') e5 = r.read('i') return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5) def main(s): r = BinaryReader(4, s) a1 = r.read('h') a2 = readB(r.copy(r.read('I'))) a3 = r.read('i') a4 = r.read('q') a5size = r.read('I') a5address = r.read('I') a5 = r.copy(a5address).readS('q', a5size) a6 = readE(r) a7 = r.read('f') return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct def int8p1(x, pos): return struct.unpack('> b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('> B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('> h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('> I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('> i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('> q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('> Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('> f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('> d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def E(x, pos): return {'E1': uint32uint16int32(x, pos), 'E2': int64p8(x, pos + 6), 'E3': int8p1(x, pos + 14)} def arrayE(x, pos): size = uint16p2(x, pos) address = uint16p2(x, pos + 2) a = [] for i in range(size): a.append(E(x, address + i * 15)) return list(a) def D(x, pos): return {'D1': uint8p1(x, pos), 'D2': float4p4(x, pos + 1), 'D3': arrayE(x, pos + 5), 'D4': int8p1(x, pos + 9), 'D5': int16p2(x, pos + 10), 'D6': uint32uint16uint64(x, pos + 12)} def C(x, pos): return {'C1': int64p8(x, pos), 'C2': int16p2(x, pos + 8), 'C3': float4p4(x, pos + 10)} def B(x, start): return {'B1': struct.unpack('> f', x[start:start + 4])[0], 'B2': struct.unpack('> H', x[start + 4:start + 6])[0], 'B3': C(x, uint32p4(x, start + 6)), 'B4': D(x, uint16p2(x, start + 10)), 'B5': struct.unpack('> b', x[start + 12:start + 13])[0]} def uint16uint16int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + 1 * size]) return list(a) def A(x, start): return {'A1': struct.unpack('> Q', x[start:start + 8])[0], 'A2': B(x, uint32p4(x, start + 8)), 'A3': struct.unpack('> I', x[start + 12:start + 16])[0], 'A4': struct.unpack('> b', x[start + 16:start + 17])[0], 'A5': struct.unpack('> h', x[start + 17:start + 19])[0], 'A6': struct.unpack('> H', x[start + 19:start + 21])[0], 'A7': uint16uint16int8(x, start + 21), 'A8': struct.unpack('> H', x[start + 25:start + 27])[0]} def main(x): return A(x, 4)" "import struct def main(bs): magic_bytes = b'CJXL' A = struct.Struct('< Q I Q IH I h B Q') C = struct.Struct('< IH b f') D = struct.Struct('< B I 8h 4b I 6h') a = A.unpack_from(bs, len(magic_bytes)) c = C.unpack_from(bs, a[1]) c_array = b''.join(list(struct.unpack_from(f'< {c[0]}c', bs, c[1]))).decode() d_array_structs = [D.unpack_from(bs, a[4] + D.size * i) for i in range(a[3])] resolved = {'A1': a[0], 'A2': {'B1': {'C1': c_array, 'C2': c[2], 'C3': c[3]}, 'B2': a[2], 'B3': [{'D1': i[0], 'D2': i[1], 'D3': list(i[2:10]), 'D4': list(i[10:14]), 'D5': i[14], 'D6': list(i[15:])} for i in d_array_structs], 'B4': a[-4], 'B5': a[-3], 'B6': a[-2]}, 'A3': a[-1]} return resolved" "def main(inp): import struct buf = inp[:102] F = struct.Struct('<4c IHI Ihi Hi8HiiI6Ii qq') S = F.unpack(buf) BEG = S[:4] A = S[4:] A1 = A[:2] A2 = A[2] A3 = C = A[3:] C1 = C[0] C2 = C[1] C3 = C[2] C4 = D = C[3:-2] C5 = C[-2] C6 = C[-1] D1 = D[0] D2 = D[1] D3 = D[2:10] D4 = D[10] D5 = D[11] D6 = D[12] D7 = D[13:19] D8 = D[19] colA1 = [] pos = A1[1] T1 = inp[pos:pos + A1[0] * 2] T2 = struct.unpack('%dH' % A1[0], T1) for i in range(A1[0]): B = inp[T2[i]:T2[i] + 8] (B1, B2, B3, B4, B5, B6, B7) = struct.unpack('H6c', B) B = {'B1': B1, 'B2': (B2 + B3 + B4 + B5 + B6 + B7).decode('ascii')} colA1.append(B) D3 = list(D3) D7 = list(D7) R = {'A1': colA1, 'A2': A2, 'A3': {'C1': C1, 'C2': C2, 'C3': C3, 'C4': {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5, 'D6': D6, 'D7': D7, 'D8': D8}, 'C5': C5, 'C6': C6}} return R" "import struct def int8p1(x, pos): return struct.unpack('> b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('> B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('> h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('> I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('> i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('> q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('> Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('> f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('> d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint16uint16int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + 1 * size]) return list(a) def uint16uint16int64(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'q' * size, x[add:add + 8 * size]) return list(a) def E(x, pos): return {'E1': [uint16p2(x, pos), uint16p2(x, pos + 2)], 'E2': double8p8(x, pos + 4), 'E3': int32p4(x, pos + 12), 'E4': uint16uint16int64(x, pos + 16), 'E5': double8p8(x, pos + 20)} def D(x, pos): return {'D1': uint8p1(x, pos), 'D2': int32p4(x, pos + 1), 'D3': float4p4(x, pos + 5), 'D4': int64p8(x, pos + 9), 'D5': uint8p1(x, pos + 17)} def C(x, pos): return {'C1': int8p1(x, pos), 'C2': uint16uint16int8(x, pos + 1), 'C3': int32p4(x, pos + 5)} def B(x, pos): return {'B1': int8p1(x, pos), 'B2': uint32p4(x, pos + 1)} def arrayb(x, pos): a = struct.unpack('> ' + 'H' * 8, x[pos:pos + 2 * 8]) a = list(a) b = [] for el in a: b.append(B(x, el)) return b def A(x, pos): return {'A1': float4p4(x, pos), 'A2': int32p4(x, pos + 4), 'A3': double8p8(x, pos + 8), 'A4': arrayb(x, pos + 16), 'A5': C(x, pos + 32), 'A6': D(x, uint32p4(x, pos + 41)), 'A7': E(x, pos + 45), 'A8': float4p4(x, pos + 45 + 28)} def main(x): return A(x, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize('>' + FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'int16') a3 = [] for _ in range(4): (a3_offs, offs) = parse(buf, offs, 'uint16') a3.append(parse_b(buf, a3_offs)[0]) (a4, offs) = parse(buf, offs, 'uint8') (a5, offs) = parse(buf, offs, 'uint8') (a6, offs) = parse_c(buf, offs) (a7_offs, offs) = parse(buf, offs, 'uint16') a7 = parse_d(buf, a7_offs)[0] (a8, offs) = parse(buf, offs, 'uint32') return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): b1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'float') b1.append(val) (b2, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint32') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize('>' + FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int16') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = parse_b(buf, a2_offs)[0] a3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint32') a3.append(val) (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs_offs, offs) = parse(buf, offs, 'uint32') b1 = [] for _ in range(b1_size): (b1_offs, b1_offs_offs) = parse(buf, b1_offs_offs, 'uint16') b1.append(parse_c(buf, b1_offs)[0]) (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') c2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint8') c2.append(val) (c3, offs) = parse_d(buf, offs) (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse(buf, offs, 'float') d6 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'uint8') d6.append(val) (d7, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('<' + FMT[ty], buf, offs)[0], offs + calcsize('<' + FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(2): (a1_offs, offs) = parse(buf, offs, 'uint32') a1.append(parse_b(buf, a1_offs)[0]) (a2, offs) = parse(buf, offs, 'uint64') (a3, offs) = parse_c(buf, offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'uint8') b3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'char') b3.append(val.decode()) return (dict(B1=b1, B2=b2, B3=''.join(b3)), offs) def parse_c(buf, offs): (c1_offs, offs) = parse(buf, offs, 'uint16') c1 = parse_d(buf, c1_offs)[0] (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'int32') d4 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'float') d4.append(val) (d5, offs) = parse(buf, offs, 'uint8') (d6_size, offs) = parse(buf, offs, 'uint32') (d6_offs, offs) = parse(buf, offs, 'uint16') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'int64') d6.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct from enum import Enum class Types(Enum): uint8 = '>B' uint16 = '>H' uint32 = '>I' uint64 = '>Q' int8 = '>b' int16 = '>h' int32 = '>i' int64 = '>q' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source, offset): self.source = source self.offset = offset def read(self, pattern): value = struct.unpack_from(pattern.value, self.source, self.offset) self.offset += struct.calcsize(pattern.value) return value[0] def read_a(reader: BinaryReader): a1_size = reader.read(Types.uint32) a1_offset = reader.read(Types.uint32) a1 = [] a1_reader = BinaryReader(reader.source, a1_offset) for _ in range(a1_size): a1.append(read_b(a1_reader)) a2 = reader.read(Types.int8) a3_offset = reader.read(Types.uint32) a3 = read_d(BinaryReader(reader.source, a3_offset)) a4 = reader.read(Types.uint64) a5 = reader.read(Types.float) a6 = reader.read(Types.int16) a7 = [] a7_size = reader.read(Types.uint32) a7_offset = reader.read(Types.uint16) a7_reader = BinaryReader(reader.source, a7_offset) for _ in range(a7_size): a7.append(a7_reader.read(Types.int16)) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def read_b(reader: BinaryReader): b1 = read_c(reader) b2 = reader.read(Types.uint32) return dict(B1=b1, B2=b2) def read_c(reader: BinaryReader): c1 = [] for _ in range(3): c1.append(reader.read(Types.int8)) c2 = reader.read(Types.uint64) return dict(C1=c1, C2=c2) def read_d(reader: BinaryReader): d1 = [] for _ in range(3): d1.append(reader.read(Types.int32)) d2 = reader.read(Types.float) return dict(D1=d1, D2=d2) def main(data): reader = BinaryReader(data, offset=4) return read_a(reader)" "import struct def D(data: bytes, addr: int): (one,) = struct.unpack('{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_c(data, offset)) offset = offset + 16 return result def parse_e(data, offset): result = dict() result['E1'] = un('>I', data[offset:offset + 4])[0] result['E2'] = un('>I', data[offset + 4:offset + 8])[0] result['E3'] = un('>H', data[offset + 8:offset + 10])[0] result['E4'] = parse_array(data, offset + 10, 'h', 4) result['E5'] = un('>h', data[offset + 18:offset + 20])[0] return result def parse_d(data, offset): result = dict() result['D1'] = un('>H', data[offset:offset + 2])[0] result['D2'] = un('>b', data[offset + 2:offset + 3])[0] result['D3'] = un('>b', data[offset + 3:offset + 4])[0] result['D4'] = un('>H', data[offset + 4:offset + 6])[0] return result def parse_c(data, offset): result = dict() result['C1'] = parse_d(data, offset) result['C2'] = un('>I', data[offset + 6:offset + 10])[0] (c3_size, c3_addr) = un('>IH', data[offset + 10:offset + 16]) result['C3'] = parse_array(data, c3_addr, 'B', c3_size) return result def parse_b(data, offset): result = dict() result['B1'] = parse_structure_array(data, offset, 6) result['B2'] = un('>H', data[offset + 96:offset + 98])[0] result['B3'] = un('>i', data[offset + 98:offset + 102])[0] result['B4'] = un('>i', data[offset + 102:offset + 106])[0] result['B5'] = parse_e(data, offset + 106) return result def parse_a(data, offset): result = dict() result['A1'] = parse_b(data, offset) (a2_size, a2_addr) = un('>IH', data[offset + 126:offset + 132]) result['A2'] = parse_array(data, a2_addr, 'h', a2_size) return result def main(data): return parse_a(data, 3)" "import struct def structE(data, pointer): (e1,) = struct.unpack('>I', data[pointer:pointer + 4]) (e2,) = struct.unpack('>Q', data[pointer + 4:pointer + 12]) return {'E1': e1, 'E2': e2} def structD(data, pointer): (d1,) = struct.unpack('>b', data[pointer:pointer + 1]) (d2,) = struct.unpack('>f', data[pointer + 1:pointer + 5]) return {'D1': d1, 'D2': d2} def structC(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) c1 = list(struct.unpack(f'>{f1[0]}b', data[f1[1]:f1[1] + f1[0] * 1])) f2 = struct.unpack('>IH', data[pointer + 4:pointer + 10]) c2 = list(struct.unpack(f'>{f2[0]}f', data[f2[1]:f2[1] + f2[0] * 4])) return {'C1': c1, 'C2': c2} def structB(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) b1 = [] for i in range(f1[0]): x = structC(data, f1[1] + i * 10) b1.append(x) b2 = structD(data, pointer + 6) (b3,) = struct.unpack('>i', data[pointer + 11:pointer + 15]) (b4,) = struct.unpack('>f', data[pointer + 15:pointer + 19]) (b5,) = struct.unpack('>B', data[pointer + 19:pointer + 20]) (b6,) = struct.unpack('>I', data[pointer + 20:pointer + 24]) f7 = struct.unpack('>H', data[pointer + 24:pointer + 26]) b7 = structE(data, f7[0]) (b8,) = struct.unpack('>I', data[pointer + 26:pointer + 30]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def structA(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) a1 = struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0] * 1]) char1 = '' for i in range(len(a1)): char1 += chr(a1[i][0]) f2 = struct.unpack('>I', data[pointer + 6:pointer + 10]) a2 = structB(data, f2[0]) (a3,) = struct.unpack('>h', data[pointer + 10:pointer + 12]) (a4,) = struct.unpack('>B', data[pointer + 12:pointer + 13]) return {'A1': char1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return structA(data, 5)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 a2 = struct_b(offset) offset += 8 + 4 + 2 + 2 + 4 return {'A1': a1, 'A2': a2} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 le = 21 b2 = [struct_c(link_str + i * le) for i in range(length1)] [b3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 [b4] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': struct_e(b4)} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 c2 = struct_d(offset) offset += 4 + 8 + 1 + 4 [c3] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 [d2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [d3] = struct.unpack('> b', binary[offset:offset + 1]) offset += 1 [d4] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def struct_e(offset: int) -> dict: [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 e1 = list(struct.unpack('> ' + str(length1) + 'f', binary[link_str:link_str + length1 * 4])) e2 = struct_f(offset) offset += 8 + 8 + 32 + 5 + 4 + 7 return {'E1': e1, 'E2': e2} def struct_f(offset: int) -> dict: [f1] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [f2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 f3 = list(struct.unpack('> 4d', binary[offset:offset + 8 * 4])) offset += 32 f4 = list(struct.unpack('> 5B', binary[offset:offset + 1 * 5])) offset += 5 [f5] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 f6 = list(struct.unpack('> 7b', binary[offset:offset + 1 * 7])) offset += 7 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6} return struct_a(4)" "import struct import pprint def parse_d(data, pointer): f1 = struct.unpack('{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_d(data, offset): res = dict() res['D1'] = un('>I', data[offset:offset + 4])[0] res['D2'] = un('>b', data[offset + 4:offset + 5])[0] return res def parse_c(data, offset): res = dict() res['C1'] = un('>B', data[offset:offset + 1])[0] res['C2'] = un('>i', data[offset + 1:offset + 5])[0] res['C3'] = un('>H', data[offset + 5:offset + 7])[0] return res def parse_b(data, offset): res = dict() b1_size = un('>H', data[offset:offset + 2])[0] b1_offs = un('>I', data[offset + 2:offset + 6])[0] b1 = parse_array(data, b1_offs, 'c', b1_size) res['B1'] = ''.join([str(item.decode()) for item in b1]) (b2_size, b2_addr) = un('>II', data[offset + 6:offset + 14]) b2_c_addr = parse_array(data, b2_addr, 'I', b2_size) b2 = [] for addr in b2_c_addr: b2.append(parse_c(data, addr)) res['B2'] = b2 res['B3'] = un('>B', data[offset + 14:offset + 15])[0] res['B4'] = parse_array(data, offset + 15, 'H', 5) res['B5'] = un('>I', data[offset + 25:offset + 29])[0] res['B6'] = parse_array(data, offset + 29, 'I', 6) res['B7'] = un('>q', data[offset + 53:offset + 61])[0] return res def parse_a(data, offset): res = dict() res['A1'] = parse_b(data, un('>H', data[offset:offset + 2])[0]) res['A2'] = un('>B', data[offset + 2:offset + 3])[0] res['A3'] = un('>i', data[offset + 3:offset + 7])[0] res['A4'] = un('>f', data[offset + 7:offset + 11])[0] res['A5'] = un('>h', data[offset + 11:offset + 13])[0] res['A6'] = un('>H', data[offset + 13:offset + 15])[0] res['A7'] = un('>H', data[offset + 15:offset + 17])[0] res['A8'] = parse_d(data, offset + 17) return res def main(data): return parse_a(data, 5)" "from struct import unpack, calcsize def main(raw_data): adress_a = 0 for byte in raw_data: adress_a += 1 if byte == 24: break a = {f'A{i}': None for i in range(1, 4)} data_a = unpack('>Hlll', raw_data[adress_a:adress_a + calcsize('>Hlll')]) (adress_b, a['A2']) = (data_a[0], list(data_a[1:])) adress_d = adress_a + calcsize('>Hlll') d = {f'D{i}': None for i in range(1, 4)} (d['D1'],) = unpack('>b', raw_data[adress_d:adress_d + calcsize('>b')]) adress_e = adress_d + calcsize('>b') e = {f'E{i}': None for i in range(1, 3)} data_e = unpack('>5h', raw_data[adress_e:adress_e + calcsize('>5h')]) (e['E1'], e['E2']) = (list(data_e[0:2]), list(data_e[2:])) d['D2'] = e adress_d = adress_e + calcsize('>5h') (d['D3'],) = unpack('>H', raw_data[adress_d:adress_d + calcsize('>H')]) a['A3'] = d b = {f'B{i}': None for i in range(1, 3)} data_b = unpack('>hHH', raw_data[adress_b:adress_b + calcsize('>hHH')]) (b['B1'], size_arr, adress_arr) = data_b array = [] data_arr = unpack(f'>{size_arr}H', raw_data[adress_arr:adress_arr + calcsize(f'>{size_arr}H')]) arr = data_arr for adress in arr: c = {f'C{i}': None for i in range(1, 3)} data_c = unpack('>bQ', raw_data[adress:adress + calcsize('>bq')]) (c['C1'], c['C2']) = data_c array.append(c) b['B2'] = array a['A1'] = b return a" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('B', data[pointer:pointer + 1])[0] d2 = ''.join(map(str, struct.unpack('>4c', data[pointer + 1:pointer + 5]))) d2 = d2.replace(""'"", '')[1::2] (d3, d4) = struct.unpack('>bd', data[pointer + 5:pointer + 14]) d5 = list(struct.unpack('>2h', data[pointer + 14:pointer + 18])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>Hqfh', data[pointer:pointer + 16]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): b1 = parse_c(data, pointer) (b2, b3, b4) = struct.unpack('>Qqf', data[pointer + 16:pointer + 36]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): (a1, a2, a3, a4) = struct.unpack('>bdQb', data[pointer:pointer + 18]) f5 = struct.unpack('>H', data[pointer + 18:pointer + 20]) a5 = parse_b(data, f5[0]) f6 = struct.unpack('>HH', data[pointer + 20:pointer + 24]) a6 = list() for i in range(f6[0]): f66 = struct.unpack('>I', data[f6[1] + 4 * i:f6[1] + 4 + 4 * i]) a6.append(parse_d(data, f66[0])) a7 = list(struct.unpack('>7I', data[pointer + 24:pointer + 52])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 4)" "import struct def main(data): A = struct.unpack_from('d', data[pointer:pointer + 8])[0] d2 = list(struct.unpack('>3Q', data[pointer + 8:pointer + 32])) (d3, d4) = struct.unpack('>BB', data[pointer + 32:pointer + 34]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>hhf', data[pointer:pointer + 8]) c4 = list(struct.unpack('>5B', data[pointer + 8:pointer + 13])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): (b1, b2) = struct.unpack('>Bh', data[pointer:pointer + 3]) f3 = struct.unpack('>HI', data[pointer + 3:pointer + 9]) b3 = list() for i in range(f3[0]): f33 = struct.unpack('>H', data[f3[1] + 2 * i:f3[1] + 2 + 2 * i]) b3.append(parse_c(data, f33[0])) b4 = struct.unpack('>Q', data[pointer + 9:pointer + 17])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, f1[0]) f2 = struct.unpack('>HI', data[pointer + 4:pointer + 10]) a2 = ''.join(map(str, struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0]]))) a2 = a2.replace(""'"", '')[1::2] (a3, a4) = struct.unpack('>qI', data[pointer + 10:pointer + 22]) f5 = struct.unpack('>H', data[pointer + 22:pointer + 24]) a5 = parse_d(data, f5[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack(' d', x[pos:pos + 8])[0], 'D2': struct.unpack('> h', x[pos + 8:pos + 10])[0]} def c_struct(x, pos): return {'C1': struct.unpack('> d', x[pos:pos + 8])[0], 'C2': str(x[pos + 8:pos + 13])[2:-1], 'C3': struct.unpack('> Q', x[pos + 13:pos + 21])[0]} def uint32uint32char(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] return str(x[add:add + size])[2:-1] def b_struct(x, pos): return {'B1': struct.unpack('> b', x[pos:pos + 1])[0], 'B2': c_struct(x, pos + 1), 'B3': struct.unpack('> q', x[pos + 22:pos + 30])[0], 'B4': struct.unpack('> d', x[pos + 30:pos + 38])[0], 'B5': uint32uint32char(x, pos + 38), 'B6': struct.unpack('> i', x[pos + 46:pos + 50])[0]} def uint32uint32address_b_d_uint16(x, pos): size = struct.unpack('> I', x[pos:pos + 4])[0] add = struct.unpack('> I', x[pos + 4:pos + 8])[0] a = [] for i in range(size): a.append(d_struct(x, address_b_d_uint16(x, add + i * 2))) return a def address_b_d_uint16(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def a_struct(x, pos): return {'A1': b_struct(x, address_b_d_uint16(x, pos)), 'A2': uint32uint32address_b_d_uint16(x, pos + 2), 'A3': struct.unpack('> h', x[pos + 10:pos + 12])[0], 'A4': [struct.unpack('> q', x[pos + 12:pos + 20])[0], struct.unpack('> q', x[pos + 20:pos + 28])[0], struct.unpack('> q', x[pos + 28:pos + 36])[0], struct.unpack('> q', x[pos + 36:pos + 44])[0], struct.unpack('> q', x[pos + 44:pos + 52])[0]], 'A5': struct.unpack('> b', x[pos + 52:pos + 53])[0]} def main(x): return a_struct(x, 5)" "import struct def d_struct(x, pos): return {'D1': struct.unpack('< b', x[pos:pos + 1])[0], 'D2': struct.unpack('< i', x[pos + 1:pos + 5])[0], 'D3': [struct.unpack('< B', x[pos + 5:pos + 6])[0], struct.unpack('< B', x[pos + 6:pos + 7])[0], struct.unpack('< B', x[pos + 7:pos + 8])[0], struct.unpack('< B', x[pos + 8:pos + 9])[0], struct.unpack('< B', x[pos + 9:pos + 10])[0], struct.unpack('< B', x[pos + 10:pos + 11])[0]]} def c_struct(x, pos): return {'C1': [struct.unpack('< B', x[pos:pos + 1])[0], struct.unpack('< B', x[pos + 1:pos + 2])[0], struct.unpack('< B', x[pos + 2:pos + 3])[0], struct.unpack('< B', x[pos + 3:pos + 4])[0], struct.unpack('< B', x[pos + 4:pos + 5])[0]], 'C2': struct.unpack('< q', x[pos + 5:pos + 13])[0], 'C3': struct.unpack('< B', x[pos + 13:pos + 14])[0]} def uint32uint32uint32(x, start): size = struct.unpack('< I', x[start:start + 4])[0] add = struct.unpack('< I', x[start + 4:start + 8])[0] a = struct.unpack('< ' + 'I' * size, x[add:add + 4 * size]) return list(a) def b_struct(x, pos): return {'B1': struct.unpack('< H', x[pos:pos + 2])[0], 'B2': struct.unpack('< b', x[pos + 2:pos + 3])[0], 'B3': struct.unpack('< f', x[pos + 3:pos + 7])[0], 'B4': struct.unpack('< I', x[pos + 7:pos + 11])[0]} def address_b_uint16(x, pos): return struct.unpack('< H', x[pos:pos + 2])[0] def a_struct(x, pos): return {'A1': struct.unpack('< b', x[pos:pos + 1])[0], 'A2': uint32uint32uint32(x, pos + 1), 'A3': str(x[pos + 9:pos + 13])[2:-1], 'A4': b_struct(x, address_b_uint16(x, pos + 13)), 'A5': [c_struct(x, pos + 15), c_struct(x, pos + 29), c_struct(x, pos + 43), c_struct(x, pos + 57), c_struct(x, pos + 71), c_struct(x, pos + 85), c_struct(x, pos + 99)], 'A6': d_struct(x, pos + 113)} def main(x): return a_struct(x, 4)" "from struct import unpack def main(data): g = '>HQ' f = '>hHHh' e = 'hiiiiiiIB' d = 'BfffQ' c = '>Qh{D}'.replace('{D}', d) b = 'IIIIi{E}'.replace('{E}', e) a = '>xxxx{B}IHHdHfI'.replace('{B}', b) obj = unpack(a, data[:81]) B2 = [] mas = [] array_c = [] array_f = [] array_g = [] (array_size_32, array_addr_32) = (obj[1], obj[2]) array_32 = [] E = {'E1': obj[5], 'E2': [obj[6], obj[7], obj[8], obj[9], obj[10], obj[11]], 'E3': obj[12], 'E4': obj[13]} for i in range(array_size_32): array_32.append(unpack('>I', data[array_addr_32:array_addr_32 + 4])[0]) array_addr_32 += 4 array_addr_c = array_32[i] array_c.append(unpack(c, data[array_addr_c:array_addr_c + 31])) array_addr_c += 31 D = {'D1': array_c[i][2], 'D2': [array_c[i][3], array_c[i][4]], 'D3': array_c[i][5], 'D4': array_c[i][6]} C = {'C1': array_c[i][0], 'C2': array_c[i][1], 'C3': D} B2.append(C) B = {'B1': obj[0], 'B2': B2, 'B3': obj[3], 'B4': obj[4], 'B5': E} array_f = unpack(f, data[obj[18]:obj[18] + 8]) array_g = unpack(g, data[obj[20]:obj[20] + 16]) array_addr_mas = array_f[2] for i in range(array_f[1]): mas.append(unpack('>BB', data[array_addr_mas:array_addr_mas + 2])[0]) array_addr_mas += 1 F = {'F1': array_f[0], 'F2': mas, 'F3': array_f[3]} G = {'G1': array_g[0], 'G2': array_g[1]} A = {'A1': B, 'A2': obj[14], 'A3': [obj[15], obj[16]], 'A4': obj[17], 'A5': F, 'A6': obj[19], 'A7': G} return A" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def getBuffer(self): return self.buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def read_b(reader): b1 = reader.read(Types.int8) b2 = reader.read(Types.int32) b3 = reader.read(Types.int32) return dict(B1=b1, B2=b2, B3=b3) def read_c(reader): c1 = read_d(reader) c2 = reader.read(Types.int16) c3 = reader.read(Types.uint8) return dict(C1=c1, C2=c2, C3=c3) def read_d(reader): d1 = reader.read(Types.uint16) size_2 = reader.read(Types.uint16) adress_2 = reader.read(Types.uint16) d2 = reader.copy(offset=adress_2).readWithSize(Types.uint32, size_2) return dict(D1=d1, D2=d2) def read_e(reader): e1 = reader.read(Types.double) e2 = reader.read(Types.float) size_3 = reader.read(Types.uint16) adress_3 = reader.read(Types.uint32) e3 = reader.copy(offset=adress_3).readWithSize(Types.float, size_3) e4 = reader.read(Types.double) e5 = reader.read(Types.int16) return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.readWithSize(Types.int8, 6) size_2 = reader.read(Types.uint16) adress_2 = reader.read(Types.uint32) a2 = [] bReader = BinaryReader(offset=adress_2, buffer=buffer) for i in range(0, size_2): a2.append(read_b(bReader)) a3 = reader.read(Types.uint8) a4 = read_c(reader) a5 = reader.read(Types.int8) a6 = read_e(reader.copy(offset=reader.read(Types.uint16))) a7 = reader.read(Types.int64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct def structD(data, pointer): (d1,) = struct.unpack(' H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_b_arr = u('> I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a1 = list() for i in range(size_b_arr): add_b = u('> I', data[add_b_arr:add_b_arr + int32_s])[0] a1.append(parse_B(data, add_b)) add_b_arr += int32_s a2 = parse_C(data) add_d = u('> I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a3 = parse_D(data, add_d) return {'A1': a1, 'A2': a2, 'A3': a3} def parse_B(data, add): b1 = u('> b', data[add:add + int8_s])[0] add += int8_s size_b2 = u('> H', data[add:add + int16_s])[0] add += int16_s add_b2 = u('> I', data[add:add + int32_s])[0] add += int32_s b2 = '' for i in range(size_b2): b2 += u('> ' + size_b2 * 'c', data[add_b2:add_b2 + size_b2])[i].decode('ascii') return {'B1': b1, 'B2': b2} def parse_C(data): global cur_offset c1 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s c2 = [] for i in range(8): c2.append(u('> d', data[cur_offset:cur_offset + double_s])[0]) cur_offset += double_s c3 = u('> B', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s c4 = u('> Q', data[cur_offset:cur_offset + int64_s])[0] cur_offset += int64_s c5 = u('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s c6 = u('> b', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_D(data, add): d1 = u('> d', data[add:add + double_s])[0] add += double_s d2 = u('> i', data[add:add + int32_s])[0] add += int32_s d3 = u('> q', data[add:add + int64_s])[0] add += int64_s d4 = u('> f', data[add:add + float_s])[0] add += float_s d5 = [] for i in range(4): d5.append(u('> b', data[add:add + int8_s])[0]) add += int8_s d6_size = u('> I', data[add:add + int32_s])[0] add += int32_s d6_add = u('> H', data[add:add + int16_s])[0] add += int16_s d6 = [] for i in range(d6_size): d6.append(u('> f', data[d6_add:d6_add + float_s])[0]) d6_add += float_s return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def main(x): return parse_A(x)" "from struct import unpack as u int8_s = 1 char_s = 1 int16_s = 2 int32_s = 4 int64_s = 8 double_s = 8 float_s = 4 cur_offset = 4 def parse_A(data): global cur_offset a1 = list() for i in range(3): a1.append(parse_B(data)) a2 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s size_a3 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_a3 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s a3 = [] for i in range(size_a3): a3.append(u('> I', data[add_a3:add_a3 + int32_s])[0]) add_a3 += int32_s a4 = u('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a5 = u('> b', data[cur_offset:cur_offset + int8_s])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def parse_B(data): global cur_offset b1 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_b2 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s b2 = parse_C(data, add_b2) return {'B1': b1, 'B2': b2} def parse_C(data, add): c1 = [] for i in range(8): c1.append(u('> b', data[add:add + int8_s])[0]) add += int8_s c2_size = u('> H', data[add:add + int16_s])[0] add += int16_s c2_add = u('> I', data[add:add + int32_s])[0] add += int32_s c2 = [] for i in range(c2_size): c2.append(u('> b', data[c2_add:c2_add + int8_s])[0]) c2_add += int8_s c3 = parse_D(data, add) add += double_s + int16_s * 3 c4 = u('> i', data[add:add + int32_s])[0] add += int32_s return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_D(data, add): d1 = u('> d', data[add:add + double_s])[0] add += double_s d2_size = u('> H', data[add:add + int16_s])[0] add += int16_s d2_add = u('> H', data[add:add + int16_s])[0] add += int16_s d2 = [] for i in range(d2_size): d2.append(u('> b', data[d2_add:d2_add + int8_s])[0]) d2_add += int8_s d3 = u('> h', data[add:add + int16_s])[0] add += int16_s return {'D1': d1, 'D2': d2, 'D3': d3} def main(x): return parse_A(x)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_a(reader): a_1 = reader.read_uint16() a_2 = reader.read_int32() a_3 = reader.read_uint64() a_4 = reader.read_int64() a_5 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_b(reader)) return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def read_b(reader): b_1 = [] for i in range(5): b_1.append(read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_c(reader))) b_2 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_d(reader)) b_3 = reader.read_int8() b_4 = reader.read_int16() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4) def read_c(reader): c_1 = reader.read_int16() c_2 = [reader.read_uint8(), reader.read_uint8()] c_3 = reader.read_uint16() return dict(C1=c_1, C2=c_2, C3=c_3) def read_d(reader): d_1 = [reader.read_uint32(), reader.read_uint32(), reader.read_uint32(), reader.read_uint32()] d_2 = reader.read_double() d_3 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_int32()) d_4 = reader.read_int8() d_5 = reader.read_int32() d_6 = reader.read_uint64() return dict(D1=d_1, D2=d_2, D3=d_3, D4=d_4, D5=d_5, D6=d_6) def main(data): reader = BinaryReader(data) reader.read('ccccc') return read_a(reader)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_a(reader): a_1 = reader.read_uint8() a_2 = [read_b(reader), read_b(reader)] a_3 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_c(reader)) return dict(A1=a_1, A2=a_2, A3=a_3) def read_b(reader): b_1 = reader.read_float() b_2 = reader.read_int16() b_3 = [reader.read_uint32(), reader.read_uint32(), reader.read_uint32(), reader.read_uint32(), reader.read_uint32()] b_4 = reader.read_int16() b_5 = reader.read_int8() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4, B5=b_5) def read_c(reader): c_1 = reader.read_uint16() c_2 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader)) c_3 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_uint16()) c_4 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_int32()) c_5 = reader.read_uint32() c_6 = reader.read_int64() c_7 = reader.read_int8() return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4, C5=c_5, C6=c_6, C7=c_7) def read_d(reader): d_1 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_double()) d_2 = reader.read_uint64() d_3 = reader.read_int64() return dict(D1=d_1, D2=d_2, D3=d_3) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('double', data, ofs) D2 = [] (D2_size, ofs) = parse('uint32', data, ofs) (D2_adr, ofs) = parse('uint16', data, ofs) for i in range(D2_size): (elem, D2_adr) = parse('uint16', data, D2_adr) D2.append(elem) (D3, ofs) = parse('int64', data, ofs) (D4, ofs) = parse('int16', data, ofs) D5 = [] for i in range(4): (elem, ofs) = parse('int8', data, ofs) D5.append(elem) (D6, ofs) = parse('double', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6), ofs) def struct_C(data, ofs): C1 = '' (C1_size, ofs) = parse('uint16', data, ofs) (C1_adr, ofs) = parse('uint32', data, ofs) for i in range(C1_size): (elem, C1_adr) = parse('char', data, C1_adr) C1 += elem.decode() (C2, ofs) = parse('uint8', data, ofs) (C3, ofs) = parse('int64', data, ofs) (C4, ofs) = parse('double', data, ofs) (C5, ofs) = parse('uint8', data, ofs) C6 = [] for i in range(3): (elem, ofs) = parse('uint32', data, ofs) C6.append(elem) (C7, ofs) = parse('float', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int16', data, ofs) (B2, ofs) = parse('int16', data, ofs) (B3, ofs) = parse('double', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint64', data, ofs) (A2, ofs) = parse('uint64', data, ofs) A3 = [] for i in range(4): (B_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_B(data, B_adr) A3.append(elem) (A4, ofs) = struct_C(data, ofs) (A5_adr, ofs) = parse('uint32', data, ofs) (A5, elem) = struct_D(data, A5_adr) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def int8p1(x, pos): return struct.unpack('> b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('> B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('> h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('> I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('> i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('> q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('> Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('> f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('> d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint16uint16int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + 1 * size]) return list(a) def uint32uint32int16p8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint16int64(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'q' * size, x[add:add + 8 * size]) return list(a) def D(x, pos): return {'D1': double8p8(x, pos), 'D2': float4p4(x, pos + 8), 'D3': [float4p4(x, pos + 12 + i * 4) for i in range(7)], 'D4': uint32p4(x, pos + 40), 'D5': double8p8(x, pos + 44), 'D6': [int16p2(x, pos + 52), int16p2(x, pos + 54)]} def C(x, pos): return {'C1': float4p4(x, pos), 'C2': int64p8(x, pos + 4), 'C3': float4p4(x, pos + 12), 'C4': uint32uint32int16p8(x, pos + 16), 'C5': int16p2(x, pos + 24), 'C6': D(x, pos + 26)} def B(x, pos): return {'B1': uint64p8(x, pos), 'B2': int64p8(x, pos + 8)} def A(x, pos): return {'A1': [B(x, uint32p4(x, pos)), B(x, uint32p4(x, pos + 4))], 'A2': float4p4(x, pos + 8), 'A3': int64p8(x, pos + 12), 'A4': C(x, uint32p4(x, pos + 20)), 'A5': uint16p2(x, pos + 24)} def main(x): return A(x, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int8', data, ofs) (E2, ofs) = parse('uint32', data, ofs) (E3, ofs) = parse('int8', data, ofs) (E4, ofs) = parse('int16', data, ofs) E5 = [] (E5_size, ofs) = parse('uint16', data, ofs) (E5_adr, ofs) = parse('uint32', data, ofs) for i in range(E5_size): (elem, E5_adr) = parse('int16', data, E5_adr) E5.append(elem) (E6, ofs) = parse('float', data, ofs) E7 = [] (E7_size, ofs) = parse('uint32', data, ofs) (E7_adr, ofs) = parse('uint16', data, ofs) for i in range(E7_size): (elem, E7_adr) = parse('float', data, E7_adr) E7.append(elem) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint8', data, ofs) (D2, ofs) = parse('uint8', data, ofs) D3 = [] (D3_size, ofs) = parse('uint16', data, ofs) (D3_adr, ofs) = parse('uint32', data, ofs) for i in range(D3_size): (elem, D3_adr) = parse('int8', data, D3_adr) D3.append(elem) (D4, ofs) = parse('uint32', data, ofs) (D5, ofs) = parse('uint16', data, ofs) (D6, ofs) = parse('uint8', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6), ofs) def struct_C(data, ofs): (C1, ofs) = parse('double', data, ofs) (C2, ofs) = parse('int8', data, ofs) (C3, ofs) = parse('uint64', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) (B2, ofs) = parse('double', data, ofs) (B3, ofs) = parse('int16', data, ofs) (B4_adr, ofs) = parse('uint32', data, ofs) (B4, elem) = struct_C(data, B4_adr) (B5, ofs) = parse('int16', data, ofs) (B6, ofs) = parse('int32', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_A(data, ofs): A1 = '' for i in range(6): (elem, ofs) = parse('char', data, ofs) A1 += elem.decode() (A2, ofs) = parse('uint16', data, ofs) (A3, ofs) = parse('uint64', data, ofs) (A4, ofs) = parse('uint16', data, ofs) (A5, ofs) = parse('int32', data, ofs) (A6, ofs) = struct_B(data, ofs) A7 = [] for i in range(3): (D_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_D(data, D_adr) A7.append(elem) (A8, ofs) = struct_E(data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def main(data): A = struct.unpack_from('>fhI8c4HI', data, offset=3) A4 = '' for i in range(8): A4 += A[i + 3].decode('utf-8') B_list = [] for i in range(4): B = struct.unpack_from('>HIiIhI', data, offset=A[i + 11]) C1 = list(struct.unpack_from('>' + str(B[0]) + 'b', data, offset=B[1])) D = struct.unpack_from('>f4bQ', data, offset=B[5]) B_list.append({'B1': {'C1': C1, 'C2': B[2]}, 'B2': B[3], 'B3': B[4], 'B4': {'D1': D[0], 'D2': [D[1], D[2], D[3], D[4]], 'D3': D[5]}}) E = struct.unpack_from('>IB', data, offset=A[15]) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': A4, 'A5': B_list, 'A6': {'E1': E[0], 'E2': E[1]}}" "import struct def int8p1(x, pos): return struct.unpack('> b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('> B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('> h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('> I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('> i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('> q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('> Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('> f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('> d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint16uint16int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + 1 * size]) return list(a) def uint16uint16uint8p4(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + 1 * size]) return list(a) def uint32uint32int16p8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint32int16p6(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint16int64(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'q' * size, x[add:add + 8 * size]) return list(a) def F(x, pos): return {'F1': float4p4(x, pos), 'F2': int8p1(x, pos + 4)} def E(x, pos): return {'E1': uint16uint32int16p6(x, pos), 'E2': int8p1(x, pos + 6), 'E3': [uint16p2(x, pos + 7 + 2 * i) for i in range(7)], 'E4': double8p8(x, pos + 21), 'E5': uint16p2(x, pos + 29), 'E6': uint64p8(x, pos + 31), 'E7': uint16uint16uint8p4(x, pos + 39)} def arraye(x, pos): size = uint32p4(x, pos) address = uint32p4(x, pos + 4) a = [] for i in range(size): a.append(E(x, address + 43 * i)) return a def D(x, pos): return {'D1': arraye(x, pos), 'D2': int64p8(x, pos + 8), 'D3': uint16p2(x, pos + 16), 'D4': double8p8(x, pos + 18), 'D5': int16p2(x, pos + 24 + 2), 'D6': float4p4(x, pos + 26 + 2), 'D7': F(x, pos + 32), 'D8': double8p8(x, pos + 37)} def C(x, pos): return {'C1': int8p1(x, pos), 'C2': int32p4(x, pos + 1), 'C3': uint16p2(x, pos + 5), 'C4': uint8p1(x, pos + 7), 'C5': char1p1(x, pos + 8) + char1p1(x, pos + 9)} def B(x, pos): return {'B1': int8p1(x, pos), 'B2': C(x, uint16p2(x, pos + 1)), 'B3': uint32p4(x, pos + 3)} def A(x, pos): return {'A1': B(x, pos), 'A2': uint8p1(x, pos + 7), 'A3': float4p4(x, pos + 8), 'A4': double8p8(x, pos + 12), 'A5': D(x, uint32p4(x, pos + 20))} def main(x): return A(x, 3)" "from struct import unpack def main(string): s = 3 w = string b_len = unpack('H', w[s:s + 2][::-1])[0] ba = unpack('H', w[s + 2:s + 4][::-1])[0] answer_b_list = [] for i in range(b_len): sh = i * 48 ca = unpack('I', w[ba + sh:ba + sh + 4][::-1])[0] c_list = [] for j in range(6): c_list.append(unpack('B', w[ca + j:ca + j + 1][::-1])[0]) c2 = unpack('d', w[ca + 6:ca + 14][::-1])[0] b_list = [] for j in range(2): b_list.append(unpack('I', w[ba + sh + 4 + j * 4:ba + sh + 4 + (j + 1) * 4][::-1])[0]) dadd = ba + 12 + sh d1 = unpack('i', w[dadd:dadd + 4][::-1])[0] d2 = [] for j in range(3): d2.append(unpack('H', w[dadd + 4 + j * 2:dadd + 4 + (j + 1) * 2][::-1])[0]) d3 = unpack('h', w[dadd + 10:dadd + 12][::-1])[0] d4 = [] for j in range(6): d4.append(unpack('I', w[dadd + 12 + j * 4:dadd + 12 + (j + 1) * 4][::-1])[0]) answer_b_list.append({'B1': {'C1': c_list, 'C2': c2}, 'B2': b_list, 'B3': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}}) a3 = unpack('I', w[s + 4:s + 8][::-1]) a4 = unpack('H', w[s + 8:s + 10][::-1]) answer = {'A1': answer_b_list, 'A2': a3[0], 'A3': a4[0]} return answer" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int8', data, ofs) (E2, ofs) = parse('uint32', data, ofs) (E3, ofs) = parse('int8', data, ofs) (E4, ofs) = parse('int16', data, ofs) E5 = [] (E5_size, ofs) = parse('uint16', data, ofs) (E5_adr, ofs) = parse('uint32', data, ofs) for i in range(E5_size): (elem, E5_adr) = parse('int16', data, E5_adr) E5.append(elem) (E6, ofs) = parse('float', data, ofs) E7 = [] (E7_size, ofs) = parse('uint32', data, ofs) (E7_adr, ofs) = parse('uint16', data, ofs) for i in range(E7_size): (elem, E7_adr) = parse('float', data, E7_adr) E7.append(elem) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7), ofs) def struct_D(data, ofs): D1 = [] for i in range(8): (elem, ofs) = parse('int8', data, ofs) D1.append(elem) (D2, ofs) = parse('int32', data, ofs) (D3, ofs) = parse('uint64', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def struct_C(data, ofs): (C1, ofs) = parse('int16', data, ofs) C2 = [] (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint32', data, ofs) for i in range(C2_size): (elem, C2_adr) = parse('int64', data, C2_adr) C2.append(elem) (C3, ofs) = parse('double', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint8', data, ofs) B2 = '' for i in range(7): (elem, ofs) = parse('char', data, ofs) B2 += elem.decode() (B3_adr, ofs) = parse('uint32', data, ofs) (B3, elem) = struct_C(data, B3_adr) (B4, ofs) = parse('double', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = struct_B(data, ofs) A2 = [] for i in range(3): (D_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_D(data, D_adr) A2.append(elem) return (dict(A1=A1, A2=A2), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def uint32uint32uint16(x, start): size = struct.unpack('5cqi2qhIh2IfQfI', data, offset=5) A1 = '' for i in range(5): A1 += A[i].decode('utf-8') B3 = struct.unpack_from('>' + 'IfB' * A[12], data, offset=A[13]) C_list = [] for i in range(A[12]): C_list.append({'C1': B3[i * 3], 'C2': B3[i * 3 + 1], 'C3': B3[i * 3 + 2]}) D = struct.unpack_from('>ib4dIH', data, offset=A[17]) D4 = list(struct.unpack_from('>' + str(D[6]) + 'H', data, offset=D[7])) return {'A1': A1, 'A2': A[5], 'A3': A[6], 'A4': A[7], 'A5': A[8], 'A6': A[9], 'A7': {'B1': A[10], 'B2': A[11], 'B3': C_list, 'B4': A[14], 'B5': A[15], 'B6': A[16], 'B7': {'D1': D[0], 'D2': D[1], 'D3': [D[2], D[3], D[4], D[5]], 'D4': D4}}}" "import struct def main(data): start_B1 = 4 b1 = struct.unpack_from('>BQH2Hd2bi', data, start_B1) start_B2 = struct.calcsize('>BQH2Hd2bi') + start_B1 b2 = struct.unpack_from('>BQH2Hd2bi', data, start_B2) len_b4_1 = b1[3] b4_1 = list(struct.unpack_from('>' + len_b4_1 * 'b', data, b1[4])) len_b4_2 = b2[3] b4_2 = list(struct.unpack_from('>' + len_b4_2 * 'b', data, b2[4])) C1 = {'C1': b1[5], 'C2': b1[6], 'C3': b1[7]} C2 = {'C1': b2[5], 'C2': b2[6], 'C3': b2[7]} start_A = 4 + struct.calcsize('>BQH2Hd2bi') * 2 a = struct.unpack_from('>2I3H6i', data, start_A) a5 = struct.unpack_from('>' + a[3] * 'c', data, a[4]) a5 = b''.join(a5).decode('utf-8') d = struct.unpack_from('>qdI', data, a[0]) D = {'D1': d[0], 'D2': d[1], 'D3': d[2]} a6 = list(a[5:]) a1 = [] b1 = {'B1': b1[0], 'B2': b1[1], 'B3': b1[2], 'B4': b4_1, 'B5': C1, 'B6': b1[-1]} b2 = {'B1': b2[0], 'B2': b2[1], 'B3': b2[2], 'B4': b4_2, 'B5': C2, 'B6': b2[-1]} a1.append(b1) a1.append(b2) A = {'A1': a1, 'A2': D, 'A3': a[1], 'A4': a[2], 'A5': a5, 'A6': a6} return A" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_d(buf, offs): d1 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'double') d1.append(val) (d2, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(6): (val, offs) = parse_c(buf, offs) b2.append(val) (b3, offs) = parse(buf, offs, 'double') (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = '' for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'char') val = val.decode('utf-8') b4 = b4 + str(val) (b5, offs) = parse(buf, offs, 'uint32') (b6, offs) = parse_d(buf, offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2_offs, offs) = parse(buf, offs, 'uint32') (val, a2_offs) = parse_b(buf, a2_offs) a2 = val (a3, offs) = parse(buf, offs, 'float') a4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint8') a4.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_f(reader: BinaryReader): f1 = reader.read_uint8() f2 = reader.read_uint32() f3 = [reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16()] f4 = reader.read_float() f5 = reader.read_int16() return dict(F1=f1, F2=f2, F3=f3, F4=f4, F5=f5) def read_e(reader: BinaryReader): e1 = reader.read_int64() e2 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_int64(), structure_size=8) e3 = reader.read_int8() e4 = reader.read_int16() e5 = reader.read_float() e6 = reader.read_int16() e7 = reader.read_int32() return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7) def read_d(reader: BinaryReader): d1 = reader.read_uint8() d2 = reader.read_int32() d3 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_e(reader), structure_size=18)[0] d4 = reader.read_uint32() d5 = read_f(reader) d6 = reader.read_uint16() d7 = reader.read_uint32() return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def read_c(reader: BinaryReader): c1 = reader.read_int32() c2 = reader.read_uint16() return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: read_c(reader), structure_size=6) b2 = read_d(reader) return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = reader.read_int16() a2 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_b(reader))[0] a3 = reader.read_uint32() a4 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_int16(), structure_size=2) return dict(A1=a1, A2=a2, A3=a3, A4=a4) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): data = unpack_from(FMT[ty], buf, offs) data = data[0] of = offs + calcsize(FMT[ty]) return (data, of) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'uint64') (a3, offs) = parse(buf, offs, 'int32') (a4, offs) = parse(buf, offs, 'double') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse_c(buf, b2_offs) b2.append(val) (b3, offs) = parse(buf, offs, 'int8') (b4, offs) = parse_d(buf, offs) (b5, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'uint64') (c3_size, offs) = parse(buf, offs, 'uint32') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'uint8') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'uint8') (d4, offs) = parse(buf, offs, 'int64') d5 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint8') d5.append(val) d6 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') d6.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def uint16uint32char(s, pointer): size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('c' * size, s[add:add + 1 * size]) b = str(a[0])[2:3] + str(a[1])[2:3] return b def uint32uint16uint32(s, pointer): size = struct.unpack('I', s[pointer:pointer + 4])[0] add = struct.unpack('H', s[pointer + 4:pointer + 6])[0] a = struct.unpack('I' * size, s[add:add + 4 * size]) return list(a) def uint16uint16_in_C_structure(s, pointer): result = [] size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('H', s[pointer + 2:pointer + 4])[0] for i in range(0, size): c1 = struct.unpack('h', s[add:add + 2])[0] c2 = struct.unpack('I', s[add + 2:add + 6])[0] result.append({'C1': c1, 'C2': c2}) add += 6 return result def main(s): a1 = struct.unpack('I', s[5:9])[0] out_dict = {'A1': {'B1': uint16uint16_in_C_structure(s, a1), 'B2': struct.unpack('h', s[a1 + 4:a1 + 6])[0], 'B3': struct.unpack('h', s[a1 + 6:a1 + 8])[0], 'B4': uint16uint32char(s, a1 + 8), 'B5': list(struct.unpack('3f', s[a1 + 12:a1 + 24])), 'B6': struct.unpack('H', s[a1 + 24:a1 + 26])[0]}, 'A2': {'D1': struct.unpack('H', s[9:11])[0], 'D2': struct.unpack('I', s[11:15])[0], 'D3': struct.unpack('b', s[15:16])[0], 'D4': list(struct.unpack('2d', s[16:32])), 'D5': uint32uint16uint32(s, 32), 'D6': struct.unpack('q', s[38:46])[0], 'D7': struct.unpack('q', s[46:54])[0], 'D8': struct.unpack('i', s[54:58])[0]}} return out_dict" "import struct def main(data): start_A = 3 a = struct.unpack_from(' reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.int32), structure_size=4), D2=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int16), structure_size=2)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.float), C2=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), C3=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.int16), structure_size=4)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int64), B2=[read_c(BinaryReader(reader.source, offset=i)) for i in read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint32), structure_size=4)]) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.int8), A2=read_b(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), A3=reader.read(Primitive.uint8), A4=reader.read(Primitive.uint32), A5=reader.read(Primitive.uint8), A6=reader.read(Primitive.double)) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack('2QHBbh2H3iIQbh2H3iIQbh2H3iIQbh2H3iIQhIH', data, offset=3) A3 = list(struct.unpack_from('>' + str(A[41]) + 'h', data, offset=A[42])) C = struct.unpack_from('>2IB', data, offset=A[2]) C1 = list(struct.unpack_from('>' + str(C[0]) + 'c', data, offset=C[1])) for i in range(C[0]): C1[i] = C1[i].decode('utf-8') C1 = ''.join(C1) return {'A1': {'B1': A[0], 'B2': A[1], 'B3': {'C1': C1, 'C2': C[2]}, 'B4': A[3], 'B5': [{'D1': A[4], 'D2': A[5], 'D3': [A[6], A[7]], 'D4': [A[8], A[9], A[10]], 'D5': A[11], 'D6': A[12]}, {'D1': A[13], 'D2': A[14], 'D3': [A[15], A[16]], 'D4': [A[17], A[18], A[19]], 'D5': A[20], 'D6': A[21]}, {'D1': A[22], 'D2': A[23], 'D3': [A[24], A[25]], 'D4': [A[26], A[27], A[28]], 'D5': A[29], 'D6': A[30]}, {'D1': A[31], 'D2': A[32], 'D3': [A[33], A[34]], 'D4': [A[35], A[36], A[37]], 'D5': A[38], 'D6': A[39]}]}, 'A2': A[40], 'A3': A3}" "from struct import unpack def main(f): signature = bytes([80, 67, 72]) a_adr = f.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(7)} temp = unpack('>bfQ', f[a_adr:a_adr + 13]) (a['A1'], a['A2'], a['A3']) = temp temp = unpack('>I7BH', f[a_adr + 54:a_adr + 67]) (a['A5'], *a['A6'], d_adr) = temp temp = unpack('>Qiq', f[d_adr:d_adr + 20]) a['A7'] = {'D1': temp[0], 'D2': temp[1], 'D3': temp[2]} b = {f'B{i + 1}': None for i in range(4)} temp = unpack('>IH', f[a_adr + 13:a_adr + 19]) (arr1_size, arr1_adr) = temp temp = unpack(f'>{arr1_size}s', f[arr1_adr:arr1_adr + arr1_size]) b['B1'] = str(temp[0], 'utf8') temp = unpack('>HB', f[a_adr + 51:a_adr + 54]) (b['B3'], b['B4']) = temp b['B2'] = [] for i in range(2): c = {f'C{i + 1}': None for i in range(3)} temp = unpack('>q4H', f[a_adr + 19 + i * 16:a_adr + 19 + (i + 1) * 16]) (c['C1'], arr2_size, arr2_adr, arr3_size, arr3_adr) = temp temp = unpack(f'>{arr2_size}i', f[arr2_adr:arr2_adr + arr2_size * 4]) c['C2'] = list(temp) temp = unpack(f'>{arr3_size}H', f[arr3_adr:arr3_adr + arr3_size * 2]) c['C3'] = list(temp) b['B2'].append(c) a['A4'] = b return a" "from struct import unpack as u int8_s = 1 char_s = 1 int16_s = 2 int32_s = 4 int64_s = 8 double_s = 8 float_s = 4 cur_offset = 4 def parse_A(data): global cur_offset a1 = [] for i in range(4): add_b = u('< I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a1.append(parse_B(data, add_b)) a2 = u('< H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s a3 = u('< B', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s add_c = u('< I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a4 = parse_C(data, add_c) a5 = u('< f', data[cur_offset:cur_offset + float_s])[0] cur_offset += float_s a6 = u('< b', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def parse_B(data, add): b1 = u('< I', data[add:add + int32_s])[0] add += int32_s b2 = u('< b', data[add:add + int8_s])[0] add += int8_s b3 = u('< q', data[add:add + int64_s])[0] add += int64_s return {'B1': b1, 'B2': b2, 'B3': b3} def parse_C(data, add): c1 = '' for j in range(7): c1 += u('< ccccccc', data[add:add + 7])[j].decode('ascii') add += 7 c2 = [] for i in range(5): c2.append(u('< b', data[add:add + int8_s])[0]) add += int8_s add_d = u('< H', data[add:add + int16_s])[0] c3 = parse_D(data, add_d) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_D(data, add): d1 = u('< h', data[add:add + int16_s])[0] add += int16_s d2 = u('< H', data[add:add + int16_s])[0] add += int16_s d3 = u('< H', data[add:add + int16_s])[0] add += int16_s size_d4 = u('< H', data[add:add + int16_s])[0] add += int16_s add_d4 = u('< H', data[add:add + int16_s])[0] add += int16_s d4 = [] for i in range(size_d4): d4.append(u('< h', data[add_d4:add_d4 + int16_s])[0]) add_d4 += int16_s size_d5 = u('< I', data[add:add + int32_s])[0] add += int32_s add_d5 = u('< H', data[add:add + int16_s])[0] add += int16_s d5 = [] for i in range(size_d5): d5.append(u('< b', data[add_d5:add_d5 + int8_s])[0]) add_d5 += int8_s d6 = u('< i', data[add:add + int32_s])[0] add += int32_s d7 = u('< i', data[add:add + int32_s])[0] add += int32_s d8 = u('< i', data[add:add + int32_s])[0] add += int32_s return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def main(x): return parse_A(x)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = readC(reader) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint16) b2 = reader.copy(offset=adress2).readWithSize(Types.uint16, size2) b3 = reader.read(Types.uint64) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.float) c2 = readD(reader) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint16) c3 = reader.copy(offset=adress3).readWithSize(Types.uint16, size3) c4 = reader.read(Types.int64) c5 = reader.read(Types.uint64) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def readD(reader): d1 = reader.read(Types.uint32) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint16) d2 = reader.copy(offset=adress2).readWithSize(Types.uint16, size2) d3 = reader.read(Types.uint32) return dict(D1=d1, D2=d2, D3=d3) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) size1 = reader.read(Types.uint32) adress1 = reader.read(Types.uint32) a1 = [] bReader = BinaryReader(offset=adress1, buffer=buffer) for i in range(0, size1): a1.append(readB(bReader)) a2 = reader.read(Types.double) a3 = reader.read(Types.float) a4 = reader.readWithSize(Types.float, 2) return dict(A1=a1, A2=a2, A3=a3, A4=a4)" "import struct def main(bs): magic_bytes = b'WNCS\x80' A = struct.Struct('< q fi fi fi fi fi fi b II b b b b b b b b b IH b I f b h q f') a = A.unpack_from(bs, len(magic_bytes)) c_address = list(struct.unpack_from(f'< {a[14]}s', bs, a[15])) c_array = c_address[0].decode() d_address = list(struct.unpack_from(f'<{a[25]}b', bs, a[26])) resolved = {'A1': a[0], 'A2': {'B1': [{'C1': a[1], 'C2': a[2]}, {'C1': a[3], 'C2': a[4]}, {'C1': a[5], 'C2': a[6]}, {'C1': a[7], 'C2': a[8]}, {'C1': a[9], 'C2': a[10]}, {'C1': a[11], 'C2': a[12]}], 'B2': a[13], 'B3': c_array, 'B4': [a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23]], 'B5': {'D1': a[24], 'D2': d_address, 'D3': a[27]}, 'B6': a[28], 'B7': a[29]}, 'A3': a[30], 'A4': a[31], 'A5': {'E1': a[32], 'E2': a[33]}} return resolved" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'double') (a3, offs) = parse_b(buf, offs) return (dict(A1=''.join(a1), A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'double') b3 = [] for _ in range(3): (val, offs) = parse_c(buf, offs) b3.append(val) (b4, offs) = parse(buf, offs, 'uint8') (b5, offs) = parse_d(buf, offs) (b6, offs) = parse(buf, offs, 'uint8') (b7_size, offs) = parse(buf, offs, 'uint32') (b7_offs, offs) = parse(buf, offs, 'uint16') b7 = [] for _ in range(b7_size): (val, b7_offs) = parse(buf, b7_offs, 'int8') b7.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int64') (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse(buf, offs, 'uint64') c5 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') c5.append(val) (c6_size, offs) = parse(buf, offs, 'uint32') (c6_offs, offs) = parse(buf, offs, 'uint16') c6 = [] for _ in range(c6_size): (val, c6_offs) = parse(buf, c6_offs, 'uint16') c6.append(val) (c7, offs) = parse(buf, offs, 'uint16') (c8, offs) = parse(buf, offs, 'int16') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'uint8') (d3, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import calcsize, unpack def main(raw_data): adress_b = 0 for byte in raw_data: adress_b += 1 if byte == 65: break a = {f'A{i}': None for i in range(1, 6)} b = {f'B{i}': None for i in range(1, 4)} d = {f'D{i}': None for i in range(1, 8)} data_b = unpack('>L4H', raw_data[adress_b:adress_b + calcsize('>L4H')]) (char_1_s, char_1_a, b['B2'], char_2_s, char_2_a) = data_b adress_a = adress_b + calcsize('>L4H') arr = unpack(f'>{char_1_s}s', raw_data[char_1_a:char_1_a + char_1_s]) b['B1'] = str(arr[0], 'utf8') arr = unpack(f'>{char_2_s}s', raw_data[char_2_a:char_2_a + char_2_s]) b['B3'] = str(arr[0], 'utf8') a['A1'] = b data_a = unpack('>4LB', raw_data[adress_a:adress_a + calcsize('>4LB')]) (arr_add, a['A3'], a['A4']) = (list(data_a[0:3]), data_a[3], data_a[4]) adress_d = adress_a + calcsize('>4LB') arr = [] for adress_c in arr_add: c = {f'C{i}': None for i in range(1, 5)} data_c = unpack('>lhlh', raw_data[adress_c:adress_c + calcsize('>lhlh')]) (c['C1'], c['C2'], c['C3'], c['C4']) = data_c arr.append(c) a['A2'] = arr data_d = unpack('>4QqL3QL', raw_data[adress_d:adress_d + calcsize('>4QqL3QL')]) (d['D1'], d['D6']) = (list(data_d[0:2]), list(data_d[6:9])) (d['D2'], d['D3'], d['D4'], d['D5']) = data_d[2:6] d['D7'] = data_d[9] a['A5'] = d return a" "import struct def main(s): d = {} a3 = {} b1 = [] c = {} b5 = {} d3 = [] d4 = [] a4 = {} a7 = [] a8 = [] base_address = 5 d.setdefault('A1', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 d.setdefault('A2', struct.unpack_from('>Q', s, base_address)[0]) base_address += 8 for i in range(6): new_address = struct.unpack_from('>I', s, base_address)[0] base_address += 4 c.setdefault('C1', struct.unpack_from('>h', s, new_address)[0]) new_address += 2 c.setdefault('C2', struct.unpack_from('>B', s, new_address)[0]) b1.append(c) c = {} a3.setdefault('B1', b1) a3.setdefault('B2', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 a3.setdefault('B3', struct.unpack_from('>q', s, base_address)[0]) base_address += 8 a3.setdefault('B4', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 b5.setdefault('D1', struct.unpack_from('>B', s, base_address)[0]) base_address += 1 b5.setdefault('D2', struct.unpack_from('>d', s, base_address)[0]) base_address += 8 for i in range(3): d3.append(struct.unpack_from('>B', s, base_address)[0]) base_address += 1 b5.setdefault('D3', d3) for i in range(3): d4.append(struct.unpack_from('>l', s, base_address)[0]) base_address += 4 b5.setdefault('D4', d4) a3.setdefault('B5', b5) d.setdefault('A3', a3) new_address = struct.unpack_from('>H', s, base_address)[0] base_address += 2 a4.setdefault('E1', struct.unpack_from('>H', s, new_address)[0]) new_address += 2 a4.setdefault('E2', struct.unpack_from('>I', s, new_address)[0]) new_address += 4 a4.setdefault('E3', struct.unpack_from('>b', s, new_address)[0]) new_address += 1 a4.setdefault('E4', struct.unpack_from('>q', s, new_address)[0]) new_address += 8 a4.setdefault('E5', struct.unpack_from('>i', s, new_address)[0]) new_address += 4 a4.setdefault('E6', struct.unpack_from('>d', s, new_address)[0]) new_address += 8 a4.setdefault('E7', struct.unpack_from('>H', s, new_address)[0]) new_address += 2 d.setdefault('A4', a4) d.setdefault('A5', struct.unpack_from('>I', s, base_address)[0]) base_address += 4 d.setdefault('A6', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 size = struct.unpack_from('>I', s, base_address)[0] base_address += 4 new_address = struct.unpack_from('>I', s, base_address)[0] base_address += 4 for i in range(size): a7.append(struct.unpack_from('>i', s, new_address)[0]) new_address += 4 d.setdefault('A7', a7) for i in range(4): a8.append(struct.unpack_from('>Q', s, base_address)[0]) base_address += 8 d.setdefault('A8', a8) return d" "import struct def main(x): f = dict() f['A1'] = struct.unpack('HHlH2bhl', file[a_adr:a_adr + 18]) (b_str_size, b_str_adr, c['C1'], d_adr, *int8_arr, c['C4'], a['A3']) = temp c['C3'] = list(int8_arr) temp = unpack('>fLLLHfHH', file[d_adr:d_adr + 26]) (d['D1'], d['D2'], d['D3'], uint64_size, uint64_adr, d['D5'], d['D6'], d['D7']) = temp temp = unpack(f'>{uint64_size}Q', file[uint64_adr:uint64_adr + uint64_size * 8]) d['D4'] = list(temp) b_strs = unpack(f"">{b_str_size * '3chdHQ'}"", file[b_str_adr:b_str_adr + b_str_size * 23]) parsed_arrays = parse_arrays(b_strs, b_str_size) a['A1'] = [] for b_str in parsed_arrays: (*ch_arr, b['B2'], b['B3'], b['B4'], b['B5']) = b_str b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A1'].append(b.copy()) a['A2'] = c c['C2'] = d return a" "import struct def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = parse_value(data, offset, 'q') (f2_size, f2_addr) = struct.unpack('LfHqdfH', file[a_adr:a_adr + 32]) (b_adr, a['A2'], a['A3'], a['A4'], a['A5'], a['A6'], d_adr) = temp temp = unpack('>QBlLH', file[d_adr:d_adr + 19]) (d['D1'], d['D2'], d['D3'], uint32_size, uint32_adr) = temp temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) d['D4'] = list(temp) temp = unpack('>B8cLHHq3BlLHHq3BlH', file[b_adr:b_adr + 57]) (b['B1'], *ch_arr) = temp[0:9] b['B2'] = ''.join((str(e, 'utf8') for e in ch_arr)) b['B3'] = [] (c['C1'], uint16_size, uint16_adr, c['C3'], *uint8_arr, c['C5']) = temp[9:17] c['C4'] = list(uint8_arr) temp1 = unpack(f'>{uint16_size}H', file[uint16_adr:uint16_adr + uint16_size * 2]) c['C2'] = list(temp1) b['B3'].append(c.copy()) (c['C1'], uint16_size, uint16_adr, c['C3'], *uint8_arr, c['C5']) = temp[17:25] c['C4'] = list(uint8_arr) temp1 = unpack(f'>{uint16_size}H', file[uint16_adr:uint16_adr + uint16_size * 2]) c['C2'] = list(temp1) b['B3'].append(c.copy()) b['B4'] = temp[25] a['A1'] = b a['A7'] = d return a" "import struct def createDict(data): B1addr = struct.unpack('>H', data[0:2])[0] - 5 B2 = ''.join([i[0].decode('ascii') for i in struct.iter_unpack('>c', data[2:8])]) E1 = struct.unpack('>B', data[8:9])[0] E2 = struct.unpack('>f', data[9:13])[0] D2size = struct.unpack('>I', data[13:17])[0] D2addr = struct.unpack('>I', data[17:21])[0] - 5 D2 = [] Flen = struct.calcsize('>bH') for i in range(D2size): F1 = struct.unpack('>b', data[D2addr + i * Flen:D2addr + i * Flen + 1])[0] F2 = struct.unpack('>H', data[D2addr + i * Flen + 1:D2addr + i * Flen + 3])[0] F = {'F1': F1, 'F2': F2} D2.append(F) D3 = struct.unpack('>b', data[21:22])[0] D4 = struct.unpack('>I', data[22:26])[0] D5 = struct.unpack('>d', data[26:34])[0] D6addr = struct.unpack('>I', data[34:38])[0] - 5 C1 = struct.unpack('>d', data[B1addr:B1addr + 8])[0] C2 = struct.unpack('>Q', data[B1addr + 8:B1addr + 16])[0] G1size = struct.unpack('>H', data[D6addr:D6addr + 2])[0] G1addr = struct.unpack('>H', data[D6addr + 2:D6addr + 4])[0] - 5 G1 = [i[0] for i in struct.iter_unpack('>I', data[G1addr:G1addr + 4 * G1size])] G2 = struct.unpack('>Q', data[D6addr + 4:D6addr + 12])[0] G3 = struct.unpack('>f', data[D6addr + 12:D6addr + 16])[0] G4 = struct.unpack('>b', data[D6addr + 16:D6addr + 17])[0] G5 = struct.unpack('>I', data[D6addr + 17:D6addr + 21])[0] G6 = struct.unpack('>Q', data[D6addr + 21:D6addr + 29])[0] G7 = [i[0] for i in struct.iter_unpack('>I', data[D6addr + 29:D6addr + 41])] G8size = struct.unpack('>H', data[D6addr + 41:D6addr + 43])[0] G8addr = struct.unpack('>I', data[D6addr + 43:D6addr + 47])[0] - 5 G8 = [i[0] for i in struct.iter_unpack('>B', data[G8addr:G8addr + G8size])] D6 = {'G1': G1, 'G2': G2, 'G3': G3, 'G4': G4, 'G5': G5, 'G6': G6, 'G7': G7, 'G8': G8} D1 = {'E1': E1, 'E2': E2} B1 = {'C1': C1, 'C2': C2} A1 = {'B1': B1, 'B2': B2} A2 = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4, 'D5': D5, 'D6': D6} return {'A1': A1, 'A2': A2} def main(data): data = data[5:] return createDict(data)" "import struct def structE(data, pointer): e1 = list(struct.unpack('<7h', data[pointer:pointer + 14])) (e2,) = struct.unpack('2H', data[address:address + 4]): c1 = list(struct.unpack('>2f', data[c_address:c_address + 8])) c2 = struct.unpack('>h', data[c_address + 8:c_address + 10])[0] c3 = struct.unpack('>q', data[c_address + 10:c_address + 18])[0] result.append({'C1': c1, 'C2': c2, 'C3': c3}) return result def create_e_structure(data, address): result = {} e_size = struct.unpack('>I', data[address:address + 4])[0] e_address = struct.unpack('>I', data[address + 4:address + 8])[0] result['E1'] = list(struct.unpack('>' + str(e_size) + 'h', data[e_address:e_address + e_size * 2])) e_size = struct.unpack('>H', data[address + 8:address + 10])[0] e_address = struct.unpack('>I', data[address + 10:address + 14])[0] result['E2'] = list(struct.unpack('>' + str(e_size) + 'B', data[e_address:e_address + e_size])) return result def main(data): a1 = struct.unpack('>I', data[3:7])[0] a2 = struct.unpack('>I', data[7:11])[0] b1 = struct.unpack('>h', data[a1:a1 + 2])[0] b2 = create_c_structures(data, a1 + 2) b3 = struct.unpack('>q', data[a1 + 6:a1 + 14])[0] b4 = struct.unpack('>d', data[a1 + 14:a1 + 22])[0] d1 = struct.unpack('>H', data[a2:a2 + 2])[0] d2 = struct.unpack('>b', data[a2 + 2:a2 + 3])[0] d3 = create_e_structure(data, a2 + 3) d4 = struct.unpack('>b', data[a2 + 17:a2 + 18])[0] out_dict = {'A1': {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4}, 'A2': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}} return out_dict" "from struct import * FMT = dict(double='d', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(5): (val, offs) = parse_b(buf, offs) a1.append(val) (a2, offs) = parse_c(buf, offs) a3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint32') a3.append(val) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse_d(buf, offs) (c4, offs) = parse(buf, offs, 'double') (c5, offs) = parse(buf, offs, 'int16') (c6, offs) = parse(buf, offs, 'uint32') (c7, offs) = parse(buf, offs, 'int8') (c8_offs, offs) = parse(buf, offs, 'uint16') (c8, c8_offs) = parse_e(buf, c8_offs) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'int16') (d3_size, offs) = parse(buf, offs, 'uint16') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'float') d3.append(val) return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint8') (e2, offs) = parse(buf, offs, 'uint8') (e3, offs) = parse(buf, offs, 'uint8') e4 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'double') e4.append(val) (e5, offs) = parse(buf, offs, 'int64') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(data): A = struct.unpack_from('d', offset) (A2_a, offset) = parseMin(buf, '>I', offset) (A2, A2_a) = parseB(buf, A2_a) A3 = [] for i in range(6): (d, offset) = parseD(buf, offset) A3.append(d) (A4, offset) = parseMin(buf, '>d', offset) (A5, offset) = parseMin(buf, '>Q', offset) (A6, offset) = parseMin(buf, '>I', offset) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), offset) def parseB(buf, offset): (B1, offset) = parseMin(buf, '>H', offset) (B2, offset) = parseMin(buf, '>b', offset) (B3, offset) = parseMin(buf, '>I', offset) (B4, offset) = parseMin(buf, '>d', offset) (B5, offset) = parseMin(buf, '>q', offset) (B6, offset) = parseC(buf, offset) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), offset) def parseC(buf, offset): (C1_s, offset) = parseMin(buf, '>H', offset) (C1_a, offset) = parseMin(buf, '>I', offset) C1 = [] for i in range(C1_s): (c, C1_a) = parseMin(buf, '>c', C1_a) C1.append(c.decode()) (C2, offset) = parseMin(buf, '>b', offset) (C3, offset) = parseMin(buf, '>b', offset) (C4, offset) = parseMin(buf, '>H', offset) (C5, offset) = parseMin(buf, '>q', offset) C6 = [] for i in range(4): (i16, offset) = parseMin(buf, '>h', offset) C6.append(i16) return (dict(C1=''.join(C1), C2=C2, C3=C3, C4=C4, C5=C5, C6=C6), offset) def parseD(buf, offset): (D1, offset) = parseMin(buf, '>b', offset) (D2, offset) = parseMin(buf, '>b', offset) (D3_s, offset) = parseMin(buf, '>H', offset) (D3_a, offset) = parseMin(buf, '>H', offset) D3 = [] for i in range(D3_s): (i8, D3_a) = parseMin(buf, '>b', D3_a) D3.append(i8) return (dict(D1=D1, D2=D2, D3=D3), offset) def main(buf): return parseA(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'int32') a1.append(val) (a2, offs) = parse(buf, offs, 'double') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) (a4, offs) = parse_c(buf, offs) (a5, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint64') (b2, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'int8') (c3, offs) = parse_d(buf, offs) c4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint32') c4.append(val) (c5, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint64') (d3_size, offs) = parse(buf, offs, 'uint16') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'int16') d3.append(val) (d4, offs) = parse(buf, offs, 'int64') (d5, offs) = parse(buf, offs, 'double') (d6, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 68: break a = {f'A{i}': None for i in range(1, 7)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 8)} d = {f'D{i}': None for i in range(1, 3)} temp = unpack('h') (A['A2'], iterator) = getNext(data, iterator, 8, '>Q') (A['A3'], iterator) = getNext(data, iterator, 4, '>f') (A['A4'], iterator) = getNext(data, iterator, 2, '>H') (A['A5'], iterator) = getNext(data, iterator, 1 * 2, '>2s') A['A5'] = A['A5'].decode('ascii') A['A6'] = [] for i in range(2): (b, iterator) = getB(data, iterator) A['A6'].append(b) (A['A7'], iterator) = getNext(data, iterator, 1, '>b') (A['A8'], iterator) = getNextArr(data, iterator, 2 * 5, '>5H') return A def getB(data, iterator): B = {} (temp, iterator) = getNext(data, iterator, 2, '>H') B['B1'] = getC(data, temp)[0] (B['B2'], iterator) = getD(data, iterator) return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 4, '>I') (lenght, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') C['C2'] = getNextArr(data, temp, lenght * 2, f'>{lenght}h')[0] return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNextArr(data, iterator, 8 * 3, '>3q') (D['D2'], iterator) = getNext(data, iterator, 1, '>B') (D['D3'], iterator) = getNext(data, iterator, 8, '>d') return (D, iterator) def main(data): return getA(data, 5)" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [a2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [a3] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 return {'A1': a1, 'A2': struct_b(a2), 'A3': a3} def struct_b(offset: int) -> dict: [b1] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 b2 = struct_c(offset) offset += 6 [b3] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 le = 16 b4 = [struct_d(offset + i * le) for i in range(2)] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 c2 = list(struct.unpack('< ' + str(length1) + 'c', binary[link_str:link_str + length1])) c2 = [i.decode('UTF-8') for i in c2] return {'C1': c1, 'C2': ''.join(c2)} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [length1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 d2 = list(struct.unpack('< ' + str(length1) + 'i', binary[link_str:link_str + length1 * 4])) [d3] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 d4 = list(struct.unpack('< 3h', binary[offset:offset + 3 * 2])) offset += 6 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} return struct_a(3)" "import struct def structA(data, pointer): (f1,) = struct.unpack(' dict: def A(offset: int) -> dict: a1 = B(offset) offset += 2 + 1 + 1 + 4 + 4 + 8 [a2] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [a3] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [length] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 le = 8 a4 = [F(link + i * le) for i in range(length)] return {'A1': a1, 'A2': a2, 'A3': D(a3), 'A4': a4} def B(offset: int) -> dict: [b1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [b2] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [b3] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 b4 = C(offset) offset += 4 + 4 + 8 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def C(offset: int) -> dict: [length] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 c1 = list(struct.unpack('< ' + str(length) + 'c', binary[link:link + length * 1])) c1 = [i.decode('UTF-8') for i in c1] [c2] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 return {'C1': ''.join(c1), 'C2': c2} def D(offset: int) -> dict: [d1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d2] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [d3] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 return {'D1': E(d1), 'D2': d2, 'D3': d3} def E(offset: int) -> dict: [e1] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [e2] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 e3 = list(struct.unpack('< 7i', binary[offset:offset + 7 * 4])) offset += 7 * 4 [e4] = struct.unpack('< i', binary[offset:offset + 4]) offset += 4 [e5] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [e6] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6} def F(offset: int) -> dict: [f1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [length] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [link] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 f2 = list(struct.unpack('< ' + str(length) + 'H', binary[link:link + length * 2])) return {'F1': f1, 'F2': f2} return A(5)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(3): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) offs += calcsize('>H') * 2 (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'char') a2.append(val.decode()) (a3, offs) = parse(buf, offs, 'int16') (a4, offs) = parse_c(buf, offs) return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'double') (b3, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2_offs, offs) = parse(buf, offs, 'uint32') (c2, c2_offs) = parse_d(buf, c2_offs) c3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int8') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'uint8') d3 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint8') d3.append(val) d4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint64') d4.append(val) (d5, offs) = parse(buf, offs, 'uint64') (d6, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(x): A1_len = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2_size, offs) = parse(buf, offs, 'uint16') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse_b(buf, a2_offs) a2.append(val) (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse_c(buf, offs) (a5, offs) = parse(buf, offs, 'double') (a6, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode()) (c3, offs) = parse(buf, offs, 'uint64') (c4, offs) = parse(buf, offs, 'uint8') c5 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint64') c5.append(val) (c6_offs, offs) = parse(buf, offs, 'uint32') (c6, c6_offs) = parse_d(buf, c6_offs) (c7, offs) = parse(buf, offs, 'int16') (c8, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint64') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse(buf, offs, 'int16') (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse(buf, offs, 'int64') (a7, offs) = parse_b(buf, offs) (a8, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'int32') (b4, offs) = parse_c(buf, offs) (b5, offs) = parse_f(buf, offs) (b6, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): c1 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) c1.append(val) (c2_offs, offs) = parse(buf, offs, 'uint32') (c2, c2_offs) = parse_e(buf, c2_offs) c3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): e1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int64') e1.append(val) (e2_size, offs) = parse(buf, offs, 'uint16') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int64') e2.append(val) (e3, offs) = parse(buf, offs, 'int64') (e4, offs) = parse(buf, offs, 'uint64') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int64') (f2, offs) = parse(buf, offs, 'int8') return (dict(F1=f1, F2=f2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(x): offset = 3 ans = A(x, offset) return ans def A(x, offset): ans = {'A1': [], 'A2': None, 'A3': None, 'A4': []} size = 97 buffer = x[offset:offset + size] obj = struct.unpack('d') A['A3'] = [] for i in range(2): (a, iterator) = getC(data, iterator) A['A3'].append(a) (A['A4'], iterator) = getNext(data, iterator, 4, '>i') (A['A5'], iterator) = getD(data, iterator) (A['A6'], iterator) = getNext(data, iterator, 4, '>I') return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 1, '>b') (B['B2'], iterator) = getNext(data, iterator, 1 * 5, '>5s') B['B2'] = B['B2'].decode('ascii') (B['B3'], iterator) = getNext(data, iterator, 4, '>f') (B['B4'], iterator) = getNext(data, iterator, 1 * 3, '>3s') B['B4'] = B['B4'].decode('ascii') (B['B5'], iterator) = getNext(data, iterator, 2, '>H') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 8, '>q') (C['C2'], iterator) = getNext(data, iterator, 4, '>f') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 4, '>f') (D['D2'], iterator) = getNextArr(data, iterator, 8 * 7, '>7d') (D['D3'], iterator) = getNext(data, iterator, 1, '>b') (D['D4'], iterator) = getNext(data, iterator, 8, '>d') (D['D5'], iterator) = getNext(data, iterator, 4, '>I') (D['D6'], iterator) = getNext(data, iterator, 8, '>d') return (D, iterator) def main(data): return getA(data, 3)" "import struct def main(x): f = dict() b = dict() pos1 = struct.unpack('{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_d(data, offset)) offset = offset + 9 return result def parse_d(data, offset): result = dict() result['D1'] = un('>B', data[offset:offset + 1])[0] result['D2'] = un('>q', data[offset + 1:offset + 9])[0] return result def parse_c(data, offset): result = dict() result['C1'] = un('>H', data[offset:offset + 2])[0] result['C2'] = un('>Q', data[offset + 2:offset + 10])[0] result['C3'] = un('>f', data[offset + 10:offset + 14])[0] c4_addr = parse_array(data, offset + 14, 'H', 3) result['C4'] = [parse_d(data, x) for x in c4_addr] result['C5'] = ''.join((x.decode('ascii') for x in parse_array(data, offset + 20, 'c', 2))) result['C6'] = parse_array(data, offset + 22, 'I', 2) result['C7'] = un('>d', data[offset + 30:offset + 38])[0] (c8_size, c8_addr) = un('>HI', data[offset + 38:offset + 44]) result['C8'] = parse_array(data, c8_addr, 'd', c8_size) return result def parse_b(data, offset): result = dict() result['B1'] = un('>H', data[offset:offset + 2])[0] result['B2'] = un('>b', data[offset + 2:offset + 3])[0] result['B3'] = un('>q', data[offset + 3:offset + 11])[0] return result def parse_a(data, offset): result = dict() result['A1'] = parse_b(data, offset) result['A2'] = parse_c(data, offset + 11) result['A3'] = un('>d', data[offset + 55:offset + 63])[0] result['A4'] = un('>b', data[offset + 63:offset + 64])[0] return result def main(data): return parse_a(data, 5)" "import struct def main(b): b = b[3:] A = {} B = {} C = [] D = {} E = {} buff = struct.unpack('>2L', b[:8]) A['A1'] = buff[0] A['A2'] = buff[1] buff = struct.unpack('>2H', b[8:12]) sizeCh = buff[0] addrCh = buff[1] - 3 tmp = [] for i in range(sizeCh): buff = struct.unpack('>s', b[addrCh:addrCh + 1]) tmp.append(buff[0].decode()) addrCh += 1 B['B1'] = ''.join(tmp) t = 12 for i in range(3): buff = struct.unpack('>hQb', b[t:t + 11]) C.append({'C1': buff[0], 'C2': buff[1], 'C3': buff[2]}) t += 11 B['B2'] = C buff = struct.unpack('>q', b[t:t + 8]) t += 8 B['B3'] = buff[0] buff = struct.unpack('>LlHQqfb', b[t:t + 31]) t += 31 D['D1'] = buff[0] D['D2'] = buff[1] D['D3'] = buff[2] D['D4'] = buff[3] D['D5'] = buff[4] D['D6'] = buff[5] D['D7'] = buff[6] B['B4'] = D buff = struct.unpack('>2L', b[t:t + 8]) t += 8 sizeArr = buff[0] addrArr = buff[1] - 3 tmp = [] for i in range(sizeArr): buff = struct.unpack('>H', b[addrArr:addrArr + 2]) tmp.append(buff[0]) addrArr += 2 B['B5'] = tmp tmp = [] for i in range(8): buff = struct.unpack('>b', b[t:t + 1]) tmp.append(buff[0]) t += 1 B['B6'] = tmp A['A3'] = B buff = struct.unpack('>b', b[t:t + 1]) t += 1 A['A4'] = buff[0] buff = struct.unpack('>BHLH', b[t:t + 9]) t += 9 E['E1'] = buff[0] E['E2'] = buff[1] sizeArr = buff[2] addrArr = buff[3] - 3 tmp = [] for i in range(sizeArr): buff = struct.unpack('>l', b[addrArr:addrArr + 4]) tmp.append(buff[0]) addrArr += 4 E['E3'] = tmp buff = struct.unpack('>l', b[t:t + 4]) t += 4 E['E4'] = buff[0] A['A5'] = E buff = struct.unpack('>bq', b[t:t + 9]) A['A6'] = buff[0] A['A7'] = buff[1] return A" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() (d1_size, d1_addr) = struct.unpack('>HI', data[offset:offset + 6]) result['D1'] = parse_array(data, d1_addr, 'h', d1_size) result['D2'] = parse_array(data, offset + 6, 'i', 3) result['D3'] = struct.unpack('>I', data[offset + 18:offset + 18 + 4])[0] result['D4'] = struct.unpack('>b', data[offset + 22:offset + 22 + 1])[0] result['D5'] = struct.unpack('>i', data[offset + 23:offset + 23 + 4])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>q', data[offset:offset + 8])[0] result['C2'] = ''.join((c.decode() for c in parse_array(data, offset + 8, 'c', 8))) result['C3'] = struct.unpack('>Q', data[offset + 16:offset + 16 + 8])[0] result['C4'] = struct.unpack('>f', data[offset + 24:offset + 24 + 4])[0] result['C5'] = struct.unpack('>B', data[offset + 28:offset + 28 + 1])[0] c6_addr = struct.unpack('>I', data[offset + 29:offset + 29 + 4])[0] result['C6'] = parse_d(data, c6_addr) return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>f', data[offset:offset + 4])[0] result['B2'] = struct.unpack('>d', data[offset + 4:offset + 4 + 8])[0] result['B3'] = struct.unpack('>h', data[offset + 12:offset + 12 + 2])[0] return result def parse_a(data, offset): result = dict() a1_addrs = parse_array(data, offset, 'I', 5) result['A1'] = [parse_b(data, addr) for addr in a1_addrs] result['A2'] = struct.unpack('>q', data[offset + 20:offset + 20 + 8])[0] result['A3'] = struct.unpack('>i', data[offset + 28:offset + 28 + 4])[0] a4_addr = struct.unpack('>H', data[offset + 32:offset + 32 + 2])[0] result['A4'] = parse_c(data, a4_addr) result['A5'] = parse_array(data, offset + 34, 'i', 3) result['A6'] = struct.unpack('>q', data[offset + 34 + 12:offset + 46 + 8])[0] return result def main(data): return parse_a(data, 5)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 88: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 6)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 7)} temp = unpack('>fLHlllhHHH', file[a_adr:a_adr + 30]) (a['A1'], b_str_size, b_str_adr, a['A3'], a['A4'], a['A5'], a['A6'], c_adr, int32_size, int32_adr) = temp temp = unpack(f'>{int32_size}l', file[int32_adr:int32_adr + int32_size * 4]) a['A8'] = list(temp) temp = unpack('>lld7BL', file[c_adr:c_adr + 27]) (c['C1'], c['C2'], c['C3'], *uint8_arr, d_adr) = temp c['C4'] = list(uint8_arr) temp = unpack('>dLLbLLB', file[d_adr:d_adr + 26]) (d['D1'], float_size, float_adr, d['D3'], d['D4'], d['D5'], d['D6']) = temp temp = unpack(f'>{float_size}f', file[float_adr:float_adr + float_size * 4]) d['D2'] = list(temp) b_adrs = unpack(f'>{b_str_size}L', file[b_str_adr:b_str_adr + b_str_size * 4]) a['A2'] = [] for b_adr in b_adrs: temp = unpack(f'>HLhQdb', file[b_adr:b_adr + 25]) (ch_arr_size, ch_arr_adr, b['B2'], b['B3'], b['B4'], b['B5']) = temp ch_arr = unpack(f'>{ch_arr_size}c', file[ch_arr_adr:ch_arr_adr + ch_arr_size]) b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A2'].append(b.copy()) a['A7'] = c c['C5'] = d return a" "from struct import unpack_from, calcsize FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', fl='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint16') (e1_offs, offs) = parse(buf, offs, 'uint16') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'fl') e1.append(val) (e2, offs) = parse(buf, offs, 'fl') return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'double') (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'uint16') d3.append(val) (d4, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint16') (c2, offs) = parse(buf, offs, 'uint64') (c3, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'uint8') b3 = [] for _ in range(5): (b3_offs, offs) = parse(buf, offs, 'uint32') (val, b3_offs) = parse_c(buf, b3_offs) b3.append(val) (b4_offs, offs) = parse(buf, offs, 'uint32') (b4, b4_offs) = parse_d(buf, b4_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2_offs, offs) = parse(buf, offs, 'uint32') (a2, a2_offs) = parse_b(buf, a2_offs) (a3, offs) = parse_e(buf, offs) a4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'double') a4.append(val) (a5, offs) = parse(buf, offs, 'int8') (a6, offs) = parse(buf, offs, 'uint64') return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(binary: bytes) -> dict: def struct_a(offset: int) -> dict: [a1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 a2 = struct_c(offset) offset += 119 [a3] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [a4] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 return {'A1': struct_b(a1), 'A2': a2, 'A3': a3, 'A4': a4} def struct_b(offset: int) -> dict: b1 = list(struct.unpack('> 6c', binary[offset:offset + 6 * 1])) offset += 6 * 1 b1 = [i.decode('UTF-8') for i in b1] [b2] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 [b3] = struct.unpack('< d', binary[offset:offset + 8]) offset += 8 [b4] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 return {'B1': ''.join(b1), 'B2': b2, 'B3': b3, 'B4': b4} def struct_c(offset: int) -> dict: [c1] = struct.unpack('< f', binary[offset:offset + 4]) offset += 4 [c2] = struct.unpack('< h', binary[offset:offset + 2]) offset += 2 le = 2 + 1 + 1 + 8 + 1 + 4 + 2 * 1 + 2 c3 = [struct_d(offset + i * le) for i in range(5)] offset += (2 + 1 + 1 + 8 + 1 + 4 + 2 * 1 + 2) * 5 [c4] = struct.unpack('< Q', binary[offset:offset + 8]) offset += 8 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(offset: int) -> dict: [d1] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 [d2] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [d3] = struct.unpack('< B', binary[offset:offset + 1]) offset += 1 [d4] = struct.unpack('< q', binary[offset:offset + 8]) offset += 8 [d5] = struct.unpack('< b', binary[offset:offset + 1]) offset += 1 [length1] = struct.unpack('< I', binary[offset:offset + 4]) offset += 4 [link_str] = struct.unpack('< H', binary[offset:offset + 2]) offset += 2 d6 = list(struct.unpack('< ' + str(length1) + 'h', binary[link_str:link_str + length1 * 2])) d7 = list(struct.unpack('> 2B', binary[offset:offset + 2 * 1])) offset += 2 * 1 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} return struct_a(5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A2'] = getB(data, temp)[0] (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A3'] = getNext(data, temp, length, f'>{length}s')[0] A['A3'] = A['A3'].decode('ascii') (A['A4'], iterator) = getNext(data, iterator, 4, '>I') A['A5'] = [] for i in range(6): (a, iterator) = getC(data, iterator) A['A5'].append(a) (A['A6'], iterator) = getNext(data, iterator, 4, '>i') (A['A7'], iterator) = getD(data, iterator) return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 8, '>q') (B['B2'], iterator) = getNext(data, iterator, 1, '>b') (B['B3'], iterator) = getNext(data, iterator, 2, '>H') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') B['B4'] = getNextArr(data, temp, length * 4, f'>{length}I')[0] (B['B5'], iterator) = getNext(data, iterator, 4, '>i') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 2, '>H') (C['C2'], iterator) = getNext(data, iterator, 1, 'B') (D['D2'], iterator) = getNext(data, iterator, 4, '>i') D['D3'] = [] for i in range(3): (d, iterator) = getNext(data, iterator, 4, '>I') D['D3'].append(d) return (D, iterator) def main(data): return getA(data, 4)" "from struct import * FMT = dict(char='h', s, base_address)[0]) base_address += 2 d.setdefault('A2', struct.unpack_from('>I', s, base_address)[0]) base_address += 4 d.setdefault('A3', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 new_address_b = struct.unpack_from('>I', s, base_address)[0] base_address += 4 a4.setdefault('B1', struct.unpack_from('>d', s, new_address_b)[0]) new_address_b += 8 new_address_c = struct.unpack_from('>H', s, new_address_b)[0] new_address_b += 2 b2.setdefault('C1', struct.unpack_from('>d', s, new_address_c)[0]) new_address_c += 8 c2 = '' for i in range(5): c2 += str(struct.unpack_from('>c', s, new_address_c)[0])[2] new_address_c += 1 b2.setdefault('C2', c2) b2.setdefault('C3', struct.unpack_from('>B', s, new_address_c)[0]) new_address_c += 1 a4.setdefault('B2', b2) a4.setdefault('B3', struct.unpack_from('>H', s, new_address_b)[0]) new_address_b += 2 for i in range(3): d123 = {} new_address_d = struct.unpack_from('>H', s, new_address_b)[0] new_address_b += 2 d1 = [] d1.append(struct.unpack_from('>q', s, new_address_d)[0]) new_address_d += 8 d1.append(struct.unpack_from('>q', s, new_address_d)[0]) new_address_d += 8 d123.setdefault('D1', d1) new_size = struct.unpack_from('>I', s, new_address_d)[0] new_address_d += 4 new_address_d_2 = struct.unpack_from('>H', s, new_address_d)[0] new_address_d += 2 d2 = [] for j in range(new_size): d2.append(struct.unpack_from('>H', s, new_address_d_2)[0]) new_address_d_2 += 2 d123.setdefault('D2', d2) d123.setdefault('D3', struct.unpack_from('>q', s, new_address_d)[0]) new_address_d += 8 b4.append(d123) a4.setdefault('B4', b4) a4.setdefault('B5', struct.unpack_from('>B', s, new_address_b)[0]) new_address_b += 1 d.setdefault('A4', a4) d.setdefault('A5', struct.unpack_from('>Q', s, base_address)[0]) base_address += 8 d.setdefault('A6', struct.unpack_from('>I', s, base_address)[0]) base_address += 4 return d" "import struct def structA(data, pointer): (a1,) = struct.unpack(' dict: def struct_a(index: int) -> dict: [a1] = struct.unpack('> H', binary[index:index + 2]) index += 2 (s, add) = struct.unpack('> I H', binary[index:index + 6]) a2 = list(struct.unpack('>' + str(s) + 'B', binary[add:add + s])) index += 6 return {'A1': struct_b(a1), 'A2': a2} def struct_b(index: int) -> dict: [b1] = struct.unpack('> I', binary[index:index + 4]) index += 4 b2 = struct_c(index) index += 28 [b3] = struct.unpack('> H', binary[index:index + 2]) index += 2 [b4] = struct.unpack('> B', binary[index:index + 1]) index += 1 [b5] = struct.unpack('> h', binary[index:index + 2]) index += 2 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def struct_c(index: int) -> dict: [c1] = struct.unpack('> Q', binary[index:index + 8]) index += 8 [c2] = struct.unpack('> d', binary[index:index + 8]) index += 8 (s, offset) = struct.unpack('> I H', binary[index:index + 6]) c3 = [struct_d(offset + i * 8) for i in range(s)] index += 6 (s2, add) = struct.unpack('> I H', binary[index:index + 6]) c4 = list(struct.unpack('>' + str(s2) + 'b', binary[add:add + s2])) index += 6 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(index: int) -> dict: (s, add) = struct.unpack('> I H', binary[index:index + 6]) d1 = list(struct.unpack('>' + str(s) + 'I', binary[add:add + 4 * s])) index += 6 [d2] = struct.unpack('> h', binary[index:index + 2]) index += 2 return {'D1': d1, 'D2': d2} return struct_a(5)" "import struct as st def main(x): return a(x, 4) def a(x, start): return {'A1': [b(x, address_b(x, start)), b(x, address_b(x, start + 4)), b(x, address_b(x, start + 8)), b(x, address_b(x, start + 12)), b(x, address_b(x, start + 16))], 'A2': c(x, address_c(x, start + 20)), 'A3': st.unpack('< f', x[start + 24:start + 28])[0], 'A4': d(x, address_d(x, start + 28)), 'A5': st.unpack('< q', x[start + 30:start + 38])[0]} def address_d(x, start): return st.unpack('< H', x[start:start + 2])[0] def address_c(x, start): return st.unpack('< I', x[start:start + 4])[0] def address_b(x, start): return st.unpack('< I', x[start:start + 4])[0] def b(x, start): return {'B1': st.unpack('< I', x[start:start + 4])[0], 'B2': str(st.unpack('< c', x[start + 4:start + 5])[0])[2] + str(st.unpack('< c', x[start + 5:start + 6])[0])[2] + str(st.unpack('< c', x[start + 6:start + 7])[0])[2] + str(st.unpack('< c', x[start + 7:start + 8])[0])[2] + str(st.unpack('< c', x[start + 8:start + 9])[0])[2] + str(st.unpack('< c', x[start + 9:start + 10])[0])[2] + str(st.unpack('< c', x[start + 10:start + 11])[0])[2] + str(st.unpack('< c', x[start + 11:start + 12])[0])[2]} def c(x, start): return {'C1': uint16_uint32_double(x, start), 'C2': st.unpack('< h', x[start + 6:start + 8])[0], 'C3': st.unpack('< i', x[start + 8:start + 12])[0], 'C4': st.unpack('< Q', x[start + 12:start + 20])[0], 'C5': st.unpack('< Q', x[start + 20:start + 28])[0], 'C6': st.unpack('< i', x[start + 28:start + 32])[0]} def uint16_uint32_double(x, start): size = st.unpack('< H', x[start:start + 2])[0] address = st.unpack('< I', x[start + 2:start + 6])[0] arr = st.unpack('< ' + 'd' * size, x[address:address + 8 * size]) return list(arr) def d(x, start): return {'D1': [st.unpack('< d', x[start:start + 8])[0], st.unpack('< d', x[start + 8:start + 16])[0]], 'D2': st.unpack('< h', x[start + 16:start + 18])[0], 'D3': st.unpack('< f', x[start + 18:start + 22])[0]} def main(x): return a(x, 4)" "import struct def main(data): return parse_a(data, 5)[0] def parse_a(data, offset): result = {} addr = struct.unpack('8c', data[offset:offset + struct.calcsize('>8c')])).decode('ascii') offset += struct.calcsize('>8c') arr = [] for i in range(3): arr.append(parse_c(data, struct.unpack('b') A['A2'] = [] for i in range(2): (a, iterator) = getB(data, iterator) A['A2'].append(a) A['A3'] = [] for i in range(6): (w, iterator) = getNext(data, iterator, 2, '>H') A['A3'].append(w) A['A4'] = [] for i in range(5): (e, iterator) = getNext(data, iterator, 1, '>b') A['A4'].append(e) (A['A5'], iterator) = getNext(data, iterator, 1, '>b') (A['A6'], iterator) = getNext(data, iterator, 4, '>i') (A['A7'], iterator) = getNext(data, iterator, 8, '>d') (A['A8'], iterator) = getNext(data, iterator, 4, '>f') return A def getB(data, iterator): B = {} (B['B1'], iterator) = getC(data, iterator) (B['B2'], iterator) = getNext(data, iterator, 8, '>q') return (B, iterator) def getC(data, iterator): C = {} C['C1'] = [] for i in range(7): (c, iterator) = getNext(data, iterator, 1, '>B') C['C1'].append(c) (C['C2'], iterator) = getNext(data, iterator, 1, '>b') (C['C3'], iterator) = getD(data, iterator) (C['C4'], iterator) = getNext(data, iterator, 4, '>I') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 8, '>d') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') D['D2'] = getNextArr(data, temp, length, f'>{length}b')[0] (D['D3'], iterator) = getNext(data, iterator, 8, '>q') (D['D4'], iterator) = getNext(data, iterator, 8, '>Q') return (D, iterator) def main(data): return getA(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '<' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'double') a2 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a2.append(val) (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse_d(buf, a3_offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'char') b2.append(val.decode('ascii')) (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b1_offs) = parse_c(buf, b3_offs) return (dict(B1=b1, B2=''.join(b2), B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'int64') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'uint64') (d4, offs) = parse(buf, offs, 'int64') (d5, offs) = parse(buf, offs, 'uint8') (d6, offs) = parse(buf, offs, 'int8') (d7_size, offs) = parse(buf, offs, 'uint32') (d7_offs, offs) = parse(buf, offs, 'uint32') d7 = [] for _ in range(d7_size): (val, d7_offs) = parse(buf, d7_offs, 'double') d7.append(val) (d8, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(bs): A = struct.Struct('> d 2c I H f f') B = struct.Struct('> I HI') C = struct.Struct('> h h B I q HI') D = struct.Struct('> HI d q q') magic_bytes = 'ôPMHQ' a = A.unpack_from(bs, len(magic_bytes)) b = B.unpack_from(bs, a[3]) c_structs = [C.unpack_from(bs, b[-1] + i * C.size) for i in range(b[-2])] d = D.unpack_from(bs, a[4]) return {'A1': a[0], 'A2': b''.join(a[1:3]).decode(), 'A3': {'B1': b[0], 'B2': [{'C1': c[0], 'C2': c[1], 'C3': c[2], 'C4': c[3], 'C5': c[4], 'C6': list(struct.unpack_from(f'> {c[-2]}H', bs, c[-1]))} for c in c_structs]}, 'A4': {'D1': list(struct.unpack_from(f'> {d[0]}i', bs, d[1])), 'D2': d[2], 'D3': d[3], 'D4': d[4]}, 'A5': a[-2], 'A6': a[-1]}" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'double') (a3, offs) = parse(buf, offs, 'float') (a4_offs, offs) = parse(buf, offs, 'uint32') (a4, a4_offs) = parse_c(buf, a4_offs) (a5, offs) = parse(buf, offs, 'uint8') (a6, offs) = parse(buf, offs, 'uint16') a7 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint16') a7.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) c2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'char') c2.append(val.decode()) (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse(buf, offs, 'int64') (c5, offs) = parse_e(buf, offs) (c6, offs) = parse(buf, offs, 'uint16') (c7_size, offs) = parse(buf, offs, 'uint32') (c7_offs, offs) = parse(buf, offs, 'uint32') c7 = [] for _ in range(c7_size): (val, c7_offs) = parse(buf, c7_offs, 'int32') c7.append(val) return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') (e2, offs) = parse(buf, offs, 'int8') (e3, offs) = parse(buf, offs, 'uint64') return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(bytes): dict = {} dictB = {} dict['A1'] = dictB dictB['B1'] = struct.unpack_from('>f', bytes, 4)[0] dictB['B2'] = struct.unpack_from('>h', bytes, 8)[0] size_B3 = struct.unpack_from('>I', bytes, 10)[0] address_B3 = struct.unpack_from('>I', bytes, 14)[0] dictB['B3'] = [] for i in range(size_B3): dictC = {} dictB['B3'].append(dictC) dictC['C1'] = [] for j in range(2): dictC['C1'].append(struct.unpack_from('>f', bytes, address_B3 + 4 * j + 11 * i)[0]) dictC['C2'] = struct.unpack_from('>h', bytes, address_B3 + 8 + 11 * i)[0] dictC['C3'] = struct.unpack_from('>b', bytes, address_B3 + 10 + 11 * i)[0] dictB['B4'] = struct.unpack_from('>H', bytes, 18)[0] dictB['B5'] = [] for i in range(3): dictB['B5'].append(struct.unpack_from('>d', bytes, 20 + 8 * i)[0]) dictB['B6'] = struct.unpack_from('>b', bytes, 44)[0] dictB['B7'] = struct.unpack_from('>q', bytes, 45)[0] address_D = struct.unpack_from('>I', bytes, 53)[0] dictD = {} dict['A2'] = dictD dictD['D1'] = struct.unpack_from('>f', bytes, address_D)[0] dictD['D2'] = [] for i in range(8): dictD['D2'].append(struct.unpack_from('>h', bytes, address_D + 4 + 2 * i)[0]) dictD['D3'] = struct.unpack_from('>Q', bytes, address_D + 20)[0] dictD['D4'] = struct.unpack_from('>q', bytes, address_D + 28)[0] dict['A3'] = struct.unpack_from('>d', bytes, 57)[0] dict['A4'] = struct.unpack_from('>d', bytes, 65)[0] return dict" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 87: break a = {f'A{i}': None for i in range(1, 5)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 8)} d = {f'D{i}': None for i in range(1, 3)} e = {f'E{i}': None for i in range(1, 9)} f = {f'F{i}': None for i in range(1, 6)} temp = unpack('>lQqLLfLLfLf6HbHQHq', file[a_adr:a_adr + 85]) (a['A1'], a['A2'], c['C1']) = temp[0:3] c['C2'] = [] (int32_size, int32_adr, d['D2']) = temp[3:6] int32_arr = unpack(f'>{int32_size}l', file[int32_adr:int32_adr + int32_size * 4]) d['D1'] = list(int32_arr) c['C2'].append(d.copy()) (int32_size, int32_adr, d['D2']) = temp[6:9] int32_arr = unpack(f'>{int32_size}l', file[int32_adr:int32_adr + int32_size * 4]) d['D1'] = list(int32_arr) c['C2'].append(d.copy()) (e_adr, c['C4'], *uin16_arr, c['C6'], c['C7'], b['B2'], f_adr, a['A4']) = temp[9:] c['C5'] = list(uin16_arr) temp = unpack('>Ldfdf6bQh', file[e_adr:e_adr + 44]) (e['E1'], e['E2'], e['E3'], e['E4'], e['E5'], *int8_arr, e['E7'], e['E8']) = temp e['E6'] = list(int8_arr) temp = unpack('>bhqLHf', file[f_adr:f_adr + 21]) (f['F1'], f['F2'], f['F3'], uint16_size, uint16_adr, f['F5']) = temp temp = unpack(f'>{uint16_size}H', file[uint16_adr:uint16_adr + uint16_size * 2]) f['F4'] = list(temp) b['B1'] = c b['B3'] = f a['A3'] = b c['C3'] = e return a" "from struct import unpack as u from pprint import pprint as p int8_s = 1 char_s = 1 int16_s = 2 int32_s = 4 int64_s = 8 double_s = 8 float_s = 4 cur_offset = 5 def parse_A(data): global cur_offset a1 = u('> b', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s a2 = u('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s a3 = u('> h', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_b = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s a4 = parse_B(data, add_b) a5 = parse_C(data) a6 = [] for i in range(6): a6.append(parse_D(data)) a7 = parse_E(data) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def parse_B(data, add): b1 = u('> f', data[add:add + float_s])[0] add += float_s b2 = u('> B', data[add:add + int8_s])[0] add += int8_s b3 = u('> q', data[add:add + int64_s])[0] add += int64_s b4 = u('> h', data[add:add + int16_s])[0] add += int16_s b5 = u('> d', data[add:add + double_s])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_C(data): global cur_offset c1 = u('> h', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s c2 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s return {'C1': c1, 'C2': c2} def parse_D(data): global cur_offset size_d1 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s add_d1 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s d1 = [] for i in range(size_d1): d1.append(u('> H', data[add_d1:add_d1 + int16_s])[0]) add_d1 += int16_s d2 = u('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s d3 = [] for i in range(2): d3.append(u('> H', data[cur_offset:cur_offset + int16_s])[0]) cur_offset += int16_s return {'D1': d1, 'D2': d2, 'D3': d3} def parse_E(data): global cur_offset e1 = u('> f', data[cur_offset:cur_offset + float_s])[0] cur_offset += float_s e2 = u('> H', data[cur_offset:cur_offset + int16_s])[0] cur_offset += int16_s e3 = u('> f', data[cur_offset:cur_offset + float_s])[0] cur_offset += float_s e4 = [] for i in range(2): e4.append(u('> h', data[cur_offset:cur_offset + int16_s])[0]) cur_offset += int16_s e5 = u('> i', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s e6 = u('> I', data[cur_offset:cur_offset + int32_s])[0] cur_offset += int32_s e7 = u('> b', data[cur_offset:cur_offset + int8_s])[0] cur_offset += int8_s return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7} def main(x): return parse_A(x)" "import struct def main(bytes): dict = {} dictB = {} address_B = struct.unpack_from('I', bytes, 4)[0] dict['A1'] = dictB dictB['B1'] = struct.unpack_from('b', bytes, address_B)[0] dictB['B2'] = struct.unpack_from('q', bytes, address_B + 1)[0] dictC = {} dictB['B3'] = dictC dictC['C1'] = [] for i in range(4): address_D = struct.unpack_from('I', bytes, address_B + 9 + 4 * i)[0] dictD = {} dictC['C1'].append(dictD) dictD['D1'] = struct.unpack_from('b', bytes, address_D)[0] dictD['D2'] = struct.unpack_from('d', bytes, address_D + 1)[0] dictE = {} dictC['C2'] = dictE dictE['E1'] = struct.unpack_from('d', bytes, address_B + 25)[0] size_E2 = struct.unpack_from('I', bytes, address_B + 33)[0] address_E2 = struct.unpack_from('H', bytes, address_B + 37)[0] dictE['E2'] = [] for i in range(size_E2): dictE['E2'].append(struct.unpack_from('q', bytes, address_E2 + 8 * i)[0]) dictE['E3'] = struct.unpack_from('i', bytes, address_B + 39)[0] dictE['E4'] = struct.unpack_from('I', bytes, address_B + 43)[0] dictB['B4'] = [] for i in range(5): dictB['B4'].append(struct.unpack_from('I', bytes, address_B + 47 + 4 * i)[0]) dictB['B5'] = struct.unpack_from('d', bytes, address_B + 67)[0] dictB['B6'] = struct.unpack_from('h', bytes, address_B + 75)[0] dictB['B7'] = [] for i in range(5): dictB['B7'].append(struct.unpack_from('Q', bytes, address_B + 77 + 8 * i)[0]) dict['A2'] = struct.unpack_from('i', bytes, 8)[0] size_A3 = struct.unpack_from('I', bytes, 12)[0] address_A3 = struct.unpack_from('I', bytes, 16)[0] dict['A3'] = [] for i in range(size_A3): dict['A3'].append(struct.unpack_from('B', bytes, address_A3 + i)[0]) dict['A4'] = struct.unpack_from('H', bytes, 20)[0] return dict" "import struct def uint16uint16char(s, pointer): buf = '' size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('c' * size, s[add:add + 1 * size]) for el in a: buf += str(el)[2:3] return buf def uint16uint16int16(s, pointer): size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('h' * size, s[add:add + 2 * size]) return list(a) def uint16uint32int8(s, pointer): size = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('b' * size, s[add:add + 1 * size]) return list(a) def create_d_structure(s, pointer): a = [] for i in range(1, 9): a.append({'D1': struct.unpack('I', s[pointer:pointer + 4])[0], 'D2': struct.unpack('b', s[pointer + 4:pointer + 5])[0], 'D3': struct.unpack('h', s[pointer + 5:pointer + 7])[0]}) pointer += 7 return a def main(s): out_dict = {'A1': {'B1': struct.unpack('q', s[4:12])[0], 'B2': struct.unpack('i', s[12:16])[0], 'B3': struct.unpack('q', s[16:24])[0], 'B4': struct.unpack('b', s[24:25])[0]}, 'A2': {'C1': create_d_structure(s, 25), 'C2': struct.unpack('H', s[81:83])[0], 'C3': struct.unpack('f', s[83:87])[0], 'C4': uint16uint16char(s, 87), 'C5': list(struct.unpack('3H', s[91:97])), 'C6': {'E1': struct.unpack('I', s[97:101])[0], 'E2': struct.unpack('b', s[101:102])[0], 'E3': struct.unpack('H', s[102:104])[0], 'E4': struct.unpack('i', s[104:108])[0], 'E5': uint16uint16int16(s, 108), 'E6': struct.unpack('H', s[112:114])[0]}, 'C7': struct.unpack('h', s[114:116])[0], 'C8': uint16uint32int8(s, 116)}} return out_dict" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') b2 = [] for _ in range(2): (b2_offs, offs) = parse(buf, offs, 'uint16') (val2, b2_offs) = parse_c(buf, b2_offs) b2.append(val2) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'uint16') c1.append(val) (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse(buf, offs, 'int8') (c5_size, offs) = parse(buf, offs, 'uint32') (c5_offs, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'int8') c5.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'double') d4 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint64') d4.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int32') (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'uint32') (a4, offs) = parse_e(buf, offs) (a5, offs) = parse_f(buf, offs) (a6, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse(buf, offs, 'float') (b3, offs) = parse_c(buf, offs) (b4, offs) = parse(buf, offs, 'int8') (b5_size, offs) = parse(buf, offs, 'uint32') (b5_offs, offs) = parse(buf, offs, 'uint16') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse_d(buf, b5_offs) b5.append(val) (b6, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'int8') (c3, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint16') d2.append(val) return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2), offs) def parse_f(buf, offs): (f1_offs, offs) = parse(buf, offs, 'uint16') (f1, TT) = parse_g(buf, f1_offs) f2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint32') f2.append(val) (f3, offs) = parse(buf, offs, 'uint8') return (dict(F1=f1, F2=f2, F3=f3), offs) def parse_g(buf, offs): (g1, offs) = parse(buf, offs, 'double') g2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint8') g2.append(val) (g3, offs) = parse(buf, offs, 'int8') (g4, offs) = parse(buf, offs, 'int64') return (dict(G1=g1, G2=g2, G3=g3, G4=g4), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def uint16uint16uint64(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('>' + 'Q' * size, s[add:add + 8 * size]) return list(a) def create_b_structure(s, pointer): b3 = '' a = [] for i in range(1, 5): buff = struct.unpack('>2c', s[pointer + 12:pointer + 14]) for el in buff: b3 += str(el)[2:3] a.append({'B1': struct.unpack('>q', s[pointer:pointer + 8])[0], 'B2': struct.unpack('>f', s[pointer + 8:pointer + 12])[0], 'B3': b3}) b3 = '' pointer += 14 return a def main(s): c1 = struct.unpack('>H', s[68:70])[0] a6 = struct.unpack('>H', s[102:104])[0] out_dict = {'A1': struct.unpack('>b', s[3:4])[0], 'A2': struct.unpack('>Q', s[4:12])[0], 'A3': create_b_structure(s, 12), 'A4': {'C1': {'D1': struct.unpack('>d', s[c1:c1 + 8])[0], 'D2': struct.unpack('>h', s[c1 + 8:c1 + 10])[0], 'D3': struct.unpack('>d', s[c1 + 10:c1 + 18])[0], 'D4': struct.unpack('>I', s[c1 + 18:c1 + 22])[0]}, 'C2': uint16uint16uint64(s, 70), 'C3': list(struct.unpack('>4I', s[74:90])), 'C4': struct.unpack('>Q', s[90:98])[0]}, 'A5': struct.unpack('>f', s[98:102])[0], 'A6': {'E1': struct.unpack('>h', s[a6:a6 + 2])[0], 'E2': struct.unpack('>f', s[a6 + 2:a6 + 6])[0], 'E3': struct.unpack('>H', s[a6 + 6:a6 + 8])[0], 'E4': struct.unpack('>H', s[a6 + 8:a6 + 10])[0], 'E5': struct.unpack('>b', s[a6 + 10:a6 + 11])[0]}} return out_dict" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): sizeb1 = reader.read(Types.uint16) adressb1 = reader.read(Types.uint16) tempb1 = reader.copy(adressb1).readWithSize(Types.char, sizeb1) b1 = b''.join(tempb1).decode('ASCII') b2 = reader.read(Types.int16) b31 = readC(reader.copy(reader.read(Types.uint16))) b32 = readC(reader.copy(reader.read(Types.uint16))) b33 = readC(reader.copy(reader.read(Types.uint16))) b34 = readC(reader.copy(reader.read(Types.uint16))) b35 = readC(reader.copy(reader.read(Types.uint16))) b36 = readC(reader.copy(reader.read(Types.uint16))) b3 = [b31, b32, b33, b34, b35, b36] b4 = reader.read(Types.int8) b5 = reader.readWithSize(Types.uint32, 7) b6 = reader.read(Types.int32) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6) def readC(reader): c1 = reader.read(Types.int8) c2 = reader.read(Types.uint16) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.int64) d2 = reader.read(Types.int32) sized3 = reader.read(Types.uint32) adressd3 = reader.read(Types.uint32) d3 = reader.copy(offset=adressd3).readWithSize(Types.int8, sized3) d4 = reader.read(Types.float) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def readE(reader): e1 = reader.read(Types.int64) e2 = reader.read(Types.uint64) e3 = reader.read(Types.int32) e4 = reader.read(Types.float) e5 = reader.read(Types.double) e6 = reader.read(Types.uint16) return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.int32) a2 = readB(reader) a3 = reader.readWithSize(Types.int16, 2) a4 = reader.read(Types.int32) a5 = reader.read(Types.int16) a6 = readD(reader) a7 = readE(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('>B', data[pointer:pointer + 1])[0] d2 = list(struct.unpack('>3B', data[pointer + 1:pointer + 4])) (d3, d4, d5) = struct.unpack('>iHf', data[pointer + 4:pointer + 14]) d6 = list(struct.unpack('>8h', data[pointer + 14:pointer + 30])) d7 = struct.unpack('>f', data[pointer + 30:pointer + 34])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def parse_c(data, pointer): c1 = struct.unpack('>h', data[pointer:pointer + 2])[0] c2 = list(struct.unpack('>8b', data[pointer + 2:pointer + 10])) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = struct.unpack('>f', data[pointer:pointer + 4])[0] f2 = struct.unpack('>4I', data[pointer + 4:pointer + 20]) b2 = list() for i in range(4): b2.append(parse_c(data, f2[i])) b3 = struct.unpack('>d', data[pointer + 20:pointer + 28])[0] b4 = list(struct.unpack('>6I', data[pointer + 28:pointer + 52])) b5 = parse_d(data, pointer + 52) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_a(data, pointer): (a1, a2) = struct.unpack('>id', data[pointer:pointer + 12]) a3 = parse_b(data, pointer + 12) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 3)" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint16') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'double') e1.append(val) (e2, offs) = parse(buf, offs, 'int32') e3 = [] for _ in range(0, 2): (val, offs) = parse(buf, offs, 'uint32') e3.append(val) (e4, offs) = parse(buf, offs, 'int8') (e5_size, offs) = parse(buf, offs, 'uint16') (e5_offs, offs) = parse(buf, offs, 'uint32') e5 = [] for _ in range(e5_size): (val, e5_offs) = parse(buf, e5_offs, 'int8') e5.append(val) (e6, offs) = parse(buf, offs, 'uint16') (e7, offs) = parse(buf, offs, 'uint16') (e8, offs) = parse(buf, offs, 'int16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7, E8=e8), offs) def parse_d(buf, offs): d1 = [] for _ in range(0, 2): (val, offs) = parse(buf, offs, 'int64') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint32') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'uint8') d3.append(val) return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'char') b1.append(val.decode()) (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse_c(buf, b2_offs) b2.append(val) (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'int8') (b5_size, offs) = parse(buf, offs, 'uint32') (b5_offs, offs) = parse(buf, offs, 'uint32') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'int8') b5.append(val) (b6, offs) = parse(buf, offs, 'uint32') return (dict(B1=''.join(b1), B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint32') (val, d5_offs) = parse_b(buf, a3_offs) a3 = val (a4, offs) = parse_d(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(x): f = dict() f['A1'] = struct.unpack('>f', x[4:8])[0] f['A2'] = struct.unpack('>f', x[8:12])[0] f['A3'] = struct.unpack('>d', x[12:20])[0] b1 = struct.unpack('>f', x[20:24])[0] b2 = struct.unpack('>f', x[24:28])[0] b3 = struct.unpack('>h', x[28:30])[0] b4 = struct.unpack('>I', x[30:34])[0] f['A4'] = {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} f['A5'] = struct.unpack('>i', x[34:38])[0] c = dict() d1 = struct.unpack('>H', x[38:40])[0] pos1 = struct.unpack('>H', x[42:44])[0] d2 = [] for i in range(0, struct.unpack('>H', x[40:42])[0]): pos2 = struct.unpack('>I', x[pos1:pos1 + 4])[0] di = struct.unpack('>I', x[pos2:pos2 + 4])[0] dis = '>' + str(di) + 'b' pos3 = struct.unpack('>I', x[pos2 + 4:pos2 + 8])[0] e1 = list(struct.unpack(dis, x[pos3:pos3 + di])) e2 = struct.unpack('>i', x[pos2 + 8:pos2 + 12])[0] d = {'E1': e1, 'E2': e2} d2.append(d) pos1 += 4 d3 = struct.unpack('>d', x[44:52])[0] d4 = struct.unpack('>B', x[52:53])[0] d5 = struct.unpack('>q', x[53:61])[0] c['C1'] = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} c['C2'] = struct.unpack('>h', x[61:63])[0] c['C3'] = struct.unpack('>d', x[63:71])[0] c['C4'] = struct.unpack('>b', x[71:72])[0] c['C5'] = struct.unpack('>f', x[72:76])[0] pos1 = struct.unpack('>I', x[76:80])[0] f1 = struct.unpack('>i', x[pos1:pos1 + 4])[0] f2 = list(struct.unpack('>6I', x[pos1 + 4:pos1 + 28])) f3 = struct.unpack('>h', x[pos1 + 28:pos1 + 30])[0] c['C6'] = {'F1': f1, 'F2': f2, 'F3': f3} c['C7'] = struct.unpack('>i', x[80:84])[0] f['A6'] = c f['A7'] = list(struct.unpack('>3b', x[84:87])) f['A8'] = struct.unpack('>d', x[87:95])[0] return f" "import struct def uint16uint32uint8(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'B' * size, s[add:add + 1 * size]) return list(a) def uint16uint16char(s, pointer): buf = '' size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('>' + 'c' * size, s[add:add + 1 * size]) for el in a: buf += str(el)[2:3] return buf def uint16uint16_in_B_structure(s, pointer): result = [] size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>H', s[pointer + 2:pointer + 4])[0] for i in range(0, size): result.append({'B1': struct.unpack('>I', s[add:add + 4])[0], 'B2': struct.unpack('>H', s[add + 4:add + 6])[0]}) add += 6 return result def main(s): a7 = struct.unpack('>H', s[39:41])[0] c6 = struct.unpack('>I', s[a7 + 66:a7 + 70])[0] out_dict = {'A1': uint16uint16_in_B_structure(s, 5), 'A2': struct.unpack('>d', s[9:17])[0], 'A3': struct.unpack('>q', s[17:25])[0], 'A4': uint16uint16char(s, 25), 'A5': struct.unpack('>Q', s[29:37])[0], 'A6': struct.unpack('>h', s[37:39])[0], 'A7': {'C1': uint16uint32uint8(s, a7), 'C2': struct.unpack('>Q', s[a7 + 6:a7 + 14])[0], 'C3': struct.unpack('>I', s[a7 + 14:a7 + 18])[0], 'C4': list(struct.unpack('>5Q', s[a7 + 18:a7 + 58])), 'C5': struct.unpack('>Q', s[a7 + 58:a7 + 66])[0], 'C6': {'D1': struct.unpack('>H', s[c6:c6 + 2])[0], 'D2': struct.unpack('>I', s[c6 + 2:c6 + 6])[0]}}, 'A8': struct.unpack('>Q', s[41:49])[0]} return out_dict" "from struct import unpack def main(f): signature = bytes([86, 82, 79, 75]) a_adr = f.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(4)} temp = unpack('>QIHI', f[a_adr + 30:a_adr + 48]) (a['A2'], arr_size, arr_adr, d_adr) = temp temp = unpack(f'>{arr_size}s', f[arr_adr:arr_adr + arr_size]) a['A3'] = str(temp[0], 'utf8') b = {f'B{i + 1}': None for i in range(4)} b['B1'] = unpack('>B', f[a_adr:a_adr + 1])[0] (b['B3'], b['B4']) = unpack('>dB', f[a_adr + 21:a_adr + 30]) b['B2'] = [] for i in range(5): temp = unpack('>hh', f[a_adr + 1 + 4 * i:a_adr + 1 + 4 * (i + 1)]) b['B2'].append({'C1': temp[0], 'C2': temp[1]}) d = {f'D{i + 1}': None for i in range(5)} temp = unpack('>H4fI', f[d_adr:d_adr + 22]) (d['D1'], *d['D2'], d['D3']) = temp temp = unpack('>5BI', f[d_adr + 22:d_adr + 31]) (*d['D4'], d['D5']) = temp a['A1'] = b a['A4'] = d return a" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.int32) b21 = readC(reader.copy(reader.read(Types.uint16))) b22 = readC(reader.copy(reader.read(Types.uint16))) b2 = [b21, b22] sizeb3 = reader.read(Types.uint32) adressb3 = reader.read(Types.uint16) b3 = reader.copy(offset=adressb3).readWithSize(Types.double, sizeb3) sizeb4 = reader.read(Types.uint32) adressb4 = reader.read(Types.uint32) b4 = reader.copy(offset=adressb4).readWithSize(Types.uint8, sizeb4) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def readC(reader): c1 = reader.read(Types.uint8) c2 = readD(reader) return dict(C1=c1, C2=c2) def readD(reader): sized1 = reader.read(Types.uint16) adressd1 = reader.read(Types.uint16) d1 = reader.copy(offset=adressd1).readWithSize(Types.uint8, sized1) d2 = reader.read(Types.int16) d3 = reader.read(Types.float) d4 = reader.read(Types.uint8) d5 = reader.read(Types.uint16) d6 = reader.read(Types.int32) d7 = reader.read(Types.uint8) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = readB(reader) a2 = reader.read(Types.int8) a3 = reader.read(Types.uint64) a4 = reader.read(Types.uint32) a5 = reader.readWithSize(Types.uint32, 3) a6 = reader.read(Types.int64) a7 = reader.read(Types.int64) a8 = reader.read(Types.uint64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.source = source self.offset = offset def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_char(self): return self.read('c') def read_int8(self): return self.read('b') def read_uint8(self): return self.read('B') def read_int16(self): return self.read('h') def read_uint16(self): return self.read('H') def read_int32(self): return self.read('i') def read_uint32(self): return self.read('I') def read_int64(self): return self.read('q') def read_uint64(self): return self.read('Q') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_address_struct(source: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) return read(reader) def read_e(reader: BinaryReader): e1 = reader.read_int16() e2 = reader.read_int16() e3 = reader.read_uint64() e4 = reader.read_uint64() e5 = reader.read_float() e6 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_double(), structure_size=6) e7 = reader.read_int32() return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7) def read_d(reader: BinaryReader): d1 = reader.read_uint32() d2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) d3 = reader.read_int64() d4 = reader.read_uint32() d5 = reader.read_uint32() return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def read_c(reader: BinaryReader): c1 = reader.read_int8() c2 = reader.read_uint16() c3 = reader.read_uint32() return dict(C1=c1, C2=c2, C3=c3) def read_b(reader: BinaryReader): b1 = reader.read_float() b2 = reader.read_uint8() b3 = reader.read_int16() b4_1 = reader.read_char().decode('ascii') b4_2 = reader.read_char().decode('ascii') b4_3 = reader.read_char().decode('ascii') b4 = b4_1 + b4_2 + b4_3 b5 = reader.read_uint32() adresses = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint32(), structure_size=3) b6 = [] for i in adresses: b6.append(read_address_struct(source=reader.source, address=i, read=lambda reader: read_c(reader))) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6) def read_a(reader: BinaryReader): a1 = reader.read_int32() a2 = read_address_struct(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_b(reader)) a3 = reader.read_uint32() a4 = reader.read_double() a5 = read_address_struct(source=reader.source, address=reader.read_uint16(), read=lambda reader: read_d(reader)) a6 = read_address_struct(source=reader.source, address=reader.read_uint32(), read=lambda reader: read_e(reader)) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_struct_b(data, addr, size): result = list() for i in range(addr, addr + size * 6, 6): result.append(parse_b(data, i)) return result def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['D2'] = struct.unpack('>f', data[offset + 2:offset + 2 + 4])[0] (size, address) = struct.unpack('>HI', data[offset + 6:offset + 6 + 6]) result['D3'] = parse_array(data, address, 'B', size) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>Q', data[offset:offset + 8])[0] result['C2'] = struct.unpack('>b', data[offset + 8:offset + 8 + 1])[0] result['C3'] = struct.unpack('>Q', data[offset + 9:offset + 9 + 8])[0] result['C4'] = struct.unpack('>h', data[offset + 17:offset + 17 + 2])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>q', data[offset:offset + 8])[0] result['B2'] = parse_array(data, offset + 8, 'd', 2) result['B3'] = struct.unpack('>I', data[offset + 24:offset + 24 + 4])[0] result['B4'] = struct.unpack('>h', data[offset + 28:offset + 28 + 2])[0] return result def parse_a(data, offset): result = dict() result['A1'] = parse_b(data, offset) (size, addr) = struct.unpack('>HH', data[offset + 30:offset + 30 + 4]) result['A2'] = ''.join([str(c, 'utf-8') for c in parse_array(data, addr, 'c', size)]) result['A3'] = parse_c(data, offset + 34) result['A4'] = struct.unpack('>H', data[offset + 53:offset + 53 + 2])[0] (size, addr) = struct.unpack('>HH', data[offset + 55:offset + 55 + 4]) d_addrs = parse_array(data, addr, 'I', size) result['A5'] = [parse_d(data, address) for address in d_addrs] result['A6'] = struct.unpack('>b', data[offset + 59:offset + 59 + 1])[0] return result def main(data): return parse_a(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = parse(buf, offs, 'uint16') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'char') a3.append(val.decode()) (a4, offs) = parse_b(buf, offs) (a5_size, offs) = parse(buf, offs, 'uint32') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'uint16') a5.append(val) return (dict(A1=a1, A2=a2, A3=''.join(a3), A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse(buf, offs, 'int32') (b3, offs) = parse(buf, offs, 'int8') (b4, offs) = parse(buf, offs, 'float') b5 = [] for _ in range(5): (b5_offs, offs) = parse(buf, offs, 'uint32') (val, b5_offs) = parse_c(buf, b5_offs) b5.append(val) b6 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int16') b6.append(val) (b7, offs) = parse(buf, offs, 'uint16') (b8_offs, offs) = parse(buf, offs, 'uint32') (b8, b8_offs) = parse_d(buf, b8_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'float') (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse(buf, offs, 'double') (d6, offs) = parse(buf, offs, 'double') (d7, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structE: def fill_struct(self, b): global BYTE_INDEX self.set_E1(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_E2(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) return self def set_E1(self, a): self.E1 = a def set_E2(self, a): self.E2 = a def get_cort(self): return {'E1': self.E1, 'E2': self.E2} class structD: def fill_struct(self, b): global BYTE_INDEX self.set_D1(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_D2(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_D3(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) return self def set_D1(self, a): self.D1 = a def set_D2(self, a): self.D2 = a def set_D3(self, a): self.D3 = a def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class structC: def fill_struct(self, b): global BYTE_INDEX arr = [] for i in range(4): arr.append(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_C1(arr) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr1 = [] for i in range(size): arr1.append(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) BYTE_INDEX = STOP_INDEX self.set_C2(arr1) self.set_C3(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_C1(self, a): self.C1 = a def set_C3(self, a): self.C3 = a def set_C2(self, a): self.C2 = a def get_cort(self): return {'C1': self.C1, 'C2': self.C2, 'C3': self.C3} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_B1(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B2(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) size = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(structC().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_B3(arr) self.set_B4(structD().fill_struct(b)) self.set_B5(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B6(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_B1(self, a): self.B1 = a def set_B2(self, a): self.B2 = a def set_B3(self, a): self.B3 = a def set_B4(self, a): self.B4 = a def set_B5(self, a): self.B5 = a def set_B6(self, a): self.B6 = a def get_cort(self): arr = [] for i in self.B3: arr.append(i.get_cort()) return {'B1': self.B1, 'B2': self.B2, 'B3': arr, 'B4': self.B4.get_cort(), 'B5': self.B5, 'B6': self.B6} class structA: def fill_struct(self, b): global BYTE_INDEX size = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer string = '' for i in range(size): string += chr(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) BYTE_INDEX = STOP_INDEX self.set_A1(string) self.set_A2(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_A3(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_A4(structB().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_A5(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_A6(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_A7(structE().fill_struct(b)) self.set_A8(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) return self def set_A1(self, a): self.A1 = a def set_A2(self, a): self.A2 = a def set_A3(self, a): self.A3 = a def set_A4(self, a): self.A4 = a def set_A5(self, a): self.A5 = a def set_A6(self, a): self.A6 = a def set_A7(self, a): self.A7 = a def set_A8(self, a): self.A8 = a def get_cort(self): return {'A1': self.A1, 'A2': self.A2, 'A3': self.A3, 'A4': self.A4.get_cort(), 'A5': self.A5, 'A6': self.A6, 'A7': self.A7.get_cort(), 'A8': self.A8} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct def u16u32u8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + 1 * size]) return list(a) def u32u32u8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + 1 * size]) return list(a) def F(x, start): return {'F1': struct.unpack('> b', x[start:start + 1])[0], 'F2': u32u32u8(x, start + 1), 'F3': struct.unpack('> I', x[start + 9:start + 13])[0]} def E(x, start): return {'E1': struct.unpack('> i', x[start:start + 4])[0], 'E2': struct.unpack('> h', x[start + 4:start + 6])[0], 'E3': struct.unpack('> d', x[start + 6:start + 14])[0], 'E4': struct.unpack('> B', x[start + 14:start + 15])[0], 'E5': struct.unpack('> d', x[start + 15:start + 23])[0], 'E6': struct.unpack('> I', x[start + 23:start + 27])[0], 'E7': struct.unpack('> Q', x[start + 27:start + 35])[0]} def D(x, start): return {'D1': struct.unpack('> f', x[start:start + 4])[0], 'D2': struct.unpack('> B', x[start + 4:start + 5])[0], 'D3': struct.unpack('> i', x[start + 5:start + 9])[0], 'D4': struct.unpack('> i', x[start + 9:start + 13])[0], 'D5': struct.unpack('> d', x[start + 13:start + 21])[0], 'D6': struct.unpack('> i', x[start + 21:start + 25])[0], 'D7': list(struct.unpack('> 2i', x[start + 25:start + 33]))} def C(x, start): return {'C1': struct.unpack('>5s', x[start:start + 5])[0].decode('ascii'), 'C2': struct.unpack('>d', x[start + 5:start + 13])[0], 'C3': struct.unpack('>H', x[start + 13:start + 15])[0], 'C4': struct.unpack('> H', x[start + 15:start + 17])[0], 'C5': D(x, start + 17)} def B(x, start): return {'B1': struct.unpack('> h', x[start:start + 2])[0], 'B2': C(x, start + 2), 'B3': struct.unpack('> H', x[start + 52:start + 54])[0], 'B4': struct.unpack('> H', x[start + 54:start + 56])[0], 'B5': E(x, start + 56)} def A(x, start): return {'A1': B(x, start), 'A2': struct.unpack('> B', x[start + 91:start + 92])[0], 'A3': struct.unpack('> h', x[start + 92:start + 94])[0], 'A4': [F(x, start + 94), F(x, start + 107), F(x, start + 120), F(x, start + 133), F(x, start + 146), F(x, start + 159), F(x, start + 172), F(x, start + 185)], 'A5': u16u32u8(x, start + 198), 'A6': struct.unpack('>I', x[start + 204:start + 208])[0]} def main(x): return A(x, 3)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = readC(reader.copy(reader.read(Types.uint32))) b2 = reader.read(Types.int16) return dict(B1=b1, B2=b2) def readC(reader): c1 = reader.read(Types.uint8) c2 = readD(reader) c3 = reader.read(Types.uint64) size4 = reader.read(Types.uint16) adress4 = reader.read(Types.uint16) arrayReader = reader.copy(adress4) c4 = [] for _ in range(0, size4): c4.append(readE(arrayReader)) return dict(C1=c1, C2=c2, C3=c3, C4=c4) def readD(reader): d1 = reader.read(Types.int16) d2 = reader.read(Types.uint64) return dict(D1=d1, D2=d2) def readE(reader): size1 = reader.read(Types.uint16) adress1 = reader.read(Types.uint32) e1 = reader.copy(adress1).readWithSize(Types.int8, size1) e2 = reader.read(Types.uint16) return dict(E1=e1, E2=e2) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = readB(reader) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint16) tempA2 = reader.copy(adress2).readWithSize(Types.char, size2) a2 = b''.join(tempA2).decode('ASCII') a3 = reader.read(Types.uint32) a4 = reader.readWithSize(Types.int32, 7) a5 = reader.read(Types.int8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5)" "import struct def main(x): f = dict() f['A1'] = struct.unpack('>d', x[5:13])[0] f['A2'] = struct.unpack('>H', x[13:15])[0] f['A3'] = struct.unpack('>d', x[15:23])[0] f['A4'] = struct.unpack('>Q', x[23:31])[0] b = dict() di = struct.unpack('>I', x[31:35])[0] dis = '>' + str(di) + 's' pos1 = struct.unpack('>H', x[35:37])[0] b['B1'] = str(struct.unpack(dis, x[pos1:pos1 + di])[0])[2:-1] b['B2'] = struct.unpack('>I', x[37:41])[0] b['B3'] = struct.unpack('>Q', x[41:49])[0] c = dict() c['C1'] = struct.unpack('>b', x[49:50])[0] c['C2'] = struct.unpack('>d', x[50:58])[0] c['C3'] = struct.unpack('>i', x[58:62])[0] c['C4'] = struct.unpack('>H', x[62:64])[0] c['C5'] = struct.unpack('>b', x[64:65])[0] c['C6'] = struct.unpack('>I', x[65:69])[0] c['C7'] = struct.unpack('>d', x[69:77])[0] b['B4'] = c b5 = [] p = 77 for i in range(0, 5): d1 = struct.unpack('>q', x[p:p + 8])[0] d2 = struct.unpack('>i', x[p + 8:p + 12])[0] d = {'D1': d1, 'D2': d2} b5.append(d) p += 12 b['B5'] = b5 e1 = list(struct.unpack('>2B', x[137:139])) di = struct.unpack('>H', x[139:141])[0] dis = '>' + str(di) + 'B' pos1 = struct.unpack('>H', x[141:143])[0] e2 = list(struct.unpack(dis, x[pos1:pos1 + di])) di = struct.unpack('>H', x[143:145])[0] dis = '>' + str(di) + 'd' pos1 = struct.unpack('>I', x[145:149])[0] e3 = list(struct.unpack(dis, x[pos1:pos1 + di * 8])) e4 = struct.unpack('>q', x[149:157])[0] b['B6'] = {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} f['A5'] = b return f" "import struct class IntMut: def __init__(self, val: int): self.__val = val def __int__(self) -> int: return self.__val def __add__(self, other: int): self.__val += other return self def a(x, start: IntMut) -> dict: return {'A1': struct.unpack('< I', x[int(start):int(start + 4)])[0], 'A2': b(x, start), 'A3': c(x, start), 'A4': struct.unpack('< Q', x[int(start):int(start + 8)])[0], 'A5': size2char(x, start), 'A6': uint16uint32int16(x, start)} def uint16uint32int16(x, start: IntMut) -> list: size = struct.unpack('< H', x[int(start):int(start + 2)])[0] add = struct.unpack('< I', x[int(start):int(start + 4)])[0] return list(struct.unpack('< ' + 'h' * size, x[add:add + 2 * size])) def uint16uint16uint8(x, start: IntMut) -> list: size = struct.unpack('< H', x[int(start):int(start + 2)])[0] add = struct.unpack('< H', x[int(start):int(start + 2)])[0] return list(struct.unpack('< ' + 'B' * size, x[add:add + 1 * size])) def size2char(x, start: IntMut) -> str: res = '' for _ in range(2): res += str(struct.unpack('< c', x[int(start):int(start + 1)])[0]).replace(""b'"", '').replace(""'"", '') return res def b(x, start: IntMut) -> dict: return {'B1': struct.unpack('< Q', x[int(start):int(start + 8)])[0], 'B2': struct.unpack('< B', x[int(start):int(start + 1)])[0]} def uint32uint16uint16d(x, start: IntMut) -> list: size = struct.unpack('< I', x[int(start):int(start + 4)])[0] add = struct.unpack('< H', x[int(start):int(start + 2)])[0] return [d(x, IntMut(i)) for i in struct.unpack('< ' + 'H' * size, x[add:add + 2 * size])] def c(x, start: IntMut) -> dict: return {'C1': struct.unpack('< d', x[int(start):int(start + 8)])[0], 'C2': struct.unpack('< B', x[int(start):int(start + 1)])[0], 'C3': struct.unpack('< f', x[int(start):int(start + 4)])[0], 'C4': struct.unpack('< q', x[int(start):int(start + 8)])[0], 'C5': uint32uint16uint16d(x, start)} def d(x, start: IntMut) -> dict: return {'D1': uint16uint16uint8(x, start), 'D2': struct.unpack('< i', x[int(start):int(start + 4)])[0], 'D3': struct.unpack('< I', x[int(start):int(start + 4)])[0], 'D4': struct.unpack('< f', x[int(start):int(start + 4)])[0], 'D5': struct.unpack('< I', x[int(start):int(start + 4)])[0], 'D6': struct.unpack('< b', x[int(start):int(start + 1)])[0]} def main(data: bytes) -> dict: return a(data, IntMut(3))" "from struct import unpack def main(file): signature = bytes([186, 80, 67, 79, 89]) a_adr = file.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(6)} temp = unpack('>f3H', file[a_adr:a_adr + 10]) (a['A1'], a['A2'], *b_adrs) = temp temp = unpack('>HIb', file[a_adr + 79:a_adr + 86]) (arr_size, arr_adr, a['A6']) = temp temp = unpack(f'>{arr_size}B', file[arr_adr:arr_adr + arr_size]) a['A5'] = list(temp) a['A3'] = [] for b_adr in b_adrs: temp = unpack('>2sI', file[b_adr:b_adr + 6]) b = {'B1': str(temp[0], 'utf8'), 'B2': None} c_adr = temp[1] c = {f'C{i + 1}': None for i in range(4)} temp = unpack('>HIHq', file[c_adr:c_adr + 16]) (c['C1'], c['C2'], c['C3'], c['C4']) = temp b['B2'] = c a['A3'].append(b) d = {f'D{i + 1}': None for i in range(5)} temp = unpack('>hIQd', file[a_adr + 10:a_adr + 32]) (d['D1'], e_adr, d['D3'], d['D4']) = temp temp = unpack('>Ifd', file[e_adr:e_adr + 16]) d['D2'] = {'E1': temp[0], 'E2': temp[1], 'E3': temp[2]} f = {f'F{i + 1}': None for i in range(4)} temp = unpack('>5di', file[a_adr + 32:a_adr + 76]) (*f['F1'], f['F2']) = temp temp = unpack('>3b', file[a_adr + 76:a_adr + 79]) (*f['F3'], f['F4']) = temp d['D5'] = f a['A4'] = d return a" "from struct import unpack_from, calcsize from enum import Enum class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def readA(reader: BinaryReader): A1 = reader.read(Types.double) A2 = reader.read(Types.int8) A3 = readB(reader) A4 = reader.read(Types.uint64) A5 = reader.read(Types.uint32) A6 = reader.read(Types.uint16) A7 = reader.read(Types.uint64) d_addr = reader.read(Types.uint16) A8 = readD(BinaryReader(source=reader.source, offset=d_addr)) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8) def readB(reader: BinaryReader): B1 = reader.read(Types.uint64) B2 = reader.read(Types.int8) B3 = reader.read(Types.double) arr_len = reader.read(Types.uint16) arr_addr = reader.read(Types.uint16) B4 = masserB4(arr_len, arr_addr, reader.source) B5 = reader.read(Types.uint64) B6 = [reader.read(Types.uint8), reader.read(Types.uint8), reader.read(Types.uint8)] return dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6) def readC(reader: BinaryReader): C1 = reader.read(Types.uint32) C2 = reader.read(Types.uint16) C3 = reader.read(Types.uint8) C4 = [reader.read(Types.uint32), reader.read(Types.uint32)] C5 = reader.read(Types.int64) return dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5) def readD(reader: BinaryReader): D1 = reader.read(Types.float) arr_len = reader.read(Types.uint32) arr_addr = reader.read(Types.uint16) D2 = masserD2(arr_len, arr_addr, reader.source) return dict(D1=D1, D2=D2) def masserB4(size, offset, source): reader = BinaryReader(source, offset) rez = [] while reader.offset < offset + size * 23: rez.append(readC(reader)) return rez def masserD2(size, offset, source): reader = BinaryReader(source, offset) rez = [] while reader.offset < offset + size: rez.append(reader.read(Types.int8)) return rez def main(data): reader = BinaryReader(source=data, offset=3) return readA(reader)" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_struct_f(data, address, size): result = list() for i in range(address, address + size * 25, 25): result.append(parse_f(data, i)) return result def parse_f(data, offset): result = dict() result['F1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['F2'] = struct.unpack('>I', data[offset + 1:offset + 1 + 4])[0] result['F3'] = struct.unpack('>B', data[offset + 5:offset + 5 + 1])[0] result['F4'] = struct.unpack('>H', data[offset + 6:offset + 6 + 2])[0] result['F5'] = struct.unpack('>b', data[offset + 8:offset + 8 + 1])[0] result['F6'] = struct.unpack('>H', data[offset + 9:offset + 9 + 2])[0] result['F7'] = parse_array(data, offset + 11, 'H', 7) return result def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>i', data[offset:offset + 4])[0] result['E2'] = struct.unpack('>d', data[offset + 4:offset + 4 + 8])[0] result['E3'] = struct.unpack('>i', data[offset + 12:offset + 12 + 4])[0] return result def parse_d(data, offset): result = dict() result['D1'] = parse_array(data, offset, 'Q', 3) result['D2'] = struct.unpack('>I', data[offset + 24:offset + 24 + 4])[0] result['D3'] = struct.unpack('>B', data[offset + 28:offset + 28 + 1])[0] result['D4'] = struct.unpack('>i', data[offset + 29:offset + 29 + 4])[0] return result def parse_c(data, offset): result = dict() result['C1'] = ''.join([str(c, 'utf-8') for c in parse_array(data, offset, 'c', 6)]) address = struct.unpack('>H', data[offset + 6:offset + 6 + 2])[0] result['C2'] = parse_d(data, address) result['C3'] = struct.unpack('>Q', data[offset + 8:offset + 8 + 8])[0] result['C4'] = struct.unpack('>h', data[offset + 16:offset + 16 + 2])[0] result['C5'] = struct.unpack('>b', data[offset + 18:offset + 18 + 1])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>i', data[offset:offset + 4])[0] address = struct.unpack('>H', data[offset + 4:offset + 4 + 2])[0] result['B2'] = parse_c(data, address) result['B3'] = struct.unpack('>Q', data[offset + 6:offset + 6 + 8])[0] result['B4'] = struct.unpack('>f', data[offset + 14:offset + 14 + 4])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['A2'] = parse_b(data, offset + 2) address = struct.unpack('>H', data[offset + 20:offset + 20 + 2])[0] result['A3'] = parse_e(data, address) (a4_size, a4_addr) = struct.unpack('>HH', data[offset + 22:offset + 22 + 4]) result['A4'] = parse_struct_f(data, a4_addr, a4_size) return result def main(data): return parse_a(data, 5)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_F(data, ofs): F1 = [] (F1_size, ofs) = parse('uint32', data, ofs) (F1_adr, ofs) = parse('uint32', data, ofs) for i in range(F1_size): (elem, F1_adr) = parse('uint8', data, F1_adr) F1.append(elem) (F2, ofs) = parse('uint16', data, ofs) return (dict(F1=F1, F2=F2), ofs) def struct_E(data, ofs): (E1, ofs) = parse('int32', data, ofs) (E2, ofs) = parse('float', data, ofs) (E3, ofs) = parse('uint16', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_D(data, ofs): (D1, ofs) = struct_E(data, ofs) (D2, ofs) = struct_F(data, ofs) return (dict(D1=D1, D2=D2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) (C2, ofs) = parse('int16', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int64', data, ofs) B2 = [] for i in range(8): (elem, ofs) = struct_C(data, ofs) B2.append(elem) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1_adr, ofs) = parse('uint32', data, ofs) (A1, elem) = struct_B(data, A1_adr) (A2, ofs) = parse('double', data, ofs) (A3, ofs) = parse('double', data, ofs) (A4, ofs) = parse('uint32', data, ofs) A5 = [] for i in range(2): (D_adr, ofs) = parse('uint32', data, ofs) (elem, lop) = struct_D(data, D_adr) A5.append(elem) A6 = [] (A6_size, ofs) = parse('uint32', data, ofs) (A6_adr, ofs) = parse('uint16', data, ofs) for i in range(A6_size): (elem, A6_adr) = parse('uint32', data, A6_adr) A6.append(elem) (A7, ofs) = parse('uint16', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 4)[0]" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.int64) size2 = reader.read(Types.uint16) adress2 = reader.read(Types.uint16) adressArray = reader.copy(adress2).readWithSize(Types.uint32, size2) b2 = [] for adress in adressArray: b2.append(readC(reader.copy(adress))) return dict(B1=b1, B2=b2) def readC(reader): size1 = reader.read(Types.uint16) adress1 = reader.read(Types.uint32) c1 = reader.copy(adress1).readWithSize(Types.int8, size1) adress2 = reader.read(Types.uint32) c2 = readD(reader.copy(adress2)) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint32) c3 = reader.copy(adress3).readWithSize(Types.uint64, size3) return dict(C1=c1, C2=c2, C3=c3) def readD(reader): d1 = reader.read(Types.float) d2 = reader.read(Types.int32) return dict(D1=d1, D2=d2) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.float) a2 = reader.read(Types.int64) a3 = reader.read(Types.float) a4 = reader.read(Types.double) a5 = reader.read(Types.int16) a6 = readB(reader) size7 = reader.read(Types.uint16) adress7 = reader.read(Types.uint16) a7 = reader.copy(offset=adress7).readWithSize(Types.uint32, size7) a8 = reader.read(Types.int32) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = [] for i in range(0, 4): b1.append(readC(reader)) b2 = reader.readWithSize(Types.int8, 8) b3 = readD(reader) b4 = reader.read(Types.int64) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def readC(reader): c1 = reader.read(Types.double) c2 = reader.readWithSize(Types.int8, 6) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.readWithSize(Types.int16, 6) size2 = reader.read(Types.uint16) adress2 = reader.read(Types.uint32) d2 = reader.copy(offset=adress2).readWithSize(Types.uint16, size2) d3 = reader.read(Types.int16) return dict(D1=d1, D2=d2, D3=d3) def main(buffer): reader = BinaryReader(offset=3, buffer=buffer) a1 = readB(reader) a2 = reader.read(Types.int8) a3 = reader.read(Types.double) a4 = reader.read(Types.int16) a5 = reader.read(Types.int64) a6 = reader.read(Types.uint64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "from struct import unpack def parse_arrays(arr, c_str_size): count = 0 parsed = [] for _ in range(0, c_str_size): a = [] for i in range(0, 8): a.append(arr[count + i]) count += 8 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 90: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 5)} temp = unpack('Hf4I4BiH', data, offset=5) C1 = struct.unpack_from('>' + str(A[4]) + 'H', data, offset=A[5]) D_list = [] for i in range(A[4]): D = struct.unpack_from('>B4fq2h', data, offset=C1[i]) D_list.append({'D1': D[0], 'D2': [D[1], D[2], D[3], D[4]], 'D3': D[5], 'D4': [D[6], D[7]]}) return {'A1': A[0], 'A2': A[1], 'A3': {'B1': A[2], 'B2': A[3], 'B3': {'C1': D_list, 'C2': [A[6], A[7], A[8], A[9]]}}, 'A4': A[10], 'A5': A[11]}" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 83: break a = {f'A{i}': None for i in range(1, 5)} b = {f'B{i}': None for i in range(1, 7)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>bHL4L', file[a_adr:a_adr + 23]) (a['A1'], b_adr, a['A3'], *d_adrs) = temp temp = unpack('>4cqlqlLHQHdB', file[b_adr:b_adr + 53]) (*ch_arr, c['C1'], c['C2'], c['C3'], c['C4'], uint32_size, uint32_adr, b['B3'], b['B4'], b['B5'], b['B6']) = temp b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) c['C5'] = list(temp) a['A4'] = [] for d_adr in d_adrs: temp = unpack('>lHHf', file[d_adr:d_adr + 12]) (d['D1'], uint8_size, uint8_adr, d['D3']) = temp temp = unpack(f'>{uint8_size}B', file[uint8_adr:uint8_adr + uint8_size]) d['D2'] = list(temp) a['A4'].append(d.copy()) a['A2'] = b b['B2'] = c return a" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.float) b2 = reader.read(Types.int16) b3 = reader.read(Types.uint8) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.uint8) c2 = reader.read(Types.int16) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.uint64) d2 = reader.read(Types.int16) d3 = reader.read(Types.uint32) d4 = [] for _ in range(3): d4.append(reader.read(Types.uint16)) d5 = readE(reader) d6 = readF(reader) d7 = reader.read(Types.uint16) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def readE(reader): e1 = reader.read(Types.uint8) e2 = reader.read(Types.uint32) size3 = reader.read(Types.uint32) address3 = reader.read(Types.uint32) e3 = reader.copy(offset=address3).readWithSize(Types.double, size3) e4 = reader.read(Types.uint64) return dict(E1=e1, E2=e2, E3=e3, E4=e4) def readF(reader): f1 = reader.read(Types.float) f2 = reader.read(Types.uint64) f3 = reader.read(Types.uint16) f4 = reader.read(Types.double) return dict(F1=f1, F2=f2, F3=f3, F4=f4) def main(buffer): reader = BinaryReader(offset=3, buffer=buffer) size1 = reader.read(Types.uint32) address1 = reader.read(Types.uint16) a1 = [] bReader = BinaryReader(offset=address1, buffer=buffer) for i in range(0, size1): a1.append(readB(reader.copy(bReader.read(Types.uint16)))) a2 = reader.read(Types.int16) a3 = reader.read(Types.float) size4 = reader.read(Types.uint16) address4 = reader.read(Types.uint16) a4 = [] cReader = BinaryReader(offset=address4, buffer=buffer) for i in range(0, size4): a4.append(readC(reader.copy(cReader.read(Types.uint32)))) a5 = readD(reader.copy(reader.read(Types.uint16))) a6 = reader.read(Types.uint16) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "import struct def structE(data, pointer): (e1,) = struct.unpack('>I', data[pointer:pointer + 4]) (e2,) = struct.unpack('>Q', data[pointer + 4:pointer + 12]) (e3,) = struct.unpack('>i', data[pointer + 12:pointer + 16]) (e4,) = struct.unpack('>b', data[pointer + 16:pointer + 17]) (e5,) = struct.unpack('>f', data[pointer + 17:pointer + 21]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def structD(data, pointer): (d1,) = struct.unpack('>I', data[pointer:pointer + 4]) (d2,) = struct.unpack('>d', data[pointer + 4:pointer + 12]) (d3,) = struct.unpack('>h', data[pointer + 12:pointer + 14]) (d4,) = struct.unpack('>B', data[pointer + 14:pointer + 15]) f5 = struct.unpack('>HH', data[pointer + 15:pointer + 19]) d5 = list(struct.unpack(f'>{f5[0]}h', data[f5[1]:f5[1] + f5[0] * 2])) f6 = struct.unpack('>II', data[pointer + 19:pointer + 27]) d6 = list(struct.unpack(f'>{f6[0]}h', data[f6[1]:f6[1] + f6[0] * 2])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def structC(data, pointer): (c1,) = struct.unpack('>h', data[pointer:pointer + 2]) (c2,) = struct.unpack('>b', data[pointer + 2:pointer + 3]) (c3,) = struct.unpack('>B', data[pointer + 3:pointer + 4]) (c4,) = struct.unpack('>Q', data[pointer + 4:pointer + 12]) c5 = structD(data, pointer + 12) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) (b2,) = struct.unpack('>I', data[pointer + 1:pointer + 5]) f3 = struct.unpack('>HH', data[pointer + 5:pointer + 9]) b3 = ''.join(map(str, struct.unpack(f'>{f3[0]}c', data[f3[1]:f3[1] + f3[0]]))) b3 = b3.replace(""'"", '') b3 = b3[1::2] (b4,) = struct.unpack('>f', data[pointer + 9:pointer + 13]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def structA(data, pointer): (a1,) = struct.unpack('>q', data[pointer:pointer + 8]) (a2,) = struct.unpack('>Q', data[pointer + 8:pointer + 16]) a3 = structB(data, pointer + 16) (a4,) = struct.unpack('>Q', data[pointer + 29:pointer + 37]) (a5,) = struct.unpack('>H', data[pointer + 37:pointer + 39]) a6 = [structC(data, pointer + 39), structC(data, pointer + 78)] f7 = struct.unpack('>I', data[pointer + 117:pointer + 121]) a7 = structE(data, f7[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return structA(data, 5)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse_b(buf, offs) a3_size = 8 a3 = [] for _ in range(a3_size): (val, offs) = parse_d(buf, offs) a3.append(val) a4_size = 2 a4 = [] for _ in range(a4_size): (val, offs) = parse(buf, offs, 'char') a4.append(val.decode()) (a5_size, offs) = parse(buf, offs, 'uint16') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse_e(buf, a5_offs) a5.append(val) (a6, offs) = parse(buf, offs, 'int32') (a7, offs) = parse(buf, offs, 'int16') (a8, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_c(buf, b2_offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'int64') (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2_size, offs) = parse(buf, offs, 'uint32') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'uint32') e2.append(val) (e3, offs) = parse(buf, offs, 'int64') (e4, offs) = parse(buf, offs, 'uint16') (e5, offs) = parse(buf, offs, 'int32') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2, ofs) = parse('uint64', data, ofs) D3 = [] (D3_size, ofs) = parse('uint16', data, ofs) (D3_adr, ofs) = parse('uint32', data, ofs) for i in range(D3_size): (elem, D3_adr) = parse('uint64', data, D3_adr) D3.append(elem) return (dict(D1=D1, D2=D2, D3=D3), ofs) def struct_C(data, ofs): (C1, ofs) = parse('int8', data, ofs) (C2, ofs) = parse('int32', data, ofs) (C3, ofs) = parse('uint64', data, ofs) (C4, ofs) = parse('int8', data, ofs) C5 = [] for i in range(2): (elem, ofs) = parse('uint8', data, ofs) C5.append(elem) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): B1 = [] for i in range(2): (C_adr, ofs) = parse('uint32', data, ofs) (elem, lop) = struct_C(data, C_adr) B1.append(elem) (B2, ofs) = parse('int32', data, ofs) (B3, ofs) = struct_D(data, ofs) (B4, ofs) = parse('int64', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = parse('float', data, ofs) (A2, ofs) = parse('int32', data, ofs) (A3, ofs) = parse('uint8', data, ofs) (A4, ofs) = parse('int64', data, ofs) (A5, ofs) = parse('float', data, ofs) A6 = '' (A6_size, ofs) = parse('uint16', data, ofs) (A6_adr, ofs) = parse('uint32', data, ofs) for i in range(A6_size): (elem, A6_adr) = parse('char', data, A6_adr) A6 += elem.decode() (A7_adr, ofs) = parse('uint32', data, ofs) (A7, elem) = struct_B(data, A7_adr) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 3)[0]" "import struct def main(data): A = struct.unpack_from('>BiBhf2If2Hq', data, offset=4) B4 = list(struct.unpack_from('>' + str(A[5]) + 'c', data, offset=A[6])) for i in range(A[5]): B4[i] = B4[i].decode('utf-8') B4 = ''.join(B4) A4 = struct.unpack_from('>' + str(A[8]) + 'I', data, offset=A[9]) C_list = [] for i in range(A[8]): C = struct.unpack_from('>3IQb3I', data, offset=A4[i]) D1 = list(struct.unpack_from('>' + str(C[1]) + 'h', data, offset=C[2])) C4 = list(struct.unpack_from('>' + str(C[5]) + 'Q', data, offset=C[6])) C_list.append({'C1': C[0], 'C2': {'D1': D1, 'D2': C[3]}, 'C3': C[4], 'C4': C4, 'C5': C[7]}) return {'A1': A[0], 'A2': A[1], 'A3': {'B1': A[2], 'B2': A[3], 'B3': A[4], 'B4': B4, 'B5': A[7]}, 'A4': C_list, 'A5': A[10]}" "from struct import * FTP = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, form): return (unpack_from(FTP[form], buf, offs)[0], offs + calcsize(FTP[form])) def a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = b(buf, offs) a3 = [] for _ in range(3): (a3_offs, offs) = parse(buf, offs, 'uint32') (val, a3_offs) = c(buf, a3_offs) a3.append(val) a4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') a4.append(val) (a5_size, offs) = parse(buf, offs, 'uint32') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'int8') a5.append(val) (a6, offs) = parse(buf, offs, 'uint64') (a7, offs) = e(buf, offs) (a8, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'double') (b3, offs) = parse(buf, offs, 'uint8') (b4, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def c(buf, offs): c1 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint16') c1.append(val) (c2, offs) = d(buf, offs) (c3_size, offs) = parse(buf, offs, 'uint16') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'uint8') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2), offs) def e(buf, offs): (e1, offs) = parse(buf, offs, 'uint64') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'int16') (e4, offs) = parse(buf, offs, 'int8') (e5, offs) = parse(buf, offs, 'uint16') (e6, offs) = parse(buf, offs, 'int8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def main(buf): return a(buf, 4)[0]" "import struct def main(data): A = struct.unpack_from('b', data[pointer:pointer + 1])[0] d2 = list(struct.unpack('>7B', data[pointer + 1:pointer + 8])) (d3, d4) = struct.unpack('>Hq', data[pointer + 8:pointer + 18]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) c1 = list() for i in range(f1[0]): c1.append(parse_d(data, f1[1] + i * 18)) f2 = struct.unpack('>II', data[pointer + 8:pointer + 16]) c2 = list(struct.unpack(f'>{f2[0]}q', data[f2[1]:f2[1] + f2[0] * 8])) (c3, c4) = struct.unpack('>fd', data[pointer + 16:pointer + 28]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): b1 = struct.unpack('>Q', data[pointer:pointer + 8])[0] f2 = struct.unpack('>I', data[pointer + 8:pointer + 12]) b2 = parse_c(data, f2[0]) b3 = list(struct.unpack('>2q', data[pointer + 12:pointer + 28])) (b4, b5) = struct.unpack('>bb', data[pointer + 28:pointer + 30]) b6 = list(struct.unpack('>5b', data[pointer + 30:pointer + 35])) (b7, b8) = struct.unpack('>bH', data[pointer + 35:pointer + 38]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def parse_a(data, pointer): (a1, a2, a3) = struct.unpack('>bBI', data[pointer:pointer + 6]) f4 = struct.unpack('>H', data[pointer + 6:pointer + 8]) a4 = parse_b(data, f4[0]) (a5, a6) = struct.unpack('>Bi', data[pointer + 8:pointer + 13]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('qfqQ', data[pointer:pointer + 28]) f5 = struct.unpack('>II', data[pointer + 28:pointer + 36]) d5 = list(struct.unpack(f'>{f5[0]}Q', data[f5[1]:f5[1] + f5[0] * 8])) (d6, d7) = struct.unpack('>qb', data[pointer + 36:pointer + 45]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def parse_c(data, pointer): (c1, c2) = struct.unpack('>bi', data[pointer:pointer + 5]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = struct.unpack('>H', data[pointer:pointer + 2])[0] f2 = struct.unpack('>3H', data[pointer + 2:pointer + 8]) b2 = list() for i in range(3): b2.append(parse_c(data, f2[i])) b3 = list(struct.unpack('>2q', data[pointer + 8:pointer + 24])) b4 = parse_d(data, pointer + 24) b5 = struct.unpack('>Q', data[pointer + 69:pointer + 77])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_a(data, pointer): a1 = struct.unpack('>I', data[pointer:pointer + 4])[0] f2 = struct.unpack('>HI', data[pointer + 4:pointer + 10]) a2 = ''.join(map(str, struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0]]))) a2 = a2.replace(""'"", '')[1::2] a3 = struct.unpack('>q', data[pointer + 10:pointer + 18])[0] a4 = parse_b(data, pointer + 18) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 4)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint64), structure_size=8), D2=reader.read(Primitive.float), D3=reader.read(Primitive.int32), D4=read_array(reader, 5, reader.offset, lambda reader: reader.read(Primitive.uint32), structure_size=4, toSum=True)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.uint8), C2=reader.read(Primitive.int8), C3=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.int32), structure_size=4), C4=reader.read(Primitive.double)) def read_b(reader: BinaryReader): return dict(B1=read_c(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), B2=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), B3=reader.read(Primitive.int8)) def read_a(reader: BinaryReader): return dict(A1=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint32), lambda reader: read_b(reader), structure_size=7), A2=reader.read(Primitive.int16), A3=reader.read(Primitive.uint8)) def main(source): return read_a(BinaryReader(source, offset=5))" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack(' reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.uint16), D2=reader.read(Primitive.uint8), D3=reader.read(Primitive.uint8), D4=reader.read(Primitive.int64), D5=reader.read(Primitive.double), D6=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int8), structure_size=1, toSum=True)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.uint64), C2=reader.read(Primitive.double), C3=reader.read(Primitive.uint16)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.float), B2=reader.read(Primitive.int32), B3=''.join(read_array(reader, 7, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1, toSum=True))) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.uint16), A2=reader.read(Primitive.uint8), A3=''.join(read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1, toSum=True)), A4=reader.read(Primitive.uint32), A5=read_b(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), A6=reader.read(Primitive.uint32), A7=[read_c(BinaryReader(reader.source, offset=i)) for i in read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.uint16), structure_size=2, toSum=True)], A8=read_d(reader)) def main(source): return read_a(BinaryReader(source, offset=4))" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse(buf, offs, 'uint32') (a5, offs) = parse(buf, offs, 'float') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_e(buf, a6_offs) (a7, offs) = parse_f(buf, offs) return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse(buf, offs, 'int64') (b4, offs) = parse(buf, offs, 'int64') (b5_size, offs) = parse(buf, offs, 'uint32') (b5_offs, offs) = parse(buf, offs, 'uint16') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse_c(buf, b5_offs) b5.append(val) (b6_offs, offs) = parse(buf, offs, 'uint16') (b6, b6_offs) = parse_d(buf, b6_offs) (b7, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): c1 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'double') c1.append(val) (c2, offs) = parse(buf, offs, 'int32') (c3, offs) = parse(buf, offs, 'int16') (c4, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int8') e2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int8') e2.append(val) (e3, offs) = parse(buf, offs, 'float') (e4, offs) = parse(buf, offs, 'uint8') (e5_size, offs) = parse(buf, offs, 'uint32') (e5_offs, offs) = parse(buf, offs, 'uint32') e5 = [] for _ in range(e5_size): (val, e5_offs) = parse(buf, e5_offs, 'uint16') e5.append(val) (e6, offs) = parse(buf, offs, 'int8') (e7, offs) = parse(buf, offs, 'int8') (e8, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7, E8=e8), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int64') (f2, offs) = parse(buf, offs, 'int32') return (dict(F1=f1, F2=f2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '<' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for i in range(6): (a1_offs, offs) = parse(buf, offs, 'uint32') (val, b1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'int8') (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'double') (a6_offs, offs) = parse(buf, offs, 'uint32') (a6, offs) = parse_c(buf, a6_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): b1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'char') b1.append(val.decode()) (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'uint16') return (dict(B1=''.join(b1), B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse_d(buf, offs) (c4, offs) = parse(buf, offs, 'uint16') (c5, offs) = parse(buf, offs, 'double') (c6, offs) = parse(buf, offs, 'uint8') (c7, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') d2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'float') d2.append(val) (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'int16') d6 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int8') d6.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('>B', data[pointer:pointer + 1])[0] d2 = list(struct.unpack('>5h', data[pointer + 1:pointer + 11])) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2) = struct.unpack('>bq', data[pointer:pointer + 9]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = struct.unpack('>f', data[pointer:pointer + 4])[0] f2 = struct.unpack('>II', data[pointer + 4:pointer + 12]) b2 = ''.join(map(str, struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0]]))) b2 = b2.replace(""'"", '')[1::2] (b3, b4) = struct.unpack('>hf', data[pointer + 12:pointer + 18]) f5 = struct.unpack('>H', data[pointer + 18:pointer + 20]) b5 = parse_c(data, f5[0]) b6 = struct.unpack('>H', data[pointer + 20:pointer + 22])[0] b7 = ''.join(map(str, struct.unpack('>2c', data[pointer + 22:pointer + 24]))) b7 = b7.replace(""'"", '')[1::2] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): a1 = struct.unpack('>H', data[pointer:pointer + 2])[0] f2 = struct.unpack('>H', data[pointer + 2:pointer + 4]) a2 = parse_b(data, f2[0]) f3 = struct.unpack('>HH', data[pointer + 4:pointer + 8]) a3 = list() for i in range(f3[0]): a3.append(parse_d(data, f3[1] + i * 11)) a4 = struct.unpack('>H', data[pointer + 8:pointer + 10])[0] a5 = list(struct.unpack('>6q', data[pointer + 10:pointer + 58])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_f(data, pointer): f1 = struct.unpack('bdf', data[pointer:pointer + 13]) return {'F1': f1, 'F2': f2, 'F3': f3} def parse_e(data, pointer): (e1, e2) = struct.unpack('>ff', data[pointer:pointer + 8]) e3 = list(struct.unpack('>5B', data[pointer + 8:pointer + 13])) (e4, e5) = struct.unpack('>bh', data[pointer + 13:pointer + 16]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def parse_d(data, pointer): d1 = struct.unpack('>q', data[pointer:pointer + 8])[0] f2 = struct.unpack('>II', data[pointer + 8:pointer + 16]) d2 = list(struct.unpack(f'>{f2[0]}Q', data[f2[1]:f2[1] + f2[0] * 8])) (d3, d4, d5) = struct.unpack('>iiH', data[pointer + 16:pointer + 26]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def parse_c(data, pointer): (f1, f2) = struct.unpack('>II', data[pointer:pointer + 8]) (c1, c2) = (parse_d(data, f1), parse_e(data, f2)) (c3, c4, c5) = struct.unpack('>bBb', data[pointer + 8:pointer + 11]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): (b1, b2) = struct.unpack('>Bf', data[pointer:pointer + 5]) f3 = struct.unpack('>IH', data[pointer + 5:pointer + 11]) b3 = ''.join(map(str, struct.unpack(f'>{f3[0]}c', data[f3[1]:f3[1] + f3[0]]))) b3 = b3.replace(""'"", '')[1::2] return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>I', data[f1[1] + 4 * i:f1[1] + 4 + 4 * i]) a1.append(parse_b(data, f11[0])) (a2, a3) = struct.unpack('>hq', data[pointer + 4:pointer + 14]) a4 = parse_c(data, pointer + 14) a5 = struct.unpack('>B', data[pointer + 25:pointer + 26])[0] a6 = parse_f(data, pointer + 26) a7 = list(struct.unpack('>5B', data[pointer + 39:pointer + 44])) a8 = struct.unpack('>f', data[pointer + 44:pointer + 48])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d', float='f') def parse(buf, offs, ty): return (unpack_from(f'>{FMT[ty]}', buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for i in range(3): (a1_addr, _) = parse(buf, offs, 'uint32') (val, _) = parse_b(buf, a1_addr) offs += 4 a1.append(val) (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse(buf, offs, 'uint8') (a4, offs) = parse(buf, offs, 'uint8') (a5_size, offs) = parse(buf, offs, 'uint32') (a5_offs, offs) = parse(buf, offs, 'uint16') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'char') a5.append(val.decode()) (a6_addr, _) = parse(buf, offs, 'uint32') (a6, _) = parse_c(buf, a6_addr) offs += 4 (a7, offs) = parse(buf, offs, 'int64') (a8, offs) = parse(buf, offs, 'int8') q = dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=''.join(a5), A6=a6, A7=a7, A8=a8) return (q, offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'int64') (b3, offs) = parse(buf, offs, 'int32') (b4, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2_addr, _) = parse(buf, offs, 'uint16') (c2, _) = parse_d(buf, c2_addr) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint16') d1.append(val) (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint8') d2.append(val) (d3, offs) = parse(buf, offs, 'uint64') (d4, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def un_pack(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def unpack_a(buf, offs): a1 = [] for _ in range(2): (c_offset, offs) = un_pack(buf, offs, 'uint32') (c, _) = unpack_b(buf, c_offset) a1.append(c) (a2, offs) = un_pack(buf, offs, 'uint8') (a3_offset, offs) = un_pack(buf, offs, 'uint16') a3 = unpack_e(buf, a3_offset) (a4, offs) = un_pack(buf, offs, 'int64') (a5, offs) = un_pack(buf, offs, 'uint64') (a6, offs) = un_pack(buf, offs, 'uint32') return ({'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6}, offs) def unpack_b(buf, offs): (b1, offs) = un_pack(buf, offs, 'float') (b2, offs) = unpack_c(buf, offs) (b3, offs) = un_pack(buf, offs, 'int32') (b4, offs) = un_pack(buf, offs, 'int32') (b5, offs) = un_pack(buf, offs, 'int16') (b6, offs) = un_pack(buf, offs, 'int8') return ({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6}, offs) def unpack_c(buf, offs): (c1, offs) = un_pack(buf, offs, 'float') (c2_size, offs) = un_pack(buf, offs, 'uint32') (c2_offs, offs) = un_pack(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = un_pack(buf, c2_offs, 'uint8') c2.append(val) (c3, offs) = un_pack(buf, offs, 'uint8') (c4, offs) = unpack_d(buf, offs) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def unpack_d(buf, offs): (d1, offs) = un_pack(buf, offs, 'int16') (d2, offs) = un_pack(buf, offs, 'float') (d3, offs) = un_pack(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def unpack_e(buf, offs): e1 = [] for _ in range(3): (val, offs) = un_pack(buf, offs, 'double') e1.append(val) (e2, offs) = un_pack(buf, offs, 'float') (e3_size, offs) = un_pack(buf, offs, 'uint16') (e3_offs, offs) = un_pack(buf, offs, 'uint32') e3 = [] for _ in range(e3_size): (val, e3_offs) = un_pack(buf, e3_offs, 'int64') e3.append(val) return dict(E1=e1, E2=e2, E3=e3) def main(buffer): return unpack_a(buffer, 5)[0]" "import struct AFORMAT = '>IIQBdiB5f' BFORMAT = '>QH' CFORMAT = '>bBHIdI' DFORMAT = '>2HH' EFORMAT = '>HbQfb' def unpack_a(raw_data): result = {} size = struct.calcsize(AFORMAT) b_size = struct.calcsize(BFORMAT) data = struct.unpack(AFORMAT, raw_data[4 + b_size:size + 4 + b_size]) a1 = unpack_b(raw_data) array_size = data[0] array_address = data[1] a2 = unpack_char_array(raw_data, array_address, array_size) for i in range(len(a2)): a2[i] = a2[i].decode('utf-8') a2 = ''.join(a2) a3 = data[2] a4 = data[3] a5 = data[4] a6 = data[5] a7 = data[6] a8 = list(data[7:]) result['A1'] = a1 result['A2'] = a2 result['A3'] = a3 result['A4'] = a4 result['A5'] = a5 result['A6'] = a6 result['A7'] = a7 result['A8'] = a8 return result def unpack_b(raw_data): size = struct.calcsize(BFORMAT) data = struct.unpack(BFORMAT, raw_data[4:size + 4]) c_address = data[1] b1 = data[0] b2 = unpack_c(raw_data, c_address) return {'B1': b1, 'B2': b2} def unpack_c(raw_data, address): size = struct.calcsize(CFORMAT) data = struct.unpack_from(CFORMAT, raw_data[:address + size], address) c1 = data[0] c2 = data[1] d_array_size = data[2] d_array_address = data[3] c3 = unpack_d_array(raw_data, d_array_address, d_array_size) c4 = data[4] c5 = data[5] c6 = unpack_e(raw_data, address + struct.calcsize(CFORMAT)) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def unpack_d_array(raw_data, address, amount): size = struct.calcsize(DFORMAT) result = [] for i in range(amount): sub_data = raw_data[:address + size * (i + 1)] data = struct.unpack_from(DFORMAT, sub_data, address + size * i) d1 = list(data[:2]) d2 = data[2] result.append({'D1': d1, 'D2': d2}) return result def unpack_e(raw_data, address): size = struct.calcsize(EFORMAT) data = struct.unpack_from(EFORMAT, raw_data[:address + size], address) (e1, e2, e3, e4, e5) = data return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def unpack_char_array(raw_data, address, size): format = '>' + str(size) + 'c' return list(struct.unpack_from(format, raw_data[:address + size], address)) def main(raw_data): return unpack_a(raw_data)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 79: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 9)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 8)} temp = unpack('LHH4QLHLLBbB', file[a_adr:a_adr + 57]) (b['B1'], uint64_size, uint64_adr, *uint64_arr, d_adrs_size, d_adrs_adr, uint64_size_1, uint64_adr_1, a['A4'], a['A5'], a['A6']) = temp c['C2'] = list(uint64_arr) temp = unpack(f'>{uint64_size}Q', file[uint64_adr:uint64_adr + uint64_size * 8]) c['C1'] = list(temp) temp = unpack(f'>{uint64_size_1}Q', file[uint64_adr_1:uint64_adr_1 + uint64_size_1 * 8]) a['A3'] = list(temp) d_adrs = unpack(f'>{d_adrs_size}L', file[d_adrs_adr:d_adrs_adr + d_adrs_size * 4]) a['A2'] = [] for d_adr in d_adrs: temp = unpack('>fbHL', file[d_adr:d_adr + 11]) (d['D1'], d['D2'], d['D3'], d['D4']) = temp a['A2'].append(d.copy()) b['B2'] = c a['A1'] = b return a" "import struct def main(x): f = dict() pos1 = struct.unpack('>H', x[6:8])[0] a1 = [] for i in range(0, struct.unpack('>H', x[4:6])[0]): pos2 = struct.unpack('>I', x[pos1:pos1 + 4])[0] b1 = struct.unpack('>I', x[pos2:pos2 + 4])[0] pos3 = struct.unpack('>H', x[pos2 + 4:pos2 + 6])[0] c1 = struct.unpack('>Q', x[pos3:pos3 + 8])[0] c2 = struct.unpack('>Q', x[pos3 + 8:pos3 + 16])[0] a1.append({'B1': b1, 'B2': {'C1': c1, 'C2': c2}}) pos1 += 4 f['A1'] = a1 f['A2'] = struct.unpack('>I', x[8:12])[0] pos1 = struct.unpack('>I', x[12:16])[0] d1 = struct.unpack('>B', x[pos1:pos1 + 1])[0] e1 = struct.unpack('>I', x[pos1 + 1:pos1 + 5])[0] e2 = struct.unpack('>d', x[pos1 + 5:pos1 + 13])[0] d3 = str(struct.unpack('>4s', x[pos1 + 13:pos1 + 17])[0])[2:-1] f['A3'] = {'D1': d1, 'D2': {'E1': e1, 'E2': e2}, 'D3': d3} di = struct.unpack('>H', x[16:18])[0] dis = '>' + str(di) + 's' pos1 = struct.unpack('>H', x[18:20])[0] f['A4'] = str(struct.unpack(dis, x[pos1:pos1 + di])[0])[2:-1] f['A5'] = struct.unpack('>Q', x[20:28])[0] f['A6'] = list(struct.unpack('>8B', x[28:36])) sf = dict() sf['F1'] = struct.unpack('>f', x[36:40])[0] sf['F2'] = list(struct.unpack('>3d', x[40:64])) sf['F3'] = struct.unpack('>f', x[64:68])[0] sf['F4'] = struct.unpack('>f', x[68:72])[0] sf['F5'] = struct.unpack('>h', x[72:74])[0] sf['F6'] = struct.unpack('>d', x[74:82])[0] sf['F7'] = struct.unpack('>Q', x[82:90])[0] f['A7'] = sf return f" "import struct def structA(data, pointer): (a1,) = struct.unpack('dqBL', file[a_adr:a_adr + 21]) (a['A1'], a['A2'], a['A3'], b_adr) = temp temp = unpack('>HHLHLH8BqB', file[b_adr:b_adr + 33]) (c_adr, b['B2'], int16_size, int16_adr, uint8_size, uint8_adr, *uint8_arr, b['B6'], b['B7']) = temp temp = unpack(f'>{int16_size}h', file[int16_adr:int16_adr + int16_size * 2]) b['B3'] = list(temp) temp = unpack(f'>{uint8_size}B', file[uint8_adr:uint8_adr + uint8_size]) b['B4'] = list(temp) b['B5'] = list(uint8_arr) temp = unpack('>LHHLHHLHHLHbqL', file[c_adr:c_adr + 43]) (c['C1'], c['C2'], *d_strs, c['C4'], c['C5'], c['C6']) = temp c['C3'] = [] (d['D1'], uint8_size, uint8_adr) = d_strs[0:3] temp = unpack(f'>{uint8_size}B', file[uint8_adr:uint8_adr + uint8_size]) d['D2'] = list(temp) c['C3'].append(d.copy()) (d['D1'], uint8_size, uint8_adr) = d_strs[3:6] temp = unpack(f'>{uint8_size}B', file[uint8_adr:uint8_adr + uint8_size]) d['D2'] = list(temp) c['C3'].append(d.copy()) (d['D1'], uint8_size, uint8_adr) = d_strs[6:9] temp = unpack(f'>{uint8_size}B', file[uint8_adr:uint8_adr + uint8_size]) d['D2'] = list(temp) c['C3'].append(d.copy()) a['A4'] = b b['B1'] = c return a" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, _) = parse_b(buf, a1_offs) (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'char') a2.append(val.decode()) (a3, offs) = parse(buf, offs, 'int16') (a4, offs) = parse(buf, offs, 'int64') (a5, offs) = parse(buf, offs, 'uint32') (a6, offs) = parse(buf, offs, 'uint16') (a7, offs) = parse_e(buf, offs) (a8, offs) = parse(buf, offs, 'double') return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse(buf, offs, 'double') b3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') (val_c, _) = parse_c(buf, val) b3.append(val_c) (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'char') b4.append(val.decode()) (b5, offs) = parse(buf, offs, 'uint16') (b6, offs) = parse(buf, offs, 'int8') (b7, offs) = parse_d(buf, offs) return (dict(B1=b1, B2=b2, B3=b3, B4=''.join(b4), B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') e2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint64') e2.append(val) (e3, offs) = parse(buf, offs, 'int8') e4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint8') e4.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import unpack def main(file): signature = bytes([227, 76, 75, 66, 80]) a_adr = file.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(6)} temp = unpack('I') b = getB(data, temp)[0] A['A1'].append(b) (A['A2'], iterator) = getNext(data, iterator, 1, '>b') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A3'] = getC(data, temp)[0] (A['A4'], iterator) = getNext(data, iterator, 4, '>f') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A5'] = getE(data, temp)[0] return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 4, '>I') (B['B2'], iterator) = getNext(data, iterator, 2, '>h') (B['B3'], iterator) = getNext(data, iterator, 1, '>B') (B['B4'], iterator) = getNext(data, iterator, 1 * 2, '>2s') B['B4'] = B['B4'].decode('ascii') (B['B5'], iterator) = getNext(data, iterator, 4, '>I') (B['B6'], iterator) = getNext(data, iterator, 4, '>i') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') C['C2'] = getD(data, temp)[0] (C['C3'], iterator) = getNext(data, iterator, 1, '>b') (C['C4'], iterator) = getNext(data, iterator, 8, '>d') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNextArr(data, iterator, 1 * 2, '>2b') (D['D2'], iterator) = getNextArr(data, iterator, 1 * 5, '>5b') (D['D3'], iterator) = getNext(data, iterator, 8, '>q') return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 1, '>B') (legth, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') E['E2'] = getNextArr(data, temp, legth * 8, f'>{legth}d')[0] (E['E3'], iterator) = getNext(data, iterator, 1, '>b') return (E, iterator) def main(data): return getA(data, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('double', data, ofs) (D2, ofs) = parse('uint8', data, ofs) return (dict(D1=D1, D2=D2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) (C2, ofs) = parse('uint32', data, ofs) (C3, ofs) = parse('uint16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): B1 = '' (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint16', data, ofs) for i in range(B1_size): (elem, B1_adr) = parse('char', data, B1_adr) B1 += elem.decode() (B2, ofs) = parse('double', data, ofs) (B3, ofs) = parse('int64', data, ofs) (B4, ofs) = parse('int32', data, ofs) (B5, ofs) = parse('uint8', data, ofs) (B6_adr, ofs) = parse('uint16', data, ofs) (B6, elem) = struct_C(data, B6_adr) (B7, ofs) = parse('int32', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6, B7=B7), ofs) def struct_A(data, ofs): (A1, ofs) = struct_B(data, ofs) A2 = '' for i in range(4): (elem, ofs) = parse('char', data, ofs) A2 += elem.decode() (A3, ofs) = parse('float', data, ofs) A4 = [] for i in range(5): (D_adr, ofs) = parse('uint32', data, ofs) (elem, lop) = struct_D(data, D_adr) A4.append(elem) A5 = [] for i in range(5): (elem, ofs) = parse('uint64', data, ofs) A5.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), ofs) def main(data): return struct_A(data, 3)[0]" "import struct def main(data): A = struct.unpack_from('>H4Q2IH', data, offset=5) B = struct.unpack_from('>fbHqQ', data, offset=A[0]) C = [[], []] C[0] = struct.unpack_from('>8hIf5H', data, offset=A[5]) C[1] = struct.unpack_from('>8hIf5H', data, offset=A[6]) D = struct.unpack_from('>fIQB', data, offset=A[7]) return {'A1': {'B1': B[0], 'B2': B[1], 'B3': B[2], 'B4': B[3], 'B5': B[4]}, 'A2': [A[1], A[2], A[3], A[4]], 'A3': [{'C1': [C[0][0], C[0][1], C[0][2], C[0][3], C[0][4], C[0][5], C[0][6], C[0][7]], 'C2': C[0][8], 'C3': C[0][9], 'C4': [C[0][10], C[0][11], C[0][12], C[0][13], C[0][14]]}, {'C1': [C[1][0], C[1][1], C[1][2], C[1][3], C[1][4], C[1][5], C[1][6], C[1][7]], 'C2': C[1][8], 'C3': C[1][9], 'C4': [C[1][10], C[1][11], C[1][12], C[1][13], C[1][14]]}], 'A4': {'D1': D[0], 'D2': D[1], 'D3': D[2], 'D4': D[3]}}" "import struct def structA(data, pointer): (f1,) = struct.unpack('>H', data[pointer:pointer + 2]) a1 = structB(data, f1) a2 = structD(data, pointer + 2) (a3,) = struct.unpack('>B', data[pointer + 70:pointer + 71]) (a4,) = struct.unpack('>I', data[pointer + 71:pointer + 75]) (a5,) = struct.unpack('>Q', data[pointer + 75:pointer + 83]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def structB(data, pointer): (b1,) = struct.unpack('>d', data[pointer:pointer + 8]) (b2,) = struct.unpack('>b', data[pointer + 8:pointer + 9]) f3 = struct.unpack('>IH', data[pointer + 9:pointer + 15]) b3 = [] adr_c = struct.unpack(f'>{f3[0]}H', data[f3[1]:f3[1] + f3[0] * 2]) count = f3[0] for i in range(count): ff3 = structC(data, adr_c[0] + i * 6) b3.append(ff3) f4 = struct.unpack('>HI', data[pointer + 15:pointer + 21]) b4 = list(struct.unpack(f'>{f4[0]}c', data[f4[1]:f4[1] + f4[0]])) char4 = '' for i in range(len(b4)): char4 += chr(b4[i][0]) (b5,) = struct.unpack('>q', data[pointer + 21:pointer + 29]) f6 = struct.unpack('>IH', data[pointer + 29:pointer + 35]) b6 = list(struct.unpack(f'>{f6[0]}H', data[f6[1]:f6[1] + f6[0] * 2])) (b7,) = struct.unpack('>I', data[pointer + 35:pointer + 39]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': char4, 'B5': b5, 'B6': b6, 'B7': b7} def structC(data, pointer): (c1,) = struct.unpack('>H', data[pointer:pointer + 2]) (c2,) = struct.unpack('>f', data[pointer + 2:pointer + 6]) return {'C1': c1, 'C2': c2} def structD(data, pointer): (d1,) = struct.unpack('>i', data[pointer:pointer + 4]) (d2,) = struct.unpack('>h', data[pointer + 4:pointer + 6]) (d3,) = struct.unpack('>I', data[pointer + 6:pointer + 10]) d4 = list(struct.unpack(f'>4d', data[pointer + 10:pointer + 42])) (d5,) = struct.unpack('>d', data[pointer + 42:pointer + 50]) (d6,) = struct.unpack('>d', data[pointer + 50:pointer + 58]) (d7,) = struct.unpack('>H', data[pointer + 58:pointer + 60]) (d8,) = struct.unpack('>Q', data[pointer + 60:pointer + 68]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def main(data): return structA(data, 4)" "import struct def main(data): A = struct.unpack_from('>QB2IbQ2IibdIHd2I', data, offset=5) A3 = list(struct.unpack_from('>' + str(A[14]) + 'i', data, offset=A[15])) B3 = list(struct.unpack_from('>' + str(A[11]) + 'h', data, offset=A[12])) C2 = list(struct.unpack_from('>' + str(A[2]) + 'H', data, offset=A[3])) D_list = [] for i in range(A[2]): D = struct.unpack_from('>qI3d', data, offset=C2[i]) D_list.append({'D1': D[0], 'D2': D[1], 'D3': D[2], 'D4': [D[3], D[4]]}) return {'A1': A[0], 'A2': {'B1': {'C1': A[1], 'C2': D_list}, 'B2': {'E1': A[4], 'E2': A[5], 'E3': A[6], 'E4': A[7], 'E5': A[8], 'E6': A[9], 'E7': A[10]}, 'B3': B3, 'B4': A[13]}, 'A3': A3}" "import struct def main(bs): magic_bytes = b'CEKO.' A = struct.Struct('> I 8c H B b I i II HI f q II I') C = struct.Struct('> 7f H b') a = A.unpack_from(bs, len(magic_bytes)) c_structs = [C.unpack_from(bs, a[15] + i * C.size) for i in range(int(a[14]))] return {'A1': a[0], 'A2': b''.join(a[1:9]).decode(), 'A3': a[9], 'A4': {'B1': a[10], 'B2': a[11], 'B3': a[12], 'B4': a[13], 'B5': [{'C1': list(c[:7]), 'C2': c[7], 'C3': c[8]} for c in c_structs], 'B6': list(struct.unpack_from(f'> {a[16]}b', bs, a[17])), 'B7': {'D1': a[-5], 'D2': a[-4]}}, 'A5': list(struct.unpack_from(f'> {a[-3]}h', bs, a[-2])), 'A6': a[-1]}" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e1 = reader.read_int8() e2 = reader.read_int32() return dict(E1=e1, E2=e2) def read_d(reader: BinaryReader): d1 = reader.read_int8() d2 = reader.read_int16() d3 = reader.read_int16() return dict(D1=d1, D2=d2, D3=d3) def read_c(reader: BinaryReader): c1 = reader.read_int8() c2 = reader.read_int8() c3 = [read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader), read_d(reader)] c4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint64(), structure_size=8) c5 = read_e(reader) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def read_b(reader: BinaryReader): b1 = reader.read_int8() b2 = reader.read_uint64() return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_char().decode('ascii'))) a2 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_b(reader))[0] a3 = read_c(reader) a4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint16(), structure_size=2) return dict(A1=a1, A2=a2, A3=a3, A4=a4) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 4, '>i') (A['A2'], iterator) = getB(data, iterator) (legth, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A3'] = getNextArr(data, temp, legth * 4, f'>{legth}f')[0] (A['A4'], iterator) = getNext(data, iterator, 1, '>b') (A['A5'], iterator) = getNext(data, iterator, 4, '>f') (A['A6'], iterator) = getNext(data, iterator, 2, '>H') return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 1, '>B') (B['B2'], iterator) = getC(data, iterator) (B['B3'], iterator) = getNext(data, iterator, 2, '>H') return (B, iterator) def getC(data, iterator): C = {} (legth, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') C['C1'] = [] for i in range(legth): (a, temp) = getD(data, temp) C['C1'].append(a) (temp, iterator) = getNext(data, iterator, 4, '>I') C['C2'] = getE(data, temp)[0] return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 4, '>I') (legth, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') D['D2'] = getNextArr(data, temp, legth * 2, f'>{legth}H')[0] (D['D3'], iterator) = getNext(data, iterator, 8, '>d') (D['D4'], iterator) = getNext(data, iterator, 2, '>h') return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 2, '>H') (E['E2'], iterator) = getNext(data, iterator, 2, '>h') (E['E3'], iterator) = getNext(data, iterator, 2, '>H') (E['E4'], iterator) = getNext(data, iterator, 8, '>q') (E['E5'], iterator) = getNextArr(data, iterator, 2 * 8, '>8H') return (E, iterator) def main(data): return getA(data, 3)" "import struct def uint16uint32uint64(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'Q' * size, s[add:add + 8 * size]) return list(a) def uint32uint32uint8(s, pointer): size = struct.unpack('>I', s[pointer:pointer + 4])[0] add = struct.unpack('>I', s[pointer + 4:pointer + 8])[0] a = struct.unpack('>' + 'B' * size, s[add:add + 1 * size]) return list(a) def uint16uint16int16(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>H', s[pointer + 2:pointer + 4])[0] a = struct.unpack('>' + 'h' * size, s[add:add + 2 * size]) return list(a) def D_structure(s, pointer): result = [] for i in range(0, 8): result.append({'D1': struct.unpack('>f', s[pointer:pointer + 4])[0], 'D2': struct.unpack('>B', s[pointer + 4:pointer + 5])[0], 'D3': struct.unpack('>H', s[pointer + 5:pointer + 7])[0], 'D4': struct.unpack('>B', s[pointer + 7:pointer + 8])[0]}) pointer += 8 return result def main(s): c3 = struct.unpack('>H', s[52:54])[0] c5 = struct.unpack('>H', s[74:76])[0] out_dict = {'A1': struct.unpack('>q', s[5:13])[0], 'A2': struct.unpack('>d', s[13:21])[0], 'A3': struct.unpack('>f', s[21:25])[0], 'A4': struct.unpack('>H', s[25:27])[0], 'A5': struct.unpack('>I', s[27:31])[0], 'A6': {'B1': struct.unpack('>I', s[31:35])[0], 'B2': struct.unpack('>B', s[35:36])[0], 'B3': struct.unpack('>f', s[36:40])[0], 'B4': struct.unpack('>H', s[40:42])[0], 'B5': {'C1': struct.unpack('>Q', s[42:50])[0], 'C2': struct.unpack('>H', s[50:52])[0], 'C3': D_structure(s, c3), 'C4': uint16uint32uint64(s, 68), 'C5': {'E1': uint16uint16int16(s, c5), 'E2': uint32uint32uint8(s, c5 + 4)}, 'C6': struct.unpack('>h', s[76:78])[0], 'C7': struct.unpack('>h', s[78:80])[0]}, 'B6': struct.unpack('>q', s[80:88])[0], 'B7': struct.unpack('>q', s[88:96])[0]}} return out_dict" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_a(reader): a_1 = read_b(reader) a_2 = reader.read_uint16() a_3 = reader.read_float() a_4 = reader.read_double() a_5 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_c(reader)) return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def read_b(reader): b_1 = reader.read_double() b_2 = reader.read_int32() b_3 = reader.read_uint32() b_4 = '' for i in range(8): b_4 += reader.read_char().decode('ascii') return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4) def read_c(reader): c_1 = reader.read_float() c_2 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader))) c_3 = reader.read_int64() c_4 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_int64()) c_5 = [reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8(), reader.read_int8()] c_6 = reader.read_uint8() c_7 = reader.read_uint16() return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4, C5=c_5, C6=c_6, C7=c_7) def read_d(reader): d_1 = reader.read_int8() d_2 = reader.read_int16() d_3 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_int8()) return dict(D1=d_1, D2=d_2, D3=d_3) def main(data): reader = BinaryReader(data) reader.read('ccc') return read_a(reader)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A1'] = getNext(data, temp, length, f'>{length}s')[0] A['A1'] = A['A1'].decode('ascii') (A['A2'], iterator) = getNext(data, iterator, 2, '>h') (A['A3'], iterator) = getNext(data, iterator, 1, '>B') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A4'] = getB(data, temp)[0] (temp, iterator) = getNext(data, iterator, 2, '>H') A['A5'] = getC(data, temp)[0] A['A6'] = [] for i in range(3): (a, iterator) = getD(data, iterator) A['A6'].append(a) (A['A7'], iterator) = getNext(data, iterator, 8, '>Q') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A8'] = getE(data, temp)[0] return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 8, '>q') (B['B2'], iterator) = getNext(data, iterator, 1, '>b') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 8, '>q') (C['C2'], iterator) = getNext(data, iterator, 2, '>H') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 8, '>q') (D['D2'], iterator) = getNext(data, iterator, 1, '>b') D['D3'] = [] for i in range(6): (d, iterator) = getNext(data, iterator, 2, '>h') D['D3'].append(d) return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 1, '>B') (E['E2'], iterator) = getNext(data, iterator, 2, '>h') (E['E3'], iterator) = getNext(data, iterator, 8, '>q') (E['E4'], iterator) = getNext(data, iterator, 4, '>I') (E['E5'], iterator) = getNext(data, iterator, 8, '>Q') (E['E6'], iterator) = getNext(data, iterator, 1, '>B') E['E7'] = [] for i in range(4): (e, iterator) = getNext(data, iterator, 2, '>h') E['E7'].append(e) (E['E8'], iterator) = getNext(data, iterator, 2, '>H') return (E, iterator) def main(data): return getA(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'int64') (a4, offs) = parse(buf, offs, 'uint8') (a5, offs) = parse_b(buf, offs) (a6_offs, offs) = parse(buf, offs, 'uint16') offs2 = offs (a6, offs) = parse_d(buf, a6_offs) (a7_size, offs) = parse(buf, offs2, 'uint32') (a7_offs, offs) = parse(buf, offs, 'uint16') a7 = [] for _ in range(a7_size): (val, a7_offs) = parse(buf, a7_offs, 'int8') a7.append(val) (a8, offs) = parse(buf, offs, 'int32') return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): b1 = [] for _ in range(5): (b1_offs, offs) = parse(buf, offs, 'uint32') (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'uint32') (b5, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'int16') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import unpack_from, calcsize from enum import Enum class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def readA(reader: BinaryReader): A1 = reader.read(Types.double) A2 = reader.read(Types.int32) A3 = reader.read(Types.uint32) A4 = reader.read(Types.int32) A5 = reader.read(Types.float) A6 = readB(reader) f_addr = reader.read(Types.uint16) A7 = readF(BinaryReader(source=reader.source, offset=f_addr)) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7) def readB(reader: BinaryReader): B1 = reader.read(Types.int16) B2 = readC(reader) return dict(B1=B1, B2=B2) def readC(reader: BinaryReader): d_addr = [reader.read(Types.uint16), reader.read(Types.uint16), reader.read(Types.uint16)] C1 = [readD(BinaryReader(source=reader.source, offset=d_addr[0])), readD(BinaryReader(source=reader.source, offset=d_addr[1])), readD(BinaryReader(source=reader.source, offset=d_addr[2]))] arr_len = reader.read(Types.uint16) arr_addr = reader.read(Types.uint16) C2 = masserC2(arr_len, arr_addr, reader.source) C3 = reader.read(Types.float) C4 = readE(reader) C5 = reader.read(Types.uint64) C6 = reader.read(Types.int16) C7 = reader.read(Types.int16) C8 = reader.read(Types.uint64) return dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7, C8=C8) def readD(reader: BinaryReader): D1 = reader.read(Types.uint32) D2 = reader.read(Types.int16) return dict(D1=D1, D2=D2) def readE(reader: BinaryReader): E1 = reader.read(Types.uint32) E2 = reader.read(Types.int16) E3 = [reader.read(Types.uint8), reader.read(Types.uint8), reader.read(Types.uint8), reader.read(Types.uint8), reader.read(Types.uint8)] E4 = reader.read(Types.int16) E5 = reader.read(Types.int64) E6 = reader.read(Types.int64) return dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6) def readF(reader: BinaryReader): F1 = reader.read(Types.uint32) F2 = [reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8)] F3 = reader.read(Types.uint8) return dict(F1=F1, F2=F2, F3=F3) def masserC2(size, offset, source): reader = BinaryReader(source, offset) res = [] while reader.offset < offset + size * 4: res.append(reader.read(Types.uint32)) return res def main(data): reader = BinaryReader(source=data, offset=5) return readA(reader)" "from struct import unpack def main(file): signature = bytes([72, 83, 69, 223]) a_adr = file.find(signature) + len(signature) a = {f'A{i + 1}': None for i in range(5)} temp = unpack('>fBd', file[a_adr:a_adr + 13]) (a['A1'], a['A2'], a['A3']) = temp a['A5'] = unpack('>B', file[a_adr + 102:a_adr + 103])[0] b = {f'B{i + 1}': None for i in range(8)} temp = unpack('>HfH', file[a_adr + 13:a_adr + 21]) (b['B1'], b['B2'], c_adr) = temp temp = unpack('>f7bh2I', file[a_adr + 81:a_adr + 102]) (b['B5'], *b['B6'], b['B7'], arr_size, arr_adr) = temp temp = unpack(f'>{arr_size}b', file[arr_adr:arr_adr + arr_size]) b['B8'] = list(temp) temp = unpack('>I5s', file[c_adr:c_adr + 9]) b['B3'] = {'C1': temp[0], 'C2': str(temp[1], 'utf8')} b['B4'] = [] for i in range(6): temp = unpack('>fiH', file[a_adr + 21 + 10 * i:a_adr + 21 + 10 * (i + 1)]) b['B4'].append({'D1': temp[0], 'D2': temp[1], 'D3': temp[2]}) a['A4'] = b return a" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'double') a3 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'float') a3.append(val) return ({'A1': a1, 'A2': a2, 'A3': a3}, offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (c_offset, b1_offs) = parse(buf, b1_offs, 'uint32') c = parse_c(buf, c_offset) b1.append(c) (b2, offs) = parse(buf, offs, 'float') b3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint16') b3.append(val) (b4, offs) = parse(buf, offs, 'int8') (b5, offs) = parse(buf, offs, 'uint64') (b6, offs) = parse(buf, offs, 'int32') (b7, offs) = parse_d(buf, offs) (b8, offs) = parse(buf, offs, 'uint8') return ({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8}, offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'int8') c1.append(val) (c2, offs) = parse(buf, offs, 'uint8') return {'C1': c1, 'C2': c2} def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 5)[0]" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.uint16) size2 = reader.read(Types.uint16) address2 = reader.read(Types.uint32) b2 = reader.copy(offset=address2).readWithSize(Types.char, size2) resB2 = '' for b in b2: resB2 += str(b)[2] return dict(B1=b1, B2=resB2) def readC(reader): c1 = reader.read(Types.uint8) c2 = reader.read(Types.double) c3 = reader.read(Types.int16) c4 = readD(reader.copy(reader.read(Types.uint16))) c5 = reader.read(Types.int16) c6 = reader.read(Types.uint8) c7 = readE(reader.copy(reader.read(Types.uint16))) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7) def readD(reader): d1 = reader.read(Types.int64) d2 = reader.read(Types.uint8) size3 = reader.read(Types.uint16) address3 = reader.read(Types.uint32) d3 = reader.copy(offset=address3).readWithSize(Types.uint64, size3) return dict(D1=d1, D2=d2, D3=d3) def readE(reader): e1 = reader.read(Types.uint64) e2 = [] for _ in range(5): e2.append(reader.read(Types.int16)) return dict(E1=e1, E2=e2) def main(buffer): reader = BinaryReader(offset=3, buffer=buffer) size1 = reader.read(Types.uint16) address1 = reader.read(Types.uint16) a1 = [] bReader = BinaryReader(offset=address1, buffer=buffer) for i in range(0, size1): a1.append(readB(reader.copy(bReader.read(Types.uint32)))) a2 = reader.read(Types.int8) a3 = readC(reader) a4 = reader.read(Types.uint16) a5 = reader.read(Types.uint64) a6 = reader.read(Types.uint64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint64') (a3, offs) = parse(buf, offs, 'uint32') (a4, offs) = parse_d(buf, offs) a5 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int16') a5.append(val) (a6, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'uint16') (val2, val) = parse_c(buf, val) b2.append(val2) (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'float') (d3_offs, offs) = parse(buf, offs, 'uint32') (d3, d3_offs) = parse_e(buf, d3_offs) return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') (e2_size, offs) = parse(buf, offs, 'uint32') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'double') e2.append(val) (e3, offs) = parse(buf, offs, 'uint8') e4 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint16') e4.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * def parse(buf, ty, offs): return (unpack_from(ty, buf, offs)[0], offs + calcsize(ty)) def parseA(buf, offs): (A1, offs) = parseB(buf, offs) (A2_size, offs) = parse(buf, 'H', offs) (A2_adress, offs) = parse(buf, 'H', offs) A2 = [] for i in range(A2_size): (e_adress, A2_adress) = parse(buf, 'I', A2_adress) (e, e_adress) = parseE(buf, e_adress) A2.append(e) (A3, offs) = parse(buf, 'h', offs) (A4, offs) = parse(buf, 'I', offs) (A5, offs) = parse(buf, 'H', offs) (A6, offs) = parse(buf, 'i', offs) (A7, offs) = parse(buf, 'i', offs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), offs) def parseB(buf, offs): (B1, offs) = parseC(buf, offs) (B2, offs) = parse(buf, 'B', offs) return (dict(B1=B1, B2=B2), offs) def parseC(buf, offs): C1 = [] (C1_size, offs) = parse(buf, 'H', offs) (C1_adress, offs) = parse(buf, 'H', offs) for i in range(C1_size): (c, C1_adress) = parse(buf, 'c', C1_adress) C1.append(c.decode()) (C2, offs) = parse(buf, 'i', offs) C3 = [] for i in range(2): (u8, offs) = parse(buf, 'B', offs) C3.append(u8) (C4, offs) = parse(buf, 'q', offs) (C5_adress, offs) = parse(buf, 'I', offs) (C5, C5_adress) = parseD(buf, C5_adress) (C6, offs) = parse(buf, 'B', offs) (C7, offs) = parse(buf, 'd', offs) return (dict(C1=''.join(C1), C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), offs) def parseD(buf, offs): (D1, offs) = parse(buf, 'H', offs) (D2, offs) = parse(buf, 'h', offs) (D3, offs) = parse(buf, 'd', offs) return (dict(D1=D1, D2=D2, D3=D3), offs) def parseE(buf, offs): (E1, offs) = parse(buf, 'H', offs) (E2, offs) = parse(buf, 'b', offs) E3 = [] for i in range(2): (i16, offs) = parse(buf, 'h', offs) E3.append(i16) (E4, offs) = parse(buf, 'f', offs) (E5, offs) = parse(buf, 'h', offs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5), offs) def main(buf): return parseA(buf, 3)[0]" "from struct import * mDict = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(mDict[ty], buf, offs)[0], offs + calcsize(mDict[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int32') (a2, offs) = parse(buf, offs, 'int64') (a3, offs) = parse_b(buf, offs) return {'A1': a1, 'A2': a2, 'A3': a3} def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse_c(buf, offs) (b3, offs) = parse(buf, offs, 'int8') (b4, offs) = parse(buf, offs, 'int8') (b5, offs) = parse(buf, offs, 'int8') (b6, offs) = parse(buf, offs, 'double') (b7, offs) = parse(buf, offs, 'int32') return ({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7}, offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') c2 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) c2.append(val) (c3, offs) = parse_e(buf, offs) c4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint32') c4.append(val) (val, offs) = parse(buf, offs, 'uint16') c5 = parse_f(buf, val)[0] return ({'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5}, offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int8') return ({'D1': d1, 'D2': d2}, offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2, offs) = parse(buf, offs, 'uint64') e3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') e3.append(val) (e4, offs) = parse(buf, offs, 'uint16') (e5, offs) = parse(buf, offs, 'uint64') (e6, offs) = parse(buf, offs, 'double') (e7, offs) = parse(buf, offs, 'double') e8 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') e8.append(val) return ({'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7, 'E8': e8}, offs) def parse_f(buf, offs): (f1_size, offs) = parse(buf, offs, 'uint16') (f1_offs, offs) = parse(buf, offs, 'uint32') f1 = [] for _ in range(f1_size): (val, f1_offs) = parse(buf, f1_offs, 'uint32') f1.append(val) (f2, offs) = parse(buf, offs, 'double') (f3, offs) = parse(buf, offs, 'int16') (f4, offs) = parse(buf, offs, 'double') (f5, offs) = parse(buf, offs, 'int8') return ({'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5}, offs) def main(buf): return parse_a(buf, 4)" "from typing import ByteString, Dict import struct class D: m: Dict shift: int def __init__(self, data: ByteString, start: int): self.m = dict() self.shift = start unpack_size = 4 + 6 * 4 raw = struct.unpack(' Dict: return A(data, 4).m" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 87: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 9)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 4)} e = {f'E{i}': None for i in range(1, 4)} temp = unpack('<2LbfHLLqbH', file[a_adr:a_adr + 34]) (*b_adrs, d['D1'], d['D2'], d['D3'], e_adr, a['A4'], a['A5'], a['A6'], a['A7']) = temp temp = unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') SZS = dict(char=1, int8=1, uint8=1, int16=2, uint16=2, int32=4, uint32=4, int64=8, uint64=8, float=4, double=8) pointer_ = 5 def parseA(data): A = {} global pointer_ global NAMES global SZS A['A1'] = unpack('>H', data[pointer_:pointer_ + 2])[0] pointer_ += 2 A['A2'] = unpack(NAMES['float'], data[pointer_:pointer_ + 4])[0] pointer_ += SZS['float'] A['A3'] = unpack(NAMES['int8'], data[pointer_:pointer_ + SZS['int8']])[0] pointer_ += SZS['int8'] A['A4'] = unpack(NAMES['double'], data[pointer_:pointer_ + SZS['double']])[0] pointer_ += SZS['double'] address = unpack(NAMES['uint32'], data[pointer_:pointer_ + SZS['uint32']])[0] pointer_ += SZS['uint32'] A['A5'] = parseB(data, address) A['A6'] = parseF(data) return A def parseB(data, address): global pointer_ global NAMES global SZS B = {} B['B1'] = unpack(NAMES['float'], data[address:address + SZS['float']])[0] address += SZS['float'] B['B2'] = unpack(NAMES['int16'], data[address:address + SZS['int16']])[0] address += SZS['int16'] B['B3'] = [0, 0, 0, 0] for i in range(4): (B['B3'][i], address) = parseC(data, address) size = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] address_2 = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] B['B4'] = [] for i in range(size): B['B4'].append(unpack(NAMES['uint16'], data[address_2:address_2 + SZS['uint16']])[0]) address_2 += SZS['uint16'] (B['B5'], address) = parseE(data, address) B['B6'] = unpack(NAMES['uint32'], data[address:address + SZS['uint32']])[0] return B def parseC(data, address): global NAMES global SZS C = {} C['C1'] = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] C['C2'] = unpack(NAMES['int16'], data[address:address + SZS['int16']])[0] address += SZS['int16'] (C['C3'], address) = parseD(data, address) return (C, address) def parseD(data, address): global NAMES global SZS D = {} D['D1'] = unpack(NAMES['int16'], data[address:address + SZS['int16']])[0] address += SZS['int16'] D['D2'] = [] for i in range(5): D['D2'].append(unpack(NAMES['uint8'], data[address:address + SZS['uint8']])[0]) address += SZS['uint8'] D['D3'] = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] return (D, address) def parseE(data, address): global NAMES global SZS E = {} E['E1'] = unpack(NAMES['float'], data[address:address + SZS['float']])[0] address += SZS['float'] E['E2'] = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] size = unpack(NAMES['uint32'], data[address:address + SZS['uint32']])[0] address += SZS['uint32'] address_2 = unpack(NAMES['uint16'], data[address:address + SZS['uint16']])[0] address += SZS['uint16'] E['E3'] = [] for i in range(size): E['E3'].append(unpack(NAMES['int16'], data[address_2:address_2 + SZS['int16']])[0]) address_2 += SZS['int16'] return (E, address) def parseF(data): f = {} global pointer_ global NAMES global SZS f['F1'] = unpack(NAMES['uint32'], data[pointer_:pointer_ + SZS['uint32']])[0] pointer_ += SZS['uint32'] f['F2'] = unpack(NAMES['int64'], data[pointer_:pointer_ + SZS['int64']])[0] pointer_ += SZS['int64'] f['F3'] = [] for i in range(3): f['F3'].append(unpack(NAMES['float'], data[pointer_:pointer_ + SZS['float']])[0]) pointer_ += SZS['float'] f['F4'] = unpack(NAMES['double'], data[pointer_:pointer_ + SZS['double']])[0] pointer_ += SZS['double'] return f def main(data): return parseA(data)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): new_address = reader.read_uint16() new_reader = BinaryReader(data=data, offset=new_address) values.append(read(new_reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_a(reader): a_1 = reader.read_uint32() a_2 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_b(reader)) a_3 = reader.read_uint16() return dict(A1=a_1, A2=a_2, A3=a_3) def read_b(reader): b_1 = [read_c(reader), read_c(reader)] b_2 = reader.read_float() b_3 = reader.read_uint64() b_4 = reader.read_uint32() b_5 = reader.read_int64() b_6 = reader.read_int32() b_7 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_d(reader)) b_8 = reader.read_int16() return dict(B1=b_1, B2=b_2, B3=b_3, B4=b_4, B5=b_5, B6=b_6, B7=b_7, B8=b_8) def read_c(reader): c_1 = reader.read_float() c_2 = reader.read_uint64() c_3 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) return dict(C1=c_1, C2=c_2, C3=c_3) def read_d(reader): d_1 = reader.read_int64() d_2 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint32()) d_3 = reader.read_int64() d_4 = [reader.read_int16(), reader.read_int16(), reader.read_int16()] d_5 = reader.read_int32() d_6 = reader.read_float() d_7 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) return dict(D1=d_1, D2=d_2, D3=d_3, D4=d_4, D5=d_5, D6=d_6, D7=d_7) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "from struct import * def parse(buf, ty, offs): return (unpack_from(ty, buf, offs)[0], offs + calcsize(ty)) def parseA(buf, offs): (a1, offs) = parse(buf, 'q', offs) (a2_size, offs) = parse(buf, 'H', offs) (a2_adress, offs) = parse(buf, 'I', offs) a2 = [] for i in range(a2_size): (add, a2_adress) = parseB(buf, a2_adress) a2.append(add) (a3, offs) = parse(buf, 'q', offs) a4 = [] for i in range(3): (add, offs) = parse(buf, 'c', offs) a4.append(add.decode()) (a5, offs) = parse(buf, 'b', offs) (a6_size, offs) = parse(buf, 'I', offs) (a6_adress, offs) = parse(buf, 'H', offs) a6 = [] for i in range(a6_size): (add, a6_adress) = parseD(buf, a6_adress) a6.append(add) (a7, offs) = parseE(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6, A7=a7), offs) def parseB(buf, offs): (b1, offs) = parse(buf, 'H', offs) (b2, offs) = parseC(buf, offs) return (dict(B1=b1, B2=b2), offs) def parseC(buf, offs): (c1, offs) = parse(buf, 'q', offs) (c2, offs) = parse(buf, 'b', offs) return (dict(C1=c1, C2=c2), offs) def parseD(buf, offs): (d1, offs) = parse(buf, 'I', offs) (d2, offs) = parse(buf, 'h', offs) return (dict(D1=d1, D2=d2), offs) def parseE(buf, offs): (e1, offs) = parse(buf, 'B', offs) (e2, offs) = parse(buf, 'h', offs) e3 = [] for i in range(4): (add, offs) = parse(buf, 'Q', offs) e3.append(add) (e4, offs) = parse(buf, 'h', offs) (e5, offs) = parse(buf, 'B', offs) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parseA(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse(buf, offs, 'int64') (a3, offs) = parse(buf, offs, 'int64') (a4, offs) = parse_b(buf, offs) (a5_size, offs) = parse(buf, offs, 'uint16') (a5_offs, offs) = parse(buf, offs, 'uint32') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'float') a5.append(val) (a6, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_f(buf, b2_offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'int8') (c3_offs, offs) = parse(buf, offs, 'uint32') (c3, c3_offs) = parse_d(buf, c3_offs) (c4_size, offs) = parse(buf, offs, 'uint16') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse_e(buf, c4_offs) c4.append(val) (c5_size, offs) = parse(buf, offs, 'uint16') (c5_offs, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'uint32') c5.append(val) (c6, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int8') (e2, offs) = parse(buf, offs, 'double') return (dict(E1=e1, E2=e2), offs) def parse_f(buf, offs): f1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'float') f1.append(val) (f2, offs) = parse(buf, offs, 'uint8') (f3, offs) = parse(buf, offs, 'float') (f4, offs) = parse(buf, offs, 'int16') return (dict(F1=f1, F2=f2, F3=f3, F4=f4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * def main(data): a_adress = 0 for byte in data: a_adress += 1 if byte == 65: break a = {f'A{i}': None for i in range(1, 4)} temp = unpack('>HdL', data[a_adress:a_adress + 14]) (b_adress, a['A2'], e_adress) = temp b = {f'B{i}': None for i in range(1, 6)} temp = unpack('>qHb', data[b_adress:b_adress + 11]) (b['B1'], b['B2'], b['B3']) = temp c = {f'C{i}': None for i in range(1, 7)} temp = unpack('>HhIHhiQ', data[b_adress + 11:b_adress + 35]) (c['C1'], c['C2'], ch_size, ch_adress, c['C4'], c['C5'], c['C6']) = temp temp = unpack('>LH', data[b_adress + 35:b_adress + 41]) (d_size, d_adress) = temp temp = unpack(f'>{ch_size}s', data[ch_adress:ch_adress + ch_size]) c['C3'] = str(temp[0], 'utf8') b['B5'] = [] temp = unpack(f'>{d_size}I', data[d_adress:d_adress + d_size * 4]) d_adresses = list(temp) for d_adress in d_adresses: d = {f'D{i}': None for i in range(1, 3)} temp = unpack(f'>fHI', data[d_adress:d_adress + 10]) (d['D1'], array_size, array_adress) = temp temp = unpack(f'>{array_size}b', data[array_adress:array_adress + array_size]) d['D2'] = list(temp) b['B5'].append(d) e = {f'E{i}': None for i in range(1, 8)} temp = unpack('>BBHHqhIHi', data[e_adress:e_adress + 26]) (e['E1'], e['E2'], array_size, array_adress, e['E4'], e['E5'], arr_size, arr_adress, e['E7']) = temp temp = unpack(f'>{array_size}b', data[array_adress:array_adress + array_size]) e['E3'] = list(temp) temp = unpack(f'>{arr_size}d', data[arr_adress:arr_adress + arr_size * 8]) e['E6'] = list(temp) a['A1'] = b b['B4'] = c a['A3'] = e return a" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def un_pack(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def unpack_a(buf, offs): (a1, offs) = un_pack(buf, offs, 'uint16') (a2, offs) = un_pack(buf, offs, 'uint64') a3 = [] for _ in range(2): (c_offset, offs) = un_pack(buf, offs, 'uint16') (c, _) = unpack_b(buf, c_offset) a3.append(c) (a4_offs, offs) = un_pack(buf, offs, 'uint16') (a4, a4_offs) = unpack_d(buf, a4_offs) (a5_offs, offs) = un_pack(buf, offs, 'uint32') (a5, a5_offs) = unpack_e(buf, a5_offs) (a6, offs) = un_pack(buf, offs, 'uint64') (a7, offs) = un_pack(buf, offs, 'uint32') return ({'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7}, offs) def unpack_b(buf, offs): (b1_offs, offs) = un_pack(buf, offs, 'uint16') (b1, b1_offs) = unpack_c(buf, b1_offs) (b2, offs) = un_pack(buf, offs, 'uint64') (b3, offs) = un_pack(buf, offs, 'double') (b4, offs) = un_pack(buf, offs, 'uint8') (b5, offs) = un_pack(buf, offs, 'int16') return ({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5}, offs) def unpack_c(buf, offs): (c1, offs) = un_pack(buf, offs, 'uint8') (c2_size, offs) = un_pack(buf, offs, 'uint32') (c2_offs, offs) = un_pack(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = un_pack(buf, c2_offs, 'int8') c2.append(val) (c3, offs) = un_pack(buf, offs, 'int32') (c4, offs) = un_pack(buf, offs, 'int32') (c5, offs) = un_pack(buf, offs, 'int8') (c6, offs) = un_pack(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def unpack_d(buf, offs): (d1, offs) = un_pack(buf, offs, 'int8') (d2, offs) = un_pack(buf, offs, 'uint32') return (dict(D1=d1, D2=d2), offs) def unpack_e(buf, offs): (e1_size, offs) = un_pack(buf, offs, 'uint16') (e1_offs, offs) = un_pack(buf, offs, 'uint16') e1 = [] for _ in range(e1_size): (val, e1_offs) = un_pack(buf, e1_offs, 'double') e1.append(val) (e2, offs) = un_pack(buf, offs, 'uint32') e3 = [] for _ in range(4): (val, offs) = un_pack(buf, offs, 'int32') e3.append(val) (e4, offs) = un_pack(buf, offs, 'int64') (e5, offs) = un_pack(buf, offs, 'int8') (e6, offs) = un_pack(buf, offs, 'float') (e7, offs) = un_pack(buf, offs, 'int16') (e8, offs) = un_pack(buf, offs, 'int8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7, E8=e8), offs) def main(buffer): return unpack_a(buffer, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('int16', data, ofs) D2 = [] for i in range(5): (elem, ofs) = parse('int16', data, ofs) D2.append(elem) (D3, ofs) = parse('uint32', data, ofs) (D4, ofs) = parse('double', data, ofs) (D5, ofs) = parse('uint64', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint8', data, ofs) (C2, ofs) = parse('uint32', data, ofs) (C3, ofs) = parse('uint8', data, ofs) (C4, ofs) = parse('int8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): B1 = [] (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint32', data, ofs) for i in range(B1_size): (elem, B1_adr) = struct_C(data, B1_adr) B1.append(elem) (B2, ofs) = parse('uint16', data, ofs) B3 = '' for i in range(7): (elem, ofs) = parse('char', data, ofs) B3 += elem.decode() B4 = [] (B4_size, ofs) = parse('uint16', data, ofs) (B4_adr, ofs) = parse('uint16', data, ofs) for i in range(B4_size): (elem, B4_adr) = parse('uint64', data, B4_adr) B4.append(elem) (B5, ofs) = parse('int8', data, ofs) (B6, ofs) = parse('float', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_A(data, ofs): (A1, ofs) = parse('float', data, ofs) (A2, ofs) = struct_B(data, ofs) (A3, ofs) = struct_D(data, ofs) (A4, ofs) = parse('uint32', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'double') (a4, offs) = parse(buf, offs, 'int64') (a5, offs) = parse_b(buf, offs) (a6, offs) = parse_e(buf, offs) (a7, offs) = parse(buf, offs, 'uint16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') b2 = [] for _ in range(3): (val, offs) = parse_c(buf, offs) b2.append(val) b3 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'float') b3.append(val) (b4, offs) = parse(buf, offs, 'float') (b5, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse_d(buf, offs) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') d2 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'uint8') d2.append(val) return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') e2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') e2.append(val) return (dict(E1=e1, E2=e2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct from enum import Enum class Types(Enum): type = '>' uint8 = f'{type}B' uint16 = f'{type}H' uint32 = f'{type}I' uint64 = f'{type}Q' int8 = f'{type}b' int16 = f'{type}h' int32 = f'{type}i' int64 = f'{type}q' float = f'{type}f' double = f'{type}d' char = f'{type}c' class BinaryReader: def __init__(self, source, offset): self.source = source self.offset = offset def read(self, pattern): value = struct.unpack_from(pattern.value, self.source, self.offset) self.offset += struct.calcsize(pattern.value) return value[0] def read_a(reader: BinaryReader): a1 = [] for _ in range(3): a1_offset = reader.read(Types.uint16) a1.append(read_b(BinaryReader(reader.source, a1_offset))) a2_size = reader.read(Types.uint32) a2_offset = reader.read(Types.uint32) a2 = [] a2_reader = BinaryReader(reader.source, a2_offset) for _ in range(a2_size): a2.append(read_c(BinaryReader(reader.source, a2_reader.read(Types.uint16)))) a3 = reader.read(Types.double) a4 = reader.read(Types.int8) a5 = reader.read(Types.int16) a6 = [] for _ in range(2): a6.append(reader.read(Types.uint32)) a7_offset = reader.read(Types.uint32) a7 = read_d(BinaryReader(reader.source, a7_offset)) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def read_b(reader: BinaryReader): b1 = '' for _ in range(7): b1 += str(reader.read(Types.char))[2:-1] b2 = reader.read(Types.uint32) b3 = reader.read(Types.int32) b4 = reader.read(Types.int16) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def read_c(reader: BinaryReader): c1 = reader.read(Types.int32) c2 = reader.read(Types.int64) c3 = reader.read(Types.uint16) return dict(C1=c1, C2=c2, C3=c3) def read_d(reader: BinaryReader): d1 = reader.read(Types.int32) d2 = reader.read(Types.uint16) d3 = reader.read(Types.int8) d4 = reader.read(Types.uint32) d5 = reader.read(Types.int32) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def main(data): reader = BinaryReader(data, offset=5) return read_a(reader)" "import struct def main(x): output_dict = {} c = struct.Struct('> IH HHHH i HH') d = struct.Struct('> dI') b = struct.Struct(f'> i {c.format[2:]} I {d.format[2:]}') a = struct.Struct('> xxxxIHdQ') temp1 = a.unpack_from(x, 0) output_dict['A1'] = [] output_dict['A2'] = temp1[2] output_dict['A3'] = temp1[3] for i in range(temp1[0]): offset = temp1[1] + b.size * i temp = b.unpack_from(x, offset) output_dict['A1'].append({'B1': temp[0], 'B2': {'C1': (temp[1], temp[2]), 'C2': [temp[3], temp[4], temp[5], temp[6]], 'C3': temp[7], 'C4': [temp[8], temp[9]]}, 'B3': temp[10], 'B4': {'D1': temp[11], 'D2': temp[12]}}) s_uint8 = struct.Struct('> B') c_dict = output_dict['A1'][-1]['B2'] arr_values = c_dict['C1'] c_dict['C1'] = [] for ii in range(arr_values[0]): c_dict['C1'].append(s_uint8.unpack_from(x, arr_values[1] + 1 * ii)[0]) return output_dict" "import struct def main(data): A = struct.unpack_from('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>q', data[offset:offset + 8])[0] result['D2'] = struct.unpack('>B', data[offset + 8:offset + 8 + 1])[0] result['D3'] = struct.unpack('>i', data[offset + 9:offset + 9 + 4])[0] result['D4'] = parse_array(data, offset + 13, 'f', 2) return result def parse_c(data, offset): result = dict() result['C1'] = parse_array(data, offset, 'h', 6) result['C2'] = struct.unpack('>f', data[offset + 12:offset + 12 + 4])[0] return result def parse_b(data, offset): result = dict() c_addresses = parse_array(data, offset, 'H', 2) result['B1'] = [parse_c(data, addr) for addr in c_addresses] result['B2'] = struct.unpack('>h', data[offset + 4:offset + 4 + 2])[0] result['B3'] = parse_d(data, offset + 6) (size, address) = struct.unpack('>HI', data[offset + 27:offset + 27 + 6]) result['B4'] = parse_array(data, address, 'H', size) return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>d', data[offset:offset + 8])[0] result['A2'] = parse_b(data, offset + 8) return result def main(data): return parse_a(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (val, a1_offs) = parse_b(buf, a1_offs) a1 = val (a2, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2_offs, offs) = parse(buf, offs, 'uint32') (val, b2_offs) = parse_e(buf, b2_offs) b2 = val (b3, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'double') (c3, offs) = parse(buf, offs, 'double') (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint32') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse_d(buf, c4_offs) c4.append(val) c5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int32') c5.append(val) (c6, offs) = parse(buf, offs, 'float') (c7_size, offs) = parse(buf, offs, 'uint32') (c7_offs, offs) = parse(buf, offs, 'uint16') c7 = [] for _ in range(c7_size): (val, c7_offs) = parse(buf, c7_offs, 'double') c7.append(val) (c8, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'int8') (d4, offs) = parse(buf, offs, 'float') (d5, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint64') (e2, offs) = parse(buf, offs, 'uint64') (e3, offs) = parse(buf, offs, 'uint8') (e4, offs) = parse(buf, offs, 'float') (e5, offs) = parse(buf, offs, 'uint16') e6 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int8') e6.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * def parse(x, typ, start): return (unpack_from(typ, x, start)[0], start + calcsize(typ)) def parse_a(x, start): a1 = [] for i in range(3): (B_adr, start) = parse(x, 'I', start) a1.append(parse_b(x, B_adr)[0]) (C_adr, start) = parse(x, 'H', start) a2 = parse_c(x, C_adr)[0] d_a = dict(A1=a1, A2=a2) return (d_a, start) def parse_b(x, start): (b1, start) = parse(x, 'H', start) (b2, start) = parse(x, 'B', start) d_b = dict(B1=b1, B2=b2) return (d_b, start) def parse_c(x, start): (c1, start) = parse(x, 'f', start) (c2, start) = parse(x, 'I', start) (c3, start) = parse_d(x, start) (c4, start) = parse(x, 'i', start) c5 = [] (c5_s, start) = parse(x, 'I', start) (c5_adr, start) = parse(x, 'I', start) for i in range(c5_s): (add, c5_adr) = parse(x, 'Q', c5_adr) c5.append(add) d_c = dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) return (d_c, start) def parse_d(x, start): (E_adr, start) = parse(x, 'H', start) d1 = parse_e(x, E_adr)[0] (d2, start) = parse(x, 'h', start) d_d = dict(D1=d1, D2=d2) return (d_d, start) def parse_e(x, start): e1 = [] (e1_s, start) = parse(x, 'I', start) (e1_adr, start) = parse(x, 'H', start) for i in range(e1_s): (add, e1_adr) = parse(x, 'q', e1_adr) e1.append(add) (e2, start) = parse(x, 'Q', start) e3 = [] (e3_s, start) = parse(x, 'I', start) (e3_adr, start) = parse(x, 'H', start) for i in range(e3_s): (add, e3_adr) = parse(x, 'h', e3_adr) e3.append(add) e4 = [] for i in range(6): (add, start) = parse(x, 'H', start) e4.append(add) d_e = dict(E1=e1, E2=e2, E3=e3, E4=e4) return (d_e, start) def main(x): return parse_a(x, 4)[0]" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_f(data, offset): result = dict() result['F1'] = struct.unpack('4cIdIiIHIHHQ', data) ret['A1'] = A_uint32 ret['A2'] = A_double ret_struct_B = {} ret_struct_B_struct_C = {} (C_uint32_1, C_int16, C_float, C_size_uint16_structD, C_address_uint16_structD, C_uint8_1, C_uint8_2, C_uint8_3, C_uint32_2, C_uint8) = struct.unpack_from('>IhfHHBBBIB', data, B_address_C) ret_struct_B_struct_C['C1'] = C_uint32_1 ret_struct_B_struct_C['C2'] = C_int16 ret_struct_B_struct_C['C3'] = C_float dStructMassive = [] dStructOneSize = struct.calcsize('HHhh') for dStructNum in range(0, C_size_uint16_structD): (D_uint16_size_massive, D_uint16_address_massive, D_int16_1, D_int16_2) = struct.unpack_from('>HHhh', data, C_address_uint16_structD + dStructOneSize * dStructNum) uint8_massive = list(struct.unpack_from('>' + 'B' * D_uint16_size_massive, data, D_uint16_address_massive)) sctruct_D_buffer = {} sctruct_D_buffer['D1'] = uint8_massive sctruct_D_buffer['D2'] = D_int16_1 sctruct_D_buffer['D3'] = D_int16_2 dStructMassive.append(sctruct_D_buffer) ret_struct_B_struct_C['C4'] = dStructMassive ret_struct_B_struct_C['C5'] = [C_uint8_1, C_uint8_2, C_uint8_3] ret_struct_B_struct_C['C6'] = C_uint32_2 ret_struct_B_struct_C['C7'] = C_uint8 ret_struct_B['B1'] = ret_struct_B_struct_C ret_struct_B['B2'] = B_int32 int16_massive = list(struct.unpack_from('>' + 'h' * B_size_uint32_massive, data, B_adress_uint16_massive)) ret_struct_B['B3'] = int16_massive ret_struct_B['B4'] = B_uint32 ret['A3'] = ret_struct_B uint32_massive = list(struct.unpack_from('>' + 'I' * A_size_uint16_massive, data, A_adress_uint16_massive)) ret['A4'] = uint32_massive ret['A5'] = A_uint64 return ret" "import struct offset = 4 def find(adress, size, unpack, data): global offset s = data[adress - offset:adress - offset + size] s = struct.unpack(unpack, s) return s def main(data): ans = {'A1': -0, 'A2': {'B1': 0, 'B2': 0, 'B3': '0', 'B4': -0}, 'A3': 0, 'A4': {'C1': [{'D1': 0, 'D2': [0, 0, 0], 'D3': 0, 'D4': 0, 'D5': -0, 'D6': 0, 'D7': 0}, {'D1': 0, 'D2': [0, 0], 'D3': 0, 'D4': 0, 'D5': 0, 'D6': 0, 'D7': 0}, {'D1': -0, 'D2': [0, 0], 'D3': 0, 'D4': 0, 'D5': -0, 'D6': 0, 'D7': 0}], 'C2': {'E1': -0, 'E2': 0, 'E3': [0, 0, 0, 0]}}, 'A5': 0, 'A6': 0, 'A7': 0} data1 = data[offset:] a = 22 b = 10 c = 6 d = 18 e = 7 a_str = find(offset, a, '>hHIHHHHhI', data1) ans['A1'] = a_str[0] b_str = find(a_str[1], b, '>Ihcccb', data1) ans['A2'] = {'B1': b_str[0], 'B2': b_str[1], 'B3': (b_str[2] + b_str[3] + b_str[4]).decode('utf-8'), 'B4': b_str[-1]} ans['A3'] = a_str[2] c_str = find(a_str[4], a_str[3] * d, f"">{a_str[3] * 'bHHHBbBQ'}"", data1) c_list = [] for i in range(a_str[3]): c_dict = {'D1': c_str[0], 'D2': list(find(c_str[2], c_str[1] * 2, f'>{c_str[1]}H', data1)), 'D3': c_str[3], 'D4': c_str[4], 'D5': c_str[5], 'D6': c_str[6], 'D7': c_str[7]} c_str = c_str[8:] c_list.append(c_dict) ans['A4']['C1'] = c_list e_str = find(a_str[5], e, '>hbHH', data1) ans['A4']['C2'] = {'E1': e_str[0], 'E2': e_str[1], 'E3': list(find(e_str[3], e_str[2] * 8, f'>{e_str[2]}Q', data1))} ans['A5'] = a_str[6] ans['A6'] = a_str[7] ans['A7'] = a_str[8] return ans" "import struct def main(byte_stack): dict_c = {} dict_d = {} dict_for_return = {} dict_for_return['A1'] = struct.unpack_from('H', byte_stack, offset=4)[0] size_b = struct.unpack_from('I', byte_stack, offset=6)[0] address_b = struct.unpack_from('H', byte_stack, offset=10)[0] dict_for_return['A2'] = [] for i in range(size_b): dict_b = {} dict_b['B1'] = struct.unpack_from('f', byte_stack, address_b)[0] address_b += 4 dict_b['B2'] = struct.unpack_from('H', byte_stack, offset=address_b)[0] address_b += 2 dict_for_return['A2'].append(dict_b) address_c = struct.unpack_from('I', byte_stack, offset=12)[0] dict_for_return['A3'] = dict_c dict_for_return['A4'] = dict_d dict_c['C1'] = struct.unpack_from('H', byte_stack, offset=address_c)[0] dict_c['C2'] = struct.unpack_from('b', byte_stack, offset=address_c + 2)[0] dict_c['C3'] = struct.unpack_from('H', byte_stack, offset=address_c + 3)[0] dict_c['C4'] = struct.unpack_from('h', byte_stack, offset=address_c + 5)[0] dict_c['C5'] = struct.unpack_from('H', byte_stack, offset=address_c + 7)[0] dict_c['C6'] = '' size_char = struct.unpack_from('H', byte_stack, offset=address_c + 9)[0] address_char = struct.unpack_from('H', byte_stack, offset=address_c + 11)[0] for y in range(size_char): dict_c['C6'] += struct.unpack_from('c', byte_stack, address_char)[0].decode() address_char += 1 dict_c['C7'] = struct.unpack_from('I', byte_stack, offset=address_c + 13)[0] dict_c['C8'] = struct.unpack_from('h', byte_stack, offset=address_c + 17)[0] dict_d['D1'] = [] size_uint8 = struct.unpack_from('H', byte_stack, offset=16)[0] address_uint8 = struct.unpack_from('I', byte_stack, offset=18)[0] for y in range(size_uint8): dict_d['D1'].append(struct.unpack_from('B', byte_stack, address_uint8)[0]) address_uint8 += 1 dict_d['D2'] = [] size_int64 = struct.unpack_from('H', byte_stack, offset=22)[0] address_int64 = struct.unpack_from('H', byte_stack, offset=24)[0] for y in range(size_int64): dict_d['D2'].append(struct.unpack_from('q', byte_stack, address_int64)[0]) address_int64 += 8 dict_d['D3'] = struct.unpack_from('I', byte_stack, offset=26)[0] return dict_for_return" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} A['A1'] = [] for i in range(2): (temp, iterator) = getNext(data, iterator, 2, 'f', data[pointer:pointer + 4]) (float_d_2,) = struct.unpack('>f', data[pointer + 4:pointer + 8]) (array_d,) = struct.unpack('>i', data[pointer + 8:pointer + 12]) (array_d_2,) = struct.unpack('>i', data[pointer + 12:pointer + 16]) (array_d_3,) = struct.unpack('>i', data[pointer + 16:pointer + 20]) d = [] d.append(array_d) d.append(array_d_2) d.append(array_d_3) (int8_d,) = struct.unpack('>b', data[pointer + 20:pointer + 21]) (uint16_d,) = struct.unpack('>H', data[pointer + 21:pointer + 23]) return {'D1': float_d, 'D2': float_d_2, 'D3': d, 'D4': int8_d, 'D5': uint16_d} def structC(data, pointer): (int32_c,) = struct.unpack('>i', data[pointer:pointer + 4]) (int64_c,) = struct.unpack('>q', data[pointer + 4:pointer + 12]) (uint8_c,) = struct.unpack('>B', data[pointer + 12:pointer + 13]) (uint32_c,) = struct.unpack('>I', data[pointer + 13:pointer + 17]) (uint64_c,) = struct.unpack('>Q', data[pointer + 17:pointer + 25]) return {'C1': int32_c, 'C2': int64_c, 'C3': uint8_c, 'C4': uint32_c, 'C5': uint64_c} def structB(data, pointer): (float_b,) = struct.unpack('>f', data[pointer:pointer + 4]) (int16_b,) = struct.unpack('>h', data[pointer + 4:pointer + 6]) (int16_b_2,) = struct.unpack('>h', data[pointer + 6:pointer + 8]) f2 = struct.unpack('>II', data[pointer + 8:pointer + 16]) b2 = list(struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0]])) b = '' for i in range(len(b2)): b += chr(b2[i][0]) (f_uint16,) = struct.unpack('>H', data[pointer + 16:pointer + 18]) uint32_c = structC(data, f_uint16) return {'B1': float_b, 'B2': int16_b, 'B3': int16_b_2, 'B4': b, 'B5': uint32_c} def structA(data, pointer): (int8_a,) = struct.unpack('>b', data[pointer:pointer + 1]) f2 = struct.unpack('>HI', data[pointer + 1:pointer + 7]) a2 = list(struct.unpack(f'>{f2[0]}c', data[f2[1]:f2[1] + f2[0] * 1])) a = '' for i in range(len(a2)): a += chr(a2[i][0]) (int16_a,) = struct.unpack('>h', data[pointer + 7:pointer + 9]) strB = structB(data, pointer + 9) f1 = struct.unpack('>IH', data[pointer + 27:pointer + 33]) a1 = [] adr_c = struct.unpack('>H', data[f1[1]:f1[1] + 2]) count = f1[0] for i in range(count): f3 = structD(data, adr_c[0] + i * 23) a1.append(f3) (double_a,) = struct.unpack('>d', data[pointer + 33:pointer + 41]) (double_a_2,) = struct.unpack('>d', data[pointer + 41:pointer + 49]) return {'A1': int8_a, 'A2': a, 'A3': int16_a, 'A4': strB, 'A5': a1, 'A6': double_a, 'A7': double_a_2} def main(data): return structA(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) a2 = [] for _ in range(3): (a2_offs, offs) = parse(buf, offs, 'uint16') (val, a2_offs) = parse_d(buf, a2_offs) a2.append(val) (a3, offs) = parse(buf, offs, 'int64') (a4, offs) = parse(buf, offs, 'uint64') (a5, offs) = parse_e(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint32') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'char') b1.append(val.decode()) b2 = [] for _ in range(2): (val, offs) = parse_c(buf, offs) b2.append(val) (b3, offs) = parse(buf, offs, 'uint16') return (dict(B1=''.join(b1), B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint8') (e2, offs) = parse(buf, offs, 'uint32') (e3, offs) = parse(buf, offs, 'uint16') (e4, offs) = parse(buf, offs, 'uint8') (e5_size, offs) = parse(buf, offs, 'uint16') (e5_offs, offs) = parse(buf, offs, 'uint16') e5 = [] for _ in range(e5_size): (val, e5_offs) = parse(buf, e5_offs, 'int32') e5.append(val) (e6, offs) = parse(buf, offs, 'double') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def b_struct(str, src): b_s = {} c_s = {} b1 = sum(struct.unpack('H', data[array_16_addr:array_16_addr + 2])[0]) array_16_addr += 2 C = {'C1': c_array[0], 'C2': c_array[1], 'C3': itog_d, 'C4': array_16, 'C5': c_array[11], 'C6': c_array[12], 'C7': c_array[13], 'C8': c_array[14]} E = {'E1': [b_array[8], b_array[9], b_array[10], b_array[11], b_array[12], b_array[13]], 'E2': b_array[14]} B = {'B1': b_array[0], 'B2': C, 'B3': [b_array[2], b_array[3], b_array[4], b_array[5], b_array[6], b_array[7]], 'B4': E} A = {'A1': B, 'A2': obj[1], 'A3': obj[2], 'A4': obj[3], 'A5': obj[4], 'A6': obj[5], 'A7': obj[6]} return A" "import struct as st def main(x): return a(x, 5) def a(x, start): size = st.unpack('< H', x[start:start + 2])[0] add = st.unpack('< I', x[start + 2:start + 6])[0] return {'A1': [b(x, add + 17 * j) for j in range(0, size)], 'A2': st.unpack('< d', x[start + 6:start + 14])[0]} def b(x, start): return {'B1': c(x, address_c(x, start)), 'B2': [st.unpack('< H', x[start + 4:start + 6])[0], st.unpack('< H', x[start + 6:start + 8])[0]], 'B3': st.unpack('< B', x[start + 8:start + 9])[0], 'B4': st.unpack('< I', x[start + 9:start + 13])[0], 'B5': st.unpack('< f', x[start + 13:start + 17])[0]} def address_c(x, start): return st.unpack('< I', x[start:start + 4])[0] def c(x, start): return {'C1': d(x, start), 'C2': e(x, start + 9), 'C3': uint32_uint32_int8(x, start + 20), 'C4': st.unpack('< i', x[start + 28:start + 32])[0], 'C5': [st.unpack('< B', x[start + 32:start + 33])[0], st.unpack('< B', x[start + 33:start + 34])[0], st.unpack('< B', x[start + 34:start + 35])[0], st.unpack('< B', x[start + 35:start + 36])[0], st.unpack('< B', x[start + 36:start + 37])[0]], 'C6': st.unpack('< i', x[start + 37:start + 41])[0], 'C7': st.unpack('< Q', x[start + 41:start + 49])[0], 'C8': f(x, address_f(x, start + 49))} def address_f(x, start): return st.unpack('< I', x[start:start + 4])[0] def uint32_uint32_int8(x, start): size = st.unpack('< I', x[start:start + 4])[0] address = st.unpack('< I', x[start + 4:start + 8])[0] arr = st.unpack('< ' + 'b' * size, x[address:address + 1 * size]) return list(arr) def d(x, start): return {'D1': st.unpack('< B', x[start:start + 1])[0], 'D2': st.unpack('< d', x[start + 1:start + 9])[0]} def e(x, start): return {'E1': st.unpack('< b', x[start:start + 1])[0], 'E2': st.unpack('< H', x[start + 1:start + 3])[0], 'E3': st.unpack('< H', x[start + 3:start + 5])[0], 'E4': st.unpack('< H', x[start + 5:start + 7])[0], 'E5': st.unpack('< i', x[start + 7:start + 11])[0]} def uint16_uint16_uint8(x, start): size = st.unpack('< H', x[start:start + 2])[0] address = st.unpack('< H', x[start + 2:start + 4])[0] arr = st.unpack('< ' + 'B' * size, x[address:address + 1 * size]) return list(arr) def f(x, start): return {'F1': uint16_uint16_uint8(x, start), 'F2': st.unpack('< H', x[start + 4:start + 6])[0]}" "from struct import * def parse(x, typ, start): return (unpack_from(typ, x, start)[0], start + calcsize(typ)) def parseA(x, start): (A1, start) = parseB(x, start) (A2, start) = parse(x, 'b', start) (A3, start) = parse(x, 'Q', start) (adress, start) = parse(x, 'I', start) A4 = parseC(x, adress)[0] (A5, start) = parse(x, 'B', start) (A6, start) = parse(x, 'q', start) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), start) def parseB(x, start): (B1, start) = parse(x, 'Q', start) (B2, start) = parse(x, 'I', start) (B3, start) = parse(x, 'B', start) (B4, start) = parse(x, 'B', start) (B5, start) = parse(x, '3s', start) B5 = B5.decode() (B6, start) = parse(x, 'd', start) (B7, start) = parse(x, 'H', start) (B8, start) = parse(x, 'h', start) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6, B7=B7, B8=B8), start) def parseC(x, start): (C1, start) = parse(x, 'I', start) C2 = [] (size, start) = parse(x, 'I', start) (adress, start) = parse(x, 'I', start) for i in range(size): (adress1, adress) = parse(x, 'I', adress) add = parseD(x, adress1)[0] C2.append(add) (adress, start) = parse(x, 'I', start) C3 = parseE(x, adress)[0] C4 = [] for i in range(4): (add, start) = parse(x, 'B', start) C4.append(add) (C5, start) = parse(x, 'f', start) C6 = [] (size, start) = parse(x, 'I', start) (adress, start) = parse(x, 'I', start) for i in range(size): (add, adress) = parse(x, 'I', adress) C6.append(add) (C7, start) = parse(x, 'H', start) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), start) def parseD(x, start): (D1, start) = parse(x, 'd', start) (D2, start) = parse(x, 'b', start) return (dict(D1=D1, D2=D2), start) def parseE(x, start): (E1, start) = parse(x, 'f', start) (E2, start) = parse(x, 'i', start) return (dict(E1=E1, E2=E2), start) def main(x): return parseA(x, 4)[0]" "from pprint import pprint import struct pointer = 4 def structA(data): A = {} global pointer address = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 A['A1'] = structB(data, address) A['A2'] = struct.unpack('>f', data[pointer:pointer + 4])[0] pointer += 4 address = struct.unpack('>H', data[pointer:pointer + 2])[0] pointer += 2 A['A3'] = structC(data, address) A['A4'] = [] size = struct.unpack('>I', data[pointer:pointer + 4])[0] pointer += 4 address = struct.unpack('>I', data[pointer:pointer + 4])[0] pointer += 4 for i in range(size): b = struct.unpack('>H', data[address + i * 2:address + 2 + i * 2])[0] A['A4'].append(b) for i in range(size): A['A4'][i] = structD(data, A['A4'][i]) A['A5'] = structE(data, pointer) return A def structB(data, address): B = {} B['B1'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 B['B2'] = [] for i in range(3): b = struct.unpack('>c', data[address + i:address + 1 + i])[0] B['B2'] += b.decode('ascii') B['B2'] = ''.join(B['B2']) address += 3 size = struct.unpack('>I', data[address:address + 4])[0] address += 4 address_2 = struct.unpack('>H', data[address:address + 2])[0] address += 2 B['B3'] = [] for i in range(size): b = struct.unpack('>b', data[address_2 + i * 1:address_2 + i * 1 + 1]) B['B3'].append(b[0]) address_2 += 4 * size B['B4'] = struct.unpack('>B', data[address:address + 1])[0] address += 1 B['B5'] = struct.unpack('>I', data[address:address + 4])[0] address += 4 B['B6'] = struct.unpack('>b', data[address:address + 1])[0] address += 1 B['B7'] = struct.unpack('>d', data[address:address + 8])[0] address += 8 return B def structC(data, address): C = {} C['C1'] = struct.unpack('>h', data[address:address + 2])[0] address += 2 C['C2'] = struct.unpack('>q', data[address:address + 8])[0] address += 8 C['C3'] = struct.unpack('>I', data[address:address + 4])[0] address += 4 C['C4'] = struct.unpack('>H', data[address:address + 2])[0] address += 2 C['C5'] = struct.unpack('>I', data[address:address + 4])[0] address += 4 C['C6'] = struct.unpack('>Q', data[address:address + 8])[0] address += 8 C['C7'] = struct.unpack('>d', data[address:address + 8])[0] address += 8 return C def structD(data, address): D = {} D['D1'] = struct.unpack('>q', data[address:address + 8])[0] address += 8 D['D2'] = struct.unpack('>B', data[address:address + 1])[0] address += 1 size = struct.unpack('>I', data[address:address + 4])[0] address += 4 address_2 = struct.unpack('>H', data[address:address + 2])[0] address += 2 D['D3'] = [] for i in range(size): b = struct.unpack('>d', data[address_2 + i * 8:address_2 + i * 8 + 8]) D['D3'].append(b[0]) address_2 += 4 * size return D def structE(data, address): E = {} E['E1'] = struct.unpack('>i', data[address:address + 4])[0] address += 4 size = struct.unpack('>I', data[address:address + 4])[0] address += 4 address_2 = struct.unpack('>H', data[address:address + 2])[0] address += 2 E['E2'] = [] for i in range(size): b = struct.unpack('>f', data[address_2 + i * 4:address_2 + i * 4 + 4]) E['E2'].append(b[0]) address_2 += 4 * size return E def main(d): return structA(d)" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] class structE: def fill_struct(self, b): global BYTE_INDEX arr1 = [] for i in range(5): arr1.append(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_arr_int16_size5(arr1) self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) return self def set_arr_int16_size5(self, arr): self.E1 = arr def set_double(self, num): self.E2 = num def get_cort(self): return {'E1': self.E1, 'E2': self.E2} class structD: def fill_struct(self, b): global BYTE_INDEX self.set_uint8(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_size_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr1 = [] for i in range(self.size): arr1.append(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_arr_int16(arr1) BYTE_INDEX = STOP_INDEX self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) return self def set_uint8(self, arr): self.D1 = arr def set_size_uint16(self, size): self.size = size def set_arr_int16(self, arr): self.D2 = arr def set_uint32(self, num): self.D3 = num def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_uint8_1(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_uint8_2(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_size_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer string = '' for i in range(self.size): int_lit = my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1]) string += chr(int_lit) self.set_arr_char(string) BYTE_INDEX = STOP_INDEX self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_int64(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_uint8_1(self, num): self.B1 = num def set_uint8_2(self, num): self.B2 = num def set_size_uint16(self, size): self.size = size def set_arr_char(self, arr): self.B3 = arr def set_uint32(self, num): self.B4 = num def set_int64(self, num): self.B5 = num def set_uint16(self, num): self.B6 = num def get_cort(self): return {'B1': self.B1, 'B2': self.B2, 'B3': self.B3, 'B4': self.B4, 'B5': self.B5, 'B6': self.B6} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_size_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer all_hueta_D = [] for i in range(self.size): all_hueta_D.append(structD().fill_struct(b)) self.set_struct_D(all_hueta_D) BYTE_INDEX = STOP_INDEX self.set_struct_E(structE().fill_struct(b)) self.set_int32_1(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_uint16_1(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int32_2(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_uint16_2(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_size_uint16(self, size): self.size = size def set_struct_D(self, D): self.C1 = D def set_struct_E(self, E): self.C2 = E def set_int32_1(self, num): self.C3 = num def set_uint16_1(self, num): self.C4 = num def set_int32_2(self, num): self.C5 = num def set_uint16_2(self, num): self.C6 = num def get_cort(self): arr = [] for i in self.C1: arr.append(i.get_cort()) return {'C1': arr, 'C2': self.C2.get_cort(), 'C3': self.C3, 'C4': self.C4, 'C5': self.C5, 'C6': self.C6} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_double(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_struct_B(structB().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_uint16(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_int8(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_uint32(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_struct_C(structC().fill_struct(b)) return self def set_double(self, num): self.A1 = num def set_struct_B(self, B): self.A2 = B def set_uint16(self, num): self.A3 = num def set_int8(self, num): self.A4 = num def set_uint32(self, num): self.A5 = num def set_struct_C(self, C): self.A6 = C def get_cort(self): return {'A1': self.A1, 'A2': self.A2.get_cort(), 'A3': self.A3, 'A4': self.A4, 'A5': self.A5, 'A6': self.A6.get_cort()} def main(h): global BYTE_INDEX BYTE_INDEX = 5 A = structA() A.fill_struct(h) return A.get_cort()" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_int16(), structure_size=2) d2 = reader.read_int8() return dict(D1=d1, D2=d2) def read_c(reader: BinaryReader): c1 = reader.read_uint32() c2 = reader.read_int32() c3 = reader.read_int8() c4 = reader.read_uint32() c5 = reader.read_double() return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5) def read_b(reader: BinaryReader): b1 = reader.read_int8() b2 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_char().decode('ascii'))) b3 = reader.read_double() return dict(B1=b1, B2=b2, B3=b3) def read_a(reader: BinaryReader): a1 = [read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=15)[0], read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=15)[0]] a2 = read_c(reader) a3 = reader.read_int16() a4 = ''.join([reader.read_char().decode('ascii'), reader.read_char().decode('ascii'), reader.read_char().decode('ascii')]) a5 = read_array(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_d(reader), structure_size=7)[0] a6 = reader.read_double() a7 = reader.read_uint64() return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "import struct def parse_e(data, pointer): f1 = struct.unpack('>HH', data[pointer:pointer + 4]) e1 = list(struct.unpack(f'>{f1[0]}b', data[f1[1]:f1[1] + f1[0] * 1])) e2 = struct.unpack('>i', data[pointer + 4:pointer + 8]) e3 = struct.unpack('>b', data[pointer + 8:pointer + 9]) e4 = list(struct.unpack('>2I', data[pointer + 9:pointer + 17])) f2 = struct.unpack('>II', data[pointer + 17:pointer + 25]) e5 = list(struct.unpack(f'>{f2[0]}f', data[f2[1]:f2[1] + f2[0] * 4])) e6 = struct.unpack('>h', data[pointer + 25:pointer + 27]) res = dict(E1=e1, E2=e2[0], E3=e3[0], E4=e4, E5=e5, E6=e6[0]) return res def parse_d(data, pointer): d1 = parse_e(data, pointer) d2 = struct.unpack('>b', data[pointer + 27:pointer + 28]) d3 = struct.unpack('>Q', data[pointer + 28:pointer + 37]) return dict(D1=d1, D2=d2[0], D3=d3[0]) def parse_c(data, pointer): c1 = struct.unpack('>H', data[pointer:pointer + 2])[0] c2 = struct.unpack('>H', data[pointer + 2:pointer + 4])[0] c3 = struct.unpack('>H', data[pointer + 4:pointer + 6])[0] return dict(C1=c1, C2=c2, C3=c3) def parse_b(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) b1 = [] for i in range(f1[0]): b1.append(parse_c(data, f1[1] + i * 6)) b2 = parse_d(data, pointer + 6) return dict(B1=b1, B2=b2) def parse_a(data, pointer): ptr_a1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, ptr_a1[0]) a2 = struct.unpack('>f', data[pointer + 4:pointer + 8]) a3 = list(struct.unpack('>2i', data[pointer + 8:pointer + 16])) return dict(A1=a1, A2=a2[0], A3=a3) def main(data): return parse_a(data, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('uint8', data, ofs) (D2, ofs) = parse('uint32', data, ofs) (D3, ofs) = parse('uint64', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def struct_C(data, ofs): C1 = [] for i in range(7): (elem, ofs) = parse('int8', data, ofs) C1.append(elem) C2 = [] for i in range(3): (elem, ofs) = parse('uint8', data, ofs) C2.append(elem) (C3, ofs) = parse('int64', data, ofs) (C4, ofs) = parse('uint16', data, ofs) (C5, ofs) = parse('int16', data, ofs) (C6, ofs) = parse('int16', data, ofs) (C7, ofs) = struct_D(data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) B2 = [] (B2_size, ofs) = parse('uint16', data, ofs) (B2_adr, ofs) = parse('uint16', data, ofs) for i in range(B2_size): (elem, B2_adr) = parse('double', data, B2_adr) B2.append(elem) (B3, ofs) = parse('uint32', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_A(data, ofs): A1 = [] (A1_size, ofs) = parse('uint32', data, ofs) (A1_adr, ofs) = parse('uint32', data, ofs) for i in range(A1_size): (B_adr, A1_adr) = parse('uint32', data, A1_adr) (elem, lop) = struct_B(data, B_adr) A1.append(elem) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, elem) = struct_C(data, A2_adr) return (dict(A1=A1, A2=A2), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse(buf, offs, 'int32') (a3, offs) = parse_b(buf, offs) (a4_offs, offs) = parse(buf, offs, 'uint16') (a4, a4_offs) = parse_d(buf, a4_offs) (a5, offs) = parse(buf, offs, 'int32') (a6, offs) = parse(buf, offs, 'float') (a7_size, offs) = parse(buf, offs, 'uint16') (a7_offs, offs) = parse(buf, offs, 'uint16') a7 = [] for _ in range(a7_size): (val, a7_offs) = parse(buf, a7_offs, 'uint32') a7.append(val) (a8, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'uint16') (val, _) = parse_c(buf, val) b1.append(val) b2 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'char') b2.append(val.decode('UTF-8')) (b3, offs) = parse(buf, offs, 'int64') (b4, offs) = parse(buf, offs, 'uint8') (b5, offs) = parse(buf, offs, 'uint16') (b6, offs) = parse(buf, offs, 'int16') (b7, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=''.join(b2), B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'int16') d1.append(val) (d2, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') (a2, offs) = parse(buf, offs, 'int32') (a3, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint32') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'char') b1.append(val.decode()) b2 = [] for _ in range(5): (val, offs) = parse_c(buf, offs) b2.append(val) (b3, offs) = parse(buf, offs, 'int8') (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse(buf, b4_offs, 'uint32') b4.append(val) (b5, offs) = parse(buf, offs, 'uint32') (b6, offs) = parse_d(buf, offs) (b7, offs) = parse(buf, offs, 'uint16') return (dict(B1=''.join(b1), B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'float') d1.append(val) d2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'float') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint8') (a3, offs) = parse_h(buf, offs) (a4, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_d(buf, b2_offs) b3 = [] for _ in range(3): (val, offs) = parse_f(buf, offs) b3.append(val) (b4_offs, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse_g(buf, b4_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse_e(buf, offs) return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): e1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') e1.append(val) (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'uint8') (e4, offs) = parse(buf, offs, 'int8') (e5, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int64') (f2, offs) = parse(buf, offs, 'uint16') f3 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int8') f3.append(val) return (dict(F1=f1, F2=f2, F3=f3), offs) def parse_g(buf, offs): (g1, offs) = parse(buf, offs, 'uint32') (g2, offs) = parse(buf, offs, 'uint16') (g3, offs) = parse(buf, offs, 'int32') (g4, offs) = parse(buf, offs, 'uint16') (g5, offs) = parse(buf, offs, 'int32') g6 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'uint32') g6.append(val) g7 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int16') g7.append(val) return (dict(G1=g1, G2=g2, G3=g3, G4=g4, G5=g5, G6=g6, G7=g7), offs) def parse_h(buf, offs): (h1, offs) = parse(buf, offs, 'uint32') (h2, offs) = parse(buf, offs, 'float') (h3, offs) = parse(buf, offs, 'uint32') (h4, offs) = parse(buf, offs, 'float') (h5, offs) = parse(buf, offs, 'double') (h6, offs) = parse(buf, offs, 'int8') (h7, offs) = parse(buf, offs, 'int32') return (dict(H1=h1, H2=h2, H3=h3, H4=h4, H5=h5, H6=h6, H7=h7), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(bs): magic_bytes = b'MMV' A = struct.Struct('> Q 6c H d') B = struct.Struct('> H q hQi hQi hQi H HH I h') D = struct.Struct('> 7B d B IH H H') a = A.unpack_from(bs, len(magic_bytes)) b = B.unpack_from(bs, a[-2]) d = D.unpack_from(bs, b[-2]) return {'A1': a[0], 'A2': b''.join(a[1:7]).decode(), 'A3': {'B1': b[0], 'B2': b[1], 'B3': [{'C1': b[2], 'C2': b[3], 'C3': b[4]}, {'C1': b[5], 'C2': b[6], 'C3': b[7]}, {'C1': b[8], 'C2': b[9], 'C3': b[10]}], 'B4': b[11], 'B5': list(struct.unpack_from(f'> {b[12]}Q', bs, b[13])), 'B6': {'D1': list(d[:7]), 'D2': d[7], 'D3': d[8], 'D4': list(struct.unpack_from(f'> {d[9]}B', bs, d[10])), 'D5': d[-2], 'D6': d[-1]}, 'B7': b[-1]}, 'A4': a[-1]}" "import pprint from struct import * class Parser: def __init__(self, data): self.data = data def parse(self, form, pos): return (unpack_from(f'>{form}', self.data, pos)[0], pos + calcsize(form)) def parse_d(self, pos=0): (ui32, pos) = self.parse('I', pos) (i16, pos) = self.parse('h', pos) (i16_2, pos) = self.parse('h', pos) return {'D1': ui32, 'D2': i16, 'D3': i16_2} def parse_c(self, pos=0): (ui8, pos) = self.parse('B', pos) (d, pos) = self.parse('d', pos) (i32, pos) = self.parse('i', pos) return {'C1': ui8, 'C2': d, 'C3': i32} def parse_b(self, pos=0): (ui64, pos) = self.parse('Q', pos) (ui16, pos) = self.parse('H', pos) chars = self.data[pos:][:6].decode('utf-8') pos += 6 (ui8, pos) = self.parse('B', pos) (f, pos) = self.parse('f', pos) (i, pos) = self.parse('i', pos) (size_ui16, pos) = self.parse('H', pos) (addr_ui32, pos) = self.parse('I', pos) chars_2 = self.data[addr_ui32:][:size_ui16].decode('utf-8') (c_start_ui32, pos) = self.parse('I', pos) struct_c = self.parse_c(c_start_ui32) return {'B1': ui64, 'B2': ui16, 'B3': chars, 'B4': ui8, 'B5': f, 'B6': i, 'B7': chars_2, 'B8': struct_c} def parse_a(self, pos=0): (b_start, pos) = self.parse('H', pos) struct_b = self.parse_b(b_start) (i8, pos) = self.parse('b', pos) (ui16, pos) = self.parse('H', pos) (i8_2, pos) = self.parse('b', pos) (size_ui16, pos) = self.parse('H', pos) (d_addr_ui16, pos) = self.parse('H', pos) d_pos = d_addr_ui16 d_array = [] for d_i in range(size_ui16): (d_start_ui16, d_pos) = self.parse('H', d_pos) d_array.append(self.parse_d(d_start_ui16)) f_array = [] for f_i in range(6): (f_value, pos) = self.parse('f', pos) f_array.append(f_value) return {'A1': struct_b, 'A2': i8, 'A3': ui16, 'A4': i8_2, 'A5': d_array, 'A6': f_array} def parse_sig(self, pos=0): if self.data.startswith(b'\xa2SMX'): return (True, pos + 4) return False def parse_all(self, pos=0): (res, pos) = self.parse_sig(pos) if res: return self.parse_a(pos) def main(data): return Parser(data).parse_all()" "from struct import unpack def parse_arrays(arr, c_arr_size): count = 0 parsed = [] for _ in range(0, c_arr_size): a = [] for i in range(0, 3): a.append(arr[count + i]) count += 3 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 80: break a = {f'A{i}': None for i in range(1, 6)} b = {f'B{i}': None for i in range(1, 8)} c = {f'C{i}': None for i in range(1, 4)} d = {f'D{i}': None for i in range(1, 5)} temp = unpack(' Q H Q 3H B i H f II Q I H i 5b Q 3d b') B = struct.Struct('> 3b I') D = struct.Struct('> Q d H') a = A.unpack_from(bs, len(magic_bytes)) b = B.unpack_from(bs, a[1]) d_structs = [D.unpack_from(bs, int(offset)) for offset in a[3:6]] return {'A1': a[0], 'A2': {'B1': list(b[:3]), 'B2': b[-1]}, 'A3': {'C1': a[2], 'C2': [{'D1': d[0], 'D2': d[1], 'D3': d[2]} for d in d_structs], 'C3': a[6], 'C4': a[7], 'C5': {'E1': a[8], 'E2': a[9], 'E3': list(struct.unpack_from(f'> {a[10]}h', bs, a[11])), 'E4': a[12], 'E5': a[13], 'E6': a[14], 'E7': a[15], 'E8': list(a[16:21])}, 'C6': a[21], 'C7': list(a[22:25])}, 'A4': a[-1]}" "import struct def for_structs(str, count, src, b_c, b_i): struct_tmp = [] for _ in range(count): tmp = struct.unpack(b_c, str[src + b_i * _:src + b_i + b_i * _]) struct_tmp.append(sum(tmp)) return struct_tmp def main(x): c1 = [] b1 = sum(struct.unpack('f', offs) (adress, offs) = parse(buf, '>H', offs) A2 = parseB(buf, adress)[0] (A3, offs) = parse(buf, '>B', offs) (A4, offs) = parse(buf, '>i', offs) (A5, offs) = parse(buf, '>Q', offs) (A6, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>I', offs) A7 = parseF(buf, adress)[0] return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), offs) def parseB(buf, offs): (B1, offs) = parse(buf, '>I', offs) (B2, offs) = parseC(buf, offs) (B3, offs) = parse(buf, '>4s', offs) B3 = B3.decode() (adress, offs) = parse(buf, '>H', offs) B4 = parseE(buf, adress)[0] return (dict(B1=B1, B2=B2, B3=B3, B4=B4), offs) def parseC(buf, offs): (C1, offs) = parse(buf, '>q', offs) C2 = [] for i in range(3): (adress, offs) = parse(buf, '>I', offs) x = parseD(buf, adress)[0] C2.append(x) return (dict(C1=C1, C2=C2), offs) def parseD(buf, offs): (D1, offs) = parse(buf, '>B', offs) (D2, offs) = parse(buf, '>f', offs) return (dict(D1=D1, D2=D2), offs) def parseE(buf, offs): (E1, offs) = parse(buf, '>q', offs) (size, offs) = parse(buf, '>I', offs) (adress, offs) = parse(buf, '>I', offs) E2 = [] for i in range(size): (x, adress) = parse(buf, '>Q', adress) E2.append(x) (E3, offs) = parse(buf, '>H', offs) return (dict(E1=E1, E2=E2, E3=E3), offs) def parseF(buf, offs): (F1, offs) = parse(buf, '>H', offs) F2 = [] for i in range(3): (x, offs) = parse(buf, '>f', offs) F2.append(x) return (dict(F1=F1, F2=F2), offs) def main(buf): return parseA(buf, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): D1 = [] (D1_size, ofs) = parse('uint16', data, ofs) (D1_adr, ofs) = parse('uint16', data, ofs) for i in range(D1_size): (elem, D1_adr) = parse('uint16', data, D1_adr) D1.append(elem) (D2, ofs) = parse('int16', data, ofs) (D3, ofs) = parse('int8', data, ofs) (D4, ofs) = parse('uint16', data, ofs) (D5, ofs) = parse('uint64', data, ofs) (D6, ofs) = parse('float', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6), ofs) def struct_C(data, ofs): C1 = [] (C1_size, ofs) = parse('uint32', data, ofs) (C1_adr, ofs) = parse('uint32', data, ofs) for i in range(C1_size): (D_adr, C1_adr) = parse('uint16', data, C1_adr) (elem, lop) = struct_D(data, D_adr) C1.append(elem) (C2, ofs) = parse('uint16', data, ofs) (C3, ofs) = parse('uint8', data, ofs) (C4, ofs) = parse('double', data, ofs) C5 = [] for i in range(5): (elem, ofs) = parse('uint64', data, ofs) C5.append(elem) C6 = [] (C6_size, ofs) = parse('uint32', data, ofs) (C6_adr, ofs) = parse('uint16', data, ofs) for i in range(C6_size): (elem, C6_adr) = parse('int8', data, C6_adr) C6.append(elem) (C7, ofs) = parse('int32', data, ofs) (C8, ofs) = parse('int32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7, C8=C8), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint16', data, ofs) (B2, ofs) = struct_C(data, ofs) (B3, ofs) = parse('uint16', data, ofs) return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int16', data, ofs) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, elem) = struct_B(data, A2_adr) A3 = [] for i in range(2): (elem, ofs) = parse('uint16', data, ofs) A3.append(elem) return (dict(A1=A1, A2=A2, A3=A3), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 70: break a = {f'A{i}': None for i in range(1, 6)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 5)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>LqHLLL', file[a_adr:a_adr + 26]) (b_adr, a['A2'], a['A3'], c_adr, uint32_size, uint32_adr) = temp temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) a['A5'] = list(temp) temp = unpack('>Hf', file[b_adr:b_adr + 6]) (b['B1'], b['B2']) = temp temp = unpack('>4cLLQL', file[c_adr:c_adr + 24]) (*ch_arr, d_adrs_size, d_adrs_adr, c['C3'], c['C4']) = temp c['C1'] = ''.join((str(e, 'utf8') for e in ch_arr)) d_adrs = unpack(f'>{d_adrs_size}L', file[d_adrs_adr:d_adrs_adr + d_adrs_size * 4]) c['C2'] = [] for d_adr in d_adrs: temp = unpack('>HfLH', file[d_adr:d_adr + 12]) (d['D1'], d['D2'], int32_size, int32_adr) = temp temp = unpack(f'>{int32_size}l', file[int32_adr:int32_adr + int32_size * 4]) d['D3'] = list(temp) c['C2'].append(d.copy()) a['A1'] = b a['A4'] = c return a" "from struct import calcsize, unpack_from from enum import Enum class Types(Enum): uint8 = 'B' uint16 = 'H' uint32 = 'I' int32 = 'i' int8 = 'b' float = 'f' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): A1 = reader.read(Types.float) A2 = reader.read(Types.uint32) A3 = b(reader) return dict(A1=A1, A2=A2, A3=A3) def b(reader: BinaryReader): B1 = c(reader) B2 = reader.read(Types.int32) B3 = reader.read(Types.int32) B41 = reader.read(Types.uint32) B42 = reader.read(Types.uint32) B4 = make_array_uint32(B41, B42, reader.source) B5 = reader.read(Types.float) return dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5) def c(reader: BinaryReader): C11 = reader.read(Types.uint16) C12 = reader.read(Types.uint16) C1 = make_array_d(C11, C12, reader.source) C2 = reader.read(Types.int8) C3 = [reader.read(Types.float), reader.read(Types.float)] C4 = reader.read(Types.uint8) C5 = reader.read(Types.int8) return dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5) def d(offset, source): reader = BinaryReader(offset, source) D1 = reader.read(Types.int8) D2 = [] for i in range(0, 8): D2.append(reader.read(Types.float)) D31 = reader.read(Types.uint16) D32 = reader.read(Types.uint32) D3 = make_arrayD_int8(D31, D32, reader.source) return dict(D1=D1, D2=D2, D3=D3) def make_array_uint32(size, offset, source): result = [] reader = BinaryReader(offset, source) while reader.offset < offset + size * 4: result.append(reader.read(Types.uint32)) return result def make_arrayD_int8(size, offset, source): result = [] reader = BinaryReader(offset, source) while reader.offset < offset + size: result.append(reader.read(Types.int8)) return result def make_array_d(size, offset, source): result = [] reader = BinaryReader(offset, source) while reader.offset < offset + size * 2: offset_d = reader.read(Types.uint16) result.append(d(offset_d, reader.source)) return result def main(source): reader = BinaryReader(offset=4, source=source) result = a(reader) return result" "import struct def main(data): A = struct.unpack_from('>fdhQIHi4BQf', data, offset=3) A5 = struct.unpack_from('>' + '2HB' * A[4], data, offset=A[5]) B_list = [] for i in range(A[4]): B1 = struct.unpack_from('>' + str(A5[i * 3]) + 'H', data, offset=A5[i * 3 + 1]) C_list = [] for j in range(A5[i * 3]): C = struct.unpack_from('>hI4B3hH', data, offset=B1[j]) C_list.append({'C1': C[0], 'C2': C[1], 'C3': [C[2], C[3], C[4], C[5]], 'C4': [C[6], C[7], C[8]], 'C5': C[9]}) B_list.append({'B1': C_list, 'B2': A5[i * 3 + 2]}) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': A[3], 'A5': B_list, 'A6': {'D1': A[6], 'D2': [A[7], A[8], A[9]], 'D3': A[10], 'D4': A[11]}, 'A7': A[12]}" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, _) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint32') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'char') a3.append(val.decode()) (a4_size, offs) = parse(buf, offs, 'uint16') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'char') a4.append(val.decode()) (a5, offs) = parse(buf, offs, 'uint16') (a6_size, offs) = parse(buf, offs, 'uint32') (a6_offs, offs) = parse(buf, offs, 'uint32') a6 = [] for _ in range(a6_size): (val, a6_offs) = parse_d(buf, a6_offs) a6.append(val) (a7, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=''.join(a3), A4=''.join(a4), A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2, offs) = parse(buf, offs, 'uint8') (b3, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int64') d2.append(val) (d3, offs) = parse(buf, offs, 'int16') d4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint32') d4.append(val) (d5, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def for_structs(str, count, src, b_c, b_i): struct_tmp = [] for _ in range(count): tmp = struct.unpack(b_c, str[src + b_i * _:src + b_i + b_i * _]) struct_tmp.append(sum(tmp)) return struct_tmp def main(x): a1 = [] for _ in range(2): b_tmp = struct.unpack('H', data[pointer:pointer + 2]) f2 = list(struct.unpack('>5I', data[pointer + 2:pointer + 22])) return {'F1': f1, 'F2': f2} def structE(data, pointer): fe1 = struct.unpack('>2I', data[pointer:pointer + 8]) e1 = [] x = fe1[1] for i in range(fe1[0]): y = struct.unpack('>B', data[x:x + 1]) x += 1 e1.append(y[0]) e2 = list(struct.unpack('>4h', data[pointer + 8:pointer + 16])) (e3,) = struct.unpack('>I', data[pointer + 16:pointer + 20]) (e4,) = struct.unpack('>B', data[pointer + 20:pointer + 21]) (e5,) = struct.unpack('>q', data[pointer + 21:pointer + 29]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def structD(data, pointer): (d1,) = struct.unpack('>B', data[pointer:pointer + 1]) (df2,) = struct.unpack('>H', data[pointer + 1:pointer + 3]) d2 = structE(data, df2) return {'D1': d1, 'D2': d2} def structC(data, pointer): (c1,) = struct.unpack('>b', data[pointer:pointer + 1]) (c2,) = struct.unpack('>f', data[pointer + 1:pointer + 5]) (c3,) = struct.unpack('>f', data[pointer + 5:pointer + 9]) return {'C1': c1, 'C2': c2, 'C3': c3} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) (b2,) = struct.unpack('>q', data[pointer + 1:pointer + 9]) return {'B1': b1, 'B2': b2} def structA(data, pointer): f1a = struct.unpack('>I', data[pointer:pointer + 4]) a1 = [] for i in range(5): a1.append(structB(data, f1a[0] + i * 9)) fa = struct.unpack('>H', data[pointer + 20:pointer + 22]) a2 = [] for j in range(4): a2.append(structC(data, fa[0] + j * 9)) f3 = struct.unpack('>I', data[pointer + 28:pointer + 32]) a3 = structD(data, f3[0]) (a4,) = struct.unpack('>Q', data[pointer + 32:pointer + 40]) (a5,) = struct.unpack('>f', data[pointer + 40:pointer + 44]) (a6,) = struct.unpack('>H', data[pointer + 44:pointer + 46]) a7 = structF(data, pointer + 46) (a8,) = struct.unpack('>d', data[pointer + 68:pointer + 76]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return structA(data, 4)" "import struct def uint32uint16_in_C_structure(s, pointer): result = [] size = struct.unpack('>I', s[pointer:pointer + 4])[0] add = struct.unpack('>H', s[pointer + 4:pointer + 6])[0] for i in range(0, size): C2 = struct.unpack('>H', s[add + 8:add + 10])[0] result.append({'C1': struct.unpack('>Q', s[add:add + 8])[0], 'C2': {'D1': struct.unpack('>q', s[C2:C2 + 8])[0], 'D2': struct.unpack('>b', s[C2 + 8:C2 + 9])[0], 'D3': list(struct.unpack('>4H', s[C2 + 9:C2 + 17]))}}) add += 10 return result def uint32uint16Float(s, pointer): size = struct.unpack('>I', s[pointer:pointer + 4])[0] add = struct.unpack('>H', s[pointer + 4:pointer + 6])[0] a = struct.unpack('>' + 'f' * size, s[add:add + 4 * size]) return list(a) def uint16uint32int64(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'q' * size, s[add:add + 8 * size]) return list(a) def main(s): b2 = struct.unpack('>H', s[11:13])[0] b3 = struct.unpack('>I', s[13:17])[0] return {'A1': {'B1': uint32uint16_in_C_structure(s, 5), 'B2': {'E1': struct.unpack('>B', s[b2:b2 + 1])[0], 'E2': struct.unpack('>H', s[b2 + 1:b2 + 3])[0]}, 'B3': {'F1': struct.unpack('>f', s[b3:b3 + 4])[0], 'F2': uint32uint16Float(s, b3 + 4), 'F3': struct.unpack('>i', s[b3 + 10:b3 + 14])[0], 'F4': struct.unpack('>i', s[b3 + 14:b3 + 18])[0], 'F5': struct.unpack('>H', s[b3 + 18:b3 + 20])[0], 'F6': uint16uint32int64(s, b3 + 20), 'F7': struct.unpack('>h', s[b3 + 26:b3 + 28])[0], 'F8': struct.unpack('>i', s[b3 + 28:b3 + 32])[0]}}, 'A2': struct.unpack('>f', s[17:21])[0], 'A3': struct.unpack('>d', s[21:29])[0], 'A4': struct.unpack('>I', s[29:33])[0], 'A5': struct.unpack('>b', s[33:34])[0]}" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.uint32) b2 = readC(reader.copy(reader.read(Types.uint16))) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint16) b3 = reader.copy(offset=adress3).readWithSize(Types.int8, size3) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): adresses = reader.readWithSize(Types.uint32, 5) c1 = [] for adress in adresses: dReader = reader.copy(adress) c1.append(readD(dReader)) c2 = reader.readWithSize(Types.uint64, 3) c3 = reader.read(Types.int16) return dict(C1=c1, C2=c2, C3=c3) def readD(reader): d1 = reader.read(Types.uint16) d2 = reader.read(Types.uint16) return dict(D1=d1, D2=d2) def readE(reader): size1 = reader.read(Types.uint16) adress1 = reader.read(Types.uint16) e1 = reader.copy(offset=adress1).readWithSize(Types.uint8, size1) e2 = reader.read(Types.double) e3 = reader.read(Types.uint64) size4 = reader.read(Types.uint32) adress4 = reader.read(Types.uint32) e4 = reader.copy(offset=adress4).readWithSize(Types.float, size4) return dict(E1=e1, E2=e2, E3=e3, E4=e4) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = readB(reader) a2 = readE(BinaryReader(offset=reader.read(Types.uint16), buffer=buffer)) a3 = reader.read(Types.int8) a4 = reader.read(Types.double) a5 = reader.read(Types.uint32) a6 = reader.read(Types.uint64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "from struct import unpack def parse_arrays(arr, d_arr_size): count = 0 parsed = [] for _ in range(0, d_arr_size): a = [] for i in range(0, 4): a.append(arr[count + i]) count += 4 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 112: break a = {f'A{i}': None for i in range(1, 5)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 8)} d = {f'D{i}': None for i in range(1, 4)} e = {f'E{i}': None for i in range(1, 9)} temp = unpack('hd5H3c6QHidHf', data, offset=3) C_list = [] for i in range(5): C = struct.unpack_from('>BbB', data, offset=A[i + 2]) C_list.append({'C1': C[0], 'C2': C[1], 'C3': C[2]}) B3 = '' for i in range(3): B3 += A[i + 7].decode('utf-8') D = struct.unpack_from('>i4dHqhi', data, offset=A[19]) return {'A1': A[0], 'A2': {'B1': A[1], 'B2': C_list, 'B3': B3, 'B4': [A[10], A[11], A[12]]}, 'A3': [A[13], A[14], A[15]], 'A4': A[16], 'A5': A[17], 'A6': A[18], 'A7': {'D1': D[0], 'D2': [D[1], D[2], D[3], D[4]], 'D3': D[5], 'D4': D[6], 'D5': D[7], 'D6': D[8]}, 'A8': A[20]}" "import pprint from struct import * class Parser: def __init__(self, data): self.data = data def parse(self, form, pos): return (unpack_from(f'>{form}', self.data, pos)[0], pos + calcsize(form)) def parse_d(self, pos=0): (i16, pos) = self.parse('h', pos) (i16_2, pos) = self.parse('h', pos) return ({'D1': i16, 'D2': i16_2}, pos) def parse_c(self, pos=0): (double, pos) = self.parse('d', pos) f_array = [] for f_i in range(6): (f_value, pos) = self.parse('f', pos) f_array.append(f_value) return ({'C1': double, 'C2': f_array}, pos) def parse_b(self, pos=0): (i8, pos) = self.parse('b', pos) (size_char, pos) = self.parse('H', pos) (d_pos_char, pos) = self.parse('H', pos) chars = self.data[d_pos_char:][:size_char].decode('utf-8') (double, pos) = self.parse('d', pos) (floats, pos) = self.parse('f', pos) struct_cm = [] (size_struct_c, pos) = self.parse('H', pos) (pos_struct_c, pos) = self.parse('H', pos) for c_i in range(size_struct_c): res = self.parse_c(pos_struct_c) struct_cm.append(res[0]) pos_struct_c = res[1] return ({'B1': i8, 'B2': chars, 'B3': double, 'B4': floats, 'B5': struct_cm}, pos) def parse_a(self, pos=0): (struct_b, pos) = self.parse_b(pos) (uint8, pos) = self.parse('B', pos) (double, pos) = self.parse('d', pos) (struct_d, pos) = self.parse_d(pos) (int32, pos) = self.parse('i', pos) (uint16, pos) = self.parse('H', pos) (uint32, pos) = self.parse('I', pos) floatm = [] (size_float, pos) = self.parse('H', pos) (d_pos_float, pos) = self.parse('I', pos) for f_i in range(size_float): (f_elem, d_pos_float) = self.parse('f', d_pos_float) floatm.append(f_elem) return {'A1': struct_b, 'A2': uint8, 'A3': double, 'A4': struct_d, 'A5': int32, 'A6': uint16, 'A7': uint32, 'A8': floatm} def parse_sig(self, pos=0): if self.data.startswith(b'\xe8JVUU'): return (True, pos + 5) return False def parse_all(self, pos=0): (res, pos) = self.parse_sig(pos) if res: return self.parse_a(pos) def main(data): return Parser(data).parse_all()" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int64') (a3, offs) = parse_d(buf, offs) (a4_offs, offs) = parse(buf, offs, 'uint32') (a4, a4_offs) = parse_f(buf, a4_offs) (a5, offs) = parse(buf, offs, 'int32') (a6, offs) = parse(buf, offs, 'uint8') (a7_size, offs) = parse(buf, offs, 'uint16') (a7_offs, offs) = parse(buf, offs, 'uint32') a7 = [] for _ in range(a7_size): (val, a7_offs) = parse(buf, a7_offs, 'int8') a7.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'uint64') (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse_c(buf, offs) (b5, offs) = parse(buf, offs, 'uint16') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode()) return (dict(C1=c1, C2=''.join(c2)), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'uint64') d3 = [] for _ in range(3): (d3_offs, offs) = parse(buf, offs, 'uint32') (val, d3_offs) = parse_e(buf, d3_offs) d3.append(val) (d4, offs) = parse(buf, offs, 'uint16') (d5, offs) = parse(buf, offs, 'int8') (d6, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse(buf, offs, 'int8') (e3_size, offs) = parse(buf, offs, 'uint32') (e3_offs, offs) = parse(buf, offs, 'uint16') e3 = [] for _ in range(e3_size): (val, e3_offs) = parse(buf, e3_offs, 'int16') e3.append(val) (e4, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'uint32') (f2, offs) = parse(buf, offs, 'uint32') (f3_size, offs) = parse(buf, offs, 'uint32') (f3_offs, offs) = parse(buf, offs, 'uint32') f3 = [] for _ in range(f3_size): (val, f3_offs) = parse(buf, f3_offs, 'int8') f3.append(val) return (dict(F1=f1, F2=f2, F3=f3), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 87: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 8)} d = {f'D{i}': None for i in range(1, 5)} temp = unpack('>LHBfLLqdHdfhfLLfL2L', file[a_adr:a_adr + 79]) (uint64_size, uint64_adr, a['A2'], a['A3'], a['A4'], a['A5'], b['B1'], b['B2'], c['C1'], c['C2'], c['C3'], c['C4'], c['C5'], uint32_size, uint32_adr, c['C7'], b['B4'], *d_adrs) = temp temp = unpack(f'>{uint64_size}Q', file[uint64_adr:uint64_adr + uint64_size * 8]) a['A1'] = list(temp) temp = unpack(f'>{uint32_size}L', file[uint32_adr:uint32_adr + uint32_size * 4]) c['C6'] = list(temp) a['A7'] = [] for d_adr in d_adrs: temp = unpack('>hb5Lh', file[d_adr:d_adr + 25]) (d['D1'], d['D2'], *uint32_arr, d['D4']) = temp d['D3'] = list(uint32_arr) a['A7'].append(d.copy()) b['B3'] = c a['A6'] = b return a" "import struct def int8p1(x, pos): return struct.unpack('>b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('>B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('>h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('>H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('>I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('>i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('>q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('>Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('>f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('>d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>H', x[start + 4:start + 6])[0] a = struct.unpack('>' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>H', x[start + 4:start + 6])[0] a = struct.unpack('>' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint32uint16uint16p6(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>H', x[start + 4:start + 6])[0] a = struct.unpack('>' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint16int8(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>H', x[start + 2:start + 4])[0] a = struct.unpack('>' + 'b' * size, x[add:add + 1 * size]) return list(a) def uint16uint16uint8p4(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>H', x[start + 2:start + 4])[0] a = struct.unpack('>' + 'B' * size, x[add:add + 1 * size]) return list(a) def uint32uint32int16p8(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>I', x[start + 4:start + 8])[0] a = struct.unpack('>' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint32int16p6(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>I', x[start + 2:start + 6])[0] a = struct.unpack('>' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint16int64(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>H', x[start + 2:start + 4])[0] a = struct.unpack('>' + 'q' * size, x[add:add + 8 * size]) return list(a) def D(x, pos): return {'D1': double8p8(x, pos), 'D2': [int32p4(x, pos + 8 + 4 * i) for i in range(4)], 'D3': int64p8(x, pos + 24), 'D4': float4p4(x, pos + 32)} def C(x, pos): return {'C1': D(x, uint16p2(x, pos)), 'C2': uint8p1(x, pos + 2)} def uint16uint32int16p6c(x, start): size = struct.unpack('>H', x[start:start + 2])[0] add = struct.unpack('>I', x[start + 2:start + 6])[0] a = struct.unpack('>' + 'H' * size, x[add:add + 2 * size]) res = [] for address in list(a): res.append(C(x, address)) return res def uint32uint16uint16p6c(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>H', x[start + 4:start + 6])[0] a = struct.unpack('>' + 'H' * size, x[add:add + 2 * size]) res = [] for address in list(a): res.append(C(x, address)) return res def B(x, pos): return {'B1': uint32uint16uint16p6c(x, pos), 'B2': uint32p4(x, pos + 6), 'B3': [int16p2(x, pos + 10 + 2 * i) for i in range(3)]} def A(x, pos): return {'A1': B(x, uint16p2(x, pos)), 'A2': double8p8(x, pos + 2), 'A3': int64p8(x, pos + 10), 'A4': [int64p8(x, pos + 18 + 8 * i) for i in range(4)], 'A5': [uint32p4(x, pos + 50 + 4 * i) for i in range(3)]} def main(x): return A(x, 4)" "from struct import unpack type_dict = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's', 'char': 'c'} def gen_d(): d = type_dict return d['int64'] + d['uint32'] + d['uint32'] + d['uint64'] + d['uint64'] def gen_c(): d = type_dict return d['float'] + d['uint32'] def gen_b(): d = type_dict return d['int64'] + d['uint16'] def gen_a(): d = type_dict return d['int32'] + 8 * d['char[]'] + 8 * d['char[]'] + gen_b() + d['uint16'] + d['int32'] + 2 * gen_d() + d['uint32'] def gen_total(): d = type_dict return '>xxxx' + gen_a() def main(arg): d = type_dict total = gen_total() obj = unpack(total, arg[:108]) m_ch1 = [] for i in range(8): m_ch1.append(obj[1 + i].decode()) m_ch1 = ''.join(m_ch1) m_ch2 = [] for i in range(8): m_ch2.append(obj[9 + i].decode()) m_ch2 = ''.join(m_ch2) d2_struct_size = obj[22] d2_struct_addr = obj[23] d2_struct_total = '>' + d2_struct_size * d['int32'] d2_struct_obj = list(unpack(d2_struct_total, arg[d2_struct_addr:d2_struct_addr + d2_struct_size * 4])) d2_2_struct_size = obj[27] d2_2_struct_addr = obj[28] d2_2_struct_total = '>' + d2_2_struct_size * d['int32'] d2_2_struct_obj = list(unpack(d2_2_struct_total, arg[d2_2_struct_addr:d2_2_struct_addr + d2_2_struct_size * 4])) c_struct_addr = obj[19] c_obj = unpack('>' + gen_c(), arg[c_struct_addr:c_struct_addr + 8]) a_dict = {'A1': obj[0], 'A2': m_ch1, 'A3': m_ch2, 'A4': {'B1': obj[17], 'B2': obj[18]}, 'A5': {'C1': c_obj[0], 'C2': c_obj[1]}, 'A6': obj[20], 'A7': [{'D1': obj[21], 'D2': d2_struct_obj, 'D3': obj[24], 'D4': obj[25]}, {'D1': obj[26], 'D2': d2_2_struct_obj, 'D3': obj[29], 'D4': obj[30]}], 'A8': obj[31]} return a_dict" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a1.append(val) (a2_offs, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse_c(buf, a2_offs) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): b1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'char') b1.append(val.decode()) (b2, offs) = parse(buf, offs, 'int32') (b3, offs) = parse(buf, offs, 'uint8') (b4, offs) = parse(buf, offs, 'int64') return (dict(B1=''.join(b1), B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse_d(buf, offs) (c3, offs) = parse(buf, offs, 'uint8') (c4_offs, offs) = parse(buf, offs, 'uint32') (c4, offs) = parse_e(buf, c4_offs) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'int32') (d3, offs) = parse(buf, offs, 'uint32') (d4, offs) = parse(buf, offs, 'uint8') (d5_size, offs) = parse(buf, offs, 'uint32') (d5_offs, offs) = parse(buf, offs, 'uint16') d5 = [] for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'int8') d5.append(val) (d6, offs) = parse(buf, offs, 'uint8') (d7_size, offs) = parse(buf, offs, 'uint16') (d7_offs, offs) = parse(buf, offs, 'uint32') d7 = [] for _ in range(d7_size): (val, d7_offs) = parse(buf, d7_offs, 'int8') d7.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse(buf, offs, 'uint8') (e3, offs) = parse(buf, offs, 'int8') (e4, offs) = parse(buf, offs, 'int16') (e5, offs) = parse(buf, offs, 'uint32') (e6, offs) = parse(buf, offs, 'uint64') (e7, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a2.append(val) a3 = parse_c(buf, offs)[0] return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int32') (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'int32') (c6, offs) = parse_d(buf, offs) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') d2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint16') d2.append(val) (d3, offs) = parse(buf, offs, 'int32') d4 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'double') d4.append(val) (d5, offs) = parse(buf, offs, 'double') (d6_size, offs) = parse(buf, offs, 'uint32') (d6_offs, offs) = parse(buf, offs, 'uint32') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'uint32') d6.append(val) (d7, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def parse_array(data, offset, types, length): offset_fin = offset + length * struct.calcsize(types) return list(struct.unpack(f'>{length}{types}', data[offset:offset_fin])) def parse_d(data, offset): result = dict() (d1_size, d1_addr) = struct.unpack('>II', data[offset:offset + 8]) result['D1'] = parse_array(data, d1_addr, 'H', d1_size) result['D2'] = struct.unpack('>H', data[offset + 8:offset + 10])[0] (d3_size, d3_addr) = struct.unpack('>II', data[offset + 10:offset + 18]) result['D3'] = parse_array(data, d3_addr, 'd', d3_size) (d4_size, d4_addr) = struct.unpack('>HI', data[offset + 18:offset + 24]) result['D4'] = parse_array(data, d4_addr, 'h', d4_size) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>B', data[offset + 2:offset + 3])[0] (c3_size, c3_addr) = struct.unpack('>II', data[offset + 3:offset + 11]) result['C3'] = [] i = 0 for _ in range(c3_size): result['C3'].append(parse_d(data, c3_addr + i)) i += 24 return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>f', data[offset:offset + 4])[0] result['B2'] = struct.unpack('>d', data[offset + 4:offset + 12])[0] c_addr = struct.unpack('>H', data[offset + 12:offset + 14])[0] result['B3'] = parse_c(data, c_addr) result['B4'] = struct.unpack('>b', data[offset + 14:offset + 15])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>B', data[offset:offset + 1])[0] result['A2'] = parse_b(data, offset + 1) result['A3'] = struct.unpack('>b', data[offset + 16:offset + 17])[0] return result def main(data): return parse_a(data, 5)" "import struct from struct import * from pprint import pprint NAMES = dict(char='xxxxx' + gen_a() def main(arg): d = type_dict total = gen_total() obj = unpack(total, arg[:11]) m_ch1 = [] for i in range(2): m_ch1.append(obj[1 + i].decode()) m_ch1 = ''.join(m_ch1) b_struct_addr = obj[3] len_b = 2 * 2 + 4 + 2 + 4 b_obj = unpack('>' + gen_b(), arg[b_struct_addr:b_struct_addr + len_b]) c_addr1 = b_obj[0] c_addr2 = b_obj[1] len_c = 2 + 4 + 24 + 2 c_obj1 = list(unpack('>' + gen_c(), arg[c_addr1:c_addr1 + len_c])) c_obj2 = list(unpack('>' + gen_c(), arg[c_addr2:c_addr2 + len_c])) c1_size = c_obj1[0] c1_addr = c_obj1[1] c1_total = '>' + c1_size * d['int32'] c1 = list(unpack(c1_total, arg[c1_addr:c1_addr + c1_size * 4])) c2_size = c_obj2[0] c2_addr = c_obj2[1] c2_total = '>' + c2_size * d['int32'] c2 = list(unpack(c2_total, arg[c2_addr:c2_addr + c2_size * 4])) d_addr = b_obj[2] len_d = 2 + 8 + 24 + 4 + 1 d_obj = list(unpack('>' + gen_d(), arg[d_addr:d_addr + len_d])) b_dict = {'B1': [{'C1': c1, 'C2': [c_obj1[2], c_obj1[3], c_obj1[4]], 'C3': c_obj1[5]}, {'C1': c2, 'C2': [c_obj2[2], c_obj2[3], c_obj2[4]], 'C3': c_obj2[5]}], 'B2': {'D1': d_obj[0], 'D2': d_obj[1], 'D3': [d_obj[2], d_obj[3], d_obj[4]], 'D4': d_obj[5], 'D5': d_obj[6]}, 'B3': b_obj[3], 'B4': b_obj[4]} a_dict = {'A1': obj[0], 'A2': m_ch1, 'A3': b_dict, 'A4': obj[4]} return a_dict" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('>2i', data[pointer:pointer + 8])) f2 = struct.unpack('>IH', data[pointer + 8:pointer + 14]) d2 = list(struct.unpack(f'>{f2[0]}h', data[f2[1]:f2[1] + f2[0] * 2])) d3 = list(struct.unpack('>4b', data[pointer + 14:pointer + 18])) d4 = struct.unpack('>B', data[pointer + 18:pointer + 19])[0] d5 = list(struct.unpack('>2f', data[pointer + 19:pointer + 27])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>BqdQ', data[pointer:pointer + 25]) c5 = list() c5.append(parse_d(data, pointer + 25)) c5.append(parse_d(data, pointer + 52)) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = parse_c(data, pointer) b2 = struct.unpack('>h', data[pointer + 79:pointer + 81])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = struct.unpack('>q', data[pointer + 81:pointer + 89])[0] return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse_b(buf, offs) (a5, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse_f(buf, offs) (b4, offs) = parse(buf, offs, 'int8') (b5, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse(buf, offs, 'int8') (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint32') c4 = [] for _ in range(c4_size): (c4_offs1, c4_offs) = parse(buf, c4_offs, 'uint32') (val, c4_offs1) = parse_d(buf, c4_offs1) c4.append(val) (c5_offs, offs) = parse(buf, offs, 'uint32') (c5, c5_offs) = parse_e(buf, c5_offs) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int32') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'uint8') (e4, offs) = parse(buf, offs, 'int16') e5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'double') e5.append(val) e6 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int16') e6.append(val) e7 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'double') e7.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'uint64') (f2, offs) = parse(buf, offs, 'int8') return (dict(F1=f1, F2=f2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def structE(data, pointer): (int32_e,) = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['D2'] = struct.unpack('>h', data[offset + 2:offset + 4])[0] result['D3'] = struct.unpack('>H', data[offset + 4:offset + 6])[0] (d4_size, d4_addr) = struct.unpack('>IH', data[offset + 6:offset + 12]) result['D4'] = parse_array(data, d4_addr, 'B', d4_size) result['D5'] = struct.unpack('>B', data[offset + 12:offset + 13])[0] (d6_size, d6_addr) = struct.unpack('>IH', data[offset + 13:offset + 19]) result['D6'] = parse_array(data, d6_addr, 'f', d6_size) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>q', data[offset:offset + 8])[0] result['C2'] = struct.unpack('>L', data[offset + 8:offset + 8 + 4])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>L', data[offset:offset + 4])[0] c_addrs = parse_array(data, offset + 4, 'H', 5) result['B2'] = [parse_c(data, addr) for addr in c_addrs] result['B3'] = parse_d(data, offset + 14) result['B4'] = struct.unpack('>b', data[offset + 33:offset + 34])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>h', data[offset:offset + 2])[0] result['A2'] = '' for c in parse_array(data, offset + 2, 'c', 3): result['A2'] += c.decode() result['A3'] = parse_b(data, offset + 5) result['A4'] = struct.unpack('>Q', data[offset + 39:offset + 47])[0] return result def main(data): return parse_a(data, 4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('float', data, ofs) E2 = [] (E2_size, ofs) = parse('uint16', data, ofs) (E2_adr, ofs) = parse('uint32', data, ofs) for i in range(E2_size): (elem, E2_adr) = parse('int32', data, E2_adr) E2.append(elem) (E3, ofs) = parse('double', data, ofs) (E4, ofs) = parse('uint32', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) D2 = [] (D2_size, ofs) = parse('uint32', data, ofs) (D2_adr, ofs) = parse('uint32', data, ofs) for i in range(D2_size): (elem, D2_adr) = parse('uint16', data, D2_adr) D2.append(elem) (D3, ofs) = parse('double', data, ofs) D4 = [] for i in range(7): (elem, ofs) = parse('uint8', data, ofs) D4.append(elem) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint64', data, ofs) C2 = [] (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint32', data, ofs) for i in range(C2_size): (elem, C2_adr) = struct_D(data, C2_adr) C2.append(elem) (C3, ofs) = struct_E(data, ofs) (C4, ofs) = parse('float', data, ofs) (C5, ofs) = parse('int8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('double', data, ofs) (B2, ofs) = parse('uint16', data, ofs) (B3, ofs) = parse('int64', data, ofs) (B4, ofs) = parse('uint64', data, ofs) (B5, ofs) = parse('int8', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5), ofs) def struct_A(data, ofs): (A1_adr, ofs) = parse('uint32', data, ofs) (A1, elem) = struct_B(data, A1_adr) (A2, ofs) = parse('int8', data, ofs) A3 = '' (A3_size, ofs) = parse('uint16', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) for i in range(A3_size): (elem, A3_adr) = parse('char', data, A3_adr) A3 += elem.decode() (A4, ofs) = struct_C(data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4), ofs) def main(data): return struct_A(data, 4)[0]" "import struct offset = 4 def find(adress, size, unpack, data): global offset s = data[adress - offset:adress - offset + size] s = struct.unpack(unpack, s) return s def main(data): ans = {} data1 = data[offset:] a = 90 b = 62 c = 5 d = 14 b_str = find(offset, b, f""<{7 * 'bi'}5cIiiHHHi"", data1) d3 = list(find(b_str[-3], b_str[-4] * 2, f'<{b_str[-4]}h', data1)) ans['A1'] = {'B1': [{'C1': b_str[0], 'C2': b_str[1]}, {'C1': b_str[2], 'C2': b_str[3]}, {'C1': b_str[4], 'C2': b_str[5]}, {'C1': b_str[6], 'C2': b_str[7]}, {'C1': b_str[8], 'C2': b_str[9]}, {'C1': b_str[10], 'C2': b_str[11]}, {'C1': b_str[12], 'C2': b_str[13]}], 'B2': (b_str[14] + b_str[15] + b_str[16] + b_str[17] + b_str[18]).decode('utf-8'), 'B3': b_str[19], 'B4': {'D1': b_str[20], 'D2': b_str[21], 'D3': d3, 'D4': b_str[-2]}, 'B5': b_str[-1]} a_str = find(offset + b, a - b, 'iBHHIIHIIHdBBf', data1) ans |= {'A1': a_str[0], 'A2': a_str[1], 'A3': a_str[2]} a4 = find(a_str[4], a_str[3], f'>{a_str[3]}c', data1) a4_str = b'' for i in a4: a4_str += i ans['A4'] = a4_str.decode('utf-8') c_array = find(a_str[6], a_str[5] * c, f"">{a_str[5] * 'QdHIq'}"", data1) c_list = [] for i in range(4, len(c_array), 5): c_dict = {'C1': c_array[i - 4], 'C2': c_array[i - 3], 'C3': list(find(c_array[i - 1], c_array[i - 2] * 4, f'>{c_array[i - 2]}I', data1)), 'C4': c_array[i]} c_list.append(c_dict) ans |= {'A5': {'B1': c_list, 'B2': {'D1': a_str[7], 'D2': list(find(a_str[9], a_str[8] * 4, f'>{a_str[8]}I', data1)), 'D3': a_str[10]}}} ans['A6'] = [a_str[-3], a_str[-2]] ans['A7'] = a_str[-1] return ans" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 77 and a_adr != 2: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 9)} temp = unpack('>HLHHLHLL', file[a_adr:a_adr + 24]) (*b_strs, d_adr, a['A3']) = temp a['A1'] = [] (ch_size, ch_adr, c_adr) = b_strs[0:3] ch_arr = unpack(f'>{ch_size}c', file[ch_adr:ch_adr + ch_size]) b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack('>ql', file[c_adr:c_adr + 12]) (c['C1'], c['C2']) = temp b['B2'] = c.copy() a['A1'].append(b.copy()) (ch_size, ch_adr, c_adr) = b_strs[3:6] ch_arr = unpack(f'>{ch_size}c', file[ch_adr:ch_adr + ch_size]) b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack('>ql', file[c_adr:c_adr + 12]) (c['C1'], c['C2']) = temp b['B2'] = c.copy() a['A1'].append(b.copy()) temp = unpack('>QLHqbhQ8hf', file[d_adr:d_adr + 53]) (d['D1'], int8_size, int8_adr, d['D3'], d['D4'], d['D5'], d['D6'], *int16_arr, d['D8']) = temp d['D7'] = list(int16_arr) temp = unpack(f'>{int8_size}b', file[int8_adr:int8_adr + int8_size]) d['D2'] = list(temp) a['A2'] = d return a" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('float', data, ofs) D2 = [] (D2_size, ofs) = parse('uint32', data, ofs) (D2_adr, ofs) = parse('uint32', data, ofs) for i in range(D2_size): (elem, D2_adr) = parse('int8', data, D2_adr) D2.append(elem) (D3, ofs) = parse('int8', data, ofs) D4 = [] (D4_size, ofs) = parse('uint32', data, ofs) (D4_adr, ofs) = parse('uint32', data, ofs) for i in range(D4_size): (elem, D4_adr) = parse('float', data, D4_adr) D4.append(elem) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): C1 = '' for i in range(2): (elem, ofs) = parse('char', data, ofs) C1 += elem.decode() (C2, ofs) = parse('uint16', data, ofs) C3 = [] for i in range(4): (elem, ofs) = parse('int8', data, ofs) C3.append(elem) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = struct_C(data, ofs) (B2, ofs) = parse('uint32', data, ofs) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint16', data, ofs) (A2, ofs) = parse('double', data, ofs) (A3, ofs) = parse('uint32', data, ofs) (A4_adr, ofs) = parse('uint32', data, ofs) (A4, elem) = struct_B(data, A4_adr) A5 = [] for i in range(2): (D_adr, ofs) = parse('uint32', data, ofs) (elem, lop) = struct_D(data, D_adr) A5.append(elem) (A6, ofs) = parse('int64', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 5)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 70: break a = {f'A{i}': None for i in range(1, 7)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 7)} temp = unpack('<4cd5HLhf', file[a_adr:a_adr + 32]) (*ch_arr, a['A2']) = temp[0:5] a['A1'] = ''.join((str(e, 'utf8') for e in ch_arr)) (*b_adrs, d_adr, a['A5'], a['A6']) = temp[5:] a['A3'] = [] for b_adr in b_adrs: temp = unpack(' d', x[start:start + 8])[0], 'D2': struct.unpack('> b', x[start + 8:start + 9])[0]} def uint16uint32uint64(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def c_struct(x, start): return {'C1': struct.unpack('> f', x[start:start + 4])[0], 'C2': uint16uint32uint64(x, start + 4), 'C3': struct.unpack('> q', x[start + 10:start + 18])[0], 'C4': struct.unpack('> B', x[start + 18:start + 19])[0], 'C5': struct.unpack('> b', x[start + 19:start + 20])[0], 'C6': struct.unpack('> H', x[start + 20:start + 22])[0], 'C7': struct.unpack('> I', x[start + 22:start + 26])[0]} def c_address(x, start): return struct.unpack('> H', x[start:start + 2])[0] def uint16uint32int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + size]) return list(a) def b_struct(x, start): return {'B1': struct.unpack('> I', x[start:start + 4])[0], 'B2': struct.unpack('> d', x[start + 4:start + 12])[0], 'B3': struct.unpack('> H', x[start + 12:start + 14])[0], 'B4': uint16uint32int8(x, start + 14), 'B5': c_struct(x, c_address(x, start + 20))} def uint16uint16char(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] return str(x[add:add + size])[2:-1] def uint16uint16uint8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + size]) return list(a) def d_address(x, start): return struct.unpack('> I', x[start:start + 4])[0] def b_address(x, start): return struct.unpack('> H', x[start:start + 2])[0] def a_struct(x, start): return {'A1': struct.unpack('> b', x[start:start + 1])[0], 'A2': struct.unpack('> Q', x[start + 1:start + 9])[0], 'A3': uint16uint16char(x, start + 9), 'A4': struct.unpack('> d', x[start + 13:start + 21])[0], 'A5': [b_struct(x, b_address(x, start + 21)), b_struct(x, b_address(x, start + 23))], 'A6': struct.unpack('> b', x[start + 25:start + 26])[0], 'A7': d_struct(x, d_address(x, start + 26)), 'A8': uint16uint16uint8(x, start + 30)} def main(x): return a_struct(x, 5)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 131: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 7)} d = {f'D{i}': None for i in range(1, 3)} e = {f'E{i}': None for i in range(1, 4)} temp = unpack('>HHHHHdfLHLL', file[a_adr:a_adr + 36]) (c_adr, d_adrs_size, d_adrs_adr, int8_size, int8_adr, a['A2'], e['E1'], uint16_size, uint16_adr, int16_size, int16_adr) = temp temp = unpack(f'>{int8_size}b', file[int8_adr:int8_adr + int8_size]) b['B3'] = list(temp) temp = unpack(f'>{uint16_size}H', file[uint16_adr:uint16_adr + uint16_size * 2]) e['E2'] = list(temp) temp = unpack(f'>{int16_size}h', file[int16_adr:int16_adr + int16_size * 5]) e['E3'] = list(temp) temp = unpack('>hbLHBL', file[c_adr:c_adr + 14]) (c['C1'], c['C2'], c['C3'], c['C4'], c['C5'], c['C6']) = temp temp = unpack(f'>{d_adrs_size}L', file[d_adrs_adr:d_adrs_adr + d_adrs_size * 4]) d_adrs = list(temp) b['B2'] = [] for d_adr in d_adrs: temp = unpack('>df', file[d_adr:d_adr + 12]) (d['D1'], d['D2']) = temp b['B2'].append(d.copy()) b['B1'] = c a['A1'] = b a['A3'] = e return a" "import struct def main(data): return parse_a(data, 5)[0] def parse_array(data, offset, type, len): return list(struct.unpack(f'<{len}{type}', data[offset:offset + struct.calcsize(f'<{len}{type}')])) FMT = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse_a(data, offset): result = {} result['A1'] = struct.unpack('3c', data[offset:offset + struct.calcsize('>3c')])).decode('ascii') offset += struct.calcsize('>3c') result['B2'] = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint64') (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (b_offs, a2_offs) = parse(buf, a2_offs, 'uint32') (val, b_offs) = parse_b(buf, b_offs) a2.append(val) (a3, offs) = parse_c(buf, offs) (a4, offs) = parse(buf, offs, 'uint64') (a5, offs) = parse_e(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'uint8') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) (c2, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'uint16') d1.append(val) d2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') d2.append(val) (d3, offs) = parse(buf, offs, 'uint16') d4 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint64') d4.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack(' reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_int8() d2 = reader.read_uint64() d3 = reader.read_int64() d4 = reader.read_uint64() d5 = reader.read_uint32() d6 = reader.read_int16() d7 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_int8()) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def read_c(reader: BinaryReader): c1 = reader.read_int16() c2 = reader.read_uint64() return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = read_array(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_c(reader), structure_size=6)[0] b2 = [reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16(), reader.read_int16()] return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = reader.read_float() a2 = reader.read_uint16() a3 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode('ascii'))) a4 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: read_b(reader), structure_size=16) a5 = read_d(reader) a6 = reader.read_double() a7 = reader.read_float() return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint16') a1_addresses = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'uint16') a1_addresses.append(val) a1 = [] for i in a1_addresses: (val, a1_offs) = parse_b(buf, i) a1.append(val) (a2, offs) = parse_c(buf, offs) (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse(buf, offs, 'double') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, c2_offs) = parse_d(buf, c2_offs) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') d1.append(val) d2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'float') d2.append(val) (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'int64') d3.append(val) (d4_size, offs) = parse(buf, offs, 'uint32') (d4_offs, offs) = parse(buf, offs, 'uint32') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'uint64') d4.append(val) (d5, offs) = parse(buf, offs, 'uint8') (d6, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse_value(data, offset, type): delta_1 = struct.calcsize(type) return struct.unpack(f'<{type}', data[offset:offset + delta_1])[0] def parse_array(data, offset, length, type): delta_2 = offset + length * struct.calcsize(type) return list(struct.unpack(f'<{length}{type}', data[offset:delta_2])) def parse_f(data, offset): result = dict() result['F1'] = parse_value(data, offset, 'i') result['F2'] = parse_value(data, offset + 4, 'h') result['F3'] = parse_array(data, offset + 6, 3, 'b') result['F4'] = parse_array(data, offset + 9, 3, 'h') result['F5'] = parse_value(data, offset + 15, 'i') return result def parse_e(data, offset): result = dict() result['E1'] = parse_array(data, offset, 4, 'H') result['E2'] = parse_value(data, offset + 8, 'd') result['E3'] = parse_value(data, offset + 16, 'd') return result def parse_d(data, offset): result = dict() result['D1'] = parse_value(data, offset, 'h') result['D2'] = parse_e(data, offset + 2) result['D3'] = parse_value(data, offset + 26, 'Q') return result def parse_c(data, offset): result = dict() (f1_size, f1_addr) = struct.unpack(' 0: temp = arr[BYTE_INDEX] BYTE_INDEX += 1 num = num << 8 num = num ^ temp count -= 1 return num class structD: def fill_struct(self, b): global BYTE_INDEX self.set_D1(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_D2(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_D3(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) BYTE_INDEX = STOP_INDEX self.set_D4(arr) return self def set_D1(self, arr): self.D1 = arr def set_D2(self, num): self.D2 = num def set_D3(self, arr): self.D3 = arr def set_D4(self, arr): self.D4 = arr def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3, 'D4': self.D4} class structC: def fill_struct(self, b): global BYTE_INDEX self.set_C1(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_C2(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_C3(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_C4(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_C5(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(my_repack('>i', b[BYTE_INDEX:BYTE_INDEX + 4])) BYTE_INDEX = STOP_INDEX self.set_C6(arr) return self def set_C1(self, num): self.C1 = num def set_C2(self, num): self.C2 = num def set_C3(self, arr): self.C3 = arr def set_C4(self, E): self.C4 = E def set_C5(self, E): self.C5 = E def set_C6(self, E): self.C6 = E def get_cort(self): return {'C1': self.C1, 'C2': self.C2, 'C3': self.C3, 'C4': self.C4, 'C5': self.C5, 'C6': self.C6} class structB: def fill_struct(self, b): global BYTE_INDEX str = '' for i in range(3): str += chr(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B1(str) arr_pointer = [] for i in range(2): arr_pointer.append(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) STOP_INDEX = BYTE_INDEX arr_structs = [] for i in arr_pointer: BYTE_INDEX = i arr_structs.append(structC().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_B2(arr_structs) self.set_B3(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_B4(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_B5(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B6(structD().fill_struct(b)) self.set_B7(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) return self def set_B1(self, num): self.B1 = num def set_B2(self, num): self.B2 = num def set_B3(self, num): self.B3 = num def set_B4(self, num): self.B4 = num def set_B5(self, num): self.B5 = num def set_B6(self, num): self.B6 = num def set_B7(self, num): self.B7 = num def get_cort(self): arr1 = [] for i in self.B2: arr1.append(i.get_cort()) return {'B1': self.B1, 'B2': arr1, 'B3': self.B3, 'B4': self.B4, 'B5': self.B5, 'B6': self.B6.get_cort(), 'B7': self.B7} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_A1(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_A2(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_A3(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_A4(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer self.set_A5(structB().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_A6(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_A7(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_A8(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_A1(self, a): self.A1 = a def set_A2(self, a): self.A2 = a def set_A3(self, a): self.A3 = a def set_A4(self, a): self.A4 = a def set_A5(self, a): self.A5 = a def set_A6(self, a): self.A6 = a def set_A7(self, a): self.A7 = a def set_A8(self, a): self.A8 = a def get_cort(self): return {'A1': self.A1, 'A2': self.A2, 'A3': self.A3, 'A4': self.A4, 'A5': self.A5.get_cort(), 'A6': self.A6, 'A7': self.A7, 'A8': self.A8} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct from enum import Enum class Types(Enum): type = '>' uint8 = f'{type}B' uint16 = f'{type}H' uint32 = f'{type}I' uint64 = f'{type}Q' int8 = f'{type}b' int16 = f'{type}h' int32 = f'{type}i' int64 = f'{type}q' float = f'{type}f' double = f'{type}d' char = f'{type}c' class BinaryReader: def __init__(self, source, offset): self.source = source self.offset = offset def read(self, pattern): value = struct.unpack_from(pattern.value, self.source, self.offset) self.offset += struct.calcsize(pattern.value) return value[0] def read_a(reader: BinaryReader): a1 = [] for _ in range(7): a1.append(reader.read(Types.uint8)) a2 = reader.read(Types.float) a3 = reader.read(Types.double) a4_size = reader.read(Types.uint16) a4_offset = reader.read(Types.uint32) a4 = [] a4_reader = BinaryReader(reader.source, a4_offset) for _ in range(a4_size): a4.append(read_b(BinaryReader(reader.source, a4_reader.read(Types.uint16)))) a5 = reader.read(Types.float) a6 = read_c(reader) a7 = read_d(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def read_b(reader: BinaryReader): b1 = reader.read(Types.float) b2 = reader.read(Types.int8) return dict(B1=b1, B2=b2) def read_c(reader: BinaryReader): c1 = reader.read(Types.int64) c2 = [] c2_size = reader.read(Types.uint32) c2_offset = reader.read(Types.uint32) c2_reader = BinaryReader(reader.source, c2_offset) for _ in range(c2_size): c2.append(c2_reader.read(Types.float)) c3 = reader.read(Types.uint64) c4 = [] for _ in range(2): c4.append(reader.read(Types.uint32)) return dict(C1=c1, C2=c2, C3=c3, C4=c4) def read_d(reader: BinaryReader): d1 = reader.read(Types.uint16) d2 = reader.read(Types.double) return dict(D1=d1, D2=d2) def main(data): reader = BinaryReader(data, offset=5) return read_a(reader)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_double(self): return self.read('d') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_a(reader): a_1_list = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode()) a_1 = ''.join(a_1_list) a_2 = read_b(reader) a_3 = reader.read_int64() a_4 = read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_d(reader)) return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4) def read_b(reader): b_1 = reader.read_int8() b_2 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: read_struct_address(data=reader.data, address=reader.read_uint16(), read=lambda reader: read_c(reader))) return dict(B1=b_1, B2=b_2) def read_c(reader): c_1 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) c_2 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint32()) c_3 = reader.read_float() return dict(C1=c_1, C2=c_2, C3=c_3) def read_d(reader): d_1 = reader.read_int64() d_2 = read_array(data=reader.data, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_int16()) return dict(D1=d_1, D2=d_2) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('int32', data, ofs) (D2, ofs) = parse('uint16', data, ofs) (D3, ofs) = parse('uint8', data, ofs) (D4, ofs) = parse('int16', data, ofs) (D5, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint8', data, ofs) C2 = [] (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint32', data, ofs) for i in range(C2_size): (elem, C2_adr) = struct_D(data, C2_adr) C2.append(elem) (C3, ofs) = parse('uint64', data, ofs) C4 = [] (C4_size, ofs) = parse('uint32', data, ofs) (C4_adr, ofs) = parse('uint16', data, ofs) for i in range(C4_size): (elem, C4_adr) = parse('float', data, C4_adr) C4.append(elem) (C5, ofs) = parse('uint32', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int16', data, ofs) (B2, ofs) = struct_C(data, ofs) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int8', data, ofs) (A2, ofs) = struct_B(data, ofs) A3 = '' (A3_size, ofs) = parse('uint32', data, ofs) (A3_adr, ofs) = parse('uint32', data, ofs) for i in range(A3_size): (elem, A3_adr) = parse('char', data, A3_adr) A3 += elem.decode() A4 = [] for i in range(4): (elem, ofs) = parse('int8', data, ofs) A4.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('float', data, ofs) (E2, ofs) = parse('int8', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int64', data, ofs) D2 = [] for i in range(2): (elem, ofs) = parse('uint8', data, ofs) D2.append(elem) return (dict(D1=D1, D2=D2), ofs) def struct_C(data, ofs): (C1, ofs) = parse('int64', data, ofs) (C2, ofs) = parse('uint16', data, ofs) (C3, ofs) = parse('int8', data, ofs) (C4, ofs) = parse('int8', data, ofs) (C5, ofs) = parse('float', data, ofs) (C6, ofs) = parse('uint64', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6), ofs) def struct_B(data, ofs): (B1, ofs) = struct_C(data, ofs) (B2_adr, ofs) = parse('uint16', data, ofs) (B2, elem) = struct_D(data, B2_adr) (B3, ofs) = parse('double', data, ofs) (B4, ofs) = parse('float', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint8', data, ofs) A2 = '' for i in range(6): (elem, ofs) = parse('char', data, ofs) A2 += elem.decode() (A3_adr, ofs) = parse('uint32', data, ofs) (A3, elem) = struct_B(data, A3_adr) A4 = [] for i in range(6): (elem, ofs) = struct_E(data, ofs) A4.append(elem) A5 = [] for i in range(2): (elem, ofs) = parse('int16', data, ofs) A5.append(elem) (A6, ofs) = parse('int64', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(f'>{FMT[ty]}', buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint16') (b1, _) = parse_c(buf, b1_offs) (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'uint32') (b4, offs) = parse(buf, offs, 'uint16') (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint32') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'int16') b5.append(val) (b6, offs) = parse(buf, offs, 'double') b7 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int16') b7.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') c2 = [] for _ in range(2): (c2_offs, offs) = parse(buf, offs, 'uint32') (val, c2_offs) = parse_d(buf, c2_offs) c2.append(val) (c3, offs) = parse(buf, offs, 'float') (c4_size, offs) = parse(buf, offs, 'uint16') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse(buf, c4_offs, 'int16') c4.append(val) c5 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int32') c5.append(val) (c6, offs) = parse(buf, offs, 'uint32') (c7, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def uint32uint32uint32(x, start): size = struct.unpack('>I', x[start:start + 4])[0] add = struct.unpack('>I', x[start + 4:start + 8])[0] a = struct.unpack('>' + 'I' * size, x[add:add + 4 * size]) return list(a) def E(x, start): return {'E1': struct.unpack('>I', x[start:start + 4])[0], 'E2': struct.unpack('>Q', x[start + 4:start + 12])[0], 'E3': struct.unpack('>b', x[start + 12:start + 13])[0], 'E4': struct.unpack('>h', x[start + 13:start + 15])[0], 'E5': struct.unpack('>H', x[start + 15:start + 17])[0], 'E6': list(struct.unpack('>hh', x[start + 17:start + 21])), 'E7': uint32uint32uint32(x, start + 21)} def D(x, start): return {'D1': struct.unpack('>b', x[start:start + 1])[0], 'D2': struct.unpack('>B', x[start + 1:start + 2])[0], 'D3': struct.unpack('>B', x[start + 2:start + 3])[0], 'D4': struct.unpack('>i', x[start + 3:start + 7])[0]} def C(x, start): return {'C1': D(x, start), 'C2': E(x, start + 7), 'C3': struct.unpack('>Q', x[start + 36:start + 44])[0]} def B(x, start): return {'B1': struct.unpack('>I', x[start:start + 4])[0], 'B2': struct.unpack('>i', x[start + 4:start + 8])[0], 'B3': struct.unpack('>b', x[start + 8:start + 9])[0], 'B4': struct.unpack('>q', x[start + 9:start + 17])[0], 'B5': struct.unpack('>f', x[start + 17:start + 21])[0]} def A(x, start): a = list(struct.unpack('>3s', x[start + 51:start + 54])) return {'A1': struct.unpack('>q', x[start:start + 8])[0], 'A2': struct.unpack('>B', x[start + 8:start + 9])[0], 'A3': [B(x, start + 9), B(x, start + 30)], 'A4': a[0].decode('utf-8'), 'A5': C(x, start + 54), 'A6': list(struct.unpack('>3I', x[start + 98:start + 110]))} def main(x): return A(x, 3)" "from struct import * def parse(buf, ty, offs): return (unpack_from(ty, buf, offs)[0], offs + calcsize(ty)) def parseA(buf, offs): (A1, offs) = parse(buf, '>d', offs) A2 = [] for i in range(2): (add, offs) = parseB(buf, offs) A2.append(add) (A3, offs) = parseD(buf, offs) return (dict(A1=A1, A2=A2, A3=A3), offs) def parseB(buf, offs): (B1, offs) = parse(buf, '>I', offs) (B2, offs) = parseC(buf, offs) (B3, offs) = parse(buf, '>H', offs) (size, offs) = parse(buf, '>I', offs) (adress, offs) = parse(buf, '>I', offs) B4 = [] for i in range(size): (add, adress) = parse(buf, '>Q', adress) B4.append(add) B5 = [] (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>I', offs) for i in range(size): (add, adress) = parse(buf, '>i', adress) B5.append(add) (B6, offs) = parse(buf, '>f', offs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), offs) def parseC(buf, offs): (C1, offs) = parse(buf, '>I', offs) (C2, offs) = parse(buf, '>d', offs) (C3, offs) = parse(buf, '>i', offs) (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>H', offs) C4 = [] for i in range(size): (add, adress) = parse(buf, '>h', adress) C4.append(add) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), offs) def parseD(buf, offs): (D1, offs) = parse(buf, '>Q', offs) D2 = [] for i in range(3): (add, offs) = parse(buf, '>f', offs) D2.append(add) (D3, offs) = parse(buf, '>b', offs) (D4, offs) = parse(buf, '>B', offs) (D5, offs) = parse(buf, '>I', offs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), offs) def main(buf): return parseA(buf, 3)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def main(buf): return parse_a(buf, 4)[0] def parse(buf, offs, dict_type): return (unpack_from(FMT[dict_type], buf, offs)[0], offs + calcsize(FMT[dict_type])) def parse_a(buf, offs): a1 = [] for i in range(4): (value, offs) = parse(buf, offs, 'float') a1.append(value) a2 = [] for i in range(6): (offs_b, offs) = parse(buf, offs, 'uint16') value = parse_b(buf, offs_b)[0] a2.append(value) (a3, offs) = parse(buf, offs, 'uint16') (a4, offs) = parse(buf, offs, 'int64') (a5, offs) = parse_c(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'int16') (b4, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'double') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = dict value = parse_d(buf, c3_offs)[0] c3 = value (c4, offs) = parse(buf, offs, 'uint8') c5 = [] for i in range(8): (value, offs) = parse(buf, offs, 'int8') c5.append(value) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): d1 = [] (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint32') for i in range(d1_size): (value, d1_offs) = parse(buf, d1_offs, 'float') d1.append(value) (d2, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2), offs)" "from struct import * FMT = dict(char='c', double='d', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'int32') (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'double') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_e(buf, a6_offs) (a7, offs) = parse_f(buf, offs) (a8, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2_offs, offs) = parse(buf, offs, 'uint32') (b2, b2_offs) = parse_c(buf, b2_offs) b3 = [] for _ in range(7): (val, offs) = parse_d(buf, offs) b3.append(val) return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode()) return (dict(C1=c1, C2=''.join(c2)), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint16') (e1_offs, offs) = parse(buf, offs, 'uint16') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'uint64') e1.append(val) (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'uint64') return (dict(E1=e1, E2=e2, E3=e3), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int8') f2 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int64') f2.append(val) (f3, offs) = parse(buf, offs, 'uint64') return (dict(F1=f1, F2=f2, F3=f3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): firstOffset = struct.calcsize('3c') structBoffset = struct.calcsize('>5siIi') ret = {} ret_structB_massive = [] for i in range(0, 3): (buffer_B_charmassive, buffer_B_int32_1, buffer_B_uint32, buffer_B_int32_2) = struct.unpack_from('>5siIi', data, firstOffset + i * structBoffset) bufferB = {} bufferB['B1'] = buffer_B_charmassive.decode('UTF-8') bufferB['B2'] = buffer_B_int32_1 bufferB['B3'] = buffer_B_uint32 bufferB['B4'] = buffer_B_int32_2 ret_structB_massive.append(bufferB) ret['A1'] = ret_structB_massive (address_struct_C, A_uint64, A_uint16) = struct.unpack_from('>HQH', data, firstOffset + structBoffset * 3) (C_int8, *C_massive_int32, D_int16_1, D_int32_1, D_int16_2) = struct.unpack_from('>b7ihih', data, address_struct_C) (*D_massive_uint8, D_int64, D_int32_2, D_int32_3, D_uint32, C_uint8) = struct.unpack_from('>5BqiiIB', data, address_struct_C + struct.calcsize('>b7ihih')) ret_structC = {} ret_structC['C1'] = C_int8 ret_structC['C2'] = C_massive_int32 ret_structC_structD = {} ret_structC_structD['D1'] = D_int16_1 ret_structC_structD['D2'] = D_int32_1 ret_structC_structD['D3'] = D_int16_2 ret_structC_structD['D4'] = D_massive_uint8 ret_structC_structD['D5'] = D_int64 ret_structC_structD['D6'] = D_int32_2 ret_structC_structD['D7'] = D_int32_3 ret_structC_structD['D8'] = D_uint32 ret_structC['C3'] = ret_structC_structD ret_structC['C4'] = C_uint8 ret['A2'] = ret_structC ret['A3'] = A_uint64 ret['A4'] = A_uint16 return ret" "from struct import unpack_from, calcsize from enum import Enum class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def readA(reader: BinaryReader): b_addr = reader.read(Types.uint32) A1 = readB(BinaryReader(source=reader.source, offset=b_addr)) A2 = reader.read(Types.uint64) A3 = reader.read(Types.uint64) d_addr = [reader.read(Types.uint16), reader.read(Types.uint16)] A4 = [readD(BinaryReader(source=reader.source, offset=d_addr[0])), readD(BinaryReader(source=reader.source, offset=d_addr[1]))] A5 = reader.read(Types.uint16) A6 = reader.read(Types.int8) return dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6) def readB(reader: BinaryReader): B1 = reader.read(Types.float) B2 = reader.read(Types.uint32) B3 = reader.read(Types.float) arr_len = reader.read(Types.uint16) arr_addr = reader.read(Types.uint16) B4 = masser(arr_len, arr_addr, reader.source) B5 = readC(reader) return dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5) def readC(reader: BinaryReader): C1 = reader.read(Types.uint64) C2 = reader.read(Types.uint64) C3 = reader.read(Types.uint32) return dict(C1=C1, C2=C2, C3=C3) def readD(reader: BinaryReader): D1 = reader.read(Types.int32) D2 = [reader.read(Types.uint16), reader.read(Types.uint16)] e_addr = reader.read(Types.uint16) D3 = readE(BinaryReader(source=reader.source, offset=e_addr)) D4 = [reader.read(Types.uint16), reader.read(Types.uint16), reader.read(Types.uint16), reader.read(Types.uint16), reader.read(Types.uint16)] return dict(D1=D1, D2=D2, D3=D3, D4=D4) def readE(reader: BinaryReader): E1 = reader.read(Types.uint32) E2 = reader.read(Types.uint16) E3 = reader.read(Types.uint16) E4 = reader.read(Types.uint8) E5 = reader.read(Types.uint64) E6 = [reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8), reader.read(Types.int8)] E7 = reader.read(Types.uint64) return dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7) def masser(size, offset, source): reader = BinaryReader(source, offset) rez = '' while reader.offset < offset + size: rez = rez + str(reader.read(Types.char))[2:3] return rez def main(data): reader = BinaryReader(source=data, offset=5) return readA(reader)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'double') (a3, offs) = parse(buf, offs, 'int32') (a4, offs) = parse(buf, offs, 'double') (a5, offs) = parse(buf, offs, 'uint16') (a6, offs) = parse(buf, offs, 'int32') a7 = [] for _ in range(5): (val, offs) = parse_b(buf, offs) a7.append(val) (a8, offs) = parse_c(buf, offs) return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, c2_offs) = parse_d(buf, c2_offs) (c3, offs) = parse(buf, offs, 'int8') (c4, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): d1 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint16') d1.append(val) (d2, offs) = parse(buf, offs, 'int16') (d3, offs) = parse(buf, offs, 'float') d4 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') d4.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from enum import Enum from struct import unpack_from, calcsize class Reader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, pattern): self.pattern = pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) return result[0] def readS(self, pattern, size): res = [] for i in range(0, size): self.pattern = pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) res.append(result[0]) return res def copy(self, offset): return Reader(offset, self.buffer) def readB(r): b1 = r.read('q') b2 = r.read('B') b3 = r.read('f') b4 = r.readS('h', 2) b5 = r.read('f') return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5) def readC(r): c1 = r.readS('f', 2) c2 = r.read('b') c3 = r.read('b') c4 = r.read('b') c5 = r.read('Q') c6 = r.read('h') c7 = r.read('B') return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7) def readD(r): d1 = r.read('h') d2 = r.read('q') d3 = r.read('I') d4 = r.read('i') return dict(D1=d1, D2=d2, D3=d3, D4=d4) def main(s): r = Reader(5, s) a1 = r.read('q') a2size = r.read('I') a2address = r.read('I') a2 = r.copy(a2address).readS('c', a2size) a2 = b''.join(a2).decode('ASCII') a3 = [] for i in range(0, 3): a3.append(readB(r)) a4size = r.read('H') a4address = r.read('I') a4 = r.copy(a4address).readS('f', a4size) a5 = r.read('b') a6 = readC(r.copy(r.read('H'))) a7 = readD(r) a8 = r.read('B') return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "from struct import * Format = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d') def parse(buf, offs, ty): return (unpack_from(Format[ty], buf, offs)[0], offs + calcsize(Format[ty])) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int16') c3 = [] for _ in range(2): (c3_data, offs) = parse(buf, offs, 'double') c3.append(c3_data) (c4_size, offs) = parse(buf, offs, 'uint16') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (c4_data, c4_offs) = parse(buf, c4_offs, 'int8') c4.append(c4_data) (c5, offs) = parse(buf, offs, 'uint8') (c6, offs) = parse(buf, offs, 'int16') (c7, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'uint16') b3 = [] for _ in range(4): (b3_offs, offs) = parse(buf, offs, 'uint16') (b3_data, _) = parse_c(buf, b3_offs) b3.append(b3_data) (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint16') b4 = [] for _ in range(b4_size): (b4_data, b4_offs) = parse(buf, b4_offs, 'int16') b4.append(b4_data) (b5_offs, offs) = parse(buf, offs, 'uint32') (b5, offs) = parse_d(buf, b5_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int16') (a2, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack, unpack_from, calcsize from typing import Any, Callable import pprint class BinaryReader: def __init__(self, data, offset=0): self.offset = offset self.data = data def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from('<' + pattern, self.data, self.offset) self.offset += size return data[0] def read_array(data: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) values = [] for i in range(size): values.append(read(reader)) return values def read_struct_address(data: str, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(data=data, offset=address) return read(reader) def read_f(reader: BinaryReader): f_1 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_int8()) f_2 = reader.read_uint8() f_3 = reader.read_int8() f_4 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8()) return dict(F1=f_1, F2=f_2, F3=f_3, F4=f_4) def read_e(reader: BinaryReader): e_1 = reader.read_int16() e_2 = reader.read_uint32() e_3 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_int16()) e_4 = reader.read_uint32() e_5 = reader.read_double() e_6 = reader.read_uint32() e_7 = reader.read_float() e_8 = reader.read_uint32() return dict(E1=e_1, E2=e_2, E3=e_3, E4=e_4, E5=e_5, E6=e_6, E7=e_7, E8=e_8) def read_d(reader: BinaryReader): d_1 = reader.read_uint64() d_2 = read_e(reader) return dict(D1=d_1, D2=d_2) def read_c(reader: BinaryReader): c_1 = read_d(reader) c_2 = reader.read_int32() c_3 = reader.read_uint16() c_4 = reader.read_int8() c_5 = reader.read_int16() c_6 = read_f(reader) c_7 = reader.read_double() return dict(C1=c_1, C2=c_2, C3=c_3, C4=c_4, C5=c_5, C6=c_6, C7=c_7) def read_b(reader: BinaryReader): b_1 = reader.read_uint32() b_2 = reader.read_int32() return dict(B1=b_1, B2=b_2) def read_a(reader: BinaryReader): a_1 = reader.read_uint32() a_2 = read_array(data=reader.data, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: read_b(reader)) a_3 = reader.read_int64() a_4 = read_struct_address(data=reader.data, address=reader.read_uint32(), read=lambda reader: read_c(reader)) a_5 = reader.read_int32() return dict(A1=a_1, A2=a_2, A3=a_3, A4=a_4, A5=a_5) def main(data): reader = BinaryReader(data) reader.read('cccc') return read_a(reader)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = '>Q' int64 = '>q' uint32 = '>I' int32 = '>i' uint16 = '>H' int16 = '>h' uint8 = '>B' int8 = '>b' float = '>f' double = '>d' char = '>c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, toSum: bool=False): if toSum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): return dict(E1=read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint16), structure_size=2), E2=reader.read(Primitive.uint32), E3=reader.read(Primitive.double), E4=reader.read(Primitive.uint64), E5=reader.read(Primitive.uint32), E6=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.float), structure_size=4)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.float), D2=reader.read(Primitive.uint64)) def read_c(reader: BinaryReader): return dict(C1=read_array(reader, 3, reader.offset, lambda reader: read_d(reader), structure_size=12, toSum=True), C2=reader.read(Primitive.uint64)) def read_b(reader: BinaryReader): return dict(B1=read_c(reader), B2=''.join(read_array(reader, reader.read(Primitive.uint32), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1)), B3=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.int16), structure_size=2), B4=read_e(reader), B5=reader.read(Primitive.double)) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.float), A2=read_b(reader)) def main(source): return read_a(BinaryReader(source, offset=5))" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_G(data, ofs): (G1, ofs) = parse('uint64', data, ofs) G2 = [] for i in range(2): (elem, ofs) = parse('uint64', data, ofs) G2.append(elem) (G3, ofs) = parse('int8', data, ofs) (G4, ofs) = parse('float', data, ofs) (G5, ofs) = parse('int32', data, ofs) return (dict(G1=G1, G2=G2, G3=G3, G4=G4, G5=G5), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int8', data, ofs) F2 = '' for i in range(8): (elem, ofs) = parse('char', data, ofs) F2 += elem.decode() (F3, ofs) = parse('int32', data, ofs) F4 = [] (F4_size, ofs) = parse('uint16', data, ofs) (F4_adr, ofs) = parse('uint32', data, ofs) for i in range(F4_size): (elem, F4_adr) = parse('uint8', data, F4_adr) F4.append(elem) (F5, ofs) = struct_G(data, ofs) (F6, ofs) = parse('uint32', data, ofs) (F7, ofs) = parse('int32', data, ofs) return (dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6, F7=F7), ofs) def struct_E(data, ofs): (E1, ofs) = parse('int16', data, ofs) (E2, ofs) = parse('uint32', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2, ofs) = parse('float', data, ofs) (D3, ofs) = parse('uint8', data, ofs) D4 = [] for i in range(6): (elem, ofs) = struct_E(data, ofs) D4.append(elem) (D5, ofs) = parse('uint32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) (C2, ofs) = parse('float', data, ofs) (C3, ofs) = parse('uint16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int32', data, ofs) (B2, ofs) = parse('int32', data, ofs) (B3, ofs) = struct_C(data, ofs) (B4, ofs) = struct_D(data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1_adr, ofs) = parse('uint16', data, ofs) (A1, elem) = struct_B(data, A1_adr) (A2, ofs) = struct_F(data, ofs) return (dict(A1=A1, A2=A2), ofs) def main(data): return struct_A(data, 4)[0]" "from enum import Enum from struct import unpack_from, calcsize class Reader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, pattern): self.pattern = pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) return result[0] def readS(self, pattern, size): res = [] for i in range(0, size): self.pattern = pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) res.append(result[0]) return res def copy(self, offset): return Reader(offset, self.buffer) def readB(r): b1 = r.read('I') b2 = readC(r) return dict(B1=b1, B2=b2) def readC(r): c1 = [] for i in range(0, 2): c1.append(readD(r)) c2 = r.read('Q') c3 = r.read('I') c4 = r.read('b') c5 = r.readS('I', 7) c6 = r.read('q') return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6) def readD(r): d1size = r.read('H') d1address = r.read('I') d1 = r.copy(d1address).readS('B', d1size) d2 = r.read('Q') return dict(D1=d1, D2=d2) def readE(r): e1 = r.read('d') e2 = r.readS('h', 7) e3 = r.read('d') return dict(E1=e1, E2=e2, E3=e3) def main(s): r = Reader(5, s) a1 = readB(r) a2 = r.read('I') a3 = r.read('i') a4 = readE(r.copy(r.read('H'))) a5 = r.read('i') a6 = r.read('B') a7 = r.read('q') return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2_size, offs) = parse(buf, offs, 'uint16') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'char') a2.append(val.decode()) (a3, offs) = parse(buf, offs, 'int64') a4 = [] for _ in range(5): (a4_offs, offs) = parse(buf, offs, 'uint16') (val, _) = parse_b(buf, a4_offs) a4.append(val) (a5_offs, offs) = parse(buf, offs, 'uint32') (a5, _) = parse_c(buf, a5_offs) (a6, offs) = parse(buf, offs, 'double') (a7_offs, offs) = parse(buf, offs, 'uint32') (a7, _) = parse_e(buf, a7_offs) (a8, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse_d(buf, offs) c4 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint8') c4.append(val) (c5, offs) = parse(buf, offs, 'int64') (c6, offs) = parse(buf, offs, 'float') (c7, offs) = parse(buf, offs, 'int8') (c8, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int16') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'uint64') (d5, offs) = parse(buf, offs, 'uint16') (d6, offs) = parse(buf, offs, 'uint64') (d7, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse(buf, offs, 'int8') e3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint8') e3.append(val) (e4, offs) = parse(buf, offs, 'float') (e5, offs) = parse(buf, offs, 'int8') (e6, offs) = parse(buf, offs, 'int16') (e7_size, offs) = parse(buf, offs, 'uint32') (e7_offs, offs) = parse(buf, offs, 'uint16') e7 = [] for _ in range(e7_size): (val, e7_offs) = parse(buf, e7_offs, 'uint8') e7.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def main(buf): return parse_a(buf, 5)[0]" "from enum import Enum from struct import unpack_from, calcsize class Reader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, pattern): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) return result[0] def readS(self, pattern, size): res = [] for i in range(0, size): self.pattern = '>' + pattern result = unpack_from(self.pattern, self.buffer, self.offset) self.offset += calcsize(self.pattern) res.append(result[0]) return res def copy(self, offset): return Reader(offset, self.buffer) def readB(r): b1 = r.read('f') b2 = r.read('B') b3 = r.read('i') b4 = r.read('h') b5 = readC(r) b6 = r.readS('B', 3) b7 = r.read('f') return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7) def readC(r): c1 = r.read('d') c2 = r.read('Q') c3 = r.read('H') c4 = [] for i in range(0, 4): c4.append(readD(r)) c5 = r.read('H') c6 = r.read('d') c7size = r.read('H') c7address = r.read('H') c7 = r.copy(c7address).readS('d', c7size) c8 = r.read('i') return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8) def readD(r): d1 = r.read('B') d2 = r.read('i') return dict(D1=d1, D2=d2) def readE(r): e1 = r.readS('h', 5) e2 = r.read('H') e3 = r.read('B') e4 = r.readS('Q', 2) e5 = r.read('f') e6 = r.read('Q') return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6) def main(s): r = Reader(5, s) a1 = readB(r) a2 = r.read('h') a3 = r.read('I') a4 = r.read('H') a5 = readE(r.copy(r.read('I'))) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (temp, iterator) = getNext(data, iterator, 2, 'IH5cIidbIIhHbd', data1) b_array = find(a_str[1], a_str[0] * b, f"">{a_str[0] * 'iB4cBbqbd'}"", data1) b_array = b_array.__iter__() b_list = [] for i in range(a_str[0]): b_list.append({'B1': b_array.__next__(), 'B2': b_array.__next__(), 'B3': (b_array.__next__() + b_array.__next__() + b_array.__next__() + b_array.__next__()).decode('utf-8'), 'B4': b_array.__next__(), 'B5': b_array.__next__(), 'B6': b_array.__next__(), 'B7': b_array.__next__(), 'B8': b_array.__next__()}) ans['A1'] = b_list ans |= {'A2': (a_str[2] + a_str[3] + a_str[4] + a_str[5] + a_str[6]).decode('utf-8'), 'A3': {'C1': a_str[7], 'C2': a_str[8], 'C3': a_str[9]}, 'A4': {'D1': a_str[10], 'D2': list(find(a_str[12], a_str[11], f'>{a_str[11]}b', data1)), 'D3': a_str[13], 'D4': a_str[14], 'D5': a_str[15], 'D6': a_str[16]}} return ans" "import struct def main(data): A = struct.unpack_from('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'int8') a2.append(val) (a3, offs) = parse(buf, offs, 'uint16') (a4, offs) = parse_b(buf, offs) (a5_offs, offs) = parse(buf, offs, 'uint16') (a5, a5_offs) = parse_d(buf, a5_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'uint8') b3 = [] for _ in range(2): (b3_offs, offs) = parse(buf, offs, 'uint16') (val, b3_offs) = parse_c(buf, b3_offs) b3.append(val) return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') c2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint16') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'double') d3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'double') d3.append(val) (d4, offs) = parse(buf, offs, 'int8') (d5, offs) = parse(buf, offs, 'double') (d6, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(data): A = struct.unpack_from('>iQ6chfhfhfhfIf2Hb2H5i', data, offset=4) A3 = '' for i in range(6): A3 += A[i + 2].decode('utf-8') D1 = list(struct.unpack_from('>' + str(A[18]) + 'b', data, offset=A[19])) E = struct.unpack_from('>2qQf2hdBi', data, offset=A[21]) return {'A1': A[0], 'A2': A[1], 'A3': A3, 'A4': [{'B1': A[8], 'B2': A[9]}, {'B1': A[10], 'B2': A[11]}, {'B1': A[12], 'B2': A[13]}, {'B1': A[14], 'B2': A[15]}], 'A5': {'C1': A[16], 'C2': A[17]}, 'A6': {'D1': D1, 'D2': A[20], 'D3': {'E1': [E[0], E[1]], 'E2': E[2], 'E3': E[3], 'E4': E[4], 'E5': E[5], 'E6': E[6], 'E7': E[7], 'E8': E[8]}, 'D4': A[22]}, 'A7': [A[23], A[24], A[25], A[26], A[27]]}" "import struct def main(buf): out = {} b = [{}, {}, {}, {}] c = {} d = {} e = {} adr_C = 0 arr32_len = 0 adr_arr32 = 0 arr16_len = 0 adr_arr16 = 0 e2 = 0 var = struct.unpack_from('@fhHfhHfhHfhHI', buf, 5) b[0]['B1'] = float(var[0]) b[0]['B2'] = var[1] b[0]['B3'] = var[2] b[1]['B1'] = var[3] b[1]['B2'] = var[4] b[1]['B3'] = var[5] b[2]['B1'] = var[6] b[2]['B2'] = var[7] b[2]['B3'] = var[8] b[3]['B1'] = var[9] b[3]['B2'] = var[10] b[3]['B3'] = var[11] out['A1'] = b adr_C = var[12] var = struct.unpack_from('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'double') (a2, offs) = parse(buf, offs, 'uint16') (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint64') (b2, offs) = parse_c(buf, offs) b3 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint16') b3.append(val) (b4, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): c1 = [] for _ in range(5): (val, offs) = parse_d(buf, offs) c1.append(val) (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse_e(buf, offs) c4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'float') c4.append(val) (c5, offs) = parse_f(buf, offs) (c6, offs) = parse(buf, offs, 'int16') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint64') (e2, offs) = parse(buf, offs, 'float') return (dict(E1=e1, E2=e2), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int16') f2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint32') f2.append(val) (f3, offs) = parse(buf, offs, 'float') return (dict(F1=f1, F2=f2, F3=f3), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_int16() d2 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint32(), structure_size=4) d3 = reader.read_uint32() d4 = reader.read_uint8() return dict(D1=d1, D2=d2, D3=d3, D4=d4) def read_c(reader: BinaryReader): c1 = reader.read_int16() c2 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint32(), read=lambda reader: reader.read_uint64(), structure_size=8) return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = ''.join(read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_char().decode('ascii'))) b2 = reader.read_uint64() b3 = reader.read_float() b4 = reader.read_int8() b5 = read_c(reader) b6 = reader.read_uint32() return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6) def read_a(reader: BinaryReader): a1 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: read_b(reader), structure_size=33) a2 = reader.read_uint64() a3 = reader.read_double() a4 = reader.read_float() a5 = read_d(reader) a6 = reader.read_float() a7 = reader.read_uint16() a8 = reader.read_int16() return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def read_a(buf, offs): (a1, offs) = read_b(buf, offs) (a2_size, offs) = parse(buf, offs, 'uint16') (a2_addr, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_addr) = parse(buf, a2_addr, 'int16') a2.append(val) (a3, offs) = parse(buf, offs, 'uint64') return ({'A1': a1, 'A2': a2, 'A3': a3}, offs) def read_b(buf, offs): (b1, offs) = read_c(buf, offs) (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'uint64') (b4, offs) = parse(buf, offs, 'int64') (b5, offs) = parse(buf, offs, 'uint16') (b6, offs) = parse(buf, offs, 'float') b7 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint32') b7.append(val) (b8, offs) = parse(buf, offs, 'int32') return ({'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8}, offs) def read_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_addr, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_addr) = read_d(buf, c1_addr) c1.append(val) (c2_addr, offs) = parse(buf, offs, 'uint32') c2 = read_e(buf, c2_addr)[0] (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse(buf, offs, 'int16') (c5, offs) = parse(buf, offs, 'uint16') return ({'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5}, offs) def read_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'uint8') (d3, offs) = parse(buf, offs, 'uint32') (d4, offs) = parse(buf, offs, 'int8') return ({'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}, offs) def read_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') (e2, offs) = parse(buf, offs, 'float') (e3_size, offs) = parse(buf, offs, 'uint16') (e3_addr, offs) = parse(buf, offs, 'uint32') e3 = [] for _ in range(e3_size): (val, e3_addr) = parse(buf, e3_addr, 'uint32') e3.append(val) (e4, offs) = parse(buf, offs, 'uint16') (e5, offs) = parse(buf, offs, 'int64') (e6, offs) = parse(buf, offs, 'double') return ({'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6}, offs) def main(buf): return read_a(buf, 4)[0]" "import struct def main(data): A = struct.unpack_from('>bBhqIHqh2H', data, offset=3) B1 = list(struct.unpack_from('>' + str(A[4]) + 'c', data, offset=A[5])) for i in range(A[4]): B1[i] = B1[i].decode('utf-8') B1 = ''.join(B1) C = [[], []] C[0] = struct.unpack_from('>ibibI2H7I', data, offset=A[8]) C[1] = struct.unpack_from('>ibibI2H7I', data, offset=A[9]) D3 = [[], []] D3[0] = list(struct.unpack_from('>' + str(C[0][4]) + 'b', data, offset=C[0][5])) D3[1] = list(struct.unpack_from('>' + str(C[1][4]) + 'b', data, offset=C[1][5])) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': A[3], 'A5': {'B1': B1, 'B2': A[6]}, 'A6': A[7], 'A7': [{'C1': C[0][0], 'C2': C[0][1], 'C3': {'D1': C[0][2], 'D2': C[0][3], 'D3': D3[0], 'D4': C[0][6]}, 'C4': [C[0][7], C[0][8], C[0][9], C[0][10], C[0][11], C[0][12], C[0][13]]}, {'C1': C[1][0], 'C2': C[1][1], 'C3': {'D1': C[1][2], 'D2': C[1][3], 'D3': D3[1], 'D4': C[1][6]}, 'C4': [C[1][7], C[1][8], C[1][9], C[1][10], C[1][11], C[1][12], C[1][13]]}]}" "from struct import * FMT = dict(char='c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint64') (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse_b(buf, offs) (a4, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse(buf, offs, 'int32') (b4_offs, offs) = parse(buf, offs, 'uint16') (val, b4_offs) = parse_c(buf, b4_offs) b4 = val (b5_offs, offs) = parse(buf, offs, 'uint16') (val, b5_offs) = parse_e(buf, b5_offs) b5 = val (b6, offs) = parse(buf, offs, 'uint32') (b7, offs) = parse(buf, offs, 'int64') (b8, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'uint64') (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'uint64') c6 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) c6.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'int8') (d3, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse_f(buf, offs) (e3, offs) = parse(buf, offs, 'int64') (e4, offs) = parse(buf, offs, 'uint32') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def parse_f(buf, offs): (f1_size, offs) = parse(buf, offs, 'uint32') (f1_offs, offs) = parse(buf, offs, 'uint32') f1 = [] for _ in range(f1_size): (val, f1_offs) = parse(buf, f1_offs, 'int32') f1.append(val) f2 = [] for i in range(3): (val, offs) = parse(buf, offs, 'uint8') f2.append(val) f3 = [] for i in range(2): (val, offs) = parse(buf, offs, 'uint8') f3.append(val) (f4, offs) = parse(buf, offs, 'uint16') return (dict(F1=f1, F2=f2, F3=f3, F4=f4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'double') a4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint16') a4.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse_c(buf, offs) (b3_size, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint16') b3 = [] for _ in range(b3_size): (val, b3_offs) = parse(buf, b3_offs, 'char') b3.append(val.decode()) (b4, offs) = parse(buf, offs, 'uint8') b5 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint32') (val_d, _) = parse_d(buf, val) b5.append(val_d) return (dict(B1=b1, B2=b2, B3=''.join(b3), B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse(buf, offs, 'float') (c5, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') (d2, offs) = parse(buf, offs, 'uint64') d3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint16') d3.append(val) (d4, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "def toFloat(x, a): return (1 - (x[a + 0] >> 7 << 1)) * 2 ** (((x[a + 0] & 127) << 1) + (x[a + 1] >> 7) - ((1 << 7) - 1)) * (1 + (((x[a + 1] & 127) << 16) + (x[a + 2] << 8) + x[a + 3]) / 2 ** 23) def toDouble(x, a): return (1 - (x[a] >> 7 << 1)) * 2 ** (((x[a] & 127) << 4) + (x[a + 1] >> 4) - ((1 << 10) - 1)) * (1 + (((x[a + 1] & 15) << 48) + (x[a + 2] << 40) + (x[a + 3] << 32) + (x[a + 4] << 24) + (x[a + 5] << 16) + (x[a + 6] << 8) + x[a + 7]) / (1 << 52)) def toUInt(x, n, a): res = 0 for i in range(0, n): res |= x[a + i] << 8 * (n - 1 - i) return res def toInt(x, n, a): res = (x[a] & 127) << 8 * (n - 1) for i in range(1, n): res |= x[a + i] << 8 * (n - 1 - i) return res - (1 << 8 * n - 1) * (x[a] >> 7) def main(x): AB1Address = toUInt(x, 2, 3) AB2Address = toUInt(x, 2, 5) AGSize = toUInt(x, 2, 7) AGAddress = toUInt(x, 2, 9) AInt32 = toInt(x, 4, 11) AInt16Size = toUInt(x, 4, 15) AInt16Address = toUInt(x, 4, 19) C1DAddress = toUInt(x, 4, AB1Address) C1EAddress = toUInt(x, 4, AB1Address + 4) C2DAddress = toUInt(x, 4, AB2Address) C2EAddress = toUInt(x, 4, AB2Address + 4) B1FAddress = toUInt(x, 2, AB1Address + 8) B2FAddress = toUInt(x, 2, AB2Address + 8) C1D1 = toInt(x, 8, C1DAddress) C1D2 = toInt(x, 8, C1DAddress + 8) C2D1 = toInt(x, 8, C2DAddress) C2D2 = toInt(x, 8, C2DAddress + 8) C1E1 = [toUInt(x, 2, C1EAddress), toUInt(x, 2, C1EAddress + 2), toUInt(x, 2, C1EAddress + 4), toUInt(x, 2, C1EAddress + 6)] C1E2 = toUInt(x, 1, C1EAddress + 8) C1E3 = toInt(x, 2, C1EAddress + 9) C1E4 = toInt(x, 4, C1EAddress + 11) C2E1 = [toUInt(x, 2, C2EAddress), toUInt(x, 2, C2EAddress + 2), toUInt(x, 2, C2EAddress + 4), toUInt(x, 2, C2EAddress + 6)] C2E2 = toUInt(x, 1, C2EAddress + 8) C2E3 = toInt(x, 2, C2EAddress + 9) C2E4 = toInt(x, 4, C2EAddress + 11) B1F1 = toUInt(x, 1, B1FAddress) B1F2 = toFloat(x, B1FAddress + 1) B1F3 = toInt(x, 4, B1FAddress + 5) B1F4 = toUInt(x, 2, B1FAddress + 9) B1F5 = toUInt(x, 2, B1FAddress + 11) B1F6 = toUInt(x, 1, B1FAddress + 13) B1F7 = toUInt(x, 1, B1FAddress + 14) B1F8 = toInt(x, 1, B1FAddress + 15) B2F1 = toUInt(x, 1, B2FAddress) B2F2 = toFloat(x, B2FAddress + 1) B2F3 = toInt(x, 4, B2FAddress + 5) B2F4 = toUInt(x, 2, B2FAddress + 9) B2F5 = toUInt(x, 2, B2FAddress + 11) B2F6 = toUInt(x, 1, B2FAddress + 13) B2F7 = toUInt(x, 1, B2FAddress + 14) B2F8 = toInt(x, 1, B2FAddress + 15) AInt16 = [] for i in range(AInt16Size): AInt16.append(toInt(x, 2, AInt16Address + i * 2)) AG = [] for i in range(AGSize): address = toUInt(x, 2, AGAddress + 2 * i) G = {'G1': toUInt(x, 4, address), 'G2': toDouble(x, address + 4), 'G3': toUInt(x, 2, address + 12)} AG.append(G) y = {'A1': [{'B1': {'C1': {'D1': C1D1, 'D2': C1D2}, 'C2': {'E1': C1E1, 'E2': C1E2, 'E3': C1E3, 'E4': C1E4}}, 'B2': {'F1': B1F1, 'F2': B1F2, 'F3': B1F3, 'F4': B1F4, 'F5': B1F5, 'F6': B1F6, 'F7': B1F7, 'F8': B1F8}}, {'B1': {'C1': {'D1': C2D1, 'D2': C2D2}, 'C2': {'E1': C2E1, 'E2': C2E2, 'E3': C2E3, 'E4': C2E4}}, 'B2': {'F1': B2F1, 'F2': B2F2, 'F3': B2F3, 'F4': B2F4, 'F5': B2F5, 'F6': B2F6, 'F7': B2F7, 'F8': B2F8}}], 'A2': AG, 'A3': AInt32, 'A4': AInt16} return y" "import struct def mparse_e(data, pointer): (e1, e2) = struct.unpack('b', bytes, offset=B_offset)[0] B_offset += 1 B_dict['B2'] = unpack_from('>f', bytes, offset=B_offset)[0] B_offset += 4 B_dict['B3'] = unpack_from('>q', bytes, offset=B_offset)[0] B_offset += 8 C_size = 2 C_addresses_struct = list(unpack_from('>' + str(C_size) + 'I', bytes, offset=B_offset)) B_offset += 4 * C_size B_dict['B4'] = [] C_offset = C_addresses_struct[0] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) C_offset = C_addresses_struct[1] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) A_dict['A1'].append(B_dict) A_offset = B_offset B_offset = A_offset B_dict = {} B_dict['B1'] = unpack_from('>b', bytes, offset=B_offset)[0] B_offset += 1 B_dict['B2'] = unpack_from('>f', bytes, offset=B_offset)[0] B_offset += 4 B_dict['B3'] = unpack_from('>q', bytes, offset=B_offset)[0] B_offset += 8 C_size = 2 C_addresses_struct = list(unpack_from('>' + str(C_size) + 'I', bytes, offset=B_offset)) B_offset += 4 * C_size B_dict['B4'] = [] C_offset = C_addresses_struct[0] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) C_offset = C_addresses_struct[1] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) A_dict['A1'].append(B_dict) A_offset = B_offset B_offset = A_offset B_dict = {} B_dict['B1'] = unpack_from('>b', bytes, offset=B_offset)[0] B_offset += 1 B_dict['B2'] = unpack_from('>f', bytes, offset=B_offset)[0] B_offset += 4 B_dict['B3'] = unpack_from('>q', bytes, offset=B_offset)[0] B_offset += 8 C_size = 2 C_addresses_struct = list(unpack_from('>' + str(C_size) + 'I', bytes, offset=B_offset)) B_offset += 4 * C_size B_dict['B4'] = [] C_offset = C_addresses_struct[0] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) C_offset = C_addresses_struct[1] C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C3'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 B_dict['B4'].append(C_dict) A_dict['A1'].append(B_dict) A_offset = B_offset D_size = 1 D_addresses_struct = list(unpack_from('>' + str(D_size) + 'I', bytes, offset=A_offset)) A_offset += 4 * D_size A_dict['A2'] = [] D_offset = D_addresses_struct[0] D_dict = {} some_size = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D1'] = list(unpack_from('>' + str(some_size) + 'B', bytes, offset=some_address)) D_dict['D2'] = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 D_dict['D3'] = unpack_from('>d', bytes, offset=D_offset)[0] D_offset += 8 some_size = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D4'] = list(unpack_from('>' + str(some_size) + 'I', bytes, offset=some_address)) D_dict['D5'] = unpack_from('>i', bytes, offset=D_offset)[0] D_offset += 4 A_dict['A2'].append(D_dict) A_dict['A2'] = A_dict['A2'][0] A_dict['A3'] = unpack_from('>B', bytes, offset=A_offset)[0] A_offset += 1 A_dict['A4'] = unpack_from('>q', bytes, offset=A_offset)[0] A_offset += 8 return A_dict" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('float', data, ofs) E2 = [] for i in range(2): (elem, ofs) = parse('float', data, ofs) E2.append(elem) (E3, ofs) = parse('uint16', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2, ofs) = parse('uint8', data, ofs) D3 = [] (D3_size, ofs) = parse('uint32', data, ofs) (D3_adr, ofs) = parse('uint16', data, ofs) for i in range(D3_size): (elem, D3_adr) = parse('uint16', data, D3_adr) D3.append(elem) (D4, ofs) = parse('double', data, ofs) (D5, ofs) = parse('uint16', data, ofs) D6 = [] for i in range(5): (elem, ofs) = parse('int8', data, ofs) D6.append(elem) (D7, ofs) = parse('int32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6, D7=D7), ofs) def struct_C(data, ofs): (C1, ofs) = struct_D(data, ofs) (C2, ofs) = parse('uint8', data, ofs) (C3, ofs) = struct_E(data, ofs) (C4, ofs) = parse('uint8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): (B1, ofs) = parse('int8', data, ofs) (B2, ofs) = parse('uint32', data, ofs) B3 = '' for i in range(2): (elem, ofs) = parse('char', data, ofs) B3 += elem.decode() return (dict(B1=B1, B2=B2, B3=B3), ofs) def struct_A(data, ofs): A1 = [] (A1_size, ofs) = parse('uint32', data, ofs) (A1_adr, ofs) = parse('uint16', data, ofs) for i in range(A1_size): (B_adr, A1_adr) = parse('uint16', data, A1_adr) (elem, lop) = struct_B(data, B_adr) A1.append(elem) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, elem) = struct_C(data, A2_adr) (A3, ofs) = parse('uint64', data, ofs) (A4, ofs) = parse('int32', data, ofs) (A5, ofs) = parse('int8', data, ofs) (A6, ofs) = parse('uint32', data, ofs) (A7, ofs) = parse('int8', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_d(reader: BinaryReader): d1 = reader.read_float() d2 = [reader.read_uint64(), reader.read_uint64(), reader.read_uint64(), reader.read_uint64(), reader.read_uint64(), reader.read_uint64()] d3 = [reader.read_int8(), reader.read_int8()] d4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_int16(), structure_size=2) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def read_c(reader: BinaryReader): c1 = ''.join(read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_char().decode('ascii'))) c2 = read_array(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_d(reader))[0] return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = reader.read_uint16() b2 = reader.read_uint32() b3 = reader.read_uint16() return dict(B1=b1, B2=b2, B3=b3) def read_a(reader: BinaryReader): a1 = reader.read_uint64() a2 = reader.read_int64() a3 = reader.read_int32() a4 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: read_b(reader), structure_size=8) a5 = read_c(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5) def main(source): reader = BinaryReader(source) reader.read('ccc') return read_a(reader)" "from struct import unpack_from def main(bytes): A_offset = 4 A_dict = {} A_dict['A1'] = unpack_from('qB6cIHh2Ih2IBH', data, offset=4) A3 = '' for i in range(6): A3 += A[i + 2].decode('utf-8') A4 = list(struct.unpack_from('>' + str(A[8]) + 'c', data, offset=A[9])) for i in range(A[8]): A4[i] = A4[i].decode('utf-8') A4 = ''.join(A4) B = [[], []] B[0] = struct.unpack_from('>HQd', data, offset=A[11]) B[1] = struct.unpack_from('>HQd', data, offset=A[12]) C2 = list(struct.unpack_from('>' + str(A[14]) + 'q', data, offset=A[15])) D = struct.unpack_from('>HhQ', data, offset=A[17]) return {'A1': A[0], 'A2': A[1], 'A3': A3, 'A4': A4, 'A5': A[10], 'A6': [{'B1': B[0][0], 'B2': B[0][1], 'B3': B[0][2]}, {'B1': B[1][0], 'B2': B[1][1], 'B3': B[1][2]}], 'A7': {'C1': A[13], 'C2': C2, 'C3': A[16]}, 'A8': {'D1': D[0], 'D2': D[1], 'D3': D[2]}}" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int16') (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse(buf, offs, 'int32') a5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'char') a5.append(val.decode()) (a6, offs) = parse(buf, offs, 'int64') (a7_offs, offs) = parse(buf, offs, 'uint16') (a7, a7_offs) = parse_e(buf, a7_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=''.join(a5), A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'int32') (b4, offs) = parse(buf, offs, 'int64') (b5, offs) = parse_c(buf, offs) (b6, offs) = parse(buf, offs, 'uint32') (b7, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'double') c3_offs = [] c3 = [] for _ in range(4): (val1, offs) = parse(buf, offs, 'uint32') c3_offs.append(val1) (val2, val1) = parse_d(buf, val1) c3.append(val2) return (dict(C1=c1, C2=c2, C3=c3), offs) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'int32') d3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int16') d3.append(val) return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint64') (e2_size, offs) = parse(buf, offs, 'uint16') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int8') e2.append(val) e3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int16') e3.append(val) return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'int64') (b3, offs) = parse(buf, offs, 'float') (b4, offs) = parse(buf, offs, 'uint32') (b5, offs) = parse(buf, offs, 'uint8') b6 = [] for _ in range(2): (b6_offs, offs) = parse(buf, offs, 'uint16') (val, b6_offs) = parse_c(buf, b6_offs) b6.append(val) (b7, offs) = parse_d(buf, offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int8') (c3_size, offs) = parse(buf, offs, 'uint16') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'float') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int8') (d2, offs) = parse(buf, offs, 'float') (d3, offs) = parse(buf, offs, 'uint16') d4 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int32') d4.append(val) (d5_size, offs) = parse(buf, offs, 'uint16') (d5_offs, offs) = parse(buf, offs, 'uint16') d5 = [] for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'int16') d5.append(val) (d6, offs) = parse(buf, offs, 'int64') (d7, offs) = parse(buf, offs, 'int64') (d8, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int32') (a3, offs) = parse(buf, offs, 'int8') (a4, offs) = parse(buf, offs, 'int32') (a5, offs) = parse(buf, offs, 'uint8') (a6_offs, offs) = parse(buf, offs, 'uint32') (a6, a6_offs) = parse_f(buf, a6_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint32') (b1, b1_offs) = parse_c(buf, b1_offs) (b2, offs) = parse(buf, offs, 'int8') b3 = [] (b3_size, offs) = parse(buf, offs, 'uint32') (b3_offs, offs) = parse(buf, offs, 'uint16') for _ in range(b3_size): (val, b3_offs) = parse(buf, b3_offs, 'int32') b3.append(val) (b4, offs) = parse(buf, offs, 'int16') (b5, offs) = parse_e(buf, offs) (b6, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): c1 = [] (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint32') for _ in range(c1_size): (val, c1_offs) = parse_d(buf, c1_offs) c1.append(val) (c2, offs) = parse(buf, offs, 'float') (c3, offs) = parse(buf, offs, 'uint8') (c4, offs) = parse(buf, offs, 'uint8') c5 = [] (c5_size, offs) = parse(buf, offs, 'uint32') (c5_offs, offs) = parse(buf, offs, 'uint32') for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'int8') c5.append(val) c6 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int32') c6.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'float') e2 = [] (e2_size, offs) = parse(buf, offs, 'uint32') (e2_offs, offs) = parse(buf, offs, 'uint16') for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int32') e2.append(val) return (dict(E1=e1, E2=e2), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'uint8') (f2, offs) = parse(buf, offs, 'uint8') (f3, offs) = parse(buf, offs, 'int16') (f4, offs) = parse(buf, offs, 'uint64') return (dict(F1=f1, F2=f2, F3=f3, F4=f4), offs) def main(buf): return parse_a(buf, 5)[0]" "def f11(bin): import struct B_pointer = struct.unpack('>H', bin[4:6])[0] B1 = str(struct.unpack('>3s', bin[B_pointer:B_pointer + 3])[0])[2:5] B2 = struct.unpack('>q', bin[B_pointer + 3:B_pointer + 11])[0] B3_size = 4 B3_pointers = struct.unpack(f'>{B3_size}H', bin[B_pointer + 11:B_pointer + 11 + B3_size * 2]) B3 = list() for B3_pointer in B3_pointers: C1 = struct.unpack('>I', bin[B3_pointer:B3_pointer + 4])[0] C2_size = 7 C2 = list(struct.unpack(f'>{C2_size}B', bin[B3_pointer + 4:B3_pointer + 4 + 1 * C2_size])) C3_size = struct.unpack('>I', bin[B3_pointer + 4 + 1 * C2_size:B3_pointer + 4 + 1 * C2_size + 4])[0] C3_pointer = struct.unpack('>H', bin[B3_pointer + 8 + 1 * C2_size:B3_pointer + 8 + 1 * C2_size + 2])[0] C3 = list(struct.unpack(f'>{C3_size}B', bin[C3_pointer:C3_pointer + 1 * C3_size])) B3.append({'C1': C1, 'C2': C2, 'C3': C3}) B4 = struct.unpack('>d', bin[B_pointer + 11 + B3_size * 2:B_pointer + 19 + B3_size * 2])[0] B5 = struct.unpack('>H', bin[B_pointer + 19 + B3_size * 2:B_pointer + 21 + B3_size * 2])[0] B6_size = struct.unpack('>I', bin[B_pointer + 21 + B3_size * 2:B_pointer + 25 + B3_size * 2])[0] B6_pointer = struct.unpack('>H', bin[B_pointer + 25 + B3_size * 2:B_pointer + 27 + B3_size * 2])[0] B6 = list(struct.unpack(f'>{B6_size}h', bin[B6_pointer:B6_pointer + B6_size * 2])) B7 = struct.unpack('>L', bin[B_pointer + 27 + B3_size * 2:B_pointer + 31 + B3_size * 2])[0] B8 = struct.unpack('>f', bin[B_pointer + 31 + B3_size * 2:B_pointer + 35 + B3_size * 2])[0] D_pointer = struct.unpack('>L', bin[6:10])[0] D1 = struct.unpack('>q', bin[D_pointer:D_pointer + 8])[0] D2 = struct.unpack('>L', bin[D_pointer + 8:D_pointer + 12])[0] D3 = struct.unpack('>H', bin[D_pointer + 12:D_pointer + 14])[0] D4 = struct.unpack('>L', bin[D_pointer + 14:D_pointer + 18])[0] A3 = struct.unpack('>q', bin[10:18])[0] A4 = struct.unpack('>h', bin[18:20])[0] struct_D = {'D1': D1, 'D2': D2, 'D3': D3, 'D4': D4} struct_B = {'B1': B1, 'B2': B2, 'B3': B3, 'B4': B4, 'B5': B5, 'B6': B6, 'B7': B7, 'B8': B8} struct_A = {'A1': struct_B, 'A2': struct_D, 'A3': A3, 'A4': A4} return struct_A def main(n): return f11(n)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('double', data, ofs) (D2, ofs) = parse('uint8', data, ofs) (D3, ofs) = parse('uint32', data, ofs) (D4, ofs) = parse('int32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint8', data, ofs) (C2, ofs) = parse('int8', data, ofs) (C3, ofs) = parse('uint64', data, ofs) (C4, ofs) = parse('uint8', data, ofs) (C5, ofs) = parse('uint8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): B1 = '' (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint32', data, ofs) for i in range(B1_size): (elem, B1_adr) = parse('char', data, B1_adr) B1 += elem.decode() B2 = [] for i in range(3): (elem, ofs) = struct_C(data, ofs) B2.append(elem) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint64', data, ofs) (A2, ofs) = parse('int8', data, ofs) (A3, ofs) = parse('uint16', data, ofs) (A4_adr, ofs) = parse('uint16', data, ofs) (A4, elem) = struct_B(data, A4_adr) A5 = [] (A5_size, ofs) = parse('uint16', data, ofs) (A5_adr, ofs) = parse('uint16', data, ofs) for i in range(A5_size): (elem, A5_adr) = struct_D(data, A5_adr) A5.append(elem) A6 = [] for i in range(2): (elem, ofs) = parse('float', data, ofs) A6.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def main(x): result = {} result['A1'] = struct.unpack('>d', x[3:11])[0] B = [] for i in range(2): Bd = {} Bd['B1'] = struct.unpack('>Q', x[11 + i * 12:11 + i * 12 + 8])[0] Bd['B2'] = struct.unpack('>f', x[11 + i * 12 + 8:11 + i * 12 + 12])[0] B.append(Bd) result['A2'] = B result['A3'] = struct.unpack('>B', x[35:36])[0] clink = struct.unpack('>H', x[36:38])[0] C = {} C['C1'] = struct.unpack('>q', x[clink:clink + 8])[0] C['C2'] = struct.unpack('>q', x[clink + 8:clink + 16])[0] c3len = struct.unpack('>I', x[clink + 16:clink + 20])[0] c3link = struct.unpack('>I', x[clink + 20:clink + 24])[0] C['C3'] = '' for i in range(c3len): tmp = struct.unpack('>c', x[c3link + i:c3link + i + 1])[0].decode() C['C3'] = C['C3'] + tmp C['C4'] = struct.unpack('>h', x[clink + 24:clink + 26])[0] dlink = struct.unpack('>I', x[clink + 26:clink + 30])[0] D = {} d1len = struct.unpack('>H', x[dlink:dlink + 2])[0] d1link = struct.unpack('>H', x[dlink + 2:dlink + 4])[0] D['D1'] = [] for i in range(d1len): D['D1'].append(struct.unpack('>I', x[d1link + i * 4:d1link + i * 4 + 4])[0]) D['D2'] = [] for i in range(3): D['D2'].append(struct.unpack('>I', x[dlink + i * 4 + 4:dlink + i * 4 + 8])[0]) d3len = struct.unpack('>H', x[dlink + 16:dlink + 18])[0] d3link = struct.unpack('>I', x[dlink + 18:dlink + 22])[0] D['D3'] = [] for i in range(d3len): D['D3'].append(struct.unpack('>H', x[d3link + i * 2:d3link + i * 2 + 2])[0]) C['C5'] = D result['A4'] = C return result" "import struct def structA(data, pointer): fa1 = struct.unpack('<2H', data[pointer:pointer + 4]) a1 = [structB(data, fa1[0]), structB(data, fa1[1])] (a2,) = struct.unpack('{size_arr_c}H', raw_data[adress_arr_c:adress_arr_c + calcsize(f'>{size_arr_c}H')]) arr = [] for adress_c in data_arr: c = {f'C{i}': None for i in range(1, 6)} data_c = unpack(PATTERN_C, raw_data[adress_c:adress_c + calcsize(PATTERN_C)]) (adress_d, c['C2'], c['C3'], c['C4'], c['C5']) = data_c d = {f'D{i}': None for i in range(1, 7)} data_d = unpack(PATTERN_D, raw_data[adress_d:adress_d + calcsize(PATTERN_D)]) (size_arr_i32, adress_arr_i32, d['D2'], d['D3'], d['D4'], size_arr_ui8, adress_arr_ui8, d['D6']) = data_d d['D1'] = list(unpack(f'>{size_arr_i32}l', raw_data[adress_arr_i32:adress_arr_i32 + calcsize('>l') * size_arr_i32])) d['D5'] = list(unpack(f'>{size_arr_ui8}B', raw_data[adress_arr_ui8:adress_arr_ui8 + calcsize('>B') * size_arr_ui8])) c['C1'] = d arr.append(c) b['B2'] = arr b['B6'] = list(unpack(f'>{size_arr_ui32}L', raw_data[adress_arr_ui32:adress_arr_ui32 + calcsize('>L') * size_arr_ui32])) a['A1'] = b return a" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint32') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse(buf, offs, 'int32') (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse(buf, offs, 'int16') (a5_offs, offs) = parse(buf, offs, 'uint16') (a5, _) = parse_c(buf, a5_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1_offs, offs) = parse(buf, offs, 'uint32') (c1, _) = parse_d(buf, c1_offs) (c2, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2_offs, offs) = parse(buf, offs, 'uint16') (d2, _) = parse_e(buf, d2_offs) (d3, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint16') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'uint32') e1.append(val) (e2_size, offs) = parse(buf, offs, 'uint32') (e2_offs, offs) = parse(buf, offs, 'uint16') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int8') e2.append(val) (e3_size, offs) = parse(buf, offs, 'uint32') (e3_offs, offs) = parse(buf, offs, 'uint16') e3 = [] for _ in range(e3_size): (val, e3_offs) = parse(buf, e3_offs, 'uint8') e3.append(val) return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct from struct import * from pprint import pprint types = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', uint64='Q', float='f') type_size = dict(char=1, int8=1, uint8=1, int16=2, uint16=2, int32=4, uint32=4, uint64=8, float=4) pointer = 5 def parse_A(data): A = {} global pointer global types global type_size A['A1'] = unpack(types['float'], data[pointer:pointer + type_size['float']])[0] pointer += type_size['float'] A['A2'] = parse_B(data, pointer) return A def parse_B(data, address): B = {} global pointer global types global type_size B['B1'] = [] for i in range(4): b = unpack(types['uint16'], data[address:address + type_size['uint16']])[0] B['B1'].append(b) address += type_size['uint16'] for i in range(4): B['B1'][i] = parse_C(data, B['B1'][i]) B['B2'] = unpack(types['float'], data[address:address + type_size['float']])[0] address += type_size['float'] B['B3'] = unpack(types['uint8'], data[address:address + type_size['uint8']])[0] address += type_size['uint8'] B['B4'] = unpack(types['int16'], data[address:address + type_size['int16']])[0] address += type_size['int16'] size = unpack(types['uint32'], data[address:address + type_size['uint32']])[0] address += 4 address_2 = unpack(types['uint16'], data[address:address + type_size['uint16']])[0] address += 2 B['B5'] = [] for i in range(size): b = unpack(types['int8'], data[address_2 + i * type_size['int8']:address_2 + i * type_size['int8'] + type_size['int8']]) B['B5'].append(b[0]) return B def parse_C(data, address): global pointer global types global type_size C = {} address_2 = unpack(types['uint32'], data[address:address + type_size['uint32']])[0] address += type_size['uint32'] C['C1'] = parse_D(data, address_2) C['C2'] = unpack(types['uint8'], data[address:address + type_size['uint8']])[0] address += type_size['uint8'] C['C3'] = [] for i in range(2): b = unpack(types['float'], data[address:address + type_size['float']])[0] address += type_size['float'] C['C3'].append(b) C['C4'] = unpack(types['int32'], data[address:address + type_size['int32']])[0] address += type_size['int32'] C['C5'] = unpack(types['uint64'], data[address:address + type_size['uint64']])[0] address += type_size['uint64'] return C def parse_D(data, address): global pointer global types global type_size D = {} D['D1'] = [] for i in range(2): b = unpack(types['int16'], data[address:address + type_size['int16']])[0] address += type_size['int16'] D['D1'].append(b) D['D2'] = unpack(types['int8'], data[address:address + type_size['int8']])[0] address += type_size['int8'] return D def main(data): return parse_A(data)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_G(data, ofs): (G1, ofs) = parse('uint8', data, ofs) (G2, ofs) = parse('uint32', data, ofs) return (dict(G1=G1, G2=G2), ofs) def struct_F(data, ofs): (F1, ofs) = parse('int64', data, ofs) F2 = [] (F2_size, ofs) = parse('uint16', data, ofs) (F2_adr, ofs) = parse('uint32', data, ofs) for i in range(F2_size): (elem, F2_adr) = parse('int32', data, F2_adr) F2.append(elem) return (dict(F1=F1, F2=F2), ofs) def struct_E(data, ofs): E1 = [] (E1_size, ofs) = parse('uint16', data, ofs) (E1_adr, ofs) = parse('uint16', data, ofs) for i in range(E1_size): (elem, E1_adr) = parse('uint32', data, E1_adr) E1.append(elem) (E2, ofs) = parse('int16', data, ofs) (E3, ofs) = parse('uint16', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2, ofs) = parse('int32', data, ofs) (D3, ofs) = parse('int32', data, ofs) D4 = [] (D4_size, ofs) = parse('uint16', data, ofs) (D4_adr, ofs) = parse('uint16', data, ofs) for i in range(D4_size): (elem, D4_adr) = parse('float', data, D4_adr) D4.append(elem) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) (C2, ofs) = struct_D(data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1_adr, ofs) = parse('uint32', data, ofs) (B1, elem) = struct_C(data, B1_adr) B2 = [] (B2_size, ofs) = parse('uint32', data, ofs) (B2_adr, ofs) = parse('uint16', data, ofs) for i in range(B2_size): (elem, B2_adr) = struct_E(data, B2_adr) B2.append(elem) (B3, ofs) = parse('float', data, ofs) (B4, ofs) = struct_F(data, ofs) (B5_adr, ofs) = parse('uint32', data, ofs) (B5, elem) = struct_G(data, B5_adr) B6 = [] (B6_size, ofs) = parse('uint32', data, ofs) (B6_adr, ofs) = parse('uint16', data, ofs) for i in range(B6_size): (elem, B6_adr) = parse('uint16', data, B6_adr) B6.append(elem) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int16', data, ofs) (A2, ofs) = parse('uint64', data, ofs) (A3, ofs) = parse('float', data, ofs) (A4, ofs) = struct_B(data, ofs) (A5, ofs) = parse('float', data, ofs) (A6, ofs) = parse('int16', data, ofs) (A7, ofs) = parse('int32', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 5)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'double') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(8): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) offs += 14 (a4, offs) = parse(buf, offs, 'int8') (a5, offs) = parse(buf, offs, 'uint32') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_c(buf, a6_offs) a7 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int64') a7.append(val) return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'double') (c4, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int32') c5.append(val) (c6, offs) = parse(buf, offs, 'int8') c7 = parse_d(buf, offs)[0] return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): d1 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack as un from struct import calcsize as jopa def parse_array(data, offset, type, arr_len): return list(un(f'<{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, addrs): result = list() for x in addrs: result.append(parse_c(data, x)) return result def parse_d(data, offset): result = dict() result['D1'] = un(' dict: def struct_a(shift: int) -> dict: [a1, a2, a3] = struct.unpack('< B I H', binary[shift:shift + 7]) shift += 7 return {'A1': a1, 'A2': struct_b(a2), 'A3': a3} def struct_b(shift: int) -> dict: [b1] = struct.unpack('< Q', binary[shift:shift + 8]) shift += 8 [length] = struct.unpack('< H', binary[shift:shift + 2]) shift += 2 [link_list] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 list_links = [struct.unpack('< I', binary[link_list + i * 4:link_list + (i + 1) * 4])[0] for i in range(length)] b2 = [struct_c(list_links[i]) for i in range(length)] [b3] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 return {'B1': b1, 'B2': b2, 'B3': struct_d(b3)} def struct_c(shift: int) -> dict: [c1, c2, c3, c4, c5] = struct.unpack('< H I i q q', binary[shift:shift + 26]) shift += 26 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def struct_d(shift: int) -> dict: d1 = struct_e(shift) shift += 22 [d2] = struct.unpack('< H', binary[shift:shift + 2]) shift += 2 d3 = struct_f(shift) shift += 39 return {'D1': d1, 'D2': d2, 'D3': d3} def struct_e(shift: int) -> dict: (razmer, address) = struct.unpack('< H I', binary[shift:shift + 6]) e1 = list(struct.unpack('<' + str(razmer) + 'b', binary[address:address + razmer])) shift += 6 [e2] = struct.unpack('< q', binary[shift:shift + 8]) shift += 8 (razmer2, address2) = struct.unpack('< H I', binary[shift:shift + 6]) e3 = list(struct.unpack('<' + str(razmer2) + 'i', binary[address2:address2 + 4 * razmer2])) shift += 6 [e4] = struct.unpack('< h', binary[shift:shift + 2]) shift += 2 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def struct_f(shift: int) -> dict: f1 = list(struct.unpack('< 3q', binary[shift:shift + 24])) shift += 24 f2 = list(struct.unpack('< 2H', binary[shift:shift + 4])) shift += 4 [f3, f4, f5] = struct.unpack('< Q h B', binary[shift:shift + 11]) shift += 11 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5} return struct_a(5)" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int64') f2 = [] for _ in range(0, 4): (val, offs) = parse(buf, offs, 'uint8') f2.append(val) f3 = [] for _ in range(0, 6): (val, offs) = parse(buf, offs, 'uint32') f3.append(val) (f4, offs) = parse(buf, offs, 'int32') (f5, offs) = parse(buf, offs, 'double') (f6, offs) = parse(buf, offs, 'uint64') return (dict(F1=f1, F2=f2, F3=f3, F4=f4, F5=f5, F6=f6), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint8') (e2, offs) = parse(buf, offs, 'uint64') return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') c2 = [] for _ in range(0, 3): (val, offs) = parse(buf, offs, 'int16') c2.append(val) (c3, offs) = parse(buf, offs, 'uint16') (c4_offs, offs) = parse(buf, offs, 'uint32') (val, c4_offs) = parse_d(buf, c4_offs) c4 = val (c5_size, offs) = parse(buf, offs, 'uint16') (c5_offs, offs) = parse(buf, offs, 'uint16') c5 = [] for _ in range(c5_size): (val, c5_offs) = parse(buf, c5_offs, 'int8') c5.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') b2 = [] for _ in range(0, 2): (val, offs) = parse_c(buf, offs) b2.append(val) (b3, offs) = parse_e(buf, offs) (b4, offs) = parse(buf, offs, 'int16') (b5, offs) = parse(buf, offs, 'uint16') (b6, offs) = parse(buf, offs, 'double') (b7, offs) = parse(buf, offs, 'float') (b8, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (val, a1_offs) = parse_b(buf, a1_offs) a1 = val (a2, offs) = parse(buf, offs, 'float') (a3_offs, offs) = parse(buf, offs, 'uint32') (val, a3_offs) = parse_f(buf, a3_offs) a3 = val return (dict(A1=a1, A2=a2, A3=a3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(bs): magic_bytes = b'SNZY' A = struct.Struct('< I B II If If If If If H 2q H') B = struct.Struct('< i q Q') D = struct.Struct('< II i B') a = A.unpack_from(bs, len(magic_bytes)) b = B.unpack_from(bs, a[0]) d = D.unpack_from(bs, a[14]) return {'A1': {'B1': b[0], 'B2': b[1], 'B3': b[2]}, 'A2': a[1], 'A3': b''.join(struct.unpack_from(f'< {a[2]}c', bs, a[3])).decode(), 'A4': [{'C1': a[4], 'C2': a[5]}, {'C1': a[6], 'C2': a[7]}, {'C1': a[8], 'C2': a[9]}, {'C1': a[10], 'C2': a[11]}, {'C1': a[12], 'C2': a[13]}], 'A5': {'D1': list(struct.unpack_from(f'< {d[0]}f', bs, d[1])), 'D2': d[2], 'D3': d[3]}, 'A6': [a[-3], a[-2]], 'A7': a[-1]}" "import struct def structA(data, pointer): (f1,) = struct.unpack('>H', data[pointer:pointer + 2]) a1 = structB(data, f1) af2 = struct.unpack('>2I', data[pointer + 2:pointer + 10]) a2 = [] for i in range(af2[0]): x = structF(data, af2[1] + i * 32) a2.append(x) return {'A1': a1, 'A2': a2} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) b2 = structC(data, pointer + 1) b3 = [] for i in range(6): (x,) = struct.unpack('>H', data[pointer + 30 + i * 2:pointer + 30 + i * 2 + 2]) b3.append(x) (b4,) = struct.unpack('>h', data[pointer + 42:pointer + 44]) (b5,) = struct.unpack('>q', data[pointer + 44:pointer + 52]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def structC(data, pointer): (c1,) = struct.unpack('>h', data[pointer:pointer + 2]) (c2,) = struct.unpack('>h', data[pointer + 2:pointer + 4]) c3 = structD(data, pointer + 4) (c4,) = struct.unpack('>f', data[pointer + 25:pointer + 29]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def structD(data, pointer): (d1,) = struct.unpack('>B', data[pointer:pointer + 1]) d2 = structE(data, pointer + 1) (d3,) = struct.unpack('>h', data[pointer + 15:pointer + 17]) (d4,) = struct.unpack(f'>f', data[pointer + 17:pointer + 21]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def structE(data, pointer): (e1,) = struct.unpack('>d', data[pointer:pointer + 8]) fe2 = struct.unpack('>IH', data[pointer + 8:pointer + 14]) e2 = [] for i in range(fe2[0]): (X,) = struct.unpack(f'>H', data[fe2[1] + 2 * i:fe2[1] + 2 * i + 2]) e2.append(X) return {'E1': e1, 'E2': e2} def structF(data, pointer): (f1,) = struct.unpack('>B', data[pointer:pointer + 1]) (f2,) = struct.unpack('>B', data[pointer + 1:pointer + 2]) (f3,) = struct.unpack('>B', data[pointer + 2:pointer + 3]) (f4,) = struct.unpack('>q', data[pointer + 3:pointer + 11]) (f5,) = struct.unpack('>f', data[pointer + 11:pointer + 15]) f6 = [] (X,) = struct.unpack('>q', data[pointer + 15:pointer + 23]) f6.append(X) (X,) = struct.unpack('>q', data[pointer + 23:pointer + 31]) f6.append(X) (f7,) = struct.unpack('>b', data[pointer + 31:pointer + 32]) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7} def main(data): return structA(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '<' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2, offs) = parse(buf, offs, 'uint64') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for i in range(a3_size): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) (a4_size, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'char') a4.append(val.decode('ascii')) (a5, offs) = parse(buf, offs, 'uint8') (a6, offs) = parse_c(buf, offs) (a7_offs, offs) = parse(buf, offs, 'uint16') (a7, a7_offs) = parse_d(buf, a7_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): b1 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'char') b1.append(val.decode()) (b2, offs) = parse(buf, offs, 'double') return (dict(B1=''.join(b1), B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'uint8') (c3_size, offs) = parse(buf, offs, 'uint32') (c3_offs, offs) = parse(buf, offs, 'uint32') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'int64') c3.append(val) (c4, offs) = parse(buf, offs, 'double') (c5, offs) = parse(buf, offs, 'float') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct SIZE_D = 4 + 2 + 1 * 2 + 8 + (2 + 2) + 8 SIZE_C = 2 + 4 + 1 + 8 SIZE_B = SIZE_C + 2 + (4 + 2) + 8 + 2 SIZE_A = 4 + 2 + 8 + 2 + 8 + 2 def parse_d(sequence, offset): d_sequence = sequence[offset:offset + SIZE_D] d = struct.unpack('>IhBBdHHQ', d_sequence) d5_sequence = sequence[d[6]:d[6] + d[5] * 4] d5 = struct.unpack('>' + 'f' * d[5], d5_sequence) return {'D1': d[0], 'D2': d[1], 'D3': [d[2], d[3]], 'D4': d[4], 'D5': list(d5), 'D6': d[7]} def parse_c(sequence, offset): c_sequence = sequence[offset:offset + SIZE_C] c = struct.unpack('>HIbq', c_sequence) c1_sequence = sequence[c[1]:c[1] + c[0] * 2] c1_addresses = struct.unpack('>' + 'H' * c[0], c1_sequence) c1 = [parse_d(sequence, address) for address in c1_addresses] return {'C1': c1, 'C2': c[2], 'C3': c[3]} def parse_b(sequence, offset): b_sequence = sequence[offset:offset + SIZE_B] b1 = parse_c(sequence, offset + 0) b25 = b_sequence[SIZE_C:SIZE_B] b = struct.unpack('>HIHdH', b25) b3_sequence = sequence[b[2]:b[2] + b[1] * 4] b3 = struct.unpack('>' + 'i' * b[1], b3_sequence) return {'B1': b1, 'B2': b[0], 'B3': list(b3), 'B4': b[3], 'B5': b[4]} def parse_a(sequence, offset): a_sequence = sequence[offset:offset + SIZE_A] a = struct.unpack('>iHQhQH', a_sequence) a6 = parse_b(sequence, a[5]) return {'A1': a[0], 'A2': a[1], 'A3': a[2], 'A4': a[3], 'A5': a[4], 'A6': a6} def main(sequence): return parse_a(sequence, 4)" "import struct def main(bs): magic_bytes = b'CELX' A = struct.Struct('< I II d f') B = struct.Struct('< fqh fqh H I I I') D = struct.Struct('< h q q 4B') E = struct.Struct('< i h 3B H H 6h H H') a = A.unpack_from(bs, len(magic_bytes)) b = B.unpack_from(bs, a[0]) d = D.unpack_from(bs, b[6]) e = E.unpack_from(bs, b[-2]) return {'A1': {'B1': [{'C1': b[0], 'C2': b[1], 'C3': b[2]}, {'C1': b[3], 'C2': b[4], 'C3': b[5]}], 'B2': {'D1': d[0], 'D2': d[1], 'D3': d[2], 'D4': list(d[3:])}, 'B3': b[7], 'B4': {'E1': e[0], 'E2': e[1], 'E3': list(e[2:5]), 'E4': e[5], 'E5': e[6], 'E6': list(e[7:13]), 'E7': e[13], 'E8': e[14]}, 'B5': b[-1]}, 'A2': list(struct.unpack_from(f'< {a[1]}f', bs, a[2])), 'A3': a[3], 'A4': a[4]}" "from struct import * def parse(buf, ty, offs): return (unpack_from(ty, buf, offs)[0], offs + calcsize(ty)) def parseA(buf, offs): (A1, offs) = parse(buf, '>B', offs) (A2, offs) = parse(buf, '>i', offs) (A3, offs) = parse(buf, '>b', offs) (A4, offs) = parseB(buf, offs) (adress, offs) = parse(buf, '>H', offs) A5 = parseF(buf, adress)[0] return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), offs) def parseB(buf, offs): (B1, offs) = parse(buf, '>Q', offs) (B2, offs) = parseC(buf, offs) return (dict(B1=B1, B2=B2), offs) def parseC(buf, offs): (C1, offs) = parse(buf, '>f', offs) (C2, offs) = parse(buf, '>B', offs) C3 = [] for i in range(2): (add, offs) = parseD(buf, offs) C3.append(add) (adress, offs) = parse(buf, '>H', offs) C4 = parseE(buf, adress)[0] return (dict(C1=C1, C2=C2, C3=C3, C4=C4), offs) def parseD(buf, offs): (D1, offs) = parse(buf, '>b', offs) (D2, offs) = parse(buf, '>h', offs) (D3, offs) = parse(buf, '>d', offs) (D4, offs) = parse(buf, '>b', offs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), offs) def parseE(buf, offs): E1 = [] for i in range(3): (add, offs) = parse(buf, '>q', offs) E1.append(add) (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>I', offs) E2 = [] for i in range(size): (add, adress) = parse(buf, '>I', adress) E2.append(add) return (dict(E1=E1, E2=E2), offs) def parseF(buf, offs): (F1, offs) = parse(buf, '>d', offs) (F2, offs) = parse(buf, '>h', offs) (F3, offs) = parse(buf, '>Q', offs) (F4, offs) = parse(buf, '>H', offs) (F5, offs) = parse(buf, '>q', offs) (F6, offs) = parse(buf, '>I', offs) F7 = [] (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>H', offs) for i in range(size): (add, adress) = parse(buf, '>i', adress) F7.append(add) (F8, offs) = parse(buf, '>I', offs) return (dict(F1=F1, F2=F2, F3=F3, F4=F4, F5=F5, F6=F6, F7=F7, F8=F8), offs) def main(buf): return parseA(buf, 4)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 84: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 5)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('>H2LH', file[a_adr:a_adr + 12]) (b_adr, *c_adrs, a['A3']) = temp temp = unpack('>f8c', file[b_adr:b_adr + 12]) (b['B1'], *ch_arr) = temp b['B2'] = ''.join((str(e, 'utf8') for e in ch_arr)) a['A2'] = [] for c_adr in c_adrs: temp = unpack('>QLHB8BLb', file[c_adr:c_adr + 28]) (c['C1'], double_size, double_adr, c['C3'], *uint8_arr, d['D2'], d['D3']) = temp temp = unpack(f'>{double_size}d', file[double_adr:double_adr + double_size * 8]) c['C2'] = list(temp) d['D1'] = list(uint8_arr) c['C4'] = d.copy() a['A2'].append(c.copy()) a['A1'] = b return a" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) (D2, ofs) = parse('int32', data, ofs) (D3, ofs) = parse('uint32', data, ofs) D4 = [] for i in range(3): (elem, ofs) = parse('uint8', data, ofs) D4.append(elem) D5 = [] for i in range(5): (elem, ofs) = parse('uint32', data, ofs) D5.append(elem) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) C2 = [] (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint16', data, ofs) for i in range(C2_size): (elem, C2_adr) = parse('uint16', data, C2_adr) C2.append(elem) (C3, ofs) = parse('float', data, ofs) (C4, ofs) = parse('int8', data, ofs) (C5, ofs) = parse('double', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint64', data, ofs) B2 = [] for i in range(4): (elem, ofs) = struct_C(data, ofs) B2.append(elem) (B3, ofs) = parse('double', data, ofs) (B4, ofs) = parse('uint32', data, ofs) (B5, ofs) = parse('uint32', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint32', data, ofs) (A2, ofs) = parse('uint32', data, ofs) A3 = '' for i in range(7): (elem, ofs) = parse('char', data, ofs) A3 += elem.decode() (A4, ofs) = parse('double', data, ofs) (A5_adr, ofs) = parse('uint32', data, ofs) (A5, elem) = struct_B(data, A5_adr) (A6_adr, ofs) = parse('uint32', data, ofs) (A6, elem) = struct_D(data, A6_adr) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 3)[0]" "import struct def structG(data, pointer): (uint16,) = struct.unpack('1c', data[pointer + 23:pointer + 24]) (array_a_2,) = struct.unpack('>c', data[pointer + 24:pointer + 25]) (array_a_3,) = struct.unpack('>c', data[pointer + 25:pointer + 26]) (array_a_4,) = struct.unpack('>c', data[pointer + 26:pointer + 27]) (array_a_5,) = struct.unpack('>c', data[pointer + 27:pointer + 28]) (array_a_6,) = struct.unpack('>c', data[pointer + 28:pointer + 29]) (array_a_7,) = struct.unpack('>c', data[pointer + 29:pointer + 30]) (array_a_8,) = struct.unpack('>c', data[pointer + 30:pointer + 31]) array_char = chr(array_a[0]) + chr(array_a_2[0]) + chr(array_a_3[0]) + chr(array_a_4[0]) + chr(array_a_5[0]) + chr(array_a_6[0]) + chr(array_a_7[0]) + chr(array_a_8[0]) return {'B1': int16_b, 'B2': int8_b, 'B3': double, 'B4': int64_b, 'B5': int32_b, 'B6': array_char} def structA(data, pointer): strB = structB(data, pointer) (uint32_a,) = struct.unpack('{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, data_type, length): return list(struct.unpack(f'>{length}{data_type}', data[offset:offset + length * struct.calcsize(data_type)])) def parse_e(data, offset): result = dict() result['E1'] = struct.unpack('>i', data[offset:offset + 4])[0] result['E2'] = parse_array(data, offset + 4, 'h', 7) result['E3'] = struct.unpack('>B', data[offset + 18:offset + 18 + 1])[0] return result def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['D2'] = struct.unpack('>B', data[offset + 2:offset + 2 + 1])[0] result['D3'] = struct.unpack('>H', data[offset + 3:offset + 3 + 2])[0] (d4_size, d4_address) = struct.unpack('>HH', data[offset + 5:offset + 5 + 4]) result['D4'] = parse_array(data, d4_address, 'b', d4_size) result['D5'] = struct.unpack('>d', data[offset + 9:offset + 9 + 8])[0] result['D6'] = struct.unpack('>Q', data[offset + 17:offset + 17 + 8])[0] result['D7'] = struct.unpack('>B', data[offset + 25:offset + 25 + 1])[0] result['D8'] = struct.unpack('>B', data[offset + 26:offset + 26 + 1])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['C2'] = struct.unpack('>I', data[offset + 2:offset + 2 + 4])[0] result['C3'] = ''.join([str(c, 'utf-8') for c in parse_array(data, offset + 6, 'c', 2)]) result['C4'] = parse_d(data, offset + 8) result['C5'] = struct.unpack('>f', data[offset + 35:offset + 35 + 4])[0] result['C6'] = struct.unpack('>Q', data[offset + 39:offset + 39 + 8])[0] return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>h', data[offset:offset + 2])[0] b2_address = struct.unpack('>I', data[offset + 2:offset + 2 + 4])[0] result['B2'] = parse_c(data, b2_address) result['B3'] = struct.unpack('>b', data[offset + 6:offset + 6 + 1])[0] result['B4'] = struct.unpack('>Q', data[offset + 7:offset + 7 + 8])[0] return result def parse_a(data, offset): result = dict() a1_address = struct.unpack('>H', data[offset:offset + 2])[0] result['A1'] = parse_b(data, a1_address) result['A2'] = struct.unpack('>b', data[offset + 2:offset + 2 + 1])[0] (a3_size, a3_address) = struct.unpack('>IH', data[offset + 3:offset + 3 + 6]) a3 = list() for i in range(a3_size): a3.append(parse_e(data, a3_address + i * 19)) result['A3'] = a3 result['A4'] = struct.unpack('>i', data[offset + 9:offset + 9 + 4])[0] result['A5'] = struct.unpack('>i', data[offset + 13:offset + 13 + 4])[0] return result def main(data): return parse_a(data, 5)" "import struct def main(s): base_address = 4 d = {} a_d = {} a_d5 = [] d_e = {} d_e1 = [] d_d5 = [] d_d6 = [] b = {} new_address_b = struct.unpack_from('>H', s, base_address)[0] base_address += 2 new_size = struct.unpack_from('>I', s, new_address_b)[0] new_address_b += 4 new_address_c = struct.unpack_from('>H', s, new_address_b)[0] new_address_b += 2 b1 = [] c_mass = [] for i in range(new_size): b1.append(struct.unpack_from('>H', s, new_address_c)[0]) new_address_c += 2 for i in range(new_size): c = {} c.setdefault('C1', struct.unpack_from('>B', s, b1[i])[0]) b1[i] += 1 c.setdefault('C2', struct.unpack_from('>I', s, b1[i])[0]) b1[i] += 4 c.setdefault('C3', struct.unpack_from('>d', s, b1[i])[0]) b1[i] += 8 c.setdefault('C4', struct.unpack_from('>f', s, b1[i])[0]) b1[i] += 4 c.setdefault('C5', struct.unpack_from('>h', s, b1[i])[0]) b1[i] += 2 c.setdefault('C6', struct.unpack_from('>h', s, b1[i])[0]) b1[i] += 2 c_mass.append(c) b.setdefault('B1', c_mass) b.setdefault('B2', struct.unpack_from('>q', s, new_address_b)[0]) new_address_b += 8 d.setdefault('A1', b) a_d.setdefault('D1', struct.unpack_from('>b', s, base_address)[0]) base_address += 1 a_d.setdefault('D2', struct.unpack_from('>B', s, base_address)[0]) base_address += 1 new_lenght = struct.unpack_from('>I', s, base_address)[0] base_address += 4 new_address = struct.unpack_from('>I', s, base_address)[0] base_address += 4 for i in range(new_lenght): d_e1.append(struct.unpack_from('>d', s, new_address)[0]) new_address += 8 d_e.setdefault('E1', d_e1) d_e.setdefault('E2', struct.unpack_from('>I', s, base_address)[0]) base_address += 4 a_d.setdefault('D3', d_e) a_d.setdefault('D4', struct.unpack_from('>b', s, base_address)[0]) base_address += 1 new_lenght = struct.unpack_from('>I', s, base_address)[0] base_address += 4 new_address = struct.unpack_from('>I', s, base_address)[0] base_address += 4 for i in range(new_lenght): a_d5.append(struct.unpack_from('>b', s, new_address)[0]) new_address += 1 a_d.setdefault('D5', a_d5) for i in range(3): d_d6.append(struct.unpack_from('>h', s, base_address)[0]) base_address += 2 a_d.setdefault('D6', d_d6) d.setdefault('A2', a_d) return d" "import struct def main(x): a1 = struct.unpack('>B', x[4:5])[0] b1 = struct.unpack('>Q', x[5:13])[0] pos1 = 13 b2 = [] for i in range(0, 5): c1 = struct.unpack('>f', x[pos1:pos1 + 4])[0] c2 = struct.unpack('>d', x[pos1 + 4:pos1 + 12])[0] c3_1 = struct.unpack('>b', x[pos1 + 12:pos1 + 13])[0] c3_2 = struct.unpack('>b', x[pos1 + 13:pos1 + 14])[0] c3_3 = struct.unpack('>b', x[pos1 + 14:pos1 + 15])[0] c3_4 = struct.unpack('>b', x[pos1 + 15:pos1 + 16])[0] c3 = [c3_1, c3_2, c3_3, c3_4] c4 = struct.unpack('>B', x[pos1 + 16:pos1 + 17])[0] pos1 += 17 d = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} b2.append(d) pos2 = struct.unpack('>I', x[pos1 + 2:pos1 + 6])[0] b3 = [] for i in range(0, struct.unpack('>H', x[pos1:pos1 + 2])[0]): b3.append(struct.unpack('>H', x[pos2:pos2 + 2])[0]) pos2 += 2 pos1 += 6 pos3 = struct.unpack('>L', x[pos1:pos1 + 4])[0] d1 = struct.unpack('>Q', x[pos3:pos3 + 8])[0] d2 = struct.unpack('>h', x[pos3 + 8:pos3 + 10])[0] d3 = [] pos4 = struct.unpack('>I', x[pos3 + 14:pos3 + 18])[0] for i in range(0, struct.unpack('>I', x[pos3 + 10:pos3 + 14])[0]): d3.append(struct.unpack('>H', x[pos4:pos4 + 2])[0]) pos4 += 2 d4 = struct.unpack('>B', x[pos3 + 18:pos3 + 19])[0] b5 = struct.unpack('>d', x[pos1 + 4:pos1 + 12])[0] b6 = struct.unpack('>d', x[pos1 + 12:pos1 + 20])[0] pos1 += 20 pos5 = struct.unpack('>L', x[pos1:pos1 + 4])[0] e1 = struct.unpack('>Q', x[pos5:pos5 + 8])[0] e2 = struct.unpack('>f', x[pos5 + 8:pos5 + 12])[0] e3 = struct.unpack('>b', x[pos5 + 12:pos5 + 13])[0] e4 = struct.unpack('>b', x[pos5 + 13:pos5 + 14])[0] e5 = struct.unpack('>H', x[pos5 + 14:pos5 + 16])[0] e6 = [] e6.append(struct.unpack('>B', x[pos5 + 16:pos5 + 17])[0]) e6.append(struct.unpack('>B', x[pos5 + 17:pos5 + 18])[0]) a4 = struct.unpack('>f', x[pos1 + 4:pos1 + 8])[0] b4 = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} a2 = {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} a3 = {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6} f = {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} return f" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse_b(buf, offs) (a3_size, offs) = parse(buf, offs, 'uint32') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'float') a3.append(val) (a4, offs) = parse(buf, offs, 'uint16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'uint32') (b4_size, offs) = parse(buf, offs, 'uint16') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse_c(buf, b4_offs) b4.append(val) (b5, offs) = parse_d(buf, offs) (b6, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'float') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'uint32') (d5_size, offs) = parse(buf, offs, 'uint16') (d5_offs, offs) = parse(buf, offs, 'uint32') d5 = [] for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'int16') d5.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 236: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 5)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 3)} temp = unpack('>LlLLHbqLH', file[a_adr:a_adr + 33]) (b_adr, a['A2'], ch_arr_size, ch_arr_adr, d_adr, a['A5'], a['A6'], double_size, double_adr) = temp ch_arr = unpack(f'>{ch_arr_size}c', file[ch_arr_adr:ch_arr_adr + ch_arr_size]) a['A3'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack(f'>{double_size}d', file[double_adr:double_adr + double_size * 8]) a['A7'] = list(temp) temp = unpack('>L3B', file[d_adr:d_adr + 7]) (d['D1'], *uint8_arr) = temp d['D2'] = list(uint8_arr) temp = unpack('>ll2Lq', file[b_adr:b_adr + 24]) (b['B1'], b['B2'], *c_adrs, b['B4']) = temp b['B3'] = [] for c_adr in c_adrs: temp = unpack('>f8b', file[c_adr:c_adr + 12]) (c['C1'], *int8_arr) = temp c['C2'] = list(int8_arr) b['B3'].append(c.copy()) a['A1'] = b a['A4'] = d return a" "import struct as st def main(x): return a(x, 4) def a(x, start): return {'A1': st.unpack('> Q', x[start:start + 8])[0], 'A2': b(x, address_b(x, start + 8)), 'A3': st.unpack('> b', x[start + 10:start + 11])[0]} def address_b(x, start): return st.unpack('> H', x[start:start + 2])[0] def b(x, start): size = st.unpack('> H', x[start:start + 2])[0] add = st.unpack('> I', x[start + 2:start + 6])[0] return {'B1': [c(x, add + 20 * j) for j in range(0, size)], 'B2': st.unpack('> d', x[start + 6:start + 14])[0], 'B3': st.unpack('> i', x[start + 14:start + 18])[0], 'B4': st.unpack('> i', x[start + 18:start + 22])[0], 'B5': d(x, start + 22)} def c(x, start): return {'C1': st.unpack('> Q', x[start:start + 8])[0], 'C2': st.unpack('> H', x[start + 8:start + 10])[0], 'C3': st.unpack('> H', x[start + 10:start + 12])[0], 'C4': [st.unpack('> f', x[start + 12:start + 16])[0], st.unpack('> f', x[start + 16:start + 20])[0]]} def d(x, start): return {'D1': st.unpack('> h', x[start:start + 2])[0], 'D2': [st.unpack('> I', x[start + 2:start + 6])[0], st.unpack('> I', x[start + 6:start + 10])[0], st.unpack('> I', x[start + 10:start + 14])[0]], 'D3': uint16_uint16_double(x, start + 14), 'D4': st.unpack('> f', x[start + 18:start + 22])[0], 'D5': st.unpack('> I', x[start + 22:start + 26])[0], 'D6': uint32_uint16_int64(x, start + 26)} def uint16_uint16_double(x, start): size = st.unpack('> H', x[start:start + 2])[0] address = st.unpack('> H', x[start + 2:start + 4])[0] arr = st.unpack('> ' + 'd' * size, x[address:address + 8 * size]) return list(arr) def uint32_uint16_int64(x, start): size = st.unpack('> I', x[start:start + 4])[0] address = st.unpack('> H', x[start + 4:start + 6])[0] arr = st.unpack('> ' + 'q' * size, x[address:address + 8 * size]) return list(arr)" "from struct import unpack type_dict = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's', 'char': 'c'} def gen_e(): d = type_dict return d['double'] + d['uint8'] + d['int16'] def gen_d(): d = type_dict return d['uint16'] + 3 * d['uint32'] + d['uint16'] + d['float'] def gen_c(): d = type_dict return d['uint64'] + 4 * d['char[]'] + d['uint16'] + d['float'] + d['uint8'] + d['double'] + d['uint8'] + d['uint16'] def gen_b(): d = type_dict return d['int64'] + gen_c() + d['uint8'] + d['float'] + d['int32'] + d['float'] + d['uint64'] + d['uint64'] def gen_a(): d = type_dict return d['int8'] + d['uint64'] + d['uint8'] + gen_b() + d['float'] + d['int16'] + 2 * gen_e() + d['uint32'] + d['uint16'] def gen_total(): d = type_dict return '>xxxxx' + gen_a() def main(arg): d = type_dict total = gen_total() obj = unpack(total, arg[:116]) a8_size = obj[29] a8_addr = obj[30] a8_total = '>' + a8_size * d['float'] a8_obj = list(unpack(a8_total, arg[a8_addr:a8_addr + a8_size * 4])) m_ch = [] for i in range(4): m_ch.append(obj[5 + i].decode()) m_ch = ''.join(m_ch) d_addr = obj[14] len_d = 2 + 12 + 2 + 4 d_obj = unpack('>' + gen_d(), arg[d_addr:d_addr + len_d]) m_i = [] for i in range(3): m_i.append(d_obj[1 + i]) d_dict = {'D1': d_obj[0], 'D2': m_i, 'D3': d_obj[4], 'D4': d_obj[5]} a_dict = {'A1': obj[0], 'A2': obj[1], 'A3': obj[2], 'A4': {'B1': obj[3], 'B2': {'C1': obj[4], 'C2': m_ch, 'C3': obj[9], 'C4': obj[10], 'C5': obj[11], 'C6': obj[12], 'C7': obj[13], 'C8': d_dict}, 'B3': obj[15], 'B4': obj[16], 'B5': obj[17], 'B6': obj[18], 'B7': obj[19], 'B8': obj[20]}, 'A5': obj[21], 'A6': obj[22], 'A7': [{'E1': obj[23], 'E2': obj[24], 'E3': obj[25]}, {'E1': obj[26], 'E2': obj[27], 'E3': obj[28]}], 'A8': a8_obj} return a_dict" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 71 and a_adr != 2: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 3)} e = {f'E{i}': None for i in range(1, 5)} temp = unpack(' reader.offset: values.append(read(reader)) return values def read_g(reader: BinaryReader): return dict(G1=reader.read(Primitive.uint32), G2=reader.read(Primitive.int16)) def read_f(reader: BinaryReader): return dict(F1=reader.read(Primitive.uint16), F2=reader.read(Primitive.int16), F3=reader.read(Primitive.uint32), F4=reader.read(Primitive.int8), F5=read_array(reader, 3, reader.offset, lambda reader: reader.read(Primitive.int16), structure_size=2, to_sum=True)) def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.int16), E2=reader.read(Primitive.double), E3=reader.read(Primitive.int16), E4=reader.read(Primitive.uint32), E5=reader.read(Primitive.int64), E6=reader.read(Primitive.uint16), E7=reader.read(Primitive.uint64), E8=reader.read(Primitive.double)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.double), D2=reader.read(Primitive.int64)) def read_c(reader: BinaryReader): return dict(C1=read_d(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), C2=reader.read(Primitive.int32)) def read_b(reader: BinaryReader): return dict(B1=read_c(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), B2=reader.read(Primitive.uint32), B3=''.join(read_array(reader, 8, reader.offset, lambda reader: reader.read(Primitive.char).decode('utf-8'), structure_size=1, to_sum=True)), B4=read_array(reader, 2, reader.offset, lambda reader: read_e(reader), structure_size=42, to_sum=True), B5=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.int8), structure_size=1, to_sum=True), B6=reader.read(Primitive.uint32), B7=read_f(reader)) def read_a(reader: BinaryReader): return dict(A1=read_b(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), A2=read_array(reader, 8, reader.offset, lambda reader: reader.read(Primitive.uint8), structure_size=1, to_sum=True), A3=read_g(BinaryReader(reader.source, offset=reader.read(Primitive.uint16)))) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): E1 = [] for i in range(2): (elem, ofs) = parse('int8', data, ofs) E1.append(elem) (E2, ofs) = parse('uint16', data, ofs) (E3, ofs) = parse('uint64', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_D(data, ofs): (D1, ofs) = parse('float', data, ofs) (D2, ofs) = parse('float', data, ofs) D3 = [] (D3_size, ofs) = parse('uint32', data, ofs) (D3_adr, ofs) = parse('uint16', data, ofs) for i in range(D3_size): (E_adr, D3_adr) = parse('uint32', data, D3_adr) (elem, lop) = struct_E(data, E_adr) D3.append(elem) (D4, ofs) = parse('float', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): (C1, ofs) = parse('float', data, ofs) (C2, ofs) = parse('int32', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint64', data, ofs) B2 = '' (B2_size, ofs) = parse('uint32', data, ofs) (B2_adr, ofs) = parse('uint32', data, ofs) for i in range(B2_size): (elem, B2_adr) = parse('char', data, B2_adr) B2 += elem.decode() (B3, ofs) = parse('uint64', data, ofs) (B4, ofs) = parse('uint16', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint16', data, ofs) (A2, ofs) = struct_B(data, ofs) (A3, ofs) = struct_C(data, ofs) (A4, ofs) = struct_D(data, ofs) (A5, ofs) = parse('int64', data, ofs) A6 = [] (A6_size, ofs) = parse('uint32', data, ofs) (A6_adr, ofs) = parse('uint32', data, ofs) for i in range(A6_size): (elem, A6_adr) = parse('float', data, A6_adr) A6.append(elem) (A7, ofs) = parse('int8', data, ofs) (A8, ofs) = parse('uint8', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8), ofs) def main(data): return struct_A(data, 5)[0]" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('>if', data[pointer:pointer + 8]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2, c3, c4, c5) = struct.unpack('>Hbfhb', data[pointer:pointer + 10]) f6 = struct.unpack('>HI', data[pointer + 10:pointer + 16]) c6 = list(struct.unpack(f'>{f6[0]}H', data[f6[1]:f6[1] + f6[0] * 2])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) b1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) b1.append(parse_c(data, f11[0])) b2 = struct.unpack('>d', data[pointer + 6:pointer + 14])[0] b3 = list(struct.unpack('>6b', data[pointer + 14:pointer + 20])) f4 = struct.unpack('>II', data[pointer + 20:pointer + 28]) b4 = list(struct.unpack(f'>{f4[0]}f', data[f4[1]:f4[1] + f4[0] * 4])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): a1 = parse_b(data, pointer) (a2, a3) = struct.unpack('>bq', data[pointer + 28:pointer + 37]) f4 = struct.unpack('>I', data[pointer + 37:pointer + 41]) a4 = parse_d(data, f4[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('>qB', data[pointer:pointer + 9]) e3 = list(struct.unpack('>8B', data[pointer + 9:pointer + 17])) e4 = list(struct.unpack('>2h', data[pointer + 17:pointer + 21])) (e5, e6, e7) = struct.unpack('>ihH', data[pointer + 21:pointer + 29]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6, 'E7': e7} def parse_d(data, pointer): (d1, d2) = struct.unpack('>Bh', data[pointer:pointer + 3]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): c1 = parse_d(data, pointer) c2 = ''.join(map(str, struct.unpack('>8c', data[pointer + 3:pointer + 11]))) c2 = c2.replace(""'"", '')[1::2] (c3, c4) = struct.unpack('>hb', data[pointer + 11:pointer + 14]) c5 = parse_e(data, pointer + 14) c6 = struct.unpack('>h', data[pointer + 43:pointer + 45])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>QbB', data[pointer:pointer + 10]) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): a1 = struct.unpack('>q', data[pointer:pointer + 8])[0] f2 = struct.unpack('>8H', data[pointer + 8:pointer + 24]) a2 = list() for i in range(8): a2.append(parse_b(data, f2[i])) f3 = struct.unpack('>H', data[pointer + 24:pointer + 26]) a3 = parse_c(data, f3[0]) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 5)" "import struct def structD(data, pointer): (int16_d,) = struct.unpack('>h', data[pointer:pointer + 2]) (int16_d_2,) = struct.unpack('>h', data[pointer + 2:pointer + 4]) (uint32_d,) = struct.unpack('>I', data[pointer + 4:pointer + 8]) return {'D1': int16_d, 'D2': int16_d_2, 'D3': uint32_d} def structC(data, pointer): fc2 = struct.unpack('>IH', data[pointer:pointer + 6]) c1 = list(struct.unpack(f'>{fc2[0]}h', data[fc2[1]:fc2[1] + fc2[0] * 2])) (array_c,) = struct.unpack('>H', data[pointer + 6:pointer + 8]) (array_c_2,) = struct.unpack('>H', data[pointer + 8:pointer + 10]) c = [] c.append(array_c) c.append(array_c_2) (uint32_c,) = struct.unpack('>I', data[pointer + 10:pointer + 14]) (float_c,) = struct.unpack('>f', data[pointer + 14:pointer + 18]) return {'C1': c1, 'C2': c, 'C3': uint32_c, 'C4': float_c} def structB(data, pointer): (f1_uint32,) = struct.unpack('>I', data[pointer:pointer + 4]) (f2_uint32,) = struct.unpack('>I', data[pointer + 4:pointer + 8]) strC = [] x = structC(data, f1_uint32) strC.append(x) x = structC(data, f2_uint32) strC.append(x) (int8_b,) = struct.unpack('>b', data[pointer + 8:pointer + 9]) (f1_uint16,) = struct.unpack('>H', data[pointer + 9:pointer + 11]) strD = structD(data, f1_uint16) (array_b,) = struct.unpack('>I', data[pointer + 11:pointer + 15]) (array_b_2,) = struct.unpack('>I', data[pointer + 15:pointer + 19]) (array_b_3,) = struct.unpack('>I', data[pointer + 19:pointer + 23]) (array_b_4,) = struct.unpack('>I', data[pointer + 23:pointer + 27]) (array_b_5,) = struct.unpack('>I', data[pointer + 27:pointer + 31]) (array_b_6,) = struct.unpack('>I', data[pointer + 31:pointer + 35]) (array_b_7,) = struct.unpack('>I', data[pointer + 35:pointer + 39]) (array_b_8,) = struct.unpack('>I', data[pointer + 39:pointer + 43]) b = [] b.append(array_b) b.append(array_b_2) b.append(array_b_3) b.append(array_b_4) b.append(array_b_5) b.append(array_b_6) b.append(array_b_7) b.append(array_b_8) return {'B1': strC, 'B2': int8_b, 'B3': strD, 'B4': b} def structA(data, pointer): (double,) = struct.unpack('>d', data[pointer:pointer + 8]) (int8_a,) = struct.unpack('>b', data[pointer + 8:pointer + 9]) (int8_a_2,) = struct.unpack('>b', data[pointer + 9:pointer + 10]) (array_a,) = struct.unpack('>1q', data[pointer + 10:pointer + 18]) (array_a_2,) = struct.unpack('>q', data[pointer + 18:pointer + 26]) (array_a_3,) = struct.unpack('>q', data[pointer + 26:pointer + 34]) (array_a_4,) = struct.unpack('>q', data[pointer + 34:pointer + 42]) (array_a_5,) = struct.unpack('>q', data[pointer + 42:pointer + 50]) (array_a_6,) = struct.unpack('>q', data[pointer + 50:pointer + 58]) a = [] a.append(array_a) a.append(array_a_2) a.append(array_a_3) a.append(array_a_4) a.append(array_a_5) a.append(array_a_6) (uint8_a,) = struct.unpack('>B', data[pointer + 58:pointer + 59]) (uint16_a,) = struct.unpack('>H', data[pointer + 59:pointer + 61]) strB = structB(data, pointer + 61) return {'A1': double, 'A2': int8_a, 'A3': int8_a_2, 'A4': a, 'A5': uint8_a, 'A6': uint16_a, 'A7': strB} def main(data): return structA(data, 3)" "import struct def uint16uint16uint32(x, start): size = struct.unpack('< H', x[start:start + 2])[0] add = struct.unpack('< H', x[start + 2:start + 4])[0] a = struct.unpack('< ' + 'I' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def uint16uint32uint32(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'I' * size, x[add:add + 4 * size]) return list(a) def D(x, start): return {'D1': struct.unpack('< f', x[start:start + 4])[0], 'D2': uint16uint16uint32(x, start + 4), 'D3': struct.unpack('< H', x[start + 8:start + 10])[0]} def addressD(x, start): return struct.unpack('< H', x[start:start + 2])[0] def C(x, start): return {'C1': struct.unpack('< d', x[start:start + 8])[0], 'C2': struct.unpack('< I', x[start + 8:start + 12])[0], 'C3': uint16uint16uint32(x, start + 12), 'C4': [struct.unpack('< B', x[start + 16:start + 17])[0], struct.unpack('< B', x[start + 17:start + 18])[0], struct.unpack('< B', x[start + 18:start + 19])[0]], 'C5': struct.unpack('< I', x[start + 19:start + 23])[0], 'C6': struct.unpack('< d', x[start + 23:start + 31])[0]} def addressC(x, start): return struct.unpack('< H', x[start:start + 2])[0] def B(x, start): return {'B1': C(x, addressC(x, start)), 'B2': struct.unpack('< f', x[start + 2:start + 6])[0], 'B3': [struct.unpack('< q', x[start + 6:start + 14])[0], struct.unpack('< q', x[start + 14:start + 22])[0], struct.unpack('< q', x[start + 22:start + 30])[0]]} def A(x, start): return {'A1': struct.unpack('< H', x[start:start + 2])[0], 'A2': struct.unpack('< h', x[start + 2:start + 4])[0], 'A3': struct.unpack('< d', x[start + 4:start + 12])[0], 'A4': [B(x, start + 12), B(x, start + 42)], 'A5': struct.unpack('< I', x[start + 72:start + 76])[0], 'A6': struct.unpack('< H', x[start + 76:start + 78])[0], 'A7': D(x, addressD(x, start + 78))} def main(x): return A(x, 4)" "import struct def main(x): f = dict() pos1 = struct.unpack('>H', x[3:5])[0] b1 = struct.unpack('>q', x[pos1:pos1 + 8])[0] b2 = struct.unpack('>d', x[pos1 + 8:pos1 + 16])[0] f['A1'] = {'B1': b1, 'B2': b2} f['A2'] = struct.unpack('>h', x[5:7])[0] pos1 = struct.unpack('>H', x[9:11])[0] a3 = [] for i in range(0, struct.unpack('>H', x[7:9])[0]): c1 = struct.unpack('>B', x[pos1:pos1 + 1])[0] c2 = struct.unpack('>I', x[pos1 + 1:pos1 + 5])[0] c3 = struct.unpack('>q', x[pos1 + 5:pos1 + 13])[0] c4 = str(struct.unpack('>3s', x[pos1 + 13:pos1 + 16])[0])[2:-1] d = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} a3.append(d) pos1 += 16 f['A3'] = a3 f['A4'] = struct.unpack('>h', x[11:13])[0] pos1 = struct.unpack('>I', x[13:17])[0] d1 = struct.unpack('>f', x[pos1:pos1 + 4])[0] d2 = struct.unpack('>d', x[pos1 + 4:pos1 + 12])[0] d3 = list(struct.unpack('>5I', x[pos1 + 12:pos1 + 32])) f['A5'] = {'D1': d1, 'D2': d2, 'D3': d3} di = struct.unpack('>I', x[17:21])[0] dis = '>' + str(di) + 'b' pos1 = struct.unpack('>I', x[21:25])[0] f['A6'] = list(struct.unpack(dis, x[pos1:pos1 + di])) f['A7'] = struct.unpack('>Q', x[25:33])[0] return f" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('{arr_len}{type}', data[offset:offset + arr_len * jopa(type)])) def parse_structure_array(data, offset, arr_len): result = list() for i in range(arr_len): result.append(parse_b(data, offset)) offset = offset + 8 return result def parse_d(data, offset): result = dict() result['D1'] = parse_array(data, offset, 'b', 6) result['D2'] = un('>h', data[offset + 6:offset + 8])[0] (d3_size, d3_addr) = un('>HH', data[offset + 8:offset + 12]) result['D3'] = parse_array(data, d3_addr, 'H', d3_size) return result def parse_c(data, offset): result = dict() result['C1'] = un('>b', data[offset:offset + 1])[0] result['C2'] = un('>h', data[offset + 1:offset + 3])[0] (c3_size, c3_addr) = un('>II', data[offset + 3:offset + 11]) result['C3'] = parse_array(data, c3_addr, 'd', c3_size) result['C4'] = parse_d(data, offset + 11) result['C5'] = un('>q', data[offset + 23:offset + 31])[0] result['C6'] = un('>l', data[offset + 31:offset + 35])[0] return result def parse_b(data, offset): result = dict() result['B1'] = un('>L', data[offset:offset + 4])[0] result['B2'] = un('>H', data[offset + 4:offset + 6])[0] result['B3'] = un('>b', data[offset + 6:offset + 7])[0] result['B4'] = un('>B', data[offset + 7:offset + 8])[0] return result def parse_a(data, offset): result = dict() (a1_size, a1_addr) = un('>IH', data[offset:offset + 6]) result['A1'] = parse_structure_array(data, a1_addr, a1_size) result['A2'] = parse_c(data, offset + 6) return result def main(data): return parse_a(data, 4)" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = struct.unpack('>b', data[offset:offset + 1])[0] (size, address) = struct.unpack('>II', data[offset + 1:offset + 1 + 8]) result['D2'] = parse_array(data, address, 'B', size) return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>b', data[offset:offset + 1])[0] result['C2'] = parse_array(data, offset + 1, 'h', 4) result['C3'] = struct.unpack('>i', data[offset + 9:offset + 9 + 4])[0] result['C4'] = struct.unpack('>B', data[offset + 13:offset + 13 + 1])[0] result['C5'] = parse_array(data, offset + 14, 'B', 8) return result def parse_b(data, offset): result = dict() result['B1'] = [] for i in range(5): result['B1'].append(parse_c(data, offset)) offset += 22 result['B2'] = struct.unpack('>d', data[offset:offset + 8])[0] return result def parse_a(data, offset): result = dict() result['A1'] = struct.unpack('>B', data[offset:offset + 1])[0] (size, address) = struct.unpack('>HH', data[offset + 1:offset + 1 + 4]) result['A2'] = ''.join([str(c, 'utf-8') for c in parse_array(data, address, 'c', size)]) result['A3'] = struct.unpack('>f', data[offset + 5:offset + 5 + 4])[0] address = struct.unpack('>I', data[offset + 9:offset + 9 + 4])[0] result['A4'] = parse_b(data, address) result['A5'] = parse_d(data, offset + 13) return result def main(data): return parse_a(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint64') a2 = [] for _ in range(2): (val, offs) = parse_b(buf, offs) a2.append(val) a3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint16') a3.append(val) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_c(buf, b2_offs) (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): c1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int8') c1.append(val) (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, b2_offs) = parse_d(buf, c2_offs) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') d2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'uint32') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('<6I', data[pointer:pointer + 24])) d2 = struct.unpack('II', data[pointer:pointer + 8]) e1 = list(struct.unpack(f'>{f1[0]}I', data[f1[1]:f1[1] + f1[0] * 4])) (e2, e3, e4, e5) = struct.unpack('>hbqd', data[pointer + 8:pointer + 27]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def parse_d(data, pointer): (d1, d2) = struct.unpack('>fI', data[pointer:pointer + 8]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2) = struct.unpack('>BB', data[pointer:pointer + 2]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2) = struct.unpack('>di', data[pointer:pointer + 12]) f3 = struct.unpack('>H', data[pointer + 12:pointer + 14]) b3 = parse_c(data, f3[0]) b4 = struct.unpack('>b', data[pointer + 14:pointer + 15])[0] f5 = struct.unpack('>HI', data[pointer + 15:pointer + 21]) b5 = list() for i in range(f5[0]): b5.append(parse_d(data, f5[1] + i * 8)) b6 = list(struct.unpack('>2d', data[pointer + 21:pointer + 37])) b7 = struct.unpack('>Q', data[pointer + 37:pointer + 45])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7} def parse_a(data, pointer): (a1, a2) = struct.unpack('>fi', data[pointer:pointer + 8]) a3 = ''.join(map(str, struct.unpack('>8c', data[pointer + 8:pointer + 16]))) a3 = a3.replace(""'"", '')[1::2] a4 = struct.unpack('>q', data[pointer + 16:pointer + 24])[0] a5 = parse_b(data, pointer + 24) f6 = struct.unpack('>I', data[pointer + 69:pointer + 73]) a6 = parse_e(data, f6[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack('>HIfq', data[pointer:pointer + 18]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>fhh', data[pointer:pointer + 8]) c4 = list(struct.unpack('>3H', data[pointer + 8:pointer + 14])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): b1 = ''.join(map(str, struct.unpack('>8c', data[pointer:pointer + 8]))) b1 = b1.replace(""'"", '')[1::2] b2 = struct.unpack('>B', data[pointer + 8:pointer + 9])[0] f3 = struct.unpack('>HH', data[pointer + 9:pointer + 13]) b3 = list(struct.unpack(f'>{f3[0]}I', data[f3[1]:f3[1] + f3[0] * 4])) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) a1.append(parse_b(data, f11[0])) f2 = struct.unpack('>I', data[pointer + 6:pointer + 10]) a2 = parse_c(data, f2[0]) (a3, a4) = struct.unpack('>Hh', data[pointer + 10:pointer + 14]) f5 = struct.unpack('>I', data[pointer + 14:pointer + 18]) a5 = parse_d(data, f5[0]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3) = struct.unpack('>hQB', data[pointer:pointer + 11]) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>hqd', data[pointer:pointer + 18]) d4 = list(struct.unpack('>3Q', data[pointer + 18:pointer + 42])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4} def parse_c(data, pointer): (c1, c2) = struct.unpack('>hH', data[pointer:pointer + 4]) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): b1 = ''.join(map(str, struct.unpack('>2c', data[pointer:pointer + 2]))) b1 = b1.replace(""'"", '')[1::2] b2 = struct.unpack('>h', data[pointer + 2:pointer + 4])[0] b3 = parse_c(data, pointer + 4) f4 = struct.unpack('>I', data[pointer + 8:pointer + 12]) b4 = parse_d(data, f4[0]) (b5, b6) = struct.unpack('>fb', data[pointer + 12:pointer + 17]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, f1[0]) f2 = struct.unpack('>6H', data[pointer + 4:pointer + 16]) a2 = list() for i in range(6): a2.append(parse_e(data, f2[i])) (a3, a4) = struct.unpack('>bQ', data[pointer + 16:pointer + 25]) a5 = list(struct.unpack('>3H', data[pointer + 25:pointer + 31])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('i', data[pointer:pointer + 4])[0] f2 = struct.unpack('>IH', data[pointer + 4:pointer + 10]) e2 = list(struct.unpack(f'>{f2[0]}B', data[f2[1]:f2[1] + f2[0]])) e3 = struct.unpack('>d', data[pointer + 10:pointer + 18])[0] return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): (d1, d2) = struct.unpack('>If', data[pointer:pointer + 8]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>Bdd', data[pointer:pointer + 17]) c4 = list(struct.unpack('>3H', data[pointer + 17:pointer + 23])) (c5, c6) = struct.unpack('>bq', data[pointer + 23:pointer + 32]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): b1 = struct.unpack('>Q', data[pointer:pointer + 8])[0] b2 = ''.join(map(str, struct.unpack('>5c', data[pointer + 8:pointer + 13]))) b2 = b2.replace(""'"", '')[1::2] b3 = parse_c(data, pointer + 13) b4 = parse_d(data, pointer + 45) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) a1 = parse_b(data, f1[0]) a2 = struct.unpack('>d', data[pointer + 4:pointer + 12])[0] a3 = list() for i in range(6): a3.append(parse_e(data, pointer + 12 + i * 18)) a4 = struct.unpack('>q', data[pointer + 120:pointer + 128])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 4)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): value = self.read(_pattern) res.append(value) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): sizeB1 = reader.read(Types.uint32) adressB1 = reader.read(Types.uint16) b1 = reader.copy(offset=adressB1).readWithSize(Types.int64, sizeB1) b2 = readC(reader) tempB3 = reader.readWithSize(Types.char, 3) b3 = b''.join(tempB3).decode('ASCII') return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.float) c2 = reader.read(Types.int16) c3 = readD(reader) c4 = reader.read(Types.uint64) return dict(C1=c1, C2=c2, C3=c3, C4=c4) def readD(reader): d1 = reader.read(Types.float) d2 = reader.read(Types.uint64) d3 = reader.read(Types.uint32) d4 = reader.read(Types.double) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def readE(reader): e1 = reader.read(Types.float) e2 = reader.read(Types.uint16) sizeE3 = reader.read(Types.uint16) adressE3 = reader.read(Types.uint32) e3 = reader.copy(offset=adressE3).readWithSize(Types.int16, sizeE3) e4 = reader.readWithSize(Types.uint8, 5) return dict(E1=e1, E2=e2, E3=e3, E4=e4) def readF(reader): f1 = reader.read(Types.uint8) f2 = reader.read(Types.float) return dict(F1=f1, F2=f2) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.int16) a2 = reader.read(Types.uint16) a3 = readB(reader) sizeA4 = reader.read(Types.uint16) adressA4 = reader.read(Types.uint16) a4 = [] eReader = BinaryReader(offset=adressA4, buffer=buffer) for i in range(0, sizeA4): a4.append(readE(BinaryReader(offset=eReader.read(Types.uint32), buffer=buffer))) a5 = readF(BinaryReader(offset=reader.read(Types.uint16), buffer=buffer)) a6 = reader.read(Types.uint16) a7 = reader.read(Types.uint8) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct def main(data): start_A = 3 a = struct.unpack_from('<2Hfq6cBIbIiQ3bf5bHb', data, start_A) (len_b, start_B) = (a[0], a[1]) Bs = [] for i in range(len_b): b = struct.unpack_from('' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse(buf, offs, 'int16') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) (a4_offs, offs) = parse(buf, offs, 'uint32') (a4, a4_offs) = parse_c(buf, a4_offs) a5 = [] for _ in range(2): (a5_offs, offs) = parse(buf, offs, 'uint32') (val, a5_offs) = parse_d(buf, a5_offs) a5.append(val) (a6, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'uint16') (b3, offs) = parse(buf, offs, 'double') (b4, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint16') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'uint8') c2.append(val) (c3, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'uint16') (d3_size, offs) = parse(buf, offs, 'uint16') (d3_offs, offs) = parse(buf, offs, 'uint32') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'uint16') d3.append(val) (d4, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2_size, offs) = parse(buf, offs, 'uint32') (a2_offs, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse(buf, a2_offs, 'float') a2.append(val) (a3, offs) = parse(buf, offs, 'int8') a4 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int64') a4.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (b1_offs_offs, b1_offs) = parse(buf, b1_offs, 'uint16') (val, b1_offs_offs) = parse_c(buf, b1_offs_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_d(buf, b3_offs) (b4, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') c2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') c2.append(val) return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'float') d1.append(val) (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' uint64 = 'Q' uint32 = 'I' uint16 = 'H' uint8 = 'B' int64 = 'q' int32 = 'i' int16 = 'h' int8 = 'b' char = 'c' double = 'd' class BinaryReader: def __init__(self, offset, source): self.offset = offset self.source = source def read(self, pattern): pattern = '>' + pattern.value result = unpack_from(pattern, self.source, self.offset) self.offset += calcsize(pattern) return result[0] def a(reader: BinaryReader): a1 = reader.read(Types.uint8) a2 = masser_a2(reader.read(Types.uint32), reader.read(Types.uint16), reader.source) a3 = reader.read(Types.int64) a4 = (reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char) + reader.read(Types.char)).decode('ascii') a5 = reader.read(Types.int16) a6 = masser_a6(reader.read(Types.uint32), reader.read(Types.uint16), reader.source) a7 = d(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7) def b(reader: BinaryReader): b1 = reader.read(Types.int16) b2 = c(reader.read(Types.uint32), reader.source) return dict(B1=b1, B2=b2) def c(offset, source): reader = BinaryReader(offset, source) c1 = reader.read(Types.float) c2 = reader.read(Types.uint16) return dict(C1=c1, C2=c2) def d(reader: BinaryReader): d1 = reader.read(Types.uint64) d2 = reader.read(Types.uint64) d3 = masser_d3(8, reader) d4 = reader.read(Types.float) d5 = reader.read(Types.double) d6 = reader.read(Types.int16) d7 = reader.read(Types.int32) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def masser_a2(size, offset, source): reader = BinaryReader(offset, source) rez = [] while reader.offset < offset + size * 6: rez.append(b(reader)) return rez def masser_a6(size, offset, source): reader = BinaryReader(offset, source) rez = '' while reader.offset < offset + size: rez += str(reader.read(Types.char).decode('ascii')) return rez def masser_d3(size, reader: BinaryReader): offset = reader.offset rez = [] while reader.offset < offset + size * 8: rez.append(reader.read(Types.uint64)) return rez def main(source): reader = BinaryReader(offset=4, source=source) return a(reader)" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3, d4) = struct.unpack('>hhfi', data[pointer:pointer + 12]) f5 = struct.unpack('>II', data[pointer + 12:pointer + 20]) d5 = list(struct.unpack(f'>{f5[0]}h', data[f5[1]:f5[1] + f5[0] * 2])) d6 = struct.unpack('>d', data[pointer + 20:pointer + 28])[0] d7 = list(struct.unpack('>2I', data[pointer + 28:pointer + 36])) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def parse_c(data, pointer): (c1, c2, c3, c4, c5, c6, c7) = struct.unpack('>iIBdHff', data[pointer:pointer + 27]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def parse_b(data, pointer): b1 = ''.join(map(str, struct.unpack('>4c', data[pointer:pointer + 4]))) b1 = b1.replace(""'"", '')[1::2] b2 = struct.unpack('>d', data[pointer + 4:pointer + 12])[0] f3 = struct.unpack('>IH', data[pointer + 12:pointer + 18]) b3 = list() for i in range(f3[0]): b3.append(parse_c(data, f3[1] + i * 27)) (b4, b5) = struct.unpack('>bI', data[pointer + 18:pointer + 23]) f6 = struct.unpack('>I', data[pointer + 23:pointer + 27]) b6 = parse_d(data, f6[0]) b7 = struct.unpack('>B', data[pointer + 27:pointer + 28])[0] b8 = list(struct.unpack('>8H', data[pointer + 28:pointer + 44])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def parse_a(data, pointer): (a1, a2) = struct.unpack('>BB', data[pointer:pointer + 2]) f3 = struct.unpack('>H', data[pointer + 2:pointer + 4]) a3 = parse_b(data, f3[0]) a4 = struct.unpack('>q', data[pointer + 4:pointer + 12])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'double') (a2, offs) = parse(buf, offs, 'float') (a3_size, offs) = parse(buf, offs, 'uint32') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'char') a3.append(val.decode()) (a4_size, offs) = parse(buf, offs, 'uint16') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse_b(buf, a4_offs) a4.append(val) (a5, offs) = parse(buf, offs, 'int16') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_d(buf, a6_offs) (a7_offs, offs) = parse(buf, offs, 'uint16') (a7, a7_offs) = parse_f(buf, a7_offs) (a8, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=''.join(a3), A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse_c(buf, offs) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse_e(buf, offs) d2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'uint16') d2.append(val) (d3, offs) = parse(buf, offs, 'uint64') (d4, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') (e2, offs) = parse(buf, offs, 'int8') (e3, offs) = parse(buf, offs, 'int32') (e4, offs) = parse(buf, offs, 'int8') (e5, offs) = parse(buf, offs, 'uint64') (e6, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'int16') f2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint8') f2.append(val) return (dict(F1=f1, F2=f2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def funcA(p): r = dict() r['A1'] = struct.unpack('>h', p[4:6])[0] r['A2'] = funcB(p, 6) r['A3'] = struct.unpack('>h', p[26:28])[0] caddr = struct.unpack('>H', p[28:30])[0] t1 = funcC(p, caddr) caddr = struct.unpack('>H', p[30:32])[0] t2 = funcC(p, caddr) r['A4'] = [t1, t2] caddr = struct.unpack('>H', p[32:34])[0] r['A5'] = funcE(p, caddr) r['A6'] = struct.unpack('>b', p[34:35])[0] size = struct.unpack('>H', p[35:37])[0] adr = struct.unpack('>I', p[37:41])[0] r['A7'] = list(struct.unpack('>' + str(size) + 'i', p[adr:adr + size * 4])) return r def funcB(p, index): r = dict() r['B1'] = struct.unpack('>i', p[index:index + 4])[0] r['B2'] = struct.unpack('>H', p[index + 4:index + 6])[0] r['B3'] = struct.unpack('>q', p[index + 6:index + 14])[0] r['B4'] = struct.unpack('>I', p[index + 14:index + 18])[0] r['B5'] = struct.unpack('>H', p[index + 18:index + 20])[0] return r def funcC(p, index): r = dict() size = struct.unpack('>I', p[index:index + 4])[0] adr = struct.unpack('>I', p[index + 4:index + 8])[0] r['C1'] = '' for i in range(size): r['C1'] += struct.unpack('>' + str(size) + 'c', p[adr:adr + size])[0].decode() adr += 1 size = struct.unpack('>I', p[index + 8:index + 12])[0] adr = struct.unpack('>H', p[index + 12:index + 14])[0] r['C2'] = list(struct.unpack('>' + str(size) + 'h', p[adr:adr + size * 2])) r['C3'] = funcD(p, index + 14) r['C4'] = struct.unpack('>b', p[index + 27:index + 28])[0] return r def funcD(p, index): r = dict() r['D1'] = struct.unpack('>i', p[index:index + 4])[0] r['D2'] = struct.unpack('>d', p[index + 4:index + 12])[0] r['D3'] = struct.unpack('>b', p[index + 12:index + 13])[0] return r def funcE(p, index): r = dict() r['E1'] = [struct.unpack('>f', p[index:index + 4])[0], struct.unpack('>f', p[index + 4:index + 8])[0]] r['E2'] = struct.unpack('>f', p[index + 8:index + 12])[0] r['E3'] = struct.unpack('>I', p[index + 12:index + 16])[0] r['E4'] = struct.unpack('>B', p[index + 16:index + 17])[0] return r def main(pack): return funcA(pack)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse(buf, offs, 'uint32') (a5_offs, offs) = parse(buf, offs, 'uint32') (val, a5_offs) = parse_b(buf, a5_offs) a5 = val (a6, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint16') (val, b1_offs) = parse_c(buf, b1_offs) b1 = val b2 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) b2.append(val) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2_size, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = '' for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2 += val.decode('utf-8') (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse(buf, offs, 'int32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'int32') d3 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint8') d3.append(val) (d4_size, offs) = parse(buf, offs, 'uint32') (d4_offs, offs) = parse(buf, offs, 'uint16') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'int8') d4.append(val) (d5, offs) = parse(buf, offs, 'int8') (d6, offs) = parse(buf, offs, 'float') (d7, offs) = parse(buf, offs, 'uint8') (d8, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('int64', data, ofs) (E2, ofs) = parse('uint8', data, ofs) (E3, ofs) = parse('uint8', data, ofs) return (dict(E1=E1, E2=E2, E3=E3), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint8', data, ofs) (D2, ofs) = parse('float', data, ofs) (D3, ofs) = parse('int16', data, ofs) (D4, ofs) = parse('uint64', data, ofs) (D5, ofs) = parse('int16', data, ofs) D6 = [] (D6_size, ofs) = parse('uint16', data, ofs) (D6_adr, ofs) = parse('uint16', data, ofs) for i in range(D6_size): (elem, D6_adr) = parse('int16', data, D6_adr) D6.append(elem) (D7, ofs) = parse('int16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6, D7=D7), ofs) def struct_C(data, ofs): (C1, ofs) = parse('float', data, ofs) (C2, ofs) = parse('double', data, ofs) (C3, ofs) = struct_D(data, ofs) (C4, ofs) = parse('uint8', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): B1 = [] (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint16', data, ofs) for i in range(B1_size): (elem, B1_adr) = struct_C(data, B1_adr) B1.append(elem) B2 = [] for i in range(3): (elem, ofs) = parse('int64', data, ofs) B2.append(elem) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint32', data, ofs) (A2, ofs) = parse('int8', data, ofs) (A3, ofs) = struct_B(data, ofs) (A4, ofs) = parse('uint64', data, ofs) (A5, ofs) = parse('double', data, ofs) A6 = [] (A6_size, ofs) = parse('uint16', data, ofs) (A6_adr, ofs) = parse('uint32', data, ofs) for i in range(A6_size): (elem, A6_adr) = parse('uint32', data, A6_adr) A6.append(elem) (A7_adr, ofs) = parse('uint32', data, ofs) (A7, elem) = struct_E(data, A7_adr) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7), ofs) def main(data): return struct_A(data, 3)[0]" "import struct def D(x, i): return {'D1': list(struct.unpack('> 4i', x[i:i + 16])), 'D2': S_u1Add_u32Ar_i16(x, i + 16), 'D3': struct.unpack('>I', x[i + 24:i + 28])[0]} def C(x, i): return {'C1': struct.unpack('> b', x[i:i + 1])[0], 'C2': struct.unpack('>I', x[i + 1:i + 5])[0]} def B(x, i): return {'B1': [C(x, addressC(x, i)), C(x, addressC(x, i + 4)), C(x, addressC(x, i + 8)), C(x, addressC(x, i + 12)), C(x, addressC(x, i + 16)), C(x, addressC(x, i + 20))], 'B2': struct.unpack('> i', x[i + 24:i + 28])[0], 'B3': D(x, addressC(x, i + 28)), 'B4': struct.unpack('> f', x[i + 32:i + 36])[0], 'B5': struct.unpack('> d', x[i + 36:i + 44])[0]} def addressC(x, i): return struct.unpack('> I', x[i:i + 4])[0] def addressB(x, i): return struct.unpack('> H', x[i:i + 2])[0] def A(x, i): return {'A1': struct.unpack('> d', x[i:i + 8])[0], 'A2': struct.unpack('>Q', x[i + 8:i + 16])[0], 'A3': struct.unpack('> h', x[i + 16:i + 18])[0], 'A4': B(x, addressB(x, i + 18)), 'A5': list(struct.unpack('> 7h', x[i + 20:i + 34]))} def S_u1Add_u32Ar_i16(x, i): size = struct.unpack('> I', x[i:i + 4])[0] address = struct.unpack('> I', x[i + 4:i + 8])[0] a = struct.unpack('> ' + 'q' * size, x[address:address + 8 * size]) return list(a) def main(x): return A(x, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'int8') (a3_offs, offs) = parse(buf, offs, 'uint16') (a3, _) = parse_b(buf, a3_offs) return (dict(A1=''.join(a1), A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'int16') (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (val, b4_offs) = parse_c(buf, b4_offs) b4.append(val) (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint32') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'float') b5.append(val) (b6, offs) = parse(buf, offs, 'float') (b7_offs, offs) = parse(buf, offs, 'uint32') (b7, _) = parse_d(buf, b7_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint32') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'double') c1.append(val) (c2, offs) = parse(buf, offs, 'uint8') c3 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') c3.append(val) (c4, offs) = parse(buf, offs, 'int32') (c5, offs) = parse(buf, offs, 'uint16') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3, e4) = struct.unpack('>hQbf', data[pointer:pointer + 15]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def parse_d(data, pointer): d1 = struct.unpack('>B', data[pointer:pointer + 1])[0] d2 = list(struct.unpack('>5I', data[pointer + 1:pointer + 21])) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (f1, f2) = struct.unpack('>HI', data[pointer:pointer + 6]) (c1, c2) = (parse_d(data, f1), parse_e(data, f2)) (c3, c4) = struct.unpack('>Ib', data[pointer + 6:pointer + 11]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): (b1, b2, b3, b4) = struct.unpack('>iHhi', data[pointer:pointer + 12]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) a1 = list(struct.unpack(f'>{f1[0]}q', data[f1[1]:f1[1] + f1[0] * 8])) (a2, a3) = struct.unpack('>hf', data[pointer + 6:pointer + 12]) f4 = struct.unpack('>HI', data[pointer + 12:pointer + 18]) a4 = list() for i in range(f4[0]): f44 = struct.unpack('>I', data[f4[1] + 4 * i:f4[1] + 4 + 4 * i]) a4.append(parse_b(data, f44[0])) f5 = struct.unpack('>I', data[pointer + 18:pointer + 22]) a5 = parse_c(data, f5[0]) a6 = struct.unpack('>I', data[pointer + 22:pointer + 26])[0] a7 = list(struct.unpack('>4H', data[pointer + 26:pointer + 34])) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 3)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def b(reader): b1 = c(reader) b2 = reader.readWithSize(Types.uint8, 6) b3 = reader.read(Types.double) return dict(B1=b1, B2=b2, B3=b3) def c(reader): tempC = reader.readWithSize(Types.char, 4) c1 = b''.join(tempC).decode('ASCII') c2 = reader.read(Types.int32) return dict(C1=c1, C2=c2) def d(reader): sized1 = reader.read(Types.uint32) adressd1 = reader.read(Types.uint16) d1 = reader.copy(offset=adressd1).readWithSize(Types.int8, sized1) d2 = reader.read(Types.int32) d3 = reader.read(Types.uint8) return dict(D1=d1, D2=d2, D3=d3) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.int32) a2 = reader.read(Types.uint32) a3 = b(reader) a4 = reader.read(Types.uint16) a5 = reader.read(Types.float) a61 = d(reader.copy(reader.read(Types.uint16))) a62 = d(reader.copy(reader.read(Types.uint16))) a6 = [a61, a62] a7 = reader.read(Types.int16) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "import struct def main(data): A = struct.unpack_from('hI', data[pointer:pointer + 6]) return {'D1': d1, 'D2': d2} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>Bbbh', data[pointer:pointer + 5]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) b1 = parse_c(data, f1[0]) b2 = list() b2.append(parse_d(data, pointer + 2)) b2.append(parse_d(data, pointer + 8)) (b3, b4) = struct.unpack('>bB', data[pointer + 14:pointer + 16]) b5 = list(struct.unpack('>2Q', data[pointer + 16:pointer + 32])) b6 = struct.unpack('>d', data[pointer + 32:pointer + 40])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): a1 = ''.join(map(str, struct.unpack('>4c', data[pointer:pointer + 4]))) a1 = a1.replace(""'"", '')[1::2] a2 = parse_b(data, pointer + 4) a3 = struct.unpack('>H', data[pointer + 44:pointer + 46])[0] f4 = struct.unpack('>HH', data[pointer + 46:pointer + 50]) a4 = list(struct.unpack(f'>{f4[0]}q', data[f4[1]:f4[1] + f4[0] * 8])) (a5, a6) = struct.unpack('>IH', data[pointer + 50:pointer + 56]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6} def main(data): return parse_a(data, 4)" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_f(reader: BinaryReader): f1 = [] for _ in range(8): val = reader.read_uint8() f1.append(val) f2 = reader.read_int16() f3 = reader.read_int64() return dict(F1=f1, F2=f2, F3=f3) def read_e(reader: BinaryReader): e1 = [reader.read_uint8(), reader.read_uint8(), reader.read_uint8()] e2 = reader.read_uint64() e3 = reader.read_int16() e4 = reader.read_int16() return dict(E1=e1, E2=e2, E3=e3, E4=e4) def read_d(reader: BinaryReader): d1 = reader.read_double() d2 = read_e(reader) d3 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint16(), structure_size=2) return dict(D1=d1, D2=d2, D3=d3) def read_c(reader: BinaryReader): c1 = reader.read_double() c2 = read_d(reader) return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = reader.read_int32() b2 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_c(reader)) b2 = b2[0] return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = reader.read_int8() a2 = read_array(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_b(reader)) a2 = a2[0] a3 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_f(reader)), structure_size=3) a3 = a3[0] + a3[1] return dict(A1=a1, A2=a2, A3=a3) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint64') (a2, offs) = parse(buf, offs, 'uint64') (a3_size, offs) = parse(buf, offs, 'uint32') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'uint32') (val2, val) = parse_b(buf, val) a3.append(val2) (a4, offs) = parse_c(buf, offs) (a5, offs) = parse(buf, offs, 'float') (a6, offs) = parse(buf, offs, 'int16') (a7, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'uint32') (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) (c2, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2_size, offs) = parse(buf, offs, 'uint32') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint16') d2.append(val) (d3, offs) = parse(buf, offs, 'int8') (d4_size, offs) = parse(buf, offs, 'uint16') (d4_offs, offs) = parse(buf, offs, 'uint32') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'int16') d4.append(val) (d5_size, offs) = parse(buf, offs, 'uint16') (d5_offs, offs) = parse(buf, offs, 'uint32') d5 = [] for _ in range(d5_size): (val, d5_offs) = parse(buf, d5_offs, 'int8') d5.append(val) (d6, offs) = parse(buf, offs, 'int64') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): A = struct.unpack_from('>q2HiI', data, offset=3) A2 = list(struct.unpack_from('>' + str(A[1]) + 'b', data, offset=A[2])) B = struct.unpack_from('>q4HBbdIHQHi5dh', data, offset=A[4]) C_list = [] for i in range(4): C = struct.unpack_from('>qHBf', data, offset=B[i + 1]) C_list.append({'C1': C[0], 'C2': C[1], 'C3': C[2], 'C4': C[3]}) D3 = list(struct.unpack_from('>' + str(B[8]) + 'h', data, offset=B[9])) return {'A1': A[0], 'A2': A2, 'A3': A[3], 'A4': {'B1': B[0], 'B2': C_list, 'B3': B[5], 'B4': {'D1': B[6], 'D2': B[7], 'D3': D3, 'D4': B[10], 'D5': B[11]}, 'B5': B[12], 'B6': {'E1': B[13], 'E2': [B[14], B[15], B[16], B[17]]}, 'B7': B[18]}}" "import struct BYTE_INDEX = 0 def my_repack(type, arr): global BYTE_INDEX BYTE_INDEX += len(arr) return struct.unpack(type, arr)[0] def get_int(type_int, arr): global BYTE_INDEX num = arr[BYTE_INDEX] BYTE_INDEX += 1 count = type_int / 8 - 1 while count > 0: temp = arr[BYTE_INDEX] BYTE_INDEX += 1 num = num << 8 num = num ^ temp count -= 1 return num class structD: def fill_struct(self, b): global BYTE_INDEX self.set_D1(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_D2(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_D3(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) return self def set_D1(self, arr): self.D1 = arr def set_D2(self, num): self.D2 = num def set_D3(self, arr): self.D3 = arr def get_cort(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3} class structC: def fill_struct(self, b): global BYTE_INDEX arr_p = [] for i in range(4): arr_p.append(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) arr_s = [] STOP_INDEX = BYTE_INDEX for i in arr_p: BYTE_INDEX = i arr_s.append(structD().fill_struct(b)) BYTE_INDEX = STOP_INDEX self.set_C1(arr_s) self.set_C2(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) return self def set_C1(self, num): self.C1 = num def set_C2(self, num): self.C2 = num def get_cort(self): arr = [] for i in self.C1: arr.append(i.get_cort()) return {'C1': arr, 'C2': self.C2} class structB: def fill_struct(self, b): global BYTE_INDEX self.set_B1(my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_B2(structC().fill_struct(b)) self.set_B3(my_repack('>q', b[BYTE_INDEX:BYTE_INDEX + 8])) str = '' for i in range(5): str += chr(my_repack('>b', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B4(str) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>I', b[BYTE_INDEX:BYTE_INDEX + 4]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(my_repack('>B', b[BYTE_INDEX:BYTE_INDEX + 1])) self.set_B5(arr) BYTE_INDEX = STOP_INDEX self.set_B6(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_B7(my_repack('>d', b[BYTE_INDEX:BYTE_INDEX + 8])) arr1 = [] for i in range(7): arr1.append(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_B8(arr1) return self def set_B1(self, num): self.B1 = num def set_B2(self, num): self.B2 = num def set_B3(self, num): self.B3 = num def set_B4(self, num): self.B4 = num def set_B5(self, num): self.B5 = num def set_B6(self, num): self.B6 = num def set_B7(self, num): self.B7 = num def set_B8(self, num): self.B8 = num def get_cort(self): return {'B1': self.B1, 'B2': self.B2.get_cort(), 'B3': self.B3, 'B4': self.B4, 'B5': self.B5, 'B6': self.B6, 'B7': self.B7, 'B8': self.B8} class structA: def fill_struct(self, b): global BYTE_INDEX self.set_A1(my_repack('>h', b[BYTE_INDEX:BYTE_INDEX + 2])) self.set_A2(structB().fill_struct(b)) size = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) pointer = my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2]) STOP_INDEX = BYTE_INDEX BYTE_INDEX = pointer arr = [] for i in range(size): arr.append(my_repack('>f', b[BYTE_INDEX:BYTE_INDEX + 4])) self.set_A3(arr) BYTE_INDEX = STOP_INDEX self.set_A4(my_repack('>Q', b[BYTE_INDEX:BYTE_INDEX + 8])) self.set_A5(my_repack('>H', b[BYTE_INDEX:BYTE_INDEX + 2])) return self def set_A1(self, a): self.A1 = a def set_A2(self, a): self.A2 = a def set_A3(self, a): self.A3 = a def set_A4(self, a): self.A4 = a def set_A5(self, a): self.A5 = a def get_cort(self): return {'A1': self.A1, 'A2': self.A2.get_cort(), 'A3': self.A3, 'A4': self.A4, 'A5': self.A5} def main(h): global BYTE_INDEX BYTE_INDEX = 4 A = structA() A.fill_struct(h) return A.get_cort()" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('>HB', data[pointer:pointer + 3]) f3 = struct.unpack('>HH', data[pointer + 3:pointer + 7]) d3 = list(struct.unpack(f'>{f3[0]}h', data[f3[1]:f3[1] + f3[0] * 2])) (d4, d5, d6, d7) = struct.unpack('>hHHH', data[pointer + 7:pointer + 15]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def parse_c(data, pointer): c1 = list() c1.append(parse_d(data, pointer)) c1.append(parse_d(data, pointer + 15)) c2 = struct.unpack('>i', data[pointer + 30:pointer + 34])[0] return {'C1': c1, 'C2': c2} def parse_b(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) b1 = parse_c(data, f1[0]) (b2, b3) = struct.unpack('>bh', data[pointer + 2:pointer + 5]) f4 = struct.unpack('>II', data[pointer + 5:pointer + 13]) b4 = list(struct.unpack(f'>{f4[0]}f', data[f4[1]:f4[1] + f4[0] * 4])) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) a1 = parse_b(data, f1[0]) a2 = struct.unpack('>I', data[pointer + 2:pointer + 6])[0] f3 = struct.unpack('>HI', data[pointer + 6:pointer + 12]) a3 = list(struct.unpack(f'>{f3[0]}f', data[f3[1]:f3[1] + f3[0] * 4])) (a4, a5, a6, a7) = struct.unpack('>IQff', data[pointer + 12:pointer + 32]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 5)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int8') (a3, offs) = parse(buf, offs, 'uint32') (a4, offs) = parse(buf, offs, 'uint16') (a5, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint32') (b1, b1_offs) = parse_c(buf, b1_offs) (b2_offs, offs) = parse(buf, offs, 'uint16') (b2, b2_offs) = parse_e(buf, b2_offs) (b3, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int32') b4.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint32') (c1_offs, offs) = parse(buf, offs, 'uint16') c1 = [] c1arr = [] for i in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'uint16') c1arr.append(val) (elem, elem_offs) = parse_d(buf, c1arr[i]) c1.append(elem) (c2, offs) = parse(buf, offs, 'int16') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): d1 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int32') d1.append(val) (d2, offs) = parse(buf, offs, 'float') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse(buf, offs, 'float') (e3, offs) = parse(buf, offs, 'int16') (e4, offs) = parse(buf, offs, 'int32') (e5, offs) = parse(buf, offs, 'int16') (e6, offs) = parse(buf, offs, 'int64') (e7_size, offs) = parse(buf, offs, 'uint16') (e7_offs, offs) = parse(buf, offs, 'uint16') e7 = [] for _ in range(e7_size): (val, e7_offs) = parse(buf, e7_offs, 'uint32') e7.append(val) (e8, offs) = parse(buf, offs, 'int16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7, E8=e8), offs) def main(buf): return parse_a(buf, 3)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2_size, offs) = parse(buf, offs, 'uint16') (a2_offs, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(a2_size): (val, a2_offs) = parse_e(buf, a2_offs) a2.append(val) (a3, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) (b2, offs) = parse(buf, offs, 'int64') (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_d(buf, b3_offs) return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2, offs) = parse(buf, offs, 'float') c3 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'char') c3.append(val.decode()) (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse(buf, c4_offs, 'float') c4.append(val) return (dict(C1=c1, C2=c2, C3=''.join(c3), C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'int32') (d3, offs) = parse(buf, offs, 'uint64') (d4, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint32') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'uint8') e1.append(val) (e2_size, offs) = parse(buf, offs, 'uint16') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'int8') e2.append(val) (e3, offs) = parse(buf, offs, 'uint64') (e4, offs) = parse(buf, offs, 'uint32') (e5, offs) = parse(buf, offs, 'int8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read_double(self): return self.read('d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_f(reader: BinaryReader): f1 = [] for _ in range(8): val = reader.read_uint8() f1.append(val) f2 = reader.read_int16() f3 = reader.read_int64() return dict(F1=f1, F2=f2, F3=f3) def read_d(reader: BinaryReader): d1 = reader.read_float() d2 = reader.read_double() d3 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint32(), read=lambda reader: reader.read_uint32(), structure_size=4) d4 = reader.read_double() d5 = reader.read_double() d6 = [] for _ in range(4): val = reader.read_int16() d6.append(val) d7 = reader.read_int64() d8 = reader.read_int32() return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8) def read_c(reader: BinaryReader): c1 = reader.read_uint16() c2 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_float(), structure_size=4) return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): b1 = reader.read_int64() b2 = reader.read_uint64() b3 = reader.read_int32() b4 = [] for _ in range(2): val = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_c(reader)) b4.append(val) b4 = b4[0] + b4[1] b5 = reader.read_int8() b6 = read_array(source=reader.source, size=reader.read_uint32(), address=reader.read_uint16(), read=lambda reader: reader.read_uint32(), structure_size=4) b7 = reader.read_uint64() return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7) def read_a(reader: BinaryReader): a1 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_b(reader)) a1 = a1[0] a2 = reader.read_int64() a3 = reader.read_int32() a4 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_d(reader)) a4 = a4[0] return dict(A1=a1, A2=a2, A3=a3, A4=a4) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('<4H', data[pointer:pointer + 8])) d2 = struct.unpack('5chIIhBBfqifIBIHBHhHH', data) C_DataSize = struct.calcsize('>hq8H') structC = [] for ic in range(0, B_uint32_size_structC): (C_int16, C_int64, *massive_uint16) = struct.unpack_from('>hq8H', data, B_uint32_adress_structC + ic * C_DataSize) bufferC = {} bufferC['C1'] = C_int16 bufferC['C2'] = C_int64 bufferC['C3'] = list(massive_uint16) structC.append(bufferC) D_massive_uint64 = struct.unpack_from('>' + str(D_uint32_massive_size_uint64) + 'Q', data, D_uint16_massive_adress_uint64) A_massive_uint16 = struct.unpack_from('>' + str(A_uint16_massive_size_int8) + 'b', data, A_uint16_massive_adress_int8) ret = {} ret['A1'] = A_int16 ret_structB = {} ret_structB['B1'] = structC ret_structB['B2'] = B_int16_1 ret_structB['B3'] = B_uint8_1 ret_structB['B4'] = B_uint8_2 ret_structB['B5'] = B_float ret_structB_structD = {} ret_structB_structD['D1'] = D_int64 ret_structB_structD['D2'] = D_int32 ret_structB_structD['D3'] = D_float ret_structB_structD['D4'] = D_uint32 ret_structB_structD['D5'] = D_uint8_1 ret_structB_structD['D6'] = list(D_massive_uint64) ret_structB_structD['D7'] = D_uint8_2 ret_structB_structD['D8'] = D_uint16 ret_structB['B6'] = ret_structB_structD ret_structB['B7'] = B_int16_2 ret['A2'] = ret_structB ret['A3'] = list(A_massive_uint16) return ret" "from struct import unpack class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('Q') def read_int64(self): return self.read('q') def read_uint32(self): return self.read('I') def read_int32(self): return self.read('i') def read_uint16(self): return self.read('H') def read_int16(self): return self.read('h') def read_uint8(self): return self.read('B') def read_int8(self): return self.read('b') def read_float(self): return self.read('f') def read_char(self): return self.read('c') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def main(file): a_adr = 5 a = {f'A{i}': None for i in range(1, 5)} a['A1'] = unpack('f', data[pointer:pointer + 4]) (e2,) = struct.unpack('>I', data[pointer + 4:pointer + 8]) (e3,) = struct.unpack('>B', data[pointer + 8:pointer + 9]) (e4,) = struct.unpack('>H', data[pointer + 9:pointer + 11]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def structD(data, pointer): fd1 = struct.unpack('>IH', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{fd1[0]}b', data[fd1[1]:fd1[1] + fd1[0]])) fd2 = struct.unpack('>II', data[pointer + 6:pointer + 14]) d2 = list(struct.unpack(f'>{fd2[0]}I', data[fd2[1]:fd2[1] + fd2[0] * 4])) (d3,) = struct.unpack('>q', data[pointer + 14:pointer + 22]) (d4,) = struct.unpack('>i', data[pointer + 22:pointer + 26]) fd3 = struct.unpack('>HI', data[pointer + 26:pointer + 32]) d5 = list(struct.unpack(f'>{fd3[0]}H', data[fd3[1]:fd3[1] + fd3[0] * 2])) (d6,) = struct.unpack('>d', data[pointer + 32:pointer + 40]) (d7,) = struct.unpack('>d', data[pointer + 40:pointer + 48]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7} def structC(data, pointer): c1 = ''.join(map(str, struct.unpack(f'>5c', data[pointer:pointer + 5]))) c1 = c1.replace(""'"", '') c1 = c1[1::2] c2 = structD(data, pointer + 5) (c3,) = struct.unpack('>I', data[pointer + 53:pointer + 57]) return {'C1': c1, 'C2': c2, 'C3': c3} def structB(data, pointer): (b1,) = struct.unpack('>B', data[pointer:pointer + 1]) (b2,) = struct.unpack('>i', data[pointer + 1:pointer + 5]) return {'B1': b1, 'B2': b2} def structA(data, pointer): fa1 = struct.unpack('>H', data[pointer:pointer + 2]) a1 = structB(data, fa1[0]) fa2 = struct.unpack('>II', data[pointer + 2:pointer + 10]) a2 = [] for i in range(fa2[0]): x = structC(data, fa2[1] + i * 57) a2.append(x) a3 = structE(data, pointer + 10) (a4,) = struct.unpack('>q', data[pointer + 21:pointer + 29]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return structA(data, 5)" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint8') (a2, offs) = parse(buf, offs, 'int16') (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, offs1) = parse_b(buf, a3_offs) a4 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') a4.append(val) a5 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') a5.append(val) (a6, offs) = parse(buf, offs, 'uint16') (a7, offs) = parse(buf, offs, 'double') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1_offs, offs) = parse(buf, offs, 'uint16') (b1, offs1) = parse_c(buf, b1_offs) (b2, offs) = parse_e(buf, offs) (b3, offs) = parse(buf, offs, 'int16') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'int64') (c3, offs) = parse(buf, offs, 'uint64') (c4, offs) = parse(buf, offs, 'int8') c5 = [] for _ in range(6): (c5_offs, offs) = parse(buf, offs, 'uint32') (val, c5_offs) = parse_d(buf, c5_offs) c5.append(val) (c6, offs) = parse(buf, offs, 'int32') (c7, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2_size, offs) = parse(buf, offs, 'uint16') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'uint8') d2.append(val) return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint16') (e2, offs) = parse(buf, offs, 'uint64') (e3, offs) = parse(buf, offs, 'int32') (e4, offs) = parse(buf, offs, 'uint8') (e5, offs) = parse(buf, offs, 'uint64') (e6, offs) = parse(buf, offs, 'int64') (e7_size, offs) = parse(buf, offs, 'uint32') (e7_offs, offs) = parse(buf, offs, 'uint16') e7 = [] for _ in range(e7_size): (val, e7_offs) = parse(buf, e7_offs, 'uint8') e7.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import pprint t_d = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char[]': 's', 'char': 'c'} def parse_b(data, p): b1 = struct.unpack('>' + t_d['int8'], data[p:p + 1])[0] p += 1 b2 = struct.unpack('>' + t_d['uint32'], data[p:p + 4])[0] p += 4 return {'B1': b1, 'B2': b2} def parse_c(data, p): c1 = list(struct.unpack('>7' + t_d['int8'], data[p:p + 7 * 1])) p += 7 * 1 c2 = struct.unpack('>' + t_d['float'], data[p:p + 4])[0] p += 4 c3 = struct.unpack('>' + t_d['uint64'], data[p:p + 8])[0] p += 8 f4 = struct.unpack('>' + t_d['uint16'], data[p:p + 2])[0] c4 = parse_d(data, f4) p += 2 c5 = struct.unpack('>' + t_d['uint16'], data[p:p + 2])[0] p += 2 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_d(data, p): d1 = struct.unpack('>' + t_d['float'], data[p:p + 4])[0] p += 4 d2 = struct.unpack('>' + t_d['double'], data[p:p + 8])[0] p += 8 d3 = struct.unpack('>' + t_d['uint8'], data[p:p + 1])[0] p += 1 d4 = struct.unpack('>' + t_d['uint8'], data[p:p + 1])[0] p += 1 d5 = struct.unpack('>' + t_d['int64'], data[p:p + 8])[0] p += 8 d6 = struct.unpack('>' + t_d['uint64'], data[p:p + 8])[0] p += 8 return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_e(data, p): e1 = struct.unpack('>' + t_d['int32'], data[p:p + 4])[0] p += 4 e2 = struct.unpack('>' + t_d['int32'], data[p:p + 4])[0] p += 4 e3 = struct.unpack('>' + t_d['int16'], data[p:p + 2])[0] p += 2 e4 = struct.unpack('>' + t_d['uint64'], data[p:p + 8])[0] p += 8 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4} def parse_f(data, p): f1 = struct.unpack('>' + t_d['uint8'], data[p:p + 1])[0] p += 1 f2 = struct.unpack('>' + t_d['int32'], data[p:p + 4])[0] p += 4 f3 = struct.unpack('>' + t_d['int16'], data[p:p + 2])[0] p += 2 f4 = struct.unpack('>' + t_d['int16'], data[p:p + 2])[0] p += 2 ff5 = struct.unpack('>' + t_d['uint32'] + t_d['uint32'], data[p:p + 4 + 4])[0] size = struct.unpack('>' + t_d['uint32'], data[p:p + 4])[0] p += 4 adr = struct.unpack('>' + t_d['uint32'], data[p:p + 4])[0] p += 4 f5 = list(struct.unpack('>' + str(size) + t_d['double'], data[adr:adr + size * 8])) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5} def parse_a(data, p): a1 = struct.unpack('>' + t_d['int8'], data[p:p + 1])[0] p += 1 a2 = [] for i in range(5): b = parse_b(data, p) a2.append(b) p += 5 f3 = list(struct.unpack('>5' + t_d['char'], data[p:p + 5 * 1])) a3 = '' for s in f3: a3 += bytes(s).decode() p += 5 * 1 f4 = struct.unpack('>' + t_d['uint16'], data[p:p + 2])[0] a4 = parse_c(data, f4) p += 2 f5 = struct.unpack('>' + t_d['uint32'], data[p:p + 4])[0] a5 = parse_e(data, f5) p += 4 a6 = parse_f(data, p) p += 17 a7 = struct.unpack('>' + t_d['int16'], data[p:p + 2])[0] p += 2 a8 = struct.unpack('>' + t_d['double'], data[p:p + 8])[0] p += 8 return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 5)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): D1 = [] (D1_size, ofs) = parse('uint32', data, ofs) (D1_adr, ofs) = parse('uint32', data, ofs) for i in range(D1_size): (elem, D1_adr) = parse('int32', data, D1_adr) D1.append(elem) (D2, ofs) = parse('uint64', data, ofs) (D3, ofs) = parse('uint32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def struct_C(data, ofs): (C1, ofs) = parse('int8', data, ofs) (C2, ofs) = parse('int64', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint64', data, ofs) (B2, ofs) = parse('float', data, ofs) (B3, ofs) = parse('uint16', data, ofs) B4 = '' (B4_size, ofs) = parse('uint32', data, ofs) (B4_adr, ofs) = parse('uint32', data, ofs) for i in range(B4_size): (elem, B4_adr) = parse('char', data, B4_adr) B4 += elem.decode() B5 = [] (B5_size, ofs) = parse('uint16', data, ofs) (B5_adr, ofs) = parse('uint32', data, ofs) for i in range(B5_size): (elem, B5_adr) = parse('uint8', data, B5_adr) B5.append(elem) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int32', data, ofs) (A2, ofs) = parse('double', data, ofs) (A3, ofs) = struct_B(data, ofs) A4 = [] for i in range(5): (C_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_C(data, C_adr) A4.append(elem) (A5_adr, ofs) = parse('uint16', data, ofs) (A5, elem) = struct_D(data, A5_adr) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): data = unpack_from(FMT[ty], buf, offs) data = data[0] of = offs + calcsize(FMT[ty]) return (data, of) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') a2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int32') a2.append(val) (a3, offs) = parse_b(buf, offs) (a4_size, offs) = parse(buf, offs, 'uint16') (a4_offs, offs) = parse(buf, offs, 'uint32') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'uint32') a4.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2_size, offs) = parse(buf, offs, 'uint16') (b2_offs, offs) = parse(buf, offs, 'uint32') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse_c(buf, b2_offs) b2.append(val) (b3, offs) = parse_d(buf, offs) (b4, offs) = parse(buf, offs, 'int8') (b5, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2, offs) = parse(buf, offs, 'uint16') (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse(buf, offs, 'double') (c5, offs) = parse(buf, offs, 'int8') (c6, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int64') d2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'double') d2.append(val) (d3, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def main(data): (*b, A_uint8, A_uint64, A_int32) = struct.unpack_from('>5cBQi', data) structCsize = struct.calcsize('>I5BIHbH') firstOffset = struct.calcsize('>5cBQi') structsCsignature = [] (*B_massive_adress_StructC_uint16, B_uint32, B_size_uint32_massive_int32, B_address_uint16_massive_int32, B_int16, B_uint8) = struct.unpack_from('>5HIIHhB', data, firstOffset) B_massive = struct.unpack_from('>' + 'i' * B_size_uint32_massive_int32, data, B_address_uint16_massive_int32) for i in B_massive_adress_StructC_uint16: structCBuffer = {} (C_uint32, *C_uint8_massive, C_addressStructD, C_uint16_1, C_int8, C_uint16_2) = struct.unpack_from('>I5BIHbH', data, i) structDBuffer = {} (D_uint32, *D_massive_uint8) = struct.unpack_from('>I5B', data, C_addressStructD) structCBuffer['C1'] = C_uint32 structCBuffer['C2'] = list(C_uint8_massive) structDBuffer['D1'] = D_uint32 structDBuffer['D2'] = list(D_massive_uint8) structCBuffer['C3'] = structDBuffer structCBuffer['C4'] = C_uint16_1 structCBuffer['C5'] = C_int8 structCBuffer['C6'] = C_uint16_2 structsCsignature.append(structCBuffer) ret = {} ret['A1'] = A_uint8 ret['A2'] = A_uint64 ret['A3'] = A_int32 ret_structB = {} ret_structB['B1'] = structsCsignature ret_structB['B2'] = B_uint32 ret_structB['B3'] = list(B_massive) ret_structB['B4'] = B_int16 ret_structB['B5'] = B_uint8 ret['A4'] = ret_structB return ret" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '<' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): value = self.read(_pattern) res.append(value) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = readC(reader.copy(reader.read(Types.uint32))) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint32) b2 = [] bReader = BinaryReader(offset=adress2, buffer=reader.buffer) for i in range(0, size2): b2.append(readE(BinaryReader(offset=bReader.read(Types.uint32), buffer=reader.buffer))) b3 = reader.read(Types.uint32) b4 = reader.readWithSize(Types.int16, 7) b5 = reader.read(Types.uint16) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5) def readC(reader): c1 = reader.read(Types.uint8) c2 = reader.read(Types.uint64) c3 = readD(reader.copy(reader.read(Types.uint32))) c4 = reader.read(Types.double) c5 = reader.read(Types.uint8) c6 = reader.read(Types.float) c7 = reader.read(Types.int64) c8 = reader.read(Types.uint64) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7, C8=c8) def readD(reader): d1 = reader.read(Types.uint32) d2 = reader.read(Types.double) return dict(D1=d1, D2=d2) def readE(reader): e1 = readF(reader) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint32) e2 = reader.copy(offset=adress3).readWithSize(Types.uint8, size3) return dict(E1=e1, E2=e2) def readF(reader): f1 = reader.read(Types.uint16) f2 = reader.readWithSize(Types.int16, 2) f3 = reader.read(Types.int64) return dict(F1=f1, F2=f2, F3=f3) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = reader.read(Types.int8) a2 = reader.read(Types.int64) a3 = readB(reader) return dict(A1=a1, A2=a2, A3=a3)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (temp, iterator) = getNext(data, iterator, 2, 'HI', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{f1[0]}B', data[f1[1]:f1[1] + f1[0]])) d2 = list(struct.unpack('>3i', data[pointer + 6:pointer + 18])) d3 = list(struct.unpack('>2d', data[pointer + 18:pointer + 34])) (d4, d5, d6) = struct.unpack('>IIh', data[pointer + 34:pointer + 44]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): c1 = struct.unpack('>i', data[pointer:pointer + 4])[0] c2 = parse_d(data, pointer + 4) return {'C1': c1, 'C2': c2} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>bbb', data[pointer:pointer + 3]) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): a1 = ''.join(map(str, struct.unpack('>4c', data[pointer:pointer + 4]))) a1 = a1.replace(""'"", '')[1::2] a2 = list() for i in range(4): a2.append(parse_b(data, pointer + 4 + i * 3)) a3 = parse_c(data, pointer + 16) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 4)" "import struct def main(data): A = struct.unpack_from('>d3Hqf2hBhI2HIQ', data, offset=4) D = [[], []] D[0] = struct.unpack_from('>HIdh', data, offset=A[1]) D[1] = struct.unpack_from('>HIdh', data, offset=A[2]) D1 = [[], []] D1[0] = list(struct.unpack_from('>' + str(D[0][0]) + 'b', data, offset=D[0][1])) D1[1] = list(struct.unpack_from('>' + str(D[1][0]) + 'b', data, offset=D[1][1])) E2 = list(struct.unpack_from('>' + str(A[12]) + 'd', data, offset=A[13])) return {'A1': A[0], 'A2': {'B1': {'C1': [{'D1': D1[0], 'D2': D[0][2], 'D3': D[0][3]}, {'D1': D1[1], 'D2': D[1][2], 'D3': D[1][3]}], 'C2': A[3], 'C3': A[4], 'C4': A[5], 'C5': [A[6], A[7]]}, 'B2': A[8]}, 'A3': A[9], 'A4': A[10], 'A5': {'E1': A[11], 'E2': E2, 'E3': A[14]}}" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint32) tempB1 = reader.copy(adress2).readWithSize(Types.char, size2) b1 = b''.join(tempB1).decode('ASCII') b2 = reader.read(Types.uint64) return dict(B1=b1, B2=b2) def readC(reader): c1 = reader.read(Types.int16) c2 = reader.read(Types.int8) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.int64) d2 = reader.read(Types.uint64) d3 = reader.read(Types.float) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint32) d4 = reader.copy(offset=adress3).readWithSize(Types.uint64, size3) d5 = reader.read(Types.float) d6 = reader.read(Types.int16) size4 = reader.read(Types.uint16) adress4 = reader.read(Types.uint32) d7 = reader.copy(offset=adress4).readWithSize(Types.uint8, size4) d8 = reader.read(Types.uint64) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = reader.read(Types.uint64) a2 = readB(reader.copy(offset=reader.read(Types.uint16))) a3 = reader.read(Types.uint32) size8 = reader.read(Types.uint32) adress8 = reader.read(Types.uint32) a4 = [] adressReader = BinaryReader(offset=adress8, buffer=buffer) for i in range(0, size8): a4.append(readC(BinaryReader(offset=adressReader.read(Types.uint32), buffer=buffer))) a5 = readD(reader) a6 = reader.read(Types.int16) a7 = reader.read(Types.int8) size5 = reader.read(Types.uint32) adress5 = reader.read(Types.uint32) a8 = reader.copy(offset=adress5).readWithSize(Types.uint32, size5) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8)" "import struct def D(data: bytes, addr: int): (one,) = struct.unpack('>I', data[addr:addr + 4]) addr += 4 (size,) = struct.unpack('>H', data[addr:addr + 2]) addr += 2 (address,) = struct.unpack('>I', data[addr:addr + 4]) addr += 4 two = [] for i in range(size): (buff,) = struct.unpack('>b', data[address:address + 1]) two.append(buff) address += 1 (three,) = struct.unpack('>b', data[addr:addr + 1]) addr += 1 (four,) = struct.unpack('>i', data[addr:addr + 4]) addr += 4 (five,) = struct.unpack('>h', data[addr:addr + 2]) addr += 2 six = [] for i in range(3): (buff,) = struct.unpack('>i', data[addr:addr + 4]) six.append(buff) addr += 4 seven = [] for i in range(8): (buff,) = struct.unpack('>b', data[addr:addr + 1]) seven.append(buff) addr += 1 (eight,) = struct.unpack('>b', data[addr:addr + 1]) return {'D1': one, 'D2': two, 'D3': three, 'D4': four, 'D5': five, 'D6': six, 'D7': seven, 'D8': eight} def C(data: bytes): (one,) = struct.unpack('>d', data[14:22]) two = [] address = 22 for i in range(3): two.append(D(data, address)) address += 38 return {'C1': one, 'C2': two} def B(data: bytes, addr: int): (one,) = struct.unpack('>I', data[addr:addr + 4]) addr += 4 (two,) = struct.unpack('>H', data[addr:addr + 2]) return {'B1': one, 'B2': two} def A(data: bytes): (address,) = struct.unpack('>I', data[4:8]) one = B(data, address) (size,) = struct.unpack('>H', data[8:10]) (address,) = struct.unpack('>I', data[10:14]) two = '' for i in range(size): (buff,) = struct.unpack('>c', data[address:address + 1]) two += chr(buff[0]) address += 1 three = C(data) (four,) = struct.unpack('>I', data[136:140]) return {'A1': one, 'A2': two, 'A3': three, 'A4': four} def main(bytesSequence): return A(bytesSequence)" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('>i', data[pointer:pointer + 4])[0] d2 = list(struct.unpack('>2b', data[pointer + 4:pointer + 6])) d3 = struct.unpack('>d', data[pointer + 6:pointer + 14])[0] return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): c1 = list(struct.unpack('>8b', data[pointer:pointer + 8])) (c2, c3) = struct.unpack('>HB', data[pointer + 8:pointer + 11]) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): b1 = struct.unpack('>d', data[pointer:pointer + 8])[0] f2 = struct.unpack('>HH', data[pointer + 8:pointer + 12]) b2 = list() for i in range(f2[0]): f22 = struct.unpack('>H', data[f2[1] + 2 * i:f2[1] + 2 + 2 * i]) b2.append(parse_c(data, f22[0])) f3 = struct.unpack('>IH', data[pointer + 12:pointer + 18]) b3 = list(struct.unpack(f'>{f3[0]}f', data[f3[1]:f3[1] + f3[0] * 4])) return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = struct.unpack('>B', data[pointer + 18:pointer + 19])[0] f3 = struct.unpack('>I', data[pointer + 19:pointer + 23]) a3 = parse_d(data, f3[0]) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 4)" "import struct import pprint def parse_f(data, pointer): x1 = struct.unpack('>HH', data[pointer:pointer + 4]) f1 = list(struct.unpack(f'>{x1[0]}H', data[x1[1]:x1[1] + x1[0] * 2])) (f2, f3, f4) = struct.unpack('>dBH', data[pointer + 4:pointer + 15]) f5 = list(struct.unpack('>2q', data[pointer + 15:pointer + 31])) f6 = struct.unpack('>h', data[pointer + 31:pointer + 33])[0] f7 = list(struct.unpack('>2Q', data[pointer + 33:pointer + 49])) f8 = struct.unpack('>I', data[pointer + 49:pointer + 53])[0] return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7, 'F8': f8} def parse_e(data, pointer): (e1, e2) = struct.unpack('>fb', data[pointer:pointer + 5]) return {'E1': e1, 'E2': e2} def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>Hfb', data[pointer:pointer + 7]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): c1 = parse_d(data, pointer) (c2, c3, c4) = struct.unpack('>bQH', data[pointer + 7:pointer + 18]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): b1 = struct.unpack('>d', data[pointer:pointer + 8])[0] b2 = parse_c(data, pointer + 8) b3 = struct.unpack('>q', data[pointer + 26:pointer + 34])[0] f4 = struct.unpack('>HH', data[pointer + 34:pointer + 38]) b4 = list() for i in range(f4[0]): f44 = struct.unpack('>I', data[f4[1] + 4 * i:f4[1] + 4 + 4 * i]) b4.append(parse_e(data, f44[0])) f5 = struct.unpack('>H', data[pointer + 38:pointer + 40]) b5 = parse_f(data, f5[0]) b6 = struct.unpack('>f', data[pointer + 40:pointer + 44])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) a1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0]]))) a1 = a1.replace(""'"", '')[1::2] (a2, a3) = struct.unpack('>fd', data[pointer + 6:pointer + 18]) a4 = parse_b(data, pointer + 18) (a5, a6, a7) = struct.unpack('>qBh', data[pointer + 62:pointer + 73]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7} def main(data): return parse_a(data, 3)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): sizeb1 = reader.read(Types.uint32) adressb1 = reader.read(Types.uint32) b1 = [] cReader = BinaryReader(offset=adressb1, buffer=reader.buffer) for i in range(0, sizeb1): b1.append(readC(cReader)) b2 = reader.read(Types.int64) return dict(B1=b1, B2=b2) def readC(reader): c1 = reader.read(Types.uint16) c2 = reader.read(Types.int16) c3 = reader.read(Types.uint64) c4 = reader.read(Types.int32) c5 = reader.read(Types.uint32) c6 = reader.readWithSize(Types.int8, 4) return dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6) def readD(reader): d1 = reader.read(Types.int16) sized2 = reader.read(Types.uint16) adresd2 = reader.read(Types.uint16) d2 = reader.copy(offset=adresd2).readWithSize(Types.int32, sized2) d3 = reader.read(Types.int16) d4 = reader.read(Types.uint8) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def readE(reader): e1 = reader.readWithSize(Types.int8, 4) e2 = reader.read(Types.double) e3 = reader.read(Types.uint32) e4 = reader.read(Types.float) e5 = reader.read(Types.double) e6 = reader.read(Types.int16) e7 = reader.read(Types.double) return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6, E7=e7) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = readB(BinaryReader(offset=reader.read(Types.uint32), buffer=buffer)) sizea2 = reader.read(Types.uint32) adressa2 = reader.read(Types.uint16) tempA2 = reader.copy(adressa2).readWithSize(Types.char, sizea2) a2 = b''.join(tempA2).decode('ASCII') adressa3 = reader.read(Types.uint16) a3 = readD(reader.copy(offset=adressa3)) a4 = reader.read(Types.uint32) adressa5 = reader.read(Types.uint32) a5 = readE(reader.copy(offset=adressa5)) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5)" "import struct def addressB(x, start): return struct.unpack('> I', x[start:start + 4])[0] def addressC(x, start): return struct.unpack('> H', x[start:start + 2])[0] def addressD(x, start): return struct.unpack('> I', x[start:start + 4])[0] def B(x, start): b1 = '' for _ in range(2): val = struct.unpack('> c', x[start + _:start + _ + 1])[0] b1 += val.decode() return {'B1': b1, 'B2': C(x, addressC(x, start + 2)), 'B3': [D(x, addressD(x, start + 4)), D(x, addressD(x, start + 8)), D(x, addressD(x, start + 12)), D(x, addressD(x, start + 16)), D(x, addressD(x, start + 20)), D(x, addressD(x, start + 24)), D(x, addressD(x, start + 28)), D(x, addressD(x, start + 32))]} def C(x, start): return {'C1': struct.unpack('> b', x[start:start + 1])[0], 'C2': struct.unpack('> i', x[start + 1:start + 5])[0], 'C3': struct.unpack('> h', x[start + 5:start + 7])[0], 'C4': struct.unpack('> H', x[start + 7:start + 9])[0], 'C5': struct.unpack('> d', x[start + 9:start + 17])[0]} def D(x, start): return {'D1': struct.unpack('> I', x[start:start + 4])[0], 'D2': struct.unpack('> i', x[start + 4:start + 8])[0], 'D3': struct.unpack('> i', x[start + 8:start + 12])[0], 'D4': struct.unpack('> b', x[start + 12:start + 13])[0], 'D5': struct.unpack('> B', x[start + 13:start + 14])[0]} def E(x, start): return {'E1': struct.unpack('> b', x[start:start + 1])[0], 'E2': [struct.unpack('> h', x[start + 1:start + 3])[0], struct.unpack('> h', x[start + 3:start + 5])[0]], 'E3': struct.unpack('> h', x[start + 5:start + 7])[0], 'E4': struct.unpack('> B', x[start + 7:start + 8])[0], 'E5': struct.unpack('> h', x[start + 8:start + 10])[0]} def A(x, start): return {'A1': B(x, addressB(x, start)), 'A2': struct.unpack('> f', x[start + 4:start + 8])[0], 'A3': [struct.unpack('> b', x[start + 8:start + 9])[0], struct.unpack('> b', x[start + 9:start + 10])[0], struct.unpack('> b', x[start + 10:start + 11])[0], struct.unpack('> b', x[start + 11:start + 12])[0], struct.unpack('> b', x[start + 12:start + 13])[0], struct.unpack('> b', x[start + 13:start + 14])[0], struct.unpack('> b', x[start + 14:start + 15])[0], struct.unpack('> b', x[start + 15:start + 16])[0]], 'A4': struct.unpack('> i', x[start + 16:start + 20])[0], 'A5': struct.unpack('> b', x[start + 20:start + 21])[0], 'A6': E(x, start + 21)} def main(x): return A(x, 4)" "import struct def main(data): A = struct.unpack_from('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'double') (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'uint8') (a6, offs) = parse(buf, offs, 'int16') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int32') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'uint16') (val2, val) = parse_c(buf, val) b2.append(val2) (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_d(buf, b3_offs) return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'int8') (c3, offs) = parse(buf, offs, 'int32') (c4, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse_e(buf, offs) (d2, offs) = parse(buf, offs, 'int8') (d3_offs, offs) = parse(buf, offs, 'uint16') (d3, d3_offs) = parse_f(buf, d3_offs) (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'uint16') (d6_size, offs) = parse(buf, offs, 'uint32') (d6_offs, offs) = parse(buf, offs, 'uint32') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'uint32') d6.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint32') (e2, offs) = parse(buf, offs, 'uint16') e3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') e3.append(val) e4 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int8') e4.append(val) (e5, offs) = parse(buf, offs, 'uint8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def parse_f(buf, offs): (f1, offs) = parse(buf, offs, 'double') (f2, offs) = parse(buf, offs, 'uint8') return (dict(F1=f1, F2=f2), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): unpack_result = unpack_from('>' + FMT[ty], buf, offs) new_offs = offs + calcsize(FMT[ty]) return (unpack_result[0], new_offs) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int16') (a2, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') (a3, _) = parse_b(buf, a3_offs) (a4, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'float') (b3_size, offs) = parse(buf, offs, 'uint16') (b3_offs, offs) = parse(buf, offs, 'uint16') b3 = [] for _ in range(b3_size): (val, b3_offs) = parse(buf, b3_offs, 'char') b3.append(val.decode('ascii')) b3 = ''.join(b3) (b4_size, offs) = parse(buf, offs, 'uint32') (b4_offs, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(b4_size): (c_address, b4_offs) = parse(buf, b4_offs, 'uint32') (c, p) = parse_c(buf, c_address) b4.append(c) b5 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int8') b5.append(val) (b6_size, offs) = parse(buf, offs, 'uint16') (b6_offs, offs) = parse(buf, offs, 'uint32') b6 = [] for _ in range(b6_size): (val, b6_offs) = parse(buf, b6_offs, 'float') b6.append(val) (b7_offs, offs) = parse(buf, offs, 'uint16') (b7, _) = parse_d(buf, b7_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'int64') c3 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'float') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): (*b, A_uint64, A_size_uint32_massive_sctructB, A_address_uint16_massive_structB, A_int32) = struct.unpack_from('>5cQIHi', data) structBcalcSize = struct.calcsize('>H8BBfbdh') massiveStructB = [] for i in range(0, A_size_uint32_massive_sctructB): StructBBuffer = {} (C_adress_uint16_structD, *C_massive_uint8, C_uint8, C_float, C_int8, B_double, B_int16) = struct.unpack_from('>H8BBfbdh', data, A_address_uint16_massive_structB + i * structBcalcSize) (D_uint8, D_int64, D_size_uint16_massive_int8, D_address_uint16_massive_int8, *D_massive_int8, D_float_mass_1, D_float_mass_2, D_float_mass_3) = struct.unpack_from('>BqHH6bfff', data, C_adress_uint16_structD) SctructDBuffer = {} SctructDBuffer['D1'] = D_uint8 SctructDBuffer['D2'] = D_int64 D_massiveStruct = struct.unpack_from('>' + 'b' * D_size_uint16_massive_int8, data, D_address_uint16_massive_int8) SctructDBuffer['D3'] = list(D_massiveStruct) SctructDBuffer['D4'] = list(D_massive_int8) SctructDBuffer['D5'] = [D_float_mass_1, D_float_mass_2, D_float_mass_3] SctructCBuffer = {} SctructCBuffer['C1'] = SctructDBuffer SctructCBuffer['C2'] = list(C_massive_uint8) SctructCBuffer['C3'] = C_uint8 SctructCBuffer['C4'] = C_float SctructCBuffer['C5'] = C_int8 StructBBuffer['B1'] = SctructCBuffer StructBBuffer['B2'] = B_double StructBBuffer['B3'] = B_int16 massiveStructB.append(StructBBuffer) ret = {} ret['A1'] = A_uint64 ret['A2'] = massiveStructB ret['A3'] = A_int32 return ret" "import struct import pprint def parse_d(data, pointer): d1 = list(struct.unpack('>2i', data[pointer:pointer + 8])) (d2, d3, d4) = struct.unpack('>hqf', data[pointer + 8:pointer + 22]) f5 = struct.unpack('>II', data[pointer + 22:pointer + 30]) d5 = list(struct.unpack(f'>{f5[0]}B', data[f5[1]:f5[1] + f5[0]])) (d6, d7, d8) = struct.unpack('>bBB', data[pointer + 30:pointer + 33]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6, 'D7': d7, 'D8': d8} def parse_c(data, pointer): (c1, c2, c3) = struct.unpack('>fiH', data[pointer:pointer + 10]) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): (b1, b2, b3) = struct.unpack('>fbd', data[pointer:pointer + 13]) b4 = list() for i in range(4): b4.append(parse_c(data, pointer + 13 + 10 * i)) b5 = list(struct.unpack('>7f', data[pointer + 53:pointer + 81])) b6 = struct.unpack('>I', data[pointer + 81:pointer + 85])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) a1 = list(struct.unpack(f'>{f1[0]}h', data[f1[1]:f1[1] + f1[0] * 2])) (a2, a3) = struct.unpack('>HH', data[pointer + 8:pointer + 12]) f4 = struct.unpack('>I', data[pointer + 12:pointer + 16]) a4 = parse_b(data, f4[0]) a5 = parse_d(data, pointer + 16) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 3)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') a2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'char') a2.append(val.decode()) (a3, offs) = parse_b(buf, offs) a4 = [] for _ in range(4): (val, offs) = parse_e(buf, offs) a4.append(val) (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint16') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse_c(buf, offs) (b4_offs, offs) = parse(buf, offs, 'uint32') (b4, b4_offs) = parse_d(buf, b4_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint16') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'double') c1.append(val) (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse(buf, offs, 'double') (c4, offs) = parse(buf, offs, 'int16') (c5, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint32') (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') (e2, offs) = parse(buf, offs, 'uint32') e3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') e3.append(val) return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(flot='f', double='d', uint8='B', uint16='H', uint32='I', uint64='Q', int8='b', int16='h', int32='i', int64='q', char='c') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = '' for _ in range(7): (val, offs) = parse(buf, offs, 'char') a1 += val.decode() a2 = [] for _ in range(3): (val, offs) = parse_b(buf, offs) a2.append(val) return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): b1 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint8') b1.append(val) (b2, offs) = parse(buf, offs, 'flot') (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_c(buf, b3_offs) (b4_offs, offs) = parse(buf, offs, 'uint16') (b4, b4_offs) = parse_d(buf, b4_offs) (b5_offs, offs) = parse(buf, offs, 'uint32') (b5, b5_offs) = parse_e(buf, b5_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') (c2, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') (e2, offs) = parse(buf, offs, 'int8') (e3, offs) = parse(buf, offs, 'uint16') (e4_size, offs) = parse(buf, offs, 'uint32') (e4_offs, offs) = parse(buf, offs, 'uint16') e4 = [] for _ in range(e4_size): (val, e4_offs) = parse(buf, e4_offs, 'uint16') e4.append(val) (e5, offs) = parse(buf, offs, 'int8') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def structE(data, pointer): (uint16_e,) = struct.unpack('>H', data[pointer:pointer + 2]) (int8_e,) = struct.unpack('>b', data[pointer + 2:pointer + 3]) f1 = struct.unpack('>HI', data[pointer + 3:pointer + 9]) e1 = list(struct.unpack(f'>{f1[0]}H', data[f1[1]:f1[1] + f1[0] * 2])) f2 = struct.unpack('>IH', data[pointer + 9:pointer + 15]) e2 = list(struct.unpack(f'>{f2[0]}i', data[f2[1]:f2[1] + f2[0] * 4])) return {'E1': uint16_e, 'E2': int8_e, 'E3': e1, 'E4': e2} def structD(data, pointer): (float_d,) = struct.unpack('>f', data[pointer:pointer + 4]) (uint16_d,) = struct.unpack('>H', data[pointer + 4:pointer + 6]) (array_d,) = struct.unpack('>q', data[pointer + 6:pointer + 14]) (array_d_1,) = struct.unpack('>q', data[pointer + 14:pointer + 22]) (array_d_2,) = struct.unpack('>q', data[pointer + 22:pointer + 30]) d = [] d.append(array_d) d.append(array_d_1) d.append(array_d_2) return {'D1': float_d, 'D2': uint16_d, 'D3': d} def structC(data, pointer): strD = structD(data, pointer) strE = structE(data, pointer + 30) (float_c,) = struct.unpack('>f', data[pointer + 45:pointer + 49]) return {'C1': strD, 'C2': strE, 'C3': float_c} def structB(data, pointer): (int64_b,) = struct.unpack('>q', data[pointer:pointer + 8]) (double,) = struct.unpack('>d', data[pointer + 8:pointer + 16]) return {'B1': int64_b, 'B2': double} def structA(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) a1 = [] adr_c = struct.unpack('>I', data[f1[1]:f1[1] + 4]) count = f1[0] for i in range(count): f3 = structB(data, adr_c[0] + i * 16) a1.append(f3) strC = structC(data, pointer + 6) (int32_a,) = struct.unpack('>i', data[pointer + 55:pointer + 59]) f2 = struct.unpack('>II', data[pointer + 59:pointer + 67]) a2 = list(struct.unpack(f'>{f2[0]}b', data[f2[1]:f2[1] + f2[0] * 1])) return {'A1': a1, 'A2': strC, 'A3': int32_a, 'A4': a2} def main(data): return structA(data, 5)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '<' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '<' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.uint32) b2 = reader.read(Types.uint32) b3 = readC(BinaryReader(offset=reader.read(Types.uint32), buffer=reader.buffer)) return dict(B1=b1, B2=b2, B3=b3) def readC(reader): c1 = reader.read(Types.uint32) c2 = reader.read(Types.int16) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.int16) d2 = [] for i in range(0, 2): d2.append(readE(reader)) d3 = reader.read(Types.uint64) d4 = reader.readWithSize(Types.uint8, 3) d5 = reader.read(Types.uint16) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def readE(reader): e1 = reader.readWithSize(Types.int32, 5) e2 = reader.read(Types.double) return dict(E1=e1, E2=e2) def main(buffer): reader = BinaryReader(offset=4, buffer=buffer) a1 = reader.read(Types.int32) a2 = readB(BinaryReader(offset=reader.read(Types.uint16), buffer=reader.buffer)) a3 = reader.read(Types.int8) a4 = readD(reader) a5 = reader.readWithSize(Types.float, 5) a6 = reader.read(Types.uint16) a7 = reader.read(Types.uint64) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'double') (a2, offs) = parse(buf, offs, 'float') (a3, offs) = parse(buf, offs, 'uint32') (a4_size, offs) = parse(buf, offs, 'uint16') (a4_offs, offs) = parse(buf, offs, 'uint32') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse(buf, a4_offs, 'char') a4.append(val.decode()) (a5, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'double') (b2, offs) = parse(buf, offs, 'uint8') (b3_size, offs) = parse(buf, offs, 'uint32') (b3_offs, offs) = parse(buf, offs, 'uint16') b3 = [] for _ in range(b3_size): (val, b3_offs) = parse(buf, b3_offs, 'uint16') val = parse_c(buf, val)[0] b3.append(val) (b4, offs) = parse(buf, offs, 'float') b5 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int16') b5.append(val) (b6, offs) = parse(buf, offs, 'float') (b7_offs, offs) = parse(buf, offs, 'uint16') (b7, offs) = parse_d(buf, b7_offs) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'double') (c2, offs) = parse(buf, offs, 'int32') c3 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int8') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'uint32') (d4_size, offs) = parse(buf, offs, 'uint32') (d4_offs, offs) = parse(buf, offs, 'uint16') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'int8') d4.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = '>' + _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.double) b2 = [] for i in range(0, 2): b2.append(readC(reader)) b3 = reader.read(Types.int32) b4 = readD(reader) return dict(B1=b1, B2=b2, B3=b3, B4=b4) def readC(reader): c1 = reader.read(Types.uint32) c2 = reader.read(Types.uint16) sizec3 = reader.read(Types.uint32) adressc3 = reader.read(Types.uint16) c3 = reader.copy(offset=adressc3).readWithSize(Types.float, sizec3) return dict(C1=c1, C2=c2, C3=c3) def readD(reader): d1 = reader.read(Types.int32) d2 = reader.read(Types.uint8) d3 = reader.read(Types.int64) d4 = reader.read(Types.int8) d5 = reader.read(Types.double) d6 = reader.read(Types.float) d7 = reader.read(Types.int64) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) sizea1 = reader.read(Types.uint16) adressa1 = reader.read(Types.uint16) a11 = reader.copy(offset=adressa1).readWithSize(Types.char, sizea1) a1 = b''.join(a11).decode('ASCII') a2 = readB(reader.copy(reader.read(Types.uint16))) a3 = reader.readWithSize(Types.int8, 8) a4 = reader.read(Types.uint64) a5 = reader.read(Types.uint16) a6 = reader.read(Types.int64) a7 = reader.read(Types.uint16) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7)" "from struct import * class A: def __init__(self, address): self.address = address self.f = '' self.b_obj = None self.par_1 = 0 def set(self, inp): s = self.address self.b_obj = B(s) self.b_obj.set(inp) self.address += calcsize('>bIBdB3d') self.f = '>I' s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] def __dict__(self): return {'A1': self.b_obj.__dict__(), 'A2': self.par_1} class B: def __init__(self, address): self.address = address self.f = '>bIBdB3d' self.par_1 = 0 self.c_obj = 0 self.par_3 = 0 self.par_4 = 0.0 self.par_5 = 0 self.double = [] def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] self.c_obj = C(tmp[1]) self.c_obj.set(inp) self.par_3 = tmp[2] self.par_4 = tmp[3] self.par_5 = tmp[4] double1 = tmp[5] self.double.append(double1) double2 = tmp[6] self.double.append(double2) double3 = tmp[7] self.double.append(double3) def __dict__(self): return {'B1': self.par_1, 'B2': self.c_obj.__dict__(), 'B3': self.par_3, 'B4': self.par_4, 'B5': self.par_5, 'B6': self.double} class C: def __init__(self, address): self.address = address self.f = '>q' self.par_1 = 0 self.d_obj = [] self.par_3 = 0 self.par_4 = 0.0 self.par_5 = 0.0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_1 = tmp[0] d1 = D(s) self.d_obj.append(d1) d1.set(inp) self.address = s + calcsize('>iHhfIH') d2 = D(self.address) self.d_obj.append(d2) d2.set(inp) self.address += calcsize('>iHhfIH') d3 = D(self.address) self.d_obj.append(d3) d3.set(inp) self.address += calcsize('>iHhfIH') self.f = '>H2If' s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.par_3 = tmp[0] self.par_4 = get_list(inp, tmp[1], tmp[2], 'double') self.par_5 = tmp[3] def __dict__(self): return {'C1': self.par_1, 'C2': [x.__dict__() for x in self.d_obj], 'C3': self.par_3, 'C4': self.par_4, 'C5': self.par_5} class D: def __init__(self, address): self.address = address self.f = '>iHhfIH' self.D1 = 0 self.D2 = 0 self.D3 = 0 self.D4 = 0.0 self.D5 = 0 def set(self, inp): s = self.address + calcsize(self.f) tmp = unpack(self.f, inp[self.address:s]) self.D1 = tmp[0] self.D2 = tmp[1] self.D3 = tmp[2] self.D4 = tmp[3] self.D5 = get_list(inp, tmp[4], tmp[5], 'int16') def __dict__(self): return {'D1': self.D1, 'D2': self.D2, 'D3': self.D3, 'D4': self.D4, 'D5': self.D5} def get_list(inp, size, address, t): type_names = {'int8': 'b', 'uint8': 'B', 'int16': 'h', 'uint16': 'H', 'int32': 'i', 'uint32': 'I', 'int64': 'q', 'uint64': 'Q', 'float': 'f', 'double': 'd', 'char': 's'} mask = '>%d%s' % (size, type_names[t]) s = address + calcsize(mask) return list(unpack(mask, inp[address:s])) def main(inp: bin): a = A(4) a.set(inp) return a.__dict__()" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'float') (a3_offs, offs) = parse(buf, offs, 'uint16') (a3, a3_offs) = parse_d(buf, a3_offs) (a4, offs) = parse(buf, offs, 'uint16') (a5, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int16') (b2, offs) = parse(buf, offs, 'int64') b3 = [] for _ in range(2): (val, offs) = parse_c(buf, offs) b3.append(val) (b4, offs) = parse(buf, offs, 'int16') b5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'double') b5.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') c2 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'int32') c2.append(val) (c3, offs) = parse(buf, offs, 'uint16') (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint32') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse(buf, c4_offs, 'uint16') c4.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint32') (d3, pffs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'float') (a2, offs) = parse(buf, offs, 'uint32') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'uint32') (val_b, _) = parse_b(buf, val) a3.append(val_b) (a4, offs) = parse_c(buf, offs) (a5_offs, offs) = parse(buf, offs, 'uint32') (a5, _) = parse_d(buf, a5_offs) (a6, offs) = parse(buf, offs, 'uint32') (a7, offs) = parse_e(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') b2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'char') b2.append(val.decode()) (b3, offs) = parse(buf, offs, 'uint8') (b4, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=''.join(b2), B3=b3, B4=b4), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') c2 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int32') c2.append(val) (c3_size, offs) = parse(buf, offs, 'uint32') (c3_offs, offs) = parse(buf, offs, 'uint32') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'int32') c3.append(val) (c4, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'int8') (d3, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'double') (e2, offs) = parse(buf, offs, 'double') (e3_size, offs) = parse(buf, offs, 'uint32') (e3_offs, offs) = parse(buf, offs, 'uint32') e3 = [] for _ in range(e3_size): (val, e3_offs) = parse(buf, e3_offs, 'int16') e3.append(val) return (dict(E1=e1, E2=e2, E3=e3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import pprint def parse_d(data, pointer): (d1, d2) = struct.unpack('>db', data[pointer:pointer + 9]) f3 = struct.unpack('>HH', data[pointer + 9:pointer + 13]) d3 = list(struct.unpack(f'>{f3[0]}h', data[f3[1]:f3[1] + f3[0] * 2])) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>dhdd', data[pointer:pointer + 26]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) b1 = ''.join(map(str, struct.unpack(f'>{f1[0]}c', data[f1[1]:f1[1] + f1[0]]))) b1 = b1.replace(""'"", '')[1::2] b2 = struct.unpack('>q', data[pointer + 8:pointer + 16])[0] b3 = parse_c(data, pointer + 16) b4 = struct.unpack('>h', data[pointer + 42:pointer + 44])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4} def parse_a(data, pointer): f1 = struct.unpack('>HI', data[pointer:pointer + 6]) a1 = list() for i in range(f1[0]): f11 = struct.unpack('>I', data[f1[1] + 4 * i:f1[1] + 4 + 4 * i]) a1.append(parse_b(data, f11[0])) a2 = struct.unpack('>b', data[pointer + 6:pointer + 7])[0] a3 = parse_d(data, pointer + 7) (a4, a5, a6) = struct.unpack('>hhi', data[pointer + 20:pointer + 28]) f7 = struct.unpack('>HI', data[pointer + 28:pointer + 34]) a7 = list(struct.unpack(f'>{f7[0]}h', data[f7[1]:f7[1] + f7[0] * 2])) a8 = struct.unpack('>Q', data[pointer + 34:pointer + 42])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 4)" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = 'Q' int64 = 'q' uint32 = 'I' int32 = 'i' uint16 = 'H' int16 = 'h' uint8 = 'B' int8 = 'b' float = 'f' char = 'c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from('>' + pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.uint16), E2=reader.read(Primitive.int8), E3=reader.read(Primitive.uint32), E4=reader.read(Primitive.int8)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.int8), D2=reader.read(Primitive.int32)) def read_c(reader: BinaryReader): return dict(C1=[reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8)], C2=reader.read(Primitive.uint32)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int32), B2=reader.read(Primitive.uint32), B3=[reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8), reader.read(Primitive.int8)], B4=[reader.read(Primitive.uint8), reader.read(Primitive.uint8), reader.read(Primitive.uint8), reader.read(Primitive.uint8), reader.read(Primitive.uint8), reader.read(Primitive.uint8), reader.read(Primitive.uint8)], B5=read_e(reader), B6=reader.read(Primitive.int8)) def read_a(reader: BinaryReader): a = {} b1 = {} b2 = {} a['A1'] = reader.read(Primitive.int8) a['A2'] = reader.read(Primitive.int64) a['A3'] = reader.read(Primitive.float) a['A4'] = reader.read(Primitive.uint16) a['A5'] = reader.read(Primitive.uint64) a['A6'] = reader.read(Primitive.uint16) a['A7'] = [read_b(reader), read_b(reader)] c12 = read_d(reader) c11 = read_c(reader) c22 = read_d(reader) c21 = read_c(reader) c11.update(C2=c12) c21.update(C2=c22) a['A7'][0].update(B2=c11) a['A7'][1].update(B2=c21) return a def main(source): return read_a(BinaryReader(source, offset=3))" "import struct import pprint def parse_e(data, pointer): (e1, e2) = struct.unpack('H') (A['A2'], iterator) = getNext(data, iterator, 4, '>i') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A3'] = getNext(data, temp, length, f'>{length}s')[0] A['A3'] = A['A3'].decode('ascii') (A['A4'], iterator) = getB(data, iterator) A['A5'] = [] for i in range(3): (a, iterator) = getNext(data, iterator, 2, '>H') b = getD(data, a)[0] A['A5'].append(b) return A def getB(data, iterator): B = {} (temp, iterator) = getNext(data, iterator, 4, '>I') B['B1'] = getC(data, temp)[0] (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') B['B2'] = getNext(data, temp, length, f'>{length}s')[0] B['B2'] = B['B2'].decode('ascii') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 2, '>h') (C['C2'], iterator) = getNext(data, iterator, 1, '>b') (C['C3'], iterator) = getNext(data, iterator, 2, '>H') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 2, '>h') (D['D2'], iterator) = getNext(data, iterator, 1, '>b') (D['D3'], iterator) = getNext(data, iterator, 4, '>i') (D['D4'], iterator) = getNext(data, iterator, 8, '>d') (D['D5'], iterator) = getNextArr(data, iterator, 2 * 3, '>3H') return (D, iterator) def main(data): return getA(data, 5)" "import struct def main(binary: bytes) -> dict: def struct_a(shift: int) -> dict: (size, shift1) = struct.unpack('< H I', binary[shift:shift + 6]) a1 = [struct_b(shift1 + i * 15) for i in range(size)] shift += 6 a2 = struct_c(shift) shift += 10 [a3] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 return {'A1': a1, 'A2': a2, 'A3': struct_f(a3)} def struct_b(shift: int) -> dict: [b1] = struct.unpack('< B', binary[shift:shift + 1]) shift += 1 b2 = ''.join([chr(i) for i in binary[shift:shift + 6]]) shift += 6 [b3] = struct.unpack('< Q', binary[shift:shift + 8]) shift += 8 return {'B1': b1, 'B2': b2, 'B3': b3} def struct_c(shift: int) -> dict: [c1] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 [c2] = struct.unpack('< H', binary[shift:shift + 2]) shift += 2 [c3] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 return {'C1': struct_d(c1), 'C2': c2, 'C3': struct_e(c3)} def struct_d(shift: int) -> dict: [d1] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 [d2] = struct.unpack('< q', binary[shift:shift + 8]) shift += 8 return {'D1': d1, 'D2': d2} def struct_e(shift: int) -> dict: e1 = list(struct.unpack('< 4I', binary[shift:shift + 16])) shift += 16 [e2] = struct.unpack('< f', binary[shift:shift + 4]) shift += 4 e3 = list(struct.unpack('< 2q', binary[shift:shift + 16])) shift += 16 [e4, e5] = struct.unpack('< i q', binary[shift:shift + 12]) shift += 12 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def struct_f(shift: int) -> dict: [f1, f2, f3] = struct.unpack('< B H H', binary[shift:shift + 5]) shift += 5 return {'F1': f1, 'F2': f2, 'F3': f3} return struct_a(4)" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint64', data, ofs) (E2, ofs) = parse('int64', data, ofs) return (dict(E1=E1, E2=E2), ofs) def struct_D(data, ofs): D1 = [] (D1_size, ofs) = parse('uint16', data, ofs) (D1_adr, ofs) = parse('uint16', data, ofs) for i in range(D1_size): (elem, D1_adr) = parse('uint8', data, D1_adr) D1.append(elem) (D2, ofs) = parse('uint64', data, ofs) D3 = [] for i in range(6): (elem, ofs) = parse('float', data, ofs) D3.append(elem) (D4, ofs) = parse('uint8', data, ofs) (D5, ofs) = parse('int32', data, ofs) D6 = [] for i in range(6): (elem, ofs) = parse('int32', data, ofs) D6.append(elem) (D7, ofs) = parse('uint32', data, ofs) (D8, ofs) = parse('uint32', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6, D7=D7, D8=D8), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) (C2, ofs) = parse('uint8', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint32', data, ofs) B2 = [] for i in range(5): (C_adr, ofs) = parse('uint16', data, ofs) (elem, lop) = struct_C(data, C_adr) B2.append(elem) (B3, ofs) = parse('int64', data, ofs) (B4_adr, ofs) = parse('uint32', data, ofs) (B4, elem) = struct_D(data, B4_adr) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = parse('uint64', data, ofs) A2 = '' (A2_size, ofs) = parse('uint16', data, ofs) (A2_adr, ofs) = parse('uint32', data, ofs) for i in range(A2_size): (elem, A2_adr) = parse('char', data, A2_adr) A2 += elem.decode() (A3_adr, ofs) = parse('uint32', data, ofs) (A3, elem) = struct_B(data, A3_adr) (A4, ofs) = parse('float', data, ofs) (A5, ofs) = parse('uint32', data, ofs) (A6, ofs) = parse('uint16', data, ofs) (A7_adr, ofs) = parse('uint16', data, ofs) (A7, elem) = struct_E(data, A7_adr) (A8, ofs) = parse('double', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6, A7=A7, A8=A8), ofs) def main(data): return struct_A(data, 5)[0]" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack(' H B h 6c II d HH d h I II f f') C = struct.Struct('> q d IH') a = A.unpack_from(bs, len(magic_bytes)) c_addresses = struct.unpack_from(f'> {a[9]}I', bs, a[10]) c_structs = [C.unpack_from(bs, adr) for adr in c_addresses] return {'A1': a[0], 'A2': a[1], 'A3': {'B1': a[2], 'B2': b''.join(a[3:9]).decode(), 'B3': [{'C1': c[0], 'C2': c[1], 'C3': list(struct.unpack_from(f'> {c[2]}h', bs, c[3]))} for c in c_structs], 'B4': a[11], 'B5': list(struct.unpack_from(f'> {a[12]}b', bs, a[13])), 'B6': a[14], 'B7': {'D1': a[15], 'D2': a[16], 'D3': list(struct.unpack_from(f'> {a[17]}h', bs, a[18]))}, 'B8': a[19]}, 'A4': a[-1]}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('int8', data, ofs) (D2, ofs) = parse('uint8', data, ofs) (D3, ofs) = parse('int64', data, ofs) D4 = [] (D4_size, ofs) = parse('uint16', data, ofs) (D4_adr, ofs) = parse('uint32', data, ofs) for i in range(D4_size): (elem, D4_adr) = parse('uint64', data, D4_adr) D4.append(elem) D5 = [] for i in range(6): (elem, ofs) = parse('int8', data, ofs) D5.append(elem) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint8', data, ofs) (C2, ofs) = struct_D(data, ofs) (C3, ofs) = parse('int8', data, ofs) (C4, ofs) = parse('int32', data, ofs) (C5, ofs) = parse('uint64', data, ofs) (C6, ofs) = parse('int16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6), ofs) def struct_B(data, ofs): (B1, ofs) = parse('uint64', data, ofs) (B2, ofs) = parse('uint8', data, ofs) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): A1 = [] for i in range(7): (elem, ofs) = parse('uint8', data, ofs) A1.append(elem) (A2, ofs) = parse('int8', data, ofs) A3 = [] for i in range(8): (B_adr, ofs) = parse('uint32', data, ofs) (elem, lop) = struct_B(data, B_adr) A3.append(elem) (A4_adr, ofs) = parse('uint32', data, ofs) (A4, elem) = struct_C(data, A4_adr) (A5, ofs) = parse('int16', data, ofs) (A6, ofs) = parse('int8', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 4)[0]" "import struct def main(binary: bytes) -> dict: def struct_a(shift: int) -> dict: a1 = ''.join([chr(i) for i in binary[shift:shift + 7]]) shift += 7 [a2, a3, a4] = struct.unpack('< f Q h', binary[shift:shift + 14]) shift += 14 [length] = struct.unpack('< H', binary[shift:shift + 2]) shift += 2 [link_list] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 list_links = [struct.unpack('< I', binary[link_list + i * 4:link_list + (i + 1) * 4])[0] for i in range(length)] a5 = [struct_b(list_links[i]) for i in range(length)] [a6] = struct.unpack('< I', binary[shift:shift + 4]) shift += 4 a7 = list(struct.unpack('< 7B', binary[shift:shift + 7])) shift += 7 [a8] = struct.unpack('< i', binary[shift:shift + 4]) shift += 4 return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': struct_c(a6), 'A7': a7, 'A8': a8} def struct_b(shift: int) -> dict: [b1, b2, b3, b4, b5, b6, b7, b8] = struct.unpack('< h b q f Q q Q b', binary[shift:shift + 40]) shift += 40 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6, 'B7': b7, 'B8': b8} def struct_c(shift: int) -> dict: c1 = struct_d(shift) shift += 9 [c2, c3] = struct.unpack('< h I', binary[shift:shift + 6]) shift += 6 return {'C1': c1, 'C2': c2, 'C3': c3} def struct_d(shift: int) -> dict: [d1] = struct.unpack('< B', binary[shift:shift + 1]) shift += 1 [d2] = struct.unpack('< H', binary[shift:shift + 2]) shift += 2 (razmer, address) = struct.unpack('< I H', binary[shift:shift + 6]) d3 = list(struct.unpack('<' + str(razmer) + 'd', binary[address:address + 8 * razmer])) shift += 6 return {'D1': d1, 'D2': d2, 'D3': d3} return struct_a(4)" "import struct def main(input): s = 4 a1 = '' for i in list('cccccc'): a1 += input[s:s + struct.calcsize(i)][::-1].decode() s += struct.calcsize(i) a2 = struct.unpack('I', input[s:s + struct.calcsize('I')][::-1])[0] s += struct.calcsize('I') a3 = struct.unpack('i', input[s:s + struct.calcsize('i')][::-1])[0] new_s = a2 xui = input[new_s:new_s + struct.calcsize('I')] b1_size = struct.unpack('I', xui[::-1])[0] new_s += struct.calcsize('I') xui = input[new_s:new_s + struct.calcsize('I')] b1_add = struct.unpack('I', xui[::-1])[0] new_s += struct.calcsize('I') b1 = [] for i in range(b1_size): xui = input[b1_add:b1_add + struct.calcsize('H')] c1_temp = struct.unpack('H', xui[::-1])[0] b1_add += struct.calcsize('H') xui = input[b1_add:b1_add + struct.calcsize('B')] c2_temp = struct.unpack('B', xui[::-1])[0] b1_add += struct.calcsize('B') b1.append({'C1': c1_temp, 'C2': c2_temp}) xui = input[new_s:new_s + struct.calcsize('H')] b2 = struct.unpack('H', xui[::-1])[0] new_s += struct.calcsize('H') xui = input[new_s:new_s + struct.calcsize('q')] d1 = struct.unpack('q', xui[::-1])[0] new_s += struct.calcsize('q') xui = input[new_s:new_s + struct.calcsize('H')] d2_size = struct.unpack('H', xui[::-1])[0] new_s += struct.calcsize('H') xui = input[new_s:new_s + struct.calcsize('I')] d2_add = struct.unpack('I', xui[::-1])[0] d2 = [] for i in range(d2_size): xui = input[d2_add:d2_add + struct.calcsize('h')] d2.append(struct.unpack('h', xui[::-1])[0]) d2_add += struct.calcsize('h') new_s += struct.calcsize('I') xui = input[new_s:new_s + struct.calcsize('b')] d3 = struct.unpack('b', xui[::-1])[0] new_s += struct.calcsize('b') xui = input[new_s:new_s + struct.calcsize('d')] d4 = struct.unpack('d', xui[::-1])[0] new_s += struct.calcsize('d') xui = input[new_s:new_s + struct.calcsize('I')] b4_size = struct.unpack('I', xui[::-1])[0] new_s += struct.calcsize('I') xui = input[new_s:new_s + struct.calcsize('I')] b4_add = struct.unpack('I', xui[::-1])[0] b4 = [] for i in range(b4_size): xui = input[b4_add:b4_add + struct.calcsize('h')] b4.append(struct.unpack('h', xui[::-1])[0]) b4_add += struct.calcsize('h') new_s += struct.calcsize('I') xui = input[new_s:new_s + struct.calcsize('q')] b5 = struct.unpack('q', xui[::-1])[0] new_s += struct.calcsize('q') xui = input[new_s:new_s + struct.calcsize('Q')] b6 = struct.unpack('Q', xui[::-1])[0] new_s += struct.calcsize('Q') return {'A1': a1, 'A2': {'B1': b1, 'B2': b2, 'B3': {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4}, 'B4': b4, 'B5': b5, 'B6': b6}, 'A3': a3}" "import struct def main(binary: bytes) -> dict: def struct_a(shift: int) -> dict: [a1] = struct.unpack('> H', binary[shift:shift + 2]) shift += 2 [a2] = struct.unpack('> I', binary[shift:shift + 4]) shift += 4 a3 = struct_c(shift) shift += 70 [a4, a5, a6, a7, a8] = struct.unpack('> h b h f q', binary[shift:shift + 17]) shift += 17 return {'A1': struct_b(a1), 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def struct_b(shift: int) -> dict: [b1, b2] = struct.unpack('> i Q', binary[shift:shift + 12]) shift += 12 return {'B1': b1, 'B2': b2} def struct_c(shift: int) -> dict: [c1] = struct.unpack('> b', binary[shift:shift + 1]) shift += 1 c2 = struct_d(shift) shift += 69 return {'C1': c1, 'C2': c2} def struct_d(shift: int) -> dict: [d1] = struct.unpack('> f', binary[shift:shift + 4]) shift += 4 d2 = list(struct.unpack('> 2I', binary[shift:shift + 8])) shift += 8 d3 = struct_f(shift) shift += 55 [d4] = struct.unpack('> h', binary[shift:shift + 2]) shift += 2 return {'D1': d1, 'D2': [struct_e(i) for i in d2], 'D3': d3, 'D4': d4} def struct_e(shift: int) -> dict: [e1, e2, e3, e4, e5] = struct.unpack('> i h Q b i', binary[shift:shift + 19]) shift += 19 return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5} def struct_f(shift: int) -> dict: (razmer, address) = struct.unpack('> H H', binary[shift:shift + 4]) f1 = list(struct.unpack('>' + str(razmer) + 'H', binary[address:address + 2 * razmer])) shift += 4 [f2, f3] = struct.unpack('> i Q', binary[shift:shift + 12]) shift += 12 f4 = list(struct.unpack('> 5h', binary[shift:shift + 10])) shift += 10 (razmer2, address2) = struct.unpack('> H I', binary[shift:shift + 6]) f5 = list(struct.unpack('>' + str(razmer2) + 'B', binary[address2:address2 + razmer2])) shift += 6 [f6, f7] = struct.unpack('> q Q', binary[shift:shift + 16]) shift += 16 f8 = list(struct.unpack('> 7b', binary[shift:shift + 7])) shift += 7 return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5, 'F6': f6, 'F7': f7, 'F8': f8} return struct_a(5)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.float) b2 = reader.read(Types.float) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint32) b3 = [] cReader = reader.copy(offset=adress3) for i in range(0, size3): b3.append(readC(reader.copy(offset=cReader.read(Types.uint16)))) b4 = readD(reader.copy(offset=reader.read(Types.uint16))) b5 = reader.read(Types.uint32) b6 = reader.read(Types.int64) b7 = reader.read(Types.uint64) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7) def readC(reader): c1 = reader.read(Types.uint16) c2 = reader.read(Types.uint16) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint32) c3 = reader.copy(adress3).readWithSize(Types.int8, size3) return dict(C1=c1, C2=c2, C3=c3) def readD(reader): d1 = reader.read(Types.uint32) d2 = reader.read(Types.float) d3 = reader.read(Types.float) d4 = reader.read(Types.float) d5 = reader.read(Types.uint32) return dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5) def main(buffer): reader = BinaryReader(offset=5, buffer=buffer) a1 = reader.read(Types.int64) a2 = readB(reader) size3 = reader.read(Types.uint32) adress3 = reader.read(Types.uint32) tempA3 = reader.copy(adress3).readWithSize(Types.char, size3) a3 = b''.join(tempA3).decode('ASCII') a4 = reader.read(Types.int16) a5 = reader.readWithSize(Types.float, 6) a6 = reader.readWithSize(Types.uint8, 6) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3, e4) = struct.unpack('I', offs) A2.append(add) (A3, offs) = parse(buf, '>B', offs) return (dict(A1=A1, A2=A2, A3=A3), offs) def parseB(buf, offs): (B1, offs) = parse(buf, '>i', offs) (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>I', offs) B2 = [] for i in range(size): (adress_1, adress) = parse(buf, '>I', adress) add = parseC(buf, adress_1)[0] B2.append(add) B3 = [] (size, offs) = parse(buf, '>H', offs) (adress, offs) = parse(buf, '>H', offs) for i in range(size): (add, adress) = parse(buf, '>b', adress) B3.append(add) (B4, offs) = parse(buf, '>b', offs) (B5, offs) = parse(buf, '>b', offs) (B6, offs) = parse(buf, '>I', offs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5, B6=B6), offs) def parseC(buf, offs): (adress, offs) = parse(buf, '>I', offs) C1 = parseD(buf, adress)[0] (C2, offs) = parse(buf, '>Q', offs) (C3, offs) = parse(buf, '>I', offs) (C4, offs) = parse(buf, '>d', offs) (C5, offs) = parse(buf, '>q', offs) (C6, offs) = parse(buf, '>H', offs) C7 = [] for i in range(2): (add, offs) = parse(buf, '>q', offs) C7.append(add) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7), offs) def parseD(buf, offs): (D1, offs) = parse(buf, '>i', offs) (D2, offs) = parse(buf, '>Q', offs) (D3, offs) = parse(buf, '>q', offs) return (dict(D1=D1, D2=D2, D3=D3), offs) def main(buf): return parseA(buf, 5)[0]" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int64') (e2, offs) = parse(buf, offs, 'int64') return (dict(E1=e1, E2=e2), offs) def parse_d(buf, offs): d1 = [] for _ in range(0, 4): (val, offs) = parse(buf, offs, 'char') d1.append(val.decode()) (d2, offs) = parse(buf, offs, 'uint8') (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'uint32') (d6, offs) = parse_e(buf, offs) (d7_size, offs) = parse(buf, offs, 'uint32') (d7_offs, offs) = parse(buf, offs, 'uint16') d7 = [] for _ in range(d7_size): (val, d7_offs) = parse(buf, d7_offs, 'uint64') d7.append(val) return (dict(D1=''.join(d1), D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint8') (c2, offs) = parse(buf, offs, 'uint32') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') b2 = [] for _ in range(8): (b2_offs, offs) = parse(buf, offs, 'uint16') (val, b2_offs) = parse_c(buf, b2_offs) b2.append(val) return (dict(B1=b1, B2=b2), offs) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (val, a1_offs) = parse_b(buf, a1_offs) a1 = val (a2, offs) = parse(buf, offs, 'uint8') (a3_offs, offs) = parse(buf, offs, 'uint32') (val, a3_offs) = parse_d(buf, a3_offs) a3 = val a4 = [] for _ in range(0, 2): (val, offs) = parse(buf, offs, 'double') a4.append(val) (a5, offs) = parse(buf, offs, 'int16') (a6, offs) = parse(buf, offs, 'int32') (a7, offs) = parse(buf, offs, 'float') (a8, offs) = parse(buf, offs, 'int64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint32') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'uint64') a3 = [] for _ in range(7): (val, offs) = parse(buf, offs, 'uint16') a3.append(val) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) b2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint64') b2.append(val) (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): c1 = [] for _ in range(2): (c1_offs, offs) = parse(buf, offs, 'uint16') (val, c1_offs) = parse_d(buf, c1_offs) c1.append(val) (c2, offs) = parse(buf, offs, 'uint64') (c3, offs) = parse(buf, offs, 'float') (c4, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') d2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int16') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 3)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('uint64', data, ofs) (E2, ofs) = parse('uint16', data, ofs) (E3, ofs) = parse('uint16', data, ofs) (E4, ofs) = parse('int8', data, ofs) E5 = [] (E5_size, ofs) = parse('uint16', data, ofs) (E5_adr, ofs) = parse('uint32', data, ofs) for i in range(E5_size): (elem, E5_adr) = parse('int8', data, E5_adr) E5.append(elem) (E6, ofs) = parse('uint64', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6), ofs) def struct_D(data, ofs): (D1, ofs) = parse('int64', data, ofs) D2 = [] for i in range(4): (elem, ofs) = parse('int8', data, ofs) D2.append(elem) return (dict(D1=D1, D2=D2), ofs) def struct_C(data, ofs): (C1, ofs) = struct_D(data, ofs) (C2, ofs) = parse('int8', data, ofs) (C3, ofs) = parse('uint16', data, ofs) return (dict(C1=C1, C2=C2, C3=C3), ofs) def struct_B(data, ofs): B1 = [] for i in range(3): (elem, ofs) = struct_C(data, ofs) B1.append(elem) (B2, ofs) = parse('int8', data, ofs) (B3, ofs) = parse('float', data, ofs) B4 = [] for i in range(4): (elem, ofs) = parse('uint16', data, ofs) B4.append(elem) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int16', data, ofs) (A2, ofs) = parse('uint32', data, ofs) (A3, ofs) = struct_B(data, ofs) (A4_adr, ofs) = parse('uint16', data, ofs) (A4, elem) = struct_E(data, A4_adr) (A5, ofs) = parse('uint64', data, ofs) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5), ofs) def main(data): return struct_A(data, 4)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) a1 = ''.join(a1) (a2, offs) = parse_b(buf, offs) (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse_d(buf, a3_offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint16') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'int8') b2.append(val) return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'uint8') d1.append(val) (d2_size, offs) = parse(buf, offs, 'uint32') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'int64') d2.append(val) return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def int8p1(x, pos): return struct.unpack('> b', x[pos:pos + 1])[0] def uint8p1(x, pos): return struct.unpack('> B', x[pos:pos + 1])[0] def int16p2(x, pos): return struct.unpack('> h', x[pos:pos + 2])[0] def uint16p2(x, pos): return struct.unpack('> H', x[pos:pos + 2])[0] def uint32p4(x, pos): return struct.unpack('> I', x[pos:pos + 4])[0] def int32p4(x, pos): return struct.unpack('> i', x[pos:pos + 4])[0] def int64p8(x, pos): return struct.unpack('> q', x[pos:pos + 8])[0] def uint64p8(x, pos): return struct.unpack('> Q', x[pos:pos + 8])[0] def float4p4(x, pos): return struct.unpack('> f', x[pos:pos + 4])[0] def double8p8(x, pos): return struct.unpack('> d', x[pos:pos + 8])[0] def char1p1(x, pos): return str(x[pos:pos + 1])[2:-1] def uint32uint16int32(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'i' * size, x[add:add + 4 * size]) return list(a) def uint32uint16uint64(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'Q' * size, x[add:add + 8 * size]) return list(a) def uint16uint16int8(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'b' * size, x[add:add + 1 * size]) return list(a) def uint16uint16uint8p4(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'B' * size, x[add:add + 1 * size]) return list(a) def uint32uint32int16p8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'h' * size, x[add:add + 2 * size]) return list(a) def uint32uint32uint16p8(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> I', x[start + 4:start + 8])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint32int16p6(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> I', x[start + 2:start + 6])[0] a = struct.unpack('> ' + 'H' * size, x[add:add + 2 * size]) return list(a) def uint16uint16int64(x, start): size = struct.unpack('> H', x[start:start + 2])[0] add = struct.unpack('> H', x[start + 2:start + 4])[0] a = struct.unpack('> ' + 'q' * size, x[add:add + 8 * size]) return list(a) def uint32uint16double8p6(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] a = struct.unpack('> ' + 'd' * size, x[add:add + 8 * size]) return list(a) def D(x, pos): return {'D1': uint32p4(x, pos), 'D2': int16p2(x, pos + 4), 'D3': uint32uint16double8p6(x, pos + 6), 'D4': int8p1(x, pos + 12), 'D5': uint64p8(x, pos + 13)} def C(x, pos): return {'C1': uint32p4(x, pos), 'C2': uint8p1(x, pos + 4)} def uint32uint16char1p6(x, start): size = struct.unpack('> I', x[start:start + 4])[0] add = struct.unpack('> H', x[start + 4:start + 6])[0] res = '' for i in range(size): res += char1p1(x, add + i) return res def B(x, pos): return {'B1': uint32uint16char1p6(x, pos), 'B2': uint32p4(x, pos + 6), 'B3': uint32p4(x, pos + 10), 'B4': int16p2(x, pos + 14), 'B5': [C(x, uint32p4(x, pos + 16 + 4 * i)) for i in range(5)], 'B6': float4p4(x, pos + 36), 'B7': D(x, pos + 40), 'B8': int64p8(x, pos + 61)} def A(x, pos): return {'A1': double8p8(x, pos), 'A2': B(x, uint16p2(x, pos + 8)), 'A3': int16p2(x, pos + 10), 'A4': uint64p8(x, pos + 12), 'A5': uint32uint32uint16p8(x, pos + 20), 'A6': int8p1(x, pos + 28)} def main(x): return A(x, 5)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (a1_offs_new, a1_offs) = parse(buf, a1_offs, 'uint32') (val, a1_offs_new) = parse_b(buf, a1_offs_new) a1.append(val) (a2_offs, offs) = parse(buf, offs, 'uint32') (val, a2_offs) = parse_c(buf, a2_offs) a2 = val (a3, offs) = parse(buf, offs, 'uint64') (a4, offs) = parse_d(buf, offs) a5 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'uint16') a5.append(val) (a6, offs) = parse(buf, offs, 'int32') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint32') (b2, offs) = parse(buf, offs, 'double') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'char') d1.append(val.decode()) (d2_size, offs) = parse(buf, offs, 'uint32') (d2_offs, offs) = parse(buf, offs, 'uint32') d2 = [] for _ in range(d2_size): (val, d2_offs) = parse(buf, d2_offs, 'int8') d2.append(val) (d3, offs) = parse_e(buf, offs) (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'int64') return (dict(D1=''.join(d1), D2=d2, D3=d3, D4=d4, D5=d5), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int32') (e2_size, offs) = parse(buf, offs, 'uint16') (e2_offs, offs) = parse(buf, offs, 'uint32') e2 = [] for _ in range(e2_size): (val, e2_offs) = parse(buf, e2_offs, 'uint32') e2.append(val) return (dict(E1=e1, E2=e2), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int32') (a2, offs) = parse_b(buf, offs) (a3, offs) = parse(buf, offs, 'uint8') return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse_c(buf, offs) (b4, offs) = parse(buf, offs, 'double') b5 = [] for i in range(2): (val, offs) = parse_d(buf, offs) b5.append(val) (b6_size, offs) = parse(buf, offs, 'uint32') (b6_offs, offs) = parse(buf, offs, 'uint32') b6 = [] for i in range(b6_size): (val, b6_offs) = parse(buf, b6_offs, 'double') b6.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') c2 = [] for i in range(5): (val, offs) = parse(buf, offs, 'char') c2.append(val.decode()) return (dict(C1=c1, C2=''.join(c2)), offs) def parse_d(buf, offs): d1 = [] for i in range(6): (val, offs) = parse(buf, offs, 'int8') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'int8') return (dict(D1=d1, D2=d2, D3=d3), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 8, 'd', x[src_new:src_new + 8])) c2_tmp = struct.unpack('>II', x[src_new + 8:src_new + 16]) c2 = for_structs(x, c2_tmp[0], c2_tmp[1], '>B', 1) c3 = sum(struct.unpack('>H', x[src_new + 16:src_new + 18])) c4 = sum(struct.unpack('>f', x[src_new + 18:src_new + 22])) c5 = for_structs(x, 6, src_new + 22, '>B', 1) c6 = sum(struct.unpack('>H', x[src_new + 28:src_new + 30])) c_s = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} b2.append(c_s) return b2 def main(x): a1_tmp = sum(struct.unpack('>I', x[5:9])) b1 = sum(struct.unpack('>H', x[a1_tmp:a1_tmp + 2])) b2_tmp = struct.unpack('>HI', x[a1_tmp + 2:a1_tmp + 8]) b2 = c_struct(x, b2_tmp[0], b2_tmp[1]) b3 = sum(struct.unpack('>f', x[a1_tmp + 8:a1_tmp + 12])) a2 = for_structs(x, 3, 9, '>I', 4) d1 = sum(struct.unpack('>H', x[21:23])) d2 = sum(struct.unpack('>q', x[23:31])) d3 = for_structs(x, 7, 31, '>B', 1) d4 = sum(struct.unpack('>d', x[38:46])) d5 = sum(struct.unpack('>Q', x[46:54])) b_s = {'B1': b1, 'B2': b2, 'B3': b3} d_s = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} out = {'A1': b_s, 'A2': a2, 'A3': d_s} return out" "from struct import * FMT = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d', char='c') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int8') (a2, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse(buf, offs, 'float') a4 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'char') a4.append(val.decode()) (a5, offs) = parse(buf, offs, 'int8') (a6, offs) = parse_b(buf, offs) return (dict(A1=a1, A2=a2, A3=a3, A4=''.join(a4), A5=a5, A6=a6), offs) def parse_b(buf, offs): b1 = [] for _ in range(6): (b1_offs, offs) = parse(buf, offs, 'uint32') (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'int8') (b3, offs) = parse(buf, offs, 'uint8') (b4_offs, offs) = parse(buf, offs, 'uint16') (b4, b4_offs) = parse_d(buf, b4_offs) (b5, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1_size, offs) = parse(buf, offs, 'uint16') (c1_offs, offs) = parse(buf, offs, 'uint32') c1 = [] for _ in range(c1_size): (val, c1_offs) = parse(buf, c1_offs, 'uint8') c1.append(val) (c2, offs) = parse(buf, offs, 'uint32') (c3, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'uint8') d3 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int16') d3.append(val) (d4, offs) = parse(buf, offs, 'int8') (d5, offs) = parse(buf, offs, 'int64') (d6, offs) = parse(buf, offs, 'uint16') (d7, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack def parse_arrays(arr, c_str_size): count = 0 parsed = [] for _ in range(0, c_str_size): a = [] for i in range(0, 4): a.append(arr[count + i]) count += 4 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 77: break a = {f'A{i}': None for i in range(1, 9)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 4)} d = {f'D{i}': None for i in range(1, 9)} temp = unpack('>QlqHBBHLL', file[a_adr:a_adr + 34]) (a['A1'], a['A2'], a['A3'], a['A4'], a['A5'], a['A6'], b_adr, int8_size, int8_adr) = temp temp = unpack(f'>{int8_size}B', file[int8_adr:int8_adr + int8_size]) a['A8'] = list(temp) temp = unpack('>LLHL', file[b_adr:b_adr + 14]) (c_str_size, c_str_adr, b['B2'], d_adr) = temp temp = unpack('>bffHLHLBf', file[d_adr:d_adr + 26]) (d['D1'], d['D2'], d['D3'], uint64_size, uint64_adr, d['D5'], d['D6'], d['D7'], d['D8']) = temp temp = unpack(f'>{uint64_size}Q', file[uint64_adr:uint64_adr + uint64_size * 8]) d['D4'] = list(temp) temp = unpack(f"">{c_str_size * 'HLdq'}"", file[c_str_adr:c_str_adr + c_str_size * 22]) c_strs = parse_arrays(temp, c_str_size) b['B1'] = [] for c_str in c_strs: (float_size, float_adr, c['C2'], c['C3']) = c_str temp = unpack(f'>{float_size}f', file[float_adr:float_adr + float_size * 4]) c['C1'] = list(temp) b['B1'].append(c.copy()) b['B3'] = d a['A7'] = b return a" "import struct import pprint def parse_e(data, pointer): (e1, e2, e3, e4, e5, e6) = struct.unpack('>hqHIqq', data[pointer:pointer + 32]) return {'E1': e1, 'E2': e2, 'E3': e3, 'E4': e4, 'E5': e5, 'E6': e6} def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>bQI', data[pointer:pointer + 13]) f4 = struct.unpack('>I', data[pointer + 13:pointer + 17]) d4 = parse_e(data, f4[0]) (d5, d6) = struct.unpack('>bf', data[pointer + 17:pointer + 22]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>fQiB', data[pointer:pointer + 17]) f5 = struct.unpack('>HI', data[pointer + 17:pointer + 23]) c5 = list(struct.unpack(f'>{f5[0]}H', data[f5[1]:f5[1] + f5[0] * 2])) c6 = struct.unpack('>Q', data[pointer + 23:pointer + 31])[0] return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6} def parse_b(data, pointer): f1 = struct.unpack('>2H', data[pointer:pointer + 4]) b1 = list() b1.append(parse_c(data, f1[0])) b1.append(parse_c(data, f1[1])) b2 = struct.unpack('>H', data[pointer + 4:pointer + 6])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = parse_b(data, pointer) f2 = struct.unpack('>H', data[pointer + 6:pointer + 8]) a2 = parse_d(data, f2[0]) a3 = ''.join(map(str, struct.unpack('>5c', data[pointer + 8:pointer + 13]))) a3 = a3.replace(""'"", '')[1::2] a4 = list(struct.unpack('>5h', data[pointer + 13:pointer + 23])) a5 = struct.unpack('>h', data[pointer + 23:pointer + 25])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 5)" "from enum import Enum from struct import unpack_from, calcsize class Types(Enum): float = 'f' double = 'd' uint8 = 'B' uint16 = 'H' uint32 = 'I' uint64 = 'Q' int8 = 'b' int16 = 'h' int32 = 'i' int64 = 'q' char = 'c' class BinaryReader: def __init__(self, offset, buffer): self.offset = offset self.buffer = buffer def read(self, _pattern): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) return result[0] def readWithSize(self, _pattern, size): res = [] for i in range(0, size): pattern = _pattern.value result = unpack_from(pattern, self.buffer, self.offset) self.offset += calcsize(pattern) res.append(result[0]) return res def copy(self, offset): return BinaryReader(offset, self.buffer) def readB(reader): b1 = reader.read(Types.int16) b2 = reader.read(Types.float) b3 = reader.read(Types.int16) b4 = reader.read(Types.int8) b5 = reader.read(Types.int16) return dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5) def readC(reader): c1 = reader.read(Types.uint64) c2 = readD(reader.copy(reader.read(Types.uint16))) return dict(C1=c1, C2=c2) def readD(reader): d1 = reader.read(Types.uint32) size2 = reader.read(Types.uint32) adress2 = reader.read(Types.uint16) d2 = reader.copy(offset=adress2).readWithSize(Types.uint8, size2) d3 = reader.read(Types.float) d4 = reader.read(Types.uint16) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def readE(reader): e1 = reader.read(Types.uint16) e2 = reader.read(Types.int64) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint16) e3 = reader.copy(offset=adress3).readWithSize(Types.uint8, size3) e4 = reader.read(Types.uint8) size5 = reader.read(Types.uint32) adress5 = reader.read(Types.uint32) e5 = reader.copy(offset=adress5).readWithSize(Types.uint16, size5) e6 = reader.read(Types.double) return dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5, E6=e6) def main(buffer): reader = BinaryReader(offset=3, buffer=buffer) a1 = reader.read(Types.float) a2 = [] for _ in range(5): val = readB(reader.copy(reader.read(Types.uint16))) a2.append(val) size3 = reader.read(Types.uint16) adress3 = reader.read(Types.uint16) a3 = [] adressReader = BinaryReader(offset=adress3, buffer=buffer) for _ in range(size3): val = readC(BinaryReader(offset=adressReader.read(Types.uint32), buffer=buffer)) a3.append(val) a4 = reader.read(Types.uint32) a5 = reader.read(Types.int8) a6 = readE(reader) return dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6)" "import struct def main(data): A = struct.unpack_from('QHIH', data.read(struct.calcsize('>QHIH'))) dict1 = {'A1': ans[0], 'A2': ans[1], 'A3': ARR(ans[2], ans[3]), 'A4': B(struct.calcsize('>QHIH'))} data.read(struct.calcsize('>dhHHHHHIHHbQ')) ans = struct.unpack('>bqH', data.read(struct.calcsize('>bqH'))) dict1['A5'] = ans[0] dict1['A6'] = ans[1] dict1['A7'] = ans[2] return dict1 def B(address): data = io.BytesIO(d) data.read(address + 5) res = struct.unpack('>dhHHHHHIHHbQ', data.read(struct.calcsize('>dhHHHHHIHHbQ'))) dict1 = {'B1': res[0], 'B2': res[1]} arr = [C(res[2]), C(res[3]), C(res[4]), C(res[5]), C(res[6])] dict1['B3'] = arr dict1['B4'] = D(res[7]) dict1['B5'] = ARRUINT8(res[8], res[9]) dict1['B6'] = res[10] dict1['B7'] = res[11] return dict1 def ARR(size, address): data = io.BytesIO(d) data.read(address) arr = [] for i in range(size): arr.append(struct.unpack('>c', data.read(struct.calcsize('>c')))[0]) ans = '' for i in arr: ans += str(i, 'UTF-8') return ans def ARRUINT8(size, address): data = io.BytesIO(d) data.read(address) arr = [] for i in range(size): arr.append(struct.unpack('>B', data.read(struct.calcsize('>B')))[0]) return arr def C(address): data = io.BytesIO(d) data.read(address) res = struct.unpack('>Bb', data.read(struct.calcsize('>Bb'))) dict1 = {'C1': res[0], 'C2': res[1]} return dict1 def D(address): data = io.BytesIO(d) data.read(address) res = struct.unpack('>bBHIQqIHfd', data.read(struct.calcsize('>bBHIQqIHfd'))) dict2 = {'D1': res[0], 'D2': res[1], 'D3': ARRUINT8(res[2], res[3]), 'D4': res[4], 'D5': res[5], 'D6': ARRUINT32(res[6], res[7]), 'D7': res[8], 'D8': res[9]} return dict2 def ARRUINT32(size, address): data = io.BytesIO(d) data.read(address) arr = [] for i in range(size): arr.append(struct.unpack('>I', data.read(struct.calcsize('>I')))[0]) return arr return A(dt)" "from struct import unpack def parse_arrays(arr, c_str_size): count = 0 parsed = [] for _ in range(0, c_str_size): a = [] for i in range(0, 5): a.append(arr[count + i]) count += 5 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 81: break a = {f'A{i}': None for i in range(1, 3)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 5)} d = {f'D{i}': None for i in range(1, 5)} temp = unpack('f', x[4:8])[0] a['A2'] = struct.unpack('>I', x[8:12])[0] a['A3'] = struct.unpack('>f', x[12:16])[0] pos1 = struct.unpack('>H', x[16:18])[0] c1 = struct.unpack('>i', x[pos1:pos1 + 4])[0] c2 = struct.unpack('>i', x[pos1 + 4:pos1 + 8])[0] c3 = struct.unpack('>h', x[pos1 + 8:pos1 + 10])[0] c4 = struct.unpack('>q', x[pos1 + 10:pos1 + 18])[0] b1 = {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} d1 = struct.unpack('>b', x[18:19])[0] pos1 = struct.unpack('>I', x[23:27])[0] d2 = [] for i in range(0, struct.unpack('>I', x[19:23])[0]): e1 = struct.unpack('>I', x[pos1:pos1 + 4])[0] e2 = struct.unpack('>q', x[pos1 + 4:pos1 + 12])[0] pos1 += 12 d2.append({'E1': e1, 'E2': e2}) d3 = list(struct.unpack('>6f', x[27:51])) d4 = struct.unpack('>b', x[51:52])[0] d5 = struct.unpack('>I', x[52:56])[0] b2 = {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} b3 = struct.unpack('>H', x[56:58])[0] a['A4'] = {'B1': b1, 'B2': b2, 'B3': b3} a['A5'] = struct.unpack('>q', x[58:66])[0] di = struct.unpack('>H', x[66:68])[0] dis = '>' + str(di) + 's' pos1 = struct.unpack('>I', x[68:72])[0] a['A6'] = str(struct.unpack(dis, x[pos1:pos1 + di])[0])[2:-1] di = struct.unpack('>I', x[72:76])[0] dis = '>' + str(di) + 'b' pos1 = struct.unpack('>H', x[76:78])[0] a['A7'] = list(struct.unpack(dis, x[pos1:pos1 + di])) return a" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint16') a2 = [] for _ in range(5): (a2_offs, offs) = parse(buf, offs, 'uint32') (val, a2_offs) = parse_b(buf, a2_offs) a2.append(val) (a3, offs) = parse(buf, offs, 'int8') (a4, offs) = parse_c(buf, offs) a5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int16') a5.append(val) (a6, offs) = parse(buf, offs, 'float') (a7_offs, offs) = parse(buf, offs, 'uint32') (a7, a7_offs) = parse_d(buf, a7_offs) (a8, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int64') c2 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'char') c2.append(val.decode()) (c3, offs) = parse(buf, offs, 'float') (c4, offs) = parse(buf, offs, 'int8') (c5, offs) = parse(buf, offs, 'int32') (c6, offs) = parse(buf, offs, 'uint64') (c7, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') (d2, offs) = parse(buf, offs, 'int64') (d3_size, offs) = parse(buf, offs, 'uint16') (d3_offs, offs) = parse(buf, offs, 'uint16') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'uint32') d3.append(val) (d4, offs) = parse(buf, offs, 'uint8') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(s): d = {} a1 = {} b1 = {} a2 = {} db4 = [] base_address = 5 new_address_b = struct.unpack_from('>I', s, base_address)[0] base_address += 4 b1.setdefault('C1', struct.unpack_from('>i', s, new_address_b)[0]) new_address_b += 4 temp_s = '' for i in range(3): temp_s += str(struct.unpack_from('>c', s, new_address_b)[0])[2:3] new_address_b += 1 b1.setdefault('C2', temp_s) b1.setdefault('C3', struct.unpack_from('>f', s, new_address_b)[0]) new_address_b += 4 a1.setdefault('B1', b1) a1.setdefault('B2', struct.unpack_from('>Q', s, new_address_b)[0]) new_address_b += 8 a1.setdefault('B3', struct.unpack_from('>Q', s, new_address_b)[0]) new_address_b += 8 new_size = struct.unpack_from('>H', s, new_address_b)[0] new_address_b += 2 new_address_b4 = struct.unpack_from('>I', s, new_address_b)[0] new_address_b += 4 b4 = [] for i in range(new_size): b4.append(struct.unpack_from('>H', s, new_address_b4)[0]) new_address_b4 += 2 for i in range(new_size): d123 = {} d2 = [] d123.setdefault('D1', struct.unpack_from('>q', s, b4[i])[0]) b4[i] += 8 d2.append(struct.unpack_from('>h', s, b4[i])[0]) b4[i] += 2 d2.append(struct.unpack_from('>h', s, b4[i])[0]) b4[i] += 2 d2.append(struct.unpack_from('>h', s, b4[i])[0]) b4[i] += 2 d123.setdefault('D2', d2) d123.setdefault('D3', struct.unpack_from('>i', s, b4[i])[0]) b4[i] += 4 db4.append(d123) a1.setdefault('B4', db4) a1.setdefault('B5', struct.unpack_from('>i', s, new_address_b)[0]) new_address_b += 4 new_size = struct.unpack_from('>H', s, new_address_b)[0] new_address_b += 2 new_address_b6 = struct.unpack_from('>I', s, new_address_b)[0] new_address_b += 4 b6 = [] for i in range(new_size): b6.append(struct.unpack_from('>q', s, new_address_b6)[0]) new_address_b6 += 8 a1.setdefault('B6', b6) a1.setdefault('B7', struct.unpack_from('>Q', s, new_address_b)[0]) new_address_b += 8 d.setdefault('A1', a1) a2.setdefault('E1', struct.unpack_from('>H', s, base_address)[0]) base_address += 2 a2.setdefault('E2', struct.unpack_from('>B', s, base_address)[0]) base_address += 1 a2.setdefault('E3', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 a2.setdefault('E4', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 a2.setdefault('E5', struct.unpack_from('>h', s, base_address)[0]) base_address += 2 d.setdefault('A2', a2) return d" "import struct def main(data): A = struct.unpack_from('c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') a1 = parse_b(buf, a1_offs)[0] s = '' for _ in range(5): (val, offs) = parse(buf, offs, 'char') s += val.decode() a2 = s a3 = [] for _ in range(2): (val, offs) = parse_c(buf, offs) a3.append(val) (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'double') (a6_size, offs) = parse(buf, offs, 'uint32') (a6_offs, offs) = parse(buf, offs, 'uint32') a6 = [] for _ in range(a6_size): (val, a6_offs) = parse(buf, a6_offs, 'double') a6.append(val) return (dict(A1=a1, A2=''.join(a2), A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse(buf, offs, 'float') (b3, offs) = parse(buf, offs, 'int64') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint32') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = parse_d(buf, c2_offs)[0] (c3_size, offs) = parse(buf, offs, 'uint16') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'int32') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): d1 = [] for _ in range(4): (val, offs) = parse(buf, offs, 'int32') d1.append(val) (d2, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'>{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = parse_array(data, offset, 'f', 6) result['D2'] = struct.unpack('>I', data[offset + 24:offset + 24 + 4])[0] result['D3'] = struct.unpack('>H', data[offset + 28:offset + 28 + 2])[0] result['D4'] = struct.unpack('>f', data[offset + 30:offset + 30 + 4])[0] result['D5'] = struct.unpack('>I', data[offset + 34:offset + 34 + 4])[0] return result def parse_c(data, offset): result = dict() result['C1'] = struct.unpack('>f', data[offset:offset + 4])[0] result['C2'] = struct.unpack('>Q', data[offset + 4:offset + 4 + 8])[0] result['C3'] = struct.unpack('>H', data[offset + 12:offset + 12 + 2])[0] result['C4'] = parse_array(data, offset + 14, 'b', 3) return result def parse_b(data, offset): result = dict() result['B1'] = struct.unpack('>H', data[offset:offset + 2])[0] result['B2'] = ''.join([str(c, 'utf-8') for c in parse_array(data, offset + 2, 'c', 5)]) addr = struct.unpack('>i', data[offset + 7:offset + 7 + 4])[0] result['B3'] = parse_c(data, addr) return result def parse_a(data, offset): result = dict() (size, address) = struct.unpack('>II', data[offset:offset + 8]) addresses = parse_array(data, address, 'I', size) result['A1'] = [parse_b(data, addr) for addr in addresses] result['A2'] = parse_d(data, offset + 8) result['A3'] = struct.unpack('>q', data[offset + 46:offset + 46 + 8])[0] result['A4'] = struct.unpack('>i', data[offset + 54:offset + 54 + 4])[0] return result def main(data): return parse_a(data, 4)" "import struct def getNext(data, i, length, type): return (struct.unpack(type, data[i:i + length])[0], i + length) def getNextArr(data, i, length, type): return (list(struct.unpack(type, data[i:i + length])), i + length) def getA(data, iterator): A = {} (A['A1'], iterator) = getNext(data, iterator, 4, '>I') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') A['A2'] = [] for i in range(length): (b, temp) = getB(data, temp) A['A2'].append(b) (A['A3'], iterator) = getNext(data, iterator, 4, '>i') (A['A4'], iterator) = getNext(data, iterator, 1, '>B') (A['A5'], iterator) = getNext(data, iterator, 4, '>i') (temp, iterator) = getNext(data, iterator, 2, '>H') A['A6'] = getC(data, temp)[0] return A def getB(data, iterator): B = {} (B['B1'], iterator) = getNext(data, iterator, 2, '>H') (B['B2'], iterator) = getNext(data, iterator, 8, '>d') (B['B3'], iterator) = getNext(data, iterator, 4, '>I') return (B, iterator) def getC(data, iterator): C = {} (C['C1'], iterator) = getNext(data, iterator, 1, '>B') (temp, iterator) = getNext(data, iterator, 4, '>I') C['C2'] = getD(data, temp)[0] (C['C3'], iterator) = getNext(data, iterator, 4, '>i') (length, iterator) = getNext(data, iterator, 2, '>H') (temp, iterator) = getNext(data, iterator, 2, '>H') C['C4'] = getNextArr(data, temp, length, f'>{length}B')[0] (C['C5'], iterator) = getNext(data, iterator, 2, '>H') (C['C6'], iterator) = getNext(data, iterator, 1, '>B') return (C, iterator) def getD(data, iterator): D = {} (D['D1'], iterator) = getNext(data, iterator, 4, '>I') (D['D2'], iterator) = getE(data, iterator) (D['D3'], iterator) = getNext(data, iterator, 4, '>f') (D['D4'], iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') D['D5'] = getF(data, temp)[0] (temp, iterator) = getNext(data, iterator, 4, '>I') D['D6'] = getG(data, temp)[0] return (D, iterator) def getE(data, iterator): E = {} (E['E1'], iterator) = getNext(data, iterator, 1, '>b') (E['E2'], iterator) = getNext(data, iterator, 1, '>b') (E['E3'], iterator) = getNext(data, iterator, 8, '>d') (E['E4'], iterator) = getNext(data, iterator, 2, '>h') (E['E5'], iterator) = getNextArr(data, iterator, 8 * 3, '>3Q') (E['E6'], iterator) = getNext(data, iterator, 8, '>q') return (E, iterator) def getF(data, iterator): F = {} (F['F1'], iterator) = getNext(data, iterator, 2, '>h') (F['F2'], iterator) = getNext(data, iterator, 2, '>H') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 4, '>I') F['F3'] = getNextArr(data, temp, length * 2, f'>{length}h')[0] (F['F4'], iterator) = getNext(data, iterator, 1, '>b') return (F, iterator) def getG(data, iterator): G = {} (G['G1'], iterator) = getNext(data, iterator, 2, '>H') (length, iterator) = getNext(data, iterator, 4, '>I') (temp, iterator) = getNext(data, iterator, 2, '>H') G['G2'] = getNextArr(data, temp, length * 2, f'>{length}h')[0] (G['G3'], iterator) = getNext(data, iterator, 1, '>b') (G['G4'], iterator) = getNext(data, iterator, 8, '>d') (G['G5'], iterator) = getNext(data, iterator, 2, '>H') (G['G6'], iterator) = getNext(data, iterator, 4, '>I') (G['G7'], iterator) = getNext(data, iterator, 2, '>h') return (G, iterator) def main(data): return getA(data, 4)" "from struct import * FMT = dict(int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'int64') (a3, offs) = parse(buf, offs, 'double') (a4, offs) = parse(buf, offs, 'uint8') return (dict(A1=a1, A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') b2 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'uint16') b2.append(val) (b3, offs) = parse(buf, offs, 'uint32') b4 = [] for _ in range(2): (val, offs) = parse_c(buf, offs) b4.append(val) (b5_offs, offs) = parse(buf, offs, 'uint16') (b5, b5_offs) = parse_d(buf, b5_offs) (b6, offs) = parse(buf, offs, 'uint32') (b7_size, offs) = parse(buf, offs, 'uint32') (b7_offs, offs) = parse(buf, offs, 'uint32') b7 = [] for _ in range(b7_size): (val, b7_offs) = parse(buf, b7_offs, 'uint8') b7.append(val) (b8, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5, B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int16') (c2, offs) = parse(buf, offs, 'int8') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'double') (d2, offs) = parse(buf, offs, 'int64') (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'uint16') (d5, offs) = parse(buf, offs, 'uint8') (d6, offs) = parse(buf, offs, 'int64') (d7_size, offs) = parse(buf, offs, 'uint16') (d7_offs, offs) = parse(buf, offs, 'uint32') d7 = [] for _ in range(d7_size): (val, d7_offs) = parse(buf, d7_offs, 'uint8') d7.append(val) (d8, offs) = parse(buf, offs, 'int32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct import pprint def parse_d(data, pointer): (d1, d2, d3) = struct.unpack('>hQd', data[pointer:pointer + 18]) f4 = struct.unpack('>IH', data[pointer + 18:pointer + 24]) d4 = list(struct.unpack(f'>{f4[0]}f', data[f4[1]:f4[1] + f4[0] * 4])) (d5, d6) = struct.unpack('>ii', data[pointer + 24:pointer + 32]) return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5, 'D6': d6} def parse_c(data, pointer): c1 = list(struct.unpack('>2H', data[pointer:pointer + 4])) (c2, c3, c4) = struct.unpack('>QHq', data[pointer + 4:pointer + 22]) c5 = list(struct.unpack('>7i', data[pointer + 22:pointer + 50])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5} def parse_b(data, pointer): b1 = struct.unpack('>b', data[pointer:pointer + 1])[0] f2 = struct.unpack('>HH', data[pointer + 1:pointer + 5]) b2 = list() for i in range(f2[0]): f22 = struct.unpack('>H', data[f2[1] + 2 * i:f2[1] + 2 + 2 * i]) b2.append(parse_c(data, f22[0])) return {'B1': b1, 'B2': b2} def parse_a(data, pointer): f1 = struct.unpack('>H', data[pointer:pointer + 2]) a1 = parse_b(data, f1[0]) a2 = list(struct.unpack('>4b', data[pointer + 2:pointer + 6])) f3 = struct.unpack('>H', data[pointer + 6:pointer + 8]) a3 = parse_d(data, f3[0]) return {'A1': a1, 'A2': a2, 'A3': a3} def main(data): return parse_a(data, 5)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 74: break a = {f'A{i}': None for i in range(1, 7)} b = {f'B{i}': None for i in range(1, 3)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 5)} e = {f'E{i}': None for i in range(1, 8)} temp = unpack('>bHfLBQ', file[a_adr:a_adr + 20]) (a['A1'], a['A2'], a['A3'], b_adr, a['A5'], a['A6']) = temp temp = unpack('>2LHQ', file[b_adr:b_adr + 18]) (*d_adrs, e_adr, b['B2']) = temp c['C1'] = [] for d_adr in d_adrs: temp = unpack('>HQLd', file[d_adr:d_adr + 22]) (d['D1'], d['D2'], d['D3'], d['D4']) = temp c['C1'].append(d.copy()) temp = unpack('>dblLHB4hLH', file[e_adr:e_adr + 34]) (e['E1'], e['E2'], e['E3'], int8_size, int8_adr, e['E5'], *int16_arr, float_size, float_adr) = temp e['E6'] = list(int16_arr) temp = unpack(f'>{int8_size}b', file[int8_adr:int8_adr + int8_size]) e['E4'] = list(temp) temp = unpack(f'>{float_size}f', file[float_adr:float_adr + float_size * 4]) e['E7'] = list(temp) c['C2'] = e b['B1'] = c a['A4'] = b return a" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'uint8') (a3_size, offs) = parse(buf, offs, 'uint16') (a3_offs, offs) = parse(buf, offs, 'uint16') a3_adresses = [] for _ in range(a3_size): (val, a3_offs) = parse(buf, a3_offs, 'uint16') a3_adresses.append(val) a3 = [] for ad in a3_adresses: (val, ad) = parse_b(buf, ad) a3.append(val) (a4, offs) = parse(buf, offs, 'int32') (a5, offs) = parse(buf, offs, 'int32') (a6, offs) = parse(buf, offs, 'float') (a7, offs) = parse_c(buf, offs) (a8, offs) = parse(buf, offs, 'int8') return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7, A8=a8), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'float') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2_offs, offs) = parse(buf, offs, 'uint16') (c2, c2_offs) = parse_d(buf, c2_offs) c3 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int32') c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'float') d3 = [] for _ in range(8): (val, offs) = parse(buf, offs, 'int32') d3.append(val) d4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int8') d4.append(val) (d5, offs) = parse(buf, offs, 'uint64') (d6, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(data): A = struct.unpack_from('>ib4IBd2H', data, offset=5) B = struct.unpack_from('>IHI2diBd2IHb2H', data, offset=A[3]) B1 = struct.unpack_from('>' + str(B[0]) + 'H', data, offset=B[1]) C_list = [] for i in range(B[0]): C = struct.unpack_from('>h2Hh', data, offset=B1[i]) C2 = list(struct.unpack_from('>' + str(C[1]) + 'B', data, offset=C[2])) C_list.append({'C1': C[0], 'C2': C2, 'C3': C[3]}) D = struct.unpack_from('>BbqQ', data, offset=B[2]) E3 = list(struct.unpack_from('>' + str(B[8]) + 'f', data, offset=B[9])) E6 = list(struct.unpack_from('>' + str(B[12]) + 'h', data, offset=B[13])) F5 = list(struct.unpack_from('>' + str(A[8]) + 'i', data, offset=A[9])) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': {'B1': C_list, 'B2': {'D1': D[0], 'D2': D[1], 'D3': D[2], 'D4': D[3]}, 'B3': B[3], 'B4': B[4], 'B5': B[5], 'B6': {'E1': B[6], 'E2': B[7], 'E3': E3, 'E4': B[10], 'E5': B[11], 'E6': E6}}, 'A5': {'F1': A[4], 'F2': A[5], 'F3': A[6], 'F4': A[7], 'F5': F5}}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('double', data, ofs) (E2, ofs) = parse('float', data, ofs) (E3, ofs) = parse('int64', data, ofs) (E4, ofs) = parse('float', data, ofs) E5 = [] (E5_size, ofs) = parse('uint32', data, ofs) (E5_adr, ofs) = parse('uint16', data, ofs) for i in range(E5_size): (elem, E5_adr) = parse('uint16', data, E5_adr) E5.append(elem) (E6, ofs) = parse('double', data, ofs) (E7, ofs) = parse('float', data, ofs) (E8, ofs) = parse('float', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7, E8=E8), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) (D2, ofs) = parse('int8', data, ofs) (D3, ofs) = parse('uint8', data, ofs) D4 = [] for i in range(4): (elem, ofs) = parse('float', data, ofs) D4.append(elem) (D5, ofs) = parse('uint16', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5), ofs) def struct_C(data, ofs): C1 = [] for i in range(2): (elem, ofs) = struct_D(data, ofs) C1.append(elem) (C2, ofs) = parse('uint32', data, ofs) (C3, ofs) = parse('uint16', data, ofs) (C4_adr, ofs) = parse('uint16', data, ofs) (C4, elem) = struct_E(data, C4_adr) C5 = [] (C5_size, ofs) = parse('uint16', data, ofs) (C5_adr, ofs) = parse('uint32', data, ofs) for i in range(C5_size): (elem, C5_adr) = parse('uint32', data, C5_adr) C5.append(elem) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5), ofs) def struct_B(data, ofs): (B1, ofs) = parse('float', data, ofs) (B2_adr, ofs) = parse('uint32', data, ofs) (B2, elem) = struct_C(data, B2_adr) (B3, ofs) = parse('int16', data, ofs) (B4, ofs) = parse('uint8', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = parse('uint64', data, ofs) (A3, ofs) = parse('uint16', data, ofs) return (dict(A1=A1, A2=A2, A3=A3), ofs) def main(data): return struct_A(data, 5)[0]" "import struct import pprint def parse_d(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{f1[0]}B', data[f1[1]:f1[1] + f1[0]])) (d2, d3) = struct.unpack('>bB', data[pointer + 6:pointer + 8]) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2) = struct.unpack('>IB', data[pointer:pointer + 5]) f3 = struct.unpack('>HH', data[pointer + 5:pointer + 9]) c3 = list(struct.unpack(f'>{f3[0]}h', data[f3[1]:f3[1] + f3[0] * 2])) return {'C1': c1, 'C2': c2, 'C3': c3} def parse_b(data, pointer): f1 = struct.unpack('>II', data[pointer:pointer + 8]) b1 = list() for i in range(f1[0]): f11 = struct.unpack('>H', data[f1[1] + 2 * i:f1[1] + 2 + 2 * i]) b1.append(parse_c(data, f11[0])) b2 = parse_d(data, pointer + 8) b3 = struct.unpack('>f', data[pointer + 16:pointer + 20])[0] return {'B1': b1, 'B2': b2, 'B3': b3} def parse_a(data, pointer): (a1, a2) = struct.unpack('>QI', data[pointer:pointer + 12]) a3 = parse_b(data, pointer + 12) f4 = struct.unpack('>HI', data[pointer + 32:pointer + 38]) a4 = list(struct.unpack(f'>{f4[0]}b', data[f4[1]:f4[1] + f4[0]])) (a5, a6, a7, a8) = struct.unpack('>ifbh', data[pointer + 38:pointer + 49]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5, 'A6': a6, 'A7': a7, 'A8': a8} def main(data): return parse_a(data, 3)" "from struct import unpack_from def main(bytes): A_offset = 4 A_dict = {} A_dict['A1'] = unpack_from('>h', bytes, offset=A_offset)[0] A_offset += 2 A_dict['A2'] = unpack_from('>h', bytes, offset=A_offset)[0] A_offset += 2 B_size = unpack_from('>I', bytes, offset=A_offset)[0] A_offset += 4 B_address = unpack_from('>H', bytes, offset=A_offset)[0] A_offset += 2 B_addresses_struct = list(unpack_from('>' + str(B_size) + 'H', bytes, offset=B_address)) A_dict['A3'] = [] for j in range(len(B_addresses_struct)): B_offset = B_addresses_struct[j] B_dict = {} B_dict['B1'] = unpack_from('>h', bytes, offset=B_offset)[0] B_offset += 2 B_dict['B2'] = [] C_offset = B_offset C_dict = {} C_dict['C1'] = unpack_from('>B', bytes, offset=C_offset)[0] C_offset += 1 C_dict['C2'] = unpack_from('>Q', bytes, offset=C_offset)[0] C_offset += 8 B_dict['B2'].append(C_dict) B_offset = C_offset B_dict['B2'] = B_dict['B2'][0] A_dict['A3'].append(B_dict) A_dict['A4'] = unpack_from('>B', bytes, offset=A_offset)[0] A_offset += 1 D_size = 1 D_address = A_offset D_addresses_struct = list(unpack_from('>' + str(D_size) + 'H', bytes, offset=D_address)) A_offset += 2 * D_size A_dict['A5'] = [] D_offset = D_addresses_struct[0] D_dict = {} D_dict['D1'] = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D2'] = unpack_from('>h', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D3'] = unpack_from('>d', bytes, offset=D_offset)[0] D_offset += 8 some_size = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D4'] = ''.join(map(lambda k: k.decode(), unpack_from('>' + str(some_size) + 'c', bytes, offset=some_address))) some_size = unpack_from('>I', bytes, offset=D_offset)[0] D_offset += 4 some_address = unpack_from('>H', bytes, offset=D_offset)[0] D_offset += 2 D_dict['D5'] = list(unpack_from('>' + str(some_size) + 'i', bytes, offset=some_address)) E_size = 1 E_address = D_offset E_addresses_struct = list(unpack_from('>' + str(E_size) + 'H', bytes, offset=E_address)) D_offset += 2 * E_size D_dict['D6'] = [] E_offset = E_addresses_struct[0] E_dict = {} E_dict['E1'] = unpack_from('>i', bytes, offset=E_offset)[0] E_offset += 4 some_size = unpack_from('>H', bytes, offset=E_offset)[0] E_offset += 2 some_address = unpack_from('>I', bytes, offset=E_offset)[0] E_offset += 4 E_dict['E2'] = list(unpack_from('>' + str(some_size) + 'b', bytes, offset=some_address)) D_dict['D6'].append(E_dict) D_dict['D6'] = D_dict['D6'][0] D_dict['D7'] = unpack_from('>i', bytes, offset=D_offset)[0] D_offset += 4 A_dict['A5'].append(D_dict) A_dict['A5'] = A_dict['A5'][0] return A_dict" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'float') return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): b1 = [] b1_offs = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint32') b1_offs.append(val) for of in b1_offs: (val, of) = parse_c(buf, of) b1.append(val) b2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'int64') b2.append(val) (b3, offs) = parse(buf, offs, 'uint16') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) c2 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'float') c2.append(val) (c3_size, offs) = parse(buf, offs, 'uint16') (c3_offs, offs) = parse(buf, offs, 'uint16') c3 = [] for _ in range(c3_size): (val, c3_offs) = parse(buf, c3_offs, 'uint16') c3.append(val) (c4, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): d1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'float') (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse(buf, offs, 'int16') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(s): d = {} a1 = [] a2 = {} c1 = {} d6 = [] c3 = [] a3 = {} a4 = {} base_address = 3 mass_1 = [] for i in range(6): mass_1.append(struct.unpack_from('>H', s, base_address)[0]) base_address += 2 for i in range(6): db1 = {} db1.setdefault('B1', struct.unpack_from('>f', s, mass_1[i])[0]) mass_1[i] += 4 temp_s = '' for j in range(5): temp_s += str(struct.unpack_from('>c', s, mass_1[i])[0])[2:3] mass_1[i] += 1 db1.setdefault('B2', temp_s) a1.append(db1) d.setdefault('A1', a1) new_address_d = struct.unpack_from('>H', s, base_address)[0] base_address += 2 c1.setdefault('D1', struct.unpack_from('>b', s, new_address_d)[0]) new_address_d += 1 c1.setdefault('D2', struct.unpack_from('>B', s, new_address_d)[0]) new_address_d += 1 c1.setdefault('D3', struct.unpack_from('>Q', s, new_address_d)[0]) new_address_d += 8 c1.setdefault('D4', struct.unpack_from('>h', s, new_address_d)[0]) new_address_d += 2 c1.setdefault('D5', struct.unpack_from('>h', s, new_address_d)[0]) new_address_d += 2 new_size = struct.unpack_from('>I', s, new_address_d)[0] new_address_d += 4 new_address_d6 = struct.unpack_from('>H', s, new_address_d)[0] new_address_d += 2 for i in range(new_size): d6.append(struct.unpack_from('>B', s, new_address_d6)[0]) new_address_d6 += 1 c1.setdefault('D6', d6) c1.setdefault('D7', struct.unpack_from('>I', s, new_address_d)[0]) new_address_d += 4 a2.setdefault('C1', c1) a2.setdefault('C2', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 for i in range(8): c3.append(struct.unpack_from('>f', s, base_address)[0]) base_address += 4 a2.setdefault('C3', c3) d.setdefault('A2', a2) a3.setdefault('E1', struct.unpack_from('>H', s, base_address)[0]) base_address += 2 a3.setdefault('E2', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 a3.setdefault('E3', struct.unpack_from('>f', s, base_address)[0]) base_address += 4 d.setdefault('A3', a3) new_address_f = struct.unpack_from('>H', s, base_address)[0] base_address += 2 a4.setdefault('F1', struct.unpack_from('>d', s, new_address_f)[0]) new_address_f += 8 a4.setdefault('F2', struct.unpack_from('>q', s, new_address_f)[0]) new_address_f += 8 d.setdefault('A4', a4) return d" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_E(data, ofs): (E1, ofs) = parse('double', data, ofs) (E2, ofs) = parse('float', data, ofs) (E3, ofs) = parse('int64', data, ofs) (E4, ofs) = parse('float', data, ofs) E5 = [] (E5_size, ofs) = parse('uint32', data, ofs) (E5_adr, ofs) = parse('uint16', data, ofs) for i in range(E5_size): (elem, E5_adr) = parse('uint16', data, E5_adr) E5.append(elem) (E6, ofs) = parse('double', data, ofs) (E7, ofs) = parse('float', data, ofs) (E8, ofs) = parse('float', data, ofs) return (dict(E1=E1, E2=E2, E3=E3, E4=E4, E5=E5, E6=E6, E7=E7, E8=E8), ofs) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) (D2, ofs) = parse('int8', data, ofs) D3 = [] (D3_size, ofs) = parse('uint16', data, ofs) (D3_adr, ofs) = parse('uint16', data, ofs) for i in range(D3_size): (elem, D3_adr) = parse('int16', data, D3_adr) D3.append(elem) (D4, ofs) = parse('double', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint16', data, ofs) (C2, ofs) = parse('uint8', data, ofs) (C3, ofs) = parse('int64', data, ofs) (C4, ofs) = parse('int8', data, ofs) (C5_adr, ofs) = parse('uint32', data, ofs) (C5, elem) = struct_D(data, C5_adr) (C6, ofs) = parse('int16', data, ofs) (C7, ofs) = parse('int64', data, ofs) (C8, ofs) = parse('int64', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, C7=C7, C8=C8), ofs) def struct_B(data, ofs): B1 = [] (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint16', data, ofs) for i in range(B1_size): (elem, B1_adr) = struct_C(data, B1_adr) B1.append(elem) B2 = [] for i in range(6): (elem, ofs) = parse('uint32', data, ofs) B2.append(elem) (B3, ofs) = parse('int64', data, ofs) (B4, ofs) = parse('float', data, ofs) return (dict(B1=B1, B2=B2, B3=B3, B4=B4), ofs) def struct_A(data, ofs): (A1, ofs) = struct_B(data, ofs) (A2, ofs) = parse('int64', data, ofs) (A3, ofs) = parse('double', data, ofs) A4 = [] (A4_size, ofs) = parse('uint32', data, ofs) (A4_adr, ofs) = parse('uint16', data, ofs) for i in range(A4_size): (elem, A4_adr) = parse('uint16', data, A4_adr) A4.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4), ofs) def main(data): return struct_A(data, 4)[0]" "import struct import pprint def parse_d(data, pointer): f1 = struct.unpack('H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'c' * size, s[add:add + 1 * size]) for el in a: buff += str(el)[2:3] return buff def uint16uint32int16(s, pointer): size = struct.unpack('>H', s[pointer:pointer + 2])[0] add = struct.unpack('>I', s[pointer + 2:pointer + 6])[0] a = struct.unpack('>' + 'h' * size, s[add:add + 2 * size]) return list(a) def B_structure(s, pointer): result = [] for i in range(0, 2): result.append({'B1': struct.unpack('>Q', s[pointer:pointer + 8])[0], 'B2': struct.unpack('>h', s[pointer + 8:pointer + 10])[0], 'B3': uint16uint32char(s, pointer + 10), 'B4': uint16uint32int16(s, pointer + 16), 'B5': struct.unpack('>B', s[pointer + 22:pointer + 23])[0], 'B6': {'C1': struct.unpack('>H', s[pointer + 23:pointer + 25])[0], 'C2': struct.unpack('>H', s[pointer + 25:pointer + 27])[0], 'C3': struct.unpack('>h', s[pointer + 27:pointer + 29])[0], 'C4': struct.unpack('>H', s[pointer + 29:pointer + 31])[0], 'C5': struct.unpack('>B', s[pointer + 31:pointer + 32])[0], 'C6': list(struct.unpack('>5H', s[pointer + 32:pointer + 42])), 'C7': struct.unpack('>f', s[pointer + 42:pointer + 46])[0]}, 'B7': struct.unpack('>i', s[pointer + 46:pointer + 50])[0]}) pointer += 50 return result def main(s): return {'A1': struct.unpack('>i', s[4:8])[0], 'A2': struct.unpack('>I', s[8:12])[0], 'A3': B_structure(s, 12), 'A4': {'D1': struct.unpack('>i', s[112:116])[0], 'D2': struct.unpack('>b', s[116:117])[0]}}" "import struct def main(x): A = {} B = {} B['B1'] = struct.unpack('>d', x[3:11])[0] B['B2'] = struct.unpack('>b', x[11:12])[0] B['B3'] = struct.unpack('>I', x[12:16])[0] A['A1'] = B clink = struct.unpack('>I', x[16:20])[0] C = {} c1len = struct.unpack('>H', x[clink:clink + 2])[0] c1link = struct.unpack('>H', x[clink + 2:clink + 4])[0] C['C1'] = [] for i in range(c1len): dlink = struct.unpack('>I', x[c1link + i * 4:c1link + i * 4 + 4])[0] D = {} D['D1'] = struct.unpack('>h', x[dlink:dlink + 2])[0] D['D2'] = struct.unpack('>B', x[dlink + 2:dlink + 3])[0] D['D3'] = struct.unpack('>I', x[dlink + 3:dlink + 7])[0] D['D4'] = struct.unpack('>H', x[dlink + 7:dlink + 9])[0] D['D5'] = struct.unpack('>f', x[dlink + 9:dlink + 13])[0] C['C1'].append(D) C['C2'] = struct.unpack('>f', x[clink + 4:clink + 8])[0] C['C3'] = struct.unpack('>h', x[clink + 8:clink + 10])[0] c4len = struct.unpack('>I', x[clink + 10:clink + 14])[0] c4link = struct.unpack('>H', x[clink + 14:clink + 16])[0] C['C4'] = [] for i in range(c4len): C['C4'].append(struct.unpack('>q', x[c4link + i * 8:c4link + i * 8 + 8])[0]) C['C5'] = struct.unpack('>B', x[clink + 16:clink + 17])[0] elink = struct.unpack('>H', x[clink + 17:clink + 19])[0] E = {} E['E1'] = struct.unpack('>I', x[elink:elink + 4])[0] E['E2'] = struct.unpack('>Q', x[elink + 4:elink + 12])[0] E['E3'] = [] for i in range(3): E['E3'].append(struct.unpack('>h', x[elink + 12 + i * 2:elink + 12 + i * 2 + 2])[0]) C['C6'] = E A['A2'] = C A['A3'] = [] a3len = struct.unpack('>H', x[20:22])[0] a3link = struct.unpack('>I', x[22:26])[0] for i in range(a3len): A['A3'].append(struct.unpack('>H', x[a3link + 2 * i:a3link + i * 2 + 2])[0]) A['A4'] = struct.unpack('>B', x[26:27])[0] A['A5'] = struct.unpack('>q', x[27:35])[0] return A" "import struct A_FORMAT = '>20sBIIHHbhI' B_FORMAT = '>if3sbQ' C_FORMAT = '>IIQ' D_FORMAT = '>bIbIH' def unpack_a(data, address): a = struct.unpack(A_FORMAT, data[address:address + 40]) b = unpack_b(a[0], 0) c = unpack_c(data, a[2]) a5_array = list(struct.unpack(f'>{a[4]}Q', data[a[5]:a[5] + a[4] * 8])) return {'A1': b, 'A2': a[1], 'A3': c, 'A4': a[3], 'A5': a5_array, 'A6': a[6], 'A7': a[7], 'A8': a[8]} def unpack_b(data, address): b = struct.unpack(B_FORMAT, data[address:address + 20]) return {'B1': b[0], 'B2': b[1], 'B3': b[2].decode('utf-8'), 'B4': b[3], 'B5': b[4]} def unpack_c(data, address): c = struct.unpack(C_FORMAT, data[address:address + 16]) d_addresses = struct.unpack(f'>{c[0]}H', data[c[1]:c[1] + c[0] * 2]) d_array = [] for d_adr in d_addresses: d_array.append(unpack_d(data, d_adr)) return {'C1': d_array, 'C2': c[2]} def unpack_d(data, address): d = struct.unpack(D_FORMAT, data[address:address + 12]) d_array_size = d[3] d_array = list(struct.unpack(f'>{d_array_size}i', data[d[4]:d[4] + d_array_size * 4])) return {'D1': d[0], 'D2': d[1], 'D3': d[2], 'D4': d_array} def main(data): if [data[0], data[1], data[2], data[3]] == [172, 76, 72, 72]: return unpack_a(data, 4)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'double') (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, a3_offs) = parse_b(buf, a3_offs) (a4, offs) = parse(buf, offs, 'uint8') (a5, offs) = parse_c(buf, offs) (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_d(buf, a6_offs) (a7_size, offs) = parse(buf, offs, 'uint16') (a7_offs, offs) = parse(buf, offs, 'uint16') a7 = [] for _ in range(a7_size): (val, a7_offs) = parse(buf, a7_offs, 'uint8') a7.append(val) return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4, A5=a5, A6=a6, A7=a7), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'float') (b2, offs) = parse(buf, offs, 'float') (b3, offs) = parse(buf, offs, 'uint16') (b4, offs) = parse(buf, offs, 'uint16') (b5, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2, offs) = parse(buf, offs, 'int8') (c3, offs) = parse(buf, offs, 'float') (c4, offs) = parse(buf, offs, 'double') (c5, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int32') (d2, offs) = parse(buf, offs, 'int32') d3 = [] for _ in range(4): (val, offs) = parse_e(buf, offs) d3.append(val) (d4, offs) = parse(buf, offs, 'uint8') (d5, offs) = parse_f(buf, offs) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'float') (e2, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2), offs) def parse_f(buf, offs): (d1, offs) = parse(buf, offs, 'uint64') (d2, offs) = parse(buf, offs, 'uint64') (d3, offs) = parse(buf, offs, 'float') (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'int32') (d6_size, offs) = parse(buf, offs, 'uint16') (d6_offs, offs) = parse(buf, offs, 'uint32') d6 = [] for _ in range(d6_size): (val, d6_offs) = parse(buf, d6_offs, 'uint32') d6.append(val) (d7, offs) = parse(buf, offs, 'uint8') (d8, offs) = parse(buf, offs, 'uint16') return (dict(F1=d1, F2=d2, F3=d3, F4=d4, F5=d5, F6=d6, F7=d7, F8=d8), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(bs): magic_bytes = b'LBEC' A = struct.Struct('> HH Q Q 6c H IH H') B = struct.Struct('> f Q') D = struct.Struct('> 2Q f d f') a = A.unpack_from(bs, len(magic_bytes)) b_struct = [B.unpack_from(bs, a[1] + i * B.size) for i in range(int(a[0]))] d = D.unpack_from(bs, a[-4]) return {'A1': [{'B1': b[0], 'B2': b[1]} for b in b_struct], 'A2': a[2], 'A3': a[3], 'A4': b''.join(a[4:10]).decode(), 'A5': {'C1': {'D1': list(d[:2]), 'D2': d[2], 'D3': d[3], 'D4': d[4]}, 'C2': list(struct.unpack_from(f'> {a[-3]}I', bs, a[-2])), 'C3': a[-1]}}" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse_a(buf, offs): a1 = unpack('f', d[a:a + 4]) a += 4 (two,) = struct.unpack('>b', d[a:a + 1]) a += 1 (size,) = struct.unpack('>I', d[a:a + 4]) a += 4 (address,) = struct.unpack('>I', d[a:a + 4]) a += 4 three = [] for i in range(size): (buff,) = struct.unpack('>B', d[address:address + 1]) address += 1 three.append(buff) (four,) = struct.unpack('>h', d[a:a + 2]) a += 2 (five,) = struct.unpack('>i', d[a:a + 4]) return {'F1': one, 'F2': two, 'F3': three, 'F4': four, 'F5': five} def E(d: bytes, a: int): (one,) = struct.unpack('>I', d[a:a + 4]) a += 4 (two,) = struct.unpack('>f', d[a:a + 4]) a += 4 (three,) = struct.unpack('>h', d[a:a + 2]) a += 2 (four,) = struct.unpack('>H', d[a:a + 2]) return {'E1': one, 'E2': two, 'E3': three, 'E4': four} def D(d: bytes, a: int): (one,) = struct.unpack('>B', d[a:a + 1]) a += 1 (two,) = struct.unpack('>d', d[a:a + 8]) a += 8 (three,) = struct.unpack('>f', d[a:a + 4]) return {'D1': one, 'D2': two, 'D3': three} def C(d: bytes): (one,) = struct.unpack('>i', d[17:21]) (two,) = struct.unpack('>i', d[21:25]) three = [] address = 25 for i in range(8): (buff,) = struct.unpack('>f', d[address:address + 4]) address += 4 three.append(buff) (four,) = struct.unpack('>i', d[address:address + 4]) address += 4 (address,) = struct.unpack('>I', d[address:address + 4]) five = D(d, address) return {'C1': one, 'C2': two, 'C3': three, 'C4': four, 'C5': five} def B(d: bytes): (size,) = struct.unpack('>H', d[7:9]) (address,) = struct.unpack('>I', d[9:13]) one = '' for i in range(size): (buff,) = struct.unpack('>c', d[address:address + 1]) address += 1 one += chr(buff[0]) (two,) = struct.unpack('>I', d[13:17]) three = C(d) return {'B1': one, 'B2': two, 'B3': three} def A(d: bytes): (one,) = struct.unpack('>h', d[5:7]) two = B(d) (three,) = struct.unpack('>I', d[65:69]) adresa = [] (buff,) = struct.unpack('>H', d[69:71]) adresa.append(buff) (buff,) = struct.unpack('>H', d[71:73]) adresa.append(buff) four = [] for i in range(len(adresa)): four.append(E(d, adresa[i])) (five,) = struct.unpack('>b', d[73:74]) (address,) = struct.unpack('>I', d[74:78]) six = F(d, address) (seven,) = struct.unpack('>Q', d[78:86]) (eight,) = struct.unpack('>B', d[86:87]) return {'A1': one, 'A2': two, 'A3': three, 'A4': four, 'A5': five, 'A6': six, 'A7': seven, 'A8': eight} def main(bytesSequence): return A(bytesSequence)" "import struct def main(x): a = dict() a['A1'] = struct.unpack('6cq3H2IBIHqHIhBf', data, offset=4) A1 = '' for i in range(6): A1 += A[i].decode('utf-8') B6 = list(struct.unpack_from('>' + str(A[13]) + 'b', data, offset=A[14])) B8 = list(struct.unpack_from('>' + str(A[16]) + 'b', data, offset=A[17])) C = [[], [], []] C[0] = struct.unpack_from('>qIhH', data, offset=A[7]) C[1] = struct.unpack_from('>qIhH', data, offset=A[8]) C[2] = struct.unpack_from('>qIhH', data, offset=A[9]) D = struct.unpack_from('>b8i', data, offset=A[11]) return {'A1': A1, 'A2': {'B1': A[6], 'B2': [{'C1': C[0][0], 'C2': C[0][1], 'C3': C[0][2], 'C4': C[0][3]}, {'C1': C[1][0], 'C2': C[1][1], 'C3': C[1][2], 'C4': C[1][3]}, {'C1': C[2][0], 'C2': C[2][1], 'C3': C[2][2], 'C4': C[2][3]}], 'B3': A[10], 'B4': {'D1': D[0], 'D2': [D[1], D[2], D[3], D[4], D[5], D[6], D[7], D[8]]}, 'B5': A[12], 'B6': B6, 'B7': A[15], 'B8': B8}, 'A3': A[18], 'A4': A[19], 'A5': A[20]}" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'uint32') (a2, offs) = parse(buf, offs, 'float') (a3_offs, offs) = parse(buf, offs, 'uint32') (a3, a3_offs) = parse_b(buf, a3_offs) return (dict(A1=a1, A2=a2, A3=a3), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'uint8') (b2, offs) = parse_c(buf, offs) (b3, offs) = parse(buf, offs, 'uint32') (b4, offs) = parse(buf, offs, 'double') (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint32') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'char') b5.append(val.decode()) (b6, offs) = parse(buf, offs, 'double') (b7_offs, offs) = parse(buf, offs, 'uint32') (b7, b7_offs) = parse_e(buf, b7_offs) (b8, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=''.join(b5), B6=b6, B7=b7, B8=b8), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'uint64') (c2, offs) = parse(buf, offs, 'int16') c3 = [] for _ in range(2): (val, offs) = parse_d(buf, offs) c3.append(val) return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint8') (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'uint16') return (dict(D1=d1, D2=d2, D3=d3), offs) def parse_e(buf, offs): (e1_size, offs) = parse(buf, offs, 'uint32') (e1_offs, offs) = parse(buf, offs, 'uint32') e1 = [] for _ in range(e1_size): (val, e1_offs) = parse(buf, e1_offs, 'int32') e1.append(val) (e2, offs) = parse(buf, offs, 'double') (e3, offs) = parse(buf, offs, 'double') e4 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int16') e4.append(val) return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '<' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): (D1, ofs) = parse('uint16', data, ofs) D2 = [] for i in range(6): (elem, ofs) = parse('uint8', data, ofs) D2.append(elem) (D3, ofs) = parse('int32', data, ofs) (D4, ofs) = parse('uint64', data, ofs) (D5, ofs) = parse('int32', data, ofs) (D6, ofs) = parse('uint32', data, ofs) (D7, ofs) = parse('float', data, ofs) return (dict(D1=D1, D2=D2, D3=D3, D4=D4, D5=D5, D6=D6, D7=D7), ofs) def struct_C(data, ofs): C1 = [] (C1_size, ofs) = parse('uint32', data, ofs) (C1_adr, ofs) = parse('uint16', data, ofs) for i in range(C1_size): (elem, C1_adr) = parse('int8', data, C1_adr) C1.append(elem) C2 = [] (C2_size, ofs) = parse('uint16', data, ofs) (C2_adr, ofs) = parse('uint32', data, ofs) for i in range(C2_size): (elem, C2_adr) = parse('uint64', data, C2_adr) C2.append(elem) (C3, ofs) = parse('int32', data, ofs) (C4, ofs) = parse('float', data, ofs) return (dict(C1=C1, C2=C2, C3=C3, C4=C4), ofs) def struct_B(data, ofs): B1 = [] (B1_size, ofs) = parse('uint32', data, ofs) (B1_adr, ofs) = parse('uint32', data, ofs) for i in range(B1_size): (C_adr, B1_adr) = parse('uint32', data, B1_adr) (elem, lop) = struct_C(data, C_adr) B1.append(elem) (B2_adr, ofs) = parse('uint32', data, ofs) (B2, elem) = struct_D(data, B2_adr) return (dict(B1=B1, B2=B2), ofs) def struct_A(data, ofs): (A1, ofs) = parse('double', data, ofs) (A2_adr, ofs) = parse('uint16', data, ofs) (A2, elem) = struct_B(data, A2_adr) (A3, ofs) = parse('uint16', data, ofs) return (dict(A1=A1, A2=A2, A3=A3), ofs) def main(data): return struct_A(data, 3)[0]" "import struct def parse_array(data, offset, type, length): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_e(data, offset): result = dict() (e1_size, e1_address) = struct.unpack('2IHI', data, offset=4) A3 = list(struct.unpack_from('>' + str(A[2]) + 'q', data, offset=A[3])) B = struct.unpack_from('>qHqd', data, offset=A[0]) C = struct.unpack_from('>3H5qd2IHqbh', data, offset=B[1]) C4 = list(struct.unpack_from('>' + str(C[9]) + 'h', data, offset=C[10])) D_list = [] for i in range(3): D = struct.unpack_from('>2I', data, offset=C[i]) D_list.append({'D1': D[0], 'D2': D[1]}) return {'A1': {'B1': B[0], 'B2': {'C1': D_list, 'C2': [C[3], C[4], C[5], C[6], C[7]], 'C3': C[8], 'C4': C4, 'C5': C[11], 'C6': {'E1': C[12], 'E2': C[13]}, 'C7': C[14]}, 'B3': B[2], 'B4': B[3]}, 'A2': A[1], 'A3': A3}" "import struct def parse(data_type, data, offset): data_types = dict(uint16='H', uint8='B', int32='i', double='d', uint32='I', int16='h', float='f', int8='b', int64='q', uint64='Q', char='s') fmt = '>' + data_types[data_type] size = struct.calcsize(fmt) val = struct.unpack_from(fmt, data, offset)[0] return (val, offset + size) def struct_D(data, ofs): D1 = [] for i in range(4): (elem, ofs) = parse('uint8', data, ofs) D1.append(elem) (D2, ofs) = parse('int8', data, ofs) (D3, ofs) = parse('int64', data, ofs) return (dict(D1=D1, D2=D2, D3=D3), ofs) def struct_C(data, ofs): (C1, ofs) = parse('uint32', data, ofs) (C2, ofs) = parse('int16', data, ofs) return (dict(C1=C1, C2=C2), ofs) def struct_B(data, ofs): B1 = '' (B1_size, ofs) = parse('uint16', data, ofs) (B1_adr, ofs) = parse('uint16', data, ofs) for i in range(B1_size): (elem, B1_adr) = parse('char', data, B1_adr) B1 += elem.decode() (B2, ofs) = parse('uint8', data, ofs) (B3, ofs) = parse('double', data, ofs) B4 = '' (B4_size, ofs) = parse('uint16', data, ofs) (B4_adr, ofs) = parse('uint32', data, ofs) for i in range(B4_size): (elem, B4_adr) = parse('char', data, B4_adr) B4 += elem.decode() (B5_adr, ofs) = parse('uint16', data, ofs) (B5, elem) = struct_C(data, B5_adr) return (dict(B1=B1, B2=B2, B3=B3, B4=B4, B5=B5), ofs) def struct_A(data, ofs): (A1, ofs) = parse('int32', data, ofs) (A2, ofs) = struct_B(data, ofs) (A3, ofs) = parse('uint32', data, ofs) (A4, ofs) = parse('uint8', data, ofs) (A5, ofs) = parse('uint64', data, ofs) A6 = [] for i in range(7): (elem, ofs) = struct_D(data, ofs) A6.append(elem) return (dict(A1=A1, A2=A2, A3=A3, A4=A4, A5=A5, A6=A6), ofs) def main(data): return struct_A(data, 5)[0]" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): a1 = [] for _ in range(2): (a1_offs, offs) = parse(buf, offs, 'uint32') (val, a1_offs) = parse_b(buf, a1_offs) a1.append(val) (a2, offs) = parse_c(buf, offs) (a3, offs) = parse(buf, offs, 'int32') a4 = [] for _ in range(6): (val, offs) = parse(buf, offs, 'int8') a4.append(val) (a5, offs) = parse(buf, offs, 'int8') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int8') (b2_size, offs) = parse(buf, offs, 'uint32') (b2_offs, offs) = parse(buf, offs, 'uint16') b2 = [] for _ in range(b2_size): (val, b2_offs) = parse(buf, b2_offs, 'char') b2.append(val.decode()) (b3, offs) = parse(buf, offs, 'uint64') return (dict(B1=b1, B2=''.join(b2), B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'int16') (c3, offs) = parse_d(buf, offs) (c4, offs) = parse(buf, offs, 'uint32') c5 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'float') c5.append(val) (c6, offs) = parse(buf, offs, 'uint32') (c7, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=c2, C3=c3, C4=c4, C5=c5, C6=c6, C7=c7), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'int16') (d2, offs) = parse(buf, offs, 'uint16') (d3, offs) = parse(buf, offs, 'uint8') (d4_size, offs) = parse(buf, offs, 'uint32') (d4_offs, offs) = parse(buf, offs, 'uint32') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'uint8') d4.append(val) (d5, offs) = parse(buf, offs, 'int64') (d6, offs) = parse(buf, offs, 'float') (d7, offs) = parse(buf, offs, 'double') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def main(buf): return parse_a(buf, 4)[0]" "import struct def main(bs): magic_bytes = b'AQSW' A = struct.Struct('> d d h f HH H h') B = struct.Struct('> B H f h') C = struct.Struct('> 7c H i f H') D = struct.Struct('> h 4H 5b') a = A.unpack_from(bs, len(magic_bytes)) b_structs = [B.unpack_from(bs, a[5] + i * B.size) for i in range(int(a[4]))] c = C.unpack_from(bs, a[-2]) d = D.unpack_from(bs, c[7]) return {'A1': a[0], 'A2': a[1], 'A3': a[2], 'A4': a[3], 'A5': [{'B1': b[0], 'B2': b[1], 'B3': b[2], 'B4': b[3]} for b in b_structs], 'A6': {'C1': b''.join(c[:7]).decode(), 'C2': {'D1': d[0], 'D2': list(d[1:5]), 'D3': list(d[5:])}, 'C3': c[-3], 'C4': c[-2], 'C5': c[-1]}, 'A7': a[-1]}" "from enum import Enum from struct import unpack_from, calcsize from typing import Any, Callable class Primitive(Enum): uint64 = 'Q' int64 = 'q' uint32 = 'I' int32 = 'i' uint16 = 'H' int16 = 'h' uint8 = 'B' int8 = 'b' float = 'f' double = 'd' char = 'c' class BinaryReader: def __init__(self, source: str, offset: int=0): self.offset = offset self.source = source def read(self, pattern: Primitive): data = unpack_from(pattern.value, self.source, self.offset) self.offset += calcsize(pattern.value) return data[0] def read_array(reader: BinaryReader, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1, to_sum: bool=False): if to_sum: reader.offset += size * structure_size reader = BinaryReader(source=reader.source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_g(reader: BinaryReader): return dict(G1=reader.read(Primitive.uint16), G2=reader.read(Primitive.uint64), G3=reader.read(Primitive.uint8)) def read_f(reader: BinaryReader): return dict(F1=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint16), lambda reader: reader.read(Primitive.uint8), structure_size=1), F2=reader.read(Primitive.int8), F3=reader.read(Primitive.int64), F4=read_array(reader, 8, reader.offset, lambda reader: reader.read(Primitive.int32), structure_size=4, to_sum=True), F5=reader.read(Primitive.int32)) def read_e(reader: BinaryReader): return dict(E1=reader.read(Primitive.uint16), E2=reader.read(Primitive.uint32)) def read_d(reader: BinaryReader): return dict(D1=reader.read(Primitive.double), D2=[read_e(BinaryReader(reader.source, offset=i)) for i in read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.uint16), structure_size=2)], D3=read_f(reader), D4=read_array(reader, reader.read(Primitive.uint16), reader.read(Primitive.uint32), lambda reader: reader.read(Primitive.int16), structure_size=2), D5=read_array(reader, 2, reader.offset, lambda reader: reader.read(Primitive.uint64), structure_size=8, to_sum=True), D6=reader.read(Primitive.float)) def read_c(reader: BinaryReader): return dict(C1=reader.read(Primitive.uint32), C2=read_d(reader), C3=reader.read(Primitive.uint32), C4=reader.read(Primitive.double), C5=reader.read(Primitive.uint64)) def read_b(reader: BinaryReader): return dict(B1=reader.read(Primitive.int8), B2=reader.read(Primitive.float), B3=reader.read(Primitive.int8)) def read_a(reader: BinaryReader): return dict(A1=reader.read(Primitive.uint16), A2=reader.read(Primitive.uint32), A3=read_b(BinaryReader(reader.source, offset=reader.read(Primitive.uint32))), A4=reader.read(Primitive.float), A5=reader.read(Primitive.float), A6=reader.read(Primitive.int8), A7=read_c(BinaryReader(reader.source, offset=reader.read(Primitive.uint16))), A8=read_g(BinaryReader(reader.source, offset=reader.read(Primitive.uint16)))) def main(source): return read_a(BinaryReader(source, offset=4))" "import struct def convert_to_dict(array, letter): return dict(((f'{letter}{i + 1}', o) for (i, o) in enumerate(array))) def main(data): f_a = '>f50sBH8sIBHH' f_b = '>BBfi' f_c = '>q22s' f_d = '>bqIHbih' a = list(struct.unpack_from(f_a, data, 4)) a[4] = a[4].decode('utf-8') a_2 = [] for i in range(5): b = struct.unpack_from(f_b, a[1], i * 10) a_2.append(convert_to_dict(b, 'B')) a[1] = a_2 c = list(struct.unpack_from(f_c, data, a[5])) d = list(struct.unpack_from(f_d, c[1], 0)) d[2] = list(struct.unpack_from(f'>{d[2]}B', data, d[3])) del d[3] c[1] = convert_to_dict(d, 'D') a[5] = convert_to_dict(c, 'C') a[7] = list(struct.unpack_from(f'>{a[7]}i', data, a[8])) del a[8] return convert_to_dict(a, 'A')" "import struct def main(data): A = struct.unpack_from('>iIHi2HQd6HBh5Bq', data, offset=3) A5 = list(struct.unpack_from('>' + str(A[4]) + 'c', data, offset=A[5])) for i in range(A[4]): A5[i] = A5[i].decode('utf-8') A5 = ''.join(A5) B = struct.unpack_from('>IQIQIQIQIQIQI', data, offset=A[1]) D = struct.unpack_from('>HIbqh', data, offset=A[2]) D1 = list(struct.unpack_from('>' + str(D[0]) + 'c', data, offset=D[1])) for i in range(D[0]): D1[i] = D1[i].decode('utf-8') D1 = ''.join(D1) return {'A1': A[0], 'A2': {'B1': B[0], 'B2': [{'C1': B[1], 'C2': B[2]}, {'C1': B[3], 'C2': B[4]}, {'C1': B[5], 'C2': B[6]}, {'C1': B[7], 'C2': B[8]}, {'C1': B[9], 'C2': B[10]}, {'C1': B[11], 'C2': B[12]}]}, 'A3': {'D1': D1, 'D2': D[2], 'D3': {'E1': D[3], 'E2': D[4]}}, 'A4': A[3], 'A5': A5, 'A6': A[6], 'A7': {'F1': A[7], 'F2': [A[8], A[9], A[10], A[11], A[12], A[13]], 'F3': A[14], 'F4': A[15], 'F5': [A[16], A[17], A[18], A[19], A[20]]}, 'A8': A[21]}" "import struct def main(d): a = {'A1': None, 'A2': None, 'A3': [], 'A4': None, 'A5': None, 'A6': None, 'A7': {}} razb(a, d) return a def razb(a, d): a['A1'] = struct.unpack('' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_size, offs) = parse(buf, offs, 'uint16') (a1_offs, offs) = parse(buf, offs, 'uint32') a1 = [] for _ in range(a1_size): (val, a1_offs) = parse(buf, a1_offs, 'char') a1.append(val.decode()) (a2, offs) = parse(buf, offs, 'uint32') (a3, offs) = parse(buf, offs, 'float') (a4_offs, offs) = parse(buf, offs, 'uint32') (a4, a4_offs) = parse_b(buf, a4_offs) return (dict(A1=''.join(a1), A2=a2, A3=a3, A4=a4), offs) def parse_b(buf, offs): b1 = [] for _ in range(3): (b1_offs, offs) = parse(buf, offs, 'uint16') (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse(buf, offs, 'int16') (b3_offs, offs) = parse(buf, offs, 'uint16') (b3, b3_offs) = parse_d(buf, b3_offs) (b4, offs) = parse(buf, offs, 'float') (b5, offs) = parse(buf, offs, 'int8') return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int8') (c2, offs) = parse(buf, offs, 'double') return (dict(C1=c1, C2=c2), offs) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'uint16') d2 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint64') d2.append(val) (d3, offs) = parse(buf, offs, 'uint16') (d4_size, offs) = parse(buf, offs, 'uint32') (d4_offs, offs) = parse(buf, offs, 'uint32') d4 = [] for _ in range(d4_size): (val, d4_offs) = parse(buf, d4_offs, 'uint16') d4.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from typing import Any, Callable from struct import * class BinaryReader: def get_specoffset(self): return self.specoffset def set_specoffset(self, offset): self.specoffset = offset def __init__(self, source, offset=0): self.offset = offset self.source = source self.specoffset = 0 def read_uint64(self): return self.read('>Q') def read_int64(self): return self.read('>q') def read_uint32(self): return self.read('>I') def read_int32(self): return self.read('>i') def read_uint16(self): return self.read('>H') def read_int16(self): return self.read('>h') def read_uint8(self): return self.read('>B') def read_int8(self): return self.read('>b') def read_float(self): return self.read('>f') def read_char(self): return self.read('>c') def read_double(self): return self.read('>d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_by_adress(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.specoffset) self.specoffset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any]): reader = BinaryReader(source=source, offset=address) values = [] for i in range(size): values.append(read(reader)) if i == 10: break return values def read_d(reader: BinaryReader): d1 = read_array(source=reader.source, size=reader.read_by_adress('>L'), address=reader.read_by_adress('>H'), read=lambda reader: reader.read_int32()) d2 = list() for i in range(8): temp = reader.read_by_adress('>B') d2.append(temp) d3 = list() for i in range(2): temp = reader.read_by_adress('>d') d3.append(temp) d4 = list() for i in range(4): temp = reader.read_by_adress('>b') d4.append(temp) return dict(D1=d1, D2=d2, D3=d3, D4=d4) def read_c(reader: BinaryReader, offset): reader.set_specoffset(offset) c1 = reader.read_by_adress('>b') adress = reader.get_specoffset() c2 = [read_d(reader), read_d(reader), read_d(reader)] return dict(C1=c1, C2=c2) def read_b(reader: BinaryReader): f1 = reader.read_uint16() b1 = read_c(reader, f1) b2 = reader.read_uint8() return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = read_b(reader) a2 = reader.read_uint32() return dict(A1=a1, A2=a2) def main(source): reader = BinaryReader(source) reader.read('cccc') return read_a(reader)" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 142: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 4)} c = {f'C{i}': None for i in range(1, 6)} d = {f'D{i}': None for i in range(1, 4)} temp = unpack('hIQHB', data[pointer:pointer + 17]) return {'F1': f1, 'F2': f2, 'F3': f3, 'F4': f4, 'F5': f5} def parse_e(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) e1 = list(struct.unpack(f'>{f1[0]}I', data[f1[1]:f1[1] + f1[0] * 4])) e2 = list(struct.unpack('>2H', data[pointer + 6:pointer + 10])) f3 = struct.unpack('>IH', data[pointer + 10:pointer + 16]) e3 = list(struct.unpack(f'>{f3[0]}b', data[f3[1]:f3[1] + f3[0]])) return {'E1': e1, 'E2': e2, 'E3': e3} def parse_d(data, pointer): d1 = struct.unpack('>Q', data[pointer:pointer + 8])[0] d2 = parse_e(data, pointer + 8) d3 = struct.unpack('>H', data[pointer + 24:pointer + 26])[0] d4 = list(struct.unpack('>8b', data[pointer + 26:pointer + 34])) d5 = struct.unpack('>Q', data[pointer + 34:pointer + 42])[0] return {'D1': d1, 'D2': d2, 'D3': d3, 'D4': d4, 'D5': d5} def parse_c(data, pointer): (c1, c2, c3, c4, c5, c6, c7) = struct.unpack('>BqQBfdB', data[pointer:pointer + 31]) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def parse_b(data, pointer): f1 = struct.unpack('>IH', data[pointer:pointer + 6]) b1 = list() for i in range(f1[0]): f11 = struct.unpack('>I', data[f1[1] + 4 * i:f1[1] + 4 + 4 * i]) b1.append(parse_c(data, f11[0])) b2 = struct.unpack('>h', data[pointer + 6:pointer + 8])[0] f3 = struct.unpack('>H', data[pointer + 8:pointer + 10]) b3 = parse_d(data, f3[0]) b4 = parse_f(data, pointer + 10) b5 = struct.unpack('>h', data[pointer + 27:pointer + 29])[0] return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5} def parse_a(data, pointer): (a1, a2) = struct.unpack('>iQ', data[pointer:pointer + 12]) f3 = struct.unpack('>H', data[pointer + 12:pointer + 14]) a3 = parse_b(data, f3[0]) (a4, a5) = struct.unpack('>QI', data[pointer + 14:pointer + 26]) return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def main(data): return parse_a(data, 4)" "import struct class StructA: def __init__(self, s): self.s = s self.current = 4 self.current_s = 0 def unpack_by_template(self, pat, length): def ret(): r = struct.unpack(pat, self.s[self.current:self.current + length]) self.current += length return r[0] return ret def unpack_by_template_struct(self, pat, length): def ret(): r = struct.unpack(pat, self.s[self.current_s:self.current_s + length]) self.current_s += length return r[0] return ret def A1(self): size_f = self.unpack_by_template(' dict: def struct_a(offset: int) -> dict: [length1] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 [adress] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 a1 = list(struct.unpack('> ' + str(length1) + 'c', binary[adress:adress + length1])) a1 = [i.decode('UTF-8') for i in a1] [a2] = struct.unpack('> Q', binary[offset:offset + 8]) offset += 8 [adress] = struct.unpack('> I', binary[offset:offset + 4]) offset += 4 a3 = struct_b(adress) a4 = list(struct.unpack('> 4Q', binary[offset:offset + 32])) offset += 32 [a5] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 return {'A1': ''.join(a1), 'A2': a2, 'A3': a3, 'A4': a4, 'A5': a5} def struct_b(offset: int) -> dict: [b1] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 adresses = list(struct.unpack('> 3I', binary[offset:offset + 12])) offset += 12 b2 = [struct_c(i) for i in adresses] [b3] = struct.unpack('> d', binary[offset:offset + 8]) offset += 8 [adress] = struct.unpack('> H', binary[offset:offset + 2]) offset += 2 b4 = struct_d(adress) [b5] = struct.unpack('> q', binary[offset:offset + 8]) offset += 8 [b6] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def struct_c(offset: int) -> dict: [c1] = struct.unpack('> B', binary[offset:offset + 1]) offset += 1 [c2] = struct.unpack('> h', binary[offset:offset + 2]) offset += 2 [c3] = struct.unpack('> i', binary[offset:offset + 4]) offset += 4 c4 = list(struct.unpack('> 4b', binary[offset:offset + 4])) offset += 4 return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def struct_d(offset: int) -> dict: [d1] = struct.unpack('> f', binary[offset:offset + 4]) offset += 4 d2 = list(struct.unpack('> 2Q', binary[offset:offset + 16])) offset += 16 return {'D1': d1, 'D2': d2} return struct_a(5)" "from struct import * import struct FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_d(buf, offs): (d1, offs) = parse(buf, offs, 'float') (d2, offs) = parse(buf, offs, 'uint64') return (dict(D1=d1, D2=d2), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'int32') (c2, offs) = parse(buf, offs, 'int64') return (dict(C1=c1, C2=c2), offs) def parse_b(buf, offs): (b1, offs) = parse_c(buf, offs) b2 = '' for _ in range(4): (val, offs) = parse(buf, offs, 'char') val = val.decode('utf-8') b2 = b2 + str(val) return (dict(B1=b1, B2=b2), offs) def parse_a(buf, offs): a1 = '' for _ in range(3): (val, offs) = parse(buf, offs, 'char') val = val.decode('utf-8') a1 = a1 + str(val) (a2, offs) = parse(buf, offs, 'uint64') (a3_offs, offs) = parse(buf, offs, 'uint32') (val, a2_offs) = parse_b(buf, a3_offs) a3 = val (a4_size, offs) = parse(buf, offs, 'uint32') (a4_offs, offs) = parse(buf, offs, 'uint16') a4 = [] for _ in range(a4_size): (val, a4_offs) = parse_d(buf, a4_offs) a4.append(val) (a5_size, offs) = parse(buf, offs, 'uint16') (a5_offs, offs) = parse(buf, offs, 'uint32') a5 = [] for _ in range(a5_size): (val, a5_offs) = parse(buf, a5_offs, 'uint32') a5.append(val) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import unpack_from, calcsize from typing import Any, Callable class BinaryReader: def __init__(self, source, offset=0): self.offset = offset self.source = source def read_uint64(self): return self.read('>Q') def read_int64(self): return self.read('>q') def read_uint32(self): return self.read('>I') def read_int32(self): return self.read('>i') def read_uint16(self): return self.read('>H') def read_int16(self): return self.read('>h') def read_uint8(self): return self.read('>B') def read_int8(self): return self.read('>b') def read_float(self): return self.read('>f') def read_char(self): return self.read('>c') def read_double(self): return self.read('>d') def read(self, pattern: str): size = calcsize(pattern) data = unpack_from(pattern, self.source, self.offset) self.offset += size return data[0] def read_array(source: str, size: int, address: int, read: Callable[[BinaryReader], Any], structure_size: int=1): reader = BinaryReader(source=source, offset=address) values = [] while address + size * structure_size > reader.offset: values.append(read(reader)) return values def read_e(reader: BinaryReader): e1 = reader.read_int8() e2 = reader.read_float() return dict(E1=e1, E2=e2) def read_d(reader: BinaryReader): d1 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint8(), structure_size=1) d2 = reader.read_uint64() d3 = [reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32(), reader.read_int32()] d4 = reader.read_float() return dict(D1=d1, D2=d2, D3=d3, D4=d4) def read_c(reader: BinaryReader): c1 = reader.read_int64() c2 = reader.read_uint64() c3 = read_array(source=reader.source, size=1, address=reader.read_uint16(), read=lambda reader: read_d(reader), structure_size=39) c4 = reader.read_uint8() c5 = reader.read_int64() c6 = read_e(reader) c7 = reader.read_int16() return dict(C1=c1, C2=c2, C3=c3[0], C4=c4, C5=c5, C6=c6, C7=c7) def read_b(reader: BinaryReader): b1 = reader.read_int8() b2 = ''.join([reader.read_char().decode('ascii'), reader.read_char().decode('ascii')]) return dict(B1=b1, B2=b2) def read_a(reader: BinaryReader): a1 = reader.read_uint16() a2 = read_array(source=reader.source, size=reader.read_uint16(), address=reader.read_uint16(), read=lambda reader: reader.read_uint32(), structure_size=4) new_a2 = [] for add in a2: new_a2.append(read_array(source=reader.source, size=len(a2), address=add, read=lambda reader: read_b(reader), structure_size=3)) a3 = read_array(source=reader.source, size=1, address=reader.read_uint32(), read=lambda reader: read_c(reader), structure_size=33) return dict(A1=a1, A2=new_a2[0], A3=a3[0]) def main(source): reader = BinaryReader(source) reader.read('ccccc') return read_a(reader)" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): readable = '>' + FMT[ty] return (unpack_from(readable, buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1_offs, offs) = parse(buf, offs, 'uint16') (a1, a1_offs) = parse_b(buf, a1_offs) (a2, offs) = parse(buf, offs, 'int64') (a3, offs) = parse(buf, offs, 'float') (a4, offs) = parse(buf, offs, 'float') (a5, offs) = parse(buf, offs, 'uint8') (a6_offs, offs) = parse(buf, offs, 'uint16') (a6, a6_offs) = parse_e(buf, a6_offs) return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): b1 = [] for i in range(2): (b1_offs, offs) = parse(buf, offs, 'uint16') (val, b1_offs) = parse_c(buf, b1_offs) b1.append(val) (b2, offs) = parse_d(buf, offs) (b3, offs) = parse(buf, offs, 'int8') (b4, offs) = parse(buf, offs, 'double') (b5_size, offs) = parse(buf, offs, 'uint16') (b5_offs, offs) = parse(buf, offs, 'uint16') b5 = [] for _ in range(b5_size): (val, b5_offs) = parse(buf, b5_offs, 'uint32') b5.append(val) return (dict(B1=b1, B2=b2, B3=b3, B4=b4, B5=b5), offs) def parse_c(buf, offs): c1 = [] for _ in range(5): (val, offs) = parse(buf, offs, 'uint16') c1.append(val) (c2, offs) = parse(buf, offs, 'uint64') (c3, offs) = parse(buf, offs, 'uint8') return (dict(C1=c1, C2=c2, C3=c3), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint16') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'float') d1.append(val) (d2, offs) = parse(buf, offs, 'int64') (d3_size, offs) = parse(buf, offs, 'uint32') (d3_offs, offs) = parse(buf, offs, 'uint32') d3 = [] for _ in range(d3_size): (val, d3_offs) = parse(buf, d3_offs, 'int16') d3.append(val) (d4, offs) = parse(buf, offs, 'int16') (d5, offs) = parse(buf, offs, 'double') (d6, offs) = parse(buf, offs, 'int64') (d7, offs) = parse(buf, offs, 'int8') (d8, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7, D8=d8), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'uint8') (e2, offs) = parse(buf, offs, 'uint64') (e3, offs) = parse(buf, offs, 'int16') (e4, offs) = parse(buf, offs, 'uint16') return (dict(E1=e1, E2=e2, E3=e3, E4=e4), offs) def main(buf): return parse_a(buf, 5)[0]" "import struct def main(x): a = dict() a['A1'] = struct.unpack('HI', data[pointer:pointer + 6]) d1 = list(struct.unpack(f'>{f1[0]}h', data[f1[1]:f1[1] + f1[0] * 2])) d2 = list(struct.unpack('>2H', data[pointer + 6:pointer + 10])) d3 = struct.unpack('>B', data[pointer + 10:pointer + 11])[0] return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): (c1, c2, c3, c4) = struct.unpack('>Iiid', data[pointer:pointer + 20]) c5 = list() c5.append(parse_d(data, pointer + 20)) c5.append(parse_d(data, pointer + 31)) c5.append(parse_d(data, pointer + 42)) c6 = struct.unpack('>Q', data[pointer + 53:pointer + 61])[0] f7 = struct.unpack('>HH', data[pointer + 61:pointer + 65]) c7 = list(struct.unpack(f'>{f7[0]}B', data[f7[1]:f7[1] + f7[0]])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4, 'C5': c5, 'C6': c6, 'C7': c7} def parse_b(data, pointer): (b1, b2, b3, b4, b5) = struct.unpack('>fhdfb', data[pointer:pointer + 19]) f6 = struct.unpack('>I', data[pointer + 19:pointer + 23]) b6 = parse_c(data, f6[0]) return {'B1': b1, 'B2': b2, 'B3': b3, 'B4': b4, 'B5': b5, 'B6': b6} def parse_a(data, pointer): (a1, a2) = struct.unpack('>bH', data[pointer:pointer + 3]) a3 = parse_b(data, pointer + 3) a4 = struct.unpack('>b', data[pointer + 26:pointer + 27])[0] return {'A1': a1, 'A2': a2, 'A3': a3, 'A4': a4} def main(data): return parse_a(data, 5)" "from struct import unpack, unpack_from, calcsize PATTERN_A = '>xxxxxQfHIHhBBBBBBBBHI' PATTERN_B_1 = '>IIBBBBBB' PATTERN_B_2 = '>HH' PATTERN_C = '>bIQdI' PATTERN_B = PATTERN_B_1 + PATTERN_C[1:] + PATTERN_B_2[1:] PATTERN_D = '>hb' ""\n int8='b',\n uint8='B',\n double='d',\n int16='h',\n uint16='H',\n int32='i',\n uint32='I',\n int64='q',\n uint64='Q',\n float='f',\n"" def parse_a(raw_data): data = unpack(PATTERN_A, raw_data[0:calcsize(PATTERN_A)]) (b_list_size, b_list_address) = (data[2], data[3]) b_data = [] for b_item_index in range(b_list_size): b_address = unpack_from('>H', raw_data, b_list_address + b_item_index * calcsize('H')) b = parse_b(raw_data, b_address[0]) b_data.append(b) (a7_size, a7_address) = (data[14], data[15]) a7_data = unpack_from('>' + 'I' * a7_size, raw_data, a7_address) return {'A1': data[0], 'A2': data[1], 'A3': b_data, 'A4': data[4], 'A5': data[5], 'A6': list(data[6:14]), 'A7': list(a7_data)} def parse_b(raw_data, address): b_one = unpack_from(PATTERN_B_1, raw_data, address) b_two = unpack_from(PATTERN_B_2, raw_data, address + calcsize(PATTERN_B_1) + calcsize(PATTERN_C)) c_data = parse_c(raw_data, address + calcsize(PATTERN_B_1)) (b1_size, b1_address) = (b_one[0], b_one[1]) b1 = unpack_from('>' + 'H' * b1_size, raw_data, b1_address) d_data = parse_d(raw_data, b_two[1]) return {'B1': list(b1), 'B2': list(b_one[2:8]), 'B3': c_data, 'B4': b_two[0], 'B5': d_data} def parse_c(raw_data, address): data = unpack_from(PATTERN_C, raw_data, address) return {'C1': data[0], 'C2': data[1], 'C3': data[2], 'C4': data[3], 'C5': data[4]} def parse_d(raw_data, address): data = unpack_from(PATTERN_D, raw_data, address) return {'D1': data[0], 'D2': data[1]} def main(raw_data): return parse_a(raw_data)" "import struct def main(data): A = struct.unpack_from('>idQ5cHBdI', data, offset=5) A4 = '' for i in range(5): A4 += A[i + 3].decode('utf-8') B = struct.unpack_from('>q4I2Hi', data, offset=A[8]) C_list = [] for i in range(4): C = struct.unpack_from('>QHB4bdb', data, offset=B[i + 1]) C_list.append({'C1': C[0], 'C2': C[1], 'C3': C[2], 'C4': [C[3], C[4], C[5], C[6]], 'C5': C[7], 'C6': C[8]}) return {'A1': A[0], 'A2': A[1], 'A3': A[2], 'A4': A4, 'A5': {'B1': B[0], 'B2': C_list, 'B3': {'D1': [B[5], B[6]], 'D2': B[7]}}, 'A6': A[9], 'A7': A[10], 'A8': A[11]}" "from struct import * FMT = dict(char='c', int8='b', uint8='B', int16='h', uint16='H', int32='i', uint32='I', int64='q', uint64='Q', float='f', double='d') def parse(buf, offs, ty): return (unpack_from('>' + FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse_b(buf, offs) (a2, offs) = parse(buf, offs, 'uint32') return (dict(A1=a1, A2=a2), offs) def parse_b(buf, offs): (b1_size, offs) = parse(buf, offs, 'uint32') (b1_offs, offs) = parse(buf, offs, 'uint16') b1 = [] for _ in range(b1_size): (val, b1_offs) = parse(buf, b1_offs, 'uint32') (val2, val) = parse_c(buf, val) b1.append(val2) (b2, offs) = parse(buf, offs, 'uint32') return (dict(B1=b1, B2=b2), offs) def parse_c(buf, offs): (c1, offs) = parse_d(buf, offs) (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'uint32') c2.append(val) (c3, offs) = parse(buf, offs, 'uint32') (c4_size, offs) = parse(buf, offs, 'uint32') (c4_offs, offs) = parse(buf, offs, 'uint16') c4 = [] for _ in range(c4_size): (val, c4_offs) = parse(buf, c4_offs, 'uint8') c4.append(val) return (dict(C1=c1, C2=c2, C3=c3, C4=c4), offs) def parse_d(buf, offs): (d1_size, offs) = parse(buf, offs, 'uint32') (d1_offs, offs) = parse(buf, offs, 'uint32') d1 = [] for _ in range(d1_size): (val, d1_offs) = parse(buf, d1_offs, 'double') d1.append(val) (d2, offs) = parse(buf, offs, 'double') (d3, offs) = parse(buf, offs, 'int16') (d4, offs) = parse(buf, offs, 'uint32') return (dict(D1=d1, D2=d2, D3=d3, D4=d4), offs) def main(buf): return parse_a(buf, 5)[0]" "from struct import * FMT = dict(char='>c', int8='>b', uint8='>B', int16='>h', uint16='>H', int32='>i', uint32='>I', int64='>q', uint64='>Q', float='>f', double='>d') def parse(buf, offs, ty): return (unpack_from(FMT[ty], buf, offs)[0], offs + calcsize(FMT[ty])) def parse_a(buf, offs): (a1, offs) = parse(buf, offs, 'int64') (a2, offs) = parse(buf, offs, 'uint32') (a3_offs, offs) = parse(buf, offs, 'uint32') a3 = [] for _ in range(2): (val, a3_offs) = parse_b(buf, a3_offs) a3.append(val) offs += 4 (a4, offs) = parse_c(buf, offs) (a5_offs, offs) = parse(buf, offs, 'uint16') (a5, _) = parse_e(buf, a5_offs) (a6, offs) = parse(buf, offs, 'uint64') return (dict(A1=a1, A2=a2, A3=a3, A4=a4, A5=a5, A6=a6), offs) def parse_b(buf, offs): (b1, offs) = parse(buf, offs, 'int64') (b2, offs) = parse(buf, offs, 'int16') (b3, offs) = parse(buf, offs, 'int32') return (dict(B1=b1, B2=b2, B3=b3), offs) def parse_c(buf, offs): (c1, offs) = parse(buf, offs, 'float') (c2_size, offs) = parse(buf, offs, 'uint16') (c2_offs, offs) = parse(buf, offs, 'uint32') c2 = [] for _ in range(c2_size): (val, c2_offs) = parse(buf, c2_offs, 'char') c2.append(val.decode('utf-8')) (c3, offs) = parse(buf, offs, 'uint16') (c4, offs) = parse_d(buf, offs) (c5, offs) = parse(buf, offs, 'uint64') return (dict(C1=c1, C2=''.join(c2), C3=c3, C4=c4, C5=c5), offs) def parse_d(buf, offs): d1 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'uint16') d1.append(val) (d2, offs) = parse(buf, offs, 'uint32') (d3, offs) = parse(buf, offs, 'uint16') (d4, offs) = parse(buf, offs, 'uint64') d5 = [] for _ in range(3): (val, offs) = parse(buf, offs, 'int32') d5.append(val) (d6, offs) = parse(buf, offs, 'double') d7 = [] for _ in range(2): (val, offs) = parse(buf, offs, 'int32') d7.append(val) return (dict(D1=d1, D2=d2, D3=d3, D4=d4, D5=d5, D6=d6, D7=d7), offs) def parse_e(buf, offs): (e1, offs) = parse(buf, offs, 'int16') (e2, offs) = parse(buf, offs, 'int16') (e3, offs) = parse(buf, offs, 'int32') (e4, offs) = parse(buf, offs, 'uint8') (e5, offs) = parse(buf, offs, 'uint64') return (dict(E1=e1, E2=e2, E3=e3, E4=e4, E5=e5), offs) def main(buf): return parse_a(buf, 4)[0]" "from struct import unpack def parse_arrays(arr, d_str_size): count = 0 parsed = [] for _ in range(0, d_str_size): a = [] for i in range(0, 9): a.append(arr[count + i]) count += 9 parsed.append(a) return parsed def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 80: break a = {f'A{i}': None for i in range(1, 4)} b = {f'B{i}': None for i in range(1, 9)} c = {f'C{i}': None for i in range(1, 4)} d = {f'D{i}': None for i in range(1, 8)} e = {f'E{i}': None for i in range(1, 3)} temp = unpack('2Hi2IqhhIHb', data, offset=4) A1 = struct.unpack_from('>' + 'IHQ' * A[0], data, offset=A[1]) B_list = [] for i in range(A[0]): B1 = list(struct.unpack_from('>' + str(A1[i * 3]) + 'c', data, offset=A1[i * 3 + 1])) for j in range(A1[i * 3]): B1[j] = B1[j].decode('utf-8') B1 = ''.join(B1) B_list.append({'B1': B1, 'B2': A1[i * 3 + 2]}) C2 = list(struct.unpack_from('>' + str(A[3]) + 'q', data, offset=A[4])) E = struct.unpack_from('>IHIHIi', data, offset=A[9]) E1 = list(struct.unpack_from('>' + str(E[0]) + 'B', data, offset=E[1])) E3 = list(struct.unpack_from('>' + str(E[3]) + 'h', data, offset=E[4])) return {'A1': B_list, 'A2': {'C1': A[2], 'C2': C2, 'C3': {'D1': A[5], 'D2': A[6]}, 'C4': A[7]}, 'A3': A[8], 'A4': {'E1': E1, 'E2': E[2], 'E3': E3, 'E4': E[5]}, 'A5': A[10]}" "from struct import unpack def main(file): a_adr = 0 for byte in file: a_adr += 1 if byte == 22: break a = {f'A{i}': None for i in range(1, 8)} b = {f'B{i}': None for i in range(1, 7)} c = {f'C{i}': None for i in range(1, 3)} d = {f'D{i}': None for i in range(1, 9)} e = {f'E{i}': None for i in range(1, 3)} temp = unpack('>LL6HLBLhqfQHHbhl', file[a_adr:a_adr + 62]) (ch_size, ch_adr, *c_adrs, d_adr, b['B4'], e['E1'], e['E2'], b['B6'], a['A2'], a['A3'], float_size, float_adr, a['A5'], a['A6'], a['A7']) = temp ch_arr = unpack(f'>{ch_size}c', file[ch_adr:ch_adr + ch_size]) b['B1'] = ''.join((str(e, 'utf8') for e in ch_arr)) temp = unpack(f'>{float_size}f', file[float_adr:float_adr + float_size * 4]) a['A4'] = list(temp) temp = unpack('>bHHBQHHdll', file[d_adr:d_adr + 34]) (d['D1'], int8_size, int8_adr, d['D3'], d['D4'], uint64_size, uint64_adr, d['D6'], d['D7'], d['D8']) = temp temp = unpack(f'>{int8_size}b', file[int8_adr:int8_adr + int8_size]) d['D2'] = list(temp) temp = unpack(f'>{uint64_size}Q', file[uint64_adr:uint64_adr + uint64_size * 8]) d['D5'] = list(temp) b['B2'] = [] for c_adr in c_adrs: temp = unpack('>Bq', file[c_adr:c_adr + 9]) (c['C1'], c['C2']) = temp b['B2'].append(c.copy()) b['B3'] = d b['B5'] = e a['A1'] = b return a" "import struct from typing import Dict def get_struct_e(bytes, address_e) -> Dict: uint64 = ' (int, Dict): _float = ' Dict: double = ' (int, Dict): ar_uint16 = ' Dict: ar_char = ' Dict: return get_struct_a(bytes)" "import struct import pprint def parse_d(data, pointer): d1 = struct.unpack('>d', data[pointer:pointer + 8])[0] d2 = list(struct.unpack('>3i', data[pointer + 8:pointer + 20])) d3 = list(struct.unpack('>2i', data[pointer + 20:pointer + 28])) return {'D1': d1, 'D2': d2, 'D3': d3} def parse_c(data, pointer): f1 = struct.unpack('>4H', data[pointer:pointer + 8]) c1 = list() for i in range(4): c1.append(parse_d(data, f1[i])) (c2, c3) = struct.unpack('>fb', data[pointer + 8:pointer + 13]) c4 = list(struct.unpack('>7h', data[pointer + 13:pointer + 27])) return {'C1': c1, 'C2': c2, 'C3': c3, 'C4': c4} def parse_b(data, pointer): f1 = struct.unpack('>I', data[pointer:pointer + 4]) b1 = parse_c(data, f1[0]) b2 = struct.unpack('>H', data[pointer + 4:pointer + 6])[0] return {'B1': b1, 'B2': b2} def parse_a(data, pointer): a1 = parse_b(data, pointer) a2 = struct.unpack('>B', data[pointer + 6:pointer + 7])[0] return {'A1': a1, 'A2': a2} def main(data): return parse_a(data, 3)" "import struct def parse_value(data, offset, type): return struct.unpack(f'<{type}', data[offset:offset + struct.calcsize(type)])[0] def parse_array(data, offset, length, type): return list(struct.unpack(f'<{length}{type}', data[offset:offset + length * struct.calcsize(type)])) def parse_d(data, offset): result = dict() result['D1'] = parse_value(data, offset, 'f') result['D2'] = parse_value(data, offset + 4, 'q') (f1_size, f1_addr) = struct.unpack('