library FindNextFileHook;
uses
Windows, SysUtils;
var
Hook: hHook;
FNCode: Pointer;
function Dummy(code: Integer; wparam: wParam; lparam: lParam): LRESULT;
stdcall;
begin
Result := CallNextHookEx(Hook,Code,wparam,lparam);
end;
function MyFindNextFile(hFindFile: THandle;
var lpFindFileData: TWIN32FindData): BOOL;
stdcall;
var CurrFile:
String;
begin
Result := FindNextFileA(hFindFile,lpFindFileData);
CurrFile := PChar(@lpFindFileData.cFileName[0]);
if ExtractFileExt(CurrFile) = '
.txt'
then
MessageBox(0,'
Textdatei gefunden!','
FindNextFileHook',MB_OK);
end;
procedure HookFindNext;
var hProc: THandle;
br: Cardinal;
jmp: Pointer;
begin
GetMem(jmp,6);
hProc := OpenProcess(PROCESS_ALL_ACCESS,false,GetCurrentProcessID);
try
// Auslesen / Sichern
FNCode := VirtualAllocEx(hProc,
nil,6,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
ReadProcessMemory(hProc,@FindNextFile,FNCode,6,br);
// Schreiben
PByte(jmp)^ := $E9;
inc(PByte(jmp));
PCardinal(jmp)^ := Cardinal(@MyFindNextFile) - Cardinal(@FindNextFile) - 5;
inc(PCardinal(jmp));
PByte(jmp)^ := $E9;
dec(PByte(jmp),5);
WriteProcessMemory(hProc,@FindNextFile,jmp,6,br);
finally
FreeMem(jmp);
CloseHandle(hProc);
end;
end;
function InstallHook: Boolean;
stdcall;
begin
Result := False;
if Hook = 0
then
begin
Hook := SetWindowsHookEx(WH_GETMESSAGE,@Dummy,
HInstance,0);
Result := true;
end;
end;
function UninstallHook: Boolean;
stdcall;
begin
Result := UnhookWindowsHookEx(Hook);
Hook := 0;
end;
exports
InstallHook,
UnInstallHook;
begin
HookFindNext;
end.