Text 在程序集中显示某些文本后,ESP和EIP不正确
又是我,有同样的问题。所以,这次我创建了一个小函数,它将在控制台上显示一些文本。在堆栈上推送2个参数,调用函数,查看文本并返回。代码如下:Text 在程序集中显示某些文本后,ESP和EIP不正确,text,assembly,console,stack,access-violation,Text,Assembly,Console,Stack,Access Violation,又是我,有同样的问题。所以,这次我创建了一个小函数,它将在控制台上显示一些文本。在堆栈上推送2个参数,调用函数,查看文本并返回。代码如下: start: push dword MyText ; Pointer to the variable from the .data section push dword 26 ; Number of characters to write call ShowText ret ShowText: push ebp
start:
push dword MyText ; Pointer to the variable from the .data section
push dword 26 ; Number of characters to write
call ShowText
ret
ShowText:
push ebp
mov ebp, esp
push 0
push WrittenChars ; Pointer to the variable from the .bss section
push dword [ebp + 8] ; Number of characters to write
push dword [ebp + 12] ; MyText
push dword [StdHandle] ; Value of StdHandle, from the .bss section
call WriteConsoleA
pop ebp
ret
[section .data]
MyText db 'Abcdefghijklmnopqrstuvxzw', 0Ah
因此,
WriteConsoleA
会推送和检索正确的值,文本显示正确,但我仍然收到访问冲突错误,因此在显示消息后,ESP看起来是错误的。我以为WriteConsoleA
会清除堆栈中的参数,我不知道会发生什么。ShowText
没有pascal调用转换,因此在这种情况下,您必须自己调整堆栈
call ShowText
add esp, 08
嗯,我想WriteConsoleA会做的(
retn 14
或其他什么)是的,这是pascal调用Conversion,但对您自己的函数的调用没有它。看看我的答案,WriteConsoleA会清除堆栈,但在您自己的函数调用ShowText
中您没有。WriteConsoleA
应该删除它的参数。。。但是ShowText
没有!在通话结束后执行ShowText
的ret 8
或add esp 8
。它应该可以工作,但不能工作。在writeconolea代码块内,ESP在某个点(ntdll.77434DFE,我看到pop esi
指令)变成00000000,这就是问题所在。所以,它甚至没有返回到我的模块