mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-12 01:42:06 +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),
|
QDialog(parent),
|
||||||
ui(new Ui::LinkTypeDialog)
|
ui(new Ui::LinkTypeDialog)
|
||||||
{
|
{
|
||||||
|
addrValid = false;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(tr("Link type to address"));
|
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);
|
ui->exprLineEdit->setText(address);
|
||||||
|
|
||||||
if (ui->addressLineEdit->text() == tr("Invalid Address")) {
|
if (!addrValid) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the current address is already linked to a type and set it as default
|
// 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()) {
|
if (!type.isEmpty()) {
|
||||||
setDefaultType(type);
|
setDefaultType(type);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,8 +103,10 @@ void LinkTypeDialog::on_exprLineEdit_textChanged(const QString &text)
|
|||||||
{
|
{
|
||||||
RVA addr = Core()->math(text);
|
RVA addr = Core()->math(text);
|
||||||
if (Core()->isAddressMapped(addr)) {
|
if (Core()->isAddressMapped(addr)) {
|
||||||
ui->addressLineEdit->setText("0x" + QString::number(addr, 16));
|
ui->addressLineEdit->setText(RAddressString(addr));
|
||||||
|
addrValid = true;
|
||||||
} else {
|
} else {
|
||||||
ui->addressLineEdit->setText(tr("Invalid Address"));
|
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
|
* If the given address is linked to a type, then it also sets the default
|
||||||
* type to the currently linked type
|
* type to the currently linked type
|
||||||
* @param address The address to be used as default address
|
* @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:
|
private slots:
|
||||||
|
|
||||||
@ -52,6 +53,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
Ui::LinkTypeDialog *ui;
|
Ui::LinkTypeDialog *ui;
|
||||||
|
|
||||||
|
bool addrValid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Used for finding the type which is linked to the given address
|
* @brief Used for finding the type which is linked to the given address
|
||||||
* @param address
|
* @param address
|
||||||
|
@ -770,7 +770,9 @@ void DisassemblyContextMenu::on_actionStructureOffsetMenu_triggered(QAction *act
|
|||||||
void DisassemblyContextMenu::on_actionLinkType_triggered()
|
void DisassemblyContextMenu::on_actionLinkType_triggered()
|
||||||
{
|
{
|
||||||
LinkTypeDialog dialog(this);
|
LinkTypeDialog dialog(this);
|
||||||
dialog.setDefaultAddress(curHighlightedWord);
|
if (!dialog.setDefaultAddress(curHighlightedWord)) {
|
||||||
|
dialog.setDefaultAddress(RAddressString(offset));
|
||||||
|
}
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +300,7 @@ void TypesWidget::on_actionLink_Type_To_Address_triggered()
|
|||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
|
TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
|
||||||
dialog.setDefaultType(t.type);
|
dialog.setDefaultType(t.type);
|
||||||
|
dialog.setDefaultAddress(RAddressString(Core()->getOffset()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
|
Loading…
Reference in New Issue
Block a user