Stackframe x86 gcc
-
Hallo,
hab mir interessehalber mal den Stack anzeigen lassen wenn foo() die Funktion bar(int) aufruft.
Ich bin den Stack in int32 Schritten zurück gewandert. Einige Dinge konnte ich am Stack wiederfinden, andere Dinge sind mir unklar.
Im Output habe ich die unklaren Dinge mit einem Fragezeichen versehen. Vielleicht kann mir jemand auf die Sprünge helfen, was was ist.Test C Programm:
void bar(int a) { int i=0xDD; // Stackmarkierung int *pInt=&i; // Stack 20 mal int32 zurückgehen for(; pInt<(&i+20); ++pInt) printf("\n0x%X --> 0x%X",pInt,*pInt); } void foo() { int ebp=0; asm("movl %%ebp,%0" : "=r"(ebp)); printf("\nebp=0x%X",ebp); printf("\nfoo=0x%X",&foo); int i=0xBB; // Stackmarkierung bar(0xCC); }
Output:
ebp=0xBFE98F78 foo=0x804848E ----- 0xBFE98F38 --> 0xDD // Stackmarkierung 0xBFE98F3C --> 0xBFE98F3C // ? 0xBFE98F40 --> 0xBFE98F54 // ? 0xBFE98F44 --> 0xBFE98F78 // alter ebp 0xBFE98F48 --> 0xBFE98F78 // alter ebp 0xBFE98F4C --> 0x80484C7 // Adresse von foo 0xBFE98F50 --> 0xCC // Übergabewert 0xBFE98F54 --> 0xBFE98F78 // alter ebp 0xBFE98F58 --> 0xBFE98F77 // ? 0xBFE98F5C --> 0x1 // ? 0xBFE98F60 --> 0x0 // ? 0xBFE98F64 --> 0xBFE99000 // ? 0xBFE98F68 --> 0xBB // Stackmarkierung
-
wie wäre es mit dem zugehörigen disassembly?
außerdem an welcher position gilt der stackframe?
-
vbjfhbvycxvy schrieb:
0xBFE98F38 --> 0xDD // Stackmarkierung 0xBFE98F3C --> 0xBFE98F3C // ? 0xBFE98F40 --> 0xBFE98F54 // ? 0xBFE98F44 --> 0xBFE98F78 // alter ebp 0xBFE98F48 --> 0xBFE98F78 // alter ebp 0xBFE98F4C --> 0x80484C7 // Adresse von foo 0xBFE98F50 --> 0xCC // Übergabewert 0xBFE98F54 --> 0xBFE98F78 // alter ebp 0xBFE98F58 --> 0xBFE98F77 // ? 0xBFE98F5C --> 0x1 // ? 0xBFE98F60 --> 0x0 // ? 0xBFE98F64 --> 0xBFE99000 // ? 0xBFE98F68 --> 0xBB // Stackmarkierung
Bei meinem GCC geht das so:
0xDD
pInt
Dummy
Dummy
ebp
Caller (Rücksprungadresse)
arg
printf-Format
printf-Argument
Dummy
Dummy
x_ebp (Variable ebp)
0xBB"Dummy" bedeutet: unbenutzt, Inhalte sind von irgendeinem anderen Stackzugriff (wahrscheinlich foo-printf) übriggeblieben.
viele grüße
ralph
-
danke!