如何调试MobileSubstrate插件?

4

什么是调试MobileSubstrate扩展的最佳方法,例如放置断点等?在Xcode中有没有这样做的方法?GNU Debugger?

3个回答

6

我使用syslog和tail。你需要从Cydia安装syslogd和Erica Utilities。然后在你的tweak中加入NSLog(@"breakpoint 1 - %@", someObject);并运行该tweak。

tail -f /var/log/syslog

2
#define Debugger() { kill( getpid(), SIGINT ) ; }

当你想要设置断点的时候,只需要在任何地方调用Debugger()即可。

如果你想要跟踪堆栈,也可以抛出异常:

[NSException raise:@"Exception Message" format:formatString];

1
Mobilesubstrate将您的dylib注入目标进程。使用GDB或LLDB调试目标进程也是调试您的扩展代码。 我将向您展示如何使用GDB调试Mobilesubstrate扩展。 这里是一个简单的Mobilesubstrate/Logos扩展:
%hook SBApplicationController
-(void)uninstallApplication:(id)application {
    int i = 5;
    i = i +7;
    NSLog(@"Hey, we're hooking uninstallApplication: and number: %d", i);
    %orig; // Call the original implementation of this method
    return;
}
%end

我编译并安装代码,然后将gdb附加到它上面:

yaron-shanis-iPhone:~ root# ps aux | grep -i springboard
mobile     396   1.6  4.3   423920  21988   ??  Ss    2:19AM   0:05.23 /System/Library/CoreServices/SpringBoard.app/SpringBoard
root       488   0.0  0.1   273024    364 s000  S+    2:22AM   0:00.01 grep -i springboard
yaron-shanis-iPhone:~ root# gdb -p 488

您可以使用以下命令找到您的Mobilesubstrate扩展:
(gdb) info sharedlibrary 

这个命令会打印已加载模块的列表,找到你的扩展程序:
test-debug-substrate.dylib            - 0x172c000         dyld Y Y /Library/MobileSubstrate/DynamicLibraries/test-debug-substrate.dylib at 0x172c000 (offset 0x172c000)

您还可以找到Logos uninstallApplication钩子的地址:
(gdb) info functions uninstallApplication

这将输出以下内容:
0x0172cef0  _logos_method$_ungrouped$SBApplicationController$uninstallApplication$(SBApplicationController*, objc_selector*, objc_object*)

您可以使用断点和其他GDB功能来调试您的uninstallApplication挂钩函数:

(gdb) b *0x0172cef0+36 

偏移量36是在卸载应用程序钩子函数中将i变量加7的汇编操作码。您可以随意从这里继续调试Mobilesubstrate扩展。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接