367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
60 lines
4.3 KiB
Python
60 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Opt-in owned PE/Wine ABI host in the existing complete private prefix.
|
|
No original client/prefix writes. Default native_pe_bridge.restore is rollback.
|
|
"""
|
|
import json,os
|
|
from pathlib import Path
|
|
import pefile
|
|
from build_wine_wire import build
|
|
from native_pe_bridge import ROOT,MANIFEST,sha,add_imports,prepare as prepare_frame
|
|
|
|
def atomic_json(path,value):
|
|
temporary=path.with_name(path.name+'.wire-journal-new')
|
|
if temporary.is_symlink():raise RuntimeError('Unrecognized journal link preserved')
|
|
with temporary.open('w') as output:
|
|
json.dump(value,output,indent=2);output.write('\n');output.flush();os.fsync(output.fileno())
|
|
temporary.chmod(0o600);temporary.replace(path)
|
|
fd=os.open(path.parent,os.O_RDONLY|os.O_DIRECTORY)
|
|
try:os.fsync(fd)
|
|
finally:os.close(fd)
|
|
|
|
def prepare():
|
|
from client_installation import running_clients
|
|
if running_clients():raise RuntimeError('Close development WowB before preparing wire host')
|
|
dll,unix=build();wire=dll.read_bytes();wire_hash=sha(wire)
|
|
codec=ROOT/'build/forever-schema/libforever_codec.so'
|
|
if codec.is_symlink() or not codec.is_file():raise RuntimeError('Build pinned source codec before native pipe installation')
|
|
previous_path=ROOT/'runtime/native-wire-host.json'
|
|
previous=json.loads(previous_path.read_text()) if previous_path.exists() else {}
|
|
target=ROOT/'runtime/native-wine-prefix/drive_c/windows/system32/GWNativeWire.dll'
|
|
if target.is_symlink() or (target.exists() and sha(target.read_bytes()) not in (wire_hash,previous.get('wire_dll_sha256'))):raise RuntimeError('Unrelated auxiliary DLL preserved')
|
|
# Existing path validates unchanged WowB/private prefix and saves a baseline.
|
|
prepare_frame();meta=json.loads(MANIFEST.read_text())
|
|
prefix=ROOT/'runtime/native-wine-prefix'
|
|
dependency=prefix/'drive_c/windows/system32/d3d11.dll'
|
|
original=(ROOT/'recovery/native-pe-graphics/d3d11.dll').read_bytes()
|
|
combined=add_imports(original,(("GWNativeBridge.dll","gw_bridge_abi"),("GWNativeWire.dll","gw_wire_abi")))
|
|
exports={row.name.decode():row.address for row in pefile.PE(data=wire).DIRECTORY_ENTRY_EXPORT.symbols if row.name}
|
|
if not all(key in exports for key in ('gw_wire_abi','gw_wire_initialize','gw_wire_dispatch','gw_wire_frame_callback','gw_wire_frame_data')):raise RuntimeError('Wire module exports unavailable')
|
|
record={'wire_dll_sha256':wire_hash,'wire_exports':exports,'wire_unix_path':str(unix),'wire_unix_sha256':sha(unix.read_bytes()),
|
|
'core_path':str(ROOT/'build/libgateway_native.so'),'core_sha256':sha((ROOT/'build/libgateway_native.so').read_bytes()),
|
|
'source_codec_path':str(codec),'source_codec_sha256':sha(codec.read_bytes()),
|
|
'previous_dependency_sha256':meta['dependency_patched_sha256'],'combined_dependency_sha256':sha(combined),
|
|
'original_client_modified':False,'original_prefix_modified':False,'engine_adoption_implemented':False,
|
|
'rollback':'Close private client, then python3 ops/native_pe_bridge.py restore'}
|
|
# Journal and rollback-accepted intermediate hash precede publication. A power
|
|
# interruption at either import stage remains recoverable by the same tool.
|
|
atomic_json(previous_path,record)
|
|
meta['dependency_previous_patched_sha256']=meta['dependency_patched_sha256'];meta['dependency_patched_sha256']=sha(combined)
|
|
meta['auxiliary_dependencies']=[{'file':'GWNativeWire.dll','sha256':wire_hash,'exports':exports}]
|
|
meta['wire_unix_library']={key:record[key] for key in ('wire_unix_path','wire_unix_sha256','core_path','core_sha256','source_codec_path','source_codec_sha256')}
|
|
temporary=target.with_name(target.name+'.native-new');temporary.write_bytes(wire);temporary.replace(target)
|
|
atomic_json(MANIFEST,meta)
|
|
temporary=dependency.with_name(dependency.name+'.native-new');temporary.write_bytes(combined);temporary.replace(dependency)
|
|
if sha(dependency.read_bytes())!=record['combined_dependency_sha256']:raise RuntimeError('Private dependency publication differs; recovery retained')
|
|
print('Prepared optional own PE/Wine host with journalled rollback; original installation/prefix untouched.')
|
|
if __name__=='__main__':
|
|
os.umask(0o077)
|
|
if len(__import__('sys').argv)!=2 or __import__('sys').argv[1]!='prepare':raise RuntimeError('Use prepare; rollback uses native_pe_bridge.py restore')
|
|
prepare()
|