Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:

Local hook

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Local hook (oprava)

Autor: bhj

20:33:24 29.06.2011

Dobrý den, jediné co potřebuji je někomu poslat něco on to otevře a mě bude chodit na e mail to co on stiskne za klávesy co proto mám udělat ? děkuji.

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: VojtaVitasek

7:49:11 05.09.2008

j.h Napsal:
-------------------------------------------------------
> Takze mate 2 moznosti:
> 1) pouzit WH_KEYBOARD a KeyBoardHook mit v
> samostatne dll, s tim ze budete muset resit
> predavani dat mezi touto dll a samotnym programem
> 2) pouzit WH_KEYBOARD_LL, kde funkce KeyBoardHook
> nemusi byt v dll knihovne, ale tento typ haku je
> mozne pozit pouze globalne (to znamena pro vsechny
> vlakna v systemu, ThreadID musi byt 0), takze u
> kazde zpracovavane zpravy musite rozlisit, jestli
> patri oknu ktere vas zajima

Udelal jsem to podle druhe moznosti a funguje bezproblemu. Dekuji tedy za radu. Pochopitelne dekuji i panu Valerianovi za ukazku.

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: JiriValerian

17:45:24 04.09.2008

Níže je upravená verze toho příkladu [b]globálního[/b] háku [b]WH_KEYBOARD_LL[/b].
Přiklad je [b]Win32 konzolovka[/b]. Otestováno ve [b]Windows XP Professional SP3[/b]
a je to plně funkční.

Všimněte si, že v proceduře háku viz [b]KeyEvent[/b] je testována existence
okna cizí aplikace v daném případě je to [b]Notepad[/b]. Vy si to nahraďte
názvem třídy hlavního okna Vámi požadované aplikace a máte to ;).

[size=14px][code][color=#0000FF]#include[/color] [color=#800080][/color]
[color=#0000FF]#include[/color] [color=#800080][/color]
[color=#0000FF]#include[/color] [color=#800080][/color]
[color=#0000FF]#include[/color] [color=#800080][/color]
[color=#0000FF]#include[/color] [color=#800080][/color]

[color=#0000FF]#ifndef[/color] WH_KEYBOARD_LL
[color=#0000FF]#define[/color] WH_KEYBOARD_LL [color=#0000FF]13[/color]
[color=#0000FF]typedef[/color] [color=#0000FF]struct[/color] tagKBDLLHOOKSTRUCT [color=#800000]{[/color]
DWORD vkCode[color=#800000];[/color]
DWORD scanCode[color=#800000];[/color]
DWORD flags[color=#800000];[/color]
DWORD time[color=#800000];[/color]
DWORD dwExtraInfo[color=#800000];[/color]
[color=#800000]}[/color] KBDLLHOOKSTRUCT[color=#800000],[/color] FAR [color=#800000]*[/color]LPKBDLLHOOKSTRUCT[color=#800000],[/color] [color=#800000]*[/color]PKBDLLHOOKSTRUCT[color=#800000];[/color]
[color=#0000FF]#endif[/color]

[color=#0000FF]static[/color] [color=#0000FF]char[/color] StartPath[color=#800000][[/color][color=#0000FF]500[/color][color=#800000]][/color][color=#800000];[/color]

HHOOK hKeyHook [color=#800000]=[/color] NULL[color=#800000];[/color]

[color=#0000FF]typedef[/color] HWND [color=#800000]([/color]WINAPI [color=#800000]*[/color] PFGCW[color=#800000])[/color][color=#800000]([/color][color=#0000FF]void[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]static[/color] PFGCW GetConWnd[color=#800000];[/color]

LRESULT CALLBACK KeyEvent [color=#800000]([/color][color=#0000FF]int[/color] nCode[color=#800000],[/color] WPARAM wParam[color=#800000],[/color] LPARAM lParam[color=#800000])[/color]
[color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color][color=#800000]([/color]nCode [color=#800000]=[/color][color=#800000]=[/color] HC_ACTION[color=#800000])[/color] [color=#800000]&[/color][color=#800000]&[/color] [color=#800000]([/color][color=#800000]([/color]wParam [color=#800000]=[/color][color=#800000]=[/color] WM_SYSKEYDOWN[color=#800000])[/color] [color=#800000]|[/color][color=#800000]|[/color] [color=#800000]([/color]wParam [color=#800000]=[/color][color=#800000]=[/color] WM_KEYDOWN[color=#800000])[/color][color=#800000])[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]lParam[color=#800000])[/color] [color=#800000]{[/color]
KBDLLHOOKSTRUCT hooked [color=#800000]=[/color] [color=#800000]*[/color][color=#800000]([/color][color=#800000]([/color]KBDLLHOOKSTRUCT[color=#800000]*[/color][color=#800000])[/color]lParam[color=#800000])[/color][color=#800000];[/color]
BYTE Buf[color=#800000][[/color][color=#0000FF]100[/color][color=#800000]][/color][color=#800000];[/color]
BOOL Attach [color=#800000]=[/color] FALSE[color=#800000];[/color]
[color=#0000FF]char[/color] Msg[color=#800000][[/color][color=#0000FF]200[/color][color=#800000]][/color][color=#800000];[/color]
BYTE Status[color=#800000][[/color][color=#0000FF]256[/color][color=#800000]][/color][color=#800000];[/color]
[color=#0000FF]int[/color] Ret[color=#800000];[/color]
HKL hKl [color=#800000]=[/color] NULL[color=#800000];[/color]
DWORD dwProcessId[color=#800000];[/color]
DWORD dwThreadId [color=#800000]=[/color] [color=#0000FF]0[/color][color=#800000];[/color]
HWND hWnd [color=#800000]=[/color] GetForegroundWindow[color=#800000]([/color][color=#800000])[/color][color=#800000];[/color]
ZeroMemory[color=#800000]([/color]Msg[color=#800000],[/color][color=#0000FF]sizeof[/color][color=#800000]([/color]Msg[color=#800000])[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hWnd[color=#800000])[/color] [color=#800000]{[/color]
HWND hWndCiziApp [color=#800000]=[/color] FindWindow[color=#800000]([/color][color=#800080]"Notepad"[/color][color=#800000],[/color]NULL[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hWndCiziApp [color=#800000]=[/color][color=#800000]=[/color] hWnd[color=#800000])[/color] [color=#800000]{[/color]
dwThreadId [color=#800000]=[/color] GetWindowThreadProcessId[color=#800000]([/color]hWnd[color=#800000],[/color][color=#800000]&[/color]dwProcessId[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]dwThreadId[color=#800000])[/color] [color=#800000]{[/color]
Attach [color=#800000]=[/color] AttachThreadInput[color=#800000]([/color]GetCurrentThreadId[color=#800000]([/color][color=#800000])[/color][color=#800000],[/color]dwThreadId[color=#800000],[/color]TRUE[color=#800000])[/color][color=#800000];[/color]
hKl [color=#800000]=[/color] GetKeyboardLayout[color=#800000]([/color]dwThreadId[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
ZeroMemory[color=#800000]([/color]Status[color=#800000],[/color][color=#0000FF]sizeof[/color][color=#800000]([/color]Status[color=#800000])[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]GetKeyboardState[color=#800000]([/color]Status[color=#800000])[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hooked[color=#800000].[/color]vkCode [color=#800000]=[/color][color=#800000]=[/color] [color=#800000]([/color]DWORD[color=#800000])[/color][color=#800080]'X'[/color] [color=#800000]&[/color][color=#800000]&[/color] [color=#800000]([/color]Status[color=#800000][[/color]VK_CONTROL[color=#800000]][/color][color=#800000]&[/color][color=#0000FF]0x80[/color][color=#800000])[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
Ret [color=#800000]=[/color] ToAsciiEx[color=#800000]([/color]hooked[color=#800000].[/color]vkCode[color=#800000],[/color]hooked[color=#800000].[/color]scanCode[color=#800000],[/color]Status[color=#800000],[/color][color=#800000]([/color]LPWORD[color=#800000])[/color]Buf[color=#800000],[/color][color=#0000FF]0[/color][color=#800000],[/color]hKl[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Ret [color=#800000]>[/color] [color=#0000FF]0[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Ret [color=#800000]=[/color][color=#800000]=[/color] [color=#0000FF]1[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color] [color=#800000]>[/color] [color=#800000]([/color]BYTE[color=#800000])[/color][color=#0000FF]32[/color][color=#800000])[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d '%c'"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color] [color=#800000]>[/color] [color=#800000]([/color]BYTE[color=#800000])[/color][color=#0000FF]32[/color][color=#800000])[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d '%c'"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Buf[color=#800000][[/color][color=#0000FF]1[/color][color=#800000]][/color] [color=#800000]>[/color] [color=#800000]([/color]BYTE[color=#800000])[/color][color=#0000FF]32[/color][color=#800000])[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d '%c'"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]1[/color][color=#800000]][/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]1[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
wsprintf[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"ASCII: %d"[/color][color=#800000],[/color]Buf[color=#800000][[/color][color=#0000FF]1[/color][color=#800000]][/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Status[color=#800000][[/color]VK_LMENU[color=#800000]][/color][color=#800000]&[/color][color=#0000FF]0x80[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Msg[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color] [color=#800000]{[/color]
lstrcat[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]" + levy ALT"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
lstrcpy[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"levy ALT"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Status[color=#800000][[/color]VK_RMENU[color=#800000]][/color][color=#800000]&[/color][color=#0000FF]0x80[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Msg[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color] [color=#800000]{[/color]
lstrcat[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]" + pravy ALT"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
lstrcpy[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"pravy ALT"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Status[color=#800000][[/color]VK_LCONTROL[color=#800000]][/color][color=#800000]&[/color][color=#0000FF]0x80[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Msg[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color] [color=#800000]{[/color]
lstrcat[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]" + levy CTRL"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
lstrcpy[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"levy CTRL"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Status[color=#800000][[/color]VK_RCONTROL[color=#800000]][/color][color=#800000]&[/color][color=#0000FF]0x80[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Msg[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color] [color=#800000]{[/color]
lstrcat[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]" + pravy CTRL"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
lstrcpy[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"pravy CTRL"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Attach[color=#800000])[/color] AttachThreadInput[color=#800000]([/color]GetCurrentThreadId[color=#800000]([/color][color=#800000])[/color][color=#800000],[/color]dwThreadId[color=#800000],[/color]FALSE[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]Msg[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000])[/color] [color=#800000]{[/color]
lstrcpy[color=#800000]([/color]Msg[color=#800000],[/color][color=#800080]"\n"[/color][color=#800000])[/color][color=#800000];[/color]
printf[color=#800000]([/color]Msg[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hooked[color=#800000].[/color]vkCode [color=#800000]=[/color][color=#800000]=[/color] [color=#800000]([/color]DWORD[color=#800000])[/color][color=#800080]'X'[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]GetAsyncKeyState[color=#800000]([/color]VK_CONTROL[color=#800000])[/color] [color=#800000]&[/color] [color=#800000]([/color]SHORT[color=#800000])[/color][color=#0000FF]0x8000[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]GetConWnd[color=#800000])[/color] [color=#800000]{[/color]
HWND hConsole [color=#800000]=[/color] GetConWnd[color=#800000]([/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hConsole[color=#800000])[/color] [color=#800000]{[/color]
PostMessage[color=#800000]([/color]hConsole[color=#800000],[/color]WM_CLOSE[color=#800000],[/color][color=#0000FF]0[/color][color=#800000],[/color][color=#0000FF]0[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
PostQuitMessage[color=#800000]([/color][color=#0000FF]0[/color][color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]return[/color] CallNextHookEx[color=#800000]([/color]hKeyHook[color=#800000],[/color]nCode[color=#800000],[/color]wParam[color=#800000],[/color]lParam[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]

[color=#0000FF]void[/color] MsgLoop[color=#800000]([/color][color=#0000FF]void[/color][color=#800000])[/color]
[color=#800000]{[/color]
MSG Msg[color=#800000];[/color]
[color=#0000FF]while[/color] [color=#800000]([/color]GetMessage[color=#800000]([/color][color=#800000]&[/color]Msg[color=#800000],[/color]NULL[color=#800000],[/color][color=#0000FF]0[/color][color=#800000],[/color][color=#0000FF]0[/color][color=#800000])[/color][color=#800000])[/color] [color=#800000]{[/color]
TranslateMessage[color=#800000]([/color][color=#800000]&[/color]Msg[color=#800000])[/color][color=#800000];[/color]
DispatchMessage[color=#800000]([/color][color=#800000]&[/color]Msg[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color]

DWORD WINAPI KeyLogger [color=#800000]([/color]LPVOID lpParameter[color=#800000])[/color]
[color=#800000]{[/color]
HINSTANCE hExe [color=#800000]=[/color] GetModuleHandle[color=#800000]([/color]NULL[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hExe[color=#800000])[/color] [color=#800000]{[/color]
hKeyHook [color=#800000]=[/color] SetWindowsHookEx[color=#800000]([/color]WH_KEYBOARD_LL[color=#800000],[/color][color=#800000]([/color]HOOKPROC[color=#800000])[/color]KeyEvent[color=#800000],[/color]hExe[color=#800000],[/color]NULL[color=#800000])[/color][color=#800000];[/color]
MsgLoop[color=#800000]([/color][color=#800000])[/color][color=#800000];[/color]
UnhookWindowsHookEx[color=#800000]([/color]hKeyHook[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]return[/color] [color=#0000FF]0[/color][color=#800000];[/color]
[color=#800000]}[/color]

[color=#0000FF]int[/color] main [color=#800000]([/color][color=#0000FF]int[/color] argc[color=#800000],[/color] [color=#0000FF]char[/color][color=#800000]*[/color][color=#800000]*[/color] argv[color=#800000])[/color]
[color=#800000]{[/color]
HANDLE hThread[color=#800000];[/color]
DWORD dwThread [color=#800000]=[/color] [color=#0000FF]0[/color][color=#800000];[/color]

HMODULE hDll [color=#800000]=[/color] GetModuleHandle[color=#800000]([/color][color=#800080]"Kernel32.dll"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hDll[color=#800000])[/color] [color=#800000]{[/color]
GetConWnd [color=#800000]=[/color] [color=#800000]([/color]PFGCW[color=#800000])[/color]GetProcAddress[color=#800000]([/color]hDll[color=#800000],[/color][color=#800080]"GetConsoleWindow"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]!GetConWnd[color=#800000])[/color] [color=#800000]{[/color]
printf[color=#800000]([/color][color=#800080]"Program vyzaduje minimalne Windows 2000 nebo novejsi!\n"[/color][color=#800000])[/color][color=#800000];[/color]
system[color=#800000]([/color][color=#800080]"PAUSE"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]return[/color] [color=#0000FF]0[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]

[color=#0000FF]if[/color] [color=#800000]([/color]GetModuleFileName[color=#800000]([/color]GetModuleHandle[color=#800000]([/color]NULL[color=#800000])[/color][color=#800000],[/color]StartPath[color=#800000],[/color][color=#0000FF]sizeof[/color][color=#800000]([/color]StartPath[color=#800000])[/color][color=#800000]-[/color][color=#0000FF]2[/color][color=#800000])[/color] [color=#800000]>[/color] [color=#0000FF]0[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]short[/color] i [color=#800000]=[/color] lstrlen[color=#800000]([/color]StartPath[color=#800000])[/color] [color=#800000]-[/color] [color=#0000FF]1[/color][color=#800000];[/color]
[color=#0000FF]for[/color] [color=#800000]([/color][color=#800000];[/color] i [color=#800000]>[/color][color=#800000]=[/color] [color=#0000FF]0[/color][color=#800000];[/color] i[color=#800000]-[/color][color=#800000]-[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]StartPath[color=#800000][[/color]i[color=#800000]][/color] [color=#800000]=[/color][color=#800000]=[/color] [color=#800080]'\\'[/color][color=#800000])[/color] [color=#800000]{[/color]
StartPath[color=#800000][[/color]i [color=#800000]+[/color] [color=#0000FF]1[/color][color=#800000]][/color] [color=#800000]=[/color] [color=#0000FF]0[/color][color=#800000];[/color]
[color=#0000FF]break[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]

hThread [color=#800000]=[/color] CreateThread[color=#800000]([/color]NULL[color=#800000],[/color]NULL[color=#800000],[/color]
[color=#800000]([/color]LPTHREAD_START_ROUTINE[color=#800000])[/color]KeyLogger[color=#800000],[/color]
[color=#800000]([/color]LPVOID[color=#800000])[/color]argv[color=#800000][[/color][color=#0000FF]0[/color][color=#800000]][/color][color=#800000],[/color]NULL[color=#800000],[/color][color=#800000]&[/color]dwThread[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hThread[color=#800000])[/color] [color=#800000]{[/color]
printf[color=#800000]([/color][color=#800080]"Konec programu (CTRL+X)\n"[/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]return[/color] WaitForSingleObject[color=#800000]([/color]hThread[color=#800000],[/color]INFINITE[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#0000FF]return[/color] [color=#0000FF]0[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[/code][/size]

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: j.h

16:44:17 04.09.2008

Zkuste pouzit WH_KEYBOARD misto WH_KEYBOARD_LL, protoze na [url]http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx[/url] pisou toto:

[quote]
WH_KEYBOARD Thread or global
WH_KEYBOARD_LL Global only
[/quote]

A kdyz hakujete jiny, nez vlastni proces, musi byt funkce KeyBoardHook v samostatne dll, jinak to nebude funkgovat (ale to uz tu myslim padlo). A handle te dll pak musite predat v tretim parametru funkce SetWindowsHookEx. Toto ale neplati pri pouziti WH_KEYBOARD_LL.

Takze mate 2 moznosti:
1) pouzit WH_KEYBOARD a KeyBoardHook mit v samostatne dll, s tim ze budete muset resit predavani dat mezi touto dll a samotnym programem
2) pouzit WH_KEYBOARD_LL, kde funkce KeyBoardHook nemusi byt v dll knihovne, ale tento typ haku je mozne pozit pouze globalne (to znamena pro vsechny vlakna v systemu, ThreadID musi byt 0), takze u kazde zpracovavane zpravy musite rozlisit, jestli patri oknu ktere vas zajima

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: JiriValerian

16:34:10 04.09.2008

[color=#008000]VojtaVitasek Napsal:
-------------------------------------------------------
> Zkusil jsem tedy toto a stale nic:ThreadID :=
> GetWindowThreadProcessId(FindWindow('TTOTAL_CMD',
> nil));
> CurrentHook := SetWindowsHookEx(WH_KEYBOARD_LL,
> @KeyBoardHook, 0, ThreadID);[/color]

Win API funkce [b]GetWindowThreadProcessId[/b] nemá jeden, ale dva parametry
a také si nejprve otestujte zda [b]FindWindow[/b] nevrátí [b]nil[/b] a zda [b]ThreadID[/b] neni [b]0[/b]
a v předposledním parametru funkce [b]SetWindowsHookEx[/b] nepředávejte nulu,
ale handle exáče tj. návratovou hodnotu [b]GetModuleHandle(nil)[/b] zhruba takto:

[size=14px][code]hWndCiziApp [color=#800000]:[/color][color=#800000]=[/color] FindWindow[color=#800000]([/color][color=#800080]'TTOTAL_CMD'[/color][color=#800000],[/color] nil[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hWndCiziApp [color=#800000]<[/color][color=#800000]>[/color] nil[color=#800000])[/color] [color=#800000]{[/color]
ThreadID [color=#800000]:[/color][color=#800000]=[/color] GetWindowThreadProcessId[color=#800000]([/color]hWndCiziApp[color=#800000],[/color] nil[color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]ThreadID [color=#800000]<[/color][color=#800000]>[/color] [color=#0000FF]0[/color][color=#800000])[/color] [color=#800000]{[/color]
CurrentHook [color=#800000]:[/color][color=#800000]=[/color] SetWindowsHookEx[color=#800000]([/color]WH_KEYBOARD_LL[color=#800000],[/color] @KeyBoardHook[color=#800000],[/color] GetModuleHandle[color=#800000]([/color]nil[color=#800000])[/color][color=#800000],[/color] ThreadID[color=#800000])[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
[color=#008000]// ohlasit chybu[/color]
[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color] [color=#0000FF]else[/color] [color=#800000]{[/color]
[color=#008000]// ohlasit chybu[/color]
[color=#800000]}[/color][color=#800000];[/color][/code][/size]

Pokud vše zmíněné uděláte a přesto to nebude fungovat pak to zkuste jako globální viz jen takto: [size=14px][code]CurrentHook [color=#800000]:[/color][color=#800000]=[/color] SetWindowsHookEx[color=#800000]([/color]WH_KEYBOARD_LL[color=#800000],[/color] @KeyBoardHook[color=#800000],[/color] GetModuleHandle[color=#800000]([/color]nil[color=#800000])[/color][color=#800000],[/color] nil[color=#800000])[/color][color=#800000];[/color][/code][/size]a okno té cizí aplikace testujte až v proceduře háku zhruba takto: [size=14px][code]hWndCiziApp[color=#800000]:[/color] [color=#800000]=[/color] GetForegroundWindow[color=#800000]([/color][color=#800000])[/color][color=#800000];[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hWndCiziApp [color=#800000]<[/color][color=#800000]>[/color] nil[color=#800000])[/color] [color=#800000]{[/color]
[color=#0000FF]if[/color] [color=#800000]([/color]hWndCiziApp [color=#800000]=[/color][color=#800000]=[/color] FindWindow[color=#800000]([/color][color=#800080]'TTOTAL_CMD'[/color][color=#800000],[/color] nil[color=#800000])[/color][color=#800000])[/color] [color=#800000]{[/color]
[color=#008000]// aktuální událost klávesnice monitorovaná hákem [/color]
[color=#008000]// se týká nalezeného okna cizí aplikace[/color]

[color=#800000]}[/color][color=#800000];[/color]
[color=#800000]}[/color][color=#800000];[/color]
[/code][/size]

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: VojtaVitasek

13:05:44 04.09.2008

JiriValerian Napsal:
-------------------------------------------------------
> Tohle všechno je komplikované a v daném případě zbytečně
> jelikož existuje nízkoúrovňový hák typu WH_KEYBOARD_LL
> jehož procedura se volá předtím než se událost klávesnice
> vyzvednutá z globální systémové fronty předává aplikaci, která
> má tzv. keyboard focus a navíc systém volá proceduru háku
> v kontextu procesu, který hák zaregistroval a tím pádem
> není potřeba, aby byla procedura háku v DLL a ani není
> potřeba řešit případné předávání dat mezi procesy.


Abych pravdu rekl, tak z te vasi druhe odpovedi moc rozumnej nejsem :( Pisete na me moc komplikovane vety, do kterych jsem se zamotal. Mohl bych vas jeste jednou poprosit o vysvetleni?

Zkusil jsem tedy toto a stale nic:[code]
ThreadID := GetWindowThreadProcessId(FindWindow('TTOTAL_CMD', nil));
CurrentHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyBoardHook, 0, ThreadID);[/code]

Citovat příspěvek

 

Re: Local hook (oprava)

Autor: JiriValerian

12:40:38 04.09.2008

[color=#008000]VojtaVitasek Napsal:
-------------------------------------------------------
> JiriValerian Napsal:
> --------------------------------------------------
> -----
> > Lokální hák lze použít jen ve vztahu k
> vlastní
> > aplikaci.
>
> Diky, toto je pro mne novinka, kterou jsem se
> nikde nedocetl. Jdu prostudovat globalni haky :)[/color]

[b]About Hooks[/b]
http://msdn.microsoft.com/en-us/library/ms644959(VS.85).aspx

[quote][color=#FF0000][i]...A thread-specific hook procedure is called only in the context
of the associated thread...

...If the application installs a hook procedure for a thread
of a different application, the procedure must be in a DLL...[/i][/color][/quote]

Z výše uvedeného je zřejmé, že k hákování ve vztahu
k vláknu cizího procesu (jiné aplikace) byste musel mít hák
uvnitř DLL vytvořené k tomu účelu a navíc byste musel řešit
případné předávání dat mezi procesy, jelikož ta DLL by byla
namapována do toho cílového procesu a hák by byl volán
v kontextu vlákna toho cizího procesu.

Tohle všechno je komplikované a v daném případě zbytečně
jelikož existuje nízkoúrovňový hák typu WH_KEYBOARD_LL
jehož procedura se volá předtím než se událost klávesnice
vyzvednutá z globální systémové fronty předává aplikaci, která
má tzv. keyboard focus a navíc systém volá proceduru háku
v kontextu procesu, který hák zaregistroval a tím pádem
není potřeba, aby byla procedura háku v DLL a ani není
potřeba řešit případné předávání dat mezi procesy.

Hák WH_KEYBOARD_LL by mělo jít použít i ve vztahu
k jednomu vláknu cizí aplikace tj. zkuste si ten příklad
upravit dle svého a mělo by to fungovat.

Citovat příspěvek

 

Re: Local hook

Autor: VojtaVitasek

12:07:41 04.09.2008

JiriValerian Napsal:
-------------------------------------------------------
> Lokální hák lze použít jen ve vztahu k vlastní
> aplikaci.

Diky, toto je pro mne novinka, kterou jsem se nikde nedocetl. Jdu prostudovat globalni haky :)

Citovat příspěvek

 

Re: Local hook

Autor: JiriValerian

12:03:55 04.09.2008

[color=#008000]VojtaVitasek Napsal:
-------------------------------------------------------
> Zdravim vespolek,
>
> chci vytvorit lokalni hook na spustenou aplikaci.
> Po googleni jsem sestavil toto:ThreadID :=
> GetWindowThreadProcessId(FindWindow('TTOTAL_CMD',
> nil));
> CurrentHook := SetWindowsHookEx(WH_KEYBOARD,
> @KeyBoardHook, 0, ThreadID);Bohuzel to ale
> nefunfuje, "CurrentHook" je stale nula.
>
> Chtel bych se zeptat, co delam spatne? Pokud
> pouziji misto promenne "ThreadID" funkci
> "GetCurrentThreadID()", hook na vlastni aplikaci
> se povede. Ale na cizi aplikaci (napr. TTOTAL_CMD)
> nikoli. Jen jeste doplnim, ze cizi aplikace
> existuje a ThreadID ma nejakou hodnotu, ale
> netusim jestli spravnou.[/color]

Lokální hák lze použít jen ve vztahu k vlastní aplikaci.
Pro cizí jedině globální v daném případě [b]WH_KEYBOARD_LL[/b],
který je ovšem platný pro všechny tj. v proceduře háku musíte
testovat, které okno je aktivní a podle toho se zařídit
viz odkaz na příklad.

http://forum.builder.cz/read.php?16,2490703,2494928#msg-2494928

Citovat příspěvek

 

Local hook

Autor: VojtaVitasek

11:02:06 04.09.2008

Zdravim vespolek,

chci vytvorit lokalni hook na spustenou aplikaci. Po googleni jsem sestavil toto:[code]
ThreadID := GetWindowThreadProcessId(FindWindow('TTOTAL_CMD', nil));
CurrentHook := SetWindowsHookEx(WH_KEYBOARD, @KeyBoardHook, 0, ThreadID);[/code]Bohuzel to ale nefunfuje, "CurrentHook" je stale nula.

Chtel bych se zeptat, co delam spatne? Pokud pouziji misto promenne "ThreadID" funkci "GetCurrentThreadID()", hook na vlastni aplikaci se povede. Ale na cizi aplikaci (napr. TTOTAL_CMD) nikoli. Jen jeste doplnim, ze cizi aplikace existuje a ThreadID ma nejakou hodnotu, ale netusim jestli spravnou.

Diky za objasneni

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: