From eb764af1efa1c5f7a82ff5f2b6e8e28fda717b7e Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Sun, 31 Oct 2004 13:30:43 +0000 Subject: [PATCH] - updated to support imports by ordinal value - doesn't break if library has no entry point --- MemoryModule.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) 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: