-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHYMenberDump.py
48 lines (40 loc) · 1.71 KB
/
CHYMenberDump.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
#!/usr/bin/python
import string
import lldb
import fblldbbase as fb
import fblldbobjcruntimehelpers as runtimeHelpers
def lldbcommands():
return [ PrintInstanceDump() ]
class PrintInstanceDump(fb.FBCommand):
def name(self):
return 'pdump'
def description(self):
return 'Print instance properties'
def run(self, arguments, options):
cls = arguments[0]
ilass = arguments[0]
if not self.isClassObject(cls):
cls = runtimeHelpers.object_getClass(cls)
if not self.isClassObject(cls):
raise Exception('Invalid argument. Please specify an instance or a Class.')
menber_json = self.get_oc_menbers_json(cls,ilass)
print menber_json
def get_oc_menbers_json(mSelf,klass,ilass):
str = """
unsigned int menberCount;
NSMutableDictionary *result = (id)[NSMutableDictionary dictionary];
objc_property_t *properties = (objc_property_t *)class_copyPropertyList((Class)$cls, &menberCount);
for (int i = 0; i<menberCount; i++)
{
char *name = (char *)property_getName(properties[i]);
NSString *ret_name = (NSString *)[NSString stringWithUTF8String:name];
id value = (id)[(NSObject *)$ils valueForKey:ret_name]?:@"nil";
[result setObject:value forKey:ret_name];
}
//free(properties);
RETURN(result);
"""
command = string.Template(str).substitute(cls=klass,ils=ilass)
return fb.evaluate(command)
def isClassObject(mSelf,arg):
return runtimeHelpers.class_isMetaClass(runtimeHelpers.object_getClass(arg))