| View previous topic :: View next topic |
| Author |
Message |
rain-13 Expert Cheater
Reputation: 0
Joined: 18 Mar 2009 Posts: 110
|
Posted: Sat Aug 13, 2011 1:37 pm Post subject: Doesn anybody know if such code example exists? |
|
|
I am looking for code example that would hook window control messages in target process.
My goal is to make injectable DLL that allows me to block given window messages.
I have tried to breakpoint GetMessageW and GetMessageA, but for some reason it CE doesn't pause explorer.exe when I drag icon on desktop. Which means I cant use code that just hooks function.
I also cant use SetWindowsHookEx because this doesn't allow me to manipulate with messages
Edit: I looked into SetWindowLong but it doesnt seem to be able to capture messages sent by users. I mean that if I send message EM_SETSEL by using SendMessageW then it works but when user selects text it doesn't work.
Edit2: Is that EM_SETSEL actually made of WM_LBUTTONDOWN + $WM_LBUTTONDOWN ?
|
|
| Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Sat Aug 13, 2011 5:19 pm Post subject: |
|
|
You could hook the WNDPROC from your target process.
or
Use SetWindowLong() to one of your WNDPROC and handle the shit there.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Aug 14, 2011 1:30 am Post subject: |
|
|
| NoMercy wrote: | You could hook the WNDPROC from your target process.
or
Use SetWindowLong() to one of your WNDPROC and handle the shit there. |
Just a heads up, use SetWindowLongPtr instead, SetWindowLong is depreciated.
_________________
- Retired. |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 14, 2011 4:14 am Post subject: |
|
|
| SetWindowsHookEx does allow you to manipulate message. Use WH_CALLWNDPROC. Check if nCode is greater or equal to 0 and if you don't want it to continue in the call chain then call CallNextHookEx
|
|
| Back to top |
|
 |
rain-13 Expert Cheater
Reputation: 0
Joined: 18 Mar 2009 Posts: 110
|
Posted: Sun Aug 14, 2011 10:45 am Post subject: |
|
|
Thanks for info, I'll try this out. I tried to play with SetWindowLong . Problem I had was that it only reacts if i call SendMessageW but it when I manually mark text, then it doesn't receive EM_SETSEL.
I think (but not sure) that it receives it as mousedown + mousemove
|
|
| Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Sun Aug 14, 2011 1:03 pm Post subject: |
|
|
| SetwindowLong() from what HWND the form or from the listview?
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 14, 2011 3:20 pm Post subject: |
|
|
| EM_SETSEL is not received by the window procedure of the parent, but of the edit control itself.
|
|
| Back to top |
|
 |
rain-13 Expert Cheater
Reputation: 0
Joined: 18 Mar 2009 Posts: 110
|
Posted: Mon Aug 15, 2011 9:14 am Post subject: |
|
|
Here's simple code I have:
note that _WinAPI_SetWindowLong($edit, $GWL_WNDPROC, $pHook)
Problem is that it reacts to clicks but not EM_SETSEL but SetWindowLong is used with edit control. At this point it's made like Slugsnack said. Does anyone got suggestions about that code?
| Code: | #include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
Opt("GUICloseOnESC", 0)
$hForm = GUICreate('', 400, 400)
$hHook = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr')
$pHook = DllCallbackGetPtr($hHook)
$edit = _GUICtrlEdit_Create($hForm, "some text", 10, 10, 300, 100);create edit control
$hProc = _WinAPI_SetWindowLong($edit, $GWL_WNDPROC, $pHook);SetWindowLong for edit control
GUISetState()
$btndown = False;variable
Do;keep gui running
Until GUIGetMsg() = $GUI_EVENT_CLOSE
ProcessClose(@AutoItPID)
_WinAPI_SetWindowLong($edit, $GWL_WNDPROC, $hProc)
DllCallbackFree($hProc)
Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
Local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
Local $hDC, $hSv, $oldMsg
Select
Case $iMsg = $EM_SETSEL
ConsoleWrite($EM_SETSEL & @LF)
Return 0
Case $iMsg = $WM_LBUTTONDOWN
$btndown = True
ConsoleWrite($WM_LBUTTONDOWN & @LF)
Case $iMsg = $WM_LBUTTONUP
$btndown = True
ConsoleWrite($WM_LBUTTONUP & @LF)
Case $iMsg = $WM_MOUSEMOVE
If $btndown Then
ConsoleWrite("Drag" & @LF)
$btndown = False
Return 0
EndIf
EndSelect
Return $Res
EndFunc ;==>_WinProc |
WH_CALLWNDPROC just monitors messages but doesnt allow manipulate with them.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Mon Aug 15, 2011 3:31 pm Post subject: |
|
|
| I don't know what language that is. WH_CALLWNDPROC does allow you to manipulate messages. Just don't call the next hook in the chain. I've done it before.
|
|
| Back to top |
|
 |
rain-13 Expert Cheater
Reputation: 0
Joined: 18 Mar 2009 Posts: 110
|
Posted: Mon Aug 15, 2011 4:17 pm Post subject: |
|
|
| If you have done it before, could you give me your code as example to learn please?
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Mon Aug 15, 2011 4:40 pm Post subject: |
|
|
| Code: | LRESULT CALLBACK CallWndProc( int nCode, WPARAM wParam, LPARAM lParam ) {
if( nCode < 0 ) {
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
CWPSTRUCT* pCWP = ( CWPSTRUCT* )lParam;
switch( pCWP -> message ) {
case SOME_MESSAGE: {
...
return MyReturnVal;
}
default:
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
} |
Put that in a DLL and export it with a .def or use __declspec(dllexport). The SetWindowsHookEx call is trivial
|
|
| Back to top |
|
 |
|