HOOK 與 DLL的例項

2021-05-27 22:42:52 字數 1443 閱讀 9301

1.dll建立:

#include

#include

#include

#pragma data_seg("mydata") 

hhook glhhook=null;         //安裝的滑鼠勾子控制代碼  

hinstance glhinstance=null; //dll例項控制代碼 

#pragma data_seg() 

lresult callback keyboardproc(int ncode,wparam wparam,lparam lparam) 

else 

fwrite(&ch, sizeof(char), 1, fl); 

} fclose(fl); 

} return callnexthookex( glhhook, ncode, wparam, lparam );  

} bool winapi dllmain(

hinstance hinstdll,  // handle to dll module

dword fdwreason,     // reason for calling function

lpvoid lpvreserved   // reserved

)bool starthook() 

bool stophook()  

return bresult; } 

2..def檔案建立:

library

exports stophook 

exports starthook

3.主程式建立(基於mfc dialog型別)

初始:_declspec (dllimport) bool starthook();

_declspec (dllimport) bool stophook();

鏈結上述生成的 .dll 檔案

呼叫:直接可以呼叫 .dll 中的函式

4.注意:

一、呼叫方式要一致,防止出現因呼叫方式不同而造成主程式中找不到指定函式;

二、除了上述的靜態鏈結 dll ,也可以用 loadlibrary()等函式動態去鏈結;

三、用#pragma data_seg建立乙個新的資料段並定義共享資料,其具體格式為: 

#pragma data_seg ("shareddata") 

hwnd sharedwnd=null;//共享資料 

#pragma data_seg()   

也可以直接用dll原始碼指定鏈結選項,就像我們在strlib.c那樣(《windows程式設計》教程動態鏈結庫):

#pragma comment(linker,"/section:shared,rws")
這種方法只能在沒有def檔案時使用,如果通過def檔案進行匯出的話,那麼設定就要在def檔案內設定而不能

在**裡設定了。

DLL注入實驗 DLL訊息鉤取HOOK

修改dll實現功能 修改改hookdll.cpp,鉤取對notepad的輸入,使得 a 輸入文字仍能正常顯示 b 所有輸入文字能夠記錄到input.txt檔案中 include windows.h include tchar.h hinstance g hinstance null hhook g ...

注入Hook技術 DLL注入

winnt win2000 winxp中的遠執行緒技術之一 dll注入 什麼是遠執行緒?我們知道用createthread可以在當前程序裡建立乙個執行緒,遠執行緒與此類似,只不過是在其他程序中建立乙個執行緒,用api函式createremotethread。這個遠執行緒建立後就與建立它的程序無關了,...

無需Dll實現的全程滑鼠Hook

該方法能夠監控到form 外面的滑鼠移動情況,無需dll實現 unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls type tform1...