mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-18 18:38:51 +00:00
Add 'Export as code' feature (#657)
This commit is contained in:
parent
9316ff8e92
commit
5342651e67
@ -37,6 +37,7 @@
|
||||
#include "utils/Helpers.h"
|
||||
#include "utils/SvgIconEngine.h"
|
||||
#include "utils/ProgressIndicator.h"
|
||||
#include "utils/TempConfig.h"
|
||||
|
||||
#include "dialogs/NewFileDialog.h"
|
||||
#include "dialogs/InitialOptionsDialog.h"
|
||||
@ -120,9 +121,6 @@ void MainWindow::initUI()
|
||||
/*
|
||||
* Toolbar
|
||||
*/
|
||||
// Hide central tab widget tabs
|
||||
QTabBar *centralbar = ui->centralTabWidget->tabBar();
|
||||
centralbar->setVisible(false);
|
||||
|
||||
// Sepparator between undo/redo and goto lineEdit
|
||||
QWidget *spacer3 = new QWidget();
|
||||
@ -198,9 +196,6 @@ void MainWindow::initUI()
|
||||
// Add graph view as dockable
|
||||
graphDock = new GraphWidget(this, ui->actionGraph);
|
||||
|
||||
// Hide centralWidget as we do not need it
|
||||
ui->centralWidget->hide();
|
||||
|
||||
sectionsDock = new SectionsWidget(this, ui->actionSections);
|
||||
entrypointDock = new EntrypointWidget(this, ui->actionEntrypoints);
|
||||
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)
|
||||
{
|
||||
addOutput(tr("Project saved: ") + name);
|
||||
|
@ -165,6 +165,8 @@ private slots:
|
||||
|
||||
void on_actionImportPDB_triggered();
|
||||
|
||||
void on_actionExport_as_code_triggered();
|
||||
|
||||
void projectSaved(const QString &name);
|
||||
|
||||
void updateTasksIndicator();
|
||||
|
@ -69,88 +69,13 @@ QToolTip {
|
||||
<property name="dockNestingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<widget class="QMenu" name="addExtraWidgets">
|
||||
<property name="title">
|
||||
<string>Add extra...</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<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>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>
|
||||
<addaction name="actionExtraGraph"/>
|
||||
<addaction name="actionExtraHexdump"/>
|
||||
<addaction name="actionExtraDisassembly"/>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
@ -158,7 +83,7 @@ border-top: 0px;
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1013</width>
|
||||
<height>20</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="defaultUp">
|
||||
@ -170,10 +95,10 @@ border-top: 0px;
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>345</x>
|
||||
<y>96</y>
|
||||
<width>148</width>
|
||||
<height>215</height>
|
||||
<x>378</x>
|
||||
<y>100</y>
|
||||
<width>136</width>
|
||||
<height>271</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
@ -186,10 +111,12 @@ border-top: 0px;
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
<addaction name="actionExport_as_code"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionRun_Script"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionQuit"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
@ -223,36 +150,6 @@ border-top: 0px;
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionPreferences"/>
|
||||
</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">
|
||||
<property name="title">
|
||||
<string>Windows</string>
|
||||
@ -269,14 +166,11 @@ border-top: 0px;
|
||||
<addaction name="actionStrings"/>
|
||||
<addaction name="actionSearch"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="addInfoWidgets"/>
|
||||
<addaction name="addDebugWidgets"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionComments"/>
|
||||
<addaction name="actionConsole"/>
|
||||
<addaction name="actionJupyter"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="addExtraWidgets"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuDebug">
|
||||
<property name="title">
|
||||
@ -1174,14 +1068,11 @@ border-top: 0px;
|
||||
<string>Disassembly view</string>
|
||||
</property>
|
||||
</action>
|
||||
<widget class="QMenu" name="addExtraWidgets">
|
||||
<property name="title">
|
||||
<string>Add extra...</string>
|
||||
</property>
|
||||
<addaction name="actionExtraGraph"/>
|
||||
<addaction name="actionExtraHexdump"/>
|
||||
<addaction name="actionExtraDisassembly"/>
|
||||
</widget>
|
||||
<action name="actionExport_as_code">
|
||||
<property name="text">
|
||||
<string>Export as code</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
Loading…
Reference in New Issue
Block a user