注册 登录
编程论坛 汇编论坛

钩子键盘消息的保存

逆鳞雪狮 发布于 2015-10-12 23:15, 4093 次点击
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sample code for < Win32ASM Programming 4th Edition>
; by 罗云彬, luoyunbin@
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Main.asm
; 键盘钩子演示程序的主程序,调用 dll 装载键盘钩子
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff Main.asm
; rc Main.rc
; Link  /subsystem:windows Main.obj Main.res
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .386
        .model flat, stdcall
        option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include        windows.inc
include        user32.inc
includelib    user32.lib
include        kernel32.inc
includelib    kernel32.lib
include        Hookdll.inc
includelib    Hookdll.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN    equ    1000
DLG_MAIN    equ    1000
IDC_TEXT    equ    1001
WM_HOOK        equ    WM_USER + 100h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  .data
szaa db '8.txt',0
da  dd 0
da1 dd 0

        .code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain    proc    uses ebx edi esi hWnd,wMsg,wParam,lParam
        local    @dwTemp
        
        local  @szcc [1000]:byte
        mov    eax,wMsg
;********************************************************************
        .if    eax ==    WM_CLOSE
            invoke    UninstallHook
            invoke    EndDialog,hWnd,NULL
;********************************************************************
        .elseif    eax ==    WM_INITDIALOG
            invoke    InstallHook,hWnd,WM_HOOK
            
            
               mov da,eax            
            .if    ! eax
                invoke    EndDialog,hWnd,NULL
               
            .endif

;********************************************************************
        .elseif    eax ==    WM_HOOK
            mov    eax,wParam
            .if    al == 0dh
                mov    eax,0a0dh
            .endif
            mov    @dwTemp,eax
            invoke    SendDlgItemMessage,hWnd,IDC_TEXT,EM_REPLACESEL,0,addr @dwTemp
            invoke    CreateFile,addr szaa,GENERIC_WRITE,FILE_SHARE_READ,\
               0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
            
            mov da1,eax
            invoke WriteFile,da1,addr @dwTemp ,sizeof @dwTemp,addr @szcc,0
            invoke FlushFileBuffers,da1
        .else
            mov    eax,FALSE
            ret
        .endif
        mov    eax,TRUE
        ret

_ProcDlgMain    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
        invoke    GetModuleHandle,NULL
        invoke    DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
        invoke    ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        end    start

我想把键盘钩子勾到消息保存在自己建的文件里面,可是文件正常建立了,就是里面没有内容,
1 回复
#2
hu9jj2015-10-13 07:39
HK啊
1