gpt4 book ai didi

ios - 为所有 Darwin 通知 Hook CFNotificationCenter - iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:53 33 4
gpt4 key购买 nike

我正在编写一个钩子(Hook),用于记录系统中的所有 Darwin 通知。我 Hook 到以下功能:

CFNotificationCenterPostNotification
CFNotificationCenterPostNotificationWithOptions
NSNotificationCenter::postNotification
NSNotificationCenter::postNotificationName

我看到了很多日志。例如,当我解锁屏幕时,它会显示 SBDeviceLockStateChangedNotification。

但我期待像“com.apple.springboard.lockcomplete”这样的事件或像here这样的其他事件

不确定为什么我无法捕获类似 Darwin 的通知。任何帮助表示赞赏。这里是审查的代码

#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);

}

最佳答案

所以,一些想法:

  1. 首先,您能解释一下为什么您要使用方法调配或 Hook 来检测这些通知吗?您是否试图真正拦截通知,在您的软件中处理它们,并阻止将它们传送到系统的其余部分?如果那是你想要的,那么我理解你的方法。如果您只是想接收这些通知,那么我建议您使用常规方法,即只注册 Darwin 事件(所有事件,或按名称)。 See here for an example .

  2. 这只是 com.apple.springboard.lockcomplete 事件的问题吗?因为当您解锁 设备时不会生成该事件。它仅在锁定 时发布。要检测解锁事件,您可以 see this answer .

  3. 如果您仍然遇到问题,这可能是因为事件可以通过多种方式发布。您可能正在连接 CFNotificationCenterPostNotification()CFNotificationCenterPostNotificationWithOptions(),但它们并不是发布事件的唯一方式。低级notify_post() API也可以使用。我的猜测是 CFNotificationCenterPostNotification() 实际上会使用 notify_post() 调用来发布事件。因此,如果您尝试检测事件,尤其是未记录的,iOS 可能会直接使用 notify_post() 发布事件,这可以解释原因你没有看到它。

希望这对您有所帮助。

关于ios - 为所有 Darwin 通知 Hook CFNotificationCenter - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17701228/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com