XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
"""Bind original published mission tables/getters to the current PE, without calls."""
from pathlib import Path
import hashlib, importlib.util, json, struct

spec=importlib.util.spec_from_file_location('audit',Path(__file__).with_name('Audit-GalaxyClientCompatibility.py'))
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
old=m.Image(Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe'))
new=m.Image(Path('D:/SteamLibrary/steamapps/common/Elite Dangerous/Products/elite-dangerous-odyssey-64/EliteDangerous64.exe'))
functions=[];refs=[]
for before in (0x208CD90,0x208E800,0x208EED0,0x20D1C40,0x20D1E10,0x20D1A00,0x3A69D00,0x3A8A190,0x20E0E60):
    span=old.function(before);length=span[1]-before if span else 512
    row=m.match(old,new,before,length)
    if row['status']!='unique':raise ValueError('Unclosed mission body '+hex(before)+': '+row['status'])
    row['oldRva']=hex(before);functions.append(row)
    refs.extend(m.references(old,new,before,int(row['newRva'],16),row['length']))
tables={}
for before in (0x525EE48,0x525EE78,0x525EF78,0x52609F8,0x5260A48,0x5260BA8,0x5260BF8):
    after={r[1] for r in refs if r[0]==before}
    if len(after)!=1:raise ValueError('Unclosed original mission table '+hex(before))
    tables[before]=after.pop()
slots=[]
for table,offset in ((0x525EF78,0),(0x525EF78,0x70),(0x525EF78,0x78),
    (0x5260A48,0x38),(0x5260A48,0xD8),(0x5260A48,0xE0),
    (0x5260BF8,0x38),(0x5260BF8,0xD8),(0x5260BF8,0xE0)):
    before=struct.unpack('<Q',old.data(table+offset,8))[0]-old.base
    after=struct.unpack('<Q',new.data(tables[table]+offset,8))[0]-new.base
    length=next(i.address+i.size-old.base-before for i in old.instructions(before,96) if i.mnemonic=='ret')
    raw,mask,*_=m.signature(old,before,length);actual=new.data(after,length)
    if any(a!=b for a,b,keep in zip(raw,actual,mask) if keep):raise ValueError('Mission leaf slot changed')
    paired=m.references(old,new,before,after,length);refs.extend(paired)
    slots.append(dict(oldVtable=hex(table),newVtable=hex(tables[table]),slot=hex(offset),oldRva=hex(before),newRva=hex(after),bytes=length,
        oldSha256=hashlib.sha256(raw).hexdigest(),newSha256=hashlib.sha256(actual).hexdigest(),references=[list(map(hex,r)) for r in paired]))
globals={}
for before in (0x5F53244,):
    candidates={r[1] for r in refs if r[0]==before}
    if len(candidates)!=1:raise ValueError('Original mission ID binding ambiguous')
    globals[hex(before)]=hex(candidates.pop())
output=dict(runtimeNeutral=True,canInstallHooks=False,gameCalls=0,networkRequests=0,
    oldImage=dict(path=str(old.path),sha256=hashlib.sha256(old.raw).hexdigest()),
    newImage=dict(path=str(new.path),sha256=hashlib.sha256(new.raw).hexdigest()),functions=functions,
    vtables={hex(a):hex(b) for a,b in tables.items()},slots=slots,globals=globals)
path=Path('artifacts/galaxy-query-research/fleet-mission-sources/missions-compatibility.json')
path.write_text(json.dumps(output,indent=2)+'\n')
print(json.dumps(dict(vtables=output['vtables'],globals=globals,functions=len(functions),slots=slots),indent=2))