Hook the byte and text validators for the supported game build while retaining original validation for unknown paths and non-project records. Pin executable and UE4SS hashes, provide an MIT-licensed source package, and verify native adapters, supported prologues, import symbols and unsupported-build refusal. In-game startup and gameplay verification remain pending.
62 lines
2.9 KiB
Python
62 lines
2.9 KiB
Python
"""Read-only verification against the user's supplied executables."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
sys.path.insert(0,str(Path(__file__).parent/'python'))
|
|
import pefile
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
parser=argparse.ArgumentParser()
|
|
parser.add_argument('game',type=Path)
|
|
parser.add_argument('ue4ss',type=Path)
|
|
args=parser.parse_args()
|
|
profile=(ROOT/'src/build_profile.hpp').read_text()
|
|
report={}
|
|
for key,path in [('game',args.game),('ue4ss',args.ue4ss)]:
|
|
digest=hashlib.sha256(path.read_bytes()).hexdigest()
|
|
expected=re.search(rf'{key}_sha256\[\] = "([0-9a-f]+)"',profile)[1]
|
|
assert digest==expected,(key,'SHA mismatch')
|
|
report[key+'_sha256']=digest
|
|
game=pefile.PE(str(args.game),fast_load=True)
|
|
for rva,size,digest in re.findall(r'\{0x([0-9a-f]+), 0x([0-9a-f]+), "([0-9a-f]+)"\}',profile):
|
|
rva,size=int(rva,16),int(size,16)
|
|
assert hashlib.sha256(game.get_data(rva,size)).hexdigest()==digest
|
|
report[hex(rva)]={'bytes':size,'sha256':digest}
|
|
game.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_BASERELOC']])
|
|
for block in getattr(game,'DIRECTORY_ENTRY_BASERELOC',[]):
|
|
for reloc in block.entries:
|
|
if reloc.type:
|
|
for start,end in [(0x62ea0e0,0x62ea1a5),(0x62f65a0,0x62f65dd),(0x62f65e0,0x62f6826)]:
|
|
assert not start<=reloc.rva<end,'Runtime code digest would require ASLR relocation'
|
|
report['code_digests_are_aslr_independent']=True
|
|
prologues=ROOT/'build/game-prologues.bin'
|
|
prologues.write_bytes(game.get_data(0x62f65a0,64)+game.get_data(0x62f65e0,64))
|
|
native=subprocess.run([str(ROOT/'build/native_hooks.exe'),str(prologues)],cwd=ROOT,
|
|
capture_output=True,text=True,check=True)
|
|
report['native_tests']=native.stdout.splitlines()
|
|
print(native.stdout,end='')
|
|
dll=ROOT/'dist/ue4ss/Mods/phantombladezero_scriptcompat/dlls/main.dll'
|
|
mod=pefile.PE(str(dll),fast_load=True)
|
|
mod.parse_data_directories(directories=[0,1])
|
|
assert mod.FILE_HEADER.Machine==0x8664
|
|
exports={s.name for s in mod.DIRECTORY_ENTRY_EXPORT.symbols if s.name}
|
|
assert exports=={b'start_mod',b'uninstall_mod'}
|
|
ue=pefile.PE(str(args.ue4ss),fast_load=True)
|
|
ue.parse_data_directories(directories=[0])
|
|
ue_exports={s.name for s in ue.DIRECTORY_ENTRY_EXPORT.symbols if s.name}
|
|
for dep in mod.DIRECTORY_ENTRY_IMPORT:
|
|
if dep.dll.lower()==b'ue4ss.dll':
|
|
assert all(i.name in ue_exports for i in dep.imports),'Missing UE4SS import'
|
|
report['verified_ue4ss_imports']=len(dep.imports)
|
|
assert report.get('verified_ue4ss_imports')==17
|
|
report['dll_sha256']=hashlib.sha256(dll.read_bytes()).hexdigest()
|
|
report['dll_bytes']=dll.stat().st_size
|
|
report['game_test']='PENDING; game was not launched or modified'
|
|
(ROOT/'research/verification.json').write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8')
|
|
print('PASS: pinned executable hashes, ASLR-independent code digests, DLL exports and UE4SS imports')
|