Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 373 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does the ret instruction add 4 to esp register?

#1
Does the [`ret` instruction][1] cause "esp" register to be increased by 4?


[1]:

[To see links please register here]

Reply

#2
Yes, it performs

pop eip

You can use

mov eax, [esp]
jmp eax

to avoid it.

EDIT: It's exactly what `ret` does. For example, `jmp rel_offet` is nothing than a hidden `add eip, offset`, or `jmp absolute_offset` is `mov eip, absolute_offset`. Sure there are differences in the way the processor treats them, but from programmer's point of view it's all that happens.

Also, there is a special form of `ret` : `ret imm8` that also adds this imm8 value to `esp` : for example a `__stdcall` function uses it to discard its parameters from the stack. Not to mention `retf` version, used in 16bit mode, that also pops the `cs` from the stack.

EDIT2:

pop register

means:

mov register, [esp]
add esp, 4
Reply

#3
yes, because on the stack there is (well, there should be, see buffer overflow) the address to where resume the execution of the program. So ret means
<pre><code>pop ret_addr ; pop deletes ret_addr from stack by adding 4 to esp
mov eip, ret_addr
</pre></code>

which is

pop eip

just as ruslik said
Reply

#4
Yes, when the processor is running in 32-bit protected mode. In Real mode or 16-bit protected mode RET does a POP IP, which will cause an ADD ESP, 2 (instead of 4).
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through