How to find out the caller from which dll

I currently have a C ++ exe project in which the dynamic loading of N DLLs.

Those DLLs will make calls for functions that are reused inside the exe project.

Now, as part of my exe project, I want to know that callers come from a DLL.

Can this be done using any available Windows API?

+3
source share
4 answers

It depends on your actual purpose. You cannot do this if you expect the DLLs to be malicious (that is, if you expect them to try to trick you). But if it's just for debugging or logging or something like that harmless, you can look at the stack and get the address that the team retwill use to return to the caller, list through the loaded DLLs and check which of them the address is inside.

To get the "return address", you can use _ ReturnAddress built into Visual C ++, and then you can use GetModuleHandleEx , passing in GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESSto get the handle to the DLL where the address is located.

: . "" , "" "" DLL. , - , .

, , , , DLL . , 5 - ....

+4

DLL, , . API , . , DLL.

, , , exe.

: , ?

0

? "GetModuleBaseRoutine"

0

exe, , DLL (. ), , DLL , . DLL, .

, , DLL, , , , DLL exe. , , , DLL , , , .

0

Source: https://habr.com/ru/post/1767304/


All Articles