简体   繁体   中英

C++ function hook

I have the source code for a DLL. The compiled DLL gets loaded by an application. The application loads several other DLL's, too. I have disassembled asm code from the application and all DLL's, but I have only the source code from the one DLL. The app and all DLL's are one process.

I want to program a function hook inside the DLL I have the source code from. I want to hook functions from the other DLL's. The hooked functions should be called by all other DLL's and the application and my compiled DLL(the original functions shouldn't be called).

The problem is, I cannot hook one DLL directly, because it's not an own process. Somehow I have to hook the DLL's, which are loaded to the application. How to do that?

For reference, I cannot hook a function with an offset from one DLL, because the function is inside the memory of the app and not in the memory of the DLL process itself!

For reference, I cannot hook a function with an offset from one DLL, because the function is inside the memory of the app and not in the memory of the DLL process itself!

When a DLL is loaded by a process, it gets loaded into that process's address space. The DLL does not have its own process. If you would like to hook a function in a DLL running in a remote process, you could inject a DLL of your own into the remote process. Now your injected DLL shares the address space of the target process, and your target DLL. From within your own DLL code, you can make calls to API's such as GetModuleHandle to get the base address of your target DLL, and handle all hooking code from within your DLL, because your code is running not in "your" app, but in theirs, as if they loaded it themselves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM