2019-2020-1 20199316 "Linux kernel principle and Analysis" in the second week of work

How a computer works

Anti compile a C program

experiment procedure

  • First view directories, and compiling main.c file in the shell environment

  • main.c code is as follows:

// main.c
int g(int x)
{
    return x + 3;
}

int f(int x)
{
    return g(x);
}

int main(void)
{
    return f(8) + 1;
}
  • Then, enter the following line of code on the platform decompile

gcc -s -o main.s main.c -m32
  • Then, when I turn on the anti-eds file full of joy - -

  • What is this? This code is not what I want ah! You wrong studio it ......
  • Closer to home, wait for me to check out their own small mistakes, and finally innocuous to decompile the code to get out, really is not easy - -

experiment analysis

  • pushl% ebp, will push ebp register. Next, the address register points esp minus 4, i.e., a downward movement.
  • movl% esp,% ebp, esp position within the meaning assigned to ebp.
  • subl $ 4,% esp, esp Decrement register 4, and a plus value of eip.
  • movl $ 8, (% esp), placed in the 8 position pointed esp.
  • Call f, the value of eip to overwhelm the stack, then the first instruction of the function f pusjl% ebp eip placed in position.
  • pushl% ebp (meaning as above)
  • Here I'll repeat the instructions omitted friends

  • leave, revocation main function of the stack.
  • ret, ebp and esp back to the initial state.

Guess you like

Origin www.cnblogs.com/destiny-love/p/11567621.html