Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting The Memory Address Of A DLL Function

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

instead of

mov eax, Beep
like image 783
James Parsons Avatar asked Jan 27 '14 14:01

James Parsons


2 Answers

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.

like image 151
David Heffernan Avatar answered Oct 27 '22 01:10

David Heffernan


Yes. Look up 'GetProcAddress' on MSDN.

like image 22
Martin James Avatar answered Oct 27 '22 01:10

Martin James