【问题标题】:How do I intercept the constructor for a Swift class using Frida?如何使用 Frida 拦截 Swift 类的构造函数?
【发布时间】:2021-10-14 04:11:11
【问题描述】:

我正在尝试使用 Frida 内置的 frida swift 桥接功能来挂钩 Swift 类的构造函数。我正在使用以下命令运行我的代码:

frida --no-pause -U -l swift_cooperia.js -f com.example.myapp

swift_cooperia.js 的内容是:

Swift.Interceptor.attach(Swift.classes.hooked_class.init, {
    onEnter: function (args) {
        console.log("obj instantiated");
    }
});

我正在尝试使用 Swift.Interceptor.Attach 函数,但我不太确定第一个参数(我要挂钩的函数)使用什么。在我看到的所有拦截器示例中,我应该为我的第一个参数,但这会引发以下错误:

Error: missing argument
    at T (frida/node_modules/frida-swift-bridge/dist/lib/macho.js:144)
    at F (frida/node_modules/frida-swift-bridge/dist/lib/macho.js:155)
    at <anonymous> (frida/node_modules/frida-swift-bridge/dist/lib/interceptor.js:23)
    at <eval> (/swift_cooperia.js:5)

我也尝试过使用 Swift.classes.hooked_class.init() 但出现以下错误:

TypeError: not a function
    at <eval> (/swift_cooperia.js:1)

我也尝试过 Swift.classes.hooked_class.init.implementation 出现以下错误:

TypeError: cannot read property 'implementation' of undefined
    at <eval> (/swift_cooperia.js:1)

当我在 frida 会话期间(不在此脚本执行中)查看使用 Swift.class.hooked_class 的类的 $methods 属性时,我得到以下信息:

"$methods": [
        {
            "address": "0x1008e37b8",
            "type": "Method"
        },
        {
            "address": "0x1008e3b90",
            "type": "Method"
        },
        {
            "address": "0x1008e5998",
            "type": "Method"
        },
        {
            "address": "0x1008e5e30",
            "type": "Method"
        },
        {
            "address": "0x1008e5e50",
            "type": "Method"
        }
    ]

这表明没有简单的构造函数或 init 方法。其中一个可能是 init 方法,但我不知道如何嗅出哪个是,如果有的话,以及如何将它用作 Swift 拦截器的第一个参数。 我对使用 Frida 非常陌生,因此我们将不胜感激。

【问题讨论】:

  • 要识别方法,您可以使用 Frida 打印模块基地址以获取二进制中的方法地址(摆脱 ASLR 偏移量)。然后使用 Ghidra 或 IDA 之类的工具对二进制文件进行反编译,并检查它们属于哪个方法的地址。

标签: ios swift frida


【解决方案1】:

Frid​​a Swift 桥梁作者在这里。您尝试挂钩的方法没有符号化,这就是桥无法拦截它的原因,来自docs

一个主要的警告是,目标函数必须有一个 Swift 符号,否则我们可以保释。解析参数和返回类型时需要该符号。

API 应该返回一个更有用的错误,所以我会修复它。

(也可以随时打开issue on GitHub,因为那里的报道会更好,我偶然发现了这个!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多