问题
So I tried debugging some simple C programs today ;
First one being
int main(){
int a ,b ;
return 0 ;
}
Which when de-compiled gave me
push ebp
mov ebp,esp
sub esp,008h
because I need to have 8 bytes to store a and b in the current stack frame since they are local variable !
But when I try the same with Strings say
int main() {
char greeting[12] = "Pwnit2Ownit";
return 0;
}
Which when de-compiled gave me
push ebp
mov ebp,esp
sub esp,0DCh
0DCh is 220 , But since the string is only 12 bytes long shouldn't the
sub esp,0DCh
be
sub esp,00ch
instead ?
And can anyone share some links on how the strings are stored in the memory and accessed later via assembly [preferebly instruction] , like hows the string greetings stored in memory if it's length is large since we can't store all in the stack itself
回答1:
As @user3386109 pointed out , The issue is to prevent overflow the default security check in visual studio is enabled , and it provides extra space in order to prevent overflows , so turning it off , made the compiler allocate only 12 bytes :D
To turn this security measure ( Buffer Security Checks GS) off Project settings -> C/C++ -> Code generation -> security check = disable GS
Some post related to GS
http://preshing.com/20110807/the-cost-of-buffer-security-checks-in-visual-c/
来源:https://stackoverflow.com/questions/37309076/why-does-initializing-a-string-in-a-function-doesnt-work-like-int-while-debuggi