I'm trying to get the values stored in my computer's memory addresses. For that, I've written a little C++ program, but it throws a Read access violation error when trying to get the value stored in the address 0x1.
The goal here is to get the values that can be retrieved, not the ones that can't.
Anyways, here's the code:
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
unsigned long long *ptr1;
for (unsigned long long i = 0; i < 0xFFFFFFFF; i++)
{
try {
ptr1 = reinterpret_cast<unsigned long long*>(i);
}
catch (...) {
cout << "Some erros happened" << endl;
}
if (ptr1 != nullptr) {
try {
cout << "Value in address 0x" << i << ": " << *ptr1 /*Error here*/ << endl;
}
catch(...) {
cout << "Some erros happened" << endl;
}
}
else {
cout << "Value in address 0x" << i << ": null pointer" << endl;
}
}
_getch();
return 0;
}
Note that in the first iteration of the for loop the program detects that ptr1 is a null pointer but in the second one, the program crashes when it gets to *ptr1.
If I'm not mistaken, I think the error comes from *ptr1 not being able to read what's stored in that address, but I don't know how to know that without actually referencing ptr1.
Apparently, the try catch blocks cannot be used in this situation.
By the way, this is the output of the program:
Value in address 0x0: null pointer
Value in address 0x1:
Then it throws the error.