Attaching with LLDB

前言

  1. program named debugserver (found in Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/) is responsible for attaching to a target process.
devzkndeMacBook-Pro:Resources devzkn$ ls -lrt
total 32160
drwxr-xr-x  3 root  wheel        96 Apr 13  2017 Clang
-rw-r--r--  1 root  wheel      1245 Apr 13  2017 Info.plist
drwxr-xr-x  3 root  wheel        96 Apr 13  2017 Python
-rw-r--r--  1 root  wheel       463 Apr 13  2017 version.plist
-rwxr-xr-x  1 root  wheel     24736 May 11  2017 darwin-debug
-rwxr-xr-x  1 root  wheel   4719552 May 11  2017 debugserver
-rwxr-xr-x  1 root  wheel     17904 May 11  2017 repl_swift
-rwxr-xr-x  1 root  wheel  41952080 May 11  2017 lldb-server
-rwxr-xr-x  1 root  wheel    132304 May 11  2017 lldb-argdumper
devzkndeMacBook-Pro:Resources devzkn$ pwd
/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources

If it’s a remote process, such as an iOS, watchOS or tvOS application running on a remote device, a remote debugserver gets launched on that remote device. It’s LLDB’s job to launch, connect, and coordinate with the debugserver to handle all the interactions in debugging an application.

process connect connect://127.0.0.1:12345

Attaching to an existing process

lldb -n Xcode
devzkndeMacBook-Pro:Resources devzkn$ pgrep -x Xcode
2416
devzkndeMacBook-Pro:Resources devzkn$ lldb -p 2416

How can you catch a process that is about to be launched, if you don’t know the PID yet?(Attaching to a future process)

You can do that with the -w argument, which causes LLDB to wait until a process launches with a PID or executable name matching the criteria supplied to the -w argument.
For example, kill your existing LLDB session by pressing Ctrl + D in your Terminal window (exit)and type the following:

devzkndeMacBook-Pro:Resources devzkn$   lldb -n Finder -w
(lldb) process attach --name "Finder" --waitfor

This will tell LLDB to attach to the process named Finder whenever it next launches. Next, open a new Terminal tab(control+N), and enter the following:

devzkndeMacBook-Pro:Resources devzkn$ pkill Finder

macOS will automatically relaunch Finder when it’s killed. Switch back to your first Terminal tab and you’ll notice LLDB has now attached itself to the newly created Finder process.

你可能感兴趣的:(逆向工程)