谁能帮助我理解这个命令:
mov %esp,%edi
lea 0x10(%edi),%esi
首先将esp
的地址加载到edi
。然后我加载edi+10
的值,这意味着esp+10
的地址到esi
。但这对堆栈意味着什么呢?如果我执行push操作,我在栈上写了4个字节,对吧?如果我在堆栈上跳回10字节,这个点在哪里?
|______| # here?
|______|
|______|
|______|
|______|
|______|
|______|
|___*__| # or at the position of the star?
|______| # 4 Byte
|______| # also 4 Byte long...
|______| <---%edi
您使用的是x86而不是x64,对吗?我要这样假设。
"这对栈意味着什么?"
mov %esp,%edi
lea 0x10(%edi),%esi
这段代码对你的堆栈操作(push
, pop
等)没有影响。这是因为堆栈操作在esp
寄存器上工作,作为堆栈指针。上面的代码没有改变esp
,所以就堆栈而言,没有任何改变。
"如果我执行push操作,我将在堆栈上写入4个字节,对吗?":
不一定。X86支持16位和32位操作数上的推送操作,因此写入堆栈的字节数取决于所推送内容的大小。例如:
push %ax ; will push 2 bytes on the stack (sizeof(ax) == 2)
push %eax ; will push 4 bytes on the stack (sizeof(eax) == 4)
注意,push也用sizeof(op1)
减去esp
。
"如果我在堆栈上跳转10个字节,这一点在哪里?"
esi
上的lea
命令不会改变堆栈指针。
nop ; 10 points back on the stack here
mov %esp,%edi
lea 0x10(%edi),%esi
nop ; will be the exact same location as here.
; relative to esi, this location is (esi - 26)