我仍然经常迷失与堆栈相关的操作,在这种情况下,问题是RET指令,它为eip寄存器弹出错误的地址。我使用NASM,我的代码如下所示:
start:
call GiveMeAHandler
call GetCommandLine
ret
GiveMeAHandler:
push ebp
mov ebp, esp
push edi
push esi
push dword -11
call dword [F_GetStdHandle] ; It executes correctly and returns
mov [StdHandler], eax ; StdHandler is stored in BSS
add esp, 4
pop esi
pop edi
pop ebp
ret ; This returns to some weird address
GetCommandLine:
; ...
; I don't get here because the function above wrong return
也许我对推送和弹出有点夸大了ebp, edi, esi
(它们毕竟没有改变),但即使我删除它们,ret
指令仍然返回错误的地址(77AE7094)而不是0040100A,我在这里调用第二个函数。