DLL loading prolem when injecting into another process
hongbo_ni at hotmail.com
Sat Aug 2 01:48:16 CDT 2008
Rolf Kalbermatter wrote:
> I do not think that the solution is to "correct" LoadLibrary to actually do
> a search for linked libraries in the parent library's directory too.
> However I fear the proper fix might go deep into Wine server and probably is
> above most people's head except for Alexandre. What you can do is trying to
> get an actual test integrated to the Wine tests that does what you do in
> your test that you wrote and mark that test as todo_wine. And then hope that
> Alexandre can find a way to implement a fix without to much trouble.
> Of course if you can find the way to implement that correctly a second patch after
> the test has been added as todo_wine would certainly be welcome.
What I have descripted is only one way of hook to another process, there are other ways.
Good news, It turns out the fix could be a simple patch as this
@ -322,7 +322,7 @@ void *get_hook_proc( void *proc, const WCHAR *module )
TRACE( "loading %s\n", debugstr_w(module) );
/* FIXME: the library will never be freed */
- if (!(mod = LoadLibraryW(module))) return NULL;
+ if (!(mod = LoadLibraryExW(module, NULL, LOAD_WITH_ALTERED_SEARCH_PATH))) return NULL;
return (char *)mod + (ULONG_PTR)proc;
When my debug, I noticed 'module' comes in full path. so LoadLibraryW will load the module, but when it process
imports, it searchs the application dir, current dir and PATH. So DLL in the same dir can not be loaded.
By using LOAD_WITH_ALTERED_SEARCH_PATH, LoadLibraryExW will put in path of 'module' on the load_path,
so fix-imports can load linked DLLs by searching the dir of injected dll first, then the current and PATH.
In process HOOK, the target proc has no idea of the injected DLL comes from. The linked DLLs are most likely
NOT in the same dir as current hooked application(s). More likely in the same dir as injected DLL .
What do I have to do to get this patch accepted ?
Are you paid what you're worth? Find out: SEEK Salary Centre
More information about the wine-devel