Reputation: 286
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:
otool -oV /path to executable/ | grep name | awk '{print $3}'
but i don't know how to only parse the objective-c class names.
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?
Upvotes: 1
Views: 1923
Reputation: 38234
Here is a little python script that would also do that.
def get_objc_class_names(app_dsym_file):
# nm app_dsym_file | grep _OBJC_CLASS_ | sed 's/.*$_//g'
nm = subprocess.Popen(["nm", app_dsym_file], stdout=subprocess.PIPE)
grep = subprocess.Popen(["grep", "_OBJC_CLASS_"], stdin=nm.stdout, stdout=subprocess.PIPE)
# Remove leading characters from output like: 000000010a643638 s _OBJC_CLASS_$_MyClass
sed = subprocess.Popen(["sed", "s/.*$_//g"], stdin=grep.stdout, stdout=subprocess.PIPE)
nm.stdout.close() # Allow nm to receive a SIGPIPE if p2 exits.
grep.stdout.close() # Allow grep to receive a SIGPIPE if p2 exits.
output,err = sed.communicate()
# Get uniq class names
objc_class_names = set(output.strip().decode('utf8').split('\n'))
return objc_class_names
Upvotes: 0
Reputation: 5543
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
Upvotes: 6