【问题标题】:How to hook os_log by using Frida如何使用 Frida 挂钩 os_log
【发布时间】:2018-08-02 07:22:23
【问题描述】:

如标题所述,如何使用 Frida 挂钩 os_log? 下面试过了,不行。

Interceptor.attach(Module.findExportByName("libSystem.B.dylib", "os_log"), {
    onEnter: function (args) {
        console.log(args[0] + args[1]);
    }
});

【问题讨论】:

    标签: frida


    【解决方案1】:
    • 启用所有日志
    var m = 'libsystem_trace.dylib';
    // bool os_log_type_enabled(os_log_t oslog, os_log_type_t type);
    var isEnabledFunc = Module.findExportByName(m, 'os_log_type_enabled');
    // _os_log_impl(void *dso, os_log_t log, os_log_type_t type, const char *format, uint8_t *buf, unsigned int size);
    var logFunc = Module.findExportByName(m, '_os_log_impl');
    
    Interceptor.attach(isEnabledFunc, {
      onLeave: function (ret) {
        // console.log('log_enabled', ret);
        ret.replace(0x1);
      }
    });
    
    Interceptor.attach(logFunc, {
      onEnter: function (a) {
        var type = a[2]; // https://github.com/darlinghq/darling/blob/master/src/libc/os/log.h#L105
        var format = a[3];
        if (type != 0x2) {
          console.log(JSON.stringify({
            type: type,
            format: format.readCString(),
            //buf: a[4].readPointer().readCString()
          }, null, 2));
        }
      }
    })
    
    

    【讨论】:

    • 我不认为你可以直接挂钩“os_log”,在我对代码进行逆向工程后,编译后代码是调用os_log_type_enabled和_os_log_impl。
    • 所以Module.findExportByName(null, "os_log") 将返回null
    猜你喜欢
    • 2020-12-17
    • 2019-10-26
    • 2022-12-25
    • 1970-01-01
    • 2020-02-17
    • 2017-12-05
    • 2020-12-11
    • 2022-09-26
    • 2019-10-08
    相关资源
    最近更新 更多