From 436c2ee89ca10ea1025d97b3c69e0b7a65078757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 15 Apr 2019 13:14:46 +0200 Subject: [PATCH] Fallback to current offset in LinkTypeDialog (#1458) --- src/dialogs/LinkTypeDialog.cpp | 14 ++++++++++---- src/dialogs/LinkTypeDialog.h | 5 ++++- src/menus/DisassemblyContextMenu.cpp | 4 +++- src/widgets/TypesWidget.cpp | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/dialogs/LinkTypeDialog.cpp b/src/dialogs/LinkTypeDialog.cpp index 4a68fedc..824bc7cc 100644 --- a/src/dialogs/LinkTypeDialog.cpp +++ b/src/dialogs/LinkTypeDialog.cpp @@ -5,6 +5,8 @@ LinkTypeDialog::LinkTypeDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LinkTypeDialog) { + addrValid = false; + ui->setupUi(this); setWindowTitle(tr("Link type to address")); @@ -30,12 +32,13 @@ void LinkTypeDialog::setDefaultType(const QString &type) } } -void LinkTypeDialog::setDefaultAddress(QString address) +bool LinkTypeDialog::setDefaultAddress(const QString &address) { + // setting the text here will trigger on_exprLineEdit_textChanged, which will update addrValid ui->exprLineEdit->setText(address); - if (ui->addressLineEdit->text() == tr("Invalid Address")) { - return; + if (!addrValid) { + return false; } // check if the current address is already linked to a type and set it as default @@ -43,6 +46,7 @@ void LinkTypeDialog::setDefaultAddress(QString address) if (!type.isEmpty()) { setDefaultType(type); } + return true; } @@ -99,8 +103,10 @@ void LinkTypeDialog::on_exprLineEdit_textChanged(const QString &text) { RVA addr = Core()->math(text); if (Core()->isAddressMapped(addr)) { - ui->addressLineEdit->setText("0x" + QString::number(addr, 16)); + ui->addressLineEdit->setText(RAddressString(addr)); + addrValid = true; } else { ui->addressLineEdit->setText(tr("Invalid Address")); + addrValid = false; } } diff --git a/src/dialogs/LinkTypeDialog.h b/src/dialogs/LinkTypeDialog.h index f5fbc972..4f914805 100644 --- a/src/dialogs/LinkTypeDialog.h +++ b/src/dialogs/LinkTypeDialog.h @@ -27,8 +27,9 @@ public: * If the given address is linked to a type, then it also sets the default * type to the currently linked type * @param address The address to be used as default address + * @return true iff the given address string was valid */ - void setDefaultAddress(QString address); + bool setDefaultAddress(const QString &address); private slots: @@ -52,6 +53,8 @@ private slots: private: Ui::LinkTypeDialog *ui; + bool addrValid; + /** * @brief Used for finding the type which is linked to the given address * @param address diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 1c86e282..ab02b885 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -770,7 +770,9 @@ void DisassemblyContextMenu::on_actionStructureOffsetMenu_triggered(QAction *act void DisassemblyContextMenu::on_actionLinkType_triggered() { LinkTypeDialog dialog(this); - dialog.setDefaultAddress(curHighlightedWord); + if (!dialog.setDefaultAddress(curHighlightedWord)) { + dialog.setDefaultAddress(RAddressString(offset)); + } dialog.exec(); } diff --git a/src/widgets/TypesWidget.cpp b/src/widgets/TypesWidget.cpp index e4d3b980..97a7fd34 100644 --- a/src/widgets/TypesWidget.cpp +++ b/src/widgets/TypesWidget.cpp @@ -300,6 +300,7 @@ void TypesWidget::on_actionLink_Type_To_Address_triggered() if (index.isValid()) { TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value(); dialog.setDefaultType(t.type); + dialog.setDefaultAddress(RAddressString(Core()->getOffset())); } dialog.exec();