我正在编写一个记录系统中所有 darwin 通知的钩子。我挂钩以下功能:
CFNotificationCenterPostNotification
CFNotificationCenterPostNotificationWithOptions
NSNotificationCenter::postNotification
NSNotificationCenter::postNotificationName
我看到很多日志。例如,当我解锁屏幕时,它会显示 SBDeviceLockStateChangedNotification。
但我期待像“com.apple.springboard.lockcomplete”这样的事件或像这里这样的其他事件
不知道为什么我无法捕获类似达尔文的通知。任何帮助表示赞赏。这是审查的代码
#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);
}