【问题标题】:hook postNotificaiton using Frida使用 Frida 挂钩 postNotificaiton
【发布时间】:2020-12-17 15:55:54
【问题描述】:

我正在尝试将 postNotificationName 函数与 Frida 挂钩。我调用了两个函数:

  • postNotificationName:(NSNotificationName)object:(id)userInfo:(NSDictionary)
  • postNotification:(NSNotification)对象

sO,当我使用 frida-trace 跟踪函数时,我看到在后一种情况下调用了 postNotificationName。我想知道 postNotification 是否调用 postNotification,为什么会这样?

还有,

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])
    }

在使用 Frida 注入以挂钩 postNotification 函数时起作用。 然而,

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])
    }
});

不适用于 postNotificationName:Object:userInfo。我猜问题出在“var hook = ObjC.classes.NSNotificationCenter[”- postNotificationName:“];”这一行。 请问有谁知道它有什么问题以及如何使它工作?

谢谢

【问题讨论】:

    标签: nsnotifications frida


    【解决方案1】:

    根据Apple documentationNSNotificationCenter 类没有选择器"- postNotificationName:"

    有两个同名的选择器,但它们有额外的参数:

    • "- postNotificationName:object:userInfo:"
    • "- postNotificationName:object:"

    如果你想钩住这些选择器中的任何一个,你必须使用上面提到的完整的选择器字符串来钩住:

    var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:object:userInfo:"];
    

    var hook = ObjC.classes.NSNotificationCenter["- postNotificationName:object:"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-26
      • 2017-12-05
      • 2020-12-11
      • 2022-12-25
      • 1970-01-01
      • 2020-02-17
      • 2022-09-26
      • 2021-01-20
      相关资源
      最近更新 更多