Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Doesn anybody know if such code example exists?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Sat Aug 13, 2011 1:37 pm    Post subject: Doesn anybody know if such code example exists? Reply with quote

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
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Aug 13, 2011 5:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Aug 14, 2011 1:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Aug 14, 2011 4:14 am    Post subject: Reply with quote

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
View user's profile Send private message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Sun Aug 14, 2011 10:45 am    Post subject: Reply with quote

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
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sun Aug 14, 2011 1:03 pm    Post subject: Reply with quote

SetwindowLong() from what HWND the form or from the listview?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Aug 14, 2011 3:20 pm    Post subject: Reply with quote

EM_SETSEL is not received by the window procedure of the parent, but of the edit control itself.
Back to top
View user's profile Send private message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Mon Aug 15, 2011 9:14 am    Post subject: Reply with quote

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. Sad
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 15, 2011 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Mon Aug 15, 2011 4:17 pm    Post subject: Reply with quote

If you have done it before, could you give me your code as example to learn please?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 15, 2011 4:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites