From fdc97fe6d14c65f1f7c11f73d0312db21774d1af Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 19 Sep 2023 08:06:03 +0200 Subject: [PATCH] Properly restore DisassemblyPopup functionality --- src/gui/Src/BasicView/ReferenceView.cpp | 5 ++ src/gui/Src/BasicView/ReferenceView.h | 1 - src/gui/Src/BasicView/SearchListView.h | 2 +- src/gui/Src/BasicView/StdSearchListView.h | 2 + src/gui/Src/Gui/BreakpointsView.cpp | 3 ++ src/gui/Src/Gui/CallStackView.cpp | 3 ++ src/gui/Src/Gui/DisassemblyPopup.cpp | 66 +++++++++++------------ src/gui/Src/Gui/DisassemblyPopup.h | 4 +- src/gui/Src/Gui/HandlesView.cpp | 5 ++ src/gui/Src/Gui/SymbolView.cpp | 6 +++ src/gui/Src/Gui/ThreadView.cpp | 3 ++ 11 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/gui/Src/BasicView/ReferenceView.cpp b/src/gui/Src/BasicView/ReferenceView.cpp index 5f0ed98f..965f5530 100644 --- a/src/gui/Src/BasicView/ReferenceView.cpp +++ b/src/gui/Src/BasicView/ReferenceView.cpp @@ -6,6 +6,7 @@ #include "Configuration.h" #include "Bridge.h" #include "MiscUtil.h" +#include "DisassemblyPopup.h" ReferenceView::ReferenceView(bool sourceView, QWidget* parent) : StdSearchListView(parent, true, false), mParent(dynamic_cast(parent)) { @@ -53,6 +54,10 @@ ReferenceView::ReferenceView(bool sourceView, QWidget* parent) : StdSearchListVi connect(this, SIGNAL(enterPressedSignal()), this, SLOT(followGenericAddress())); setupContextMenu(); + + // Add disassembly popups + new DisassemblyPopup(stdList(), Bridge::getArchitecture()); + new DisassemblyPopup(stdSearchList(), Bridge::getArchitecture()); } void ReferenceView::setupContextMenu() diff --git a/src/gui/Src/BasicView/ReferenceView.h b/src/gui/Src/BasicView/ReferenceView.h index 85acff91..f1a1b839 100644 --- a/src/gui/Src/BasicView/ReferenceView.h +++ b/src/gui/Src/BasicView/ReferenceView.h @@ -3,7 +3,6 @@ #include #include #include "StdSearchListView.h" -class DisassemblyPopup; class QTabWidget; diff --git a/src/gui/Src/BasicView/SearchListView.h b/src/gui/Src/BasicView/SearchListView.h index bef1f5ab..42236806 100644 --- a/src/gui/Src/BasicView/SearchListView.h +++ b/src/gui/Src/BasicView/SearchListView.h @@ -12,7 +12,7 @@ class SearchListView : public QWidget, public ActionHelper Q_OBJECT public: - explicit SearchListView(QWidget* parent, AbstractSearchList* abstractSearchList, bool enableRegex, bool enableLock); + SearchListView(QWidget* parent, AbstractSearchList* abstractSearchList, bool enableRegex, bool enableLock); AbstractStdTable* mCurList = nullptr; duint mSearchStartCol = 0; diff --git a/src/gui/Src/BasicView/StdSearchListView.h b/src/gui/Src/BasicView/StdSearchListView.h index 85a0d964..0757005a 100644 --- a/src/gui/Src/BasicView/StdSearchListView.h +++ b/src/gui/Src/BasicView/StdSearchListView.h @@ -31,6 +31,8 @@ private: protected: friend class SymbolView; friend class Bridge; + friend class HandlesView; + StdTable* stdList(); StdTable* stdSearchList(); }; diff --git a/src/gui/Src/Gui/BreakpointsView.cpp b/src/gui/Src/Gui/BreakpointsView.cpp index 8ded4ef8..bff79ecd 100644 --- a/src/gui/Src/Gui/BreakpointsView.cpp +++ b/src/gui/Src/Gui/BreakpointsView.cpp @@ -5,6 +5,7 @@ #include "Bridge.h" #include "MenuBuilder.h" #include "Breakpoints.h" +#include "DisassemblyPopup.h" BreakpointsView::BreakpointsView(QWidget* parent) : StdTable(parent), mExceptionMaxLength(0) @@ -37,6 +38,8 @@ BreakpointsView::BreakpointsView(QWidget* parent) connect(this, SIGNAL(enterPressedSignal()), this, SLOT(followBreakpointSlot())); Initialize(); + + new DisassemblyPopup(this, Bridge::getArchitecture()); } void BreakpointsView::setupContextMenu() diff --git a/src/gui/Src/Gui/CallStackView.cpp b/src/gui/Src/Gui/CallStackView.cpp index 1e3e43d1..d4e061b0 100644 --- a/src/gui/Src/Gui/CallStackView.cpp +++ b/src/gui/Src/Gui/CallStackView.cpp @@ -1,6 +1,7 @@ #include "CallStackView.h" #include "CommonActions.h" #include "Bridge.h" +#include "DisassemblyPopup.h" CallStackView::CallStackView(StdTable* parent) : StdIconTable(parent) { @@ -21,6 +22,8 @@ CallStackView::CallStackView(StdTable* parent) : StdIconTable(parent) connect(this, SIGNAL(doubleClickedSignal()), this, SLOT(followFrom())); setupContextMenu(); + + new DisassemblyPopup(this, Bridge::getArchitecture()); } void CallStackView::setupContextMenu() diff --git a/src/gui/Src/Gui/DisassemblyPopup.cpp b/src/gui/Src/Gui/DisassemblyPopup.cpp index 8e5f73d4..8b3c6879 100644 --- a/src/gui/Src/Gui/DisassemblyPopup.cpp +++ b/src/gui/Src/Gui/DisassemblyPopup.cpp @@ -107,13 +107,12 @@ bool DisassemblyPopup::eventFilter(QObject* object, QEvent* event) case QEvent::KeyPress: { hide(); + stopPopupTimer(); } break; case QEvent::MouseMove: { - hide(); - auto mouseEvent = (QMouseEvent*)event; auto x = mouseEvent->x(); auto y = mouseEvent->y(); @@ -121,11 +120,23 @@ bool DisassemblyPopup::eventFilter(QObject* object, QEvent* event) // TODO: make sure the cursor isn't on the column separators if(y > mParent->getHeaderHeight()) { - mLastX = x; - mLastY = y; - if(mPopupTimer != 0) - killTimer(mPopupTimer); - mPopupTimer = startTimer(QApplication::startDragTime()); + // Show the popup if relevant for the current position + auto addr = mParent->getAddressForPosition(x, y); + if(getAddress() != addr) + { + if(DbgFunctions()->MemIsCodePage(addr, false)) + { + move(mParent->mapToGlobal(QPoint(x + 20, y + fontMetrics().height() * 2))); + setAddress(addr); + if(mPopupTimer == 0) + mPopupTimer = startTimer(QApplication::startDragTime()); + } + else + { + hide(); + stopPopupTimer(); + } + } } } break; @@ -142,46 +153,35 @@ void DisassemblyPopup::timerEvent(QTimerEvent* event) { if(event->timerId() == mPopupTimer) { - // Kill the timer - killTimer(mPopupTimer); - mPopupTimer = 0; + // Show the popup + show(); - // Show the popup if relevant for the current position - auto addr = mParent->getAddressForPosition(mLastX, mLastY); - if(getAddress() != addr) - { - if(DbgFunctions()->MemIsCodePage(addr, false)) - { - move(mParent->mapToGlobal(QPoint(mLastX + 20, mLastY + fontMetrics().height() * 2))); - setAddress(addr); - show(); - } - else - { - hide(); - if(mPopupTimer != 0) - { - mPopupTimer = 0; - killTimer(mPopupTimer); - } - } - } + stopPopupTimer(); } QFrame::timerEvent(event); } -void DisassemblyPopup::setAddress(duint Address) +void DisassemblyPopup::stopPopupTimer() { - mAddr = Address; + if(mPopupTimer != 0) + { + killTimer(mPopupTimer); + mPopupTimer = 0; + } +} + +void DisassemblyPopup::setAddress(duint addr) +{ + mAddr = addr; QList instBuffer; mDisassemblyToken.clear(); mDisasm.UpdateArchitecture(); + if(mAddr != 0) { mWidth = 1; // Get RVA - auto addr = Address; duint size; duint base = DbgMemFindBaseAddr(addr, &size); // Prepare RVA of every instruction diff --git a/src/gui/Src/Gui/DisassemblyPopup.h b/src/gui/Src/Gui/DisassemblyPopup.h index 935d1f44..76d4da32 100644 --- a/src/gui/Src/Gui/DisassemblyPopup.h +++ b/src/gui/Src/Gui/DisassemblyPopup.h @@ -4,6 +4,7 @@ #include "Imports.h" #include "QZydis.h" #include "AbstractTableView.h" +#include "StdSearchListView.h" class CachedFontMetrics; @@ -25,6 +26,7 @@ protected: void paintEvent(QPaintEvent* event) override; bool eventFilter(QObject* object, QEvent* event) override; void timerEvent(QTimerEvent* event) override; + void stopPopupTimer(); CachedFontMetrics* mFontMetrics = nullptr; duint mAddr = 0; @@ -35,8 +37,6 @@ protected: int mCharHeight = 0; int mWidth = 0; int mPopupTimer = 0; - int mLastX = 0; - int mLastY = 0; unsigned int mMaxInstructions = 20; QColor mDisassemblyBackgroundColor; diff --git a/src/gui/Src/Gui/HandlesView.cpp b/src/gui/Src/Gui/HandlesView.cpp index 2568bf25..22e4ba9b 100644 --- a/src/gui/Src/Gui/HandlesView.cpp +++ b/src/gui/Src/Gui/HandlesView.cpp @@ -10,6 +10,7 @@ #include "StdIconSearchListView.h" #include "MainWindow.h" #include "MessagesBreakpoints.h" +#include "DisassemblyPopup.h" #include HandlesView::HandlesView(QWidget* parent) : QWidget(parent) @@ -27,6 +28,10 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent) mHandlesTable->addColumnAt(8 + charWidth * 20, tr("Name"), true); mHandlesTable->loadColumnFromConfig("Handle"); + // Add disassembly popups + new DisassemblyPopup(mHandlesTable->stdList(), Bridge::getArchitecture()); + new DisassemblyPopup(mHandlesTable->stdSearchList(), Bridge::getArchitecture()); + // Setup windows list mWindowsTable = new StdIconSearchListView(this, true, true); mWindowsTable->setInternalTitle("Windows"); diff --git a/src/gui/Src/Gui/SymbolView.cpp b/src/gui/Src/Gui/SymbolView.cpp index 53ace790..c08d290f 100644 --- a/src/gui/Src/Gui/SymbolView.cpp +++ b/src/gui/Src/Gui/SymbolView.cpp @@ -6,6 +6,8 @@ #include "BrowseDialog.h" #include "StdIconSearchListView.h" #include "ZehSymbolTable.h" +#include "DisassemblyPopup.h" + #include #include #include @@ -174,6 +176,10 @@ SymbolView::SymbolView(QWidget* parent) : QWidget(parent), ui(new Ui::SymbolView mSymbolList = new SearchListView(this, mSymbolSearchList, true, true); mSymbolList->mSearchStartCol = 1; + // Add a disassembly popup + new DisassemblyPopup(mSymbolSearchList->list(), Bridge::getArchitecture()); + new DisassemblyPopup(mSymbolSearchList->searchList(), Bridge::getArchitecture()); + // Create module list mModuleList = new StdIconSearchListView(this, true, false, new StdTableSearchList(new ModuleStdTable(), new ModuleStdTable())); mModuleList->setSearchStartCol(ColBase); diff --git a/src/gui/Src/Gui/ThreadView.cpp b/src/gui/Src/Gui/ThreadView.cpp index 289140ad..64319dc1 100644 --- a/src/gui/Src/Gui/ThreadView.cpp +++ b/src/gui/Src/Gui/ThreadView.cpp @@ -3,6 +3,7 @@ #include "Bridge.h" #include "StringUtil.h" #include "LineEditDialog.h" +#include "DisassemblyPopup.h" void ThreadView::contextMenuSlot(const QPoint & pos) { @@ -179,6 +180,8 @@ ThreadView::ThreadView(StdTable* parent) : StdTable(parent) connect(this, SIGNAL(contextMenuSignal(QPoint)), this, SLOT(contextMenuSlot(QPoint))); setupContextMenu(); + + new DisassemblyPopup(this, Bridge::getArchitecture()); } void ThreadView::updateThreadList()