diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 439c4db3..454ca6b1 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -3571,23 +3571,6 @@ QList CutterCore::getAllTypedefs() return getBaseType(RZ_BASE_TYPE_KIND_TYPEDEF, "Typedef"); } -QString CutterCore::addTypes(const char *str) -{ - CORE_LOCK(); - char *error_msg = nullptr; - int parsed = rz_type_parse_string(core->analysis->typedb, str, &error_msg); - QString error; - - if (!parsed && error_msg) { - error = error_msg; - rz_mem_free(error_msg); - } else if (!parsed) { - error = QString("Failed to load new type %1").arg(str); - } - - return error; -} - QString CutterCore::getTypeAsC(QString name) { CORE_LOCK(); @@ -3602,11 +3585,6 @@ QString CutterCore::getTypeAsC(QString name) return result; } -bool CutterCore::deleteType(const char *typeName) { - CORE_LOCK(); - return rz_type_db_del(core->analysis->typedb, typeName); -} - bool CutterCore::isAddressMapped(RVA addr) { // If value returned by "om. @ addr" is empty means that address is not mapped diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 54a7bb55..687e71c3 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -594,25 +594,6 @@ public: */ QString getTypeAsC(QString name); - /** - * @brief Adds new types - * It first uses the rz_parse_c_string() function from Rizin API to parse the - * supplied C file (in the form of a string). If there were errors, they are displayed. - * If there were no errors, it uses sdb_query_lines() function from Rizin API - * to save the parsed types returned by rz_parse_c_string() - * \param str Contains the definition of the data types - * \return returns an empty QString if there was no error, else returns the error - */ - QString addTypes(const char *str); - QString addTypes(const QString &str) { return addTypes(str.toUtf8().constData()); } - - /** - * @brief Remove a type - * @param typeName Name of the type to remove - */ - bool deleteType(const char *typeName); - bool deleteType(QString typeName) { return deleteType(typeName.toUtf8().constData()); } - /** * @brief Checks if the given address is mapped to a region * @param addr The address to be checked diff --git a/src/dialogs/TypesInteractionDialog.cpp b/src/dialogs/TypesInteractionDialog.cpp index 7f7b6a72..eb2c2284 100644 --- a/src/dialogs/TypesInteractionDialog.cpp +++ b/src/dialogs/TypesInteractionDialog.cpp @@ -22,10 +22,16 @@ 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() {} +void TypesInteractionDialog::setTypeName(QString name) +{ + this->typeName = name; +} + void TypesInteractionDialog::on_selectFileButton_clicked() { QString filename = @@ -57,8 +63,11 @@ void TypesInteractionDialog::on_plainTextEdit_textChanged() void TypesInteractionDialog::done(int r) { if (r == QDialog::Accepted) { - QString error = Core()->addTypes(ui->plainTextEdit->toPlainText()); - if (error.isEmpty()) { + RzCoreLocked core(Core()); + bool edited = rz_type_db_edit_base_type( + core->analysis->typedb, this->typeName.toUtf8().constData(), + ui->plainTextEdit->toPlainText().toUtf8().constData()); + if (edited) { emit newTypesLoaded(); QDialog::done(r); return; @@ -67,7 +76,6 @@ void TypesInteractionDialog::done(int r) QMessageBox popup(this); popup.setWindowTitle(tr("Error")); popup.setText(tr("There was some error while loading new types")); - popup.setDetailedText(error); popup.setStandardButtons(QMessageBox::Ok); popup.exec(); } else { diff --git a/src/dialogs/TypesInteractionDialog.h b/src/dialogs/TypesInteractionDialog.h index d45640b3..2c33328e 100644 --- a/src/dialogs/TypesInteractionDialog.h +++ b/src/dialogs/TypesInteractionDialog.h @@ -27,6 +27,12 @@ public: */ void fillTextArea(QString content); + /** + * @brief Set the name of the type that is going to be changed + * @param name - name of the type + */ + void setTypeName(QString name); + private slots: /** * @brief Executed when the user clicks the selectFileButton @@ -50,6 +56,7 @@ private slots: private: std::unique_ptr ui; QSyntaxHighlighter *syntaxHighLighter; + QString typeName; signals: /** diff --git a/src/widgets/TypesWidget.cpp b/src/widgets/TypesWidget.cpp index e5c7a8ec..c2e069a6 100644 --- a/src/widgets/TypesWidget.cpp +++ b/src/widgets/TypesWidget.cpp @@ -76,7 +76,8 @@ QVariant TypesModel::headerData(int section, Qt::Orientation, int role) const bool TypesModel::removeRows(int row, int count, const QModelIndex &parent) { - Core()->deleteType(types->at(row).type); + RzCoreLocked core(Core()); + rz_type_db_del(core->analysis->typedb, types->at(row).type.toUtf8().constData()); beginRemoveRows(parent, row, row + count - 1); while (count--) { types->removeAt(row); @@ -282,9 +283,17 @@ void TypesWidget::on_actionExport_Types_triggered() void TypesWidget::on_actionLoad_New_Types_triggered() { + QModelIndex index = ui->typesTreeView->currentIndex(); + if (!index.isValid()) { + return; + } + + TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value(); + TypesInteractionDialog dialog(this); connect(&dialog, &TypesInteractionDialog::newTypesLoaded, this, &TypesWidget::refreshTypes); dialog.setWindowTitle(tr("Load New Types")); + dialog.setTypeName(t.type); dialog.exec(); } @@ -306,6 +315,7 @@ void TypesWidget::viewType(bool readOnly) dialog.setWindowTitle(tr("View Type: ") + t.type + tr(" (Read Only)")); } dialog.fillTextArea(Core()->getTypeAsC(t.type)); + dialog.setTypeName(t.type); dialog.exec(); } @@ -354,5 +364,6 @@ void TypesWidget::typeItemDoubleClicked(const QModelIndex &index) } dialog.fillTextArea(Core()->getTypeAsC(t.type)); dialog.setWindowTitle(tr("View Type: ") + t.type + tr(" (Read Only)")); + dialog.setTypeName(t.type); dialog.exec(); }