알 수 없는 사용자
2013. 9. 13. 20:02
어셈블리어 함수(프로시저) C코드에서 호출해 사용하기
- main의 ESP 찾기 |
☞ C 소스
#include <stdio.h>
struct context { int eax; int ebx; int ecx; int edx; int esp; };
void linux(struct context *);
int main() {
int iNum1 = 100; struct context stReg; int iNum2 = 200;
linux(&stReg);
printf("%08X\n", stReg.eax); printf("%08X\n", stReg.ebx); printf("%08X\n", stReg.ecx); printf("%08X\n", stReg.edx); printf("%08X\n", stReg.esp);
return 0;
}
|
☞ 어셈블리어 프로시저(함수)
.386 .MODEL FLAT
PUBLIC _linux .CODE _linux PROC NEAR32
push ebp ; Entry code mov ebp, esp push eax ;레지스터 값 백업 push ebx push ecx push edx
mov eax, esp mov esp, [ebp+8] add esp, 20 ;esp 이동
mov edx, ebp add edx, 12 ;main esp 값 -> edx
push edx ;main esp 값 push
mov edx, eax push [edx]
add edx, 4 push [edx]
add edx, 4 push [edx]
add edx, 4 push [edx]
mov esp, eax ;esp 원래 위치로
pop edx ; 레지스터값 복원 pop ecx pop ebx pop eax mov esp, ebp ; Exit code pop ebp ret
_linux ENDP
END
|


|