#!/usr/bin/env python3 """Guard/generate complete mode2 context and static reclip component evidence.""" import argparse,hashlib,json,struct from pathlib import Path from collision_dispatch import collect as dispatch_collect,POINTERS from collision_response import header from checkpoint_script_state import find_case,read_va from pe_inspect import PE START,END=0x47a5e0,0x47b3dc DIGEST='9bb2c187d12f73a73f4ac2f31e19072d9010f919ce93fb6884e2be35b2fac894' def collect(original): report=dispatch_collect(original);pe=PE(find_case(Path(original),'Neutron.exe')) body=read_va(pe,START,END-START) if hashlib.sha256(body).hexdigest()!=DIGEST:raise ValueError('Changed mode2 routine/table') report['bodies'].append(dict(name='mode2_box',va=hex(START),file_offset=hex(pe.offset(START-pe.base)),length=END-START,sha256=DIGEST)) jumps=struct.unpack('<12I',read_va(pe,0x47b3ac,48)) for target in sorted(set((*POINTERS,0x695d45,0x47b3ac,*jumps))): encoded=struct.pack('=0:raise ValueError('Kernel winding/normal relationship changed') files=[directory/'wine.log',directory/'capture.json',directory/'probe-identity.json',output/'source.json', *(output/name for name in ('dynamic_context_probe.c','collision_dispatch_probe.c', 'collision_response_probe.c','collision_response_relocations.h','probe.exe'))] result=dict(cases=cases,kernel_triangles=triangles[0],provenance={str(p):sha(p) for p in files},scope=source['scope']) (output/'observations.json').write_text(json.dumps(result,indent=2)+'\n') return dict(cases=len(cases),scope=source['scope']) if __name__=='__main__': cli=argparse.ArgumentParser(description=__doc__);cli.add_argument('original',type=Path) cli.add_argument('--output',type=Path);cli.add_argument('--capture',type=Path);args=cli.parse_args() if args.capture and not args.output:cli.error('--capture requires --output') print(json.dumps(capture(args.output,args.capture) if args.capture else generate(args.original,args.output) if args.output else collect(args.original),indent=2))