关于ios:iOS-lldb寄存器读写Macho解析

4次阅读

共计 2072 个字符,预计需要花费 6 分钟才能阅读完成。

咱们明天探讨的是办法调用的传参, 寄存器是怎么运作的:
首先咱们在一个办法里打上断点,lldb 输出 re re 打印所有寄存器的值

惟一的输出参数, 是在 x2 寄存器里, 咱们当初看看能用什么办法读出寄存器里的值,
memory read 0x0000000100b24850

这里能够看到是占 32 位的一个数据结构, 再这里咱们要先回到 MachOView 里查看这个地址所在的数据是什么样子的, 首先咱们通过减去 ASLR 的值找到 MachoView 里的地址

关上 MachOView,数据是这样的,总共 32 位,咱们以 8 个字节来宰割来解析这个数据结构,最高 8 字节是示意数据的大小, 次高 8 字节是示意寄存的是地址指向真正的内容, 次次 8 字节可能存发的是类型???0x07c8, 最低 8 字节可能是寄存的是给指针调配的地址
图解:

最高 8 字节
在 memory read 最高 8 字节是 0A 00 00 00 00 00 00 00
咱们先看最高 8 字节, 因左边是高位,它的数据得从右向左读 (是一个字节一个字节的读的,16 进制两位示意一个字节)
00 00 00 00 00 00 00 0A

由此得出和 MachOView 这里的值是合乎的

次高 8 字节
在 memory read 次高 8 字节是 7f b0 62 04 01 00 00 00,因左边是高位从右向左读失去
0x000000010462b07f 减去 ASLR 失去 0x000000010001f07f

去 MachOView 里寻找 0x000000010001f07f 果然是对应的字符串, 这里是寄存在__TEXT,__cstring 里,示意是不可批改的.

在 lldb 读出字符串内容, 因为咱们得悉字符串大小是 10 字节,由此咱们能够以 memory read -c 10 读出字符串,

后记: 字面量字符串是寄存在__TEXT,__cstring 里的, 比如说下图中的 appsafekb

而 oc 字符串类的属性是放在__DATA,__cfstring 里的, 比如说上图的_jsonName

示例: 在函数里定义一个字符串变量,NSString *key = @"songxuhua_OK";

由此可见, 字符串变量地址指向的是一个占有 32 字节的空间,16~23 字节所寄存的地址指向字符串的内容,23~31 字节寄存的是字符串大小,前 16 字节临时不是很分明代表啥

memory read 具体应用办法
x/memory read:dump 指定地址的内存(Read from the memory of the process being debugged),后接起止地址或 - c 指定 count 加起始地址。可 help mem read 查看帮忙:

Syntax:
memory read[]

Command Options Usage:
size 指定内存块(block/item)的大小,默认为 1byte。
–size):The size in bytes to use when displaying with the selected format.

count 指定内存块(block/item)的个数,可配合起始地址应用。
-c(–count):The number of total items to display.

format 指定内容显示格局,格局符同 print:c-char,s-string,d-decimal,x-hex。
-f(–format):Specify a format to be used for display.

Command Samples:
(a)起止地址
(lldb)mem read 0x10b88f0c 0x10b88f0c+9
0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
(b)起始地址 + 内存块 count
(lldb)mem read 0x10b88f0c -c 9
0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
(c)起始地址 + 内存块 size+ 内存块 count(dump hex format)
(lldb)memory read -s 1 -f x -c 9 0x10b88f0c
0x10b88f0c: 0x39 0x38 0x37 0x36 0x35 0x34 0x33 0x32
0x10b88f14: 0x31
(d)起始地址 + 内存块 size+ 内存块 count(dump char format)
(lldb)memory read -s 1 -f c -c 9 0x10b88f0c
0x10b88f0c: 987654321
(e)起始地址 + 内存块 size+ 内存块 count(dump string format)
(lldb)mem read 0x10b5cf2c -f s -c 1
0x10b88f0c: “987654321”
(f)起始地址 + 内存块 size+ 内存块 count(dump int format)
(lldb)memory read -s 4 -f x -c 3 0x10b88f0c
0x10b88f0c: 0x36373839 0x32333435 0x109f0031
memory write:改写指定地址的内存(Write to the memory of the process being debugged)。可 help mem write 查看帮忙:

Syntax: memory write

正文完
 0