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();
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();
tempItem->setText(0, RAddressString(refs.at(i).to));
tempItem->setText(1, refs.at(i).opcode);
tempItem->setText(0, RAddressString(xref.to));
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( 1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) );
ui->fromTreeWidget->insertTopLevelItem(0, tempItem);
}
// Adjust columns to content
@ -50,12 +53,15 @@ void XrefsDialog::fillRefs(QList<XRefDescription> refs, QList<XRefDescription> x
ui->toTreeWidget->clear();
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();
tempItem->setText(0, RAddressString(xrefs.at(i).from));
tempItem->setText(1, xrefs.at(i).opcode);
tempItem->setText(0, RAddressString(xref.from));
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( 1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) );
ui->toTreeWidget->insertTopLevelItem(0, tempItem);
}
// Adjust columns to content
@ -152,6 +158,21 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
void XrefsDialog::updateLabels(QString name)
{
ui->label_2->setText(ui->label_2->text() + name);
ui->label_3->setText(ui->label_3->text() + name);
ui->label_2->setText(tr("X-Refs to %1:").arg(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);
~XrefsDialog();
void fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs);
void updateLabels(QString name);
void fillRefsForFunction(RVA addr, QString name);
private slots:
@ -44,6 +43,9 @@ private:
Highlighter *highlighter;
void fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs);
void updateLabels(QString name);
};
#endif // XREFSDIALOG_H

View File

@ -398,6 +398,8 @@ bool QRCore::tryFile(QString path, bool rw)
return true;
}
QList<QString> QRCore::getList(const QString &type, const QString &subtype)
{
CORE_LOCK();
@ -563,6 +565,11 @@ QString QRCore::disassemble(const QString &hex)
return code;
}
QString QRCore::disassembleSingleInstruction(RVA addr)
{
return cmd("pi 1@" + QString::number(addr)).simplified();
}
RAnalFunction *QRCore::functionAt(ut64 addr)
{
CORE_LOCK();
@ -1156,10 +1163,6 @@ QList<XRefDescription> QRCore::getXRefs(RVA addr, bool to, const QString &filter
else
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;
}

View File

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

View File

@ -508,24 +508,8 @@ void FunctionsWidget::on_action_References_triggered()
// Get selected item in functions tree view
QTreeView *treeView = getCurrentTreeView();
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);
x->setWindowTitle("X-Refs for function " + QString::fromUtf8(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->fillRefsForFunction(function.offset, function.name);
x->exec();
}

View File

@ -1876,18 +1876,7 @@ void MemoryWidget::on_actionXRefs_triggered()
return;
}
XrefsDialog *x = new XrefsDialog(this->main, this);
x->setWindowTitle("X-Refs for function " + QString(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->fillRefsForFunction(fcn->addr, QString::fromUtf8(fcn->name));
x->exec();
}
}

View File

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