80 lines
3.6 KiB
Python
80 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only source guards for VR07 moving targets; projections are not execution."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
from checkpoint_script_state import EXE_SHA256, find_case, read_va
|
|
from pe_inspect import PE
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels'))
|
|
from gam import parse
|
|
|
|
BODIES = (
|
|
('target_constructor', 0x430220, 0x4304F6, '17b53c1d4a2196a52bfc43bb7a96216874d7d8923474a2062513312bbe783ae2'),
|
|
('target_contact', 0x430570, 0x4306A2, 'c5aeee5d71caba224d24159edbfc9a9d835cb4524ae13eee063e69e3187a76c4'),
|
|
('target_frame', 0x4306B0, 0x430860, '85fd36a64db4876ffabe0f66d3897ef0ee95ed1401646591afcff2ebdb55093f'),
|
|
('sprite_postload', 0x441AC0, 0x441B20, '10dcae6c03a8cf9f54aade2062a315179a4de9546f1c36380083edfb3d344062'),
|
|
('vr07_constructor', 0x4573F0, 0x4574D8, '5a4772c281584d37184d99a7b995fa806ff653bc8ed680c75227560663110523'),
|
|
('parent_activation', 0x40E1F0, 0x40E270, '515567cf4a702fa8864c3b714759585e83f34bddb047e8eb762dede3ef480951'),
|
|
)
|
|
TABLES = ((0x4A8A10, 0x40, 0x430570), (0x4A8A10, 0x3C4, 0x4306B0),
|
|
(0x4A8A10, 0x40C, 0x441AC0), (0x4CFAE0, 0x134, 0x475CD0),
|
|
(0x4BE404, 0x428, 0x40E1F0))
|
|
|
|
|
|
def collect(original: Path):
|
|
pe = PE(find_case(original, 'Neutron.exe'))
|
|
if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256:
|
|
raise ValueError('Unexpected original executable identity')
|
|
bodies = []
|
|
for name, start, end, expected in BODIES:
|
|
if hashlib.sha256(read_va(pe, start, end-start)).hexdigest() != expected:
|
|
raise ValueError(f'Changed original span {name}')
|
|
bodies.append(dict(name=name, va=hex(start), fileOffset=hex(pe.offset(start-pe.base)),
|
|
length=end-start, sha256=expected))
|
|
for table, slot, target in TABLES:
|
|
if struct.unpack('<I', read_va(pe, table+slot, 4))[0] != target:
|
|
raise ValueError('Changed original virtual target')
|
|
if read_va(pe, 0x45CA06, 5) != bytes.fromhex('e81538fdff'):
|
|
raise ValueError('Changed 3TAR factory constructor')
|
|
if read_va(pe, 0x475CD0, 5) != bytes.fromhex('32c0c21800'):
|
|
raise ValueError('Changed false game registration filter')
|
|
level = parse(find_case(original, 'gam/VR07.gam').read_bytes())
|
|
targets = [dict(offset=hex(e.offset), properties=e.values()) for e in level.entities if e.kind == '3TAR']
|
|
return dict(sha256=EXE_SHA256, bodies=bodies, targets=targets,
|
|
vtables=[dict(table=hex(t), slot=hex(s), target=hex(f)) for t,s,f in TABLES],
|
|
evidenceType='Static source guards and serialized data, not original runtime')
|
|
|
|
|
|
def hit_target(timer: float, points: int, respawn: float):
|
|
"""430592..4305D1: caller already proved a C3DBASEBALL contact."""
|
|
if timer > 0:
|
|
return dict(accepted=False, hidden=False, timer=timer, points=0)
|
|
return dict(accepted=True, hidden=True, timer=respawn, points=points)
|
|
|
|
|
|
def step_respawn(timer: float, seconds: float):
|
|
"""4306FA..43074F: expiry is <=0 after the stored float subtraction."""
|
|
if timer <= 0:
|
|
return timer, False
|
|
value = struct.unpack('<f', struct.pack('<f', timer-seconds))[0]
|
|
return (0, True) if value <= 0 else (value, False)
|
|
|
|
|
|
def parent_hits(count: int, required: int):
|
|
"""4305FB..430631: strict >, not >=; only after a matching parent lookup."""
|
|
count += 1
|
|
return (0, True) if count > required else (count, False)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cli = argparse.ArgumentParser(description=__doc__)
|
|
cli.add_argument('original', type=Path)
|
|
print(json.dumps(collect(cli.parse_args().original), indent=2))
|