dlsym fails quietly loading from CoreTelephony

461 views Asked by At

I am trying to call a private function in the CoreTelephony framework; here is my current code:

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);

I know both the CoreTelephony binary and the CTRegistrationDataCounterGetLastResetTime symbol exist because if I insert gobbledegook for either I get an immediate crash. The code compiles fine, and no errors arise.

However, I don't think the function is getting called because it always returns 0, when it shouldn't (the CTRegistrationDataCounterGetLastResetTime function returns the date last time cellular data was reset in the number of seconds after 1 January 2001, GMT, hence it returning a double. The NSDate is gotten with [NSDate dateWithTimeIntervalSinceReferenceDate:])

If I had to hazard a guess, I'd say something is wrong with my casting of the void * returned by dlsym to a function pointer. There seems to be a surprising amount of dispute over it.

1

There are 1 answers

1
l0gg3r On BEST ANSWER

I've tried to call that method, as I usually do, and really it returns 0, so I tried to call another method from 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);

And I got my operator name. So I think Apple just removed CTRegistrationDataCounterGetLastResetTime function. enter image description here