我试图在CoreTelephony框架中调用一个私有函数;下面是我的当前代码:
double (*func)(void);
void *handle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
if (!handle) {
[@{@"handle": @"handle"} writeToFile:@"/var/mobile/err.plist" atomically:YES];
}
*(void **)(&func) = dlsym(handle, "CTRegistrationDataCounterGetLastResetTime");
if (dlerror() != NULL) {
[@{@"symbol": @"symbol"} writeToFile:@"/var/mobile/err.plist" atomically:YES];
}
double r = (*func)();
NSNumber *a = [NSNumber numberWithDouble:r];
[@{@"time": a} writeToFile:@"/var/mobile/err.plist" atomically:YES];
dlclose(handle);我知道CoreTelephony二进制和CTRegistrationDataCounterGetLastResetTime符号都存在,因为如果插入gobbledegook,就会立即崩溃。代码编译得很好,不会出现错误。
但是,我认为函数没有被调用,因为它总是返回0,而它不应该返回( CTRegistrationDataCounterGetLastResetTime函数返回上次在2001年1月1日GMT之后的秒数内重置蜂窝数据的日期,因此它返回一个double。NSDate是用[NSDate dateWithTimeIntervalSinceReferenceDate:]获得的)
如果我不得不冒险猜一猜,我会说,我把dlsym返回的dlsym转换为一个函数指针是有问题的。在这方面似乎存在着令人惊讶的争议。
发布于 2014-11-26 15:57:14
我试图像往常一样调用该方法,实际上它返回0,所以我尝试从CoreTelephony调用另一个方法。
void *handle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_NOW);
if (!handle) {
NSLog(@"Can't dlopen");
}
CFStringRef (*func)(CFAllocatorRef) = dlsym(handle, "CTRegistrationCopyLocalizedOperatorName");
if (dlerror() != NULL) {
NSLog(@"Can't find symbol");
}
CFStringRef r = func(CFAllocatorGetDefault());
dlclose(handle);我知道了我的接线员的名字。所以我认为苹果公司刚刚删除了CTRegistrationDataCounterGetLastResetTime功能。

https://stackoverflow.com/questions/27152062
复制相似问题