into the C language function, the system will then do another thing, is the pressure ebp into the stack. And then put the current ESP=>EBP. Low Address ---> +---------+
| ... |
EBP ---> | Old EBP | <---New ESP
| EIP | <---old ESP
| Arg1 |
| Arg2 |
| Arg3 |
| ... |
| Argn |
| ... |
| ... |
High Address---> +---------+
4 How do I get the call Stack for a function?From the previous analysis, we can see that when the function call is complete, the location that EBP points to stores the value before the function call EBP. (ebp+4) is the location of the program's return address (EIP). So through EBP we can constantly get to the position of the last ebp, and we can constantly get the return address of the last program call. Low Address ---> +---------+ +---------+ + ---------+
| ... | | ... | | ... |
EBP ---> | Old EBP | --> | Old EBP | --> | Old EBP |
| EIP | | EIP | | EIP |
| Arg1 | | Arg1 | | Arg1 |
| Arg2 | | Arg2 | | Arg2 |
| Arg3 | | Arg3 | | Arg3 |
| ... | | ... | | ... |
| Argn | | Argn | | Argn |
| ... | | ... | | ... |
| ... | | ... | | ... |
High Address---> +---------+ +---------+ + ---------+
5 Example AnalysisThe following code is very simple, the main want to use a practical example to test the above mentioned theory.5.1 Source CodeThe Foo function is defined as int foo (int a, int b). There are two input parameters. Called by the main function. The following is a major analysis of the call procedure for the Foo function.#include "stdafx.h"
int foo (intint b)
{
int sum = 0;
sum = a + b;
return sum;
}
int _tmain (int_tchar* argv[])
{
foo (1, 2);
return 0;
}
5.2 Register value before calling foo () 5.3 The value of the register after calling Foo () sets the breakpoint to the first assembly statement after the function call. At this point, the function has not been pressed into the EBP,ESP from 0xfaf958 into 0xfaf94c. 12 bytes less. Then look at the definition of the Foo function, a total of two parameters, plus the push of the EIP is just 12 bytes.
5.4 The contents of the stack from the following figure can be seen, at this time has not been pressed into the EBP
Press into the contents of the EBP front stack: EIP (0x002d1417), parameter a = 1, parameter b = 2.
After pressing into the EBP the contents register changes in the stack, before the EBP into the stack, ESP (0x00faf948) => EBP
Stack of changes, stacks of EBP (0x00fafa24)
Date:2014-07-20 13:29:59
HTML generated by Org-mode 6.31a in Emacs 23