 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
k4sh Cheater
Reputation: 0
Joined: 01 Mar 2016 Posts: 28
|
Posted: Wed Mar 30, 2016 3:54 pm Post subject: How to 16 byte align rsp |
|
|
I need to call a lua function in a code injected.
The call CE lua function template says that rsp has to be 16 byte aligned prior to call my function.
Here is a portion of my actual code :
| Code: |
...
mov rcx, setnewxyratios
sub rsp,20
call LuaFunctionCall
add rsp,20
...
...
setnewxyratios:
db 'setNewXYRatios',0
|
The only ending is a game crash after LuaFunctionCall has been called. |
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Wed Mar 30, 2016 4:12 pm Post subject: |
|
|
| Code: | push rbp
mov rbp,rsp
sub rsp,20
and rsp,-10 // aligning the stack with the next lowest 16-byte boundary
mov rcx, setnewxyratios
call LuaFunctionCall
mov rsp,rbp
pop rbp
...
...
setnewxyratios:
db 'setNewXYRatios',0 |
and rsp,-10 instruction zeroes the low 4 bits of rsp, which may decrease it (it might reserve an additional 8 bytes if needed) _________________
|
|
| Back to top |
|
 |
k4sh Cheater
Reputation: 0
Joined: 01 Mar 2016 Posts: 28
|
Posted: Fri Apr 01, 2016 12:14 pm Post subject: |
|
|
Again big thank mgr.inz.Player
Now with this code, my game is not crashing anymore :
| Code: |
...
{$lua}
function test()
print('triggered')
end
{$asm}
...
mov rcx,[rax+rdi*8] <== original game code
mov rax,[rcx] <== original game code
push rcx
push rax
push rbp
mov rbp,rsp
sub rsp,20
and rsp,-10 // aligning the stack with the next lowest 16-byte boundary
mov rcx, setnewxyratios
call LuaFunctionCall
mov rsp,rbp
pop rbp
pop rax
pop rcx
...
setnewxyratios:
db 'test',0
|
However, my function test to print the string triggered is never executed as i don't get any lua output.
What could i have done wrong ? |
|
| Back to top |
|
 |
|
|
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
|
|