3

システム内のすべての 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);

}
4

1 に答える 1