DLL loading prolem when injecting into another process
hongbo_ni at hotmail.com
Fri Aug 1 11:11:47 CDT 2008
Rolf Kalbermatter wrote:
> My guess is that it will however fail on most Windows versions except maybe
> Vista which would still be a reason to try to implement that behaviour in Wine
> too. However you will likely have to do quite
> a bit more tests to then figure out the exact conditions under which this
> behaviour is applied under newer Windows versions.
You are right, when loading a DLL from specific folder, the linked DLL in same folder
can not be loaded. I have tested on Windows Vista.
Back to DLL injecting, It works since Windows 95. My program has been working
for many years, but not on Wine.
Here is how to inject a DLL into another process:
A.exe is linked to A.dll, A.dll is linked to B.dll, they are all in the same folder.
in A.dll I have a function called InjectDll(), it calls SetWindowsHookEx(WH_GETMESSAGE,...)
to inject A.dll into Notepad process. Since A.dll is lined to B.dll, B.dll will be loaded on
window, but on wine.
LRESULT WINAPI GetMsgProc (int nCode, WPARAM wParam, LPARAM lParam)
if(g_hHookGetMsg==NULL) return 0;
return(CallNextHookEx(g_hHookGetMsg, nCode, wParam, lParam));
DLLA_API int InjectDll(void)
HWND hwnd = FindWindow(NULL,"Notepad");
g_hHookGetMsg = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hinstDll,GetWindowThreadProcessId(hwnd, NULL));
PostMessage(hwnd, WM_NULL, 0, 0);
return fnDllB(); //in DLLB.dll
Maybe in window SetWindowsHookEx not only map A.dll, but so all DLL linked by A.dll into Hooked
Also at the time A.exe is injecting A.dll, B.dll is loaded, so the system knows where B.dll is.
Now I am wondering how window do that.
To Prove windows do it, I have put a Test suite at http://www.njstar.com/zipfile/HookApp.zip
It contains source project and compiled exe in BIN folder.
1. start BIN\App-exe\App.exe first, it's is not linked to DLLA or DLLB.
2. start BIN\HookApp.exe and DLLA and DLLB is linked and loaded.
3. Click BIN\HookApp.exe's menu Inject. it will inject DLLA into BIN\App-exe\App.exe, and
DLLB will also got loaded into BIN\App-exe\App.exe on Windows. This will be fail on Wine.
Are you paid what you're worth? Find out: SEEK Salary Centre
More information about the wine-devel