In an attempt to understand what is happening under this, I make small C programs and then change it and try to understand its objdump output.
Program C:
#include <stdio.h> int function(int a, int b, int c) { printf("%d, %d, %d\n", a,b,c); } int main() { int a; int *ptr; asm("nop"); function(1,2,3); }
The objdump result for the function gives me the following.
080483a4 <function>: 80483a4: 55 push ebp 80483a5: 89 e5 mov ebp,esp 80483a7: 83 ec 08 sub esp,0x8 80483aa: ff 75 10 push DWORD PTR [ebp+16] 80483ad: ff 75 0c push DWORD PTR [ebp+12] 80483b0: ff 75 08 push DWORD PTR [ebp+8] 80483b3: 68 04 85 04 08 push 0x8048504 80483b8: e8 fb fe ff ff call 80482b8 < printf@plt > 80483bd: 83 c4 10 add esp,0x10 80483c0: c9 leave
Note that before calling printf, three DWORD stacks with offsets of 8,16,12 (they must be the function argument in the reverse order) are pushed onto the stack. Later, the hex address is pressed, which should be the address of the format string.
My doubt is
- Instead of directly pushing 3 DWORDS and the format specifier onto the stack, I expected esp to be manually reduced, and after that the values would be pushed onto the stack. How can this behavior be explained?
user277465
source share