LLDB Scripts
對于下面的所有命令,您可以通過 help {command} 查看文檔。 如果您想查看命令有哪些選項,請輸入 {command} -h。
TLDR:search、lookup 和 dclass 都是不錯的 GOTO,無論您是開發(fā)人員還是沒有資源的探索者。
如果您喜歡 ObjC swizzling,請查看 sclass。 如果您喜歡 DTrace,請查看 pmodule 和 snoopie。
search
在堆中搜索某個類的所有活動實例。 這個類必須是動態(tài)的(也就是從NSObject/SwiftObject 類繼承)。 目前不適用于 NSString 或 NSNumber(標記的指針對象)。
Example:
# Find all instances and subclasses of UIView
(lldb) search UIView
# Find all instances of UIView that are UIViews. Ignore subclasses.
(lldb) search UIView -e
#Find all instances of UIView whose tag is equal to 5. Objective-C syntax only. Can reference object by 'obj'
(lldb) search UIView -c "(int)[obj tag]==5"
# Find all instances of a UIView subclass whose class is implemented in the SpringBoardUI module
(lldb) search UIView -m SpringBoardUI
# Find all UIView subclasses created in the "Woot" module and hide them
(lldb) search UIView -m Woot -p "[obj setHidden:YES]"
# Search for UIViews but just print the class, don't print object description (ideal for Swift where they hide the pointer)
(lldb) search UIView -b
# Remember, Swift includes the module in a class name, so if you have a Swift UIView called TestView in module WOOT...
(lldb) search WOOT.TestView -b
# Search for all classes that contain a reference to the pointer 0xfeedfacf
(lldb) search -r 0xfeedfacf
dclass
在此過程中轉(zhuǎn)儲所有 NSObject/SwiftObject 繼承類。 如果你給它一個模塊,它只會轉(zhuǎn)儲該模塊中的類。 您還可以將類過濾為僅特定類型,還可以為特定類生成頭文件。
Example:
# Dump ALL the classes (Swift and Objective-C) found within the process
(lldb) dclass
# Dump ObjC/Swift info (if applicable) about the class "Hello.SomeClass" (same as dclass -i Hello.SomeClass)
(lldb) dclass Hello.SomeClass
# Dump all the classes that are a UIViewController within the process
(lldb) dclass -f UIViewController
# Dump all the classes with the regex case insensitive search "viewcontroller" in the class name
(lldb) dclass -r (?i)viewCoNtrolLer
# Dump all the classes within the UIKit module
(lldb) dclass -m UIKit
# Dump all classes in CKConfettiEffect NSBundle that are UIView subclasses
(lldb) dclass /System/Library/Messages/iMessageEffects/CKConfettiEffect.bundle/CKConfettiEffect -f UIView
# Generate a header file for the class specified:
(lldb) dclass -g UIView
# Generate a protocol that you can cast an object to. Ideal when working with private classes at dev time
(lldb) dclass -P UIView
# Dump all classes and methods for a particular module, ideal for viewing changes in frameworks over time
(lldb) dclass -o UIKit
# Only dump classes whose superclass is of type NSObjecr and in the UIKit module. Ideal for going after specific classes like a datasource where it will likely inherit from NSObject
(lldb) dclass -s NSObject -m UIKit
# Dump only Swift classes
(lldb) dclass -t swift
# Dump only Objective-C classes
(lldb) dclass -t objc
# Get a simplified "class-dump" of the UIView class
(lldb) dclass -i UIView
# Get more information than you ever wanted to know about UIView
(lldb) dclass -I UIView
section
顯示加載到 proc 中的可執(zhí)行文件或框架的 Mach-O 段/部分中的數(shù)據(jù)
dd
替代 LLDB 的反匯編命令。 使用顏色。 僅限終端,專為 x86)64 設(shè)計。 ARM64 支持終有一天會到來...

sbt -象征回溯。 如果回溯使用的是 Objective-C,則將符號化從可執(zhí)行文件中剝離的回溯
代碼。 目前不適用于 aarch64 剝離的可執(zhí)行文件,但在 x64 上效果很好:]

msl
msl 0xadd7e55
msl 或 malloc 堆棧日志記錄將獲取一個地址并嘗試獲取堆棧跟蹤以
什么時候創(chuàng)建的。
您需要將環(huán)境變量設(shè)置為 MallocStackLogging,或execute turn_on_stack_logging(1)
當進程處于活動狀態(tài)時

lookup -對可執(zhí)行文件中的內(nèi)容執(zhí)行正則表達式搜索
Example:
# Find all methods that contain the phrase viewDidLoad
(lldb) lookup viewDidLoad
# Find a summary of all the modules that have a (known) function containing the phrase viewDidLoad
(lldb) lookup viewDidLoad -s
# Search for Objective-C code in a stripped module (i.e. in SpringBoard)
(lldb) loo -x StocksFramework .
# Search for Objective-C code containing the case insensitive phrase init inside a stripped main bundle
(lldb) lookup -X (?i)init
# Search for all hardcoded, embeded `char *` inside an executable containing the phrase *http* inside UIKit
(lldb) lookup -S http -m UIKit
# Dump all the md5'd base64 keys in libMobileGestalt along w/ the address in memory
(lldb) loo -S ^[a-zA-Z0-9\+]{22,22}$ -m libMobileGestalt.dylib -l
# Dump all the global bss code referenced by DWARF. Ideal for accessing `static` variables when not in scope
(lldb) lookup . -g HonoluluArt -l
# Look for phrase "nominal" (Swift's nominal type descriptors) in module "SwiftTest" and get address, don't evaluate symbol
(lldb) lookup -G SwiftTest nominal -l
biof
如果在 func 上,則中斷。 語法:biof regex1 [OptionalModuleName] ||| regex2 必需模塊名稱
接受兩個正則表達式輸入的正則表達式斷點。 第一個正則表達式在所有匹配的函數(shù)上創(chuàng)建一個斷點。
只有當?shù)诙€正則表達式斷點在堆棧跟蹤中時,第二個正則表達式才會使斷點條件停止
例如,僅在“TestApp”模塊中的代碼導致執(zhí)行 setTintColor: 方法時停止
biof setTintColor: ||| . 測試
作為提示,明智的做法是使用有限的 regex1 來匹配少量函數(shù),同時將 regex2 保持在任意大小
yoink
在 iOS/tvOS/watchOS 上獲取路徑并寫入您計算機上的 /tmp/ 目錄。 如果可以通過-[NSData dataWithContentsOfFile:]讀取,則可以寫入磁盤
Example (on iOS 10 device):
(lldb) yoink /System/Library/Messages/iMessageEffects/CKConfettiEffect.bundle/CKConfettiEffect

pmodule
創(chuàng)建自定義 dtrace 腳本,該腳本根據(jù)可執(zhí)行文件的內(nèi)存布局和 ASLR 對可執(zhí)行文件中的模塊進行概要分析。 如果您想要所有模塊觸發(fā)的計數(shù),請不要提供帶有“-a”的參數(shù)。 如果您想在所有方法發(fā)生時轉(zhuǎn)儲它們,請?zhí)峁┮粋€模塊。 腳本的位置將復制到您的計算機,以便您可以將即將執(zhí)行的 dtrace 腳本粘貼到終端中。
警告:您必須禁用 ROOTLESS 才能使用 DTRACE
(lldb) pmodule UIKit
# Trace all non-Objective-C code in libsystem_kernel.dylib (i.e. pid$target:libsystem_kernel.dylib::entry)
(lldb) pmodule -n libsystem_kernel.dylib
# Dump errrything. Only displays count of function calls from modules after you end the script. Warning slow
(lldb) pmodule -a

snoopie
生成一個 DTrace 腳本,該腳本將只分析實現(xiàn)的類
在主可執(zhí)行文件中,無論二進制文件是否被剝離。 這是通過
分析 objc_msgSend。 本書討論了該命令的創(chuàng)建。
警告:您必須禁用 ROOTLESS 才能使用 DTRACE
LLDB Commands
ls -從進程的角度列出目錄。 在實際設(shè)備上工作時很有用。
# List the root dir's contents on an actual iOS device
(lldb) ls /
# List contents for /System/Library on an actual iOS device
(lldb) ls /System/Library
reload_lldbinit
重新加載 ~/.lldbinit 文件中的所有內(nèi)容。 用于查看您的 python 腳本是否損壞或想要對 python 腳本進行增量更新
# Reload/Refresh your LLDB scripts
(lldb) reload_lldbinit
tv
切換視圖。 根據(jù)當前狀態(tài)隱藏/顯示視圖。 您無需恢復 LLDB 即可查看更改。 僅限對象
# Toggle a view on or off
(lldb) tv [UIView new]
pprotocol
轉(zhuǎn)儲特定協(xié)議的所有必需和可選方法(僅限 Objective-C)
# Dump the protocol for UITableViewDataSource
(lldb) pprotocol UITableViewDataSource
pexecutable
將文件路徑的位置(在磁盤上)打印到可執(zhí)行文件
(lldb) pexecutable
pframework
打印框架的位置(在磁盤上)
(lldb) pframework UIKit
sys
進入 shell 以執(zhí)行命令。 請注意,您可以通過 $() 語法執(zhí)行 LLDB 命令
# ls the directory LLDB is running in
(lldb) sys ls
# Use otool -l on the UIKit framework
(lldb) sys otool -l $(pframework UIKit)
# Open the main executable in another program
(lldb) sys open -a "Hopper" $(pexecutable)
methods
轉(zhuǎn)儲 NSObject 子類實現(xiàn)的所有方法(僅限 iOS、NSObject 子類)
# Get all the methods of UIView
(lldb) methods UIView
ivars
轉(zhuǎn)儲從 NSObject 繼承的特定類的實例的所有 ivars(僅限 iOS、NSObject 子類)
# Get all the ivars on a newly created instance of UIView
(lldb) ivars [UIView new]
dumpenv
轉(zhuǎn)儲在進程中找到的環(huán)境變量
(lldb) dumpenv
TESTMANAGERD_SIM_SOCK=/private/tmp/com.apple.launchd.9BmpbuRgyE/com.apple.testmanagerd.unix-domain.socket
MallocNanoZone=0
...
keychain
轉(zhuǎn)儲與進程相關(guān)的鑰匙串數(shù)據(jù)庫
(lldb) keychain
<__NSArrayM 0x600001fb1590>(
{
acct = "localdevice-AuthToken";
agrp = apple;
"v_Data (str)" = "A8CD94D2-13E3-40B...
info
確定地址是什么。 確定它是堆、MachO 還是堆棧地址
(lldb) info 0x00007ffee39fd540
0x00007ffee39fd540, stack address (SP: 0x7ffee39fd4e8, FP: 0x7ffee39fd540) mach_msg_trap
(lldb) info 0x7ff15e866800
0x7ff15e866800, 0x7ff15e866800 heap pointer, (0x600 bytes)
(lldb) info 0x1279232a6
0x1279232a6, -[MKPlaceInfoViewController viewDidLoad] <+0> `MapKit`__TEXT.__text + 0x1813d6
lsof
列出進程中打開的文件描述符。 (無參數(shù))
(lldb) lsof
0 /dev/null
1 /dev/null
2 /dev/null
4 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/KeyboardLayouts/USBKeyboardLayouts.bundle/uchrs/US.uchr
gg
暫停進程(好游戲,AKA 游戲結(jié)束,奇怪的,我知道)。 (無參數(shù))
dump_app_contents
轉(zhuǎn)儲應用程序包的內(nèi)容。 (無參數(shù))
mload
dlopen 便捷方法
pbpaste
將選定的文本從您的 Mac 粘貼到您的 iOS 設(shè)備。 (沒有參數(shù),但請確保剪貼板中有內(nèi)容)
bdel
按地址刪除斷點
data
轉(zhuǎn)儲 NSData 對象的字節(jié)
pexecutable
將完整路徑轉(zhuǎn)儲到可執(zhí)行文件。 (無參數(shù))
plocalmodulelist
轉(zhuǎn)儲特定于應用程序的本地模塊。 (無參數(shù))
overlaydbg
在 11 中顯示 iOS 上的 UIDebuggingInformationOverlay。查看 http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/ 以獲取說明
# Display UIDebuggingInformationOverlay
(lldb) overlaydbg