Search code examples
objective-cobjdumpmach-ootool

How to print the names of all Objective-C classes in an iOS binary?


I want to print the names of all Objective-C classes found in an iOS binary using "otool" or "objdump". I am doing this on macOS, on an iOS binary that is not encrypted.

What I tried:

  1. Solution suggested here How to statically dump all ObjC methods called in a Cocoa App?
otool -oV /path to executable/ | grep name | awk '{print $3}'

but i don't know how to only parse the objective-c class names.

  1. Solution using "nm" but i dont really like it:
nm /path to executable/ | grep _OBJC_CLASS_

Can you guys help me with a cmd/script to print the names of all Objective-C classes in an iOS binary?


Solution

  • I assume what you don't like about

    nm /path to executable/ | grep _OBJC_CLASS_ 
    

    output:

    0000000100003d08 S _OBJC_CLASS_$_AppDelegate
                     U _OBJC_CLASS_$_UIResponder
                     U _OBJC_CLASS_$_UIViewController
    0000000100003c90 S _OBJC_CLASS_$_ViewController
    

    are the parent classes marked with U.

    Using otool I got to:

    otool -tv /path to executable/|grep ]|awk '{print substr($1,3)}'|uniq 
    

    yielding in comparison

    ViewController
    AppDelegate