#!/usr/bin/env python3 """Guard the original derived Jimmy frame and prepare a bounded caller probe.""" import argparse import hashlib import json from pathlib import Path import re import struct import subprocess from checkpoint_script_state import EXE_SHA256, find_case, read_va, rel_call_target from pe_inspect import PE REA_ID = 'ev_0d64cc58fa8f5573fc8e61e0f2c20e36288099212bd2257d3a3121361fd6c904' RANGES = ( (0x424600, 0x425110), (0x425120, 0x42516f), (0x425170, 0x425488), (0x425490, 0x4255b4), (0x4255c0, 0x425862), (0x42aac0, 0x42aaf2), (0x409f60, 0x409f80), (0x458960, 0x458985), (0x471a10, 0x471a18), (0x471b40, 0x471b4d), (0x471f10, 0x471f3a), (0x472300, 0x47232a), (0x403a10, 0x403a18), (0x403700, 0x403723), (0x406590, 0x406645), ) SLOTS = ( (0x4a3bdc, 0x208, 0x424d10), (0x4a3bdc, 0x1a4, 0x425170), (0x4a3bdc, 0x1a8, 0x4252e0), (0x4a3bdc, 0x194, 0x42aac0), (0x4a3bdc, 0x1c8, 0x424e80), (0x4a3bdc, 0x1b4, 0x4255c0), (0x4a3bdc, 0x1b0, 0x425490), (0x4a3bdc, 0x1e0, 0x425120), (0x4a373c, 0x218, 0x458960), (0x4a373c, 0x264, 0x471b40), (0x4a373c, 0x2bc, 0x471f10), (0x4a373c, 0x310, 0x472300), (0x4a373c, 0x314, 0x472360), (0x4a373c, 0x318, 0x472330), (0x4a373c, 0x2c0, 0x471f70), (0x4a3bdc, 0xfc, 0x40dd40), (0x4a3bdc, 0x114, 0x40e4a0), (0x48d414, 0x4a8, 0x403a10), (0x48d414, 0x4c4, 0x406590), (0x48d414, 0x488, 0x403700), (0x48d414, 0x460, 0x4033f0), ) SITES = ( (0x424721, 'a081814f00', 'menu lock load'), (0x424732, '663d0200', 'menu state2 comparison'), (0x424736, '0f85ca050000', 'locked other state returns'), (0x424744, 'ff9060040000', 'locked state2 menu callback'), (0x424767, 'ff9208020000', 'objective helper before controller'), (0x424bfc, 'ff92a4010000', 'rising helper before controller'), (0x424c08, 'ff90a8010000', 'shadow helper before controller'), (0x424c2b, 'ff9094010000', 'airborne sound cleanup'), (0x424c3f, 'ff92c8010000', 'post-controller Invisible helper'), (0x424c88, 'ff92b4010000', 'post-controller impact helper'), (0x424c94, 'ff90b0010000', 'post-controller root history helper'), (0x425521, 'ff9214030000', 'history root setter'), (0x425142, '668986c4070000', 'ceiling fall mode remains1'), (0x424ea6, '0f8564020000', 'non-Invisible upkeep return'), ) def generate(original, output, rea): original, output = Path(original).resolve(), Path(output).resolve() if output.is_relative_to(original) or original.is_relative_to(output): raise ValueError('Output must be separate from originals') pe = PE(find_case(original, 'Neutron.exe')) if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256: raise ValueError('Unexpected source EXE') record = next(r for r in json.loads(Path(rea).read_text())['records'] if r['evidence_id'] == REA_ID) if record['subject']['digest']['sha256'] != EXE_SHA256: raise ValueError('REA subject identity mismatch') for table, slot, target in SLOTS: if struct.unpack('1e-6: raise ValueError('Movement state changed outside controller') if row['current'] != '13,155,17' or row['target'] != '-40,154,-12': raise ValueError('Euler changed outside controller') paths = [output/'probe.exe', output/'jimmy_derived_frame_probe.c', output/'source.json', capture/'wine.log', capture/'capture.json', capture/'game/Neutron.exe'] if hashlib.sha256(paths[-1].read_bytes()).hexdigest() != EXE_SHA256: raise ValueError('Executed mapped source copy identity') result = dict(cases=cases, source_sha256=EXE_SHA256, rea_evidence_id=REA_ID, provenance={str(p):hashlib.sha256(p.read_bytes()).hexdigest() for p in paths}, scope='50 derived-caller cases; recorded controller, no-hit world queries and UI adapters.') (output.parent/'native-observations.json').write_text(json.dumps(result, indent=2)+'\n') return dict(cases=len(cases), wine_exit=0) if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('original', type=Path) parser.add_argument('--output', type=Path, required=True) parser.add_argument('--rea', type=Path, required=True) parser.add_argument('--capture', type=Path) args = parser.parse_args() result = generate(args.original, args.output, args.rea) if args.capture: result['observations'] = observe(args.output, args.capture) print(json.dumps({k:v for k,v in result.items() if k != 'rea_extracts'}, indent=2))