From c6787fd58da1675b490a18faf1a948eec69d7fbe Mon Sep 17 00:00:00 2001 From: Paul I Date: Sat, 25 Aug 2018 21:54:23 +0300 Subject: [PATCH] Export graph as SVG, PDF, PNG... Fix #242 Export graph as SVG, PDF, PNG... Fix #242 --- radare2 | 2 +- src/widgets/DisassemblerGraphView.cpp | 33 +++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/radare2 b/radare2 index f82b2898..b5044de5 160000 --- a/radare2 +++ b/radare2 @@ -1 +1 @@ -Subproject commit f82b289822825e4c7403734f3b95dfd7f5e4f725 +Subproject commit b5044de59bf36a2ba6deb19100b57aa40592e829 diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 30d6f091..0579c302 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "Cutter.h" #include "utils/Colors.h" @@ -821,8 +822,36 @@ void DisassemblerGraphView::blockTransitionedTo(GraphView::GraphBlock *to) void DisassemblerGraphView::on_actionExportGraph_triggered() { - QString fileName = QFileDialog::getSaveFileName(this, - tr("Export Graph"), "", tr("Dot file (*.dot)")); + QStringList filters; + filters.append(tr("Graphiz dot (*.dot)")); + if (!QStandardPaths::findExecutable("dot").isEmpty() + || !QStandardPaths::findExecutable("xdot").isEmpty()) { + filters.append(tr("GIF (*.gif)")); + filters.append(tr("PNG (*.png)")); + filters.append(tr("JPEG (*.jpg)")); + filters.append(tr("PostScript (*.ps)")); + filters.append(tr("SVG (*.svg)")); + filters.append(tr("JSON (*.json)")); + } + + QFileDialog dialog(this, tr("Export Graph")); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.selectFile("graph"); + dialog.setDefaultSuffix("dot"); + if (!dialog.exec()) + return; + int startIdx = dialog.selectedNameFilter().lastIndexOf("*.") + 2; + int count = dialog.selectedNameFilter().length() - startIdx - 1; + QString format = dialog.selectedNameFilter().mid(startIdx, count); + QString fileName = dialog.selectedFiles()[0]; + if (format != "dot") { + TempConfig tempConfig; + tempConfig.set("graph.gv.format", format); + qWarning() << Core()->cmd(QString("agfw \"%1\" @ $FB").arg(fileName)); + return; + } QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning() << "Can't open file";