Added ResourcesWidget (fix #259)

This commit is contained in:
xarkes 2018-02-04 15:32:18 +01:00
parent 293078d358
commit 3712cf1529
12 changed files with 254 additions and 82 deletions

View File

@ -64,6 +64,7 @@
#include "widgets/EntrypointWidget.h"
#include "dialogs/SaveProjectDialog.h"
#include "widgets/ClassesWidget.h"
#include "widgets/ResourcesWidget.h"
// graphics
#include <QGraphicsEllipseItem>
@ -87,29 +88,7 @@ static void registerCustomFonts()
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
core(CutterCore::getInstance()),
notepadDock(nullptr),
pseudocodeDock(nullptr),
asmDock(nullptr),
calcDock(nullptr),
omnibar(nullptr),
ui(new Ui::MainWindow),
highlighter(nullptr),
hex_highlighter(nullptr),
visualNavbar(nullptr),
entrypointDock(nullptr),
functionsDock(nullptr),
importsDock(nullptr),
exportsDock(nullptr),
symbolsDock(nullptr),
relocsDock(nullptr),
commentsDock(nullptr),
stringsDock(nullptr),
flagsDock(nullptr),
dashboardDock(nullptr),
gotoEntry(nullptr),
sdbDock(nullptr),
sectionsDock(nullptr),
consoleDock(nullptr)
ui(new Ui::MainWindow)
{
panelLock = false;
tabsOnTop = false;
@ -180,7 +159,7 @@ void MainWindow::initUI()
/*
* Dock Widgets
*/
dockWidgets.reserve(14);
dockWidgets.reserve(20);
#define ADD_DOCK(cls, dockMember, action) \
{ \
@ -243,6 +222,7 @@ void MainWindow::initUI()
ADD_DOCK(Dashboard, dashboardDock, ui->actionDashboard);
ADD_DOCK(SdbDock, sdbDock, ui->actionSDBBrowser);
ADD_DOCK(ClassesWidget, classesDock, ui->actionClasses);
ADD_DOCK(ResourcesWidget, resourcesDock, ui->actionResources);
#undef ADD_DOCK
@ -548,6 +528,7 @@ void MainWindow::restoreDocks()
tabifyDockWidget(dashboardDock, symbolsDock);
tabifyDockWidget(dashboardDock, notepadDock);
tabifyDockWidget(dashboardDock, classesDock);
tabifyDockWidget(dashboardDock, resourcesDock);
updateDockActionsChecked();
}

View File

@ -37,6 +37,7 @@ class ConsoleWidget;
class EntrypointWidget;
class DisassemblerGraphView;
class ClassesWidget;
class ResourcesWidget;
class QDockWidget;
@ -145,48 +146,46 @@ private slots:
void projectSaved(const QString &name);
private:
CutterCore *core;
Notepad *notepadDock;
DisassemblyWidget *disassemblyDock;
SidebarWidget *sidebarDock;
HexdumpWidget *hexdumpDock;
PseudocodeWidget *pseudocodeDock;
QDockWidget *graphDock;
DisassemblerGraphView *graphView;
QDockWidget *asmDock;
QDockWidget *calcDock;
Omnibar *omnibar;
//SideBar *sideBar;
Configuration *configuration;
CutterCore *core;
bool panelLock;
bool tabsOnTop;
ut64 hexdumpTopOffset;
ut64 hexdumpBottomOffset;
QString filename;
std::unique_ptr<Ui::MainWindow> ui;
Highlighter *highlighter;
Highlighter *highlighter;
AsciiHighlighter *hex_highlighter;
VisualNavbar *visualNavbar;
EntrypointWidget *entrypointDock;
FunctionsWidget *functionsDock;
ImportsWidget *importsDock;
ExportsWidget *exportsDock;
SymbolsWidget *symbolsDock;
RelocsWidget *relocsDock;
CommentsWidget *commentsDock;
StringsWidget *stringsDock;
FlagsWidget *flagsDock;
Dashboard *dashboardDock;
QLineEdit *gotoEntry;
SdbDock *sdbDock;
//QAction *sidebar_action;
SectionsDock *sectionsDock;
ConsoleWidget *consoleDock;
ClassesWidget *classesDock;
VisualNavbar *visualNavbar;
Omnibar *omnibar;
Configuration *configuration;
QList<QDockWidget *> dockWidgets;
QMap<QAction *, QDockWidget *> dockWidgetActions;
Notepad *notepadDock = nullptr;
DisassemblyWidget *disassemblyDock = nullptr;
SidebarWidget *sidebarDock = nullptr;
HexdumpWidget *hexdumpDock = nullptr;
PseudocodeWidget *pseudocodeDock = nullptr;
QDockWidget *graphDock = nullptr;
EntrypointWidget *entrypointDock = nullptr;
FunctionsWidget *functionsDock = nullptr;
ImportsWidget *importsDock = nullptr;
ExportsWidget *exportsDock = nullptr;
SymbolsWidget *symbolsDock = nullptr;
RelocsWidget *relocsDock = nullptr;
CommentsWidget *commentsDock = nullptr;
StringsWidget *stringsDock = nullptr;
FlagsWidget *flagsDock = nullptr;
Dashboard *dashboardDock = nullptr;
QLineEdit *gotoEntry = nullptr;
SdbDock *sdbDock = nullptr;
SectionsDock *sectionsDock = nullptr;
ConsoleWidget *consoleDock = nullptr;
ClassesWidget *classesDock = nullptr;
ResourcesWidget *resourcesDock = nullptr;
DisassemblerGraphView *graphView = nullptr;
QDockWidget *asmDock = nullptr;
QDockWidget *calcDock = nullptr;
void toggleDockWidget(QDockWidget *dock_widget, bool show);

View File

@ -249,6 +249,7 @@ border-top: 0px;
<addaction name="actionExports"/>
<addaction name="actionSymbols"/>
<addaction name="actionSDBBrowser"/>
<addaction name="actionResources"/>
<addaction name="separator"/>
<addaction name="actionRelocs"/>
<addaction name="actionStrings"/>
@ -1041,6 +1042,14 @@ QToolButton:pressed {
<string>Analyze</string>
</property>
</action>
<action name="actionResources">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Resources</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -1204,6 +1204,29 @@ QList<ClassDescription> CutterCore::getAllClasses()
return ret;
}
QList<ResourcesDescription> CutterCore::getAllResources()
{
CORE_LOCK();
QList<ResourcesDescription> ret;
QJsonArray resourcesArray = cmdj("iRj").array();
for (QJsonValueRef value : resourcesArray)
{
QJsonObject resourceObject = value.toObject();
ResourcesDescription res;
res.name = resourceObject["name"].toString();
res.vaddr = resourceObject["vaddr"].toVariant().toULongLong();
res.index = resourceObject["index"].toVariant().toULongLong();
res.type = resourceObject["type"].toString();
res.size = resourceObject["size"].toVariant().toULongLong();
res.lang = resourceObject["lang"].toString();
ret << res;
}
return ret;
}
QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_function, const QString &filterType)
{
QList<XrefDescription> ret = QList<XrefDescription>();

View File

@ -195,6 +195,16 @@ struct ClassDescription
QList<ClassFieldDescription> fields;
};
struct ResourcesDescription
{
QString name;
RVA vaddr;
ut64 index;
QString type;
ut64 size;
QString lang;
};
Q_DECLARE_METATYPE(FunctionDescription)
Q_DECLARE_METATYPE(ImportDescription)
Q_DECLARE_METATYPE(ExportDescription)
@ -210,6 +220,7 @@ Q_DECLARE_METATYPE(RBinPluginDescription)
Q_DECLARE_METATYPE(ClassMethodDescription)
Q_DECLARE_METATYPE(ClassFieldDescription)
Q_DECLARE_METATYPE(ClassDescription)
Q_DECLARE_METATYPE(ResourcesDescription)
Q_DECLARE_METATYPE(const ClassDescription *)
Q_DECLARE_METATYPE(const ClassMethodDescription *)
Q_DECLARE_METATYPE(const ClassFieldDescription *)
@ -341,6 +352,7 @@ public:
QList<SectionDescription> getAllSections();
QList<EntrypointDescription> getAllEntrypoint();
QList<ClassDescription> getAllClasses();
QList<ResourcesDescription> getAllResources();
QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function, const QString &filterType = QString::null);

View File

@ -86,7 +86,8 @@ SOURCES += \
dialogs/preferences/GeneralOptionsWidget.cpp \
dialogs/preferences/GraphOptionsWidget.cpp \
widgets/QuickFilterView.cpp \
widgets/ClassesWidget.cpp
widgets/ClassesWidget.cpp \
widgets/ResourcesWidget.cpp
HEADERS += \
cutter.h \
@ -143,7 +144,8 @@ HEADERS += \
dialogs/preferences/GeneralOptionsWidget.h \
dialogs/preferences/GraphOptionsWidget.h \
widgets/QuickFilterView.h \
widgets/ClassesWidget.h
widgets/ClassesWidget.h \
widgets/ResourcesWidget.h
FORMS += \
dialogs/AboutDialog.ui \

View File

@ -3,7 +3,6 @@
#include "ClassesWidget.h"
#include "ui_ClassesWidget.h"
#include "MainWindow.h"
#include "utils/Helpers.h"
ClassesModel::ClassesModel(QList<ClassDescription> *classes, QObject *parent)
@ -243,16 +242,12 @@ bool ClassesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModel
ClassesWidget::ClassesWidget(MainWindow *main, QWidget *parent) :
ClassesWidget::ClassesWidget(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::ClassesWidget),
main(main)
ui(new Ui::ClassesWidget)
{
ui->setupUi(this);
// Radare core found in:
this->main = main;
model = new ClassesModel(&classes, this);
proxy_model = new ClassesSortFilterProxyModel(model, this);
ui->classesTreeView->setModel(proxy_model);

View File

@ -1,5 +1,5 @@
#ifndef CLASSWSWIDGET_H
#define CLASSWSWIDGET_H
#ifndef CLASSESWIDGET_H
#define CLASSESWIDGET_H
#include <memory>
@ -9,16 +9,12 @@
#include <QSortFilterProxyModel>
#include <QDockWidget>
class MainWindow;
class QTreeWidget;
namespace Ui
{
class ClassesWidget;
}
class MainWindow;
class QTreeWidget;
class QTreeWidgetItem;
@ -52,7 +48,7 @@ public:
void endReload();
};
Q_DECLARE_METATYPE(ClassesModel::RowType);
Q_DECLARE_METATYPE(ClassesModel::RowType)
class ClassesSortFilterProxyModel : public QSortFilterProxyModel
@ -74,7 +70,7 @@ class ClassesWidget : public QDockWidget
Q_OBJECT
public:
explicit ClassesWidget(MainWindow *main, QWidget *parent = 0);
explicit ClassesWidget(QWidget *parent = nullptr);
~ClassesWidget();
private slots:
@ -84,7 +80,6 @@ private slots:
private:
std::unique_ptr<Ui::ClassesWidget> ui;
MainWindow *main;
ClassesModel *model;
ClassesSortFilterProxyModel *proxy_model;
@ -92,4 +87,4 @@ private:
};
#endif // CLASSWSWIDGET_H
#endif // CLASSESWIDGET_H

View File

@ -0,0 +1,114 @@
#include "ResourcesWidget.h"
#include <QVBoxLayout>
ResourcesModel::ResourcesModel(QList<ResourcesDescription> *resources, QObject *parent)
: QAbstractListModel(parent),
resources(resources)
{
}
int ResourcesModel::rowCount(const QModelIndex &) const
{
return resources->count();
}
int ResourcesModel::columnCount(const QModelIndex &) const
{
return Columns::COUNT;
}
QVariant ResourcesModel::data(const QModelIndex &index, int role) const
{
const ResourcesDescription *res = &resources->at(index.row());
switch (role)
{
case Qt::DisplayRole:
switch (index.column())
{
case NAME:
return res->name;
case VADDR:
return RAddressString(res->vaddr);
case INDEX:
return res->index;
case TYPE:
return res->type;
case SIZE:
return res->size;
case LANG:
return res->lang;
default:
return QVariant();
}
default:
return QVariant();
}
}
QVariant ResourcesModel::headerData(int section, Qt::Orientation, int role) const
{
switch (role)
{
case Qt::DisplayRole:
switch (section)
{
case NAME:
return tr("Name");
case VADDR:
return tr("Vaddr");
case INDEX:
return tr("Index");
case TYPE:
return tr("Type");
case SIZE:
return tr("Size");
case LANG:
return tr("Lang");
default:
return QVariant();
}
default:
return QVariant();
}
}
void ResourcesModel::beginReload()
{
beginResetModel();
}
void ResourcesModel::endReload()
{
endResetModel();
}
ResourcesWidget::ResourcesWidget(QWidget *parent)
: QDockWidget(parent)
{
model = new ResourcesModel(&resources, this);
// Configure widget
this->setWindowTitle(tr("Resources"));
// Add resources tree view
view = new QTreeView(this);
view->setModel(model);
view->show();
this->setWidget(view);
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshResources()));
connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(onDoubleClicked(const QModelIndex &)));
}
void ResourcesWidget::refreshResources()
{
model->beginReload();
resources = Core()->getAllResources();
model->endReload();
}
void ResourcesWidget::onDoubleClicked(const QModelIndex &index)
{
ResourcesDescription res = index.data().value<ResourcesDescription>();
CutterCore::getInstance()->seek(res.vaddr);
}

View File

@ -0,0 +1,48 @@
#ifndef RESOURCESWIDGET_H
#define RESOURCESWIDGET_H
#include "cutter.h"
#include <QDockWidget>
#include <QAbstractListModel>
#include <QTreeView>
class ResourcesModel : public QAbstractListModel
{
Q_OBJECT
private:
QList<ResourcesDescription> *resources;
public:
enum Columns { INDEX = 0, NAME, VADDR, TYPE, SIZE, LANG, COUNT };
explicit ResourcesModel(QList<ResourcesDescription> *resources, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
void beginReload();
void endReload();
};
class ResourcesWidget : public QDockWidget
{
Q_OBJECT
private:
ResourcesModel *model;
QTreeView *view;
QList<ResourcesDescription> resources;
public:
ResourcesWidget(QWidget *parent = nullptr);
private slots:
void refreshResources();
void onDoubleClicked(const QModelIndex &);
};
#endif // RESOURCESWIDGET_H

View File

@ -79,10 +79,6 @@ void StringsModel::endReload()
endResetModel();
}
StringsSortFilterProxyModel::StringsSortFilterProxyModel(StringsModel *source_model, QObject *parent)
: QSortFilterProxyModel(parent)
{

View File

@ -17,8 +17,6 @@ namespace Ui
class StringsWidget;
}
class StringsModel: public QAbstractListModel
{
Q_OBJECT