-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
195 lines (161 loc) · 5.03 KB
/
mainwindow.cpp
File metadata and controls
195 lines (161 loc) · 5.03 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sstream"
#include <QFile>
#include <QFileDialog>
#include "framework/utils/pattern_scan.h"
extern WinContext* g_ctx;
WinProcess* proc = nullptr;
void ReadMem(void* dest, void* source, size_t size)
{
VMemRead(&g_ctx->ctx.process, proc->proc.dirBase, (uint64_t)dest, (uint64_t)source, size);
}
void WriteMem(void* dest, void* source, size_t size)
{
VMemWrite(&g_ctx->ctx.process, proc->proc.dirBase, (uint64_t)source, (uint64_t)dest, size);
}
int currow = 0;
int curcolumn = 0;
uintptr_t pprocess = 0;
uintptr_t vprocess = 0;
void RefreshList(QComboBox* combo)
{
QStringList pList = QStringList();
g_ctx->processList.Refresh();
for (auto& p : g_ctx->processList) {
std::stringstream stream;
stream << "[" << p.proc.pid << "] " << p.proc.name << " (" << std::hex << p.proc.physProcess << "; " << p.proc.process << ")";
pList << stream.str().c_str();
}
combo->clear();
combo->addItems(pList);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
hexEdit = new QHexEdit();
ui->setupUi(this);
ui->hexWidget->setWidget(hexEdit);
RefreshList(ui->processList);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_refreshButton_clicked()
{
RefreshList(ui->processList);
}
void MainWindow::on_processList_currentIndexChanged(int index)
{
uintptr_t pid;
char name[16];
sscanf(ui->processList->itemText(index).toLatin1().data(), "[%lu] %s (%lx; %lx)", &pid, name, &pprocess, &vprocess);
int module_count = 0;
proc = nullptr;
for (auto& p : g_ctx->processList)
if (p.proc.pid == pid) {
proc = &p;
break;
}
if (!proc)
return;
ui->moduleList->setRowCount(proc->modules.getSize());
ui->moduleList->setColumnCount(3);
QHeaderView* theader = ui->moduleList->horizontalHeader();
theader->setSectionResizeMode(QHeaderView::Stretch);
QStringList header;
header << "Name" << "Start" << "End";
ui->moduleList->setHorizontalHeaderLabels(header);
int i = 0;
for (auto& m : proc->modules) {
ui->moduleList->setItem(i, 0, new QTableWidgetItem(m.info.name));
ui->moduleList->setItem(i, 1, new QTableWidgetItem(QString::number(m.info.baseAddress, 16)));
ui->moduleList->setItem(i, 2, new QTableWidgetItem(QString::number(m.info.baseAddress + m.info.sizeOfModule, 16)));
i++;
}
}
void MainWindow::on_refreshPaged_clicked()
{
uintptr_t start = ui->moduleList->item(currow, 1)->text().toLong(nullptr, 16);
uintptr_t end = ui->moduleList->item(currow, 2)->text().toLong(nullptr, 16);
uintptr_t success_count = 0;
uintptr_t try_count = 0;
for (uintptr_t addr = (start & ~0xfff); addr < end; addr += 0x1000) {
uintptr_t naddr = VTranslate(&g_ctx->ctx.process, proc->proc.dirBase, addr);
if (naddr)
success_count++;
try_count++;
}
ui->amountUnpaged->setMaximum(try_count);
ui->amountUnpaged->setValue(success_count);
}
void MainWindow::on_moduleList_cellClicked(int row, int column)
{
currow = row;
curcolumn = column;
}
void MainWindow::on_dumpModule_clicked()
{
uintptr_t start = ui->moduleList->item(currow, 1)->text().toLong(nullptr, 16);
uintptr_t end = ui->moduleList->item(currow, 2)->text().toLong(nullptr, 16);
char* buf = (char*)malloc(end - start);
VMemRead(&g_ctx->ctx.process, proc->proc.dirBase, (uint64_t)buf, start, end - start);
QString filename = QFileDialog::getSaveFileName(this, "Dump Module", "~/Documents", "Executables (*.dll *.exe)");
QFile f(filename);
f.open(QIODevice::WriteOnly);
f.write(buf, (end - start));
f.close();
free(buf);
}
void MainWindow::reloadHex(uintptr_t address, uintptr_t size = 16)
{
char buf[4096];
if (VMemRead(&g_ctx->ctx.process, proc->proc.dirBase, (uint64_t)buf, address & ~0xfff, 4096) < 0)
memset(buf, 0, 4096);
QByteArray data(buf, 4096);
hexEdit->setAddressWidth(16);
hexEdit->setData(data);
hexEdit->setAddressOffset(address & ~0xfff);
hexEdit->setCursorPosition(address & 0xfff);
hexEdit->resetSelection((address & 0xfff) * 2);
hexEdit->setSelection(((address + size) & 0xfff) * 2);
}
uintptr_t spaceCount(const char* text)
{
char* t = (char*)text - 1;
uintptr_t c = 0;
while (*(++t) != '\0')
if (*t == ' ')
c++;
return c;
}
void MainWindow::on_findPattern_clicked()
{
uintptr_t start = ui->moduleList->item(currow, 1)->text().toLong(nullptr, 16);
uintptr_t end = ui->moduleList->item(currow, 2)->text().toLong(nullptr, 16);
uintptr_t caddr = ui->curAddress->text().toLong(nullptr, 16);
uintptr_t address = PatternScan::FindPattern(ui->patternField->text().toLatin1(), caddr, end);
if (!address)
address = PatternScan::FindPattern(ui->patternField->text().toLatin1(), start, end);
reloadHex(address, (spaceCount(ui->patternField->text().toLatin1()) + 1));
}
void MainWindow::on_curAddress_returnPressed()
{
uintptr_t addr = ui->curAddress->text().toLong(nullptr, 16);
reloadHex(addr);
}
void MainWindow::on_processName_returnPressed()
{
char* str = strdup(ui->processName->text().toLatin1().data());
int i = 0;
for (auto& p : g_ctx->processList) {
if (!strcmp(p.proc.name, str)) {
ui->processList->setCurrentIndex(i);
return;
}
i++;
}
free(str);
}