-
Notifications
You must be signed in to change notification settings - Fork 0
/
memorywidget.cpp
78 lines (74 loc) · 2.98 KB
/
memorywidget.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
#include "memorywidget.h"
#include "ui_memorywidget.h"
memoryWidget::memoryWidget(std::map<uint64_t, std::map<int, memoryInfo>> *memories,
QStandardItemModel* memModel, QWidget *parent) :
QWidget(parent),
ui(new Ui::memoryWidget)
{
ui->setupUi(this);
this->memories = memories;
memoryViewModel = memModel;
ui->memoryView->setModel(memModel);
ui->memoryContent->setModel(memoryContentModel);
ui->memoryView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->memoryContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->setWindowIcon(QIcon(":/background/icon.ico"));
Qt::WindowFlags m_flags = windowFlags();
setWindowFlags(m_flags | Qt::WindowStaysOnTopHint);
}
memoryWidget::~memoryWidget()
{
delete ui;
}
void memoryWidget::on_memoryView_clicked(const QModelIndex &index)
{
memoryContentModel->clear();
memoryContentModel->setHorizontalHeaderLabels(QStringList() << "偏移" << "内容" << "字符");
if(!index.parent().isValid())
return;
QStandardItem* father = memoryViewModel->item(index.parent().row());
uint64_t addr = father->text().toULongLong(nullptr, 16);
int id = father->child(index.row(), 0)->text().toInt();
auto outer_iter = memories->find(addr);
assert(outer_iter != memories->end());
auto inner_iter = outer_iter->second.find(id);
assert(inner_iter != outer_iter->second.end());
char* buf = inner_iter->second.content;
int length = inner_iter->second.length;
int ptr = 0;
char oneBuffer[4] = {0};
for(int i=0; i<length / 16; i++){
ptr = i << 4;
QString contentLine;
char charsLine[17] = {0};
for(int j=0; j<16; j++){
sprintf_s(oneBuffer, "%02hhx ", buf[ptr + j]);
contentLine += oneBuffer;
if(isprint((unsigned char)buf[ptr + j]))
charsLine[j] = buf[ptr + j];
else
charsLine[j] = '.';
}
memoryContentModel->appendRow(QList<QStandardItem*>() <<
new QStandardItem(ull2a(i << 4)) <<
new QStandardItem(contentLine) <<
new QStandardItem(charsLine));
}
if(length & 15){
QString lastLine;
char charsLastLine[17] = {0};
for(int i=0; ptr + i < length; i++){
sprintf_s(oneBuffer, "%02hhx ", buf[ptr + i]);
lastLine += oneBuffer;
if(isprint((unsigned char)buf[ptr + i]))
charsLastLine[i] = buf[ptr + i];
else
charsLastLine[i] = '.';
}
memoryContentModel->appendRow(QList<QStandardItem*>() <<
new QStandardItem(ull2a(ptr)) <<
new QStandardItem(lastLine) <<
new QStandardItem(charsLastLine));
}
ui->memoryContent->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}