Disassembly analysis - global, local, static, heap variables

When the executable file is compiled, it is already stored in a fixed location, and can even be shared across files, because it is static and fixed in the file.

The disassembly window directly dereferences the pointer, that is, uses this address to access, direct addressing

Automatic variables do not need to be released manually. The space will be released automatically after the function execution is completed. 

Local variables are stored in the stack space. Each thread has its own function call stack, which stores the function call relationship and the local variables inside the function. When the function returns, the local variables disappear.

The begbug version accesses local variables through ebp-XX, while the release version addresses local variables directly through esp. Register relative addressing here is achieved by adding or subtracting a number from esp/ebp. Access to memory address.

 Local static variables are inside a function and cannot be accessed in other functions.

test eax, eax; jne 0x1234 》The e in jne means equal to 0

0x427e4c is the address where the flag bit is stored. If there are <= 8 static variables, one byte will be used to store the flag bit. Otherwise, N bytes will be added. Next to it, 0x427e48 stores the value of i.

The final output is all 0: because static will only be initialized at the beginning, and then set the flag to 1, this initialization statement will not be executed later, and printf will be executed directly. If you want to change its value, it is also very simple. :

static int i=n;
i=n;
printf("%d\n",i);

To put it bluntly, you can just modify the value of i after initialization.

Use a constant to initialize a static variable

To summarize, an important feature of a static variable is that it has a flag. Once initialized, it will not be initialized again.

 

 

The four FDs before and after are used to check whether the space is out of bounds. The CD in the middle is the default data. You can memset the applied heap space after application. The returned first address is as shown in the figure.

The heap space is connected using a data structure such as a doubly linked list_CrtMemBlockHeader. 

Guess you like

Origin blog.csdn.net/Tandy12356_/article/details/131125780