Get iOS classes by Objective-C runtime feature

Hooking something in iOS is really interesting while checking header files to find them is boring. So there are some codes to print a  list of classes by using Objective-C runtime feature.

In fact, these codes work in OS X, too. I find them in Xcode documents. And I made a little modification on them.

Code

int numClasses;
Class * classes = NULL;
if ((numClasses = objc_getClassList(NULL, 0)) > 0 ){
classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
        for (int i = 0; i < numClasses; i++) {
                printf("%sn",class_getName(classes[i]));
}
        free(classes);
}

Within the result of these codes, I created a Xcode template. It's useful when you want to hook a class but without libsubstrate.dylib. You can find this template here.

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty − 13 =