56.windbg-s、#(搜索字符串、地址、汇编)

s(Search Memory)

s 命令搜索内存查找指定模板

1.  寻找内存泄露的线索。比如知道当前内存泄漏的内容是一些固定的字符串,就可以在 
   DLL 区域搜索这些字符串出现的地址,然后再搜索这些地址用到什么代码中,找出这些 
    内存是在什么地方开始分配的。 
2.  寻找错误代码的根源。比如知道当前程序返回了 0x80074015  这样的一个代码,但是不 
    知道这个代码是由哪一个内层函数返回的。就可以在代码区搜索 0x80074015,找到可能 
    返回这个代码的函数。

比如我的代码中有个char* g_char = "I am string";全局字符串变量

我想要查找,这个肯定是放在.rdata段中,所以

0:000> !dh -s 01270000 

SECTION HEADER #3
  .rdata name
    1D11 virtual size
   15000 virtual address
    1E00 size of raw data
    3A00 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         (no align specified)
         Read Only
 

//字符串搜索--------------------------------------------------------------------------------------------------------------------------------------------------

s-sa 和s-su 命令搜索未指定的ASCII和Unicode字符串。这在检查某段内存是否包含可打印字符时有用。 

s-a 和s-u 命令分别用来搜索指定的ASCII和Unicode字符串。这些字符串不一定要null结尾

0:000> s -sa 01270000+15000 L1D11
0128573c  "I am string"
01285868  "bad allocation"
012858e0  "Stack around _alloca corrupted"
01285908  "Local variable used before initi"
01285928  "alization"
0128593c  "Stack memory corruption"
01285958  "Cast to smaller type causing los"
0:000> s -a 01270000+15000 L1D11 "I am"
0128573c  49 20 61 6d 20 73 74 72-69 6e 67 00 25 73 0a 00  I am string.%s..

可以使用flag [1]在搜索输出中仅显示匹配项的地址。该选项在使用.foreach把输出通过管道传递给其他命令作为输入时很有用。  

注意有个[]号

0:000> s -[1]a 01270000+15000 L1D11 "I am"
0x0128573c
0:000> .foreach (addr {s -[1]a 01270000+15000 L1D11 "I am"}){da ${addr}}
0128573c  "I am string"


// 内存地址搜索------------------------------------------------------------------------------------------------------------------------------

搜索printf的调用地址

009614d4 test1!printf = <no type information>
009682c8 test1!_imp__printf = <no type information>
0:000> s -[1]d 00961431 L130000 009682c8
0x0096145d

0:000> u 0096145d L2
test1!wmain+0x2d [d:\windbg\test1\test1.cpp @ 23]:
0096145d c8829600        enter   9682h,0
00961461 83c408          add     esp,8
0:000> ub 00961461 L1
test1!wmain+0x2b [d:\windbg\test1\test1.cpp @ 23]:
0096145b ff15c8829600    call    dword ptr [test1!_imp__printf (009682c8)]

(反汇编)

在反汇编代码中搜索符合指定模板的数据

0:001> lm m test1
start    end        module name
00a50000 00a6b000   test1    C (private pdb symbols)  C:\Program Files (x86)\Debugging Tools for Windows (x86)\sym\test1.pdb\0142AD0EED1143078D35079F6E0C70AB5\test1.pdb
0:001> # test1!_imp__printf 00a50000
test1!printf:
00a614d4 ff25c882a600    jmp     dword ptr [test1!_imp__printf (00a682c8)]
0:001> # test1!_imp__printf   ///<接着上次搜索结果地址后搜索
test1!ThreadProc+0x58 [d:\windbg\test1\test1.cpp @ 23]:
00a61b48 ff15c882a600    call    dword ptr [test1!_imp__printf (00a682c8)]
0:001> # test1!_imp__printf
test1!wmain+0x4d [d:\windbg\test1\test1.cpp @ 33]:
00a630dd ff15c882a600    call    dword ptr [test1!_imp__printf (00a682c8)]

地址也可以直接使用函数名替代

0:001> # *test1!_imp__printf* test1!wmain
test1!wmain+0x4d [d:\windbg\test1\test1.cpp @ 33]:
00a630dd ff15c882a600    call    dword ptr [test1!_imp__printf (00a682c8)]

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值