我想知道如何记录函数的堆栈返回地址?
如果你像这样记录参数:
int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
//在 DllMain 之下
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
fprintf(pSendLogFile, "%s\n", buf);
fclose(pSendLogFile);
return pSend(s, buf, len, flags);
}
那Send的返回地址怎么记录呢?
最佳答案
我不确定您要实现的目标,因此很难知道这是否是正确答案。我假设您知道自己在做什么,但我会敦促您重新考虑您的设计。
话虽如此,请在 http://msdn.microsoft.com/en-us/library/64ez38eh 查看内在函数 _ReturnAddress()
这将为您提供指令的地址,该指令将在您从返回调用 _ReturnAddress()
的函数之后立即执行,而 _AddressOfReturnAddress()
位于 http://msdn.microsoft.com/en-us/library/s975zw7。这将为您提供存储返回地址的地址。
请务必仔细阅读文档并理解您返回的地址代表什么。如果您操纵返回地址,请非常小心,因为如果您做错了事,事情可能会(而且将会)大发雷霆。
关于c++ - 如何在 C++ 中记录函数的堆栈返回地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11183346/