我正在阅读有关Windbg 基于断点的操作,它就像触发断点时在调试器中自动执行命令一样。
例如这个:
0:005> bp kernel32!WriteFile ".printf \"The number of bytes written is: %p\", poi(esp
+ 0x0C);.echo;g"
此命令的想法是显示已写入文件的字节。
忽略该命令,只关注为什么他们使用 esp + 0x0c 作为 WriteFile API 的偏移量? 我的意思是当我从微软检查这个 winapi 的原型时
BOOL WriteFile(
[in] HANDLE hFile,
[in] LPCVOID lpBuffer,
[in] DWORD nNumberOfBytesToWrite,
[out, optional] LPDWORD lpNumberOfBytesWritten,
[in, out, optional] LPOVERLAPPED lpOverlapped
);
这个 WINAPI 使用 _stdcall 约定,因为它是 32 位的,所以参数将从右到左,如下所示:
esp+0x00 would be the address of hFile.
esp+0x04 would be the address of lpBuffer.
esp+0x08 would be the address of nNumberOfBytesToWrite.
那么为什么在上面的命令中他们使用了偏移量 12 而不是 8 呢?有什么我错过的吗?
上面的命令来自OSED课程
0x402020 调用Writefile 0x40202x 返回此处
调用Writefile会在进入Writefile之前推送返回地址0x40202x
进入函数后
Esp + 0 will have 0x40202x the return address
Esp + 4 will hold hFile
Esp + 8 will hold LpBuffer
Eso + c will hold nNumberOfBytesToWrite