[英]Why does initializing a string in a function doesn't work like int while debugging
So I tried debugging some simple C programs today ; 所以今天我尝试调试一些简单的C程序;
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 ! 因为我需要8个字节在当前堆栈帧中存储a和b,因为它们是局部变量!
But when I try the same with Strings say 但是当我用Strings尝试相同时
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 0DCh是220,但是由于字符串只有12个字节长,因此不应
sub esp,0DCh sub esp,0DCh
be 是
sub esp,00ch 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 任何人都可以共享一些有关如何将字符串存储在内存中并稍后通过汇编程序[preferebly指令]进行访问的链接,例如,如果字符串问候语的长度很大,那么该字符串如何存储在内存中,因为我们无法将所有字符串存储在堆栈本身中
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 正如@ user3386109所指出的那样,问题是防止溢出,Visual Studio中启用了默认安全检查,并且它提供了额外的空间以防止溢出,因此将其关闭,使编译器仅分配12个字节:D
To turn this security measure ( Buffer Security Checks GS) off Project settings -> C/C++ -> Code generation -> security check = disable GS 要关闭此安全措施(缓冲区安全检查GS),请关闭项目设置-> C / C ++->代码生成->安全检查=禁用GS
Some post related to GS 一些与GS相关的帖子
http://preshing.com/20110807/the-cost-of-buffer-security-checks-in-visual-c/ http://preshing.com/20110807/the-cost-of-buffer-security-checks-in-visual-c/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.