user1881587 user1881587 - 7 months ago 44
C++ Question

Can you get the caller DLL or executable module from the callee

I only want to allow specific DLLs to execute code I have written on a function I hooked. short of performing a stack trace how do you get the module name of your caller?


Get a stack trace to find the return address of your function, for instance with CaptureStackBackTrace.

And then call GetModuleHandleEx passing GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS to obtain the module handle containing that code.

Finally, call GetModuleFileName to find the filename associated with that module.