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"
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterDockWidget(main, action),
|
|
|
|
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()));
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
|
|
|
|
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
2017-12-06 23:19:14 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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());
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:23:44 +00:00
|
|
|
refresh(RVA_INVALID);
|
2017-12-06 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PseudocodeWidget::~PseudocodeWidget() {}
|
|
|
|
|
|
|
|
|
|
|
|
void PseudocodeWidget::refresh(RVA addr)
|
|
|
|
{
|
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()
|
|
|
|
{
|
|
|
|
refresh(Core()->getOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PseudocodeWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (type == CutterCore::MemoryWidgetType::Pseudocode) {
|
2017-12-06 23:19:14 +00:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|