-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps.cpp
More file actions
38 lines (32 loc) · 869 Bytes
/
maps.cpp
File metadata and controls
38 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "maps.h"
int getRegions(std::vector<scanRegion> ®ions, pid_t pid)
{
std::stringstream path;
path << "/proc/" << pid << "/maps";
std::cout << "path:" << path.str() << std::endl;
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen(path.str().c_str(), "r");
if (fp == NULL)
{
std::cout << "unable to open file" << std::endl;
return 1;
}
scanRegion lineBuffer;
char readable, writeable;
while ((read = getline(&line, &len, fp)) != -1)
{
if (sscanf(line, "%lx-%lx %c%c", &lineBuffer.startRegion, &lineBuffer.endRegion, &readable, &writeable) >= 4)
{
if ((readable == 'r') && (writeable == 'w'))
{
regions.push_back(lineBuffer);
}
}
}
fclose(fp);
free(line);
return 0;
}