ret
指令会使"esp"寄存器增加4吗?
是的,它执行。
pop eip
你可以使用
标签来呈现代码。mov eax, [esp]
jmp eax
为了避免这种情况。
编辑:这就是ret
的作用。例如,jmp rel_offet
实际上就是一个隐藏的add eip,offset
,或者jmp absolute_offset
实际上就是mov eip,absolute_offset
。当然,处理器处理它们的方式有所不同,但从程序员的角度来看,这就是发生的所有事情。
此外,还有一种特殊形式的ret
:ret imm8
,它还将这个imm8值添加到esp
中:例如__stdcall
函数使用它来从堆栈中丢弃其参数。更不用说在16位模式下使用的retf
版本,它还从堆栈中弹出cs
。
编辑2:
pop register
意思是:
mov register, [esp]
add esp, 4
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
这是
pop eip
是的,当处理器运行在32位保护模式下时。在实模式或16位保护模式下,RET会执行POP IP指令,这将导致ADD ESP,2(而不是4)。
jmp target_of_jump
是直接修改 eip 的方法(因为mov eip, target_of_jump
不起作用)。有关 Intel 64 和 IA32 汇编的详细信息,我建议阅读 "Intel® 64 and IA-32 Architectures Software Developer's Manual":http://www.intel.com/products/processor/manuals/顺便说一句:除非我在 ARM 处理器上弄错了,否则你可以直接读写程序计数器(它在那里是寄存器 15)。 - Nubok