Reputation:
I understand that it's not possible to gain direct access to all the memory locations using c++ but all I want to do is to return all the accessible ram memory locations by the application. It becomes impossible to store this address list in a dynamic variable as we would require even more space to hold the address of the variables holding this address! But that doesn't matter as I could save it in a text file. Even one attempt to try to read such a memory location crashes the application. Instead of crashing, if the application provides a better error message I could write a code to obtain the address of all the accessible memory locations.
if there is a method to return this address list, I would like to know (I am using windows 7). Thanks in advance.
I have tried this following idea to try and return if a memory location is accessible:
there are two codes included:
the first:
#include <stdlib.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
if(!(system("\"C:\\Users\\ ...\\read0.exe \""))// I have not provided the complete path
cout<<"readable memory location";
else
cout<<"not readable";
getch();
return 0;
}
the second:
///one trying to read the accessible memory location
/// read0.cpp; released as read0.exe
int main()
{
int *a;//runs in 32-bit computer
a= (int*)0;
if((*a))
{/*do nothing; just try reading the memory location*/
}
return 0;
}
when the first console file opens the second, it causes the second file to crash; It results in making the operating system open a window to ask for either debugging or closing the application. This delays time and makes it more inefficient. So as a result I have been trying to find a way to temperately disable this message box from popping out and I have found this.
could you give the command line in windows 7 command prompt so that I could use the system command in c++ to set the dword value to zero and thereby disabling the error message during crashes. I am new to editing registry using cmd.
Upvotes: 0
Views: 125
Reputation: 119089
As far as I know this cannot be done portably.
In Linux there is /proc/<PID>/maps
, which (I believe) gives the entire list of mapped virtual memory addresses for a process. It looks something like this:
00400000-004e5000 r-xp 00000000 08:01 11567110 /bin/bash
006e4000-006e5000 r--p 000e4000 08:01 11567110 /bin/bash
006e5000-006ee000 rw-p 000e5000 08:01 11567110 /bin/bash
006ee000-006f4000 rw-p 00000000 00:00 0
02243000-0242e000 rw-p 00000000 00:00 0 [heap]
7f1d1744e000-7f1d17459000 r-xp 00000000 08:01 5260634 /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f1d17459000-7f1d17658000 ---p 0000b000 08:01 5260634 /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f1d17658000-7f1d17659000 r--p 0000a000 08:01 5260634 /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f1d17659000-7f1d1765a000 rw-p 0000b000 08:01 5260634 /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f1d1765a000-7f1d17664000 r-xp 00000000 08:01 5260630 /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f1d17664000-7f1d17863000 ---p 0000a000 08:01 5260630 /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f1d17863000-7f1d17864000 r--p 00009000 08:01 5260630 /lib/x86_64-linux-gnu/libnss_nis-2.13.so
(34 more lines)
Upvotes: 1