ios逆向過程中lldb調試技巧


在ios逆向過程中,善於運用lldb,會給逆向帶來很大的方便

一般的命令:

1、image list -o -f  看看各個模塊在內存中的基址

2、register read r0  讀取寄存器r0的值。register read  讀取所有寄存器的值

3、expression(或者縮寫expr)  表達式 

     例子:

     expression $r6 = 1   // 設置r6寄存器的值

     expression $r6       // 查看r6寄存器的值

     expression username(源代碼中變量) = @"11111"

     expression [self btnTest]     // 調用某類某方法

4、po 表達式

    例子:

    po $r6

    po username

    po [[NSString alloc] initWithData:$r2 encoding:4]   // 打印$r2寄存器的明文數據

    po [$r5 base64EncodedStringWithOptions:0];          // 打印$r5寄存器(NSData)類型的base64明文數據

5、print (type)表達式

     例子:

     print (int)$r6

     print username

 6、bt [all]   --- 打印調用堆棧

     例子:

     bt

    返回如下:

 * thread #1: tid = 0x1ee09, 0x00035e80 debug`-[ViewController loginWithUserName:password:](self=0x15d7be60, _cmd=0x00036441, username=0x15db0120, password=0x0003768c) + 168 at ViewController.m:34, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1

  * frame #0: 0x00035e80 debug`-[ViewController loginWithUserName:password:](self=0x15d7be60, _cmd=0x00036441, username=0x15db0120, password=0x0003768c) + 168 at ViewController.m:34

7、breakpoint list     //打印斷點列表

    例子:br l

8、s   源碼級別單步執行,遇到子函數則進入

9、si  單步執行,遇到子函數則進入

10、n 源碼級別單步執行,遇到子函數不進入,直接步過

11、ni 單步執行,遇到子函數不進入,直接步過

12、finish/f  退出子函數

13、thread list 打印線程列表

14、image lookup -a 表達式、image list

      例子:

     image lookup -a $pc

     返回如下:

      Address: debug[0x0000b236] (debug.__TEXT.__text + 1254)

      Summary: debug`main + 58 at main.m:16

15、查找某個函數:

      對於有調試符號的這樣使用

      image lookup -r -n <FUNC_REGEX>

      對於無調試符號的這樣使用:

      image lookup -r -s <FUNC_REGEX>

16、disassemble(簡寫di) -a 地址

      disassemble -A thumb    

      可選:

      thumbv4t

      thumbv5

      thumbv5e

      等等一系列

17、memory read(簡寫x) [起始地址 結束地址]/寄存器 -outfile 輸出路徑

 (lldb) memory read -f s $x1
 或者
 (lldb) x -f s $x1
(lldb) x -f A $sp $fp
 sp是上級函數即調用者的堆棧首地址,fp是上級函數的堆棧結束地址,所以根據sp和fp就可以一級一級得出調用關系

( lldb ) memory read –format x –size 4 0xbffff3c0

以16進制格式顯示0xbffff3c0開始的內存數據,數據是4個字節為一個單位的

(lldb)memory read –outfile /tmp/mem.bin –binary 0x1000 0x1200

 把0x100 到 0x1200的內存數據輸出到文件

18、內存斷點 watchpoint set expression 地址    /  watchpoint set variable 變量名稱 -- (源碼調試用到,略過)

      例子:

      watchpoint set expression 0x1457fa70

     命中后得到結果:

     Watchpoint 3 hit:

     old value: 3

     new value: 4

18.1、內存訪問斷點 watchpoint set expression -w read -- 內存地址

     watchpoint set expression -w read -- 0x16b9dd91

18.2、內存寫入斷點 watchpoint set expression -w write -- 內存地址

     watchpoint set expression -w read -- 0x16b9dd91

18.3、條件斷點 watchpoint modify -c 表達式

     例子:

     watchpoint modify -c '*(int *)0x1457fa70 == 20'

     命中后得到結果:

     Watchpoint 3 hit:

     old value: 15

     new value: 20

19、找按鈕事件 po [按鈕名稱/內存地址 allTargets] 

     例子:

    (lldb) po [[self btnTest] allTargets]
    {(
        <ViewController: 0x166af1f0>
    )}

  (lldb) po [[self btnTest] actionsForTarget:(id)0x166af1f0 forControlEvent:0]
   <__NSArrayM 0x165b8950>(
  testAction:
  )

Bash
// 在機器上實戰一下:
(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription] <UIWindow: 0x15e771c0; frame = (0 0; 320 568); gestureRecognizers = <NSArray: 0x15e96210>; layer = <UIWindowLayer: 0x15e988e0>> | <UIView: 0x15eb4180; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x15eb4300>> | | <UIButton: 0x15eb32d0; frame = (277 285; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15eb2e30>> | | | <UIButtonLabel: 0x15db5220; frame = (0 6; 46 18); text = 'Button'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15db5410>> | | <_UILayoutGuide: 0x15eb4360; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x15eb4540>> | | <_UILayoutGuide: 0x15eb4af0; frame = (0 568; 0 0); hidden = YES; layer = <CALayer: 0x15eb4b70>> (lldb) po [(UIButton *)0x15eb32d0 allTargets] {( <ViewController: 0x15e93250> )} (lldb) po [(UIButton *)0x15eb32d0 allTargets] {( <ViewController: 0x15e93250> )} (lldb) po [(UIButton *)0x15eb32d0 actionsForTarget:(id)0x15e93250 forControlEvent:0] <__NSArrayM 0x15dbfc50>( testAction: ) // 調用-- (lldb) po [0x15e93250 testAction:nil] 0x00210c18

 // 再來一發,對按鈕屬性操作

Bash
(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription] <UIWindow: 0x15e771c0; frame = (0 0; 320 568); gestureRecognizers = <NSArray: 0x15e96210>; layer = <UIWindowLayer: 0x15e988e0>> | <UIView: 0x15eb4180; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x15eb4300>> | | <UIButton: 0x15eb32d0; frame = (277 285; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15eb2e30>> | | | <UIButtonLabel: 0x15db5220; frame = (0 6; 46 18); text = 'Button'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15db5410>> | | <_UILayoutGuide: 0x15eb4360; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x15eb4540>> | | <_UILayoutGuide: 0x15eb4af0; frame = (0 568; 0 0); hidden = YES; layer = <CALayer: 0x15eb4b70>> (lldb) expression UIButton *$btn = (UIButton *)0x15eb32d0 (lldb) expression [$btn setHidden:YES]

20、std::string 讀取方式:從內存+8的地方開始  64bit自行變通

    例:

    Bash
(lldb) x $r0+8 0x02db9248: 20 82 e3 14 71 00 00 00 61 00 00 00 c0 82 d3 14 .惝q...a...喇贏 0x02db9258: 71 00 00 00 2b 00 00 00 20 f9 e6 14 61 00 00 00 q...+... .a... (lldb) x/s 0x14e38220 0x14e38220: "hello!piaoyun"


參考:http://www.dllhook.com/post/51.html

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM