Advanced.Apple.Debugging.&.Reverse.Engineering.v2.0 学习笔记

Chap 16 讲解了如何显示出来苹果的调试窗口 UIDebuggingInformationOverlay,内容最后,作者提到他自己的lldb_commands里提供了python脚本,可以直接完成在模拟器或者真机上显示出这个Overlay,尝试了一下,简单记录了步骤。
lldb_commands在这里。

模拟器是 iOS 11.2

如何查看模拟器里Apple原生App的 process名称:

1, 用lldb随便连接一个已经知道process name的App:
flora:~ flora $ lldb -n Maps
(lldb) process attach --name "Maps"

成功连上后,控制台输出信息的最底部,出现:

Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/Maps.app/Maps".
Architecture set to: x86_64h-apple-ios.

复制地址:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications
并在控制台用open命令打开, 进入到Finder, Applications目录中显示了模拟器自带的app.

finder-applications.png

2, 查找自己要找的App, 如果不确定找的对不对,可以右键打开包查看是不是自己需要的。
3, 我要找的是Calendar, 直接lldb -n Calendar会报错:
(lldb) process attach --name "Calendar"
error: attach failed: could not find a process named Calendar

可见它的名字不是Calendar

4, 通过上面的方法, 在Applications目录里找到了MobileCal.app, 试一下:
# lldb -n MobileCal
(lldb) process attach --name "MobileCal"
Process 52308 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x000000011689c34a libsystem_kernel.dylib` mach_msg_trap  + 10
libsystem_kernel.dylib`mach_msg_trap:
->  0x11689c34a <+10>: ret
    0x11689c34b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap:    0x11689c34c <+0>: mov    r10, rcx
    0x11689c34f <+3>:  mov    eax, 0x1000020
    0x11689c354 <+8>:  syscall
    0x11689c356 <+10>: ret
    0x11689c357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap:    0x11689c358 <+0>: mov    r10, rcx
Target 0: (MobileCal) stopped.

Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal".
Architecture set to: x86_64h-apple-ios.

attach成功

5, 显示overlaywindow
(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution

(lldb) continue
Process 52308 resuming

在iphone x 模拟器上截屏如下:


Simulator Screen Shot - iPhone X - 2018-03-23 at 14.34.59.png
6, 这是一次就成功的情况, 我第一次执行lldb -n MobileCal时,遇到了一个问题,提示attach失败:
flora:~ flora $ lldb -n MobileCal
(lldb) process attach --name "MobileCal"
error: attach failed: more than one process named MobileCal:
PID    PARENT USER       TRIPLE                   ARGUMENTS
====== ====== ========== ======================== ============================
52308  587    flora       x86_64-apple-macosx      /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal
20201  20091  flora       x86_64-apple-macosx      /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal

只能使用pid进行attach。

(lldb) process attach --pid 52308
Process 52308 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x000000011689c34a libsystem_kernel.dylib` mach_msg_trap  + 10
libsystem_kernel.dylib`mach_msg_trap:
->  0x11689c34a <+10>: ret
    0x11689c34b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap:    0x11689c34c <+0>: mov    r10, rcx
    0x11689c34f <+3>:  mov    eax, 0x1000020
    0x11689c354 <+8>:  syscall
    0x11689c356 <+10>: ret
    0x11689c357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap:    0x11689c358 <+0>: mov    r10, rcx
Target 0: (MobileCal) stopped.

Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal".
Architecture set to: x86_64h-apple-ios.

attach 成功。

(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution

(lldb) continue
Process 52308 resuming

很奇怪的现象是,此时使用另外一个控制台,直接执行 lldb -n MobileCal 就能成功attach上.

如果刚才指定pid时,指定另外一个呢?
(lldb) process attach --pid 20201
There is a running process, detach from it and attach?: [Y/n] y
Process 52308 detached
Process 20201 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x000000010b72834a libsystem_kernel.dylib` mach_msg_trap  + 10
libsystem_kernel.dylib`mach_msg_trap:
->  0x10b72834a <+10>: ret
    0x10b72834b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap:    0x10b72834c <+0>: mov    r10, rcx
    0x10b72834f <+3>:  mov    eax, 0x1000020
    0x10b728354 <+8>:  syscall
    0x10b728356 <+10>: ret
    0x10b728357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap:    0x10b728358 <+0>: mov    r10, rcx
Target 0: (MobileCal) stopped.

看样子也是成功的, 但是想要查看overlay是,却不能够:

(lldb) overlaydbg
Failure, womp

看来这个进程不能显示overlay,那么第一个尝试的pid就是当前正在前台的Calendar的进程了.
当然,此时在另外的控制台直接lldb -n MobileCal也是能够成功attach到Calendar的。

7, 如果是有源码的App, 直接在Schemes中查看Executable就是它进程的名称, 不需要额外的查看。
8, 模拟器里安装AppStore上的应用有点困难, 就不考虑了。
9, 真机环境 iPhone 6p, iOS 11.2

运行我自己的程序,然后点『暂停』进入lldb调试环境, 输入: overlaydbg:

(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution

(lldb) continue
Process 5240 resuming

真机成功显示debuggingOverlay
第一次执行报了两个python的错误(手慢没几下来), 再次执行就成功了,也没有再出现错误, 可惜。

10, 真机环境的第三方APP, 暂时还没尝试如何连上lldb。但是如果能使用方法, 例如usbmuxd连上lldb, 执行overlaydbg应该也能显示出debuggingOverlay的.

你可能感兴趣的:(Advanced.Apple.Debugging.&.Reverse.Engineering.v2.0 学习笔记)