获取DLL函数的内存地址
问题描述:
我想知道是否可以使用C和WindowsAPI,是否有一个函数可以让我获得dll中某个函数的32位(我认为)内存地址.例如.如何在kernel32.dll中获取Beep()的32位$ xxxxxxxx地址.其次,如果我在汇编中使用内存地址而不是函数名,可以避免链接.例如
I want to know if it is possible, using C and the WindowsAPI, if there is a function that will get me the 32 bit(I think) memory address of a function in a dll. For example. How do I get the 32 bit $xxxxxxxx address of Beep() in kernel32.dll. Secondly, if I use the memory address instead of the function name in assembly, can I avoid linking. For example
mov eax, $xxxxxxxx
代替
mov eax, Beep
答
该程序将在kernel32中打印Beep
的地址:
This program will print the address of Beep
in kernel32:
#include <windows.h>
#include <stdio.h>
int main(void)
{
HMODULE hMod = GetModuleHandle("kernel32.dll");
void* fn = GetProcAddress(hMod, "Beep");
printf("%p", fn);
}
为简单起见,我省略了错误检查.在真实程序中,您不会这样做.
I omitted error checking for the sake of simplicity. In a real program you would not do so.