Re: Globaler API-Hook funktioniert nicht
Hi,
Im Moment funktionierts nicht so ganz. Also die Delphi IDE ballert mich dauernd mit ShowMessages zu aber sonst siehts mager aus. Hier mal die ganze DLL (wobei ShowMessage zum Debuggen gedacht ist ;) )
Delphi-Quellcode:
Gruß
library FindNextFileHook;
uses Windows, SysUtils, Dialogs; type TFindNext = function (hFindFile: THandle; var lpFindFileData: TWIN32FindData): BOOL; stdcall; var Hook: hHook; function Dummy(code: Integer; wparam: wParam; lparam: lParam): LRESULT; stdcall; begin Result := CallNextHookEx(Hook,Code,wparam,lparam); end; var FindNextOld: TFindNext = nil; tmp: THandle = INVALID_HANDLE_VALUE; function MyFindNextFile(hFindFile: THandle; var lpFindFileData: TWIN32FindData): BOOL; stdcall; var s: String; begin s := lpFIndFileData.cFileName; if ExtractFileExt(s) = '.txt' then ShowMessage('Erwischt!'); end; function NextHook(var F: TSearchRec): Integer; asm nop nop nop nop nop add FindNextOld,5 jmp FindNextOld end; procedure FindNextHooked; asm push [esp+8] push [esp+8] call nexthook sub FindNextOld,5 jmp MyFindNextFile ret end; procedure HookFindNext; var hProc: THandle; br,old: Cardinal; jmp: Pointer; Sicherung: Pointer; lib: hModule; begin if @FindNextOld = nil then begin Lib := LoadLibrary('kernel32.dll'); FindNextOld := GetProcAddress(lib,'FindNextFileA'); FreeLibrary(lib); end; GetMem(jmp,5); hProc := OpenProcess(PROCESS_ALL_ACCESS,false,GetCurrentProcessID); try // Auslesen / Sichern VirtualProtectEx(hProc,@FindNextOld,5,PAGE_EXECUTE_WRITECOPY,old); GetMem(Sicherung,5); ReadProcessMemory(hProc,@FindNextOld,Sicherung,5,br); WriteProcessMemory(hProc,@NextHook,Sicherung,5,br); // Schreiben PByte(jmp)^ := $E9; inc(PByte(jmp)); PCardinal(jmp)^ := Cardinal(@FindNextHooked) - Cardinal(@FindNextOld) - 5; dec(PByte(jmp)); WriteProcessMemory(hProc,@FindNextOld,jmp,5,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. Neutral General |
Re: Globaler API-Hook funktioniert nicht
Hast du mal probiert, die DLL in ein eigenes Programm zu laden und dann einfach mal durchzusteppen?
|
Re: Globaler API-Hook funktioniert nicht
Hi,
Ich merke gerade, das es in Delphiprogrammen funktioniert. Also in meinem Testprogramm zumindest... Im Explorer funktioniert es allerdings nicht... Kann es sein, dass der Explorer FindNextFileW benutzt? |
Re: Globaler API-Hook funktioniert nicht
Ich bin mir diesbezüglich sogar ziemlich sicher.
|
Re: Globaler API-Hook funktioniert nicht
Neutral General:
Hast du nun versucht, die FindNextFileW zu hooken - bzw hat es funktioniert ? MfG |
Re: Globaler API-Hook funktioniert nicht
Hi,
Ehm das ist schon lange her.. Ich weiß gar nicht :mrgreen: Entweder hab ichs nicht probiert oder es hat nicht funktioniert. Würde ich mal tippen. :stupid: |
Re: Globaler API-Hook funktioniert nicht
Mist :(
Ich versuche auch schon seit ca ner 1/2 h FindFirstFileW zu hooken, nur misslingt mir das Hooken mit der injizierten Dll in Explorer.exe Wäre schon, wenn irgendein andere mir sagen könnte, wie / womit genau Windows die Dateien auflistet / findet. EDIT: Am besten erstell ich nen eigenen Thread dafür :) MfG |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz