4

调试 MobileSubstrate 扩展(即放置断点等)的最佳方法是什么?在 Xcode 中可以做到这一点吗?GNU 调试器?

4

3 回答 3

6

我使用系统日志和尾巴。您将需要syslogdErica Utilities来自 Cydia。然后在整个调整位置NSLog(@"breakpoint 1 - %@", someObject);并运行调整。

tail -f /var/log/syslog
于 2012-01-31T23:42:47.737 回答
2
#define Debugger() { kill( getpid(), SIGINT ) ; }

然后,您只需在要放置断点的任何地方调用 Debugger() 即可。

如果要跟踪堆栈,也可以引发异常:

[NSException raise:@"Exception Message" format:formatString];
于 2011-07-26T13:00:10.340 回答
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 是在 uninstallApplication 挂钩函数中将 7 添加到 i 变量的程序集操作码。您可以根据需要继续从此处调试您的 Mobilesubstrate 扩展。

于 2014-08-22T22:41:56.077 回答