1
0
Fork 0

CPUDisassembly : replacing repaint() with update() forces to call repaint explicitely when a custom action is done

CPUSideBar : Added a tooltip when hovering over the dots/bullets to tell what their current color mean
Bridge : Removed GuiDisplayWarning, no longer used/needed
This commit is contained in:
Herzeh 2015-12-23 19:03:56 +01:00
parent 3a9ef35db8
commit c78ede593a
8 changed files with 102 additions and 50 deletions

View File

@ -1250,11 +1250,6 @@ BRIDGE_IMPEXP void GuiDumpAtN(duint va, int index)
_gui_sendmessage(GUI_DUMP_AT_N, (void*)va, (void*)index);
}
BRIDGE_IMPEXP void GuiDisplayWarning(const char *title, const char *text)
{
_gui_sendmessage(GUI_DISPLAY_WARNING, (void*)title, (void*)text);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst = hinstDLL;

View File

@ -787,8 +787,7 @@ typedef enum
GUI_GET_GLOBAL_NOTES, // param1=char** text, param2=unused
GUI_SET_DEBUGGEE_NOTES, // param1=const char* text, param2=unused
GUI_GET_DEBUGGEE_NOTES, // param1=char** text, param2=unused
GUI_DUMP_AT_N, // param1=int index, param2=duint va
GUI_DISPLAY_WARNING // param1=const char *text, param2=unused
GUI_DUMP_AT_N // param1=int index, param2=duint va
} GUIMSG;
//GUI Typedefs
@ -888,7 +887,6 @@ BRIDGE_IMPEXP void GuiGetGlobalNotes(char** text);
BRIDGE_IMPEXP void GuiSetDebuggeeNotes(const char* text);
BRIDGE_IMPEXP void GuiGetDebuggeeNotes(char** text);
BRIDGE_IMPEXP void GuiDumpAtN(duint va, int index);
BRIDGE_IMPEXP void GuiDisplayWarning(const char *title, const char *text);
#ifdef __cplusplus
}

View File

@ -282,7 +282,7 @@ void AbstractTableView::mouseMoveEvent(QMouseEvent* event)
int wNewSize = getColumnWidth(mColResizeData.index) + delta;
setColumnWidth(mColResizeData.index, wNewSize);
mColResizeData.lastPosX = event->x();
update();
repaint();
}
}
break;
@ -299,8 +299,6 @@ void AbstractTableView::mouseMoveEvent(QMouseEvent* event)
{
mColumnList[mHeader.activeButtonIndex].header.isMouseOver = false;
}
update();
}
break;
@ -355,7 +353,7 @@ void AbstractTableView::mousePressEvent(QMouseEvent* event)
mGuiState = AbstractTableView::HeaderButtonPressed;
update();
repaint();
}
}
@ -399,7 +397,7 @@ void AbstractTableView::mouseReleaseEvent(QMouseEvent* event)
mColumnList[i].header.isPressed = false;
}
update();
repaint();
}
}

View File

@ -528,14 +528,6 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
emit dumpAtN((duint)param1, (int)param2);
}
break;
case GUI_DISPLAY_WARNING:
{
QString title = QString((const char*)param1);
QString text = QString((const char*)param2);
emit displayWarning(title, text);
}
break;
}
return nullptr;
}

View File

@ -306,6 +306,7 @@ void CPUDisassembly::setupRightClickContextMenu()
MenuBuilder* labelMenu = new MenuBuilder(this);
labelMenu->addAction(makeShortcutAction("Label Current Address", SLOT(setLabelSlot()), "ActionSetLabel"));
QAction* labelAddress = makeAction("Label", SLOT(setLabelAddressSlot()));
labelMenu->addAction(labelAddress, [this, labelAddress](QMenu*)
{
BASIC_INSTRUCTION_INFO instr_info;
@ -448,6 +449,8 @@ void CPUDisassembly::toggleInt3BPActionSlot()
DbgCmdExec(wCmd.toUtf8().constData());
//emit Disassembly::repainted();
repaint();
}
@ -467,6 +470,8 @@ void CPUDisassembly::toggleHwBpActionSlot()
}
DbgCmdExec(wCmd.toUtf8().constData());
repaint();
}
@ -526,6 +531,8 @@ void CPUDisassembly::setHwBpAt(duint va, int slot)
}
if(wBPList.count)
BridgeFree(wBPList.bp);
repaint();
}
void CPUDisassembly::setNewOriginHereActionSlot()
@ -558,6 +565,9 @@ void CPUDisassembly::setLabelSlot()
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
repaint();
GuiUpdateAllViews();
}
@ -587,6 +597,9 @@ void CPUDisassembly::setLabelAddressSlot()
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
repaint();
GuiUpdateAllViews();
}
@ -616,6 +629,7 @@ void CPUDisassembly::setCommentSlot()
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
GuiUpdateAllViews();
}
@ -637,6 +651,9 @@ void CPUDisassembly::setBookmarkSlot()
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
repaint();
GuiUpdateAllViews();
}
@ -690,6 +707,8 @@ void CPUDisassembly::toggleFunctionSlot()
QString cmd = "functiondel " + start_text;
DbgCmdExec(cmd.toUtf8().constData());
}
repaint();
}
void CPUDisassembly::assembleSlot()
@ -945,6 +964,8 @@ void CPUDisassembly::enableHighlightingModeSlot()
else
mHighlightingMode = true;
reloadData();
repaint();
}
void CPUDisassembly::binaryEditSlot()
@ -1234,11 +1255,6 @@ void CPUDisassembly::decompileFunctionSlot()
}
}
void CPUDisassembly::displayWarningSlot(QString title, QString text)
{
QMessageBox::QMessageBox(QMessageBox::Information, title, text, QMessageBox::Ok).exec();
}
void CPUDisassembly::paintEvent(QPaintEvent* event)
{
// Hook/hack to update the sidebar at the same time as this widget.

View File

@ -83,7 +83,6 @@ public slots:
void openSourceSlot();
void decompileSelectionSlot();
void decompileFunctionSlot();
void displayWarningSlot(QString title, QString text);
protected:
void paintEvent(QPaintEvent* event);

View File

@ -1,6 +1,7 @@
#include "CPUSideBar.h"
#include "Configuration.h"
#include "Breakpoints.h"
#include <QToolTip>
CPUSideBar::CPUSideBar(CPUDisassembly* Ptr, QWidget* parent) : QAbstractScrollArea(parent)
{
@ -8,13 +9,16 @@ CPUSideBar::CPUSideBar(CPUDisassembly* Ptr, QWidget* parent) : QAbstractScrollAr
selectedVA = -1;
viewableRows = 0;
CodePtr = Ptr;
mDisas = Ptr;
InstrBuffer = CodePtr->instructionsBuffer();
InstrBuffer = mDisas->instructionsBuffer();
memset(&regDump, 0, sizeof(REGDUMP));
updateSlots();
this->setMouseTracking(true);
}
CPUSideBar::~CPUSideBar()
@ -51,12 +55,15 @@ void CPUSideBar::updateColors()
void CPUSideBar::updateFonts()
{
m_DefaultFont = CodePtr->font();
m_DefaultFont = mDisas->font();
this->setFont(m_DefaultFont);
QFontMetrics metrics(m_DefaultFont);
fontWidth = metrics.width(' ');
fontHeight = metrics.height();
mBulletRadius = fontHeight / 2;
mBulletYOffset = (fontHeight - mBulletRadius) / 2;
}
QSize CPUSideBar::sizeHint() const
@ -74,7 +81,7 @@ void CPUSideBar::debugStateChangedSlot(DBGSTATE state)
void CPUSideBar::repaint()
{
fontHeight = CodePtr->getRowHeight();
fontHeight = mDisas->getRowHeight();
viewport()->update();
}
@ -109,8 +116,8 @@ bool CPUSideBar::isJump(int i) const
auto branchType = instr.branchType;
if(branchType != Instruction_t::None)
{
duint start = CodePtr->getBase();
duint end = start + CodePtr->getSize();
duint start = mDisas->getBase();
duint end = start + mDisas->getSize();
duint addr = instr.branchDestination;
return addr >= start && addr < end; //do not draw jumps that go out of the section
}
@ -135,15 +142,15 @@ void CPUSideBar::paintEvent(QPaintEvent* event)
int jumpoffset = 0;
dsint last_va = InstrBuffer->last().rva + CodePtr->getBase();
dsint first_va = InstrBuffer->first().rva + CodePtr->getBase();
dsint last_va = InstrBuffer->last().rva + mDisas->getBase();
dsint first_va = InstrBuffer->first().rva + mDisas->getBase();
for(int line = 0; line < viewableRows; line++)
{
if(line >= InstrBuffer->size()) //at the end of the page it will crash otherwise
break;
Instruction_t instr = InstrBuffer->at(line);
dsint instrVA = instr.rva + CodePtr->getBase();
dsint instrVA = instr.rva + mDisas->getBase();
// draw bullet
drawBullets(&painter, line, DbgGetBpxTypeAt(instrVA) != bp_none, DbgIsBpDisabled(instrVA), DbgGetBookmarkAt(instrVA));
@ -155,7 +162,7 @@ void CPUSideBar::paintEvent(QPaintEvent* event)
bool isConditional = instr.branchType == Instruction_t::Conditional;
/*
if(CodePtr->currentEIP() != InstrBuffer->at(line).rva) //create a setting for this
if(mDisas->currentEIP() != InstrBuffer->at(line).rva) //create a setting for this
isJumpGoingToExecute=false;
*/
@ -168,13 +175,13 @@ void CPUSideBar::paintEvent(QPaintEvent* event)
continue;
// Do not draw jumps that leave the memory range
if(destVA >= CodePtr->getBase() + CodePtr->getSize() || destVA < CodePtr->getBase())
if(destVA >= mDisas->getBase() + mDisas->getSize() || destVA < mDisas->getBase())
continue;
if(destVA <= last_va && destVA >= first_va)
{
int destLine = line;
while(destLine > -1 && destLine < InstrBuffer->size() && InstrBuffer->at(destLine).rva + CodePtr->getBase() != destVA)
while(destLine > -1 && destLine < InstrBuffer->size() && InstrBuffer->at(destLine).rva + mDisas->getBase() != destVA)
{
if(destVA > instrVA) //jump goes up
destLine++;
@ -190,9 +197,9 @@ void CPUSideBar::paintEvent(QPaintEvent* event)
}
// Register label line positions
const dsint cur_VA = CodePtr->getBase() + InstrBuffer->at(line).rva;
const dsint cur_VA = mDisas->getBase() + InstrBuffer->at(line).rva;
if(InstrBuffer->at(line).rva == CodePtr->currentEIP())
if(InstrBuffer->at(line).rva == mDisas->currentEIP())
registerLines[0] = line;
if(cur_VA == regDump.regcontext.cax) registerLines[1] = line;
@ -242,8 +249,8 @@ void CPUSideBar::mouseReleaseEvent(QMouseEvent* e)
if(y < bulletY || y > bulletY + bulletRadius)
return;
// calculate virtual adress of clicked line
duint wVA = InstrBuffer->at(line).rva + CodePtr->getBase();
// calculate virtual address of clicked line
duint wVA = InstrBuffer->at(line).rva + mDisas->getBase();
QString wCmd;
// create --> disable --> delete --> create --> ...
@ -264,7 +271,50 @@ void CPUSideBar::mouseReleaseEvent(QMouseEvent* e)
wCmd = "bp " + QString("%1").arg(wVA, sizeof(dsint) * 2, 16, QChar('0')).toUpper();
DbgCmdExec(wCmd.toUtf8().constData());
break;
}
mDisas->repaint();
}
void CPUSideBar::mouseMoveEvent(QMouseEvent *event)
{
if(!DbgIsDebugging())
{
QAbstractScrollArea::mouseMoveEvent(event);
return;
}
QPoint mousePos = event->pos();
QPoint globalMousePos = event->globalPos();
const int mLine = mousePos.y() / fontHeight;
const int mBulletX = viewport()->width() - mBulletXOffset;
const int mBulletY = mLine * fontHeight + mBulletYOffset;
const int mouseBulletXOffset = abs(mBulletX - mousePos.x());
const int mouseBulletYOffset = abs(mBulletY - mousePos.y());
// mouseCursor not on a bullet
if(mouseBulletXOffset > mBulletRadius || mouseBulletYOffset > mBulletRadius)
{
QToolTip::hideText();
return;
}
// calculate virtual address of clicked line
duint wVA = InstrBuffer->at(mLine).rva + mDisas->getBase();
switch(Breakpoints::BPState(bp_normal, wVA))
{
case bp_enabled:
QToolTip::showText(globalMousePos, "BP enabled");
break;
case bp_disabled:
QToolTip::showText(globalMousePos, "BP disabled");
break;
case bp_non_existent:
QToolTip::showText(globalMousePos, "No BP set");
break;
}
}
@ -413,15 +463,14 @@ void CPUSideBar::drawBullets(QPainter* painter, int line, bool isbp, bool isbpdi
painter->setPen(mBackgroundColor);
const int radius = fontHeight / 2; //14/2=7
const int x = viewport()->width() - mBulletXOffset; //initial x
const int y = line * fontHeight; //initial y
const int yAdd = (fontHeight - radius) / 2;
const int x = viewport()->width() - 10; //initial x
painter->setRenderHint(QPainter::Antialiasing, true);
if(isbpdisabled) //disabled breakpoint
painter->setBrush(QBrush(mBulletDisabledBreakpointColor));
painter->drawEllipse(x, y + yAdd, radius, radius);
painter->drawEllipse(x, y + mBulletYOffset, mBulletRadius, mBulletRadius);
painter->restore();
}

View File

@ -33,8 +33,9 @@ public slots:
void setSelection(dsint selVA);
protected:
virtual void paintEvent(QPaintEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* e);
void paintEvent(QPaintEvent* event);
void mouseReleaseEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* event);
void drawLabel(QPainter* painter, int Line, QString Text);
void drawBullets(QPainter* painter, int line, bool ispb, bool isbpdisabled, bool isbookmark);
@ -47,8 +48,12 @@ private:
QFont m_DefaultFont;
int fontWidth, fontHeight;
int viewableRows;
int mBulletRadius;
int mBulletYOffset = 10;
const int mBulletXOffset = 10;
CPUDisassembly* CodePtr;
CPUDisassembly* mDisas;
QList<Instruction_t>* InstrBuffer;
REGDUMP regDump;