mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 00:35:05 +00:00
Fallback to current offset in LinkTypeDialog (#1458)
This commit is contained in:
parent
800594551b
commit
436c2ee89c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -300,6 +300,7 @@ void TypesWidget::on_actionLink_Type_To_Address_triggered()
|
||||
if (index.isValid()) {
|
||||
TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
|
||||
dialog.setDefaultType(t.type);
|
||||
dialog.setDefaultAddress(RAddressString(Core()->getOffset()));
|
||||
}
|
||||
|
||||
dialog.exec();
|
||||
|
Loading…
Reference in New Issue
Block a user