diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index a45aa75c..cde5fc85 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -75,6 +75,9 @@ NewFileDialog::NewFileDialog(MainWindow *main) /* Set focus on the TextInput */ ui->newFileEdit->setFocus(); + /* Install an event filter for shellcode text edit to enable ctrl+return event */ + ui->shellcodeText->installEventFilter(this); + updateLoadProjectButton(); } @@ -366,3 +369,32 @@ void NewFileDialog::on_tabWidget_currentChanged(int index) { Config()->setNewFileLastClicked(index); } + +bool NewFileDialog::eventFilter(QObject * /*obj*/, QEvent *event) +{ + QString shellcode = ui->shellcodeText->toPlainText(); + QString extractedCode = ""; + static const QRegularExpression rx("([0-9a-f]{2})", QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatchIterator i = rx.globalMatch(shellcode); + int size = 0; + + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + + // Confirm comment by pressing Ctrl/Cmd+Return + if ((keyEvent->modifiers() & Qt::ControlModifier) + && ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))) { + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + extractedCode.append(match.captured(1)); + } + size = extractedCode.size() / 2; + if (size > 0) { + loadShellcode(extractedCode, size); + } + return true; + } + } + + return false; +} diff --git a/src/dialogs/NewFileDialog.h b/src/dialogs/NewFileDialog.h index 197f0508..eb5cb542 100644 --- a/src/dialogs/NewFileDialog.h +++ b/src/dialogs/NewFileDialog.h @@ -69,6 +69,8 @@ private: void loadProject(const QString &project); void loadShellcode(const QString &shellcode, const int size); + bool eventFilter(QObject *obj, QEvent *event); + static const int MaxRecentFiles = 5; };