Repository navigation
Metadata: MSVC RTTI class-name recovery (s1_rtti, x86+x64) - #108
Merged
Merged
Conversation
…, x86+x64)
PR 1 of 3 of the PE/Mach-O deep-metadata frontier (canonical design in the
co-landed docs/metadata-analyzers-design.md). The kuna analog of Ghidra's
RttiAnalyzer: on a Windows PE built by MSVC (or clang -target ...-windows-msvc),
recover the C++ class names from the run-time type information graph in
.rdata/.data.
The walk (port of RttiAnalyzer.added(), entirely in the loaded image): find the
common type_info vftable (the pointer every RTTI0 TypeDescriptor shares) -> locate
the TypeDescriptors by scanning for the `.?A...@@` type-info names -> byte-search
back to each CompleteObjectLocator (COL = ref - 12) -> validate the
COL -> RTTI3 -> RTTI2 -> RTTI1 -> RTTI0 chain -> demangle each class name -> emit
`<Class>::RTTI_Type_Descriptor` / `<Class>::RTTI_Complete_Object_Locator` /
`<Class>::vftable` Data labels, so `Box`/`Shape` surface as recovered classes.
x86 vs x64 (design 3.1f, isolated in refkind.rs): inter-structure refs are raw VAs
on x86 but image-base-relative IBO32 disp32 on x64; the RTTI0 name string sits at
TypeDescriptor offset 8 (x86) / 16 (x64). Both verified against the real fixtures.
Zero new demangler code: s1_demangle::demangle_rtti_class_name reuses the existing
msvc_demangler crate via the Ghidra RttiUtil `??_R0...@8` wrap.
Gated default-OFF (--option rtti on), registered in passes_for ONLY for a PE image
(the pass also self-gates on PE in run); the facts commit only behind the
analysis_rtti gate. Real-PE-path-only + default-off => the XML datatest oracles are
structurally untouched. Settable count 65 -> 66; catalog regenerated.
Fixtures: clang -target {x86_64,i686}-pc-windows-msvc -fuse-ld=lld -nostdlib emits
a linked PE with the genuine MSVC RTTI bytes (a one-cell inline-asm stub supplies
the only CRT symbol the Type Descriptors reference, ??_7type_info@@6b@). Both arches
vendored with the .cpp source + a README entry pinning the COL/RTTI0/vftable VMAs.
Gates: make test 675/675 PARITY OK; make test-stages 235/235 PARITY OK
(KUNA-CATALOG #5/#9 max 66 -> 67 -- the catalog script emits the full catalog + one
returnpair single-row, so the count is settables+1); make rust-test green incl. the
new verify_rtti e2e (4 tests, x64+x86 x on/off, ran not skipped); kuna catalog
--check catalog OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
# Conflicts: # decompiler/crates/kuna-analysis/src/lib.rs # docs/analysis-port-log.md
This was referenced Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Metadata frontier, PR 1 of 3 — MSVC RTTI class-name recovery
The kuna analog of Ghidra's
RttiAnalyzer(a Microsoft-PE analyzer), and the first of the three PE/Mach-O deep-metadata analyzers laid out in the canonical design doc this PR also lands (docs/metadata-analyzers-design.md). On a Windows PE built by MSVC (orclang -target …-windows-msvc), it recovers the C++ class names from the run-time type information graph — the one self-contained, highest-ROI metadata analyzer.Before → after
On a polymorphic-C++ PE (
tests/fixtures/msvc_rtti_x{64,86}.exe, one base classShape+ one derived classBoxwith a virtual method):The walk (port of
RttiAnalyzer.added(), entirely in the loaded image)Find the common
type_infovftable (the pointer every RTTI0TypeDescriptorshares; ≥2 agreeing) → locate theTypeDescriptors by scanning for the.?A…@@type-info name strings → byte-search the image for a reference to eachTypeDescriptor,−12= theCompleteObjectLocator(COL) base → validate the COL→RTTI3ClassHierarchyDescriptor→RTTI2BaseClassArray→RTTI1BaseClassDescriptor→RTTI0 reachability chain → demangle each.?A…@@class name → emit the<Class>::RTTI_Type_Descriptor/<Class>::RTTI_Complete_Object_Locator/<Class>::vftableData labels.x86 vs x64 ref-kind handling (design §3.1f — the one place a port goes wrong)
Isolated in
s1_rtti/refkind.rs(RefKind::new(is64, image_base, end)); the walk never branches onis64directly:image_base + disp32Both arches verified against the real fixtures (
objdump -s -j .rdata).Zero new demangler code: the new
s1_demangle::demangle_rtti_class_namereuses the samemsvc_demanglercrate already driving the MSVC arm — it wraps the.?A…@@type-info name as??_R0<name>@8(the GhidraRttiUtilrecipe) and demangles that, taking the class prefix of…::RTTI Type Descriptor'. RecoversBox,Shape, namespacedns::Inner, and templatedVec→Vec`.Gate + catalog
Default-OFF (
--option rtti on), registered inpasses_forONLY forBinaryFormat::Pe(the pass also self-gates on PE inrun); the facts are committed only behind the"rtti" => arch.analysis_rttigate. Real-PE-path-only + default-off ⇒ the XML datatest oracles are structurally untouched. Settable count65 → 66(stages.toml+ all count assertions);kuna catalog --check→ catalog OK.Gates (all four green)
make test— 675/675 PARITY OKmake test-stages— 235/235 PARITY OK (KUNA-CATALOG Stage reorg #5/Fix test stages #9use_when/change_kindmax66 → 67: the catalog<script>emits the full catalog + onereturnpairsingle-row, so the count is settables+1)make rust-test— green, incl. the newverify_rttie2e (4 tests — x64+x86 × on/off — ran, not skipped) + the regenerated catalog/count testskuna catalog --check— catalog OKFixtures
clang -target {x86_64,i686}-pc-windows-msvc -fuse-ld=lld -nostdlibemits a linked PE with the genuine MSVC RTTI bytes in.rdata(a one-cell inline-asm stub supplies the only CRT symbol the Type Descriptors reference,??_7type_info@@6B@, so it links freestanding). Both arches built inkuna-dev, vendored with the.cppsource + a README entry pinning the COL/RTTI0/vftable VMAs.🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb