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),
|
||||
addr(0),
|
||||
func_name(QString::null),
|
||||
ui(new Ui::XrefsDialog),
|
||||
core(Core())
|
||||
ui(new Ui::XrefsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
||||
@ -30,7 +29,6 @@ XrefsDialog::XrefsDialog(QWidget *parent) :
|
||||
|
||||
// Highlight current line
|
||||
connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||
|
||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupPreviewFont()));
|
||||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(setupPreviewColors()));
|
||||
}
|
||||
@ -39,33 +37,31 @@ XrefsDialog::~XrefsDialog() {}
|
||||
|
||||
void XrefsDialog::fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs)
|
||||
{
|
||||
/* Fill refs */
|
||||
// Fill refs
|
||||
ui->fromTreeWidget->clear();
|
||||
for (int i = 0; i < refs.size(); ++i) {
|
||||
XrefDescription xref = refs[i];
|
||||
|
||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
||||
for (const auto &xref : refs) {
|
||||
auto *tempItem = new QTreeWidgetItem();
|
||||
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->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
||||
ui->fromTreeWidget->insertTopLevelItem(0, tempItem);
|
||||
}
|
||||
|
||||
// Adjust columns to content
|
||||
qhelpers::adjustColumns(ui->fromTreeWidget, 0);
|
||||
|
||||
/* Fill Xrefs */
|
||||
// Fill Xrefs
|
||||
ui->toTreeWidget->clear();
|
||||
for (int i = 0; i < xrefs.size(); ++i) {
|
||||
XrefDescription xref = xrefs[i];
|
||||
|
||||
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
||||
for (const auto &xref : xrefs) {
|
||||
auto *tempItem = new QTreeWidgetItem();
|
||||
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->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
||||
ui->toTreeWidget->insertTopLevelItem(0, tempItem);
|
||||
}
|
||||
|
||||
// Adjust columns to content
|
||||
qhelpers::adjustColumns(ui->toTreeWidget, 0);
|
||||
}
|
||||
@ -120,7 +116,7 @@ void XrefsDialog::highlightCurrentLine()
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
if (ui->previewTextEdit->isReadOnly()) {
|
||||
QTextEdit::ExtraSelection selection;
|
||||
QTextEdit::ExtraSelection selection = QTextEdit::ExtraSelection();
|
||||
|
||||
selection.format.setBackground(ConfigColor("highlight"));
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
@ -134,8 +130,9 @@ void XrefsDialog::highlightCurrentLine()
|
||||
|
||||
void XrefsDialog::on_fromTreeWidget_itemSelectionChanged()
|
||||
{
|
||||
if (ui->fromTreeWidget->selectedItems().isEmpty())
|
||||
if (ui->fromTreeWidget->selectedItems().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ui->toTreeWidget->clearSelection();
|
||||
QTreeWidgetItem *item = ui->fromTreeWidget->currentItem();
|
||||
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
||||
@ -144,8 +141,9 @@ void XrefsDialog::on_fromTreeWidget_itemSelectionChanged()
|
||||
|
||||
void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
||||
{
|
||||
if (ui->toTreeWidget->selectedItems().isEmpty())
|
||||
if (ui->toTreeWidget->selectedItems().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ui->fromTreeWidget->clearSelection();
|
||||
QTreeWidgetItem *item = ui->toTreeWidget->currentItem();
|
||||
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
||||
@ -154,25 +152,15 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
||||
|
||||
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.set("scr.html", true);
|
||||
tempConfig.set("scr.color", COLOR_MODE_16M);
|
||||
|
||||
QString disass;
|
||||
|
||||
if (isFunction)
|
||||
disass = core->cmd("pdf @ " + QString::number(addr));
|
||||
else
|
||||
disass = core->cmd("pd 10 @ " + QString::number(addr));
|
||||
|
||||
ui->previewTextEdit->document()->setHtml(disass);
|
||||
QString disas = Core()->cmd("pd--20 @ " + QString::number(addr));
|
||||
ui->previewTextEdit->document()->setHtml(disas);
|
||||
|
||||
// Does it make any sense?
|
||||
ui->previewTextEdit->moveCursor(QTextCursor::End);
|
||||
ui->previewTextEdit->find(this->normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward);
|
||||
ui->previewTextEdit->find(normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward);
|
||||
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.color", COLOR_MODE_DISABLED);
|
||||
|
||||
this->addr = addr;
|
||||
this->func_name = func_name;
|
||||
|
||||
setWindowTitle(tr("X-Refs for %1").arg(name));
|
||||
updateLabels(name);
|
||||
|
||||
// Get Refs and Xrefs
|
||||
|
||||
// refs = calls q hace esa funcion
|
||||
QList<XrefDescription> refs = core->getXRefs(addr, false, whole_function);
|
||||
|
||||
// xrefs = calls a esa funcion
|
||||
QList<XrefDescription> xrefs = core->getXRefs(addr, true, whole_function);
|
||||
QList<XrefDescription> refs = Core()->getXRefs(addr, false, whole_function);
|
||||
QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, whole_function);
|
||||
|
||||
fillRefs(refs, xrefs);
|
||||
}
|
||||
@ -217,6 +199,9 @@ QString XrefsDialog::xrefTypeString(const QString &type)
|
||||
return QString("");
|
||||
case R_ANAL_REF_TYPE_STRING:
|
||||
return QString("String");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ private:
|
||||
QString func_name;
|
||||
|
||||
std::unique_ptr<Ui::XrefsDialog> ui;
|
||||
CutterCore *core;
|
||||
|
||||
void fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs);
|
||||
void updateLabels(QString name);
|
||||
|
Loading…
Reference in New Issue
Block a user