2019-09-06 05:40:20 +00:00
|
|
|
#ifndef DECOMPILERWIDGET_H
|
|
|
|
#define DECOMPILERWIDGET_H
|
2017-12-06 23:19:14 +00:00
|
|
|
|
2019-12-19 17:58:30 +00:00
|
|
|
#include <QTextEdit>
|
2017-12-06 23:19:14 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2019-03-27 08:24:54 +00:00
|
|
|
#include "MemoryDockWidget.h"
|
2019-08-27 15:27:39 +00:00
|
|
|
#include "Decompiler.h"
|
2017-12-06 23:19:14 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
namespace Ui {
|
2019-09-06 05:40:20 +00:00
|
|
|
class DecompilerWidget;
|
2017-12-21 14:23:44 +00:00
|
|
|
}
|
2017-12-15 10:52:47 +00:00
|
|
|
|
|
|
|
class QTextEdit;
|
2019-07-11 13:21:54 +00:00
|
|
|
class QSyntaxHighlighter;
|
2019-07-12 08:57:07 +00:00
|
|
|
class QTextCursor;
|
2020-06-22 20:25:30 +00:00
|
|
|
class DecompilerContextMenu;
|
2019-07-12 08:57:07 +00:00
|
|
|
struct DecompiledCodeTextLine;
|
2017-12-06 23:19:14 +00:00
|
|
|
|
2019-09-06 05:40:20 +00:00
|
|
|
class DecompilerWidget : public MemoryDockWidget
|
2017-12-06 23:19:14 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
Q_OBJECT
|
2019-08-07 11:38:22 +00:00
|
|
|
protected:
|
2020-06-22 20:25:30 +00:00
|
|
|
DecompilerContextMenu *mCtxMenu;
|
2017-12-06 23:19:14 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-22 11:49:34 +00:00
|
|
|
explicit DecompilerWidget(MainWindow *main);
|
2019-09-06 05:40:20 +00:00
|
|
|
~DecompilerWidget();
|
2019-08-07 11:38:22 +00:00
|
|
|
public slots:
|
|
|
|
void showDisasContextMenu(const QPoint &pt);
|
2017-12-06 23:19:14 +00:00
|
|
|
|
2019-12-19 17:58:30 +00:00
|
|
|
void highlightPC();
|
2017-12-06 23:19:14 +00:00
|
|
|
private slots:
|
2019-10-12 05:50:10 +00:00
|
|
|
void fontsUpdatedSlot();
|
2017-12-06 23:19:14 +00:00
|
|
|
void colorsUpdatedSlot();
|
2019-09-06 05:40:20 +00:00
|
|
|
void refreshDecompiler();
|
2019-07-16 18:33:05 +00:00
|
|
|
void decompilerSelected();
|
2019-07-12 08:57:07 +00:00
|
|
|
void cursorPositionChanged();
|
|
|
|
void seekChanged();
|
2020-06-08 21:29:26 +00:00
|
|
|
void decompilationFinished(RAnnotatedCode *code);
|
2017-12-15 10:52:47 +00:00
|
|
|
|
|
|
|
private:
|
2019-09-06 05:40:20 +00:00
|
|
|
std::unique_ptr<Ui::DecompilerWidget> ui;
|
2017-12-21 14:23:44 +00:00
|
|
|
|
2019-09-01 09:06:54 +00:00
|
|
|
RefreshDeferrer *refreshDeferrer;
|
|
|
|
|
2019-07-11 13:21:54 +00:00
|
|
|
QSyntaxHighlighter *syntaxHighlighter;
|
2019-08-28 17:01:12 +00:00
|
|
|
bool decompilerSelectionEnabled;
|
2019-09-01 09:06:54 +00:00
|
|
|
bool autoRefreshEnabled;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if doRefresh() was called, but the decompiler was still running
|
|
|
|
* This means, after the decompiler has finished, it should be refreshed immediately.
|
|
|
|
*/
|
|
|
|
bool decompilerWasBusy;
|
2017-12-21 14:23:44 +00:00
|
|
|
|
2019-09-01 09:06:54 +00:00
|
|
|
RVA decompiledFunctionAddr;
|
2020-06-29 19:08:02 +00:00
|
|
|
std::unique_ptr<RAnnotatedCode, void (*)(RAnnotatedCode *)> code;
|
2019-07-12 08:57:07 +00:00
|
|
|
bool seekFromCursor = false;
|
|
|
|
|
2019-09-01 09:06:54 +00:00
|
|
|
Decompiler *getCurrentDecompiler();
|
|
|
|
|
|
|
|
void setAutoRefresh(bool enabled);
|
|
|
|
void doAutoRefresh();
|
|
|
|
void doRefresh(RVA addr = Core()->getOffset());
|
|
|
|
void updateRefreshButton();
|
2017-12-15 10:52:47 +00:00
|
|
|
void setupFonts();
|
2019-07-12 08:57:07 +00:00
|
|
|
void updateSelection();
|
|
|
|
void connectCursorPositionChanged(bool disconnect);
|
|
|
|
void updateCursorPosition();
|
|
|
|
|
2019-06-18 13:02:41 +00:00
|
|
|
QString getWindowTitle() const override;
|
2019-12-14 12:57:36 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief a wrapper around CutterSeekable::seekToReference to seek to an object which is
|
|
|
|
* referenced from the address under cursor
|
|
|
|
*/
|
|
|
|
void seekToReference();
|
2019-12-19 17:58:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieve the Cursor for a location as close as possible to the given address
|
|
|
|
* @param addr - an address in the decompiled function
|
|
|
|
* @return a Cursor object for the given address
|
|
|
|
*/
|
|
|
|
QTextCursor getCursorForAddress(RVA addr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Append a highlighted line to the TextEdit
|
|
|
|
* @param extraSelection - an ExtraSelection object colored with the appropriate color
|
|
|
|
* @return True on success, otherwise False
|
|
|
|
*/
|
|
|
|
bool colorLine(QTextEdit::ExtraSelection extraSelection);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function responsible to highlight all the breakpoints in the decompiler view.
|
|
|
|
* It will also run when a breakpoint is added, removed or modified.
|
|
|
|
*/
|
|
|
|
void highlightBreakpoints();
|
2020-06-29 19:08:02 +00:00
|
|
|
/**
|
|
|
|
* @brief Finds the earliest offset and breakpoints within the specified range [startPos, endPos]
|
|
|
|
* in the specified RAnnotatedCode
|
|
|
|
*
|
|
|
|
* This function is supposed to be used for finding the earliest offset and breakpoints within the specified range
|
|
|
|
* [startPos, endPos]. This will set the value of the variables 'RVA firstOffsetInLine' and 'QVector<RVA> availableBreakpoints' in
|
|
|
|
* this->mCtxMenu.
|
|
|
|
*
|
|
|
|
* @param codeDecompiled - A reference to the RAnnotatedCode for the function that is decompiled.
|
|
|
|
* @param startPos - Position of the start of the range(inclusive).
|
|
|
|
* @param endPos - Position of the end of the range(inclusive).
|
|
|
|
*/
|
|
|
|
void gatherBreakpointInfo(RAnnotatedCode &codeDecompiled, size_t startPos, size_t endPos);
|
2020-06-08 21:29:26 +00:00
|
|
|
|
2020-06-29 19:08:02 +00:00
|
|
|
void setInfoForBreakpoints();
|
2020-07-16 08:56:38 +00:00
|
|
|
|
|
|
|
void setAnnotationsAtCursor(size_t pos);
|
2017-12-06 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
2019-09-06 05:40:20 +00:00
|
|
|
#endif // DECOMPILERWIDGET_H
|