""" Verify key derivation and analyze DX index structure. Proven scheme: DX key = SHA256(master_key_32 + file[8:24]) AES-256-CFB128, IV = "Copyright @ OneO" """ import hashlib import struct from pathlib import Path from Crypto.Cipher import AES KEY = b'kj)TGtrK>f]b[Piow.gU+nC@s""""""4' IV = b"Copyright @ OneO" file_data = Path("ocr_data/oneocr.onemodel").read_bytes() # Step 1: Derive DX key header_hash = file_data[8:24] derived_key = hashlib.sha256(KEY + header_hash).digest() print(f"DX derived key: {derived_key.hex()}") # Step 2: Decrypt DX index encrypted_dx = file_data[24:24 + 22624] cipher = AES.new(derived_key, AES.MODE_CFB, iv=IV, segment_size=128) dx = cipher.decrypt(encrypted_dx) assert dx[:2] == b"DX", "DX header mismatch!" valid_size = struct.unpack('= 0: print(f" {name}: found at DX offset {pos} ({pos:#x})") else: print(f" {name}: NOT found in DX (len={len(target)})") # Step 5: Analyze DX structure around container header magic magic = bytes.fromhex("4a1a082b25000000") print(f"\nContainer magic 4a1a082b25000000 locations:") pos = 0 while True: pos = dx.find(magic, pos) if pos < 0: break # Read surrounding context ctx = dx[pos:pos+40] print(f" offset {pos} ({pos:#x}): {ctx.hex()}") pos += 1 # Step 6: Parse DX as record-based structure # Looking at the structure: # Offset 0-7: "DX\x00\x00\x00\x00\x00\x00" # Offset 8-15: valid_size (uint64) = 22620 # Offset 16-23: container magic = 4a1a082b25000000 # Offset 24-31: uint64 = 0x2ea7 = 11943 # Let's see what's after that print(f"\n--- DX parsed fields ---") off = 0 print(f" [{off}] Magic: {dx[off:off+8]}") off = 8 print(f" [{off}] ValidSize: {struct.unpack('