EXE or DLL Image base address

Idov picture Idov · Nov 28, 2010 · Viewed 35.3k times · Source

Is there a way in C++/windows to get the exe/DLL image base address? thanks :)

Answer

Lars Truijens picture Lars Truijens · Nov 28, 2010

If you load the binary into your own process you can use GetModuleHandle. It returns a HMODULE, but that is the same as HINSTANCE and the base address.

If you want to know what base address the binary prefers you should read the PE header. See here and look for the ImageBase field in IMAGE_OPTIONAL_HEADER.

Edit: GetModuleHandle(NULL) will return the base address (altough the specified type is HMODULE) for the current process.