diff --git a/src/Cutter.cpp b/src/Cutter.cpp index b3bdacd9..0386b9d0 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -769,16 +769,22 @@ RVA CutterCore::getOffsetJump(RVA addr) return value; } -QString CutterCore::getDecompiledCode(RVA addr) +QString CutterCore::getDecompiledCodePDC(RVA addr) { return cmd("pdc @ " + QString::number(addr)); } -QString CutterCore::getDecompiledCode(QString addr) +bool CutterCore::getR2DecAvailable() { - return cmd("pdc @ " + addr); + return cmd("e cmd.pdc=?").split('\n').contains("r2dec"); } +QString CutterCore::getDecompiledCodeR2Dec(RVA addr) +{ + return cmd("pdd @ " + QString::number(addr)); +} + + QJsonDocument CutterCore::getFileInfo() { return cmdj("ij"); diff --git a/src/Cutter.h b/src/Cutter.h index 50bbd52c..9044e023 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -526,9 +526,11 @@ public: bool currentlyDebugging = false; bool currentlyEmulating = false; + QString getDecompiledCodePDC(RVA addr); + bool getR2DecAvailable(); + QString getDecompiledCodeR2Dec(RVA addr); + RVA getOffsetJump(RVA addr); - QString getDecompiledCode(RVA addr); - QString getDecompiledCode(QString addr); QJsonDocument getFileInfo(); QJsonDocument getSignatureInfo(); QJsonDocument getFileVersionInfo(); diff --git a/src/widgets/PseudocodeWidget.cpp b/src/widgets/PseudocodeWidget.cpp index d5de6e68..8c7eb1c8 100644 --- a/src/widgets/PseudocodeWidget.cpp +++ b/src/widgets/PseudocodeWidget.cpp @@ -34,6 +34,14 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) : refresh(Core()->getOffset()); }); + if (Core()->getR2DecAvailable()) { + ui->decompilerComboBox->setEnabled(true); + ui->decompilerComboBox->setCurrentIndex(DecompilerCBR2Dec); + } else { + ui->decompilerComboBox->setEnabled(false); + ui->decompilerComboBox->setCurrentIndex(DecompilerCBPdc); + } + refresh(RVA_INVALID); } @@ -47,7 +55,19 @@ void PseudocodeWidget::refresh(RVA addr) return; } - const QString &decompiledCode = Core()->getDecompiledCode(addr); + 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; + } + if (decompiledCode.length() == 0) { ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString( addr) + " " + tr("(Not a function?)")); diff --git a/src/widgets/PseudocodeWidget.h b/src/widgets/PseudocodeWidget.h index 1ab6ad0a..283fc627 100644 --- a/src/widgets/PseudocodeWidget.h +++ b/src/widgets/PseudocodeWidget.h @@ -28,6 +28,7 @@ private slots: void refreshPseudocode(); private: + enum DecompilerComboBoxValues { DecompilerCBR2Dec, DecompilerCBPdc }; std::unique_ptr ui; SyntaxHighlighter *syntaxHighLighter; diff --git a/src/widgets/PseudocodeWidget.ui b/src/widgets/PseudocodeWidget.ui index 0494ca27..eb768006 100644 --- a/src/widgets/PseudocodeWidget.ui +++ b/src/widgets/PseudocodeWidget.ui @@ -62,6 +62,27 @@ + + + + Decompiler: + + + + + + + + r2dec + + + + + pdc + + + +