diff --git a/src/createnewdialog.cpp b/src/createnewdialog.cpp index 4c745446..a93b17e8 100644 --- a/src/createnewdialog.cpp +++ b/src/createnewdialog.cpp @@ -64,7 +64,7 @@ void createNewDialog::on_exampleButton_clicked() { str = "48656c6c6f20576f726c6400"; } - else fprintf(stderr, tr("Unknown combo value selected").toLocal8Bit().constData()); + else fprintf(stderr, "%s", tr("Unknown combo value selected").toLocal8Bit().constData()); if (str.length() > 0) ui->plainTextEdit->setPlainText(str); // } diff --git a/src/cutter.cpp b/src/cutter.cpp index 4ab4562c..6c3c5ef1 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -311,7 +311,8 @@ void CutterCore::analyze(int level, QList advanced) } else if (level == 3) { - foreach(QString option, advanced){ + foreach (QString option, advanced) + { r_core_cmd0(core_, option.toStdString().c_str()); } } @@ -323,6 +324,7 @@ void CutterCore::renameFunction(QString prev_name, QString new_name) emit functionRenamed(prev_name, new_name); } + void CutterCore::setComment(RVA addr, QString cmt) { //r_meta_add (core->anal, 'C', addr, 1, cmt.toUtf8()); @@ -330,7 +332,6 @@ void CutterCore::setComment(RVA addr, QString cmt) emit commentsChanged(); } - void CutterCore::delComment(ut64 addr) { CORE_LOCK(); @@ -358,20 +359,22 @@ QMap>> CutterCore::getNestedComments() return ret; } + + void CutterCore::seek(QString addr) { if (addr.length() > 0) seek(this->math(addr.toUtf8().constData())); } - - void CutterCore::seek(ut64 offset) { CORE_LOCK(); r_core_seek(this->core_, offset, true); } + + bool CutterCore::tryFile(QString path, bool rw) { CORE_LOCK(); @@ -386,8 +389,9 @@ bool CutterCore::tryFile(QString path, bool rw) } bool is_writable = false; - if (cf->core && cf->core->io && cf->core->io->desc) { - is_writable = cf->core->io->desc->flags & R_IO_WRITE; + if (cf->core && cf->core->io && cf->core->io->desc) + { + is_writable = cf->core->io->desc->flags & R_IO_WRITE; } // if rbin works, tell entry0, and symbols (main, constructor, ..) @@ -399,44 +403,6 @@ bool CutterCore::tryFile(QString path, bool rw) return true; } - - -QList CutterCore::getList(const QString &type, const QString &subtype) -{ - CORE_LOCK(); - QList ret = QList(); - - if (type == "bin") - { - if (subtype == "types") - { - ret << "raw"; - auto ft = sdb_const_get(DB, "try.filetype", 0); - if (ft && *ft) - ret << ft; - } - else if (subtype == "entrypoints") - { - if (math("entry0") != 0) - ret << "entry0"; - } - } - else if (type == "asm") - { - if (subtype == "cpus") - { - QString funcs = cmd("e asm.cpu=?"); - QStringList lines = funcs.split("\n"); - for (auto cpu : lines) - { - ret << cpu; - } - } - } - - return ret; -} - ut64 CutterCore::math(const QString &expr) { CORE_LOCK(); @@ -720,6 +686,10 @@ void CutterCore::getOpcodes() this->regs.removeLast(); } + + + + void CutterCore::setSettings() { config("scr.color", "false"); @@ -785,8 +755,6 @@ void CutterCore::setSettings() - - QList CutterCore::getSeekHistory() { CORE_LOCK(); @@ -799,8 +767,6 @@ QList CutterCore::getSeekHistory() return ret; } - - QStringList CutterCore::getAsmPluginNames() { CORE_LOCK(); @@ -816,6 +782,7 @@ QStringList CutterCore::getAsmPluginNames() return ret; } + QStringList CutterCore::getAnalPluginNames() { CORE_LOCK(); @@ -832,6 +799,7 @@ QStringList CutterCore::getAnalPluginNames() } + QStringList CutterCore::getProjectNames() { CORE_LOCK(); @@ -845,7 +813,6 @@ QStringList CutterCore::getProjectNames() } - QList CutterCore::getAllFunctions() { CORE_LOCK(); @@ -870,6 +837,7 @@ QList CutterCore::getAllFunctions() } + QList CutterCore::getAllImports() { CORE_LOCK(); @@ -896,7 +864,6 @@ QList CutterCore::getAllImports() } - QList CutterCore::getAllExports() { CORE_LOCK(); @@ -962,7 +929,6 @@ QList CutterCore::getAllSymbols() return ret; } - QList CutterCore::getAllComments(const QString &filterType) { CORE_LOCK(); @@ -1015,6 +981,7 @@ QList CutterCore::getAllRelocs() return ret; } + QList CutterCore::getAllStrings() { CORE_LOCK(); @@ -1109,7 +1076,6 @@ QList CutterCore::getAllSections() return ret; } - QList CutterCore::getAllEntrypoint() { CORE_LOCK(); @@ -1176,3 +1142,8 @@ void CutterCore::addFlag(RVA offset, QString name, RVA size) cmd(QString("f %1 %2 @ %3").arg(name).arg(size).arg(offset)); emit flagsChanged(); } + +void CutterCore::loadPDB(const QString &file) +{ + cmd("idp " + sanitizeStringForCommand(file)); +} diff --git a/src/cutter.h b/src/cutter.h index 4a4f258b..012461e4 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -1,4 +1,4 @@ -#ifndef CUTTER_H +#ifndef CUTTER_H #define CUTTER_H #include @@ -186,6 +186,7 @@ public: int fcnEndBbs(RVA addr); 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; } void renameFunction(QString prev_name, QString new_name); void setComment(RVA addr, QString cmt); void delComment(ut64 addr); @@ -231,7 +232,7 @@ public: QList regs; void setSettings(); - QList getList(const QString &type, const QString &subtype = ""); + void loadPDB(const QString &file); QList getSeekHistory(); diff --git a/src/dialogs/aboutdialog.cpp b/src/dialogs/aboutdialog.cpp index 33fb37ec..11be3cdd 100644 --- a/src/dialogs/aboutdialog.cpp +++ b/src/dialogs/aboutdialog.cpp @@ -9,12 +9,12 @@ AboutDialog::AboutDialog(QWidget *parent) : ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); ui->label->setText(tr("

Cutter

" - "Version 1.0 alpha
" - "Using r2-" R2_GITTAP - "

License

" - "This Software is released under the GNU General Public License v3.0" - "

Authors

" - "Hugo Teso <hugo.teso@gmail.org>\nSoon to be thousands more!")); + "Version 1.0 alpha
" + "Using r2-" R2_GITTAP + "

License

" + "This Software is released under the GNU General Public License v3.0" + "

Authors

" + "Hugo Teso <hugo.teso@gmail.org>\nSoon to be thousands more!")); } AboutDialog::~AboutDialog() diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8607afd9..f6de7191 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -93,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent) : highlighter(nullptr), hex_highlighter(nullptr), graphicsBar(nullptr), + entrypointDock(nullptr), functionsDock(nullptr), importsDock(nullptr), exportsDock(nullptr), @@ -107,7 +108,6 @@ MainWindow::MainWindow(QWidget *parent) : sidebar_action(nullptr), sectionsDock(nullptr), consoleWidget(nullptr), - entrypointDock(nullptr), webserver(core) { doLock = false; @@ -183,14 +183,17 @@ void MainWindow::initUI() // Asm syntaxes QList list = core->cmd("e asm.syntax =?").split("\n"); QString checked = core->getConfig("asm.syntax"); - for (QString syntax : list) { - if (syntax == "") { + for (QString syntax : list) + { + if (syntax == "") + { break; } - QAction* action = new QAction(ui->menuAsm_syntax); - action->setText(syntax); + QAction *action = new QAction(ui->menuAsm_syntax); + action->setText(syntax); action->setCheckable(true); - if (syntax == checked) { + if (syntax == checked) + { action->setChecked(true); } connect(action, SIGNAL(triggered()), this, SLOT(actionAsm_syntax_triggered())); @@ -1113,13 +1116,14 @@ void MainWindow::on_actionDisplay_Offsets_triggered() void MainWindow::actionAsm_syntax_triggered() { - QObject* sender = QObject::sender(); + QObject *sender = QObject::sender(); // Uncheck every other choices - for (QAction* action : asmSyntaxes) { + for (QAction *action : asmSyntaxes) + { action->setChecked(false); } // Check selected choice - QAction* action = (QAction*) sender; + QAction *action = (QAction *) sender; action->setChecked(true); // Set r2 config core->config("asm.syntax", action->text()); diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 52d2cc69..17020cea 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -11,6 +11,7 @@ #include #include +#include OptionsDialog::OptionsDialog(MainWindow *main): QDialog(0), // parent may not be main @@ -29,7 +30,20 @@ OptionsDialog::OptionsDialog(MainWindow *main): // Fill the plugins combo asm_plugins = main->core->getAsmPluginNames(); for (auto plugin : asm_plugins) - ui->processorComboBox->addItem(plugin, plugin); + ui->archComboBox->addItem(plugin, plugin); + ui->archComboBox->setToolTip(main->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()); + updateCPUComboBox(); + + // os combo box + for (const auto &plugin : main->core->cmdList("e asm.os=?")) + ui->kernelComboBox->addItem(plugin, plugin); + ui->kernelComboBox->setToolTip(main->core->cmd("e? asm.os").trimmed()); + + ui->bitsComboBox->setToolTip(main->core->cmd("e? asm.bits").trimmed()); // Restore settings QSettings settings; @@ -42,6 +56,10 @@ OptionsDialog::OptionsDialog(MainWindow *main): ui->hideFrame->setVisible(false); ui->analoptionsFrame->setVisible(false); + updatePDBLayout(); + + connect(ui->pdbCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updatePDBLayout())); + // Add this so the dialog resizes when widgets are shown/hidden //this->layout()->setSizeConstraint(QLayout::SetFixedSize); @@ -57,6 +75,54 @@ OptionsDialog::~OptionsDialog() delete ui; } +void OptionsDialog::updateCPUComboBox() +{ + QString currentText = ui->cpuComboBox->lineEdit()->text(); + ui->cpuComboBox->clear(); + + QString cmd = "e asm.cpu=?"; + + QString arch = getSelectedArch(); + if (!arch.isNull()) + cmd += " @a:" + arch; + + ui->cpuComboBox->addItem(""); + ui->cpuComboBox->addItems(main->core->cmdList(cmd)); + + ui->cpuComboBox->lineEdit()->setText(currentText); +} + +QString OptionsDialog::getSelectedArch() +{ + QVariant archValue = ui->archComboBox->currentData(); + return archValue.isValid() ? archValue.toString() : nullptr; +} + +QString OptionsDialog::getSelectedCPU() +{ + QString cpu = ui->cpuComboBox->currentText(); + if (cpu.isNull() || cpu.isEmpty()) + return nullptr; + return cpu; +} + +int OptionsDialog::getSelectedBits() +{ + QString sel_bits = ui->bitsComboBox->currentText(); + if (sel_bits != "Auto") + { + return sel_bits.toInt(); + } + + return 0; +} + +QString OptionsDialog::getSelectedOS() +{ + QVariant os = ui->kernelComboBox->currentData(); + return os.isValid() ? os.toString() : nullptr; +} + void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) { ui->analSlider->setValue(level); @@ -93,18 +159,8 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) // // Advanced Options // - QVariant archValue = ui->processorComboBox->currentData(); - int bits = 0; - QString sel_bits = ui->bitsComboBox->currentText(); - if (sel_bits != "Auto") - { - bits = sel_bits.toInt(); - } - - main->core->setCPU(archValue.isValid() ? archValue.toString() : NULL, - QString(), - bits); + main->core->setCPU(getSelectedArch(), getSelectedCPU(), getSelectedBits()); bool rw = false; bool load_bininfo = ui->binCheckBox->isChecked(); @@ -135,6 +191,20 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) //ui->progressBar->setValue(40); ui->statusLabel->setText(tr("Analysis in progress")); + + QString os = getSelectedOS(); + if (!os.isNull()) + { + main->core->cmd("e asm.os=" + os); + } + + + if (ui->pdbCheckBox->isChecked()) + { + main->core->loadPDB(ui->pdbLineEdit->text()); + } + + // Threads stuff // connect signal/slot analThread.start(main->core, level, advanced); @@ -148,38 +218,50 @@ void OptionsDialog::on_closeButton_clicked() void OptionsDialog::on_okButton_clicked() { QList advanced = QList(); - if (ui->analSlider->value() == 3){ - if (ui->aa_symbols->isChecked()){ + if (ui->analSlider->value() == 3) + { + if (ui->aa_symbols->isChecked()) + { advanced << "aa"; } - if (ui->aar_references->isChecked()){ + if (ui->aar_references->isChecked()) + { advanced << "aar"; } - if (ui->aac_calls->isChecked()){ + if (ui->aac_calls->isChecked()) + { advanced << "aac"; } - if (ui->aan_rename->isChecked()){ + if (ui->aan_rename->isChecked()) + { advanced << "aan"; } - if (ui->aae_emulate->isChecked()){ + if (ui->aae_emulate->isChecked()) + { advanced << "aae"; } - if (ui->aat_consecutive->isChecked()){ + if (ui->aat_consecutive->isChecked()) + { advanced << "aat"; } - if (ui->afta_typeargument->isChecked()){ + if (ui->afta_typeargument->isChecked()) + { advanced << "afta"; } - if (ui->aaT_aftertrap->isChecked()){ + if (ui->aaT_aftertrap->isChecked()) + { advanced << "aaT"; } - if (ui->aap_preludes->isChecked()){ + if (ui->aap_preludes->isChecked()) + { advanced << "aap"; } - if (ui->jmptbl->isChecked()){ + if (ui->jmptbl->isChecked()) + { advanced << "e! anal.jmptbl"; } - if (ui->pushret->isChecked()){ + if (ui->pushret->isChecked()) + { advanced << "e! anal.pushret"; } } @@ -247,7 +329,7 @@ void OptionsDialog::on_analSlider_valueChanged(int value) { ui->analCheckBox->setChecked(true); ui->analCheckBox->setText(tr("Analysis: Enabled")); - if (value==3) + if (value == 3) { ui->analoptionsFrame->setVisible(true); } @@ -278,3 +360,32 @@ void OptionsDialog::on_analCheckBox_clicked(bool checked) defaultAnalLevel = ui->analSlider->value(); ui->analSlider->setValue(checked ? defaultAnalLevel : 0); } + +void OptionsDialog::on_archComboBox_currentIndexChanged(int) +{ + updateCPUComboBox(); +} + +void OptionsDialog::updatePDBLayout() +{ + ui->pdbWidget->setEnabled(ui->pdbCheckBox->isChecked()); +} + +void OptionsDialog::on_pdbSelectButton_clicked() +{ + QFileDialog dialog(this); + dialog.setWindowTitle(tr("Select PDB file")); + dialog.setNameFilters({ tr("PDB file (*.pdb)"), tr("All files (*)") }); + + if (!dialog.exec()) + { + return; + } + + QString fileName = dialog.selectedFiles().first(); + + if (!fileName.isEmpty()) + { + ui->pdbLineEdit->setText(fileName); + } +} diff --git a/src/optionsdialog.h b/src/optionsdialog.h index 2605c1ba..691d8399 100644 --- a/src/optionsdialog.h +++ b/src/optionsdialog.h @@ -27,19 +27,18 @@ public: private slots: void on_closeButton_clicked(); - void on_okButton_clicked(); - void on_cancelButton_clicked(); + void on_analSlider_valueChanged(int value); + void on_AdvOptButton_clicked(); + void on_analCheckBox_clicked(bool checked); + void on_archComboBox_currentIndexChanged(int index); + void on_pdbSelectButton_clicked(); + + void updatePDBLayout(); void anal_finished(); - void on_analSlider_valueChanged(int value); - - void on_AdvOptButton_clicked(); - - void on_analCheckBox_clicked(bool checked); - private: Ui::OptionsDialog *ui; AnalThread analThread; @@ -47,6 +46,12 @@ private: int defaultAnalLevel; QString analysisDescription(int level); + + void updateCPUComboBox(); + QString getSelectedArch(); + QString getSelectedCPU(); + int getSelectedBits(); + QString getSelectedOS(); }; #endif // OPTIONSDIALOG_H diff --git a/src/optionsdialog.ui b/src/optionsdialog.ui index 0f184639..2811ded3 100644 --- a/src/optionsdialog.ui +++ b/src/optionsdialog.ui @@ -26,7 +26,7 @@ Load Options - + :/img/logo-small.png:/img/logo-small.png @@ -94,7 +94,7 @@ - :/img/logo-small.png + :/img/logo-small.png Qt::AlignCenter @@ -602,22 +602,7 @@ color: rgb(0, 0, 0); - - - 10 - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -646,7 +631,7 @@ color: rgb(0, 0, 0); - + 0 @@ -659,7 +644,7 @@ color: rgb(0, 0, 0); - + Auto @@ -671,7 +656,38 @@ color: rgb(0, 0, 0); - + + + + 0 + 0 + + + + CPU: + + + + + + + + 70 + 0 + + + + true + + + + + + + + + + 0 @@ -745,26 +761,6 @@ color: rgb(0, 0, 0); Auto - - - Linux - - - - - BSD - - - - - OS X - - - - - Windows - - @@ -926,6 +922,48 @@ color: rgb(0, 0, 0); + + + + Load PDB + + + + + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + pdb file + + + + + + + Select + + + + + + diff --git a/src/widgets/consolewidget.cpp b/src/widgets/consolewidget.cpp index 61cfad4a..e081b6de 100644 --- a/src/widgets/consolewidget.cpp +++ b/src/widgets/consolewidget.cpp @@ -183,7 +183,7 @@ void ConsoleWidget::on_inputLineEdit_returnPressed() QString input = ui->inputLineEdit->text(); if (!input.isEmpty() && core != nullptr) { - if (!isForbidden(input)) + if (true || !isForbidden(input)) { ui->outputTextEdit->appendPlainText(this->core->cmd(input)); scrollOutputToEnd(); diff --git a/src/widgets/memorywidget.cpp b/src/widgets/memorywidget.cpp index f004045a..3b226972 100644 --- a/src/widgets/memorywidget.cpp +++ b/src/widgets/memorywidget.cpp @@ -469,7 +469,7 @@ void MemoryWidget::replaceTextDisasm(QString txt) bool MemoryWidget::loadMoreDisassembly() { /* -z * Add more disasm as the user scrolls + z * Add more disasm as the user scrolls * Not working properly when scrolling upwards * r2 doesn't handle properly 'pd-' for archs with variable instruction size */ @@ -2005,11 +2005,15 @@ void MemoryWidget::updateViews(RVA offset) } } -void MemoryWidget::showOffsets(bool show) { - if (show) { +void MemoryWidget::showOffsets(bool show) +{ + if (show) + { this->hexOffsetText->show(); main->core->config("asm.offset", 1); - } else { + } + else + { this->hexOffsetText->hide(); main->core->config("asm.offset", 0); }