Skip to content

Metadata: Mach-O Objective-C method-name recovery (s1_objc, x86-64) - #109

Merged
mahaloz merged 2 commits into
mainfrom
metadata-objc
Jun 27, 2026
Merged

mahaloz merged 2 commits into
mainfrom
metadata-objc

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Headline

A gated, default-off Mach-O Objective-C metadata analyzer (the kuna analog of Ghidra's ObjcTypeMetadataAnalyzer, name-recovery half). It walks the __objc_* ObjC 2.0 metadata web and renames each IMP function -[Class sel] / +[Class sel] — so a stripped IMP renders the real method name instead of sub_<addr>.

Before / after

On a (locally-)stripped x86-64 Objective-C Mach-O (tests/fixtures/macho_objc), decompiling the IMP at 0x100000640:

--option objc off (default) →  sub_100000640
    int4 sub_100000640(unsigned long a0,unsigned long a1,int4 a2) { return a2 * 3 + 7; }

--option objc on            →  -[Greeter greet:]
    int4 -[Greeter greet:](unsigned long a0,unsigned long a1,int4 a2) { return a2 * 3 + 7; }

The name changes — sub_* → -[Greeter greet:] — in both the symbol table AND the rendered body; the math body is identical either way. The fixture is stripped (ld64.lld -x), so the IMP has no leftover symbol — only the __objc_* metadata recovers the name.

The walk (design §3.2)

__objc_classlist (array of class_t*, stride=ptr) → per class data & FAST_DATA_MASK (~0x7) → class_ro_t → .name (class name) + .baseMethods (the - instance method_list_t); follow class_t.isa to the metaclass baseMethods (the + class methods). The method_list_t walk handles both forms — the large absolute-pointer form (the §3.2 MVP) AND the small/relative form (entsizeAndFlags & 0x80000000) a modern clang actually emits (__TEXT,__objc_methlist) — resolving the selector (plain ASCII, no demangler needed), the type encoding, and the IMP VA (32-bit ARM Thumb LSB stripped). Emits the IMP rename via out.fid_names (the label-gated placeholder rename, the FID precedent — never overwrites a real symbol), plus _OBJC_CLASS_$_<name> + selector symbols.

How the fixture is built (the root-class trick)

macho_objc.m uses a root class (__attribute__((objc_root_class))), so it needs no macOS SDK / Foundation — bare clang synthesizes the __objc_* metadata from the @interface/@implementation alone, then ld64.lld -x strips the local IMP symbol (the exact macho_imports recipe + -x). No real-macOS slice needed; x86-64, no chained fixups (this toolchain's clang emits classic rebase pointers). VMAs pinned in fixtures/README.md.

Gate (the fid precedent, full wiring)

  • passes.rs — passes_for(compiler, format); the pass registers only when format == MachO (the Mach-O-format gate, like gopclntab's Go gate).
  • engine.rs::analysis_pass_enabled — "objc" => arch.analysis_objc (default-off, output-changing).
  • architecture.rs — analysis_objc field / default-false / reset-false / on_off! arm.
  • options.rs — KUNA_OPTION_NAMES += "objc".
  • stages.toml — a [[settable]] objc block cloned from the fid row.

Settable count 65 → 66 (computed, not hard-coded): bumped kuna_num_settables/SETTABLE_TABLE.len (66), the },\n-comma count (64 → 65), the catalog "option": count (65 → 66), objc → PASS_GATES (suppressed-set; with_live stays 28), KUNA-CATALOG #5/#9 max (66 → 67); regenerated stage_catalog.json + docs/assertions.md; kuna catalog --check → OK.

Gates (all four green)

  • make test — 675/675 PARITY OK
  • make test-stages — 235/235 PARITY OK
  • make rust-test — green (incl. verify_objc, which RUNS — not skipped — plus a spec-less s1_objc fixture-walk unit test)
  • kuna catalog --check — OK

Default-off + Mach-O-real-binary-path only ⇒ the XML datatest path never constructs an ObjectLoadImage, so the parity oracles are byte-identical by construction.

Scope / deferred (design §3.2 LOSS)

ObjC v2 only; standalone Mach-O only (no dyld-shared-cache); the arm64 + LC_DYLD_CHAINED_FIXUPS resolver (PR-O0/O2), ivar/method-type prototypes, and the objc_msgSend annotation are deferred.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 27, 2026 17:16
Add a gated, default-off Mach-O Objective-C metadata analyzer (the kuna
analog of Ghidra's ObjcTypeMetadataAnalyzer, name-recovery half). It walks
the __objc_* ObjC 2.0 metadata web and renames each IMP function
-[Class sel] / +[Class sel] — so a stripped IMP renders -[Greeter greet:]
instead of sub_<addr>.

The headline before/after, on a (locally-)stripped x86-64 ObjC Mach-O:

    --option objc off (default) →  sub_100000640
        int4 sub_100000640(...) { return a2 * 3 + 7; }
    --option objc on            →  -[Greeter greet:]
        int4 -[Greeter greet:](...) { return a2 * 3 + 7; }

The walk (design §3.2): __objc_classlist (array of class_t*, stride=ptr) →
per class data & FAST_DATA_MASK (~0x7) → class_ro_t → .name (class name) +
.baseMethods (the - instance method_list_t); follow class_t.isa to the
metaclass baseMethods (the + class methods). The method_list_t walk handles
BOTH forms — the large absolute-pointer form AND the small/relative form
(entsizeAndFlags & 0x80000000) a modern clang actually emits — resolving the
selector (plain ASCII, no demangler), the type encoding, and the IMP VA.
Emits the IMP rename via out.fid_names (the label-gated placeholder rename,
the FID precedent), plus _OBJC_CLASS_$_<name> + selector symbols.

New: kuna-analysis/src/s1_objc/{mod,sections,classt,methods}.rs;
kuna-console/tests/verify_objc.rs (the two-state e2e, RUNS not skipped);
the vendored macho_objc fixture (a root-class Greeter, built bare-clang +
ld64.lld -x, no macOS SDK) + macho_objc.m + a README entry pinning the
IMP/class/method-list VMAs.

Gate (the fid precedent, full wiring): passes.rs behind a Mach-O-format gate
(passes_for(compiler, format)); engine.rs analysis_pass_enabled
"objc" => arch.analysis_objc; architecture.rs analysis_objc
field/default-false/reset/on_off arm; options.rs KUNA_OPTION_NAMES += "objc";
a [[settable]] objc block in stages.toml cloned from the fid row. Settable
count 65 → 66: bumped kuna_num_settables/SETTABLE_TABLE.len, the },\n-comma
count (64→65), the catalog "option": count (65→66), objc → PASS_GATES
(with_live stays 28), KUNA-CATALOG #5/#9 max (66→67); regenerated
stage_catalog.json + docs/assertions.md; kuna catalog --check → OK.

Default-off + Mach-O-real-binary-path only ⇒ the parity oracles are
structurally untouched: make test 675/675 PARITY OK, make test-stages 235/235
PARITY OK, make rust-test green (incl. verify_objc), kuna catalog --check 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
#	decompiler/crates/kuna-analysis/src/passes.rs
#	decompiler/crates/kuna-console/tests/verify_multiformat_sourcelang.rs
#	decompiler/crates/kuna-decomp/src/p0_knowledge/kuna_stages/tests.rs
#	decompiler/crates/kuna-decomp/tests/catalog_bytecompat.rs
#	docs/analysis-port-log.md
@mahaloz
mahaloz merged commit 91be355 into main Jun 27, 2026
@mahaloz
mahaloz deleted the metadata-objc branch July 29, 2026 08:01
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