diff --git a/src/createnewdialog.cpp b/src/createnewdialog.cpp index 9d86301c..b19790df 100644 --- a/src/createnewdialog.cpp +++ b/src/createnewdialog.cpp @@ -230,7 +230,7 @@ void createNewDialog::on_buttonCreate_clicked() w->core->seek(0); w->updateFrames(); w->setFilename("-"); - w->add_output("Finished, check its contents"); + w->addOutput("Finished, check its contents"); w->showMaximized(); } else diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cd01b097..5dc52848 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "highlighter.h" #include "hexascii_highlighter.h" @@ -59,6 +60,7 @@ #include "widgets/sidebar.h" #include "widgets/sdbdock.h" #include "widgets/omnibar.h" +#include "widgets/consolewidget.h" // graphics #include @@ -104,6 +106,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : sdbDock(nullptr), sidebar_action(nullptr), sectionsDock(nullptr), + consoleWidget(nullptr), webserverThread(core, this) { this->start_web_server(); @@ -121,17 +124,8 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : // Hide central tab widget tabs QTabBar *centralbar = ui->centralTabWidget->tabBar(); centralbar->setVisible(false); - // Adjust console lineedit - ui->consoleInputLineEdit->setTextMargins(10, 0, 0, 0); - /* - ui->consoleOutputTextEdit->setFont(QFont("Monospace", 8)); - ui->consoleOutputTextEdit->setStyleSheet("background-color:black;color:gray;"); - ui->consoleInputLineEdit->setStyleSheet("background-color:black;color:gray;"); - */ - - // Adjust text margins of consoleOutputTextEdit - QTextDocument *console_docu = ui->consoleOutputTextEdit->document(); - console_docu->setDocumentMargin(10); + consoleWidget = new ConsoleWidget(core, this); + ui->tabVerticalLayout->addWidget(consoleWidget); // Sepparator between back/forward and undo/redo buttons QWidget *spacer4 = new QWidget(); @@ -176,9 +170,6 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : addToolBarBreak(Qt::TopToolBarArea); addToolBar(graphicsBar); - // Fix output panel font - qhelpers::normalizeFont(ui->consoleOutputTextEdit); - /* * Dock Widgets */ @@ -247,11 +238,6 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); //setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea ); - // Set console output context menu - ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->consoleOutputTextEdit, SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(showConsoleContextMenu(const QPoint &))); - // Setup and hide sidebar by default this->sideBar = new SideBar(this); this->sidebar_action = ui->sideToolBar->addWidget(this->sideBar); @@ -266,7 +252,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : */ // Period goes to command entry QShortcut *cmd_shortcut = new QShortcut(QKeySequence(Qt::Key_Period), this); - connect(cmd_shortcut, SIGNAL(activated()), ui->consoleInputLineEdit, SLOT(setFocus())); + connect(cmd_shortcut, SIGNAL(activated()), consoleWidget, SLOT(focusInputLineEdit())); // G and S goes to goto entry QShortcut *goto_shortcut = new QShortcut(QKeySequence(Qt::Key_G), this); @@ -345,20 +331,6 @@ void MainWindow::setFilename(const QString &fn) this->setWindowTitle("Iaito - " + fn); } -void MainWindow::showConsoleContextMenu(const QPoint &pt) -{ - // Set console output popup menu - QMenu *menu = ui->consoleOutputTextEdit->createStandardContextMenu(); - menu->clear(); - menu->addAction(ui->actionClear_ConsoleOutput); - menu->addAction(ui->actionConsoleSync_with_core); - ui->actionConsoleSync_with_core->setChecked(true); - ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu); - - menu->exec(ui->consoleOutputTextEdit->mapToGlobal(pt)); - delete menu; -} - void MainWindow::closeEvent(QCloseEvent *event) { QMessageBox::StandardButton ret = QMessageBox::question(this, "Iaito", @@ -673,49 +645,6 @@ void MainWindow::on_actionAbout_triggered() a->open(); } -void MainWindow::on_consoleInputLineEdit_returnPressed() -{ - if (this->core) - { - QString input = ui->consoleInputLineEdit->text(); - ui->consoleOutputTextEdit->appendPlainText(this->core->cmd(input)); - ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum()); - // Add new command to history - QCompleter *completer = ui->consoleInputLineEdit->completer(); - if (completer != NULL) - { - QStringListModel *completerModel = (QStringListModel *)(completer->model()); - if (completerModel != NULL) - completerModel->setStringList(completerModel->stringList() << input); - } - - ui->consoleInputLineEdit->setText(""); - } -} - -void MainWindow::on_showHistoToolButton_clicked() -{ - QCompleter *completer = ui->consoleInputLineEdit->completer(); - if (completer == NULL) - return; - - if (ui->showHistoToolButton->isChecked()) - { - completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); - // Uhm... shouldn't it be called always? - completer->complete(); - } - else - { - completer->setCompletionMode(QCompleter::PopupCompletion); - } -} - -void MainWindow::on_actionClear_ConsoleOutput_triggered() -{ - ui->consoleOutputTextEdit->setPlainText(""); -} - void MainWindow::on_actionRefresh_Panels_triggered() { this->updateFrames(); @@ -740,7 +669,6 @@ void MainWindow::seek(const QString &offset, const QString &name, bool raise_mem void MainWindow::seek(const RVA offset, const QString &name, bool raise_memory_dock) { - if (name != NULL) { this->memoryDock->setWindowTitle(name); //this->current_address = name; @@ -809,28 +737,11 @@ void MainWindow::on_actionAssembler_triggered() } } -void MainWindow::on_consoleExecButton_clicked() -{ - on_consoleInputLineEdit_returnPressed(); -} - void MainWindow::on_actionStart_Web_Server_triggered() { setWebServerState(ui->actionStart_Web_Server->isChecked()); } -void MainWindow::on_actionConsoleSync_with_core_triggered() -{ - if (ui->actionConsoleSync_with_core->isChecked()) - { - //Enable core syncronization - } - else - { - // Disable core sync - } -} - void MainWindow::on_actionDisasAdd_comment_triggered() { CommentsDialog *c = new CommentsDialog(this); @@ -905,7 +816,7 @@ void MainWindow::on_actionhide_bottomPannel_triggered() } } -void MainWindow::send_to_notepad(const QString &txt) +void MainWindow::sendToNotepad(const QString &txt) { this->notepadDock->appendPlainText("```\n" + txt + "\n```"); } @@ -923,17 +834,15 @@ void MainWindow::get_refs(const QString &offset) this->memoryDock->get_refs_data(offset); } -void MainWindow::add_output(QString msg) +void MainWindow::addOutput(const QString &msg) { - ui->consoleOutputTextEdit->appendPlainText(msg); - ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum()); + consoleWidget->addOutput(msg); } -void MainWindow::add_debug_output(QString msg) +void MainWindow::addDebugOutput(const QString &msg) { printf("debug output: %s\n", msg.toLocal8Bit().constData()); - ui->consoleOutputTextEdit->appendHtml(" [DEBUG]:\t" + msg + ""); - ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum()); + consoleWidget->addDebugOutput(msg); } void MainWindow::on_actionNew_triggered() @@ -948,7 +857,7 @@ void MainWindow::on_actionSave_triggered() QString notes = this->notepadDock->textToBase64(); //this->add_debug_output(notes); this->core->cmd("Pnj " + notes); - this->add_output("Project saved"); + this->addOutput("Project saved"); } void MainWindow::on_actionRun_Script_triggered() @@ -1022,7 +931,7 @@ void MainWindow::on_actionForward_triggered() { this->core->cmd("s+"); RVA offset = core->getOffset(); - this->add_debug_output(QString::number(offset)); + this->addDebugOutput(QString::number(offset)); this->seek(offset); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 390a917d..1713db3b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,7 @@ class QLineEdit; class SdbDock; class QAction; class SectionsDock; +class ConsoleWidget; class QDockWidget; @@ -62,9 +63,9 @@ public: void refreshFunctions(); void refreshComments(); void get_refs(const QString &offset); - void add_output(QString msg); - void add_debug_output(QString msg); - void send_to_notepad(const QString &txt); + void addOutput(const QString &msg); + void addDebugOutput(const QString &msg); + void sendToNotepad(const QString &txt); void setWebServerState(bool start); void raiseMemoryDock(); void toggleSideBarTheme(); @@ -123,14 +124,6 @@ private slots: void on_actionAbout_triggered(); - void on_consoleInputLineEdit_returnPressed(); - - void on_showHistoToolButton_clicked(); - - void showConsoleContextMenu(const QPoint &pt); - - void on_actionClear_ConsoleOutput_triggered(); - void on_actionRefresh_Panels_triggered(); void on_actionCalculator_triggered(); @@ -139,12 +132,8 @@ private slots: void on_actionAssembler_triggered(); - void on_consoleExecButton_clicked(); - void on_actionStart_Web_Server_triggered(); - void on_actionConsoleSync_with_core_triggered(); - void on_actionDisasAdd_comment_triggered(); void restoreDocks(); @@ -210,6 +199,7 @@ private: SdbDock *sdbDock; QAction *sidebar_action; SectionsDock *sectionsDock; + ConsoleWidget *consoleWidget; WebServerThread webserverThread; RVA cursor_address; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index c12f527a..d5f2a1e2 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -131,7 +131,7 @@ border-top: 0px; Console - + 0 @@ -147,162 +147,6 @@ border-top: 0px; 0 - - - - - 0 - 0 - - - - - Monaco - 11 - - - - /*QPlainTextEdit { background: rgb(226, 230, 235) }*/ - - - QFrame::NoFrame - - - 0 - - - false - - - true - - - - - - - - - - 0 - - - 5 - - - 3 - - - 5 - - - 3 - - - - - - 12 - - - - border-top: 1px solid rgb(255, 255, 255); - - - - - - false - - - Type "?" for help - - - true - - - - - - - false - - - - 16777215 - 18 - - - - Show commands history - - - background-color: white; - - - ... - - - true - - - true - - - Qt::DownArrow - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - Execute command - - - /* -border: none; -padding: 2px; -*/ - -QToolButton { /* all types of tool button */ - border: 0px solid rgb(255, 255, 255); - border-radius: 6px; - border-top: 2px solid rgb(255, 255, 255); - border-bottom: 2px solid rgb(255, 255, 255); - border-left: 8px solid rgb(255, 255, 255); - border-right: 5px solid rgb(255, 255, 255); - margin-bottom: 1px; - margin-top: 1px; - background-color: rgb(255, 255, 255); -} - - - ... - - - - :/new/prefix1/img/icons/play.png:/new/prefix1/img/icons/play.png - - - - - @@ -772,11 +616,6 @@ background: rgb(64, 64, 64); Tabs Up/Down - - - Clear output - - @@ -969,14 +808,6 @@ background: rgb(64, 64, 64); Syntax AT&T/Intel - - - true - - - Sync with core - - Rename diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 135e4755..60c8f27d 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -188,7 +188,7 @@ void OptionsDialog::setupAndStartAnalysis(int level) // options dialog should show the list of archs inside the given fatbin int binidx = 0; // index of subbin - this->w->add_output(" > Loading file: " + this->filename); + this->w->addOutput(" > Loading file: " + this->filename); this->w->core->loadFile(this->filename, loadaddr, mapaddr, rw, va, bits, binidx, load_bininfo); //ui->progressBar->setValue(40); ui->statusLabel->setText("Analysis in progress"); @@ -223,7 +223,7 @@ void OptionsDialog::anal_finished() // Set settings to override any incorrect saved in the project this->core->setSettings(); ui->statusLabel->setText("Loading interface"); - this->w->add_output(" > Analysis finished"); + this->w->addOutput(" > Analysis finished"); QString initial_seek = ui->entry_initialSeek->text(); if (initial_seek.length() > 0) { @@ -233,7 +233,7 @@ void OptionsDialog::anal_finished() { this->w->core->seek("entry0"); } - this->w->add_output(" > Populating UI"); + this->w->addOutput(" > Populating UI"); // FIXME: initialization order frakup. the next line is needed so that the // comments widget displays the function names. core->cmd("fs sections"); @@ -256,9 +256,9 @@ void OptionsDialog::anal_finished() this->core->binStart = this->core->cmd("?v $M"); this->core->binEnd = this->core->cmd("?v $M+$s"); - this->w->add_output(" > Finished, happy reversing :)"); + this->w->addOutput(" > Finished, happy reversing :)"); // Add fortune message - this->w->add_output("\n" + this->w->core->cmd("fo")); + this->w->addOutput("\n" + this->w->core->cmd("fo")); this->w->memoryDock->setWindowTitle("entry0"); this->w->start_web_server(); close(); diff --git a/src/widgets/commentswidget.cpp b/src/widgets/commentswidget.cpp index a9185131..9b4cfea7 100644 --- a/src/widgets/commentswidget.cpp +++ b/src/widgets/commentswidget.cpp @@ -53,7 +53,7 @@ void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *it // Get offset and name of item double clicked CommentDescription comment = item->data(0, Qt::UserRole).value(); - this->main->add_debug_output(RAddressString(comment.offset) + ": " + comment.name); + this->main->addDebugOutput(RAddressString(comment.offset) + ": " + comment.name); this->main->seek(comment.offset, comment.name, true); } diff --git a/src/widgets/functionswidget.cpp b/src/widgets/functionswidget.cpp index cd53aa52..3a3b22f7 100644 --- a/src/widgets/functionswidget.cpp +++ b/src/widgets/functionswidget.cpp @@ -447,7 +447,7 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered() { // Get new function name QString comment = c->getComment(); - this->main->add_debug_output("Comment: " + comment + " at: " + function.name); + this->main->addDebugOutput("Comment: " + comment + " at: " + function.name); // Rename function in r2 core this->main->core->setComment(function.offset, comment); // Seek to new renamed function diff --git a/src/widgets/memorywidget.cpp b/src/widgets/memorywidget.cpp index fbd7d00d..d386b1a6 100644 --- a/src/widgets/memorywidget.cpp +++ b/src/widgets/memorywidget.cpp @@ -474,7 +474,7 @@ void MemoryWidget::disasmScrolled() tc.movePosition(QTextCursor::End); tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); - this->main->add_debug_output("Last line: " + lastline); + this->main->addDebugOutput("Last line: " + lastline); } // Code below will be used to append more disasm upwards, one day } /* else if (sb->value() < sb->minimum() + 10) { @@ -739,7 +739,7 @@ void MemoryWidget::hexScrolled() if (sb->value() > sb->maximum() - 10) { - this->main->add_debug_output("End is coming"); + this->main->addDebugOutput("End is coming"); QTextCursor tc = this->hexOffsetText->textCursor(); tc.movePosition(QTextCursor::End); @@ -1230,7 +1230,7 @@ void MemoryWidget::on_actionSend_to_Notepad_triggered() { QTextCursor cursor = ui->disasTextEdit_2->textCursor(); QString text = cursor.selectedText(); - this->main->send_to_notepad(text); + this->main->sendToNotepad(text); } void MemoryWidget::on_actionDisasAdd_comment_triggered() @@ -1548,7 +1548,7 @@ void MemoryWidget::fillOffsetInfo(QString off) void MemoryWidget::create_graph(QString off) { ui->graphWebView->setZoomFactor(0.85); - this->main->add_debug_output("Graph Offset: '" + off + "'"); + this->main->addDebugOutput("Graph Offset: '" + off + "'"); if (off == "") { off = "0x0" + this->main->core->cmd("s").split("0x")[1].trimmed(); @@ -1914,7 +1914,7 @@ void MemoryWidget::on_copyMD5_clicked() QString md5 = ui->bytesMD5->text(); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(md5); - this->main->add_output("MD5 copied to clipboard: " + md5); + this->main->addOutput("MD5 copied to clipboard: " + md5); } void MemoryWidget::on_copySHA1_clicked() @@ -1922,7 +1922,7 @@ void MemoryWidget::on_copySHA1_clicked() QString sha1 = ui->bytesSHA1->text(); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(sha1); - this->main->add_output("SHA1 copied to clipboard: " + sha1); + this->main->addOutput("SHA1 copied to clipboard: " + sha1); } void MemoryWidget::switchTheme(bool dark) diff --git a/src/widgets/notepad.cpp b/src/widgets/notepad.cpp index 976316be..c4d27f83 100644 --- a/src/widgets/notepad.cpp +++ b/src/widgets/notepad.cpp @@ -49,7 +49,7 @@ Notepad::~Notepad() void Notepad::setup() { - main->add_output(" > Adding binary information to notepad"); + main->addOutput(" > Adding binary information to notepad"); setText("# Binary information\n\n" + main->core->cmd("i") + "\n" + main->core->cmd("ie") + "\n" + main->core->cmd("iM") + "\n");