"""TP5 .td5 block header checksum - solved. Block layout (first 0x13 bytes): +0x00 u8 0x43 'C' block type tag +0x01 u16 CRC-16/ARC over block[3:blockLen] <-- the "mystery field" low half +0x03 u32 rand() (MSVCRT, 0..0x7FFF; srand(time(NULL)) once per export) +0x07 u32 blockLen +0x0b u8 1 +0x0c u8 1 +0x0d u16 1 +0x0f u8 0x84 +0x10 u16 0x0116 (offset of bitmap data = header size) The 4 bytes read as one u32-LE at +1 are therefore CRC | (rand<<16). """ import struct from parse import records def crc16_arc(data, init=0, poly=0xA001): """TP5 sub_409150 with polyIndex=1 (table @0x447020 = [8480,A001,8621,E950]).""" c = init for b in data: c ^= b for _ in range(8): c = (c >> 1) ^ poly if c & 1 else c >> 1 return c & 0xFFFF def td5_block_checksum(block): """block: the full block bytes (length == u32 at block[7:11]). Returns u16 for block[1:3].""" blen = struct.unpack_from('