I am writing a hook which logs all darwin notifications in the system. I hook into below functions:
CFNotificationCenterPostNotification
CFNotificationCenterPostNotificationWithOptions
NSNotificationCenter::postNotification
NSNotificationCenter::postNotificationName
I see lot of logs. Example when I unlock the screen it shows me SBDeviceLockStateChangedNotification.
But I am expecting events like - "com.apple.springboard.lockcomplete" or other events like here
Not sure why I am not able to capture darwin-like notifications. Any help appreciated. Here's the code for review
#include <notify.h>
#include <substrate.h>
#include <sqlite3.h>
#include <string.h>
#import <CoreFoundation/CFNotificationCenter.h>
//#include "CPDistributedMessagingCenter.h"
#import <CoreFoundation/CoreFoundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
//#import <SpringBoard/SpringBoard.h>
// init CFNotificationCenterPostNotification hook
void (*orig_CFNotificationCenterPostNotification) (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
Boolean deliverImmediately
);
void replaced_CFNotificationCenterPostNotification (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
Boolean deliverImmediately
){
NSLog(@"CFNotificationCenterPostNotification: %@", name );
orig_CFNotificationCenterPostNotification(center,name,object,userInfo,deliverImmediately);
}
void (*orig_CFNotificationCenterPostNotificationWithOptions) (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
CFOptionFlags options
);
void replaced_CFNotificationCenterPostNotificationWithOptions (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
CFOptionFlags options
)
{
NSLog(@"CFNotificationCenterPostNotificationWithOptions: %@", name );
orig_CFNotificationCenterPostNotificationWithOptions(center,name,object,userInfo,options);
}
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome"
message:@"Welcome to my iPhone!"
delegate:nil
cancelButtonTitle:@"Thanks"
otherButtonTitles:nil];
[alert show];
//[alert release];
}
%end
%hook NSNotificationCenter
- (void)postNotification:(NSNotification *)notification{
NSLog(@"NSNotificationCenterpostNotification: %@",[notification name]);
%orig;
}
- (void)postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo{
NSLog(@"NSNotificationCenterpostNotificationName: %@",aName);
%orig;
}
%end
__attribute__((constructor)) void notificationinit() {
%init;
MSHookFunction(CFNotificationCenterPostNotification, replaced_CFNotificationCenterPostNotification, &orig_CFNotificationCenterPostNotification);
MSHookFunction(CFNotificationCenterPostNotificationWithOptions, replaced_CFNotificationCenterPostNotificationWithOptions, &orig_CFNotificationCenterPostNotificationWithOptions);
}