C++ hooking a dll?

前端 未结 5 1605
我寻月下人不归
我寻月下人不归 2021-02-03 11:26

Is there a quick way to hook a dll in c++? I know there is Microsoft\'s Detours thing, but isn\'t there a quick a simple way just to hook a few dll functions?

For examp

5条回答
  •  执念已碎
    2021-02-03 12:03

    Probably the easiest way is to put your own wrapper DLL with the same name in the directory of the EXE, and put a copy of the hooked DLL in the same directory with a new name. Then, in the IAT of your wrapper DLL, redirect any non-intercepted call to the wrapped DLL (export forwarding), and implement the others yourself.

    To redirect functions, put the following line in your .DEF file: Foo=wrapped_mytestdll.Foo where Foo is the (mangled) function name and wrapped_mytestdll is the new name of the copied DLL.

    As a result, the affected EXE loads your wrapper DLL, and in turn the wrapped DLL. Functions in your wrapper DLL take precedence over the wrapped DLL. The only calls not intercepted are calls by the wrapped DLL to itself, as those don't go through your IAT.

    (I've since found a link to a tool to generate a basic ".DEF" file, but haven't tested it myself. Use at your own risk.)

提交回复
热议问题