2017-12-06 23:19:14 +00:00
|
|
|
#include "PseudocodeWidget.h"
|
2017-12-21 14:23:44 +00:00
|
|
|
#include "ui_PseudocodeWidget.h"
|
2017-12-15 10:52:47 +00:00
|
|
|
|
|
|
|
#include <QTextEdit>
|
2017-12-06 23:19:14 +00:00
|
|
|
|
|
|
|
#include "utils/Configuration.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-12-15 10:52:47 +00:00
|
|
|
#include "utils/SyntaxHighlighter.h"
|
2017-12-06 23:19:14 +00:00
|
|
|
#include "utils/TempConfig.h"
|
|
|
|
|
2017-12-21 14:23:44 +00:00
|
|
|
PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags) :
|
|
|
|
QDockWidget(parent, flags),
|
|
|
|
ui(new Ui::PseudocodeWidget)
|
2017-12-06 23:19:14 +00:00
|
|
|
{
|
2017-12-21 14:23:44 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
syntaxHighLighter = new SyntaxHighlighter(ui->textEdit->document());
|
2017-12-16 13:22:56 +00:00
|
|
|
|
2017-12-06 23:19:14 +00:00
|
|
|
setupFonts();
|
|
|
|
colorsUpdatedSlot();
|
|
|
|
|
|
|
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
|
|
|
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
|
|
|
|
|
|
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshPseudocode()));
|
|
|
|
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshPseudocode()));
|
|
|
|
connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshPseudocode()));
|
|
|
|
connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshPseudocode()));
|
|
|
|
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshPseudocode()));
|
2017-12-14 19:51:24 +00:00
|
|
|
connect(Core(), &CutterCore::instructionChanged, this, [this](/*RVA offset*/) {
|
2017-12-06 23:19:14 +00:00
|
|
|
refreshPseudocode();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
|
|
|
if (visibility)
|
|
|
|
{
|
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Pseudocode);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-21 14:23:44 +00:00
|
|
|
connect(ui->refreshButton, &QAbstractButton::clicked, this, [this]() {
|
2017-12-06 23:19:14 +00:00
|
|
|
refresh(Core()->getOffset());
|
|
|
|
});
|
|
|
|
|
2017-12-21 14:23:44 +00:00
|
|
|
refresh(RVA_INVALID);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PseudocodeWidget::PseudocodeWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: PseudocodeWidget(parent, flags)
|
|
|
|
{
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
PseudocodeWidget::~PseudocodeWidget() {}
|
|
|
|
|
|
|
|
|
|
|
|
void PseudocodeWidget::refresh(RVA addr)
|
|
|
|
{
|
2017-12-21 14:23:44 +00:00
|
|
|
if (addr == RVA_INVALID)
|
|
|
|
{
|
|
|
|
ui->textEdit->setText(tr("Click Refresh to generate Pseudocode from current offset."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-15 10:52:47 +00:00
|
|
|
const QString& decompiledCode = Core()->getDecompiledCode(addr);
|
2017-12-06 23:19:14 +00:00
|
|
|
if (decompiledCode.length() == 0)
|
|
|
|
{
|
2017-12-21 14:23:44 +00:00
|
|
|
ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString(addr) + " " + tr("(Not a function?)"));
|
2017-12-15 10:52:47 +00:00
|
|
|
return;
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
2017-12-21 14:23:44 +00:00
|
|
|
ui->textEdit->setText(decompiledCode);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::refreshPseudocode()
|
|
|
|
{
|
|
|
|
refresh(Core()->getOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
|
|
|
{
|
|
|
|
if (type == CutterCore::MemoryWidgetType::Pseudocode)
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::setupFonts()
|
|
|
|
{
|
|
|
|
QFont font = Config()->getFont();
|
2017-12-21 14:23:44 +00:00
|
|
|
ui->textEdit->setFont(font);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::fontsUpdated()
|
|
|
|
{
|
|
|
|
setupFonts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::colorsUpdatedSlot()
|
|
|
|
{
|
2017-12-21 14:23:44 +00:00
|
|
|
const QString textEditClassName(ui->textEdit->metaObject()->className());
|
2017-12-15 10:52:47 +00:00
|
|
|
QString styleSheet = QString(textEditClassName + " { background-color: %1; color: %2; }")
|
2017-12-06 23:19:14 +00:00
|
|
|
.arg(ConfigColor("gui.background").name())
|
|
|
|
.arg(ConfigColor("btext").name());
|
2017-12-21 14:23:44 +00:00
|
|
|
ui->textEdit->setStyleSheet(styleSheet);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|