方案如下:
让我说我有这个应用程序"应用程序",依赖于这个库"library.dll".我想知道"App"在运行时调用的函数.假设我无法访问"App"或"library.dll"的源代码,但我知道存在的每个函数的名称和参数都是"library.dll".有什么方法可以找出"app.dll"调用"library.dll"中的哪些函数?
我在stackoverflow中看到了类似的问题:如何拦截dll方法调用?
答案我的Ates Goral先生引起了我的兴趣,他提到写一个wrapperDLL,它将函数调用转发给真正的DLL.我希望有人可以向我提供一些有关如何实现这一点的见解,或者指出我可以获得有关此事的信息的地方.
我最感兴趣的两个部分是让我的应用程序加载我的.dll以及如何将函数实际转发到原始的"library.dll"
谢谢
包装器DLL工作完美 - 这是它的工作原理:
让我们假设,library.dll导出int somefunct(int i, void* o)- 你现在创建自己的DLL,类似于
#include <windows.h>
//Declare this for every function prototype
typedef int (*int_f_int_pvoid)(int,void*);
//Declare this for every function
int_f_int_pvoid lib_somefunct
//this snipplet goes into dllmain
...
HINSTANCE hlibdll = LoadLibrary("X:\PATH\TO\renamed_library.dll");
//For every function
lib_somefunct=(int_f_int_pvoid)GetProcAddress(hlibdll,"somefunct");
...
//Again for every function
int somefunct(int i, void* o)
{
//Log the function call and parameters
//...
//Call library.dll
int result=lib_somefunct(i, o);
//Log the result
//...
return result;
}
Run Code Online (Sandbox Code Playgroud)
导出您的函数,library.dll在将原始文件重命名为之后命名生成的DLLrenamed_library.dll
现在目标EXE将加载(你的)library.dll,然后加载(原始,但重命名)renamed_library.dll- 每当目标程序调用一个函数时,它将运行你的登录代码.
警告:您的traget EXE可能是多线程的,因此请准备好具有线程安全的日志记录机制.
我已成功使用此方法来调试奇怪的MAPI问题.