How to read variable from another program?

1

I'm learning programming and I would like to know: how do I make the program read the value of a variable from another program (theoretically this would be without "awareness" of the program read, I do not know exactly how this works, some permission ... Something like the Cheat Engine does, only without attribution, just read same)? I have the basics (pretty basic myself, concludes only the discipline of Intro to Computing in my college) from Python, C and I risk a little in C ++ and Java

    
asked by anonymous 09.08.2014 / 04:01

2 answers

7

I am sorry to inform you that only with basic knowledge you will not be able to do this - even with advanced knowledge this is not trivial. You need to somehow enter the process space of the other program, learn or discover how your data structures are set from memory, know the local and the exact time which should read the memory of the program, and map the information read in its concept of "variable".

There are many other considerations. For example, it depends heavily on the environment in which the program is running. Is your app a phone app (iOS / Android / WinPhone) or tablets (iOS / Android / Windows)? No way - the operating system isolates apps so they do not have access to other apps. Is it a desktop application (Windows or Mac)? Your program would have to have access to the virtual memory space of the other program, which is not the case most of the time (you may need to use a driver ) to gain access to the memory space of the other process.)

Ok, assuming you can at some point read the entire memory of the other program (as I said above, it's not a likely assumption). What kind of variable do you want to read? If it is a local variable of a method, it will be allocated in the program's execution stack, so you will have to access memory exactly at the time that function is running, and know inside the stack which value corresponds to the variable you want (another non-trivial task). Another thing: it might be that the variable represents not a primitive value, but an object - which is stored not in the heap, but in the heap of objects (what happens when you use new in Java, for example). Then in the stack you will only have the address of the memory space where the value of the variable is. And that value can change - in Java or C #, when the garbage collector runs, the object has chances of being moved.

Finally, if you want to hack another program, trying to get the value of one of your variables is not the best way:)

    
09.08.2014 / 04:42
3

As already said is somewhat complex (excuses carlosfigueira, plus you exaggerated a little is not so difficult so if he has already worked with C, must understand well how the system of allocation and structure of data in memory, of course supposing he really learned C well, not just 'hello world') more not impossible ...

If it is in windows OS you can study the windows' DLL 'kernel32.dll' which deals with this subject, more specifically the following functions: 'OpenProcess',' ReadProcessMemory 'and' WriteProcessMemory ';

You can also search for a ready library with these abstracted functions for the language you are working on.

    
18.12.2014 / 23:54