?? unithookdll.pas
字號:
unit UnitHookDLL;
interface
uses Windows, Messages, Dialogs, SysUtils;
function OpenGetKeyHook(sender : HWND;MessageID : WORD) : BOOL; export;
function CloseGetKeyHook: BOOL; export;
function LoadLibrary16(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;
procedure FreeLibrary16(HInstance: THandle); stdcall; external kernel32 index 36;
function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;
procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';
var
hInst16: THandle; {}
pFuncCreate,pFuncFree: Pointer; {函數指針}
MessageHook: THandle;
{ QT_Thunk 需要堆棧}
{$StackFrames On}
implementation
function SetGDIHook: boolean;
begin
result:=false;
if pFuncCreate = nil then exit;
asm
{保存寄存器的值}
pushad
push ebp
sub esp,$2c
mov edx, pFuncCreate{函數地址}
mov ebp,esp
add ebp,$2c
call QT_Thunk
add esp,$2c
pop ebp
mov byte ptr result,al
popad
end;
end;
function UnSetGDIHook: boolean;
var
reserve:array[0..$40] of char; //堆棧,一定要在最下!!!
begin
result:=false;
if pFuncCreate = nil then exit;
asm
{保存寄存器的值}
pushad
push ebp
sub esp,$2c
mov edx, pFuncFree{函數地址}
mov ebp,esp
add ebp,$2c
call QT_Thunk
add esp,$2c
pop ebp
mov byte ptr result,al
popad
end;
end;
function GetMsgProc(code: integer; removal: integer; msg: integer): Integer; stdcall;
begin
Result:=0;
end;
function OpenGetKeyHook(sender : HWND;MessageID : WORD) : BOOL; export;
begin
MessageHook:=SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, HInstance, 0);
SetGDIHook;
result:=true;
end;
function CloseGetKeyHook: BOOL; export;
begin
UnSetGDIHook;
UnhookWindowsHookEx(MessageHook);
result:=true;
end;
initialization
pFuncFree:=nil;
pFuncCreate:=nil;
hInst16 := LoadLibrary16('project1.DLL');
if hInst16 >= 32 then
begin
pFuncCreate := GetProcAddress16(hInst16, 'TextHookCreate');
pFuncFree := GetProcAddress16(hInst16, 'TextHookFree');
if (pFuncCreate=nil)or(pFuncFree=nil) then
begin
pFuncCreate:=nil;
pFuncFree:=nil;
end;
end;
finalization
if hInst16 >= 32 then
FreeLibrary16(hInst16);
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -