Windbg查看函数的参数
⽤Windbg挂载到中,在CreateFile函数上下断点
0:001> bp kernel32!CreateFileW
0:001> bp kernel32!CreateFileA
在notepad上选择保存,Windbg停⽌在CreateFileW的⼊⼝点
Breakpoint 1 hit
eax=00000000 ebx=00000001 ecx=0007c54c edx=00000001 esi=00000000 edi=00000000
eip=7c810760 esp=0007c404 ebp=0007c42c iopl=0        nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000            efl=00000202
kernel32!CreateFileW:
7c810760 8bff            mov    edi,edi
[SIZE=3]问题:此时我想查看CreateFile的各个参数应该如何看呢?
⽤kb列出当前的堆栈如下:
0:000> kb
ChildEBP RetAddr  Args to Child
0007c400 76fa6b6e 0007c54c 80000000 00000001 kernel32!CreateFileW
0007c42c 76faac07 0007c54c 80000000 00000001 CLBCATQ!WszCreateFile+0x7f
0007c464 76fac121 0007c54c 00000001 00000000 CLBCATQ!StgIO::Open+0xfc
0007c498 76fd770a 0007c54c 00000001 00000000 CLBCATQ!StgDatabase::InitDatabase+0x118
0007c4bc 76fd5316 0007c54c 00000001 000c7bc8 CLBCATQ!OpenComponentLibraryEx+0x3e
0007c4d8 76fa9595 0007c54c 00000001 0007c52c CLBCATQ!OpenComponentLibraryTS+0x1a
0007c774 76fa217b 0007c7cc 00000000 0007c842 CLBCATQ!_RegGetICR+0x205
0007c794 76fa2da1 0007c7cc 0007c842 76fa2d66 CLBCATQ!CoRegGetICR+0x29
0007c7d4 76fa2d38 000c6d20 0007c7f8 8007000e CLBCATQ!IsComplusComponent+0x2f
0007c848 76fa28c6 000c6d20 76ab8e40 00000000 CLBCATQ!CComClass::Init+0x78
0007c878 76fa2946 000c6d20 00000000 00000000 CLBCATQ!CComClass::Create+0x5e
0007c8a0 769b05af 000c78c0 00000000 000c6d20 CLBCATQ!CComCLBCatalog::GetClassInfoW+0x23 0007c910 769aff58 76ab8e38 00000017 00000000 ole32!CComCatalog::GetClassInfoInternal+0x262 0007c934 769b12a7 76ab8e38 000c6d20 76991964 ole32!CComCatalog::GetClassInfoW+0x1c
0007c94c 769b12c9 000c6d20 0007c968 000c6d20 ole32!GetClassInfoFromClsid+0x24
0007c96c 769af99d 000c6d20 0007ca3c 0007cf78 ole32!LookForConfiguredClsid+0x19
0007ca50 769afaba 000c6d20 00000000 00000001 ole32!ICoCreateInstanceEx+0x106
0007ca78 769afa89 000c6d20 00000000 00000001 ole32!CComActivator::DoCreateInstance+0x28 0007ca9c 769afaf7 000c6d20 00000000 00000001 ole32!CoCreateInstanceEx+0x1e
0007cacc 77f4937c 000c6d20 00000000 00000001 ole32!CoCreateInstance+0x37
根据kb的命令说明,其中Args表⽰函数的第⼀个参数,那么其他的参数⼜该如何查看?
0:000> kb
ChildEBP RetAddr  Args to Child
0007c400 76fa6b6e 0007c54c 80000000 00000001 kernel32!CreateFileW
第⼀个参数应该是打开的⽂件路径,⽤dd 0007c54c命令看到该地址的内容如下:
0:000> dd 0007c54c
0007c54c  003a0043 0057005c 004e0049 004f0044
0007c55c  00530057 0052005c 00670065 00730069
0007c56c  00720074 00740061 006f0069 005c006e
0007c57c  00300052 00300030 00300030 00300030
0007c58c  00300030 00300030 002e0062 006c0063
0007c59c  00000062 00000000 00000000 00000000
0007c5ac  00000000 00000000 00000000 00000000
0007c5bc  00000000 00000000 00000000 00000000
那么da 003a0043是否就是显⽰第⼀个参数的内容呢?
刚才试了⼀下,
notepad++
0:000> kb
ChildEBP RetAddr  Args to Child
0007c400 76fa6b6e 0007c54c 80000000 00000001 kernel32!CreateFileW
0007c54c确实就是函数的第⼀个参数,之所以⽤da不能查看,是因为断点在CreateFileW上,该函数的参数是UNICODE字符串,⽤0:000> dW 0007dc88
0007dc88  0044 003a 005c 0061 0061 0061 002e 0074  D.:.\.a.
0007dc98  0078 0074 0000 0007 882a 77d1 000d 0000  *..w....
0007dca8  3dbf 771a 000d 0000 0014 0000 0001 0000  .=.w............
0007dcb8  0000 0000 0000 0000 0010 0000 0000 0000  ................
0007dcc8  882a 77d1 0000 0000 0000 0000 0007 0000  *..w............
0007dcd8  dca4 0007 0001 0000 dda8 0007 0467 77d4  ............g..w
0007dce8  8830 77d1 ffff ffff 882a 77d1 c63f 77d1  0..w....*..w?..w
0007dcf8  4818 000b 3dbf 771a 06e8 000c 000d 0000  .H...=.w........
可以看到⽂件的路径为D:\
那么第⼆、第三或更多的参数应该如何查看了?
呵呵,稍微清楚了⼀些,但汇编基础还需要认真学习(呵呵就这⽔平还能算有基础吗 )
⾸先⽤kb查看函数堆栈
0:000> kb
ChildEBP RetAddr  Args to Child
0007d838 7632beb6 0007dea8 40000000 00000003 kernel32!CreateFileW
0007e0bc 7632741f 0007e0e8 00000000 004a0398 comdlg32!CFileOpenBrowser::OKButtonPressed+0x905
0007e2fc 76327327 0020029c 00230450 000ced30 comdlg32!CFileOpenBrowser::ProcessEdit+0x192
0007e33c 7632274e 00000001 00230450 0007e5e4 comdlg32!CFileOpenBrowser::OnCommandMessage+0x1d3 0007e57c 77d18734 0020029c 00000111 00000001 comdlg32!OpenDlgProc+0x2f5
0007e5a8 77d2418d 763225e4 0020029c 00000111 USER32!InternalCallWinProc+0x28
0007e614 77d23fd9 00000000 763225e4 0020029c USER32!UserCallDlgProcCheckWow+0x146
0007e65c 77d2cb2b 00000000 00000111 00000001 USER32!DefDlgProcWorker+0xa8
0007e68c 77d1b903 005c3200 005bfea8 00000001 USER32!SendMessageWorker+0x384
0007e6ac 771a7344 0020029c 00000111 00000001 USER32!SendMessageW+0x7f
0007e6cc 771a7426 000d0dd0 00000000 00090014 COMCTL32!Button_NotifyParent+0x3d
0007e6e8 771a972b 000d0dd0 00000001 0007e7e0 COMCTL32!Button_ReleaseCapture+0xd7
0007e778 77d18734 00230450 00000202 00000000 COMCTL32!Button_WndProc+0x887
0007e7a4 77d18816 771a8ea4 00230450 00000202 USER32!InternalCallWinProc+0x28
0007e80c 77d1c63f 00000000 771a8ea4 00230450 USER32!UserCallWinProcCheckWow+0x150
0007e83c 77d1c665 771a8ea4 00230450 00000202 USER32!CallWindowProcAorW+0x98
0007e85c 76322dc5 771a8ea4 00230450 00000202 USER32!CallWindowProcW+0x1b
0007e878 77d18734 00230450 00000202 00000000 comdlg32!OKSubclass+0x46
0007e8a4 77d18816 76322d82 00230450 00000202 USER32!InternalCallWinProc+0x28
0007e90c 77d189cd 00000000 76322d82 00230450 USER32!UserCallWinProcCheckWow+0x150
其次,查看ESP,ESP的地址保存的就是EIP的内容,那么ESP+4就是函数的第⼀个参数,ESP+8是第⼆个参数,根据函数的参数个数,以此类推。
在上⾯的例⼦中(ESP为7d83c)
0:000> dd 7d83c
0007d83c  7632beb6 0007dea8 40000000 00000003
0007d84c  00000000 00000001 00000080 00000000
0007d85c  0007e0e8 000ced30 00000000 000ced30
0007d86c  00000000 00000000 00000003 00000000
0007d87c  00000000 0007e0e8 00000000 00000000
0007d88c  00000002 00620061 00000063 00000014
0007d89c  00000001 00000000 00000000 00000010
0007d8ac  00000000 0007d8c4 00000000 00000000
那么0007d83c的内容7632beb6就是对应的EIP了,7d83c+4,就是CreateFileW的第⼀个参数,我们可以⽤dW来look⼀下就能看到参数的内容了。
我开始看过kp,他的说明⾥⾯也说了包括函数参数,但是kp列出的栈信息反⽽⽐kb列出的还要少⼀些。
如下
0:004> bp kernel32!CreateFileW
0:004> g
Breakpoint 0 hit
eax=0007fbb0 ebx=00000104 ecx=00008db0 edx=7c92eb94 esi=00000000 edi=7c80b9ef
eip=7c810760 esp=0007fb04 ebp=0007fb3c iopl=0        nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000            efl=00000202
kernel32!CreateFileW:
7c810760 8bff            mov    edi,edi
0:000> kp
ChildEBP RetAddr
0007fb00 01004ede kernel32!CreateFileW
0007fb3c 01002cde notepad!SaveFile+0x30
0007fdbc 01003927 notepad!NPCommand+0x157
0007fde0 77d18734 notepad!NPWndProc+0x4fe
0007fe0c 77d18816 USER32!InternalCallWinProc+0x28
0007fe74 77d189cd USER32!UserCallWinProcCheckWow+0x150
0007fed4 77d18a10 USER32!DispatchMessageWorker+0x306
0007fee4 01002a12 USER32!DispatchMessageW+0xf
0007ff1c 01007511 notepad!WinMain+0xdc
0007ffc0 7c816fd7 notepad!WinMainCRTStartup+0x174
0007fff0 00000000 kernel32!BaseProcessStart+0x23
0:000> kb
ChildEBP RetAddr  Args to Child
0007fb00 01004ede 0007fbb0 c0000000 00000003 kernel32!CreateFileW
0007fb3c 01002cde 001a0314 0007fbb0 00000001 notepad!SaveFile+0x30
0007fdbc 01003927 001a0314 ******** 00000000 notepad!NPCommand+0x157
0007fde0 77d18734 001a0314 ******** 00000004 notepad!NPWndProc+0x4fe
0007fe0c 77d18816 01003429 001a0314 ******** USER32!InternalCallWinProc+0x28
0007fe74 77d189cd 00000000 01003429 001a0314 USER32!UserCallWinProcCheckWow+0x150 0007fed4 77d18a10 0007fefc 00000000 0007ff1c USER32!DispatchMessageWorker+0x306
0007fee4 01002a12 0007fefc 00000000 7c80b6a1 USER32!DispatchMessageW+0xf
0007ff1c 01007511 01000000 00000000 000b2332 notepad!WinMain+0xdc
0007ffc0 7c816fd7 012dd1fc 00000018 7ffd5000 notepad!WinMainCRTStartup+0x174
0007fff0 00000000 0100739d 00000000 78746341 kernel32!BaseProcessStart+0x23

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。