[英]Why does this return different values everytime I run the program? 0x3759F8B0 - 0x100
It's not really a problem for me but I just started thinking about it and I thought I'd ask. 这对我来说不是一个问题,但我刚开始考虑它,我想我会问。 Why would that return different values each time I run the program (0x3759F8B0 - 0x100)?
为什么每次运行程序时返回不同的值(0x3759F8B0 - 0x100)?
One time it says 00AFFD00 and the next it says 006FFD48 有一次它说00AFFD00而下一个说006FFD48
test = 0x3759F8B0 - 0x100;
cout << &test << endl;
I suppose your full program source reads as 我想你的完整程序源读作为
#include <iostream>
using namespace std;
int main()
{
int test;
test = 0x3759F8B0 - 0x100;
cout << &test << endl;
}
As @pat already mentioned in comment, your program emits the address of the variable test
, not its value. 正如@pat在评论中已经提到的那样,你的程序会发出变量
test
的地址 ,而不是它的值。 On modern operating systems there is something called "address space layout randomization" (ASLR, see https://en.wikipedia.org/wiki/Address_space_layout_randomization for a good overview) which helps making it harder to exploit security vulnerabilities that may exist in a program. 在现代操作系统上,有一种称为“地址空间布局随机化”的东西(ASLR,请参阅https://en.wikipedia.org/wiki/Address_space_layout_randomization以获得良好的概述),这有助于更难以利用可能存在的安全漏洞。程序。 The idea is, that with every new start of a program the addresses of the stuff it uses are randomized.
这个想法是,随着程序的每个新开始,它使用的东西的地址是随机的。 Hence the address of variables will change on every launch with ASLR enabled.
因此,在启用ASLR的每次启动时,变量的地址都会发生变化。
ASLR is now a standard feature in mainstream operating systems. ASLR现在是主流操作系统的标准功能。 However it can be disabled (not recommended) and without ASLR the above program would indeed always emit the same output.
但是它可以被禁用(不推荐),如果没有ASLR,上述程序确实会发出相同的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.