-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRegion.cpp
More file actions
101 lines (79 loc) · 2.91 KB
/
Region.cpp
File metadata and controls
101 lines (79 loc) · 2.91 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "Region.hpp"
using namespace std;
using namespace remote;
vector<Region> remote::GetRegions(pid_t pid) {
vector<Region> ret;
stringstream path;
path << "/proc/" << pid << "/maps";
ifstream m(path.str().c_str());
string line;
while(getline(m, line)) {
Region r;
size_t count = 0;
string str = line;
while(str.length()) {
size_t nextSpace = str.find_first_of(' ');
if(nextSpace == -1) {
if(!str.empty()) {
r.pathname = str;
if(str.c_str()[0] == '/') {
r.filename = str.substr(str.find_last_of('/') + 1, str.length());
} else {
r.filename = r.pathname;
}
}
break; // Stuff
} else {
string content = str.substr(0, nextSpace);
// Deal with content
stringstream ss;
if(count == 0) {
size_t spl = content.find_first_of('-');
if(spl != -1) {
ss << hex << content.substr(0, spl);
ss >> r.start;
ss.clear();
ss << hex << content.substr(spl + 1, content.size());
ss >> r.end;
ss.clear();
}
} else if(count == 1) { // Permissions
r.read = (content.c_str()[0] == 'r');
r.write = (content.c_str()[1] == 'w');
r.exec = (content.c_str()[2] == 'x');
r.shared = (content.c_str()[3] == 'p');
} else if(count == 2) { // Offset
ss << hex << content;
ss >> r.offset;
ss.clear();
} else if(count == 3) { // Device Info
size_t spl = content.find_first_of(':');
if(spl != -1) {
ss << dec << content.substr(0, spl);
ss >> r.deviceMajor;
ss.clear();
ss << dec << content.substr(spl + 1, content.size());
ss >> r.deviceMinor;
ss.clear();
}
} else if(count == 4) { // INode shit
ss << content;
ss >> r.inodeFileNumber;
ss.clear();
}
count++;
// Advance
str = str.substr(nextSpace);
size_t firstNonSpace = str.find_first_not_of(' ');
if(firstNonSpace == -1) {
break;
}
str = str.substr(firstNonSpace);
}
}
if(r.start != 0 && r.end != 0) {
ret.push_back(r);
}
}
return ret;
}