Created
March 3, 2021 16:28
-
-
Save pixelomer/4030283737335afdef2802f9e962f785 to your computer and use it in GitHub Desktop.
Small Objective-C program for finding the longest built-in method name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
static void LoadAllFrameworks(NSString *root) { | |
NSFileManager *defaultManager = [NSFileManager defaultManager]; | |
NSDirectoryEnumerator *enumerator = [defaultManager | |
enumeratorAtURL:[NSURL fileURLWithPath:root] | |
includingPropertiesForKeys:nil | |
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants | |
errorHandler:nil | |
]; | |
NSURL *bundleURL; | |
NSArray *blacklist = @[ | |
@"ActionKit.framework", | |
@"UIKit.framework" | |
]; | |
while ((bundleURL = [enumerator nextObject])) { | |
NSString *lastComponent = [bundleURL lastPathComponent]; | |
if ([blacklist containsObject:lastComponent] || [lastComponent hasSuffix:@"MacHelper.framework"]) { | |
continue; | |
} | |
NSLog(@"==> Loading \"%@\"...", [bundleURL path]); | |
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; | |
@try { | |
[bundle load]; | |
} | |
@catch (NSException *exception) {} | |
} | |
} | |
int main(int argc, char **argv) { | |
LoadAllFrameworks(@"/System/Library/Frameworks"); | |
LoadAllFrameworks(@"/System/Library/PrivateFrameworks"); | |
unsigned int classCount; | |
Class *allClasses = objc_copyClassList(&classCount); | |
Class classForLongestMethodName; | |
const char *longestMethodName = ""; | |
for (unsigned int i=0; i<classCount; i++) { | |
unsigned int methodCount; | |
Method *allMethods = class_copyMethodList(allClasses[i], &methodCount); | |
for (unsigned int j=0; j<methodCount; j++) { | |
SEL methodSelector = method_getName(allMethods[j]); | |
const char *methodName = sel_getName(methodSelector); | |
if (strlen(methodName) > strlen(longestMethodName)) { | |
longestMethodName = methodName; | |
classForLongestMethodName = allClasses[i]; | |
} | |
} | |
free(allMethods); | |
} | |
free(allClasses); | |
printf("Longest method: -[%s %s]\n", class_getName(classForLongestMethodName), longestMethodName); | |
NSBundle *bundle = [NSBundle bundleForClass:classForLongestMethodName]; | |
printf("Source: %s\n", [[bundle description] UTF8String]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On macOS 14.6, this program outputs the following: