-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainwindow.cpp
211 lines (177 loc) · 5.43 KB
/
mainwindow.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QDebug>
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
ui(new Ui::MainWindow)
{
//scanner declared in mainwindow.h
scanner = new Scanner;
//scanner is initialized before GUI
scanner->start();
ui->setupUi(this);
// to get progress value from the scanner thread
connect(scanner, SIGNAL(setProgress(int)), ui->progressBar, SLOT(setValue(int)), Qt::AutoConnection);
// to start the initial scanning
connect(this, SIGNAL(startNewScan(int, BYTE, int, int)), scanner, SLOT(newScan(int, BYTE, int, int)), Qt::AutoConnection);
// to be able to cancel a scan in progress
connect(this, SIGNAL(stopScan()), scanner, SLOT(stop()), Qt::AutoConnection);
// to be able to show the user what went wrong with the scanning
connect(scanner, SIGNAL(scanFailed(std::string)), this, SLOT(scanFailed(std::string)), Qt::AutoConnection);
// to get the results of the completed scan
connect(scanner, SIGNAL(setResults(std::vector<Result>)) , this, SLOT(scanFinished(std::vector<Result>)), Qt::AutoConnection);
ui->pushButton_next->setDisabled(true);
ui->pushButton_stop->setDisabled(true);
ui->pushButton_undo->setDisabled(true);
ui->progressBar->setValue(0);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::setTarget(QMap<int, QString> target)
{
targetProc = target;
}
void MainWindow::showProcessList()
{
ProcessList* pl = new ProcessList(this);
pl->setModal(true);
pl->show();
}
void MainWindow::enableScan()
{
ui->pushButton_scan->setEnabled(true);
}
void MainWindow::firstScan()
{
// we could do without this but it keeps the code easy to read
#define CONTROL_STATEMENT \
buffValue = new unsigned char[sizeof(testValue)]; \
memcpy(buffValue, &testValue, sizeof(testValue));
ui->pushButton_scan->setDisabled(true);
int pid = targetProc.keys().at(0);
ui->pushButton_stop->setEnabled(true);
foundAddresses = new std::vector<Result>;
// determine the operation type from the UI
int operation = ui->searchOperationCombo->currentIndex();
switch(operation) {
case 0:
operation = EXACT;
break;
case 1:
operation = GREATER;
break;
case 2:
operation = LESSER;
break;
case 3:
operation = CHANGED;
break;
case 4:
operation = UNCHANGED;
break;
case 5:
operation = UNKNOWN;
break;
}
//determine the value to search for and it's data-type
BYTE buffValue;
QString value = ui->valueEdit->text();
int valueType = ui->dataTypeCombo->currentIndex();
qDebug() << "valueType: " << valueType << " value: " << value;
if(valueType == 0) {
valueType = BOOLEAN;
bool testValue;
if(value.toLower() == "true" || value.toInt() != 0)
testValue = true;
else
testValue = false;
CONTROL_STATEMENT
}
else if(valueType == 0) {
valueType = CHARACTER;
char testValue = value.toLatin1().at(0);
CONTROL_STATEMENT
}
else if(valueType == 1) {
valueType = SHORT_INTEGER;
short testValue = value.toShort();
CONTROL_STATEMENT
}
else if(valueType == 2) {
valueType = INTEGER;
int testValue = value.toInt();
CONTROL_STATEMENT
}
else if(valueType == 3) {
valueType = LONG_INTEGER;
long testValue = value.toLong();
CONTROL_STATEMENT
}
else if(valueType == 4) {
valueType = FLOAT;
float testValue = value.toFloat();
CONTROL_STATEMENT
}
else if(valueType == 6) {
valueType = DOUBLE;
double testValue = value.toDouble();
}
else if(valueType == 7) {
valueType = STRING;
char* testValue = value.toLatin1().data();
CONTROL_STATEMENT
}
else if(valueType == 8) {
valueType = UNICODE_CHARECTER;
wchar_t testValue[value.size()]; // = new wchar_t;
mbtowc(testValue, (const char*)value.toUtf8().data()[0], sizeof(value.toUtf8().data()[0]));
CONTROL_STATEMENT
}
else if(valueType == 9) {
valueType = UNICODE_STRING;
wchar_t *testValue = new wchar_t;
mbstowcs(testValue, value.toUtf8().data(), value.size());
CONTROL_STATEMENT
}
emit startNewScan(pid, buffValue, valueType, operation);
}
void MainWindow::nextScan()
{
//((Result)foundAddresses->at(1)).getData()
}
void MainWindow::scanFinished(std::vector<Result> results)
{
for(int i = 0; i < results.size(); i++)
{
QTableWidgetItem *address = new QTableWidgetItem(QString::number(static_cast<Result>(results.at(i)).baseAddr(),16));
QTableWidgetItem *currentValue = new QTableWidgetItem(QString((char*)static_cast<Result>(results.at(i)).data()));
ui->tableWidget->setItem(i,0,address);
ui->tableWidget->setItem(i,1,currentValue);
}
ui->pushButton_next->setEnabled(true);
}
void MainWindow::scanFailed(std::string errorMsg)
{
error(QString(errorMsg.c_str()));
}
void MainWindow::error(QString message)
{
QMessageBox info;
info.setIcon(QMessageBox::Critical);
info.setText(message);
info.exec();
}