I am trying to hook postNotificationName Function with Frida. I call two functions:
sO, When I trace the functions using frida-trace, I see that in the later case there is calls to postNotificationName. I want to know if postNotification calls postNotification and why is that?
Also,
var newObject = ObjC.classes.NSNotification;
var myObj = newObject.alloc().initWithName_object_userInfo_('notificationName','nil','userInfo');
var hook = ObjC.classes.NSNotificationCenter["- postNotification:"];
Interceptor.attach(hook.implementation, {
onEnter: function(args) {
console.log("\n[*] Detected call to: " + NsNotificationCenter + " -> " + postNotification);
console.log("\t[-] Argument Value: " + args[2]);
args[2] = ptr(myObj)
console.log("\t[-] New Argument Value: " + args[2])
}
works when is injected using Frida to hook the postNotification function. However,
var nsName = ObjC.classes.NSString;
var notificationName= nsName.stringWithString_("Blah");
var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:"];
Interceptor.attach(hook.implementation, {
onEnter: function(args) {
console.log("\n[*] Detected call to: " + NSNotificationCenter + " -> " + postNotificationName);
console.log("\t[-] Argument Value: " + args[2]);
args[2] = ptr(notifname)
console.log("\t[-] New Argument Value for postNotificaitonName: " + args[2])
}
});
is not working for the postNotificationName:Object:userInfo. I guess the issue is in the line "var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:"];". Does anyone know what is wrong with it and how to make it work please?
Thank you
According to the Apple documentation the class NSNotificationCenter
has no selector "- postNotificationName:"
.
There are two selectors with that name but they have additional parameters:
"- postNotificationName:object:userInfo:"
"- postNotificationName:object:"
If you want to hook any of these selectors you have to use the full selector string as stated above for hooking:
var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:object:userInfo:"];
or
var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:object:"];