Refactor XrefsDialog

This commit is contained in:
Florian Märkl 2017-06-07 17:48:36 +02:00 committed by radare
parent af39658da7
commit 132cebf8a1
7 changed files with 60 additions and 75 deletions

View File

@ -32,12 +32,15 @@ void XrefsDialog::fillRefs(QList<XRefDescription> refs, QList<XRefDescription> x
ui->fromTreeWidget->clear(); ui->fromTreeWidget->clear();
for (int i = 0; i < refs.size(); ++i) for (int i = 0; i < refs.size(); ++i)
{ {
//this->add_debug_output(refs.at(i).at(0) + " " + refs.at(i).at(1)); XRefDescription xref = refs[i];
QTreeWidgetItem *tempItem = new QTreeWidgetItem(); QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, RAddressString(refs.at(i).to)); tempItem->setText(0, RAddressString(xref.to));
tempItem->setText(1, refs.at(i).opcode); tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from));
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
//tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); //tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) );
//tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); //tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) );
ui->fromTreeWidget->insertTopLevelItem(0, tempItem); ui->fromTreeWidget->insertTopLevelItem(0, tempItem);
} }
// Adjust columns to content // Adjust columns to content
@ -50,12 +53,15 @@ void XrefsDialog::fillRefs(QList<XRefDescription> refs, QList<XRefDescription> x
ui->toTreeWidget->clear(); ui->toTreeWidget->clear();
for (int i = 0; i < xrefs.size(); ++i) for (int i = 0; i < xrefs.size(); ++i)
{ {
//this->add_debug_output(xrefs.at(i).at(0) + " " + xrefs.at(i).at(1)); XRefDescription xref = xrefs[i];
QTreeWidgetItem *tempItem = new QTreeWidgetItem(); QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, RAddressString(xrefs.at(i).from)); tempItem->setText(0, RAddressString(xref.from));
tempItem->setText(1, xrefs.at(i).opcode); tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from));
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
//tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); //tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) );
//tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); //tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) );
ui->toTreeWidget->insertTopLevelItem(0, tempItem); ui->toTreeWidget->insertTopLevelItem(0, tempItem);
} }
// Adjust columns to content // Adjust columns to content
@ -152,6 +158,21 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
void XrefsDialog::updateLabels(QString name) void XrefsDialog::updateLabels(QString name)
{ {
ui->label_2->setText(ui->label_2->text() + name); ui->label_2->setText(tr("X-Refs to %1:").arg(name));
ui->label_3->setText(ui->label_3->text() + name); ui->label_3->setText(tr("X-Refs from %1:").arg(name));
}
void XrefsDialog::fillRefsForFunction(RVA addr, QString name)
{
setWindowTitle(tr("X-Refs for function %1").arg(name));
updateLabels(name);
// Get Refs and Xrefs
// refs = calls q hace esa funcion
QList<XRefDescription> refs = main->core->getXRefs(addr, false, "C");
// xrefs = calls a esa funcion
QList<XRefDescription> xrefs = main->core->getXRefs(addr, true);
fillRefs(refs, xrefs);
} }

View File

@ -22,8 +22,7 @@ public:
explicit XrefsDialog(MainWindow *main, QWidget *parent = 0); explicit XrefsDialog(MainWindow *main, QWidget *parent = 0);
~XrefsDialog(); ~XrefsDialog();
void fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs); void fillRefsForFunction(RVA addr, QString name);
void updateLabels(QString name);
private slots: private slots:
@ -44,6 +43,9 @@ private:
Highlighter *highlighter; Highlighter *highlighter;
void fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs);
void updateLabels(QString name);
}; };
#endif // XREFSDIALOG_H #endif // XREFSDIALOG_H

View File

@ -398,6 +398,8 @@ bool QRCore::tryFile(QString path, bool rw)
return true; return true;
} }
QList<QString> QRCore::getList(const QString &type, const QString &subtype) QList<QString> QRCore::getList(const QString &type, const QString &subtype)
{ {
CORE_LOCK(); CORE_LOCK();
@ -563,6 +565,11 @@ QString QRCore::disassemble(const QString &hex)
return code; return code;
} }
QString QRCore::disassembleSingleInstruction(RVA addr)
{
return cmd("pi 1@" + QString::number(addr)).simplified();
}
RAnalFunction *QRCore::functionAt(ut64 addr) RAnalFunction *QRCore::functionAt(ut64 addr)
{ {
CORE_LOCK(); CORE_LOCK();
@ -1156,10 +1163,6 @@ QList<XRefDescription> QRCore::getXRefs(RVA addr, bool to, const QString &filter
else else
xref.to = xrefObject["to"].toVariant().toULongLong(); xref.to = xrefObject["to"].toVariant().toULongLong();
xref.opcode = xrefObject["opcode"].toString();
printf("xref %s %s\n", to ? "to" : "from", xref.opcode.toLocal8Bit().constData());
ret << xref; ret << xref;
} }

View File

@ -139,7 +139,6 @@ struct XRefDescription
RVA from; RVA from;
RVA to; RVA to;
QString type; QString type;
QString opcode;
}; };
Q_DECLARE_METATYPE(FunctionDescription) Q_DECLARE_METATYPE(FunctionDescription)
@ -151,6 +150,7 @@ Q_DECLARE_METATYPE(RelocDescription)
Q_DECLARE_METATYPE(StringDescription) Q_DECLARE_METATYPE(StringDescription)
Q_DECLARE_METATYPE(FlagspaceDescription) Q_DECLARE_METATYPE(FlagspaceDescription)
Q_DECLARE_METATYPE(FlagDescription) Q_DECLARE_METATYPE(FlagDescription)
Q_DECLARE_METATYPE(XRefDescription)
class QRCore : public QObject class QRCore : public QObject
{ {
@ -187,6 +187,7 @@ public:
int config(const QString &k, int v); int config(const QString &k, int v);
QString assemble(const QString &code); QString assemble(const QString &code);
QString disassemble(const QString &hex); QString disassemble(const QString &hex);
QString disassembleSingleInstruction(RVA addr);
void setDefaultCPU(); void setDefaultCPU();
void setCPU(QString arch, QString cpu, int bits, bool temporary = false); void setCPU(QString arch, QString cpu, int bits, bool temporary = false);
RAnalFunction *functionAt(ut64 addr); RAnalFunction *functionAt(ut64 addr);

View File

@ -508,24 +508,8 @@ void FunctionsWidget::on_action_References_triggered()
// Get selected item in functions tree view // Get selected item in functions tree view
QTreeView *treeView = getCurrentTreeView(); QTreeView *treeView = getCurrentTreeView();
FunctionDescription function = treeView->selectionModel()->currentIndex().data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>(); FunctionDescription function = treeView->selectionModel()->currentIndex().data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>();
//this->main->add_debug_output("Addr: " + address);
// Get function for clicked offset
RAnalFunction *fcn = this->main->core->functionAt(function.offset);
XrefsDialog *x = new XrefsDialog(this->main, this); XrefsDialog *x = new XrefsDialog(this->main, this);
x->setWindowTitle("X-Refs for function " + QString::fromUtf8(fcn->name)); x->fillRefsForFunction(function.offset, function.name);
// Get Refs and Xrefs
// refs = calls q hace esa funcion
QList<XRefDescription> refs = main->core->getXRefs(fcn->addr, false, "C");
// xrefs = calls a esa funcion
QList<XRefDescription> xrefs = main->core->getXRefs(fcn->addr, true);
x->fillRefs(refs, xrefs);
x->exec(); x->exec();
} }

View File

@ -1876,18 +1876,7 @@ void MemoryWidget::on_actionXRefs_triggered()
return; return;
} }
XrefsDialog *x = new XrefsDialog(this->main, this); XrefsDialog *x = new XrefsDialog(this->main, this);
x->setWindowTitle("X-Refs for function " + QString(fcn->name)); x->fillRefsForFunction(fcn->addr, QString::fromUtf8(fcn->name));
x->updateLabels(QString(fcn->name));
// Get Refs and Xrefs
// refs = calls q hace esa funcion
QList<XRefDescription> refs = main->core->getXRefs(fcn->addr, false, "C");
// xrefs = calls a esa funcion
QList<XRefDescription> xrefs = main->core->getXRefs(fcn->addr, true);
x->fillRefs(refs, xrefs);
x->exec(); x->exec();
} }
} }

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>950</width> <width>990</width>
<height>767</height> <height>767</height>
</rect> </rect>
</property> </property>
@ -933,7 +933,7 @@ QToolTip {
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebEngineView" name="webSimpleGraph" native="true"> <widget class="QWebEngineView" name="webSimpleGraph">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -954,7 +954,7 @@ QToolTip {
font: 11pt &quot;Monaco&quot;; font: 11pt &quot;Monaco&quot;;
}</string> }</string>
</property> </property>
<property name="url" stdset="0"> <property name="url">
<url> <url>
<string>about:blank</string> <string>about:blank</string>
</url> </url>
@ -1229,16 +1229,16 @@ p, li { white-space: pre-wrap; }
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebEngineView" name="graphWebView" native="true"> <widget class="QWebEngineView" name="graphWebView">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum> <enum>Qt::DefaultContextMenu</enum>
</property> </property>
<property name="url" stdset="0"> <property name="url">
<url> <url>
<string>about:blank</string> <string>about:blank</string>
</url> </url>
</property> </property>
<property name="zoomFactor" stdset="0"> <property name="zoomFactor">
<double>1.000000000000000</double> <double>1.000000000000000</double>
</property> </property>
</widget> </widget>
@ -1325,9 +1325,9 @@ border-top: 0px;
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-175</y>
<width>257</width> <width>256</width>
<height>885</height> <height>887</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1629,7 +1629,7 @@ QToolTip {
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebEngineView" name="fcnWebView" native="true"> <widget class="QWebEngineView" name="fcnWebView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1648,7 +1648,7 @@ QToolTip {
<height>250</height> <height>250</height>
</size> </size>
</property> </property>
<property name="url" stdset="0"> <property name="url">
<url> <url>
<string>qrc:/html/fcn_graph.html</string> <string>qrc:/html/fcn_graph.html</string>
</url> </url>
@ -1678,7 +1678,7 @@ QToolTip {
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebEngineView" name="radarGraphWebView" native="true"> <widget class="QWebEngineView" name="radarGraphWebView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1697,7 +1697,7 @@ QToolTip {
<height>250</height> <height>250</height>
</size> </size>
</property> </property>
<property name="url" stdset="0"> <property name="url">
<url> <url>
<string>qrc:/html/fcn_radar.html</string> <string>qrc:/html/fcn_radar.html</string>
</url> </url>
@ -1770,11 +1770,6 @@ QToolTip {
<height>175</height> <height>175</height>
</size> </size>
</property> </property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -1926,11 +1921,6 @@ color: rgb(0, 0, 0);</string>
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QTreeWidget::item <string notr="true">QTreeWidget::item
{ {
@ -2036,11 +2026,6 @@ QToolTip {
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QTreeWidget::item <string notr="true">QTreeWidget::item
{ {
@ -3038,7 +3023,7 @@ QToolTip {
<customwidget> <customwidget>
<class>QWebEngineView</class> <class>QWebEngineView</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>QtWebEngineWidgets/QWebEngineView</header> <header location="global">QtWebEngineWidgets/QWebEngineView</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
@ -3046,8 +3031,8 @@ QToolTip {
</resources> </resources>
<connections/> <connections/>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup_3"/>
<buttongroup name="buttonGroup"/> <buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_3"/>
<buttongroup name="buttonGroup_2"/>
</buttongroups> </buttongroups>
</ui> </ui>