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
|
|
|
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/Helpers.h"
|
|
|
|
#include "common/SyntaxHighlighter.h"
|
|
|
|
#include "common/TempConfig.h"
|
2017-12-06 23:19:14 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
|
2019-03-27 08:24:54 +00:00
|
|
|
MemoryDockWidget(CutterCore::MemoryWidgetType::Pseudocode, main, action),
|
2018-03-21 20:32:32 +00:00
|
|
|
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(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (visibility) {
|
2017-12-06 23:19:14 +00:00
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Pseudocode);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-13 15:41:08 +00:00
|
|
|
// TODO Use RefreshDeferrer and remove the refresh button
|
2017-12-21 14:23:44 +00:00
|
|
|
connect(ui->refreshButton, &QAbstractButton::clicked, this, [this]() {
|
2019-01-12 17:02:51 +00:00
|
|
|
doRefresh(Core()->getOffset());
|
2017-12-06 23:19:14 +00:00
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-12 17:02:51 +00:00
|
|
|
doRefresh(RVA_INVALID);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 15:41:08 +00:00
|
|
|
PseudocodeWidget::~PseudocodeWidget() = default;
|
2017-12-06 23:19:14 +00:00
|
|
|
|
|
|
|
|
2019-01-12 17:02:51 +00:00
|
|
|
void PseudocodeWidget::doRefresh(RVA addr)
|
2017-12-06 23:19:14 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (addr == RVA_INVALID) {
|
2017-12-21 14:23:44 +00:00
|
|
|
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?)"));
|
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()
|
|
|
|
{
|
2019-01-12 17:02:51 +00:00
|
|
|
doRefresh(Core()->getOffset());
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-18 13:02:41 +00:00
|
|
|
QString PseudocodeWidget::getWindowTitle() const
|
|
|
|
{
|
|
|
|
return tr("Pseudocode");
|
|
|
|
}
|
|
|
|
|
2017-12-06 23:19:14 +00:00
|
|
|
void PseudocodeWidget::fontsUpdated()
|
|
|
|
{
|
|
|
|
setupFonts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::colorsUpdatedSlot()
|
|
|
|
{
|
|
|
|
}
|