Reading memory that belongs to another process on Windows
Show older comments
Suppose I have another process running on Windws. That process is stopped in the debugger (Visual Studio). Visual Studio does not have a means of dumping the contents of specified memory locations into a file. However, Visual Studio will tell me the starting address in memory for the data.
Is there a way that Matlab can take a process i.d., a starting address and the number of bytes and read the memory from the process and load it into a Matlab variable / array? Then I would want to have Matlab read this data as 4-byte integer data and give me an array of the integers.
Is there anything that has to be set on the other process to make its memory readable of can Matlab read memory that belongs to any other process?
Thank you for your replies. This would be enormously cool if it worked.
Linda Seltzer
Answers (2)
James Tursa
on 23 Jul 2012
0 votes
No. In general, the memory of one process cannot be accessed by another process. There are ways to pass data such as the address itself across (e.g., a COM link ala the MATLAB Engine etc), but the address of one process means nothing to the other process and will not map correctly to the memory you are trying to access (you will likely get a seg fault if you try it).
6 Comments
Linda
on 23 Jul 2012
Edited: Walter Roberson
on 23 Jul 2012
James Tursa
on 23 Jul 2012
You could start here with the doc and examples:
Basically, your program opens a MATLAB Engine (another process that is linked to your program via a COM link). Then your program can create MATLAB variables with the various mxCreateDoubleMatrix etc functions (i.e., copies of your data) and send those over the COM link to the MATLAB Engine, where they can be independently examined. When the Engine is opened you basically have a MATLAB session running with a command line available, so there is a lot of flexibility in how you want to look at the data.
Walter Roberson
on 23 Jul 2012
Note: Linux and (probably) OS-X have mechanisms for accessing memory that is in a different process. There are, of course, security restrictions on the mechanism.
Linda
on 23 Jul 2012
Edited: Walter Roberson
on 23 Jul 2012
James Tursa
on 23 Jul 2012
Am I to understand from your comment below that you cannot modify the C/C++ program? This would be required to add the code for the MATLAB Engine.
Walter Roberson
on 23 Jul 2012
Can COM be used to control Visual Studios? And can Visual Studios, so controlled, report back memory contents?
Walter Roberson
on 23 Jul 2012
0 votes
It appears that it is possible on MS Windows. See http://www.codeproject.com/Articles/4865/Performing-a-hex-dump-of-another-process-s-memory
Categories
Find more on COM Component Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!