3 Commits

Author SHA1 Message Date
Matt Graham 12e8ba06dc rtti: word reads stay inside file-backed bytes; executable sections count as code
Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-11 23:49:41 +00:00
sp00nz d901dcf7ee tools.rtti: --names, so the generated C carries class names
RTTI gives class names, not member names, so a method's own name is not
recoverable -- but the owning class is, and "CBaseEntity__000162C2" beats
"sub_000162C2" both for reading generated code and for crash stacks.
--names emits the {address: name} format merge_names.py --apply already
consumes, so this plugs into the existing naming path rather than adding
one.

Which class owns a method appearing in several vtables is well defined,
unlike per-slot declaration: the vtables share one implementation because
they inherit it, so the declaring class is the one that is an ancestor of
every other class in the set. That needs only the hierarchy sets, no MSVC
layout modelling. On Half-Life 2 it resolves 2,528 shared methods on top
of the 8,992 already unique -- 11,520 of 12,288 (94%) -- and returns zero
ambiguous cases. The 768 with no common ancestor are multiple inheritance
and thunks shared between unrelated classes; they are omitted rather than
guessed at.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BuW5WGcXFFrLAYEfvCNGs1
2026-09-01 00:01:09 -07:00
sp00nz af7b4541cd tools.rtti: recover C++ classes and vtables from MSVC RTTI
A title compiled as C++ with RTTI left on describes its own class graph in
the shipping binary. MSVC stores the CompleteObjectLocator at vtable[-1],
so vtable discovery is mechanical: find the COLs, find words pointing at
one, and the method array starts 4 bytes later.

The payoff that changes pipeline output is not the names, it is the
function starts. A method only ever called virtually is invisible to both
linear sweep and call-target scanning -- nothing in the image names its
address except the vtable. --seeds emits those addresses for
tools.disasm --seed-functions, which is why this runs BEFORE disasm.

On Half-Life 2: 2,336 type descriptors, 2,932 vtables, 176,865 slots,
12,288 unique methods. 7,992 of those addresses fell in bytes the sweep
never claimed (only 10 landed inside a known function, all adjustor
thunks), taking the function count 33,140 -> 41,215 (+24%). disasm also
realigned 19 seeded addresses it had stepped over.

RTTI is uncommon: of the eight titles on hand only HL2 has a usable
graph, Crimson Skies and the dashboard carry 4 CRT type_info records with
no vtables, and the rest have none. Absence is a normal result -- the
tool reports zero and exits 0, so regen.sh scripts can run it
unconditionally. Verified against all eight.

Deliberately does not infer which ancestor declared a slot: the
BaseClassDescriptor array is a depth-first preorder, so trailing entries
are secondary inheritance branches rather than the least-derived base,
and multiple inheritance makes the question need real layout modelling.

Reuses abi_analysis's XbeFile, so it needs no analysis JSON and can run
straight after xbe_parser.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BuW5WGcXFFrLAYEfvCNGs1
2026-08-31 23:56:07 -07:00