From 0bccbd0c0dbce8551949fb2cd9979955d52168bc Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Fri, 26 Dec 2014 14:43:20 +0100 Subject: [PATCH] GUI: resolved issue #229 (automatic comments have a different color) --- .../Project/Src/BasicView/Disassembly.cpp | 23 +++++++++++++++---- .../Project/Src/Gui/AppearanceDialog.cpp | 1 + .../Project/Src/Gui/BreakpointsView.cpp | 21 ++++++++++++++--- .../Project/Src/Gui/CPUDisassembly.cpp | 14 +++++++++-- .../Project/Src/Utils/Configuration.cpp | 2 ++ 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/x64_dbg_gui/Project/Src/BasicView/Disassembly.cpp b/x64_dbg_gui/Project/Src/BasicView/Disassembly.cpp index 8be1ef08..16570069 100644 --- a/x64_dbg_gui/Project/Src/BasicView/Disassembly.cpp +++ b/x64_dbg_gui/Project/Src/BasicView/Disassembly.cpp @@ -380,13 +380,28 @@ QString Disassembly::paintContent(QPainter* painter, int_t rowBase, int rowOffse char comment[MAX_COMMENT_SIZE] = ""; if(DbgGetCommentAt(rvaToVa(mInstBuffer.at(rowOffset).rva), comment)) { - painter->setPen(ConfigColor("DisassemblyCommentColor")); - int width = getCharWidth() * QString(comment).length() + 4; + QString commentText; + QColor penColor; + QColor backgroundColor; + if(comment[0] == '\1') //automatic comment + { + penColor = ConfigColor("DisassemblyAutoCommentColor"); + backgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor"); + commentText = QString(comment + 1); + } + else //user comment + { + penColor = ConfigColor("DisassemblyCommentColor"); + backgroundColor = ConfigColor("DisassemblyCommentBackgroundColor"); + commentText = comment; + } + painter->setPen(penColor); + int width = getCharWidth() * commentText.length() + 4; if(width > w) width = w; if(width) - painter->fillRect(QRect(x + 2, y, width, h), QBrush(ConfigColor("DisassemblyCommentBackgroundColor"))); //fill bookmark color - painter->drawText(QRect(x + 4, y , w - 4 , h), Qt::AlignVCenter | Qt::AlignLeft, QString(comment)); + painter->fillRect(QRect(x + 2, y, width, h), QBrush(backgroundColor)); //fill comment color + painter->drawText(QRect(x + 4, y , w - 4 , h), Qt::AlignVCenter | Qt::AlignLeft, commentText); } } break; diff --git a/x64_dbg_gui/Project/Src/Gui/AppearanceDialog.cpp b/x64_dbg_gui/Project/Src/Gui/AppearanceDialog.cpp index 6ea0e2fb..5f5a9823 100644 --- a/x64_dbg_gui/Project/Src/Gui/AppearanceDialog.cpp +++ b/x64_dbg_gui/Project/Src/Gui/AppearanceDialog.cpp @@ -428,6 +428,7 @@ void AppearanceDialog::colorInfoListInit() colorInfoListAppend("Hardware Breakpoints", "DisassemblyHardwareBreakpointColor", "DisassemblyHardwareBreakpointBackgroundColor"); colorInfoListAppend("Bookmarks", "DisassemblyBookmarkColor", "DisassemblyBookmarkBackgroundColor"); colorInfoListAppend("Comments", "DisassemblyCommentColor", "DisassemblyCommentBackgroundColor"); + colorInfoListAppend("Automatic Comments", "DisassemblyAutoCommentColor", "DisassemblyAutoCommentBackgroundColor"); colorInfoListAppend("Labels", "DisassemblyLabelColor", "DisassemblyLabelBackgroundColor"); colorInfoListAppend("Addresses", "DisassemblyAddressColor", "DisassemblyAddressBackgroundColor"); colorInfoListAppend("Selected Addresses", "DisassemblySelectedAddressColor", "DisassemblySelectedAddressBackgroundColor"); diff --git a/x64_dbg_gui/Project/Src/Gui/BreakpointsView.cpp b/x64_dbg_gui/Project/Src/Gui/BreakpointsView.cpp index 48d70b09..74266e41 100644 --- a/x64_dbg_gui/Project/Src/Gui/BreakpointsView.cpp +++ b/x64_dbg_gui/Project/Src/Gui/BreakpointsView.cpp @@ -97,7 +97,12 @@ void BreakpointsView::reloadData() char comment[MAX_COMMENT_SIZE] = ""; if(DbgGetCommentAt(wBPList.bp[wI].addr, comment)) - mHardBPTable->setCellContent(wI, 4, comment); + { + if(comment[0] == '\1') //automatic comment + mHardBPTable->setCellContent(wI, 4, QString(comment + 1)); + else + mHardBPTable->setCellContent(wI, 4, comment); + } } mHardBPTable->reloadData(); if(wBPList.count) @@ -129,7 +134,12 @@ void BreakpointsView::reloadData() char comment[MAX_COMMENT_SIZE] = ""; if(DbgGetCommentAt(wBPList.bp[wI].addr, comment)) - mSoftBPTable->setCellContent(wI, 4, comment); + { + if(comment[0] == '\1') //automatic comment + mSoftBPTable->setCellContent(wI, 4, QString(comment + 1)); + else + mSoftBPTable->setCellContent(wI, 4, comment); + } } mSoftBPTable->reloadData(); if(wBPList.count) @@ -161,7 +171,12 @@ void BreakpointsView::reloadData() char comment[MAX_COMMENT_SIZE] = ""; if(DbgGetCommentAt(wBPList.bp[wI].addr, comment)) - mMemBPTable->setCellContent(wI, 4, comment); + { + if(comment[0] == '\1') //automatic comment + mMemBPTable->setCellContent(wI, 4, QString(comment + 1)); + else + mMemBPTable->setCellContent(wI, 4, comment); + } } mMemBPTable->reloadData(); if(wBPList.count) diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp index 072fa532..2503a4d2 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp @@ -708,7 +708,12 @@ void CPUDisassembly::setComment() QString addr_text = QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); char comment_text[MAX_COMMENT_SIZE] = ""; if(DbgGetCommentAt((duint)wVA, comment_text)) - mLineEdit.setText(QString(comment_text)); + { + if(comment_text[0] == '\1') //automatic comment + mLineEdit.setText(QString(comment_text + 1)); + else + mLineEdit.setText(QString(comment_text)); + } mLineEdit.setWindowTitle("Add comment at " + addr_text); if(mLineEdit.exec() != QDialog::Accepted) return; @@ -1160,7 +1165,12 @@ void CPUDisassembly::copySelection(bool copyBytes) char comment[MAX_COMMENT_SIZE] = ""; QString fullComment; if(DbgGetCommentAt(cur_addr, comment)) - fullComment = " ;" + QString(comment); + { + if(comment[0] == '\1') //automatic comment + fullComment = " ;" + QString(comment + 1); + else + fullComment = " ;" + QString(comment); + } clipboard += address.leftJustified(addressLen, QChar(' '), true); if(copyBytes) clipboard += " | " + bytes.leftJustified(bytesLen, QChar(' '), true); diff --git a/x64_dbg_gui/Project/Src/Utils/Configuration.cpp b/x64_dbg_gui/Project/Src/Utils/Configuration.cpp index 92d51dab..cd55f46e 100644 --- a/x64_dbg_gui/Project/Src/Utils/Configuration.cpp +++ b/x64_dbg_gui/Project/Src/Utils/Configuration.cpp @@ -39,6 +39,8 @@ Configuration::Configuration() : QObject() defaultColors.insert("DisassemblyModifiedBytesColor", QColor("#FF0000")); defaultColors.insert("DisassemblyCommentColor", QColor("#000000")); defaultColors.insert("DisassemblyCommentBackgroundColor", Qt::transparent); + defaultColors.insert("DisassemblyAutoCommentColor", QColor("#808080")); + defaultColors.insert("DisassemblyAutoCommentBackgroundColor", Qt::transparent); defaultColors.insert("SideBarCipLabelColor", QColor("#FFFFFF")); defaultColors.insert("SideBarCipLabelBackgroundColor", QColor("#4040FF"));