Recover actor normal callbacks and late collision reads
This commit is contained in:
1 parent
bf876e9c3c
commit
bdca29d3aa
19 files changed
+963
-1
No files matched your search
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guard and execute original normal callbacks on bounded synthetic actors."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
from dynamic_context import collect as dynamic_collect
|
||||
from collision_response import header
|
||||
from checkpoint_script_state import find_case,read_va
|
||||
from pe_inspect import PE
|
||||
from physical_registration import CLASSES
|
||||
from dynamic_reclip import differences
|
||||
|
||||
CALLBACKS=(('jimmy_wall',0x42a660,0x42a714),('player_wall',0x43aa40,0x43afe3),
|
||||
('base_ceiling',0x472690,0x47274a),('base_wall',0x458890,0x4588cd),
|
||||
('reflection',0x472750,0x472970),('soldier_wall',0x409590,0x4095ee))
|
||||
# Complete operands reviewed within individual instructions in retained REA
|
||||
# ev_0d64cc58fa8f5573fc8e61e0f2c20e36288099212bd2257d3a3121361fd6c904.
|
||||
# A numeric scan across instruction boundaries incorrectly selected4095BE.
|
||||
CALLBACK_OPERANDS=(
|
||||
(0x42a663,0x4f0588),(0x42a678,0x4f8210),(0x42a69d,0x4f82bc),
|
||||
(0x42a6a3,0x4f82c0),(0x42a6b1,0x4f82bc),(0x42a6bb,0x4f82c0),
|
||||
(0x42a6cd,0x49d5b4),(0x43aa52,0x48e5a0),(0x43ab58,0x48d400),
|
||||
(0x43abd2,0x4f0668),(0x43ac25,0x48d108),(0x43ac3c,0x48e5b4),
|
||||
(0x43acb9,0x4f0668),(0x43ad05,0x4afd40),(0x43ad9d,0x48e5ec),
|
||||
(0x43adbd,0x48d400),(0x43ae4c,0x48e5ec),(0x43ae6c,0x48d400),
|
||||
(0x43af16,0x48d108),(0x43af30,0x48e5b4),(0x43afd1,0x4f0670),
|
||||
(0x4726ac,0x48d914),(0x472703,0x48d914),(0x47278f,0x48d104),
|
||||
(0x47279d,0x48d104),(0x4727a3,0x48d924),(0x472882,0x48d108),
|
||||
(0x4728b1,0x48e5b4),(0x4728bb,0x48d104),(0x4728c1,0x48d924),
|
||||
(0x472900,0x48e5b4),(0x47290a,0x48d914),(0x472917,0x48e5b0),
|
||||
(0x472924,0x48e5c4),(0x47292c,0x48e5c0),(0x472939,0x48e5c4),
|
||||
(0x47294a,0x4d5fd8))
|
||||
GETTERS=((0x1d0,0x4718f0,'8a813c010000c3',0x13c),
|
||||
(0x1d8,0x471910,'8a813d010000c3',0x13d),
|
||||
(0x1e0,0x471930,'8a8137010000c3',0x137),
|
||||
(0x248,0x471ad0,'d98150010000c3',0x150),
|
||||
(0x260,0x471b30,'d9815c010000c3',0x15c))
|
||||
SLOTS=(0x370,0x374,0x378,0x1d0,0x1d8,0x1e0,0x248,0x260,0x270,0x274,0x2b8,0x2bc,0x2c0,0x2c4)
|
||||
CASES=('jimmy_null','jimmy_jetpack','jimmy_ordinary_polygon','jimmy_elapsed_gate',
|
||||
'jimmy_mode1','jimmy_mode2','jimmy_uncontrolled','jimmy_gadget7_inactive',
|
||||
'jimmy_gadget7_equal','jimmy_gadget7_large','ceiling_positive','ceiling_negative',
|
||||
'ceiling_velocity_only','ceiling_acceleration_only','generic_disabled','generic_axis',
|
||||
'generic_no_damping','generic_excess_damping','generic_oblique','generic_fresh_y',
|
||||
'soldier_mode0','soldier_mode10','soldier_mode10_disabled','dynamic_jimmy',
|
||||
'dynamic_generic','dynamic_soldier','late_inhibition','late_radius','late_geometry','late_force')
|
||||
|
||||
|
||||
def collect(original):
|
||||
report=dynamic_collect(original);pe=PE(find_case(Path(original),'Neutron.exe'))
|
||||
for name,start,end in CALLBACKS:
|
||||
code=read_va(pe,start,end-start)
|
||||
report['bodies'].append(dict(name=name,va=hex(start),file_offset=hex(pe.offset(start-pe.base)),
|
||||
length=end-start,sha256=hashlib.sha256(code).hexdigest()))
|
||||
for va,target in CALLBACK_OPERANDS:
|
||||
if read_va(pe,va,4)!=struct.pack('<I',target):raise ValueError('Changed reviewed operand')
|
||||
report['probe_operands'].append(dict(va=va,target=target))
|
||||
report['probe_operands'].sort(key=lambda p:p['va'])
|
||||
bindings=[]
|
||||
for kind,name,ctor,table,displacement,*_ in CLASSES:
|
||||
bindings.append(dict(kind=kind,name=name,table=hex(table),displacement=hex(displacement),
|
||||
table_file_offset=hex(pe.offset(table-pe.base)),
|
||||
methods={hex(slot):hex(struct.unpack('<I',read_va(pe,table+slot,4))[0]) for slot in SLOTS}))
|
||||
report['normal_bindings']=bindings
|
||||
getters=[]
|
||||
for slot,va,code,field in GETTERS:
|
||||
if read_va(pe,va,len(bytes.fromhex(code))).hex()!=code:raise ValueError('Changed scalar getter')
|
||||
if any(c['methods'][hex(slot)]!=hex(va) for c in bindings):raise ValueError('Getter override requires separate recovery')
|
||||
getters.append(dict(slot=hex(slot),va=hex(va),file_offset=hex(pe.offset(va-pe.base)),field=hex(field),bytes=code))
|
||||
report['scalar_getters']=getters
|
||||
report['scope']='Complete normal callbacks and dynamic/static kernels, synthetic actor/getters/grid; Soldier complete174 and Jimmy204 are record-only stubs, not executed policies.'
|
||||
return report
|
||||
|
||||
|
||||
def generate(original,output):
|
||||
original,output=Path(original).resolve(),Path(output).resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):raise ValueError('Separate output required')
|
||||
if output.exists() and any(p.is_symlink() for p in output.rglob('*')):raise ValueError('Generated output contains symlinks')
|
||||
report=collect(original);output.mkdir(parents=True,exist_ok=True)
|
||||
for name in ('actor_contact_probe.c','collision_dispatch_probe.c','collision_response_probe.c'):
|
||||
text=Path(__file__).with_name(name).read_text()
|
||||
if name=='collision_dispatch_probe.c':text=text.split('int main(void)')[0]
|
||||
(output/name).write_text(text)
|
||||
(output/'collision_response_relocations.h').write_text(header(report))
|
||||
(output/'source.json').write_text(json.dumps(report,indent=2)+'\n')
|
||||
return dict(bodies=len(report['bodies']),relocations=len(report['probe_operands']),classes=len(report['normal_bindings']))
|
||||
|
||||
|
||||
def capture(output,directory):
|
||||
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
source=json.loads((output/'source.json').read_text());metadata=json.loads((directory/'capture.json').read_text())
|
||||
log=(directory/'wine.log').read_text()
|
||||
if metadata['captures'][-1]['wineExit']!=0 or 'ACTOR_CONTACT_COMPLETE' not in log:raise ValueError('Incomplete execution')
|
||||
for name,key in [('Neutron.exe','sha256'),('OMT2.dll','omt_sha256')]:
|
||||
if sha(find_case(directory/'game',name))!=source[key]:raise ValueError('Copied source identity mismatch')
|
||||
if json.loads((directory/'probe-identity.json').read_text())['sha256']!=sha(output/'probe.exe'):raise ValueError('Probe identity mismatch')
|
||||
cases=[json.loads(line[6:]) for line in log.splitlines() if line.startswith('ACTOR ')]
|
||||
if tuple(c['name'] for c in cases)!=CASES:raise ValueError('Incomplete case sequence')
|
||||
files=[directory/'wine.log',directory/'capture.json',directory/'probe-identity.json',
|
||||
*(output/name for name in ('source.json','actor_contact_probe.c','collision_dispatch_probe.c',
|
||||
'collision_response_probe.c','collision_response_relocations.h','probe.exe'))]
|
||||
(output/'observations.json').write_text(json.dumps(dict(cases=cases,scope=source['scope'],
|
||||
provenance={str(p):sha(p) for p in files}),indent=2)+'\n')
|
||||
return dict(cases=len(cases),scope=source['scope'])
|
||||
|
||||
|
||||
def compare(output,managed):
|
||||
native=json.loads((output/'observations.json').read_text());actual=json.loads(managed.read_text())
|
||||
if any(tuple(c['name'] for c in data['cases'])!=CASES for data in (native,actual)):
|
||||
raise ValueError('Case sequence differs')
|
||||
cases=[dict(name=a['name'],differences=differences(a,b)) for a,b in zip(native['cases'],actual['cases'])]
|
||||
result=dict(exact_cases=sum(not c['differences'] for c in cases),total_cases=len(cases),cases=cases,
|
||||
scope='Exact float32 numeric values and full emitted state/trace; derived endpoints remain synthetic.')
|
||||
(output/'comparison.json').write_text(json.dumps(result,indent=2)+'\n')
|
||||
return result
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__);cli.add_argument('original',type=Path)
|
||||
cli.add_argument('--output',type=Path,required=True);mode=cli.add_mutually_exclusive_group()
|
||||
mode.add_argument('--capture',type=Path);mode.add_argument('--managed',type=Path);args=cli.parse_args()
|
||||
print(json.dumps(compare(args.output,args.managed) if args.managed else
|
||||
capture(args.output,args.capture) if args.capture else generate(args.original,args.output),indent=2))
|
||||
Reference in new issue
Block a user