News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Goasm and messages

Started by SIMO, January 09, 2009, 11:10:18 AM

Previous topic - Next topic

SIMO

Hi Folks,
I've got a problem with WM_MOUSEHOOK  equ WM_USER+6. It equates to 406h message number but does not appear in the message queue when I debug using Goasm. My debugger is PeBrowseDbg. WM_MOUSEHOOK is a private message but it shows 406h as a message in MASM when I debug the file and does the routine. I'm converting a MASM file to Goasm but I can't get the message number to appear. Is there a quirk in  WM_USER+6? 


SIMO

jorgon

Hi SIMO

QuoteIs there a quirk in  WM_USER+6?

No there isn't.

QuoteWM_MOUSEHOOK  equ WM_USER+6
should resolve to 406h - you can check this in the GoAsm list file (use /l switch).

Have you remembered to declare WM_USER as 400h?

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

donkey

Hi SIMO,

The fact that it does not show up in the message queue would tell me that the message is not being sent at all and not that there is a problem with the actual value of the message (since your program obviously compiled without error). I sometimes skip a message or two when translating the IF/THEN/ENDIF blocks from MASM to GoAsm, I suspect thats what happened here, go over the flow of your code paying special attention to the block that actually sends the message, also verify that the window handle of SendMessage is the correct handle for the message queue you are spying. If you like you can post the code here or the affected portions and we can probably help a little more.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

SIMO

Hi Jeremy
I've looked at the list file and it has 406h as the message. The WM_USER is in my "inc" file and it equates to 400h. I've tried the message 406h on it's own but still no luck.

SIMO

donkey

Hi SIMO,

Could you post the code, it would make it easier to debug.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

SIMO

Hi Fella's
Here is the code as well as the Dll and the .rc file

#include simo.inc

;const section
IDD_MAINDLG    equ   101
IDC_CLASSNAME   equ   1000
IDC_HANDLE   equ   1001
IDC_WNDPROC    equ   1002
IDC_HOOK      equ   1004
IDC_EXIT      equ   1005
IDC_STATIC      equ   -1
WM_MOUSEHOOK    equ WM_USER+6
;==========================================================================================
                           DATA SECTION 
rect RECT
export hInst   DD 0                        ;handle to the process itself
HookFlag    dd FALSE
HookText    db "&Hook",0
UnhookText    db "&Unhook",0
template    db "%lx",0
;===========================================================================================
                           CODE section 
START:
   INVOKE GetModuleHandleA,0     ;get handle to the process   
   MOV [hInst],eax
   
   invoke DialogBoxParamA,[hInst],IDD_MAINDLG,NULL,addr DlgFunc,0
    invoke ExitProcess,0
;====================================================================================
DlgFunc frame hDlg,uMsg,wParam,lParam      
local buffer [80h]:b,buffer1 [80h]:b      

   mov eax,[uMsg]             ;get message
   cmp eax,WM_CLOSE         ;10h wm_close
   jnz >L1      
   cmp d[HookFlag],TRUE
   jnz >fini
   call  UninstallHook
fini:
   invoke EndDialog,[hDlg],0
   jmp >>.return
;==============================================
L1:   
   cmp eax,WM_INITDIALOG    ;message110h
   jnz >WMH               
   invoke GetWindowRect,[hDlg],addr rect
   invoke SetWindowPos,[hDlg],HWND_TOPMOST,[rect.left],[rect.top],[rect.right],[rect.bottom],SWP_SHOWWINDOW      
   jmp >>.return
WMH:         
cmp eax,WM_MOUSEHOOK        ;message 406
jnz >>L22      

      invoke GetDlgItemTextA,[hDlg],IDC_HANDLE,[buffer1],80h
      invoke wsprintfA,ADDR buffer,addr template,[wParam]
      invoke lstrcmpiA,addr buffer,addr buffer1
      
L3:
cmp eax,!0
jnz >L4      
      invoke SetDlgItemTextA,[hDlg],IDC_HANDLE,addr buffer
L4:
      invoke GetDlgItemTextA,[hDlg],IDC_CLASSNAME,addr buffer1,80h
      invoke GetClassNameA,[wParam],addr buffer,80h
      invoke lstrcmpiA,addr buffer,addr buffer1
cmp eax,!0
jnz >L5
      invoke SetDlgItemTextA,[hDlg],IDC_CLASSNAME,addr buffer
L5:
      invoke GetDlgItemTextA,[hDlg],IDC_WNDPROC,addr buffer1,80h
      invoke GetClassLongA,[hDlg],GCL_WNDPROC
      invoke wsprintfA,addr buffer,addr template,eax
      invoke lstrcmpi,addr buffer,addr buffer1
cmp eax,!0
jnz >>.return      
      invoke SetDlgItemTextA,[hDlg],IDC_WNDPROC,addr buffer
jmp >>.return
;===========================================
L22:
cmp eax,WM_COMMAND       ;message 111h
jnz >>.false         
cmp d[lParam],!0
jz >>.return      
mov eax,[wParam]
         mov edx,eax
         shr edx,16
         cmp dx,BN_CLICKED
         jnz >>.return

cmp ax,IDC_EXIT
jnz >L11
invoke SendMessageA,[hDlg],WM_CLOSE,0,0   
;==============================================
L11:
cmp d[HookFlag],FALSE   
jnz >L12
   invoke InstallHook,[hDlg]      ;call InstallHook
cmp eax,!0
jz >.return
   mov d[HookFlag],TRUE
   invoke SetDlgItemTextA,[hDlg],IDC_HOOK,addr UnhookText
jmp >.return

L12:
   call UninstallHook      
   invoke SetDlgItemTextA,[hDlg],IDC_HOOK,addr HookText
   mov d[HookFlag],FALSE
   invoke SetDlgItemTextA,[hDlg],IDC_CLASSNAME,NULL
   invoke SetDlgItemTextA,[hDlg],IDC_HANDLE,NULL
   invoke SetDlgItemTextA,[hDlg],IDC_WNDPROC,NULL
jmp >.return
.false      
xor eax,eax
ret
endf
.return      
mov eax,1
ret
endf

;===============================================================
The Dll code.

#include simo.inc
export MouseProc,InstallHook,UninstallHook
data section
hHook dd 0
Hookdll dd 0
hWnd dd 0
code section
main:
   invoke GetModuleHandleA, "mhook.dll"
   mov [Hookdll],eax
    mov  eax,TRUE
ret
MouseProc frame nCode,wParam,lParam
   invoke CallNextHookEx,[hHook],[nCode],[wParam],[lParam]
   mov edx,[lParam]

   invoke WindowFromPoint,[edx],[edx+4]
   invoke PostMessageA,[hWnd],WM_MOUSEHOOK,eax,0
   xor eax,eax
   ret
endf

InstallHook:
   invoke SetWindowsHookExA,WH_MOUSE,addr MouseProc,[Hookdll],NULL
   mov [hHook],eax
   ret


UninstallHook:
   invoke UnhookWindowsHookEx,[hHook]
   ret
;==============================================================================
The .rc code

#define IDD_MAINDLG                     101
#define IDC_CLASSNAME                   1000
#define IDC_HANDLE                      1001
#define IDC_WNDPROC                     1002
#define IDC_HOOK                        1004
#define IDC_EXIT                        1005
#define IDC_STATIC                      -1
#define DS_MODALFRAME                   0x80
#define WS_POPUP                        0x80000000
#define WS_CAPTION                      0xC00000
#define WS_SYSMENU                      0x80000
#define ES_AUTOHSCROLL                  0x80
#define ES_READONLY                     0x800

IDD_MAINDLG DIALOG   0,0,229,80         
STYLE  DS_MODALFRAME  | WS_CAPTION | WS_SYSMENU   | WS_POPUP
CAPTION "I SHOULD COCO"
FONT 8, "MS Sans Serif"
BEGIN
    GROUPBOX        "Window Information",IDC_STATIC,7,7,214,67
    LTEXT           "Class name:",IDC_STATIC,21,22,39,8
    EDITTEXT        IDC_CLASSNAME,69,20,139,12,ES_AUTOHSCROLL | ES_READONLY
    LTEXT           "Handle:",IDC_STATIC,33,37,26,8
    EDITTEXT        IDC_HANDLE,69,36,77,12,ES_AUTOHSCROLL | ES_READONLY
    LTEXT           "Window Proc:",IDC_STATIC,13,52,46,8
    EDITTEXT        IDC_WNDPROC,69,51,77,12,ES_AUTOHSCROLL | ES_READONLY
    DEFPUSHBUTTON   "&Hook",IDC_HOOK,159,35,50,14
    PUSHBUTTON      "E&xit",IDC_EXIT,159,50,50,14
END

Thanks fella's

SIMO



MichaelW

Among other problems, in your DLL code you are passing PostMessageA a hWnd value of zero. I think you should be passing the handle of your dialog window. I don't know what MASM example you are converting, but in Iczelion's Tutorial 24 this handle is passed to the DLL InstallHook procedure and stored in the uninitialized data section. And if your goal is a system-wide hook, there is another non-obvious detail to be dealt with. The full tutorial is available here.
eschew obfuscation