Created
April 17, 2014 08:32
-
-
Save annidy/10964785 to your computer and use it in GitHub Desktop.
电话监听私有api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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