LLDB-插件指令集

LLDB Scripts

对于下面的所有命令,您可以通过 help {command} 查看文档。 如果您想查看命令有哪些选项,请输入 {command} -h

TLDR:searchlookupdclass 都是不错的 GOTO,无论您是开发人员还是没有资源的探索者。

如果您喜欢 ObjC swizzling,请查看 sclass。 如果您喜欢 DTrace,请查看 pmodulesnoopie

search

在堆中搜索某个类的所有活动实例。 这个类必须是动态的(也就是从NSObject/SwiftObject 类继承)。 目前不适用于 NSStringNSNumber(标记的指针对象)。

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

在此过程中转储所有 NSObject/SwiftObject 继承类。 如果你给它一个模块,它只会转储该模块中的类。 您还可以将类过滤为仅特定类型,还可以为特定类生成头文件。

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 中的可执行文件或框架的 Mach-O 段/部分中的数据

dd

替代 LLDB 的反汇编命令。 使用颜色。 仅限终端,专为 x86)64 设计。 ARM64 支持终有一天会到来...


image.png

sbt -象征回溯。 如果回溯使用的是 Objective-C,则将符号化从可执行文件中剥离的回溯

代码。 目前不适用于 aarch64 剥离的可执行文件,但在 x64 上效果很好:]

sbt_gif.gif

msl

msl 0xadd7e55
msl 或 malloc 堆栈日志记录将获取一个地址并尝试获取堆栈跟踪以
什么时候创建的。

您需要将环境变量设置为 MallocStackLogging,或execute turn_on_stack_logging(1)
当进程处于活动状态时

msl_gif.gif

lookup -对可执行文件中的内容执行正则表达式搜索

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 必需模块名称
接受两个正则表达式输入的正则表达式断点。 第一个正则表达式在所有匹配的函数上创建一个断点。
只有当第二个正则表达式断点在堆栈跟踪中时,第二个正则表达式才会使断点条件停止

例如,仅在“TestApp”模块中的代码导致执行 setTintColor: 方法时停止
biof setTintColor: ||| . 测试

作为提示,明智的做法是使用有限的 regex1 来匹配少量函数,同时将 regex2 保持在任意大小

yoink

在 iOS/tvOS/watchOS 上获取路径并写入您计算机上的 /tmp/ 目录。 如果可以通过-[NSData dataWithContentsOfFile:]读取,则可以写入磁盘

Example (on iOS 10 device):

 (lldb) yoink /System/Library/Messages/iMessageEffects/CKConfettiEffect.bundle/CKConfettiEffect
yoink_gif.gif

pmodule

创建自定义 dtrace 脚本,该脚本根据可执行文件的内存布局和 ASLR 对可执行文件中的模块进行概要分析。 如果您想要所有模块触发的计数,请不要提供带有“-a”的参数。 如果您想在所有方法发生时转储它们,请提供一个模块。 脚本的位置将复制到您的计算机,以便您可以将即将执行的 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
pmodule_gif.gif

snoopie

生成一个 DTrace 脚本,该脚本将只分析实现的类
在主可执行文件中,无论二进制文件是否被剥离。 这是通过
分析 objc_msgSend。 本书讨论了该命令的创建。
警告:您必须禁用 ROOTLESS 才能使用 DTRACE

LLDB Commands

ls -从进程的角度列出目录。 在实际设备上工作时很有用。

  # 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 文件中的所有内容。 用于查看您的 python 脚本是否损坏或想要对 python 脚本进行增量更新

# Reload/Refresh your LLDB scripts
(lldb) reload_lldbinit

tv

切换视图。 根据当前状态隐藏/显示视图。 您无需恢复 LLDB 即可查看更改。 仅限对象

# Toggle a view on or off
(lldb) tv [UIView new]

pprotocol

转储特定协议的所有必需和可选方法(仅限 Objective-C)

# Dump the protocol for UITableViewDataSource
(lldb) pprotocol UITableViewDataSource

pexecutable

将文件路径的位置(在磁盘上)打印到可执行文件

(lldb) pexecutable

pframework

打印框架的位置(在磁盘上)

(lldb) pframework UIKit

sys

进入 shell 以执行命令。 请注意,您可以通过 $() 语法执行 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

转储 NSObject 子类实现的所有方法(仅限 iOS、NSObject 子类)

# Get all the methods of UIView
(lldb) methods UIView

ivars

转储从 NSObject 继承的特定类的实例的所有 ivars(仅限 iOS、NSObject 子类)

# Get all the ivars on a newly created instance of UIView
(lldb) ivars [UIView new]

dumpenv

转储在进程中找到的环境变量

(lldb) dumpenv

TESTMANAGERD_SIM_SOCK=/private/tmp/com.apple.launchd.9BmpbuRgyE/com.apple.testmanagerd.unix-domain.socket

MallocNanoZone=0
...

keychain

转储与进程相关的钥匙串数据库

(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

列出进程中打开的文件描述符。 (无参数)

(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 游戏结束,奇怪的,我知道)。 (无参数)

dump_app_contents

转储应用程序包的内容。 (无参数)

mload

dlopen 便捷方法

pbpaste

将选定的文本从您的 Mac 粘贴到您的 iOS 设备。 (没有参数,但请确保剪贴板中有内容)

bdel

按地址删除断点

data

转储 NSData 对象的字节

pexecutable

将完整路径转储到可执行文件。 (无参数)

plocalmodulelist

转储特定于应用程序的本地模块。 (无参数)

overlaydbg

在 11 中显示 iOS 上的 UIDebuggingInformationOverlay。查看 http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/ 以获取说明

# Display UIDebuggingInformationOverlay
(lldb) overlaydbg
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容