How to change an object knowing the memory address in C ++?

Good evening.

I opened Visual Studio 2012 and ran the program:

    double x = 8768130;
    cout << &x;

    cin.get();
    return 0;

The address that he wrote in the console was 003CFBF8.

Then I opened another copy of Visual Studio and tried to read this, but I'm not sure if I am doing this correctly. I already did a search in Qaru before posting and found out that I should do something like this:

    double* ptr = reinterpret_cast<double*>(0x003CFBF8);

    cout << *ptr;

but he made an exception

Unhandled exception at 0x00A943DD in Project2.exe: 0xC0000005: Access violation reading location 0x003CFBF8.

What does it mean? I have no acces? Did I do it wrong?

If you ask me why I want to do this, I learn C ++ from some books, and I wanted to check how it works volatile. This is why I wanted:

  • open the first program, initialize the variable, write its address;
  • open the second program and change which written address refers to
  • , , .
+4
1

... Visual Studio...

. , , . .

(). ASLR ( ), , , , .

, , , API . , Windows WriteProcessMemory.

volatile ( - ), , .

+9

Source: https://habr.com/ru/post/1535407/


All Articles