diff --git a/src/AnalTask.cpp b/src/AnalTask.cpp index b281618a..40d766b0 100644 --- a/src/AnalTask.cpp +++ b/src/AnalTask.cpp @@ -71,6 +71,11 @@ void AnalTask::runTask() return; } + if (!options.shellcode.isNull() && options.shellcode.size() / 2 > 0) { + log(tr("Loading shellcode...\n")); + Core()->cmd("wx " + options.shellcode); + } + if (options.endian != InitialOptions::Endianness::Auto) { Core()->setEndianness(options.endian == InitialOptions::Endianness::Big); } diff --git a/src/AnalTask.h b/src/AnalTask.h index 3cdf1cce..9e920017 100644 --- a/src/AnalTask.h +++ b/src/AnalTask.h @@ -37,6 +37,8 @@ struct InitialOptions int bbsize = 0; QList analCmd; + + QString shellcode; }; class AnalTask : public AsyncTask diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 09acc8df..a3a18d35 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -312,7 +312,7 @@ void MainWindow::addExtraWidget(QDockWidget *extraDock) restoreExtraDock.restoreWidth(extraDock->widget()); } -void MainWindow::openNewFile(const QString &fn, int analLevel, QList advancedOptions) +void MainWindow::openNewFile(const QString &fn, int analLevel, QList advancedOptions, const QString &shellcode) { setFilename(fn); @@ -330,7 +330,7 @@ void MainWindow::openNewFile(const QString &fn, int analLevel, QList ad } /* Show analysis options dialog */ - displayAnalysisOptionsDialog(analLevel, advancedOptions, loadScript); + displayAnalysisOptionsDialog(analLevel, advancedOptions, loadScript, shellcode); } void MainWindow::openNewFileFailed() @@ -361,11 +361,12 @@ void MainWindow::closeNewFileDialog() newFileDialog = nullptr; } -void MainWindow::displayAnalysisOptionsDialog(int analLevel, QList advancedOptions, const QString &script) +void MainWindow::displayAnalysisOptionsDialog(int analLevel, QList advancedOptions, const QString &script, const QString &shellcode) { OptionsDialog *o = new OptionsDialog(this); o->setAttribute(Qt::WA_DeleteOnClose); o->setInitialScript(script); + o->setShellcode(shellcode); o->show(); if (analLevel >= 0) { diff --git a/src/MainWindow.h b/src/MainWindow.h index de838657..027f725f 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -68,10 +68,10 @@ public: ~MainWindow(); void openNewFile(const QString &fn, int analLevel = -1, - QList advancedOptions = QList()); + QList advancedOptions = QList(), const QString &shellcode = QString()); void displayNewFileDialog(); void closeNewFileDialog(); - void displayAnalysisOptionsDialog(int analLevel, QList advancedOptions, const QString &script); + void displayAnalysisOptionsDialog(int analLevel, QList advancedOptions, const QString &script, const QString &shellcode = QString()); void openProject(const QString &project_name); void initUI(); diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index 5ca35a5e..5c6c04bb 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -127,6 +127,22 @@ void NewFileDialog::on_loadProjectButton_clicked() loadProject(item->data(Qt::UserRole).toString()); } +void NewFileDialog::on_shellcodeButton_clicked() +{ + QString shellcode = ui->shellcodeText->toPlainText(); + QString extractedCode = ""; + static const QRegularExpression rx("([0-9a-f]{2})", QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatchIterator i = rx.globalMatch(shellcode); + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + extractedCode.append(match.captured(1)); + } + int size = extractedCode.size() / 2; + if (size > 0) { + loadShellcode(extractedCode, size); + } +} + void NewFileDialog::on_recentsListWidget_itemClicked(QListWidgetItem *item) { QVariant data = item->data(Qt::UserRole); @@ -358,6 +374,14 @@ void NewFileDialog::loadProject(const QString &project) close(); } +void NewFileDialog::loadShellcode(const QString &shellcode, const int size) +{ + MainWindow *main = new MainWindow(); + QString ioFile = QString("malloc://%1").arg(size); + main->openNewFile(ioFile, -1, QList(), shellcode); + close(); +} + void NewFileDialog::on_tabWidget_currentChanged(int index) { Config()->setNewFileLastClicked(index); diff --git a/src/dialogs/NewFileDialog.h b/src/dialogs/NewFileDialog.h index 2653863a..933bfc5e 100644 --- a/src/dialogs/NewFileDialog.h +++ b/src/dialogs/NewFileDialog.h @@ -23,6 +23,7 @@ private slots: void on_selectProjectsDirButton_clicked(); void on_loadProjectButton_clicked(); + void on_shellcodeButton_clicked(); void on_aboutButton_clicked(); @@ -58,6 +59,7 @@ private: void loadFile(const QString &filename); void loadProject(const QString &project); + void loadShellcode(const QString &shellcode, const int size); static const int MaxRecentFiles = 5; }; diff --git a/src/dialogs/NewfileDialog.ui b/src/dialogs/NewfileDialog.ui index f4d6b854..45e1bd4e 100755 --- a/src/dialogs/NewfileDialog.ui +++ b/src/dialogs/NewfileDialog.ui @@ -138,6 +138,7 @@ 0 + Open File @@ -312,6 +313,66 @@ + + + + Open Shellcode + + + + + + + + 0 + 0 + + + + <b>Paste Shellcode<b> + + + + + + + + + 1 + 1 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Open + + + + + + + + > + Projects @@ -456,6 +517,7 @@ + diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 0b28d7a3..f9918d7a 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -91,6 +91,11 @@ void OptionsDialog::setInitialScript(const QString &script) } } +void OptionsDialog::setShellcode(const QString &shellcode) +{ + this->shellcode = shellcode; +} + QString OptionsDialog::getSelectedArch() { QVariant archValue = ui->archComboBox->currentData(); @@ -199,6 +204,7 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) InitialOptions options; options.filename = main->getFilename(); + options.shellcode = this->shellcode; // Where the bin header is located in the file (-B) if (ui->entry_loadOffset->text().length() > 0) { diff --git a/src/dialogs/OptionsDialog.h b/src/dialogs/OptionsDialog.h index 95610953..c0367d36 100644 --- a/src/dialogs/OptionsDialog.h +++ b/src/dialogs/OptionsDialog.h @@ -47,11 +47,13 @@ private: int defaultAnalLevel; QString analysisDescription(int level); + QString shellcode; void updateCPUComboBox(); public: void setInitialScript(const QString &script); + void setShellcode(const QString &shellcode); QString getSelectedArch(); QString getSelectedCPU(); diff --git a/src/dialogs/R2PluginsDialog.ui b/src/dialogs/R2PluginsDialog.ui index 4ecf3b89..fdb26ade 100644 --- a/src/dialogs/R2PluginsDialog.ui +++ b/src/dialogs/R2PluginsDialog.ui @@ -13,7 +13,7 @@ radare2 plugin information - +