diff --git a/MemoryModule.c b/MemoryModule.c index 78b3fc9..b88cbca 100644 --- a/MemoryModule.c +++ b/MemoryModule.c @@ -250,8 +250,12 @@ BuildImportTable(PMEMORYMODULE module) } for (; *thunkRef; thunkRef++, funcRef++) { - PIMAGE_IMPORT_BY_NAME thunkData = (PIMAGE_IMPORT_BY_NAME)(codeBase + *thunkRef); - *funcRef = (DWORD)GetProcAddress(handle, (LPCSTR)&thunkData->Name); + if IMAGE_SNAP_BY_ORDINAL(*thunkRef) + *funcRef = (DWORD)GetProcAddress(handle, (LPCSTR)IMAGE_ORDINAL(*thunkRef)); + else { + PIMAGE_IMPORT_BY_NAME thunkData = (PIMAGE_IMPORT_BY_NAME)(codeBase + *thunkRef); + *funcRef = (DWORD)GetProcAddress(handle, (LPCSTR)&thunkData->Name); + } if (*funcRef == 0) { result = 0; @@ -359,26 +363,29 @@ HMEMORYMODULE MemoryLoadLibrary(const void *data) FinalizeSections(result); // get entry point of loaded library - DllEntry = (DllEntryProc)(code + result->headers->OptionalHeader.AddressOfEntryPoint); - if (DllEntry == 0) + if (result->headers->OptionalHeader.AddressOfEntryPoint != 0) { + DllEntry = (DllEntryProc)(code + result->headers->OptionalHeader.AddressOfEntryPoint); + if (DllEntry == 0) + { #if DEBUG_OUTPUT - OutputDebugString("Library has no entry point.\n"); + OutputDebugString("Library has no entry point.\n"); #endif - goto error; + goto error; + } + + // notify library about attaching to process + successfull = (*DllEntry)((HINSTANCE)code, DLL_PROCESS_ATTACH, 0); + if (!successfull) + { +#if DEBUG_OUTPUT + OutputDebugString("Can't attach library.\n"); +#endif + goto error; + } + result->initialized = 1; } - // notify library about attaching to process - successfull = (*DllEntry)((HINSTANCE)code, DLL_PROCESS_ATTACH, 0); - if (!successfull) - { -#if DEBUG_OUTPUT - OutputDebugString("Can't attach library.\n"); -#endif - goto error; - } - - result->initialized = 1; return (HMEMORYMODULE)result; error: