DLL loading prolem when injecting into another process
Hongbo Ni
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.
//in A.dll
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");
if(hwnd){
g_hHookGetMsg = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hinstDll,GetWindowThreadProcessId(hwnd, NULL));
if(g_hHookGetMsg){
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
Window process.
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.
Regards
Hongbo
_________________________________________________________________
Are you paid what you're worth? Find out: SEEK Salary Centre
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau%2Fcareer%2Dresources%2Fsalary%2Dcentre%2F%3Ftracking%3Dsk%3Ahet%3Asc%3Anine%3A0%3Ahot%3Atext&_t=764565661&_r=OCT07_endtext_salary&_m=EXT
More information about the wine-devel
mailing list