Skip to content

Instantly share code, notes, and snippets.

@annidy
Created April 17, 2014 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annidy/10964785 to your computer and use it in GitHub Desktop.
Save annidy/10964785 to your computer and use it in GitHub Desktop.
电话监听私有api
#include <dlfcn.h>
typedef CFNotificationCenterRef (*fpCFNotificationCenterRef)(void);
typedef void (*fpCTTelephonyCenterAddObserver)(CFNotificationCenterRef center, const void *observer, CFNotificationCallback callBack, CFStringRef name, const void *object, CFNotificationSuspensionBehavior suspensionBehavior);
void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo);
int install_callback()
{
void *framework = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
fpCFNotificationCenterRef CTTelephonyCenterGetDefault = (fpCFNotificationCenterRef)dlsym(framework, "CTTelephonyCenterGetDefault");
if (CTTelephonyCenterGetDefault == NULL) {
return 1;
}
CFNotificationCenterRef ct = CTTelephonyCenterGetDefault();
fpCTTelephonyCenterAddObserver CTTelephonyCenterAddObserver = (fpCTTelephonyCenterAddObserver)dlsym(framework, "CTTelephonyCenterAddObserver");
if (CTTelephonyCenterAddObserver == NULL) {
return 1;
}
CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorHold);
dlclose(framework);
return 0;
}
void callback(CFNotificationCenterRef center, void *observer, CFStringRef name_, const void *object, CFDictionaryRef userInfo_)
{
NSString *name = (NSString *)name_;
NSDictionary *info = (NSDictionary *)userInfo_;
NSLog(@"Notification intercepted: %s %@\n", [name UTF8String], info);
if([name isEqualToString:@"kCTCallStatusChangeNotification"] && info)
{
NSString *state=[[info objectForKey:@"kCTCallStatus"] stringValue];
// 拨出电话时为3,有呼入电话时为4,挂断电话时为5
int callState = [state intValue];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment