# MSVC RTTI vtables read straight from the exe (TypeDescriptor -> CompleteObjectLocator -> vftable, bases from the # ClassHierarchyDescriptor). Usage: # vtable.py exe functions.tsv zhl_vtables.tsv CLASS [maxslots] print CLASS's slots with their current names # vtable.py exe functions.tsv zhl_vtables.tsv names.tsv lines for still-FUN_ slots whose slot name a base # class declares in REPENTOGON (zhl_vtables.tsv) import struct, sys, re, collections exe, fns_path, zv_path = sys.argv[1:4] data = open(exe, 'rb').read() names = {int(p[0], 16): p[1] for p in (l.rstrip('\n').split('\t') for l in open(fns_path)) if len(p) >= 2} zv = collections.defaultdict(dict) for l in open(zv_path): c, s, n = l.rstrip('\n').split('\t'); zv[c][int(s)] = n pe = struct.unpack_from(' (vtable offset, bases list nearest first) for m in re.finditer(rb'\.\?AV[\w@]+?@@\x00', data): tdva = off2va(m.start() - 8); cls = tdname(tdva) if not cls or cls in vt: continue for k in re.finditer(re.escape(struct.pack(' 200: return out out.append(f) if len(sys.argv) > 4: for cls in [c for c in vt if c == sys.argv[4] or c.endswith('::' + sys.argv[4])]: print(f'{cls} vftable @ {off2va(vt[cls][0]):08x}, bases: {", ".join(vt[cls][1]) or "-"}') for i, f in enumerate(slots(cls)[:int(sys.argv[5]) if len(sys.argv) > 5 else 60]): print(f' {i:2d} {f:08x} {names.get(f, "?")}') sys.exit() seen = set() for cls, (o, bases) in sorted(vt.items()): for i, f in enumerate(slots(cls)): if not names.get(f, '').startswith('FUN_') or f in seen: continue for b in [cls] + bases: nm = zv.get(b, {}).get(i) # REPENTOGON's declared layout only: names on base stubs are often ICF-folded if nm: print(f'{f:08x}\t{cls}::{nm}\tvtable slot {i} of {cls}; slot name from {b}'); seen.add(f); break