.386 .MODEL FLAT
PUBLIC _STST ; Store Status PUBLIC _LDST ; Load Status ;PUBLIC _ASKY PUBLIC _MD PUBLIC _MM
.CODE
_STST PROC NEAR32
; Entry Code ) ------------------------------------ PUSH EBP ; establish stack frame MOV EBP,ESP ; -------------------------------------------------
; PUSH EFL pushfd
; Trap Flag set 임의 제거 mov eax, [ebp-4] and eax, 0FFFFFEFFh mov [ebp-4], eax
; &context 위치 가리킴 mov esp, [ebp+8]
; EAX 로 이동 add esp, 40
pushad
; EIP(return Address) 대입 push [ebp+4]
; EFL 대입 push [ebp-4]
; esp 위치 조정 add esp, 24 mov eax, ebp add eax, 8 push eax push [ebp] ; Exit Code ) ------------------------------------ MOV ESP,EBP ; restore ESP if local variables used POP EBP ; restore EBP RET ; return ; ------------------------------------------------
; Store Status _STST ENDP
; Load Status _LDST PROC NEAR32 MOV ESP, [ESP+4] ; CONTEXT 주소로 ESP를 옮김 , ESP = &CONTEXT POPFD ; EFL 을 CPU 로 , EFL = CONTEXT.EFL
POP EAX ; EIP 백업 (EAX Reg 에다가) , EAX = Old EIP MOV EBX, ESP ; EBX 에 ESP 를 백업 , Current ESP Backup MOV ESP, [ESP+12] ; 뽑아왔던 ESP 넣음 , ESP = Old ESP PUSH EAX ; Old EIP 넣음 , SAVE Old EIP
MOV ESP, EBX ; ESP = Current ESP POPAD ; PUSHAD 와 반대순서로 CPU에 올라가고, ESP는 무시
MOV ESP, [ESP-20] ; ESP를 Return Address 로 돌려주기 SUB ESP, 4 RET ; return
_LDST ENDP
; 반환값 넣는 방법 ;_ASKY PROC NEAR32
; Entry Code ) ------------------------------------ ; PUSH EBP ; establish stack frame ; MOV EBP,ESP ; -------------------------------------------------
; MOV EAX, 100 ; 반환값은 EAX에
; Exit Code ) ------------------------------------- ; MOV ESP,EBP ; restore ESP if local variables used ; POP EBP ; restore EBP ; RET ; return ; -------------------------------------------------
;_ASKY ENDP
_MD PROC NEAR32
; Entry Code ) ------------------------------------ PUSH EBP ; establish stack frame MOV EBP,ESP ; ------------------------------------------------- MOV EAX, [EBP+8] ; EAX = &A MOV EAX, [EAX] ; EAX = *(&A) ; Exit Code ) ------------------------------------- MOV ESP,EBP ; restore ESP if local variables used POP EBP ; restore EBP RET ; return ; -------------------------------------------------
_MD ENDP
_MM PROC NEAR32
; Entry Code ) ------------------------------------ PUSH EBP ; establish stack frame MOV EBP,ESP ; ------------------------------------------------- PUSH EBX ; EBX Back up MOV EAX, [EBP+8] ; EAX = &A MOV BL, [EBP+12] ; BL = 0xFF MOV [EAX], BL ; *(&A) = 0xFF POP EBX
; Exit Code ) ------------------------------------- MOV ESP,EBP ; restore ESP if local variables used POP EBP ; restore EBP RET ; return ; -------------------------------------------------
_MM ENDP
END
|