Added Dialog box for windows heaps and fixed some warnings in sections widget

This commit is contained in:
Pulak Malhotra 2021-07-30 16:45:16 +05:30
parent bd75c45505
commit abee334070
11 changed files with 252 additions and 30 deletions

View File

@ -148,6 +148,7 @@ set(SOURCES
widgets/HeapBinsGraphView.cpp
dialogs/ArenaInfoDialog.cpp
widgets/WindowsHeapWidget.cpp
dialogs/WindowsHeapDialog.cpp
)
set(HEADER_FILES
core/Cutter.h
@ -307,7 +308,8 @@ set(HEADER_FILES
dialogs/GlibcHeapBinsDialog.h
widgets/HeapBinsGraphView.h
dialogs/ArenaInfoDialog.h
widgets/WindowsHeapWidget.h
widgets/WindowsHeapWidget.h
dialogs/WindowsHeapDialog.h
)
set(UI_FILES
dialogs/AboutDialog.ui
@ -379,7 +381,8 @@ set(UI_FILES
widgets/GlibcHeapWidget.ui
dialogs/GlibcHeapBinsDialog.ui
dialogs/ArenaInfoDialog.ui
widgets/WindowsHeapWidget.ui
widgets/WindowsHeapWidget.ui
dialogs/WindowsHeapDialog.ui
)
set(QRC_FILES
resources.qrc

View File

@ -1621,6 +1621,33 @@ QVector<HeapBlock> CutterCore::getHeapBlocks()
return blocks_vector;
}
QVector<WindowsHeapInfo> CutterCore::getWindowsHeaps()
{
CORE_LOCK();
QVector<WindowsHeapInfo> heaps_vector;
RzList *heaps = rz_heap_windows_heap_list(core);
if (!heaps || !rz_list_length(heaps)) {
rz_list_free(heaps);
return heaps_vector;
}
RzListIter *iter;
RzWindowsHeapInfo *data;
CutterRListForeach(heaps, iter, RzWindowsHeapInfo, data)
{
WindowsHeapInfo block;
block.base = data->base;
block.blockCount = data->blockCount;
block.allocated = data->allocated;
block.committed = data->committed;
heaps_vector.append(block);
}
rz_list_free(heaps);
return heaps_vector;
}
int CutterCore::getArchBits()
{
CORE_LOCK();

View File

@ -433,6 +433,7 @@ public:
*/
bool writeHeapChunk(RzHeapChunkSimple *chunkSimple);
QVector<HeapBlock> getHeapBlocks();
QVector<WindowsHeapInfo> getWindowsHeaps();
int getArchBits();
void startDebug();
void startEmulation();

View File

@ -387,12 +387,20 @@ struct HeapBlock
{
RVA headerAddress;
RVA userAddress;
RVA size;
RVA unusedBytes;
RVA granularity;
ut64 size;
ut64 unusedBytes;
ut64 granularity;
QString type;
};
struct WindowsHeapInfo
{
RVA base;
ut64 committed;
ut64 allocated;
ut64 blockCount;
};
Q_DECLARE_METATYPE(FunctionDescription)
Q_DECLARE_METATYPE(ImportDescription)
Q_DECLARE_METATYPE(ExportDescription)

View File

@ -0,0 +1,99 @@
#include "WindowsHeapDialog.h"
#include "ui_WindowsHeapDialog.h"
#include <Cutter.h>
#include <Configuration.h>
WindowsHeapDialog::WindowsHeapDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::WindowsHeapDialog)
{
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);
updateContents();
}
WindowsHeapDialog::~WindowsHeapDialog()
{
delete ui;
}
void WindowsHeapDialog::updateContents()
{
modelHeap->reload();
viewHeap->resizeColumnsToContents();
}
HeapInfoModel::HeapInfoModel(QObject *parent) : QAbstractTableModel(parent) {}
QVariant HeapInfoModel::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 BaseColumn:
return RAddressString(item.base);
case AllocatedColumn:
return item.allocated;
case CommittedColumn:
return item.committed;
case BlockCountColumn:
return item.blockCount;
default:
return QVariant();
}
default:
return QVariant();
}
}
QVariant HeapInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(orientation);
switch (role) {
case Qt::DisplayRole:
switch (section) {
case BaseColumn:
return tr("Base Address");
case AllocatedColumn:
return tr("Allocated");
case CommittedColumn:
return tr("Committed");
case BlockCountColumn:
return tr("Block Count");
default:
return QVariant();
}
default:
return QVariant();
}
}
int HeapInfoModel::columnCount(const QModelIndex &) const
{
return ColumnCount;
}
int HeapInfoModel::rowCount(const QModelIndex &) const
{
return this->values.size();
}
void HeapInfoModel::reload()
{
beginResetModel();
values.clear();
values = Core()->getWindowsHeaps();
endResetModel();
}

View File

@ -0,0 +1,43 @@
#ifndef WINDOWSHEAPDIALOG_H
#define WINDOWSHEAPDIALOG_H
#include <QDialog>
#include <ui_WindowsHeapDialog.h>
#include <CutterDescriptions.h>
namespace Ui {
class WindowsHeapDialog;
}
class HeapInfoModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit HeapInfoModel(QObject *parent = nullptr);
enum Column { BaseColumn = 0, AllocatedColumn, CommittedColumn, BlockCountColumn, 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<WindowsHeapInfo> values;
};
class WindowsHeapDialog : public QDialog
{
Q_OBJECT
public:
explicit WindowsHeapDialog(QWidget *parent);
~WindowsHeapDialog() override;
private slots:
void updateContents();
private:
Ui::WindowsHeapDialog *ui;
QTableView *viewHeap;
HeapInfoModel *modelHeap = new HeapInfoModel(this);
};
#endif // WINDOWSHEAPDIALOG_H

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WindowsHeapDialog</class>
<widget class="QDialog" name="WindowsHeapDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="tableView"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -51,11 +51,12 @@ public:
SectionsModel(QList<SectionDescription> *sections, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
RVA address(const QModelIndex &index) const override;
QString name(const QModelIndex &index) const override;
@ -78,7 +79,7 @@ class SectionsWidget : public ListDockWidget
public:
explicit SectionsWidget(MainWindow *main);
~SectionsWidget();
~SectionsWidget() override;
private slots:
void refreshSections();

View File

@ -1,3 +1,4 @@
#include <dialogs/WindowsHeapDialog.h>
#include "WindowsHeapWidget.h"
#include "ui_WindowsHeapWidget.h"
@ -15,6 +16,7 @@ WindowsHeapWidget::WindowsHeapWidget(MainWindow *main, QWidget *parent)
connect(Core(), &CutterCore::refreshAll, this, &WindowsHeapWidget::updateContents);
connect(Core(), &CutterCore::debugTaskStateChanged, this, &WindowsHeapWidget::updateContents);
connect(ui->heapButton, &QPushButton::clicked, this, &WindowsHeapWidget::viewHeapInfo);
refreshDeferrer = dynamic_cast<CutterDockWidget *>(parent)->createRefreshDeferrer(
[this]() { updateContents(); });
@ -27,6 +29,12 @@ WindowsHeapWidget::~WindowsHeapWidget()
delete ui;
}
void WindowsHeapWidget::viewHeapInfo()
{
WindowsHeapDialog windowsHeapDialog(this);
windowsHeapDialog.exec();
}
void WindowsHeapWidget::updateContents()
{
if (!refreshDeferrer->attemptRefresh(nullptr) || Core()->isDebugTaskInProgress()) {

View File

@ -43,6 +43,7 @@ public:
~WindowsHeapWidget();
private slots:
void updateContents();
void viewHeapInfo();
private:
Ui::WindowsHeapWidget *ui;

View File

@ -1,24 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<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>
<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>
<item>
<widget class="QPushButton" name="heapButton">
<property name="text">
<string>Heaps</string>
</property>
</widget>
<resources/>
<connections/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>