-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
192 lines (173 loc) · 5.71 KB
/
main.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "myTypes.h"
#include "menu.h"
#include "maps.h"
#include "scan.h"
#include "print.h"
int main(int argc, char* argv[])
{
pid_t pid;
int input = 0;
bool isFirstRun = true;
std::string commando;
std::vector<scanRegion> regions;
std::vector<scanResult> results;
if(argc < 2)
{
printError("usage ./MemCrawl <pid>");
return 1;
}
if ((pid = atol(argv[1])) == 0)
{
printError("usage ./MemCrawl <pid>");
return 1;
}
// get read/writeable scan regions
if (getRegions(regions, pid) != 0)
{
printError("could not get regions");
return 1;
}
std::cout << "Enter Command (try: help)" << std::endl;
std::cout << results.size() << "> ";
std::getline (std::cin, commando);
while (commando != "quit" && commando != "q")
{
try
{
input = string2int(commando);
if (isFirstRun)
{
isFirstRun = false;
if (scanIntInit(regions, results, pid, input) != 0)
{
printError("could not scan memory");
return 1;
}
}
else
{
if (scanIntResults(results, pid, input) != 0)
{
std::cout << "could not scan memory" << std::endl;
return 1;
}
}
}
catch (int e)
{
if (e == 1)
{
if (commando == "help")
{
printHelp();
}
if (commando == "list")
{
printResults(results);
}
if (commando == "update")
{
if (updateIntResults(results, pid) != 0)
{
printError("could not scan memory");
return 1;
}
}
if (commando == "ulist")
{
if (updateIntResults(results, pid) != 0)
{
printError("could not scan memory");
return 1;
}
printResults(results);
}
if (commando == "info")
{
std::cout << std::endl << "scan regions: " << std::endl;
int adresses = 0;
for(std::vector<scanRegion>::iterator it = regions.begin(); it != regions.end(); ++it)
{
scanRegion sr = (scanRegion) *it;
std::cout << std::hex << sr.startRegion << " - " << sr.endRegion << std::dec <<std::endl;
adresses += sr.endRegion - sr.startRegion;
}
std::cout << std::endl << adresses << " adresses" << std::endl;
}
if (commando == "reset")
{
regions.clear();
results.clear();
isFirstRun = true;
// get read/writeable scan regions
if (getRegions(regions, pid) != 0)
{
printError("could not get regions");
return 1;
}
}
if (commando.substr(0, 3) == "pid")
{
if (commando.length() < 5)
{
std::cout << "correct usage: pid <pid>" << std::endl;
}
else
{
int val = 0;
std::stringstream ss(commando.substr(4, commando.length()));
if ((ss >> val).fail())
{
printError("wrong parameter for pid command");
}
else
{
pid = val;
// reset
regions.clear();
results.clear();
isFirstRun = true;
// get read/writeable scan regions
if (getRegions(regions, pid) != 0)
{
printError("could not get regions");
return 1;
}
}
}
}
if (commando.substr(0, 3) == "set")
{
if (commando.length() < 5)
{
std::cout << "correct usage: set 5" << std::endl;
}
else
{
int val = 0;
std::stringstream ss(commando.substr(4, commando.length()));
if ((ss >> val).fail())
{
printError("wrong parameter for set command");
}
else
{
if (setInt(results, pid, val) != 0)
{
std::cout << "could not set value" << std::endl;
return 1;
}
}
}
}
}
else
{
printError("unknown");
}
}
std::cout << results.size() << "> ";
std::getline (std::cin, commando);
}
return 0;
}