#!/usr/bin/env python3 """Guard bounded VR04 generated-helper constructor and registration leads.""" import argparse import hashlib import json from pathlib import Path import re import struct from checkpoint_script_state import EXE_SHA256,find_case,read_va,rel_call_target from pe_inspect import PE from rtti_map import rtti_map CALLS = ( ('Jimmy baseball loop',0x422633,0x40fc50), ('Player jetpack fire',0x4374df,0x421d80), ('Jimmy owned Rocketship',0x42243f,0x43d840), ('Rocketship FireStrato',0x43d9bc,0x4192e0), ('Jimmy Bubble',0x42232c,0x410840), ('Jimmy Shadow',0x42250c,0x43f640), ('Jimmy TargetCursor',0x42255b,0x4453b0), ('Jimmy PointCursor',0x4225be,0x43bc70), ('Jimmy GraplingHook',0x422800,0x41eeb0), ('Jimmy PostLoad Goddard',0x423c98,0x41c810), ('Jimmy PostLoad Jeep',0x423d1a,0x4211a0), ('Smoke SmokePuff',0x4406b1,0x440980), ('Yokian Shield',0x44a826,0x44b510), ('Yokian conditional Shadow',0x44a88f,0x43f640), ('Goddard Cursor first',0x41ca9c,0x415760), ('Goddard Cursor second',0x41cb09,0x415760), ('Bubble registration',0x410992,0x464210), ('PointCursor registration',0x43bd67,0x4623d0), ('GraplingHook registration',0x41efb4,0x4623d0), ('SmokePuff registration',0x440acc,0x464210), ('Cursor registration',0x415857,0x4623d0), ) CLASSES = ( ('C3DBaseball',0x49141c,0xc8),('C3DJetpackFire',0x4a3160,0xc0), ('C3DFireStrato',0x49bdd4,0xc0),('C3DBubble',0x49250c,0xc8), ('C3DShadow',0x4b37b8,0xc8),('C3DTargetCursor',0x4b9f48,0xc8), ('C3DPointCursor',0x4b0390,0xc0),('C3DGraplingHook',0x49fafc,0xc0), ('C3DJeep',0x4a2aec,0xc0),('C3DSmokePuff',0x4b545c,0xc8), ('C3DYokianShield',0x4c0e24,0xc8),('C3DCursor',0x497620,0xc0), ) SITES = ( ('Baseball explicit PostLoad registration',0x41000c,'ff502c'), ('Jimmy own selected-start registration',0x4238b4,'ff502c'), ('Jimmy owner-driven fire registration',0x4238ef,'ff522c'), ('Jeep InitObject registration',0x421552,'ff522c'), ('Jeep pointer overwritten before allocation test',0x423792,'89bd70090000'), ('Jeep allocation null branch',0x423cee,'85c00f8585000000'), ('Jeep overwrite source register is zero',0x4236fa,'33ff'), ('Baseball loop count20',0x422610,'be14000000'), ('Baseball loop decrement/backedge',0x422695,'4e0f8579ffffff'), ) def collect(original,rea=None): pe=PE(find_case(Path(original),'Neutron.exe')) if hashlib.sha256(pe.data).hexdigest()!=EXE_SHA256:raise ValueError('Original identity mismatch') calls=[] for name,va,target in CALLS: if rel_call_target(pe,va)!=target:raise ValueError(name) calls.append(dict(name=name,va=hex(va),file_offset=hex(pe.offset(va-pe.base)),target=hex(target))) sites=[] for name,va,expected in SITES: if read_va(pe,va,len(bytes.fromhex(expected))).hex()!=expected:raise ValueError(name) sites.append(dict(name=name,va=hex(va),file_offset=hex(pe.offset(va-pe.base)),bytes=expected)) classes=[] for name,table,displacement in CLASSES: candidates=rtti_map(pe,name)['vtables'] if not any(int(t['va'],16)==table and int(t['object_displacement'],16)==displacement for t in candidates): raise ValueError('Helper RTTI/table mismatch') classes.append(dict(name=name,table=hex(table),displacement=hex(displacement), methods={hex(slot):hex(struct.unpack('