1.类名
unsigned long size;
uint8_t *ptrClassName = getsectiondata(&_mh_execute_header, "__TEXT", "__objc_classname", &size);
NSData *dataClassName = [NSData dataWithBytesNoCopy:ptrClassName length:size freeWhenDone:NO];
NSString * strClassName = [[NSString alloc]initWithData:dataClassName encoding:NSUTF8StringEncoding];
NSArray * arrayClassName = [strClassName componentsSeparatedByString:@"\00"];
[arrayClassName enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"className = %@ interger = %lu",obj, (unsigned long)idx);
}];
2.方法名
unsigned long sizeMethName;
uint8_t * ptrMethName = getsectiondata(&_mh_execute_header, "__TEXT", "__objc_methname", &sizeMethName);
NSData * dataMethName = [NSData dataWithBytesNoCopy:ptrMethName length:sizeMethName freeWhenDone:NO];
NSString * strMethName = [[NSString alloc]initWithData:dataMethName encoding:NSUTF8StringEncoding];
NSArray * arrMethName = [strMethName componentsSeparatedByString:@"\00"];
[arrMethName enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"methName = %@",obj);
}];
3.可能遇到的问题
方法名或者类名遇到特殊字符, data->string的时候闪退, 那就把NSData->NSString的方法换成下面的
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingGB_18030_2000 );
NSString* strMethName = [[NSString alloc] initWithData:dataMethName encoding:enc];
网友评论