1
0
Fork 0

GUI: Cache some values in dissassembler; standardize config updates (signals/vtable)

This commit is contained in:
Nukem 2015-11-12 23:59:00 -05:00
parent 5ae3315ece
commit c56f0d4d76
12 changed files with 172 additions and 86 deletions

View File

@ -13,9 +13,6 @@ AbstractTableView::AbstractTableView(QWidget* parent) : QAbstractScrollArea(pare
data.activeButtonIndex = -1;
mHeader = data;
fontsUpdated();
colorsUpdated();
// Paint cell content only when debugger is running
setDrawDebugOnly(true);
@ -41,18 +38,32 @@ AbstractTableView::AbstractTableView(QWidget* parent) : QAbstractScrollArea(pare
mMouseWheelScrollDelta = 4;
setMouseTracking(true);
// Signals/Slots Connections
// Slots
connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(vertSliderActionSlot(int)));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(slot_updateColors()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(slot_updateFonts()));
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(slot_updateShortcuts()));
// todo: try Qt::QueuedConnection to init
Initialize();
}
void AbstractTableView::colorsUpdatedSlot()
/************************************************************************************
Configuration
************************************************************************************/
void AbstractTableView::Initialize()
{
colorsUpdated();
// Required to be called by each constructor because
// of VTable changes
//
// Init all other updates once
updateColors();
updateFonts();
updateShortcuts();
}
void AbstractTableView::colorsUpdated()
void AbstractTableView::updateColors()
{
backgroundColor = ConfigColor("AbstractTableViewBackgroundColor");
textColor = ConfigColor("AbstractTableViewTextColor");
@ -61,16 +72,30 @@ void AbstractTableView::colorsUpdated()
selectionColor = ConfigColor("AbstractTableViewSelectionColor");
}
void AbstractTableView::fontsUpdatedSlot()
{
fontsUpdated();
}
void AbstractTableView::fontsUpdated()
void AbstractTableView::updateFonts()
{
setFont(ConfigFont("AbstractTableView"));
}
void AbstractTableView::updateShortcuts()
{
}
void AbstractTableView::slot_updateColors()
{
updateColors();
}
void AbstractTableView::slot_updateFonts()
{
updateFonts();
}
void AbstractTableView::slot_updateShortcuts()
{
updateShortcuts();
}
/************************************************************************************
Painting Stuff
************************************************************************************/

View File

@ -36,15 +36,18 @@ public:
class AbstractTableView : public QAbstractScrollArea
{
Q_OBJECT
public:
enum GuiState_t {NoState, ReadyToResize, ResizeColumnState, HeaderButtonPressed};
// Constructor
explicit AbstractTableView(QWidget* parent = 0);
// Config updates
virtual void colorsUpdated();
virtual void fontsUpdated();
// Configuration
virtual void Initialize();
virtual void updateColors();
virtual void updateFonts();
virtual void updateShortcuts();
// Pure Virtual Methods
virtual QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) = 0;
@ -116,8 +119,10 @@ signals:
void repainted();
public slots:
void colorsUpdatedSlot();
void fontsUpdatedSlot();
// Configuration
void slot_updateColors();
void slot_updateFonts();
void slot_updateShortcuts();
// Update/Reload/Refresh/Repaint
virtual void reloadData();
@ -185,13 +190,15 @@ private:
ScrollBar64_t mScrollBarAttributes;
protected:
bool mAllowPainting;
bool mDrawDebugOnly;
// Configuration
QColor backgroundColor;
QColor textColor;
QColor separatorColor;
QColor headerTextColor;
QColor selectionColor;
bool mAllowPainting;
bool mDrawDebugOnly;
};
#endif // ABSTRACTTABLEVIEW_H

View File

@ -2,10 +2,8 @@
#include "Configuration.h"
#include "Bridge.h"
Disassembly::Disassembly(QWidget* parent)
: AbstractTableView(parent)
Disassembly::Disassembly(QWidget* parent) : AbstractTableView(parent)
{
fontsUpdated();
mMemPage = new MemoryPage(0, 0);
mInstBuffer.clear();
@ -32,6 +30,9 @@ Disassembly::Disassembly(QWidget* parent)
mGuiState = Disassembly::NoState;
// Update fonts immediately because they are used in calculations
updateFonts();
setRowCount(mMemPage->getSize());
addColumnAt(getCharWidth() * 2 * sizeof(dsint) + 8, "", false); //address
@ -43,18 +44,41 @@ Disassembly::Disassembly(QWidget* parent)
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
// Slots
connect(Bridge::getBridge(), SIGNAL(repaintGui()), this, SLOT(reloadData()));
connect(Bridge::getBridge(), SIGNAL(updateDump()), this, SLOT(reloadData()));
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChanged(DBGSTATE)));
Initialize();
}
void Disassembly::colorsUpdated()
void Disassembly::updateColors()
{
AbstractTableView::colorsUpdated();
AbstractTableView::updateColors();
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
mInstructionHighlightColor = ConfigColor("InstructionHighlightColor");
mSelectionColor = ConfigColor("DisassemblySelectionColor");
mCipBackgroundColor = ConfigColor("DisassemblyCipBackgroundColor");
mBreakpointBackgroundColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
mBreakpointColor = ConfigColor("DisassemblyBreakpointColor");
mCipColor = ConfigColor("DisassemblyCipColor");
mHardwareBreakpointBackgroundColor = ConfigColor("DisassemblyHardwareBreakpointBackgroundColor");
mHardwareBreakpointColor = ConfigColor("DisassemblyHardwareBreakpointColor");
mBookmarkBackgroundColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
mBookmarkColor = ConfigColor("DisassemblyBookmarkColor");
mLabelColor = ConfigColor("DisassemblyLabelColor");
mLabelBackgroundColor = ConfigColor("DisassemblyLabelBackgroundColor");
mSelectedAddressBackgroundColor = ConfigColor("DisassemblySelectedAddressBackgroundColor");
mSelectedAddressColor = ConfigColor("DisassemblySelectedAddressColor");
mAddressBackgroundColor = ConfigColor("DisassemblyAddressBackgroundColor");
mAddressColor = ConfigColor("DisassemblyAddressColor");
CapstoneTokenizer::UpdateColors();
mDisasm->UpdateConfig();
}
void Disassembly::fontsUpdated()
void Disassembly::updateFonts()
{
setFont(ConfigFont("Disassembly"));
}
@ -83,7 +107,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
if(mHighlightingMode)
{
QPen pen(ConfigColor("InstructionHighlightColor"));
QPen pen(mInstructionHighlightColor);
pen.setWidth(2);
painter->setPen(pen);
QRect rect = viewport()->rect();
@ -95,7 +119,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
// Highlight if selected
if(wIsSelected)
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblySelectionColor")));
painter->fillRect(QRect(x, y, w, h), QBrush(mSelectionColor));
switch(col)
{
@ -108,39 +132,39 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
bool isbookmark = DbgGetBookmarkAt(cur_addr);
if(mInstBuffer.at(rowOffset).rva == mCipRva && !mIsRunning) //cip + not running
{
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyCipBackgroundColor")));
painter->fillRect(QRect(x, y, w, h), QBrush(mCipBackgroundColor));
if(!isbookmark) //no bookmark
{
if(bpxtype & bp_normal) //normal breakpoint
{
QColor bpColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
QColor& bpColor = mBreakpointBackgroundColor;
if(!bpColor.alpha()) //we don't want transparent text
bpColor = ConfigColor("DisassemblyBreakpointColor");
if(bpColor == ConfigColor("DisassemblyCipBackgroundColor"))
bpColor = ConfigColor("DisassemblyCipColor");
bpColor = mBreakpointColor;
if(bpColor == mCipBackgroundColor)
bpColor = mCipColor;
painter->setPen(QPen(bpColor));
}
else if(bpxtype & bp_hardware) //hardware breakpoint only
{
QColor hwbpColor = ConfigColor("DisassemblyHardwareBreakpointBackgroundColor");
QColor hwbpColor = mHardwareBreakpointBackgroundColor;
if(!hwbpColor.alpha()) //we don't want transparent text
hwbpColor = ConfigColor("DisassemblyHardwareBreakpointColor");
if(hwbpColor == ConfigColor("DisassemblyCipBackgroundColor"))
hwbpColor = ConfigColor("DisassemblyCipColor");
hwbpColor = mHardwareBreakpointColor;
if(hwbpColor == mCipBackgroundColor)
hwbpColor = mCipColor;
painter->setPen(hwbpColor);
}
else //no breakpoint
{
painter->setPen(QPen(ConfigColor("DisassemblyCipColor")));
painter->setPen(QPen(mCipColor));
}
}
else //bookmark
{
QColor bookmarkColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
QColor bookmarkColor = mBookmarkBackgroundColor;
if(!bookmarkColor.alpha()) //we don't want transparent text
bookmarkColor = ConfigColor("DisassemblyBookmarkColor");
if(bookmarkColor == ConfigColor("DisassemblyCipBackgroundColor"))
bookmarkColor = ConfigColor("DisassemblyCipColor");
bookmarkColor = mBookmarkColor;
if(bookmarkColor == mCipBackgroundColor)
bookmarkColor = mCipColor;
painter->setPen(QPen(bookmarkColor));
}
}
@ -152,25 +176,25 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
{
if(bpxtype == bp_none) //label only
{
painter->setPen(QPen(ConfigColor("DisassemblyLabelColor"))); //red -> address + label text
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyLabelBackgroundColor"))); //fill label background
painter->setPen(QPen(mLabelColor)); //red -> address + label text
painter->fillRect(QRect(x, y, w, h), QBrush(mLabelBackgroundColor)); //fill label background
}
else //label+breakpoint
{
if(bpxtype & bp_normal) //label + normal breakpoint
{
painter->setPen(QPen(ConfigColor("DisassemblyBreakpointColor")));
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBreakpointBackgroundColor"))); //fill red
painter->setPen(QPen(mBreakpointColor));
painter->fillRect(QRect(x, y, w, h), QBrush(mBreakpointBackgroundColor)); //fill red
}
else if(bpxtype & bp_hardware) //label + hardware breakpoint only
{
painter->setPen(QPen(ConfigColor("DisassemblyHardwareBreakpointColor")));
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyHardwareBreakpointBackgroundColor"))); //fill ?
painter->setPen(QPen(mHardwareBreakpointColor));
painter->fillRect(QRect(x, y, w, h), QBrush(mHardwareBreakpointBackgroundColor)); //fill ?
}
else //other cases -> do as normal
{
painter->setPen(QPen(ConfigColor("DisassemblyLabelColor"))); //red -> address + label text
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyLabelBackgroundColor"))); //fill label background
painter->setPen(QPen(mLabelColor)); //red -> address + label text
painter->fillRect(QRect(x, y, w, h), QBrush(mLabelBackgroundColor)); //fill label background
}
}
}
@ -181,13 +205,13 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
QColor background;
if(wIsSelected)
{
background = ConfigColor("DisassemblySelectedAddressBackgroundColor");
painter->setPen(QPen(ConfigColor("DisassemblySelectedAddressColor"))); //black address (DisassemblySelectedAddressColor)
background = mSelectedAddressBackgroundColor;
painter->setPen(QPen(mSelectedAddressColor)); //black address (DisassemblySelectedAddressColor)
}
else
{
background = ConfigColor("DisassemblyAddressBackgroundColor");
painter->setPen(QPen(ConfigColor("DisassemblyAddressColor"))); //DisassemblyAddressColor
background = mAddressBackgroundColor;
painter->setPen(QPen(mAddressColor)); //DisassemblyAddressColor
}
if(background.alpha())
painter->fillRect(QRect(x, y, w, h), QBrush(background)); //fill background

View File

@ -10,8 +10,10 @@ class Disassembly : public AbstractTableView
Q_OBJECT
public:
explicit Disassembly(QWidget* parent = 0);
void colorsUpdated();
void fontsUpdated();
// Configuration
virtual void updateColors();
virtual void updateFonts();
// Reimplemented Functions
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h);
@ -135,6 +137,24 @@ private:
CapstoneTokenizer::SingleToken mHighlightToken;
protected:
// Configuration
QColor mInstructionHighlightColor;
QColor mSelectionColor;
QColor mCipBackgroundColor;
QColor mBreakpointBackgroundColor;
QColor mBreakpointColor;
QColor mCipColor;
QColor mHardwareBreakpointBackgroundColor;
QColor mHardwareBreakpointColor;
QColor mBookmarkBackgroundColor;
QColor mBookmarkColor;
QColor mLabelColor;
QColor mLabelBackgroundColor;
QColor mSelectedAddressBackgroundColor;
QColor mSelectedAddressColor;
QColor mAddressBackgroundColor;
QColor mAddressColor;
bool mRvaDisplayEnabled;
duint mRvaDisplayBase;
dsint mRvaDisplayPageBase;

View File

@ -5,7 +5,6 @@
HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
{
fontsUpdated();
SelectionData_t data;
memset(&data, 0, sizeof(SelectionData_t));
mSelection = data;
@ -25,20 +24,24 @@ HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
mRvaDisplayEnabled = false;
// Slots
connect(Bridge::getBridge(), SIGNAL(updateDump()), this, SLOT(reloadData()));
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChanged(DBGSTATE)));
Initialize();
}
void HexDump::colorsUpdated()
void HexDump::updateColors()
{
AbstractTableView::colorsUpdated();
AbstractTableView::updateColors();
backgroundColor = ConfigColor("HexDumpBackgroundColor");
textColor = ConfigColor("HexDumpTextColor");
selectionColor = ConfigColor("HexDumpSelectionColor");
reloadData();
}
void HexDump::fontsUpdated()
void HexDump::updateFonts()
{
setFont(ConfigFont("HexDump"));
}

View File

@ -77,8 +77,10 @@ public:
} ColumnDescriptor_t;
explicit HexDump(QWidget* parent = 0);
void colorsUpdated();
void fontsUpdated();
// Configuration
virtual void updateColors();
virtual void updateFonts();
//QString getStringToPrint(int rowBase, int rowOffset, int col);
void mouseMoveEvent(QMouseEvent* event);

View File

@ -54,7 +54,7 @@ SearchListView::SearchListView(QWidget* parent) :
mSearchAction = new QAction("Search...", this);
connect(mSearchAction, SIGNAL(triggered()), this, SLOT(searchSlot()));
// Setup signals
// Slots
connect(mList, SIGNAL(keyPressedSignal(QKeyEvent*)), this, SLOT(listKeyPressed(QKeyEvent*)));
connect(mList, SIGNAL(contextMenuSignal(QPoint)), this, SLOT(listContextMenu(QPoint)));
connect(mList, SIGNAL(doubleClickedSignal()), this, SLOT(doubleClickedSlot()));

View File

@ -52,8 +52,8 @@ private:
QList<Instruction_t>* InstrBuffer;
REGDUMP regDump;
// Configuration
private:
// Configuration
QColor mBackgroundColor;
QColor mConditionalJumpLineFalseColor;

View File

@ -7,7 +7,6 @@
CPUStack::CPUStack(QWidget* parent) : HexDump(parent)
{
fontsUpdated();
setShowHeader(false);
int charwidth = getCharWidth();
ColumnDescriptor_t wColDesc;
@ -35,28 +34,28 @@ CPUStack::CPUStack(QWidget* parent) : HexDump(parent)
wColDesc.data = dDesc;
appendDescriptor(2000, "Comments", false, wColDesc);
connect(Bridge::getBridge(), SIGNAL(stackDumpAt(duint, duint)), this, SLOT(stackDumpAt(duint, duint)));
connect(Bridge::getBridge(), SIGNAL(selectionStackGet(SELECTIONDATA*)), this, SLOT(selectionGet(SELECTIONDATA*)));
connect(Bridge::getBridge(), SIGNAL(selectionStackSet(const SELECTIONDATA*)), this, SLOT(selectionSet(const SELECTIONDATA*)));
setupContextMenu();
mGoto = 0;
backgroundColor = ConfigColor("StackBackgroundColor");
textColor = ConfigColor("StackTextColor");
selectionColor = ConfigColor("StackSelectionColor");
// Slots
connect(Bridge::getBridge(), SIGNAL(stackDumpAt(duint, duint)), this, SLOT(stackDumpAt(duint, duint)));
connect(Bridge::getBridge(), SIGNAL(selectionStackGet(SELECTIONDATA*)), this, SLOT(selectionGet(SELECTIONDATA*)));
connect(Bridge::getBridge(), SIGNAL(selectionStackSet(const SELECTIONDATA*)), this, SLOT(selectionSet(const SELECTIONDATA*)));
Initialize();
}
void CPUStack::colorsUpdated()
void CPUStack::updateColors()
{
HexDump::colorsUpdated();
HexDump::updateColors();
backgroundColor = ConfigColor("StackBackgroundColor");
textColor = ConfigColor("StackTextColor");
selectionColor = ConfigColor("StackSelectionColor");
}
void CPUStack::fontsUpdated()
void CPUStack::updateFonts()
{
setFont(ConfigFont("Stack"));
}

View File

@ -9,8 +9,11 @@ class CPUStack : public HexDump
Q_OBJECT
public:
explicit CPUStack(QWidget* parent = 0);
void colorsUpdated();
void fontsUpdated();
// Configuration
virtual void updateColors();
virtual void updateFonts();
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h);
void contextMenuEvent(QContextMenuEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);

View File

@ -20,6 +20,9 @@ ScriptView::ScriptView(StdTable* parent) : StdTable(parent)
setIp(0); //no IP
setupContextMenu();
// Slots
connect(Bridge::getBridge(), SIGNAL(scriptAdd(int, const char**)), this, SLOT(add(int, const char**)));
connect(Bridge::getBridge(), SIGNAL(scriptClear()), this, SLOT(clear()));
connect(Bridge::getBridge(), SIGNAL(scriptSetIp(int)), this, SLOT(setIp(int)));
@ -31,15 +34,13 @@ ScriptView::ScriptView(StdTable* parent) : StdTable(parent)
connect(Bridge::getBridge(), SIGNAL(scriptEnableHighlighting(bool)), this, SLOT(enableHighlighting(bool)));
connect(this, SIGNAL(contextMenuSignal(QPoint)), this, SLOT(contextMenuSlot(QPoint)));
setupContextMenu();
selectionColor = ConfigColor("DisassemblySelectionColor");
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
Initialize();
}
void ScriptView::colorsUpdated()
void ScriptView::updateColors()
{
StdTable::colorsUpdated();
StdTable::updateColors();
selectionColor = ConfigColor("DisassemblySelectionColor");
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
}

View File

@ -8,7 +8,9 @@ class ScriptView : public StdTable
Q_OBJECT
public:
explicit ScriptView(StdTable* parent = 0);
void colorsUpdated();
// Configuration
void updateColors();
// Reimplemented Functions
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h);