mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 10:58:51 +00:00
Improved xref widget performances (#1112)
* Improved xref widget performances Removed call to afij that could be very slow. * Deleted destructor definition It is bydefault defined in QObject derived classes so since it's empty we should better ommit it * Use pd-- and readd destructor
This commit is contained in:
parent
00c0994fb5
commit
25b8243f8f
@ -12,8 +12,7 @@ XrefsDialog::XrefsDialog(QWidget *parent) :
|
|||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
addr(0),
|
addr(0),
|
||||||
func_name(QString::null),
|
func_name(QString::null),
|
||||||
ui(new Ui::XrefsDialog),
|
ui(new Ui::XrefsDialog)
|
||||||
core(Core())
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
||||||
@ -30,42 +29,39 @@ XrefsDialog::XrefsDialog(QWidget *parent) :
|
|||||||
|
|
||||||
// Highlight current line
|
// Highlight current line
|
||||||
connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||||
|
|
||||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupPreviewFont()));
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupPreviewFont()));
|
||||||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(setupPreviewColors()));
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(setupPreviewColors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
XrefsDialog::~XrefsDialog() {}
|
XrefsDialog::~XrefsDialog() { }
|
||||||
|
|
||||||
void XrefsDialog::fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs)
|
void XrefsDialog::fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs)
|
||||||
{
|
{
|
||||||
/* Fill refs */
|
// Fill refs
|
||||||
ui->fromTreeWidget->clear();
|
ui->fromTreeWidget->clear();
|
||||||
for (int i = 0; i < refs.size(); ++i) {
|
for (const auto &xref : refs) {
|
||||||
XrefDescription xref = refs[i];
|
auto *tempItem = new QTreeWidgetItem();
|
||||||
|
|
||||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
||||||
tempItem->setText(0, xref.to_str);
|
tempItem->setText(0, xref.to_str);
|
||||||
tempItem->setText(1, core->disassembleSingleInstruction(xref.to));
|
tempItem->setText(1, Core()->disassembleSingleInstruction(xref.to));
|
||||||
tempItem->setText(2, xrefTypeString(xref.type));
|
tempItem->setText(2, xrefTypeString(xref.type));
|
||||||
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
||||||
ui->fromTreeWidget->insertTopLevelItem(0, tempItem);
|
ui->fromTreeWidget->insertTopLevelItem(0, tempItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust columns to content
|
// Adjust columns to content
|
||||||
qhelpers::adjustColumns(ui->fromTreeWidget, 0);
|
qhelpers::adjustColumns(ui->fromTreeWidget, 0);
|
||||||
|
|
||||||
/* Fill Xrefs */
|
// Fill Xrefs
|
||||||
ui->toTreeWidget->clear();
|
ui->toTreeWidget->clear();
|
||||||
for (int i = 0; i < xrefs.size(); ++i) {
|
for (const auto &xref : xrefs) {
|
||||||
XrefDescription xref = xrefs[i];
|
auto *tempItem = new QTreeWidgetItem();
|
||||||
|
|
||||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
||||||
tempItem->setText(0, xref.from_str);
|
tempItem->setText(0, xref.from_str);
|
||||||
tempItem->setText(1, core->disassembleSingleInstruction(xref.from));
|
tempItem->setText(1, Core()->disassembleSingleInstruction(xref.from));
|
||||||
tempItem->setText(2, xrefTypeString(xref.type));
|
tempItem->setText(2, xrefTypeString(xref.type));
|
||||||
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
||||||
ui->toTreeWidget->insertTopLevelItem(0, tempItem);
|
ui->toTreeWidget->insertTopLevelItem(0, tempItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust columns to content
|
// Adjust columns to content
|
||||||
qhelpers::adjustColumns(ui->toTreeWidget, 0);
|
qhelpers::adjustColumns(ui->toTreeWidget, 0);
|
||||||
}
|
}
|
||||||
@ -120,7 +116,7 @@ void XrefsDialog::highlightCurrentLine()
|
|||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
|
|
||||||
if (ui->previewTextEdit->isReadOnly()) {
|
if (ui->previewTextEdit->isReadOnly()) {
|
||||||
QTextEdit::ExtraSelection selection;
|
QTextEdit::ExtraSelection selection = QTextEdit::ExtraSelection();
|
||||||
|
|
||||||
selection.format.setBackground(ConfigColor("highlight"));
|
selection.format.setBackground(ConfigColor("highlight"));
|
||||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
@ -134,8 +130,9 @@ void XrefsDialog::highlightCurrentLine()
|
|||||||
|
|
||||||
void XrefsDialog::on_fromTreeWidget_itemSelectionChanged()
|
void XrefsDialog::on_fromTreeWidget_itemSelectionChanged()
|
||||||
{
|
{
|
||||||
if (ui->fromTreeWidget->selectedItems().isEmpty())
|
if (ui->fromTreeWidget->selectedItems().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ui->toTreeWidget->clearSelection();
|
ui->toTreeWidget->clearSelection();
|
||||||
QTreeWidgetItem *item = ui->fromTreeWidget->currentItem();
|
QTreeWidgetItem *item = ui->fromTreeWidget->currentItem();
|
||||||
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
||||||
@ -144,8 +141,9 @@ void XrefsDialog::on_fromTreeWidget_itemSelectionChanged()
|
|||||||
|
|
||||||
void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
||||||
{
|
{
|
||||||
if (ui->toTreeWidget->selectedItems().isEmpty())
|
if (ui->toTreeWidget->selectedItems().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ui->fromTreeWidget->clearSelection();
|
ui->fromTreeWidget->clearSelection();
|
||||||
QTreeWidgetItem *item = ui->toTreeWidget->currentItem();
|
QTreeWidgetItem *item = ui->toTreeWidget->currentItem();
|
||||||
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
||||||
@ -154,25 +152,15 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
|||||||
|
|
||||||
void XrefsDialog::updatePreview(RVA addr)
|
void XrefsDialog::updatePreview(RVA addr)
|
||||||
{
|
{
|
||||||
// is the address part of a function, so we can use pdf?
|
|
||||||
bool isFunction = !core->cmdj("afij@" + QString::number(addr)).array().isEmpty();
|
|
||||||
|
|
||||||
TempConfig tempConfig;
|
TempConfig tempConfig;
|
||||||
tempConfig.set("scr.html", true);
|
tempConfig.set("scr.html", true);
|
||||||
tempConfig.set("scr.color", COLOR_MODE_16M);
|
tempConfig.set("scr.color", COLOR_MODE_16M);
|
||||||
|
|
||||||
QString disass;
|
QString disas = Core()->cmd("pd--20 @ " + QString::number(addr));
|
||||||
|
ui->previewTextEdit->document()->setHtml(disas);
|
||||||
if (isFunction)
|
|
||||||
disass = core->cmd("pdf @ " + QString::number(addr));
|
|
||||||
else
|
|
||||||
disass = core->cmd("pd 10 @ " + QString::number(addr));
|
|
||||||
|
|
||||||
ui->previewTextEdit->document()->setHtml(disass);
|
|
||||||
|
|
||||||
// Does it make any sense?
|
// Does it make any sense?
|
||||||
ui->previewTextEdit->moveCursor(QTextCursor::End);
|
ui->previewTextEdit->find(normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward);
|
||||||
ui->previewTextEdit->find(this->normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward);
|
|
||||||
ui->previewTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
|
ui->previewTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,18 +176,12 @@ void XrefsDialog::fillRefsForAddress(RVA addr, QString name, bool whole_function
|
|||||||
tempConfig.set("scr.html", false);
|
tempConfig.set("scr.html", false);
|
||||||
tempConfig.set("scr.color", COLOR_MODE_DISABLED);
|
tempConfig.set("scr.color", COLOR_MODE_DISABLED);
|
||||||
|
|
||||||
this->addr = addr;
|
|
||||||
this->func_name = func_name;
|
|
||||||
|
|
||||||
setWindowTitle(tr("X-Refs for %1").arg(name));
|
setWindowTitle(tr("X-Refs for %1").arg(name));
|
||||||
updateLabels(name);
|
updateLabels(name);
|
||||||
|
|
||||||
// Get Refs and Xrefs
|
// Get Refs and Xrefs
|
||||||
|
QList<XrefDescription> refs = Core()->getXRefs(addr, false, whole_function);
|
||||||
// refs = calls q hace esa funcion
|
QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, whole_function);
|
||||||
QList<XrefDescription> refs = core->getXRefs(addr, false, whole_function);
|
|
||||||
|
|
||||||
// xrefs = calls a esa funcion
|
|
||||||
QList<XrefDescription> xrefs = core->getXRefs(addr, true, whole_function);
|
|
||||||
|
|
||||||
fillRefs(refs, xrefs);
|
fillRefs(refs, xrefs);
|
||||||
}
|
}
|
||||||
@ -217,6 +199,9 @@ QString XrefsDialog::xrefTypeString(const QString &type)
|
|||||||
return QString("");
|
return QString("");
|
||||||
case R_ANAL_REF_TYPE_STRING:
|
case R_ANAL_REF_TYPE_STRING:
|
||||||
return QString("String");
|
return QString("String");
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ private:
|
|||||||
QString func_name;
|
QString func_name;
|
||||||
|
|
||||||
std::unique_ptr<Ui::XrefsDialog> ui;
|
std::unique_ptr<Ui::XrefsDialog> ui;
|
||||||
CutterCore *core;
|
|
||||||
|
|
||||||
void fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs);
|
void fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs);
|
||||||
void updateLabels(QString name);
|
void updateLabels(QString name);
|
||||||
|
Loading…
Reference in New Issue
Block a user