cutter/src/widgets/DisassemblyWidget.h

198 lines
4.7 KiB
C
Raw Normal View History

#ifndef DISASSEMBLYWIDGET_H
#define DISASSEMBLYWIDGET_H
#include "core/Cutter.h"
#include "MemoryDockWidget.h"
#include "common/CutterSeekable.h"
2019-01-12 19:25:43 +00:00
#include "common/RefreshDeferrer.h"
#include "common/CachedFontMetrics.h"
2019-01-12 19:25:43 +00:00
#include <QTextEdit>
#include <QPlainTextEdit>
2017-10-16 19:00:47 +00:00
#include <QShortcut>
#include <QAction>
#include <vector>
class DisassemblyTextEdit;
class DisassemblyScrollArea;
class DisassemblyContextMenu;
class DisassemblyLeftPanel;
class DisassemblyWidget : public MemoryDockWidget
{
Q_OBJECT
public:
explicit DisassemblyWidget(MainWindow *main);
2018-03-21 20:32:32 +00:00
QWidget *getTextWidget();
static QString getWidgetType();
public slots:
/**
2021-01-24 14:50:13 +00:00
* @brief Highlights the currently selected line and updates the
* highlighting of the same words under the cursor in the visible screen.
* This overrides all previous highlighting.
*/
void highlightCurrentLine();
/**
* @brief Adds the PC line highlighting to the other current highlighting.
* This should be called after highlightCurrentLine since that function
* overrides all previous highlighting.
*/
void highlightPCLine();
void showDisasContextMenu(const QPoint &pt);
void fontsUpdatedSlot();
2017-11-20 11:23:37 +00:00
void colorsUpdatedSlot();
void scrollInstructions(int count);
void seekPrev();
void setPreviewMode(bool previewMode);
QFontMetrics getFontMetrics();
QList<DisassemblyLine> getLines();
protected slots:
void on_seekChanged(RVA offset);
void refreshIfInRange(RVA offset);
void refreshDisasm(RVA offset = RVA_INVALID);
bool updateMaxLines();
void cursorPositionChanged();
protected:
DisassemblyContextMenu *mCtxMenu;
DisassemblyScrollArea *mDisasScrollArea;
DisassemblyTextEdit *mDisasTextEdit;
DisassemblyLeftPanel *leftPanel;
QList<DisassemblyLine> lines;
private:
RVA topOffset;
RVA bottomOffset;
int maxLines;
QString curHighlightedWord;
2019-03-06 20:30:39 +00:00
/**
* offset of lines below the first line of the current seek
*/
int cursorLineOffset;
int cursorCharOffset;
bool seekFromCursor;
RefreshDeferrer *disasmRefresh;
RVA readCurrentDisassemblyOffset();
2017-11-28 11:56:38 +00:00
RVA readDisassemblyOffset(QTextCursor tc);
bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
QString getWindowTitle() const override;
QList<RVA> breakpoints;
2017-11-30 14:00:22 +00:00
void setupFonts();
void setupColors();
void updateCursorPosition();
void connectCursorPositionChanged(bool disconnect);
void moveCursorRelative(bool up, bool page);
2021-01-24 14:50:13 +00:00
void jumpToOffsetUnderCursor(const QTextCursor &);
};
class DisassemblyScrollArea : public QAbstractScrollArea
{
Q_OBJECT
public:
explicit DisassemblyScrollArea(QWidget *parent = nullptr);
signals:
void scrollLines(int lines);
void disassemblyResized();
protected:
bool viewportEvent(QEvent *event) override;
private:
void resetScrollBars();
};
2021-01-24 14:50:13 +00:00
class DisassemblyTextEdit : public QPlainTextEdit
{
Q_OBJECT
public:
explicit DisassemblyTextEdit(QWidget *parent = nullptr)
2021-01-24 14:50:13 +00:00
: QPlainTextEdit(parent), lockScroll(false)
2018-03-21 20:32:32 +00:00
{
}
2021-01-24 14:50:13 +00:00
void setLockScroll(bool lock) { this->lockScroll = lock; }
qreal textOffset() const;
2021-01-24 14:50:13 +00:00
protected:
bool viewportEvent(QEvent *event) override;
void scrollContentsBy(int dx, int dy) override;
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
bool lockScroll;
};
/**
* This class is used to draw the left pane of the disassembly
* widget. Its goal is to draw proper arrows for the jumps of the disassembly.
*/
2021-01-24 14:50:13 +00:00
class DisassemblyLeftPanel : public QFrame
{
public:
DisassemblyLeftPanel(DisassemblyWidget *disas);
void paintEvent(QPaintEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
private:
DisassemblyWidget *disas;
struct Arrow {
Arrow(RVA v1, RVA v2)
: min(v1), max(v2),
level(0), up(false)
{
if (min > max) {
std::swap(min, max);
up = true;
}
}
inline bool contains(RVA point) const
{ return min <= point && max >= point; }
inline bool intersects(const Arrow& other) const
{ return std::max(min, other.min) <= std::min(max, other.max); }
ut64 length() const { return max - min; }
RVA jmpFromOffset() const { return up ? max : min; }
RVA jmpToffset() const { return up ? min : max; }
RVA min;
RVA max;
uint32_t level;
bool up;
};
const size_t arrowsSize = 128;
const uint32_t maxLevelBeforeFlush = 32;
RVA lastBeginOffset = 0;
std::vector<Arrow> arrows;
};
#endif // DISASSEMBLYWIDGET_H