diff --git a/src/iaito.pro b/src/iaito.pro index 26640508..82a8cc6f 100644 --- a/src/iaito.pro +++ b/src/iaito.pro @@ -61,7 +61,8 @@ SOURCES += \ widgets/dashboard.cpp \ dialogs/xrefsdialog.cpp \ hexhighlighter.cpp \ - widgets/sectionsdock.cpp + widgets/sectionsdock.cpp \ + widgets/consolewidget.cpp HEADERS += \ mainwindow.h \ @@ -98,7 +99,8 @@ HEADERS += \ dialogs/xrefsdialog.h \ hexhighlighter.h \ widgets/sectionsdock.h \ - widgets/dockwidget.h + widgets/dockwidget.h \ + widgets/consolewidget.h FORMS += \ mainwindow.ui \ @@ -121,7 +123,8 @@ FORMS += \ widgets/sidebar.ui \ widgets/dashboard.ui \ dialogs/xrefsdialog.ui \ - widgets/sectionsdock.ui + widgets/sectionsdock.ui \ + widgets/consolewidget.ui RESOURCES += \ resources.qrc diff --git a/src/widgets/consolewidget.cpp b/src/widgets/consolewidget.cpp new file mode 100644 index 00000000..5b19144a --- /dev/null +++ b/src/widgets/consolewidget.cpp @@ -0,0 +1,189 @@ +#include "consolewidget.h" +#include "ui_consolewidget.h" + +#include "helpers.h" +#include "qrcore.h" + +#include +#include +#include +//TODO: delete +#include + + +// TODO: Find a way to get to this without copying it here +// source: libr/core/core.c:585.. +#define CMDS (sizeof (radare_argv)/sizeof(const char*)) +static const char *radare_argv[] = { + "?", "?v", "whereis", "which", "ls", "rm", "mkdir", "pwd", "cat", "less", + "dH", "ds", "dso", "dsl", "dc", "dd", "dm", "db ", "db-", + "dp", "dr", "dcu", "dmd", "dmp", "dml", + "ec","ecs", "eco", + "S", "S.", "S*", "S-", "S=", "Sa", "Sa-", "Sd", "Sl", "SSj", "Sr", + "s", "s+", "s++", "s-", "s--", "s*", "sa", "sb", "sr", + "!", "!!", + "#sha1", "#crc32", "#pcprint", "#sha256", "#sha512", "#md4", "#md5", + "#!python", "#!perl", "#!vala", + "V", "v", + "aa", "ab", "af", "ar", "ag", "at", "a?", "ax", "ad", + "ae", "aec", "aex", "aep", "aea", "aeA", "aes", "aeso", "aesu", "aesue", "aer", "aei", "aeim", "aef", + "aaa", "aac","aae", "aai", "aar", "aan", "aas", "aat", "aap", "aav", + "af", "afa", "afan", "afc", "afC", "afi", "afb", "afbb", "afn", "afr", "afs", "af*", "afv", "afvn", + "aga", "agc", "agd", "agl", "agfl", + "e", "et", "e-", "e*", "e!", "e?", "env ", + "i", "ii", "iI", "is", "iS", "iz", + "q", "q!", + "f", "fl", "fr", "f-", "f*", "fs", "fS", "fr", "fo", "f?", + "m", "m*", "ml", "m-", "my", "mg", "md", "mp", "m?", + "o", "o+", "oc", "on", "op", "o-", "x", "wf", "wF", "wta", "wtf", "wp", + "t", "to", "t-", "tf", "td", "td-", "tb", "tn", "te", "tl", "tk", "ts", "tu", + "(", "(*", "(-", "()", ".", ".!", ".(", "./", + "r", "r+", "r-", + "b", "bf", "b?", + "/", "//", "/a", "/c", "/h", "/m", "/x", "/v", "/v2", "/v4", "/v8", "/r", "/re", + "y", "yy", "y?", + "wx", "ww", "w?", "wxf", + "p6d", "p6e", "p8", "pb", "pc", + "pd", "pda", "pdb", "pdc", "pdj", "pdr", "pdf", "pdi", "pdl", "pds", "pdt", + "pD", "px", "pX", "po", "pf", "pf.", "pf*", "pf*.", "pfd", "pfd.", "pv", "p=", "p-", + "pfj", "pfj.", "pfv", "pfv.", + "pm", "pr", "pt", "ptd", "ptn", "pt?", "ps", "pz", "pu", "pU", "p?", + "z", "z*", "zj", "z-", "z-*", + "za", "zaf", "zaF", + "zo", "zoz", "zos", + "zfd", "zfs", "zfz", + "z/", "z/*", + "zc", + "zs", "zs+", "zs-", "zs-*", "zsr", + "#!pipe", + NULL +}; + + +ConsoleWidget::ConsoleWidget(QRCore *core, QWidget *parent) : + QWidget(parent), + ui(new Ui::ConsoleWidget), + core(core) +{ + ui->setupUi(this); + + // 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); + + // Fix output panel font + qhelpers::normalizeFont(ui->consoleOutputTextEdit); + + // Set console output context menu + ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->consoleOutputTextEdit, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(showConsoleContextMenu(const QPoint &))); +} + +ConsoleWidget::~ConsoleWidget() +{ + delete ui; +} + +void ConsoleWidget::addOutput(const QString &msg) +{ + ui->consoleOutputTextEdit->appendPlainText(msg); + ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum()); +} + +void ConsoleWidget::addDebugOutput(const QString &msg) +{ + ui->consoleOutputTextEdit->appendHtml(" [DEBUG]:\t" + msg + ""); + ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum()); +} + +void ConsoleWidget::focusInputLineEdit() +{ + ui->consoleInputLineEdit->setFocus(); +} + +void ConsoleWidget::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 ConsoleWidget::on_consoleExecButton_clicked() +{ + on_consoleInputLineEdit_returnPressed(); +} + +void ConsoleWidget::showConsoleContextMenu(const QPoint &pt) +{ + // Set console output popup menu + QMenu *menu = ui->consoleOutputTextEdit->createStandardContextMenu(); + menu->clear(); +// TODO: +// 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 ConsoleWidget::on_actionConsoleSync_with_core_triggered() +{ +// TODO: +// if (ui->actionConsoleSync_with_core->isChecked()) +// { +// //Enable core syncronization +// } +// else +// { +// // Disable core sync +// } +} + +void ConsoleWidget::on_actionClear_ConsoleOutput_triggered() +{ + ui->consoleOutputTextEdit->clear(); +} + + +void ConsoleWidget::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); + } +} diff --git a/src/widgets/consolewidget.h b/src/widgets/consolewidget.h new file mode 100644 index 00000000..edfd5075 --- /dev/null +++ b/src/widgets/consolewidget.h @@ -0,0 +1,44 @@ +#ifndef CONSOLEWIDGET_H +#define CONSOLEWIDGET_H + +#include + +class QRCore; + +namespace Ui +{ + class ConsoleWidget; +} + +class ConsoleWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ConsoleWidget(QRCore *core, QWidget *parent = 0); + ~ConsoleWidget(); + + void addOutput(const QString &msg); + void addDebugOutput(const QString &msg); + +public slots: + void focusInputLineEdit(); + +private slots: + void on_consoleInputLineEdit_returnPressed(); + + void on_consoleExecButton_clicked(); + + void showConsoleContextMenu(const QPoint &pt); + + void on_actionClear_ConsoleOutput_triggered(); + void on_actionConsoleSync_with_core_triggered(); + + void on_showHistoToolButton_clicked(); + +private: + Ui::ConsoleWidget *ui; + QRCore *core; +}; + +#endif // CONSOLEWIDGET_H diff --git a/src/widgets/consolewidget.ui b/src/widgets/consolewidget.ui new file mode 100644 index 00000000..458cbcb7 --- /dev/null +++ b/src/widgets/consolewidget.ui @@ -0,0 +1,194 @@ + + + ConsoleWidget + + + + 0 + 0 + 583 + 534 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 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 + + + + + + + + + + + +