HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个gdb脚本,我正在努力跟踪所有通过objc_msgSend的Objective-C方法调用,但我遇到了一个我似乎无法处理的问题.在查看了Objective-C运行时源代码之后,我开发了以下脚本,以便在objc_msgSend的每个中断处打印[].问题是在某些情况下data_NEVER_USE不是有效指针但也不是null.我可以找到关于类是否被初始化的唯一指标是id-> data_NEVER_USE-> flags& RW_REALIZED.我在这里遗漏的类初始化的哪个方面可以让我跳过这个案例?

b objc_msgSend
c
commands
silent

if (*$r0 == 0)
    continue
end

set $id = (class_t *)$r0
set $sel = $r1      
print *$id  
if($id->data_NEVER_USE != 0)
    set $data = (class_ro_t *) ($id->data_NEVER_USE)
    if (($data->flags & 0x80000000) && ($data->name))
        set $classname = $data->name
        printf "[%s ",$classname
    else
        continue
    end
end

if ($sel != 0)
    printf "%s",$sel
else
    printf "null"
end

printf "]\n"
continue
end

我很感激任何帮助.谢谢.

解决方法

这两种方法对我来说效果相当不错.请注意,在我的示例中,我手动启动“SomeApp”以便在启动时立即对其进行监控.

gdb
(gdb) attach --waitfor 'SomeApp'

**this is where you manually start SomeApp on your device**

call (void)instrumentObjcMessageSends(YES)

“instrumentObjcMessageSends”启用/禁用运行时内的消息记录.这是一些more information on this method.

一个选项,仍然在你的iDevice上使用GDB,就是写一个这样的小命令:

FooPad:~ root# gdb
(gdb) attach SBSettings
Attaching to process 440.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............................. done
0x35686004 in mach_msg_trap ()

(gdb) break objc_msgSend
Breakpoint 1 at 0x3323ef72

(gdb) commands
Type commands for when breakpoint 1 is hit,one per line.
End with a line saying just "end".

>printf "-[%s %s]\n",(char *)class_getName(*(long *)$r0,$r1),$r1
>c
>end

(gdb) c
Continuing.
// a ton of information will follow

只要按下“c”(右上方的行显示“继续.”),您的屏幕将填充函数名称和参数.

最后按照these instructions在你的iDevice上获得一个可用的GDB.对于后代,我会在这里发布简短说明:

大佬总结

以上是大佬教程为你收集整理的用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题全部内容,希望文章能够帮你解决用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: