Hello! today I bring you a doubt about c++ asm and the stack
since I couldn't find the anwer in google.
Let's assume I have a function in c++
Code:
void foo(){
//do something
}
this function will be comiled into a asm function like this
0 //some code
1 //some code
2 //some code
3 //some code
4 //some code
5 //some code
6 ret
My question is: c++ compiler gives me the warranty that the STACK in 0 will be exactly as the stack in 6?
(I will not use any asm instruction so discard human errors like pushing something without poping it later)
If I'm not wrong ret instruction returns to the firt element of the stack and then it pops it, right?
So the stack should be the same in 0 and 6?
This is to hook a function, but Tibia freezes so I think Im not seting the values back to the registers properly.
So Im thinking in doing something like this:
1) find some free bytes in the program memory
2) make a function like this:
Code:
push ebp
push esp
push edi
push esi
call foo
pop esi
pop edi
pop esp
pop ebp
push ebp
mov esp, ebp
push -1
ret
Note: the last 3 instructions before the ret are the ones I relplaced with the call to this function in the original function
3)
replace this code in the original function with a call to my asm function
Code:
push ebp
mov esp, ebp
push -1
What do you think about this method?
There is any error/miss concept I'm doing?
Thanks for your feedback!