This is full code, that's not work!!!
i'm using NASM and ALINK (on Windows 7 32bit Professional)
; nasm -fobj dllHook.asm
; alink -oPE -dll dllHook.obj win32.lib
and
; nasm -fobj Call.asm
; alink -oPE Call.obj
dllHook.asm (dllHook.dll)
global dllstart
export dllstart
global KeyBoardHook
export KeyBoardHook
global SetHook
export SetHook
global hHook
;--------------------------------------------
%include 'win32.inc'
[extern GetModuleHandleA]
[extern SetWindowsHookExA]
[extern CallNextHookEx]
[extern MessageBoxA]
segment data public use32 class=DATA
Module db 'dllHook',0
lpText db 'Key A is Pressed',0
lpCaption db 'Key A',0
lpErrorC db 'Error',0
lpErrorT db 'Cannot Set Hook',0
hHook dd 0
hHandle dd 0
segment .code use32
;DLL entry point - do nothing, but flag success
;This is a STDCALL entrypoint, so remove 3 params from stack on return
..start:
dllstart:
mov eax,1
ret 12
;exported procedure
KeyBoardHook:
%define nCode ebp+8
%define wParam ebp+0Ch
%define lParam ebp+10h
;--------------------------------------
mov eax, [nCode]
cmp eax, 0
je .reCallNextHookEx
cmp eax, HC_ACTION
jne .reCallNextHookEx
xor eax,eax
mov eax, [wParam]
cmp eax, 41h ; if wParam= 'A' then show messagebox
je .MsgBox
jmp .reCallNextHookEx
.MsgBox:
push 0
push dword lpCaption
push dword lpText
push 0
call MessageBoxA
jmp .RetProcHook
.reCallNextHookEx:
push dword [lParam]
push dword [wParam]
push dword [nCode]
push dword [hHook]
call CallNextHookEx
;-----------------------------------------
.RetProcHook:
ret
SetHook:
push dword Module
call GetModuleHandleA
cmp eax, 0
je .notHook
mov [hHandle], eax
push 0
push dword [hHandle]
push dword KeyBoardHook
push WH_KEYBOARD
call SetWindowsHookExA
cmp eax,0
je .notHook
mov [hHook], eax
jmp .RetProcSet
.notHook:
push byte 0
push dword lpErrorC
push dword lpErrorT
push byte 0
call MessageBoxA
.RetProcSet:
ret
;-----------------------------
Call.asm (Call function in dllHook.dll)
extern SetHook
import SetHook dllHook.dll
extern ExitProcess
import ExitProcess kernel32.dll
extern _getch
import _getch msvcrt.dll
segment .data USE32
lpText db 'Hello',0
lpCaption db 'Welcome',0
..start:
;-------------------------------
call [SetHook]
call [_getch]
;-------------------------------
push dword 0
call [ExitProcess]
;-------------------------------