C Programming - Skip

This will give desired output for Windows/Linux x86 Platform with gcc and visual studio 6.0 compilers

int f()
int i;
int *j = &i;
*(j+2) += 7;

int main()
int i=10;
i = 20;

Here the function f() manupulates the return address i.e. where it was supposed to return to main() because the return address(EIP) is pushed, during a function call, into the stack. We computed that, to skip the instruction i=20, we need to increment the EIP by 7 such that the resulting address will point to printf statement.


About this entry