使用gdb调试theos tweak插件

本文介绍如何使用GDB调试Mobilesubstrate扩展代码。通过实例演示了如何为uninstallApplication方法设置断点,并跟踪调试过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看设备日志tail -f /var/log/syslog
或者

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值