1
0
Fork 0

Update Zydis in the UI and remove DisassemblyPopup

development
Duncan Ogilvie 2023-08-26 13:58:54 +02:00
parent 812c91d361
commit 5797dae1c3
37 changed files with 1691 additions and 1530 deletions

View File

@ -8,7 +8,7 @@ AbstractStdTable::AbstractStdTable(QWidget* parent) : AbstractTableView(parent)
connect(Bridge::getBridge(), SIGNAL(repaintTableView()), this, SLOT(reloadData()));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestedSlot(QPoint)));
connect(this, SIGNAL(headerButtonPressed(int)), this, SLOT(headerButtonPressedSlot(int)));
connect(this, SIGNAL(headerButtonPressed(duint)), this, SLOT(headerButtonPressedSlot(duint)));
Initialize();
@ -22,27 +22,27 @@ AbstractStdTable::AbstractStdTable(QWidget* parent) : AbstractTableView(parent)
mExportTableCSV = makeShortcutAction(DIcon("database-export"), tr("&Export Table"), SLOT(exportTableSlot()), "ActionExport");
}
QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h)
QString AbstractStdTable::paintContent(QPainter* painter, duint row, duint col, int x, int y, int w, int h)
{
bool isaddr = DbgIsDebugging() && getRowCount() > 0 && col == mAddressColumn;
bool wIsSelected = isSelected(rowBase, rowOffset);
QString text = getCellContent(rowBase + rowOffset, col);
bool rowSelected = isSelected(row);
QString text = getCellContent(row, col);
duint wVA = isaddr ? duint(text.toULongLong(&isaddr, 16)) : 0;
auto wIsTraced = isaddr && DbgFunctions()->GetTraceRecordHitCount(wVA) != 0;
duint va = isaddr ? duint(text.toULongLong(&isaddr, 16)) : 0;
auto rowTraced = isaddr && DbgFunctions()->GetTraceRecordHitCount(va) != 0;
QColor lineBackgroundColor;
bool isBackgroundColorSet;
if(wIsSelected && wIsTraced)
if(rowSelected && rowTraced)
{
lineBackgroundColor = mTracedSelectedAddressBackgroundColor;
isBackgroundColorSet = true;
}
else if(wIsSelected)
else if(rowSelected)
{
lineBackgroundColor = mSelectionColor;
isBackgroundColorSet = true;
}
else if(wIsTraced)
else if(rowTraced)
{
lineBackgroundColor = mTracedBackgroundColor;
isBackgroundColorSet = true;
@ -57,16 +57,16 @@ QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int row
if(col == mAddressColumn && isaddr)
{
char label[MAX_LABEL_SIZE] = "";
if(bAddressLabel && DbgGetLabelAt(wVA, SEG_DEFAULT, label)) //has label
if(bAddressLabel && DbgGetLabelAt(va, SEG_DEFAULT, label)) //has label
{
char module[MAX_MODULE_SIZE] = "";
if(DbgGetModuleAt(wVA, module) && !QString(label).startsWith("JMP.&"))
if(DbgGetModuleAt(va, module) && !QString(label).startsWith("JMP.&"))
text += " <" + QString(module) + "." + QString(label) + ">";
else
text += " <" + QString(label) + ">";
}
BPXTYPE bpxtype = DbgGetBpxTypeAt(wVA);
bool isbookmark = DbgGetBookmarkAt(wVA);
BPXTYPE bpxtype = DbgGetBpxTypeAt(va);
bool isbookmark = DbgGetBookmarkAt(va);
duint cip = Bridge::getBridge()->mLastCip;
if(bCipBase)
@ -76,7 +76,7 @@ QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int row
cip = base;
}
if(DbgIsDebugging() && wVA == cip) //debugging + cip
if(DbgIsDebugging() && va == cip) //debugging + cip
{
painter->fillRect(QRect(x, y, w, h), QBrush(mCipBackgroundColor));
if(!isbookmark) //no bookmark
@ -149,7 +149,7 @@ QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int row
if(bpxtype == bp_none) //no label, no breakpoint
{
QColor background;
if(wIsSelected)
if(rowSelected)
{
background = mSelectedAddressBackgroundColor;
painter->setPen(mSelectedAddressColor); //black address (DisassemblySelectedAddressColor)
@ -177,7 +177,7 @@ QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int row
else //other cases (memory breakpoint in disassembly) -> do as normal
{
QColor background;
if(wIsSelected)
if(rowSelected)
{
background = mSelectedAddressBackgroundColor;
painter->setPen(mSelectedAddressColor); //black address (DisassemblySelectedAddressColor)
@ -265,12 +265,12 @@ QString AbstractStdTable::paintContent(QPainter* painter, dsint rowBase, int row
}
}
while(index != -1);
QStringList split = text.split(QChar('\1'), QString::SkipEmptyParts, Qt::CaseInsensitive);
QStringList split = text.split(QChar('\1'), Qt::SkipEmptyParts, Qt::CaseInsensitive);
//create rich text list
RichTextPainter::CustomRichText_t curRichText;
curRichText.flags = RichTextPainter::FlagColor;
QColor textColor = getCellColor(rowBase + rowOffset, col);
QColor textColor = getCellColor(row, col);
QColor textBackgroundColor = Qt::transparent;
QColor highlightColor = ConfigColor("SearchListViewHighlightColor");
QColor highlightBackgroundColor = ConfigColor("SearchListViewHighlightBackgroundColor");
@ -344,6 +344,7 @@ void AbstractStdTable::mouseMoveEvent(QMouseEvent* event)
else
setSingleSelection(rowIndex);
// TODO: only update if the selection actually changed
updateViewport();
accept = false;
@ -384,6 +385,7 @@ void AbstractStdTable::mousePressEvent(QMouseEvent* event)
mGuiState = AbstractStdTable::MultiRowsSelectionState;
// TODO: only update if the selection actually changed
updateViewport();
accept = true;
@ -413,8 +415,6 @@ void AbstractStdTable::mouseReleaseEvent(QMouseEvent* event)
{
mGuiState = AbstractStdTable::NoState;
updateViewport();
accept = false;
}
}
@ -509,6 +509,7 @@ void AbstractStdTable::keyPressEvent(QKeyEvent* event)
setTableOffset(getInitialSelection() - getNbrOfLineToPrint() + 2);
}
// TODO: only update if the selection actually changed
updateViewport();
}
else
@ -530,19 +531,19 @@ void AbstractStdTable::enableColumnSorting(bool enabled)
/************************************************************************************
Selection Management
************************************************************************************/
void AbstractStdTable::expandSelectionUpTo(int to)
void AbstractStdTable::expandSelectionUpTo(duint to)
{
if(to < mSelection.firstSelectedIndex)
{
mSelection.fromIndex = to;
mSelection.toIndex = mSelection.firstSelectedIndex;
emit selectionChangedSignal(to);
emit selectionChanged(to);
}
else if(to > mSelection.firstSelectedIndex)
{
mSelection.fromIndex = mSelection.firstSelectedIndex;
mSelection.toIndex = to;
emit selectionChangedSignal(to);
emit selectionChanged(to);
}
else if(to == mSelection.firstSelectedIndex)
{
@ -612,24 +613,24 @@ void AbstractStdTable::expandBottom()
}
}
void AbstractStdTable::setSingleSelection(int index)
void AbstractStdTable::setSingleSelection(duint index)
{
mSelection.firstSelectedIndex = index;
mSelection.fromIndex = index;
mSelection.toIndex = index;
emit selectionChangedSignal(index);
emit selectionChanged(index);
}
int AbstractStdTable::getInitialSelection() const
duint AbstractStdTable::getInitialSelection() const
{
return mSelection.firstSelectedIndex;
}
QList<int> AbstractStdTable::getSelection() const
QList<duint> AbstractStdTable::getSelection() const
{
QList<int> selection;
QList<duint> selection;
selection.reserve(mSelection.toIndex - mSelection.fromIndex);
for(int i = mSelection.fromIndex; i <= mSelection.toIndex; i++)
for(duint i = mSelection.fromIndex; i <= mSelection.toIndex; i++)
{
selection.append(i);
}
@ -655,60 +656,56 @@ void AbstractStdTable::selectEnd()
void AbstractStdTable::selectNext()
{
int wNext = getInitialSelection() + 1;
// TODO: fix the signed/unsigned
duint next = getInitialSelection() + 1;
// Bounding
wNext = wNext > getRowCount() - 1 ? getRowCount() - 1 : wNext;
wNext = wNext < 0 ? 0 : wNext;
next = next > getRowCount() - 1 ? getRowCount() - 1 : next;
next = next < 0 ? 0 : next;
setSingleSelection(wNext);
setSingleSelection(next);
}
void AbstractStdTable::selectPrevious()
{
int wNext = getInitialSelection() - 1;
duint next = getInitialSelection() - 1;
// Bounding
wNext = wNext > getRowCount() - 1 ? getRowCount() - 1 : wNext;
wNext = wNext < 0 ? 0 : wNext;
next = next > getRowCount() - 1 ? getRowCount() - 1 : next;
next = next < 0 ? 0 : next;
setSingleSelection(wNext);
setSingleSelection(next);
}
void AbstractStdTable::selectAll()
{
int index = 0;
int indexEnd = getRowCount() - 1;
duint index = 0;
duint indexEnd = getRowCount() - 1;
mSelection.firstSelectedIndex = index;
mSelection.fromIndex = index;
mSelection.toIndex = indexEnd;
emit selectionChangedSignal(index);
emit selectionChanged(index);
}
bool AbstractStdTable::isSelected(int base, int offset) const
bool AbstractStdTable::isSelected(duint row) const
{
int wIndex = base + offset;
if(wIndex >= mSelection.fromIndex && wIndex <= mSelection.toIndex)
return true;
else
return false;
return row >= mSelection.fromIndex && row <= mSelection.toIndex;
}
bool AbstractStdTable::scrollSelect(int offset)
bool AbstractStdTable::scrollSelect(duint row)
{
if(!isValidIndex(offset, 0))
if(!isValidIndex(row, 0))
return false;
int rangefrom = getTableOffset();
int rangeto = rangefrom + getViewableRowsCount() - 1;
if(offset < rangefrom) //offset lays before the current view
setTableOffset(offset);
else if(offset > (rangeto - 1)) //offset lays after the current view
setTableOffset(offset - getViewableRowsCount() + 2);
setSingleSelection(offset);
auto rangefrom = getTableOffset();
auto rangeto = rangefrom + getViewableRowsCount() - 1;
if(row < rangefrom) //offset lays before the current view
setTableOffset(row);
else if(row > (rangeto - 1)) //offset lays after the current view
setTableOffset(row - getViewableRowsCount() + 2);
setSingleSelection(row);
return true;
}
@ -735,15 +732,15 @@ void AbstractStdTable::deleteAllColumns()
void AbstractStdTable::copyLineSlot()
{
int colCount = getColumnCount();
auto colCount = getColumnCount();
QString finalText = "";
if(colCount == 1)
finalText = getCellContent(getInitialSelection(), 0);
else
{
for(int selected : getSelection())
for(auto selected : getSelection())
{
for(int i = 0; i < colCount; i++)
for(duint i = 0; i < colCount; i++)
{
QString cellContent = getCellContent(selected, i);
if(!cellContent.length()) //skip empty cells
@ -761,14 +758,14 @@ void AbstractStdTable::copyLineSlot()
void AbstractStdTable::copyLineToLogSlot()
{
int colCount = getColumnCount();
int selected = getInitialSelection();
auto colCount = getColumnCount();
auto selected = getInitialSelection();
QString finalText = "";
if(colCount == 1)
finalText = getCellContent(selected, 0);
else
{
for(int i = 0; i < colCount; i++)
for(duint i = 0; i < colCount; i++)
{
QString cellContent = getCellContent(selected, i);
if(!cellContent.length()) //skip empty cells
@ -785,12 +782,12 @@ void AbstractStdTable::copyLineToLogSlot()
QString AbstractStdTable::copyTable(const std::vector<int> & colWidths)
{
int colCount = getColumnCount();
int rowCount = getRowCount();
auto colCount = getColumnCount();
auto rowCount = getRowCount();
QString finalText = "";
if(colCount == 1)
{
for(int i = 0; i < rowCount; i++)
for(duint i = 0; i < rowCount; i++)
{
QString cellContent = getCellContent(i, 0);
if(!cellContent.length()) //skip empty cells
@ -803,7 +800,7 @@ QString AbstractStdTable::copyTable(const std::vector<int> & colWidths)
//std::vector<int> colWidths;
//for(int i = 0; i < colCount; i++)
// colWidths.push_back(getMaxColumnLength(i));
for(int i = 0; i < colCount; i++)
for(duint i = 0; i < colCount; i++)
{
if(i)
finalText += " ";
@ -855,11 +852,11 @@ void AbstractStdTable::copyTableToLogSlot()
void AbstractStdTable::copyTableResizeSlot()
{
std::vector<int> colWidths;
int rowCount = getRowCount();
int colCount = getColumnCount();
for(int i = 0; i < colCount; i++)
auto rowCount = getRowCount();
auto colCount = getColumnCount();
for(duint i = 0; i < colCount; i++)
{
int max = getCellContent(0, i).length();
auto max = getCellContent(0, i).length();
for(int j = 1; j < rowCount; j++)
max = std::max(getCellContent(j, i).length(), max);
colWidths.push_back(max);
@ -874,7 +871,7 @@ void AbstractStdTable::copyTableResizeToLogSlot()
int colCount = getColumnCount();
for(int i = 0; i < colCount; i++)
{
int max = getCellContent(0, i).length();
auto max = getCellContent(0, i).length();
for(int j = 1; j < rowCount; j++)
max = std::max(getCellContent(j, i).length(), max);
colWidths.push_back(max);
@ -934,7 +931,7 @@ void AbstractStdTable::setupCopyMenu(QMenu* copyMenu)
void AbstractStdTable::setupCopyColumnMenu(QMenu* copyMenu)
{
for(int i = 0; i < getColumnCount(); i++)
for(duint i = 0; i < getColumnCount(); i++)
{
if(!getCellContent(getInitialSelection(), i).length()) //skip empty cells
continue;
@ -1022,7 +1019,7 @@ void AbstractStdTable::contextMenuRequestedSlot(const QPoint & pos)
}
}
void AbstractStdTable::headerButtonPressedSlot(int col)
void AbstractStdTable::headerButtonPressedSlot(duint col)
{
if(!mIsColumnSortingAllowed)
return;
@ -1046,22 +1043,16 @@ void AbstractStdTable::reloadData()
AbstractTableView::reloadData();
}
duint AbstractStdTable::getDisassemblyPopupAddress(int mousex, int mousey)
duint AbstractStdTable::getAddressForPosition(int x, int y)
{
if(!bDisassemblyPopupEnabled) //No disassembly popup is meaningful for this table
return 0;
int c = getColumnIndexFromX(mousex);
int r = getTableOffset() + getIndexOffsetFromY(transY(mousey));
auto c = getColumnIndexFromX(x);
auto r = getTableOffset() + getIndexOffsetFromY(transY(y));
if(r < getRowCount())
{
QString cell = getCellContent(r, c);
duint addr;
bool ok = false;
#ifdef _WIN64
addr = cell.toULongLong(&ok, 16);
#else //x86
addr = cell.toULong(&ok, 16);
#endif //_WIN64
if(!ok)
return 0;
else

View File

@ -7,7 +7,7 @@ class AbstractStdTable : public AbstractTableView
Q_OBJECT
public:
explicit AbstractStdTable(QWidget* parent = 0);
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) override;
QString paintContent(QPainter* painter, duint row, duint col, int x, int y, int w, int h) override;
void updateColors() override;
void reloadData() override;
@ -21,30 +21,29 @@ public:
void enableColumnSorting(bool enabled);
// Selection Management
void expandSelectionUpTo(int to);
void expandSelectionUpTo(duint to);
void expandUp();
void expandDown();
void expandTop();
void expandBottom();
void setSingleSelection(int index);
int getInitialSelection() const;
QList<int> getSelection() const;
void setSingleSelection(duint index);
duint getInitialSelection() const;
QList<duint> getSelection() const;
void selectStart();
void selectEnd();
void selectNext();
void selectPrevious();
void selectAll();
bool isSelected(int base, int offset) const;
bool scrollSelect(int offset);
bool isSelected(duint row) const;
bool scrollSelect(duint row);
// Data Management
void addColumnAt(int width, QString title, bool isClickable, QString copyTitle = "");
void deleteAllColumns() override;
virtual QString getCellContent(int r, int c) = 0;
virtual bool isValidIndex(int r, int c) = 0;
virtual void sortRows(int column, bool ascending) = 0;
duint getDisassemblyPopupAddress(int mousex, int mousey) override;
virtual QString getCellContent(duint row, duint column) = 0;
virtual bool isValidIndex(duint row, duint column) = 0;
virtual void sortRows(duint column, bool ascending) = 0;
//context menu helpers
void setupCopyMenu(QMenu* copyMenu);
@ -54,13 +53,13 @@ public:
void setCopyMenuOnly(bool bSet, bool bDebugOnly = true);
//draw helpers
void setHighlightText(QString highlightText, int minCol = 0)
void setHighlightText(QString highlightText, duint minCol = 0)
{
mHighlightText = highlightText;
mMinimumHighlightColumn = minCol;
}
void setAddressColumn(int col, bool cipBase = false)
void setAddressColumn(duint col, bool cipBase = false)
{
mAddressColumn = col;
bCipBase = cipBase;
@ -71,13 +70,8 @@ public:
bAddressLabel = addressLabel;
}
bool setDisassemblyPopupEnabled(bool enabled)
{
return bDisassemblyPopupEnabled = enabled;
}
signals:
void selectionChangedSignal(int index);
void selectionChanged(duint index);
void keyPressedSignal(QKeyEvent* event);
void doubleClickedSignal();
void contextMenuSignal(const QPoint & pos);
@ -92,21 +86,22 @@ public slots:
void copyEntrySlot();
void exportTableSlot();
void contextMenuRequestedSlot(const QPoint & pos);
void headerButtonPressedSlot(int col);
void headerButtonPressedSlot(duint col);
protected:
QString copyTable(const std::vector<int> & colWidths);
duint getAddressForPosition(int x, int y) override;
struct SelectionData
{
int firstSelectedIndex = 0;
int fromIndex = 0;
int toIndex = 0;
duint firstSelectedIndex = 0;
duint fromIndex = 0;
duint toIndex = 0;
};
SelectionData mSelection;
enum
enum GuiState
{
NoState,
MultiRowsSelectionState
@ -121,7 +116,7 @@ protected:
struct SortData
{
int column = -1;
duint column = -1;
bool ascending = true;
} mSort;
@ -146,7 +141,6 @@ protected:
int mMinimumHighlightColumn = 0;
int mAddressColumn = -1;
bool bAddressLabel = true;
bool bDisassemblyPopupEnabled = true;
QAction* mCopyLine;
QAction* mCopyTable;

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
#include "ActionHelpers.h"
class CachedFontMetrics;
class DisassemblyPopup;
class ColumnReorderDialog;
//Hacky class that fixes a really annoying cursor problem
class AbstractTableScrollBar : public QScrollBar
@ -22,8 +22,7 @@ class AbstractTableScrollBar : public QScrollBar
Q_OBJECT
public:
explicit AbstractTableScrollBar(QScrollBar* scrollbar);
void enterEvent(QEvent* event) override;
void leaveEvent(QEvent* event) override;
bool event(QEvent* event) override;
};
class AbstractTableView;
@ -32,16 +31,6 @@ class AbstractTableView : public QAbstractScrollArea, public ActionHelper<Abstra
Q_OBJECT
public:
enum GuiState
{
NoState,
ReadyToResize,
ResizeColumnState,
HeaderButtonPressed,
HeaderButtonReordering
};
// Constructor
explicit AbstractTableView(QWidget* parent = 0);
virtual ~AbstractTableView() = default;
@ -51,8 +40,8 @@ public:
virtual void updateFonts();
// Pure Virtual Methods
virtual QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) = 0;
virtual QColor getCellColor(int r, int c);
virtual QString paintContent(QPainter* painter, duint row, duint col, int x, int y, int w, int h) = 0;
virtual QColor getCellColor(duint row, duint col);
// Painting Stuff
void paintEvent(QPaintEvent* event) override;
@ -65,53 +54,62 @@ public:
void wheelEvent(QWheelEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void leaveEvent(QEvent* event) override;
void hideEvent(QHideEvent* event) override;
// ScrollBar Management
virtual dsint sliderMovedHook(int type, dsint value, dsint delta); // can be made protected
int scaleFromUint64ToScrollBarRange(dsint value); // can be made private
dsint scaleFromScrollBarRangeToUint64(int value); // can be made private
virtual duint sliderMovedHook(QScrollBar::SliderAction action, duint prevTableOffset, dsint delta); // can be made protected
int scaleFromUint64ToScrollBarRange(duint value); // can be made private
duint scaleFromScrollBarRangeToUint64(int value); // can be made private
void updateScrollBarRange(dsint range); // setRowCount+resizeEvent needs this, can be made private
void updateScrollBarRange(duint range); // setRowCount+resizeEvent needs this, can be made private
// Coordinates Utils
int getIndexOffsetFromY(int y) const; // can be made protected
int getColumnIndexFromX(int x) const; // can be made protected
int getColumnPosition(int index) const; // can be made protected
dsint getIndexOffsetFromY(int y) const; // can be made protected
duint getColumnIndexFromX(int x) const; // can be made protected
int getColumnPosition(duint column) const; // can be made protected
int transY(int y) const; // can be made protected
int getViewableRowsCount() const; // can be made protected
virtual int getLineToPrintcount() const;
// TODO: this should probably be uint32_t?
duint getViewableRowsCount() const; // can be made protected
duint getMaxTableOffset() const;
// New Columns/New Size
virtual void addColumnAt(int width, const QString & title, bool isClickable);
virtual void setRowCount(dsint count);
virtual void setRowCount(duint count);
virtual void deleteAllColumns(); // can be made protected, although it makes sense as a public API
void setColTitle(int index, const QString & title); // can be deleted, although it makes sense as a public API
QString getColTitle(int index) const; // can be deleted, although it makes sense as a public API
void setColTitle(duint col, const QString & title); // can be deleted, although it makes sense as a public API
QString getColTitle(duint col) const; // can be deleted, although it makes sense as a public API
enum GuiState
{
NoState,
ReadyToResize,
ResizeColumnState,
HeaderButtonPressed,
HeaderButtonReordering
};
// Getter & Setter
dsint getRowCount() const;
int getColumnCount() const;
duint getRowCount() const;
duint getColumnCount() const;
int getRowHeight() const;
int getColumnWidth(int index) const;
void setColumnWidth(int index, int width);
void setColumnOrder(int pos, int index);
int getColumnOrder(int index) const;
int getColumnWidth(duint col) const;
void setColumnWidth(duint col, int width);
void setColumnOrder(duint col, duint colNew);
duint getColumnOrder(duint col) const;
int getHeaderHeight() const; // can be made protected
int getTableHeight() const; // can be made protected
int getGuiState() const; // can be made protected
int getNbrOfLineToPrint() const;
void setNbrOfLineToPrint(int parNbrOfLineToPrint);
GuiState getGuiState() const; // can be made protected
duint getNbrOfLineToPrint() const; // TODO: should this be signed?
void setNbrOfLineToPrint(duint parNbrOfLineToPrint);
void setShowHeader(bool show);
int getCharWidth() const;
bool getColumnHidden(int col) const;
void setColumnHidden(int col, bool hidden);
int calculateColumnWidth(int characterCount) const;
bool getColumnHidden(duint col) const;
void setColumnHidden(duint col, bool hidden);
bool getDrawDebugOnly() const;
void setDrawDebugOnly(bool value);
bool getAllowPainting() const;
void setAllowPainting(bool allow);
void setDisassemblyPopupEnabled(bool enable);
// UI customization
void loadColumnFromConfig(const QString & viewName);
@ -119,20 +117,20 @@ public:
static void setupColumnConfigDefaultValue(QMap<QString, duint> & map, const QString & viewName, int columnCount);
// Table offset management
dsint getTableOffset() const;
void setTableOffset(dsint val);
duint getTableOffset() const; // TODO: duint
void setTableOffset(duint val); // TODO: duint
// Update/Reload/Refresh/Repaint
virtual void prepareData();
virtual duint getDisassemblyPopupAddress(int mousex, int mousey);
virtual duint getAddressForPosition(int x, int y);
signals:
void enterPressedSignal();
void headerButtonPressed(int col);
void headerButtonReleased(int col);
void tableOffsetChanged(dsint i);
void viewableRowsChanged(int rows);
void headerButtonPressed(duint col);
void headerButtonReleased(duint col);
void tableOffsetChanged(duint i);
void viewableRowsChanged(duint rowCount);
void repainted();
public slots:
@ -145,96 +143,96 @@ public slots:
void editColumnDialog();
protected slots:
void ShowDisassemblyPopup(duint addr, int x, int y); // this should probably be a slot, but doesn't need emit fixes (it's already used correctly)
void timerEvent(QTimerEvent* event);
private slots:
// Configuration
void updateColorsSlot();
void updateFontsSlot();
void updateShortcutsSlot();
void shutdownSlot();
void closeSlot();
private:
struct ColumnResizingData
GuiState mGuiState = NoState;
struct ColumnResizeState
{
bool splitHandle;
int index;
int lastPosX;
};
bool splitHandle = false;
int index = -1;
int lastPosX = -1;
} mColResizeData;
struct HeaderButton
{
bool isClickable;
bool isPressed;
bool isMouseOver;
bool isClickable = false;
bool isPressed = false;
bool isMouseOver = false;
};
struct Column
{
int width;
bool hidden;
int width = 0;
int paintedWidth = -1;
bool hidden = false;
HeaderButton header;
QString title;
};
struct Header
struct HeaderConfig
{
bool isVisible;
int height;
int activeButtonIndex;
};
struct ScrollBar64
{
bool is64;
int rightShiftCount;
};
GuiState mGuiState;
Header mHeader;
QPushButton mHeaderButtonSytle;
bool isVisible = true;
int height = 20;
int activeButtonIndex = -1;
} mHeader;
int mMinColumnWidth = 5;
QList<Column> mColumnList;
ColumnResizingData mColResizeData;
QList<duint> mColumnOrder;
int mReorderStartX = -1;
int mHoveredColumnDisplayIndex = -1;
QList<int> mColumnOrder;
int mReorderStartX;
int mHoveredColumnDisplayIndex;
duint mRowCount = 0;
duint mTableOffset = 0;
duint mPrevTableOffset = -1;
duint mNbrOfLineToPrint = 0;
dsint mRowCount;
dsint mTableOffset;
dsint mPrevTableOffset;
int mNbrOfLineToPrint;
bool mShouldReload = true;
bool mDrawDebugOnly = false;
bool mShouldReload;
bool mDrawDebugOnly;
bool mPopupEnabled;
int mPopupTimer;
// State for accumulating scroll events
enum ScrollDirection
{
ScrollUnknown,
ScrollVertical,
ScrollHorizontal,
} mPixelScrollDirection = ScrollUnknown;
QPoint mPixelScrollDelta;
QPoint mAngleScrollDelta;
static int mMouseWheelScrollDelta;
ScrollBar64 mScrollBarAttributes;
struct ScrollBarAttributes
{
bool is64 = false;
int rightShiftCount = 0;
} mScrollBarAttributes;
int getColumnDisplayIndexFromX(int x);
friend class ColumnReorderDialog;
protected:
// Configuration
QColor mBackgroundColor;
QColor mTextColor;
QColor mSeparatorColor;
QColor mHeaderTextColor;
QColor mSelectionColor;
QString mViewName;
void updateLastColumnWidth();
bool mAllowPainting;
protected:
bool mAllowPainting = true;
// Configuration
QColor mTextColor;
QColor mBackgroundColor;
QColor mHeaderTextColor;
QColor mHeaderBackgroundColor;
QColor mSeparatorColor;
QColor mSelectionColor;
QString mViewName; // TODO: this is needed during construction
// Font metrics
CachedFontMetrics* mFontMetrics;
CachedFontMetrics* mFontMetrics = nullptr;
void invalidateCachedFont();
// Disassembly Popup
DisassemblyPopup* mDisassemblyPopup;
ColumnReorderDialog* mReorderDialog = nullptr;
};

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,19 @@
#pragma once
#include "AbstractTableView.h"
#include "QBeaEngine.h"
#include "QZydis.h"
#include <QTextLayout>
#include "Architecture.h"
class CodeFoldingHelper;
class MemoryPage;
class DisassemblyPopup;
class Disassembly : public AbstractTableView
{
Q_OBJECT
public:
Disassembly(QWidget* parent, bool isMain);
Disassembly(QWidget* parent, bool isMain, Architecture* architecture);
~Disassembly() override;
// Configuration
@ -19,7 +21,7 @@ public:
void updateFonts() override;
// Reimplemented Functions
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) override;
QString paintContent(QPainter* painter, duint row, duint col, int x, int y, int w, int h) override;
// Mouse Management
void mouseMoveEvent(QMouseEvent* event) override;
@ -31,25 +33,25 @@ public:
void keyPressEvent(QKeyEvent* event) override;
// ScrollBar Management
dsint sliderMovedHook(int type, dsint value, dsint delta) override;
duint sliderMovedHook(QScrollBar::SliderAction action, duint value, dsint delta) override;
// Instructions Management
dsint getPreviousInstructionRVA(dsint rva, duint count);
dsint getNextInstructionRVA(dsint rva, duint count, bool isGlobal = false);
dsint getInstructionRVA(dsint index, dsint count);
Instruction_t DisassembleAt(dsint rva);
Instruction_t DisassembleAt(dsint rva, dsint count);
duint getPreviousInstructionRVA(duint rva, duint count);
duint getNextInstructionRVA(duint rva, duint count, bool isGlobal = false);
duint getInstructionRVA(duint index, dsint count);
Instruction_t DisassembleAt(duint rva);
Instruction_t DisassembleAt(duint rva, dsint count);
// Selection Management
void expandSelectionUpTo(dsint to);
void setSingleSelection(dsint index);
dsint getInitialSelection() const;
dsint getSelectionSize() const;
dsint getSelectionStart() const;
dsint getSelectionEnd() const;
void expandSelectionUpTo(duint to);
void setSingleSelection(duint index);
duint getInitialSelection() const;
duint getSelectionSize() const;
duint getSelectionStart() const;
duint getSelectionEnd() const;
void selectNext(bool expand);
void selectPrevious(bool expand);
bool isSelected(dsint base, dsint offset);
bool isSelected(duint base, dsint offset);
bool isSelected(QList<Instruction_t>* buffer, int index) const;
duint getSelectedVa() const;
@ -60,7 +62,7 @@ public:
void paintEvent(QPaintEvent* event) override;
// Public Methods
duint rvaToVa(dsint rva) const;
duint rvaToVa(duint rva) const;
void disassembleClear();
const duint getBase() const;
duint getSize() const;
@ -75,32 +77,31 @@ public:
//disassemble
void gotoAddress(duint addr);
void disassembleAt(dsint parVA, bool history, dsint newTableOffset);
void disassembleAt(duint va, bool history, duint newTableOffset);
QList<Instruction_t>* instructionsBuffer(); // ugly
const dsint baseAddress() const;
const duint baseAddress() const;
QString getAddrText(dsint cur_addr, char label[MAX_LABEL_SIZE], bool getLabel = true);
void prepareDataCount(const QList<dsint> & wRVAs, QList<Instruction_t>* instBuffer);
void prepareDataRange(dsint startRva, dsint endRva, const std::function<bool(int, const Instruction_t &)> & disassembled);
QString getAddrText(duint cur_addr, QString & label, bool getLabel = true);
void prepareDataCount(const QList<duint> & rvas, QList<Instruction_t>* instBuffer);
void prepareDataRange(duint startRva, duint endRva, const std::function<bool(int, const Instruction_t &)> & disassembled);
RichTextPainter::List getRichBytes(const Instruction_t & instr, bool isSelected) const;
//misc
void setCodeFoldingManager(CodeFoldingHelper* CodeFoldingManager);
duint getDisassemblyPopupAddress(int mousex, int mousey) override;
void unfold(dsint rva);
void unfold(duint rva);
bool hightlightToken(const ZydisTokenizer::SingleToken & token);
bool isHighlightMode() const;
signals:
void selectionChanged(dsint parVA);
void selectionChanged(duint va);
void selectionExpanded();
void updateWindowTitle(QString title);
public slots:
void disassembleAtSlot(dsint parVA, dsint parCIP);
void disassembleAtSlot(duint va, duint cip);
void debugStateChangedSlot(DBGSTATE state);
void selectionChangedSlot(dsint parVA);
void selectionChangedSlot(duint va);
void tokenizerConfigUpdatedSlot();
void updateConfigSlot();
@ -127,30 +128,31 @@ private:
{
GJD_Nothing,
GJD_Up,
GJD_Down
GJD_Down,
GJD_Out,
};
struct SelectionData
{
dsint firstSelectedIndex;
dsint fromIndex;
dsint toIndex;
};
SelectionData mSelection;
duint firstSelectedIndex = 0;
duint fromIndex = 0;
duint toIndex = 0;
} mSelection;
Architecture* mArchitecture = nullptr;
bool mIsLastInstDisplayed;
GuiState mGuiState;
duint mCipVa = 0;
Instruction_t mSelectedInstruction;
QList<Instruction_t> mInstBuffer;
struct HistoryData
{
dsint va;
dsint tableOffset;
duint va = 0;
duint tableOffset = 0;
};
QList<HistoryData> mVaHistory;
@ -165,9 +167,11 @@ private:
ColMnemonicBrief,
};
DisassemblyPopup* mDisassemblyPopup = nullptr;
protected:
// Jumps Graphic
int paintJumpsGraphic(QPainter* painter, int x, int y, dsint addr, bool isjmp);
int paintJumpsGraphic(QPainter* painter, int x, int y, const Instruction_t & instruction);
// Function Graphic
@ -182,6 +186,9 @@ protected:
};
int paintFunctionGraphic(QPainter* painter, int x, int y, Function_t funcType, bool loop);
duint getAddressForPosition(int mousex, int mousey) override;
// Configuration
QColor mInstructionHighlightColor;
QColor mDisassemblyRelocationUnderlineColor;
@ -243,7 +250,7 @@ protected:
dsint mRvaDisplayPageBase;
bool mHighlightingMode;
MemoryPage* mMemPage;
QBeaEngine* mDisasm;
QZydis* mDisasm;
bool mShowMnemonicBrief;
XREF_INFO mXrefInfo;
CodeFoldingHelper* mCodeFoldingManager;

View File

@ -85,12 +85,6 @@ void StdSearchListView::setSearchStartCol(int col)
mSearchStartCol = col;
}
bool StdSearchListView::setDisassemblyPopupEnabled(bool enabled)
{
stdList()->setDisassemblyPopupEnabled(enabled);
return stdSearchList()->setDisassemblyPopupEnabled(enabled);
}
StdTable* StdSearchListView::stdList()
{
return mSearchListData->mList;

View File

@ -18,7 +18,6 @@ public:
void enableMultiSelection(bool enabled);
void setAddressColumn(int col, bool cipBase = false);
void loadColumnFromConfig(const QString & viewName);
bool setDisassemblyPopupEnabled(bool enabled);
public slots:
virtual void setRowCount(dsint count);

View File

@ -1,6 +1,6 @@
#include "Bridge.h"
#include <QClipboard>
#include "QBeaEngine.h"
#include "QZydis.h"
#include "main.h"
#include "Exports.h"
@ -12,6 +12,19 @@
************************************************************************************/
static Bridge* mBridge;
class BridgeArchitecture : public Architecture
{
bool disasm64() const override
{
return ArchValue(false, true);
}
bool addr64() const override
{
return ArchValue(false, true);
}
} mArch;
/************************************************************************************
Class Members
************************************************************************************/
@ -72,6 +85,11 @@ void Bridge::initBridge()
mBridge = new Bridge();
}
Architecture* Bridge::getArch()
{
return &mArch;
}
/************************************************************************************
Helper Functions
************************************************************************************/
@ -100,7 +118,7 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
{
case GUI_DISASSEMBLE_AT:
mLastCip = (duint)param2;
emit disassembleAt((dsint)param1, (dsint)param2);
emit disassembleAt((duint)param1, (duint)param2);
break;
case GUI_SET_DEBUG_STATE:
@ -361,7 +379,7 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
byte_t buffer[16];
if(!DbgMemRead(parVA, buffer, 16))
return 0;
QBeaEngine disasm(int(ConfigUint("Disassembler", "MaxModuleSize")), Bridge::getArch());
QZydis disasm(int(ConfigUint("Disassembler", "MaxModuleSize")), Bridge::getArch());
Instruction_t instr = disasm.DisassembleAt(buffer, 16, 0, parVA);
QString finalInstruction;
for(const auto & curToken : instr.tokens.tokens)

View File

@ -7,6 +7,15 @@
#include <QMenu>
#include "Imports.h"
#include "BridgeResult.h"
#include "Architecture.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
namespace Qt
{
static QString::SplitBehavior KeepEmptyParts = QString::KeepEmptyParts;
static QString::SplitBehavior SkipEmptyParts = QString::SkipEmptyParts;
}
#endif // QT_VERSION
class ReferenceManager;
class SymbolView;
@ -23,6 +32,7 @@ public:
static Bridge* getBridge();
static void initBridge();
static Architecture* getArch();
// Message processing function
void* processMessage(GUIMSG type, void* param1, void* param2);
@ -47,7 +57,7 @@ public:
bool loggingEnabled = true;
signals:
void disassembleAt(dsint va, dsint eip);
void disassembleAt(duint va, duint eip);
void updateDisassembly();
void dbgStateChanged(DBGSTATE state);
void addMsgToLog(QByteArray msg);
@ -57,11 +67,11 @@ signals:
void saveLogToFile(QString file);
void redirectLogStop();
void redirectLogToFile(QString filename);
void shutdown();
void close();
void updateRegisters();
void updateBreakpoints();
void updateWindowTitle(QString filename);
void dumpAt(dsint va);
void dumpAt(duint va);
void scriptAdd(int count, const char** lines);
void scriptClear();
void scriptSetIp(int line);
@ -76,7 +86,7 @@ signals:
void clearSymbolLog();
void setSymbolProgress(int progress);
void referenceAddColumnAt(int width, QString title);
void referenceSetRowCount(dsint count);
void referenceSetRowCount(duint count);
void referenceSetCellContent(int r, int c, QString s);
void referenceAddCommand(QString title, QString command);
void referenceReloadData();

View File

@ -0,0 +1 @@
#include "Architecture.h"

View File

@ -0,0 +1,17 @@
#pragma once
/*
This should probably take some inspiration from Zydis:
- Address space min/max (64 vs 32 bit basically)
- Disassembly architecture (likely should return a reference to a disassembler)
*/
class Architecture
{
public:
virtual ~Architecture() = default;
// TODO: replace this with something about address space
virtual bool disasm64() const = 0;
virtual bool addr64() const = 0;
};

View File

@ -1,75 +0,0 @@
#pragma once
#include <QString>
#include <vector>
#include "ZydisTokenizer.h"
class EncodeMap;
class CodeFoldingHelper;
struct Instruction_t
{
enum BranchType
{
None,
Conditional,
Unconditional,
Call
};
Instruction_t()
: rva(0),
length(0),
branchDestination(0),
branchType(None)
{
}
QString instStr;
QByteArray dump;
uint8_t prefixSize, opcodeSize, group1Size, group2Size, group3Size;
duint rva;
int length;
duint branchDestination;
BranchType branchType;
ZydisTokenizer::InstructionToken tokens;
std::vector<std::pair<const char*, uint8_t>> regsReferenced;
uint8_t vectorElementType[4];
};
class QBeaEngine
{
public:
explicit QBeaEngine(int maxModuleSize);
~QBeaEngine();
ulong DisassembleBack(const byte_t* data, duint base, duint size, duint ip, int n);
ulong DisassembleNext(const byte_t* data, duint base, duint size, duint ip, int n);
Instruction_t DisassembleAt(const byte_t* data, duint size, duint origBase, duint origInstRVA, bool datainstr = true);
Instruction_t DecodeDataAt(const byte_t* data, duint size, duint origBase, duint origInstRVA, ENCODETYPE type);
void setCodeFoldingManager(CodeFoldingHelper* CodeFoldingManager);
void UpdateConfig();
EncodeMap* getEncodeMap()
{
return mEncodeMap;
}
private:
struct DataInstructionInfo
{
QString shortName;
QString longName;
QString cName;
};
void UpdateDataInstructionMap();
ZydisTokenizer _tokenizer;
QHash<ENCODETYPE, DataInstructionInfo> dataInstMap;
bool _bLongDataInst;
EncodeMap* mEncodeMap;
CodeFoldingHelper* mCodeFoldingManager;
uint8_t reginfo[ZYDIS_REGISTER_MAX_VALUE + 1];
uint8_t flaginfo[ZYDIS_CPUFLAG_MAX_VALUE + 1];
};
void formatOpcodeString(const Instruction_t & inst, RichTextPainter::List & list, std::vector<std::pair<size_t, bool>> & realBytes);

View File

@ -1,19 +1,24 @@
#include "QBeaEngine.h"
#include "QZydis.h"
#include "StringUtil.h"
#include "EncodeMap.h"
#include "CodeFolding.h"
#include "Bridge.h"
QBeaEngine::QBeaEngine(int maxModuleSize)
: _tokenizer(maxModuleSize), mCodeFoldingManager(nullptr), _bLongDataInst(false)
#ifndef _countof
#define _countof(array) (sizeof(array) / sizeof(array[0]))
#endif // _countof