- updated to support imports by ordinal value

- doesn't break if library has no entry point
This commit is contained in:
Joachim Bauch
2004-10-31 13:30:43 +00:00
parent a7a9eda6c4
commit eb764af1ef
+24 -17
View File
@@ -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: