This is why arguments are preempted in reverse order in a C call, for example:
If you call:
printf("%s %s", foo, bar);
The stack ends like this:
... +-------------------+ | bar | +-------------------+ | foo | +-------------------+ | "%s %s" | +-------------------+ | return address | +-------------------+ | old frame pointer | <- frame pointer +-------------------+ ...
The arguments are indirectly related to its offset from the frame pointer (the frame pointer can be omitted by intelligent compilers that can calculate things from the stack pointer). The first argument is always at a well-known address in this scheme; the function accesses the set of arguments that its first arguments talk about.
Try the following:
printf("%x %x %x %x %x %x\n");
This will delete part of the stack.
ninjalj
source share