Getting the memory address of a DLL function

I want to know if this is possible using C and WindowsAPI if there is a function that will get me the 32-bit (I think) memory address of the function in the dll. For example. How to get the 32-bit address of $ xxxxxxxx Beep () in the kernel32.dll file. Secondly, if I use the memory address instead of the function name in the assembly, can I avoid binding. for example

mov eax, $xxxxxxxx

instead

mov eax, Beep
+4
source share
2 answers

This program will print the address Beepin kernel32:

#include <windows.h>
#include <stdio.h>

int main(void)
{
    HMODULE hMod = GetModuleHandle("kernel32.dll");
    void* fn = GetProcAddress(hMod, "Beep");
    printf("%p", fn);
}

I skipped error checking for simplicity. In a real program, you would not do that.

+2
source

Yes. See "GetProcAddress" on MSDN.

+2
source

Source: https://habr.com/ru/post/1523914/


All Articles