diff --git a/src/core/CutterDescriptions.h b/src/core/CutterDescriptions.h index 12170f92..cf0a4e1c 100644 --- a/src/core/CutterDescriptions.h +++ b/src/core/CutterDescriptions.h @@ -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) diff --git a/src/widgets/HeapDockWidget.cpp b/src/widgets/HeapDockWidget.cpp index 428fb52a..d88071e5 100644 --- a/src/widgets/HeapDockWidget.cpp +++ b/src/widgets/HeapDockWidget.cpp @@ -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(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); } diff --git a/src/widgets/HeapDockWidget.h b/src/widgets/HeapDockWidget.h index 4e507c39..976f8915 100644 --- a/src/widgets/HeapDockWidget.h +++ b/src/widgets/HeapDockWidget.h @@ -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; diff --git a/src/widgets/WindowsHeapWidget.cpp b/src/widgets/WindowsHeapWidget.cpp index 50f30b63..d2b0fc2b 100644 --- a/src/widgets/WindowsHeapWidget.cpp +++ b/src/widgets/WindowsHeapWidget.cpp @@ -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(); +} \ No newline at end of file diff --git a/src/widgets/WindowsHeapWidget.h b/src/widgets/WindowsHeapWidget.h index aa6a6370..d87051ec 100644 --- a/src/widgets/WindowsHeapWidget.h +++ b/src/widgets/WindowsHeapWidget.h @@ -2,21 +2,44 @@ #define WINDOWSHEAPWIDGET_H #include +#include +#include +#include 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 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 diff --git a/src/widgets/WindowsHeapWidget.ui b/src/widgets/WindowsHeapWidget.ui index d00caa18..13473eb4 100644 --- a/src/widgets/WindowsHeapWidget.ui +++ b/src/widgets/WindowsHeapWidget.ui @@ -1,21 +1,24 @@ + - - - - WindowsHeapWidget - - - - 0 - 0 - 400 - 300 - - - - Form - - - - + WindowsHeapWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + +