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 


Calling GetAsyncKeyState , game ends up crashing

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
aeree
Cheater
Reputation: 3

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Thu Aug 29, 2013 6:07 pm    Post subject: Calling GetAsyncKeyState , game ends up crashing Reply with quote

I tried calling GetAsyncKeyState in counter strike source using auto assembler.
The game just ends up crashing every time.

here is the code

Code:

push eax

    push 58

        call GetAsyncKeyState

    pop eax

pop eax

_________________
1 + 1 =
Back to top
View user's profile Send private message
Geri
Moderator
Reputation: 112

Joined: 05 Feb 2010
Posts: 5627

PostPosted: Thu Aug 29, 2013 6:21 pm    Post subject: Reply with quote

Use pushfd and pushad, popfd and popad. eax is not enough, it is changing other registers and flags too.
_________________
My trainers can be found here: http://www.szemelyesintegracio.hu/cheats

If you are interested in any of my crappy articles/tutorials about CE and game hacking, you can find them here:
http://www.szemelyesintegracio.hu/cheats/41-game-hacking-articles

Don't request cheats or updates.
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Thu Aug 29, 2013 6:22 pm    Post subject: Reply with quote

You have an extra pop eax.

Code:

push eax
    push 58
    call GetAsyncKeyState // __stdcall calling convention so stack cleanup done by the called function
pop eax
Back to top
View user's profile Send private message
aeree
Cheater
Reputation: 3

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Thu Aug 29, 2013 7:09 pm    Post subject: Reply with quote

Geri wrote:
Use pushfd and pushad, popfd and popad. eax is not enough, it is changing other registers and flags too.


Blacknight wrote:
You have an extra pop eax.

Code:

push eax
    push 58
    call GetAsyncKeyState // __stdcall calling convention so stack cleanup done by the called function
pop eax


Thank you both! It seems to work now.

I didnt think that the arguements get popped off the stack once you call the function. now i feel like an idiot :s

_________________
1 + 1 =
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Thu Aug 29, 2013 7:16 pm    Post subject: Reply with quote

fishbone105 wrote:

I didnt think that the arguements get popped off the stack once you call the function. now i feel like an idiot :s


It's not always the case. Sometimes the caller has to clean the stack. It all depends on the calling convention.

Take a look at: http://www.codeproject.com/Articles/1388/Calling-Conventions-Demystified
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 474

Joined: 09 May 2003
Posts: 25956
Location: The netherlands

PostPosted: Thu Aug 29, 2013 8:04 pm    Post subject: Reply with quote

and keep in mind that other registers might have been changed as well. While some registers are required to be restored on return of a function, some are not (e.g ECX if you check that link blacknight posted)
_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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