如何调试 MobileSubstrate 调整?

发布于 2024-11-25 09:55:04 字数 72 浏览 10 评论 0原文

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

What is the best way to debug MobileSubstrate extensions, i.e. placing breakpoints etc.? Is there away to do this in Xcode? GNU Debugger?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嗳卜坏 2024-12-02 09:55:04

我使用系统日志和尾部。您需要 Cydia 的 syslogdErica Utilities。然后在整个调整过程中放置​​ NSLog(@"breakpoint 1 - %@", someObject); 并运行调整。

tail -f /var/log/syslog

I use the syslog and tail. You'll need syslogd and Erica Utilities from Cydia. Then throughout your tweak place NSLog(@"breakpoint 1 - %@", someObject); and run the tweak.

tail -f /var/log/syslog
定格我的天空 2024-12-02 09:55:04
#define Debugger() { kill( getpid(), SIGINT ) ; }

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

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

[NSException raise:@"Exception Message" format:formatString];
#define Debugger() { kill( getpid(), SIGINT ) ; }

Then you just call Debugger() wherever you want to place a breakpoint.

You can also raise an exception if you want to trace the stack:

[NSException raise:@"Exception Message" format:formatString];
无力看清 2024-12-02 09:55:04

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 扩展。

Mobilesubstrate injects your dylib into the target process. Debugging the target process using GDB or LLDB is also debugging your extension code.
I will show you how to debug Mobilesubstrate extension using GDB.
Here is simple Mobilesubstrate/Logos extension:

%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

I compile and install the code, and then attaching gdb to it:

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

You can find your Mobilesubstrate extension with the command:

(gdb) info sharedlibrary 

This command print a list of loaded modules, find your extension:

test-debug-substrate.dylib            - 0x172c000         dyld Y Y /Library/MobileSubstrate/DynamicLibraries/test-debug-substrate.dylib at 0x172c000 (offset 0x172c000)

You can also find the address of Logos uninstallApplication hook:

(gdb) info functions uninstallApplication

Which outputs this:

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

You can debug your uninstallApplication hook function with breakpoints and other gdb features:

(gdb) b *0x0172cef0+36 

Where the offset 36 is the assembly opcode that adding of 7 to the i variable in uninstallApplication hook function. You can continue to debug your Mobilesubstrate extension from here as you wish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文