367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
222 lines
10 KiB
Python
222 lines
10 KiB
Python
"""Assemble a credential-free public-profile DX12 PE bundle offline.
|
|
|
|
This accepts only the already reviewed VKD3D carrier and a newly built
|
|
profile-2 Bridge/Wire pair. It does not install a client, authenticate, or
|
|
modify any source prefix. Public login remains an explicit runtime gate.
|
|
"""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pefile
|
|
|
|
if __package__:
|
|
from .dx12_native_bootstrap import verify_pair
|
|
else:
|
|
from dx12_native_bootstrap import verify_pair
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PUBLIC_HOST = b'play.octowow.st'
|
|
DX12_CARRIER_SHA = '403b1036c7635a4c9fc48d1e5eb183d47ad6a478c5ad82b9f84ee01bd1e75f95'
|
|
GE_D3D12CORE_SHA = '9cc2ab2c367e17923c0b9401c399b0514f1182f65bafed63485525a74776a251'
|
|
GE_DXGI_SHA = 'eb261854e11896dd2bde2b7ee3cfbc48d5acf06f1cb56195b15fe54173c7fc4d'
|
|
ACCEPTED_CORE_SHA = 'b0061ea1733960c2b18b246d14659515b89cd7f8f19d4a4bf09a687f77a562e9'
|
|
|
|
|
|
def sha(path):
|
|
digest = hashlib.sha256()
|
|
with Path(path).open('rb') as stream:
|
|
for part in iter(lambda: stream.read(1 << 20), b''):
|
|
digest.update(part)
|
|
return digest.hexdigest()
|
|
|
|
|
|
def regular(path, expected=None):
|
|
path = Path(path)
|
|
if path.is_symlink() or not path.is_file():
|
|
raise ValueError('Require owned regular PE input: ' + str(path))
|
|
if expected is not None and sha(path) != expected:
|
|
raise ValueError('Pinned PE input changed: ' + path.name)
|
|
return path
|
|
|
|
|
|
def export_map(pe):
|
|
return {row.name: row for row in pe.DIRECTORY_ENTRY_EXPORT.symbols if row.name}
|
|
|
|
|
|
def public_profile_gate(bridge, wire, wire_manifest):
|
|
"""Check the selected public endpoint in source receipt and PE bytes."""
|
|
bridge_bytes = bridge.read_bytes()
|
|
wire_bytes = wire.read_bytes()
|
|
if bridge_bytes.count(PUBLIC_HOST) != 1 or b'127.0.0.1' in bridge_bytes:
|
|
raise ValueError('Public Bridge contains wrong direct endpoint bytes')
|
|
manifest = json.loads(wire_manifest.read_text())
|
|
if (manifest.get('source_only_profile') != 2
|
|
or manifest.get('source_only_host') != PUBLIC_HOST.decode()
|
|
or manifest.get('source_only_auth_port') != 3724
|
|
or manifest.get('pe_sha256') != sha(wire)):
|
|
raise ValueError('Public Wire build receipt endpoint/profile differs')
|
|
bridge_pe = pefile.PE(str(bridge))
|
|
wire_pe = pefile.PE(str(wire))
|
|
for name, pe in (('Bridge', bridge_pe), ('Wire', wire_pe)):
|
|
if (pe.FILE_HEADER.Machine != 0x8664 or pe.OPTIONAL_HEADER.Magic != 0x20b
|
|
or pe.OPTIONAL_HEADER.AddressOfEntryPoint):
|
|
raise ValueError(name + ' AMD64/no-entry PE contract differs')
|
|
bridge_exports = export_map(bridge_pe)
|
|
wire_exports = export_map(wire_pe)
|
|
if bridge_exports.get(b'gw_startup_D3D12CreateDevice', None) is None:
|
|
raise ValueError('Public Bridge lacks DX12 wrapper')
|
|
if bridge_exports[b'gw_startup_D3D12CreateDevice'].ordinal != 27:
|
|
raise ValueError('Public Bridge DX12 export ordinal differs')
|
|
if b'gw_bridge_abi' not in bridge_exports or b'gw_wire_abi' not in wire_exports:
|
|
raise ValueError('Public gateway ABI exports differ')
|
|
profile = wire_exports.get(b'gw_source_profile_kind')
|
|
if profile is None:
|
|
raise ValueError('Public Wire source profile getter absent')
|
|
offset = wire_pe.get_offset_from_rva(profile.address)
|
|
if wire_bytes[offset:offset + 6] != bytes.fromhex('b802000000c3'):
|
|
raise ValueError('Public Wire getter is not exact constant profile 2')
|
|
if wire_bytes.count(PUBLIC_HOST) != 1:
|
|
raise ValueError('Public Wire selected hostname bytes differ')
|
|
return {
|
|
'source_profile': 2,
|
|
'auth_host': PUBLIC_HOST.decode(),
|
|
'auth_port': 3724,
|
|
'bridge_host_occurrences': 1,
|
|
'wire_host_occurrences': 1,
|
|
'wire_profile_getter_bytes': 'b802000000c3',
|
|
'bridge_dx12_export_ordinal': 27,
|
|
'bridge_no_entry': True,
|
|
'wire_no_entry': True,
|
|
}
|
|
|
|
|
|
def assemble(output, bridge, wire, wire_manifest, carrier_dir, d3d12core, dxgi):
|
|
output = Path(output).resolve()
|
|
if (output.exists() or output.is_symlink()
|
|
or not output.is_relative_to(ROOT / 'build')
|
|
or output == ROOT / 'build'):
|
|
raise ValueError('Fresh owned build subdirectory required')
|
|
bridge = regular(bridge)
|
|
wire = regular(wire)
|
|
wire_manifest = regular(wire_manifest)
|
|
carrier_dir = Path(carrier_dir)
|
|
carrier = regular(carrier_dir / 'd3d12.dll', DX12_CARRIER_SHA)
|
|
original = regular(carrier_dir / 'preimages/d3d12.dll')
|
|
d3d12core = regular(d3d12core, GE_D3D12CORE_SHA)
|
|
dxgi = regular(dxgi, GE_DXGI_SHA)
|
|
for name, path in (('d3d12core.dll', d3d12core), ('dxgi.dll', dxgi)):
|
|
pe = pefile.PE(str(path), fast_load=True)
|
|
if pe.FILE_HEADER.Machine != 0x8664 or pe.OPTIONAL_HEADER.Magic != 0x20b:
|
|
raise ValueError('GE runtime is not AMD64 PE32+: ' + name)
|
|
pair = verify_pair(carrier_dir, bridge, wire)
|
|
endpoint = public_profile_gate(bridge, wire, wire_manifest)
|
|
core = regular(ROOT / 'build/libgateway_native.so', ACCEPTED_CORE_SHA)
|
|
manifest = {
|
|
'kind': 'optional-public-profile2-dx12-pe-bundle-v1',
|
|
'status': 'OFFLINE_STATIC_VERIFIED',
|
|
'native_client_acceptance': 'local profile5 only; separate public runtime check pending',
|
|
'public_authentication_tested': False,
|
|
'credentials_included': False,
|
|
'source_client_modified': False,
|
|
'installed': False,
|
|
'profile': endpoint,
|
|
'pair': pair,
|
|
'accepted_native_core_sha256': sha(core),
|
|
'ge_source': 'GE-Proton11-12-x86_64',
|
|
'required_prefix_override': 'd3d12=native;d3d12core=native;dxgi=native',
|
|
'required_renderer_flag': '-d3d12',
|
|
'source_files': {
|
|
'GWNativeBridge.dll': str(bridge),
|
|
'GWNativeWire.dll': str(wire),
|
|
'd3d12.dll': str(carrier),
|
|
'd3d12core.dll': str(d3d12core),
|
|
'dxgi.dll': str(dxgi),
|
|
},
|
|
}
|
|
partial = output.with_name(output.name + '.partial')
|
|
if partial.exists() or partial.is_symlink():
|
|
raise ValueError('Existing partial bundle preserved')
|
|
partial.mkdir(parents=True, mode=0o700)
|
|
files = {}
|
|
for name, source in manifest['source_files'].items():
|
|
target = partial / name
|
|
with target.open('xb') as stream:
|
|
with Path(source).open('rb') as input_stream:
|
|
shutil.copyfileobj(input_stream, stream, length=1 << 20)
|
|
stream.flush()
|
|
os.fsync(stream.fileno())
|
|
target.chmod(0o644)
|
|
files[name] = {'bytes': target.stat().st_size, 'sha256': sha(target)}
|
|
if files[name]['sha256'] != sha(source):
|
|
raise ValueError('Public bundle copy differs: ' + name)
|
|
original_target = partial / 'preimages/d3d12.dll'
|
|
original_target.parent.mkdir(mode=0o700)
|
|
shutil.copy2(original, original_target)
|
|
original_target.chmod(0o400)
|
|
files['preimages/d3d12.dll'] = {'bytes': original_target.stat().st_size,
|
|
'sha256': sha(original_target)}
|
|
for name, source in (('candidate.json', carrier_dir / 'candidate.json'),
|
|
('wire-build-manifest.json', wire_manifest)):
|
|
source = regular(source)
|
|
target = partial / name
|
|
shutil.copy2(source, target)
|
|
target.chmod(0o644)
|
|
files[name] = {'bytes': target.stat().st_size, 'sha256': sha(target)}
|
|
manifest['files'] = files
|
|
(partial / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
|
partial.rename(output)
|
|
return manifest
|
|
|
|
|
|
def verify_bundle(directory):
|
|
"""Recheck a portable offline bundle before a release packager consumes it."""
|
|
directory = Path(directory)
|
|
manifest = json.loads(regular(directory / 'manifest.json').read_text())
|
|
expected = {'GWNativeBridge.dll', 'GWNativeWire.dll', 'd3d12.dll',
|
|
'd3d12core.dll', 'dxgi.dll', 'preimages/d3d12.dll',
|
|
'candidate.json', 'wire-build-manifest.json'}
|
|
if (manifest.get('kind') != 'optional-public-profile2-dx12-pe-bundle-v1'
|
|
or manifest.get('status') != 'OFFLINE_STATIC_VERIFIED'
|
|
or set(manifest.get('files', {})) != expected
|
|
or manifest.get('credentials_included') is not False
|
|
or manifest.get('public_authentication_tested') is not False):
|
|
raise ValueError('Public DX12 bundle manifest contract differs')
|
|
for name, row in manifest['files'].items():
|
|
path = regular(directory / name)
|
|
if path.stat().st_size != row['bytes'] or sha(path) != row['sha256']:
|
|
raise ValueError('Public DX12 bundle file differs: ' + name)
|
|
pair = verify_pair(directory, directory / 'GWNativeBridge.dll',
|
|
directory / 'GWNativeWire.dll')
|
|
profile = public_profile_gate(directory / 'GWNativeBridge.dll',
|
|
directory / 'GWNativeWire.dll',
|
|
directory / 'wire-build-manifest.json')
|
|
if pair != manifest['pair'] or profile != manifest['profile']:
|
|
raise ValueError('Public DX12 bundle pair/profile receipt differs')
|
|
if (manifest.get('accepted_native_core_sha256') != ACCEPTED_CORE_SHA
|
|
or manifest.get('required_prefix_override') != 'd3d12=native;d3d12core=native;dxgi=native'
|
|
or manifest.get('required_renderer_flag') != '-d3d12'):
|
|
raise ValueError('Public DX12 bundle runtime contract differs')
|
|
return manifest
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--output', type=Path, required=True)
|
|
parser.add_argument('--bridge', type=Path, required=True)
|
|
parser.add_argument('--wire', type=Path, required=True)
|
|
parser.add_argument('--wire-manifest', type=Path, required=True)
|
|
parser.add_argument('--carrier-dir', type=Path, required=True)
|
|
parser.add_argument('--d3d12core', type=Path, required=True)
|
|
parser.add_argument('--dxgi', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
result = assemble(args.output, args.bridge, args.wire, args.wire_manifest,
|
|
args.carrier_dir, args.d3d12core, args.dxgi)
|
|
print(json.dumps({'kind': result['kind'], 'status': result['status'],
|
|
'files': result['files'], 'profile': result['profile']}, indent=2))
|