diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99095ac9..9b258ddb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,6 +12,10 @@ Make a clear description of the bug/feature, use screenshots, send binaries, etc Note that cutter is still under development and many parts of the code are to be improved. +### CutterCore class + +This is the main class where every link with r2 is made. It is *unique* accross the whole process. To access it, simply call `CutterCore::getInstance()`. + ### Calling a radare2 command There are two ways to do it: @@ -20,12 +24,12 @@ There are two ways to do it: ### Seek the current file -To modify radare2 seek use `MainWindow::seek(const RVA offset)`. This is important because it will emit a `MainWindow::seekChanged(RVA offset)` signal. +To modify radare2 seek use `CutterCore::seek(const RVA offset)`. This is important because it will emit a `CutterCore::seekChanged(RVA offset)` signal. Never ever call cmd("s offset"); ### Creating a widget -Make sure to connect the `MainWindow::seekChanged(RVA offset)` signal so your widget refreshes its output when radare2 seek is modified (switching to another function, etc.). +Make sure to connect the `CutterCore::seekChanged(RVA offset)` signal so your widget refreshes its output when radare2 seek is modified (switching to another function, etc.). ## General coding guidelines diff --git a/src/AnalThread.cpp b/src/AnalThread.cpp index 8150bf19..2addc8be 100644 --- a/src/AnalThread.cpp +++ b/src/AnalThread.cpp @@ -8,7 +8,8 @@ AnalThread::AnalThread(OptionsDialog *parent) : QThread(parent), level(2), - main(nullptr) + main(nullptr), + core(CutterCore::getInstance()) { } @@ -43,7 +44,7 @@ void AnalThread::run() // Advanced Options // - main->core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(), optionsDialog->getSelectedBits()); + core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(), optionsDialog->getSelectedBits()); bool rw = false; bool load_bininfo = ui->binCheckBox->isChecked(); @@ -54,7 +55,7 @@ void AnalThread::run() { va = 2; loadaddr = UT64_MAX; - r_config_set_i(main->core->core()->config, "bin.laddr", loadaddr); + r_config_set_i(core->core()->config, "bin.laddr", loadaddr); mapaddr = 0; } } @@ -76,22 +77,22 @@ void AnalThread::run() forceBinPlugin = pluginDesc.name; } - main->core->setConfig("bin.demangle", ui->demangleCheckBox->isChecked()); + core->setConfig("bin.demangle", ui->demangleCheckBox->isChecked()); - main->core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo, forceBinPlugin); + core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo, forceBinPlugin); emit updateProgress("Analysis in progress."); QString os = optionsDialog->getSelectedOS(); if (!os.isNull()) { - main->core->cmd("e asm.os=" + os); + core->cmd("e asm.os=" + os); } if (ui->pdbCheckBox->isChecked()) { - main->core->loadPDB(ui->pdbLineEdit->text()); + core->loadPDB(ui->pdbLineEdit->text()); } //qDebug() << "Anal level: " << this->level; - main->core->analyze(this->level, this->advanced); + core->analyze(this->level, this->advanced); } diff --git a/src/AnalThread.h b/src/AnalThread.h index 18d840bc..88704b56 100644 --- a/src/AnalThread.h +++ b/src/AnalThread.h @@ -28,6 +28,7 @@ private: int level; QList advanced; MainWindow *main; + CutterCore *core; }; #endif // ANALTHREAD_H diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 58df88af..a3d240cc 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -84,7 +84,7 @@ static void registerCustomFonts() MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - core(new CutterCore), + core(CutterCore::getInstance()), memoryDock(nullptr), notepadDock(nullptr), asmDock(nullptr), @@ -120,7 +120,6 @@ MainWindow::~MainWindow() delete core; } - void MainWindow::initUI() { ui->setupUi(this); @@ -133,7 +132,7 @@ void MainWindow::initUI() // Hide central tab widget tabs QTabBar *centralbar = ui->centralTabWidget->tabBar(); centralbar->setVisible(false); - consoleWidget = new ConsoleWidget(this, this); + consoleWidget = new ConsoleWidget(this); ui->tabVerticalLayout->addWidget(consoleWidget); // Sepparator between back/forward and undo/redo buttons @@ -185,7 +184,7 @@ void MainWindow::initUI() dockWidgets.reserve(12); // Add Memory DockWidget - this->memoryDock = new MemoryWidget(this); + this->memoryDock = new MemoryWidget(); dockWidgets.push_back(memoryDock); // To use in the future when we handle more than one memory views // this->memoryDock->setAttribute(Qt::WA_DeleteOnClose); @@ -601,7 +600,7 @@ void MainWindow::on_actionMem_triggered() { //this->memoryDock->show(); //this->memoryDock->raise(); - MemoryWidget *newMemDock = new MemoryWidget(this); + MemoryWidget *newMemDock = new MemoryWidget(); this->dockWidgets << newMemDock; newMemDock->setAttribute(Qt::WA_DeleteOnClose); this->tabifyDockWidget(this->memoryDock, newMemDock); @@ -694,20 +693,13 @@ void MainWindow::setCursorAddress(RVA addr) emit cursorAddressChanged(core->getOffset()); } -void MainWindow::seek(const RVA offset) -{ - core->seek(offset); - setCursorAddress(core->getOffset()); - emit seekChanged(core->getOffset()); -} - void MainWindow::backButton_clicked() { QList seek_history = core->getSeekHistory(); this->core->cmd("s-"); RVA offset = this->core->getOffset(); //QString fcn = this->core->cmdFunctionAt(QString::number(offset)); - this->seek(offset); + core->seek(offset); } void MainWindow::on_actionCalculator_triggered() @@ -920,7 +912,7 @@ void MainWindow::on_actionForward_triggered() this->core->cmd("s+"); RVA offset = core->getOffset(); this->addDebugOutput(QString::number(offset)); - this->seek(offset); + core->seek(offset); } void MainWindow::toggleResponsive(bool maybe) diff --git a/src/MainWindow.h b/src/MainWindow.h index b1161fd8..2eec7138 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -45,10 +45,6 @@ class MainWindow : public QMainWindow Q_OBJECT public: - CutterCore* core; - MemoryWidget *memoryDock; - Notepad *notepadDock; - bool responsive; explicit MainWindow(QWidget *parent = 0); @@ -77,8 +73,7 @@ public: void refreshOmniBar(const QStringList &flags); signals: - void seekChanged(RVA offset); - void cursorAddressChanged(RVA offset); + void cursorAddressChanged(RVA offset); // TODO cursor should be handled by its own widget public slots: @@ -173,10 +168,13 @@ private slots: void on_actionAsmOptions_triggered(); private: + CutterCore *core; QDockWidget *asmDock; QDockWidget *calcDock; Omnibar *omnibar; SideBar *sideBar; + MemoryWidget *memoryDock; + Notepad *notepadDock; bool doLock; void refreshMem(); diff --git a/src/cutter.cpp b/src/cutter.cpp index cc1ea4f6..eeccf12e 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -3,8 +3,8 @@ #include "cutter.h" #include "sdb.h" #include "Settings.h" -#include "MainWindow.h" +Q_GLOBAL_STATIC(ccClass, uniqueInstance) #define DB this->db @@ -69,6 +69,12 @@ CutterCore::CutterCore(QObject *parent) : } +CutterCore *CutterCore::getInstance() +{ + return uniqueInstance; +} + + int CutterCore::getCycloComplex(ut64 addr) { CORE_LOCK(); @@ -179,12 +185,14 @@ QString CutterCore::cmd(const QString &str) { CORE_LOCK(); + RVA offset = core_->offset; QByteArray cmd = str.toUtf8(); - //r_cons_flush(); 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); + if (offset != core_->offset) { + emit seekChanged(core_->offset); + } return o; } @@ -378,6 +386,7 @@ void CutterCore::seek(ut64 offset) { CORE_LOCK(); r_core_seek(this->core_, offset, true); + emit seekChanged(core_->offset); } diff --git a/src/cutter.h b/src/cutter.h index 849e87c3..13aaca13 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -180,20 +180,23 @@ Q_DECLARE_METATYPE(RBinPluginDescription) class CutterCore: public QObject { Q_OBJECT + friend class ccClass; public: QString projectPath; explicit CutterCore(QObject *parent = 0); ~CutterCore(); + static CutterCore* getInstance(); + /* Getters */ RVA getOffset() const { return core_->offset; } - static QString sanitizeStringForCommand(QString s); int getCycloComplex(ut64 addr); int getFcnSize(ut64 addr); int fcnCyclomaticComplexity(ut64 addr); int fcnBasicBlockCount(ut64 addr); int fcnEndBbs(RVA addr); + static QString sanitizeStringForCommand(QString s); QString cmd(const QString &str); QJsonDocument cmdj(const QString &str); QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; } @@ -210,11 +213,11 @@ public: ut64 math(const QString &expr); QString itoa(ut64 num, int rdx = 16); + /* Config related */ void setConfig(const QString &k, const QString &v); void setConfig(const QString &k, int v); void setConfig(const QString &k, bool v); void setConfig(const QString &k, const char *v) { setConfig(k, QString(v)); } - int getConfigi(const QString &k); bool getConfigb(const QString &k); QString getConfig(const QString &k); @@ -227,7 +230,8 @@ public: RAnalFunction *functionAt(ut64 addr); QString cmdFunctionAt(QString addr); QString cmdFunctionAt(RVA addr); - /* sdb */ + + /* SDB */ QList sdbList(QString path); QList sdbListKeys(QString path); QString sdbGet(QString path, QString key); @@ -297,6 +301,12 @@ signals: */ void asmOptionsChanged(); + /*! + * \brief seekChanged is emitted each time radare2 seek value is modified + * \param offset + */ + void seekChanged(RVA offset); + public slots: private: @@ -307,4 +317,8 @@ private: RCore *core_; }; +class ccClass : public CutterCore +{ +}; + #endif // CUTTER_H diff --git a/src/dialogs/CreateNewDialog.cpp b/src/dialogs/CreateNewDialog.cpp index 39b9696a..144367de 100644 --- a/src/dialogs/CreateNewDialog.cpp +++ b/src/dialogs/CreateNewDialog.cpp @@ -7,7 +7,8 @@ CreateNewDialog::CreateNewDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CreateNewDialog), - w(new MainWindow) + w(new MainWindow), + core(CutterCore::getInstance()) { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); @@ -69,7 +70,7 @@ void CreateNewDialog::on_exampleButton_clicked() void CreateNewDialog::on_buttonCreate_clicked() { - RCoreLocked lcore = w->core->core(); + RCoreLocked lcore = core->core(); QString type = ui->comboType->currentText(); QString str; bool created = false; @@ -85,7 +86,7 @@ void CreateNewDialog::on_buttonCreate_clicked() { char file[32]; snprintf(file, sizeof(file) - 1, "malloc://%d", code->len); - if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + if (core->loadFile(file, 0, 0, 1, 0, 0, false)) { created = true; r_core_write_at(lcore, 0, code->buf, code->len); @@ -108,7 +109,7 @@ void CreateNewDialog::on_buttonCreate_clicked() char file[32]; created = true; snprintf(file, sizeof(file) - 1, "malloc://%d", fsize); - if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + if (core->loadFile(file, 0, 0, 1, 0, 0, false)) { r_core_patch(lcore, ui->plainTextEdit->toPlainText().toUtf8().constData()); r_core_seek(lcore, 0, 1); @@ -136,14 +137,14 @@ void CreateNewDialog::on_buttonCreate_clicked() char file[32]; created = true; snprintf(file, sizeof(file) - 1, "malloc://%d", fsize); - if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + if (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) { - w->core->cmd(str); + core->cmd(str); } } else @@ -164,7 +165,7 @@ void CreateNewDialog::on_buttonCreate_clicked() if (sz > 0) { snprintf(file, sizeof(file) - 1, "malloc://%d", (int)sz); - if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + if (core->loadFile(file, 0, 0, 1, 0, 0, false)) { created = true; r_core_write_at(lcore, 0, (const ut8 *)hexpairs.constData(), (int)sz); @@ -189,7 +190,7 @@ void CreateNewDialog::on_buttonCreate_clicked() if (sz > 0) { snprintf(file, sizeof(file) - 1, "malloc://%d", sz); - if (w->core->loadFile(file, 0, 0, 1, 0, 0, false)) + if (core->loadFile(file, 0, 0, 1, 0, 0, false)) { created = true; r_core_write_at(lcore, 0, buf, sz); @@ -215,8 +216,8 @@ void CreateNewDialog::on_buttonCreate_clicked() { __alert("TODO: non-raw fileformat is not yet supported"); created = false; - delete w->core; - w->core = nullptr; + delete core; + core = nullptr; } if (created) @@ -225,7 +226,7 @@ void CreateNewDialog::on_buttonCreate_clicked() // Close dialog and open OptionsDialog close(); - w->core->seek(0); + core->seek(0); w->updateFrames(); w->setFilename("-"); w->addOutput(tr("Finished, check its contents")); diff --git a/src/dialogs/CreateNewDialog.h b/src/dialogs/CreateNewDialog.h index 19085e81..6655827e 100644 --- a/src/dialogs/CreateNewDialog.h +++ b/src/dialogs/CreateNewDialog.h @@ -30,6 +30,7 @@ private slots: private: std::unique_ptr ui; MainWindow *w; + CutterCore *core; }; #endif // CREATENEWDIALOG_H diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 4e887d7a..0927dfe2 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -16,8 +16,9 @@ OptionsDialog::OptionsDialog(MainWindow *main): QDialog(0), // parent may not be main analThread(this), - main(main), defaultAnalLevel(1), + core(CutterCore::getInstance()), + main(main), ui(new Ui::OptionsDialog) { ui->setupUi(this); @@ -28,25 +29,25 @@ OptionsDialog::OptionsDialog(MainWindow *main): ui->analSlider->setValue(defaultAnalLevel); // Fill the plugins combo - asm_plugins = main->core->getAsmPluginNames(); + asm_plugins = core->getAsmPluginNames(); for (auto plugin : asm_plugins) ui->archComboBox->addItem(plugin, plugin); - ui->archComboBox->setToolTip(main->core->cmd("e? asm.arch").trimmed()); + ui->archComboBox->setToolTip(core->cmd("e? asm.arch").trimmed()); // cpu combo box ui->cpuComboBox->lineEdit()->setPlaceholderText(tr("Auto")); - ui->cpuComboBox->setToolTip(main->core->cmd("e? asm.cpu").trimmed()); + ui->cpuComboBox->setToolTip(core->cmd("e? asm.cpu").trimmed()); updateCPUComboBox(); // os combo box - for (const auto &plugin : main->core->cmdList("e asm.os=?")) + for (const auto &plugin : core->cmdList("e asm.os=?")) ui->kernelComboBox->addItem(plugin, plugin); - ui->kernelComboBox->setToolTip(main->core->cmd("e? asm.os").trimmed()); + ui->kernelComboBox->setToolTip(core->cmd("e? asm.os").trimmed()); - ui->bitsComboBox->setToolTip(main->core->cmd("e? asm.bits").trimmed()); + ui->bitsComboBox->setToolTip(core->cmd("e? asm.bits").trimmed()); - for (auto plugin : main->core->getRBinPluginDescriptions("bin")) + for (auto plugin : core->getRBinPluginDescriptions("bin")) ui->formatComboBox->addItem(plugin.name, QVariant::fromValue(plugin)); ui->hideFrame->setVisible(false); @@ -63,7 +64,7 @@ OptionsDialog::OptionsDialog(MainWindow *main): ui->programLineEdit->setText(main->getFilename()); QFileInfo fi(this->main->getFilename()); - this->main->core->tryFile(fi.filePath(), fi.isWritable()); + this->core->tryFile(fi.filePath(), fi.isWritable()); } OptionsDialog::~OptionsDialog() {} @@ -80,7 +81,7 @@ void OptionsDialog::updateCPUComboBox() cmd += " @a:" + arch; ui->cpuComboBox->addItem(""); - ui->cpuComboBox->addItems(main->core->cmdList(cmd)); + ui->cpuComboBox->addItems(core->cmdList(cmd)); ui->cpuComboBox->lineEdit()->setText(currentText); } @@ -134,7 +135,7 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) main->initUI(); - main->core->resetDefaultAsmOptions(); + core->resetDefaultAsmOptions(); // Threads stuff // connect signal/slot diff --git a/src/dialogs/OptionsDialog.h b/src/dialogs/OptionsDialog.h index b1c707c1..3000eac4 100644 --- a/src/dialogs/OptionsDialog.h +++ b/src/dialogs/OptionsDialog.h @@ -41,6 +41,7 @@ private slots: private: AnalThread analThread; MainWindow *main; + CutterCore *core; int defaultAnalLevel; QString analysisDescription(int level); diff --git a/src/dialogs/XrefsDialog.cpp b/src/dialogs/XrefsDialog.cpp index 45d94997..6ca7a3c6 100644 --- a/src/dialogs/XrefsDialog.cpp +++ b/src/dialogs/XrefsDialog.cpp @@ -10,7 +10,8 @@ XrefsDialog::XrefsDialog(MainWindow *main, QWidget *parent) : addr(0), func_name(QString::null), ui(new Ui::XrefsDialog), - main(main) + main(main), + core(CutterCore::getInstance()) { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); @@ -20,7 +21,7 @@ XrefsDialog::XrefsDialog(MainWindow *main, QWidget *parent) : asm_docu->setDocumentMargin(10); // Syntax highlight - highlighter = new Highlighter(this->main, ui->previewTextEdit->document()); + highlighter = new Highlighter(ui->previewTextEdit->document()); // Highlight current line connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); @@ -37,10 +38,10 @@ void XrefsDialog::fillRefs(QList refs, QList x QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, RAddressString(xref.to)); - tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from)); + tempItem->setText(1, core->disassembleSingleInstruction(xref.from)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); - //tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); - //tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); + //tempItem->setToolTip( 0, this->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); + //tempItem->setToolTip( 1, this->core->cmd("pdi 10 @ " + refs.at(i).at(0)) ); ui->fromTreeWidget->insertTopLevelItem(0, tempItem); } @@ -58,10 +59,10 @@ void XrefsDialog::fillRefs(QList refs, QList x QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, RAddressString(xref.from)); - tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from)); + tempItem->setText(1, core->disassembleSingleInstruction(xref.from)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); - //tempItem->setToolTip( 0, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); - //tempItem->setToolTip( 1, this->main->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); + //tempItem->setToolTip( 0, this->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); + //tempItem->setToolTip( 1, this->core->cmd("pdi 10 @ " + xrefs.at(i).at(0)) ); ui->toTreeWidget->insertTopLevelItem(0, tempItem); } @@ -79,7 +80,7 @@ void XrefsDialog::on_fromTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int Q_UNUSED(column); XrefDescription xref = item->data(0, Qt::UserRole).value(); - RAnalFunction *fcn = this->main->core->functionAt(xref.to); + RAnalFunction *fcn = this->core->functionAt(xref.to); // TODO Seek //this->main->seek(xref.to, fcn ? QString::fromUtf8(fcn->name) : QString::null, true); @@ -91,7 +92,7 @@ void XrefsDialog::on_toTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int c Q_UNUSED(column); XrefDescription xref = item->data(0, Qt::UserRole).value(); - RAnalFunction *fcn = this->main->core->functionAt(xref.from); + RAnalFunction *fcn = this->core->functionAt(xref.from); // TODO Seek //this->main->seek(xref.from, fcn ? QString::fromUtf8(fcn->name) : QString::null, true); @@ -161,10 +162,10 @@ void XrefsDialog::updatePreview(RVA addr) QString disass; // is the address part of a function, so we can use pdf? - if (!main->core->cmdj("afij@" + QString::number(addr)).array().isEmpty()) - disass = main->core->cmd("pdf @ " + QString::number(addr)); + if (!core->cmdj("afij@" + QString::number(addr)).array().isEmpty()) + disass = core->cmd("pdf @ " + QString::number(addr)); else - disass = main->core->cmd("pd 10 @ " + QString::number(addr)); + disass = core->cmd("pd 10 @ " + QString::number(addr)); ui->previewTextEdit->setPlainText(disass.trimmed()); @@ -190,10 +191,10 @@ void XrefsDialog::fillRefsForAddress(RVA addr, QString name, bool whole_function // Get Refs and Xrefs // refs = calls q hace esa funcion - QList refs = main->core->getXRefs(addr, false, whole_function); + QList refs = core->getXRefs(addr, false, whole_function); // xrefs = calls a esa funcion - QList xrefs = main->core->getXRefs(addr, true, whole_function); + QList xrefs = core->getXRefs(addr, true, whole_function); fillRefs(refs, xrefs); } diff --git a/src/dialogs/XrefsDialog.h b/src/dialogs/XrefsDialog.h index e1ac366f..5eb4198d 100644 --- a/src/dialogs/XrefsDialog.h +++ b/src/dialogs/XrefsDialog.h @@ -43,6 +43,7 @@ private: std::unique_ptr ui; MainWindow *main; + CutterCore *core; Highlighter *highlighter; diff --git a/src/main.cpp b/src/main.cpp index 1649b743..0d0cbf13 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,8 +52,6 @@ int main(int argc, char *argv[]) return 1; } - - bool anal_level_specified = false; int anal_level = 0; diff --git a/src/utils/Highlighter.cpp b/src/utils/Highlighter.cpp index 8a45d74e..148209e5 100644 --- a/src/utils/Highlighter.cpp +++ b/src/utils/Highlighter.cpp @@ -3,18 +3,17 @@ #include "Highlighter.h" #include "MainWindow.h" -Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) : +Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { - // Radare core found in: - this->main = main; - HighlightingRule rule; + core = CutterCore::getInstance(); + keywordFormat.setForeground(QColor(65, 131, 215)); keywordFormat.setFontWeight(QFont::Bold); - foreach (const QString &pattern, this->main->core->opcodes) + foreach (const QString &pattern, this->core->opcodes) { rule.pattern = QRegExp("\\b" + pattern + "\\b"); rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); @@ -25,7 +24,7 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) : regFormat.setForeground(QColor(236, 100, 75)); regFormat.setFontWeight(QFont::Bold); - foreach (const QString &pattern, this->main->core->regs) + foreach (const QString &pattern, this->core->regs) { rule.pattern = QRegExp("\\b" + pattern + "\\b"); rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); diff --git a/src/utils/Highlighter.h b/src/utils/Highlighter.h index 68a44c39..e75054a8 100644 --- a/src/utils/Highlighter.h +++ b/src/utils/Highlighter.h @@ -3,6 +3,7 @@ #include +#include "cutter.h" #include #include @@ -14,13 +15,13 @@ class Highlighter : public QSyntaxHighlighter Q_OBJECT public: - Highlighter(MainWindow *main, QTextDocument *parent = 0); + Highlighter(QTextDocument *parent = 0); protected: void highlightBlock(const QString &text); private: - MainWindow *main; + CutterCore *core; struct HighlightingRule { diff --git a/src/widgets/CodeGraphic.cpp b/src/widgets/CodeGraphic.cpp index b5f9e51b..5102d8fc 100644 --- a/src/widgets/CodeGraphic.cpp +++ b/src/widgets/CodeGraphic.cpp @@ -66,7 +66,7 @@ void GraphicsBar::fillData() this->codeGraphic->setToolTip("gap"); // Parse JSON data - QString jsonData = this->main->core->cmd("p-j"); + QString jsonData = CutterCore::getInstance()->cmd("p-j"); QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8()); if (doc.isNull()) diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index 1e443950..b1bebf01 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -26,7 +26,7 @@ CommentsWidget::CommentsWidget(MainWindow *main, QWidget *parent) : connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showTitleContextMenu(const QPoint &))); - connect(main->core, SIGNAL(commentsChanged()), this, SLOT(refreshTree())); + connect(CutterCore::getInstance(), SIGNAL(commentsChanged()), this, SLOT(refreshTree())); // Hide the buttons frame ui->frame->hide(); @@ -51,8 +51,8 @@ void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *it // Get offset and name of item double clicked CommentDescription comment = item->data(0, Qt::UserRole).value(); this->main->addDebugOutput(RAddressString(comment.offset) + ": " + comment.name); - this->main->seek(comment.offset); - //this->main->seek(comment.offset, comment.name, true); + CutterCore::getInstance()->seek(comment.offset); + //CutterCore::getInstance()->seek(comment.offset, comment.name, true); } void CommentsWidget::on_toolButton_clicked() @@ -123,12 +123,12 @@ void CommentsWidget::resizeEvent(QResizeEvent *event) void CommentsWidget::refreshTree() { ui->nestedCmtsTreeWidget->clear(); - QList comments = this->main->core->getAllComments("CCu"); + QList comments = CutterCore::getInstance()->getAllComments("CCu"); for (CommentDescription comment : comments) { //this->main->add_debug_output(RAddressString(comment.offset)); - QString fcn_name = this->main->core->cmdFunctionAt(comment.offset); + QString fcn_name = CutterCore::getInstance()->cmdFunctionAt(comment.offset); QTreeWidgetItem *item = qhelpers::appendRow(ui->commentsTreeWidget, RAddressString(comment.offset), fcn_name, comment.name); item->setData(0, Qt::UserRole, QVariant::fromValue(comment)); } @@ -136,7 +136,7 @@ void CommentsWidget::refreshTree() // Add nested comments ui->nestedCmtsTreeWidget->clear(); - QMap>> cmts = this->main->core->getNestedComments(); + QMap>> cmts = CutterCore::getInstance()->getNestedComments(); for (auto cmt : cmts.keys()) { QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget); diff --git a/src/widgets/ConsoleWidget.cpp b/src/widgets/ConsoleWidget.cpp index 4627f077..160ebcdd 100644 --- a/src/widgets/ConsoleWidget.cpp +++ b/src/widgets/ConsoleWidget.cpp @@ -90,11 +90,9 @@ static bool isForbidden(const QString &input) -ConsoleWidget::ConsoleWidget(MainWindow *main, QWidget *parent) : +ConsoleWidget::ConsoleWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ConsoleWidget), - core(main->core), - main(main), debugOutputEnabled(true), maxHistoryEntries(100), lastHistoryPosition(invalidHistoryPos) @@ -121,11 +119,6 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QWidget *parent) : connect(action, SIGNAL(triggered(bool)), ui->outputTextEdit, SLOT(clear())); actions.append(action); - action = new QAction(tr("Sync with core"), ui->outputTextEdit); - action->setCheckable(true); - connect(action, SIGNAL(toggled(bool)), this, SLOT(syncWithCoreToggled(bool))); - actions.append(action); - // Completion QCompleter *completer = new QCompleter(radareArgs, this); completer->setMaxVisibleItems(20); @@ -176,25 +169,14 @@ void ConsoleWidget::focusInputLineEdit() ui->inputLineEdit->setFocus(); } -QString ConsoleWidget::executeCommand(QString command) -{ - RVA offset = this->core->getOffset(); - QString res = this->core->cmd(command); - RVA newOffset = this->core->getOffset(); - if (offset != newOffset) { - emit main->seekChanged(newOffset); - } - return res; -} - void ConsoleWidget::on_inputLineEdit_returnPressed() { QString input = ui->inputLineEdit->text(); - if (!input.isEmpty() && core != nullptr) + if (!input.isEmpty()) { if (!isForbidden(input)) { - QString res = executeCommand(input); + QString res = CutterCore::getInstance()->cmd(input); ui->outputTextEdit->appendPlainText(res); scrollOutputToEnd(); historyAdd(input); @@ -221,19 +203,6 @@ void ConsoleWidget::showCustomContextMenu(const QPoint &pt) menu->deleteLater(); } -void ConsoleWidget::syncWithCoreToggled(bool checked) -{ - // TODO Core and Cutter are always in sync - if (checked) - { - //Enable core syncronization - } - else - { - // Disable core sync - } -} - void ConsoleWidget::historyNext() { if (!history.isEmpty()) diff --git a/src/widgets/ConsoleWidget.h b/src/widgets/ConsoleWidget.h index c1f7837b..292cd87f 100644 --- a/src/widgets/ConsoleWidget.h +++ b/src/widgets/ConsoleWidget.h @@ -5,9 +5,6 @@ #include #include "MainWindow.h" -class CutterCore; -class QAction; - namespace Ui { class ConsoleWidget; @@ -19,7 +16,7 @@ class ConsoleWidget : public QWidget Q_OBJECT public: - explicit ConsoleWidget(MainWindow *main, QWidget *parent = 0); + explicit ConsoleWidget(QWidget *parent = 0); ~ConsoleWidget(); void addOutput(const QString &msg); @@ -39,8 +36,6 @@ private slots: void showCustomContextMenu(const QPoint &pt); - void syncWithCoreToggled(bool checked); - void historyNext(); void historyPrev(); @@ -53,8 +48,6 @@ private: QString executeCommand(QString command); std::unique_ptr ui; - CutterCore *core; - MainWindow *main; QList actions; bool debugOutputEnabled; int maxHistoryEntries; diff --git a/src/widgets/Dashboard.cpp b/src/widgets/Dashboard.cpp index 3bef5c15..8f22093b 100644 --- a/src/widgets/Dashboard.cpp +++ b/src/widgets/Dashboard.cpp @@ -37,7 +37,7 @@ void Dashboard::refresh() void Dashboard::updateContents() { // Parse and add JSON file info - QString info = this->main->core->getFileInfo(); + QString info = CutterCore::getInstance()->getFileInfo(); QJsonDocument docu = QJsonDocument::fromJson(info.toUtf8()); QJsonObject object = docu.object(); @@ -145,12 +145,12 @@ void Dashboard::updateContents() } // Add file hashes and libraries - QString md5 = this->main->core->cmd("e file.md5"); - QString sha1 = this->main->core->cmd("e file.sha1"); + QString md5 = CutterCore::getInstance()->cmd("e file.md5"); + QString sha1 = CutterCore::getInstance()->cmd("e file.sha1"); ui->md5Edit->setText(md5); ui->sha1Edit->setText(sha1); - QString libs = this->main->core->cmd("il"); + QString libs = CutterCore::getInstance()->cmd("il"); QStringList lines = libs.split("\n", QString::SkipEmptyParts); if (!lines.isEmpty()) { @@ -189,11 +189,11 @@ void Dashboard::updateContents() ui->verticalLayout_2->addSpacerItem(spacer); // Add entropy value - QString entropy = this->main->core->cmd("ph entropy").trimmed(); + QString entropy = CutterCore::getInstance()->cmd("ph entropy").trimmed(); ui->lblEntropy->setText(entropy); // Get stats for the graphs - QStringList stats = this->main->core->getStats(); + QStringList stats = CutterCore::getInstance()->getStats(); // Add data to HTML graphs (stats) QFile html(":/html/stats.html"); diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index d1fd97d4..334f98f2 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -14,12 +14,10 @@ #undef max #endif -DisassemblerGraphView::DisassemblerGraphView(QWidget *parent, MainWindow *main) +DisassemblerGraphView::DisassemblerGraphView(QWidget *parent) : QAbstractScrollArea(parent), //currentGraph(duint(0)), //disasm(ConfigUint("Disassembler", "MaxModuleSize")), - mCore(main->core), - mMain(main), mFontMetrics(nullptr), syncOrigin(false), mCip(0), @@ -75,7 +73,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent, MainWindow *main) setupContextMenu(); //Connect to bridge - connect(main, SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); + connect(CutterCore::getInstance(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); //connect(Bridge::getBridge(), SIGNAL(loadGraph(BridgeCFGraphList*, duint)), this, SLOT(loadGraphSlot(BridgeCFGraphList*, duint))); //connect(Bridge::getBridge(), SIGNAL(graphAt(duint)), this, SLOT(graphAtSlot(duint))); //connect(Bridge::getBridge(), SIGNAL(updateGraph()), this, SLOT(updateGraphSlot())); @@ -733,11 +731,11 @@ void DisassemblerGraphView::mouseDoubleClickEvent(QMouseEvent* event) { toggleOverviewSlot(); } - /*else + else { duint instr = this->getInstrForMouseEvent(event); - DbgCmdExec(QString("graph dis.branchdest(%1), silent").arg(ToPtrString(instr)).toUtf8().constData()); - }*/ + //DbgCmdExec(QString("graph dis.branchdest(%1), silent").arg(ToPtrString(instr)).toUtf8().constData()); + } } void DisassemblerGraphView::prepareGraphNode(DisassemblerBlock & block) @@ -1543,7 +1541,7 @@ void DisassemblerGraphView::tokenizerConfigUpdatedSlot() void DisassemblerGraphView::loadCurrentGraph() { // Read functions - QJsonDocument functionsDoc = mCore->cmdj("agj"); + QJsonDocument functionsDoc = CutterCore::getInstance()->cmdj("agj"); QJsonArray functions = functionsDoc.array(); Analysis anal; diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 7e5abdde..e63c7c86 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -208,7 +208,7 @@ public: Narrow, }; - DisassemblerGraphView(QWidget *parent, MainWindow *main); + DisassemblerGraphView(QWidget *parent); ~DisassemblerGraphView(); void initFont(); void adjustSize(int width, int height); @@ -286,8 +286,7 @@ public slots: void decompileSlot(); private: - CutterCore *mCore; - MainWindow *mMain; + MainWindow* main; QString status; Analysis analysis; duint function; diff --git a/src/widgets/EntrypointWidget.cpp b/src/widgets/EntrypointWidget.cpp index 23f18bf2..0ae6154d 100644 --- a/src/widgets/EntrypointWidget.cpp +++ b/src/widgets/EntrypointWidget.cpp @@ -43,7 +43,7 @@ void EntrypointWidget::refresh() void EntrypointWidget::fillEntrypoint() { ui->entrypointTreeWidget->clear(); - for (auto i : this->main->core->getAllEntrypoint()) + for (auto i : CutterCore::getInstance()->getAllEntrypoint()) { QTreeWidgetItem *item = qhelpers::appendRow(ui->entrypointTreeWidget, RAddressString(i.vaddr), i.type); item->setData(0, Qt::UserRole, QVariant::fromValue(i)); @@ -60,6 +60,6 @@ void EntrypointWidget::setScrollMode() void EntrypointWidget::on_entrypointTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int /* column */) { EntrypointDescription ep = item->data(0, Qt::UserRole).value(); - this->main->seek(ep.vaddr); - //this->main->seek(ep.vaddr, ep.type, true); + CutterCore::getInstance()->seek(ep.vaddr); + //CutterCore::getInstance()->seek(ep.vaddr, ep.type, true); } diff --git a/src/widgets/ExportsWidget.cpp b/src/widgets/ExportsWidget.cpp index 704b75db..baee41e1 100644 --- a/src/widgets/ExportsWidget.cpp +++ b/src/widgets/ExportsWidget.cpp @@ -162,7 +162,7 @@ void ExportsWidget::refresh() void ExportsWidget::refreshExports() { exports_model->beginReloadExports(); - exports = main->core->getAllExports(); + exports = CutterCore::getInstance()->getAllExports(); exports_model->endReloadExports(); ui->exportsTreeView->resizeColumnToContents(0); @@ -179,5 +179,5 @@ void ExportsWidget::setScrollMode() void ExportsWidget::on_exportsTreeView_doubleClicked(const QModelIndex &index) { ExportDescription exp = index.data(ExportsModel::ExportDescriptionRole).value(); - this->main->seek(exp.vaddr); + CutterCore::getInstance()->seek(exp.vaddr); } diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index b38ce04b..54de3d1b 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -137,7 +137,7 @@ FlagsWidget::FlagsWidget(MainWindow *main, QWidget *parent) : ui->flagsTreeView->setModel(flags_proxy_model); ui->flagsTreeView->sortByColumn(FlagsModel::OFFSET, Qt::AscendingOrder); - connect(main->core, SIGNAL(flagsChanged()), this, SLOT(flagsChanged())); + connect(CutterCore::getInstance(), SIGNAL(flagsChanged()), this, SLOT(flagsChanged())); } FlagsWidget::~FlagsWidget() {} @@ -157,7 +157,7 @@ void FlagsWidget::refresh() void FlagsWidget::on_flagsTreeView_doubleClicked(const QModelIndex &index) { FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value(); - this->main->seek(flag.offset); + CutterCore::getInstance()->seek(flag.offset); } void FlagsWidget::on_flagspaceCombo_currentTextChanged(const QString &arg1) @@ -181,7 +181,7 @@ void FlagsWidget::refreshFlagspaces() ui->flagspaceCombo->clear(); ui->flagspaceCombo->addItem(tr("(all)")); - for (auto i : main->core->getAllFlagspaces()) + for (auto i : CutterCore::getInstance()->getAllFlagspaces()) { ui->flagspaceCombo->addItem(i.name, QVariant::fromValue(i)); } @@ -202,7 +202,7 @@ void FlagsWidget::refreshFlags() flags_model->beginReloadFlags(); - flags = main->core->getAllFlags(flagspace); + flags = CutterCore::getInstance()->getAllFlags(flagspace); flags_model->endReloadFlags(); ui->flagsTreeView->resizeColumnToContents(0); diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 130bb5d1..852ce6c0 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -26,7 +26,7 @@ FunctionModel::FunctionModel(QList *functions, QSet *i { connect(main, SIGNAL(cursorAddressChanged(RVA)), this, SLOT(cursorAddressChanged(RVA))); - connect(main->core, SIGNAL(functionRenamed(QString, QString)), this, SLOT(functionRenamed(QString, QString))); + connect(CutterCore::getInstance(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(functionRenamed(QString, QString))); } QModelIndex FunctionModel::index(int row, int column, const QModelIndex &parent) const @@ -145,7 +145,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const case Qt::ToolTipRole: { - QList info = main->core->cmd("afi @ " + function.name).split("\n"); + QList info = CutterCore::getInstance()->cmd("afi @ " + function.name).split("\n"); if (info.length() > 2) { QString size = info[4].split(" ")[1]; @@ -154,8 +154,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const return QString("Summary:\n\n Size: " + size + "\n Cyclomatic complexity: " + complex + "\n Basic blocks: " + bb + - "\n\nDisasm preview:\n\n" + main->core->cmd("pdi 10 @ " + function.name) + - "\nStrings:\n\n" + main->core->cmd("pdsf @ " + function.name)); + "\n\nDisasm preview:\n\n" + CutterCore::getInstance()->cmd("pdi 10 @ " + function.name) + + "\nStrings:\n\n" + CutterCore::getInstance()->cmd("pdsf @ " + function.name)); } return QVariant(); } @@ -226,7 +226,7 @@ void FunctionModel::updateCurrentIndex() { const FunctionDescription &function = functions->at(i); - if (function.contains(this->main->core->getOffset()) + if (function.contains(CutterCore::getInstance()->getOffset()) && function.offset >= offset) { offset = function.offset; @@ -396,10 +396,10 @@ void FunctionsWidget::refreshTree() function_model->beginReloadFunctions(); nested_function_model->beginReloadFunctions(); - functions = this->main->core->getAllFunctions(); + functions = CutterCore::getInstance()->getAllFunctions(); import_addresses.clear(); - foreach (ImportDescription import, main->core->getAllImports()) + foreach (ImportDescription import, CutterCore::getInstance()->getAllImports()) import_addresses.insert(import.plt); function_model->endReloadFunctions(); @@ -422,7 +422,7 @@ QTreeView *FunctionsWidget::getCurrentTreeView() void FunctionsWidget::functionsTreeView_doubleClicked(const QModelIndex &index) { FunctionDescription function = index.data(FunctionModel::FunctionDescriptionRole).value(); - this->main->seek(function.offset); + CutterCore::getInstance()->seek(function.offset); } void FunctionsWidget::showFunctionsContextMenu(const QPoint &pt) @@ -458,9 +458,9 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered() QString comment = c->getComment(); this->main->addDebugOutput("Comment: " + comment + " at: " + function.name); // Rename function in r2 core - this->main->core->setComment(function.offset, comment); + CutterCore::getInstance()->setComment(function.offset, comment); // Seek to new renamed function - this->main->seek(function.offset); + CutterCore::getInstance()->seek(function.offset); // TODO: Refresh functions tree widget } this->main->refreshComments(); @@ -483,7 +483,7 @@ void FunctionsWidget::on_actionFunctionsRename_triggered() // Get new function name QString new_name = r->getFunctionName(); // Rename function in r2 core - this->main->core->renameFunction(function.name, new_name); + CutterCore::getInstance()->renameFunction(function.name, new_name); // Scroll to show the new name in functions tree widget // @@ -494,7 +494,7 @@ void FunctionsWidget::on_actionFunctionsRename_triggered() // //ui->functionsTreeWidget->scrollToItem(selected_rows.first(), QAbstractItemView::PositionAtTop); // Seek to new renamed function - this->main->seek(function.offset); + CutterCore::getInstance()->seek(function.offset); } } diff --git a/src/widgets/ImportsWidget.cpp b/src/widgets/ImportsWidget.cpp index edaba360..34954a4b 100644 --- a/src/widgets/ImportsWidget.cpp +++ b/src/widgets/ImportsWidget.cpp @@ -63,7 +63,7 @@ void ImportsWidget::refresh() void ImportsWidget::fillImports() { ui->importsTreeWidget->clear(); - for (auto i : this->main->core->getAllImports()) + for (auto i : CutterCore::getInstance()->getAllImports()) { QTreeWidgetItem *item = qhelpers::appendRow(ui->importsTreeWidget, RAddressString(i.plt), i.type, "", i.name); item->setData(0, Qt::UserRole, QVariant::fromValue(i)); @@ -108,5 +108,5 @@ void ImportsWidget::setScrollMode() void ImportsWidget::on_importsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int /* column */) { ImportDescription imp = item->data(0, Qt::UserRole).value(); - this->main->seek(imp.plt); + CutterCore::getInstance()->seek(imp.plt); } diff --git a/src/widgets/MemoryWidget.cpp b/src/widgets/MemoryWidget.cpp index 328aef06..952deb52 100644 --- a/src/widgets/MemoryWidget.cpp +++ b/src/widgets/MemoryWidget.cpp @@ -25,15 +25,12 @@ #include -MemoryWidget::MemoryWidget(MainWindow *main) : - DockWidget(main), - ui(new Ui::MemoryWidget) +MemoryWidget::MemoryWidget() : + ui(new Ui::MemoryWidget), + core(CutterCore::getInstance()) { ui->setupUi(this); - // Radare core found in: - this->main = main; - this->disasTextEdit = ui->disasTextEdit_2; this->hexOffsetText = ui->hexOffsetText_2; this->hexHexText = ui->hexHexText_2; @@ -142,11 +139,11 @@ MemoryWidget::MemoryWidget(MainWindow *main) : // Create Graph View ui->tabGraph->setLayout(new QGridLayout); - mGraphView = new DisassemblerGraphView(ui->tabGraph, main); + mGraphView = new DisassemblerGraphView(ui->tabGraph); ui->tabGraph->layout()->addWidget(mGraphView); // 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); connect(graph_shortcut, SIGNAL(activated()), this, SLOT(cycleViews())); //graph_shortcut->setContext(Qt::WidgetShortcut); @@ -174,11 +171,11 @@ MemoryWidget::MemoryWidget(MainWindow *main) : connect(this->disasTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(disasmScrolled())); connect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); - connect(main, SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); - connect(main, SIGNAL(cursorAddressChanged(RVA)), this, SLOT(on_cursorAddressChanged(RVA))); - connect(main->core, SIGNAL(flagsChanged()), this, SLOT(updateViews())); - connect(main->core, SIGNAL(commentsChanged()), this, SLOT(updateViews())); - connect(main->core, SIGNAL(asmOptionsChanged()), this, SLOT(updateViews())); + connect(core, SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); + //connect(main, SIGNAL(cursorAddressChanged(RVA)), this, SLOT(on_cursorAddressChanged(RVA))); + connect(core, SIGNAL(flagsChanged()), this, SLOT(updateViews())); + connect(core, SIGNAL(commentsChanged()), this, SLOT(updateViews())); + connect(core, SIGNAL(asmOptionsChanged()), this, SLOT(updateViews())); fillPlugins(); } @@ -202,12 +199,12 @@ void MemoryWidget::on_cursorAddressChanged(RVA addr) void MemoryWidget::highlightDisasms() { // Syntax Highliting - highlighter = new Highlighter(this->main, ui->disasTextEdit_2->document()); - highlighter_5 = new Highlighter(this->main, ui->hexDisasTextEdit_2->document()); + highlighter = new Highlighter(ui->disasTextEdit_2->document()); + highlighter_5 = new Highlighter(ui->hexDisasTextEdit_2->document()); ascii_highlighter = new AsciiHighlighter(ui->hexASCIIText_2->document()); hex_highlighter = new HexHighlighter(ui->hexHexText_2->document()); - preview_highlighter = new Highlighter(this->main, ui->previewTextEdit->document()); - deco_highlighter = new Highlighter(this->main, ui->decoTextEdit->document()); + preview_highlighter = new Highlighter(ui->previewTextEdit->document()); + deco_highlighter = new Highlighter(ui->decoTextEdit->document()); } @@ -404,7 +401,7 @@ void MemoryWidget::setup() { setScrollMode(); - const QString off = main->core->cmd("afo entry0").trimmed(); + const QString off = core->cmd("afo entry0").trimmed(); RVA offset = off.toULongLong(0, 16); updateViews(offset); @@ -430,7 +427,7 @@ void MemoryWidget::refresh() void MemoryWidget::fillPlugins() { // Fill the plugins combo for the hexdump sidebar - ui->hexArchComboBox_2->insertItems(0, main->core->getAsmPluginNames()); + ui->hexArchComboBox_2->insertItems(0, core->getAsmPluginNames()); } void MemoryWidget::addTextDisasm(QString txt) @@ -472,8 +469,8 @@ bool MemoryWidget::loadMoreDisassembly() if (offset != RVA_INVALID) { - main->core->seek(offset); - QString raw = this->main->core->cmd("pd 200"); + core->seek(offset); + QString raw = this->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()); @@ -483,7 +480,7 @@ bool MemoryWidget::loadMoreDisassembly() tc.movePosition(QTextCursor::End); tc.select(QTextCursor::LineUnderCursor); QString lastline = tc.selectedText(); - this->main->addDebugOutput("Last line: " + lastline); + //this->main->addDebugOutput("Last line: " + lastline); } loaded = true; @@ -501,9 +498,9 @@ bool MemoryWidget::loadMoreDisassembly() //this->main->add_debug_output("First Offset: " + ele); if (ele.contains("0x")) { int b = this->disasTextEdit->verticalScrollBar()->maximum(); - this->main->core->cmd("ss " + ele); - this->main->core->cmd("so -50"); - QString raw = this->main->core->cmd("pd 50"); + this->core->cmd("ss " + ele); + this->core->cmd("so -50"); + QString raw = this->core->cmd("pd 50"); //this->main->add_debug_output(raw); //QString txt = raw.section("\n", 1, -1); //this->main->add_debug_output(txt); @@ -535,7 +532,7 @@ void MemoryWidget::disasmScrolled() void MemoryWidget::refreshDisasm() { - RCoreLocked lcore = this->main->core->core(); + RCoreLocked lcore = this->core->core(); // Prevent further scroll disconnect(this->disasTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(disasmScrolled())); @@ -548,14 +545,14 @@ void MemoryWidget::refreshDisasm() if (offset_changed) // new offset (seek) { disasm_top_offset = offset; - this->main->core->cmd(QString("s %1").arg(offset)); + this->core->cmd(QString("s %1").arg(offset)); } else // simple refresh { - main->core->cmd(QString("s %1").arg(disasm_top_offset)); + core->cmd(QString("s %1").arg(disasm_top_offset)); } - QString txt2 = this->main->core->cmd("pd 200"); + QString txt2 = this->core->cmd("pd 200"); disasTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); @@ -588,7 +585,7 @@ void MemoryWidget::refreshDisasm() void MemoryWidget::refreshHexdump(const QString &where) { - RCoreLocked lcore = this->main->core->core(); + RCoreLocked lcore = this->core->core(); // Prevent further scroll disconnect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); @@ -611,18 +608,18 @@ void MemoryWidget::refreshHexdump(const QString &where) } //int size; - //size = main->core->get_size(); + //size = core->get_size(); QString s = ""; if (!where.isEmpty()) { - this->main->core->cmd("ss " + where); + this->core->cmd("ss " + where); } // Add first the hexdump at block size -- - this->main->core->cmd("ss-" + this->main->core->itoa(hexdumpLength)); - //s = this->normalize_addr(this->main->core->cmd("s")); + this->core->cmd("ss-" + this->core->itoa(hexdumpLength)); + //s = this->normalize_addr(this->core->cmd("s")); QList ret = this->get_hexdump(""); hexdumpBottomOffset = lcore->offset; @@ -632,10 +629,10 @@ void MemoryWidget::refreshHexdump(const QString &where) this->resizeHexdump(); // Add then the hexdump at block size ++ - this->main->core->cmd("ss+" + this->main->core->itoa(hexdumpLength)); + this->core->cmd("ss+" + this->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")); + //QString s = "0x0" + this->core->cmd("s").split("0x")[1].trimmed(); + s = this->normalize_addr(this->core->cmd("s")); ret = this->get_hexdump(""); hexdumpBottomOffset = lcore->offset; @@ -658,7 +655,7 @@ void MemoryWidget::refreshHexdump(const QString &where) QList MemoryWidget::get_hexdump(const QString &offset) { - RCoreLocked lcore = this->main->core->core(); + RCoreLocked lcore = this->core->core(); QList ret; QString hexdump; @@ -676,17 +673,17 @@ QList MemoryWidget::get_hexdump(const QString &offset) hexdumpLength = bsize; } - //this->main->add_debug_output("BSize: " + this->main->core->itoa(hexdumpLength, 10)); + //this->main->add_debug_output("BSize: " + this->core->itoa(hexdumpLength, 10)); if (offset.isEmpty()) { - hexdump = this->main->core->cmd("px " + this->main->core->itoa(hexdumpLength, 10)); + hexdump = this->core->cmd("px " + this->core->itoa(hexdumpLength, 10)); } else { - hexdump = this->main->core->cmd("px " + this->main->core->itoa(hexdumpLength, 10) + " @ " + offset); + hexdump = this->core->cmd("px " + this->core->itoa(hexdumpLength, 10) + " @ " + offset); } - //QString hexdump = this->main->core->cmd ("px 0x" + this->main->core->itoa(size) + " @ 0x0"); + //QString hexdump = this->core->cmd ("px 0x" + this->core->itoa(size) + " @ 0x0"); // TODO: use pxl to simplify QString offsets; QString hex; @@ -742,12 +739,12 @@ void MemoryWidget::resizeHexdump() void MemoryWidget::hexScrolled() { - RCoreLocked lcore = this->main->core->core(); + RCoreLocked lcore = this->core->core(); QScrollBar *sb = this->hexASCIIText->verticalScrollBar(); if (sb->value() > sb->maximum() - 10) { - this->main->addDebugOutput("End is coming"); + //this->main->addDebugOutput("End is coming"); QTextCursor tc = this->hexOffsetText->textCursor(); tc.movePosition(QTextCursor::End); @@ -794,7 +791,7 @@ void MemoryWidget::hexScrolled() int bsize = 800; QString s = QString::number(bsize); // s = 2048.. sigh... - QString kk = this->main->core->cmd("? " + firstline + " - " + s); + QString kk = this->core->cmd("? " + firstline + " - " + s); QString k = kk.split(" ")[1]; QList ret = this->get_hexdump(k); @@ -862,15 +859,15 @@ void MemoryWidget::on_hexHexText_2_selectionChanged() QString arch = ui->hexArchComboBox_2->currentText(); QString bits = ui->hexBitsComboBox_2->currentText(); - QString oarch = this->main->core->getConfig("asm.arch"); - QString obits = this->main->core->getConfig("asm.bits"); + QString oarch = this->core->getConfig("asm.arch"); + QString obits = this->core->getConfig("asm.bits"); - this->main->core->setConfig("asm.arch", arch); - this->main->core->setConfig("asm.bits", bits); - QString str = this->main->core->cmd("pad " + sel_text); + this->core->setConfig("asm.arch", arch); + this->core->setConfig("asm.bits", bits); + QString str = this->core->cmd("pad " + sel_text); this->hexDisasTextEdit->setPlainText(str); - this->main->core->setConfig("asm.arch", oarch); - this->main->core->setConfig("asm.bits", obits); + this->core->setConfig("asm.arch", oarch); + this->core->setConfig("asm.bits", obits); //qDebug() << "Selected Arch: " << arch; //qDebug() << "Selected Bits: " << bits; //qDebug() << "Selected Text: " << sel_text; @@ -878,41 +875,41 @@ void MemoryWidget::on_hexHexText_2_selectionChanged() // TODO: update on selection changes.. use cmd("pc "+len+"@"+off) else if (parsing == "C byte array") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pc@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pc@x:" + sel_text)); } else if (parsing == "C dword array") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcw@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pcw@x:" + sel_text)); } else if (parsing == "C qword array") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcq@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pcq@x:" + sel_text)); } else if (parsing == "Assembler") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pca@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pca@x:" + sel_text)); } else if (parsing == "String") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcs@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pcs@x:" + sel_text)); } else if (parsing == "JSON") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcj@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pcj@x:" + sel_text)); } else if (parsing == "Javascript") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcJ@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->core->cmd("pcJ@x:" + sel_text)); } else if (parsing == "Python") { - this->hexDisasTextEdit->setPlainText(this->main->core->cmd("pcp@x:" + sel_text)); + this->hexDisasTextEdit->setPlainText(this->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->core->cmd("ph md5@x:" + sel_text).trimmed()); + ui->bytesSHA1->setText(this->core->cmd("ph sha1@x:" + sel_text).trimmed()); + ui->bytesEntropy->setText(this->core->cmd("ph entropy@x:" + sel_text).trimmed()); ui->bytesMD5->setCursorPosition(0); ui->bytesSHA1->setCursorPosition(0); } @@ -988,7 +985,7 @@ void MemoryWidget::showHexASCIIContextMenu(const QPoint &pt) void MemoryWidget::on_actionDisplayOptions_triggered() { - auto dialog = new AsmOptionsDialog(main->core, this); + auto dialog = new AsmOptionsDialog(core, this); dialog->show(); } @@ -1070,10 +1067,12 @@ void MemoryWidget::showXrefsDialog() QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; if (ele.contains("0x")) { - RVA addr = ele.toLongLong(0, 16); + /*TODO FIXME + * RVA addr = ele.toLongLong(0, 16); XrefsDialog *x = new XrefsDialog(this->main, this); x->fillRefsForAddress(addr, RAddressString(addr), false); x->exec(); + */ } } @@ -1196,7 +1195,8 @@ void MemoryWidget::on_actionSend_to_Notepad_triggered() { QTextCursor cursor = ui->disasTextEdit_2->textCursor(); QString text = cursor.selectedText(); - this->main->sendToNotepad(text); + // TODO + // this->main->sendToNotepad(text); } void MemoryWidget::on_actionDisasAdd_comment_triggered() @@ -1204,7 +1204,7 @@ void MemoryWidget::on_actionDisasAdd_comment_triggered() RVA offset = readCurrentDisassemblyOffset(); // Get function for clicked offset - RAnalFunction *fcn = this->main->core->functionAt(offset); + RAnalFunction *fcn = this->core->functionAt(offset); CommentsDialog *c = new CommentsDialog(this); if (c->exec()) { @@ -1212,16 +1212,16 @@ void MemoryWidget::on_actionDisasAdd_comment_triggered() QString comment = c->getComment(); //this->main->add_debug_output("Comment: " + comment + " at: " + ele); // Rename function in r2 core - this->main->core->setComment(offset, comment); + this->core->setComment(offset, comment); // Seek to new renamed function if (fcn) { - this->main->seek(fcn->addr); + core->seek(fcn->addr); } // TODO: Refresh functions tree widget } - this->main->refreshComments(); + // this->main->refreshComments(); } @@ -1229,16 +1229,17 @@ void MemoryWidget::on_actionAddFlag_triggered() { RVA offset = readCurrentDisassemblyOffset(); - FlagDialog *dialog = new FlagDialog(main->core, offset, this); + FlagDialog *dialog = new FlagDialog(core, offset, this); if (dialog->exec()) { //QString comment = dialog->getFlagName(); // Rename function in r2 core - //this->main->core->setComment(offset, comment); + //this->core->setComment(offset, comment); } - this->main->refreshComments(); + // FIXME? + // this->main->refreshComments(); } void MemoryWidget::on_actionFunctionsRename_triggered() @@ -1251,7 +1252,7 @@ void MemoryWidget::on_actionFunctionsRename_triggered() if (ele.contains("0x")) { // Get function for clicked offset - RAnalFunction *fcn = this->main->core->functionAt(ele.toLongLong(0, 16)); + RAnalFunction *fcn = this->core->functionAt(ele.toLongLong(0, 16)); RenameDialog *r = new RenameDialog(this); // Get function based on click position r->setFunctionName(fcn->name); @@ -1260,66 +1261,67 @@ void MemoryWidget::on_actionFunctionsRename_triggered() // Get new function name QString new_name = r->getFunctionName(); // Rename function in r2 core - this->main->core->renameFunction(fcn->name, new_name); + this->core->renameFunction(fcn->name, new_name); // Seek to new renamed function - this->main->seek(fcn->addr); + this->core->seek(fcn->addr); } } - this->main->refreshFunctions(); + // FIXME? + // this->main->refreshFunctions(); } void MemoryWidget::on_action8columns_triggered() { - this->main->core->setConfig("hex.cols", 8); + this->core->setConfig("hex.cols", 8); this->refreshHexdump(); } void MemoryWidget::on_action16columns_triggered() { - this->main->core->setConfig("hex.cols", 16); + this->core->setConfig("hex.cols", 16); this->refreshHexdump(); } void MemoryWidget::on_action4columns_triggered() { - this->main->core->setConfig("hex.cols", 4); + this->core->setConfig("hex.cols", 4); this->refreshHexdump(); } void MemoryWidget::on_action32columns_triggered() { - this->main->core->setConfig("hex.cols", 32); + this->core->setConfig("hex.cols", 32); this->refreshHexdump(); } void MemoryWidget::on_action64columns_triggered() { - this->main->core->setConfig("hex.cols", 64); + this->core->setConfig("hex.cols", 64); this->refreshHexdump(); } void MemoryWidget::on_action2columns_triggered() { - this->main->core->setConfig("hex.cols", 2); + this->core->setConfig("hex.cols", 2); this->refreshHexdump(); } void MemoryWidget::on_action1column_triggered() { - this->main->core->setConfig("hex.cols", 1); + this->core->setConfig("hex.cols", 1); this->refreshHexdump(); } void MemoryWidget::on_xreFromTreeWidget_2_itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) { XrefDescription xref = item->data(0, Qt::UserRole).value(); - this->main->seek(xref.to); + this->core->seek(xref.to); } void MemoryWidget::on_xrefToTreeWidget_2_itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) { XrefDescription xref = item->data(0, Qt::UserRole).value(); - this->main->seek(xref.from); + this->core->seek(xref.from); } void MemoryWidget::on_xrefFromToolButton_2_clicked() @@ -1367,10 +1369,10 @@ void MemoryWidget::on_codeCombo_2_currentTextChanged(const QString &arg1) void MemoryWidget::get_refs_data(RVA addr) { // refs = calls q hace esa funcion - QList refs = main->core->getXRefs(addr, false, false); + QList refs = core->getXRefs(addr, false, false); // xrefs = calls a esa funcion - QList xrefs = main->core->getXRefs(addr, true, false); + QList xrefs = core->getXRefs(addr, true, false); // Data for the disasm side graph QList data; @@ -1378,13 +1380,13 @@ void MemoryWidget::get_refs_data(RVA addr) data << refs.size(); //qDebug() << "XRefs:" << xrefs.size(); data << xrefs.size(); - //qDebug() << "CC: " << this->main->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16)); - //data << this->main->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16)); - data << this->main->core->getCycloComplex(addr); - //qDebug() << "BB: " << this->main->core->fcnBasicBlockCount(offset.toLong(&ok, 16)); - data << this->main->core->fcnBasicBlockCount(addr); - data << this->main->core->fcnEndBbs(addr); - //qDebug() << "MEOW: " + this->main->core->fcnEndBbs(offset); + //qDebug() << "CC: " << this->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16)); + //data << this->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16)); + data << this->core->getCycloComplex(addr); + //qDebug() << "BB: " << this->core->fcnBasicBlockCount(offset.toLong(&ok, 16)); + data << this->core->fcnBasicBlockCount(addr); + data << this->core->fcnEndBbs(addr); + //qDebug() << "MEOW: " + this->core->fcnEndBbs(offset); // Update disasm side bar this->fill_refs(refs, xrefs, data); @@ -1398,9 +1400,9 @@ void MemoryWidget::fill_refs(QList refs, QList XrefDescription xref = refs[i]; QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, RAddressString(xref.to)); - tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from)); + tempItem->setText(1, core->disassembleSingleInstruction(xref.from)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); - QString tooltip = this->main->core->cmd("pdi 10 @ " + QString::number(xref.to)).trimmed(); + QString tooltip = this->core->cmd("pdi 10 @ " + QString::number(xref.to)).trimmed(); tempItem->setToolTip(0, tooltip); tempItem->setToolTip(1, tooltip); this->xreFromTreeWidget_2->insertTopLevelItem(0, tempItem); @@ -1419,11 +1421,11 @@ void MemoryWidget::fill_refs(QList refs, QList QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, RAddressString(xref.from)); - tempItem->setText(1, main->core->disassembleSingleInstruction(xref.from)); + tempItem->setText(1, core->disassembleSingleInstruction(xref.from)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); - QString tooltip = this->main->core->cmd("pdi 10 @ " + QString::number(xref.from)).trimmed(); - tempItem->setToolTip(0, this->main->core->cmd("pdi 10 @ " + tooltip).trimmed()); - tempItem->setToolTip(1, this->main->core->cmd("pdi 10 @ " + tooltip).trimmed()); + QString tooltip = this->core->cmd("pdi 10 @ " + QString::number(xref.from)).trimmed(); + tempItem->setToolTip(0, this->core->cmd("pdi 10 @ " + tooltip).trimmed()); + tempItem->setToolTip(1, this->core->cmd("pdi 10 @ " + tooltip).trimmed()); this->xrefToTreeWidget_2->insertTopLevelItem(0, tempItem); } // Adjust columns to content @@ -1463,7 +1465,7 @@ void MemoryWidget::fill_refs(QList refs, QList void MemoryWidget::fillOffsetInfo(QString off) { ui->offsetTreeWidget->clear(); - QString raw = this->main->core->getOffsetInfo(off); + QString raw = this->core->getOffsetInfo(off); QList lines = raw.split("\n", QString::SkipEmptyParts); foreach (QString line, lines) { @@ -1482,7 +1484,7 @@ void MemoryWidget::fillOffsetInfo(QString off) } // Add opcode description - QStringList description = this->main->core->cmd("?d. @ " + off).split(": "); + QStringList description = this->core->cmd("?d. @ " + off).split(": "); if (description.length() >= 2) { ui->opcodeDescText->setPlainText("# " + description[0] + ":\n" + description[1]); @@ -1491,7 +1493,7 @@ void MemoryWidget::fillOffsetInfo(QString off) QString MemoryWidget::normalize_addr(QString addr) { - QString base = this->main->core->cmd("s").split("0x")[1].trimmed(); + QString base = this->core->cmd("s").split("0x")[1].trimmed(); int len = base.length(); if (len < 8) { @@ -1512,15 +1514,15 @@ void MemoryWidget::setFcnName(RVA addr) RAnalFunction *fcn; QString addr_string; - fcn = this->main->core->functionAt(addr); + fcn = this->core->functionAt(addr); if (fcn) { - QString segment = this->main->core->cmd("S. @ " + QString::number(addr)).split(" ").last(); + QString segment = this->core->cmd("S. @ " + QString::number(addr)).split(" ").last(); addr_string = segment.trimmed() + ":" + fcn->name; } else { - addr_string = main->core->cmdFunctionAt(addr); + addr_string = core->cmdFunctionAt(addr); } ui->fcnNameEdit->setText(addr_string); @@ -1541,12 +1543,13 @@ void MemoryWidget::on_disasTextEdit_2_cursorPositionChanged() if (ele.contains("0x")) { this->fillOffsetInfo(ele); - QString at = this->main->core->cmdFunctionAt(ele); - QString deco = this->main->core->getDecompiledCode(at); + QString at = this->core->cmdFunctionAt(ele); + QString deco = this->core->getDecompiledCode(at); RVA addr = ele.midRef(2).toULongLong(0, 16); - this->main->setCursorAddress(addr); + // FIXME per widget CursorAddress no? + // this->main->setCursorAddress(addr); if (deco != "") { @@ -1557,11 +1560,11 @@ void MemoryWidget::on_disasTextEdit_2_cursorPositionChanged() ui->decoTextEdit->setPlainText(""); } // Get jump information to fill the preview - QString jump = this->main->core->getOffsetJump(ele); + QString jump = this->core->getOffsetJump(ele); if (!jump.isEmpty()) { // Fill the preview - QString jump_code = this->main->core->cmd("pdf @ " + jump); + QString jump_code = this->core->cmd("pdf @ " + jump); ui->previewTextEdit->setPlainText(jump_code.trimmed()); ui->previewTextEdit->moveCursor(QTextCursor::End); ui->previewTextEdit->find(jump.trimmed(), QTextDocument::FindBackward); @@ -1578,7 +1581,8 @@ void MemoryWidget::on_disasTextEdit_2_cursorPositionChanged() //this->main->add_debug_output("New Fcn: '" + this->last_fcn + "'"); // Refresh function information at sidebar ui->fcnNameEdit->setText(at); - this->main->memoryDock->setWindowTitle(at); + // FIXME TITLE? + // this->main->memoryDock->setWindowTitle(at); //this->main->memoryDock->create_graph(ele); this->setMiniGraph(at); } @@ -1605,8 +1609,8 @@ QString MemoryWidget::normalizeAddr(QString addr) void MemoryWidget::setMiniGraph(QString at) { - QString dot = this->main->core->getSimpleGraph(at); - //QString dot = this->main->core->cmd("agc " + at); + QString dot = this->core->getSimpleGraph(at); + //QString dot = this->core->cmd("agc " + at); // Add data to HTML Polar functions graph QFile html(":/html/graph.html"); if (!html.open(QIODevice::ReadOnly)) @@ -1698,6 +1702,8 @@ void MemoryWidget::on_previewToolButton_2_clicked() void MemoryWidget::resizeEvent(QResizeEvent *event) { + // FIXME + /* if (main->responsive && isVisible()) { if (event->size().width() <= 1150) @@ -1725,6 +1731,7 @@ void MemoryWidget::resizeEvent(QResizeEvent *event) ui->previewToolButton_2->setChecked(true); } } + */ QDockWidget::resizeEvent(event); } @@ -1741,22 +1748,22 @@ bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) QString ele = eles.isEmpty() ? "" : eles[0]; if (ele.contains("0x")) { - QString jump = this->main->core->getOffsetJump(ele); + QString jump = this->core->getOffsetJump(ele); if (!jump.isEmpty()) { if (jump.contains("0x")) { - QString fcn = this->main->core->cmdFunctionAt(jump); + QString fcn = this->core->cmdFunctionAt(jump); if (!fcn.isEmpty()) { RVA addr = jump.trimmed().toULongLong(0, 16); - this->main->seek(addr); + this->core->seek(addr); } } else { - RVA addr = this->main->core->cmd("?v " + jump).toULongLong(0, 16); - this->main->seek(addr); + RVA addr = this->core->cmd("?v " + jump).toULongLong(0, 16); + this->core->seek(addr); } } } @@ -1781,7 +1788,8 @@ void MemoryWidget::on_copyMD5_clicked() QString md5 = ui->bytesMD5->text(); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(md5); - this->main->addOutput("MD5 copied to clipboard: " + md5); + // FIXME + // this->main->addOutput("MD5 copied to clipboard: " + md5); } void MemoryWidget::on_copySHA1_clicked() @@ -1789,7 +1797,8 @@ void MemoryWidget::on_copySHA1_clicked() QString sha1 = ui->bytesSHA1->text(); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(sha1); - this->main->addOutput("SHA1 copied to clipboard: " + sha1); + // FIXME + // this->main->addOutput("SHA1 copied to clipboard: " + sha1); } void MemoryWidget::switchTheme(bool dark) @@ -1807,8 +1816,8 @@ void MemoryWidget::switchTheme(bool dark) 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(); + QString arch = this->core->cmd("e asm.arch").trimmed(); + QString bits = this->core->cmd("e asm.bits").trimmed(); //int arch_index = ui->hexArchComboBox_2->findText(arch); if (ui->hexArchComboBox_2->findText(arch) != -1) @@ -1826,7 +1835,8 @@ void MemoryWidget::selectHexPreview() void MemoryWidget::seek_back() { //this->main->add_debug_output("Back!"); - this->main->backButton_clicked(); + // FIXME + // this->main->backButton_clicked(); } void MemoryWidget::on_memTabWidget_currentChanged(int /*index*/) @@ -1844,9 +1854,12 @@ void MemoryWidget::updateViews(RVA offset) int index = ui->memTabWidget->tabBar()->currentIndex(); - RVA cursor_addr = main->getCursorAddress(); - - QString cursor_addr_string = RAddressString(cursor_addr); + // Anyway updateViews will die after break this widget. + // FIXME? One cursor per widget ? (if not synced) + // RVA cursor_addr = main->getCursorAddress(); + // QString cursor_addr_string = RAddressString(cursor_addr); + QString cursor_addr_string = core->cmd("s"); + RVA cursor_addr = cursor_addr_string.toULongLong(); if (offset != RVA_INVALID) next_disasm_top_offset = offset; @@ -1873,11 +1886,11 @@ void MemoryWidget::showOffsets(bool show) if (show) { this->hexOffsetText->show(); - main->core->setConfig("asm.offset", 1); + core->setConfig("asm.offset", 1); } else { this->hexOffsetText->hide(); - main->core->setConfig("asm.offset", 0); + core->setConfig("asm.offset", 0); } } diff --git a/src/widgets/MemoryWidget.h b/src/widgets/MemoryWidget.h index cca19781..313e0f30 100644 --- a/src/widgets/MemoryWidget.h +++ b/src/widgets/MemoryWidget.h @@ -18,7 +18,6 @@ #include "Dashboard.h" #include "widgets/DisassemblerGraphView.h" -class MainWindow; namespace Ui { @@ -30,14 +29,13 @@ class MemoryWidget : public DockWidget Q_OBJECT public: - explicit MemoryWidget(MainWindow *main); + explicit MemoryWidget(); ~MemoryWidget(); void setup() override; void refresh() override; - MainWindow *main; QPlainTextEdit *disasTextEdit; QTextEdit *hexOffsetText; QPlainTextEdit *hexDisasTextEdit; @@ -96,6 +94,7 @@ protected: private: std::unique_ptr ui; + CutterCore *core; ut64 hexdumpTopOffset; ut64 hexdumpBottomOffset; diff --git a/src/widgets/Notepad.cpp b/src/widgets/Notepad.cpp index af1a4a2f..2fb0c44d 100644 --- a/src/widgets/Notepad.cpp +++ b/src/widgets/Notepad.cpp @@ -180,7 +180,7 @@ void Notepad::on_redoButton_clicked() void Notepad::highlightPreview() { - disasm_highlighter = new Highlighter(this->main, ui->previewTextEdit->document()); + disasm_highlighter = new Highlighter(ui->previewTextEdit->document()); } void Notepad::on_searchEdit_returnPressed() @@ -337,25 +337,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(CutterCore::getInstance()->cmd("pd 100 @ " + this->addr)); } void Notepad::on_actionDisassmble_function_triggered() { - ui->previewTextEdit->setPlainText(this->main->core->cmd("pdf @ " + this->addr)); + ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pdf @ " + this->addr)); } void Notepad::on_actionHexdump_bytes_triggered() { - ui->previewTextEdit->setPlainText(this->main->core->cmd("px 1024 @ " + this->addr)); + ui->previewTextEdit->setPlainText(CutterCore::getInstance()->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(CutterCore::getInstance()->cmd("pxi 1024 @ " + this->addr)); } void Notepad::on_actionHexdump_function_triggered() { - ui->previewTextEdit->setPlainText(this->main->core->cmd("pxf @ " + this->addr)); + ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pxf @ " + this->addr)); } diff --git a/src/widgets/Omnibar.cpp b/src/widgets/Omnibar.cpp index 49cb6833..e961c56a 100644 --- a/src/widgets/Omnibar.cpp +++ b/src/widgets/Omnibar.cpp @@ -174,9 +174,9 @@ void Omnibar::on_gotoEntry_returnPressed() } 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().toInt()); + //CutterCore::getInstance()->seek(CutterCore::getInstance()->cmd("?v " + this->text()), this->text()); + QString off = CutterCore::getInstance()->cmd("afo " + this->text()); + CutterCore::getInstance()->seek(off.trimmed().toInt()); } } diff --git a/src/widgets/RelocsWidget.cpp b/src/widgets/RelocsWidget.cpp index 5d1b7df5..f567109a 100644 --- a/src/widgets/RelocsWidget.cpp +++ b/src/widgets/RelocsWidget.cpp @@ -37,14 +37,14 @@ void RelocsWidget::on_relocsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, // Get offset and name of item double clicked RelocDescription reloc = item->data(0, Qt::UserRole).value(); - main->seek(reloc.vaddr); + CutterCore::getInstance()->seek(reloc.vaddr); } void RelocsWidget::fillTreeWidget() { ui->relocsTreeWidget->clear(); - for (auto i : main->core->getAllRelocs()) + for (auto i : CutterCore::getInstance()->getAllRelocs()) { QTreeWidgetItem *item = qhelpers::appendRow(ui->relocsTreeWidget, RAddressString(i.vaddr), i.type, i.name); item->setData(0, Qt::UserRole, QVariant::fromValue(i)); diff --git a/src/widgets/SdbDock.cpp b/src/widgets/SdbDock.cpp index 25e75629..b787ab47 100644 --- a/src/widgets/SdbDock.cpp +++ b/src/widgets/SdbDock.cpp @@ -27,19 +27,19 @@ void SdbDock::reload(QString path) ui->treeWidget->clear(); QList keys; /* key-values */ - keys = main->core->sdbListKeys(path); + keys = CutterCore::getInstance()->sdbListKeys(path); foreach (QString key, keys) { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, key); - tempItem->setText(1, main->core->sdbGet(path, key)); + tempItem->setText(1, CutterCore::getInstance()->sdbGet(path, key)); tempItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable); ui->treeWidget->insertTopLevelItem(0, tempItem); } ui->treeWidget->resizeColumnToContents(0); ui->treeWidget->resizeColumnToContents(1); /* namespaces */ - keys = main->core->sdbList(path); + keys = CutterCore::getInstance()->sdbList(path); keys.append(".."); foreach (QString key, keys) { diff --git a/src/widgets/SectionsWidget.cpp b/src/widgets/SectionsWidget.cpp index 7fa5111e..e46fd937 100644 --- a/src/widgets/SectionsWidget.cpp +++ b/src/widgets/SectionsWidget.cpp @@ -24,7 +24,7 @@ void SectionsWidget::setup() tree->clear(); int row = 0; - for (auto section : main->core->getAllSections()) + for (auto section : CutterCore::getInstance()->getAllSections()) { if (!section.name.contains(".")) continue; diff --git a/src/widgets/Sidebar.cpp b/src/widgets/Sidebar.cpp index a7af779b..fed68c96 100644 --- a/src/widgets/Sidebar.cpp +++ b/src/widgets/Sidebar.cpp @@ -93,17 +93,17 @@ 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(CutterCore::getInstance()->math(arg1))); } void SideBar::on_asm2hex_clicked() { - ui->hexInput->setPlainText(main->core->assemble(ui->asmInput->toPlainText())); + ui->hexInput->setPlainText(CutterCore::getInstance()->assemble(ui->asmInput->toPlainText())); } void SideBar::on_hex2asm_clicked() { - ui->asmInput->setPlainText(main->core->disassemble(ui->hexInput->toPlainText())); + ui->asmInput->setPlainText(CutterCore::getInstance()->disassemble(ui->hexInput->toPlainText())); } void SideBar::on_respButton_toggled(bool checked) diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index ecdc33d5..c85aca6a 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -38,13 +38,13 @@ void StringsWidget::on_stringsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item // Get offset and name of item double clicked // TODO: use this info to change disasm contents StringDescription str = item->data(0, Qt::UserRole).value(); - this->main->seek(str.vaddr); + CutterCore::getInstance()->seek(str.vaddr); } void StringsWidget::fillTreeWidget() { ui->stringsTreeWidget->clear(); - for (auto i : main->core->getAllStrings()) + for (auto i : CutterCore::getInstance()->getAllStrings()) { QTreeWidgetItem *item = qhelpers::appendRow(ui->stringsTreeWidget, RAddressString(i.vaddr), i.string); item->setData(0, Qt::UserRole, QVariant::fromValue(i)); diff --git a/src/widgets/SymbolsWidget.cpp b/src/widgets/SymbolsWidget.cpp index 45cccd2a..0f7161bb 100644 --- a/src/widgets/SymbolsWidget.cpp +++ b/src/widgets/SymbolsWidget.cpp @@ -7,10 +7,9 @@ #include -SymbolsWidget::SymbolsWidget(MainWindow *main, QWidget *parent) : +SymbolsWidget::SymbolsWidget(QWidget *parent) : DockWidget(parent), - ui(new Ui::SymbolsWidget), - main(main) + ui(new Ui::SymbolsWidget) { ui->setupUi(this); @@ -37,13 +36,13 @@ void SymbolsWidget::on_symbolsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item // Get offset and name of item double clicked SymbolDescription symbol = item->data(0, Qt::UserRole).value(); - this->main->seek(symbol.vaddr); + CutterCore::getInstance()->seek(symbol.vaddr); } void SymbolsWidget::fillSymbols() { ui->symbolsTreeWidget->clear(); - for (auto symbol : this->main->core->getAllSymbols()) + for (auto symbol : CutterCore::getInstance()->getAllSymbols()) { QTreeWidgetItem *item = qhelpers::appendRow(ui->symbolsTreeWidget, RAddressString(symbol.vaddr), diff --git a/src/widgets/SymbolsWidget.h b/src/widgets/SymbolsWidget.h index 69e8f657..4c42a09b 100644 --- a/src/widgets/SymbolsWidget.h +++ b/src/widgets/SymbolsWidget.h @@ -17,7 +17,7 @@ class SymbolsWidget : public DockWidget Q_OBJECT public: - explicit SymbolsWidget(MainWindow *main, QWidget *parent = 0); + explicit SymbolsWidget(QWidget *parent = 0); ~SymbolsWidget(); void setup() override; @@ -29,7 +29,6 @@ private slots: private: std::unique_ptr ui; - MainWindow *main; void fillSymbols(); void setScrollMode();