flat assembler
Message board for the users of flat assembler.
Index
> Windows > proper way to sub class a MessageBox created by ..... |
Author |
|
sleepsleep 23 Mar 2007, 01:45
i just coded using the following method.
it works, but ... just i don't feel it is bug free.... make a dll hook the WH_CBT detect the HCBT_ACTIVATE event lstrcmp the msgbox title if title matched, use SetWindowLong subclass that msgbox check for WM_COMMAND , BN_CLICKED shl 16 or 6 if yes, then use GetDlgItem,[hwnd],0xFFFF to get the handle then the text of the static control. lstrcmp with the one we want. then finally we know the user click Yes. |
|||
23 Mar 2007, 01:45 |
|
sleepsleep 23 Mar 2007, 18:09
hi,
just wish to know, is that safe to use SetWindowsHookEx on dllmain DLL_PROCESS_ATTACH and UnhookWindowsHookEx on DLL_PROCESS_DETACH ? |
|||
23 Mar 2007, 18:09 |
|
hidden 23 Mar 2007, 20:18
sleepsleep wrote: hi, |
|||
23 Mar 2007, 20:18 |
|
sleepsleep 24 Mar 2007, 03:34
thank hidden,
i end up using a cbtHookCounter, whenever a DLL_PROCESS_ATTACH detected, it adds 1. If it is 0, it would SetWindowsHookEx, so counter starts from -1 if DLL_PROCESS_DETACH found, and counter shows 0, it would call UnhookWindowsHookEx. something like below Code: proc dllmain hinstDLL, fdwReason, lpvReserved cmp [fdwReason],DLL_PROCESS_ATTACH je .pattach cmp [fdwReason],DLL_PROCESS_DETACH je .pdettach ret .pdettach: dec [cbtHookCounter] cmp [cbtHookCounter],0 jne .exit invoke OutputDebugString,r1 invoke UnhookWindowsHookEx,[cbtHookH] ret .pattach: push [hinstDLL] pop [dllH] inc [cbtHookCounter] cmp [cbtHookCounter],0 jne .exit invoke OutputDebugString,r2 invoke SetWindowsHookEx,WH_CBT,cbtHookProc,[hinstDLL],0 mov [cbtHookH],eax .exit: mov eax,TRUE ret endp |
|||
24 Mar 2007, 03:34 |
|
LocoDelAssembly 24 Mar 2007, 03:47
Both "cmp [cbtHookCounter],0" can be removed without loosing current functionality.
|
|||
24 Mar 2007, 03:47 |
|
hidden 24 Mar 2007, 04:24
Where do you store cbtHookCounter? Do you know, that if you're hooking another process, your module will be loaded second time into that prosess' addressing apace and this variable won't be available?
Why don't you just do like shown in MSDN example? http://msdn2.microsoft.com/en-us/library/ms644960.aspx It's much more easy. Or if you don't want application initialize hooking, check which application loaded this module by GetModuleFileName PS You're using system debugger, right? OutputDebugString at MSDN wrote: If the application has no debugger, the system debugger displays the string. If the application has no debugger and the system debugger is not active, OutputDebugString does nothing. |
|||
24 Mar 2007, 04:24 |
|
sleepsleep 24 Mar 2007, 04:50
yo yo LocoDelAssembly & hidden
i store the cbtHookCounter on .sdata shareable readable writeable section. this dll is actually coded to fix a missing feature in another software. and i don't know what is that application name too, the sort of guide line given by my friend or client is, i should write the missing feature whenever i detect a pops up of this message box and when user clicks yes. wat i got is, the messagebox title and its static control text... thats all . yeap, i am using the debugview to dump the debug string :p http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx well, i did monitored some debug message sent by another application |
|||
24 Mar 2007, 04:50 |
|
hidden 24 Mar 2007, 05:31
But you know name of your program, and you need to set up hook only if your program attach this dll otherwise do nothing.
Quote: i store the cbtHookCounter on .sdata shareable readable writeable section. |
|||
24 Mar 2007, 05:31 |
|
sleepsleep 24 Mar 2007, 15:31
okie, the GetModuleFileName seems like a more easier way to deal things.
but it returns eg. "C:\somefolder\desktop\myapp.exe" and etc that come prefixed with "C:\watever\watever\thenonly\theapp.exe" is there an easy to get only the application name? no need path and drive prefix? |
|||
24 Mar 2007, 15:31 |
|
sleepsleep 24 Mar 2007, 15:52
while, code an ugly way of doing things
Code: .processdetach: invoke GetModuleHandle,NULL invoke GetModuleFileName,eax,modBuff,MAX_PATH cmp eax,0 je @f add eax,modBuff .repeatcheck: dec eax cmp byte [eax],"\" jne .repeatcheck invoke OutputDebugString,eax |
|||
24 Mar 2007, 15:52 |
|
hidden 25 Mar 2007, 03:31
Actually, I don't think it's an ugly way, you can also compare in the same time and stop comparing when you found "\"
Also you can use StrRChr to get "\myapp.exe" from "C:\somefolder\desktop\myapp.exe" and then compare them by StrCmpI, but for this you need "shlwapi.dll" and another buffer for the filename, but I wouldn't use them. |
|||
25 Mar 2007, 03:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.