From 3d49c4b65a952196e0df0f1e1ced9079b7523e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 7 Jan 2023 20:05:41 +0100 Subject: [PATCH] Fix parsing of new types from C (#3068) In the TypesWidget, right-click+Load New Types was opening the dialog for editing an existing type instead of creating a new one. This would either result in an error (for atomic types) or the old type being deleted on success. --- src/dialogs/TypesInteractionDialog.cpp | 16 +++++++++++++--- src/widgets/TypesWidget.cpp | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dialogs/TypesInteractionDialog.cpp b/src/dialogs/TypesInteractionDialog.cpp index eb2c2284..be363a30 100644 --- a/src/dialogs/TypesInteractionDialog.cpp +++ b/src/dialogs/TypesInteractionDialog.cpp @@ -22,7 +22,6 @@ TypesInteractionDialog::TypesInteractionDialog(QWidget *parent, bool readOnly) syntaxHighLighter = Config()->createSyntaxHighlighter(ui->plainTextEdit->document()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); ui->plainTextEdit->setReadOnly(readOnly); - this->typeName = ""; } TypesInteractionDialog::~TypesInteractionDialog() {} @@ -64,10 +63,21 @@ void TypesInteractionDialog::done(int r) { if (r == QDialog::Accepted) { RzCoreLocked core(Core()); - bool edited = rz_type_db_edit_base_type( + bool success; + if (!typeName.isEmpty()) { + success = rz_type_db_edit_base_type( core->analysis->typedb, this->typeName.toUtf8().constData(), ui->plainTextEdit->toPlainText().toUtf8().constData()); - if (edited) { + } else { + char *error_msg = NULL; + success = rz_type_parse_string_stateless(core->analysis->typedb->parser, + ui->plainTextEdit->toPlainText().toUtf8().constData(), &error_msg) == 0; + if (error_msg) { + RZ_LOG_ERROR("%s\n", error_msg); + rz_mem_free(error_msg); + } + } + if (success) { emit newTypesLoaded(); QDialog::done(r); return; diff --git a/src/widgets/TypesWidget.cpp b/src/widgets/TypesWidget.cpp index ebdeace1..3891314e 100644 --- a/src/widgets/TypesWidget.cpp +++ b/src/widgets/TypesWidget.cpp @@ -293,7 +293,6 @@ void TypesWidget::on_actionLoad_New_Types_triggered() TypesInteractionDialog dialog(this); connect(&dialog, &TypesInteractionDialog::newTypesLoaded, this, &TypesWidget::refreshTypes); dialog.setWindowTitle(tr("Load New Types")); - dialog.setTypeName(t.type); dialog.exec(); }