mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Move more common disassembly-previewing functionality to namaspace (#2849)
This commit is contained in:
parent
84d4a64f47
commit
2b50e2722b
@ -35,9 +35,6 @@ QString DisassemblyPreview::getToolTipStyleSheet()
|
|||||||
bool DisassemblyPreview::showDisasPreview(QWidget *parent, const QPoint &pointOfEvent,
|
bool DisassemblyPreview::showDisasPreview(QWidget *parent, const QPoint &pointOfEvent,
|
||||||
const RVA offsetFrom)
|
const RVA offsetFrom)
|
||||||
{
|
{
|
||||||
QProcessEnvironment env;
|
|
||||||
QPoint point = pointOfEvent;
|
|
||||||
|
|
||||||
QList<XrefDescription> refs = Core()->getXRefs(offsetFrom, false, false);
|
QList<XrefDescription> refs = Core()->getXRefs(offsetFrom, false, false);
|
||||||
if (refs.length()) {
|
if (refs.length()) {
|
||||||
if (refs.length() > 1) {
|
if (refs.length() > 1) {
|
||||||
@ -75,10 +72,20 @@ bool DisassemblyPreview::showDisasPreview(QWidget *parent, const QPoint &pointOf
|
|||||||
.arg(qMax(8, fnt.pointSize() - 1))
|
.arg(qMax(8, fnt.pointSize() - 1))
|
||||||
.arg(disasmPreview.join("<br>"));
|
.arg(disasmPreview.join("<br>"));
|
||||||
|
|
||||||
QToolTip::showText(point, tooltip, parent, QRect {}, 3500);
|
QToolTip::showText(pointOfEvent, tooltip, parent, QRect {}, 3500);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RVA DisassemblyPreview::readDisassemblyOffset(QTextCursor tc)
|
||||||
|
{
|
||||||
|
auto userData = getUserData(tc.block());
|
||||||
|
if (!userData) {
|
||||||
|
return RVA_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return userData->line.offset;
|
||||||
|
}
|
||||||
|
@ -31,8 +31,15 @@ QString getToolTipStyleSheet();
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Show a QToolTip that previews the disassembly that is pointed to
|
* @brief Show a QToolTip that previews the disassembly that is pointed to
|
||||||
|
* It works for GraphWidget and DisassemblyWidget
|
||||||
* @return True if the tooltip is shown
|
* @return True if the tooltip is shown
|
||||||
*/
|
*/
|
||||||
bool showDisasPreview(QWidget *parent, const QPoint &pointOfEvent, const RVA offsetFrom);
|
bool showDisasPreview(QWidget *parent, const QPoint &pointOfEvent, const RVA offsetFrom);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reads the offset for the cursor position
|
||||||
|
* @return The disassembly offset of the hovered asm text
|
||||||
|
*/
|
||||||
|
RVA readDisassemblyOffset(QTextCursor tc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -997,13 +997,3 @@ bool DisassemblerGraphView::Instr::contains(ut64 addr) const
|
|||||||
{
|
{
|
||||||
return this->addr <= addr && (addr - this->addr) < size;
|
return this->addr <= addr && (addr - this->addr) < size;
|
||||||
}
|
}
|
||||||
|
|
||||||
RVA DisassemblerGraphView::readDisassemblyOffset(QTextCursor tc)
|
|
||||||
{
|
|
||||||
auto userData = getUserData(tc.block());
|
|
||||||
if (!userData) {
|
|
||||||
return RVA_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
return userData->line.offset;
|
|
||||||
}
|
|
||||||
|
@ -178,7 +178,6 @@ private:
|
|||||||
DisassemblyBlock *blockForAddress(RVA addr);
|
DisassemblyBlock *blockForAddress(RVA addr);
|
||||||
void seekLocal(RVA addr, bool update_viewport = true);
|
void seekLocal(RVA addr, bool update_viewport = true);
|
||||||
void seekInstruction(bool previous_instr);
|
void seekInstruction(bool previous_instr);
|
||||||
RVA readDisassemblyOffset(QTextCursor tc);
|
|
||||||
|
|
||||||
CutterSeekable *seekable = nullptr;
|
CutterSeekable *seekable = nullptr;
|
||||||
QList<QShortcut *> shortcuts;
|
QList<QShortcut *> shortcuts;
|
||||||
|
@ -371,7 +371,7 @@ void DisassemblyWidget::highlightCurrentLine()
|
|||||||
highlightSelection.cursor = cursor;
|
highlightSelection.cursor = cursor;
|
||||||
highlightSelection.cursor.movePosition(QTextCursor::Start);
|
highlightSelection.cursor.movePosition(QTextCursor::Start);
|
||||||
while (true) {
|
while (true) {
|
||||||
RVA lineOffset = readDisassemblyOffset(highlightSelection.cursor);
|
RVA lineOffset = DisassemblyPreview::readDisassemblyOffset(highlightSelection.cursor);
|
||||||
if (lineOffset == seekable->getOffset()) {
|
if (lineOffset == seekable->getOffset()) {
|
||||||
highlightSelection.format.setBackground(highlightColor);
|
highlightSelection.format.setBackground(highlightColor);
|
||||||
highlightSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
highlightSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
@ -406,7 +406,7 @@ void DisassemblyWidget::highlightPCLine()
|
|||||||
highlightSelection.cursor.movePosition(QTextCursor::Start);
|
highlightSelection.cursor.movePosition(QTextCursor::Start);
|
||||||
if (PCAddr != RVA_INVALID) {
|
if (PCAddr != RVA_INVALID) {
|
||||||
while (true) {
|
while (true) {
|
||||||
RVA lineOffset = readDisassemblyOffset(highlightSelection.cursor);
|
RVA lineOffset = DisassemblyPreview::readDisassemblyOffset(highlightSelection.cursor);
|
||||||
if (lineOffset == PCAddr) {
|
if (lineOffset == PCAddr) {
|
||||||
highlightSelection.format.setBackground(highlightPCColor);
|
highlightSelection.format.setBackground(highlightPCColor);
|
||||||
highlightSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
highlightSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
@ -439,17 +439,7 @@ void DisassemblyWidget::showDisasContextMenu(const QPoint &pt)
|
|||||||
RVA DisassemblyWidget::readCurrentDisassemblyOffset()
|
RVA DisassemblyWidget::readCurrentDisassemblyOffset()
|
||||||
{
|
{
|
||||||
QTextCursor tc = mDisasTextEdit->textCursor();
|
QTextCursor tc = mDisasTextEdit->textCursor();
|
||||||
return readDisassemblyOffset(tc);
|
return DisassemblyPreview::readDisassemblyOffset(tc);
|
||||||
}
|
|
||||||
|
|
||||||
RVA DisassemblyWidget::readDisassemblyOffset(QTextCursor tc)
|
|
||||||
{
|
|
||||||
auto userData = getUserData(tc.block());
|
|
||||||
if (!userData) {
|
|
||||||
return RVA_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
return userData->line.offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblyWidget::updateCursorPosition()
|
void DisassemblyWidget::updateCursorPosition()
|
||||||
@ -476,7 +466,7 @@ void DisassemblyWidget::updateCursorPosition()
|
|||||||
cursor.movePosition(QTextCursor::Start);
|
cursor.movePosition(QTextCursor::Start);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
RVA lineOffset = readDisassemblyOffset(cursor);
|
RVA lineOffset = DisassemblyPreview::readDisassemblyOffset(cursor);
|
||||||
if (lineOffset == offset) {
|
if (lineOffset == offset) {
|
||||||
if (cursorLineOffset > 0) {
|
if (cursorLineOffset > 0) {
|
||||||
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,
|
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,
|
||||||
@ -537,7 +527,7 @@ void DisassemblyWidget::cursorPositionChanged()
|
|||||||
cursorCharOffset = c.positionInBlock();
|
cursorCharOffset = c.positionInBlock();
|
||||||
while (c.blockNumber() > 0) {
|
while (c.blockNumber() > 0) {
|
||||||
c.movePosition(QTextCursor::PreviousBlock);
|
c.movePosition(QTextCursor::PreviousBlock);
|
||||||
if (readDisassemblyOffset(c) != offset) {
|
if (DisassemblyPreview::readDisassemblyOffset(c) != offset) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursorLineOffset++;
|
cursorLineOffset++;
|
||||||
@ -623,7 +613,7 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)
|
|||||||
|
|
||||||
void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)
|
void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
RVA offset = readDisassemblyOffset(cursor);
|
RVA offset = DisassemblyPreview::readDisassemblyOffset(cursor);
|
||||||
seekable->seekToReference(offset);
|
seekable->seekToReference(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,47 +635,9 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
auto cursorForWord = mDisasTextEdit->cursorForPosition(helpEvent->pos());
|
auto cursorForWord = mDisasTextEdit->cursorForPosition(helpEvent->pos());
|
||||||
cursorForWord.select(QTextCursor::WordUnderCursor);
|
cursorForWord.select(QTextCursor::WordUnderCursor);
|
||||||
|
|
||||||
RVA offsetFrom = readDisassemblyOffset(cursorForWord);
|
RVA offsetFrom = DisassemblyPreview::readDisassemblyOffset(cursorForWord);
|
||||||
RVA offsetTo = RVA_INVALID;
|
|
||||||
|
|
||||||
QList<XrefDescription> refs = Core()->getXRefs(offsetFrom, false, false);
|
return DisassemblyPreview::showDisasPreview(this, helpEvent->globalPos(), offsetFrom);
|
||||||
|
|
||||||
if (refs.length()) {
|
|
||||||
if (refs.length() > 1) {
|
|
||||||
qWarning() << tr("More than one (%1) references here. Weird behaviour expected.")
|
|
||||||
.arg(refs.length());
|
|
||||||
}
|
|
||||||
offsetTo = refs.at(0).to; // This is the offset we want to preview
|
|
||||||
|
|
||||||
if (Q_UNLIKELY(offsetFrom != refs.at(0).from)) {
|
|
||||||
qWarning() << tr("offsetFrom (%1) differs from refs.at(0).from (%(2))")
|
|
||||||
.arg(offsetFrom)
|
|
||||||
.arg(refs.at(0).from);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only if the offset we point *to* is different from the one the cursor is currently
|
|
||||||
// on *and* the former is a valid offset, we are allowed to get a preview of offsetTo
|
|
||||||
if (offsetTo != offsetFrom && offsetTo != RVA_INVALID) {
|
|
||||||
QStringList disasmPreview = Core()->getDisassemblyPreview(offsetTo, 10);
|
|
||||||
|
|
||||||
// Last check to make sure the returned preview isn't an empty text (QStringList)
|
|
||||||
if (!disasmPreview.isEmpty()) {
|
|
||||||
const QFont &fnt = Config()->getFont();
|
|
||||||
QFontMetrics fm { fnt };
|
|
||||||
|
|
||||||
QString tooltip =
|
|
||||||
QString("<html><div style=\"font-family: %1; font-size: %2pt; "
|
|
||||||
"white-space: nowrap;\"><div style=\"margin-bottom: "
|
|
||||||
"10px;\"><strong>Disassembly Preview</strong>:<br>%3<div>")
|
|
||||||
.arg(fnt.family())
|
|
||||||
.arg(qMax(6, fnt.pointSize() - 1))
|
|
||||||
.arg(disasmPreview.join("<br>"));
|
|
||||||
QToolTip::showText(helpEvent->globalPos(), tooltip, this, QRect(), 3500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return MemoryDockWidget::eventFilter(obj, event);
|
return MemoryDockWidget::eventFilter(obj, event);
|
||||||
|
@ -83,7 +83,6 @@ private:
|
|||||||
RefreshDeferrer *disasmRefresh;
|
RefreshDeferrer *disasmRefresh;
|
||||||
|
|
||||||
RVA readCurrentDisassemblyOffset();
|
RVA readCurrentDisassemblyOffset();
|
||||||
RVA readDisassemblyOffset(QTextCursor tc);
|
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
QString getWindowTitle() const override;
|
QString getWindowTitle() const override;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "ui_ListDockWidget.h"
|
#include "ui_ListDockWidget.h"
|
||||||
|
|
||||||
#include "core/MainWindow.h"
|
#include "core/MainWindow.h"
|
||||||
|
#include "common/DisassemblyPreview.h"
|
||||||
#include "common/Helpers.h"
|
#include "common/Helpers.h"
|
||||||
#include "common/FunctionsTask.h"
|
#include "common/FunctionsTask.h"
|
||||||
#include "common/TempConfig.h"
|
#include "common/TempConfig.h"
|
||||||
@ -634,10 +635,5 @@ void FunctionsWidget::onActionVerticalToggled(bool enable)
|
|||||||
*/
|
*/
|
||||||
void FunctionsWidget::setTooltipStylesheet()
|
void FunctionsWidget::setTooltipStylesheet()
|
||||||
{
|
{
|
||||||
setStyleSheet(QString("QToolTip { border-width: 1px; max-width: %1px;"
|
setStyleSheet(DisassemblyPreview::getToolTipStyleSheet());
|
||||||
"opacity: 230; background-color: %2;"
|
|
||||||
"color: %3; border-color: %3;}")
|
|
||||||
.arg(kMaxTooltipWidth)
|
|
||||||
.arg(Config()->getColor("gui.tooltip.background").name())
|
|
||||||
.arg(Config()->getColor("gui.tooltip.foreground").name()));
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user