Refactored old disassembly popup in CPUDisassembly
This commit is contained in:
parent
707cd444ae
commit
594319a654
|
|
@ -379,7 +379,7 @@ void AbstractTableView::mouseMoveEvent(QMouseEvent* event)
|
|||
}
|
||||
else if(wHandle == false && wHasCursor == false)
|
||||
{
|
||||
if(event->y() > getHeaderHeight())
|
||||
if(event->y() > getHeaderHeight() && DbgIsDebugging())
|
||||
ShowDisassemblyPopup(getDisassemblyPopupAddress(event->x(), event->y()), event->x(), event->y());
|
||||
}
|
||||
}
|
||||
|
|
@ -1276,6 +1276,8 @@ void AbstractTableView::prepareData()
|
|||
************************************************************************************/
|
||||
duint AbstractTableView::getDisassemblyPopupAddress(int mousex, int mousey)
|
||||
{
|
||||
Q_UNUSED(mousex)
|
||||
Q_UNUSED(mousey)
|
||||
return 0; //Default is no disassembly popup
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "QBeaEngine.h"
|
||||
#include "MemoryPage.h"
|
||||
|
||||
Disassembly::Disassembly(QWidget* parent) : AbstractTableView(parent), mDisassemblyPopup(this)
|
||||
Disassembly::Disassembly(QWidget* parent) : AbstractTableView(parent)
|
||||
{
|
||||
mMemPage = new MemoryPage(0, 0);
|
||||
|
||||
|
|
@ -32,11 +32,13 @@ Disassembly::Disassembly(QWidget* parent) : AbstractTableView(parent), mDisassem
|
|||
tokenizerConfigUpdatedSlot();
|
||||
|
||||
mCodeFoldingManager = nullptr;
|
||||
duint setting;
|
||||
if(BridgeSettingGetUint("Gui", "DisableBranchDestinationPreview", &setting))
|
||||
mPopupEnabled = !setting;
|
||||
else
|
||||
mPopupEnabled = true;
|
||||
/*
|
||||
duint setting;
|
||||
if(BridgeSettingGetUint("Gui", "DisableBranchDestinationPreview", &setting))
|
||||
mPopupEnabled = !setting;
|
||||
else
|
||||
mPopupEnabled = true;
|
||||
*/
|
||||
mIsLastInstDisplayed = false;
|
||||
|
||||
mGuiState = Disassembly::NoState;
|
||||
|
|
@ -674,44 +676,40 @@ void Disassembly::mouseMoveEvent(QMouseEvent* event)
|
|||
verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub);
|
||||
}
|
||||
}
|
||||
else if(mGuiState == Disassembly::NoState)
|
||||
{
|
||||
if(!mHighlightingMode && mPopupEnabled)
|
||||
{
|
||||
bool popupShown = false;
|
||||
if(y > getHeaderHeight() && getColumnIndexFromX(event->x()) == 2)
|
||||
{
|
||||
int rowOffset = getIndexOffsetFromY(transY(y));
|
||||
if(rowOffset < mInstBuffer.size())
|
||||
{
|
||||
CapstoneTokenizer::SingleToken token;
|
||||
auto & instruction = mInstBuffer.at(rowOffset);
|
||||
if(CapstoneTokenizer::TokenFromX(instruction.tokens, token, event->x(), mFontMetrics))
|
||||
{
|
||||
duint addr = token.value.value;
|
||||
bool isCodePage = DbgFunctions()->MemIsCodePage(addr, false);
|
||||
if(!isCodePage && instruction.branchDestination)
|
||||
{
|
||||
addr = instruction.branchDestination;
|
||||
isCodePage = DbgFunctions()->MemIsCodePage(addr, false);
|
||||
}
|
||||
if(isCodePage && (addr - mMemPage->getBase() < mInstBuffer.front().rva || addr - mMemPage->getBase() > mInstBuffer.back().rva))
|
||||
{
|
||||
ShowDisassemblyPopup(addr, event->x(), y);
|
||||
popupShown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(popupShown == false)
|
||||
ShowDisassemblyPopup(0, 0, 0); // hide popup
|
||||
}
|
||||
}
|
||||
|
||||
if(wAccept == true)
|
||||
AbstractTableView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
duint Disassembly::getDisassemblyPopupAddress(int mousex, int mousey)
|
||||
{
|
||||
if(mHighlightingMode)
|
||||
return 0; //Don't show this in highlight mode
|
||||
if(getColumnIndexFromX(mousex) != 2)
|
||||
return 0; //Disassembly popup for other column is undefined
|
||||
int rowOffset = getIndexOffsetFromY(transY(mousey));
|
||||
if(rowOffset < mInstBuffer.size())
|
||||
{
|
||||
CapstoneTokenizer::SingleToken token;
|
||||
auto & instruction = mInstBuffer.at(rowOffset);
|
||||
if(CapstoneTokenizer::TokenFromX(instruction.tokens, token, mousex, mFontMetrics))
|
||||
{
|
||||
duint addr = token.value.value;
|
||||
bool isCodePage = DbgFunctions()->MemIsCodePage(addr, false);
|
||||
if(!isCodePage && instruction.branchDestination)
|
||||
{
|
||||
addr = instruction.branchDestination;
|
||||
isCodePage = DbgFunctions()->MemIsCodePage(addr, false);
|
||||
}
|
||||
if(isCodePage && (addr - mMemPage->getBase() < mInstBuffer.front().rva || addr - mMemPage->getBase() > mInstBuffer.back().rva))
|
||||
{
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This method has been reimplemented. It manages the following actions:
|
||||
* - Multi-rows selection
|
||||
|
|
@ -838,12 +836,6 @@ void Disassembly::mouseReleaseEvent(QMouseEvent* event)
|
|||
AbstractTableView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void Disassembly::leaveEvent(QEvent* event)
|
||||
{
|
||||
ShowDisassemblyPopup(0, 0, 0);
|
||||
AbstractTableView::leaveEvent(event);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
Keyboard Management
|
||||
************************************************************************************/
|
||||
|
|
@ -2142,21 +2134,6 @@ void Disassembly::unfold(dsint rva)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Disassembly::ShowDisassemblyPopup(duint addr, int x, int y)
|
||||
{
|
||||
if(mDisassemblyPopup.getAddress() == addr)
|
||||
return;
|
||||
if(DbgMemIsValidReadPtr(addr))
|
||||
{
|
||||
mDisassemblyPopup.move(mapToGlobal(QPoint(x + 20, y + mFontMetrics->height() * 2)));
|
||||
mDisassemblyPopup.setAddress(addr);
|
||||
mDisassemblyPopup.show();
|
||||
}
|
||||
else
|
||||
mDisassemblyPopup.hide();
|
||||
}
|
||||
|
||||
bool Disassembly::hightlightToken(const CapstoneTokenizer::SingleToken & token)
|
||||
{
|
||||
mHighlightToken = token;
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
#define DISASSEMBLY_H
|
||||
|
||||
#include "AbstractTableView.h"
|
||||
#include "DisassemblyPopup.h"
|
||||
#include "QBeaEngine.h"
|
||||
|
||||
class CodeFoldingHelper;
|
||||
class QBeaEngine;
|
||||
class MemoryPage;
|
||||
|
||||
class Disassembly : public AbstractTableView
|
||||
|
|
@ -26,7 +25,6 @@ public:
|
|||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void leaveEvent(QEvent* event) override;
|
||||
|
||||
// Keyboard Management
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
|
@ -103,8 +101,8 @@ public:
|
|||
|
||||
//misc
|
||||
void setCodeFoldingManager(CodeFoldingHelper* CodeFoldingManager);
|
||||
duint getDisassemblyPopupAddress(int mousex, int mousey) override;
|
||||
void unfold(dsint rva);
|
||||
void ShowDisassemblyPopup(duint addr, int x, int y);
|
||||
bool hightlightToken(const CapstoneTokenizer::SingleToken & token);
|
||||
bool isHighlightMode() const;
|
||||
|
||||
|
|
@ -243,13 +241,12 @@ protected:
|
|||
duint mRvaDisplayBase;
|
||||
dsint mRvaDisplayPageBase;
|
||||
bool mHighlightingMode;
|
||||
bool mPopupEnabled;
|
||||
//bool mPopupEnabled;
|
||||
MemoryPage* mMemPage;
|
||||
QBeaEngine* mDisasm;
|
||||
bool mShowMnemonicBrief;
|
||||
XREF_INFO mXrefInfo;
|
||||
CodeFoldingHelper* mCodeFoldingManager;
|
||||
DisassemblyPopup mDisassemblyPopup;
|
||||
CapstoneTokenizer::SingleToken mHighlightToken;
|
||||
bool mPermanentHighlightingMode;
|
||||
bool mNoCurrentModuleText;
|
||||
|
|
|
|||
|
|
@ -353,13 +353,15 @@ void CPUDisassembly::setupRightClickContextMenu()
|
|||
});
|
||||
|
||||
mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"));
|
||||
QAction* togglePreview = makeShortcutAction(DIcon("branchpreview.png"), tr("Disable Branch Destination Preview"), SLOT(togglePreviewSlot()), "ActionToggleDestinationPreview");
|
||||
mMenuBuilder->addAction(togglePreview, [this, togglePreview](QMenu*)
|
||||
{
|
||||
togglePreview->setText(mPopupEnabled ? tr("Disable Branch Destination Preview") : tr("Enable Branch Destination Preview"));
|
||||
return false; //hide this menu from the user, but keep the shortcut working
|
||||
});
|
||||
|
||||
//The following code to manage branch preview has been disabled and will be implemented in a setting instead.
|
||||
/*
|
||||
QAction* togglePreview = makeShortcutAction(DIcon("branchpreview.png"), tr("Disable Branch Destination Preview"), SLOT(togglePreviewSlot()), "ActionToggleDestinationPreview");
|
||||
mMenuBuilder->addAction(togglePreview, [this, togglePreview](QMenu*)
|
||||
{
|
||||
togglePreview->setText(mPopupEnabled ? tr("Disable Branch Destination Preview") : tr("Enable Branch Destination Preview"));
|
||||
return false; //hide this menu from the user, but keep the shortcut working
|
||||
});
|
||||
*/
|
||||
MenuBuilder* labelMenu = new MenuBuilder(this);
|
||||
labelMenu->addAction(makeShortcutAction(tr("Label Current Address"), SLOT(setLabelSlot()), "ActionSetLabel"));
|
||||
QAction* labelAddress = makeShortcutAction(tr("Label"), SLOT(setLabelAddressSlot()), "ActionSetLabelOperand");
|
||||
|
|
@ -1980,7 +1982,7 @@ void CPUDisassembly::graphSlot()
|
|||
if(DbgCmdExecDirect(QString("graph %1").arg(ToPtrString(rvaToVa(getSelectionStart()))).toUtf8().constData()))
|
||||
emit displayGraphWidget();
|
||||
}
|
||||
|
||||
/*
|
||||
void CPUDisassembly::togglePreviewSlot()
|
||||
{
|
||||
if(mPopupEnabled == true)
|
||||
|
|
@ -1988,7 +1990,7 @@ void CPUDisassembly::togglePreviewSlot()
|
|||
mPopupEnabled = !mPopupEnabled;
|
||||
BridgeSettingSetUint("Gui", "DisableBranchDestinationPreview", !mPopupEnabled);
|
||||
}
|
||||
|
||||
*/
|
||||
void CPUDisassembly::analyzeModuleSlot()
|
||||
{
|
||||
DbgCmdExec("cfanal");
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public slots:
|
|||
void setEncodeTypeRangeSlot();
|
||||
void graphSlot();
|
||||
void analyzeModuleSlot();
|
||||
void togglePreviewSlot();
|
||||
//void togglePreviewSlot();
|
||||
void createThreadSlot();
|
||||
void copyTokenTextSlot();
|
||||
void copyTokenValueSlot();
|
||||
|
|
|
|||
Loading…
Reference in New Issue