天天看點

46.windbg-條件斷點(windbg script)

使用j指令的條件斷點的基本文法如下:

0:000> 

bp 

Address

 "j (

Condition

) '

OptionalCommands

'; 'gc' "

使用.if指令的條件斷點的基本文法如下:

0:000> 

bp 

Address

 ".if (

Condition

) {

OptionalCommands

} .else {gc}"

其實結合起來看就是雙引号括起來了判斷條件語句

可以通過windbg搜尋conditinal breakpoints查到相關示例

要注意的是,一旦使用别名:

1.必須使用.block{}把使用别名的包含在裡面

2.必須在使用别名前,先用ad指令把别名删除掉

1. 0:000> as /mu $ustr poi(@esp+4)  
2. 0:000> al  
3.   Alias            Value    
4.  -------          -------   
5.  $str             C:\Windows\system32\shell32.dll   
6.  $ustr            imm32.dll   
7. 0:000> ad*  
8. 0:000> al  
9. No aliases  
10. 0:000> as /mu $ustr poi(@esp+4)  
11. 0:000> al  
12.   Alias            Value    
13.  -------          -------   
14.  $ustr            imm32.dll   
15. 0:000> ? $spat(@"$ustr", @"*mm32.dll")  
16. Evaluate expression: 1 = 00000001  
17. 0:000> ad /q $ustr  
18. 0:000> al  
19. No aliases      

綜合起來

1. 0:000> ad*  
2. 0:000> bc*  
3. 0:000> bu Kernel32!LoadLibraryW"aS /mu $ustr poi(@esp+0x4);.block{r @$t0=$spat(@\"$ustr\", @\"*32.dll\");.if(0==@$t0){gc;}}"  
4. 0:000> g  
5. eax=00000001 ebx=00000001 ecx=76b36833 edx=773c7094 esi=76b367cf edi=00000000  
6. eip=7687ef42 esp=00aff2ec ebp=00aff30c iopl=0         nv up ei pl nz na po nc  
7. cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202  
8. kernel32!LoadLibraryW:  
9. 7687ef42 8bff            mov     edi,edi  
10. 0:000> al  
11.   Alias            Value    
12.  -------          -------   
13.  $ustr            imm32.dll   
14. 0:000> ad*  
15. 0:000> g      

這裡要注意的是不要在.if中加ad*,不然下次就斷到未知名的地方了,具體原因不清楚!

1. 0:000> al  
2.   Alias            Value    
3.  -------          -------   
4.  $ustr            advapi32.dll   
5. 0:000> ad*  
6. 0:000> g      
1. 0:000> al  
2.   Alias            Value    
3.  -------          -------   
4.  $ustr            C:\Windows\system32\ole32.dll   
5. 0:000> ad*  
6. 0:000> g      

去掉.block試下:

1. 0:000> bu Kernel32!LoadLibraryW"aS /mu $ustr poi(@esp+0x4);r @$t0=$spat(@\"$ustr\", @\"*32.dll\");.if(0==@$t0){gc;}"  
2. 0:000> BL  
3. t0=$spat(@\"$ustr\", @\"*32.dll\");.if(0==@$t0){gc;}"  
4. 0:000> G