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 


C++ PostMessageX crashing

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

Joined: 08 Nov 2007
Posts: 198

PostPosted: Wed Aug 20, 2008 6:21 am    Post subject: C++ PostMessageX crashing Reply with quote

Code:

DWORD PMA = (DWORD)GetProcAddress(LoadLibrary("USER32.DLL"), "PostMessageA")+5;

_declspec(naked) BOOL PostMessageX(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
   _asm {
      mov edi, edi
      push ebp
      mov ebp, esp
      jmp[PMA]
  }
}

//Shitloads of useless code
HWND h = FindWindow( "MapleStoryClass", NULL );
while (  bAtkON )
{
UINT pewram;
LPARAM lparam;
   pewram = MapVirtualKey( 0xA2, 0 );

   lparam = ( pewram << 16 ) + 1;

PostMessageX( h, WM_KEYDOWN, 0xA2, lparam );
Sleep( 1000 );
PostMessageX( h, WM_KEYUP, 0xA2, lparam );
Sleep( 1000 );
}


It attacks about 17 times before crashing...
I have tested on:
Notepad (Different keys)
a Maple private server (Same keys and different keys... no difference)

Yes, I am using an injected DLL with AllocConsole()...
Yes, the loop is in a new thread...


Last edited by Wintermoot on Wed Aug 20, 2008 6:47 am; edited 1 time in total
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Wed Aug 20, 2008 6:27 am    Post subject: Reply with quote

Use pewram as your wParam
Back to top
View user's profile Send private message
Wintermoot
Expert Cheater
Reputation: 0

Joined: 08 Nov 2007
Posts: 198

PostPosted: Wed Aug 20, 2008 6:50 am    Post subject: Reply with quote

Code:

HWND h = FindWindow( "MapleStoryClass", NULL );
UINT pewram;
LPARAM lparam;
   pewram = MapVirtualKey( 0xA2, 0 );

   lparam = ( pewram << 16 ) + 1;

PostMessageX( h, WM_KEYDOWN, pewram, lparam );
Sleep( 1000 );
PostMessageX( h, WM_KEYUP, pewram, lparam );
Sleep( 1000 );

Attacks 17 times and crashes while finishing the 18th...
*bets that it is my compiler because MSVC++ 2008 Express = evil*
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Wed Aug 20, 2008 6:56 am    Post subject: Reply with quote

It attacks 17 times?

Hmm

Code:

HWND h = FindWindow( "MapleStoryClass", NULL );
UINT pewram = MapVirtualKey( 0xA2, 0 );

PostMessageX( h, WM_KEYDOWN, pewram, pewram << 16 );
PostMessageX( h, WM_KEYUP, pewram,  pewram << 16 );
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Aug 20, 2008 7:41 am    Post subject: Reply with quote

Stack Overflow.
Quote:
while ( bAtkON )
{
UINT pewram;
LPARAM lparam;

pewram = MapVirtualKey( 0xA2, 0 );

lparam = ( pewram << 16 ) + 1;

PostMessageX( h, WM_KEYDOWN, 0xA2, lparam );
Sleep( 1000 );
PostMessageX( h, WM_KEYUP, 0xA2, lparam );
Sleep( 1000 );
}


By the way, there's no point of sending WM_KEYUP message, you can remove it.
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Wed Aug 20, 2008 8:26 pm    Post subject: Reply with quote

Symbol wrote:
Stack Overflow.
Quote:
while ( bAtkON )
{
UINT pewram;
LPARAM lparam;

pewram = MapVirtualKey( 0xA2, 0 );

lparam = ( pewram << 16 ) + 1;

PostMessageX( h, WM_KEYDOWN, 0xA2, lparam );
Sleep( 1000 );
PostMessageX( h, WM_KEYUP, 0xA2, lparam );
Sleep( 1000 );
}


By the way, there's no point of sending WM_KEYUP message, you can remove it.


You're partially correct. Look at his function prototype:
Code:

_declspec(naked) BOOL PostMessageX(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)


He forgot WINAPI or __stdcall. The function doesn't clean up the stack and stack overflows. It's not the loop variables that are causing it. It's the PostMessageX function.
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Thu Aug 21, 2008 12:19 am    Post subject: Reply with quote

i think it's

jmp[PMA]

with that you are getting the address of PMA variable

just

jmp PMA

should work.. since PMA holds the address where to jump!

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Thu Aug 21, 2008 12:25 am    Post subject: Reply with quote

Its what Symbol and rapion said. The stack is over flowing because he did not label it __stdcall. Its just a silly mistake thats all. But also putting those variable declarations inside the while loop; it doesn't make it any easier on your computer.
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Thu Aug 21, 2008 12:27 am    Post subject: Reply with quote

pkedpker wrote:
i think it's

jmp[PMA]

with that you are getting the address of PMA variable

just

jmp PMA

should work.. since PMA holds the address where to jump!

The compiler ignores the brackets if you didn't specify the size, and you can also simple do:
Code:
mov eax,dword ptr ds:[PostMessageA]
add eax,5
jmp eax
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Thu Aug 21, 2008 12:40 am    Post subject: Reply with quote

Right

Code:


__declspec(naked) BOOL WINAPI PostMessageX(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
   __asm
   {
      mov  edi, edi
      push ebp
      mov  ebp, esp
      jmp dword ptr ds:[PMA]
   }
}


_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Thu Aug 21, 2008 12:43 am    Post subject: Reply with quote

i don't like using hookhop. it tends to mess up ur real keyboard input sometimes and BSOD.

use callwindowproc instead. no need to modify USER32 or other dll

Code:
CallWindowProc(WndProc, hWnd, uMsg, wParam, lParam);
[/code]
_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Back to top
View user's profile Send private message
Wintermoot
Expert Cheater
Reputation: 0

Joined: 08 Nov 2007
Posts: 198

PostPosted: Fri Aug 22, 2008 8:28 am    Post subject: Reply with quote

Thank you x0r. That is a much nicer method.

Everyone else, I solved it after seeing rapion's post but, I forgot to post... Thank you all for helping though.
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