lldb - 附加执行过程时未达到断点(但在应用程序运行之前设置时执行)

逆向工程 数据库 操作系统 ios 数据库 断点
2021-07-10 21:56:49

我正在尝试为现有进程设置断点,但是当我尝试设置断点时,未达到断点,但是当我直接在 lldb 中运行应用程序并在运行之前设置断点时,所有断点都正常。让我们看一个例子:

第一种情况(尝试附加到现有流程):

MacBook-Pro-Michal:Damn m1entus$ ps aux | grep -i calculator
m1entus         28940   0,0  0,0  2432772    676 s001  S+    1:21     0:00.00 grep -i calculator
m1entus         28863   0,0  0,2  2762000  36000   ??  U     1:19     0:00.73 /Applications/Calculator.app/Contents/MacOS/Calculator

下一个

(lldb) attach -p 28863

下一个

(lldb) b *0x00000001000093dd
Breakpoint 1: address = 0x00000001000093dd
(lldb) c
Process 28863 resuming

打开 showAbout 时什么也没发生...(我从 Hopper 那里获取了地址)

第二种情况(使用 lldb 命令运行应用程序):

MacBook-Pro-Michal:Damn m1entus$ lldb /Applications/Calculator.app/Contents/MacOS/Calculator 
(lldb) target create "/Applications/Calculator.app/Contents/MacOS/Calculator"
Current executable set to '/Applications/Calculator.app/Contents/MacOS/Calculator' (x86_64).
(lldb) b *0x00000001000093dd
Breakpoint 1: address = 0x00000001000093dd
(lldb) run
Process 28972 launched: '/Applications/Calculator.app/Contents/MacOS/Calculator' (x86_64)

当我打开 showAbout: 在计算器中我的断点到达:

Process 28972 stopped
* thread #1: tid = 0x8f823, 0x00000001000093dd Calculator`___lldb_unnamed_function161$$Calculator, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
 frame #0: 0x00000001000093dd Calculator`___lldb_unnamed_function161$$Calculator
Calculator`___lldb_unnamed_function161$$Calculator:
->  0x1000093dd <+0>:  pushq  %rbp
0x1000093de <+1>:  movq   %rsp, %rbp
0x1000093e1 <+4>:  movq   0x12b98(%rip), %rdi       ; (void *)0x00007fff7374e488: NSDictionary
0x1000093e8 <+11>: movq   0x12301(%rip), %rsi       ; "dictionaryWithObject:forKey:"

有人可以解释一下为什么会发生这种情况以及如何附加到现有进程并命中断点吗?

1个回答

原因是地址空间布局随机化 (ASLR)。动态加载器将在您必须考虑的起始地址(幻灯片)中使用一些随机化。当您在 中启动应用程序时lldb,不会应用任何幻灯片,因此地址相同。

这是两个不同的计算器应用程序运行的示例

  1. 0x00000200 container [0x00000001040c6000-0x00000001040db000) 0x00000000 0x00015000 0x00000000 Calculator.__TEXT
  2. 0x00000200 container [0x0000000105e21000-0x0000000105e36000) 0x00000000 0x00015000 0x00000000 Calculator.__TEXT

TEXT 段的默认起始地址是 0x0100000000,所以第一个是应用 0x40c6000 的幻灯片,第二个是 0x5e21000 的幻灯片。

假设我想在 上设置断点-[LCDController showValue]对于我的特定版本的计算器,它的地址为0x0100001610. 如果我在lldb. 在第一个示例中,我需要在以下位置设置断点:

0x0100001610 + 0x40c6000 = 0x1040c7610

第二个是:

0x0100001610 + 0x5e21000 = 0x105e22610.