Can I operate a variable of another application in my program by pointer in C++

kanch96

Solid State Member
Messages
18
Location
China
hi,tkank you guys come in and I got a question in C++.

Like thread's title suggest, can I operate a variable of another application in my program by a pointer?
code might be :


int *pi ,address=0,buf=0;
std:cout<<"enter the address of a variable:";
std:cin>>address;
*pi = (int*) address;
std:cout<<"change variable at "<<address<<"into:";
cin>>buf;
*pi = buf;



I had complied that code,but when change the data, the application crashed.
So,I can't do this?Or there's something wrong of my approach?
If this way don't work, there's any other ways to do that?To change other applications variable in my program,I mean.
 
Pretty sure it's getting blocked because of Data Execution Prevention, or something similar, by the OS.

The OS has safe guards put in place to prevent applications from accessing each others' memory spaces; so instead of allowing it, it will crash the application that's trying to access outside of it's own memory space.
 
Pretty sure it's getting blocked because of Data Execution Prevention, or something similar, by the OS.

The OS has safe guards put in place to prevent applications from accessing each others' memory spaces; so instead of allowing it, it will crash the application that's trying to access outside of it's own memory space.

sorry, but how can I do that?
 
Well if it's Data Execution Prevent, you can try and disable it. But a lot of times it's backed by hardware and not just the OS.

What you're essentially trying to do is what forms of malware do; and the OS/hardware try to block malicious attempts. One program modifying another program's memory space is considered malicious (hence why you're getting the crash).
 
Back
Top Bottom