diff --git a/.gitignore b/.gitignore index 5b3fe0fd..d12191ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # The final executable after `make clean` iaito +AStyle* # C++ objects and libs diff --git a/README.md b/README.md index 74d4dd15..caae69ed 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,16 @@ Iaitō is not aimed at existing radare2 users, it is focused on those whose are Yes, the code sucks. Hopefully we will be able to remove this statement from the README one day, but I had never coded Qt nor C++ until I started Iaitō, so obviously the code is ugly and not well designed. +### Code formatting + +We use [AStyle 2.06](https://sourceforge.net/projects/astyle/files/astyle/astyle%202.06/) to format the code. The command line for formatting the code according to the style is: + +```bash +AStyle --style=allman --convert-tabs --align-pointer=name --align-reference=name --indent=spaces --indent-namespaces --indent-col1-comments --pad-oper --pad-header --unpad-paren --keep-one-line-blocks --close-templates $(git ls-files *.cpp *.h *.c *.hpp) +``` + +**If in doubt, check the source around you and follow that style!** + ## Requirements - **Radare2**: Make sure that, when cloning the project, you use `git clone --recurse-submodules` or run `git submodule init` and `git submodule update` to clone the correct radare2 version. Then execute the following command in the radare2 folder: diff --git a/src/analthread.cpp b/src/analthread.cpp index 1e3eb4c3..517e9020 100644 --- a/src/analthread.cpp +++ b/src/analthread.cpp @@ -11,7 +11,8 @@ AnalThread::AnalThread(QWidget *parent) : AnalThread::~AnalThread() { - if (isRunning()) { + if (isRunning()) + { quit(); wait(); } diff --git a/src/analthread.h b/src/analthread.h index 1c52d924..3b5f5e41 100644 --- a/src/analthread.h +++ b/src/analthread.h @@ -7,7 +7,7 @@ class QRCore; class AnalThread : public QThread { - Q_OBJECT + Q_OBJECT public: explicit AnalThread(QWidget *parent = 0); ~AnalThread(); diff --git a/src/createnewdialog.cpp b/src/createnewdialog.cpp index 64b1cf4a..9d86301c 100644 --- a/src/createnewdialog.cpp +++ b/src/createnewdialog.cpp @@ -22,7 +22,7 @@ void createNewDialog::on_pushButton_2_clicked() { // Close dialog and open OptionsDialog close(); - NewFileDialog* n = new NewFileDialog(nullptr); + NewFileDialog *n = new NewFileDialog(nullptr); n->show(); } @@ -35,25 +35,37 @@ void createNewDialog::on_exampleButton_clicked() { QString type = ui->comboType->currentText(); QString str; - if (type == "Assembler") { + if (type == "Assembler") + { str = "; Sample program code\nmov eax, 1\nint 0x80"; - } else if (type == "Text") { + } + else if (type == "Text") + { str = "Hello World"; - } else if (type == "Rapatch") { + } + else if (type == "Rapatch") + { str = "; Sample rapatch script\n" - "0x0 \"Hello World\n" - "0x10 909090"; - } else if (type == "C Code") { + "0x0 \"Hello World\n" + "0x10 909090"; + } + else if (type == "C Code") + { str = "int main() {\n" - " write (1, \"Hello World\", 12);\n" - " exit (0);\n" - "}"; - } else if (type == "Radare2 script") { + " write (1, \"Hello World\", 12);\n" + " exit (0);\n" + "}"; + } + else if (type == "Radare2 script") + { str = "w Hello\ns+5\nw World"; - } else if (type == "Hexpairs") { + } + else if (type == "Hexpairs") + { str = "48656c6c6f20576f726c6400"; - } else fprintf (stderr, "Unknown combo value selected"); - if (str.length()>0) + } + else fprintf(stderr, "Unknown combo value selected"); + if (str.length() > 0) ui->plainTextEdit->setPlainText(str); // } } @@ -66,105 +78,151 @@ void createNewDialog::on_buttonCreate_clicked() bool created = false; QString arch = ui->comboArch->currentText(); - int fsize = r_num_math (NULL, ui->entrySize->text().toUtf8().constData()); + int fsize = r_num_math(NULL, ui->entrySize->text().toUtf8().constData()); QString format = ui->comboFormat->currentText(); - if (type == "Assembler") { - RAsmCode *code = r_asm_massemble (lcore->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData()); - if (code && code->len>0) { + if (type == "Assembler") + { + RAsmCode *code = r_asm_massemble(lcore->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData()); + if (code && code->len > 0) + { char file[32]; - snprintf (file, sizeof(file)-1, "malloc://%d", code->len); - if (w->core->loadFile(file,0,0,1,0,0,false)) { + snprintf(file, sizeof(file) - 1, "malloc://%d", code->len); + if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + { created = true; - r_core_write_at(lcore,0, code->buf, code->len); - } else { - __alert ("Failed to create file"); + r_core_write_at(lcore, 0, code->buf, code->len); + } + else + { + __alert("Failed to create file"); } - } else { - __alert ("Invalid assembler code"); } - r_asm_code_free (code); - } else if (type == "Rapatch") { - if (fsize>0) { + else + { + __alert("Invalid assembler code"); + } + r_asm_code_free(code); + } + else if (type == "Rapatch") + { + if (fsize > 0) + { char file[32]; created = true; - snprintf (file, sizeof(file)-1, "malloc://%d", fsize); - if (w->core->loadFile(file,0,0,1,0,0,false)) { - r_core_patch (lcore, ui->plainTextEdit->toPlainText().toUtf8().constData()); + snprintf(file, sizeof(file) - 1, "malloc://%d", fsize); + if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + { + r_core_patch(lcore, ui->plainTextEdit->toPlainText().toUtf8().constData()); r_core_seek(lcore, 0, 1); created = true; - } else { - __alert ("failed to open file"); } - } else { - __alert ("Invalid file size"); + else + { + __alert("failed to open file"); + } } - } else if (type == "C Code") { + else + { + __alert("Invalid file size"); + } + } + else if (type == "C Code") + { __alert("C Code: TODO"); // ragg2-cc -x - } else if (type == "Radare2 script") { - if (fsize>0) { + } + else if (type == "Radare2 script") + { + if (fsize > 0) + { char file[32]; created = true; - snprintf (file, sizeof(file)-1, "malloc://%d", fsize); - if (w->core->loadFile(file,0,0,1,0,0,false)) { + snprintf(file, sizeof(file) - 1, "malloc://%d", fsize); + if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + { created = true; QString str = ui->plainTextEdit->toPlainText(); QList lines = str.split("\n"); - foreach (QString str, lines) { + foreach (QString str, lines) + { w->core->cmd(str); } - } else { - __alert ("failed to open file"); } - } else { - __alert ("Invalid file size"); + else + { + __alert("failed to open file"); + } } - } else if (type == "Text") { + else + { + __alert("Invalid file size"); + } + } + else if (type == "Text") + { char file[32]; QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8(); - int sz = strlen (hexpairs.constData()); - if (sz>0) { - snprintf (file, sizeof(file)-1, "malloc://%d", sz); - if (w->core->loadFile(file,0,0,1,0,0,false)) { + int sz = strlen(hexpairs.constData()); + if (sz > 0) + { + snprintf(file, sizeof(file) - 1, "malloc://%d", sz); + if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + { created = true; - r_core_write_at(lcore,0, (const ut8*)hexpairs.constData(), sz); - } else { - __alert ("failed to open file"); + r_core_write_at(lcore, 0, (const ut8 *)hexpairs.constData(), sz); + } + else + { + __alert("failed to open file"); } - } else { - __alert ("Empty string?"); } - } else if (type == "Hexpairs") { + else + { + __alert("Empty string?"); + } + } + else if (type == "Hexpairs") + { char file[32]; int sz; QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8(); - ut8 *buf = (ut8*)malloc (strlen (hexpairs.constData()) + 1); - sz = r_hex_str2bin (hexpairs.constData(), buf); - if (sz>0) { - snprintf (file, sizeof(file)-1, "malloc://%d", sz); - if (w->core->loadFile(file,0,0,1,0,0,false)) { + ut8 *buf = (ut8 *)malloc(strlen(hexpairs.constData()) + 1); + sz = r_hex_str2bin(hexpairs.constData(), buf); + if (sz > 0) + { + snprintf(file, sizeof(file) - 1, "malloc://%d", sz); + if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + { created = true; - r_core_write_at(lcore,0, buf, sz); - } else { - __alert ("failed to open file"); + r_core_write_at(lcore, 0, buf, sz); + } + else + { + __alert("failed to open file"); } - } else { - __alert ("Invalid hexpair string"); } - free (buf); - } else { - __alert ("Unknown combo value selected"); + else + { + __alert("Invalid hexpair string"); + } + free(buf); + } + else + { + __alert("Unknown combo value selected"); return; } - if (format != "Raw") { - __alert ("TODO: non-raw fileformat is not yet supported"); + if (format != "Raw") + { + __alert("TODO: non-raw fileformat is not yet supported"); created = false; delete w->core; } - if (created) { + if (created) + { // Close dialog and open OptionsDialog close(); @@ -174,8 +232,10 @@ void createNewDialog::on_buttonCreate_clicked() w->setFilename("-"); w->add_output("Finished, check its contents"); w->showMaximized(); - } else { - __alert ("No file created."); + } + else + { + __alert("No file created."); } } diff --git a/src/createnewdialog.h b/src/createnewdialog.h index c5b6bec3..e01890ec 100644 --- a/src/createnewdialog.h +++ b/src/createnewdialog.h @@ -4,8 +4,9 @@ #include #include "mainwindow.h" -namespace Ui { -class createNewDialog; +namespace Ui +{ + class createNewDialog; } class createNewDialog : public QDialog @@ -27,7 +28,7 @@ private slots: private: Ui::createNewDialog *ui; - MainWindow* w; + MainWindow *w; }; #endif // CREATENEWDIALOG_H diff --git a/src/dialogs/aboutdialog.h b/src/dialogs/aboutdialog.h index 7c23bd44..8bf0eaa5 100644 --- a/src/dialogs/aboutdialog.h +++ b/src/dialogs/aboutdialog.h @@ -3,8 +3,9 @@ #include -namespace Ui { -class AboutDialog; +namespace Ui +{ + class AboutDialog; } class AboutDialog : public QDialog diff --git a/src/dialogs/commentsdialog.cpp b/src/dialogs/commentsdialog.cpp index c0faf2c1..f61f737d 100644 --- a/src/dialogs/commentsdialog.cpp +++ b/src/dialogs/commentsdialog.cpp @@ -24,7 +24,8 @@ void CommentsDialog::on_buttonBox_rejected() close(); } -QString CommentsDialog::getComment() { +QString CommentsDialog::getComment() +{ QString ret = ui->lineEdit->text(); return ret; } diff --git a/src/dialogs/commentsdialog.h b/src/dialogs/commentsdialog.h index 893463b2..5029d534 100644 --- a/src/dialogs/commentsdialog.h +++ b/src/dialogs/commentsdialog.h @@ -3,8 +3,9 @@ #include -namespace Ui { -class CommentsDialog; +namespace Ui +{ + class CommentsDialog; } class CommentsDialog : public QDialog diff --git a/src/dialogs/renamedialog.h b/src/dialogs/renamedialog.h index 7663466f..a8528c2a 100644 --- a/src/dialogs/renamedialog.h +++ b/src/dialogs/renamedialog.h @@ -3,8 +3,9 @@ #include -namespace Ui { -class RenameDialog; +namespace Ui +{ + class RenameDialog; } class RenameDialog : public QDialog diff --git a/src/dialogs/xrefsdialog.cpp b/src/dialogs/xrefsdialog.cpp index 3689397f..8815ab57 100644 --- a/src/dialogs/xrefsdialog.cpp +++ b/src/dialogs/xrefsdialog.cpp @@ -27,9 +27,11 @@ XrefsDialog::~XrefsDialog() delete ui; } -void XrefsDialog::fillRefs(QList refs, QList xrefs) { +void XrefsDialog::fillRefs(QList refs, QList xrefs) +{ ui->fromTreeWidget->clear(); - for (int i = 0; i < refs.size(); ++i) { + for (int i = 0; i < refs.size(); ++i) + { //this->add_debug_output(refs.at(i).at(0) + " " + refs.at(i).at(1)); QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, refs.at(i).at(0)); @@ -40,12 +42,14 @@ void XrefsDialog::fillRefs(QList refs, QList xrefs) { } // Adjust columns to content int count = ui->fromTreeWidget->columnCount(); - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { ui->fromTreeWidget->resizeColumnToContents(i); } ui->toTreeWidget->clear(); - for (int i = 0; i < xrefs.size(); ++i) { + for (int i = 0; i < xrefs.size(); ++i) + { //this->add_debug_output(xrefs.at(i).at(0) + " " + xrefs.at(i).at(1)); QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, xrefs.at(i).at(0)); @@ -56,7 +60,8 @@ void XrefsDialog::fillRefs(QList refs, QList xrefs) { } // Adjust columns to content int count2 = ui->toTreeWidget->columnCount(); - for (int i = 0; i != count2; ++i) { + for (int i = 0; i != count2; ++i) + { ui->toTreeWidget->resizeColumnToContents(i); } @@ -84,24 +89,30 @@ void XrefsDialog::on_toTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int c this->close(); } -QString XrefsDialog::normalizeAddr(QString addr) { +QString XrefsDialog::normalizeAddr(QString addr) +{ QString base = addr.split("0x")[1].trimmed(); int len = base.length(); - if (len < 8) { + if (len < 8) + { int padding = 8 - len; QString zero = "0"; QString zeroes = zero.repeated(padding); QString s = "0x" + zeroes + base; return s; - } else { + } + else + { return addr; } } -void XrefsDialog::highlightCurrentLine() { +void XrefsDialog::highlightCurrentLine() +{ QList extraSelections; - if (ui->previewTextEdit->isReadOnly()) { + if (ui->previewTextEdit->isReadOnly()) + { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(190, 144, 212); @@ -120,10 +131,10 @@ void XrefsDialog::on_fromTreeWidget_itemSelectionChanged() { QTreeWidgetItem *item = ui->fromTreeWidget->currentItem(); QString offset = item->text(0); - ui->previewTextEdit->setPlainText( this->main->core->cmd("pdf @ " + offset).trimmed() ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pdf @ " + offset).trimmed()); ui->previewTextEdit->moveCursor(QTextCursor::End); // Does it make any sense? - ui->previewTextEdit->find( this->normalizeAddr(offset), QTextDocument::FindBackward); + ui->previewTextEdit->find(this->normalizeAddr(offset), QTextDocument::FindBackward); ui->previewTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } @@ -131,15 +142,16 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged() { QTreeWidgetItem *item = ui->toTreeWidget->currentItem(); QString offset = item->text(0); - ui->previewTextEdit->setPlainText( this->main->core->cmd("pdf @ " + offset).trimmed() ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pdf @ " + offset).trimmed()); ui->previewTextEdit->moveCursor(QTextCursor::End); // Again, does it make any sense? // Also, this code should be refactored and shared instead of copied & pasted - ui->previewTextEdit->find( this->normalizeAddr(offset), QTextDocument::FindBackward); + ui->previewTextEdit->find(this->normalizeAddr(offset), QTextDocument::FindBackward); ui->previewTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } -void XrefsDialog::updateLabels(QString name) { +void XrefsDialog::updateLabels(QString name) +{ ui->label_2->setText(ui->label_2->text() + name); ui->label_3->setText(ui->label_3->text() + name); } diff --git a/src/dialogs/xrefsdialog.h b/src/dialogs/xrefsdialog.h index 61bffca7..74747ca5 100644 --- a/src/dialogs/xrefsdialog.h +++ b/src/dialogs/xrefsdialog.h @@ -8,8 +8,9 @@ class MainWindow; -namespace Ui { -class XrefsDialog; +namespace Ui +{ + class XrefsDialog; } class XrefsDialog : public QDialog diff --git a/src/helpers.cpp b/src/helpers.cpp index 01158be1..613f79a5 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -6,22 +6,24 @@ namespace qhelpers { -// TODO: wouldn't it be enough to setFont on the QWidget? + // TODO: wouldn't it be enough to setFont on the QWidget? -void normalizeFont(QPlainTextEdit *edit) { - #ifdef Q_OS_LINUX + void normalizeFont(QPlainTextEdit *edit) + { +#ifdef Q_OS_LINUX QFont anonFont("Inconsolata", 12); QTextDocument *out_doc = edit->document(); out_doc->setDefaultFont(anonFont); - #endif -} +#endif + } -void normalizeEditFont(QTextEdit *edit) { - #ifdef Q_OS_LINUX + void normalizeEditFont(QTextEdit *edit) + { +#ifdef Q_OS_LINUX QFont anonFont("Inconsolata", 12); QTextDocument *out_doc = edit->document(); out_doc->setDefaultFont(anonFont); - #endif -} +#endif + } } // end namespace diff --git a/src/hexascii_highlighter.cpp b/src/hexascii_highlighter.cpp index 6add1a28..8bef810d 100644 --- a/src/hexascii_highlighter.cpp +++ b/src/hexascii_highlighter.cpp @@ -18,10 +18,12 @@ AsciiHighlighter::AsciiHighlighter(QTextDocument *parent) void AsciiHighlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + foreach (const HighlightingRule &rule, highlightingRules) + { QRegExp expression(rule.pattern); int index = expression.indexIn(text); - while (index >= 0) { + while (index >= 0) + { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); @@ -33,13 +35,17 @@ void AsciiHighlighter::highlightBlock(const QString &text) if (previousBlockState() != 1) startIndex = commentStartExpression.indexIn(text); - while (startIndex >= 0) { + while (startIndex >= 0) + { int endIndex = commentEndExpression.indexIn(text, startIndex); int commentLength; - if (endIndex == -1) { + if (endIndex == -1) + { setCurrentBlockState(1); commentLength = text.length() - startIndex; - } else { + } + else + { commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); } diff --git a/src/hexhighlighter.cpp b/src/hexhighlighter.cpp index 09e7193e..98031fe4 100644 --- a/src/hexhighlighter.cpp +++ b/src/hexhighlighter.cpp @@ -25,7 +25,8 @@ HexHighlighter::HexHighlighter(QTextDocument *parent) << "\\b6e\\b" << "\\b6f\\b" << "\\b70\\b" << "\\b71\\b" << "\\b72\\b" << "\\b73\\b" << "\\b74\\b" << "\\b75\\b" << "\\b76\\b" << "\\b77\\b" << "\\b78\\b" << "\\b79\\b" << "\\b7a\\b" << "\\b7b\\b" << "\\b7c\\b" << "\\b7d\\b" << "\\b7e\\b" << "\\b7f\\b"; - foreach (const QString &pattern, keywordPatterns) { + foreach (const QString &pattern, keywordPatterns) + { rule.pattern = QRegExp(pattern); rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); rule.format = keywordFormat; @@ -44,10 +45,12 @@ HexHighlighter::HexHighlighter(QTextDocument *parent) void HexHighlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + foreach (const HighlightingRule &rule, highlightingRules) + { QRegExp expression(rule.pattern); int index = expression.indexIn(text); - while (index >= 0) { + while (index >= 0) + { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); @@ -59,13 +62,17 @@ void HexHighlighter::highlightBlock(const QString &text) if (previousBlockState() != 1) startIndex = commentStartExpression.indexIn(text); - while (startIndex >= 0) { + while (startIndex >= 0) + { int endIndex = commentEndExpression.indexIn(text, startIndex); int commentLength; - if (endIndex == -1) { + if (endIndex == -1) + { setCurrentBlockState(1); commentLength = text.length() - startIndex; - } else { + } + else + { commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); } diff --git a/src/highlighter.cpp b/src/highlighter.cpp index ef89434a..e0d1a260 100644 --- a/src/highlighter.cpp +++ b/src/highlighter.cpp @@ -14,17 +14,19 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) : keywordFormat.setForeground(QColor(65, 131, 215)); keywordFormat.setFontWeight(QFont::Bold); - foreach (const QString &pattern, this->main->core->opcodes) { + foreach (const QString &pattern, this->main->core->opcodes) + { rule.pattern = QRegExp("\\b" + pattern + "\\b"); rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); rule.format = keywordFormat; highlightingRules.append(rule); } - regFormat.setForeground(QColor(236,100,75)); + regFormat.setForeground(QColor(236, 100, 75)); regFormat.setFontWeight(QFont::Bold); - foreach (const QString &pattern, this->main->core->regs) { + foreach (const QString &pattern, this->main->core->regs) + { rule.pattern = QRegExp("\\b" + pattern + "\\b"); rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); rule.format = regFormat; @@ -44,10 +46,12 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) : void Highlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + foreach (const HighlightingRule &rule, highlightingRules) + { QRegExp expression(rule.pattern); int index = expression.indexIn(text); - while (index >= 0) { + while (index >= 0) + { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); @@ -59,13 +63,17 @@ void Highlighter::highlightBlock(const QString &text) if (previousBlockState() != 1) startIndex = commentStartExpression.indexIn(text); - while (startIndex >= 0) { + while (startIndex >= 0) + { int endIndex = commentEndExpression.indexIn(text, startIndex); int commentLength; - if (endIndex == -1) { + if (endIndex == -1) + { setCurrentBlockState(1); commentLength = text.length() - startIndex; - } else { + } + else + { commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); } diff --git a/src/main.cpp b/src/main.cpp index 8bb6d8a4..3ce22be4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) // Check r2 version QString r2version = r_core_version(); QString localVersion = "" R2_GITTAP; - if(r2version != localVersion) + if (r2version != localVersion) { QMessageBox msg; msg.setIcon(QMessageBox::Critical); @@ -43,11 +43,11 @@ int main(int argc, char *argv[]) msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msg.setWindowTitle("Version mismatch!"); msg.setText(QString("The version used to compile iaito (%1) does not match the binary version of radare2 (%2). This could result in unexpected behaviour. Are you sure you want to continue?").arg(localVersion, r2version)); - if(msg.exec() == QMessageBox::No) + if (msg.exec() == QMessageBox::No) return 1; } - if(args.empty()) + if (args.empty()) { NewFileDialog *n = new NewFileDialog(); n->setAttribute(Qt::WA_DeleteOnClose); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5b0c2ee7..e5152714 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : console_docu->setDocumentMargin(10); // Sepparator between back/forward and undo/redo buttons - QWidget* spacer4 = new QWidget(); + QWidget *spacer4 = new QWidget(); spacer4->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); spacer4->setMinimumSize(10, 10); ui->mainToolBar->insertWidget(ui->actionForward, spacer4); @@ -94,7 +94,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked())); // Sepparator between undo/redo and goto lineEdit - QWidget* spacer3 = new QWidget(); + QWidget *spacer3 = new QWidget(); spacer3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); spacer3->setMinimumSize(20, 20); spacer3->setMaximumWidth(300); @@ -105,14 +105,14 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : ui->mainToolBar->insertWidget(ui->actionShow_Hide_mainsidebar, this->omnibar); // Add special sepparators to the toolbar that expand to separate groups of elements - QWidget* spacer2 = new QWidget(); + QWidget *spacer2 = new QWidget(); spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); spacer2->setMinimumSize(10, 10); spacer2->setMaximumWidth(300); ui->mainToolBar->insertWidget(ui->actionShow_Hide_mainsidebar, spacer2); // Sepparator between back/forward and undo/redo buttons - QWidget* spacer = new QWidget(); + QWidget *spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); spacer->setMinimumSize(20, 20); ui->mainToolBar->addWidget(spacer); @@ -143,7 +143,7 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : this->sectionsDock->setObjectName("sectionsDock"); this->sectionsDock->setAllowedAreas(Qt::AllDockWidgetAreas); this->sectionsDock->setWidget(this->sectionsWidget); - this->sectionsWidget->setContentsMargins(0,0,0,5); + this->sectionsWidget->setContentsMargins(0, 0, 0, 5); this->sectionsDock->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); this->sectionsDock->setContextMenuPolicy(Qt::CustomContextMenu); connect(this->sectionsDock, SIGNAL(customContextMenuRequested(const QPoint &)), @@ -185,9 +185,9 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : this->readSettings(); // TODO: Allow the user to select this option visually in the GUI settings // Adjust the DockWidget areas - setCorner( Qt::TopLeftCorner, Qt::LeftDockWidgetArea ); + setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); //setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea ); - setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea ); + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); //setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea ); this->flagsDock->flagsTreeWidget->clear(); @@ -216,28 +216,30 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) : * Some global shortcuts */ // Period goes to command entry - QShortcut* cmd_shortcut = new QShortcut(QKeySequence(Qt::Key_Period), this); + QShortcut *cmd_shortcut = new QShortcut(QKeySequence(Qt::Key_Period), this); connect(cmd_shortcut, SIGNAL(activated()), ui->consoleInputLineEdit, SLOT(setFocus())); // G and S goes to goto entry - QShortcut* goto_shortcut = new QShortcut(QKeySequence(Qt::Key_G), this); + QShortcut *goto_shortcut = new QShortcut(QKeySequence(Qt::Key_G), this); connect(goto_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus())); - QShortcut* seek_shortcut = new QShortcut(QKeySequence(Qt::Key_S), this); + QShortcut *seek_shortcut = new QShortcut(QKeySequence(Qt::Key_S), this); connect(seek_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus())); // : goes to goto entry - QShortcut* commands_shortcut = new QShortcut(QKeySequence(Qt::Key_Colon), this); + QShortcut *commands_shortcut = new QShortcut(QKeySequence(Qt::Key_Colon), this); connect(commands_shortcut, SIGNAL(activated()), this->omnibar, SLOT(showCommands())); connect(&webserverThread, SIGNAL(finished()), this, SLOT(webserverThreadFinished())); } -MainWindow::~MainWindow() { +MainWindow::~MainWindow() +{ delete ui; delete core; } -void MainWindow::start_web_server() { +void MainWindow::start_web_server() +{ // Start web server webserverThread.startServer(); } @@ -252,45 +254,52 @@ void MainWindow::webserverThreadFinished() //} } -void MainWindow::adjustColumns(QTreeWidget *tw) { +void MainWindow::adjustColumns(QTreeWidget *tw) +{ int count = tw->columnCount(); - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { tw->resizeColumnToContents(i); } } void MainWindow::appendRow(QTreeWidget *tw, const QString &str, const QString &str2, - const QString &str3, const QString &str4, const QString &str5) { + const QString &str3, const QString &str4, const QString &str5) +{ QTreeWidgetItem *tempItem = new QTreeWidgetItem(); // Fill dummy hidden column - tempItem->setText(0,"0"); - tempItem->setText(1,str); - if (str2!=NULL) + tempItem->setText(0, "0"); + tempItem->setText(1, str); + if (str2 != NULL) tempItem->setText(2, str2); - if (str3!=NULL) + if (str3 != NULL) tempItem->setText(3, str3); - if (str4!=NULL) + if (str4 != NULL) tempItem->setText(4, str4); - if (str5!=NULL) + if (str5 != NULL) tempItem->setText(5, str5); tw->insertTopLevelItem(0, tempItem); } void MainWindow::setWebServerState(bool start) { - if (start) { + if (start) + { webserverThread.startServer(); // Open web interface on default browser // ballessay: well isn't this possible with =H& //QString link = "http://localhost:9090/"; //QDesktopServices::openUrl(QUrl(link)); - } else { + } + else + { webserverThread.stopServer(); } } -void MainWindow::hideDummyColumns() { +void MainWindow::hideDummyColumns() +{ // UGLY, should be a loop over all treewidgets... this->functionsDock->functionsTreeWidget->setColumnHidden(0, true); this->importsDock->importsTreeWidget->setColumnHidden(0, true); @@ -301,7 +310,8 @@ void MainWindow::hideDummyColumns() { this->commentsDock->commentsTreeWidget->setColumnHidden(0, true); } -void MainWindow::setFilename(QString fn) { +void MainWindow::setFilename(QString fn) +{ // Add file name to window title this->filename = fn; @@ -325,10 +335,11 @@ void MainWindow::showConsoleContextMenu(const QPoint &pt) void MainWindow::closeEvent(QCloseEvent *event) { QMessageBox::StandardButton ret = QMessageBox::question(this, "Iaito", - "Do you really want to exit?\nSave your project before closing!", - QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + "Do you really want to exit?\nSave your project before closing!", + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); //qDebug() << ret; - if (ret == QMessageBox::Save) { + if (ret == QMessageBox::Save) + { QSettings settings; settings.setValue("geometry", saveGeometry()); settings.setValue("size", size()); @@ -339,13 +350,17 @@ void MainWindow::closeEvent(QCloseEvent *event) //this->add_debug_output(notes); this->core->cmd("Pnj " + notes); QMainWindow::closeEvent(event); - } else if (ret == QMessageBox::Discard) { + } + else if (ret == QMessageBox::Discard) + { QSettings settings; settings.setValue("geometry", saveGeometry()); settings.setValue("size", size()); settings.setValue("pos", pos()); settings.setValue("state", saveState()); - } else { + } + else + { event->ignore(); } } @@ -357,20 +372,23 @@ void MainWindow::readSettings() restoreGeometry(geo); QByteArray state = settings.value("state", QByteArray()).toByteArray(); restoreState(state); - if (settings.value("dark").toBool()) { + if (settings.value("dark").toBool()) + { this->dark(); } this->responsive = settings.value("responsive").toBool(); } -void MainWindow::dark() { +void MainWindow::dark() +{ qApp->setStyleSheet("QPlainTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} QTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} "); this->memoryDock->switchTheme(true); QSettings settings; settings.setValue("dark", true); } -void MainWindow::def_theme() { +void MainWindow::def_theme() +{ qApp->setStyleSheet(""); this->memoryDock->switchTheme(false); QSettings settings; @@ -381,28 +399,33 @@ void MainWindow::def_theme() { * Refresh widget functions */ -void MainWindow::refreshFunctions() { +void MainWindow::refreshFunctions() +{ this->functionsDock->refreshTree(); } -void MainWindow::refreshComments() { +void MainWindow::refreshComments() +{ this->commentsDock->refreshTree(); } -void MainWindow::refreshFlagspaces() { +void MainWindow::refreshFlagspaces() +{ int cur_idx = this->flagsDock->flagspaceCombo->currentIndex(); - if (cur_idx<0)cur_idx = 0; + if (cur_idx < 0)cur_idx = 0; this->flagsDock->flagspaceCombo->clear(); this->flagsDock->flagspaceCombo->addItem("(all)"); - for (auto i : core->getList("flagspaces")) { + for (auto i : core->getList("flagspaces")) + { this->flagsDock->flagspaceCombo->addItem(i); } - if (cur_idx>0) + if (cur_idx > 0) this->flagsDock->flagspaceCombo->setCurrentIndex(cur_idx); refreshFlags(); } -void MainWindow::refreshFlags() { +void MainWindow::refreshFlags() +{ QString flagspace = this->flagsDock->flagspaceCombo->currentText(); this->omnibar->clearFlags(); if (flagspace == "(all)") @@ -410,13 +433,16 @@ void MainWindow::refreshFlags() { this->flagsDock->flagsTreeWidget->clear(); - for (auto i: core->getList("flags", flagspace)) { - QStringList a = i.split (","); - if (a.length()>3) { + for (auto i : core->getList("flags", flagspace)) + { + QStringList a = i.split(","); + if (a.length() > 3) + { appendRow(this->flagsDock->flagsTreeWidget, a[1], a[2], a[0], a[3]); this->omnibar->fillFlags(a[0]); } - else if (a.length()>2) { + else if (a.length() > 2) + { appendRow(this->flagsDock->flagsTreeWidget, a[1], a[2], a[0], ""); this->omnibar->fillFlags(a[0]); } @@ -426,18 +452,22 @@ void MainWindow::refreshFlags() { this->omnibar->setupCompleter(); } -void MainWindow::updateFrames() { +void MainWindow::updateFrames() +{ if (core == NULL) return; static bool first_time = true; - if (first_time) { + if (first_time) + { setup_mem(); this->add_output(" > Adding binary information to notepad"); notepadDock->setText("# Binary information\n\n" + core->cmd("i") + "\n" + core->cmd("ie") + "\n" + core->cmd("iM") + "\n"); //first_time = false; - } else { + } + else + { refreshMem(""); } @@ -448,7 +478,8 @@ void MainWindow::updateFrames() { // TODO: make this configurable by the user? const bool use_scrollperpixel = true; - if (use_scrollperpixel) { + if (use_scrollperpixel) + { this->flagsDock->flagsTreeWidget->setVerticalScrollMode(spp); this->symbolsDock->symbolsTreeWidget->setVerticalScrollMode(spp); this->importsDock->importsTreeWidget->setVerticalScrollMode(spp); @@ -457,7 +488,9 @@ void MainWindow::updateFrames() { this->relocsDock->relocsTreeWidget->setVerticalScrollMode(spp); this->memoryDock->xreFromTreeWidget_2->setVerticalScrollMode(spp); this->memoryDock->xrefToTreeWidget_2->setVerticalScrollMode(spp); - } else { + } + else + { this->flagsDock->flagsTreeWidget->setVerticalScrollMode(spi); this->symbolsDock->symbolsTreeWidget->setVerticalScrollMode(spi); this->importsDock->importsTreeWidget->setVerticalScrollMode(spi); @@ -485,9 +518,10 @@ void MainWindow::updateFrames() { adjustColumns(this->importsDock->importsTreeWidget); this->relocsDock->relocsTreeWidget->clear(); - for (auto i: core->getList ("bin","relocs")) { - QStringList pieces = i.split (","); - if (pieces.length()==3) + for (auto i : core->getList("bin", "relocs")) + { + QStringList pieces = i.split(","); + if (pieces.length() == 3) appendRow(this->relocsDock->relocsTreeWidget, pieces[0], pieces[1], pieces[2]); } adjustColumns(this->relocsDock->relocsTreeWidget); @@ -495,16 +529,18 @@ void MainWindow::updateFrames() { this->symbolsDock->fillSymbols(); this->stringsDock->stringsTreeWidget->clear(); - for (auto i : core->getList ("bin", "strings")) { - QStringList pieces = i.split (","); - if (pieces.length () == 2) + for (auto i : core->getList("bin", "strings")) + { + QStringList pieces = i.split(","); + if (pieces.length() == 2) appendRow(this->stringsDock->stringsTreeWidget, pieces[0], pieces[1]); } adjustColumns(this->stringsDock->stringsTreeWidget); this->commentsDock->commentsTreeWidget->clear(); QList> comments = this->core->getComments(); - for (QList comment: comments) { + for (QList comment : comments) + { /* QString name; //this->add_debug_output("Comment: " + comment[1] + ": " + comment[0]); @@ -522,11 +558,13 @@ void MainWindow::updateFrames() { // Add nested comments QMap>> cmts = this->core->getNestedComments(); - for(auto cmt : cmts.keys()) { + for (auto cmt : cmts.keys()) + { QTreeWidgetItem *item = new QTreeWidgetItem(this->commentsDock->nestedCommentsTreeWidget); item->setText(0, cmt); QList> meow = cmts.value(cmt); - for (int i = 0; i < meow.size(); ++i) { + for (int i = 0; i < meow.size(); ++i) + { QList tmp = meow.at(i); QTreeWidgetItem *it = new QTreeWidgetItem(); it->setText(0, tmp[1]); @@ -538,25 +576,32 @@ void MainWindow::updateFrames() { adjustColumns(this->commentsDock->nestedCommentsTreeWidget); // TODO: FIXME: Remove the check for first_time; - if (first_time) { + if (first_time) + { sectionsWidget->tree->clear(); int row = 0; - for (auto i: core->getList("bin","sections")) { - QStringList a = i.split (","); - if (a.length()>2) { + for (auto i : core->getList("bin", "sections")) + { + QStringList a = i.split(","); + if (a.length() > 2) + { // Fix to work with ARM bins //if (a[4].startsWith(".")) { - if (a[4].contains(".")) { + if (a[4].contains(".")) + { QString addr = a[1]; - QString addr_end = "0x0"+core->itoa(core->math(a[1]+"+"+a[2])); + QString addr_end = "0x0" + core->itoa(core->math(a[1] + "+" + a[2])); QString size = QString::number(core->math(a[2])); QString name = a[4]; this->sectionsWidget->fillSections(row, name, size, addr, addr_end); // Used to select a color for the sections graph - if (row == 10) { + if (row == 10) + { row = 0; - } else { + } + else + { row++; } } @@ -578,25 +623,35 @@ void MainWindow::updateFrames() { void MainWindow::on_actionLock_triggered() { doLock = !doLock; - if (doLock) { - foreach (QDockWidget *dockWidget, findChildren()) { - dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); - } - } else { - foreach (QDockWidget *dockWidget, findChildren()) { - dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); + if (doLock) + { + foreach (QDockWidget *dockWidget, findChildren()) + { + dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); + } } + else + { + foreach (QDockWidget *dockWidget, findChildren()) + { + dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); + } } } void MainWindow::lockUnlock_Docks(bool what) { - if(what) { - foreach (QDockWidget *dockWidget, findChildren()) { + if (what) + { + foreach (QDockWidget *dockWidget, findChildren()) + { dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); } - } else { - foreach (QDockWidget *dockWidget, findChildren()) { + } + else + { + foreach (QDockWidget *dockWidget, findChildren()) + { dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); } } @@ -605,27 +660,34 @@ void MainWindow::lockUnlock_Docks(bool what) void MainWindow::on_actionLockUnlock_triggered() { - if(ui->actionLockUnlock->isChecked()) + if (ui->actionLockUnlock->isChecked()) { - foreach (QDockWidget *dockWidget, findChildren()) { + foreach (QDockWidget *dockWidget, findChildren()) + { dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); } - ui->actionLockUnlock->setIcon( QIcon(":/new/prefix1/lock") ); - } else { - foreach (QDockWidget *dockWidget, findChildren()) { + ui->actionLockUnlock->setIcon(QIcon(":/new/prefix1/lock")); + } + else + { + foreach (QDockWidget *dockWidget, findChildren()) + { dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); } - ui->actionLockUnlock->setIcon( QIcon(":/new/prefix1/unlock") ); + ui->actionLockUnlock->setIcon(QIcon(":/new/prefix1/unlock")); } } void MainWindow::on_actionTabs_triggered() { - if (ui->centralTabWidget->tabPosition() == QTabWidget::South) { + if (ui->centralTabWidget->tabPosition() == QTabWidget::South) + { ui->centralTabWidget->setTabPosition(QTabWidget::North); this->memoryDock->memTabWidget->setTabPosition(QTabWidget::North); this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); - } else { + } + else + { ui->centralTabWidget->setTabPosition(QTabWidget::South); this->memoryDock->memTabWidget->setTabPosition(QTabWidget::South); this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); @@ -636,7 +698,7 @@ void MainWindow::on_actionMem_triggered() { //this->memoryDock->show(); //this->memoryDock->raise(); - MemoryWidget* newMemDock = new MemoryWidget(this); + MemoryWidget *newMemDock = new MemoryWidget(this); this->dockList << newMemDock; newMemDock->setAttribute(Qt::WA_DeleteOnClose); this->tabifyDockWidget(this->memoryDock, newMemDock); @@ -646,9 +708,12 @@ void MainWindow::on_actionMem_triggered() void MainWindow::on_actionFunctions_triggered() { - if (this->functionsDock->isVisible()) { + if (this->functionsDock->isVisible()) + { this->functionsDock->close(); - } else { + } + else + { this->functionsDock->show(); this->functionsDock->raise(); } @@ -656,9 +721,12 @@ void MainWindow::on_actionFunctions_triggered() void MainWindow::on_actionImports_triggered() { - if (this->importsDock->isVisible()) { + if (this->importsDock->isVisible()) + { this->importsDock->close(); - } else { + } + else + { this->importsDock->show(); this->importsDock->raise(); } @@ -666,9 +734,12 @@ void MainWindow::on_actionImports_triggered() void MainWindow::on_actionSymbols_triggered() { - if (this->symbolsDock->isVisible()) { + if (this->symbolsDock->isVisible()) + { this->symbolsDock->close(); - } else { + } + else + { this->symbolsDock->show(); this->symbolsDock->raise(); } @@ -676,9 +747,12 @@ void MainWindow::on_actionSymbols_triggered() void MainWindow::on_actionReloc_triggered() { - if (this->relocsDock->isVisible()) { + if (this->relocsDock->isVisible()) + { this->relocsDock->close(); - } else { + } + else + { this->relocsDock->show(); this->relocsDock->raise(); } @@ -686,9 +760,12 @@ void MainWindow::on_actionReloc_triggered() void MainWindow::on_actionStrings_triggered() { - if (this->stringsDock->isVisible()) { + if (this->stringsDock->isVisible()) + { this->stringsDock->close(); - } else { + } + else + { this->stringsDock->show(); this->stringsDock->raise(); } @@ -696,9 +773,12 @@ void MainWindow::on_actionStrings_triggered() void MainWindow::on_actionSections_triggered() { - if (this->sectionsDock->isVisible()) { + if (this->sectionsDock->isVisible()) + { this->sectionsDock->close(); - } else { + } + else + { this->sectionsDock->show(); this->sectionsDock->raise(); } @@ -706,9 +786,12 @@ void MainWindow::on_actionSections_triggered() void MainWindow::on_actionFlags_triggered() { - if (this->flagsDock->isVisible()) { + if (this->flagsDock->isVisible()) + { this->flagsDock->close(); - } else { + } + else + { this->flagsDock->show(); this->flagsDock->raise(); } @@ -716,9 +799,12 @@ void MainWindow::on_actionFlags_triggered() void MainWindow::on_actionComents_triggered() { - if (this->commentsDock->isVisible()) { + if (this->commentsDock->isVisible()) + { this->commentsDock->close(); - } else { + } + else + { this->commentsDock->show(); this->commentsDock->raise(); } @@ -726,9 +812,12 @@ void MainWindow::on_actionComents_triggered() void MainWindow::on_actionNotepad_triggered() { - if (this->notepadDock->isVisible()) { + if (this->notepadDock->isVisible()) + { this->notepadDock->close(); - } else { + } + else + { this->notepadDock->show(); this->notepadDock->raise(); } @@ -736,22 +825,24 @@ void MainWindow::on_actionNotepad_triggered() void MainWindow::on_actionAbout_triggered() { - AboutDialog* a = new AboutDialog(this); + AboutDialog *a = new AboutDialog(this); a->open(); } void MainWindow::on_consoleInputLineEdit_returnPressed() { - if (this->core) { + 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); + if (completer != NULL) + { + QStringListModel *completerModel = (QStringListModel *)(completer->model()); + if (completerModel != NULL) + completerModel->setStringList(completerModel->stringList() << input); } ui->consoleInputLineEdit->setText(""); @@ -762,13 +853,16 @@ void MainWindow::on_showHistoToolButton_clicked() { QCompleter *completer = ui->consoleInputLineEdit->completer(); if (completer == NULL) - return; + return; - if (ui->showHistoToolButton->isChecked()) { + if (ui->showHistoToolButton->isChecked()) + { completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); // Uhm... shouldn't it be called always? completer->complete(); - } else { + } + else + { completer->setCompletionMode(QCompleter::PopupCompletion); } } @@ -783,20 +877,22 @@ void MainWindow::on_actionRefresh_Panels_triggered() this->updateFrames(); } -void MainWindow::seek(const QString& offset, const QString& name) { - if (offset.length()==0) +void MainWindow::seek(const QString &offset, const QString &name) +{ + if (offset.length() == 0) return; if (name != NULL) this->memoryDock->setWindowTitle(name); this->hexdumpTopOffset = 0; this->hexdumpBottomOffset = 0; - core->seek (offset); + core->seek(offset); refreshMem(offset); this->memoryDock->disasTextEdit->setFocus(); } -void MainWindow::setup_mem() { +void MainWindow::setup_mem() +{ QString off = this->core->cmd("afo entry0").trimmed(); //graphicsBar->refreshColorBar(); graphicsBar->fillData(); @@ -807,7 +903,8 @@ void MainWindow::setup_mem() { this->memoryDock->setFcnName(off); } -void MainWindow::refreshMem(QString off) { +void MainWindow::refreshMem(QString off) +{ //add_debug_output("Refreshing to: " + off); //graphicsBar->refreshColorBar(); this->memoryDock->refreshDisasm(off); @@ -821,7 +918,8 @@ void MainWindow::on_backButton_clicked() { this->core->cmd("s-"); QString back_offset = this->core->cmd("s=").split(" > ").last().trimmed(); - if (back_offset != "") { + if (back_offset != "") + { QString fcn = this->core->cmdFunctionAt(back_offset); this->seek(this->memoryDock->normalizeAddr(back_offset), fcn); } @@ -829,20 +927,22 @@ void MainWindow::on_backButton_clicked() void MainWindow::on_actionCalculator_triggered() { - if (!this->sideBar->isVisible()) { + if (!this->sideBar->isVisible()) + { this->on_actionShow_Hide_mainsidebar_triggered(); } } void MainWindow::on_actionCreate_File_triggered() { - createNewDialog* n = new createNewDialog(this); + createNewDialog *n = new createNewDialog(this); n->exec(); } void MainWindow::on_actionAssembler_triggered() { - if (!this->sideBar->isVisible()) { + if (!this->sideBar->isVisible()) + { this->on_actionShow_Hide_mainsidebar_triggered(); } } @@ -859,16 +959,19 @@ void MainWindow::on_actionStart_Web_Server_triggered() void MainWindow::on_actionConsoleSync_with_core_triggered() { - if (ui->actionConsoleSync_with_core->isChecked()) { + if (ui->actionConsoleSync_with_core->isChecked()) + { //Enable core syncronization - } else { + } + else + { // Disable core sync } } void MainWindow::on_actionDisasAdd_comment_triggered() { - CommentsDialog* c = new CommentsDialog(this); + CommentsDialog *c = new CommentsDialog(this); c->exec(); } @@ -928,9 +1031,12 @@ void MainWindow::showDefaultDocks() void MainWindow::on_actionhide_bottomPannel_triggered() { - if (ui->centralWidget->isVisible()) { + if (ui->centralWidget->isVisible()) + { ui->centralWidget->hide(); - } else { + } + else + { ui->centralWidget->show(); } } @@ -942,13 +1048,13 @@ void MainWindow::send_to_notepad(QString txt) void MainWindow::on_actionFunctionsRename_triggered() { - RenameDialog* r = new RenameDialog(this); + RenameDialog *r = new RenameDialog(this); // Get function based on click position //r->setFunctionName(fcn_name); r->open(); } -void MainWindow::get_refs(const QString& offset) +void MainWindow::get_refs(const QString &offset) { this->memoryDock->get_refs_data(offset); } @@ -1022,18 +1128,24 @@ void MainWindow::on_actionLoad_triggered() void MainWindow::on_actionShow_Hide_mainsidebar_triggered() { - if (ui->sideToolBar->isVisible()) { + if (ui->sideToolBar->isVisible()) + { ui->sideToolBar->hide(); - } else { + } + else + { ui->sideToolBar->show(); } } void MainWindow::on_actionDashboard_triggered() { - if (this->dashboardDock->isVisible()) { + if (this->dashboardDock->isVisible()) + { this->dashboardDock->close(); - } else { + } + else + { this->dashboardDock->show(); this->dashboardDock->raise(); } @@ -1047,10 +1159,13 @@ void MainWindow::showSectionsContextMenu(const QPoint &pt) menu->addAction(ui->actionSectionsHorizontal); menu->addAction(ui->actionSectionsVertical); - if (this->sectionsWidget->orientation() == 1) { + if (this->sectionsWidget->orientation() == 1) + { ui->actionSectionsHorizontal->setChecked(true); ui->actionSectionsVertical->setChecked(false); - } else { + } + else + { ui->actionSectionsVertical->setChecked(true); ui->actionSectionsHorizontal->setChecked(false); } @@ -1074,13 +1189,15 @@ void MainWindow::on_actionForward_triggered() { this->core->cmd("s+"); QString offset = this->core->cmd("s=").split(" > ").last().trimmed(); - if (offset != "") { + if (offset != "") + { this->add_debug_output(offset); this->seek(offset); } } -void MainWindow::toggleResponsive(bool maybe) { +void MainWindow::toggleResponsive(bool maybe) +{ this->responsive = maybe; // Save options in settings QSettings settings; @@ -1095,9 +1212,10 @@ void MainWindow::on_actionTabs_on_Top_triggered() void MainWindow::on_actionReset_settings_triggered() { QMessageBox::StandardButton ret = QMessageBox::question(this, "Iaito", - "Do you really want to clear all settings?", - QMessageBox::Ok | QMessageBox::Cancel); - if (ret == QMessageBox::Ok) { + "Do you really want to clear all settings?", + QMessageBox::Ok | QMessageBox::Cancel); + if (ret == QMessageBox::Ok) + { // Save options in settings QSettings settings; settings.clear(); diff --git a/src/mainwindow.h b/src/mainwindow.h index b53bcea8..0aaef18d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -35,8 +35,9 @@ #include "newfiledialog.h" #include "helpers.h" -namespace Ui { -class MainWindow; +namespace Ui +{ + class MainWindow; } @@ -64,18 +65,18 @@ public: void readSettings(); void setFilename(QString fn); void setCore(QRCore *core); - void seek(const QString& offset, const QString& name=NULL); + void seek(const QString &offset, const QString &name = NULL); void updateFrames(); void refreshFunctions(); void refreshComments(); void refreshFlags(); - void get_refs(const QString& offset); + void get_refs(const QString &offset); void add_output(QString msg); void add_debug_output(QString msg); void send_to_notepad(QString txt); void adjustColumns(QTreeWidget *tw); - void appendRow(QTreeWidget *tw, const QString &str, const QString &str2=NULL, - const QString &str3=NULL, const QString &str4=NULL, const QString &str5=NULL); + void appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = NULL, + const QString &str3 = NULL, const QString &str4 = NULL, const QString &str5 = NULL); void setWebServerState(bool start); @@ -201,7 +202,7 @@ private: ut64 hexdumpTopOffset; ut64 hexdumpBottomOffset; QString filename; - QList dockList; + QList dockList; QLabel *logo; Ui::MainWindow *ui; Highlighter *highlighter; diff --git a/src/mdhighlighter.cpp b/src/mdhighlighter.cpp index 2865d8ad..93dcd508 100644 --- a/src/mdhighlighter.cpp +++ b/src/mdhighlighter.cpp @@ -15,7 +15,8 @@ MdHighlighter::MdHighlighter(QTextDocument *parent) << "\\*([^\\\\]+)\\*" << "\\_([^\\\\]+)\\_" << "\\_\\_([^\\\\]+)\\_\\_"; - foreach (const QString &pattern, keywordPatterns) { + foreach (const QString &pattern, keywordPatterns) + { rule.pattern = QRegExp(pattern); rule.format = keywordFormat; highlightingRules.append(rule); @@ -30,10 +31,12 @@ MdHighlighter::MdHighlighter(QTextDocument *parent) void MdHighlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + foreach (const HighlightingRule &rule, highlightingRules) + { QRegExp expression(rule.pattern); int index = expression.indexIn(text); - while (index >= 0) { + while (index >= 0) + { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); diff --git a/src/newfiledialog.cpp b/src/newfiledialog.cpp index 557b3de9..69ffc8fc 100644 --- a/src/newfiledialog.cpp +++ b/src/newfiledialog.cpp @@ -10,7 +10,8 @@ const int NewFileDialog::MaxRecentFiles; -static QColor getColorFor(QString str, int pos) { +static QColor getColorFor(QString str, int pos) +{ QNOTUSED(str); QList Colors; @@ -25,22 +26,23 @@ static QColor getColorFor(QString str, int pos) { } -static QIcon getIconFor(QString str, int pos) { +static QIcon getIconFor(QString str, int pos) +{ // Add to the icon list int w = 64; int h = 64; - QPixmap pixmap(w,h); + QPixmap pixmap(w, h); pixmap.fill(Qt::transparent); QPainter pixPaint(&pixmap); pixPaint.setPen(Qt::NoPen); pixPaint.setRenderHint(QPainter::Antialiasing); pixPaint.setBrush(QBrush(QBrush(getColorFor(str, pos)))); - pixPaint.drawEllipse(1,1,w-2,h-2); + pixPaint.drawEllipse(1, 1, w - 2, h - 2); pixPaint.setPen(Qt::white); - pixPaint.setFont(QFont("Verdana",24,1)); - pixPaint.drawText(0, 0, w, h-2, Qt::AlignCenter, QString(str).toUpper().mid(0,2)); + pixPaint.setFont(QFont("Verdana", 24, 1)); + pixPaint.drawText(0, 0, w, h - 2, Qt::AlignCenter, QString(str).toUpper().mid(0, 2)); return QIcon(pixmap); } NewFileDialog::NewFileDialog(QWidget *parent) : @@ -60,19 +62,20 @@ NewFileDialog::NewFileDialog(QWidget *parent) : int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); - for (int i = 0; i < numRecentFiles; ++i) { + for (int i = 0; i < numRecentFiles; ++i) + { // Get stored files //QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); // Remove all but the file name QString sep = QDir::separator(); - QStringList name_list = files[i].split( sep ); + QStringList name_list = files[i].split(sep); QString name = name_list.last(); // Get file info QFileInfo info(files[i]); - QListWidgetItem* item = new QListWidgetItem(getIconFor(name, i),files[i] + "\nCreated: " + info.created().toString() + "\nSize: " + QString::number(info.size())); + QListWidgetItem *item = new QListWidgetItem(getIconFor(name, i), files[i] + "\nCreated: " + info.created().toString() + "\nSize: " + QString::number(info.size())); //":/new/prefix1/img/icons/target.png"), name ); item->setData(Qt::UserRole, files[i]); ui->recentsList->addItem(item); @@ -93,11 +96,14 @@ void NewFileDialog::on_loadFileButton_clicked() // Check that there is a file selected QString fname = ui->newFileEdit->text(); QFileInfo checkfile(fname); - if (!checkfile.exists() || !checkfile.isFile()) { + if (!checkfile.exists() || !checkfile.isFile()) + { QMessageBox msgBox; msgBox.setText("Select a new program or a previous one\nbefore continue"); msgBox.exec(); - } else { + } + else + { // Add file to recent file list QSettings settings; QStringList files = settings.value("recentFileList").toStringList(); @@ -107,10 +113,10 @@ void NewFileDialog::on_loadFileButton_clicked() files.removeLast(); settings.setValue("recentFileList", files); - + // Close dialog and open OptionsDialog close(); - OptionsDialog* o = new OptionsDialog(fname); + OptionsDialog *o = new OptionsDialog(fname); o->exec(); } } @@ -125,15 +131,16 @@ void NewFileDialog::on_newFileButton_clicked() QString fileName; fileName = dialog.getOpenFileName(this, "Select file"); - if (!fileName.isEmpty()) { + if (!fileName.isEmpty()) + { ui->newFileEdit->setText(fileName); - ui->loadFileButton->setFocus(); + ui->loadFileButton->setFocus(); } } void NewFileDialog::on_recentsList_itemClicked(QListWidgetItem *item) { - QVariant data = item->data( Qt::UserRole ); + QVariant data = item->data(Qt::UserRole); QString sitem = data.toString(); ui->newFileEdit->setText(sitem); } @@ -141,11 +148,11 @@ void NewFileDialog::on_recentsList_itemClicked(QListWidgetItem *item) void NewFileDialog::on_recentsList_itemDoubleClicked(QListWidgetItem *item) { // Get selected item to send to options dialog - QVariant data = item->data( Qt::UserRole ); + QVariant data = item->data(Qt::UserRole); QString sitem = data.toString(); // Close dialog and open OptionsDialog close(); - OptionsDialog* o = new OptionsDialog(sitem); + OptionsDialog *o = new OptionsDialog(sitem); o->exec(); } @@ -157,9 +164,9 @@ void NewFileDialog::on_cancelButton_clicked() void NewFileDialog::on_actionRemove_item_triggered() { // Remove selected item from recents list - QListWidgetItem* item = ui->recentsList->currentItem(); + QListWidgetItem *item = ui->recentsList->currentItem(); - QVariant data = item->data( Qt::UserRole ); + QVariant data = item->data(Qt::UserRole); QString sitem = data.toString(); QSettings settings; @@ -167,7 +174,7 @@ void NewFileDialog::on_actionRemove_item_triggered() files.removeAll(sitem); settings.setValue("recentFileList", files); - ui->recentsList->takeItem( ui->recentsList->currentRow() ); + ui->recentsList->takeItem(ui->recentsList->currentRow()); ui->newFileEdit->clear(); } @@ -176,7 +183,7 @@ void NewFileDialog::on_createButton_clicked() { // Close dialog and open create new file dialog close(); - createNewDialog* n = new createNewDialog(this); + createNewDialog *n = new createNewDialog(this); n->exec(); } diff --git a/src/newfiledialog.h b/src/newfiledialog.h index 5ad3af59..f9be1d4b 100644 --- a/src/newfiledialog.h +++ b/src/newfiledialog.h @@ -4,8 +4,9 @@ #include #include -namespace Ui { -class NewFileDialog; +namespace Ui +{ + class NewFileDialog; } class NewFileDialog : public QDialog diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index c0957484..b4a4bff6 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -21,7 +21,8 @@ OptionsDialog::OptionsDialog(QString filename, QWidget *parent): // Fill the plugins combo QStringList plugins; - for (auto i: this->core->getList ("asm", "plugins")) { + for (auto i : this->core->getList("asm", "plugins")) + { this->asm_plugins.append(i); plugins.append(i); } @@ -42,7 +43,7 @@ OptionsDialog::OptionsDialog(QString filename, QWidget *parent): //this->layout()->setSizeConstraint(QLayout::SetFixedSize); connect(&analThread, SIGNAL(finished()), this, SLOT(anal_finished())); - + setFilename(filename); } @@ -51,12 +52,13 @@ OptionsDialog::~OptionsDialog() delete ui; } -void OptionsDialog::setFilename(QString fn, QString shortfn) { +void OptionsDialog::setFilename(QString fn, QString shortfn) +{ this->filename = fn; this->shortfn = shortfn; //qDebug() << QFileInfo(fn).fileName(); ui->programLineEdit->setText(fn); - this->core->tryFile (fn, 1); + this->core->tryFile(fn, 1); } void OptionsDialog::setFilename(QString fn) @@ -94,7 +96,8 @@ void OptionsDialog::on_okButton_clicked() ut64 mapaddr = 0LL; int bits = 0; QString sel_bits = ui->bitsComboBox->currentText(); - if (sel_bits != "Auto") { + if (sel_bits != "Auto") + { bits = sel_bits.toInt(); } @@ -102,51 +105,69 @@ void OptionsDialog::on_okButton_clicked() QSettings settings; // Show asm bytes - if (ui->bytesCheckBox->isChecked()) { + if (ui->bytesCheckBox->isChecked()) + { this->w->core->config("asm.bytes", "true"); this->w->core->config("asm.cmtcol", "100"); - } else { + } + else + { this->w->core->config("asm.bytes", "false"); this->w->core->config("asm.cmtcol", "70"); } settings.setValue("bytes", ui->bytesCheckBox->isChecked()); // Show AT&T syntax - if (ui->attCheckBox->isChecked()) { + if (ui->attCheckBox->isChecked()) + { this->w->core->config("asm.syntax", "att"); - } else { + } + else + { this->w->core->config("asm.syntax", "intel"); } settings.setValue("syntax", ui->attCheckBox->isChecked()); // Show opcode description - if (ui->descriptionCheckBox->isChecked()) { + if (ui->descriptionCheckBox->isChecked()) + { this->w->core->config("asm.describe", "true"); - } else { + } + else + { this->w->core->config("asm.describe", "false"); } settings.setValue("describe", ui->descriptionCheckBox->isChecked()); // Show stack pointer - if (ui->stackCheckBox->isChecked()) { + if (ui->stackCheckBox->isChecked()) + { this->w->core->config("asm.stackptr", "true"); - } else { + } + else + { this->w->core->config("asm.stackptr", "false"); } settings.setValue("stackptr", ui->stackCheckBox->isChecked()); // Show uppercase dasm - if (ui->ucaseCheckBox->isChecked()) { + if (ui->ucaseCheckBox->isChecked()) + { this->w->core->config("asm.ucase", "true"); - } else { + } + else + { this->w->core->config("asm.ucase", "false"); } settings.setValue("ucase", ui->ucaseCheckBox->isChecked()); // Show spaces in dasm - if (ui->spacyCheckBox->isChecked()) { + if (ui->spacyCheckBox->isChecked()) + { this->w->core->config("asm.spacy", "true"); - } else { + } + else + { this->w->core->config("asm.spacy", "false"); } settings.setValue("spacy", ui->spacyCheckBox->isChecked()); @@ -154,14 +175,18 @@ void OptionsDialog::on_okButton_clicked() bool rw = false; bool load_bininfo = ui->binCheckBox->isChecked(); - if (load_bininfo) { - if (!va) { + if (load_bininfo) + { + if (!va) + { va = 2; loadaddr = UT64_MAX; - r_config_set_i (this->core->core()->config, "bin.laddr", loadaddr); + r_config_set_i(this->core->core()->config, "bin.laddr", loadaddr); mapaddr = 0; } - } else { + } + else + { va = false; loadaddr = mapaddr = 0; } @@ -181,7 +206,8 @@ void OptionsDialog::on_okButton_clicked() // connect signal/slot int level = 0; - if (anal_level == true) { + if (anal_level == true) + { level = ui->analSlider->value(); } @@ -201,21 +227,25 @@ void OptionsDialog::anal_finished() ui->statusLabel->setText("Loading interface"); this->w->add_output(" > Analysis finished"); QString initial_seek = ui->entry_initialSeek->text(); - if (initial_seek.length()>0) { + if (initial_seek.length() > 0) + { this->w->core->seek(initial_seek); - } else { + } + else + { this->w->core->seek("entry0"); } this->w->add_output(" > Populating UI"); this->w->updateFrames(); this->w->setFilename(this->filename); - this->w->get_refs( this->w->core->cmd("?v entry0") ); + this->w->get_refs(this->w->core->cmd("?v entry0")); this->w->memoryDock->selectHexPreview(); // Restore project notes QString notes = this->core->cmd("Pn"); //qDebug() << "Notes:" << notes; - if (notes != "") { + if (notes != "") + { QByteArray ba; ba.append(notes); this->w->notepadDock->notesTextEdit->setPlainText(QByteArray::fromBase64(ba)); @@ -227,7 +257,7 @@ void OptionsDialog::anal_finished() this->w->add_output(" > Finished, happy reversing :)"); // Add fortune message - this->w->add_output( "\n" + this->w->core->cmd("fo") ); + this->w->add_output("\n" + this->w->core->cmd("fo")); this->w->memoryDock->setWindowTitle("entry0"); this->w->start_web_server(); close(); @@ -243,27 +273,32 @@ void OptionsDialog::on_cancelButton_clicked() this->core = NULL; // Close dialog and open OptionsDialog close(); - NewFileDialog* n = new NewFileDialog(this); + NewFileDialog *n = new NewFileDialog(this); n->show(); } void OptionsDialog::on_analSlider_valueChanged(int value) { ui->analLevel->setText(QString::number(value)); - if (value == 0) { + if (value == 0) + { ui->analCheckBox->setChecked(false); - } else { + } + else + { ui->analCheckBox->setChecked(true); } } void OptionsDialog::on_AdvOptButton_clicked() { - if(ui->AdvOptButton->isChecked()) + if (ui->AdvOptButton->isChecked()) { ui->hideFrame->setVisible(true); ui->AdvOptButton->setArrowType(Qt::DownArrow); - } else { + } + else + { ui->hideFrame->setVisible(false); ui->AdvOptButton->setArrowType(Qt::RightArrow); diff --git a/src/optionsdialog.h b/src/optionsdialog.h index f86b313e..794f2902 100644 --- a/src/optionsdialog.h +++ b/src/optionsdialog.h @@ -9,8 +9,9 @@ class MainWindow; -namespace Ui { -class OptionsDialog; +namespace Ui +{ + class OptionsDialog; } class OptionsDialog : public QDialog diff --git a/src/qrcore.cpp b/src/qrcore.cpp index dbbb14cc..bba1a0c9 100644 --- a/src/qrcore.cpp +++ b/src/qrcore.cpp @@ -9,7 +9,7 @@ RCoreLocked::RCoreLocked(RCore *core) r_th_lock_enter(core->lock); } -RCoreLocked::RCoreLocked(RCoreLocked&& o) +RCoreLocked::RCoreLocked(RCoreLocked &&o) : core(o.core) { o.core = nullptr; @@ -20,12 +20,12 @@ RCoreLocked::~RCoreLocked() r_th_lock_leave(core->lock); } -RCoreLocked::operator RCore*() const +RCoreLocked::operator RCore *() const { return core; } -RCore* RCoreLocked::operator->() const +RCore *RCoreLocked::operator->() const { return core; } @@ -40,17 +40,17 @@ RCoreLocked QRCore::core() const QRCore::QRCore(QObject *parent) : QObject(parent) { - r_cons_new (); // initialize console + r_cons_new(); // initialize console this->projectPath = ""; - this->core_ = r_core_new (); - r_core_loadlibs (this->core_, R_CORE_LOADLIBS_ALL, NULL); + this->core_ = r_core_new(); + r_core_loadlibs(this->core_, R_CORE_LOADLIBS_ALL, NULL); // IMPLICIT r_bin_iobind (core_->bin, core_->io); // Otherwise r2 may ask the user for input and Iaito would freeze - config("scr.interactive","false"); + config("scr.interactive", "false"); // Used by the HTML5 graph - config("http.cors","true"); + config("http.cors", "true"); config("http.sandbox", "false"); //config("http.port", "14170"); @@ -58,244 +58,304 @@ QRCore::QRCore(QObject *parent) : //config("http.root","/usr/local/share/radare2/last/www"); //config("http.root","/usr/local/radare2/osx/share/radare2/1.1.0-git/www"); - this->db = sdb_new (NULL, NULL, 0); // WTF NOES + this->db = sdb_new(NULL, NULL, 0); // WTF NOES } -QList QRCore::getFunctionXrefs(ut64 addr) { +QList QRCore::getFunctionXrefs(ut64 addr) +{ CORE_LOCK(); QList ret = QList(); RList *list = r_anal_xrefs_get(core_->anal, addr); RAnalRef *ref; RListIter *it; - QRListForeach (list, it, RAnalRef, ref) { - ret << QString ("%1,0x%2,0x%3").arg( - QString(ref->type), - QString::number(ref->addr,16), - QString::number(ref->at,16)); + QRListForeach(list, it, RAnalRef, ref) + { + ret << QString("%1,0x%2,0x%3").arg( + QString(ref->type), + QString::number(ref->addr, 16), + QString::number(ref->at, 16)); } return ret; } -QList QRCore::getFunctionRefs(ut64 addr, char type) { +QList QRCore::getFunctionRefs(ut64 addr, char type) +{ CORE_LOCK(); QList ret = QList(); //RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr); RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); - if (!fcn) { + if (!fcn) + { eprintf("qcore->getFunctionRefs: No function found\n"); return ret; } //eprintf(fcn->name); RAnalRef *ref; RListIter *it; - QRListForeach (fcn->refs, it, RAnalRef, ref) { + QRListForeach(fcn->refs, it, RAnalRef, ref) + { if (type == ref->type || type == 0) - ret << QString ("%1,0x%2,0x%3").arg( - QString(ref->type), - QString::number(ref->addr,16), - QString::number(ref->at,16)); + ret << QString("%1,0x%2,0x%3").arg( + QString(ref->type), + QString::number(ref->addr, 16), + QString::number(ref->at, 16)); } return ret; } -int QRCore::getCycloComplex(ut64 addr) { +int QRCore::getCycloComplex(ut64 addr) +{ CORE_LOCK(); QString ret = ""; RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); - if (fcn) { + if (fcn) + { ret = cmd("afcc @ " + QString(fcn->name)); return ret.toInt(); - } else { + } + else + { eprintf("qcore->getCycloComplex: no fcn found"); return 0; } } -int QRCore::getFcnSize(ut64 addr) { +int QRCore::getFcnSize(ut64 addr) +{ CORE_LOCK(); QString ret = ""; QString tmp_ret = ""; RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); - if (fcn) { + if (fcn) + { tmp_ret = cmd("afi~size[1] " + QString(fcn->name)); ret = tmp_ret.split("\n")[0]; - return ret.toInt()/10; - } else { + return ret.toInt() / 10; + } + else + { eprintf("qcore->getFcnSize: no fcn found"); return 0; } } -QList QRCore::sdbList(QString path) { +QList QRCore::sdbList(QString path) +{ CORE_LOCK(); QList list = QList(); - Sdb *root = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); - if (root) { + Sdb *root = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0); + if (root) + { void *vsi; ls_iter_t *iter; - ls_foreach(root->ns, iter, vsi) { - SdbNs *nsi = (SdbNs*)vsi; + ls_foreach(root->ns, iter, vsi) + { + SdbNs *nsi = (SdbNs *)vsi; list << nsi->name; } } return list; } -QList QRCore::sdbListKeys(QString path) { +QList QRCore::sdbListKeys(QString path) +{ CORE_LOCK(); QList list = QList(); - Sdb *root = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); - if (root) { + Sdb *root = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0); + if (root) + { void *vsi; ls_iter_t *iter; SdbList *l = sdb_foreach_list(root, false); - ls_foreach(l, iter, vsi) { - SdbKv *nsi = (SdbKv*)vsi; + ls_foreach(l, iter, vsi) + { + SdbKv *nsi = (SdbKv *)vsi; list << nsi->key; } } return list; } -QString QRCore::sdbGet(QString path, QString key) { +QString QRCore::sdbGet(QString path, QString key) +{ CORE_LOCK(); - Sdb *db = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); - if (db) { + Sdb *db = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0); + if (db) + { const char *val = sdb_const_get(db, key.toUtf8().constData(), 0); if (val && *val) return val; } - return QString (""); + return QString(""); } -bool QRCore::sdbSet(QString path, QString key, QString val) { +bool QRCore::sdbSet(QString path, QString key, QString val) +{ CORE_LOCK(); - Sdb *db = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 1); + Sdb *db = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 1); if (!db) return false; - return sdb_set (db, key.toUtf8().constData(), val.toUtf8().constData(), 0); + return sdb_set(db, key.toUtf8().constData(), val.toUtf8().constData(), 0); } -QRCore::~QRCore() { +QRCore::~QRCore() +{ r_core_free(this->core_); r_cons_free(); } -QString QRCore::cmd(const QString &str) { +QString QRCore::cmd(const QString &str) +{ CORE_LOCK(); QByteArray cmd = str.toUtf8(); //r_cons_flush(); - char *res = r_core_cmd_str (this->core_, cmd.constData()); + char *res = r_core_cmd_str(this->core_, cmd.constData()); QString o = QString(res ? res : ""); //r_mem_free was added in https://github.com/radare/radare2/commit/cd28744049492dc8ac25a1f2b3ba0e42f0e9ce93 r_mem_free(res); return o; } -bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, bool rw=false, int va=0, int bits = 0, int idx, bool loadbin) { +bool QRCore::loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int bits = 0, int idx, bool loadbin) +{ QNOTUSED(loadaddr); QNOTUSED(idx); CORE_LOCK(); RCoreFile *f; - if (va==0 || va == 2) - r_config_set_i (core_->config, "io.va", va); + if (va == 0 || va == 2) + r_config_set_i(core_->config, "io.va", va); // NO ONE KNOWS WHY THIS IS FIXING A SEGFAULT. core_->file should have already a proper value. Pancake dixit //core_->file = NULL; // mapaddr = 0LL; - printf ("FILE OPEN (%s)\n", path.toUtf8().constData()); - f = r_core_file_open(core_, path.toUtf8().constData(), rw?(R_IO_READ|R_IO_WRITE):R_IO_READ, mapaddr); - if (!f) { - eprintf ("r_core_file_open failed\n"); + printf("FILE OPEN (%s)\n", path.toUtf8().constData()); + f = r_core_file_open(core_, path.toUtf8().constData(), rw ? (R_IO_READ | R_IO_WRITE) : R_IO_READ, mapaddr); + if (!f) + { + eprintf("r_core_file_open failed\n"); return false; } - if (loadbin) { - if (va==1) { - if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) { + if (loadbin) + { + if (va == 1) + { + if (r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX)) + { RBinObject *obj = r_bin_get_object(core_->bin); - if (obj) { - eprintf ("BITS %d\n", obj->info->bits); + if (obj) + { + eprintf("BITS %d\n", obj->info->bits); } - } else { - eprintf ("CANNOT GET RBIN INFO\n"); } - } else { - if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) { + else + { + eprintf("CANNOT GET RBIN INFO\n"); + } + } + else + { + if (r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX)) + { RBinObject *obj = r_bin_get_object(core_->bin); - if (obj) { - eprintf ("BITS %d\n", obj->info->bits); - } else { + if (obj) + { + eprintf("BITS %d\n", obj->info->bits); + } + else + { eprintf("Bin load failed\n"); return false; } - } else { - eprintf ("CANNOT GET RBIN INFO\n"); + } + else + { + eprintf("CANNOT GET RBIN INFO\n"); } } - if (bits != 0) { - r_config_set_i (core_->config, "asm.bits", bits); + if (bits != 0) + { + r_config_set_i(core_->config, "asm.bits", bits); } #if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE - if (!r_core_file_open (core, path.toUtf8(), R_IO_READ|rw?R_IO_WRITE:0, mapaddr)) { - eprintf ("Cannot open file\n"); - } else { + if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | rw ? R_IO_WRITE : 0, mapaddr)) + { + eprintf("Cannot open file\n"); + } + else + { // load RBin information // XXX only for sub-bins - r_core_bin_load (core, path.toUtf8(), loadaddr); - r_bin_select_idx (core_->bin, NULL, idx); + r_core_bin_load(core, path.toUtf8(), loadaddr); + r_bin_select_idx(core_->bin, NULL, idx); } #endif - } else { + } + else + { // Not loading RBin info coz va = false } r_core_hash_load(core_, path.toUtf8().constData()); - fflush (stdout); + fflush(stdout); return true; } -void QRCore::analyze(int level) { +void QRCore::analyze(int level) +{ CORE_LOCK(); - /* - * Levels - * Nivel 1: afr @ entry0 y main (afr@entry0;afr@main) - * Nivel 2: aa - * Nivel 3: aaa - * Nivel 4: aaaa - */ + /* + * Levels + * Nivel 1: afr @ entry0 y main (afr@entry0;afr@main) + * Nivel 2: aa + * Nivel 3: aaa + * Nivel 4: aaaa + */ - if (level == 1) { - r_core_cmd0 (core_, "afr@entry0;afr@main"); - } else if (level == 2) { - r_core_cmd0 (core_, "aa"); - } else if (level == 3) { - r_core_cmd0 (core_, "aaa"); - } else if (level == 4) { - r_core_cmd0 (core_, "aaaa"); + if (level == 1) + { + r_core_cmd0(core_, "afr@entry0;afr@main"); + } + else if (level == 2) + { + r_core_cmd0(core_, "aa"); + } + else if (level == 3) + { + r_core_cmd0(core_, "aaa"); + } + else if (level == 4) + { + r_core_cmd0(core_, "aaaa"); } } -void QRCore::renameFunction(QString prev_name, QString new_name) { - cmd ("afn " + new_name + " " + prev_name); +void QRCore::renameFunction(QString prev_name, QString new_name) +{ + cmd("afn " + new_name + " " + prev_name); } -void QRCore::setComment(QString addr, QString cmt) { +void QRCore::setComment(QString addr, QString cmt) +{ //r_meta_add (core->anal, 'C', addr, 1, cmt.toUtf8()); cmd("CC " + cmt + " @ " + addr); } -void QRCore::delComment(ut64 addr) { +void QRCore::delComment(ut64 addr) +{ CORE_LOCK(); - r_meta_del (core_->anal, 'C', addr, 1, NULL); + r_meta_del(core_->anal, 'C', addr, 1, NULL); //cmd (QString("CC-@")+addr); } -QList> QRCore::getComments() { - QList > ret; +QList> QRCore::getComments() +{ + QList> ret; QString comments = cmd("CC~CCu"); - for (QString line: comments.split ("\n")) { + for (QString line : comments.split("\n")) + { QStringList fields = line.split("CCu"); - if (fields.length() == 2) { + if (fields.length() == 2) + { QList tmp = QList(); tmp << fields[1].split("\"")[1].trimmed(); tmp << fields[0].trimmed(); @@ -305,20 +365,26 @@ QList> QRCore::getComments() { return ret; } -QMap>> QRCore::getNestedComments() { +QMap>> QRCore::getNestedComments() +{ QMap>> ret; QString comments = cmd("CC~CCu"); - for (QString line: comments.split ("\n")) { + for (QString line : comments.split("\n")) + { QStringList fields = line.split("CCu"); - if (fields.length() == 2) { + if (fields.length() == 2) + { QList tmp = QList(); tmp << fields[1].split("\"")[1].trimmed(); tmp << fields[0].trimmed(); QString fcn_name = this->cmdFunctionAt(fields[0].trimmed()); - if (ret.contains(fcn_name)) { + if (ret.contains(fcn_name)) + { ret[fcn_name].append(tmp); - } else { + } + else + { ret[fcn_name].append(tmp); } } @@ -326,24 +392,28 @@ QMap>> QRCore::getNestedComments() { return ret; } -void QRCore::seek(QString addr) { - if (addr.length()>0) - seek (this->math(addr.toUtf8().constData())); +void QRCore::seek(QString addr) +{ + if (addr.length() > 0) + seek(this->math(addr.toUtf8().constData())); } -void QRCore::seek(ut64 addr) { +void QRCore::seek(ut64 addr) +{ CORE_LOCK(); - r_core_seek (this->core_, addr, true); + r_core_seek(this->core_, addr, true); } -bool QRCore::tryFile(QString path, bool rw) { +bool QRCore::tryFile(QString path, bool rw) +{ CORE_LOCK(); RCoreFile *cf; int flags = R_IO_READ; if (rw) flags |= R_IO_WRITE; - cf = r_core_file_open (this->core_, path.toUtf8().constData(), flags, 0LL); - if (!cf) { - eprintf ("QRCore::tryFile: Cannot open file?\n"); + cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL); + if (!cf) + { + eprintf("QRCore::tryFile: Cannot open file?\n"); return false; } @@ -352,162 +422,219 @@ bool QRCore::tryFile(QString path, bool rw) { //r_core_file_close (this->core, cf); - sdb_bool_set (DB, "try.is_writable", is_writable, 0); - sdb_set (DB, "try.filetype", "elf.i386", 0); - sdb_set (DB, "try.filename", path.toUtf8().constData(), 0); + sdb_bool_set(DB, "try.is_writable", is_writable, 0); + sdb_set(DB, "try.filetype", "elf.i386", 0); + sdb_set(DB, "try.filename", path.toUtf8().constData(), 0); return true; } -QList QRCore::getList(const QString & type, const QString & subtype) { +QList QRCore::getList(const QString &type, const QString &subtype) +{ CORE_LOCK(); RListIter *it; QList ret = QList(); - if (type == "bin") { - if (subtype == "sections") { - QString text = cmd ("S*~^S"); - for (QString i: text.split ("\n")) { - ret << i.mid(2).replace (" ", ","); + if (type == "bin") + { + if (subtype == "sections") + { + QString text = cmd("S*~^S"); + for (QString i : text.split("\n")) + { + ret << i.mid(2).replace(" ", ","); } - } else if (subtype == "types") { + } + else if (subtype == "types") + { ret << "raw"; - auto ft = sdb_const_get (DB, "try.filetype",0); + auto ft = sdb_const_get(DB, "try.filetype", 0); if (ft && *ft) ret << ft; - } else if (subtype == "imports") { + } + else if (subtype == "imports") + { QStringList lines = this->cmd("ii").split("\n"); - foreach (QString line, lines) { + foreach (QString line, lines) + { QStringList tmp = line.split(" "); - if (tmp.length() > 2) { + if (tmp.length() > 2) + { QString final; - foreach (QString field, tmp) { + foreach (QString field, tmp) + { QString value = field.split("=")[1]; final.append(value + ","); } ret << final; } } - } else if (subtype == "entrypoints") { - if (math ("entry0") !=0) + } + else if (subtype == "entrypoints") + { + if (math("entry0") != 0) ret << "entry0"; - } else if (subtype == "relocs") { + } + else if (subtype == "relocs") + { RBinReloc *br; - if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { - QRListForeach (core_->bin->cur->o->relocs, it, RBinReloc, br) { - if (br->import) { + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) + { + QRListForeach(core_->bin->cur->o->relocs, it, RBinReloc, br) + { + if (br->import) + { // TODO: we want the offset too! - QString type = (br->additive?"ADD_":"SET_")+QString::number(br->type); - ret << QString ("0x%1,%2,%3").arg(QString::number(br->vaddr,16), type, br->import->name); - } else { + QString type = (br->additive ? "ADD_" : "SET_") + QString::number(br->type); + ret << QString("0x%1,%2,%3").arg(QString::number(br->vaddr, 16), type, br->import->name); + } + else + { // TODO: we want the offset too! - QString type = (br->additive?"ADD_":"SET_")+QString::number(br->type); - ret << QString ("0x%1,%2,reloc_%3").arg(QString::number(br->vaddr,16), type, QString::number(br->vaddr,16)); + QString type = (br->additive ? "ADD_" : "SET_") + QString::number(br->type); + ret << QString("0x%1,%2,reloc_%3").arg(QString::number(br->vaddr, 16), type, QString::number(br->vaddr, 16)); } } } - } else if (subtype == "symbols") { + } + else if (subtype == "symbols") + { RBinSymbol *bs; - if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { - QRListForeach (core_->bin->cur->o->symbols, it, RBinSymbol, bs) { - QString type = QString(bs->bind)+" "+QString(bs->type); - ret << QString ("0x%1,%2,%3").arg(QString::number(bs->vaddr,16), type, bs->name); + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) + { + QRListForeach(core_->bin->cur->o->symbols, it, RBinSymbol, bs) + { + QString type = QString(bs->bind) + " " + QString(bs->type); + ret << QString("0x%1,%2,%3").arg(QString::number(bs->vaddr, 16), type, bs->name); } /* list entrypoints as symbols too */ int n = 0; RBinAddr *entry; - QRListForeach (core_->bin->cur->o->entries, it, RBinAddr, entry) { - ret <vaddr,16),"entry","entry", QString::number(n++)); - } - } - } else if (subtype == "strings") { - RBinString *bs; - if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { - QRListForeach (core_->bin->cur->o->strings, it, RBinString, bs) { - ret << QString ("0x%1,%2").arg(QString::number(bs->vaddr,16), bs->string); + QRListForeach(core_->bin->cur->o->entries, it, RBinAddr, entry) + { + ret << QString("0x%1,%2,%3%4").arg(QString::number(entry->vaddr, 16), "entry", "entry", QString::number(n++)); } } } - } else if (type == "asm") { - if (subtype == "plugins") { + else if (subtype == "strings") + { + RBinString *bs; + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) + { + QRListForeach(core_->bin->cur->o->strings, it, RBinString, bs) + { + ret << QString("0x%1,%2").arg(QString::number(bs->vaddr, 16), bs->string); + } + } + } + } + else if (type == "asm") + { + if (subtype == "plugins") + { RAsmPlugin *ap; - QRListForeach (core_->assembler->plugins, it, RAsmPlugin, ap) { + QRListForeach(core_->assembler->plugins, it, RAsmPlugin, ap) + { ret << ap->name; } - } else if (subtype == "cpus") { + } + else if (subtype == "cpus") + { QString funcs = cmd("e asm.cpu=?"); QStringList lines = funcs.split("\n"); - for (auto cpu : lines) { + for (auto cpu : lines) + { ret << cpu; } } - } else if (type == "anal") { - if (subtype == "plugins") { + } + else if (type == "anal") + { + if (subtype == "plugins") + { RAnalPlugin *ap; - QRListForeach (core_->anal->plugins, it, RAnalPlugin, ap) { + QRListForeach(core_->anal->plugins, it, RAnalPlugin, ap) + { ret << ap->name; } - } else if (subtype == "functions") { + } + else if (subtype == "functions") + { QString funcs = cmd("afl"); QStringList lines = funcs.split("\n"); - for (auto i : lines) { - if (i != "") { - ret << i.replace(" ", ",").replace(",,",",").replace(",,",",").replace(",,",","); - } + for (auto i : lines) + { + if (i != "") + { + ret << i.replace(" ", ",").replace(",,", ",").replace(",,", ",").replace(",,", ","); + } } } - } else if (type == "flagspaces") { - QStringList lines = cmd ("fs*").split ("\n"); - for (auto i : lines) { - QStringList a = i.replace("*","").split (" "); - if (a.length()>1) + } + else if (type == "flagspaces") + { + QStringList lines = cmd("fs*").split("\n"); + for (auto i : lines) + { + QStringList a = i.replace("*", "").split(" "); + if (a.length() > 1) ret << a[1]; } - } else if (type == "flags") { - if (subtype!=NULL && subtype != "") - cmd ("fs "+subtype); - else cmd ("fs *"); + } + else if (type == "flags") + { + if (subtype != NULL && subtype != "") + cmd("fs " + subtype); + else cmd("fs *"); QString flags = cmd("f*"); QStringList lines = flags.split("\n"); - for (auto i : lines) { - if (i[0]!=0&&i[1]=='s') continue; // skip 'fs ..' + for (auto i : lines) + { + if (i[0] != 0 && i[1] == 's') continue; // skip 'fs ..' ret << i.mid(2).replace(" ", ","); } } return ret; } -ut64 QRCore::math(const QString &expr) { +ut64 QRCore::math(const QString &expr) +{ CORE_LOCK(); - return r_num_math (this->core_?this->core_->num:NULL, expr.toUtf8().constData()); + return r_num_math(this->core_ ? this->core_->num : NULL, expr.toUtf8().constData()); } -int QRCore::fcnCyclomaticComplexity(ut64 addr) { +int QRCore::fcnCyclomaticComplexity(ut64 addr) +{ CORE_LOCK(); - RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr,addr); + RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr); if (fcn) return r_anal_fcn_cc(fcn); return 0; } -int QRCore::fcnBasicBlockCount(ut64 addr) { +int QRCore::fcnBasicBlockCount(ut64 addr) +{ CORE_LOCK(); //RAnalFunction *fcn = r_anal_get_fcn_at (core_->anal, addr, addr); - RAnalFunction *fcn = r_anal_get_fcn_in (core_->anal, addr, 0); - if (fcn) { - return r_list_length (fcn->bbs); + RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); + if (fcn) + { + return r_list_length(fcn->bbs); } return 0; } -int QRCore::fcnEndBbs(QString addr) { +int QRCore::fcnEndBbs(QString addr) +{ CORE_LOCK(); bool ok; int offset = addr.toLong(&ok, 16); - RAnalFunction *fcn = r_anal_get_fcn_in (core_->anal, offset, 0); - if (fcn) { + RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, offset, 0); + if (fcn) + { QString tmp = this->cmd("afi @ " + addr + " ~end-bbs").split("\n")[0]; - if (tmp.contains(":")) { + if (tmp.contains(":")) + { QString endbbs = tmp.split(": ")[1]; return endbbs.toInt(); } @@ -516,31 +643,37 @@ int QRCore::fcnEndBbs(QString addr) { return 0; } -QString QRCore::itoa(ut64 num, int rdx) { +QString QRCore::itoa(ut64 num, int rdx) +{ return QString::number(num, rdx); } -QString QRCore::config(const QString &k, const QString &v) { +QString QRCore::config(const QString &k, const QString &v) +{ CORE_LOCK(); QByteArray key = k.toUtf8(); - if (v!=NULL) { - r_config_set (core_->config, key.constData(), v.toUtf8().constData()); + if (v != NULL) + { + r_config_set(core_->config, key.constData(), v.toUtf8().constData()); return NULL; } - return QString(r_config_get (core_->config, key.constData())); + return QString(r_config_get(core_->config, key.constData())); } -int QRCore::config(const QString &k, int v) { +int QRCore::config(const QString &k, int v) +{ CORE_LOCK(); QByteArray key = k.toUtf8(); - if (v!=-1) { - r_config_set_i (core_->config, key.constData(), v); + if (v != -1) + { + r_config_set_i(core_->config, key.constData(), v); return 0; } - return r_config_get_i (core_->config, key.constData()); + return r_config_get_i(core_->config, key.constData()); } -void QRCore::setOptions(QString key) { +void QRCore::setOptions(QString key) +{ QNOTUSED(key); // va @@ -552,46 +685,53 @@ void QRCore::setOptions(QString key) { // anal plugin } -void QRCore::setCPU (QString arch, QString cpu, int bits, bool temporary=false) { - config ("asm.arch", arch); - config ("asm.cpu", cpu); - config ("asm.bits", bits); - if (!temporary) { +void QRCore::setCPU(QString arch, QString cpu, int bits, bool temporary = false) +{ + config("asm.arch", arch); + config("asm.cpu", cpu); + config("asm.bits", bits); + if (!temporary) + { default_arch = arch; default_cpu = cpu; default_bits = bits; } } -void QRCore::setDefaultCPU() { - config ("asm.arch", default_arch); - config ("asm.cpu", default_cpu); - config ("asm.bits", QString::number(default_bits)); +void QRCore::setDefaultCPU() +{ + config("asm.arch", default_arch); + config("asm.cpu", default_cpu); + config("asm.bits", QString::number(default_bits)); } -QString QRCore::assemble(const QString &code) { +QString QRCore::assemble(const QString &code) +{ CORE_LOCK(); - RAsmCode *ac = r_asm_massemble (core_->assembler, code.toUtf8().constData()); + RAsmCode *ac = r_asm_massemble(core_->assembler, code.toUtf8().constData()); QString hex(ac != nullptr ? ac->buf_hex : ""); - r_asm_code_free (ac); + r_asm_code_free(ac); return hex; } -QString QRCore::disassemble(const QString &hex) { +QString QRCore::disassemble(const QString &hex) +{ CORE_LOCK(); RAsmCode *ac = r_asm_mdisassemble_hexstr(core_->assembler, hex.toUtf8().constData()); - QString code = QString (ac != nullptr ? ac->buf_asm : ""); - r_asm_code_free (ac); + QString code = QString(ac != nullptr ? ac->buf_asm : ""); + r_asm_code_free(ac); return code; } -RAnalFunction* QRCore::functionAt(ut64 addr) { +RAnalFunction *QRCore::functionAt(ut64 addr) +{ CORE_LOCK(); //return r_anal_fcn_find (core_->anal, addr, addr); - return r_anal_get_fcn_in (core_->anal, addr, 0); + return r_anal_get_fcn_in(core_->anal, addr, 0); } -QString QRCore::cmdFunctionAt(QString addr) { +QString QRCore::cmdFunctionAt(QString addr) +{ QString ret; //afi~name:1[1] @ 0x08048e44 //ret = cmd("afi~name[1] @ " + addr); @@ -616,13 +756,16 @@ ulong QRCore::get_baddr() QList> QRCore::get_exec_sections() { - QList > ret; + QList> ret; - QString text = cmd ("S*~^S"); - for (QString line: text.split ("\n")) { + QString text = cmd("S*~^S"); + for (QString line : text.split("\n")) + { QStringList fields = line.split(" "); - if (fields.length() == 7) { - if (fields[6].contains("x")) { + if (fields.length() == 7) + { + if (fields[6].contains("x")) + { QList tmp = QList(); tmp << fields[2]; tmp << fields[3]; @@ -634,21 +777,25 @@ QList> QRCore::get_exec_sections() return ret; } -QString QRCore::getOffsetInfo(QString addr) { +QString QRCore::getOffsetInfo(QString addr) +{ return cmd("ao @ " + addr); } -QString QRCore::getOffsetJump(QString addr) { +QString QRCore::getOffsetJump(QString addr) +{ QString ret = ""; ret = cmd("ao @" + addr + "~jump[1]"); return ret; } -QString QRCore::getDecompiledCode(QString addr) { +QString QRCore::getDecompiledCode(QString addr) +{ return cmd("pdc @ " + addr); } -QString QRCore::getFileInfo() { +QString QRCore::getFileInfo() +{ QString info; info = cmd("ij"); @@ -656,7 +803,8 @@ QString QRCore::getFileInfo() { return info; } -QStringList QRCore::getStats() { +QStringList QRCore::getStats() +{ QStringList stats; cmd("fs functions"); stats << cmd("f~?").trimmed(); @@ -678,7 +826,8 @@ QStringList QRCore::getStats() { return stats; } -QString QRCore::getSimpleGraph(QString function) { +QString QRCore::getSimpleGraph(QString function) +{ // New styles QString graph = "graph [bgcolor=invis, splines=polyline];"; @@ -700,7 +849,8 @@ QString QRCore::getSimpleGraph(QString function) { return dot; } -void QRCore::getOpcodes() { +void QRCore::getOpcodes() +{ QString opcodes = cmd("?O"); this->opcodes = opcodes.split("\n"); // Remove the last empty element @@ -710,10 +860,11 @@ void QRCore::getOpcodes() { this->regs.removeLast(); } -void QRCore::setSettings() { +void QRCore::setSettings() +{ config("scr.color", "false"); - config("scr.interactive","false"); - config("asm.lines","false"); + config("scr.interactive", "false"); + config("asm.lines", "false"); // Intredazting... //config("asm.linesright", "true"); //config("asm.lineswidth", "15"); @@ -735,7 +886,7 @@ void QRCore::setSettings() { config("anal.hasnext", "true"); config("asm.fcncalls", "false"); config("asm.calls", "false"); - config("asm.lines.call","false"); + config("asm.lines.call", "false"); config("asm.flgoff", "true"); config("anal.autoname", "true"); @@ -752,7 +903,7 @@ void QRCore::setSettings() { //config("asm.flags", "false"); // Add with default true in future // Used by the HTML5 graph - config("http.cors","true"); + config("http.cors", "true"); config("http.sandbox", "false"); //config("http.port", "14170"); diff --git a/src/qrcore.h b/src/qrcore.h index 55513fca..88bb5158 100644 --- a/src/qrcore.h +++ b/src/qrcore.h @@ -29,16 +29,16 @@ class RCoreLocked { - RCore* core; + RCore *core; public: - explicit RCoreLocked(RCore* core); - RCoreLocked(const RCoreLocked&) = delete; - RCoreLocked& operator=(const RCoreLocked&) = delete; - RCoreLocked(RCoreLocked&&); + explicit RCoreLocked(RCore *core); + RCoreLocked(const RCoreLocked &) = delete; + RCoreLocked &operator=(const RCoreLocked &) = delete; + RCoreLocked(RCoreLocked &&); ~RCoreLocked(); - operator RCore*() const; - RCore* operator->() const; + operator RCore *() const; + RCore *operator->() const; }; #define QNOTUSED(x) do { (void)(x); } while ( 0 ); @@ -62,23 +62,23 @@ public: void setComment(QString addr, QString cmt); void delComment(ut64 addr); QList> getComments(); - QMap > > getNestedComments(); + QMap>> getNestedComments(); void setOptions(QString key); - bool loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, bool rw, int va, int bits, int idx=0, bool loadbin=false); + bool loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, bool rw, int va, int bits, int idx = 0, bool loadbin = false); bool tryFile(QString path, bool rw); void analyze(int level); void seek(QString addr); void seek(ut64 addr); ut64 math(const QString &expr); - QString itoa(ut64 num, int rdx=16); - QString config(const QString &k, const QString &v=NULL); + QString itoa(ut64 num, int rdx = 16); + QString config(const QString &k, const QString &v = NULL); int config(const QString &k, int v); - QList getList(const QString & type, const QString & subtype=""); + QList getList(const QString &type, const QString &subtype = ""); QString assemble(const QString &code); QString disassemble(const QString &code); void setDefaultCPU(); void setCPU(QString arch, QString cpu, int bits, bool temporary); - RAnalFunction* functionAt(ut64 addr); + RAnalFunction *functionAt(ut64 addr); QString cmdFunctionAt(QString addr); /* sdb */ QList sdbList(QString path); diff --git a/src/qrdisasm.cpp b/src/qrdisasm.cpp index c0caffb5..52cdc4c0 100644 --- a/src/qrdisasm.cpp +++ b/src/qrdisasm.cpp @@ -8,11 +8,12 @@ QRDisasm::QRDisasm(QRCore *core) this->core = core; } -bool QRDisasm::disassembleAt (ut64 addr, QRDisasmOption opt, QRDisasmRow &dr) { +bool QRDisasm::disassembleAt(ut64 addr, QRDisasmOption opt, QRDisasmRow &dr) +{ QNOTUSED(addr); QNOTUSED(opt); QNOTUSED(dr); - printf ("FUCK\n"); + printf("FUCK\n"); return false; } diff --git a/src/qrdisasm.h b/src/qrdisasm.h index c9f40c03..8754a5c5 100644 --- a/src/qrdisasm.h +++ b/src/qrdisasm.h @@ -3,19 +3,21 @@ #include -enum QRDisasmDataType { +enum QRDisasmDataType +{ STRING = 'z', STRUCT = 's', DATA = 'd', }; -enum QRDisasmOption { - DWARF = 1<<1, - REFS = 1<<2, - ESIL = 1<<3, - HEXPAIRS = 1<<4, - COMMENT = 1<<5, +enum QRDisasmOption +{ + DWARF = 1 << 1, + REFS = 1 << 2, + ESIL = 1 << 3, + HEXPAIRS = 1 << 4, + COMMENT = 1 << 5, }; class QRDisasmRow @@ -64,7 +66,7 @@ class QRDisasm Sdb *db; public: QRDisasm(QRCore *core); - bool disassembleAt (ut64 addr, QRDisasmOption opt, QRDisasmRow &dr); + bool disassembleAt(ut64 addr, QRDisasmOption opt, QRDisasmRow &dr); // high level api for the disasm thing to manage comments, xrefs, etc //next(); //prev(); diff --git a/src/webserverthread.cpp b/src/webserverthread.cpp index 8be19e3f..91f30dbc 100644 --- a/src/webserverthread.cpp +++ b/src/webserverthread.cpp @@ -12,7 +12,8 @@ WebServerThread::WebServerThread(QRCore *core, QObject *parent) : WebServerThread::~WebServerThread() { - if (isRunning()) { + if (isRunning()) + { quit(); wait(); } @@ -22,7 +23,8 @@ void WebServerThread::startServer() { assert(nullptr != core); - if (!isRunning() && !started) { + if (!isRunning() && !started) + { QThread::start(); } } @@ -43,7 +45,8 @@ bool WebServerThread::isStarted() const return started; } -void WebServerThread::run() { +void WebServerThread::run() +{ QMutexLocker locker(&mutex); if (core == nullptr) @@ -63,13 +66,16 @@ void WebServerThread::toggleWebServer() // "=h*", "", "restart current webserver", // "=h&", " port", "start http server in background)", - if (started) { + if (started) + { // after this the only reaction to this commands is: // sandbox: connect disabled // and the webserver is still running // TODO: find out why core->cmd("=h-"); - } else { + } + else + { core->cmd("=h&"); } diff --git a/src/widgets/banned.h b/src/widgets/banned.h index 220ca91b..61a132a3 100644 --- a/src/widgets/banned.h +++ b/src/widgets/banned.h @@ -9,18 +9,18 @@ class Banned : public QObject public: QString banned = "[a-zA-Z_.]*(system|strcpy|strcpyA|strcpyW|wcscpy|_tcscpy|_mbscpy|StrCpy|StrCpyA|StrCpyW|lstrcpy|lstrcpyA|lstrcpyW" \ - "|_tccpy|_mbccpy|_ftcscpy|strcat|strcatA|strcatW|wcscat|_tcscat|_mbscat|StrCat|StrCatA|StrCatW|lstrcat|lstrcatA|" \ - "lstrcatW|StrCatBuff|StrCatBuffA|StrCatBuffW|StrCatChainW|_tccat|_mbccat|_ftcscat|sprintfW|sprintfA|wsprintf|wsprintfW|" \ - "wsprintfA|sprintf|swprintf|_stprintf|wvsprintf|wvsprintfA|wvsprintfW|vsprintf|_vstprintf|vswprintf|strncpy|wcsncpy|" \ - "_tcsncpy|_mbsncpy|_mbsnbcpy|StrCpyN|StrCpyNA|StrCpyNW|StrNCpy|strcpynA|StrNCpyA|StrNCpyW|lstrcpyn|lstrcpynA|lstrcpynW|" \ - "strncat|wcsncat|_tcsncat|_mbsncat|_mbsnbcat|StrCatN|StrCatNA|StrCatNW|StrNCat|StrNCatA|StrNCatW|lstrncat|lstrcatnA|" \ - "lstrcatnW|lstrcatn|gets|_getts|_gettws|IsBadWritePtr|IsBadHugeWritePtr|IsBadReadPtr|IsBadHugeReadPtr|IsBadCodePtr|" \ - "IsBadStringPtr|memcpy|RtlCopyMemory|CopyMemory|wmemcpy|wnsprintf|wnsprintfA|wnsprintfW|_snwprintf|_snprintf|_sntprintf|" \ - "_vsnprintf|vsnprintf|_vsnwprintf|_vsntprintf|wvnsprintf|wvnsprintfA|wvnsprintfW|strtok|_tcstok|wcstok|_mbstok|makepath|" \ - "_tmakepath| _makepath|_wmakepath|_splitpath|_tsplitpath|_wsplitpath|scanf|wscanf|_tscanf|sscanf|swscanf|_stscanf|snscanf|" \ - "snwscanf|_sntscanf|_itoa|_itow|_i64toa|_i64tow|_ui64toa|_ui64tot|_ui64tow|_ultoa|_ultot|_ultow|CharToOem|CharToOemA|CharToOemW|" \ - "OemToChar|OemToCharA|OemToCharW|CharToOemBuffA|CharToOemBuffW|alloca|_alloca|strlen|wcslen|_mbslen|_mbstrlen|StrLen|lstrlen|" \ - "ChangeWindowMessageFilter)"; + "|_tccpy|_mbccpy|_ftcscpy|strcat|strcatA|strcatW|wcscat|_tcscat|_mbscat|StrCat|StrCatA|StrCatW|lstrcat|lstrcatA|" \ + "lstrcatW|StrCatBuff|StrCatBuffA|StrCatBuffW|StrCatChainW|_tccat|_mbccat|_ftcscat|sprintfW|sprintfA|wsprintf|wsprintfW|" \ + "wsprintfA|sprintf|swprintf|_stprintf|wvsprintf|wvsprintfA|wvsprintfW|vsprintf|_vstprintf|vswprintf|strncpy|wcsncpy|" \ + "_tcsncpy|_mbsncpy|_mbsnbcpy|StrCpyN|StrCpyNA|StrCpyNW|StrNCpy|strcpynA|StrNCpyA|StrNCpyW|lstrcpyn|lstrcpynA|lstrcpynW|" \ + "strncat|wcsncat|_tcsncat|_mbsncat|_mbsnbcat|StrCatN|StrCatNA|StrCatNW|StrNCat|StrNCatA|StrNCatW|lstrncat|lstrcatnA|" \ + "lstrcatnW|lstrcatn|gets|_getts|_gettws|IsBadWritePtr|IsBadHugeWritePtr|IsBadReadPtr|IsBadHugeReadPtr|IsBadCodePtr|" \ + "IsBadStringPtr|memcpy|RtlCopyMemory|CopyMemory|wmemcpy|wnsprintf|wnsprintfA|wnsprintfW|_snwprintf|_snprintf|_sntprintf|" \ + "_vsnprintf|vsnprintf|_vsnwprintf|_vsntprintf|wvnsprintf|wvnsprintfA|wvnsprintfW|strtok|_tcstok|wcstok|_mbstok|makepath|" \ + "_tmakepath| _makepath|_wmakepath|_splitpath|_tsplitpath|_wsplitpath|scanf|wscanf|_tscanf|sscanf|swscanf|_stscanf|snscanf|" \ + "snwscanf|_sntscanf|_itoa|_itow|_i64toa|_i64tow|_ui64toa|_ui64tot|_ui64tow|_ultoa|_ultot|_ultow|CharToOem|CharToOemA|CharToOemW|" \ + "OemToChar|OemToCharA|OemToCharW|CharToOemBuffA|CharToOemBuffW|alloca|_alloca|strlen|wcslen|_mbslen|_mbstrlen|StrLen|lstrlen|" \ + "ChangeWindowMessageFilter)"; }; diff --git a/src/widgets/codegraphic.cpp b/src/widgets/codegraphic.cpp index 8634824a..31515fe3 100644 --- a/src/widgets/codegraphic.cpp +++ b/src/widgets/codegraphic.cpp @@ -17,7 +17,7 @@ GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) : setObjectName("codeGraphics"); setWindowTitle("Code bar"); -// setMovable(false); + // setMovable(false); setContentsMargins(0, 0, 0, 0); // If line below is used, with the dark theme the paintEvent is not called // and the result is wrong. Something to do with overwriting the style sheet :/ @@ -41,21 +41,23 @@ GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) : //addWidget(addsCombo); } -void GraphicsBar::paintEvent(QPaintEvent *event) { +void GraphicsBar::paintEvent(QPaintEvent *event) +{ QNOTUSED(event); QPainter painter(this); this->fillData(); } -void GraphicsBar::fillData() { +void GraphicsBar::fillData() +{ // Prepare the graph scene int w = this->codeGraphic->width(); int h = this->codeGraphic->height(); QGraphicsScene *scene = new QGraphicsScene(); - const QBrush bg = QBrush(QColor(74,74,74)); + const QBrush bg = QBrush(QColor(74, 74, 74)); scene->setBackgroundBrush(bg); this->codeGraphic->setRenderHints(0); @@ -67,10 +69,12 @@ void GraphicsBar::fillData() { QString jsonData = this->main->core->cmd("p-j"); QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8()); - if (doc.isNull()) { + if (doc.isNull()) + { qDebug() << "Invalid json in p-j command"; } - else if (doc.isObject()) { + else if (doc.isObject()) + { //get the jsonObject QJsonObject jObject = doc.object(); @@ -82,34 +86,42 @@ void GraphicsBar::fillData() { int block = mainMap["blocksize"].toInt(); int size = (to - from); int num = size / block; - if (num < 1) { + if (num < 1) + { num = 1; } int graph_block = w / num; int counter = 0; - for (auto i : mainMap["blocks"].toList()) { + for (auto i : mainMap["blocks"].toList()) + { QMap map = i.toMap(); - if (map.empty()) { + if (map.empty()) + { // Fill empty color // addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush()) //scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(252, 249, 190))); - QGraphicsRectItem* rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block ,h); + QGraphicsRectItem *rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block, h); rect->setPen(Qt::NoPen); rect->setBrush(QBrush(QColor(252, 249, 190))); rect->setToolTip("Data"); scene->addItem(rect); - } else { + } + else + { // Fill type of color //scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(69, 104, 229))); - QGraphicsRectItem* rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block ,h); + QGraphicsRectItem *rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block, h); rect->setPen(Qt::NoPen); - if (i.toMap()["functions"].toInt() == 0) { + if (i.toMap()["functions"].toInt() == 0) + { rect->setBrush(QBrush(QColor(190, 190, 190))); - } else { + } + else + { rect->setBrush(QBrush(QColor(69, 104, 229))); } - rect->setToolTip("Offset: 0x" + QString::number(i.toMap()["offset"].toInt(), 16) + "\nFunctions: " + QString::number( i.toMap()["functions"].toInt()) + "\nFlags: " + QString::number( i.toMap()["flags"].toInt())); + rect->setToolTip("Offset: 0x" + QString::number(i.toMap()["offset"].toInt(), 16) + "\nFunctions: " + QString::number(i.toMap()["functions"].toInt()) + "\nFlags: " + QString::number(i.toMap()["flags"].toInt())); scene->addItem(rect); } counter += 1; diff --git a/src/widgets/commentswidget.cpp b/src/widgets/commentswidget.cpp index acfeb995..7f7a9e17 100644 --- a/src/widgets/commentswidget.cpp +++ b/src/widgets/commentswidget.cpp @@ -45,13 +45,15 @@ void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *it QString offset = item->text(1); QString name = item->text(2); this->main->add_debug_output(offset + ": " + name); - this->main->seek (offset, name); + this->main->seek(offset, name); } -void CommentsWidget::refreshTree() { +void CommentsWidget::refreshTree() +{ this->commentsTreeWidget->clear(); QList> comments = this->main->core->getComments(); - for (QList comment: comments) { + for (QList comment : comments) + { this->main->add_debug_output(comment[1]); QString fcn_name = this->main->core->cmdFunctionAt(comment[1]); this->main->appendRow(this->commentsTreeWidget, comment[1], fcn_name, comment[0].remove('"')); @@ -61,11 +63,13 @@ void CommentsWidget::refreshTree() { // Add nested comments this->nestedCommentsTreeWidget->clear(); QMap>> cmts = this->main->core->getNestedComments(); - for(auto cmt : cmts.keys()) { + for (auto cmt : cmts.keys()) + { QTreeWidgetItem *item = new QTreeWidgetItem(this->nestedCommentsTreeWidget); item->setText(0, cmt); QList> meow = cmts.value(cmt); - for (int i = 0; i < meow.size(); ++i) { + for (int i = 0; i < meow.size(); ++i) + { QList tmp = meow.at(i); QTreeWidgetItem *it = new QTreeWidgetItem(); it->setText(0, tmp[1]); @@ -95,10 +99,13 @@ void CommentsWidget::showTitleContextMenu(const QPoint &pt) menu->addAction(ui->actionHorizontal); menu->addAction(ui->actionVertical); - if (ui->tabWidget->currentIndex() == 0) { + if (ui->tabWidget->currentIndex() == 0) + { ui->actionHorizontal->setChecked(true); ui->actionVertical->setChecked(false); - } else { + } + else + { ui->actionVertical->setChecked(true); ui->actionHorizontal->setChecked(false); } @@ -119,17 +126,23 @@ void CommentsWidget::on_actionVertical_triggered() ui->tabWidget->setCurrentIndex(1); } -bool CommentsWidget::eventFilter(QObject *obj, QEvent *event) { - if (this->main->responsive) { - if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { - QResizeEvent *resizeEvent = static_cast(event); +bool CommentsWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (this->main->responsive) + { + if (event->type() == QEvent::Resize && obj == this && this->isVisible()) + { + QResizeEvent *resizeEvent = static_cast(event); //qDebug("Dock Resized (New Size) - Width: %d Height: %d", // resizeEvent->size().width(), // resizeEvent->size().height()); - if (resizeEvent->size().width() >= resizeEvent->size().height()) { + if (resizeEvent->size().width() >= resizeEvent->size().height()) + { // Set horizontal view (list) this->on_actionHorizontal_triggered(); - } else { + } + else + { // Set vertical view (Tree) this->on_actionVertical_triggered(); } diff --git a/src/widgets/commentswidget.h b/src/widgets/commentswidget.h index 28e8b6e8..b5f29e92 100644 --- a/src/widgets/commentswidget.h +++ b/src/widgets/commentswidget.h @@ -7,8 +7,9 @@ class MainWindow; -namespace Ui { -class CommentsWidget; +namespace Ui +{ + class CommentsWidget; } class CommentsWidget : public QDockWidget diff --git a/src/widgets/dashboard.cpp b/src/widgets/dashboard.cpp index 0f467d59..7941ae16 100644 --- a/src/widgets/dashboard.cpp +++ b/src/widgets/dashboard.cpp @@ -26,7 +26,8 @@ Dashboard::~Dashboard() delete ui; } -void Dashboard::updateContents() { +void Dashboard::updateContents() +{ // Parse and add JSON file info QString info = this->main->core->getFileInfo(); @@ -46,8 +47,8 @@ void Dashboard::updateContents() { this->ui->formatEdit->setText(item["format"].toString()); this->ui->modeEdit->setText(item["mode"].toString()); this->ui->typeEdit->setText(item["type"].toString()); - this->ui->sizeEdit->setText( QString::number(item["size"].toDouble()) ); - this->ui->fdEdit->setText( QString::number(item["fd"].toDouble()) ); + this->ui->sizeEdit->setText(QString::number(item["size"].toDouble())); + this->ui->fdEdit->setText(QString::number(item["fd"].toDouble())); this->ui->archEdit->setText(item2["arch"].toString()); this->ui->langEdit->setText(item2["lang"].toString().toUpper()); @@ -57,51 +58,75 @@ void Dashboard::updateContents() { this->ui->subsysEdit->setText(item2["subsys"].toString()); this->ui->endianEdit->setText(item2["endian"].toString()); this->ui->compiledEdit->setText(item2["compiled"].toString()); - this->ui->bitsEdit->setText( QString::number(item2["bits"].toDouble()) ); + this->ui->bitsEdit->setText(QString::number(item2["bits"].toDouble())); - this->ui->baddrEdit->setText( QString::number(item2["baddr"].toDouble()) ); + this->ui->baddrEdit->setText(QString::number(item2["baddr"].toDouble())); - if ( item2["va"].toBool() == true) { + if (item2["va"].toBool() == true) + { this->ui->vaEdit->setText("True"); - } else { + } + else + { this->ui->vaEdit->setText("False"); } - if ( item2["canary"].toBool() == true) { + if (item2["canary"].toBool() == true) + { this->ui->canaryEdit->setText("True"); - } else { + } + else + { this->ui->canaryEdit->setText("False"); this->ui->canaryEdit->setStyleSheet("color: rgb(255, 0, 0);"); } - if ( item2["crypto"].toBool() == true) { + if (item2["crypto"].toBool() == true) + { this->ui->cryptoEdit->setText("True"); - } else { + } + else + { this->ui->cryptoEdit->setText("False"); } - if ( item2["nx"].toBool() == true) { + if (item2["nx"].toBool() == true) + { this->ui->nxEdit->setText("True"); - } else { + } + else + { this->ui->nxEdit->setText("False"); this->ui->nxEdit->setStyleSheet("color: rgb(255, 0, 0);"); } - if ( item2["pic"].toBool() == true) { + if (item2["pic"].toBool() == true) + { this->ui->picEdit->setText("True"); - } else { + } + else + { this->ui->picEdit->setText("False"); this->ui->picEdit->setStyleSheet("color: rgb(255, 0, 0);"); } - if ( item2["static"].toBool() == true) { + if (item2["static"].toBool() == true) + { this->ui->staticEdit->setText("True"); - } else { + } + else + { this->ui->staticEdit->setText("False"); } - if ( item2["stripped"].toBool() == true) { + if (item2["stripped"].toBool() == true) + { this->ui->strippedEdit->setText("True"); - } else { + } + else + { this->ui->strippedEdit->setText("False"); } - if ( item2["relocs"].toBool() == true) { + if (item2["relocs"].toBool() == true) + { this->ui->relocsEdit->setText("True"); - } else { + } + else + { this->ui->relocsEdit->setText("False"); } @@ -113,17 +138,19 @@ void Dashboard::updateContents() { QString libs = this->main->core->cmd("il"); QStringList lines = libs.split("\n", QString::SkipEmptyParts); - if (! lines.isEmpty()) { + if (! lines.isEmpty()) + { lines.removeFirst(); lines.removeLast(); } - foreach (QString lib, lines) { + foreach (QString lib, lines) + { QLabel *label = new QLabel(this); label->setText(lib); label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); ui->verticalLayout_2->addWidget(label); } - QSpacerItem *spacer = new QSpacerItem(1,1, QSizePolicy::Fixed, QSizePolicy::Expanding); + QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding); ui->verticalLayout_2->addSpacerItem(spacer); // Add entropy value @@ -135,8 +162,9 @@ void Dashboard::updateContents() { // Add data to HTML graphs (stats) QFile html(":/html/stats.html"); - if(!html.open(QIODevice::ReadOnly)) { - QMessageBox::information(0,"error",html.errorString()); + if (!html.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", html.errorString()); } QString code = html.readAll(); html.close(); @@ -147,8 +175,9 @@ void Dashboard::updateContents() { // Add data to polar graph QFile html2(":/html/radar.html"); - if(!html2.open(QIODevice::ReadOnly)) { - QMessageBox::information(0,"error",html2.errorString()); + if (!html2.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", html2.errorString()); } QString code2 = html2.readAll(); html2.close(); diff --git a/src/widgets/dashboard.h b/src/widgets/dashboard.h index e5f6c585..ac1f1b57 100644 --- a/src/widgets/dashboard.h +++ b/src/widgets/dashboard.h @@ -5,8 +5,9 @@ class MainWindow; -namespace Ui { -class Dashboard; +namespace Ui +{ + class Dashboard; } class Dashboard : public QDockWidget diff --git a/src/widgets/flagswidget.h b/src/widgets/flagswidget.h index 8ae71d38..5dab4b08 100644 --- a/src/widgets/flagswidget.h +++ b/src/widgets/flagswidget.h @@ -7,8 +7,9 @@ class MainWindow; -namespace Ui { -class FlagsWidget; +namespace Ui +{ + class FlagsWidget; } class FlagsWidget : public QDockWidget diff --git a/src/widgets/functionswidget.cpp b/src/widgets/functionswidget.cpp index c2b6cfaa..31f87178 100644 --- a/src/widgets/functionswidget.cpp +++ b/src/widgets/functionswidget.cpp @@ -47,17 +47,20 @@ FunctionsWidget::~FunctionsWidget() delete ui; } -void FunctionsWidget::fillFunctions() { +void FunctionsWidget::fillFunctions() +{ this->functionsTreeWidget->clear(); ui->nestedFunctionsTree->clear(); - for (auto i: this->main->core->getList ("anal", "functions")) { - QStringList a = i.split (","); + for (auto i : this->main->core->getList("anal", "functions")) + { + QStringList a = i.split(","); // off,sz,unk,name // "0x0804ada3,1,13,,fcn.0804ada3" // "0x0804ad4a,6,,1,,fcn.0804ad4a" - if (a.length() == 5) { + if (a.length() == 5) + { // Add list function - this->main->appendRow(this->functionsTreeWidget,a[0],a[1],a[4]); + this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[4]); // Add nested function QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedFunctionsTree); item->setText(0, a[4]); @@ -68,9 +71,11 @@ void FunctionsWidget::fillFunctions() { off_it->setText(0, "Size: " + a[1]); item->addChild(off_it); ui->nestedFunctionsTree->addTopLevelItem(item); - } else if (a.length() == 6) { + } + else if (a.length() == 6) + { // Add list function - this->main->appendRow(this->functionsTreeWidget,a[0],a[1],a[5]); + this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[5]); // Add nested function QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedFunctionsTree); item->setText(0, a[5]); @@ -81,7 +86,9 @@ void FunctionsWidget::fillFunctions() { off_it->setText(0, "Size: " + a[1]); item->addChild(off_it); ui->nestedFunctionsTree->addTopLevelItem(item); - } else { + } + else + { qDebug() << "fillFunctions()" << a; } } @@ -113,27 +120,33 @@ void FunctionsWidget::showFunctionsContextMenu(const QPoint &pt) menu->addSeparator(); menu->addAction(ui->action_References); - if(ui->tabWidget->currentIndex() == 0) { + if (ui->tabWidget->currentIndex() == 0) + { this->functionsTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); menu->exec(ui->functionsTreeWidget->mapToGlobal(pt)); - } else { + } + else + { ui->nestedFunctionsTree->setContextMenuPolicy(Qt::CustomContextMenu); menu->exec(ui->nestedFunctionsTree->mapToGlobal(pt)); } delete menu; } -void FunctionsWidget::refreshTree() { +void FunctionsWidget::refreshTree() +{ this->functionsTreeWidget->clear(); ui->nestedFunctionsTree->clear(); - for (auto i: this->main->core->getList ("anal", "functions")) { - QStringList a = i.split (","); + for (auto i : this->main->core->getList("anal", "functions")) + { + QStringList a = i.split(","); // off,sz,unk,name // "0x0804ada3,1,13,,fcn.0804ada3" // "0x0804ad4a,6,,1,,fcn.0804ad4a" - if (a.length() == 5) { + if (a.length() == 5) + { // Add list function - this->main->appendRow(this->functionsTreeWidget,a[0],a[1],a[4]); + this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[4]); // Add nested function QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedFunctionsTree); item->setText(0, a[4]); @@ -144,9 +157,11 @@ void FunctionsWidget::refreshTree() { off_it->setText(0, "Size: " + a[1]); item->addChild(off_it); ui->nestedFunctionsTree->addTopLevelItem(item); - } else if (a.length() == 6) { + } + else if (a.length() == 6) + { // Add list function - this->main->appendRow(this->functionsTreeWidget,a[0],a[1],a[5]); + this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[5]); // Add nested function QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedFunctionsTree); item->setText(0, a[5]); @@ -157,7 +172,9 @@ void FunctionsWidget::refreshTree() { off_it->setText(0, "Size: " + a[1]); item->addChild(off_it); ui->nestedFunctionsTree->addTopLevelItem(item); - } else { + } + else + { qDebug() << "fillFunctions()" << a; } } @@ -172,18 +189,22 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered() { QString fcn_name = ""; // Create dialog - CommentsDialog* c = new CommentsDialog(this); + CommentsDialog *c = new CommentsDialog(this); // Get selected item in functions tree widget - if(ui->tabWidget->currentIndex() == 0) { + if (ui->tabWidget->currentIndex() == 0) + { QList selected_rows = ui->functionsTreeWidget->selectedItems(); // Get selected function name fcn_name = selected_rows.first()->text(3); - } else { + } + else + { QList selected_rows = ui->nestedFunctionsTree->selectedItems(); // Get selected function name fcn_name = selected_rows.first()->text(0); } - if (c->exec()) { + if (c->exec()) + { // Get new function name QString comment = c->getComment(); this->main->add_debug_output("Comment: " + comment + " at: " + fcn_name); @@ -196,15 +217,17 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered() this->main->refreshComments(); } -void FunctionsWidget::addTooltips() { +void FunctionsWidget::addTooltips() +{ // Add comments to list functions - QList clist = this->functionsTreeWidget->findItems("*", Qt::MatchWildcard, 3); - foreach(QTreeWidgetItem* item, clist) + QList clist = this->functionsTreeWidget->findItems("*", Qt::MatchWildcard, 3); + foreach (QTreeWidgetItem *item, clist) { QString name = item->text(3); QList info = this->main->core->cmd("afi @ " + name).split("\n"); - if (info.length() > 2) { + if (info.length() > 2) + { QString size = info[4].split(" ")[1]; QString complex = info[8].split(" ")[1]; QString bb = info[11].split(" ")[1]; @@ -213,17 +236,18 @@ void FunctionsWidget::addTooltips() { "\n Basic blocks: " + bb + "\n\nDisasm preview:\n\n" + this->main->core->cmd("pdi 10 @ " + name) + "\nStrings:\n\n" + this->main->core->cmd("pdsf @ " + name)); - //"\nStrings:\n\n" + this->main->core->cmd("pds @ " + name + "!$F")); + //"\nStrings:\n\n" + this->main->core->cmd("pds @ " + name + "!$F")); } } // Add comments to nested functions - QList nlist = ui->nestedFunctionsTree->findItems("*", Qt::MatchWildcard, 0); - foreach(QTreeWidgetItem* item, nlist) + QList nlist = ui->nestedFunctionsTree->findItems("*", Qt::MatchWildcard, 0); + foreach (QTreeWidgetItem *item, nlist) { QString name = item->text(0); QList info = this->main->core->cmd("afi @ " + name).split("\n"); - if (info.length() > 2) { + if (info.length() > 2) + { QString size = info[4].split(" ")[1]; QString complex = info[8].split(" ")[1]; QString bb = info[11].split(" ")[1]; @@ -232,7 +256,7 @@ void FunctionsWidget::addTooltips() { "\n Basic blocks: " + bb + "\n\nDisasm preview:\n\n" + this->main->core->cmd("pdi 10 @ " + name) + "\nStrings:\n\n" + this->main->core->cmd("pdsf @ " + name)); - //"\nStrings:\n\n" + this->main->core->cmd("pds @ " + name + "!$F")); + //"\nStrings:\n\n" + this->main->core->cmd("pds @ " + name + "!$F")); } } } @@ -240,7 +264,7 @@ void FunctionsWidget::addTooltips() { void FunctionsWidget::on_actionFunctionsRename_triggered() { // Create dialog - RenameDialog* r = new RenameDialog(this); + RenameDialog *r = new RenameDialog(this); // Get selected item in functions tree widget QList selected_rows = ui->functionsTreeWidget->selectedItems(); // Get selected function name @@ -248,7 +272,8 @@ void FunctionsWidget::on_actionFunctionsRename_triggered() // Set function name in dialog r->setFunctionName(old_name); // If user accepted - if (r->exec()) { + if (r->exec()) + { // Get new function name QString new_name = r->getFunctionName(); // Rename function in r2 core @@ -279,7 +304,7 @@ void FunctionsWidget::on_action_References_triggered() // Get function for clicked offset RAnalFunction *fcn = this->main->core->functionAt(address.toLongLong(0, 16)); - XrefsDialog* x = new XrefsDialog(this->main, this); + XrefsDialog *x = new XrefsDialog(this->main, this); x->setWindowTitle("X-Refs for function " + QString::fromUtf8(fcn->name)); // Get Refs and Xrefs @@ -288,8 +313,10 @@ void FunctionsWidget::on_action_References_triggered() // refs = calls q hace esa funcion QList refs = this->main->core->getFunctionRefs(fcn->addr, 'C'); - if (refs.size() > 0) { - for (int i = 0; i < refs.size(); ++i) { + if (refs.size() > 0) + { + for (int i = 0; i < refs.size(); ++i) + { //this->main->add_debug_output(refs.at(i)); QStringList retlist = refs.at(i).split(","); QStringList temp; @@ -304,8 +331,10 @@ void FunctionsWidget::on_action_References_triggered() // xrefs = calls a esa funcion //qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16)); QList xrefs = this->main->core->getFunctionXrefs(fcn->addr); - if (xrefs.size() > 0) { - for (int i = 0; i < xrefs.size(); ++i) { + if (xrefs.size() > 0) + { + for (int i = 0; i < xrefs.size(); ++i) + { //this->main->add_debug_output(xrefs.at(i)); QStringList retlist = xrefs.at(i).split(","); QStringList temp; @@ -328,10 +357,13 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt) menu->addAction(ui->actionHorizontal); menu->addAction(ui->actionVertical); - if (ui->tabWidget->currentIndex() == 0) { + if (ui->tabWidget->currentIndex() == 0) + { ui->actionHorizontal->setChecked(true); ui->actionVertical->setChecked(false); - } else { + } + else + { ui->actionVertical->setChecked(true); ui->actionHorizontal->setChecked(false); } @@ -363,17 +395,23 @@ void FunctionsWidget::on_nestedFunctionsTree_itemDoubleClicked(QTreeWidgetItem * this->main->memoryDock->raise(); } -bool FunctionsWidget::eventFilter(QObject *obj, QEvent *event) { - if (this->main->responsive) { - if (event->type() == QEvent::Resize && obj == this && this->isVisible() == true) { - QResizeEvent *resizeEvent = static_cast(event); +bool FunctionsWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (this->main->responsive) + { + if (event->type() == QEvent::Resize && obj == this && this->isVisible() == true) + { + QResizeEvent *resizeEvent = static_cast(event); //qDebug("Dock Resized (New Size) - Width: %d Height: %d", // resizeEvent->size().width(), // resizeEvent->size().height()); - if (resizeEvent->size().width() >= resizeEvent->size().height()) { + if (resizeEvent->size().width() >= resizeEvent->size().height()) + { // Set horizontal view (list) this->on_actionHorizontal_triggered(); - } else { + } + else + { // Set vertical view (Tree) this->on_actionVertical_triggered(); } diff --git a/src/widgets/functionswidget.h b/src/widgets/functionswidget.h index 4ef04cae..c3c65b07 100644 --- a/src/widgets/functionswidget.h +++ b/src/widgets/functionswidget.h @@ -6,8 +6,9 @@ class MainWindow; -namespace Ui { -class FunctionsWidget; +namespace Ui +{ + class FunctionsWidget; } class FunctionsWidget : public QDockWidget diff --git a/src/widgets/importswidget.cpp b/src/widgets/importswidget.cpp index fa0dd742..7b878e24 100644 --- a/src/widgets/importswidget.cpp +++ b/src/widgets/importswidget.cpp @@ -5,7 +5,7 @@ #include "widgets/banned.h" #include "mainwindow.h" -void CMyDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index) const +void CMyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 itemOption(option); initStyleOption(&itemOption, index); @@ -43,22 +43,25 @@ ImportsWidget::ImportsWidget(MainWindow *main, QWidget *parent) : //ui->importsTreeWidget->setItemDelegate(delegate); } -void ImportsWidget::fillImports() { +void ImportsWidget::fillImports() +{ this->importsTreeWidget->clear(); - for (auto i: this->main->core->getList ("bin", "imports")) { - QStringList a = i.split (","); + for (auto i : this->main->core->getList("bin", "imports")) + { + QStringList a = i.split(","); // ord,plt,name - if (a.length()==6) - this->main->appendRow(this->importsTreeWidget, a[1],a[3], "", a[4]); + if (a.length() == 6) + this->main->appendRow(this->importsTreeWidget, a[1], a[3], "", a[4]); } highlightUnsafe(); this->main->adjustColumns(this->importsTreeWidget); } -void ImportsWidget::highlightUnsafe() { +void ImportsWidget::highlightUnsafe() +{ Banned *ban = new Banned(); - QList clist = this->importsTreeWidget->findItems(ban->banned, Qt::MatchRegExp, 4); - foreach(QTreeWidgetItem* item, clist) + QList clist = this->importsTreeWidget->findItems(ban->banned, Qt::MatchRegExp, 4); + foreach (QTreeWidgetItem *item, clist) { item->setText(3, "Unsafe"); //item->setBackgroundColor(4, QColor(255, 129, 123)); @@ -68,9 +71,11 @@ void ImportsWidget::highlightUnsafe() { //ui->importsTreeWidget->setStyleSheet("QTreeWidget::item { padding-left:10px; padding-top: 1px; padding-bottom: 1px; border-left: 10px; }"); } -void ImportsWidget::adjustColumns(QTreeWidget *tw) { +void ImportsWidget::adjustColumns(QTreeWidget *tw) +{ int count = tw->columnCount(); - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { ui->importsTreeWidget->resizeColumnToContents(i); int width = ui->importsTreeWidget->columnWidth(i); ui->importsTreeWidget->setColumnWidth(i, width + 10); diff --git a/src/widgets/importswidget.h b/src/widgets/importswidget.h index 67d275be..850d59e0 100644 --- a/src/widgets/importswidget.h +++ b/src/widgets/importswidget.h @@ -7,8 +7,9 @@ class MainWindow; -namespace Ui { -class ImportsWidget; +namespace Ui +{ + class ImportsWidget; } class ImportsWidget : public QDockWidget @@ -33,9 +34,9 @@ private: class CMyDelegate : public QStyledItemDelegate { public: - CMyDelegate(QObject* parent) : QStyledItemDelegate(parent) {} + CMyDelegate(QObject *parent) : QStyledItemDelegate(parent) {} - void paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; #endif // IMPORTSWIDGET_H diff --git a/src/widgets/memwidget/memorywidget.cpp b/src/widgets/memwidget/memorywidget.cpp index 08871dca..6816e7d8 100644 --- a/src/widgets/memwidget/memorywidget.cpp +++ b/src/widgets/memwidget/memorywidget.cpp @@ -70,7 +70,8 @@ MemoryWidget::MemoryWidget(MainWindow *main) : ui->graphWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); // Allows the local resources (qrc://) to access http content - if (!ui->graphWebView->settings()->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls)) { + if (!ui->graphWebView->settings()->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls)) + { ui->graphWebView->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true); } @@ -90,7 +91,7 @@ MemoryWidget::MemoryWidget(MainWindow *main) : QMenu *memMenu = new QMenu(); ui->memSettingsButton_2->addAction(ui->actionSettings_menu_1); memMenu->addAction(ui->actionSettings_menu_1); - QMenu* hideSide = memMenu->addMenu("Show/Hide"); + QMenu *hideSide = memMenu->addMenu("Show/Hide"); hideSide->addAction(ui->actionDisas_ShowHideBytes); hideSide->addAction(ui->actionSeparate_bytes); hideSide->addAction(ui->actionRight_align_bytes); @@ -142,37 +143,37 @@ MemoryWidget::MemoryWidget(MainWindow *main) : ui->hexHexText_2->verticalScrollBar(), SLOT(setValue(int))); // X to show hexdump - QShortcut* hexdump_shortcut = new QShortcut(QKeySequence(Qt::Key_X), this->main); + QShortcut *hexdump_shortcut = new QShortcut(QKeySequence(Qt::Key_X), this->main); connect(hexdump_shortcut, SIGNAL(activated()), this, SLOT(showHexdump())); //hexdump_shortcut->setContext(Qt::WidgetShortcut); // Space to switch between disassembly and graph - QShortcut* graph_shortcut = new QShortcut(QKeySequence(Qt::Key_Space), this->main); + QShortcut *graph_shortcut = new QShortcut(QKeySequence(Qt::Key_Space), this->main); connect(graph_shortcut, SIGNAL(activated()), this, SLOT(cycleViews())); //graph_shortcut->setContext(Qt::WidgetShortcut); // Semicolon to add comment - QShortcut* comment_shortcut = new QShortcut(QKeySequence(Qt::Key_Semicolon), ui->disasTextEdit_2); + QShortcut *comment_shortcut = new QShortcut(QKeySequence(Qt::Key_Semicolon), ui->disasTextEdit_2); connect(comment_shortcut, SIGNAL(activated()), this, SLOT(on_actionDisasAdd_comment_triggered())); comment_shortcut->setContext(Qt::WidgetShortcut); // N to rename function - QShortcut* rename_shortcut = new QShortcut(QKeySequence(Qt::Key_N), ui->disasTextEdit_2); + QShortcut *rename_shortcut = new QShortcut(QKeySequence(Qt::Key_N), ui->disasTextEdit_2); connect(rename_shortcut, SIGNAL(activated()), this, SLOT(on_actionFunctionsRename_triggered())); rename_shortcut->setContext(Qt::WidgetShortcut); // R to show XRefs - QShortcut* xrefs_shortcut = new QShortcut(QKeySequence(Qt::Key_R), ui->disasTextEdit_2); + QShortcut *xrefs_shortcut = new QShortcut(QKeySequence(Qt::Key_R), ui->disasTextEdit_2); connect(xrefs_shortcut, SIGNAL(activated()), this, SLOT(on_actionXRefs_triggered())); xrefs_shortcut->setContext(Qt::WidgetShortcut); // Esc to seek back - QShortcut* back_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), ui->disasTextEdit_2); + QShortcut *back_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), ui->disasTextEdit_2); connect(back_shortcut, SIGNAL(activated()), this, SLOT(seek_back())); back_shortcut->setContext(Qt::WidgetShortcut); // CTRL + R to refresh the disasm - QShortcut* refresh_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), ui->disasTextEdit_2); + QShortcut *refresh_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), ui->disasTextEdit_2); connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshDisasm())); refresh_shortcut->setContext(Qt::WidgetShortcut); @@ -204,7 +205,8 @@ void MemoryWidget::highlightCurrentLine() QList extraSelections; // Highlight the current line in yellow - if (ui->disasTextEdit_2->isReadOnly()) { + if (ui->disasTextEdit_2->isReadOnly()) + { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(190, 144, 212); @@ -242,10 +244,12 @@ void MemoryWidget::highlightCurrentLine() cursor2.beginEditBlock(); highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); - while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) { + while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) + { highlightSelection.cursor = document->find(searchString, highlightSelection.cursor, QTextDocument::FindWholeWords); - if (!highlightSelection.cursor.isNull()) { + if (!highlightSelection.cursor.isNull()) + { highlightSelection.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); extraSelections.append(highlightSelection); } @@ -259,7 +263,8 @@ void MemoryWidget::highlightHexCurrentLine() { QList extraSelections; - if (!ui->hexHexText_2->isReadOnly()) { + if (!ui->hexHexText_2->isReadOnly()) + { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(190, 144, 212); @@ -305,10 +310,12 @@ void MemoryWidget::highlightHexWords(QString str) QTextCharFormat colorFormat = plainFormat; colorFormat.setBackground(blueColor); - while (!highlightCursor.isNull() && !highlightCursor.atEnd()) { + while (!highlightCursor.isNull() && !highlightCursor.atEnd()) + { highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords); - if (!highlightCursor.isNull()) { + if (!highlightCursor.isNull()) + { highlightCursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); highlightCursor.mergeCharFormat(colorFormat); } @@ -316,12 +323,15 @@ void MemoryWidget::highlightHexWords(QString str) cursor.endEditBlock(); } -void MemoryWidget::highlightPreviewCurrentLine() { +void MemoryWidget::highlightPreviewCurrentLine() +{ QList extraSelections; - if (ui->previewTextEdit->toPlainText() != "") { - if (ui->previewTextEdit->isReadOnly()) { + if (ui->previewTextEdit->toPlainText() != "") + { + if (ui->previewTextEdit->isReadOnly()) + { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(190, 144, 212); @@ -336,12 +346,15 @@ void MemoryWidget::highlightPreviewCurrentLine() { ui->previewTextEdit->setExtraSelections(extraSelections); } -void MemoryWidget::highlightDecoCurrentLine() { +void MemoryWidget::highlightDecoCurrentLine() +{ QList extraSelections; - if (ui->decoTextEdit->toPlainText() != "") { - if (ui->decoTextEdit->isReadOnly()) { + if (ui->decoTextEdit->toPlainText() != "") + { + if (ui->decoTextEdit->isReadOnly()) + { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(190, 144, 212); @@ -366,18 +379,21 @@ MemoryWidget::~MemoryWidget() * Content management functions */ -void MemoryWidget::fillPlugins(QStringList plugins) { +void MemoryWidget::fillPlugins(QStringList plugins) +{ // Fill the plugins combo for the hexdump sidebar ui->hexArchComboBox_2->insertItems(0, plugins); } -void MemoryWidget::addTextDisasm(QString txt) { +void MemoryWidget::addTextDisasm(QString txt) +{ QTextDocument *document = ui->disasTextEdit_2->document(); //document->undo(); ui->disasTextEdit_2->appendPlainText(txt); } -void MemoryWidget::replaceTextDisasm(QString txt) { +void MemoryWidget::replaceTextDisasm(QString txt) +{ QTextDocument *document = ui->disasTextEdit_2->document(); ui->disasTextEdit_2->clear(); //document->undo(); @@ -397,23 +413,27 @@ void MemoryWidget::disasmScrolled() QScrollBar *sb = this->disasTextEdit->verticalScrollBar(); - if ( sb->value() > sb->maximum() - 10 ) { + if (sb->value() > sb->maximum() - 10) + { //this->main->add_debug_output("End is coming"); QTextCursor tc = this->disasTextEdit->textCursor(); - tc.movePosition( QTextCursor::End ); - tc.select( QTextCursor::LineUnderCursor ); + tc.movePosition(QTextCursor::End); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { this->main->core->cmd("ss " + ele); QString raw = this->main->core->cmd("pd 200"); QString txt = raw.section("\n", 1, -1); //this->disasTextEdit->appendPlainText(" ;\n ; New content here\n ;\n " + txt.trimmed()); this->disasTextEdit->appendPlainText(txt.trimmed()); - } else { - tc.movePosition( QTextCursor::End ); - tc.select( QTextCursor::LineUnderCursor ); + } + else + { + tc.movePosition(QTextCursor::End); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); this->main->add_debug_output("Last line: " + lastline); } @@ -465,17 +485,22 @@ void MemoryWidget::refreshDisasm(const QString &offset) disconnect(this->disasTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(disasmScrolled())); // Get disas at offset - if (!offset.isEmpty()) { + if (!offset.isEmpty()) + { this->main->core->cmd("s " + offset); - } else { + } + else + { // Get current offset QTextCursor tc = this->disasTextEdit->textCursor(); - tc.select( QTextCursor::LineUnderCursor ); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); QStringList elements = lastline.split(" ", QString::SkipEmptyParts); - if (elements.length() > 0) { + if (elements.length() > 0) + { QString ele = elements[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { this->main->core->cmd("s " + ele); } } @@ -491,7 +516,8 @@ void MemoryWidget::refreshDisasm(const QString &offset) this->disasTextEdit->ensureCursorVisible(); this->disasTextEdit->moveCursor(QTextCursor::End); - while ( this->disasTextEdit->find(QRegExp("^" + s), QTextDocument::FindBackward) ) { + while (this->disasTextEdit->find(QRegExp("^" + s), QTextDocument::FindBackward)) + { this->disasTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } @@ -534,7 +560,8 @@ void MemoryWidget::refreshHexdump(QString where) { hexdumpBottomOffset = 0; hexdumpLength = bsize;//-hexdumpBottomOffset; - } else + } + else { hexdumpLength = bsize; } @@ -544,11 +571,12 @@ void MemoryWidget::refreshHexdump(QString where) QString s = ""; - if (where != "") { + if (where != "") + { this->main->core->cmd("ss " + where); } // Add first the hexdump at block size -- - this->main->core->cmd ("ss -" + this->main->core->itoa(hexdumpLength)); + this->main->core->cmd("ss -" + this->main->core->itoa(hexdumpLength)); //s = this->normalize_addr(this->main->core->cmd("s")); QList ret = this->get_hexdump(""); @@ -559,7 +587,7 @@ void MemoryWidget::refreshHexdump(QString where) this->resizeHexdump(); // Add then the hexdump at block size ++ - this->main->core->cmd ("ss +" + this->main->core->itoa(hexdumpLength)); + this->main->core->cmd("ss +" + this->main->core->itoa(hexdumpLength)); // Get address to move cursor to later //QString s = "0x0" + this->main->core->cmd("s").split("0x")[1].trimmed(); s = this->normalize_addr(this->main->core->cmd("s")); @@ -583,7 +611,8 @@ void MemoryWidget::refreshHexdump(QString where) connect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); } -QList MemoryWidget::get_hexdump(QString off = "") { +QList MemoryWidget::get_hexdump(QString off = "") +{ RCoreLocked lcore = this->main->core->core(); QList ret; QString hexdump; @@ -596,28 +625,32 @@ QList MemoryWidget::get_hexdump(QString off = "") { hexdumpBottomOffset = 0; hexdumpLength = bsize; //-hexdumpBottomOffset; - } else + } + else { hexdumpLength = bsize; } //this->main->add_debug_output("BSize: " + this->main->core->itoa(hexdumpLength, 10)); - if (off == "" ) { - hexdump = this->main->core->cmd ("px " + this->main->core->itoa(hexdumpLength, 10)); - } else { - hexdump = this->main->core->cmd ("px " + this->main->core->itoa(hexdumpLength, 10) + " @ " + off); + if (off == "") + { + hexdump = this->main->core->cmd("px " + this->main->core->itoa(hexdumpLength, 10)); + } + else + { + hexdump = this->main->core->cmd("px " + this->main->core->itoa(hexdumpLength, 10) + " @ " + off); } //QString hexdump = this->main->core->cmd ("px 0x" + this->main->core->itoa(size) + " @ 0x0"); // TODO: use pxl to simplify QString offset = QString(""); QString hex = QString(""); - QString ascii = QString (""); + QString ascii = QString(""); int ln = 0; - for (const QString line : hexdump.split ("\n")) + for (const QString line : hexdump.split("\n")) { - if (ln++==0) + if (ln++ == 0) { continue; } @@ -626,11 +659,16 @@ QList MemoryWidget::get_hexdump(QString off = "") { { switch (wc++) { - case 0: offset += a+"\n"; break; - case 1: { - hex += a.trimmed()+"\n"; - } break; - case 2: ascii += a+"\n"; + case 0: + offset += a + "\n"; + break; + case 1: + { + hex += a.trimmed() + "\n"; + } + break; + case 2: + ascii += a + "\n"; break; } } @@ -643,18 +681,20 @@ QList MemoryWidget::get_hexdump(QString off = "") { } -void MemoryWidget::seek_to(QString offset) { +void MemoryWidget::seek_to(QString offset) +{ this->disasTextEdit->moveCursor(QTextCursor::End); int pos = this->disasTextEdit->find(offset, QTextDocument::FindBackward); this->disasTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); //this->main->add_debug_output("OFFSET: " + offset); } -void MemoryWidget::resizeHexdump() { +void MemoryWidget::resizeHexdump() +{ //qDebug() << "size: " << ui->hexHexText->document()->size().width(); - this->hexOffsetText->setMinimumWidth( this->hexOffsetText->document()->size().width() ); - this->hexHexText->setMinimumWidth( this->hexHexText->document()->size().width() ); - this->hexASCIIText->setMinimumWidth( this->hexASCIIText->document()->size().width() ); + this->hexOffsetText->setMinimumWidth(this->hexOffsetText->document()->size().width()); + this->hexHexText->setMinimumWidth(this->hexHexText->document()->size().width()); + this->hexASCIIText->setMinimumWidth(this->hexASCIIText->document()->size().width()); } void MemoryWidget::hexScrolled() @@ -662,12 +702,13 @@ void MemoryWidget::hexScrolled() RCoreLocked lcore = this->main->core->core(); QScrollBar *sb = this->hexASCIIText->verticalScrollBar(); - if ( sb->value() > sb->maximum() -10 ) { + if (sb->value() > sb->maximum() - 10) + { this->main->add_debug_output("End is coming"); QTextCursor tc = this->hexOffsetText->textCursor(); - tc.movePosition( QTextCursor::End ); - tc.select( QTextCursor::LineUnderCursor ); + tc.movePosition(QTextCursor::End); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); //this->main->add_debug_output("Last Offset/VA: " + lastline); //refreshHexdump(2); @@ -683,12 +724,14 @@ void MemoryWidget::hexScrolled() // ui->disasTextEdit->moveCursor(QTextCursor::Start); // ui->disasTextEdit->insertPlainText(core->cmd("pd@$$-100")); //... same for the other text (offset and hex text edits) - } else if (sb->value() < sb->minimum() + 10) { + } + else if (sb->value() < sb->minimum() + 10) + { //this->main->add_debug_output("Begining is coming"); QTextCursor tc = this->hexOffsetText->textCursor(); - tc.movePosition( QTextCursor::Start ); - tc.select( QTextCursor::LineUnderCursor ); + tc.movePosition(QTextCursor::Start); + tc.select(QTextCursor::LineUnderCursor); QString firstline = tc.selectedText(); //disathis->main->add_debug_output("First Offset/VA: " + firstline); //refreshHexdump(1); @@ -730,7 +773,7 @@ void MemoryWidget::hexScrolled() // Get new maximum scroll value int c = this->hexASCIIText->verticalScrollBar()->maximum(); // Get size of new added content - int z = c -b; + int z = c - b; // Get new slider position int a = this->hexASCIIText->verticalScrollBar()->sliderPosition(); // move to previous position @@ -752,13 +795,17 @@ void MemoryWidget::on_hexHexText_2_selectionChanged() sel_text = sel_text.simplified().remove(" "); //eprintf ("-- (((%s))) --\n", sel_text.toUtf8().constData()); - if (sel_text == "") { + if (sel_text == "") + { this->hexDisasTextEdit->setPlainText(""); ui->bytesEntropy->setText(""); ui->bytesMD5->setText(""); ui->bytesSHA1->setText(""); - } else { - if (parsing == "Dissasembly") { + } + else + { + if (parsing == "Dissasembly") + { // Get selected combos QString arch = ui->hexArchComboBox_2->currentText(); QString bits = ui->hexBitsComboBox_2->currentText(); @@ -766,39 +813,54 @@ void MemoryWidget::on_hexHexText_2_selectionChanged() QString oarch = this->main->core->config("asm.arch"); QString obits = this->main->core->config("asm.bits"); - this->main->core->config("asm.arch" , arch); - this->main->core->config("asm.bits" , bits); + this->main->core->config("asm.arch", arch); + this->main->core->config("asm.bits", bits); QString str = this->main->core->cmd("pad " + sel_text); this->hexDisasTextEdit->setPlainText(str); - this->main->core->config("asm.arch" , oarch); - this->main->core->config("asm.bits" , obits); + this->main->core->config("asm.arch", oarch); + this->main->core->config("asm.bits", obits); //qDebug() << "Selected Arch: " << arch; //qDebug() << "Selected Bits: " << bits; //qDebug() << "Selected Text: " << sel_text; } // TODO: update on selection changes.. use cmd("pc "+len+"@"+off) - else if (parsing == "C byte array") { + else if (parsing == "C byte array") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pc@x:" + sel_text)); - } else if (parsing == "C dword array") { + } + else if (parsing == "C dword array") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcw@x:" + sel_text)); - } else if (parsing == "C qword array") { + } + else if (parsing == "C qword array") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcq@x:" + sel_text)); - } else if (parsing == "Assembler") { + } + else if (parsing == "Assembler") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pca@x:" + sel_text)); - } else if (parsing == "String") { + } + else if (parsing == "String") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcs@x:" + sel_text)); - } else if (parsing == "JSON") { + } + else if (parsing == "JSON") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcj@x:" + sel_text)); - } else if (parsing == "Javascript") { + } + else if (parsing == "Javascript") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcJ@x:" + sel_text)); - } else if (parsing == "Python") { + } + else if (parsing == "Python") + { this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcp@x:" + sel_text)); } // Fill the information tab hashes and entropy - ui->bytesMD5->setText( this->main->core->cmd("ph md5@x:" + sel_text).trimmed() ); - ui->bytesSHA1->setText( this->main->core->cmd("ph sha1@x:" + sel_text).trimmed() ); - ui->bytesEntropy->setText( this->main->core->cmd("ph entropy@x:" + sel_text).trimmed() ); + ui->bytesMD5->setText(this->main->core->cmd("ph md5@x:" + sel_text).trimmed()); + ui->bytesSHA1->setText(this->main->core->cmd("ph sha1@x:" + sel_text).trimmed()); + ui->bytesEntropy->setText(this->main->core->cmd("ph entropy@x:" + sel_text).trimmed()); ui->bytesMD5->setCursorPosition(0); ui->bytesSHA1->setCursorPosition(0); } @@ -827,7 +889,7 @@ void MemoryWidget::showHexdumpContextMenu(const QPoint &pt) menu->addAction(ui->actionHexCopy_ASCII); menu->addAction(ui->actionHexCopy_Text); menu->addSeparator(); - QMenu* colSubmenu = menu->addMenu("Columns"); + QMenu *colSubmenu = menu->addMenu("Columns"); colSubmenu->addAction(ui->action4columns); colSubmenu->addAction(ui->action8columns); colSubmenu->addAction(ui->action16columns); @@ -854,7 +916,7 @@ void MemoryWidget::showHexASCIIContextMenu(const QPoint &pt) menu->addAction(ui->actionHexCopy_ASCII); menu->addAction(ui->actionHexCopy_Text); menu->addSeparator(); - QMenu* colSubmenu = menu->addMenu("Columns"); + QMenu *colSubmenu = menu->addMenu("Columns"); colSubmenu->addAction(ui->action4columns); colSubmenu->addAction(ui->action8columns); colSubmenu->addAction(ui->action16columns); @@ -882,11 +944,14 @@ void MemoryWidget::showDisasContextMenu(const QPoint &pt) cur.setPosition(ui->disasTextEdit_2->cursorForPosition(pt).position(), QTextCursor::MoveAnchor); ui->disasTextEdit_2->setTextCursor(cur); - if (cur.hasSelection()) { + if (cur.hasSelection()) + { menu->addSeparator(); menu->addAction(ui->actionSend_to_Notepad); ui->disasTextEdit_2->setContextMenuPolicy(Qt::DefaultContextMenu); - } else { + } + else + { // Add menu actions menu->clear(); menu->addAction(ui->actionDisasAdd_comment); @@ -917,11 +982,13 @@ void MemoryWidget::showDisasContextMenu(const QPoint &pt) void MemoryWidget::on_showInfoButton_2_clicked() { - if(ui->showInfoButton_2->isChecked()) + if (ui->showInfoButton_2->isChecked()) { ui->fcnGraphTabWidget->hide(); ui->showInfoButton_2->setArrowType(Qt::RightArrow); - } else { + } + else + { ui->fcnGraphTabWidget->show(); ui->showInfoButton_2->setArrowType(Qt::DownArrow); } @@ -929,11 +996,13 @@ void MemoryWidget::on_showInfoButton_2_clicked() void MemoryWidget::on_offsetToolButton_clicked() { - if(ui->offsetToolButton->isChecked()) + if (ui->offsetToolButton->isChecked()) { ui->offsetTreeWidget->hide(); ui->offsetToolButton->setArrowType(Qt::RightArrow); - } else { + } + else + { ui->offsetTreeWidget->show(); ui->offsetToolButton->setArrowType(Qt::DownArrow); } @@ -943,24 +1012,31 @@ void MemoryWidget::on_offsetToolButton_clicked() * Show widgets */ -void MemoryWidget::showHexdump() { +void MemoryWidget::showHexdump() +{ ui->hexButton_2->setChecked(true); ui->memTabWidget->setCurrentIndex(1); ui->memSideTabWidget_2->setCurrentIndex(1); } -void MemoryWidget::cycleViews() { - if (ui->memTabWidget->currentIndex() == 0) { +void MemoryWidget::cycleViews() +{ + if (ui->memTabWidget->currentIndex() == 0) + { // Show graph ui->graphButton_2->setChecked(true); ui->memTabWidget->setCurrentIndex(2); ui->memSideTabWidget_2->setCurrentIndex(0); - } else if (ui->memTabWidget->currentIndex() == 2) { + } + else if (ui->memTabWidget->currentIndex() == 2) + { // Show disasm ui->disButton_2->setChecked(true); ui->memTabWidget->setCurrentIndex(0); ui->memSideTabWidget_2->setCurrentIndex(0); - } else { + } + else + { // Show disasm ui->disButton_2->setChecked(true); ui->memTabWidget->setCurrentIndex(0); @@ -978,11 +1054,12 @@ void MemoryWidget::on_actionSettings_menu_1_triggered() // QFont font = QFont("Monospace", 8); - QFont font = QFontDialog::getFont( &ok, ui->disasTextEdit_2->font(), this); - setFonts (font); + QFont font = QFontDialog::getFont(&ok, ui->disasTextEdit_2->font(), this); + setFonts(font); } -void MemoryWidget::setFonts(QFont font) { - ui->disasTextEdit_2->setFont (font); +void MemoryWidget::setFonts(QFont font) +{ + ui->disasTextEdit_2->setFont(font); // the user clicked OK and font is set to the font the user selected ui->disasTextEdit_2->setFont(font); ui->hexOffsetText_2->setFont(font); @@ -995,27 +1072,36 @@ void MemoryWidget::setFonts(QFont font) { void MemoryWidget::on_actionHideDisasm_side_panel_triggered() { - if (ui->memSideTabWidget_2->isVisible()) { + if (ui->memSideTabWidget_2->isVisible()) + { ui->memSideTabWidget_2->hide(); - } else { + } + else + { ui->memSideTabWidget_2->show(); } } void MemoryWidget::on_actionHideHexdump_side_panel_triggered() { - if (ui->hexSideTab_2->isVisible()) { + if (ui->hexSideTab_2->isVisible()) + { ui->hexSideTab_2->hide(); - } else { + } + else + { ui->hexSideTab_2->show(); } } void MemoryWidget::on_actionHideGraph_side_panel_triggered() { - if (ui->graphTreeWidget_2->isVisible()) { + if (ui->graphTreeWidget_2->isVisible()) + { ui->graphTreeWidget_2->hide(); - } else { + } + else + { ui->graphTreeWidget_2->show(); } } @@ -1038,13 +1124,16 @@ void MemoryWidget::on_hexButton_2_clicked() void MemoryWidget::on_actionDisas_ShowHideBytes_triggered() { - this->main->core->cmd ("e!asm.bytes"); + this->main->core->cmd("e!asm.bytes"); - if (this->main->core->cmd ("e asm.bytes").trimmed() == "true") { + if (this->main->core->cmd("e asm.bytes").trimmed() == "true") + { ui->actionSeparate_bytes->setDisabled(false); ui->actionRight_align_bytes->setDisabled(false); this->main->core->config("asm.cmtcol", "100"); - } else { + } + else + { ui->actionSeparate_bytes->setDisabled(true); ui->actionRight_align_bytes->setDisabled(true); this->main->core->config("asm.cmtcol", "70"); @@ -1055,16 +1144,19 @@ void MemoryWidget::on_actionDisas_ShowHideBytes_triggered() void MemoryWidget::on_actionDisasSwitch_case_triggered() { - this->main->core->cmd ("e!asm.ucase"); + this->main->core->cmd("e!asm.ucase"); this->refreshDisasm(); } void MemoryWidget::on_actionSyntax_AT_T_Intel_triggered() { - QString syntax = this->main->core->cmd ("e asm.syntax").trimmed(); - if (syntax == "intel") { + QString syntax = this->main->core->cmd("e asm.syntax").trimmed(); + if (syntax == "intel") + { this->main->core->config("asm.syntax", "att"); - } else { + } + else + { this->main->core->config("asm.syntax", "intel"); } this->refreshDisasm(); @@ -1072,26 +1164,26 @@ void MemoryWidget::on_actionSyntax_AT_T_Intel_triggered() void MemoryWidget::on_actionSeparate_bytes_triggered() { - this->main->core->cmd ("e!asm.bytespace"); + this->main->core->cmd("e!asm.bytespace"); this->refreshDisasm(); } void MemoryWidget::on_actionRight_align_bytes_triggered() { - this->main->core->cmd ("e!asm.lbytes"); + this->main->core->cmd("e!asm.lbytes"); this->refreshDisasm(); } void MemoryWidget::on_actionSeparate_disasm_calls_triggered() { - this->main->core->cmd ("e!asm.spacy"); + this->main->core->cmd("e!asm.spacy"); this->refreshDisasm(); } void MemoryWidget::on_actionShow_stack_pointer_triggered() { - this->main->core->cmd ("e!asm.stackptr"); + this->main->core->cmd("e!asm.stackptr"); this->refreshDisasm(); } @@ -1112,21 +1204,24 @@ void MemoryWidget::on_actionDisasAdd_comment_triggered() { // Get current offset QTextCursor tc = this->disasTextEdit->textCursor(); - tc.select( QTextCursor::LineUnderCursor); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { // Get function for clicked offset RAnalFunction *fcn = this->main->core->functionAt(ele.toLongLong(0, 16)); - CommentsDialog* c = new CommentsDialog(this); - if (c->exec()) { + CommentsDialog *c = new CommentsDialog(this); + if (c->exec()) + { // Get new function name QString comment = c->getComment(); //this->main->add_debug_output("Comment: " + comment + " at: " + ele); // Rename function in r2 core this->main->core->setComment(ele, comment); // Seek to new renamed function - if (fcn) { + if (fcn) + { this->main->seek(fcn->name); } // TODO: Refresh functions tree widget @@ -1139,16 +1234,18 @@ void MemoryWidget::on_actionFunctionsRename_triggered() { // Get current offset QTextCursor tc = this->disasTextEdit->textCursor(); - tc.select( QTextCursor::LineUnderCursor ); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { // Get function for clicked offset RAnalFunction *fcn = this->main->core->functionAt(ele.toLongLong(0, 16)); - RenameDialog* r = new RenameDialog(this); + RenameDialog *r = new RenameDialog(this); // Get function based on click position r->setFunctionName(fcn->name); - if (r->exec()) { + if (r->exec()) + { // Get new function name QString new_name = r->getFunctionName(); // Rename function in r2 core @@ -1163,43 +1260,43 @@ void MemoryWidget::on_actionFunctionsRename_triggered() void MemoryWidget::on_action8columns_triggered() { - this->main->core->config ("hex.cols", "8"); + this->main->core->config("hex.cols", "8"); this->refreshHexdump(); } void MemoryWidget::on_action16columns_triggered() { - this->main->core->config ("hex.cols", "16"); + this->main->core->config("hex.cols", "16"); this->refreshHexdump(); } void MemoryWidget::on_action4columns_triggered() { - this->main->core->config ("hex.cols", "4"); + this->main->core->config("hex.cols", "4"); this->refreshHexdump(); } void MemoryWidget::on_action32columns_triggered() { - this->main->core->config ("hex.cols", "32"); + this->main->core->config("hex.cols", "32"); this->refreshHexdump(); } void MemoryWidget::on_action64columns_triggered() { - this->main->core->config ("hex.cols", "64"); + this->main->core->config("hex.cols", "64"); this->refreshHexdump(); } void MemoryWidget::on_action2columns_triggered() { - this->main->core->config ("hex.cols", "2"); + this->main->core->config("hex.cols", "2"); this->refreshHexdump(); } void MemoryWidget::on_action1column_triggered() { - this->main->core->config ("hex.cols", "1"); + this->main->core->config("hex.cols", "1"); this->refreshHexdump(); } @@ -1221,11 +1318,13 @@ void MemoryWidget::on_xrefToTreeWidget_2_itemDoubleClicked(QTreeWidgetItem *item void MemoryWidget::on_xrefFromToolButton_2_clicked() { - if(ui->xrefFromToolButton_2->isChecked()) + if (ui->xrefFromToolButton_2->isChecked()) { ui->xreFromTreeWidget_2->hide(); ui->xrefFromToolButton_2->setArrowType(Qt::RightArrow); - } else { + } + else + { ui->xreFromTreeWidget_2->show(); ui->xrefFromToolButton_2->setArrowType(Qt::DownArrow); } @@ -1233,11 +1332,13 @@ void MemoryWidget::on_xrefFromToolButton_2_clicked() void MemoryWidget::on_xrefToToolButton_2_clicked() { - if(ui->xrefToToolButton_2->isChecked()) + if (ui->xrefToToolButton_2->isChecked()) { ui->xrefToTreeWidget_2->hide(); ui->xrefToToolButton_2->setArrowType(Qt::RightArrow); - } else { + } + else + { ui->xrefToTreeWidget_2->show(); ui->xrefToToolButton_2->setArrowType(Qt::DownArrow); } @@ -1245,16 +1346,19 @@ void MemoryWidget::on_xrefToToolButton_2_clicked() void MemoryWidget::on_codeCombo_2_currentTextChanged(const QString &arg1) { - if (arg1 == "Dissasembly") { + if (arg1 == "Dissasembly") + { ui->hexSideFrame_2->show(); ui->hexDisasTextEdit_2->setPlainText(";; Select some bytes on the left\n;; to see them disassembled"); - } else { + } + else + { ui->hexSideFrame_2->hide(); ui->hexDisasTextEdit_2->setPlainText(";; Select some bytes on the left\n;; to see them parsed here"); } } -void MemoryWidget::get_refs_data(const QString& offset) +void MemoryWidget::get_refs_data(const QString &offset) { // Get Refs and Xrefs bool ok; @@ -1263,8 +1367,10 @@ void MemoryWidget::get_refs_data(const QString& offset) // refs = calls q hace esa funcion QList refs = this->main->core->getFunctionRefs(offset.toLong(&ok, 16), 'C'); - if (refs.size() > 0) { - for (int i = 0; i < refs.size(); ++i) { + if (refs.size() > 0) + { + for (int i = 0; i < refs.size(); ++i) + { //this->add_debug_output(refs.at(i)); QStringList retlist = refs.at(i).split(","); QStringList temp; @@ -1279,8 +1385,10 @@ void MemoryWidget::get_refs_data(const QString& offset) // xrefs = calls a esa funcion //qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16)); QList xrefs = this->main->core->getFunctionXrefs(offset.toLong(&ok, 16)); - if (xrefs.size() > 0) { - for (int i = 0; i < xrefs.size(); ++i) { + if (xrefs.size() > 0) + { + for (int i = 0; i < xrefs.size(); ++i) + { //this->add_debug_output(xrefs.at(i)); QStringList retlist = xrefs.at(i).split(","); QStringList temp; @@ -1313,41 +1421,46 @@ void MemoryWidget::get_refs_data(const QString& offset) void MemoryWidget::fill_refs(QList refs, QList xrefs, QList graph_data) { this->xreFromTreeWidget_2->clear(); - for (int i = 0; i < refs.size(); ++i) { + for (int i = 0; i < refs.size(); ++i) + { //this->add_debug_output(refs.at(i).at(0) + " " + refs.at(i).at(1)); QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, refs.at(i).at(0)); tempItem->setText(1, refs.at(i).at(1)); - tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)).trimmed() ); - tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)).trimmed() ); + tempItem->setToolTip(0, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)).trimmed()); + tempItem->setToolTip(1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)).trimmed()); this->xreFromTreeWidget_2->insertTopLevelItem(0, tempItem); } // Adjust columns to content int count = this->xreFromTreeWidget_2->columnCount(); - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { this->xreFromTreeWidget_2->resizeColumnToContents(i); } this->xrefToTreeWidget_2->clear(); - for (int i = 0; i < xrefs.size(); ++i) { + for (int i = 0; i < xrefs.size(); ++i) + { //this->add_debug_output(xrefs.at(i).at(0) + " " + xrefs.at(i).at(1)); QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, xrefs.at(i).at(0)); tempItem->setText(1, xrefs.at(i).at(1)); - tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)).trimmed() ); - tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)).trimmed() ); + tempItem->setToolTip(0, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)).trimmed()); + tempItem->setToolTip(1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)).trimmed()); this->xrefToTreeWidget_2->insertTopLevelItem(0, tempItem); } // Adjust columns to content int count2 = this->xrefToTreeWidget_2->columnCount(); - for (int i = 0; i != count2; ++i) { + for (int i = 0; i != count2; ++i) + { this->xrefToTreeWidget_2->resizeColumnToContents(i); } // Add data to HTML Polar functions graph QFile html(":/html/fcn_graph.html"); - if(!html.open(QIODevice::ReadOnly)) { - QMessageBox::information(0,"error",html.errorString()); + if (!html.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", html.errorString()); } QString code = html.readAll(); html.close(); @@ -1358,8 +1471,9 @@ void MemoryWidget::fill_refs(QList refs, QList xrefs, // Add data to HTML Radar functions graph QFile html2(":/html/fcn_radar.html"); - if(!html2.open(QIODevice::ReadOnly)) { - QMessageBox::information(0,"error",html.errorString()); + if (!html2.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", html.errorString()); } QString code2 = html2.readAll(); html2.close(); @@ -1369,12 +1483,14 @@ void MemoryWidget::fill_refs(QList refs, QList xrefs, ui->radarGraphWebView->setHtml(code2); } -void MemoryWidget::fillOffsetInfo( QString off) { +void MemoryWidget::fillOffsetInfo(QString off) +{ ui->offsetTreeWidget->clear(); QString raw = ""; raw = this->main->core->getOffsetInfo(off); QList lines = raw.split("\n", QString::SkipEmptyParts); - foreach(QString line, lines) { + foreach (QString line, lines) + { QList eles = line.split(":", QString::SkipEmptyParts); QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, eles.at(0).toUpper()); @@ -1384,21 +1500,25 @@ void MemoryWidget::fillOffsetInfo( QString off) { // Adjust column to contents int count = ui->offsetTreeWidget->columnCount(); - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { ui->offsetTreeWidget->resizeColumnToContents(i); } // Add opcode description QStringList description = this->main->core->cmd("?d. @ " + off).split(": "); - if(description.length() >= 2) { + if (description.length() >= 2) + { ui->opcodeDescText->setPlainText("# " + description[0] + ":\n" + description[1]); } } -void MemoryWidget::create_graph(QString off) { +void MemoryWidget::create_graph(QString off) +{ ui->graphWebView->setZoomFactor(0.85); //this->main->add_debug_output("Graph Offset: '" + off + "'"); - if (off == "") { + if (off == "") + { off = "0x0" + this->main->core->cmd("s").split("0x")[1].trimmed(); } QString fcn = this->main->core->cmdFunctionAt(off); @@ -1410,30 +1530,37 @@ void MemoryWidget::create_graph(QString off) { ui->graphWebView->page()->mainFrame()->evaluateJavaScript(QString("r2.root=\"http://localhost:" + port + "\"")); } -QString MemoryWidget::normalize_addr(QString addr) { +QString MemoryWidget::normalize_addr(QString addr) +{ QString base = this->main->core->cmd("s").split("0x")[1].trimmed(); int len = base.length(); - if (len < 8) { + if (len < 8) + { int padding = 8 - len; QString zero = "0"; QString zeroes = zero.repeated(padding); QString s = "0x" + zeroes + base; return s; - } else { + } + else + { return addr; } } -void MemoryWidget::setFcnName(QString addr) { +void MemoryWidget::setFcnName(QString addr) +{ RAnalFunction *fcn; bool ok; // TDOD: FIX ME, ugly - if (addr.contains("0x")) { + if (addr.contains("0x")) + { fcn = this->main->core->functionAt(addr.toULongLong(&ok, 16)); - if (ok && fcn) { + if (ok && fcn) + { QString segment = this->main->core->cmd("S. @ " + addr).split(" ").last(); - addr = segment.trimmed() + ":"+ fcn->name; + addr = segment.trimmed() + ":" + fcn->name; } } ui->fcnNameEdit->setText(addr); @@ -1443,34 +1570,42 @@ void MemoryWidget::on_disasTextEdit_2_cursorPositionChanged() { // Get current offset QTextCursor tc = this->disasTextEdit->textCursor(); - tc.select( QTextCursor::LineUnderCursor ); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText().trimmed(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { this->fillOffsetInfo(ele); QString at = this->main->core->cmdFunctionAt(ele); QString deco = this->main->core->getDecompiledCode(at); - if (deco != "") { + if (deco != "") + { ui->decoTextEdit->setPlainText(deco); - } else { + } + else + { ui->decoTextEdit->setPlainText(""); } // Get jump information to fill the preview QString jump = ""; jump = this->main->core->getOffsetJump(ele); - if (jump != "") { + if (jump != "") + { // Fill the preview QString jump_code = this->main->core->cmd("pdf @ " + jump); ui->previewTextEdit->setPlainText(jump_code.trimmed()); ui->previewTextEdit->moveCursor(QTextCursor::End); - int pos = ui->previewTextEdit->find( jump.trimmed(), QTextDocument::FindBackward); + int pos = ui->previewTextEdit->find(jump.trimmed(), QTextDocument::FindBackward); ui->previewTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); - } else { + } + else + { ui->previewTextEdit->setPlainText(""); } //this->main->add_debug_output("Fcn at: '" + at + "'"); - if (this->last_fcn != at) { + if (this->last_fcn != at) + { this->last_fcn = at; //this->main->add_debug_output("New Fcn: '" + this->last_fcn + "'"); // Refresh function information at sidebar @@ -1483,27 +1618,33 @@ void MemoryWidget::on_disasTextEdit_2_cursorPositionChanged() } } -QString MemoryWidget::normalizeAddr(QString addr) { +QString MemoryWidget::normalizeAddr(QString addr) +{ QString base = addr.split("0x")[1].trimmed(); int len = base.length(); - if (len < 8) { + if (len < 8) + { int padding = 8 - len; QString zero = "0"; QString zeroes = zero.repeated(padding); QString s = "0x" + zeroes + base; return s; - } else { + } + else + { return addr; } } -void MemoryWidget::setMiniGraph(QString at) { +void MemoryWidget::setMiniGraph(QString at) +{ QString dot = this->main->core->getSimpleGraph(at); //QString dot = this->main->core->cmd("agc " + at); // Add data to HTML Polar functions graph QFile html(":/html/graph.html"); - if(!html.open(QIODevice::ReadOnly)) { - QMessageBox::information(0,"error",html.errorString()); + if (!html.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", html.errorString()); } QString code = html.readAll(); html.close(); @@ -1547,11 +1688,14 @@ void MemoryWidget::on_hexSideTab_2_currentChanged(int index) void MemoryWidget::on_memSideToolButton_clicked() { - if (ui->memSideToolButton->isChecked()) { + if (ui->memSideToolButton->isChecked()) + { ui->memSideTabWidget_2->hide(); ui->hexSideTab_2->hide(); ui->memSideToolButton->setIcon(QIcon(":/new/prefix1/img/icons/left.png")); - } else { + } + else + { ui->memSideTabWidget_2->show(); ui->hexSideTab_2->show(); ui->memSideToolButton->setIcon(QIcon(":/new/prefix1/img/icons/right.png")); @@ -1575,56 +1719,76 @@ void MemoryWidget::on_simpleGrapgToolButton_clicked() void MemoryWidget::on_previewToolButton_2_clicked() { - if (ui->previewToolButton_2->isChecked()) { + if (ui->previewToolButton_2->isChecked()) + { ui->frame_3->setVisible(true); - } else { + } + else + { ui->frame_3->setVisible(false); } } -bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { - if (this->main->responsive) { - QResizeEvent *resizeEvent = static_cast(event); +bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::Resize && obj == this && this->isVisible()) + { + if (this->main->responsive) + { + QResizeEvent *resizeEvent = static_cast(event); //qDebug("Dock Resized (New Size) - Width: %d Height: %d", // resizeEvent->size().width(), // resizeEvent->size().height()); - if (resizeEvent->size().width() <= 1150) { + if (resizeEvent->size().width() <= 1150) + { ui->frame_3->setVisible(false); ui->memPreviewTab->setVisible(false); ui->previewToolButton_2->setChecked(false); - if (resizeEvent->size().width() <= 950) { + if (resizeEvent->size().width() <= 950) + { ui->memSideTabWidget_2->hide(); ui->hexSideTab_2->hide(); ui->memSideToolButton->setChecked(true); - } else { + } + else + { ui->memSideTabWidget_2->show(); ui->hexSideTab_2->show(); ui->memSideToolButton->setChecked(false); } - } else { + } + else + { ui->frame_3->setVisible(true); ui->memPreviewTab->setVisible(true); ui->previewToolButton_2->setChecked(true); } } - } else if ((obj == ui->disasTextEdit_2 || obj==ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) { - QMouseEvent *mouseEvent = static_cast(event); + } + else if ((obj == ui->disasTextEdit_2 || obj == ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) + { + QMouseEvent *mouseEvent = static_cast(event); //qDebug()<x()).arg(mouseEvent->y()); - QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition( QPoint(mouseEvent->x(), mouseEvent->y()) ); - cursor.select( QTextCursor::LineUnderCursor ); + QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition(QPoint(mouseEvent->x(), mouseEvent->y())); + cursor.select(QTextCursor::LineUnderCursor); QString lastline = cursor.selectedText(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { QString jump = ""; jump = this->main->core->getOffsetJump(ele); - if (jump != "") { - if (jump.contains("0x")) { + if (jump != "") + { + if (jump.contains("0x")) + { QString fcn = this->main->core->cmdFunctionAt(jump); - if (fcn != "") { + if (fcn != "") + { this->main->seek(jump.trimmed(), fcn); } - } else { + } + else + { this->main->seek(this->main->core->cmd("?v " + jump), jump); } } @@ -1637,14 +1801,15 @@ void MemoryWidget::on_actionXRefs_triggered() { // Get current offset QTextCursor tc = this->disasTextEdit->textCursor(); - tc.select( QTextCursor::LineUnderCursor ); + tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { + if (ele.contains("0x")) + { // Get function for clicked offset RAnalFunction *fcn = this->main->core->functionAt(ele.toLongLong(0, 16)); - XrefsDialog* x = new XrefsDialog(this->main, this); + XrefsDialog *x = new XrefsDialog(this->main, this); x->setWindowTitle("X-Refs for function " + QString(fcn->name)); x->updateLabels(QString(fcn->name)); @@ -1655,8 +1820,10 @@ void MemoryWidget::on_actionXRefs_triggered() // refs = calls q hace esa funcion QList refs = this->main->core->getFunctionRefs(fcn->addr, 'C'); - if (refs.size() > 0) { - for (int i = 0; i < refs.size(); ++i) { + if (refs.size() > 0) + { + for (int i = 0; i < refs.size(); ++i) + { //this->main->add_debug_output(refs.at(i)); QStringList retlist = refs.at(i).split(","); QStringList temp; @@ -1671,8 +1838,10 @@ void MemoryWidget::on_actionXRefs_triggered() // xrefs = calls a esa funcion //qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16)); QList xrefs = this->main->core->getFunctionXrefs(fcn->addr); - if (xrefs.size() > 0) { - for (int i = 0; i < xrefs.size(); ++i) { + if (xrefs.size() > 0) + { + for (int i = 0; i < xrefs.size(); ++i) + { //this->main->add_debug_output(xrefs.at(i)); QStringList retlist = xrefs.at(i).split(","); QStringList temp; @@ -1705,52 +1874,65 @@ void MemoryWidget::on_copySHA1_clicked() this->main->add_output("SHA1 copied to clipboard: " + sha1); } -void MemoryWidget::switchTheme(bool dark) { - if (dark) { +void MemoryWidget::switchTheme(bool dark) +{ + if (dark) + { ui->webSimpleGraph->setStyleSheet("background-color: rgb(64, 64, 64);"); - } else { + } + else + { ui->webSimpleGraph->setStyleSheet(""); } } void MemoryWidget::on_opcodeDescButton_clicked() { - if(ui->opcodeDescButton->isChecked()) + if (ui->opcodeDescButton->isChecked()) { ui->opcodeDescText->hide(); ui->opcodeDescButton->setArrowType(Qt::RightArrow); - } else { + } + else + { ui->opcodeDescText->show(); ui->opcodeDescButton->setArrowType(Qt::DownArrow); } } -void MemoryWidget::selectHexPreview() { +void MemoryWidget::selectHexPreview() +{ // Pre-select arch and bits in the hexdump sidebar QString arch = this->main->core->cmd("e asm.arch").trimmed(); QString bits = this->main->core->cmd("e asm.bits").trimmed(); //int arch_index = ui->hexArchComboBox_2->findText(arch); - if (ui->hexArchComboBox_2->findText(arch) != -1) { + if (ui->hexArchComboBox_2->findText(arch) != -1) + { ui->hexArchComboBox_2->setCurrentIndex(ui->hexArchComboBox_2->findText(arch)); } //int bits_index = ui->hexBitsComboBox_2->findText(bits); - if (ui->hexBitsComboBox_2->findText(bits) != -1) { + if (ui->hexBitsComboBox_2->findText(bits) != -1) + { ui->hexBitsComboBox_2->setCurrentIndex(ui->hexBitsComboBox_2->findText(bits)); } } -void MemoryWidget::seek_back() { +void MemoryWidget::seek_back() +{ //this->main->add_debug_output("Back!"); this->main->on_backButton_clicked(); } -void MemoryWidget::frameLoadFinished(bool ok) { +void MemoryWidget::frameLoadFinished(bool ok) +{ //qDebug() << "LOAD FRAME: " << ok; - if (ok) { + if (ok) + { QSettings settings; - if (settings.value("dark").toBool()) { + if (settings.value("dark").toBool()) + { QString js = "r2ui.graph_panel.render('dark');"; ui->graphWebView->page()->mainFrame()->evaluateJavaScript(js); } diff --git a/src/widgets/memwidget/memorywidget.h b/src/widgets/memwidget/memorywidget.h index 31d3101d..6df95a5d 100644 --- a/src/widgets/memwidget/memorywidget.h +++ b/src/widgets/memwidget/memorywidget.h @@ -18,8 +18,9 @@ class MainWindow; -namespace Ui { -class MemoryWidget; +namespace Ui +{ + class MemoryWidget; } class MemoryWidget : public QDockWidget @@ -58,13 +59,13 @@ public slots: void refreshDisasm(const QString &offset = QString()); - void refreshHexdump(QString where=0); + void refreshHexdump(QString where = 0); void fill_refs(QList list, QList xrefs, QList graph_data); void fillOffsetInfo(QString off); - void get_refs_data(const QString& offset); + void get_refs_data(const QString &offset); void seek_to(QString offset); diff --git a/src/widgets/notepad.cpp b/src/widgets/notepad.cpp index 205660da..c5c28b1c 100644 --- a/src/widgets/notepad.cpp +++ b/src/widgets/notepad.cpp @@ -36,7 +36,8 @@ Notepad::Notepad(MainWindow *main, QWidget *parent) : this, SLOT(showNotepadContextMenu(const QPoint &))); } -void Notepad::setText(QString str) { +void Notepad::setText(QString str) +{ ui->notepadTextEdit->setPlainText(str); } @@ -49,8 +50,9 @@ void Notepad::on_fontButton_clicked() { bool ok = true; - QFont font = QFontDialog::getFont( &ok, ui->notepadTextEdit->font(), this) ; - if (ok) { + QFont font = QFontDialog::getFont(&ok, ui->notepadTextEdit->font(), this) ; + if (ok) + { // the user clicked OK and font is set to the font the user selected //ui->notepadTextEdit->setFont(font); //ui->previewTextEdit->setFont(font); @@ -58,7 +60,8 @@ void Notepad::on_fontButton_clicked() } } -void Notepad::setFonts(QFont font) { +void Notepad::setFonts(QFont font) +{ ui->notepadTextEdit->setFont(font); ui->previewTextEdit->setFont(font); } @@ -66,11 +69,14 @@ void Notepad::setFonts(QFont font) { void Notepad::on_boldButton_clicked() { QTextCursor cursor = ui->notepadTextEdit->textCursor(); - if (cursor.hasSelection()) { + if (cursor.hasSelection()) + { QString text = cursor.selectedText(); cursor.removeSelectedText(); cursor.insertText("**" + text + "**"); - } else { + } + else + { cursor.insertText("****"); } } @@ -78,11 +84,14 @@ void Notepad::on_boldButton_clicked() void Notepad::on_italicsButton_clicked() { QTextCursor cursor = ui->notepadTextEdit->textCursor(); - if (cursor.hasSelection()) { + if (cursor.hasSelection()) + { QString text = cursor.selectedText(); cursor.removeSelectedText(); cursor.insertText("*" + text + "*"); - } else { + } + else + { cursor.insertText("**"); } } @@ -90,11 +99,14 @@ void Notepad::on_italicsButton_clicked() void Notepad::on_h1Button_clicked() { QTextCursor cursor = ui->notepadTextEdit->textCursor(); - if (cursor.hasSelection()) { + if (cursor.hasSelection()) + { QString text = cursor.selectedText(); cursor.removeSelectedText(); cursor.insertText("# " + text); - } else { + } + else + { cursor.insertText("# "); } } @@ -102,11 +114,14 @@ void Notepad::on_h1Button_clicked() void Notepad::on_h2Button_clicked() { QTextCursor cursor = ui->notepadTextEdit->textCursor(); - if (cursor.hasSelection()) { + if (cursor.hasSelection()) + { QString text = cursor.selectedText(); cursor.removeSelectedText(); cursor.insertText("## " + text); - } else { + } + else + { cursor.insertText("## "); } } @@ -114,11 +129,14 @@ void Notepad::on_h2Button_clicked() void Notepad::on_h3Button_clicked() { QTextCursor cursor = ui->notepadTextEdit->textCursor(); - if (cursor.hasSelection()) { + if (cursor.hasSelection()) + { QString text = cursor.selectedText(); cursor.removeSelectedText(); cursor.insertText("### " + text); - } else { + } + else + { cursor.insertText("### "); } } @@ -139,7 +157,7 @@ void Notepad::on_redoButton_clicked() void Notepad::highlightPreview() { - disasm_highlighter = new Highlighter(this->main, ui->previewTextEdit->document()); + disasm_highlighter = new Highlighter(this->main, ui->previewTextEdit->document()); } void Notepad::on_searchEdit_returnPressed() @@ -150,7 +168,8 @@ void Notepad::on_searchEdit_returnPressed() if (isFirstTime == false) document->undo(); - if (!searchString.isEmpty()) { + if (!searchString.isEmpty()) + { QTextCursor highlightCursor(document); QTextCursor cursor(document); @@ -161,12 +180,14 @@ void Notepad::on_searchEdit_returnPressed() QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); - while (!highlightCursor.isNull() && !highlightCursor.atEnd()) { + while (!highlightCursor.isNull() && !highlightCursor.atEnd()) + { highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords); - if (!highlightCursor.isNull()) { + if (!highlightCursor.isNull()) + { highlightCursor.movePosition(QTextCursor::WordRight, - QTextCursor::KeepAnchor); + QTextCursor::KeepAnchor); highlightCursor.mergeCharFormat(colorFormat); } } @@ -186,7 +207,8 @@ void Notepad::on_searchEdit_textEdited(const QString &arg1) if (isFirstTime == false) document->undo(); - if (!searchString.isEmpty()) { + if (!searchString.isEmpty()) + { QTextCursor highlightCursor(document); QTextCursor cursor(document); @@ -197,10 +219,12 @@ void Notepad::on_searchEdit_textEdited(const QString &arg1) QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); - while (!highlightCursor.isNull() && !highlightCursor.atEnd()) { + while (!highlightCursor.isNull() && !highlightCursor.atEnd()) + { highlightCursor = document->find(searchString, highlightCursor); - if (!highlightCursor.isNull()) { + if (!highlightCursor.isNull()) + { //highlightCursor.movePosition(QTextCursor::WordRight, // QTextCursor::KeepAnchor); highlightCursor.mergeCharFormat(colorFormat); @@ -222,7 +246,8 @@ void Notepad::on_searchEdit_textChanged(const QString &arg1) if (isFirstTime == false) document->undo(); - if (!searchString.isEmpty()) { + if (!searchString.isEmpty()) + { QTextCursor highlightCursor(document); QTextCursor cursor(document); @@ -233,10 +258,12 @@ void Notepad::on_searchEdit_textChanged(const QString &arg1) QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); - while (!highlightCursor.isNull() && !highlightCursor.atEnd()) { + while (!highlightCursor.isNull() && !highlightCursor.atEnd()) + { highlightCursor = document->find(searchString, highlightCursor); - if (!highlightCursor.isNull()) { + if (!highlightCursor.isNull()) + { //highlightCursor.movePosition(QTextCursor::WordRight, // QTextCursor::KeepAnchor); highlightCursor.mergeCharFormat(colorFormat); @@ -253,23 +280,26 @@ void Notepad::showNotepadContextMenu(const QPoint &pt) // Set Notepad popup menu QMenu *menu = ui->notepadTextEdit->createStandardContextMenu(); QTextCursor cur = ui->notepadTextEdit->textCursor(); - QAction* first = menu->actions().at(0); + QAction *first = menu->actions().at(0); - if (cur.hasSelection()) { + if (cur.hasSelection()) + { // Get selected text //this->main->add_debug_output("Selected text: " + cur.selectedText()); this->addr = cur.selectedText(); - } else { + } + else + { // Get word under the cursor - cur.select( QTextCursor::WordUnderCursor); + cur.select(QTextCursor::WordUnderCursor); //this->main->add_debug_output("Word: " + cur.selectedText()); this->addr = cur.selectedText(); } - ui->actionDisassmble_bytes->setText( "Disassemble bytes at: " + this->addr); - ui->actionDisassmble_function->setText( "Disassemble function at: " + this->addr); - ui->actionHexdump_bytes->setText( "Hexdump bytes at: " + this->addr); - ui->actionCompact_Hexdump->setText( "Compact Hexdump at: " + this->addr); - ui->actionHexdump_function->setText( "Hexdump function at: " + this->addr); + ui->actionDisassmble_bytes->setText("Disassemble bytes at: " + this->addr); + ui->actionDisassmble_function->setText("Disassemble function at: " + this->addr); + ui->actionHexdump_bytes->setText("Hexdump bytes at: " + this->addr); + ui->actionCompact_Hexdump->setText("Compact Hexdump at: " + this->addr); + ui->actionHexdump_function->setText("Hexdump function at: " + this->addr); menu->insertAction(first, ui->actionDisassmble_bytes); menu->insertAction(first, ui->actionDisassmble_function); menu->insertAction(first, ui->actionHexdump_bytes); @@ -284,25 +314,25 @@ void Notepad::showNotepadContextMenu(const QPoint &pt) void Notepad::on_actionDisassmble_bytes_triggered() { - ui->previewTextEdit->setPlainText( this->main->core->cmd("pd 100 @ " + this->addr) ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pd 100 @ " + this->addr)); } void Notepad::on_actionDisassmble_function_triggered() { - ui->previewTextEdit->setPlainText( this->main->core->cmd("pdf @ " + this->addr) ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pdf @ " + this->addr)); } void Notepad::on_actionHexdump_bytes_triggered() { - ui->previewTextEdit->setPlainText( this->main->core->cmd( "px 1024 @ " + this->addr ) ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("px 1024 @ " + this->addr)); } void Notepad::on_actionCompact_Hexdump_triggered() { - ui->previewTextEdit->setPlainText( this->main->core->cmd( "pxi 1024 @ " + this->addr ) ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pxi 1024 @ " + this->addr)); } void Notepad::on_actionHexdump_function_triggered() { - ui->previewTextEdit->setPlainText( this->main->core->cmd( "pxf @ " + this->addr ) ); + ui->previewTextEdit->setPlainText(this->main->core->cmd("pxf @ " + this->addr)); } diff --git a/src/widgets/notepad.h b/src/widgets/notepad.h index c6530d0a..088494ec 100644 --- a/src/widgets/notepad.h +++ b/src/widgets/notepad.h @@ -8,8 +8,9 @@ class MainWindow; -namespace Ui { -class Notepad; +namespace Ui +{ + class Notepad; } class Notepad : public QDockWidget diff --git a/src/widgets/omnibar.cpp b/src/widgets/omnibar.cpp index 41984d4c..147bef81 100644 --- a/src/widgets/omnibar.cpp +++ b/src/widgets/omnibar.cpp @@ -39,12 +39,13 @@ Omnibar::Omnibar(MainWindow *main, QWidget *parent) : connect(this, SIGNAL(returnPressed()), this, SLOT(on_gotoEntry_returnPressed())); // Esc clears omnibar - QShortcut* clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); + QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clearContents())); clear_shortcut->setContext(Qt::WidgetShortcut); } -void Omnibar::setupCompleter() { +void Omnibar::setupCompleter() +{ // Set gotoEntry completer for jump history QStringList flagsList = this->getFlags(); QCompleter *completer = new QCompleter(flagsList, this); @@ -54,7 +55,7 @@ void Omnibar::setupCompleter() { completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setFilterMode(Qt::MatchContains); - QStringListModel *completerModel = (QStringListModel*)(completer->model()); + QStringListModel *completerModel = (QStringListModel *)(completer->model()); completerModel->setStringList(completerModel->stringList() << this->commands); this->setCompleter(completer); @@ -66,7 +67,8 @@ void Omnibar::restoreCompleter() completer->setFilterMode(Qt::MatchContains); } -void Omnibar::showCommands() { +void Omnibar::showCommands() +{ this->setFocus(); this->setText(": "); @@ -82,7 +84,8 @@ void Omnibar::showCommands() { completer->complete(); } -void Omnibar::clearContents() { +void Omnibar::clearContents() +{ this->setText(""); // Necessary hack to make it work properly this->clearFocus(); @@ -92,38 +95,69 @@ void Omnibar::clearContents() { void Omnibar::on_gotoEntry_returnPressed() { QString str = this->text(); - if (str.length()>0) { - if (str.contains(": ")) { - if (str.contains("Lock")){ + if (str.length() > 0) + { + if (str.contains(": ")) + { + if (str.contains("Lock")) + { this->main->on_actionLock_triggered(); - } else if (str.contains("Functions")) { + } + else if (str.contains("Functions")) + { this->main->on_actionFunctions_triggered(); - } else if (str.contains("Flags")) { + } + else if (str.contains("Flags")) + { this->main->on_actionFlags_triggered(); - } else if (str.contains("Sections")) { + } + else if (str.contains("Sections")) + { this->main->on_actionSections_triggered(); - } else if (str.contains("Strings")) { + } + else if (str.contains("Strings")) + { this->main->on_actionStrings_triggered(); - } else if (str.contains("Imports")) { + } + else if (str.contains("Imports")) + { this->main->on_actionImports_triggered(); - } else if (str.contains("Symbols")) { + } + else if (str.contains("Symbols")) + { this->main->on_actionSymbols_triggered(); - } else if (str.contains("Relocs")) { + } + else if (str.contains("Relocs")) + { this->main->on_actionReloc_triggered(); - } else if (str.contains("Comments")) { + } + else if (str.contains("Comments")) + { this->main->on_actionComents_triggered(); - } else if (str.contains("Notepad")) { + } + else if (str.contains("Notepad")) + { this->main->on_actionNotepad_triggered(); - } else if (str.contains("Dashboard")) { + } + else if (str.contains("Dashboard")) + { this->main->on_actionDashboard_triggered(); - } else if (str.contains("Theme")) { + } + else if (str.contains("Theme")) + { this->main->sideBar->themesButtonToggle(); - } else if (str.contains("Script")) { + } + else if (str.contains("Script")) + { this->main->on_actionRun_Script_triggered(); - } else if (str.contains("Tabs")) { + } + else if (str.contains("Tabs")) + { this->main->on_actionTabs_triggered(); } - } else { + } + else + { //this->main->seek(this->main->core->cmd("?v " + this->text()), this->text()); QString off = this->main->core->cmd("afo " + this->text()); this->main->seek(off.trimmed(), this->text()); @@ -137,14 +171,17 @@ void Omnibar::on_gotoEntry_returnPressed() this->restoreCompleter(); } -void Omnibar::fillFlags(QString flag) { +void Omnibar::fillFlags(QString flag) +{ this->flags << flag; } -void Omnibar::clearFlags() { +void Omnibar::clearFlags() +{ this->flags.clear(); } -QStringList Omnibar::getFlags() { +QStringList Omnibar::getFlags() +{ return this->flags; } diff --git a/src/widgets/omnibar.h b/src/widgets/omnibar.h index 21be871b..413091f4 100644 --- a/src/widgets/omnibar.h +++ b/src/widgets/omnibar.h @@ -20,18 +20,18 @@ public: void setupCompleter(); private: - MainWindow *main; + MainWindow *main; private slots: - void on_gotoEntry_returnPressed(); + void on_gotoEntry_returnPressed(); - void restoreCompleter(); + void restoreCompleter(); signals: public slots: - void showCommands(); - void clearContents(); + void showCommands(); + void clearContents(); }; #endif // OMNIBAR_H diff --git a/src/widgets/pieview.cpp b/src/widgets/pieview.cpp index 83069b0b..c8867426 100644 --- a/src/widgets/pieview.cpp +++ b/src/widgets/pieview.cpp @@ -74,12 +74,14 @@ void PieView::dataChanged(const QModelIndex &topLeft, validItems = 0; totalValue = 0.0; - for (int row = 0; row < model()->rowCount(rootIndex()); ++row) { + for (int row = 0; row < model()->rowCount(rootIndex()); ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); double value = model()->data(index).toDouble(); - if (value > 0.0) { + if (value > 0.0) + { totalValue += value; validItems++; } @@ -108,7 +110,8 @@ QModelIndex PieView::indexAt(const QPoint &point) const int wx = point.x() + horizontalScrollBar()->value(); int wy = point.y() + verticalScrollBar()->value(); - if (wx < totalSize) { + if (wx < totalSize) + { double cx = wx - totalSize / 2; double cy = totalSize / 2 - wy; // positive cy for items above the center @@ -126,12 +129,14 @@ QModelIndex PieView::indexAt(const QPoint &point) const // Find the relevant slice of the pie. double startAngle = 0.0; - for (int row = 0; row < model()->rowCount(rootIndex()); ++row) { + for (int row = 0; row < model()->rowCount(rootIndex()); ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); double value = model()->data(index).toDouble(); - if (value > 0.0) { + if (value > 0.0) + { double sliceAngle = 360 * value / totalValue; if (angle >= startAngle && angle < (startAngle + sliceAngle)) @@ -140,15 +145,19 @@ QModelIndex PieView::indexAt(const QPoint &point) const startAngle += sliceAngle; } } - } else { + } + else + { double itemHeight = QFontMetrics(viewOptions().font).height(); int listItem = int((wy - margin) / itemHeight); int validRow = 0; - for (int row = 0; row < model()->rowCount(rootIndex()); ++row) { + for (int row = 0; row < model()->rowCount(rootIndex()); ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); - if (model()->data(index).toDouble() > 0.0) { + if (model()->data(index).toDouble() > 0.0) + { if (listItem == validRow) return model()->index(row, 0, rootIndex()); @@ -191,19 +200,21 @@ QRect PieView::itemRect(const QModelIndex &index) const return QRect(); int listItem = 0; - for (int row = index.row()-1; row >= 0; --row) { + for (int row = index.row() - 1; row >= 0; --row) + { if (model()->data(model()->index(row, 1, rootIndex())).toDouble() > 0.0) listItem++; } double itemHeight; - switch (index.column()) { + switch (index.column()) + { case 0: itemHeight = QFontMetrics(viewOptions().font).height(); return QRect(totalSize, - int(margin + listItem*itemHeight), + int(margin + listItem * itemHeight), totalSize - margin, int(itemHeight)); case 1: return viewport()->rect(); @@ -223,18 +234,21 @@ QRegion PieView::itemRegion(const QModelIndex &index) const return QRegion(); double startAngle = 0.0; - for (int row = 0; row < model()->rowCount(rootIndex()); ++row) { + for (int row = 0; row < model()->rowCount(rootIndex()); ++row) + { QModelIndex sliceIndex = model()->index(row, 1, rootIndex()); double value = model()->data(sliceIndex).toDouble(); - if (value > 0.0) { + if (value > 0.0) + { double angle = 360 * value / totalValue; - if (sliceIndex == index) { + if (sliceIndex == index) + { QPainterPath slicePath; slicePath.moveTo(totalSize / 2, totalSize / 2); - slicePath.arcTo(margin, margin, margin+pieSize, margin+pieSize, + slicePath.arcTo(margin, margin, margin + pieSize, margin + pieSize, startAngle, angle); slicePath.closeSubpath(); @@ -283,26 +297,27 @@ QModelIndex PieView::moveCursor(QAbstractItemView::CursorAction cursorAction, { QModelIndex current = currentIndex(); - switch (cursorAction) { - case MoveLeft: - case MoveUp: - if (current.row() > 0) - current = model()->index(current.row() - 1, current.column(), - rootIndex()); - else - current = model()->index(0, current.column(), rootIndex()); - break; - case MoveRight: - case MoveDown: - if (current.row() < rows(current) - 1) - current = model()->index(current.row() + 1, current.column(), - rootIndex()); - else - current = model()->index(rows(current) - 1, current.column(), - rootIndex()); - break; - default: - break; + switch (cursorAction) + { + case MoveLeft: + case MoveUp: + if (current.row() > 0) + current = model()->index(current.row() - 1, current.column(), + rootIndex()); + else + current = model()->index(0, current.column(), rootIndex()); + break; + case MoveRight: + case MoveDown: + if (current.row() < rows(current) - 1) + current = model()->index(current.row() + 1, current.column(), + rootIndex()); + else + current = model()->index(rows(current) - 1, current.column(), + rootIndex()); + break; + default: + break; } viewport()->update(); @@ -341,12 +356,14 @@ void PieView::paintEvent(QPaintEvent *event) double startAngle = 0.0; int row; - for (row = 0; row < model()->rowCount(rootIndex()); ++row) { + for (row = 0; row < model()->rowCount(rootIndex()); ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); double value = model()->data(index).toDouble(); - if (value > 0.0) { - double angle = 360*value/totalValue; + if (value > 0.0) + { + double angle = 360 * value / totalValue; QModelIndex colorIndex = model()->index(row, 0, rootIndex()); QColor color = QColor(model()->data(colorIndex, Qt::DecorationRole).toString()); @@ -358,7 +375,7 @@ void PieView::paintEvent(QPaintEvent *event) else painter.setBrush(QBrush(color)); - painter.drawPie(0, 0, pieSize, pieSize, int(startAngle*16), int(angle*16)); + painter.drawPie(0, 0, pieSize, pieSize, int(startAngle * 16), int(angle * 16)); startAngle += angle; } @@ -370,7 +387,7 @@ void PieView::paintEvent(QPaintEvent *event) //painter.drawEllipse(meowRect); QPoint p = pieRect.center(); QPoint q(margin - 2, margin - 2); - painter.drawEllipse(p -= q, pieSize/4, pieSize/4); + painter.drawEllipse(p -= q, pieSize / 4, pieSize / 4); painter.restore(); } @@ -387,11 +404,13 @@ int PieView::rows(const QModelIndex &index) const void PieView::rowsInserted(const QModelIndex &parent, int start, int end) { - for (int row = start; row <= end; ++row) { + for (int row = start; row <= end; ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); double value = model()->data(index).toDouble(); - if (value > 0.0) { + if (value > 0.0) + { totalValue += value; ++validItems; } @@ -402,10 +421,12 @@ void PieView::rowsInserted(const QModelIndex &parent, int start, int end) void PieView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { - for (int row = start; row <= end; ++row) { + for (int row = start; row <= end; ++row) + { QModelIndex index = model()->index(row, 1, rootIndex()); double value = model()->data(index).toDouble(); - if (value > 0.0) { + if (value > 0.0) + { totalValue -= value; --validItems; } @@ -424,19 +445,25 @@ void PieView::scrollTo(const QModelIndex &index, ScrollHint) QRect area = viewport()->rect(); QRect rect = visualRect(index); - if (rect.left() < area.left()) { + if (rect.left() < area.left()) + { horizontalScrollBar()->setValue( horizontalScrollBar()->value() + rect.left() - area.left()); - } else if (rect.right() > area.right()) { + } + else if (rect.right() > area.right()) + { horizontalScrollBar()->setValue( horizontalScrollBar()->value() + qMin( rect.right() - area.right(), rect.left() - area.left())); } - if (rect.top() < area.top()) { + if (rect.top() < area.top()) + { verticalScrollBar()->setValue( verticalScrollBar()->value() + rect.top() - area.top()); - } else if (rect.bottom() > area.bottom()) { + } + else if (rect.bottom() > area.bottom()) + { verticalScrollBar()->setValue( verticalScrollBar()->value() + qMin( rect.bottom() - area.bottom(), rect.top() - area.top())); @@ -457,15 +484,17 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag // function to check for intersections. QRect contentsRect = rect.translated( - horizontalScrollBar()->value(), - verticalScrollBar()->value()).normalized(); + horizontalScrollBar()->value(), + verticalScrollBar()->value()).normalized(); int rows = model()->rowCount(rootIndex()); int columns = model()->columnCount(rootIndex()); QModelIndexList indexes; - for (int row = 0; row < rows; ++row) { - for (int column = 0; column < columns; ++column) { + for (int row = 0; row < rows; ++row) + { + for (int column = 0; column < columns; ++column) + { QModelIndex index = model()->index(row, column, rootIndex()); QRegion region = itemRegion(index); if (region.intersects(contentsRect)) @@ -473,13 +502,15 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag } } - if (indexes.size() > 0) { + if (indexes.size() > 0) + { int firstRow = indexes[0].row(); int lastRow = indexes[0].row(); int firstColumn = indexes[0].column(); int lastColumn = indexes[0].column(); - for (int i = 1; i < indexes.size(); ++i) { + for (int i = 1; i < indexes.size(); ++i) + { firstRow = qMin(firstRow, indexes[i].row()); lastRow = qMax(lastRow, indexes[i].row()); firstColumn = qMin(firstColumn, indexes[i].column()); @@ -490,7 +521,9 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag model()->index(firstRow, firstColumn, rootIndex()), model()->index(lastRow, lastColumn, rootIndex())); selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - } else { + } + else + { QModelIndex noIndex; QItemSelection selection(noIndex, noIndex); selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); @@ -543,10 +576,13 @@ QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const return QRect(); QRegion region; - for (int i = 0; i < ranges; ++i) { + for (int i = 0; i < ranges; ++i) + { QItemSelectionRange range = selection.at(i); - for (int row = range.top(); row <= range.bottom(); ++row) { - for (int col = range.left(); col <= range.right(); ++col) { + for (int row = range.top(); row <= range.bottom(); ++row) + { + for (int col = range.left(); col <= range.right(); ++col) + { QModelIndex index = model()->index(row, col, rootIndex()); region += visualRect(index); } @@ -558,5 +594,5 @@ QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const /*Function to find minimum of x and y*/ int PieView::getMin(int x, int y) { - return y ^ ((x ^ y) & -(x < y)); + return y ^ ((x ^ y) & -(x < y)); } diff --git a/src/widgets/pieview.h b/src/widgets/pieview.h index 79599f9f..0ada5525 100644 --- a/src/widgets/pieview.h +++ b/src/widgets/pieview.h @@ -71,7 +71,7 @@ protected: bool isIndexHidden(const QModelIndex &index) const; - void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command); + void setSelection(const QRect &, QItemSelectionModel::SelectionFlags command); void mousePressEvent(QMouseEvent *event); diff --git a/src/widgets/relocswidget.h b/src/widgets/relocswidget.h index 2d55afeb..963f7ee0 100644 --- a/src/widgets/relocswidget.h +++ b/src/widgets/relocswidget.h @@ -6,8 +6,9 @@ class MainWindow; -namespace Ui { -class RelocsWidget; +namespace Ui +{ + class RelocsWidget; } class RelocsWidget : public QDockWidget diff --git a/src/widgets/sdbdock.cpp b/src/widgets/sdbdock.cpp index 33a99665..0989817b 100644 --- a/src/widgets/sdbdock.cpp +++ b/src/widgets/sdbdock.cpp @@ -25,7 +25,8 @@ void SdbDock::reload(QString path) QList keys; /* key-values */ keys = main->core->sdbListKeys(path); - foreach (QString key, keys) { + foreach (QString key, keys) + { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, key); tempItem->setText(1, main->core->sdbGet(path, key)); @@ -37,9 +38,10 @@ void SdbDock::reload(QString path) /* namespaces */ keys = main->core->sdbList(path); keys.append(".."); - foreach (QString key, keys) { + foreach (QString key, keys) + { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); - tempItem->setText(0, key+"/"); + tempItem->setText(0, key + "/"); tempItem->setText(1, ""); ui->treeWidget->insertTopLevelItem(0, tempItem); } @@ -52,29 +54,39 @@ void SdbDock::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { QString newpath; - if (column == 0) { - if (item->text(0) == "../") { + if (column == 0) + { + if (item->text(0) == "../") + { int idx = path.lastIndexOf("/"); - if (idx != -1) { - newpath = path.mid(0,idx); - } else { + if (idx != -1) + { + newpath = path.mid(0, idx); + } + else + { newpath = ""; } - reload (newpath); + reload(newpath); - } else - if (item->text(0).indexOf("/")!=-1) { - if (path != "") { - newpath = path +"/"+ item->text(0).replace ("/",""); - } else { - newpath = path + item->text(0).replace ("/",""); - } - // enter directory - reload (newpath); + } + else if (item->text(0).indexOf("/") != -1) + { + if (path != "") + { + newpath = path + "/" + item->text(0).replace("/", ""); } - else { - //__alert ("TODO: change value"); + else + { + newpath = path + item->text(0).replace("/", ""); } + // enter directory + reload(newpath); + } + else + { + //__alert ("TODO: change value"); + } } } @@ -85,19 +97,21 @@ SdbDock::~SdbDock() void SdbDock::on_lockButton_clicked() { - if(ui->lockButton->isChecked()) + if (ui->lockButton->isChecked()) { this->setAllowedAreas(Qt::NoDockWidgetArea); - ui->lockButton->setIcon( QIcon(":/new/prefix1/lock") ); - } else { + ui->lockButton->setIcon(QIcon(":/new/prefix1/lock")); + } + else + { this->setAllowedAreas(Qt::AllDockWidgetAreas); - ui->lockButton->setIcon( QIcon(":/new/prefix1/unlock") ); + ui->lockButton->setIcon(QIcon(":/new/prefix1/unlock")); } } void SdbDock::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column) { - __alert (item->text(column)); + __alert(item->text(column)); // El nuevo valor esta en: // item->text(column) // ya sabras tu que hacer con el :P diff --git a/src/widgets/sdbdock.h b/src/widgets/sdbdock.h index 876d91d3..9e27a885 100644 --- a/src/widgets/sdbdock.h +++ b/src/widgets/sdbdock.h @@ -6,8 +6,9 @@ class MainWindow; -namespace Ui { -class SdbDock; +namespace Ui +{ + class SdbDock; } class SdbDock : public QDockWidget diff --git a/src/widgets/sectionswidget.cpp b/src/widgets/sectionswidget.cpp index b4ece08e..8e6b7486 100644 --- a/src/widgets/sectionswidget.cpp +++ b/src/widgets/sectionswidget.cpp @@ -63,8 +63,8 @@ void SectionsWidget::setupViews() pieChart->setSelectionModel(selectionModel); } -void SectionsWidget::fillSections(int row, const QString &str, const QString &str2=NULL, - const QString &str3=NULL, const QString &str4=NULL) +void SectionsWidget::fillSections(int row, const QString &str, const QString &str2 = NULL, + const QString &str3 = NULL, const QString &str4 = NULL) { QList colors; //colors << "#F7464A" << "#46BFBD" << "#FDB45C" << "#949FB1" << "#4D5360" << "#D97041" <<"#C7604C" << "#21323D" << "#9D9B7F" << "#7D4F6D" << "#584A5E"; @@ -85,28 +85,36 @@ void SectionsWidget::fillSections(int row, const QString &str, const QString &st tempItem->setText(1, str2); tempItem->setText(2, str3); tempItem->setText(3, str4); - tempItem->setData( 0, Qt::DecorationRole, QColor(colors[row])); + tempItem->setData(0, Qt::DecorationRole, QColor(colors[row])); this->tree->insertTopLevelItem(0, tempItem); } -void SectionsWidget::adjustColumns() { +void SectionsWidget::adjustColumns() +{ int count = 4; - for (int i = 0; i != count; ++i) { + for (int i = 0; i != count; ++i) + { this->tree->resizeColumnToContents(i); } } -bool SectionsWidget::eventFilter(QObject *obj, QEvent *event) { - if (this->main->responsive) { - if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { - QResizeEvent *resizeEvent = static_cast(event); +bool SectionsWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (this->main->responsive) + { + if (event->type() == QEvent::Resize && obj == this && this->isVisible()) + { + QResizeEvent *resizeEvent = static_cast(event); //qDebug("Dock Resized (New Size) - Width: %d Height: %d", // resizeEvent->size().width(), // resizeEvent->size().height()); - if (resizeEvent->size().width() >= resizeEvent->size().height()) { + if (resizeEvent->size().width() >= resizeEvent->size().height()) + { // Set horizontal view (list) this->main->on_actionSectionsHorizontal_triggered(); - } else { + } + else + { // Set vertical view (Tree) this->main->on_actionSectionsVertical_triggered(); } diff --git a/src/widgets/sectionswidget.h b/src/widgets/sectionswidget.h index 8da501a6..8e818f0a 100644 --- a/src/widgets/sectionswidget.h +++ b/src/widgets/sectionswidget.h @@ -14,8 +14,9 @@ class QItemSelectionModel; QT_END_NAMESPACE -namespace Ui { -class SectionsWidget; +namespace Ui +{ + class SectionsWidget; } class SectionsWidget : public QSplitter @@ -25,7 +26,7 @@ class SectionsWidget : public QSplitter public: explicit SectionsWidget(MainWindow *main, QWidget *parent = 0); void fillSections(int row, const QString &str, const QString &str2, - const QString &str3, const QString &str4); + const QString &str3, const QString &str4); void adjustColumns(); QTreeWidget *tree; diff --git a/src/widgets/sidebar.cpp b/src/widgets/sidebar.cpp index ed6312fb..384002b9 100644 --- a/src/widgets/sidebar.cpp +++ b/src/widgets/sidebar.cpp @@ -14,14 +14,20 @@ SideBar::SideBar(MainWindow *main) : ui->setupUi(this); QSettings settings; - if (settings.value("responsive").toBool()) { + if (settings.value("responsive").toBool()) + { ui->respButton->setChecked(true); - } else { + } + else + { ui->respButton->setChecked(false); } - if (settings.value("dark").toBool()) { + if (settings.value("dark").toBool()) + { ui->themesButton->setChecked(true); - } else { + } + else + { ui->themesButton->setChecked(false); } } @@ -39,9 +45,12 @@ void SideBar::on_tabsButton_clicked() void SideBar::on_consoleButton_clicked() { this->main->on_actionhide_bottomPannel_triggered(); - if (ui->consoleButton->isChecked()) { + if (ui->consoleButton->isChecked()) + { ui->consoleButton->setIcon(QIcon(":/new/prefix1/img/icons/up_white.png")); - } else { + } + else + { ui->consoleButton->setIcon(QIcon(":/new/prefix1/img/icons/down_white.png")); } } @@ -53,25 +62,32 @@ void SideBar::on_webServerButton_clicked() void SideBar::on_lockButton_clicked() { - if(ui->lockButton->isChecked()) { - ui->lockButton->setIcon( QIcon(":/new/prefix1/img/icons/unlock_white.png") ); + if (ui->lockButton->isChecked()) + { + ui->lockButton->setIcon(QIcon(":/new/prefix1/img/icons/unlock_white.png")); this->main->lockUnlock_Docks(1); - } else { - ui->lockButton->setIcon( QIcon(":/new/prefix1/img/icons/lock_white.png") ); + } + else + { + ui->lockButton->setIcon(QIcon(":/new/prefix1/img/icons/lock_white.png")); this->main->lockUnlock_Docks(0); } } -void SideBar::themesButtonToggle() { +void SideBar::themesButtonToggle() +{ ui->themesButton->click(); } void SideBar::on_themesButton_clicked() { - if (ui->themesButton->isChecked() ) { + if (ui->themesButton->isChecked()) + { // Dark theme this->main->dark(); - } else { + } + else + { // Clear theme this->main->def_theme(); } @@ -79,7 +95,7 @@ void SideBar::on_themesButton_clicked() void SideBar::on_calcInput_textChanged(const QString &arg1) { - ui->calcOutput->setText(QString::number(this->main->core->math (arg1))); + ui->calcOutput->setText(QString::number(this->main->core->math(arg1))); } void SideBar::on_asm2hex_clicked() diff --git a/src/widgets/sidebar.h b/src/widgets/sidebar.h index 98fa8676..06328f5e 100644 --- a/src/widgets/sidebar.h +++ b/src/widgets/sidebar.h @@ -5,8 +5,9 @@ class MainWindow; -namespace Ui { -class SideBar; +namespace Ui +{ + class SideBar; } class SideBar : public QWidget diff --git a/src/widgets/stringswidget.cpp b/src/widgets/stringswidget.cpp index 730b1db2..7c62b8b8 100644 --- a/src/widgets/stringswidget.cpp +++ b/src/widgets/stringswidget.cpp @@ -28,7 +28,7 @@ void StringsWidget::on_stringsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item // TODO: use this info to change disasm contents QString offset = item->text(1); QString name = item->text(2); - this->main->seek (offset); + this->main->seek(offset); // Rise and shine baby! this->main->memoryDock->raise(); } diff --git a/src/widgets/stringswidget.h b/src/widgets/stringswidget.h index a64a98fc..d6f9f6c0 100644 --- a/src/widgets/stringswidget.h +++ b/src/widgets/stringswidget.h @@ -6,8 +6,9 @@ class MainWindow; -namespace Ui { -class StringsWidget; +namespace Ui +{ + class StringsWidget; } class StringsWidget : public QDockWidget diff --git a/src/widgets/symbolswidget.cpp b/src/widgets/symbolswidget.cpp index 4eff3f2b..7431137a 100644 --- a/src/widgets/symbolswidget.cpp +++ b/src/widgets/symbolswidget.cpp @@ -17,11 +17,13 @@ SymbolsWidget::~SymbolsWidget() delete ui; } -void SymbolsWidget::fillSymbols() { +void SymbolsWidget::fillSymbols() +{ this->symbolsTreeWidget->clear(); - for (auto i: this->main->core->getList ("bin", "symbols")) { - QStringList pieces = i.split (","); - if (pieces.length()==3) + for (auto i : this->main->core->getList("bin", "symbols")) + { + QStringList pieces = i.split(","); + if (pieces.length() == 3) this->main->appendRow(this->symbolsTreeWidget, pieces[0], pieces[1], pieces[2]); } this->main->adjustColumns(this->symbolsTreeWidget); diff --git a/src/widgets/symbolswidget.h b/src/widgets/symbolswidget.h index 4edfb878..0c1a5064 100644 --- a/src/widgets/symbolswidget.h +++ b/src/widgets/symbolswidget.h @@ -6,8 +6,9 @@ class MainWindow; -namespace Ui { -class SymbolsWidget; +namespace Ui +{ + class SymbolsWidget; } class SymbolsWidget : public QDockWidget