Skip to content

[AUTOMATED] fix(cli): take the C spelling of a Mach-O name, and stop calling every miss stripped - #701

Merged
mahaloz merged 1 commit into
mainfrom
fix/macho-name-lookup
Sep 21, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/macho-name-lookup

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

The problem

Mach-O stores a C identifier with a leading underscore, so the name a caller
reads in the source selects nothing — and the miss advises --addr "for a
stripped binary" on an image whose symbols are all present.

$ K=decompiler/target/release/kuna
$ F=decompiler/crates/kuna-analysis/tests/fixtures/macho_imports
$ $K functions $F
0x1000005a0	_compute	(sub_1000005a0)
0x1000005b0	_main	(sub_1000005b0)
$ $K decompile $F main
error: no function "main" in .../macho_imports; for a stripped binary pass an address with --addr

The fix

  • Name lookup tries the name as given first and retries it with the platform
    underscore only on a miss, so an image that carries both main and _main
    still answers main with main. The decoration is a property of the
    container, read off its magic at load, so ELF/PE/COFF gain no underscore they
    never had. The reverse direction (_main against an image spelling it main)
    is not added — that name is already one the image carries.
  • EntryLookupError::NotFound now carries the near spelling and how many
    entries carry a name the image supplied. The stripped-binary advice is what
    the CLI says when that count is zero; otherwise the miss names the near
    spelling, or says how many names the image does have.
$ $K decompile $F main
unsigned long main(int a0) { ... }
$ $K decompile .../fauxware start
error: no function "start" in .../fauxware; did you mean "_start" (0x400580)?
$ $K decompile .../argclobber_x86_64 zork
error: no function "zork" in .../argclobber_x86_64; for a stripped binary pass an address with --addr

The tests

Four cases in verify_entry_selectors.rs and four in name_miss_cli.rs: the
Mach-O C spelling resolves, an ELF start stays a miss and names _start, a
named image is not reported as stripped, and a placeholder-only one still is.
Each fails on the unpatched tree. A tests/cli/ probe pins the Mach-O
resolution. 675/675 datatests, stages PARITY OK, workspace suite green,
make test-cli 215/215.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ocFS1B6rT3wfWcQsuwE6B

@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 21, 2026
…calling every miss stripped

Mach-O stores a C identifier with a leading underscore, so `int main(void)`
is `_main` in the symbol table and the name a caller reads in the source
selected nothing. Name lookup now tries the name as given first and retries it
decorated only on a miss, scoped to the container that decorates, so an image
carrying both spellings still answers the one it was asked.

The miss itself advised `--addr` "for a stripped binary" whatever the image
held. `EntryLookupError::NotFound` now carries the near spelling and how many
entries carry a name the image supplied; the stripped-binary advice is what the
CLI says when that count is zero.

Closes #666.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015ocFS1B6rT3wfWcQsuwE6B
@mahaloz
mahaloz force-pushed the fix/macho-name-lookup branch from f798e42 to ea0aec4 Compare September 21, 2026 17:17
@mahaloz
mahaloz merged commit d072341 into main Sep 21, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/macho-name-lookup branch September 21, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant