ret指令是否将4加到esp寄存器上?

发布于 2024-10-05 11:06:15 字数 120 浏览 0 评论 0原文

ret 指令是否导致“esp”寄存器增加4?

Does the ret instruction cause "esp" register to be increased by 4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多孤肩上扛 2024-10-12 11:06:15

是的,它执行

pop eip

您可以使用它

mov eax, [esp]
jmp eax

来避免它。

编辑:这正是 ret 所做的。例如,jmp rel_offet只不过是隐藏的add eip, offset,或者jmpabsolute_offsetmov eip,absolute_offset >。当然,处理器处理它们的方式存在差异,但从程序员的角度来看,这就是发生的一切。

此外,还有一种特殊形式的 ret : ret imm8 也会将此 imm8 值添加到 esp :例如 __stdcall< /code> 函数使用它从堆栈中丢弃其参数。更不用说在 16 位模式下使用的 retf 版本,它还会从堆栈中弹出 cs

编辑2:

pop register

意味着:

mov register, [esp]
add esp, 4

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
醉酒的小男人 2024-10-12 11:06:15

是的,因为在堆栈上有(嗯,应该有,请参阅缓冲区溢出)恢复程序执行的地址。所以 ret 的意思是

pop ret_addr           ; pop deletes ret_addr from stack by adding 4 to esp
mov eip, ret_addr

正如

pop eip

鲁斯利克所说

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

pop ret_addr           ; pop deletes ret_addr from stack by adding 4 to esp
mov eip, ret_addr

which is

pop eip

just as ruslik said

病毒体 2024-10-12 11:06:15

是的,当处理器在 32 位保护模式下运行时。在实模式或 16 位保护模式下,RET 执行 POP IP,这将导致 ADD ESP, 2(而不是 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文