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.
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
"""Read-only PE string xrefs and containing x64 runtime functions."""
|
|
import argparse
|
|
import bisect
|
|
from pathlib import Path
|
|
import re
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent / 'python'))
|
|
import pefile
|
|
from capstone import Cs, CS_ARCH_X86, CS_MODE_64
|
|
|
|
def inspect(path, needles):
|
|
pe = pefile.PE(str(path), fast_load=True)
|
|
pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_EXCEPTION']])
|
|
data = path.read_bytes()
|
|
base = pe.OPTIONAL_HEADER.ImageBase
|
|
functions = sorted((e.struct.BeginAddress, e.struct.EndAddress)
|
|
for e in pe.DIRECTORY_ENTRY_EXCEPTION)
|
|
starts = [f[0] for f in functions]
|
|
targets = {}
|
|
for needle in needles:
|
|
for encoding in ('utf-8', 'utf-16le'):
|
|
raw = needle.encode(encoding)
|
|
offset = data.find(raw)
|
|
while offset >= 0:
|
|
rva = pe.get_rva_from_offset(offset)
|
|
targets[rva] = needle
|
|
print(f'STRING {needle!r} {encoding} RVA=0x{rva:x}')
|
|
offset = data.find(raw, offset + 1)
|
|
dump = set()
|
|
for rva, needle in list(targets.items()):
|
|
pointer = (base+rva).to_bytes(8, 'little')
|
|
pos = data.find(pointer)
|
|
while pos >= 0:
|
|
pointer_rva = pe.get_rva_from_offset(pos)
|
|
targets[pointer_rva] = needle + ' [pointer]'
|
|
print(f'POINTER RVA=0x{pointer_rva:x} -> 0x{rva:x}')
|
|
pos = data.find(pointer, pos+1)
|
|
for section in pe.sections:
|
|
if not section.Characteristics & 0x20000000:
|
|
continue
|
|
code = section.get_data()
|
|
for match in re.finditer(rb'(?=([\x48\x4c][\x8d\x8b][\x05\x0d\x15\x1d\x25\x2d\x35\x3d]....))', code, re.DOTALL):
|
|
rva = section.VirtualAddress + match.start()
|
|
target = rva + 7 + int.from_bytes(match.group(1)[3:], 'little', signed=True)
|
|
if target not in targets:
|
|
continue
|
|
index = bisect.bisect_right(starts, rva) - 1
|
|
if index < 0 or rva >= functions[index][1]:
|
|
continue
|
|
start, end = functions[index]
|
|
print(f'XREF {targets[target]!r} RVA=0x{rva:x} FUNCTION=0x{start:x}..0x{end:x}')
|
|
dump.add((start, end))
|
|
md = Cs(CS_ARCH_X86, CS_MODE_64)
|
|
for start, end in sorted(dump):
|
|
print(f'\nFUNCTION RVA=0x{start:x} size={end-start}')
|
|
for ins in md.disasm(pe.get_data(start, end-start), base+start):
|
|
print(f'{ins.address-base:08x} {ins.bytes.hex():24} {ins.mnemonic:8} {ins.op_str}')
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('image', type=Path)
|
|
parser.add_argument('needles', nargs='+')
|
|
args = parser.parse_args()
|
|
inspect(args.image, args.needles)
|