2017-10-12 19:55:15 +00:00
|
|
|
#include "DisassemblyWidget.h"
|
2017-10-11 21:07:32 +00:00
|
|
|
#include "menus/DisassemblyContextMenu.h"
|
|
|
|
#include "utils/HexAsciiHighlighter.h"
|
|
|
|
#include "utils/HexHighlighter.h"
|
2017-10-14 09:35:49 +00:00
|
|
|
#include "utils/Configuration.h"
|
2017-11-15 21:56:10 +00:00
|
|
|
#include "utils/Helpers.h"
|
2017-11-20 20:11:56 +00:00
|
|
|
#include "utils/TempConfig.h"
|
2017-11-02 06:48:32 +00:00
|
|
|
|
2017-10-16 19:00:47 +00:00
|
|
|
#include <QScrollBar>
|
2017-11-02 06:48:32 +00:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QVBoxLayout>
|
2017-11-03 11:31:20 +00:00
|
|
|
#include <QRegularExpression>
|
2017-11-02 06:48:32 +00:00
|
|
|
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-03 11:31:20 +00:00
|
|
|
DisassemblyWidget::DisassemblyWidget(QWidget *parent)
|
|
|
|
: QDockWidget(parent)
|
|
|
|
, mCtxMenu(new DisassemblyContextMenu(this))
|
|
|
|
, mDisasScrollArea(new DisassemblyScrollArea(this))
|
|
|
|
, mDisasTextEdit(new DisassemblyTextEdit(this))
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
topOffset = bottomOffset = RVA_INVALID;
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout();
|
|
|
|
layout->addWidget(mDisasTextEdit);
|
|
|
|
layout->setMargin(0);
|
|
|
|
mDisasScrollArea->viewport()->setLayout(layout);
|
|
|
|
mDisasScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
|
|
|
setWidget(mDisasScrollArea);
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
setObjectName("DisassemblyWidget");
|
2017-11-20 11:23:37 +00:00
|
|
|
colorsUpdatedSlot();
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2017-10-14 09:35:49 +00:00
|
|
|
mDisasTextEdit->setFont(Config()->getFont());
|
2017-10-16 19:00:47 +00:00
|
|
|
mDisasTextEdit->setReadOnly(true);
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth);
|
|
|
|
// wrapping breaks readCurrentDisassemblyOffset() at the moment :-(
|
|
|
|
mDisasTextEdit->setWordWrapMode(QTextOption::NoWrap);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
|
|
|
// Increase asm text edit margin
|
|
|
|
QTextDocument *asm_docu = mDisasTextEdit->document();
|
|
|
|
asm_docu->setDocumentMargin(10);
|
|
|
|
|
|
|
|
// Event filter to intercept double clicks in the textbox
|
|
|
|
mDisasTextEdit->viewport()->installEventFilter(this);
|
|
|
|
|
|
|
|
// Set Disas context menu
|
|
|
|
mDisasTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(mDisasTextEdit, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
|
|
this, SLOT(showDisasContextMenu(const QPoint &)));
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
maxLines = 0;
|
|
|
|
updateMaxLines();
|
|
|
|
|
2017-11-04 11:46:29 +00:00
|
|
|
|
|
|
|
// Space to switch to graph
|
|
|
|
QShortcut *graphShortcut = new QShortcut(QKeySequence(Qt::Key_Space), this);
|
|
|
|
graphShortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(graphShortcut, &QShortcut::activated, this, []{
|
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Graph);
|
|
|
|
Core()->triggerRaisePrioritizedMemoryWidget();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
connect(mDisasScrollArea, SIGNAL(scrollLines(int)), this, SLOT(scrollInstructions(int)));
|
|
|
|
connect(mDisasScrollArea, SIGNAL(disassemblyResized()), this, SLOT(updateMaxLines()));
|
|
|
|
|
|
|
|
connectCursorPositionChanged(false);
|
|
|
|
connect(mDisasTextEdit->verticalScrollBar(), &QScrollBar::valueChanged, this, [=](int value) {
|
|
|
|
if (value != 0)
|
|
|
|
{
|
|
|
|
mDisasTextEdit->verticalScrollBar()->setValue(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-04 11:46:29 +00:00
|
|
|
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
|
|
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
|
|
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm()));
|
2017-11-07 08:16:49 +00:00
|
|
|
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));
|
2017-11-04 11:46:29 +00:00
|
|
|
|
2017-10-14 09:35:49 +00:00
|
|
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
|
2017-11-20 11:23:37 +00:00
|
|
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
2017-11-04 11:46:29 +00:00
|
|
|
|
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
|
|
|
if (visibility)
|
|
|
|
{
|
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly);
|
|
|
|
}
|
|
|
|
});
|
2017-11-19 12:56:10 +00:00
|
|
|
|
|
|
|
connect(Core(), &CutterCore::refreshAll, this, [this]() {
|
|
|
|
refreshDisasm(Core()->getOffset());
|
|
|
|
});
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
DisassemblyWidget::DisassemblyWidget(const QString &title, QWidget *parent) :
|
|
|
|
DisassemblyWidget(parent)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
|
|
|
this->setWindowTitle(title);
|
|
|
|
}
|
2017-10-16 19:00:47 +00:00
|
|
|
|
2017-10-22 10:21:44 +00:00
|
|
|
QWidget* DisassemblyWidget::getTextWidget()
|
|
|
|
{
|
|
|
|
return mDisasTextEdit;
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
QString DisassemblyWidget::readDisasm(const QString &cmd, bool stripLastNewline)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-20 20:11:56 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.html", true)
|
|
|
|
.set("scr.color", true);
|
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
QString disas = Core()->cmd(cmd);
|
2017-11-02 06:48:32 +00:00
|
|
|
|
|
|
|
if (stripLastNewline)
|
|
|
|
{
|
|
|
|
// ugly hack to remove trailing newline
|
|
|
|
static const auto trimBrRegExp = QRegularExpression("<br />$");
|
|
|
|
disas = disas.remove(trimBrRegExp);
|
|
|
|
}
|
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
return disas.trimmed();
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
|
|
|
|
void DisassemblyWidget::refreshDisasm(RVA offset)
|
2017-10-22 13:55:42 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
if (offset != RVA_INVALID)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
topOffset = offset;
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
if (maxLines <= 0)
|
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
connectCursorPositionChanged(true);
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->clear();
|
2017-11-18 12:56:48 +00:00
|
|
|
connectCursorPositionChanged(false);
|
2017-11-02 06:48:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
int horizontalScrollValue = mDisasTextEdit->horizontalScrollBar()->value();
|
|
|
|
mDisasTextEdit->setLockScroll(true); // avoid flicker
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
QString disas = readDisasm("pd " + QString::number(maxLines) + "@" + QString::number(topOffset), true);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
connectCursorPositionChanged(true);
|
2017-10-22 13:55:42 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->document()->setHtml(disas);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
// get bottomOffset from last visible line.
|
|
|
|
// because pd N may return more than N lines, move maxLines lines down from the top
|
|
|
|
mDisasTextEdit->moveCursor(QTextCursor::Start);
|
|
|
|
QTextCursor tc = mDisasTextEdit->textCursor();
|
2017-11-20 10:04:03 +00:00
|
|
|
tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, maxLines - 1);
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->setTextCursor(tc);
|
|
|
|
|
|
|
|
connectCursorPositionChanged(false);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
bottomOffset = readCurrentDisassemblyOffset();
|
|
|
|
if (bottomOffset == RVA_INVALID)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
bottomOffset = topOffset;
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-20 10:04:03 +00:00
|
|
|
// remove additional lines
|
|
|
|
tc.movePosition(QTextCursor::EndOfLine);
|
|
|
|
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
|
|
|
tc.removeSelectedText();
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
updateCursorPosition();
|
|
|
|
|
|
|
|
mDisasTextEdit->setLockScroll(false);
|
|
|
|
mDisasTextEdit->horizontalScrollBar()->setValue(horizontalScrollValue);
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
|
|
|
|
void DisassemblyWidget::scrollInstructions(int count)
|
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
return;
|
2017-10-22 13:55:42 +00:00
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
RVA offset;
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
offset = Core()->nextOpAddr(topOffset, count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = Core()->prevOpAddr(topOffset, -count);
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
refreshDisasm(offset);
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-20 10:04:03 +00:00
|
|
|
bool DisassemblyWidget::updateMaxLines()
|
2017-11-02 06:48:32 +00:00
|
|
|
{
|
2017-11-15 21:56:10 +00:00
|
|
|
int currentMaxLines = qhelpers::getMaxFullyDisplayedLines(mDisasTextEdit);
|
2017-11-20 10:04:03 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
if (currentMaxLines != maxLines)
|
|
|
|
{
|
|
|
|
maxLines = currentMaxLines;
|
|
|
|
refreshDisasm();
|
2017-11-20 10:04:03 +00:00
|
|
|
return true;
|
2017-11-02 06:48:32 +00:00
|
|
|
}
|
2017-11-20 10:04:03 +00:00
|
|
|
|
|
|
|
return false;
|
2017-11-02 06:48:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
void DisassemblyWidget::highlightCurrentLine()
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-10-22 13:55:42 +00:00
|
|
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
// Highlight the current line
|
2017-10-22 13:55:42 +00:00
|
|
|
if (mDisasTextEdit->isReadOnly())
|
|
|
|
{
|
|
|
|
QTextEdit::ExtraSelection selection;
|
2017-11-20 11:23:37 +00:00
|
|
|
QColor lineColor = ConfigColor("gui.highlight");
|
|
|
|
lineColor.setAlpha(128);
|
2017-10-22 13:55:42 +00:00
|
|
|
selection.format.setBackground(lineColor);
|
|
|
|
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
|
|
|
selection.cursor = mDisasTextEdit->textCursor();
|
|
|
|
selection.cursor.clearSelection();
|
|
|
|
extraSelections.append(selection);
|
|
|
|
}
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
// Highlight the current word
|
|
|
|
QTextCursor cursor = mDisasTextEdit->textCursor();
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
QTextEdit::ExtraSelection currentWord;
|
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
QColor highlightColor = ConfigColor("comment");
|
|
|
|
highlightColor.setAlpha(128);
|
|
|
|
currentWord.format.setBackground(highlightColor);
|
2017-10-22 13:55:42 +00:00
|
|
|
|
|
|
|
currentWord.cursor = cursor;
|
|
|
|
extraSelections.append(currentWord);
|
|
|
|
currentWord.cursor.clearSelection();
|
|
|
|
|
|
|
|
// Highlight all the words in the document same as the actual one
|
|
|
|
QString searchString = cursor.selectedText();
|
|
|
|
QTextDocument *document = mDisasTextEdit->document();
|
|
|
|
|
|
|
|
//QTextCursor highlightCursor(document);
|
|
|
|
QTextEdit::ExtraSelection highlightSelection;
|
|
|
|
highlightSelection.cursor = cursor;
|
2017-11-20 11:23:37 +00:00
|
|
|
highlightSelection.format.setBackground(highlightColor);
|
2017-10-22 13:55:42 +00:00
|
|
|
QTextCursor cursor2(document);
|
|
|
|
|
|
|
|
cursor2.beginEditBlock();
|
|
|
|
|
|
|
|
highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
|
|
|
while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd())
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-10-22 13:55:42 +00:00
|
|
|
highlightSelection.cursor = document->find(searchString, highlightSelection.cursor, QTextDocument::FindWholeWords);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
if (!highlightSelection.cursor.isNull())
|
|
|
|
{
|
|
|
|
highlightSelection.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
extraSelections.append(highlightSelection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor2.endEditBlock();
|
2017-10-13 13:53:23 +00:00
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
mDisasTextEdit->setExtraSelections(extraSelections);
|
2017-11-03 11:31:20 +00:00
|
|
|
mCtxMenu->setOffset(readCurrentDisassemblyOffset());
|
2017-10-22 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::showDisasContextMenu(const QPoint &pt)
|
|
|
|
{
|
2017-11-03 11:31:20 +00:00
|
|
|
mCtxMenu->exec(mDisasTextEdit->mapToGlobal(pt));
|
2017-10-22 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RVA DisassemblyWidget::readCurrentDisassemblyOffset()
|
|
|
|
{
|
|
|
|
// TODO: do this in a different way without parsing the disassembly text
|
2017-11-02 06:48:32 +00:00
|
|
|
|
|
|
|
static const QRegularExpression offsetRegExp("^0x[0-9A-Fa-f]*");
|
|
|
|
|
2017-10-22 13:55:42 +00:00
|
|
|
QTextCursor tc = mDisasTextEdit->textCursor();
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
tc.select(QTextCursor::LineUnderCursor);
|
|
|
|
|
|
|
|
QString line = tc.selectedText();
|
|
|
|
|
|
|
|
auto match = offsetRegExp.match(line);
|
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
|
|
|
return match.captured(0).toULongLong(nullptr, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
tc.movePosition(QTextCursor::StartOfLine);
|
|
|
|
if (tc.atStart())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-10-22 13:55:42 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
tc.movePosition(QTextCursor::Up);
|
2017-10-22 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
return RVA_INVALID;
|
2017-10-22 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
void DisassemblyWidget::updateCursorPosition()
|
2017-10-22 13:55:42 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
connectCursorPositionChanged(true);
|
|
|
|
RVA offset = Core()->getOffset();
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
if (offset < topOffset || (offset > bottomOffset && bottomOffset != RVA_INVALID))
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->moveCursor(QTextCursor::Start);
|
|
|
|
mDisasTextEdit->setExtraSelections({});
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
2017-11-02 06:48:32 +00:00
|
|
|
else
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
RVA currentCursorOffset = readCurrentDisassemblyOffset();
|
|
|
|
QTextCursor originalCursor = mDisasTextEdit->textCursor();
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
QTextCursor cursor = originalCursor;
|
|
|
|
cursor.movePosition(QTextCursor::Start);
|
2017-10-11 21:07:32 +00:00
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
while (true)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->setTextCursor(cursor);
|
|
|
|
RVA lineOffset = readCurrentDisassemblyOffset();
|
|
|
|
if (lineOffset == offset)
|
|
|
|
{
|
|
|
|
highlightCurrentLine();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (lineOffset != RVA_INVALID && lineOffset > offset)
|
|
|
|
{
|
|
|
|
mDisasTextEdit->moveCursor(QTextCursor::Start);
|
|
|
|
mDisasTextEdit->setExtraSelections({});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.movePosition(QTextCursor::EndOfLine);
|
|
|
|
if (cursor.atEnd())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.movePosition(QTextCursor::Down);
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
2017-11-02 06:48:32 +00:00
|
|
|
|
|
|
|
// this is true if a seek came from the user clicking on a line.
|
|
|
|
// then the cursor should be restored 1:1 to retain selection and cursor position.
|
|
|
|
if (currentCursorOffset == offset)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
mDisasTextEdit->setTextCursor(originalCursor);
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-02 06:48:32 +00:00
|
|
|
connectCursorPositionChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::connectCursorPositionChanged(bool disconnect)
|
|
|
|
{
|
|
|
|
if (disconnect)
|
|
|
|
{
|
|
|
|
QObject::disconnect(mDisasTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
connect(mDisasTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyWidget::cursorPositionChanged()
|
|
|
|
{
|
|
|
|
RVA offset = readCurrentDisassemblyOffset();
|
|
|
|
Core()->seek(offset);
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
|
|
|
if ((obj == mDisasTextEdit || obj == mDisasTextEdit->viewport()) && event->type() == QEvent::MouseButtonDblClick)
|
|
|
|
{
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
|
|
//qDebug()<<QString("Click location: (%1,%2)").arg(mouseEvent->x()).arg(mouseEvent->y());
|
|
|
|
QTextCursor cursor = mDisasTextEdit->cursorForPosition(QPoint(mouseEvent->x(), mouseEvent->y()));
|
|
|
|
cursor.select(QTextCursor::LineUnderCursor);
|
|
|
|
QString lastline = cursor.selectedText();
|
|
|
|
auto eles = lastline.split(" ", QString::SkipEmptyParts);
|
|
|
|
QString ele = eles.isEmpty() ? "" : eles[0];
|
|
|
|
if (ele.contains("0x"))
|
|
|
|
{
|
|
|
|
QString jump = CutterCore::getInstance()->getOffsetJump(ele);
|
|
|
|
if (!jump.isEmpty())
|
|
|
|
{
|
|
|
|
if (jump.contains("0x"))
|
|
|
|
{
|
|
|
|
QString fcn = CutterCore::getInstance()->cmdFunctionAt(jump);
|
|
|
|
if (!fcn.isEmpty())
|
|
|
|
{
|
|
|
|
RVA addr = jump.trimmed().toULongLong(0, 16);
|
|
|
|
CutterCore::getInstance()->seek(addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RVA addr = CutterCore::getInstance()->cmd("?v " + jump).toULongLong(0, 16);
|
|
|
|
CutterCore::getInstance()->seek(addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QDockWidget::eventFilter(obj, event);
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void DisassemblyWidget::on_seekChanged(RVA offset)
|
2017-10-11 21:07:32 +00:00
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
if (topOffset != RVA_INVALID && bottomOffset != RVA_INVALID
|
|
|
|
&& offset >= topOffset && offset <= bottomOffset)
|
|
|
|
{
|
|
|
|
// if the line with the seek offset is currently visible, just move the cursor there
|
|
|
|
updateCursorPosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// otherwise scroll there
|
|
|
|
refreshDisasm(offset);
|
|
|
|
}
|
2017-11-03 11:31:20 +00:00
|
|
|
mCtxMenu->setOffset(offset);
|
2017-10-11 21:07:32 +00:00
|
|
|
}
|
2017-10-14 09:35:49 +00:00
|
|
|
|
2017-11-04 11:46:29 +00:00
|
|
|
void DisassemblyWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
|
|
|
{
|
|
|
|
if (type == CutterCore::MemoryWidgetType::Disassembly)
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-14 09:35:49 +00:00
|
|
|
void DisassemblyWidget::fontsUpdatedSlot()
|
|
|
|
{
|
|
|
|
mDisasTextEdit->setFont(Config()->getFont());
|
2017-11-20 10:04:03 +00:00
|
|
|
|
|
|
|
if (!updateMaxLines()) // updateMaxLines() returns true if it already refreshed.
|
|
|
|
{
|
|
|
|
refreshDisasm();
|
|
|
|
}
|
2017-10-14 09:35:49 +00:00
|
|
|
}
|
2017-10-16 19:00:47 +00:00
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
void DisassemblyWidget::colorsUpdatedSlot()
|
|
|
|
{
|
2017-11-20 11:45:25 +00:00
|
|
|
mDisasTextEdit->setStyleSheet(QString("QPlainTextEdit { background-color: %1; color: %2; }")
|
|
|
|
.arg(ConfigColor("gui.background").name())
|
|
|
|
.arg(ConfigColor("btext").name()));
|
2017-11-20 11:23:37 +00:00
|
|
|
refreshDisasm();
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
DisassemblyScrollArea::DisassemblyScrollArea(QWidget *parent) : QAbstractScrollArea(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisassemblyScrollArea::viewportEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
int dy = verticalScrollBar()->value() - 5;
|
|
|
|
if (dy != 0)
|
|
|
|
{
|
|
|
|
emit scrollLines(dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->type() == QEvent::Resize)
|
|
|
|
{
|
|
|
|
emit disassemblyResized();
|
|
|
|
}
|
|
|
|
|
|
|
|
resetScrollBars();
|
|
|
|
return QAbstractScrollArea::viewportEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyScrollArea::resetScrollBars()
|
|
|
|
{
|
|
|
|
verticalScrollBar()->blockSignals(true);
|
|
|
|
verticalScrollBar()->setRange(0, 10);
|
|
|
|
verticalScrollBar()->setValue(5);
|
|
|
|
verticalScrollBar()->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisassemblyTextEdit::viewportEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
switch(event->type())
|
|
|
|
{
|
|
|
|
case QEvent::Type::Wheel:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return QAbstractScrollArea::viewportEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyTextEdit::scrollContentsBy(int dx, int dy)
|
|
|
|
{
|
|
|
|
if (!lockScroll)
|
|
|
|
{
|
|
|
|
QPlainTextEdit::scrollContentsBy(dx, dy);
|
|
|
|
}
|
|
|
|
}
|
2017-11-04 11:46:29 +00:00
|
|
|
|
2017-11-19 17:49:29 +00:00
|
|
|
void DisassemblyTextEdit::keyPressEvent(QKeyEvent */*event*/)
|
2017-11-04 11:46:29 +00:00
|
|
|
{
|
|
|
|
//QPlainTextEdit::keyPressEvent(event);
|
|
|
|
}
|