0
votes

I'm trying get the address of GetProcAddress with GetProcAddress (yes. calling it on itself). When I'm doing it from an empty exe project I get a valid address (between the allocated address of kernel32).

When I'm calling it from a dll, I'm getting invalid address (not in the range of the allocated kernel32)

What is the difference? I'm running on windows 7 with 64 bit.

The project are compiled as 32 bit. Here is the code that I'm running:

typedef FARPROC (WINAPI * GetProcAddressType)(HMODULE , LPCSTR );

HMODULE kernel32Hmodule = LoadLibraryW(L"c:\windows\system32\kernel32.dll");

GetProcAddressType abc = (GetProcAddressType)GetProcAddress(kernel32Hmodule, "GetProcAddress");

I also tried to get the address like this: void* a = GetProcAddress; but it returns the same invalid address when running from a dll...

Please help.

2

2 Answers

0
votes

Exe are normally loaded at their preferred addresses, DLL are often relocated (not loaded at their preferred addresses) when they opt for ASLR and when the relocation is needed (e.g. their preferred address is already taken). This could explain the delta you experienced between the behaviours.

0
votes

ok i found the problem. when i loaded the dll with rundll32 it acted wierd... when i build a loader by myself (loadlibrary, than getprocaddress) it worked fine. rundll32 is the one caused the problems