-
Notifications
You must be signed in to change notification settings - Fork 0
/
findclass.py
52 lines (41 loc) · 1.81 KB
/
findclass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import lldb
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f findclass.findclass findclass')
def findclass(debugger, command, result, internal_dict):
"""
The findclass command will dump all the Objective-C runtime classes it knows about.
Alternatively, if you supply an argument for it, it will do a case sensitive search
looking only for the classes which contain the input.
Usage: findclass # All Classes
Usage: findclass UIViewController # Only classes that contain UIViewController in name
"""
codeString = r'''
@import Foundation;
int numClasses;
Class * classes = NULL;
classes = NULL;
numClasses = (int)objc_getClassList(NULL, 0);
NSMutableString *returnString = [NSMutableString string];
classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses);
numClasses = (int)objc_getClassList(classes, numClasses);
for (int i = 0; i < numClasses; i++) {
Class c = classes[i];
[returnString appendFormat:@"%s,", (char *)class_getName(c)];
}
free(classes);
returnString;
'''
res = lldb.SBCommandReturnObject()
debugger.GetCommandInterpreter().HandleCommand("po " + codeString, res)
if res.GetError():
raise AssertionError("Uhoh... something went wrong, can you figure it out? :]")
elif not res.HasResult():
raise AssertionError("There's no result. Womp womp....")
returnVal = res.GetOutput()
resultArray = returnVal.split(",")
if not command: # No input supplied
print returnVal.replace(",", "\n").replace("\n\n\n", "")
else:
filteredArray = filter(lambda className: command in className, resultArray)
filteredResult = "\n".join(filteredArray)
result.AppendMessage(filteredResult)