2013-07-10 2 views
0

에 다시 텍스트를 표시 한 후 잘못된 ESP 및 EIP가 나옵니다. 그래서 이번에는 콘솔에 텍스트를 표시하는 작은 함수를 만들었습니다. 스택에 2 개의 인자를 넣고, 함수를 호출하고, 텍스트를보고 리턴한다. ESP가 보여주는 후 잘못된 것 같습니다, 그래서동일한 종류의 문제로 조립품

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에 의해 추진되고 검색됩니다 이것은 코드 메시지. 나는 WriteConsoleA이 그 인자들의 스택을 지울 것이라고 생각했는데, 나는 어떻게되는지 모른다.

답변

1

ShowText에는 파스칼 통화 호출이 없으므로이 경우 스택을 직접 조정해야합니다.

call ShowText 
add esp, 08 
+0

글쎄, 나는 WriteConsoleA 그것을 할 것이라고 생각 ('RETN 14' 또는 무언가) – ali

+0

그래, 파스칼 호출 convetion이지만, 자신의 함수 호출이 없습니다. – Devolus

+0

내 대답 좀 봐, WriteConsoleA 스택을 지우지 만, 당신의 함수 호출'ShowText' 당신은하지 않습니다. – Devolus