Add table and model for windows heap widget

This commit is contained in:
Pulak Malhotra 2021-07-29 15:37:42 +05:30
parent 0de63ffb34
commit ee0b0f5d1d
6 changed files with 144 additions and 24 deletions

View File

@ -383,6 +383,15 @@ struct Arena
ut64 max_system_mem;
};
struct HeapBlock
{
RVA headerAddress;
RVA userAddress;
RVA size;
RVA unused_bytes;
QString type;
};
Q_DECLARE_METATYPE(FunctionDescription)
Q_DECLARE_METATYPE(ImportDescription)
Q_DECLARE_METATYPE(ExportDescription)

View File

@ -1,6 +1,7 @@
#include "HeapDockWidget.h"
#include "ui_HeapDockWidget.h"
#include "widgets/GlibcHeapWidget.h"
#include "WindowsHeapWidget.h"
HeapDockWidget::HeapDockWidget(MainWindow *main)
: CutterDockWidget(main), ui(new Ui::HeapDockWidget), main(main)
@ -8,6 +9,7 @@ HeapDockWidget::HeapDockWidget(MainWindow *main)
ui->setupUi(this);
ui->allocatorSelector->addItem("Glibc Heap");
ui->allocatorSelector->addItem("Windows Heap");
ui->verticalLayout->setMargin(0);
connect<void (QComboBox::*)(int)>(ui->allocatorSelector, &QComboBox::currentIndexChanged, this,
@ -36,6 +38,9 @@ void HeapDockWidget::onAllocatorSelected(int index)
// change widget depending upon selected allocator
if (index == Glibc) {
currentHeapWidget = new GlibcHeapWidget(main, this);
} else if (index == Windows) {
currentHeapWidget = new WindowsHeapWidget(main, this);
}
ui->verticalLayout->addWidget(currentHeapWidget);
}

View File

@ -19,7 +19,7 @@ private slots:
void onAllocatorSelected(int index);
private:
enum Allocator { Glibc = 0, AllocatorCount };
enum Allocator { Glibc = 0, Windows, AllocatorCount };
Ui::HeapDockWidget *ui;
MainWindow *main;
QWidget* currentHeapWidget = nullptr;

View File

@ -1,14 +1,94 @@
#include "WindowsHeapWidget.h"
#include "ui_WindowsHeapWidget.h"
WindowsHeapWidget::WindowsHeapWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::WindowsHeapWidget)
WindowsHeapWidget::WindowsHeapWidget(MainWindow *main, QWidget *parent)
: QWidget(parent), ui(new Ui::WindowsHeapWidget)
{
ui->setupUi(this);
viewHeap = ui->tableView;
viewHeap->setFont(Config()->getFont());
viewHeap->setModel(modelHeap);
viewHeap->verticalHeader()->hide();
// change the scroll mode to ScrollPerPixel
viewHeap->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
viewHeap->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
}
WindowsHeapWidget::~WindowsHeapWidget()
{
delete ui;
}
void WindowsHeapWidget::updateContents()
{
modelHeap->reload();
viewHeap->resizeColumnsToContents();
}
WindowsHeapModel::WindowsHeapModel(QObject *parent) : QAbstractTableModel(parent) {}
QVariant WindowsHeapModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= values.count())
return QVariant();
const auto &item = values.at(index.row());
switch (role) {
case Qt::DisplayRole:
switch (index.column()) {
case HeaderAddColumn:
return RAddressString(item.headerAddress);
case UserAddColumn:
return RAddressString(item.userAddress);
case SizeColumn:
return item.size;
case TypeColumn:
return item.type;
default:
return QVariant();
}
default:
return QVariant();
}
}
QVariant WindowsHeapModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(orientation);
switch (role) {
case Qt::DisplayRole:
switch (section) {
case HeaderAddColumn:
return tr("Header Address");
case UserAddColumn:
return tr("User Address");
case SizeColumn:
return tr("Size");
case TypeColumn:
return tr("Type");
default:
return QVariant();
}
default:
return QVariant();
}
}
int WindowsHeapModel::columnCount(const QModelIndex &) const
{
return ColumnCount;
}
int WindowsHeapModel::rowCount(const QModelIndex &) const
{
return this->values.size();
}
void WindowsHeapModel::reload()
{
beginResetModel();
values.clear();
// Call cutter core here for data
endResetModel();
}

View File

@ -2,21 +2,44 @@
#define WINDOWSHEAPWIDGET_H
#include <QWidget>
#include <QAbstractTableModel>
#include <MainWindow.h>
#include <QTableView>
namespace Ui {
class WindowsHeapWidget;
}
class WindowsHeapModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit WindowsHeapModel(QObject *parent = nullptr);
enum Column { HeaderAddColumn = 0, UserAddColumn, SizeColumn, TypeColumn, ColumnCount };
void reload();
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private:
QVector<HeapBlock> values;
};
class WindowsHeapWidget : public QWidget
{
Q_OBJECT
public:
explicit WindowsHeapWidget(QWidget *parent = nullptr);
explicit WindowsHeapWidget(MainWindow *main, QWidget *parent);
~WindowsHeapWidget();
private slots:
void updateContents();
private:
Ui::WindowsHeapWidget *ui;
QTableView *viewHeap;
WindowsHeapModel *modelHeap = new WindowsHeapModel(this);
};
#endif // WINDOWSHEAPWIDGET_H

View File

@ -1,21 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>WindowsHeapWidget</class>
<widget class="QWidget" name="WindowsHeapWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
<class>WindowsHeapWidget</class>
<widget class="QWidget" name="WindowsHeapWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableView"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>