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

Is it possible to "create" garbage memory data in one C program, and then later read in that same data in from another C program?

I would like to know if it is possible to in the first C program:

  1. Allocate and declare an int to the value of 5 in memory
  2. Print out the address of the variable (eg: 0x7ffee6a98ad8)
  3. Terminate

And then in a second C program, after the first has completely finished executing:

  1. Read in the data that was previously declared at address 0x7ffee6a98ad8
  2. Print the correct value of 5

Is this a possibility in C?

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

If so, how would one go about accomplishing such a task?

I am using Linux, if that matters.

>Solution :

It once was possible. If you made a large C program in DOS and alllocated some RAM with malloc() you could in fact save that address somewhere (like on disk) and start another C program and read that memory.

I hear it’s still possible on deeply embedded platforms, but on modern multi-user operating systems, when you allocate RAM from the OS it clears the RAM first so you can’t see it.

Question edited to say Linux. Well no, but also yes. Open up the shell process with ptrace(), allocate some memory in the shell process and write to it, and the next program can find it there. This is nothing like wild pointer games, and is really quite tricky. https://techryptic.github.io/2018/04/07/Using-PTRACE-to-Inspect-&-Alter-Memory/ The window is closing; they’re starting to tighten things so you can’t debug any processes but your own child processes because they don’t want a sudo disaster.

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