367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
217 lines
11 KiB
Python
217 lines
11 KiB
Python
"""Prepare one owned, three-stop MapAreaLOD role-4 observation.
|
|
|
|
The saved Map1 publication is a prerequisite, not proof of the active WDT.
|
|
This observer changes no engine code or gameplay data and never logs in.
|
|
"""
|
|
import ctypes
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import struct
|
|
import time
|
|
from pathlib import Path
|
|
|
|
from engine_main_thread_probe import Probe, Registers
|
|
from native_registration_trace import exact_owned_image
|
|
import native_client_lifecycle as lifecycle
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
IMAGE_BASE = 0x140000000
|
|
PRE_RVA, RETURN_RVA, LOAD_RVA = 0x20c33cf, 0x20c33d4, 0x20c3408
|
|
CAPTURE_RVA = 0x20c3360
|
|
SAVED_SHA256 = '1054407c28d58c1cb22ef91b4d2bc5f247e63f9997887109eb2685b9346383df'
|
|
EXPECTED_ROOT = '962ade1931a394ede85e589aa80fda9d'
|
|
EXPECTED_BUILD = '2374172947c0f7ff47c0705349483285'
|
|
EXPECTED_WDT = 8560831
|
|
SEED_NAME = 'TelAbim-Async2236958-role-selector-family-20c3360-190.bin'
|
|
|
|
|
|
def signed32(value):
|
|
return ctypes.c_int32(value).value
|
|
|
|
|
|
def mapped_read(pid, address, size):
|
|
if type(address) is not int or address <= 0 or not 0 < size <= 190 or address + size >= 1 << 64:
|
|
raise ValueError('bounded readable address required')
|
|
maps = Path(f'/proc/{pid}/maps').read_text().splitlines()
|
|
readable = False
|
|
for line in maps:
|
|
parts = line.split()
|
|
lo, hi = (int(v, 16) for v in parts[0].split('-'))
|
|
if lo <= address and address + size <= hi and 'r' in parts[1]:
|
|
readable = True
|
|
break
|
|
if not readable:
|
|
raise ValueError('selected mapping is not readable')
|
|
fd = os.open(f'/proc/{pid}/mem', os.O_RDONLY)
|
|
try:
|
|
body = os.pread(fd, size, address)
|
|
finally:
|
|
os.close(fd)
|
|
if len(body) != size:
|
|
raise ValueError('short selected read')
|
|
return body
|
|
|
|
|
|
def saved_prefixes():
|
|
paths = (ROOT / 'runtime' / SEED_NAME, ROOT / 'runtime/Octo-Run-1023/runtime' / SEED_NAME)
|
|
path = next((p for p in paths if p.is_file() and not p.is_symlink()), None)
|
|
if path is None:
|
|
raise ValueError('retained original caller capture required')
|
|
body = path.read_bytes()
|
|
if len(body) != 190 or hashlib.sha256(body).hexdigest() != SAVED_SHA256:
|
|
raise ValueError('retained original caller identity differs')
|
|
return {rva: body[rva - CAPTURE_RVA:rva - CAPTURE_RVA + size]
|
|
for rva, size in ((PRE_RVA, 5), (RETURN_RVA, 3), (LOAD_RVA, 4))}
|
|
|
|
|
|
class CellCapture:
|
|
def __init__(self, pid, base, output, *, read=mapped_read):
|
|
self.pid, self.base, self.output, self.read = pid, base, Path(output), read
|
|
self.partial = self.output.with_suffix('.partial.jsonl')
|
|
self.partial_created = False
|
|
self.probe = None
|
|
self.pre = None
|
|
self.result = {'kind': 'owned-map-lod-role4-cell-observation-v1',
|
|
'candidate_publication_root': EXPECTED_ROOT,
|
|
'candidate_map1_wdt_fdi': EXPECTED_WDT,
|
|
'candidate_context_is_not_runtime_wdt_identity': True,
|
|
'runtime_wdt_identity': 'HELD_UNPROVED',
|
|
'thread_scope': 'owned-main-thread-only', 'events': [],
|
|
'native_code_modified': False, 'runtime_data_modified': False}
|
|
|
|
def save_event(self, event):
|
|
flags = os.O_WRONLY | os.O_CREAT | (os.O_APPEND if self.partial_created else os.O_EXCL)
|
|
flags |= getattr(os, 'O_NOFOLLOW', 0)
|
|
self.partial.parent.mkdir(parents=True, exist_ok=True)
|
|
fd = os.open(self.partial, flags, 0o600)
|
|
with os.fdopen(fd, 'a') as stream:
|
|
stream.write(json.dumps(event) + '\n')
|
|
self.partial_created = True
|
|
self.result['events'].append(event)
|
|
|
|
def finish(self, status, reason):
|
|
self.result.update(status=status, reason=reason)
|
|
self.output.parent.mkdir(parents=True, exist_ok=True)
|
|
fd = os.open(self.output, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
with os.fdopen(fd, 'w') as stream:
|
|
json.dump(self.result, stream, indent=2)
|
|
stream.write('\n')
|
|
|
|
def pre_call(self, pid, regs):
|
|
if pid != self.pid or regs.rip != self.base + PRE_RVA:
|
|
raise ValueError('exact owned pre-call required')
|
|
child, parent = regs.rbx, regs.rcx
|
|
if not child or not parent:
|
|
raise ValueError('owned child and parent required')
|
|
if struct.unpack('<Q', self.read(pid, child + 0x18, 8))[0] != parent:
|
|
raise ValueError('parent argument differs from child')
|
|
coords = self.read(pid, child + 0x4c, 8)
|
|
a, b = signed32(regs.rdx), signed32(regs.r8)
|
|
if struct.unpack('<ii', coords) != (a, b):
|
|
raise ValueError('cell arguments differ from child')
|
|
raw = self.read(pid, parent + 0x438, 40)
|
|
b_min, a_min, b_max, a_max, width, height = struct.unpack_from('<iiiiii', raw)
|
|
table = struct.unpack_from('<Q', raw, 0x20)[0]
|
|
self.pre = dict(child=child, parent=parent, a=a, b=b, rsp=regs.rsp,
|
|
b_min=b_min, a_min=a_min, b_max=b_max, a_max=a_max,
|
|
width=width, height=height, table=table)
|
|
self.save_event(dict(point='pre-call', **self.pre))
|
|
return {'status': 'owned-pre-call-captured', 'active_wdt_identity': 'held'}
|
|
|
|
def current_registers(self):
|
|
regs = Registers()
|
|
self.probe.ptrace('getregs', 0, ctypes.addressof(regs))
|
|
return regs
|
|
|
|
def after_return(self, pid, caller):
|
|
regs = self.current_registers()
|
|
p = self.pre
|
|
if pid != self.pid or regs.rip != self.base + RETURN_RVA or regs.rbx != p['child'] or regs.rsp != p['rsp']:
|
|
raise ValueError('return is not correlated to the owned caller')
|
|
pointer = regs.rax
|
|
self.save_event(dict(point='return', rax=pointer))
|
|
if not pointer:
|
|
self.finish('HELD_NULL_CELL', 'original getter returned null')
|
|
return
|
|
if not (1 <= p['width'] <= 64 and 1 <= p['height'] <= 64 and
|
|
p['a_min'] <= p['a'] <= p['a_max'] and p['b_min'] <= p['b'] <= p['b_max']):
|
|
self.finish('HELD_BOUNDS', 'runtime bounds do not establish a safe compact grid')
|
|
return
|
|
row = signed32((p['b'] - p['b_min']) * p['width'])
|
|
column = signed32(p['a'] - p['a_min'])
|
|
index = row + column
|
|
address = p['table'] + index * 72
|
|
if not (0 <= index < p['width'] * p['height'] and 0 < address < (1 << 64) - 72 and
|
|
pointer == address + 0x20):
|
|
self.finish('HELD_CELL_ADDRESS', 'returned view differs from the bounded saved getter formula')
|
|
return
|
|
raw = self.read(pid, address, 72)
|
|
self.result['record'] = {'address': address, 'index': index, 'bytes_hex': raw.hex(),
|
|
'role4_dword': struct.unpack_from('<I', raw, 0x30)[0]}
|
|
self.result['return_view'] = pointer
|
|
entry = self.base + LOAD_RVA
|
|
self.probe.followup = (entry, self.prefixes[LOAD_RVA], self.at_load)
|
|
self.probe.validate_followup()
|
|
|
|
def at_load(self, pid, caller):
|
|
regs = self.current_registers()
|
|
if (pid != self.pid or regs.rip != self.base + LOAD_RVA or regs.rbx != self.pre['child'] or
|
|
regs.rsp != self.pre['rsp'] or regs.rsi != self.result['return_view']):
|
|
raise ValueError('role-4 load is not correlated to the return')
|
|
value = struct.unpack('<I', self.read(pid, regs.rsi + 0x10, 4))[0]
|
|
if value != self.result['record']['role4_dword']:
|
|
raise ValueError('role-4 load differs from captured record')
|
|
self.save_event(dict(point='role4-load', rsi=regs.rsi, consumed_dword=value))
|
|
self.finish('PASS_SAME_THREAD_CELL_CAPTURE_WDT_IDENTITY_HELD',
|
|
'same caller, return and load correlated; active WDT and serialized-cell association remain unproved')
|
|
|
|
|
|
def start(pid, *, clean_copy, existing_probe):
|
|
if not clean_copy or (existing_probe is not None and (existing_probe.attached or not existing_probe.done)):
|
|
raise ValueError('idle owned private client required')
|
|
launch = lifecycle.read_launch(ROOT, pid)
|
|
if not launch:
|
|
raise ValueError('current owned client lifetime required')
|
|
release = json.loads((ROOT / 'linux-release.json').read_text())
|
|
if release.get('private_asset_publication', {}).get('composed_root') != EXPECTED_ROOT:
|
|
raise ValueError('saved Map6 candidate publication is not active')
|
|
client = ROOT / 'runtime/native-client'
|
|
info = (client / '.build.info').read_text().splitlines()
|
|
names = [v.split('!')[0] for v in info[0].split('|')]
|
|
active = [dict(zip(names, line.split('|'))) for line in info[1:] if line]
|
|
active = [row for row in active if row.get('Active') == '1' and row.get('Product') == 'wow_classic_beta']
|
|
if len(active) != 1 or active[0].get('Build Key') != EXPECTED_BUILD:
|
|
raise ValueError('saved Map6 candidate build is not active')
|
|
config = client / 'Data/config' / EXPECTED_BUILD[:2] / EXPECTED_BUILD[2:4] / EXPECTED_BUILD
|
|
if 'root = ' + EXPECTED_ROOT not in config.read_text().splitlines():
|
|
raise ValueError('candidate build root differs')
|
|
base, mappings = exact_owned_image(Path(f'/proc/{pid}/maps').read_text(), client / '_classic_beta_/WowB.exe')
|
|
if base != IMAGE_BASE:
|
|
raise ValueError('relocated executable is held by the existing probe address guard')
|
|
if not any(lo <= base + PRE_RVA < hi and 'x' in permissions for lo, hi, permissions, _ in mappings):
|
|
raise ValueError('original pre-call is not executable')
|
|
prefixes = saved_prefixes()
|
|
if mapped_read(pid, base + PRE_RVA, len(prefixes[PRE_RVA])) != prefixes[PRE_RVA]:
|
|
raise ValueError('loaded original caller differs from the retained capture')
|
|
stamp = str(time.time_ns())
|
|
directory = ROOT / 'runtime/map-lod-cell-capture'
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
if directory.is_symlink():
|
|
raise ValueError('capture output directory must not be a symlink')
|
|
plan, trace, output = (directory / (stamp + suffix) for suffix in ('-plan.json', '-probe.json', '-cell.private.json'))
|
|
fd = os.open(plan, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
with os.fdopen(fd, 'w') as stream:
|
|
json.dump({'pid': pid, 'login_callback': hex(base + PRE_RVA), 'bridge_callback': '0x0'}, stream)
|
|
observer = CellCapture(pid, base, output)
|
|
observer.result['launch'] = launch
|
|
observer.prefixes = prefixes
|
|
probe = Probe(pid, observe_only=True, plan_path=plan, result_path=trace, armed_timeout=45,
|
|
at_observation=lambda actual, caller: None,
|
|
metadata_at_observation=observer.pre_call,
|
|
followup=(base + RETURN_RVA, prefixes[RETURN_RVA], observer.after_return))
|
|
observer.probe = probe
|
|
return probe, {'status': 'STARTED_NOT_YET_ARMED', 'trace': str(trace), 'output': str(output),
|
|
'partial': str(observer.partial),
|
|
'thread_scope': 'owned-main-thread-only', 'candidate_wdt_identity_is_not_runtime_proof': True}
|