iOS逆向学习-lldb断点调试

lldb断点调试

在xcode中进入lldb调试模式,方法区分大小写

breakpoint

breakpoint set -n method
断点某个方法或者函数
-n 表示名称
method表示方法或函数

缩写:b -r method

对于函数

void *test1() {
}

breakpoint set -n test1

缩写 b -n test1

对于方法

- (void)save:(NSString*)name {
//.....
}
- (void)pause:(NSString*)name {
//.....
}
breakpoint set -n "[ViewController save:]" -n "[ViewController pause:]"
缩写:b set -n "[ViewController save:]" -n "[ViewController pause:]"

对于任何这个方法

breakpoint set --selector touchesBegan:withEvent:
这个方法断点了所有的touchesBegan:withEvent:方法,与类无关

对于文件中这个方法

breakpoint set --file ViewController.m --selector touchesBegan:withEvent:
只在当前的ViewController.m的文件中查找这个方法,并断点

遍历断点

breakpoint set -r Game:
遍历工程中所有的带有Game:字段的方法

查看断点

breakpoint list
可以获取所有断点组
组1可以包含1.1 、1.2

缩写 break list

退出lldb模式

c continue
意味continue

n next
s step

断点开关

breakpoint enable 1
breakpoint disable 1

1代表断点组,或者单个断点1.1,由breakpoint list获取

缩写 break dis 1
缩写 break en 1

断点删除

breakpoint delete 1
如果不传组,则清空所有的断点
breakpoint delete
只能删除指定的组
如果删除1.1,那和disable命令一样,是禁用

指令查看

help breakpoint
查看所有的breakpoint指令

help b
则可以查看b的作用

全部缩写方法可以自己尝试

执行代码

expression

expression self

缩写 p self
使用 p object会获取一个对象
$0 = 地址
然后我们可以通过p $0.property来打印该对象的属性
相当于使用了一个局部变量$0接收该对象的地址,或者该值。
联想block中的对象拷贝和值拷贝

执行代码创建变量

p Person *p4 = [Person new]; 此时按住Alt+Enter既可以写代码,创建p4

堆栈信息查看

bt

使用bt可查看当前堆栈信息。函数调用栈

up down

通过up down可以在堆栈中向上查看

frame值固定查看

通过frame select 1 指令,选择frame查看
指令中显示的都是汇编代码

frame variable 查看参数

可以查看frame的参数

回滚指令 thread return

通过线程回滚,回滚到上一步,但是不会执行了,因为return了。

内存断点

监听值变化

watchpoint set variable p1.name

watchpoint 指令与breakpoint一样,有dis,en,delelte等命令

p1的name属性变更时,会断点
会给两个值

old value : address1
new value : address2

可以通过po执行来查看地址的值

取地址

p &obj.name 这种写法错误,点语法不对
p &obj->_name  只能访问成员变量来获取地址

断点命令

当断点到某个断点时,如果需要指令多个命令,我们可以提前加好断点命令

breakpoint command add 1

> po self
> p self.view
> DONE

这样,当断点1触发时,会自动执行po和p的两句断点指令。

同样command也可以delete、list来查看调用

target

target stop-hook

target stop-hook add -o "frame variable"

意为每次断点的时候,都会调用该frame的variable指令,不管你断住哪个方法,都会打印参数列表

target stop-hook list
target stop-hook delete
target stop-hook disable
target stop-hook enalbe

同样有list delete等指令。

stop-hook的配置

stop-hook一般不是临时调用的,一般是配置好的。lldb有一个初始化文件

cd ~
ls
ls -a
//查找到.lldbinit文件,即为初始化文件,vim操作该文件即可。
vim .lldbinit
cat .lldbinit
target stop-hook add -o "frame variable"

常用指令image

数组越界

  1. bt查看调用堆栈
  2. image lookup -a address

查看文件信息

image lookup -t filename

查看动态库

image list

查看内存值

memory read addressValue

猜你喜欢

转载自blog.csdn.net/shengpeng3344/article/details/91906267