From 97ee9f17b63e2d5626c117cbc8e61702ad8fd859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 29 Sep 2017 13:32:53 +0200 Subject: [PATCH] Implement forcing format in OptionsDialog --- src/analthread.cpp | 14 +++++++++++--- src/cutter.cpp | 35 +++++++++++++++++++++++++++++++++- src/cutter.h | 13 ++++++++++++- src/newfiledialog.cpp | 13 ++++++++----- src/optionsdialog.cpp | 14 ++++---------- src/optionsdialog.ui | 36 +---------------------------------- src/widgets/consolewidget.cpp | 2 +- 7 files changed, 71 insertions(+), 56 deletions(-) diff --git a/src/analthread.cpp b/src/analthread.cpp index 1dd5286a..50e8abda 100644 --- a/src/analthread.cpp +++ b/src/analthread.cpp @@ -8,8 +8,8 @@ AnalThread::AnalThread(OptionsDialog *parent) : QThread(parent), - main(nullptr), - level(2) + level(2), + main(nullptr) { } @@ -69,7 +69,15 @@ void AnalThread::run() // options dialog should show the list of archs inside the given fatbin int binidx = 0; // index of subbin - main->core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo); + QString forceBinPlugin = nullptr; + QVariant forceBinPluginData = ui->formatComboBox->currentData(); + if (!forceBinPluginData.isNull()) + { + RBinPluginDescription pluginDesc = forceBinPluginData.value(); + forceBinPlugin = pluginDesc.name; + } + + main->core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo, forceBinPlugin); emit updateProgress("Analysis in progress."); QString os = optionsDialog->getSelectedOS(); diff --git a/src/cutter.cpp b/src/cutter.cpp index 6c3c5ef1..cdd184bd 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -208,7 +208,7 @@ QJsonDocument CutterCore::cmdj(const QString &str) return doc; } -bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, bool rw, int va, int idx, bool loadbin) +bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, bool rw, int va, int idx, bool loadbin, const QString &forceBinPlugin) { CUTTERNOTUSED(loadaddr); CUTTERNOTUSED(idx); @@ -228,6 +228,11 @@ bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, boo return false; } + if (!forceBinPlugin.isNull()) + { + r_bin_force_plugin(r_core_get_bin(core_), forceBinPlugin.toUtf8().constData()); + } + if (loadbin) { if (va == 1) @@ -813,6 +818,34 @@ QStringList CutterCore::getProjectNames() } +QList CutterCore::getRBinPluginDescriptions(const QString &type) +{ + QList ret; + + QJsonObject jsonRoot = cmdj("iLj").object(); + for (const QString &key : jsonRoot.keys()) + { + if (!type.isNull() && key != type) + continue; + + QJsonArray pluginArray = jsonRoot[key].toArray(); + + for (const auto &pluginValue : pluginArray) + { + QJsonObject pluginObject = pluginValue.toObject(); + RBinPluginDescription desc; + desc.name = pluginObject["name"].toString(); + desc.description = pluginObject["description"].toString(); + desc.license = pluginObject["license"].toString(); + desc.type = key; + ret.append(desc); + } + } + + return ret; +} + + QList CutterCore::getAllFunctions() { CORE_LOCK(); diff --git a/src/cutter.h b/src/cutter.h index 012461e4..eaabc606 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -155,6 +155,14 @@ struct XrefDescription QString type; }; +struct RBinPluginDescription +{ + QString name; + QString description; + QString license; + QString type; +}; + Q_DECLARE_METATYPE(FunctionDescription) Q_DECLARE_METATYPE(ImportDescription) Q_DECLARE_METATYPE(ExportDescription) @@ -166,6 +174,7 @@ Q_DECLARE_METATYPE(FlagspaceDescription) Q_DECLARE_METATYPE(FlagDescription) Q_DECLARE_METATYPE(XrefDescription) Q_DECLARE_METATYPE(EntrypointDescription) +Q_DECLARE_METATYPE(RBinPluginDescription) class CutterCore: public QObject { @@ -192,7 +201,7 @@ public: void delComment(ut64 addr); QMap>> getNestedComments(); void setOptions(QString key); - bool loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int idx = 0, bool loadbin = false); + bool loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int idx = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr); bool tryFile(QString path, bool rw); void analyze(int level, QList advanced); void seek(QString addr); @@ -241,6 +250,8 @@ public: QStringList getProjectNames(); + QList getRBinPluginDescriptions(const QString &type = nullptr); + QList getAllFunctions(); QList getAllImports(); QList getAllExports(); diff --git a/src/newfiledialog.cpp b/src/newfiledialog.cpp index d867000d..696d052a 100644 --- a/src/newfiledialog.cpp +++ b/src/newfiledialog.cpp @@ -77,7 +77,7 @@ NewFileDialog::NewFileDialog(QWidget *parent) : int i = 0; while (it.hasNext()) { - const QString& file = it.next(); + const QString &file = it.next(); // Get stored files // Remove all but the file name @@ -87,12 +87,15 @@ NewFileDialog::NewFileDialog(QWidget *parent) : // Get file info QFileInfo info(file); - if (!info.exists()) { + if (!info.exists()) + { it.remove(); - } else { + } + else + { QListWidgetItem *item = new QListWidgetItem( - getIconFor(name, i++), - file + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size()) + getIconFor(name, i++), + file + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size()) ); //":/img/icons/target.svg"), name ); item->setData(Qt::UserRole, file); diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index e349bccd..40ae82bd 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -45,6 +45,10 @@ OptionsDialog::OptionsDialog(MainWindow *main): ui->bitsComboBox->setToolTip(main->core->cmd("e? asm.bits").trimmed()); + + for (auto plugin : main->core->getRBinPluginDescriptions("bin")) + ui->formatComboBox->addItem(plugin.name, QVariant::fromValue(plugin)); + // Restore settings QSettings settings; ui->bytesCheckBox->setChecked(settings.value("bytes").toBool()); @@ -228,16 +232,6 @@ void OptionsDialog::anal_finished() ui->statusLabel->setText(tr("Loading interface")); main->addOutput(tr(" > Analysis finished")); - QString initial_seek = ui->entry_initialSeek->text(); - if (initial_seek.length() > 0) - { - main->core->seek(initial_seek); - } - else - { - main->core->seek("entry0"); - } - main->finalizeOpen(); close(); } diff --git a/src/optionsdialog.ui b/src/optionsdialog.ui index 272da2c9..d94b008b 100644 --- a/src/optionsdialog.ui +++ b/src/optionsdialog.ui @@ -889,47 +889,13 @@ color: rgb(0, 0, 0); - - - - 0 - 0 - - - - Initial seek: - - - - - - - - 12 - - - - - - - - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - Load PDB - + true diff --git a/src/widgets/consolewidget.cpp b/src/widgets/consolewidget.cpp index e081b6de..61cfad4a 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 (true || !isForbidden(input)) + if (!isForbidden(input)) { ui->outputTextEdit->appendPlainText(this->core->cmd(input)); scrollOutputToEnd();