Add 'Export as code' feature (#657)

This commit is contained in:
Paul I 2018-08-25 01:36:15 +03:00 committed by xarkes
parent 9316ff8e92
commit 5342651e67
3 changed files with 73 additions and 133 deletions

View File

@ -37,6 +37,7 @@
#include "utils/Helpers.h" #include "utils/Helpers.h"
#include "utils/SvgIconEngine.h" #include "utils/SvgIconEngine.h"
#include "utils/ProgressIndicator.h" #include "utils/ProgressIndicator.h"
#include "utils/TempConfig.h"
#include "dialogs/NewFileDialog.h" #include "dialogs/NewFileDialog.h"
#include "dialogs/InitialOptionsDialog.h" #include "dialogs/InitialOptionsDialog.h"
@ -120,9 +121,6 @@ void MainWindow::initUI()
/* /*
* Toolbar * Toolbar
*/ */
// Hide central tab widget tabs
QTabBar *centralbar = ui->centralTabWidget->tabBar();
centralbar->setVisible(false);
// Sepparator between undo/redo and goto lineEdit // Sepparator between undo/redo and goto lineEdit
QWidget *spacer3 = new QWidget(); QWidget *spacer3 = new QWidget();
@ -198,9 +196,6 @@ void MainWindow::initUI()
// Add graph view as dockable // Add graph view as dockable
graphDock = new GraphWidget(this, ui->actionGraph); graphDock = new GraphWidget(this, ui->actionGraph);
// Hide centralWidget as we do not need it
ui->centralWidget->hide();
sectionsDock = new SectionsWidget(this, ui->actionSections); sectionsDock = new SectionsWidget(this, ui->actionSections);
entrypointDock = new EntrypointWidget(this, ui->actionEntrypoints); entrypointDock = new EntrypointWidget(this, ui->actionEntrypoints);
functionsDock = new FunctionsWidget(this, ui->actionFunctions); functionsDock = new FunctionsWidget(this, ui->actionFunctions);
@ -951,6 +946,58 @@ void MainWindow::on_actionImportPDB_triggered()
} }
} }
void MainWindow::on_actionExport_as_code_triggered()
{
QStringList filters;
QMap<QString, QString> cmdMap;
filters << tr("C uin8_t array (*.c)");
cmdMap[filters.last()] = "pc";
filters << tr("C uin16_t array (*.c)");
cmdMap[filters.last()] = "pch";
filters << tr("C uin32_t array (*.c)");
cmdMap[filters.last()] = "pcw";
filters << tr("C uin64_t array (*.c)");
cmdMap[filters.last()] = "pcd";
filters << tr("C string (*.c)");
cmdMap[filters.last()] = "pcs";
filters << tr("Shell-script that reconstructs the bin (*.sh)");
cmdMap[filters.last()] = "pcS";
filters << tr("JSON array (*.json)");
cmdMap[filters.last()] = "pcj";
filters << tr("JavaScript array (*.js)");
cmdMap[filters.last()] = "pcJ";
filters << tr("Python array (*.py)");
cmdMap[filters.last()] = "pcp";
filters << tr("Print 'wx' r2 commands (*.r2)");
cmdMap[filters.last()] = "pc*";
filters << tr("GAS .byte blob (*.txt)");
cmdMap[filters.last()] = "pca";
filters << tr(".bytes with instructions in comments (*.txt)");
cmdMap[filters.last()] = "pcA";
QFileDialog dialog(this, tr("Export as code"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilters(filters);
dialog.selectFile("dump");
dialog.setDefaultSuffix("c");
if (!dialog.exec())
return;
QFile file(dialog.selectedFiles()[0]);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Can't open file";
return;
}
TempConfig tempConfig;
tempConfig.set("io.va", false);
QTextStream fileOut(&file);
QString &cmd = cmdMap[dialog.selectedNameFilter()];
fileOut << Core()->cmd(cmd + " $s @ 0");
}
void MainWindow::projectSaved(const QString &name) void MainWindow::projectSaved(const QString &name)
{ {
addOutput(tr("Project saved: ") + name); addOutput(tr("Project saved: ") + name);

View File

@ -165,6 +165,8 @@ private slots:
void on_actionImportPDB_triggered(); void on_actionImportPDB_triggered();
void on_actionExport_as_code_triggered();
void projectSaved(const QString &name); void projectSaved(const QString &name);
void updateTasksIndicator(); void updateTasksIndicator();

View File

@ -69,88 +69,13 @@ QToolTip {
<property name="dockNestingEnabled"> <property name="dockNestingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QMenu" name="addExtraWidgets">
<property name="sizePolicy"> <property name="title">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <string>Add extra...</string>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_10"> <addaction name="actionExtraGraph"/>
<property name="leftMargin"> <addaction name="actionExtraHexdump"/>
<number>0</number> <addaction name="actionExtraDisassembly"/>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QTabWidget" name="centralTabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QTabWidget::pane { /* The tab widget frame */
border-top: 0px;
}</string>
</property>
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="usesScrollButtons">
<bool>false</bool>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<property name="tabsClosable">
<bool>false</bool>
</property>
<widget class="QWidget" name="tab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string notr="true">Console</string>
</attribute>
<layout class="QVBoxLayout" name="tabVerticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">
<property name="geometry"> <property name="geometry">
@ -158,7 +83,7 @@ border-top: 0px;
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1013</width> <width>1013</width>
<height>20</height> <height>21</height>
</rect> </rect>
</property> </property>
<property name="defaultUp"> <property name="defaultUp">
@ -170,10 +95,10 @@ border-top: 0px;
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>345</x> <x>378</x>
<y>96</y> <y>100</y>
<width>148</width> <width>136</width>
<height>215</height> <height>271</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
@ -186,10 +111,12 @@ border-top: 0px;
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionSaveAs"/> <addaction name="actionSaveAs"/>
<addaction name="actionExport_as_code"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionRun_Script"/> <addaction name="actionRun_Script"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
<addaction name="separator"/>
</widget> </widget>
<widget class="QMenu" name="menuView"> <widget class="QMenu" name="menuView">
<property name="title"> <property name="title">
@ -223,36 +150,6 @@ border-top: 0px;
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionPreferences"/> <addaction name="actionPreferences"/>
</widget> </widget>
<widget class="QMenu" name="addDebugWidgets">
<property name="title">
<string>Debug...</string>
</property>
<addaction name="actionStack"/>
<addaction name="actionRegisters"/>
<addaction name="actionBacktrace"/>
<addaction name="actionMemoryMap"/>
<addaction name="actionBreakpoint"/>
<addaction name="actionRegisterRefs"/>
</widget>
<widget class="QMenu" name="addInfoWidgets">
<property name="title">
<string>Info...</string>
</property>
<addaction name="actionEntrypoints"/>
<addaction name="actionClasses"/>
<addaction name="actionImports"/>
<addaction name="actionExports"/>
<addaction name="actionSymbols"/>
<addaction name="actionSDBBrowser"/>
<addaction name="actionResources"/>
<addaction name="actionVTables"/>
<addaction name="actionTypes"/>
<addaction name="actionFlags"/>
<addaction name="actionSections"/>
<addaction name="actionHeaders"/>
<addaction name="actionZignatures"/>
<addaction name="actionRelocs"/>
</widget>
<widget class="QMenu" name="menuWindows"> <widget class="QMenu" name="menuWindows">
<property name="title"> <property name="title">
<string>Windows</string> <string>Windows</string>
@ -269,14 +166,11 @@ border-top: 0px;
<addaction name="actionStrings"/> <addaction name="actionStrings"/>
<addaction name="actionSearch"/> <addaction name="actionSearch"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="addInfoWidgets"/>
<addaction name="addDebugWidgets"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionComments"/> <addaction name="actionComments"/>
<addaction name="actionConsole"/> <addaction name="actionConsole"/>
<addaction name="actionJupyter"/> <addaction name="actionJupyter"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="addExtraWidgets"/>
</widget> </widget>
<widget class="QMenu" name="menuDebug"> <widget class="QMenu" name="menuDebug">
<property name="title"> <property name="title">
@ -1174,14 +1068,11 @@ border-top: 0px;
<string>Disassembly view</string> <string>Disassembly view</string>
</property> </property>
</action> </action>
<widget class="QMenu" name="addExtraWidgets"> <action name="actionExport_as_code">
<property name="title"> <property name="text">
<string>Add extra...</string> <string>Export as code</string>
</property> </property>
<addaction name="actionExtraGraph"/> </action>
<addaction name="actionExtraHexdump"/>
<addaction name="actionExtraDisassembly"/>
</widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources> <resources>