I see here ( http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx ) that in C++ there is a way to get the pe header offset of your module.
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
I wish to do this in masm but I cannot figure out for the life of me how to.
I was thinking of something like:
mov eax, [0400000h]
but how do I get that constant (0400000h) to become relocatable and what if my module doesn't have a preferred base address of 400000h ?
I hope some bright fellow here has the solution.
Thanks in advance
If by module you mean a DLL, DLLMain is passed an HINSTANCE - from the SDK
Quote
hinstDLL
[in] Handle to the DLL module. The value is the base address of the DLL. The HINSTANCE of a DLL is the same as the HMODULE of the DLL, so hinstDLL can be used in calls to functions that require a module handle.
If you mean your EXE, GetModuleHandle *should* point to the PE header of your EXE file - it is almost always 00400000h.
Aye stupid me. I forgot that DllMain receives the hInstance. Thanks!
thanks for the info jag, i knew about _IMPORT_DESCRIPTOR_dll stuff but didn't know about this!
EXTERNDEF C __ImageBase:IMAGE_DOS_HEADER
mov eax,offset __ImageBase
EXTERNDEF C _IMPORT_DESCRIPTOR_KERNEL32:IMAGE_IMPORT_DESCRIPTOR
add eax,_IMPORT_DESCRIPTOR_KERNEL32.Name1