Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i want to change the value of the first program with the second program

here is my problem

#include <iostream>
#include <Windows.h>

int main()
{
    int coins = 1;
    

    std::cout << &coins <<std::endl;

    Sleep(10000);
    return 0;
}

the coins value is the one i want to change with the second program

here is the code of the second program

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>

int main()
{
    int* coins = reinterpret_cast<int*> (0x57da7ffe7c);
    std::cout<<*coins<<"\n";
    return 0;
}

i expected that it will print the value of coins witch is (1) but it gives me this error (exited with code=3221225477)

the editor i use is vs code

>Solution :

Summary of information from the comments:

  1. Each process has its own address space. Even if the address 0x57da7ffe7c is a fixed one in one process, you cannot access it from another like this.
    The error code you get 3221225477 (which is 0xC0000005 in hex) is "Access Violation", meaning that you attempted to read an invalid address.

  2. You seems to be using Windows. There is a Windows API for reading another process memory (under certain limitations): ReadProcessMemory. You can have a look at the documentation link, but it’s quite advanced to use.

  3. The address space of a process is valid only as long as it is alive. Therefore if you use ReadProcessMemory, the first program would need to be still running at that stage (before your edit to the question you didn’t have a Sleep in the first program, and so it would have exited almost immediatly).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading