Recover OMT resources, morph topology, and original engine evidence
This commit is contained in:
1 parent
d62e2ab4de
commit
3df20ac19a
12 files changed
+1648
No files matched your search
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Find MSVC x86 RTTI complete-object locators and candidate vtables.
|
||||
|
||||
Output is evidence, not a claim that every candidate is an actual vtable.
|
||||
Usage: python3 tools/binary/rtti_map.py ../Original/Neutron.exe C3DJimmy
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import struct
|
||||
from pe_inspect import PE
|
||||
|
||||
|
||||
def rtti_map(pe, class_name):
|
||||
marker = ('.?AV'+class_name+'@@').encode('ascii')
|
||||
at = pe.data.find(marker)
|
||||
if at < 8:
|
||||
raise ValueError(f'No type descriptor for {class_name}')
|
||||
type_va = pe.va(at-8)
|
||||
result = dict(class_name=class_name, type_descriptor=hex(type_va), vtables=[])
|
||||
for m in re.finditer(re.escape(struct.pack('<I', type_va)), pe.data):
|
||||
off = m.start()-12
|
||||
if off < 0 or off % 4:
|
||||
continue
|
||||
sig, displacement, ctor_displacement, _, hierarchy = struct.unpack_from('<IIIII', pe.data, off)
|
||||
if sig != 0 or displacement > 0x100000:
|
||||
continue
|
||||
locator_va = pe.va(off)
|
||||
for ref in re.finditer(re.escape(struct.pack('<I', locator_va)), pe.data):
|
||||
if ref.start() % 4:
|
||||
continue
|
||||
methods = []
|
||||
for i in range(512):
|
||||
pos = ref.start()+4+i*4
|
||||
if pos+4 > len(pe.data):
|
||||
break
|
||||
va = pe.u32(pos)
|
||||
try:
|
||||
function_off = pe.offset(va-pe.base)
|
||||
section = next(s for s in pe.sections if s['file_offset'] <= function_off < s['file_offset']+s['raw_size'])
|
||||
if section['name'] != '.text':
|
||||
break
|
||||
except (ValueError, StopIteration):
|
||||
break
|
||||
methods.append(dict(slot=hex(i*4), va=hex(va)))
|
||||
if methods:
|
||||
result['vtables'].append(dict(va=hex(pe.va(ref.start()+4)),
|
||||
complete_object_locator=hex(locator_va), object_displacement=hex(displacement),
|
||||
hierarchy=hex(hierarchy), methods=methods))
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('binary')
|
||||
parser.add_argument('class_name')
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(rtti_map(PE(args.binary), args.class_name), indent=2))
|
||||
Reference in new issue
Block a user