cutter/src/widgets/PseudocodeWidget.cpp

97 lines
2.6 KiB
C++
Raw Normal View History

#include "PseudocodeWidget.h"
#include "ui_PseudocodeWidget.h"
#include <QTextEdit>
2018-10-17 07:55:53 +00:00
#include "common/Configuration.h"
#include "common/Helpers.h"
#include "common/SyntaxHighlighter.h"
#include "common/TempConfig.h"
PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
MemoryDockWidget(CutterCore::MemoryWidgetType::Pseudocode, main, action),
2018-03-21 20:32:32 +00:00
ui(new Ui::PseudocodeWidget)
{
ui->setupUi(this);
syntaxHighLighter = new SyntaxHighlighter(ui->textEdit->document());
2017-12-16 13:22:56 +00:00
setupFonts();
colorsUpdatedSlot();
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
2018-03-21 20:32:32 +00:00
if (visibility) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Pseudocode);
}
});
// TODO Use RefreshDeferrer and remove the refresh button
connect(ui->refreshButton, &QAbstractButton::clicked, this, [this]() {
doRefresh(Core()->getOffset());
});
2018-09-08 07:12:08 +00:00
if (Core()->getR2DecAvailable()) {
ui->decompilerComboBox->setEnabled(true);
ui->decompilerComboBox->setCurrentIndex(DecompilerCBR2Dec);
} else {
ui->decompilerComboBox->setEnabled(false);
ui->decompilerComboBox->setCurrentIndex(DecompilerCBPdc);
}
doRefresh(RVA_INVALID);
}
PseudocodeWidget::~PseudocodeWidget() = default;
void PseudocodeWidget::doRefresh(RVA addr)
{
2018-03-21 20:32:32 +00:00
if (addr == RVA_INVALID) {
ui->textEdit->setText(tr("Click Refresh to generate Pseudocode from current offset."));
return;
}
2018-09-08 07:12:08 +00:00
QString decompiledCode;
switch (ui->decompilerComboBox->currentIndex()) {
case DecompilerCBR2Dec:
if (Core()->getR2DecAvailable()) {
decompiledCode = Core()->getDecompiledCodeR2Dec(addr);
break;
} // else fallthrough
case DecompilerCBPdc:
default:
decompiledCode = Core()->getDecompiledCodePDC(addr);
break;
}
2018-03-21 20:32:32 +00:00
if (decompiledCode.length() == 0) {
ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString(
addr) + " " + tr("(Not a function?)"));
return;
}
ui->textEdit->setText(decompiledCode);
}
void PseudocodeWidget::refreshPseudocode()
{
doRefresh(Core()->getOffset());
}
void PseudocodeWidget::setupFonts()
{
QFont font = Config()->getFont();
ui->textEdit->setFont(font);
}
void PseudocodeWidget::fontsUpdated()
{
setupFonts();
}
void PseudocodeWidget::colorsUpdatedSlot()
{
}