Implement Grappler scalar component with original-code references
This commit is contained in:
1 parent
70cba65c1f
commit
0c913d15aa
18 files changed
+1014
-14
No files matched your search
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guarded Grappler scalar spans and copied-original reference import.
|
||||
|
||||
No target execution here. Probe execution uses reference_capture.py with a
|
||||
generated Win32 harness and copied installation in a separate namespace.
|
||||
"""
|
||||
import argparse
|
||||
from collections import Counter
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from grappler import collect as source_contract
|
||||
from checkpoint_script_state import find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
RANGES=(('attach',0x426be8,0x426c70),('held',0x426dac,0x426dd5),
|
||||
('fast',0x429dc9,0x429df5),('swing',0x42a077,0x42a1a2))
|
||||
|
||||
|
||||
def collect(original):
|
||||
contract=source_contract(original)
|
||||
pe=PE(find_case(Path(original),'Neutron.exe'))
|
||||
return dict(source_sha256=contract['sha256'],ranges=[dict(kind=kind,va=hex(start),
|
||||
end_va=hex(end),file_offset=hex(pe.offset(start-pe.base)),
|
||||
sha256=hashlib.sha256(read_va(pe,start,end-start)).hexdigest()) for kind,start,end in RANGES],
|
||||
scope='Isolated scalar prefixes/suffixes; no ray, body, camera, renderer or original gameplay execution')
|
||||
|
||||
|
||||
def reference(original,log,executable):
|
||||
result=collect(original)
|
||||
log=Path(log);text=log.read_text()
|
||||
if 'GRAPPLER_SCALARS_COMPLETE' not in text:raise ValueError('Probe did not finish')
|
||||
cases=[]
|
||||
for line in text.splitlines():
|
||||
m=re.fullmatch(r'CASE (attach|held|fast|swing) (\w+) in=([^ ]+) out=([^ ]+)',line)
|
||||
if not m:continue
|
||||
kind,name,inputs,outputs=m.groups()
|
||||
cases.append(dict(kind=kind,name=name,input=[float(x) for x in inputs.split(',')],
|
||||
observed=[float(x) for x in outputs.split(',')]))
|
||||
if Counter(c['kind'] for c in cases)!=dict(attach=8,held=6,fast=6,swing=10):
|
||||
raise ValueError('Incomplete or duplicate scalar cases')
|
||||
result.update(generator_sha256=hashlib.sha256(Path(__file__).with_name('grappler_scalar_probe.c').read_bytes()).hexdigest(),
|
||||
executable_sha256=hashlib.sha256(Path(executable).read_bytes()).hexdigest(),
|
||||
log_sha256=hashlib.sha256(log.read_bytes()).hexdigest(),cases=cases)
|
||||
return result
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('original',type=Path);cli.add_argument('--log',type=Path)
|
||||
cli.add_argument('--executable',type=Path);cli.add_argument('--output',type=Path)
|
||||
args=cli.parse_args()
|
||||
if bool(args.log)!=bool(args.executable):cli.error('--log and --executable are required together')
|
||||
if args.output:
|
||||
source=args.original.resolve();target=args.output.resolve()
|
||||
if target.is_relative_to(source) or source.is_relative_to(target):
|
||||
cli.error('Output must be separate from originals')
|
||||
result=reference(args.original,args.log,args.executable) if args.log else collect(args.original)
|
||||
text=json.dumps(result,indent=2)+'\n'
|
||||
if args.output:args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_text(text)
|
||||
else:print(text,end='')
|
||||
Reference in new issue
Block a user