367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
210 lines
14 KiB
Python
210 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Stage an additive, uninstalled Windows overlay for a prepared Linux client.
|
|
|
|
The overlay is not a release or an authentication acceptance. The two source
|
|
packages and real Windows native artifacts must already be independently built.
|
|
No client data, CASC tree, account store or existing package is modified.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
|
|
from windows_client_package import artifact_inputs, digest, read_json
|
|
from windows_native_bootstrap import pe_exports
|
|
|
|
# Exact existing owned Windows launcher and host dependency set. Shared files
|
|
# must already be pinned by the Linux release; Windows-only files may be added.
|
|
HELPERS = ('windows_launcher_backend', 'windows_native_bootstrap', 'windows_process_access',
|
|
'windows_frame_probe', 'engine_poll_host', 'engine_wire_host', 'engine_main_thread_probe',
|
|
'engine_channel_policy_host', 'engine_pipe_host', 'engine_listener_host',
|
|
'engine_login_input_binding', 'engine_session_retirement', 'native_runtime_paths')
|
|
ROLES = {'bridge':'GWNativeBridge.dll','wire':'GWNativeWire.dll',
|
|
'backend':'GWNativeBackend.dll','codec':'forever_codec.dll',
|
|
'backend_host':'windows-backend-host.exe'}
|
|
|
|
|
|
def regular(root, relative):
|
|
root=Path(root).resolve(); path=Path(relative)
|
|
if path.is_absolute() or not path.parts or '..' in path.parts or '\\' in str(relative):
|
|
raise ValueError('Relative package path required')
|
|
original=root/path; current=root
|
|
for part in path.parts:
|
|
current=current/part
|
|
if current.is_symlink():raise ValueError('Symlink package input refused')
|
|
if not original.is_file() or not original.resolve().is_relative_to(root):raise ValueError('Missing regular package input: '+str(relative))
|
|
return original
|
|
|
|
|
|
def pinned_json(path, sha):
|
|
path=Path(path)
|
|
if path.is_symlink() or not path.is_file() or not isinstance(sha,str) or len(sha)!=64 or digest(path)!=sha:
|
|
raise ValueError('Pinned owning receipt differs')
|
|
return read_json(path)
|
|
|
|
|
|
def require_absent(root, relative):
|
|
"""Refuse existing paths and case aliases on a future Windows volume."""
|
|
parts=Path(relative).parts;current=Path(root)
|
|
for index,part in enumerate(parts):
|
|
if current.is_symlink() or not current.is_dir():
|
|
raise ValueError('Unsafe overlay parent: '+str(relative))
|
|
matches=[p for p in current.iterdir() if p.name.casefold()==part.casefold()]
|
|
if len(matches)>1:raise ValueError('Ambiguous Windows case alias: '+str(relative))
|
|
if not matches:return
|
|
match=matches[0]
|
|
if index==len(parts)-1:raise ValueError('Overlay would overwrite Linux package: '+str(relative))
|
|
if match.name!=part or match.is_symlink() or not match.is_dir():
|
|
raise ValueError('Unsafe or case-aliased overlay parent: '+str(relative))
|
|
current=match
|
|
|
|
|
|
def proven_build(receipt, artifacts, revision, source):
|
|
"""Consume the existing VM owning build/pair-check receipt shape."""
|
|
result=receipt.get('owning_result',{}); status=result.get('status',{}); provenance=receipt.get('module_provenance',{})
|
|
changed=provenance.get('changed_modules',{}); pair=result.get('matching-pair-check',{})
|
|
if (status.get('status')!='passed' or status.get('phase')!='complete' or
|
|
not isinstance(status.get('kind'),str) or not status['kind'].startswith('coherent-current-windows-native-') or
|
|
result.get('compile-backend-exit',{}).get('exit_code')!=0 or
|
|
result.get('matching-pair-check-exit',{}).get('exit_code')!=0 or
|
|
pair.get('native_initialize_status')!='0x0' or
|
|
pair.get('GWNativeBackend.dll')!='loaded' or pair.get('forever_codec.dll')!='loaded' or
|
|
pair.get('GWNativeBridge.dll')!='loaded' or
|
|
provenance.get('source_revision')!=revision or
|
|
changed.get('GWNativeBackend.dll',{}).get('sha256')!=artifacts['GWNativeBackend.dll'] or
|
|
changed.get('GWNativeWire.dll',{}).get('sha256')!=artifacts['GWNativeWire.dll'] or
|
|
provenance.get('retained_codec_sha256')!=artifacts['forever_codec.dll']):
|
|
raise ValueError('Exact successful native-Windows backend/codec build evidence required')
|
|
inputs=receipt.get('exact_source_inputs',{}).get('files')
|
|
if not isinstance(inputs,list) or not inputs:
|
|
raise ValueError('Pinned owning Windows source inputs required')
|
|
seen=set()
|
|
for row in inputs:
|
|
if not isinstance(row,dict) or not isinstance(row.get('path'),str) or row.get('path') in seen:
|
|
raise ValueError('Invalid Windows source input receipt')
|
|
name=row.get('path');seen.add(name)
|
|
if digest(regular(source,name))!=row.get('sha256'):
|
|
raise ValueError('Windows source input changed: '+str(name))
|
|
|
|
|
|
def plan(linux, windows, source, modules, module_profile, module_profile_sha256, build_receipt, build_receipt_sha256, launcher_profile_sha256):
|
|
linux=Path(linux).resolve();windows=Path(windows).resolve();source=Path(source).resolve();modules=Path(modules).resolve()
|
|
lm=read_json(regular(linux,'linux-release.json'));wm=read_json(regular(windows,'windows-release.json'))
|
|
if lm.get('kind')!='linux-forever-client-folder-package-v1' or wm.get('kind')!='native-Windows-client-preview':
|
|
raise ValueError('Existing Linux and Windows package contracts required')
|
|
if lm.get('credentials_included') is not False or wm.get('credentials_included') is not False:
|
|
raise ValueError('Credential-free package receipts required')
|
|
if not isinstance(lm.get('runtime_file_sha256'),dict):raise ValueError('Linux runtime file pins required')
|
|
revision=wm.get('source_git_revision')
|
|
if not revision or revision!=lm.get('source_git_revision'):raise ValueError('Package source revisions differ')
|
|
transport, artifacts=artifact_inputs(modules,module_profile,'owned-stdio-ipc-v1',module_profile_sha256)
|
|
for name in artifacts:
|
|
regular(modules,name)
|
|
package_identity=wm.get('package_input_identity',{})
|
|
if package_identity.get('backend_transport')!=transport or package_identity.get('artifacts')!=artifacts:
|
|
raise ValueError('Complete Windows package artifact identity differs')
|
|
proven_build(pinned_json(build_receipt,build_receipt_sha256),artifacts,revision,source)
|
|
wp=read_json(regular(windows,'compat/windows-native.json'))
|
|
lp=pinned_json(regular(windows,'compat/launcher.json'),launcher_profile_sha256)
|
|
allowed={'schema','client','bridge','wire','backend','codec','backend_host','backend_transport'}
|
|
if wp.get('schema')!=1 or wp.get('backend_transport')!=transport or set(wp)!=allowed:
|
|
raise ValueError('A plain matching native Windows profile is required')
|
|
old=wm.get('native_dlls',{})
|
|
for role,name in ROLES.items():
|
|
row=wp.get(role,{});release_row=old.get(role,{})
|
|
if row.get('sha256')!=artifacts[name] or release_row.get('sha256')!=artifacts[name]:raise ValueError('Windows module/package identity differs: '+role)
|
|
if digest(regular(windows,row.get('path','')))!=artifacts[name]:raise ValueError('Windows package module differs: '+role)
|
|
client='runtime/native-client/_classic_beta_/WowB.exe'
|
|
if wp.get('client',{}).get('path')!=client or wp['client'].get('sha256')!=old.get('client',{}).get('sha256') or digest(regular(linux,client))!=wp['client']['sha256']:
|
|
raise ValueError('Shared original client image differs')
|
|
if digest(regular(linux,'runtime/native-client/.build.info'))!=digest(regular(windows,'runtime/native-client/.build.info')):
|
|
raise ValueError('Shared client data build identity differs')
|
|
if not {'gw_bridge_abi','gw_bridge_data'}<=set(pe_exports(modules/ROLES['bridge'])):raise ValueError('Real Bridge PE exports required')
|
|
if not {'gw_wire_abi','gw_wire_frame_data'}<=set(pe_exports(modules/ROLES['wire'])):raise ValueError('Real Wire PE exports required')
|
|
if 'gw_native_wire_dispatch' not in pe_exports(modules/ROLES['backend']):raise ValueError('Real native Windows backend PE required')
|
|
if not {'gw_codec_abi','gw_codec_serialize'}<=set(pe_exports(modules/ROLES['codec'])):raise ValueError('Real native Windows codec PE required')
|
|
pe_exports(modules/ROLES['backend_host'])
|
|
launcher=regular(windows,'Play-OctoWoW.exe');bootstrap=regular(windows,'bin/ForeverBootstrap.exe');python=regular(windows,'python/python.exe')
|
|
for path in (launcher,bootstrap,python):pe_exports(path)
|
|
if digest(launcher)!=wm.get('frontend_sha256'):raise ValueError('Windows frontend identity differs')
|
|
spec=lp.get('platforms',{}).get('windows',{})
|
|
if spec.get('status')!='available' or spec.get('backend')!='bin/ForeverBootstrap.exe' or spec.get('sha256')!=digest(bootstrap):
|
|
raise ValueError('Existing Windows bootstrap profile differs')
|
|
frontend=regular(linux,'launcher/launcher.py')
|
|
if lm['runtime_file_sha256'].get('launcher/launcher.py')!=digest(frontend) or digest(frontend)!=digest(regular(source,'launcher/launcher.py')):
|
|
raise ValueError('Linux and shared Windows frontend differ')
|
|
copies={'Play-OctoWoW.exe':launcher,'bin/ForeverBootstrap.exe':bootstrap,'launcher.py':frontend,
|
|
'platform/windows/native-engine-template.json':regular(windows,'compat/native-engine-template.json')}
|
|
for name in artifacts:
|
|
copies[('platform/windows/' if name in ('GWNativeBridge.dll','GWNativeWire.dll') else 'build/')+name]=regular(modules,name)
|
|
for name in HELPERS:
|
|
rel='ops/'+name+'.py';expected=regular(source,rel);target=linux/rel
|
|
if target.exists() or target.is_symlink():
|
|
if lm['runtime_file_sha256'].get(rel)!=digest(regular(linux,rel)) or digest(target)!=digest(expected):raise ValueError('Shared helper differs: '+rel)
|
|
else:copies[rel]=expected
|
|
pyroot=windows/'python'
|
|
for directory,subdirs,files in os.walk(pyroot,followlinks=False):
|
|
current=Path(directory)
|
|
if current.is_symlink() or any((current/d).is_symlink() for d in subdirs):raise ValueError('Symlink Python runtime refused')
|
|
if any(d.casefold() in ('account','accounts','secrets','savedvariables','wtf') for d in subdirs):
|
|
raise ValueError('Private account directory in Python runtime')
|
|
subdirs[:]=[d for d in subdirs if d!='__pycache__']
|
|
for name in files:
|
|
path=current/name
|
|
if name.endswith(('.pyc','.pyo')):continue
|
|
relative=path.relative_to(windows).as_posix()
|
|
copies[relative]=regular(windows,relative)
|
|
if 'python/python.exe' not in copies:raise ValueError('Windows Python runtime missing')
|
|
for rel in copies:
|
|
require_absent(linux,rel)
|
|
for rel in ('compat/windows-launcher.json','compat/windows-native.json','windows-overlay-candidate.json'):
|
|
require_absent(linux,rel)
|
|
profile=dict(wp);profile['client']={'path':client,'sha256':wp['client']['sha256']}
|
|
for role,name in ROLES.items():
|
|
path=('platform/windows/' if role in ('bridge','wire') else 'build/')+name
|
|
profile[role]={**wp[role],'path':path,'sha256':artifacts[name]}
|
|
template='platform/windows/native-engine-template.json';profile['engine_template']={'path':template,'sha256':digest(copies[template])}
|
|
profile['runtime_journal_scope']='windows-isolated-v1'
|
|
launcher_profile={'schema':1,'runtime_root':'..','platforms':{'windows':{'status':'available','backend':'bin/ForeverBootstrap.exe','sha256':digest(bootstrap)}}}
|
|
return {'copies':copies,'windows_profile':profile,'launcher_profile':launcher_profile,
|
|
'linux_manifest_sha256':digest(linux/'linux-release.json'),'windows_manifest_sha256':digest(windows/'windows-release.json'),
|
|
'module_profile_sha256':module_profile_sha256,'build_receipt_sha256':build_receipt_sha256,
|
|
'launcher_profile_sha256':launcher_profile_sha256,'revision':revision}
|
|
|
|
|
|
def stage(output, **inputs):
|
|
output=Path(output).resolve()
|
|
if output.exists() or output.is_symlink():raise ValueError('New overlay directory required')
|
|
for name in ('linux','windows','modules'):
|
|
root=Path(inputs[name]).resolve()
|
|
if output==root or output.is_relative_to(root) or root.is_relative_to(output):raise ValueError('Overlay must be separate from all source packages')
|
|
source=Path(inputs['source']).resolve()
|
|
if output==source or source.is_relative_to(output) or (output.is_relative_to(source) and not output.is_relative_to(source/'runtime')):
|
|
raise ValueError('Overlay must not overlap source files')
|
|
prepared=plan(**inputs) # No output is created on a failed identity/provenance check.
|
|
output.mkdir(parents=True)
|
|
recorded={}
|
|
for rel,source in sorted(prepared['copies'].items()):
|
|
dest=output/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(source,dest)
|
|
recorded[rel]=digest(dest)
|
|
if recorded[rel]!=digest(source):raise ValueError('Overlay copy identity differs: '+rel)
|
|
for rel,key in [('compat/windows-native.json','windows_profile'),('compat/windows-launcher.json','launcher_profile')]:
|
|
dest=output/rel;dest.parent.mkdir(parents=True,exist_ok=True);dest.write_text(json.dumps(prepared[key],indent=2)+'\n');recorded[rel]=digest(dest)
|
|
result={'kind':'private-Windows-shared-client-overlay-candidate-v1','installed':False,'native_windows_accepted':False,
|
|
'client_data_copied':False,'source_revision':prepared['revision'],'linux_manifest_sha256':prepared['linux_manifest_sha256'],
|
|
'windows_manifest_sha256':prepared['windows_manifest_sha256'],'module_profile_sha256':prepared['module_profile_sha256'],
|
|
'build_receipt_sha256':prepared['build_receipt_sha256'],'launcher_profile_sha256':prepared['launcher_profile_sha256'],'files':recorded}
|
|
(output/'windows-overlay-candidate.json').write_text(json.dumps(result,indent=2)+'\n')
|
|
return result
|
|
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
for name in ('linux','windows','source','modules','module-profile','module-profile-sha256','build-receipt','build-receipt-sha256','launcher-profile-sha256','output'):p.add_argument('--'+name,required=True)
|
|
args=vars(p.parse_args());output=args.pop('output');stage(output,**{k.replace('-','_'):v for k,v in args.items()})
|
|
print('Private Windows overlay candidate staged; no client or native acceptance.')
|
|
|
|
if __name__=='__main__':main()
|