2012-05-27 27 views
0

該方案如下:應用程序對DLL所做的截取函數調用

可以說我有這個應用程序「應用程序」,依賴於這個庫「library.dll」。我想知道函數調用「App」在運行時的功能。假設我沒有訪問「App」或「library.dll」的源代碼,但我知道存在的每個函數的名稱和參數都是「library.dll」。有什麼辦法可以找到「library.dll」中的哪些函數被「App」調用?

我看到了一個計算器類似的問題:How to intercept dll method calls?

的回答我的阿泰古拉爾先生吸引了我,他提書面方式轉發函數調用到真正的DLL一個wrapperDLL。我希望有人能夠向我提供一些見解,告訴我如何實現這一目標,或者指向一個我可以從中獲得有關信息的地方。

兩個部分,我最感興趣的是有我的應用程序加載我.dll和如何實際轉發功能原有的「library.dll」

謝謝

+0

Google for「dll wrapper generator」。一年前在Perl中,但不記得名字。我確定還有其他人。 – dgnorton

回答

4

的包裝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; 
} 

導出功能,命名結果DLL library.dll重命名原來的以renamed_library.dll

現在的目標EXE將加載(你)library.dll,這反過來將加載後(原件,但改名)renamed_library.dll - 每當目標程序調用一個函數,它將運行你的登錄代碼。

警告:您的traget EXE可能是多線程的,因此請準備好線程安全的日誌記錄機制。

我已成功使用此方法調試一個奇怪的MAPI問題。

+0

這正是我正在尋找的。您爲我的項目給了我一個很好的起點,我感謝您的幫助。 –

相關問題