Use ConsoleWidget in MainWindow

- Replace the MainWidget console handling with the new custom Widget
- Rename some functions
- Fix cppcheck warnings (non reference parameters)
This commit is contained in:
ballessay 2017-04-27 01:00:20 +02:00 committed by C. Balles
parent 6731032495
commit a8418e3b53
9 changed files with 34 additions and 304 deletions

View File

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

View File

@ -37,6 +37,7 @@
#include <QLineEdit>
#include <QSettings>
#include <QList>
#include <QToolButton>
#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 <QGraphicsEllipseItem>
@ -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("<font color=\"red\"> [DEBUG]:\t" + msg + "</font>");
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);
}

View File

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

View File

@ -131,7 +131,7 @@ border-top: 0px;
<attribute name="title">
<string notr="true">Console</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<layout class="QVBoxLayout" name="tabVerticalLayout">
<property name="spacing">
<number>0</number>
</property>
@ -147,162 +147,6 @@ border-top: 0px;
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="consoleOutputTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">/*QPlainTextEdit { background: rgb(226, 230, 235) }*/</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLineEdit" name="consoleInputLineEdit">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">border-top: 1px solid rgb(255, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="placeholderText">
<string> Type &quot;?&quot; for help</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="showHistoToolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>18</height>
</size>
</property>
<property name="toolTip">
<string>Show commands history</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: white;</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="consoleExecButton">
<property name="toolTip">
<string>Execute command</string>
</property>
<property name="styleSheet">
<string notr="true">/*
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);
}</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/new/prefix1/img/icons/play.png</normaloff>:/new/prefix1/img/icons/play.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
@ -772,11 +616,6 @@ background: rgb(64, 64, 64);</string>
<string>Tabs Up/Down</string>
</property>
</action>
<action name="actionClear_ConsoleOutput">
<property name="text">
<string>Clear output</string>
</property>
</action>
<action name="actionRefresh_Panels">
<property name="icon">
<iconset resource="resources.qrc">
@ -969,14 +808,6 @@ background: rgb(64, 64, 64);</string>
<string>Syntax AT&amp;T/Intel</string>
</property>
</action>
<action name="actionConsoleSync_with_core">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Sync with core</string>
</property>
</action>
<action name="actionFunctionsRename">
<property name="text">
<string>Rename</string>

View File

@ -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();

View File

@ -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<CommentDescription>();
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);
}

View File

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

View File

@ -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)

View File

@ -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");