简体   繁体   English

为什么每次运行程序时都会返回不同的值? 0x3759F8B0 - 0x100

[英]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.

相关问题 HWND abc = 0x100; 这行不通,我知道原因。 那怎么办呢? - HWND abc = 0x100; This does not work, and I understand why. How to do it then? 为什么每次运行这个程序时 &amp;x 都会打印出不同的值? - Why &x prints a different value every time I run this program? 为什么当我 hover cursor 在快板的 x 轴上从 0 到 100 区域时程序突然关闭 - Why the program suddenly closes when I hover the cursor in area from 0 to 100 on x axis in allegro 为什么 FOLDERID_ProgramFiles 返回“C:\\Program Files (x86)”? - Why does FOLDERID_ProgramFiles return “C:\Program Files (x86)”? Visual Studio C ++ 每当我尝试从[80] x [80]数组中循环一个cout时,程序就会崩溃 - Visual Studio C++ | Program crashes everytime I try to loop a cout from an array of [80]x[80] «F(5)»和«int x; F(x)»调用不同的函数? - «F(5)» and «int x; F(x)» to call different functions? X f()是什么意思? - What does X f() mean? 在实践中,为什么不同的编译器会计算不同的 int x = ++i + ++i; 值? - In practice, why would different compilers compute different values of int x = ++i + ++i;? 0x0 @ 0x196f2f0是什么意思? - what does 0x0 @ 0x196f2f0 mean? 每次我运行程序时,随机算法(随机 pivot 选择)都会给出不同的 output - Randomized algo (randomized pivot selection) gives different output everytime i run the program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM