diff --git a/src/cutter.cpp b/src/cutter.cpp index f3d508a1..70c574ac 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -332,7 +332,7 @@ void CutterCore::renameFlag(QString old_name, QString new_name) cmd("fr " + old_name + " " + new_name); } -void CutterCore::setComment(RVA addr, QString cmt) +void CutterCore::setComment(RVA addr, const QString &cmt) { cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr)); emit commentsChanged(); diff --git a/src/cutter.h b/src/cutter.h index 7d84a311..b2e442ad 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -204,8 +204,10 @@ public: QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; } void renameFunction(QString prev_name, QString new_name); void renameFlag(QString old_name, QString new_name); - void setComment(RVA addr, QString cmt); + + void setComment(RVA addr, const QString &cmt); void delComment(ut64 addr); + void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); QMap>> getNestedComments(); void setOptions(QString key); diff --git a/src/dialogs/CommentsDialog.cpp b/src/dialogs/CommentsDialog.cpp index 70528b3d..a19ad567 100644 --- a/src/dialogs/CommentsDialog.cpp +++ b/src/dialogs/CommentsDialog.cpp @@ -25,3 +25,8 @@ QString CommentsDialog::getComment() QString ret = ui->lineEdit->text(); return ret; } + +void CommentsDialog::setComment(const QString &comment) +{ + ui->lineEdit->setText(comment); +} \ No newline at end of file diff --git a/src/dialogs/CommentsDialog.h b/src/dialogs/CommentsDialog.h index e8d4a532..b95461fa 100644 --- a/src/dialogs/CommentsDialog.h +++ b/src/dialogs/CommentsDialog.h @@ -18,6 +18,7 @@ public: ~CommentsDialog(); QString getComment(); + void setComment(const QString &comment); private slots: void on_buttonBox_accepted(); diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 068c3a29..8fda3c0f 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -122,6 +122,17 @@ void DisassemblyContextMenu::aboutToShowSlot() auto keys = instObject.keys(); bool immBase = keys.contains("val") || keys.contains("ptr"); setBaseMenuAction->setVisible(immBase); + + QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject(); + QString comment = disasObject["comment"].toString(); + if (comment.isNull() || QByteArray::fromBase64(comment.toUtf8()).isEmpty()) + { + actionAddComment.setText(tr("Add Comment")); + } + else + { + actionAddComment.setText(tr("Edit Comment")); + } } QKeySequence DisassemblyContextMenu::getCommentSequence() const @@ -151,11 +162,32 @@ QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const void DisassemblyContextMenu::on_actionAddComment_triggered() { + QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject(); + QString oldComment = QString::fromUtf8(QByteArray::fromBase64(disasObject["comment"].toString().toUtf8())); + CommentsDialog *c = new CommentsDialog(this); + + if (oldComment.isNull() || QByteArray::fromBase64(oldComment.toUtf8()).isEmpty()) + { + c->setWindowTitle(tr("Add Comment at %1").arg(RAddressString(offset))); + } + else + { + c->setWindowTitle(tr("Edit Comment at %1").arg(RAddressString(offset))); + } + + c->setComment(oldComment); if (c->exec()) { QString comment = c->getComment(); - Core()->setComment(offset, comment); + if (comment.isEmpty()) + { + Core()->delComment(offset); + } + else + { + Core()->setComment(offset, comment); + } } }