Added support for ctrl+Enter submission in open shellcode tab (#2851)

* Added support for ctrl+Enter submission in shellcode tab in the new file dialog
This commit is contained in:
nirkog 2022-01-08 13:07:20 +02:00 committed by Anton Kochkov
parent 98411b4dbf
commit 138078a6f4
2 changed files with 34 additions and 0 deletions

View File

@ -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<QKeyEvent *>(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;
}

View File

@ -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;
};