2017-12-06 23:19:14 +00:00
|
|
|
#include "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-15 10:52:47 +00:00
|
|
|
PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: QDockWidget(parent, flags)
|
|
|
|
, textEditWidget(new QTextEdit(this))
|
|
|
|
, syntaxHighLighter( new SyntaxHighlighter(textEditWidget->document()))
|
2017-12-06 23:19:14 +00:00
|
|
|
{
|
2017-12-15 10:52:47 +00:00
|
|
|
textEditWidget->setParent(this);
|
|
|
|
setWidget(textEditWidget);
|
2017-12-06 23:19:14 +00:00
|
|
|
setupFonts();
|
|
|
|
colorsUpdatedSlot();
|
2017-12-15 10:52:47 +00:00
|
|
|
textEditWidget->setReadOnly(true);
|
|
|
|
textEditWidget->setLineWrapMode(QTextEdit::NoWrap);
|
2017-12-06 23:19:14 +00:00
|
|
|
|
|
|
|
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(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get alerted when there's a refresh
|
|
|
|
connect(Core(), &CutterCore::refreshAll, this, [this]() {
|
|
|
|
refresh(Core()->getOffset());
|
|
|
|
});
|
|
|
|
|
|
|
|
refresh(Core()->getOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
PseudocodeWidget::PseudocodeWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: PseudocodeWidget(parent, flags)
|
|
|
|
{
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
PseudocodeWidget::~PseudocodeWidget() {}
|
|
|
|
|
|
|
|
|
|
|
|
void PseudocodeWidget::on_seekChanged(RVA addr)
|
|
|
|
{
|
|
|
|
refresh(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::refresh(RVA addr)
|
|
|
|
{
|
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-15 10:52:47 +00:00
|
|
|
textEditWidget->setText(tr("Cannot decompile at") + " " + RAddressString(addr) + " " + tr("(Not a function?)"));
|
|
|
|
return;
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
2017-12-15 10:52:47 +00:00
|
|
|
textEditWidget->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-15 10:52:47 +00:00
|
|
|
textEditWidget->setFont(font);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::fontsUpdated()
|
|
|
|
{
|
|
|
|
setupFonts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::colorsUpdatedSlot()
|
|
|
|
{
|
2017-12-15 10:52:47 +00:00
|
|
|
const QString textEditClassName(textEditWidget->metaObject()->className());
|
|
|
|
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-15 10:52:47 +00:00
|
|
|
textEditWidget->setStyleSheet(styleSheet);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|