어셈블리 과제 0916 -임기준
.386
.MODEL FLAT
PUBLIC _LINUX
.CODE
_LINUX PROC NEAR32
push ebp
mov ebp, esp
pushfd ; efl 를 스택에 미리 저장
mov ebx, esp ;ebx = esp
add ebx, 8 ;main의 old esp
mov esp, [ebp+8] ;contest 의 시작 주소
add esp, 40 ;contest 의 끝 주소
pushad ; eax, ecx, edx, ebx, esp, ebp, esi, edi
mov eax, [ebp+4] ;eax = eip(return address)
push eax ;eip값을 구조체 멤버 eip에 대입
mov eax, [ebp-4] ;eax = efl
push eax ;efl값을 구조체 멤버 efl에 대입
add esp, 24 ;구조체멤버 ebx에 점프
push ebx ;old esp값을 구조체 멤버 esp에 대입
mov eax, [ebp] ;eax = old ebp
push eax ;old ebp값을 구조체 멤버 ebp에 대입
mov esp, ebp
pop ebp
ret
_LINUX ENDP
END
#include <stdio.h>
typedef struct _contest
{
int efl;
int eip;
int edi;
int esi;
int ebp;
int esp;
int ebx;
int edx;
int ecx;
int eax;
} contest;
void LINUX(contest *);
void printReg(contest *stpReg);
int main ()
{
contest stReg ={0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678};
LINUX(&stReg);
printf ("eax : %d\n", stReg.eax);
printf ("ebx : %d\n", stReg.ebx);
printf ("ecx : %d\n", stReg.ecx);
printf ("edx : %d\n", stReg.edx);
printf ("esp : %d\n", stReg.esp);
printReg(&stReg);
return 0;
}
void printReg(contest *stpReg)
{
printf ("EAX VALUE : 0x%08X ECX VALUE : 0x%08X\n", stpReg->eax, stpReg->ecx);
printf ("EDX VALUE : 0x%08X EBX VALUE : 0x%08X\n", stpReg->edx, stpReg->ebx);
printf ("ESP ADDRESS VALUE : 0x%08X EBP ADDRESS VALUE : 0x%08X\n", stpReg->esp, stpReg->ebp);
printf ("ESI ADDRESS VALUE : 0x%08X EDI ADDRESS VALUE : 0x%08X\n", stpReg->esi, stpReg->edi);
printf ("EIP ADDRESS VALUE : 0x%08X EFL ADDRESS VALUE : 0x%08X\n", stpReg->eip, stpReg->efl);
return;
}