Repository navigation
Metadata: Mach-O Objective-C method-name recovery (s1_objc, x86-64) - #109
Merged
Merged
Conversation
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
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.
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 ofsub_<addr>.Before / after
On a (locally-)stripped x86-64 Objective-C Mach-O (
tests/fixtures/macho_objc), decompiling the IMP at0x100000640: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 ofclass_t*, stride=ptr) → per classdata & FAST_DATA_MASK(~0x7) →class_ro_t→.name(class name) +.baseMethods(the-instancemethod_list_t); followclass_t.isato the metaclassbaseMethods(the+class methods). Themethod_list_twalk 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 viaout.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.muses a root class (__attribute__((objc_root_class))), so it needs no macOS SDK / Foundation — bareclangsynthesizes the__objc_*metadata from the@interface/@implementationalone, thenld64.lld -xstrips the local IMP symbol (the exactmacho_importsrecipe +-x). No real-macOS slice needed; x86-64, no chained fixups (this toolchain's clang emits classic rebase pointers). VMAs pinned infixtures/README.md.Gate (the
fidprecedent, full wiring)passes.rs—passes_for(compiler, format); the pass registers only whenformat == MachO(the Mach-O-format gate, likegopclntab's Go gate).engine.rs::analysis_pass_enabled—"objc" => arch.analysis_objc(default-off, output-changing).architecture.rs—analysis_objcfield / default-false / reset-false /on_off!arm.options.rs—KUNA_OPTION_NAMES += "objc".stages.toml— a[[settable]] objcblock cloned from thefidrow.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_livestays 28),KUNA-CATALOG #5/#9max(66 → 67); regeneratedstage_catalog.json+docs/assertions.md;kuna catalog --check→ OK.Gates (all four green)
make test— 675/675 PARITY OKmake test-stages— 235/235 PARITY OKmake rust-test— green (incl.verify_objc, which RUNS — not skipped — plus a spec-lesss1_objcfixture-walk unit test)kuna catalog --check— OKDefault-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_FIXUPSresolver (PR-O0/O2), ivar/method-type prototypes, and theobjc_msgSendannotation are deferred.🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb