如何调试MobileSubstrate调整?

时间:2011-07-20 15:14:03

标签: iphone objective-c xcode debugging tweak

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

3 个答案:

答案 0 :(得分:6)

我使用syslog和tail。您需要来自Cydia的syslogdErica Utilities。然后在整个调整位置NSLog(@"breakpoint 1 - %@", someObject);进行调整。

tail -f /var/log/syslog

答案 1 :(得分:2)

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

然后,只需调用Debugger(),无论您想要放置断点。

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

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

答案 2 :(得分: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 hook的地址:

(gdb) info functions uninstallApplication

哪个输出:

0x0172cef0  _logos_method$_ungrouped$SBApplicationController$uninstallApplication$(SBApplicationController*, objc_selector*, objc_object*)

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

(gdb) b *0x0172cef0+36 

其中偏移量36是程序集操作码,即在uninstallApplication挂钩函数中向i变量添加7。您可以根据需要继续从此处调试Mobilesubstrate扩展。