| View previous topic :: View next topic |
| Author |
Message |
aeree Cheater
Reputation: 3
Joined: 23 Jan 2010 Posts: 42 Location: Germany
|
Posted: Thu Aug 29, 2013 6:07 pm Post subject: Calling GetAsyncKeyState , game ends up crashing |
|
|
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 |
|
 |
Geri Moderator
Reputation: 112
Joined: 05 Feb 2010 Posts: 5627
|
Posted: Thu Aug 29, 2013 6:21 pm Post subject: |
|
|
Use pushfd and pushad, popfd and popad. eax is not enough, it is changing other registers and flags too.
_________________
|
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu Aug 29, 2013 6:22 pm Post subject: |
|
|
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 |
|
 |
aeree Cheater
Reputation: 3
Joined: 23 Jan 2010 Posts: 42 Location: Germany
|
Posted: Thu Aug 29, 2013 7:09 pm Post subject: |
|
|
| 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 |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu Aug 29, 2013 7:16 pm Post subject: |
|
|
| 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 |
|
 |
Dark Byte Site Admin
Reputation: 474
Joined: 09 May 2003 Posts: 25956 Location: The netherlands
|
Posted: Thu Aug 29, 2013 8:04 pm Post subject: |
|
|
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 |
|
 |
|