Preserve retained Jimmy update order on initial story entry

This commit is contained in:
UnixNight committed 2026-11-06 17:08:59 -05:00
1 parent 4cd62d3627
commit ea04210f52
24 files changed
+1209 -22

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
"""Guard the original menu background and successful TSK-to-level reuse chain.
This proves a conditional source lifecycle, not a whole-original Carl capture.
Originals remain read-only; output contains source coordinates and evidence.
"""
import argparse
import hashlib
import json
from pathlib import Path
import re
import struct
import sys
from checkpoint_script_state import EXE_SHA256, find_case, read_va, rel_call_target
from pe_inspect import PE
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/'levels'))
import gam
REA_ID = 'ev_0d64cc58fa8f5573fc8e61e0f2c20e36288099212bd2257d3a3121361fd6c904'
CALLS = ((0x46a641, 0x46b160), (0x46a660, 0x46a310), (0x46a33d, 0x44d0e0),
(0x44d122, 0x459110), (0x404b54, 0x460e70), (0x460ef0, 0x4603f0),
(0x4587f3, 0x470540), (0x46e0d9, 0x473710))
SITES = (
(0x46ba18, '899d08080000', 'initial splash stage0'),
(0x46bf07, 'd81da0e54800', 'strict elapsed3s stage gate'),
(0x46bfef, 'c7860808000002000000', 'stage1 to stage2'),
(0x46bff9, '68004a4f00', 'background level1d.gam'),
(0x46c004, 'ff9214010000', 'delayed background request app114'),
(0x46dfb6, '66c781fa0700000200', 'two-callback countdown'),
(0x46bedf, 'c6864c07000001', 'countdown underflow requests teardown/load'),
(0x46c05e, 'ff9204010000', 'consume pending request app104'),
(0x46e5c3, 'ff5228', 'every existing nonnull object gets Init28'),
(0x4705b3, 'ff978c000000', 'Init reads stored lifetime'),
(0x4705bc, 'ff9704020000', 'Init restores live lifetime'),
(0x460a50, '8b0de4995000', 'TSK character request requires raw controlled owner'),
(0x460a65, 'ff5218', 'TSK owner must accept C3DJIMMY type'),
(0x460bd1, 'ff9268010000', 'TSK requests level through player168'),
(0x42275a, 'c685c900000001', 'Jimmy reusable game09=1'),
)
SLOTS = ((0x4d5ea0, 0xc4, 0x46bec0), (0x4d5ea0, 0x114, 0x46dfb0),
(0x4d5ea0, 0x104, 0x46dff0), (0x4d5ea0, 0x128, 0x46e570),
(0x4d0c0c, 0x28, 0x44d4e0), (0x4c444c, 0x28, 0x44d4e0),
(0x4d0c0c, 0x200, 0x4719b0), (0x4c444c, 0x200, 0x4719b0),
(0x4d0c0c, 0x420, 0x472970), (0x4c444c, 0x420, 0x472970),
(0x4d0c0c, 0x40c, 0x44df30), (0x4c444c, 0x40c, 0x44df30),
(0x4a3bdc, 0x168, 0x43b5a0), (0x4a373c, 0x200, 0x4719b0),
(0x4a373c, 0x420, 0x472970))
RANGES = ((0x46b9e0, 0x46ba2a), (0x46bec0, 0x46c067), (0x46df70, 0x46dfe5),
(0x44d0e0, 0x44d161), (0x460e70, 0x460f00), (0x460a50, 0x460bdd),
(0x46e570, 0x46e680), (0x46e6a0, 0x46e710), (0x46ff4a, 0x46ff81),
(0x4226b5, 0x4226c5), (0x422750, 0x422765), (0x44df30, 0x44df44))
def collect(original, rea):
pe = PE(find_case(original, 'Neutron.exe'))
if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256:
raise ValueError('Unexpected executable')
if struct.unpack('<f', read_va(pe, 0x48e5a0, 4))[0] != 3:
raise ValueError('Splash duration changed')
if read_va(pe, 0x4f4a00, 12) != b'level1d.gam\0':
raise ValueError('Background filename changed')
if read_va(pe, 0x4ecb20, 9) != b'C3DJIMMY\0':
raise ValueError('TSK receiver class changed')
for a, b in CALLS:
if rel_call_target(pe, a) != b:
raise ValueError(f'Call {a:x}')
for a, expected, name in SITES:
if read_va(pe, a, len(bytes.fromhex(expected))).hex() != expected:
raise ValueError(f'{name} at {a:x}')
for table, slot, expected in SLOTS:
if struct.unpack('<I', read_va(pe, table+slot, 4))[0] != expected:
raise ValueError(f'Binding {table:x}+{slot:x}')
levels=[]
for filename in ('level1d.gam', 'level1b.gam'):
path=find_case(original, 'gam/'+filename)
level=gam.parse(path.read_bytes())
jimmy=next(e for e in level.entities if e.kind=='3JIM')
levels.append(dict(file=filename, sha256=hashlib.sha256(path.read_bytes()).hexdigest(),
code=level.code, count=len(level.entities), jimmy_offset=jimmy.offset,
jimmy_tag=jimmy.values()['ObjectTag']))
record=next(r for r in json.loads(Path(rea).read_text())['records'] if r['evidence_id']==REA_ID)
if record['subject']['digest']['sha256'] != EXE_SHA256:
raise ValueError('REA subject mismatch')
rows=[]
for line in record['raw_result']['stdout'].splitlines():
m=re.match(r'\s*([0-9a-f]+):',line)
if m:rows.append((int(m[1],16),line))
extracts={hex(a):'\n'.join(l for va,l in rows if a<=va<b)+'\n' for a,b in RANGES}
if any(not s.strip() for s in extracts.values()):
raise ValueError('Missing retained instructions')
return dict(source_sha256=EXE_SHA256, rea_evidence_id=REA_ID, levels=levels,
calls=[dict(va=hex(a), target=hex(b), file_offset=hex(pe.offset(a-pe.base)))for a,b in CALLS],
sites=[dict(va=hex(a), bytes=e, role=n, file_offset=hex(pe.offset(a-pe.base)))for a,e,n in SITES],
slots=[dict(table=hex(t), slot=hex(s), target=hex(v), file_offset=hex(pe.offset(t+s-pe.base)))for t,s,v in SLOTS],
ranges=[dict(va=hex(a),length=b-a,file_offset=hex(pe.offset(a-pe.base)),sha256=hashlib.sha256(read_va(pe,a,b-a)).hexdigest())for a,b in RANGES],
rea_extracts=extracts,
scope='Conditional successful TSK entry reuses existing Jimmy; source lifecycle, not a native Windows/Carl trace.')
if __name__=='__main__':
cli=argparse.ArgumentParser(description=__doc__)
cli.add_argument('original',type=Path)
cli.add_argument('--rea',type=Path,required=True)
args=cli.parse_args()
print(json.dumps(collect(args.original,args.rea),indent=2))