+2011-09-14 Vincent Torri <doursse at users dot sf dot net>
+
+ * src/lib/dlfcn/dlfcn.c:
+ add RTLD_DEFAULT support in dlsym()
+
2011-05-19 Vincent Torri <doursse at users dot sf dot net>
* src/lib/dlfcn/dlfcn.c:
libdl_la_SOURCES = dlfcn.c
-libdl_la_CPPFLAGS = -DEFL_EVIL_DLFCN_BUILD
+libdl_la_CPPFLAGS = @win32_cppflags@ -DEFL_EVIL_DLFCN_BUILD -DPSAPI_VERSION=1
libdl_la_CFLAGS = @win32_cflags@
-libdl_la_LIBADD = $(top_builddir)/src/lib/libevil.la $(EFL_MPATROL_LIBS)
+libdl_la_LIBADD = $(top_builddir)/src/lib/libevil.la $(EFL_MPATROL_LIBS) -lpsapi
libdl_la_LDFLAGS = -no-undefined -Wl,--enable-auto-import -version-info @version_info@
# include <limits.h>
#endif /* __MINGW32CE__ || _MSC_VER */
+#include <windows.h>
+#include <psapi.h> /* EnumProcessModules(Ex) */
+
#include "../Evil.h"
#include "dlfcn.h"
void *
dlsym(void *handle, const char *symbol)
{
- FARPROC fp;
+ FARPROC fp = NULL;
+ LPCTSTR new_symbol;
-#ifdef UNICODE
- {
- wchar_t *wsymbol;
+ if (!symbol || !*symbol) return NULL;
- wsymbol = evil_char_to_wchar(symbol);
- fp = GetProcAddress(handle, wsymbol);
- free(wsymbol);
- }
+#ifdef UNICODE
+ new_symbol = evil_char_to_wchar(symbol);
#else
- fp = GetProcAddress(handle, symbol);
-#endif /* ! UNICODE */
+ new_symbol = symbol;
+#endif /* UNICODE */
+
+ if (handle == RTLD_DEFAULT)
+ {
+ HMODULE modules[1024];
+ DWORD needed;
+ DWORD i;
+
+ /* TODO: use EnumProcessModulesEx() on Windows >= Vista */
+ if (!EnumProcessModules(GetCurrentProcess(),
+ modules, sizeof(modules), &needed))
+ return NULL;
+
+ for (i = 0; i < (needed / sizeof(HMODULE)); i++)
+ {
+ fp = GetProcAddress(modules[i], new_symbol);
+ if (fp) break;
+ }
+ }
+ else
+ fp = GetProcAddress(handle, new_symbol);
+
+#ifdef UNICODE
+ free(new_symbol);
+#endif /* UNICODE */
+
if (!fp)
get_last_error("GetProcAddress returned: ");
* Symbols in this dlopen'ed obj are visible to other dlopen'ed objs
*/
+/**
+ * @def RTLD_DEFAULT
+ * Symbols are searched in all the DLL opened by the current process
+ */
+
# define RTLD_LAZY 0x00001 /* lazy function call binding */
# define RTLD_NOW 0x00002 /* immediate function call binding */
# define RTLD_GLOBAL 0x00100 /* symbols in this dlopen'ed obj are visible
to other dlopen'ed objs */
#define RTLD_NODELETE 0x01000 /* do not delete object when closed. */
+#define RTLD_DEFAULT ((void*)1) /* search the symbol on all the DLL of the current process */
/**
* @typedef Dl_info
#ifdef UNICODE
str = evil_wchar_to_char(msg);
#else
- str = strdup(msg);
+ str = msg;
#endif /* UNICODE */
LocalFree(msg);
snprintf(disp, strlen(str) + strlen("(00000) ") + 1,
"(%5ld) %s", err, str);
+#ifdef UNICODE
free(str);
+#endif /* UNICODE */
return disp;
}