1
0
Fork 0

mnemonic help in trace and graph, bookmark in graph

This commit is contained in:
torusrxxx 2020-08-19 23:56:39 +08:00 committed by Duncan Ogilvie
parent 392d46bf8c
commit 1f0577ff68
7 changed files with 140 additions and 6 deletions

View File

@ -267,6 +267,11 @@ CPUDisassembly* CPUWidget::getDisasmWidget()
return mDisas;
}
DisassemblerGraphView* CPUWidget::getGraphWidget()
{
return mGraph;
}
CPUMultiDump* CPUWidget::getDumpWidget()
{
return mDump;

View File

@ -41,6 +41,7 @@ public:
// Widget getters
CPUSideBar* getSidebarWidget();
CPUDisassembly* getDisasmWidget();
DisassemblerGraphView* getGraphWidget();
CPUMultiDump* getDumpWidget();
CPUStack* getStackWidget();
CPUInfoBox* getInfoBoxWidget();

View File

@ -414,6 +414,7 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
QRectF bpRect(x - rectSize / 3.0, y + (this->charHeight - rectSize) / 2.0, rectSize, rectSize);
bool isbp = DbgGetBpxTypeAt(instr.addr) != bp_none;
bool isbookmark = DbgGetBookmarkAt(instr.addr);
bool isbpdisabled = DbgIsBpDisabled(instr.addr);
bool iscip = instr.addr == mCip;
@ -431,6 +432,20 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
p.fillRect(bpRect, isbp ? mBreakpointColor : mDisabledBreakpointColor);
}
else if(isbookmark)
{
if(iscip)
{
// Left half is cip
bpRect.setWidth(bpRect.width() / 2);
p.fillRect(bpRect, mCipColor);
// Right half is breakpoint
bpRect.translate(bpRect.width(), 0);
}
p.fillRect(bpRect, mBookmarkBackgroundColor);
}
else if(iscip)
p.fillRect(bpRect, mCipColor);
@ -2183,6 +2198,7 @@ void DisassemblerGraphView::setupContextMenu()
mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), zoomActionHelperNonZero);
mMenuBuilder->addAction(makeShortcutAction(DIcon("label.png"), tr("&Label"), SLOT(setLabelSlot()), "ActionSetLabel"), zoomActionHelperNonZero);
mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(setBookmarkSlot()), "ActionToggleBookmark"));
mMenuBuilder->addAction(makeShortcutAction(DIcon("xrefs.png"), tr("Xrefs..."), SLOT(xrefSlot()), "ActionXrefs"), zoomActionHelperNonZero);
MenuBuilder* gotoMenu = new MenuBuilder(this);
@ -2268,7 +2284,8 @@ void DisassemblerGraphView::setupContextMenu()
gotoMenu->addSeparator();
gotoMenu->addBuilder(childrenAndParentMenu);
mMenuBuilder->addMenu(makeMenu(DIcon("goto.png"), tr("Go to")), gotoMenu);
mMenuBuilder->addAction(makeShortcutAction(DIcon("helpmnemonic.png"), tr("Help on mnemonic"), SLOT(mnemonicHelpSlot()), "ActionHelpOnMnemonic"));
mMenuBuilder->addSeparator();
auto ifgraphZoomMode = [this](QMenu*)
{
return graphZoomMode;
@ -2276,8 +2293,6 @@ void DisassemblerGraphView::setupContextMenu()
mMenuBuilder->addAction(mZoomToCursor = makeShortcutAction(DIcon("zoom.png"), tr("&Zoom 100%"), SLOT(zoomToCursorSlot()), "ActionGraphZoomToCursor"), ifgraphZoomMode);
mMenuBuilder->addAction(mFitToWindow = makeShortcutAction(DIcon("fit.png"), tr("&Fit to window"), SLOT(fitToWindowSlot()), "ActionGraphFitToWindow"), ifgraphZoomMode);
mMenuBuilder->addSeparator();
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("graph.png"), tr("&Overview"), SLOT(toggleOverviewSlot()), "ActionGraphToggleOverview"), ifgraphZoomMode);
mToggleOverview->setCheckable(true);
mMenuBuilder->addAction(mToggleSummary = makeShortcutAction(DIcon("summary.png"), tr("S&ummary"), SLOT(toggleSummarySlot()), "ActionGraphToggleSummary"));
@ -2383,6 +2398,7 @@ void DisassemblerGraphView::colorsUpdatedSlot()
mCipColor = ConfigColor("GraphCipColor");
mBreakpointColor = ConfigColor("GraphBreakpointColor");
mDisabledBreakpointColor = ConfigColor("GraphDisabledBreakpointColor");
mBookmarkBackgroundColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
fontChanged();
loadCurrentGraph();
@ -2565,6 +2581,28 @@ restart:
this->refreshSlot();
}
void DisassemblerGraphView::setBookmarkSlot()
{
if(!DbgIsDebugging())
return;
duint wVA = this->get_cursor_pos();
bool result;
if(DbgGetBookmarkAt(wVA))
result = DbgSetBookmarkAt(wVA, false);
else
result = DbgSetBookmarkAt(wVA, true);
if(!result)
{
QMessageBox msg(QMessageBox::Critical, tr("Error!"), tr("DbgSetBookmarkAt failed!"));
msg.setWindowIcon(DIcon("compile-error.png"));
msg.setParent(this, Qt::Dialog);
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
GuiUpdateAllViews();
}
void DisassemblerGraphView::xrefSlot()
{
if(!DbgIsDebugging())
@ -2596,6 +2634,17 @@ void DisassemblerGraphView::followActionSlot()
}
}
void DisassemblerGraphView::mnemonicHelpSlot()
{
unsigned char data[16] = { 0xCC };
auto addr = this->get_cursor_pos();
DbgMemRead(addr, data, sizeof(data));
Zydis zydis;
zydis.Disassemble(addr, data);
DbgCmdExecDirect(QString("mnemonichelp %1").arg(zydis.Mnemonic().c_str()).toUtf8().constData());
emit displayLogWidget();
}
void DisassemblerGraphView::fitToWindowSlot()
{
auto areaSize = viewport()->size();

View File

@ -260,6 +260,7 @@ public:
signals:
void selectionChanged(dsint parVA);
void displayLogWidget();
void detachGraph();
public slots:
@ -286,7 +287,9 @@ public slots:
void saveImageSlot();
void setCommentSlot();
void setLabelSlot();
void setBookmarkSlot();
void xrefSlot();
void mnemonicHelpSlot();
void fitToWindowSlot();
void zoomToCursorSlot();
void getCurrentGraphSlot(BridgeCFGraphList* graphList);
@ -371,6 +374,7 @@ private:
QColor mCipColor;
QColor mBreakpointColor;
QColor mDisabledBreakpointColor;
QColor mBookmarkBackgroundColor;
QColor graphNodeColor;
QColor graphNodeBackgroundColor;
QColor graphCurrentShadowColor;

View File

@ -207,6 +207,7 @@ MainWindow::MainWindow(QWidget* parent)
mTraceWidget->setWindowTitle(tr("Trace"));
mTraceWidget->setWindowIcon(DIcon("trace.png"));
connect(mTraceWidget->getTraceBrowser(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));
connect(mTraceWidget->getTraceBrowser(), SIGNAL(displayLogWidget()), this, SLOT(displayLogWidget()));
mTabWidget = new MHTabWidget(this, true, true);
@ -336,7 +337,7 @@ MainWindow::MainWindow(QWidget* parent)
connect(mCpuWidget->getDisasmWidget(), SIGNAL(displayGraphWidget()), this, SLOT(displayGraphWidget()));
connect(mCpuWidget->getDisasmWidget(), SIGNAL(displaySymbolsWidget()), this, SLOT(displaySymbolWidget()));
connect(mCpuWidget->getDisasmWidget(), SIGNAL(showPatches()), this, SLOT(patchWindow()));
connect(mCpuWidget->getGraphWidget(), SIGNAL(displayLogWidget()), this, SLOT(displayLogWidget()));
connect(mCpuWidget->getDumpWidget(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));

View File

@ -38,6 +38,7 @@ TraceBrowser::TraceBrowser(QWidget* parent) : AbstractTableView(parent)
mHighlightingMode = false;
mPermanentHighlightingMode = false;
mShowMnemonicBrief = false;
mMRUList = new MRUList(this, "Recent Trace Files");
connect(mMRUList, SIGNAL(openFile(QString)), this, SLOT(openSlot(QString)));
@ -628,6 +629,7 @@ NotDebuggingLabel:
case Comments:
{
int xinc = 3;
int width;
if(DbgIsDebugging())
{
//TODO: draw arguments
@ -649,7 +651,7 @@ NotDebuggingLabel:
backgroundColor = mCommentBackgroundColor;
}
int width = mFontMetrics->width(comment);
width = mFontMetrics->width(comment);
if(width > w)
width = w;
if(width)
@ -663,13 +665,49 @@ NotDebuggingLabel:
painter->setPen(mLabelColor);
backgroundColor = mLabelBackgroundColor;
int width = mFontMetrics->width(labelText);
width = mFontMetrics->width(labelText);
if(width > w)
width = w;
if(width)
painter->fillRect(QRect(x + xinc, y, width, h), QBrush(backgroundColor)); //fill comment color
painter->drawText(QRect(x + xinc, y, width, h), Qt::AlignVCenter | Qt::AlignLeft, labelText);
}
else
width = 0;
x += width + 3;
}
if(mShowMnemonicBrief)
{
char brief[MAX_STRING_SIZE] = "";
QString mnem;
for(const ZydisTokenizer::SingleToken & token : inst.tokens.tokens)
{
if(token.type != ZydisTokenizer::TokenType::Space && token.type != ZydisTokenizer::TokenType::Prefix)
{
mnem = token.text;
break;
}
}
if(mnem.isEmpty())
mnem = inst.instStr;
int index = mnem.indexOf(' ');
if(index != -1)
mnem.truncate(index);
DbgFunctions()->GetMnemonicBrief(mnem.toUtf8().constData(), MAX_STRING_SIZE, brief);
painter->setPen(mMnemonicBriefColor);
QString mnemBrief = brief;
if(mnemBrief.length())
{
width = mFontMetrics->width(mnemBrief);
if(width > w)
width = w;
if(width)
painter->fillRect(QRect(x, y, width, h), QBrush(mMnemonicBriefBackgroundColor)); //mnemonic brief background color
painter->drawText(QRect(x, y, width, h), Qt::AlignVCenter | Qt::AlignLeft, mnemBrief);
}
}
return "";
}
@ -830,6 +868,16 @@ void TraceBrowser::setupRightClickContextMenu()
mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), isDebugging);
mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(setBookmarkSlot()), "ActionToggleBookmark"), isDebugging);
mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid);
mMenuBuilder->addAction(makeShortcutAction(DIcon("helpmnemonic.png"), tr("Help on mnemonic"), SLOT(mnemonicHelpSlot()), "ActionHelpOnMnemonic"), isValid);
QAction* mnemonicBrief = makeShortcutAction(DIcon("helpbrief.png"), tr("Show mnemonic brief"), SLOT(mnemonicBriefSlot()), "ActionToggleMnemonicBrief");
mMenuBuilder->addAction(mnemonicBrief, [this, mnemonicBrief](QMenu*)
{
if(mShowMnemonicBrief)
mnemonicBrief->setText(tr("Hide mnemonic brief"));
else
mnemonicBrief->setText(tr("Show mnemonic brief"));
return true;
});
MenuBuilder* gotoMenu = new MenuBuilder(this, isValid);
gotoMenu->addAction(makeShortcutAction(DIcon("goto.png"), tr("Expression"), SLOT(gotoSlot()), "ActionGotoExpression"), isValid);
gotoMenu->addAction(makeShortcutAction(DIcon("previous.png"), tr("Previous"), SLOT(gotoPreviousSlot()), "ActionGotoPrevious"), [this](QMenu*)
@ -1191,6 +1239,8 @@ void TraceBrowser::updateColors()
mBytesBackgroundColor = ConfigColor("DisassemblyBytesBackgroundColor");
mAutoCommentColor = ConfigColor("DisassemblyAutoCommentColor");
mAutoCommentBackgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor");
mMnemonicBriefColor = ConfigColor("DisassemblyMnemonicBriefColor");
mMnemonicBriefBackgroundColor = ConfigColor("DisassemblyMnemonicBriefBackgroundColor");
mCommentColor = ConfigColor("DisassemblyCommentColor");
mCommentBackgroundColor = ConfigColor("DisassemblyCommentBackgroundColor");
mConditionalJumpLineTrueColor = ConfigColor("DisassemblyConditionalJumpLineTrueColor");
@ -1307,6 +1357,23 @@ void TraceBrowser::parseFinishedSlot()
emit selectionChanged(getInitialSelection());
}
void TraceBrowser::mnemonicBriefSlot()
{
mShowMnemonicBrief = !mShowMnemonicBrief;
reloadData();
}
void TraceBrowser::mnemonicHelpSlot()
{
unsigned char data[16] = { 0xCC };
int size;
mTraceFile->OpCode(getInitialSelection(), data, &size);
Zydis zydis;
zydis.Disassemble(mTraceFile->Registers(getInitialSelection()).regcontext.cip, data);
DbgCmdExecDirect(QString("mnemonichelp %1").arg(zydis.Mnemonic().c_str()).toUtf8().constData());
emit displayLogWidget();
}
void TraceBrowser::gotoSlot()
{
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)

View File

@ -75,6 +75,7 @@ private:
bool mHighlightingMode;
bool mPermanentHighlightingMode;
bool mAutoDisassemblyFollowSelection;
bool mShowMnemonicBrief;
TraceFileReader* mTraceFile;
BreakpointMenu* mBreakpointMenu;
@ -115,6 +116,9 @@ private:
QColor mCommentBackgroundColor;
QColor mDisassemblyRelocationUnderlineColor;
QColor mMnemonicBriefColor;
QColor mMnemonicBriefBackgroundColor;
QColor mConditionalJumpLineTrueColor;
QColor mLoopColor;
@ -140,6 +144,7 @@ private:
signals:
void displayReferencesWidget();
void displayLogWidget();
void selectionChanged(unsigned long long selection);
public slots:
@ -160,6 +165,8 @@ public slots:
void setLabelSlot();
void setCommentSlot();
void setBookmarkSlot();
void mnemonicBriefSlot();
void mnemonicHelpSlot();
void copyDisassemblySlot();
void copyCipSlot();
void copyIndexSlot();