2017-03-29 10:18:37 +00:00
|
|
|
#ifndef SECTIONSWIDGET_H
|
|
|
|
#define SECTIONSWIDGET_H
|
|
|
|
|
2018-05-03 07:52:30 +00:00
|
|
|
#include <memory>
|
2018-11-12 08:22:28 +00:00
|
|
|
#include <map>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-11-26 11:09:35 +00:00
|
|
|
#include <QtWidgets/QToolButton>
|
2018-05-03 07:52:30 +00:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
2018-11-12 08:22:28 +00:00
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QHash>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2018-05-03 07:52:30 +00:00
|
|
|
#include "CutterDockWidget.h"
|
|
|
|
|
2018-11-10 09:17:52 +00:00
|
|
|
class CutterTreeView;
|
2018-05-03 07:52:30 +00:00
|
|
|
class QAbstractItemView;
|
|
|
|
class MainWindow;
|
2018-10-10 11:33:55 +00:00
|
|
|
class SectionsWidget;
|
2018-12-13 12:24:56 +00:00
|
|
|
class AbstractAddrDock;
|
2018-12-30 16:13:27 +00:00
|
|
|
class AddrDockScene;
|
|
|
|
class QGraphicsSceneMouseEvent;
|
2018-12-13 12:24:56 +00:00
|
|
|
class RawAddrDock;
|
|
|
|
class VirtualAddrDock;
|
2018-10-20 18:20:06 +00:00
|
|
|
class QuickFilterView;
|
2018-11-12 08:22:28 +00:00
|
|
|
class QGraphicsView;
|
|
|
|
class QGraphicsRectItem;
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2018-05-03 07:52:30 +00:00
|
|
|
class SectionsModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2018-10-10 11:33:55 +00:00
|
|
|
friend SectionsWidget;
|
|
|
|
|
2018-05-03 07:52:30 +00:00
|
|
|
private:
|
|
|
|
QList<SectionDescription> *sections;
|
|
|
|
|
|
|
|
public:
|
2019-05-16 10:48:14 +00:00
|
|
|
enum Column { NameColumn = 0, SizeColumn, AddressColumn, EndAddressColumn, PermissionsColumn, EntropyColumn, ColumnCount };
|
2018-05-03 07:52:30 +00:00
|
|
|
enum Role { SectionDescriptionRole = Qt::UserRole };
|
|
|
|
|
2018-05-04 07:58:32 +00:00
|
|
|
SectionsModel(QList<SectionDescription> *sections, QObject *parent = nullptr);
|
2018-05-03 07:52:30 +00:00
|
|
|
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SectionsProxyModel : public QSortFilterProxyModel
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-04 07:58:32 +00:00
|
|
|
SectionsProxyModel(SectionsModel *sourceModel, QObject *parent = nullptr);
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-05-03 07:52:30 +00:00
|
|
|
protected:
|
|
|
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SectionsWidget : public CutterDockWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-05-03 07:52:30 +00:00
|
|
|
public:
|
2018-05-04 07:58:32 +00:00
|
|
|
explicit SectionsWidget(MainWindow *main, QAction *action = nullptr);
|
2018-05-03 07:52:30 +00:00
|
|
|
~SectionsWidget();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void refreshSections();
|
2019-05-16 11:41:53 +00:00
|
|
|
void refreshDocks();
|
|
|
|
|
2018-02-02 15:56:39 +00:00
|
|
|
void onSectionsDoubleClicked(const QModelIndex &index);
|
2019-05-16 11:41:53 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2018-02-02 15:56:39 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
private:
|
2018-05-03 07:52:30 +00:00
|
|
|
QList<SectionDescription> sections;
|
|
|
|
SectionsModel *sectionsModel;
|
2018-11-12 08:22:28 +00:00
|
|
|
SectionsProxyModel *proxyModel;
|
2018-11-10 09:17:52 +00:00
|
|
|
CutterTreeView *sectionsTable;
|
2018-05-03 07:52:30 +00:00
|
|
|
MainWindow *main;
|
2018-10-20 18:20:06 +00:00
|
|
|
QWidget *dockWidgetContents;
|
|
|
|
QuickFilterView *quickFilterView;
|
2018-11-12 08:22:28 +00:00
|
|
|
|
2018-11-26 11:09:35 +00:00
|
|
|
QWidget *addrDockWidget;
|
2018-12-13 12:24:56 +00:00
|
|
|
RawAddrDock *rawAddrDock;
|
|
|
|
VirtualAddrDock *virtualAddrDock;
|
2018-11-26 11:09:35 +00:00
|
|
|
QToolButton *toggleButton;
|
2018-11-12 08:22:28 +00:00
|
|
|
|
2019-05-16 11:41:53 +00:00
|
|
|
/**
|
|
|
|
* RefreshDeferrer for loading the section data
|
|
|
|
*/
|
|
|
|
RefreshDeferrer *sectionsRefreshDeferrer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RefreshDeferrer for updating the visualization docks
|
|
|
|
*/
|
|
|
|
RefreshDeferrer *dockRefreshDeferrer;
|
|
|
|
|
2018-12-13 12:24:56 +00:00
|
|
|
void initSectionsTable();
|
|
|
|
void initQuickFilter();
|
|
|
|
void initConnects();
|
|
|
|
void initAddrMapDocks();
|
2018-11-12 08:22:28 +00:00
|
|
|
void drawIndicatorOnAddrDocks();
|
2018-11-26 11:09:35 +00:00
|
|
|
void updateToggle();
|
2018-11-12 08:22:28 +00:00
|
|
|
};
|
|
|
|
|
2018-12-13 12:24:56 +00:00
|
|
|
class AbstractAddrDock : public QDockWidget
|
2018-11-12 08:22:28 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2018-11-23 07:21:49 +00:00
|
|
|
friend SectionsWidget;
|
|
|
|
|
2018-12-13 12:24:56 +00:00
|
|
|
public:
|
|
|
|
explicit AbstractAddrDock(SectionsModel *model, QWidget *parent = nullptr);
|
|
|
|
~AbstractAddrDock();
|
|
|
|
|
|
|
|
virtual void updateDock();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int indicatorHeight;
|
|
|
|
int indicatorParamPosY;
|
2019-01-07 10:43:44 +00:00
|
|
|
float heightThreshold;
|
|
|
|
float heightDivisor;
|
2018-11-12 08:22:28 +00:00
|
|
|
int rectOffset;
|
2019-05-16 11:41:53 +00:00
|
|
|
int rectWidthMin;
|
|
|
|
int rectWidthMax;
|
2018-11-12 08:22:28 +00:00
|
|
|
QColor indicatorColor;
|
2018-12-13 12:24:56 +00:00
|
|
|
QColor textColor;
|
2018-12-30 16:13:27 +00:00
|
|
|
AddrDockScene *addrDockScene;
|
2018-11-23 07:21:49 +00:00
|
|
|
QGraphicsView *graphicsView;
|
2018-11-12 08:22:28 +00:00
|
|
|
SectionsProxyModel *proxyModel;
|
2018-12-30 16:13:27 +00:00
|
|
|
|
|
|
|
void addTextItem(QColor color, QPoint pos, QString string);
|
2019-01-07 10:43:44 +00:00
|
|
|
int getAdjustedSize(int size, int validMinSize);
|
2019-05-16 11:41:53 +00:00
|
|
|
int getRectWidth();
|
|
|
|
int getIndicatorWidth();
|
2018-12-30 16:13:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void drawIndicator(QString name, float ratio);
|
|
|
|
};
|
|
|
|
|
|
|
|
class AddrDockScene : public QGraphicsScene
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AddrDockScene(QWidget *parent = nullptr);
|
|
|
|
~AddrDockScene();
|
|
|
|
|
|
|
|
bool disableCenterOn;
|
|
|
|
|
|
|
|
QHash<QString, RVA> nameAddrMap;
|
|
|
|
QHash<QString, int> nameAddrSizeMap;
|
|
|
|
QHash<QString, RVA> seekAddrMap;
|
|
|
|
QHash<QString, int> seekAddrSizeMap;
|
2018-11-12 08:22:28 +00:00
|
|
|
QHash<QString, int> namePosYMap;
|
|
|
|
QHash<QString, int> nameHeightMap;
|
2018-12-13 12:24:56 +00:00
|
|
|
|
2018-12-30 16:13:27 +00:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
|
2018-12-13 12:24:56 +00:00
|
|
|
private:
|
2018-12-30 16:13:27 +00:00
|
|
|
RVA getAddrFromPos(int posY, bool seek);
|
2018-12-13 12:24:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RawAddrDock : public AbstractAddrDock
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit RawAddrDock(SectionsModel *model, QWidget *parent = nullptr);
|
|
|
|
~RawAddrDock();
|
|
|
|
|
|
|
|
void updateDock() override;
|
2019-01-07 10:43:44 +00:00
|
|
|
int getValidMinSize();
|
2018-12-13 12:24:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class VirtualAddrDock : public AbstractAddrDock
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit VirtualAddrDock(SectionsModel *model, QWidget *parent = nullptr);
|
|
|
|
~VirtualAddrDock();
|
|
|
|
|
|
|
|
void updateDock() override;
|
2019-01-07 10:43:44 +00:00
|
|
|
int getValidMinSize();
|
2017-03-29 10:18:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SECTIONSWIDGET_H
|