本程序的目的是用A程序监控B程序(目标程序),当B程序的BUTTON按下时被HOOK 住WH_CALLWNDPROC,
现在的问题是A程序运行后,启动B程序(当A程序运行后第一次运行B程序)按下B程序的BUTTON,成功被HOOK,然后退出B程序(A程序继续运行但不要点击A的界面),再次启动B,按下BUTTON 这一次HOOK失败,然后B退出。然后只要随便点击A的界面后,再次启动B,HOOK成功,,当B关闭后,如不点击A的界面,刚B启动后HOOK还是失败,如随便点A的界面断续HOOK成功,实在头痛。请高手指教。
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;main.asm 为主文件。(为源程序即为A程序)
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include qqweiba.inc
includelib qqweiba.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN equ 1000
DLG_MAIN equ 1000
IDC_START equ 1001
IDC_EXIT equ 1002
ID_MYTIMER equ 1003
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
dwBool dd ?
hFind dd ?
hDLGTract dd ?
.const
szStop db '停止',0
szStart db '开始',0
szTitle db '翻班查询表测试版',0
szButtonClass db 'Button',0
szButtonName db '查询',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
local @dwThreadID,@dwBool
mov eax,wMsg
;********************************************************************
.if eax == WM_TIMER
invoke IsWindow,hDLGTract
.if !eax
mov hDLGTract,NULL
invoke InstallHook,NULL
invoke FindWindow,NULL,addr szTitle
.if eax
mov hDLGTract,eax
invoke InstallHook,hDLGTract
.endif
.endif
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDC_EXIT
invoke UninstallHook
invoke KillTimer,hWinMain,ID_MYTIMER
invoke EndDialog,hWnd,NULL
.elseif ax == IDC_START
.if dwBool
invoke SetDlgItemText,hWnd,IDC_START,addr szStart
mov dwBool,FALSE
invoke KillTimer,hWinMain,ID_MYTIMER
.else
invoke SetDlgItemText,hWnd,IDC_START,addr szStop
mov dwBool,TRUE
invoke SetTimer,hWinMain,ID_MYTIMER, 1000, NULL
.endif
.endif
;********************************************************************
.elseif eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
;********************************************************************
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
mov dwBool,FALSE
mov hDLGTract,NULL
;********************************************************************
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
;qqweiba.asm (即DLL)
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
.data?
hInstance dd ?
dwThreadId dd ?
@dw dd ?
@dw2 dd ?
hKey dd ?
hRichEdit dd ?
@szBuffer db 256 dup(?)
.data
hProc dd ?
.const
szFormat db 'fdgwsdfgsfdgsfdgsfdgsfdgsfdgsdfgsfdgfsdgdfsgsfdgsdfg:%dhhhhhhh%d',0
szTextHttp db '欢迎来我的小站坐坐:http://titilima.nease.net',0
.code
DllEntry proc _hInstance,_dwReason,_dwReserved
push _hInstance
pop hInstance
mov eax,TRUE
ret
DllEntry Endp
_ErrorExit proc
local @szbuf[80]:BYTE
local @lpMsgBuf
;local @dw
;local @szBuffer[256]:BYTE
invoke GetLastError
mov @dw,eax
;invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS ,NULL,@dw ,0,addr @lpMsgBuf,0,NULL
invoke wsprintf,addr @szBuffer,addr szFormat,@dw,hInstance
invoke MessageBox,NULL,addr @szBuffer,NULL,MB_OK
;invoke LocalFree,@lpMsgBuf
;invoke ExitProcess,@dw
ret
_ErrorExit endp
CallWndProc proc _nCode, _wParam, _lParam
invoke CallNextHookEx,hProc,_nCode,_wParam,_lParam
mov edx,_lParam
assume edx:ptr CWPSTRUCT
.if [edx].message==WM_COMMAND && [edx].wParam==1008
invoke MessageBox,NULL,addr szTextHttp,NULL,MB_OK
.endif
assume edx:nothing
ret
CallWndProc endp
InstallHook proc _hDlg
mov eax,_hDlg
.if eax
invoke GetWindowThreadProcessId,eax,NULL
mov dwThreadId,eax
.else
invoke UnhookWindowsHookEx,hProc
mov hProc,NULL
mov eax,FALSE
ret
.endif
invoke SetWindowsHookEx,WH_CALLWNDPROC, addr CallWndProc, hInstance, dwThreadId
.if !eax
invoke _ErrorExit
invoke MessageBeep,MB_YESNO
xor eax,eax
ret
;.endif
.endif
mov hProc,eax
ret
InstallHook endp
UninstallHook proc
invoke UnhookWindowsHookEx,hProc
ret
UninstallHook endp
END DllEntry
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!