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; return value;
} }
QString CutterCore::getDecompiledCode(RVA addr) QString CutterCore::getDecompiledCodePDC(RVA addr)
{ {
return cmd("pdc @ " + QString::number(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() QJsonDocument CutterCore::getFileInfo()
{ {
return cmdj("ij"); return cmdj("ij");

View File

@ -526,9 +526,11 @@ public:
bool currentlyDebugging = false; bool currentlyDebugging = false;
bool currentlyEmulating = false; bool currentlyEmulating = false;
QString getDecompiledCodePDC(RVA addr);
bool getR2DecAvailable();
QString getDecompiledCodeR2Dec(RVA addr);
RVA getOffsetJump(RVA addr); RVA getOffsetJump(RVA addr);
QString getDecompiledCode(RVA addr);
QString getDecompiledCode(QString addr);
QJsonDocument getFileInfo(); QJsonDocument getFileInfo();
QJsonDocument getSignatureInfo(); QJsonDocument getSignatureInfo();
QJsonDocument getFileVersionInfo(); QJsonDocument getFileVersionInfo();

View File

@ -34,6 +34,14 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
refresh(Core()->getOffset()); 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); refresh(RVA_INVALID);
} }
@ -47,7 +55,19 @@ void PseudocodeWidget::refresh(RVA addr)
return; 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) { if (decompiledCode.length() == 0) {
ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString( ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString(
addr) + " " + tr("(Not a function?)")); addr) + " " + tr("(Not a function?)"));

View File

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

View File

@ -62,6 +62,27 @@
</property> </property>
</spacer> </spacer>
</item> </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> </layout>
</item> </item>
</layout> </layout>