简体   繁体   English

是否可以在一个 C 程序中“创建”垃圾 memory 数据,然后再从另一个 C 程序中读取相同的数据?

[英]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:我想知道是否可以在第一个 C 程序中:

  1. Allocate and declare an int to the value of 5 in memory分配并声明一个 int 到 memory 中的值5
  2. Print out the address of the variable (eg: 0x7ffee6a98ad8 )打印出变量的地址(例如: 0x7ffee6a98ad8
  3. Terminate终止

And then in a second C program, after the first has completely finished executing:然后在第二个 C 程序中,在第一个完全完成执行后:

  1. Read in the data that was previously declared at address 0x7ffee6a98ad8读入之前在地址0x7ffee6a98ad8声明的数据
  2. Print the correct value of 5打印正确的值5

Is this a possibility in C?这是 C 中的可能性吗?

If so, how would one go about accomplishing such a task?如果是这样,一个 go 将如何完成这样的任务?

I am using Linux, if that matters.如果这很重要,我正在使用 Linux。

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.如果您在DOS中创建了一个大型 C 程序并使用malloc()分配了一些 RAM,您实际上可以将该地址保存在某处(如磁盘上)并启动另一个 C 程序并读取 ZCD69B4957F06CD818D7BDE291

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.我听说它在深度嵌入式平台上仍然是可能的,但是在现代多用户操作系统上,当你从操作系统分配 RAM 时,它首先会清除 RAM,所以你看不到它。

Question edited to say Linux.问题编辑为 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.ptrace()打开 shell 进程,在 shell 进程中分配一些 memory 并写入它,下一个程序可以找到它。 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; https://techryptic.github.io/2018/04/07/Using-PTRACE-to-Inspect-&-Alter-Memory/ Z05B8C742502FBF2DEZC1A; 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.他们开始收紧事情,因此您无法调试除您自己的子进程之外的任何进程,因为他们不想要sudo灾难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM