mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
XRefs from JSON Commands
This commit is contained in:
parent
e7f6cdcd8a
commit
af39658da7
@ -27,15 +27,15 @@ XrefsDialog::~XrefsDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs)
|
||||
void XrefsDialog::fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs)
|
||||
{
|
||||
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));
|
||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
||||
tempItem->setText(0, refs.at(i).at(0));
|
||||
tempItem->setText(1, refs.at(i).at(1));
|
||||
tempItem->setText(0, RAddressString(refs.at(i).to));
|
||||
tempItem->setText(1, refs.at(i).opcode);
|
||||
//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);
|
||||
@ -52,8 +52,8 @@ void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs)
|
||||
{
|
||||
//this->add_debug_output(xrefs.at(i).at(0) + " " + xrefs.at(i).at(1));
|
||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
||||
tempItem->setText(0, xrefs.at(i).at(0));
|
||||
tempItem->setText(1, xrefs.at(i).at(1));
|
||||
tempItem->setText(0, RAddressString(xrefs.at(i).from));
|
||||
tempItem->setText(1, xrefs.at(i).opcode);
|
||||
//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);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define XREFSDIALOG_H
|
||||
|
||||
#include "highlighter.h"
|
||||
#include "qrcore.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTreeWidgetItem>
|
||||
@ -21,7 +22,7 @@ public:
|
||||
explicit XrefsDialog(MainWindow *main, QWidget *parent = 0);
|
||||
~XrefsDialog();
|
||||
|
||||
void fillRefs(QList<QStringList> refs, QList<QStringList> xrefs);
|
||||
void fillRefs(QList<XRefDescription> refs, QList<XRefDescription> xrefs);
|
||||
void updateLabels(QString name);
|
||||
|
||||
private slots:
|
||||
|
122
src/qrcore.cpp
122
src/qrcore.cpp
@ -66,47 +66,6 @@ QRCore::QRCore(QObject *parent) :
|
||||
this->db = sdb_new(NULL, NULL, 0); // WTF NOES
|
||||
}
|
||||
|
||||
QList<QString> QRCore::getFunctionXrefs(ut64 addr)
|
||||
{
|
||||
CORE_LOCK();
|
||||
QList<QString> ret = QList<QString>();
|
||||
RList *list = r_anal_xrefs_get(core_->anal, addr);
|
||||
RAnalRef *ref;
|
||||
RListIter *it;
|
||||
QRListForeach(list, it, RAnalRef, ref)
|
||||
{
|
||||
ret << QString("%1,0x%2,0x%3").arg(
|
||||
QString(ref->type),
|
||||
QString::number(ref->addr, 16),
|
||||
QString::number(ref->at, 16));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<QString> QRCore::getFunctionRefs(ut64 addr, char type)
|
||||
{
|
||||
CORE_LOCK();
|
||||
QList<QString> ret = QList<QString>();
|
||||
//RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr);
|
||||
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
|
||||
if (!fcn)
|
||||
{
|
||||
eprintf("qcore->getFunctionRefs: No function found\n");
|
||||
return ret;
|
||||
}
|
||||
//eprintf(fcn->name);
|
||||
RAnalRef *ref;
|
||||
RListIter *it;
|
||||
QRListForeach(fcn->refs, it, RAnalRef, ref)
|
||||
{
|
||||
if (type == ref->type || type == 0)
|
||||
ret << QString("%1,0x%2,0x%3").arg(
|
||||
QString(ref->type),
|
||||
QString::number(ref->addr, 16),
|
||||
QString::number(ref->at, 16));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int QRCore::getCycloComplex(ut64 addr)
|
||||
{
|
||||
@ -1125,3 +1084,84 @@ QList<SectionDescription> QRCore::getAllSections()
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QList<QString> QRCore::getFunctionXrefs(ut64 addr)
|
||||
{
|
||||
CORE_LOCK();
|
||||
QList<QString> ret = QList<QString>();
|
||||
RList *list = r_anal_xrefs_get(core_->anal, addr);
|
||||
RAnalRef *ref;
|
||||
RListIter *it;
|
||||
QRListForeach(list, it, RAnalRef, ref)
|
||||
{
|
||||
ret << QString("%1,0x%2,0x%3").arg(
|
||||
QString(ref->type),
|
||||
QString::number(ref->addr, 16),
|
||||
QString::number(ref->at, 16));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<QString> QRCore::getFunctionRefs(ut64 addr, char type)
|
||||
{
|
||||
CORE_LOCK();
|
||||
QList<QString> ret = QList<QString>();
|
||||
//RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr);
|
||||
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
|
||||
if (!fcn)
|
||||
{
|
||||
eprintf("qcore->getFunctionRefs: No function found\n");
|
||||
return ret;
|
||||
}
|
||||
//eprintf(fcn->name);
|
||||
RAnalRef *ref;
|
||||
RListIter *it;
|
||||
QRListForeach(fcn->refs, it, RAnalRef, ref)
|
||||
{
|
||||
if (type == ref->type || type == 0)
|
||||
ret << QString("%1,0x%2,0x%3").arg(
|
||||
QString(ref->type),
|
||||
QString::number(ref->addr, 16),
|
||||
QString::number(ref->at, 16));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<XRefDescription> QRCore::getXRefs(RVA addr, bool to, const QString &filterType)
|
||||
{
|
||||
QList<XRefDescription> ret = QList<XRefDescription>();
|
||||
|
||||
QJsonArray xrefsArray;
|
||||
|
||||
if (to)
|
||||
xrefsArray = cmdj("axtj@" + QString::number(addr)).array();
|
||||
else
|
||||
xrefsArray = cmdj("axfj@" + QString::number(addr)).array();
|
||||
|
||||
for (QJsonValue value : xrefsArray)
|
||||
{
|
||||
QJsonObject xrefObject = value.toObject();
|
||||
|
||||
XRefDescription xref;
|
||||
xref.type = xrefObject["type"].toString();
|
||||
|
||||
if (!filterType.isNull() && filterType != xref.type)
|
||||
continue;
|
||||
|
||||
xref.from = xrefObject["from"].toVariant().toULongLong();
|
||||
|
||||
if (to && !xrefObject.contains("to"))
|
||||
xref.to = addr;
|
||||
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;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
15
src/qrcore.h
15
src/qrcore.h
@ -134,6 +134,14 @@ struct SectionDescription
|
||||
QString flags;
|
||||
};
|
||||
|
||||
struct XRefDescription
|
||||
{
|
||||
RVA from;
|
||||
RVA to;
|
||||
QString type;
|
||||
QString opcode;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FunctionDescription)
|
||||
Q_DECLARE_METATYPE(ImportDescription)
|
||||
Q_DECLARE_METATYPE(ExportDescription)
|
||||
@ -155,8 +163,6 @@ public:
|
||||
~QRCore();
|
||||
|
||||
RVA getOffset() const { return core_->offset; }
|
||||
QList<QString> getFunctionXrefs(ut64 addr);
|
||||
QList<QString> getFunctionRefs(ut64 addr, char type);
|
||||
int getCycloComplex(ut64 addr);
|
||||
int getFcnSize(ut64 addr);
|
||||
int fcnCyclomaticComplexity(ut64 addr);
|
||||
@ -227,6 +233,11 @@ public:
|
||||
QList<FlagDescription> getAllFlags(QString flagspace = NULL);
|
||||
QList<SectionDescription> getAllSections();
|
||||
|
||||
|
||||
QList<QString> getFunctionXrefs(ut64 addr);
|
||||
QList<QString> getFunctionRefs(ut64 addr, char type);
|
||||
QList<XRefDescription> getXRefs(RVA addr, bool to, const QString &filterType = QString::null);
|
||||
|
||||
RCoreLocked core() const;
|
||||
|
||||
/* fields */
|
||||
|
@ -518,44 +518,14 @@ void FunctionsWidget::on_action_References_triggered()
|
||||
x->setWindowTitle("X-Refs for function " + QString::fromUtf8(fcn->name));
|
||||
|
||||
// Get Refs and Xrefs
|
||||
QList<QStringList> ret_refs;
|
||||
QList<QStringList> ret_xrefs;
|
||||
|
||||
// refs = calls q hace esa funcion
|
||||
QList<QString> refs = this->main->core->getFunctionRefs(fcn->addr, 'C');
|
||||
if (refs.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < refs.size(); ++i)
|
||||
{
|
||||
//this->main->add_debug_output(refs.at(i));
|
||||
QStringList retlist = refs.at(i).split(",");
|
||||
QStringList temp;
|
||||
QString addr = retlist.at(2);
|
||||
temp << addr;
|
||||
QString op = this->main->core->cmd("pi 1 @ " + addr);
|
||||
temp << op.simplified();
|
||||
ret_refs << temp;
|
||||
}
|
||||
}
|
||||
QList<XRefDescription> refs = main->core->getXRefs(fcn->addr, false, "C");
|
||||
|
||||
// xrefs = calls a esa funcion
|
||||
//qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16));
|
||||
QList<QString> xrefs = this->main->core->getFunctionXrefs(fcn->addr);
|
||||
if (xrefs.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < xrefs.size(); ++i)
|
||||
{
|
||||
//this->main->add_debug_output(xrefs.at(i));
|
||||
QStringList retlist = xrefs.at(i).split(",");
|
||||
QStringList temp;
|
||||
QString addr = retlist.at(1);
|
||||
temp << addr;
|
||||
QString op = this->main->core->cmd("pi 1 @ " + addr);
|
||||
temp << op.simplified();
|
||||
ret_xrefs << temp;
|
||||
}
|
||||
}
|
||||
x->fillRefs(ret_refs, ret_xrefs);
|
||||
QList<XRefDescription> xrefs = main->core->getXRefs(fcn->addr, true);
|
||||
|
||||
x->fillRefs(refs, xrefs);
|
||||
x->exec();
|
||||
}
|
||||
|
||||
|
@ -1880,44 +1880,14 @@ void MemoryWidget::on_actionXRefs_triggered()
|
||||
x->updateLabels(QString(fcn->name));
|
||||
|
||||
// Get Refs and Xrefs
|
||||
QList<QStringList> ret_refs;
|
||||
QList<QStringList> ret_xrefs;
|
||||
|
||||
// refs = calls q hace esa funcion
|
||||
QList<QString> refs = this->main->core->getFunctionRefs(fcn->addr, 'C');
|
||||
if (refs.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < refs.size(); ++i)
|
||||
{
|
||||
//this->main->add_debug_output(refs.at(i));
|
||||
QStringList retlist = refs.at(i).split(",");
|
||||
QStringList temp;
|
||||
QString addr = retlist.at(2);
|
||||
temp << addr;
|
||||
QString op = this->main->core->cmd("pi 1 @ " + addr);
|
||||
temp << op.simplified();
|
||||
ret_refs << temp;
|
||||
}
|
||||
}
|
||||
QList<XRefDescription> refs = main->core->getXRefs(fcn->addr, false, "C");
|
||||
|
||||
// xrefs = calls a esa funcion
|
||||
//qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16));
|
||||
QList<QString> xrefs = this->main->core->getFunctionXrefs(fcn->addr);
|
||||
if (xrefs.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < xrefs.size(); ++i)
|
||||
{
|
||||
//this->main->add_debug_output(xrefs.at(i));
|
||||
QStringList retlist = xrefs.at(i).split(",");
|
||||
QStringList temp;
|
||||
QString addr = retlist.at(1);
|
||||
temp << addr;
|
||||
QString op = this->main->core->cmd("pi 1 @ " + addr);
|
||||
temp << op.simplified();
|
||||
ret_xrefs << temp;
|
||||
}
|
||||
}
|
||||
x->fillRefs(ret_refs, ret_xrefs);
|
||||
QList<XRefDescription> xrefs = main->core->getXRefs(fcn->addr, true);
|
||||
|
||||
x->fillRefs(refs, xrefs);
|
||||
x->exec();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user