2018-02-04 14:32:18 +00:00
|
|
|
#ifndef CLASSESWIDGET_H
|
|
|
|
#define CLASSESWIDGET_H
|
2017-12-23 16:42:42 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-03-04 17:42:02 +00:00
|
|
|
#include "Cutter.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
#include "CutterDockWidget.h"
|
2017-12-23 16:42:42 +00:00
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
namespace Ui {
|
|
|
|
class ClassesWidget;
|
2017-12-23 16:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 14:32:18 +00:00
|
|
|
class QTreeWidget;
|
2017-12-23 16:42:42 +00:00
|
|
|
class QTreeWidgetItem;
|
2018-03-16 21:46:57 +00:00
|
|
|
class MainWindow;
|
2018-10-10 11:33:55 +00:00
|
|
|
class ClassesWidget;
|
2017-12-23 16:42:42 +00:00
|
|
|
|
2019-02-02 13:14:39 +00:00
|
|
|
/*!
|
|
|
|
* \brief Common abstract base class for Bin and Anal classes models
|
|
|
|
*/
|
2017-12-23 16:42:42 +00:00
|
|
|
class ClassesModel: public QAbstractItemModel
|
|
|
|
{
|
|
|
|
public:
|
2018-08-17 11:27:07 +00:00
|
|
|
enum Columns { NAME = 0, TYPE, OFFSET, VTABLE, COUNT };
|
2019-02-02 13:14:39 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief values for TypeRole data
|
|
|
|
*/
|
2019-02-01 16:10:05 +00:00
|
|
|
enum class RowType { Class = 0, Base, VTable, Method, Field };
|
2017-12-23 16:42:42 +00:00
|
|
|
|
2019-02-02 13:14:39 +00:00
|
|
|
/*!
|
|
|
|
* \brief Offset role of data for QModelIndex
|
|
|
|
*
|
|
|
|
* will contain values of type RVA
|
|
|
|
*/
|
2017-12-23 16:42:42 +00:00
|
|
|
static const int OffsetRole = Qt::UserRole;
|
2019-02-02 13:14:39 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Name role of data for QModelIndex
|
|
|
|
*
|
|
|
|
* will contain values of QString, used for sorting,
|
|
|
|
* as well as identifying classes and methods
|
|
|
|
*/
|
2017-12-23 16:42:42 +00:00
|
|
|
static const int NameRole = Qt::UserRole + 1;
|
2019-02-02 13:14:39 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Type role of data for QModelIndex
|
|
|
|
*
|
|
|
|
* will contain values of RowType
|
|
|
|
*/
|
2017-12-23 16:42:42 +00:00
|
|
|
static const int TypeRole = Qt::UserRole + 2;
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
explicit ClassesModel(QObject *parent = nullptr) : QAbstractItemModel(parent) {}
|
|
|
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
|
|
|
int role = Qt::DisplayRole) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(ClassesModel::RowType)
|
|
|
|
|
|
|
|
class BinClassesModel: public ClassesModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<BinClassDescription> classes;
|
2017-12-23 16:42:42 +00:00
|
|
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
QModelIndex parent(const QModelIndex &index) const override;
|
2017-12-23 16:42:42 +00:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2018-08-17 11:27:07 +00:00
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
2018-08-17 11:27:07 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2017-12-23 16:42:42 +00:00
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
public:
|
|
|
|
explicit BinClassesModel(QObject *parent = nullptr);
|
|
|
|
void setClasses(const QList<BinClassDescription> &classes);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AnalClassesModel: public ClassesModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2019-02-02 13:14:39 +00:00
|
|
|
/*!
|
|
|
|
* \brief List entry below a class
|
|
|
|
*
|
|
|
|
* This roughly corresponds to attributes of r2 anal classes, which means it is not an attribute in the sense of
|
|
|
|
* a class member variable, but any kind of sub-info associated with the class.
|
|
|
|
* This struct in particular is used to provide a model for the list entries below a class.
|
|
|
|
*/
|
2019-02-01 14:51:29 +00:00
|
|
|
struct Attribute
|
|
|
|
{
|
|
|
|
enum class Type { VTable, Base, Method };
|
|
|
|
Type type;
|
|
|
|
QVariant data;
|
|
|
|
|
|
|
|
Attribute() = default;
|
|
|
|
Attribute(Type type, const QVariant &data) : type(type), data(data) {}
|
|
|
|
};
|
|
|
|
|
2019-02-07 10:42:53 +00:00
|
|
|
/*!
|
|
|
|
* This must always stay sorted alphabetically.
|
|
|
|
*/
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<QString> classes;
|
2019-02-02 13:14:39 +00:00
|
|
|
|
2019-02-07 10:42:53 +00:00
|
|
|
RefreshDeferrer *refreshDeferrer;
|
|
|
|
|
2019-02-02 13:14:39 +00:00
|
|
|
/*!
|
|
|
|
* \brief Cache for class attributes
|
|
|
|
*
|
|
|
|
* Maps class names to a list of Attributes.
|
|
|
|
* This is filled only when the attributes of a specific class are requested.
|
|
|
|
* (i.e. the user expands the class in the QTreeView)
|
|
|
|
*
|
|
|
|
* This must be a pointer instead of just a QMap, because it has to be modified
|
|
|
|
* in methods that are defined as const by QAbstractItemModel.
|
|
|
|
*/
|
2019-02-01 14:51:29 +00:00
|
|
|
std::unique_ptr<QMap<QString, QVector<Attribute>>> attrs;
|
|
|
|
|
|
|
|
const QVector<Attribute> &getAttrs(const QString &cls) const;
|
2018-08-17 11:27:07 +00:00
|
|
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
|
|
QModelIndex parent(const QModelIndex &index) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
2017-12-23 16:42:42 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2018-08-17 11:27:07 +00:00
|
|
|
|
|
|
|
public:
|
2019-02-07 10:42:53 +00:00
|
|
|
explicit AnalClassesModel(CutterDockWidget *parent);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void refreshAll();
|
|
|
|
void classNew(const QString &cls);
|
|
|
|
void classDeleted(const QString &cls);
|
|
|
|
void classRenamed(const QString &oldName, const QString &newName);
|
|
|
|
void classAttrsChanged(const QString &cls);
|
2017-12-23 16:42:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClassesSortFilterProxyModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-08-17 11:27:07 +00:00
|
|
|
explicit ClassesSortFilterProxyModel(QObject *parent = nullptr);
|
2017-12-23 16:42:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
|
|
|
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
2019-02-01 16:10:05 +00:00
|
|
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
2017-12-23 16:42:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
class ClassesWidget : public CutterDockWidget
|
2017-12-23 16:42:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-03-16 21:46:57 +00:00
|
|
|
explicit ClassesWidget(MainWindow *main, QAction *action = nullptr);
|
2017-12-23 16:42:42 +00:00
|
|
|
~ClassesWidget();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_classesTreeView_doubleClicked(const QModelIndex &index);
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
void on_seekToVTableAction_triggered();
|
|
|
|
void on_addMethodAction_triggered();
|
|
|
|
void on_editMethodAction_triggered();
|
2019-02-07 12:40:41 +00:00
|
|
|
void on_newClassAction_triggered();
|
|
|
|
void on_deleteClassAction_triggered();
|
|
|
|
void on_renameClassAction_triggered();
|
2018-08-17 11:27:07 +00:00
|
|
|
|
|
|
|
void showContextMenu(const QPoint &pt);
|
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
void refreshClasses();
|
|
|
|
|
|
|
|
private:
|
2018-08-17 11:27:07 +00:00
|
|
|
enum class Source { BIN, ANAL };
|
2018-03-11 15:57:38 +00:00
|
|
|
|
|
|
|
Source getSource();
|
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
std::unique_ptr<Ui::ClassesWidget> ui;
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassesModel *bin_model = nullptr;
|
|
|
|
AnalClassesModel *anal_model = nullptr;
|
2017-12-23 16:42:42 +00:00
|
|
|
ClassesSortFilterProxyModel *proxy_model;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-04 14:32:18 +00:00
|
|
|
#endif // CLASSESWIDGET_H
|