jailbreak - Hooking CFNotificationCenter for all darwin notifications - iOS -
i writing hook logs darwin notifications in system. hook below functions:
cfnotificationcenterpostnotification cfnotificationcenterpostnotificationwithoptions nsnotificationcenter::postnotification nsnotificationcenter::postnotificationname
i see lot of logs. example when unlock screen shows me sbdevicelockstatechangednotification.
but expecting events - "com.apple.springboard.lockcomplete" or other events here
not sure why not able capture darwin-like notifications. appreciated. here's code 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 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); }
so, few thoughts:
first, can explain why want use method swizzling, or hooking detect these notifications? trying intercept notifications, process them in software, , stop them being delivered rest of system? if that's want, understand approach. if want receive these notifications, recommend normal approach of registering darwin events (all of them, or name). see here example.
is problem
com.apple.springboard.lockcomplete
event? because event not generated when unlock device. it's posted when locking. detect unlock event, can see answer.if you're still having trouble, perhaps because events can posted in multiple ways. may hooking
cfnotificationcenterpostnotification()
,cfnotificationcenterpostnotificationwithoptions()
, not ways post events. low level notify_post() api can used. guesscfnotificationcenterpostnotification()
usenotify_post()
call post event. so, it's possible if you're trying detect event, undocumented one, ios posting event directlynotify_post()
, explain why you're not seeing it.
hope helps.
Comments
Post a Comment