Skip to content

[AUTOMATED] Relabel the C++ definition name each backend prints - #128

Open
sjkim1127 wants to merge 1 commit into
Noelo-Lab:mainfrom
sjkim1127:codex/cpp-relabel-definition-names
Open

sjkim1127 wants to merge 1 commit into
Noelo-Lab:mainfrom
sjkim1127:codex/cpp-relabel-definition-names

Conversation

@sjkim1127

Copy link
Copy Markdown
Contributor

Problem

_relabel_to_dwarf renames a decompiled function by substituting the name its backend reported (fd.name) with the DWARF name. For C++ methods the backends report one spelling and print another:

Backend Reported fd.name Printed definition
angr _ZN6snappy22UncheckedByteArraySink15GetAppendBufferEmPc snappy::UncheckedByteArraySink::GetAppendBuffer(...)
Fission snappy::Sink::GetAppendBuffer(unsigned long, char*) fission_symbol_snappy_x3A__x3A_Sink_x3A__x3A_GetAppendBuffer(...)
Kuna snappy::Sink::GetAppendBuffer snappy::Sink::GetAppendBuffer(...)

Only Kuna's substitution applies. Elsewhere, the decompiled CFG is keyed by the printed spelling and never matches the DWARF-named source CFG, so GED drops the function.

Change

After the existing substitution, find the declarator of the first top-level definition in the decompiled code and rename that spelling to the DWARF name as well. Comments, prototypes and typedefs before the definition are skipped. A DWARF name that is not a C identifier (~Sink, operator==) is left alone, because substituting it would turn valid decompiled C into invalid C.

Evidence

Local C++ corpus: ninja, double-conversion and snappy built for aarch64 at O0, O2 and O2-noinline, decompiled from stripped binaries. On snappy O0, decompiled functions whose name has a matching decompiled CFG:

Decompiler Before After
angr 5 / 144 94 / 144
Fission 5 / 157 118 / 157
Ghidra 5 / 157 118 / 157
Kuna 63 / 157 63 / 157

Across the whole local corpus, scored GED rows with a non-strict parser rose from 3,814 to 4,192, mostly from angr and Fission. This is a local measurement, not an official ranking.

Testing

  • New tests/test_relabel_definition_names.py (13 cases) covers the printed spellings of angr, Fission, Kuna and Ghidra, prototypes before the definition, and a destructor.
  • On macOS, the full suite has the same 54 pre-existing environment failures with and without this change. Ruff and Black pass on the changed files.

Not measured

The published C corpus was not re-run. For C functions the printed and DWARF names normally agree after the existing substitution, so the new step is expected to be a no-op there. A maintainer re-run of the GED overlay would confirm it.

🤖 Generated with Claude Code

[AUTOMATED]

C++ backends report one spelling of a method and print another: angr
reports the mangled symbol but prints ns::Class::method, and Fission
prints an escaped identifier. Replacing only the reported name left the
definition unrenamed, so its decompiled CFG never matched the DWARF
source CFG. Also rename the declarator of the first top-level definition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant