On the compilation of the stack

What is the stack

  • During program execution to use a memory
  • Is the heart of the program, all the key data will appear here side
  • Regardless of the stack data structure

Stack View program

Drag and drop in OD, at the command line dd (FS corresponding address) to.
Here Insert Picture Description

  • When a program uses the stack is toward the bottom of the memory, the more memory space is also smaller from the top until the save any time, it will collapse, and this is perhaps a stack overflow it.
  • ESP register is the reaction of the current program usage in the stack, that is telling you to run this step it is being spent in the stack

Stack use of the program

The current program execution to the 19C6EC, we can then use down until the bottom of the program until the image above.
Here Insert Picture Description
Using the remaining stack can use the following commands:

mov DWORD ptr ds:[19C6E4],1  //向目标堆栈中存1
mov DWORD ptr ds:[19C6E0],2  //向目标堆栈中存2

Here Insert Picture Description
Then be sure to tell you to use the stack there, let him keep up with your pace, otherwise the latter will overwrite the contents of your written to the stack, this time need to modify the value of the ESP register, so he is now occupied by pointing stack, if you do not know why change the value of the ESP, you can click here .

Here Insert Picture DescriptionSimilarly, if you do not want to use in the mov or add back ok.

Here Insert Picture Description

It's just two data, if the data is more, one by one is very troublesome to play, this time we use the push and pop instructions instruction.

push instruction (PUSH)

Features:

  • Pushed into the data stack (stack)
  • Modify the value of the ESP register stack pointer (minus 4)

Before us is to modify the value of the stack, and then go to modify the value of the stack pointer ESP, now do not need, we just need to push it, he will complete the first two operations, such as:

push 666  //这里push的是立即数,也可以是寄存器和内存

running result:
Here Insert Picture Description

pop instruction (pop)

Features:

  • The storage stack (stack) memory data to a register or
  • Modify the value of stack pointer ESP (plus 4)

running result:
Here Insert Picture Description

to sum up

  • The push data is pushed into the top of the stack, and the value of the stack pointer ESP -4
  • pop the stack is pushed out to the data register or a memory, and the value of the stack pointer +4 ESP
  • These instructions will generally appear in pairs, front push, later on there will be pop
  • Order of push and pop that last out, LIFO
Published 25 original articles · won praise 29 · views 4207

Guess you like

Origin blog.csdn.net/qq_43573676/article/details/104313857