c++ - 在 C++ 中查找函数的地址

标签 c++ winapi assembly reverse-engineering

我想知道是否有人知道如何获取您所在函数的地址。假设我挂接了 MessageBoxA()。当调用 MessageBoxA() 时,我称我为名为 hookMes​​sageboxA() 的伪函数。在 hookMes​​sageBoxA() 中,我想吐出调用 MessageBoxA() 的位置。那有意义吗?可能需要使用汇编,但我不确定如何完成。

下面的代码是错误的,这只是我认为可能必须要做的事情。非常感谢任何有关如何在汇编和 C++ 中执行此操作的帮助!!!!!

DWORD address = 0x00;
_asm {
    mov address, ebp
}
DWORD keyPointerAddr = (DWORD)hInstance + 0x1000 - address + 0x00401000;
char str[255];
    sprintf(str,"That call is coming from [%d]\n", keyPointerAddr);

最佳答案

您实际上不需要使用任何 API。 MSVC 提供 an intrinsic仅获取返回地址:

#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(_ReturnAddress)

__declspec(noinline)
void noinline_func(void)
{
   printf("Return address from %s: %p\n", __FUNCTION__, _ReturnAddress());
}

关于c++ - 在 C++ 中查找函数的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8797943/

相关文章:

C++,通过指针传递泛型数组,继承,错误: no operator which takes a right-hand operand

c++ - 字符串前面的 'L' 在 C++ 中是什么意思?

python - 已安装程序列表

c++ - 以编程方式查找目录中的文件列表 C++ MFC

assembly - x86中的BEXTR指令是如何工作的

c++ - 插值噪声中的伪影

c++ - vector如何分配内存

c++ - 将 win32 应用程序图标添加到任务栏

linux - 从堆栈中弹出和打印 argc

x86 寄存器重命名的成本