Added Main function highlighting Fix #124 (#326)

* fix #124
* use cmdj instead of cmd
This commit is contained in:
0xcpy 2018-02-12 09:59:45 +01:00 committed by xarkes
parent b5a2ec74b0
commit b119181757
3 changed files with 19 additions and 3 deletions

View File

@ -119,6 +119,7 @@ void Configuration::loadDefaultTheme()
setColor("gui.alt_background", QColor(245, 250, 255));
// Custom
setColor("gui.imports", colorA);
setColor("gui.main", color2);
setColor("gui.navbar.err", QColor(255, 0, 0));
setColor("gui.navbar.code", QColor(104, 229, 69));
setColor("gui.navbar.str", QColor(69, 104, 229));
@ -213,6 +214,7 @@ void Configuration::loadDarkTheme()
setColor("gui.alt_background", QColor(58, 100, 128));
// Custom
setColor("gui.imports", colorA);
setColor("gui.main", color2);
setColor("gui.navbar.err", QColor(255, 0, 0));
setColor("gui.navbar.code", QColor(104, 229, 69));
setColor("gui.navbar.str", QColor(69, 104, 229));

View File

@ -13,11 +13,13 @@
#include <QString>
#include <QResource>
#include <QShortcut>
#include <QJsonObject>
FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, bool nested, QFont default_font, QFont highlight_font, QObject *parent)
FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, ut64 *mainAdress, bool nested, QFont default_font, QFont highlight_font, QObject *parent)
: QAbstractItemModel(parent),
functions(functions),
importAddresses(importAddresses),
mainAdress(mainAdress),
highlightFont(highlight_font),
defaultFont(default_font),
nested(nested),
@ -75,6 +77,10 @@ bool FunctionModel::functionIsImport(ut64 addr) const
return importAddresses->contains(addr);
}
bool FunctionModel::functionIsMain(ut64 addr) const
{
return *mainAdress == addr;
}
QVariant FunctionModel::data(const QModelIndex &index, int role) const
{
@ -167,6 +173,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
case Qt::ForegroundRole:
if (functionIsImport(function.offset))
return QVariant(ConfigColor("gui.imports"));
if (functionIsMain(function.offset))
return QVariant(ConfigColor("gui.main"));
return QVariant(this->property("color"));
case FunctionDescriptionRole:
@ -361,7 +369,7 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
QFont default_font = QFont(font_info.family(), font_info.pointSize());
QFont highlight_font = QFont(font_info.family(), font_info.pointSize(), QFont::Bold);
functionModel = new FunctionModel(&functions, &importAddresses, false, default_font, highlight_font, this);
functionModel = new FunctionModel(&functions, &importAddresses, &mainAdress, false, default_font, highlight_font, this);
functionProxyModel = new FunctionSortFilterProxyModel(functionModel, this);
ui->functionsTreeView->setModel(functionProxyModel);
ui->functionsTreeView->sortByColumn(FunctionModel::NameColumn, Qt::AscendingOrder);
@ -400,6 +408,8 @@ void FunctionsWidget::refreshTree()
foreach (ImportDescription import, CutterCore::getInstance()->getAllImports())
importAddresses.insert(import.plt);
mainAdress = (ut64)CutterCore::getInstance()->cmdj("iMj").object()["vaddr"].toInt();
functionModel->endReloadFunctions();
// resize offset and size columns

View File

@ -25,6 +25,7 @@ class FunctionModel : public QAbstractItemModel
private:
QList<FunctionDescription> *functions;
QSet<RVA> *importAddresses;
ut64 *mainAdress;
QFont highlightFont;
@ -35,13 +36,15 @@ private:
bool functionIsImport(ut64 addr) const;
bool functionIsMain(ut64 addr) const;
public:
static const int FunctionDescriptionRole = Qt::UserRole;
static const int IsImportRole = Qt::UserRole + 1;
enum Column { NameColumn = 0, SizeColumn, ImportColumn, OffsetColumn, ColumnCount };
FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, bool nested, QFont defaultFont, QFont highlightFont, QObject *parent = 0);
FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, ut64 *mainAdress, bool nested, QFont defaultFont, QFont highlightFont, QObject *parent = 0);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
@ -116,6 +119,7 @@ private:
QList<FunctionDescription> functions;
QSet<RVA> importAddresses;
ut64 mainAdress;
FunctionModel *functionModel;
FunctionSortFilterProxyModel *functionProxyModel;