What process is calling LoadLibrary

220 views Asked by At

I'm developing a dll and I need to know some information of the process where it will be attached to, to take desitions whether I hook calls to some functions or not. For instance, if process is explorer.exe I don't want to do anything of that, just when the process is firefox.exe. To set up global hooks I use the "AppInit_DLLs infrastructure" so the Operating System is who calls LoadLibrary, not the process explicitely. The hook process take place in DllMain, so there is where I need the information.

Thank in advance.

1

There are 1 answers

0
GuidedHacking On

To get the file of the process which is loading your DLL you can use GetModuleFileName:

char szExeFileName[MAX_PATH];
GetModuleFileName(NULL, szExeFileName, MAX_PATH);