Dried bean curd
Dried bean curd

Reputation: 23

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call

#include<stdio.h>
int a[100];
int main(){
    char UserName[100];
    char *n=UserName;
    char *q=NULL;
    char Serial[200];
    q=Serial;
    scanf("%s",UserName);
//this is about 
    __asm{
        pushad
            mov eax,q
            push eax
            mov eax,n
            push eax
            mov EAX,EAX
            mov EAX,EAX
            CALL G1
            LEA EDX,DWORD PTR SS:[ESP+10H]
        jmp End
G1:
        SUB ESP,400H
            XOR ECX,ECX
            PUSH EBX
            PUSH EBP
            MOV EBP,DWORD PTR SS:[ESP+40CH]
        PUSH ESI
            PUSH EDI
            MOV DL,BYTE PTR SS:[EBP]
        TEST DL,DL
            JE L048
            LEA EDI,DWORD PTR SS:[ESP+10H]
        MOV AL,DL
            MOV ESI,EBP
            SUB EDI,EBP
L014:
        MOV BL,AL
            ADD BL,CL
            XOR BL,AL
            SHL AL,1
            OR BL,AL
            MOV AL,BYTE PTR DS:[ESI+1]
        MOV BYTE PTR DS:[EDI+ESI],BL
            INC ECX
            INC ESI
            TEST AL,AL
            JNZ L014
            TEST DL,DL
            JE L048
            MOV EDI,DWORD PTR SS:[ESP+418H]
        LEA EBX,DWORD PTR SS:[ESP+10H]
        MOV ESI,EBP
            SUB EBX,EBP
L031:
        MOV AL,BYTE PTR DS:[ESI+EBX]
        PUSH EDI
            PUSH EAX
            CALL G2
            MOV AL,BYTE PTR DS:[ESI+1]
        ADD ESP,8
            ADD EDI,2
            INC ESI
            TEST AL,AL
            JNZ L031
            MOV BYTE PTR DS:[EDI],0
            POP EDI
            POP ESI
            POP EBP
            POP EBX
            ADD ESP,400H
            RETN
L048:
        MOV ECX,DWORD PTR SS:[ESP+418H]
        POP EDI
            POP ESI
            POP EBP
            MOV BYTE PTR DS:[ECX],0
            POP EBX
            ADD ESP,400H
            RETN


G2:
        MOVSX ECX,BYTE PTR SS:[ESP+4]
        MOV EAX,ECX
            AND ECX,0FH
            SAR EAX,4
            AND EAX,0FH
            CMP EAX,0AH
            JGE L009
            ADD AL,30H
            JMP L010
L009:
        ADD AL,42H
L010:
        MOV EDX,DWORD PTR SS:[ESP+8]
        CMP ECX,0AH
            MOV BYTE PTR DS:[EDX],AL
            JGE L017
            ADD CL,61H
            MOV BYTE PTR DS:[EDX+1],CL
            RETN
L017:
        ADD CL,45H

            MOV BYTE PTR DS:[EDX+1],CL
            RETN



End:
        mov eax,eax
        popad
    }

    printf("%s\n",Serial);

    return 0;
}

Can you help me? this problem about Asm,I don't know why cause this result. this program is very easy,and it about a program of internal code.

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Upvotes: 2

Views: 1763

Answers (2)

Alex
Alex

Reputation: 10126

Possibly it happens because at the beginning of the function G1 you SUB ESP,400H, after L031 you make ADD ESP,8 and at the end you ADD ESP,400H. It seems like ESP before the G1 call is by 8 less then after call.

EDIT: Regarding to the coding style of assembly function please see this. Here briefly described what are the caller's responsibilities and what are callee's responsibilities, that are regarded to ESP.

Upvotes: 0

Henrik
Henrik

Reputation: 23324

It seems the two parameters which are pushed onto the stack before the call to G1 are never popped from the stack.

Upvotes: 1

Related Questions