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.

声明: 本文为0xBBC原创, 转载注明出处喵~

发表评论

电子邮件地址不会被公开。 必填项已用*标注