Removed CreateNewDialog

This commit is contained in:
xarkes 2017-12-13 17:20:58 +01:00
parent 4213852419
commit d34b45ab4a
10 changed files with 26 additions and 826 deletions

View File

@ -1,6 +1,5 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "dialogs/CreateNewDialog.h"
#include "dialogs/CommentsDialog.h"
#include "dialogs/AboutDialog.h"
#include "dialogs/RenameDialog.h"
@ -636,12 +635,6 @@ void MainWindow::on_actionForward_triggered()
core->seekNext();
}
void MainWindow::on_actionCreate_File_triggered()
{
CreateNewDialog *n = new CreateNewDialog(this);
n->exec();
}
void MainWindow::on_actionDisasAdd_comment_triggered()
{
CommentsDialog *c = new CommentsDialog(this);

View File

@ -126,8 +126,6 @@ private slots:
void on_actionRefresh_Panels_triggered();
void on_actionCreate_File_triggered();
void on_actionDisasAdd_comment_triggered();
void on_actionDefaut_triggered();

View File

@ -166,7 +166,7 @@ border-top: 0px;
<x>0</x>
<y>0</y>
<width>1013</width>
<height>23</height>
<height>22</height>
</rect>
</property>
<property name="defaultUp">
@ -180,8 +180,8 @@ border-top: 0px;
<rect>
<x>367</x>
<y>185</y>
<width>140</width>
<height>239</height>
<width>156</width>
<height>206</height>
</rect>
</property>
<property name="title">
@ -646,14 +646,6 @@ QToolButton:pressed {
<string>Default Theme</string>
</property>
</action>
<action name="actionCreate_File">
<property name="text">
<string>Create file</string>
</property>
<property name="toolTip">
<string>Create file</string>
</property>
</action>
<action name="actionBindiff">
<property name="text">
<string>Bindiff</string>

View File

@ -49,7 +49,6 @@ SOURCES += \
utils/Highlighter.cpp \
utils/MdHighlighter.cpp \
dialogs/AsmOptionsDialog.cpp \
dialogs/CreateNewDialog.cpp \
dialogs/NewFileDialog.cpp \
AnalThread.cpp \
widgets/CommentsWidget.cpp \
@ -100,7 +99,6 @@ HEADERS += \
utils/Highlighter.h \
utils/MdHighlighter.h \
dialogs/OptionsDialog.h \
dialogs/CreateNewDialog.h \
dialogs/NewFileDialog.h \
AnalThread.h \
widgets/CommentsWidget.h \
@ -143,7 +141,6 @@ FORMS += \
dialogs/NewfileDialog.ui \
dialogs/OptionsDialog.ui \
MainWindow.ui \
dialogs/CreateNewDialog.ui \
widgets/CommentsWidget.ui \
widgets/ConsoleWidget.ui \
widgets/Dashboard.ui \

View File

@ -1,240 +0,0 @@
#include <QMessageBox>
#include "dialogs/NewFileDialog.h"
#include "dialogs/CreateNewDialog.h"
#include "ui_CreateNewDialog.h"
#include "r_util.h"
CreateNewDialog::CreateNewDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CreateNewDialog),
w(new MainWindow),
core(CutterCore::getInstance())
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
}
CreateNewDialog::~CreateNewDialog() {}
void CreateNewDialog::on_pushButton_2_clicked()
{
// Close dialog and open OptionsDialog
close();
NewFileDialog *n = new NewFileDialog(nullptr); // TODO: This leaks
n->show();
}
void CreateNewDialog::on_pushButton_3_clicked()
{
close();
}
void CreateNewDialog::on_exampleButton_clicked()
{
QString type = ui->comboType->currentText();
QString str;
if (type == "Assembler")
{
str = "; Sample program code\nmov eax, 1\nint 0x80";
}
else if (type == "Text")
{
str = "Hello World";
}
else if (type == "Rapatch")
{
str = "; Sample rapatch script\n"
"0x0 \"Hello World\n"
"0x10 909090";
}
else if (type == "C Code")
{
str = "int main() {\n"
" write (1, \"Hello World\", 12);\n"
" exit (0);\n"
"}";
}
else if (type == "Radare2 script")
{
str = "w Hello\ns+5\nw World";
}
else if (type == "Hexpairs")
{
str = "48656c6c6f20576f726c6400";
}
else fprintf(stderr, "%s", tr("Unknown combo value selected").toLocal8Bit().constData());
if (str.length() > 0)
ui->plainTextEdit->setPlainText(str);
// }
}
void CreateNewDialog::on_buttonCreate_clicked()
{
RCoreLocked lcore = core->core();
QString type = ui->comboType->currentText();
QString str;
bool created = false;
QString arch = ui->comboArch->currentText();
int fsize = r_num_math(NULL, ui->entrySize->text().toUtf8().constData());
QString format = ui->comboFormat->currentText();
if (type == "Assembler")
{
RAsmCode *code = r_asm_massemble(lcore->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData());
if (code && code->len > 0)
{
char file[32];
snprintf(file, sizeof(file) - 1, "malloc://%d", code->len);
if (core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, code->buf, code->len);
}
else
{
__alert(tr("Failed to create file"));
}
}
else
{
__alert(tr("Invalid assembler code"));
}
r_asm_code_free(code);
}
else if (type == "Rapatch")
{
if (fsize > 0)
{
char file[32];
created = true;
snprintf(file, sizeof(file) - 1, "malloc://%d", fsize);
if (core->loadFile(file, 0, 0, 1, 0, 0, false))
{
r_core_patch(lcore, ui->plainTextEdit->toPlainText().toUtf8().constData());
r_core_seek(lcore, 0, 1);
created = true;
}
else
{
__alert(tr("Failed to open file"));
}
}
else
{
__alert(tr("Invalid file size"));
}
}
else if (type == "C Code")
{
__alert("C Code: TODO");
// ragg2-cc -x
}
else if (type == "Radare2 script")
{
if (fsize > 0)
{
char file[32];
created = true;
snprintf(file, sizeof(file) - 1, "malloc://%d", fsize);
if (core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
QString str = ui->plainTextEdit->toPlainText();
QList <QString> lines = str.split("\n");
foreach (QString str, lines)
{
core->cmd(str);
}
}
else
{
__alert(tr("Failed to open file"));
}
}
else
{
__alert(tr("Invalid file size"));
}
}
else if (type == "Text")
{
char file[32];
QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8();
size_t sz = strlen(hexpairs.constData());
if (sz > 0)
{
snprintf(file, sizeof(file) - 1, "malloc://%d", (int)sz);
if (core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, (const ut8 *)hexpairs.constData(), (int)sz);
}
else
{
__alert(tr("Failed to open file"));
}
}
else
{
__alert(tr("Empty string?"));
}
}
else if (type == "Hexpairs")
{
char file[32];
int sz;
QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8();
ut8 *buf = (ut8 *)malloc(strlen(hexpairs.constData()) + 1);
sz = r_hex_str2bin(hexpairs.constData(), buf);
if (sz > 0)
{
snprintf(file, sizeof(file) - 1, "malloc://%d", sz);
if (core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, buf, sz);
}
else
{
__alert(tr("Failed to open file"));
}
}
else
{
__alert(tr("Invalid hexpair string"));
}
free(buf);
}
else
{
__alert(tr("Unknown combo value selected"));
return;
}
if (format != "Raw")
{
__alert("TODO: non-raw fileformat is not yet supported");
created = false;
delete core;
core = nullptr;
}
if (created)
{
// Close dialog and open OptionsDialog
close();
core->seek(0);
w->refreshAll();
w->setFilename("-");
w->addOutput(tr("Finished, check its contents"));
w->showMaximized();
}
else
{
__alert(tr("No file created."));
}
}

View File

@ -1,36 +0,0 @@
#ifndef CREATENEWDIALOG_H
#define CREATENEWDIALOG_H
#include <QDialog>
#include "MainWindow.h"
#include <memory>
namespace Ui
{
class CreateNewDialog;
}
class CreateNewDialog : public QDialog
{
Q_OBJECT
public:
explicit CreateNewDialog(QWidget *parent = 0);
~CreateNewDialog();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
void on_exampleButton_clicked();
void on_buttonCreate_clicked();
private:
std::unique_ptr<Ui::CreateNewDialog> ui;
MainWindow *w;
CutterCore *core;
};
#endif // CREATENEWDIALOG_H

View File

@ -1,482 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateNewDialog</class>
<widget class="QDialog" name="CreateNewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>587</width>
<height>474</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>5</number>
</property>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>96</width>
<height>96</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>96</width>
<height>96</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../resources.qrc">:/img/cutter_plain.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>8</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true"> Create new file</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Architecture:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboArch">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>arm</string>
</property>
</item>
<item>
<property name="text">
<string>bf</string>
</property>
</item>
<item>
<property name="text">
<string>dalvik</string>
</property>
</item>
<item>
<property name="text">
<string>dcpu16</string>
</property>
</item>
<item>
<property name="text">
<string>java</string>
</property>
</item>
<item>
<property name="text">
<string>mips</string>
</property>
</item>
<item>
<property name="text">
<string>ppc</string>
</property>
</item>
<item>
<property name="text">
<string>psosvm</string>
</property>
</item>
<item>
<property name="text">
<string>rar</string>
</property>
</item>
<item>
<property name="text">
<string>x86</string>
</property>
</item>
<item>
<property name="text">
<string>z80</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bits:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBits">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Binary format:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboFormat">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Raw</string>
</property>
</item>
<item>
<property name="text">
<string>ELF</string>
</property>
</item>
<item>
<property name="text">
<string>PE</string>
</property>
</item>
<item>
<property name="text">
<string>MACH-0</string>
</property>
</item>
<item>
<property name="text">
<string>COFF</string>
</property>
</item>
<item>
<property name="text">
<string>Plan9</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>File size:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="entrySize">
<property name="inputMask">
<string notr="true"/>
</property>
<property name="text">
<string notr="true">0</string>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Input type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboType">
<property name="currentText">
<string>Text</string>
</property>
<item>
<property name="text">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Hexpairs</string>
</property>
</item>
<item>
<property name="text">
<string>Assembler</string>
</property>
</item>
<item>
<property name="text">
<string>Radare2 script</string>
</property>
</item>
<item>
<property name="text">
<string>Rapatch</string>
</property>
</item>
<item>
<property name="text">
<string>C Code</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="exampleButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string notr="true">Fill the textarea with example code</string>
</property>
<property name="text">
<string>Example</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Cancel</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCreate">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -1,5 +1,5 @@
#include "OptionsDialog.h"
#include "dialogs/CreateNewDialog.h"
#include "MainWindow.h"
#include "dialogs/NewFileDialog.h"
#include "dialogs/AboutDialog.h"
#include "ui_NewfileDialog.h"
@ -84,9 +84,6 @@ NewFileDialog::NewFileDialog(QWidget *parent) :
ui->tabWidget->setCurrentWidget(ui->filesTab);
}
// Hide "create" button until the dialog works
ui->createButton->hide();
ui->loadProjectButton->setEnabled(ui->projectsListWidget->currentItem() != nullptr);
}
@ -198,14 +195,6 @@ void NewFileDialog::on_actionRemove_item_triggered()
ui->newFileEdit->clear();
}
void NewFileDialog::on_createButton_clicked()
{
// Close dialog and open create new file dialog
close();
CreateNewDialog *n = new CreateNewDialog(nullptr);
n->exec();
}
void NewFileDialog::on_actionClear_all_triggered()
{
// Clear recent file list

View File

@ -21,7 +21,6 @@ public:
private slots:
void on_loadFileButton_clicked();
void on_selectFileButton_clicked();
void on_createButton_clicked();
void on_selectProjectsDirButton_clicked();
void on_loadProjectButton_clicked();

View File

@ -231,13 +231,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="createButton">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadFileButton">
<property name="text">
@ -401,7 +394,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="buttonBar" stretch="0,0">
<layout class="QHBoxLayout" name="buttonBar" stretch="0,0,0,0">
<property name="spacing">
<number>10</number>
</property>
@ -415,26 +408,26 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>500</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="aboutButton">
<property name="text">
<string>About</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>500</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="aboutButton">
<property name="text">
<string>About</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -470,9 +463,6 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../resources.qrc"/>
<include location="../resources.qrc"/>
</resources>
<resources/>
<connections/>
</ui>