iOS 11上debugserver与LLDB的配置


#1

iOS11越狱发行半年有余,Cycript这个最好用的运行时刻更新似乎因为神仙打架的原因而不支持iOS11.笔者只能将目光投入到lldb+debugserver。

按照debugserver的配置办法从设备中拷贝debugserver到电脑,除了小黄书提到的4个权限需要额外签名 platform-application 否则会被直接干掉。原本以为就此结束可以开心的用debugserver调试。但是现实中做到这一步确实可以运行debugserver但基本会出现以下问题
debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-360.0.26.14
for arm64.
Attaching to process Preferences…
error: failed to attach to process named: “” (os/kern) invalid argument
按照@Ouroboros大佬提示的原因,需要使用jailbreak_client提权。

按照大佬给的代码。

#include <spawn.h>

int  main(int argc, char *argv[], char *envp[])
{
    if (argc < 2)
    {
   fprintf(stderr, "usage: %s program args...\n", argv[0]);
       
       return EXIT_FAILURE;
    }
    
    int ret, status;
    pid_t pid;
    posix_spawnattr_t attr;
    
    posix_spawnattr_init(&attr);
    posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED);
    
    ret = posix_spawnp(&pid, argv[1], NULL, &attr, &argv[1], envp);
    
    posix_spawnattr_destroy(&attr);
    
    if (ret != 0)
    {
        printf("posix_spawnp failed with %d: %s\n", ret, strerror(ret));
        return ret;
    }
    
    char buf[200];
    
    snprintf(buf, sizeof(buf), "/electra/jailbreakd_client %d 1", pid);
    system(buf);
    
    kill(pid, SIGCONT);
    waitpid(pid, &status, 0);
    
    return 0;
}

使用theos的tool模版制作一个小的命令行工具,我这里用的名字是JBDO。make package install 后ssh进入设备


执行命令JBDO debugserver *:1234 -a “Preferences”

提示如下

 debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-360.0.26.14
 for arm64.
Attaching to process Preferences...
Listening to port 1234 for a connection from *...
Failed to get connection from a remote gdb process.
Exiting.

还是不行。通过简单搜索,发现debugserver只能绑定iOS设备本地ip。可是lldb for ios同样没有iOS11的版本。只好祭出usbmux


使用python运行tcp tcprelay.py 监听端口:监听端口

新建另一个终端窗口 lldb

process connect connect://localhost:监听端口

挺卡的,即使usb有线也用了数十秒

  Process 2788 stopped
* thread #1: tid = 0xb3313, 0x0000000181bd4bc4 libsystem_kernel.dylib`mach_msg_trap + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x0000000181bd4bc4 libsystem_kernel.dylib`mach_msg_trap + 8
libsystem_kernel.dylib`mach_msg_trap:
->  0x181bd4bc4 <+8>: ret    

libsystem_kernel.dylib`mach_msg_overwrite_trap:
    0x181bd4bc8 <+0>: movn   x16, #0x1f
    0x181bd4bcc <+4>: svc    #0x80
    0x181bd4bd0 <+8>: ret    
(lldb)  

至此,iOS11上面的lldb+debugserver就完成了。感谢群里大佬们的指点。希望能帮到遇到同样问题的坛友。


#2

可以把markdown格式重新编辑一下吗?然后我发个帖广而告之一下 :star_struck:


#3

好的狗神,最近忙着考试。等考完来施工


#4

@LuaSaltFish lldb for iOS 正好没有iOS11的设备,帮我测试一下呗 https://github.com/abit-me/lldb.ios


#5

期待整理的文章。另外,我测试发现下面的错误,请问是怎么解决的?

==> Compiling main.mm (armv7)…
main.mm:32:5: error: call to unavailable function ‘system’: not available on iOS
system(buf);
^~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk/usr/include/stdlib.h:195:6: note:
candidate function has been explicitly made unavailable
int system(const char *) __DARWIN_ALIAS_C(system);
^
1 error generated.


#6

测试了,报下面的错误。

iPhone:~ root# dpkg -i lldb.deb
dpkg: warning: parsing file ‘/var/lib/dpkg/status’ near line 1588 package ‘test.touchsprite.ios.arm64’:
missing description
dpkg-deb: error: ‘lldb.deb’ is not a debian format archive
dpkg: error processing archive lldb.deb (–install):
subprocess dpkg-deb --control returned error exit status 2
Errors were encountered while processing:
lldb.deb


#7

#8

无视这个警告就好了。theos把警告当作错误来抛