367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
474 lines
31 KiB
Python
474 lines
31 KiB
Python
"""Own-module scalar ABI check at the genuine frame safepoint. No auth/state writes."""
|
|
import hashlib,json,struct,os,ntpath
|
|
from pathlib import Path
|
|
import native_runtime_paths
|
|
import engine_poll_host as host
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
_WINDOWS=os.name=='nt'
|
|
SIZE=1080
|
|
|
|
_WIRE_FILE_IDENTITIES=globals().get('_WIRE_FILE_IDENTITIES',{})
|
|
|
|
def wire_file_identity(path,expected):
|
|
"""Reuse a verified frozen DLL until its actual artifact dependency changes."""
|
|
before=path.stat()
|
|
fingerprint=(str(path),expected,before.st_dev,before.st_ino,before.st_size,before.st_mtime_ns,before.st_ctime_ns)
|
|
if fingerprint in _WIRE_FILE_IDENTITIES:return True
|
|
matched=hashlib.sha256(path.read_bytes()).hexdigest()==expected
|
|
after=path.stat()
|
|
if (before.st_dev,before.st_ino,before.st_size,before.st_mtime_ns,before.st_ctime_ns)!=(after.st_dev,after.st_ino,after.st_size,after.st_mtime_ns,after.st_ctime_ns):
|
|
raise ValueError('Wire artifact changed during identity check')
|
|
if matched:
|
|
if len(_WIRE_FILE_IDENTITIES)>=16:_WIRE_FILE_IDENTITIES.pop(next(iter(_WIRE_FILE_IDENTITIES)))
|
|
_WIRE_FILE_IDENTITIES[fingerprint]=True
|
|
return matched
|
|
|
|
def module_path():
|
|
profile=ROOT/'compat/windows-native.json'
|
|
if _WINDOWS and profile.exists():
|
|
from windows_native_bootstrap import owned_file
|
|
return owned_file(ROOT,json.loads(profile.read_text())['wire'])
|
|
return ROOT/'runtime/native-wine-prefix/drive_c/windows/system32/GWNativeWire.dll'
|
|
|
|
def module(access):
|
|
meta=json.loads((native_runtime_paths.engine_journal(ROOT)).read_text())
|
|
items=meta.get('auxiliary_dependencies',[])
|
|
if meta.get('restored') or len(items)!=1 or items[0].get('file')!='GWNativeWire.dll':raise ValueError('Owned wire dependency unavailable')
|
|
info=items[0];path=module_path()
|
|
if path.is_symlink() or not wire_file_identity(path,info['sha256']):raise ValueError('Wire module identity differs')
|
|
key=lambda value:ntpath.normcase(ntpath.normpath(str(value))) if _WINDOWS else str(value)
|
|
bases=[a for a,_,_,offset,name in access.maps if offset=='00000000' and key(name)==key(path)]
|
|
if len(bases)!=1:raise ValueError('Wire module header unavailable')
|
|
return bases[0],info,meta
|
|
|
|
def prepare_realm_snapshot(access,bridge,bridge_meta,wire,wire_info):
|
|
"""Bind realm facades from the modules already verified by this host.
|
|
|
|
Older providers retain their existing startup path. This does not enable
|
|
the UI control or submit a request. ABI1 remains read-only; ABI2 also binds
|
|
the qualified strict request callback's existing wire target.
|
|
"""
|
|
slot=bridge_meta.get('exports',{}).get('gw_registration_realm_binding')
|
|
if slot is None:return dict(available=False,ready=False)
|
|
data=bridge+slot
|
|
abi,size=struct.unpack('<2I',access.read(data,8))
|
|
if (abi,size) not in ((1,32),(2,40)):
|
|
raise ValueError('Owned realm snapshot binding ABI differs')
|
|
export=wire_info.get('exports',{}).get('gw_wire_account_ui_snapshot')
|
|
if export is None:return dict(available=True,ready=False,held='snapshot-export-unavailable')
|
|
select_export=wire_info.get('exports',{}).get('gw_wire_account_ui_select') if abi==2 else None
|
|
if abi==2 and select_export is None:
|
|
return dict(available=True,ready=False,held='select-export-unavailable')
|
|
pointers=(wire,wire+export) if abi==1 else (wire,wire+export,wire+select_export)
|
|
if any(not access.allowed(target,1,'x') for target in pointers[1:]) or not access.allowed(data,size,'w'):
|
|
raise ValueError('Owned realm snapshot binding is unavailable')
|
|
values=struct.unpack('<4I'+('2Q' if abi==1 else '3Q'),access.read(data,size))
|
|
_,_,ready,error,*old_pointers=values
|
|
if error or ready not in (0,1):
|
|
raise ValueError('Owned realm snapshot binding ABI differs')
|
|
result=dict(available=True,ready=True)
|
|
if abi==2:result['request_ready']=True
|
|
if ready:
|
|
if tuple(old_pointers)!=pointers:raise ValueError('Owned realm snapshot binding differs')
|
|
return result
|
|
if any(old_pointers):raise ValueError('Owned realm snapshot preparation is incomplete')
|
|
# Every required pointer is valid before either facade can observe ready=1.
|
|
access.write(data+16,struct.pack('<'+'Q'*len(pointers),*pointers))
|
|
access.write(data+8,struct.pack('<I',1))
|
|
return result
|
|
|
|
def _realm_ui_pinned_json(reference):
|
|
"""Consume a small owning receipt; never reopen CASC or Source payloads."""
|
|
if not isinstance(reference,dict) or set(reference)!={'path','sha256'}:
|
|
raise ValueError('Pinned Source realm UI receipt required')
|
|
path=Path(reference['path'])
|
|
if not path.is_absolute():path=ROOT/path
|
|
if path.is_symlink() or not path.resolve().is_relative_to(ROOT/'runtime') or not path.is_file() or path.stat().st_size>1048576:
|
|
raise ValueError('Bounded runtime Source realm UI receipt required')
|
|
data=path.read_bytes()
|
|
if hashlib.sha256(data).hexdigest()!=reference['sha256']:
|
|
raise ValueError('Source realm UI receipt identity differs')
|
|
return json.loads(data)
|
|
|
|
def require_realm_ui_readiness(reference):
|
|
"""Use the published pair's existing owning checks, not a second SDK pass."""
|
|
ready=_realm_ui_pinned_json(reference)
|
|
target=ROOT/'runtime/native-client'
|
|
if (ready.get('kind')!='original-Source-realm-UI-CASC-ready-v1' or
|
|
ready.get('status')!='PASS_INSTALLED_SOURCE_REALM_UI_PAIR' or
|
|
ready.get('installed') is not True or ready.get('casc_ready') is not True or
|
|
Path(ready.get('target_root','')).resolve()!=target):
|
|
raise ValueError('Installed CASC-ready Source realm UI pair required')
|
|
consumers=ready.get('consumers',{})
|
|
if set(consumers)!={'realm-list','glue-parent'}:
|
|
raise ValueError('Both original Source realm UI consumers are required')
|
|
stage=_realm_ui_pinned_json(ready.get('stage'))
|
|
check=_realm_ui_pinned_json(ready.get('check'))
|
|
publication=_realm_ui_pinned_json(ready.get('publication'))
|
|
if not isinstance(stage,list) or len(stage)!=2 or {r.get('consumer') for r in stage}!={'realm-list','glue-parent'}:
|
|
raise ValueError('Owning original UI stage pair differs')
|
|
if check.get('status')!='PASS_OFFLINE_ORIGINAL_CONSUMERS_SOURCE_FACTORY_AND_NATIVE_FALLBACK':
|
|
raise ValueError('Owning original UI consumer check is not qualified')
|
|
fdids=[]
|
|
for row in stage:
|
|
name=row['consumer'];declared=consumers[name];fdid=declared.get('file_data_id')
|
|
digest=declared.get('candidate_sha256')
|
|
if (type(fdid)is not int or fdid<=0 or not isinstance(digest,str) or len(digest)!=64 or
|
|
any(c not in '0123456789abcdef' for c in digest) or
|
|
digest!=row.get('candidate',{}).get('sha256') or
|
|
digest!=check.get('candidates',{}).get(name,{}).get('sha256') or
|
|
row.get('source_pending_enabled') is not True or row.get('global_native_APIs_overridden') is not False):
|
|
raise ValueError('Published original UI candidate relationship differs')
|
|
fdids.append(fdid)
|
|
if len(set(fdids))!=2:
|
|
raise ValueError('Original UI consumer FileDataIDs overlap')
|
|
if (publication.get('applied') is not True or Path(publication.get('target','')).resolve()!=target or
|
|
publication.get('composed_root')!=ready.get('composed_root') or
|
|
not isinstance(publication.get('published_build_info_sha256'),str) or
|
|
hashlib.sha256((target/'.build.info').read_bytes()).hexdigest()!=publication['published_build_info_sha256']):
|
|
raise ValueError('Current Source realm UI publication differs')
|
|
return dict(readiness=dict(reference),composed_root=ready['composed_root'],consumers=consumers,
|
|
native_ui_acceptance_verified=False)
|
|
|
|
def activate_realm_ui(pid,caller,*,readiness):
|
|
"""Explicit command11, before original Login can consume a new generation."""
|
|
host.require_safepoint(caller)
|
|
proof=require_realm_ui_readiness(readiness)
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access)
|
|
binding_path=native_runtime_paths.state_file(ROOT,'engine-poll-binding.json')
|
|
binding=json.loads(binding_path.read_text())
|
|
if (binding.get('pid')!=pid or binding.get('restored') or not binding.get('wire_ping_only') or
|
|
access.u64(binding['owner'])!=binding['bound_vtable'] or
|
|
access.u64(binding['bound_vtable']+40)!=binding['wire_frame_callback']):
|
|
raise ValueError('Require verified idle owned wire frame binding')
|
|
exports=info.get('exports',{})
|
|
_require_realm_ui_binding(access,base,info)
|
|
frame=base+exports['gw_wire_frame_data']
|
|
values=struct.unpack('<IIi6IiIIQ',access.read(frame,56))
|
|
if (values[:2]!=(1,SIZE) or values[2] not in (2,10,12) or values[3]!=1 or
|
|
any(values[i] for i in (6,7,8,9)) or values[10]!=1):
|
|
raise ValueError('Require completed idle wire frame before UI activation')
|
|
account=inspect_account(pid)
|
|
memory=account.get('memory_credentials',{})
|
|
if (account.get('state')!=0 or account.get('server_proof_verified') or account.get('transport_prepared') or
|
|
any(memory.get(key)!=0 for key in ('state','consumed_generation','username_bytes','password_bytes'))):
|
|
raise ValueError('Source realm UI activation requires unused original Login input')
|
|
_require_idle_realm_ui(account.get('source_ui',{}),required=True)
|
|
if values[2]==12:
|
|
if binding.get('realm_ui_activation',{}).get('readiness')!=readiness:
|
|
raise ValueError('Existing Source realm UI activation proof differs')
|
|
return
|
|
binding['realm_ui_activation']=proof
|
|
binding_path.write_text(json.dumps(binding,indent=2)+'\n');binding_path.chmod(0o600)
|
|
access.write(frame+8,struct.pack('<i',11))
|
|
finally:access.close()
|
|
|
|
def _require_realm_ui_binding(access,base,info):
|
|
"""Reuse the ABI2 ready-last contract at the explicit action boundary."""
|
|
bridge,bridge_meta=access.module()
|
|
slot=bridge_meta.get('exports',{}).get('gw_registration_realm_binding')
|
|
exports=info.get('exports',{})
|
|
required=('gw_wire_account_ui_snapshot','gw_wire_account_ui_select','gw_wire_account_ui_activate')
|
|
if slot is None or any(name not in exports for name in required):
|
|
raise ValueError('Complete ABI2 Source realm UI exports required')
|
|
if (struct.unpack('<4I3Q',access.read(bridge+slot,40))!=
|
|
(2,40,1,0,base,base+exports[required[0]],base+exports[required[1]]) or
|
|
any(not access.allowed(base+exports[name],1,'x') for name in required)):
|
|
raise ValueError('Complete verified ABI2 Source realm UI binding required')
|
|
|
|
def _require_idle_realm_ui(control,*,required=False):
|
|
# Activation acknowledges the opt-in internally. enabled stays zero until
|
|
# account_start binds an actual memory-input generation, never before it.
|
|
if not control.get('available'):
|
|
if required or control.get('held'):raise ValueError('Source realm UI control is unavailable')
|
|
return
|
|
if any(control.get(key)!=0 for key in ('enabled','request','state','error')):
|
|
raise ValueError('Source realm UI control is not pristine before original Login')
|
|
|
|
def require_account_start_ready(access,base,info,binding):
|
|
"""Gate both existing account publishers before any credential is read."""
|
|
frame=base+info['exports']['gw_wire_frame_data']
|
|
values=struct.unpack('<IIi6IiIIQ',access.read(frame,56))
|
|
if (values[:2]!=(1,SIZE) or values[3]!=1 or any(values[i] for i in (6,7,8,9)) or values[10]!=1):
|
|
raise ValueError('Owned scalar wire ABI must complete before original Login')
|
|
activation=binding.get('realm_ui_activation')
|
|
if activation:
|
|
if values[2]!=12 or not activation.get('readiness'):
|
|
raise ValueError('Explicit Source realm UI activation acknowledgment required before account publication')
|
|
_require_realm_ui_binding(access,base,info)
|
|
elif values[2] not in (2,10):
|
|
raise ValueError('Require idle default wire command before account publication')
|
|
_require_idle_realm_ui(read_ui_realm_control(access,base,info),required=bool(activation))
|
|
return values[2]
|
|
|
|
def install_ping(pid,caller):
|
|
host.require_safepoint(caller)
|
|
def prepare_binding(access,bridge,bridge_meta,binding):
|
|
# The owner still uses its original table while both owned modules and
|
|
# the complete poll/receive clone are prepared. Host publishes last.
|
|
base,info,meta=module(access)
|
|
data=base+info['exports']['gw_wire_frame_data'];callback=base+info['exports']['gw_wire_frame_callback']
|
|
if struct.unpack('<II',access.read(data,8))!=(1,SIZE) or not access.allowed(callback,1,'x'):raise ValueError('Owned wire frame ABI differs')
|
|
if any(access.read(data+8,48)):raise ValueError('Wire frame already active')
|
|
if binding['pid']!=pid or binding['restored']:raise ValueError('Poll binding identity differs')
|
|
receive=bridge+bridge_meta['exports']['gw_packet_receive_callback']
|
|
if not binding.get('packet_host') or access.u64(binding['bound_vtable']+48)!=receive:
|
|
raise ValueError('Verified queued-packet observer binding differs')
|
|
unix=meta['wire_unix_library'];path=Path(unix['wire_unix_path'])
|
|
if os.name=='nt':
|
|
expected=ROOT/'build/GWNativeBackend.dll';codec=ROOT/'build/forever_codec.dll'
|
|
if path!=expected or hashlib.sha256(path.read_bytes()).hexdigest()!=unix['wire_unix_sha256']:raise ValueError('Owned Windows backend identity differs')
|
|
if Path(unix['core_path'])!=expected or unix['core_sha256']!=unix['wire_unix_sha256']:raise ValueError('Windows core identity differs')
|
|
if Path(unix['source_codec_path'])!=codec or hashlib.sha256(codec.read_bytes()).hexdigest()!=unix['source_codec_sha256']:raise ValueError('Owned Windows codec identity differs')
|
|
filename=str(path).encode('utf-16le')
|
|
else:
|
|
if path!=ROOT/'build/libgateway_wine_wire.so' or hashlib.sha256(path.read_bytes()).hexdigest()!=unix['wire_unix_sha256']:raise ValueError('Owned Unix wire identity differs')
|
|
core=Path(unix['core_path'])
|
|
if core!=ROOT/'build/libgateway_native.so' or hashlib.sha256(core.read_bytes()).hexdigest()!=unix['core_sha256']:raise ValueError('Owned wire core identity differs')
|
|
slash=chr(92);filename=(slash+'??'+slash+'Z:'+str(path).replace('/',slash)).encode('utf-16le')
|
|
if len(filename)>1022:raise ValueError('Owned module path exceeds frame bound')
|
|
payload=struct.pack('<9IiIIQ',1,SIZE,1,0,0,0,0,0,0,-1,0,0,binding['data'])+filename+bytes(1024-len(filename))
|
|
realm_snapshot=prepare_realm_snapshot(access,bridge,bridge_meta,base,info)
|
|
binding.update(wire_frame_data=data,wire_frame_callback=callback,wire_ping_only=True,
|
|
realm_snapshot=realm_snapshot)
|
|
record=native_runtime_paths.state_file(ROOT,'engine-poll-binding.json');record.write_text(json.dumps(binding,indent=2)+'\n');record.chmod(0o600)
|
|
access.write(data,payload)
|
|
access.write(binding['bound_vtable']+5*8,struct.pack('<Q',callback))
|
|
host.install(pid,caller,packet=True,prepare_binding=prepare_binding)
|
|
|
|
def inspect(pid):
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);data=base+info['exports']['gw_wire_frame_data']
|
|
raw=access.read(data,56);values=struct.unpack('<IIi6IiIIQ',raw)
|
|
if values[:2]!=(1,SIZE):raise ValueError('Wire frame ABI differs')
|
|
borrowing=values[2] in (5,6)
|
|
return {'kind':'actual-client-owned-channel-borrow' if borrowing else ('actual-client-owned-native-Windows-ABI-scalar-probe'if os.name=='nt'else 'actual-client-owned-Wine-ABI-scalar-probe'),'pid':pid,
|
|
'command':values[2],'completed':values[3]==1,'calls':values[4],
|
|
'windows_thread_id':values[5],'error':values[6],
|
|
'initialize_status':hex(values[7]),'call_status':hex(values[8]),'api_result':values[9],
|
|
'borrowed_world_port' if borrowing else 'abi_echo':values[10],'initialize_and_scalar_call_ms':values[11],
|
|
'authentication_attempted_by_scalar_probe':False,'engine_account_state_changed_by_probe':False,
|
|
'native_character_selection_proven':False,'native_world_entry_proven':False}
|
|
finally:access.close()
|
|
|
|
def probe_channel(pid,caller):
|
|
host.require_safepoint(caller)
|
|
if inspect_account(pid)['state']!=2:raise ValueError('Require genuinely prepared account channel')
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);frame=base+info['exports']['gw_wire_frame_data']
|
|
binding=json.loads((native_runtime_paths.state_file(ROOT,'engine-poll-binding.json')).read_text())
|
|
if binding['pid']!=pid or binding['restored'] or access.u64(binding['owner'])!=binding['bound_vtable'] or access.u64(binding['bound_vtable']+40)!=binding['wire_frame_callback']:raise ValueError('Frame ownership changed')
|
|
if struct.unpack('<I',access.read(frame+8,4))[0]!=4:raise ValueError('Require completed account-start command')
|
|
access.write(frame+8,struct.pack('<I',5))
|
|
finally:access.close()
|
|
|
|
def open_engine_realm(pid,caller,verified_before_stop=False):
|
|
"""Opt-in genuine engine TCP construction; no success events/state writes."""
|
|
host.require_safepoint(caller)
|
|
caller_address=int(caller,16)
|
|
account=inspect_account(pid)
|
|
if account['state']!=2 or account['server_proof_verified']!=1 or account['transport_prepared']!=1:raise ValueError('Require genuine prepared Turtle account')
|
|
access=host.Access(pid)
|
|
try:
|
|
callsite=caller_address-5
|
|
instruction=access.read(callsite,5)
|
|
if not access.allowed(callsite,5,'x') or instruction[0]!=0xe8 or caller_address+struct.unpack('<i',instruction[1:])[0]!=0x141e53d80:
|
|
raise ValueError('Observed frame-pump callsite differs')
|
|
base,info,_=module(access);frame=base+info['exports']['gw_wire_frame_data'];data=base+info['exports']['gw_wire_realm_data']
|
|
binding=json.loads((native_runtime_paths.state_file(ROOT,'engine-poll-binding.json')).read_text());owner=binding['owner']
|
|
if binding['pid']!=pid or binding['restored'] or access.u64(0x145e7a098)!=owner or access.u64(owner)!=binding['bound_vtable'] or access.u64(binding['bound_vtable']+40)!=binding['wire_frame_callback']:raise ValueError('Frame ownership changed')
|
|
if struct.unpack('<I',access.read(owner+0x98,4))[0]!=2 or any(access.read(owner+0x1a0,32)):raise ValueError('Require initialized disconnected engine')
|
|
entry=0x141e46020;prefix=bytes.fromhex('48895c2410488974241855')
|
|
if not verified_before_stop and (not access.allowed(entry,len(prefix),'x') or access.read(entry,len(prefix))!=prefix):raise ValueError('Verified engine realm entry is not naturally ready')
|
|
if struct.unpack('<II',access.read(data,8))!=(1,48) or any(access.read(data+8,40)):raise ValueError('Engine realm control is not idle')
|
|
if struct.unpack('<I',access.read(frame+8,4))[0]!=6:raise ValueError('Require verified main-thread channel borrow first')
|
|
# The only engine writes come from its own original OpenRealm method.
|
|
# Publish only this module's expected owner and one-shot command.
|
|
access.write(data+40,struct.pack('<Q',owner));access.write(frame+8,struct.pack('<I',7))
|
|
finally:access.close()
|
|
|
|
def preflight_pipe_open(pid):
|
|
"""Version-pinned observed engine methods, preserving natural guard faults.
|
|
Cold pages need not be forced RX: prior actual execution and captured code
|
|
are bound to this exact private image; setup is rechecked at natural return.
|
|
"""
|
|
import engine_pipe_host
|
|
pin='c49ce22c3e0aaeb7a7007a5c5cb792e4c3e6cdecc55a1145a5933fc113e3e57f'
|
|
identity=json.loads((ROOT/'docs/evidence/gameplay/native-lifecycle-static-contract.json').read_text())
|
|
image=ROOT/'runtime/native-client/_classic_beta_/WowB.exe'
|
|
code=(ROOT/'runtime/native-handler-code/141e46000.bin').read_bytes()
|
|
if identity['image_sha256']!=pin or hashlib.sha256(__import__('windows_image_profile').source_bytes(image.read_bytes())if os.name=='nt'else image.read_bytes()).hexdigest()!=pin or hashlib.sha256(code).hexdigest()!=identity['code_pages']['0x141e46000']:raise ValueError('Pinned observed engine code identity differs')
|
|
access=host.Access(pid)
|
|
try:
|
|
for entry,prefix in ((0x141e46020,bytes.fromhex('48895c2410488974241855')),(engine_pipe_host.ENTRY,engine_pipe_host.PREFIX)):
|
|
if code[entry-0x141e46000:entry-0x141e46000+len(prefix)]!=prefix:raise ValueError('Previously observed engine entry differs')
|
|
if not any(low<=entry and entry+len(prefix)<=high for low,high,*_ in access.maps):raise ValueError('Original engine entry not mapped')
|
|
# Runtime guarded bytes need not be plaintext even when the map
|
|
# reports RX. Use the version-pinned prior actual execution contract;
|
|
# natural setup execution must match before any pipe binding.
|
|
# No page permissions or guard/exception handlers are changed.
|
|
finally:access.close()
|
|
path=native_runtime_paths.state_file(ROOT,'engine-pipe-entry-preflight.json');path.write_text(json.dumps(dict(pid=pid,verified_entries=[0x141e46020,engine_pipe_host.ENTRY],previously_verified_queue=0x141e54190))+'\n');path.chmod(0o600)
|
|
return lambda actual,caller:open_engine_realm(actual,caller,verified_before_stop=actual==pid)
|
|
|
|
def inspect_engine_realm(pid):
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);data=base+info['exports']['gw_wire_realm_data']
|
|
values=struct.unpack('<II6iIIQ',access.read(data,48))
|
|
if values[:2]!=(1,48):raise ValueError('Owned engine realm ABI differs')
|
|
report=dict(zip(('stage','error','windows_thread_id','call_return','engine_state_before','engine_state_after','advertised_port','realm_index'),values[2:10]))
|
|
entry=0x141e46020;prefix=bytes.fromhex('48895c2410488974241855')
|
|
ready=access.allowed(entry,len(prefix),'x')
|
|
report.update(engine_entry_naturally_executable=ready,engine_entry_matches_observed_prefix=ready and access.read(entry,len(prefix))==prefix)
|
|
report.update(kind='actual-native-engine-TCP-opening',world_authentication_proven=False,native_character_selection_proven=False,native_world_entry_proven=False)
|
|
return report
|
|
finally:access.close()
|
|
|
|
def start_account(pid,caller):
|
|
"""Publish private file references only to our module on the real frame thread."""
|
|
host.require_safepoint(caller)
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access)
|
|
binding=json.loads((native_runtime_paths.state_file(ROOT,'engine-poll-binding.json')).read_text())
|
|
data=base+info['exports']['gw_wire_auth_data']
|
|
frame=base+info['exports']['gw_wire_frame_data']
|
|
if binding['pid']!=pid or binding['restored'] or not binding.get('wire_ping_only'):raise ValueError('Require verified idle wire frame binding')
|
|
if access.u64(binding['owner'])!=binding['bound_vtable'] or access.u64(binding['bound_vtable']+40)!=binding['wire_frame_callback']:raise ValueError('Wire frame owner changed')
|
|
require_account_start_ready(access,base,info,binding)
|
|
if struct.unpack('<II',access.read(data,8))!=(1,1732) or any(access.read(data+8,60)):raise ValueError('Owned account control is not idle')
|
|
config=json.loads((ROOT/'secrets/native-local-bootstrap.json').read_text())
|
|
directory=Path(config['account_directory']).resolve()
|
|
if not directory.is_relative_to(ROOT/'secrets'):raise ValueError('Account outside private workspace secrets')
|
|
def owned_file(name):
|
|
path=directory/name
|
|
if path.is_symlink() or not path.is_file() or path.stat().st_uid!=__import__('os').getuid() or path.stat().st_mode&0o077:raise ValueError('Private account input permissions differ')
|
|
return str(path)
|
|
account=json.loads(Path(owned_file('account.json')).read_text())
|
|
def field(value,bound):
|
|
raw=value.encode('ascii')
|
|
if not raw or b'\0' in raw or len(raw)>=bound:raise ValueError('Private account input exceeds bounded ABI')
|
|
return raw+bytes(bound-len(raw))
|
|
payload=struct.pack('<II13iII',1,1732,0,0,0,0,-1,-1,0,-1,-1,0,0,0,0,3724,120000)
|
|
payload+=field(account['username'],128)
|
|
for name in ('password.txt','version-hash.bin','addon-tail.bin'):payload+=field(owned_file(name),512)
|
|
binding.update(wire_account_data=data,wire_ping_only=False)
|
|
record=native_runtime_paths.state_file(ROOT,'engine-poll-binding.json');record.write_text(json.dumps(binding,indent=2)+'\n');record.chmod(0o600)
|
|
access.write(data,payload)
|
|
access.write(frame+8,struct.pack('<I',3))
|
|
finally:access.close()
|
|
|
|
def read_ui_realm_control(access,base,info):
|
|
"""Optional owned UI intent; absent on older wire modules."""
|
|
export=info.get('exports',{}).get('gw_wire_account_ui_data')
|
|
if export is None:return dict(available=False,enabled=False)
|
|
raw=read_public_bytes(access,base+export,32)
|
|
abi,size,request,state,error,enabled,reserved=struct.unpack('<IIQ4i',raw)
|
|
if (abi,size)!=(1,32) or state not in (0,1,2,3) or enabled not in (0,1) or reserved:
|
|
return dict(available=False,enabled=False,held='owned-ui-control-ABI')
|
|
generation=request>>32;low=request&0xffffffff
|
|
if request and (not generation or not 1<=low<=64):
|
|
return dict(available=False,enabled=False,held='owned-ui-control-request')
|
|
return dict(available=True,enabled=bool(enabled),request=request,state=state,error=error,
|
|
request_generation=generation if request else None,request_index=low-1 if request else None)
|
|
|
|
def resolve_ui_realm_request(pid,request,error=0):
|
|
"""Acknowledge UI intent only; never change Source authentication results."""
|
|
if type(request)is not int or not 0<request<1<<64 or type(error)is not int or not -65535<=error<=0:
|
|
raise ValueError('Invalid owned UI proposal acknowledgement')
|
|
if not error:
|
|
account=inspect_account(pid)
|
|
if (account.get('memory_credentials',{}).get('generation')!=request>>32 or account.get('selected_index',-1)<0 or
|
|
account.get('server_proof_verified')!=1 or account.get('auth_result')!=0 or account.get('discovery_result')!=0 or account.get('error')!=0):
|
|
raise ValueError('Source realm proposal has not been admitted by the backend')
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);ui=read_ui_realm_control(access,base,info)
|
|
if not ui.get('available') or not ui.get('enabled') or ui.get('request')!=request or ui.get('state')!=1:
|
|
raise ValueError('Owned UI proposal changed before acknowledgement')
|
|
data=base+info['exports']['gw_wire_account_ui_data']
|
|
access.write(data+20,struct.pack('<i',error))
|
|
access.write(data+16,struct.pack('<i',2 if not error else 3))
|
|
finally:access.close()
|
|
|
|
def select_realm(pid,index):
|
|
"""Publish a choice from the genuine discovered list, while worker waits.
|
|
|
|
No engine callback/state or fabricated realm row. The worker validates the
|
|
index against its core-owned list and freezes the selected real endpoint.
|
|
"""
|
|
if type(index) is not int or not 0<=index<64:raise ValueError('Invalid discovered realm index')
|
|
current=inspect_account(pid)
|
|
if current['state']!=5 or current['server_proof_verified']!=1 or current['transport_prepared']:
|
|
raise ValueError('Require genuine authenticated realm-selection phase')
|
|
if index>=current['realm_count'] or current['realms'][index]['flags']&2:
|
|
raise ValueError('Selected discovered realm is unavailable')
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);data=base+info['exports']['gw_wire_auth_data']
|
|
if struct.unpack('<i',access.read(data+12,4))[0]!=5:raise ValueError('Realm-selection phase changed')
|
|
access.write(data+36,struct.pack('<i',index))
|
|
finally:access.close()
|
|
|
|
def inspect_account(pid):
|
|
access=host.Access(pid)
|
|
try:
|
|
base,info,_=module(access);data=base+info['exports']['gw_wire_auth_data']
|
|
values=struct.unpack('<II13iII',access.read(data,68))
|
|
if values[:2]!=(1,1732):raise ValueError('Owned account ABI differs')
|
|
count=values[8]
|
|
if not 0<=count<=64:raise ValueError('Owned realm count exceeds bound')
|
|
names=('command','state','error','windows_thread_id','auth_result','discovery_result','realm_count','selected_index','transport_result','elapsed_ms','cancel','server_proof_verified','transport_prepared','auth_port','retention_ms')
|
|
report=dict(zip(names,values[2:]));rows=[]
|
|
# Realm metadata is public; credential/path and opaque handle regions are
|
|
# never inspected. Worker publishes state2/5 after writing all rows.
|
|
if report['state'] in (2,4,5):
|
|
for index in range(count):
|
|
address=base+info['exports']['gw_wire_auth_realms']+index*408
|
|
raw=read_public_realm(access,address)
|
|
t,flags,characters,category,wire,population=struct.unpack('<5If',raw[:24])
|
|
rows.append(dict(index=index,type=t,flags=flags,characters=characters,category=category,wire_id=wire,population=population,name=raw[24:152].split(b'\0')[0].decode('utf-8'),address=raw[152:].split(b'\0')[0].decode('ascii')))
|
|
if 'gw_wire_session_lease_data' in info['exports']:
|
|
lease=read_public_bytes(access,base+info['exports']['gw_wire_session_lease_data'],32)
|
|
abi,size,attached,beats,last,released,_=struct.unpack('<4IQ2I',lease)
|
|
if (abi,size)!=(1,32) or attached>1 or released>1:raise ValueError('Owned connection lease metadata differs')
|
|
report['engine_session_lease']=dict(attached=bool(attached),heartbeats=beats,released=bool(released))
|
|
if 'gw_wire_auth_credentials_data' in info['exports']:
|
|
# Only the public header is diagnostic metadata. Never read the
|
|
# remaining100 bytes, even to try to establish that they were wiped.
|
|
header=read_public_bytes(access,base+info['exports']['gw_wire_auth_credentials_data'],32)
|
|
abi,size,state,generation,username_bytes,password_bytes,consumed,reserved=struct.unpack('<IIi5I',header)
|
|
if (abi,size)!=(1,132) or not -1<=state<=3 or username_bytes>32 or password_bytes>64 or reserved:
|
|
raise ValueError('Owned memory credential metadata differs')
|
|
report['memory_credentials']=dict(state=state,generation=generation,consumed_generation=consumed,
|
|
username_bytes=username_bytes,password_bytes=password_bytes,
|
|
secret_payload_read=False)
|
|
report.update(kind='actual-client-Windows-owned-Turtle-account',realms=rows,
|
|
engine_account_adoption_verified=False,native_character_selection_verified=False,native_world_entry_verified=False)
|
|
report['source_ui']=read_ui_realm_control(access,base,info)
|
|
return report
|
|
finally:access.close()
|
|
|
|
def read_public_realm(access,address):
|
|
"""Exactly one public408-byte export row, including adjacent readable maps."""
|
|
return read_public_bytes(access,address,408)
|
|
|
|
def read_public_bytes(access,address,size,*,max_size=2048):
|
|
if not 0<size<=max_size:raise ValueError('Public metadata exceeds bound')
|
|
if size<=2048:
|
|
try:return access.read(address,size)
|
|
except ValueError:pass
|
|
result=bytearray()
|
|
while len(result)<size:
|
|
current=address+len(result)
|
|
end=next((high for low,high,permissions,_,_ in access.maps if low<=current<high and 'r' in permissions),None)
|
|
if end is None:raise ValueError('Owned public realm row is not fully readable')
|
|
segment=min(size-len(result),end-current,2048)
|
|
result+=access.read(current,segment)
|
|
return bytes(result)
|