Use API to fetch xrefs in CutterCore::getXRefs() (#2771)

This commit is contained in:
Paul I 2021-09-22 20:19:38 +03:00 committed by GitHub
parent 35de2ae413
commit 82e8896267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3731,51 +3731,36 @@ QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_functi
{ {
QList<XrefDescription> xrefList = QList<XrefDescription>(); QList<XrefDescription> xrefList = QList<XrefDescription>();
QJsonArray xrefsArray; RzList *xrefs = nullptr;
{
CORE_LOCK();
if (to) { if (to) {
xrefsArray = cmdj("axtj@" + QString::number(addr)).array(); xrefs = rz_analysis_xrefs_get_to(core->analysis, addr);
} else { } else {
xrefsArray = cmdj("axfj@" + QString::number(addr)).array(); xrefs = rz_analysis_xrefs_get_from(core->analysis, addr);
}
} }
for (const QJsonValue &value : xrefsArray) { RzListIter *it;
QJsonObject xrefObject = value.toObject(); RzAnalysisXRef *xref;
CutterRzListForeach (xrefs, it, RzAnalysisXRef, xref) {
XrefDescription xd;
xd.from = xref->from;
xd.to = xref->to;
xd.type = rz_analysis_xrefs_type_tostring(xref->type);
XrefDescription xref; if (!filterType.isNull() && filterType != xd.type)
xref.type = xrefObject[RJsonKey::type].toString();
if (!filterType.isNull() && filterType != xref.type)
continue; continue;
if (!whole_function && !to && xd.from != addr) {
xref.from = xrefObject[RJsonKey::from].toVariant().toULongLong();
if (!to) {
xref.from_str = RzAddressString(xref.from);
} else {
QString fcn = xrefObject[RJsonKey::fcn_name].toString();
if (!fcn.isEmpty()) {
RVA fcnAddr = xrefObject[RJsonKey::fcn_addr].toVariant().toULongLong();
xref.from_str = fcn + " + 0x" + QString::number(xref.from - fcnAddr, 16);
} else {
xref.from_str = RzAddressString(xref.from);
}
}
if (!whole_function && !to && xref.from != addr) {
continue; continue;
} }
if (to && !xrefObject.contains(RJsonKey::to)) { xd.from_str = RzAddressString(xd.from);
xref.to = addr; xd.to_str = Core()->cmdRaw(QString("fd %1").arg(xd.to)).trimmed();
} else {
xref.to = xrefObject[RJsonKey::to].toVariant().toULongLong();
}
xref.to_str = Core()->cmdRaw(QString("fd %1").arg(xref.to)).trimmed();
xrefList << xref; xrefList << xd;
} }
rz_list_free(xrefs);
return xrefList; return xrefList;
} }