Fix #400 - Support r2dec

This commit is contained in:
Florian Märkl 2018-09-08 09:12:08 +02:00
parent f7d1ce8771
commit e3896dd01f
5 changed files with 56 additions and 6 deletions

View File

@ -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");

View File

@ -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();

View File

@ -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?)"));

View File

@ -28,6 +28,7 @@ private slots:
void refreshPseudocode();
private:
enum DecompilerComboBoxValues { DecompilerCBR2Dec, DecompilerCBPdc };
std::unique_ptr<Ui::PseudocodeWidget> ui;
SyntaxHighlighter *syntaxHighLighter;

View File

@ -62,6 +62,27 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="decompilerLabel">
<property name="text">
<string>Decompiler:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="decompilerComboBox">
<item>
<property name="text">
<string>r2dec</string>
</property>
</item>
<item>
<property name="text">
<string>pdc</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>