I created a program in C++ that creates a pointer to a variable, and then proceeds to read every byte in the my machine's memory as a character. Here is my code:
#include <iostream>
#include <windows.h>
int main(int argc, char** argv) {
unsigned long long i = 0;
char start = 65;
char* ptr = &start;
while (1) {
try {
std::cout << *(ptr + i);
} catch (...) {
std::cout << "!";
}
i++;
Sleep(atoi(argv[1]));
}
}
When I run the program, the output changes; sometimes I get a few lines of gibberish, but other times I get pages' worth of output, amidst which I can find system information (e.g. directories and languages). This is cool. So cool, that I'm worried it might be potentially harmful to my system. Is there any risk in printing the contents of random pointers?
Also, my computer has made a notification noise twice in the past three minutes, and neither time did I receive a notification. It might just be a coincidence, but I'm getting spooked
No. OS assign a virtual address space before launching any process. Any access outside that address results in a segfault.
So the program may keep reading all the random(maybe interesting) bytes in its address space until it gets a segfault.
References: