C/C++ code#include
void whocallme();
void fun1() {
whocallme();
}
void fun2() {
whocallme();
}
void fun3() {
fun1();
}
void whocallme() {
int *_esp,i;
__asm {
mov eax,esp
mov _esp,eax
}
printf("\nfun1,fun2,fun3,_esp=%08x,%08x,%08x,%08x\n",(int)fun1,(int)fun2,(int)fun3,(int)_esp);
for (i=0;i<100;i++) if (_esp[i]==(int)_esp) break;
if (i<100) {
printf("ret addr=%08x\n",_esp[i+2]);
if ((int)fun1<=_esp[i+2] && _esp[i+2]
if ((int)fun2<=_esp[i+2] && _esp[i+2]
}
}
void main() {
fun2();
fun1();
}
//C:\tmp\tmp\Debug>tmp
//
//fun1,fun2,fun3,_esp=00401000,00401020,00401040,0012fe84
//ret addr=0040102e
//fun2 callme
//
//fun1,fun2,fun3,_esp=00401000,00401020,00401040,0012fe84
//ret addr=0040100e
//fun1 callme
//
//C:\tmp\tmp\Debug>cd ..\release
//
//C:\tmp\tmp\Release>tmp
//
//fun1,fun2,fun3,_esp=00401000,0040100a,00401014,0012ff5c
//ret addr=00401012
//fun2 callme
//
//fun1,fun2,fun3,_esp=00401000,0040100a,00401014,0012ff5c
//ret addr=00401008
//fun1 callme
//