我正在編寫一個掛鉤,它會在系統中記錄所有達爾文通知。我鉤入以下功能:爲所有達爾文通知掛鉤CFNotificationCenter - iOS
CFNotificationCenterPostNotification
CFNotificationCenterPostNotificationWithOptions
NSNotificationCenter::postNotification
NSNotificationCenter::postNotificationName
我看到很多的日誌。示例當我解鎖屏幕時,它顯示我SBDeviceLockStateChangedNotification。
但我希望喜歡的活動 - 「com.apple.springboard.lockcomplete」或其他類似事件here
不知道爲什麼我不能夠捕捉到達爾文樣的通知。任何幫助讚賞。下面是審覈
#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);
}
Nate - 非常感謝您的詳細解答。 1)我只想收到每一條達爾文通知。但是,您提到的示例僅在我的應用處於前景時纔會收到通知。 (或者我正在打扮)。 2)&3)notify_post做了詭計。現在我可以掛接到notify_post並捕獲系統中的每個通知。感謝您的幫助和時間。 – Jailbroken
順便說一句,目的不是阻止他們,而是記錄他們,並建立一個所有可能的通知數據庫,以便有需求時,我們可以通過主列表,並找出它是如何實現的... – Jailbroken
@Bugivore,我現在不在我的Mac上,所以我無法運行。當您的應用在後臺時,您應該能夠收到通知。但是,您可能需要執行一些步驟,以便在後臺保持應用程序完全*活動狀態。對於一個普通的UIApplication,iOS會在後臺禁用相當多的功能。您可以通過將您的應用程序設置爲守護程序或通過在Info.plist中使用未記錄的背景模式('continuous'和'unboundedTaskCompletion')來解決此問題。我現在需要去睡覺,但我明天可以發佈更多信息。或者,你可以搜索我的舊帖子... – Nate