For my bachelor's thesis, I want to visualize the residual data memory and how it is saved after a system reboot.
I had a simple idea: moisten the picture in memory, turn off the computer, wait x seconds, boot the computer and see if the image is still there.
int mmap_lena (void)
{
FILE * fd = NULL;
size_t lena_size;
void * addr = NULL;
fd = fopen ("lena.png", "r");
fseek (fd, 0, SEEK_END);
lena_size = ftell (fd);
addr = mmap ((void *) 0x12345678, (size_t) lena_size, (int) PROT_READ, (int) MAP_SHARED, (int) fileno (fd), (off_t) 0);
fprintf (stdout, "Addr =% p \ n", addr);
munmap ((void *) addr, (size_t) lena_size);
fclose (fd);
fclose (fd_log);
return EXIT_SUCCESS;
}
I skipped checking the return values ββfor clarity.
So, after mmap, I tried to somehow get the address, but I usually end up with a segmentation error, since I understand that the memory is protected by my operating system.
int fetch_lena (void)
{
FILE * fd = NULL;
FILE * fd_out = NULL;
size_t lenna_size;
FILE * addr = (FILE *) 0x12346000;
fd = fopen ("lena.png", "r");
fd_out = fopen ("lena_out.png", "rw");
fseek (fd, 0, SEEK_END);
lenna_size = ftell (fd);
// Segfault
fwrite ((FILE *) addr, (size_t) 1, (size_t) lenna_size, (FILE *) fd_out);
fclose (fd);
fclose (fd_out);
return 0;
}
Also note that I hardcoded the addresses in this example, so whenever you run mmap_lena, the value I use in fetch_lena may be wrong, since the operating system only accepts the first parameter in mmap as a hint (on my system, this always defaults to 0x12346000).
If there is any trivial coding error, I regret that my C skills were not fully developed.
I would like now if there is any way to access the data I want without implementing any malloc interceptors or memory hackers.
Thanks in advance, David