367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
163 lines
11 KiB
Python
163 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify the actual private Forever engine's native character phase.
|
|
|
|
Requires serve-poll-host already owning the private client. Performs only fixed
|
|
bindings/public inspection; all SRP/world packets run inside WowB. Never types
|
|
credentials or starts a gateway. Partial character UI is reported as partial.
|
|
"""
|
|
import argparse,json,socket,time
|
|
from pathlib import Path
|
|
from client_installation import client_debug_socket
|
|
from native_test_guard import require_authenticated_turtle_realm,require_local_turtle_ports
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
class Controller:
|
|
def __init__(self,pid):self.pid=pid;self.timings={}
|
|
def rpc(self,operation,**fields):
|
|
with socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) as peer:
|
|
peer.settimeout(5);peer.connect(str(client_debug_socket(ROOT)))
|
|
peer.sendall(json.dumps({'operation':operation,**fields}).encode());raw=b''
|
|
while chunk:=peer.recv(65536):
|
|
raw+=chunk
|
|
if len(raw)>65536:raise RuntimeError('Fixed diagnostic response exceeded bound')
|
|
if not raw.startswith(b'OK\n'):raise RuntimeError(raw.decode(errors='replace'))
|
|
try:return json.loads(raw[3:])
|
|
except ValueError:return raw[3:].decode().strip()
|
|
def wait(self,predicate,timeout):
|
|
deadline=time.monotonic()+timeout
|
|
while True:
|
|
result=predicate()
|
|
if result:return result
|
|
if time.monotonic()>=deadline:raise RuntimeError('Bounded native readiness wait expired')
|
|
time.sleep(.05)
|
|
def action(self,operation,**fields):
|
|
start=time.monotonic();published=time.time();until=start+8
|
|
while True:
|
|
try:self.rpc(operation,**fields);break
|
|
except RuntimeError as error:
|
|
# No command is published before this fixed preflight rejection.
|
|
if operation!='open-native-engine-realm-with-pipe' or 'Original engine open/setup code not naturally ready' not in str(error) or time.monotonic()>=until:raise
|
|
time.sleep(.05)
|
|
path=ROOT/'runtime'/(operation+'-trace.json')
|
|
def completed():
|
|
try:
|
|
if path.stat().st_mtime<published:return False
|
|
row=json.loads(path.read_text())
|
|
except (FileNotFoundError,json.JSONDecodeError):
|
|
# The existing producer may truncate/write this result before
|
|
# publishing its final JSON. Retry only the read, never the
|
|
# engine operation; the normal deadline and binding checks stay.
|
|
return False
|
|
if row.get('pid')!=self.pid or row.get('status') in ('hardware-breakpoint-armed','followup-data-binding-armed'):return False
|
|
if row.get('status')!='engine-safepoint-data-binding' or not row.get('hardware_registers_restored'):raise RuntimeError('Native data binding failed; diagnostic client preserved')
|
|
return row
|
|
trace=self.wait(completed,8);self.timings[operation]=round(time.monotonic()-start,3);return trace
|
|
def activate_realm_ui(self,readiness):
|
|
"""Opt in once and observe command12 before any original Login arm."""
|
|
self.action('activate-source-realm-ui',readiness=readiness)
|
|
def acknowledged():
|
|
frame=self.rpc('inspect-wire-frame')
|
|
if frame['command'] in (11,-11):return False
|
|
if(frame['command']!=12 or frame['error'] or frame['api_result'] or
|
|
not frame['completed'] or frame['abi_echo']!=1):
|
|
raise RuntimeError('Source realm UI activation failed; no account publication')
|
|
return frame
|
|
frame=self.wait(acknowledged,5)
|
|
from engine_wire_host import _require_idle_realm_ui
|
|
_require_idle_realm_ui(self.rpc('inspect-wire-account').get('source_ui',{}),required=True)
|
|
return frame
|
|
def prepare_original_login(self,*,retirement_generation=None,source_realm_ui_readiness=None):
|
|
"""Reuse only an idle verified binding after pre-password UI failure."""
|
|
account=None
|
|
path=ROOT/'runtime/engine-poll-binding.json'
|
|
binding=json.loads(path.read_text()) if path.exists() else {}
|
|
if binding.get('pid')==self.pid and not binding.get('restored'):
|
|
listener=json.loads((ROOT/'runtime/engine-listener-binding.json').read_text())
|
|
frame=self.rpc('inspect-wire-frame');account=self.rpc('inspect-wire-account')
|
|
facts=self.rpc('inspect-engine-listener')
|
|
if retirement_generation is not None:
|
|
ack=self.rpc('inspect-native-session-retirement')
|
|
from launcher_account_generation import require_retirement_ack
|
|
expected=binding.get('retired_credentials_generation')
|
|
verified=require_retirement_ack(dict(expected_credentials_generation=expected,owner=binding.get('owner')),ack)
|
|
memory=account.get('memory_credentials',{})
|
|
if(verified!=retirement_generation or binding.get('credentials_generation')!=verified or
|
|
not binding.get('wire_ping_only')or listener.get('pid')!=self.pid or listener.get('restored')or
|
|
facts['stage']!=1 or facts['error']or frame['command']!=10 or frame['error']or not frame['completed']or
|
|
account['state']!=0 or account['server_proof_verified']or account.get('transport_prepared')or
|
|
any(memory.get(key)!=0 for key in ('state','generation','consumed_generation','username_bytes','password_bytes'))):
|
|
raise RuntimeError('Retired generation is not pristine; preserve session')
|
|
elif (not binding.get('wire_ping_only') or listener.get('pid')!=self.pid or listener.get('restored') or
|
|
facts['stage']!=1 or facts['error'] or frame['command'] not in ((2,12) if source_realm_ui_readiness is not None else (2,)) or account['state']!=0 or
|
|
account['server_proof_verified'] or account['memory_credentials']['state']!=0):
|
|
raise RuntimeError('Existing binding is not an idle original-login preparation; preserve session')
|
|
else:
|
|
self.action('install-engine-listener-observer');self.action('install-engine-wire-ping')
|
|
frame=self.wait(lambda:(row if (row:=self.rpc('inspect-wire-frame'))['completed'] else False),5)
|
|
if frame['error'] or frame['api_result'] or not frame['completed'] or frame['abi_echo']!=1:
|
|
raise RuntimeError('Owned scalar ABI not verified; no credential input')
|
|
if account is None:account=self.rpc('inspect-wire-account')
|
|
if(account.get('state')!=0 or account.get('server_proof_verified') or account.get('transport_prepared') or
|
|
account.get('memory_credentials',{}).get('state')!=0):
|
|
raise RuntimeError('Original login preparation is not an idle owned account; preserve session')
|
|
if source_realm_ui_readiness is not None:
|
|
frame=self.activate_realm_ui(source_realm_ui_readiness)
|
|
return frame
|
|
def start(self, observe_boundary=None):
|
|
self.action('install-engine-listener-observer');self.action('install-engine-wire-ping')
|
|
self.wait(lambda:self.rpc('inspect-wire-frame')['completed'],5)
|
|
frame=self.rpc('inspect-wire-frame')
|
|
if frame['error'] or frame['api_result'] or frame['abi_echo']!=1:raise RuntimeError('Owned scalar ABI did not verify')
|
|
self.action('start-engine-wire-account')
|
|
account=self.wait(lambda:(r if (r:=self.rpc('inspect-wire-account'))['state']!=1 else False),15)
|
|
if account['state']!=2 or account['server_proof_verified']!=1 or account['transport_prepared']!=1:raise RuntimeError('Genuine account channel not prepared; no engine open requested')
|
|
self.action('probe-engine-wire-channel');self.wait(lambda:self.rpc('inspect-wire-frame')['command']==6,3)
|
|
self.action('open-native-engine-realm-with-pipe')
|
|
if observe_boundary:
|
|
self.rpc('observe-engine-boundary',boundary=observe_boundary)
|
|
self.wait(lambda:(r if (r:=self.rpc('inspect-engine-pipe'))['error'] or r['roster_queued'] else False),8)
|
|
return account
|
|
|
|
def local_listeners():
|
|
ports=set()
|
|
for name in ('tcp','tcp6'):
|
|
for line in Path('/proc/net',name).read_text().splitlines()[1:]:
|
|
fields=line.split()
|
|
if fields[3]=='0A':ports.add(int(fields[1].split(':')[1],16))
|
|
return ports
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--evidence',type=Path,default=ROOT/'runtime/native-engine-character-check.json')
|
|
parser.add_argument('--observe-race-class-vector-copy',action='store_true',
|
|
help='Arm a fixed code-only observer immediately after native pipe setup and before roster readiness polling')
|
|
args=parser.parse_args();path=args.evidence.resolve()
|
|
if not path.is_relative_to(ROOT/'runtime'):parser.error('Keep unreviewed actual-client evidence in runtime')
|
|
ports=local_listeners()
|
|
require_local_turtle_ports(ports)
|
|
pid=int((ROOT/'runtime/native-client.pid').read_text());controller=Controller(pid)
|
|
from client_session import Session
|
|
with Session(pid) as session:
|
|
if session.state()!='login':raise RuntimeError('Require ready private native login; preserve other active sessions')
|
|
started=time.monotonic();account=controller.start('race-class-vector-copy' if args.observe_race_class_vector_copy else None)
|
|
require_authenticated_turtle_realm(account)
|
|
# Bound readiness by actual consumer state; do not spend the whole account
|
|
# retention repeatedly taking screenshots of a known pending roster.
|
|
deadline=time.monotonic()+5;engine={}
|
|
while time.monotonic()<deadline:
|
|
engine=controller.rpc('inspect-engine-session')
|
|
if engine.get('netclient',{}).get('lifecycle',{}).get('character_list_consumer_marker'):break
|
|
time.sleep(.1)
|
|
with Session(pid) as session:
|
|
state=session.state()
|
|
if state!='login':session.shot(path.with_suffix('.png'))
|
|
pipe=controller.rpc('inspect-engine-pipe')
|
|
complete=bool(not pipe['error'] and pipe['world_auth'] and state=='characters' and engine.get('netclient',{}).get('lifecycle',{}).get('character_list_consumer_marker'))
|
|
report=dict(pid=pid,ui=state,pipe=pipe,account=account,engine=engine,
|
|
native_character_selection_verified=complete,native_world_entry_verified=False,
|
|
external_gateway_running=False,elapsed_seconds=round(time.monotonic()-started,3),timings=controller.timings,
|
|
client_left_running_for_diagnostics=True,account_retention_limit_seconds=120)
|
|
path.write_text(json.dumps(report,indent=2)+'\n');path.chmod(0o600)
|
|
print(json.dumps(dict(ui=state,world_authenticated=bool(pipe['world_auth']),characters_received=pipe['characters'],adapter_error=pipe['error'],native_character_selection_verified=complete,elapsed_seconds=report['elapsed_seconds'],timings=controller.timings)))
|
|
return 0 if complete else 2
|
|
if __name__=='__main__':raise SystemExit(main())
|