#14023

[Bug] inspect-native-dispatch-metadata omits Objective-C categories that Swift lists in __objc_catlist2

OpenLew1sWongopened 3d ago

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

Native analysis or decompilation

Observed behavior

inspect-native-dispatch-metadata never reads __objc_catlist2. Swift lists a category there when its class is reached through a Swift class stub, for example an @objc extension of a class whose superclass comes from a resilient module. The Objective-C runtime loads this list as well as __objc_catlist. REA returns objc_categories: [], no category implementations, and reports objc_properties_categories as complete with examined: 0.

Reproduction

macOS 27.0.1 arm64, Apple Swift 6.4, REA 6.10.1 at b565f787c.

printf 'import Foundation\nopen class Base: NSObject {}\n' > Base.swift
printf 'import Foundation\nimport ResLib\nclass Child: Base {}\nextension Child { @objc func extra() {} }\nprint(Child())\n' > main.swift
swiftc -emit-library -enable-library-evolution -emit-module -module-name ResLib Base.swift -o libResLib.dylib
swiftc main.swift -I . -L . -lResLib -module-name app -o app
otool -ov app          # (__DATA_CONST,__objc_catlist2): category "app", cls _$s3app5ChildCMs (the class stub), 1 instance method
node scripts/rea.mjs inspect-native-dispatch-metadata app --format json

REA returns objc_categories: [], and its objc_properties_categories coverage is {"status":"complete","examined":0,"decoded":0}.

A real case is the arm64e slice of /System/Applications/Stocks.app/Contents/MacOS/Stocks, extracted with lipo -thin arm64e. Its only category is StocksApp, listed in __objc_catlist2. otool shows that the category has 12 instance methods and adopts TUWindowRestorationManagerDelegate. REA reports no categories and complete coverage.

7 of the 65 main executables under /System/Applications and /System/Applications/Utilities have a __objc_catlist2 section: App Store, Books, Font Book, Journal, Reminders, Stocks and Voice Memos.

Expected behavior

The tool decodes __objc_catlist2 categories as it decodes __objc_catlist categories. This is source-derived from Apple's objc4 runtime. load_categories_nolock processes both lists, and notes that "Categories in catlist2 point to stub classes".

A stub is not a class_t. Its first word is a small value; isStubClass checks 1 <= isa && isa < 16. A category on a stub should therefore keep an unresolved class, with a reason that names the stub. It should not get a class name read from the bytes after the stub.

Impact and scope

P2. These categories and their methods are missing, while the coverage reports complete. An analyst therefore has no signal that they exist. In Stocks this hides 12 @objc entry points, including scene:openURLContexts: and windowScene:performActionForShortcutItem:completionHandler:.

Classes in __objc_classlist and categories in __objc_catlist are unaffected.

REA version

6.10.1, source b565f787c

Runtime and platform

Node.js 24.22.1; macOS 27.0.1 (26A434) arm64; Apple Swift 6.4

Target and artifact context

A binary built locally with swiftc, plus a slice of a stock macOS system app; no private target

Interface

CLI

Earliest failure stage

Native analysis or reconstruction

Relevant output or evidence

See Reproduction.

Typed outcome or recovery expected

For app, the category app is returned with its extra method. Its class_name is null, because the class reference is a Swift class stub, and the coverage names that reference.

Analysis or suspected cause

Source-derived: decodeObjcCategories in src/native/AppleObjcCategories.ts iterates only sections named __objc_catlist.

Reading __objc_catlist2 alone is not enough. The local class path reads the stub as a class_t. In Stocks it takes the stub's data word and returns the method type encoding @"UIWindow"24@0:8@"TUWindowRestorationManager"16 as a local class name, with the category marked decoded.

Additional context

I have a fix with regression tests ready and will open a PR.

Activity

0

No activity yet.