367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
205 lines
18 KiB
Python
205 lines
18 KiB
Python
#!/usr/bin/env python3
|
|
"""Install a staged item registry/codec/PE into the owned disposable client.
|
|
|
|
No builds, process termination, authentication, SQL, original client changes or
|
|
schema modifications. Mapped-module changes require a normally closed client. All previous files
|
|
and coherent ADB caches are backed up before the first publication.
|
|
"""
|
|
import argparse,datetime,hashlib,json,shutil,re,struct,subprocess
|
|
from pathlib import Path
|
|
import pefile
|
|
from client_installation import ROOT,COPY,running_clients,inspect_installation
|
|
from item_package_preflight import read_public_json,read_compatibility_package,bounded_digest,MAX_COMPATIBILITY_PACKAGE_JSON_BYTES,MAX_TARGET_BYTES
|
|
from item_sparse_compat import package_payloads,package_pages
|
|
from native_wire_host import atomic_json
|
|
|
|
|
|
def verify_weapon_presentation(package):
|
|
"""A projected weapon must never be installed without its declared provider.
|
|
|
|
Validate deterministic source regeneration and the already installed owned
|
|
Lua/data/load order. This is a dependency check, not gameplay acceptance.
|
|
"""
|
|
requirement=package.get('required_weapon_presentation')
|
|
if requirement is None:return None
|
|
if (not isinstance(requirement,dict)or requirement.get('kind')not in('source-physical-melee-base-tooltips-v2','source-physical-weapon-base-tooltips-v3','source-weapon-base-tooltips-v4','source-weapon-base-tooltips-v5')
|
|
or not isinstance(requirement.get('item_ids'),list)or not requirement['item_ids']
|
|
or len(requirement['item_ids'])!=len(set(requirement['item_ids']))
|
|
or any(type(i)is not int or not 0<i<2**31 for i in requirement['item_ids'])):
|
|
raise ValueError('Explicit source primary presentation requirement differs')
|
|
directory=Path(requirement.get('profile_directory','')).resolve()
|
|
if not directory.is_relative_to(ROOT/'runtime'):raise ValueError('Owned generated weapon profile required')
|
|
from item_damage_profile import verified_payload,canonical
|
|
payload,receipt=verified_payload(directory,ROOT/'runtime/all-item-templates-20261017',
|
|
Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'))
|
|
profile,_=read_public_json(directory/'profile.json',8388608)
|
|
expected_kind='source-weapon-base-tooltips-v5'if profile.get('schema_version')==5 and profile.get('thrown_weapons')is True else'source-weapon-base-tooltips-v4'if profile.get('schema_version')==4 and profile.get('caster_wands')is True else'source-physical-weapon-base-tooltips-v3'if profile.get('schema_version')==3 and profile.get('physical_ranged')is True else'source-physical-melee-base-tooltips-v2'
|
|
if requirement['kind']!=expected_kind:raise ValueError('Required weapon presentation scope differs')
|
|
if (profile.get('primary_tooltips')is not True or not set(requirement['item_ids'])<=set(profile.get('primary_item_ids',[]))
|
|
or hashlib.sha256(canonical(profile)).hexdigest()!=requirement.get('profile_sha256')
|
|
or receipt['lua_sha256']!=requirement.get('lua_sha256')):
|
|
raise ValueError('Required source presentation profile identity differs')
|
|
target=COPY/'_classic_beta_/Interface/AddOns/GatewayDiagnostics'
|
|
source=ROOT/'client_addons/GatewayDiagnostics/SourceWeaponDamage.lua'
|
|
if (bounded_digest(source)!=requirement.get('provider_sha256')or bounded_digest(target/'SourceWeaponDamage.lua')!=requirement['provider_sha256']
|
|
or (target/'SourceWeaponDamageData.lua').read_bytes()!=payload):
|
|
raise ValueError('Required source presentation provider is not installed exactly')
|
|
toc=(target/'GatewayDiagnostics.toc').read_text().splitlines()
|
|
names=('SourceWeaponDamageData.lua','SourceWeaponDamage.lua')
|
|
if any(toc.count(n)!=1 for n in names)or toc.index(names[0])>=toc.index(names[1]):raise ValueError('Required presentation load order differs')
|
|
return dict(item_ids=requirement['item_ids'],profile_sha256=requirement['profile_sha256'],installed_provider_verified=True,gameplay_verified=False)
|
|
|
|
def verify_presentation_only_update(package,published,changed_paths):
|
|
"""Reuse a world session only when every wire row/mapped module is identical."""
|
|
if {k for k in package.keys()|published.keys()if package.get(k)!=published.get(k)}!={'required_weapon_presentation'}:
|
|
raise ValueError('Presentation-only update may change only its source provider requirement')
|
|
allowed={ROOT/'docs/evidence/data/item-sparse-compat/package.json',ROOT/'build/forever-schema/provenance.json'}
|
|
if not changed_paths or not set(changed_paths)<=allowed:raise ValueError('Presentation-only update changes a mapped module or unrelated publication')
|
|
|
|
|
|
def native_core_contract(path,soname_expected="libgateway_native.so"):
|
|
"""Inspect our own x64 ELF/C exports without executing code or engine calls."""
|
|
path=Path(path)
|
|
with path.open('rb')as stream:header=stream.read(64)
|
|
if (len(header)!=64 or header[:7]!=b'\x7fELF\x02\x01\x01'or struct.unpack_from('<HH',header,16)!=(3,62)):
|
|
raise ValueError('Native core must be an x64 little-endian ELF shared library')
|
|
def output(args):
|
|
r=subprocess.run(args,capture_output=True,text=True,timeout=30)
|
|
if r.returncode or len(r.stdout)>8388608:raise ValueError('Native core ELF/export inspection failed')
|
|
return r.stdout
|
|
symbols=output(['nm','-D','--defined-only',str(path)])
|
|
exports=sorted(set(re.findall(r'^\S+\s+[TW]\s+(gw_\w+)\s*$',symbols,re.M)))
|
|
dynamic=output(['readelf','-d',str(path)])
|
|
needed=sorted(set(re.findall(r'Shared library: \[([^\]]+)\]',dynamic)))
|
|
soname=re.findall(r'Library soname: \[([^\]]+)\]',dynamic)
|
|
if not exports or soname!=[soname_expected]:raise ValueError('Native core C ABI/SONAME missing')
|
|
return dict(exports=exports,needed=needed,soname=soname[0])
|
|
|
|
|
|
def verify_core_replacement(old,new):
|
|
before=native_core_contract(old);after=native_core_contract(new)
|
|
if before!=after:raise ValueError('Native core C ABI or shared dependencies differ; separate review required')
|
|
return dict(c_exports_preserved=len(before['exports']),soname=before['soname'],shared_dependencies_unchanged=before['needed'])
|
|
|
|
|
|
def verify_wire_replacement(old,new):
|
|
before=native_core_contract(old,'libgateway_wine_wire.so')
|
|
after=native_core_contract(new,'libgateway_wine_wire.so')
|
|
if before!=after:raise ValueError('Wine bridge ABI/dependencies changed; separate review required')
|
|
dynamic=subprocess.run(['readelf','-d',str(new)],capture_output=True,text=True,check=True,timeout=30).stdout
|
|
paths=re.findall(r'(?:Library runpath|Library rpath): \[([^\]]+)\]',dynamic)
|
|
if paths!=['$ORIGIN']:raise ValueError('Wine bridge must resolve its paired core beside itself')
|
|
return after
|
|
|
|
|
|
def install(package_path,codec_directory,wire_dll,*,dry_run=False,presentation_only=False,native_core=None,wire_unix=None):
|
|
if (native_core is not None or wire_unix is not None) and presentation_only:raise ValueError('Native core replacement requires closed-client installation')
|
|
package_path=Path(package_path).resolve();codec_directory=Path(codec_directory).resolve();wire_dll=Path(wire_dll).resolve()
|
|
if (not package_path.is_relative_to(ROOT/'runtime')or not codec_directory.is_relative_to(ROOT/'build')
|
|
or not wire_dll.is_relative_to(ROOT/'build')):raise ValueError('Owned runtime stage and isolated build outputs required')
|
|
package,_=read_compatibility_package(package_path);root,header=package_payloads(package['rows']);pages=package_pages(package['rows'])
|
|
presentation=verify_weapon_presentation(package)
|
|
from item_icon_native_assets import verify_installed_icon_dependency
|
|
native_icons=verify_installed_icon_dependency(package,COPY)
|
|
if (package.get('build')!='1.60.1.70334'or package.get('schema')!='wowstatic_camelot_1_60_1'
|
|
or package.get('push_id')!=root or package.get('pushes')!=pages):raise ValueError('Staged registry build/schema/page identity differs')
|
|
provenance,_=read_public_json(codec_directory/'provenance.json')
|
|
wire_manifest=ROOT/'runtime/native-wire-host.json';engine_manifest=ROOT/'runtime/native-engine-pe.json'
|
|
previous,_=read_public_json(wire_manifest);engine,_=read_public_json(engine_manifest)
|
|
codec=ROOT/'build/forever-schema/libforever_codec.so';private_wire=ROOT/'runtime/native-wine-prefix/drive_c/windows/system32/GWNativeWire.dll'
|
|
if bounded_digest(codec)!=previous['source_codec_sha256']or bounded_digest(private_wire)!=previous['wire_dll_sha256']:raise ValueError('Current owned module differs from journal')
|
|
for key in ('core','wire_unix'):
|
|
if bounded_digest(Path(previous[key+'_path']))!=previous[key+'_sha256']:raise ValueError('Existing native dependency changed')
|
|
inspect_installation(COPY)
|
|
pe=pefile.PE(str(wire_dll));exports={r.name.decode():r.address for r in pe.DIRECTORY_ENTRY_EXPORT.symbols if r.name}
|
|
if not set(previous['wire_exports'])<=set(exports):raise ValueError('New PE removes an existing ABI export')
|
|
wire_hash=bounded_digest(wire_dll);codec_hash=bounded_digest(codec_directory/'libforever_codec.so')
|
|
new_previous=dict(previous,wire_dll_sha256=wire_hash,wire_exports=exports,source_codec_sha256=codec_hash)
|
|
new_engine=dict(engine);new_engine['wire_unix_library']=dict(engine['wire_unix_library'],source_codec_sha256=codec_hash)
|
|
new_engine['auxiliary_dependencies']=[dict(r,sha256=wire_hash,exports=exports)if r['file']=='GWNativeWire.dll'else r for r in engine['auxiliary_dependencies']]
|
|
core_receipt=None;core_path=None;wire_receipt=None
|
|
if native_core is not None:
|
|
native_core=Path(native_core).resolve();core_path=Path(previous['core_path']).resolve()
|
|
if (not native_core.is_relative_to(ROOT/'build')or not core_path.is_relative_to(ROOT/'build')or native_core.is_symlink()
|
|
or not native_core.is_file()or not 0<native_core.stat().st_size<=134217728):raise ValueError('Owned bounded isolated native core required')
|
|
core_receipt=verify_core_replacement(core_path,native_core)
|
|
core_hash=bounded_digest(native_core)
|
|
if engine['wire_unix_library'].get('core_sha256')!=previous['core_sha256']or engine['wire_unix_library'].get('core_path')!=previous['core_path']:
|
|
raise ValueError('Native core ownership manifests disagree')
|
|
new_previous['core_sha256']=core_hash;new_engine['wire_unix_library']['core_sha256']=core_hash
|
|
from compiled_item_render_profile import verify_compiled_item_render_profiles
|
|
compiled_appearances=verify_compiled_item_render_profiles(package,
|
|
native_core if native_core is not None else ROOT/'build/libgateway_native.so',codec_directory/'libforever_codec.so')
|
|
if compiled_appearances is not None and (compiled_appearances['codec']['module_sha256']!=codec_hash
|
|
or compiled_appearances['native_core']['module_sha256']!=(core_hash if native_core is not None else previous['core_sha256'])):
|
|
raise ValueError('Compiled item render consumer changed during inspection')
|
|
outputs={ROOT/'docs/evidence/data/item-sparse-compat/package.json':package_path.read_bytes(),
|
|
ROOT/'include/gateway/item_sparse_compat.hpp':header.encode(),
|
|
codec:(codec_directory/'libforever_codec.so').read_bytes(),
|
|
ROOT/'build/forever-schema/forever-create-codec':(codec_directory/'forever-create-codec').read_bytes(),
|
|
ROOT/'build/forever-schema/provenance.json':(codec_directory/'provenance.json').read_bytes(),
|
|
ROOT/'build/wine-wire/GWNativeWire.dll':wire_dll.read_bytes(),private_wire:wire_dll.read_bytes(),
|
|
wire_manifest:(json.dumps(new_previous,indent=2)+'\n').encode(),
|
|
engine_manifest:(json.dumps(new_engine,indent=2)+'\n').encode()}
|
|
if native_core is not None:outputs[core_path]=native_core.read_bytes()
|
|
if wire_unix is not None:
|
|
wire_unix=Path(wire_unix).resolve();destination=Path(previous['wire_unix_path']).resolve()
|
|
if (not wire_unix.is_relative_to(ROOT/'build') or not destination.is_relative_to(ROOT/'build')
|
|
or wire_unix.is_symlink() or not wire_unix.is_file() or not 0<wire_unix.stat().st_size<=134217728):
|
|
raise ValueError('Owned bounded isolated Wine bridge required')
|
|
wire_receipt=verify_wire_replacement(destination,wire_unix)
|
|
if engine['wire_unix_library'].get('wire_unix_path')!=previous['wire_unix_path'] or engine['wire_unix_library'].get('wire_unix_sha256')!=previous['wire_unix_sha256']:
|
|
raise ValueError('Wine bridge ownership manifests disagree')
|
|
digest=bounded_digest(wire_unix)
|
|
new_previous['wire_unix_sha256']=digest;new_engine['wire_unix_library']['wire_unix_sha256']=digest
|
|
outputs[destination]=wire_unix.read_bytes()
|
|
outputs[wire_manifest]=(json.dumps(new_previous,indent=2)+'\n').encode()
|
|
outputs[engine_manifest]=(json.dumps(new_engine,indent=2)+'\n').encode()
|
|
|
|
if any(path.is_symlink()or not path.is_file()or path.with_name(path.name+'.item-batch-new').exists()for path in outputs):raise ValueError('Existing owned publication file missing/linked or interrupted publication preserved')
|
|
def publication_digest(path,destination=None):
|
|
target=destination or path
|
|
bound=MAX_COMPATIBILITY_PACKAGE_JSON_BYTES if target==ROOT/'docs/evidence/data/item-sparse-compat/package.json'else MAX_TARGET_BYTES
|
|
return bounded_digest(path,bound)
|
|
if provenance.get('item_package_sha256')!=bounded_digest(package_path,MAX_COMPATIBILITY_PACKAGE_JSON_BYTES):raise ValueError('Codec package provenance differs')
|
|
if presentation_only:
|
|
published,_=read_compatibility_package(ROOT/'docs/evidence/data/item-sparse-compat/package.json')
|
|
changed={p:v for p,v in outputs.items()if publication_digest(p)!=hashlib.sha256(v).hexdigest()}
|
|
verify_presentation_only_update(package,published,changed)
|
|
outputs=changed
|
|
report=dict(kind='owned-native-item-batch-installation',registry_rows=len(package['rows']),pushes=pages,
|
|
codec_sha256=codec_hash,pe_sha256=wire_hash,core_unchanged=native_core is None,original_installations_changed=False,
|
|
paths=[str(p.relative_to(ROOT))for p in outputs],installed=False)
|
|
report['mapped_modules_reused']=presentation_only
|
|
if core_receipt is not None:report['native_core_replacement']=dict(core_receipt,sha256=core_hash,source_path=str(native_core.relative_to(ROOT)))
|
|
if wire_receipt is not None:report['wire_unix_replacement']=dict(wire_receipt,runpath='$ORIGIN',source_path=str(wire_unix.relative_to(ROOT)))
|
|
if presentation is not None:report['required_weapon_presentation']=presentation
|
|
if native_icons is not None:report['required_native_icon_assets']=native_icons
|
|
if compiled_appearances is not None:report['compiled_item_render_profiles']=compiled_appearances
|
|
if dry_run:return report
|
|
if not presentation_only and running_clients():raise RuntimeError('Close private client normally before installing mapped modules')
|
|
from native_data_cache import backup
|
|
recovery=ROOT/'recovery'/('native-item-batch-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S'));recovery.mkdir(mode=0o700)
|
|
records=[]
|
|
for index,(path,content)in enumerate(outputs.items()):
|
|
saved=recovery/(str(index)+'-'+path.name);shutil.copy2(path,saved)
|
|
records.append(dict(path=str(path.relative_to(ROOT)),backup=saved.name,old_sha256=publication_digest(saved,path),new_sha256=hashlib.sha256(content).hexdigest()))
|
|
if publication_digest(path)!=records[-1]['old_sha256']:raise RuntimeError('Installation input changed while backing up')
|
|
report.update(files=records,recovery=str(recovery.relative_to(ROOT)),cache_recovery=None if presentation_only else str(backup().relative_to(ROOT)),status='PREPARED',
|
|
restore='Close private client normally. Preserve current files first. Verify backup hashes in files[], then restore each backup to its recorded workspace-relative path and restore the coherent ADB cache. Never touch original installations.')
|
|
if presentation_only:report['restore']='Restore only the two recorded JSON backups after preserving newer metadata. Mapped modules, wire rows and ADB caches were unchanged; no client restart or cache restore is required.'
|
|
atomic_json(recovery/'manifest.json',report)
|
|
for path,content in outputs.items():
|
|
temporary=path.with_name(path.name+'.item-batch-new');temporary.write_bytes(content);shutil.copymode(path,temporary);temporary.replace(path)
|
|
if publication_digest(path)!=hashlib.sha256(content).hexdigest():raise RuntimeError('Publication verification failed; use recovery manifest')
|
|
report.update(installed=True,status='INSTALLED_NATIVE_VERIFICATION_PENDING');atomic_json(recovery/'manifest.json',report)
|
|
return report
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
p.add_argument('--package',type=Path,required=True);p.add_argument('--codec-directory',type=Path,required=True);p.add_argument('--wire-dll',type=Path,required=True)
|
|
p.add_argument('--wire-unix',type=Path,help='Paired relocatable Wine bridge; same ABI/dependencies and $ORIGIN RUNPATH required');p.add_argument('--output',type=Path,required=True);p.add_argument('--dry-run',action='store_true');p.add_argument('--presentation-only',action='store_true',help='Reuse mapped modules/session only when all wire rows and binaries are unchanged');p.add_argument('--native-core',type=Path,help='Paired frozen-source native core; same C exports/SONAME/dependencies required, private client must be closed');a=p.parse_args()
|
|
if not a.output.resolve().is_relative_to(ROOT/'runtime')or a.output.exists():p.error('New runtime installation report required')
|
|
result=install(a.package,a.codec_directory,a.wire_dll,dry_run=a.dry_run,presentation_only=a.presentation_only,native_core=a.native_core,wire_unix=a.wire_unix);atomic_json(a.output,result)
|
|
print('Item registry:',result['registry_rows'],'pages:',len(result['pushes']),'installed:',result['installed'],'report:',a.output)
|