#!/usr/bin/env python3 """Check the bounded fresh-lab registry construction proof against original bytes.""" import argparse import hashlib import json from pathlib import Path import struct import sys from pe_inspect import PE sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels')) from gam import parse EXE_HASH = 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8' GAM_HASH = '316fff40db565c2add5b07cbccdef640ddb67c64d6625fea1429ce2a0542a234' CALLS = [ (0x46E335, 0x459CB0, 'loader constructs header game before reading entities'), (0x45D3FD, 0x44F300, 'LV1B factory constructor'), (0x44F358, 0x44D2B0, 'lab constructor calls JimmyGame base'), (0x44D306, 0x4745A0, 'JimmyGame calls game base'), (0x47460A, 0x4586F0, 'game base constructs interface at complete+8C'), (0x458712, 0x46FBE0, 'interface base owns registry insertion'), (0x46E3B9, 0x459CB0, 'loader first fresh entity factory'), (0x45B1E2, 0x422160, '3JIM factory constructor'), (0x4221B1, 0x437280, 'Jimmy calls player base'), (0x4372DA, 0x40D110, 'player calls animated base'), (0x40D162, 0x462040, 'animated calls object base'), (0x4620AA, 0x4586F0, 'object base constructs interface at complete+C0'), (0x4374DF, 0x421D80, 'player constructs owned jetpack fire'), (0x421DD2, 0x40D110, 'fire calls animated base and registers'), (0x42250C, 0x43F640, 'Jimmy constructs owned shadow'), (0x43F692, 0x4352F0, 'shadow calls picture base'), (0x435341, 0x463F10, 'picture calls sprite base'), (0x463F74, 0x4586F0, 'sprite base constructs interface at complete+C8'), (0x46E49A, 0x459CB0, 'loader remaining fresh entities factory'), (0x423C98, 0x41C810, 'Jimmy postload creates absent Goddard'), (0x41C861, 0x407A40, 'Goddard calls AI base'), (0x407A92, 0x40D110, 'AI calls animated base and registers'), (0x41C95F, 0x43F640, 'Goddard constructs owned shadow'), ] ANCHORS = [ (0x46FF4A, '8b359c9950006a0c8b7e04', 'registry sentinel,12-byte node,old tail'), (0x46FF6D, '8978048946048b48048901', 'link node before sentinel after old tail'), (0x46FF7F, '8928', 'node payload receives interface pointer'), (0x46E36A, 'ffd6', 'read entity count after header construction'), (0x46E37F, 'ffd6', 'read first entity code after count'), (0x46E61A, 'ff920c040000', 'postload pass calls interface40C'), (0x4374EF, '8985f8070000', 'Jimmy complete+7F8 owns fire complete pointer'), (0x42251C, '89852c0a0000', 'Jimmy complete+A2C owns shadow complete pointer'), (0x41C96F, '898694090000', 'Goddard complete+994 owns shadow complete pointer'), (0x42275A, 'c685c900000001', 'Jimmy enables interface+09 reuse flag'), (0x41C9C0, 'c686c900000001', 'Goddard enables interface+09 reuse flag'), (0x46E6B9, '3bb00404000075078a580984db750d', 'reuse requires matching class code and interface+09'), ] SLOTS = [ (0x4D5EA0, 0x128, 0x46E570, 'supervisor postload pass'), (0x4D5EA0, 0x110, 0x46E6E0, 'supervisor existing class lookup'), (0x4D5EA0, 0x11C, 0x46E6A0, 'supervisor class reuse predicate'), (0x4A373C, 0x40C, 0x423610, 'Jimmy postload contains Goddard creation'), ] def collect(original): original = Path(original) pe = PE(original / 'Neutron.exe') gam_data = (original / 'gam' / 'level1b.gam').read_bytes() if hashlib.sha256(pe.data).hexdigest() != EXE_HASH: raise ValueError('Unsupported Neutron.exe hash') if hashlib.sha256(gam_data).hexdigest() != GAM_HASH: raise ValueError('Unsupported lab GAM hash') evidence = [] for va, expected, label in ANCHORS: off = pe.offset(va - pe.base) actual = pe.data[off:off + len(expected)//2].hex() if actual != expected: raise ValueError(f'{label} {va:#x}: {actual} != {expected}') evidence.append(dict(va=hex(va), file_offset=hex(off), bytes=actual, evidence=label)) for va, target, label in CALLS: off = pe.offset(va - pe.base) data = pe.data[off:off + 5] if data[0] != 0xE8 or va + 5 + struct.unpack('