diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 87d307b7..15a14084 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -994,29 +994,7 @@ QList CutterCore::getRAsmPluginDescriptions() QList CutterCore::getAllFunctions() { - CORE_LOCK(); - QList ret; - - QJsonArray jsonArray = cmdj("aflj").array(); - - for (QJsonValue value : jsonArray) { - QJsonObject jsonObject = value.toObject(); - - FunctionDescription function; - - function.offset = (RVA)jsonObject["offset"].toVariant().toULongLong(); - function.size = (RVA)jsonObject["size"].toVariant().toULongLong(); - function.nargs = (RVA)jsonObject["nargs"].toVariant().toULongLong(); - function.nbbs = (RVA)jsonObject["nbbs"].toVariant().toULongLong(); - function.nlocals = (RVA)jsonObject["nlocals"].toVariant().toULongLong(); - function.cc = (RVA)jsonObject["cc"].toVariant().toULongLong(); - function.calltype = jsonObject["calltype"].toString(); - function.name = jsonObject["name"].toString(); - - ret << function; - } - - return ret; + return parseFunctionsJson(cmdjTask("aflj")); } QList CutterCore::getAllImports() @@ -1233,6 +1211,31 @@ QList CutterCore::parseStringsJson(const QJsonDocument &doc) return ret; } +QList CutterCore::parseFunctionsJson(const QJsonDocument &doc) +{ + QList ret; + QJsonArray jsonArray = doc.array(); + + for (QJsonValue value : jsonArray) { + QJsonObject jsonObject = value.toObject(); + + FunctionDescription function; + + function.offset = (RVA)jsonObject["offset"].toVariant().toULongLong(); + function.size = (RVA)jsonObject["size"].toVariant().toULongLong(); + function.nargs = (RVA)jsonObject["nargs"].toVariant().toULongLong(); + function.nbbs = (RVA)jsonObject["nbbs"].toVariant().toULongLong(); + function.nlocals = (RVA)jsonObject["nlocals"].toVariant().toULongLong(); + function.cc = (RVA)jsonObject["cc"].toVariant().toULongLong(); + function.calltype = jsonObject["calltype"].toString(); + function.name = jsonObject["name"].toString(); + + ret << function; + } + + return ret; +} + QList CutterCore::getAllFlagspaces() { CORE_LOCK(); @@ -1652,7 +1655,6 @@ void CutterCore::loadScript(const QString &scriptname) { r_core_cmd_file(core_, scriptname.toStdString().data()); } - QString CutterCore::getVersionInformation() { int i; @@ -1693,15 +1695,16 @@ QString CutterCore::getVersionInformation() } return ret; } + + + + QJsonArray CutterCore::getOpenedFiles() { QJsonDocument files = cmdj("oj"); return files.array(); } - - - QList CutterCore::getColorThemes() { QList r; @@ -1722,7 +1725,6 @@ void CutterCore::joinTask(RCoreTask *task) { r_core_task_join(core_, nullptr, task); } - void CutterCore::deleteTask(RCoreTask *task) { r_core_task_del(core_, task->id); diff --git a/src/Cutter.h b/src/Cutter.h index fdf9d4b3..58a96ef9 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -493,6 +493,7 @@ public: const QString &filterType = QString::null); QList parseStringsJson(const QJsonDocument &doc); + QList parseFunctionsJson(const QJsonDocument &doc); /* Signals related */ void triggerVarsChanged(); diff --git a/src/Cutter.pro b/src/Cutter.pro index dba1439d..ec3072ad 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -167,7 +167,6 @@ SOURCES += \ widgets/RegistersWidget.cpp \ widgets/BacktraceWidget.cpp \ dialogs/OpenFileDialog.cpp \ - utils/StringsTask.cpp \ utils/CommandTask.cpp \ utils/ProgressIndicator.cpp @@ -252,6 +251,7 @@ HEADERS += \ widgets/BacktraceWidget.h \ dialogs/OpenFileDialog.h \ utils/StringsTask.h \ + utils/FunctionsTask.h \ utils/CommandTask.h \ utils/ProgressIndicator.h diff --git a/src/Main.cpp b/src/Main.cpp index a686a506..a1672e3a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -5,6 +5,7 @@ int main(int argc, char *argv[]) { qRegisterMetaType>(); + qRegisterMetaType>(); CutterApplication a(argc, argv); diff --git a/src/utils/AsyncTask.h b/src/utils/AsyncTask.h index 627a3ddd..d405f91c 100644 --- a/src/utils/AsyncTask.h +++ b/src/utils/AsyncTask.h @@ -56,7 +56,6 @@ private: void prepareRun(); }; - class AsyncTaskManager : public QObject { Q_OBJECT diff --git a/src/utils/FunctionsTask.h b/src/utils/FunctionsTask.h new file mode 100644 index 00000000..d6f8f82a --- /dev/null +++ b/src/utils/FunctionsTask.h @@ -0,0 +1,26 @@ + +#ifndef FUNCTIONSTASK_H +#define FUNCTIONSTASK_H + +#include "utils/AsyncTask.h" +#include "Cutter.h" + +class FunctionsTask : public AsyncTask +{ +Q_OBJECT + +public: + QString getTitle() override { return tr("Fetching Functions"); } + +signals: + void fetchFinished(const QList &strings); + +protected: + void runTask() override + { + auto functions = Core()->getAllFunctions(); + emit fetchFinished(functions); + } +}; + +#endif //FUNCTIONSTASK_H diff --git a/src/utils/StringsTask.cpp b/src/utils/StringsTask.cpp deleted file mode 100644 index 5d667f24..00000000 --- a/src/utils/StringsTask.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -#include "StringsTask.h" - -void StringsTask::runTask() -{ - auto strings = Core()->getAllStrings(); - - /*RCoreTask *task = Core()->startTask("izzj"); - Core()->joinTask(task); - - QList strings = Core()->parseStringsJson(task->msg->res);*/ - - emit stringSearchFinished(strings); -} diff --git a/src/utils/StringsTask.h b/src/utils/StringsTask.h index 169c81a3..b01e5c2b 100644 --- a/src/utils/StringsTask.h +++ b/src/utils/StringsTask.h @@ -7,7 +7,7 @@ class StringsTask : public AsyncTask { - Q_OBJECT +Q_OBJECT public: QString getTitle() override { return tr("Searching for Strings"); } @@ -16,7 +16,11 @@ signals: void stringSearchFinished(const QList &strings); protected: - void runTask() override; + void runTask() override + { + auto strings = Core()->getAllStrings(); + emit stringSearchFinished(strings); + } }; #endif //STRINGSASYNCTASK_H diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 8c3126f5..e826fdc7 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -6,6 +6,7 @@ #include "dialogs/CommentsDialog.h" #include "dialogs/RenameDialog.h" #include "dialogs/XrefsDialog.h" +#include "utils/FunctionsTask.h" #include #include @@ -439,20 +440,29 @@ FunctionsWidget::~FunctionsWidget() {} void FunctionsWidget::refreshTree() { - functionModel->beginReloadFunctions(); + if (task) { + task->wait(); + } - functions = Core()->getAllFunctions(); + task = QSharedPointer(new FunctionsTask()); + connect(task.data(), &FunctionsTask::fetchFinished, this, [this] (const QList &functions) { + functionModel->beginReloadFunctions(); - importAddresses.clear(); - for (ImportDescription import : Core()->getAllImports()) - importAddresses.insert(import.plt); + this->functions = functions; - mainAdress = (ut64)Core()->cmdj("iMj").object()["vaddr"].toInt(); + importAddresses.clear(); + for (ImportDescription import : Core()->getAllImports()) { + importAddresses.insert(import.plt); + } - functionModel->endReloadFunctions(); + mainAdress = (ut64)Core()->cmdj("iMj").object()["vaddr"].toInt(); - // resize offset and size columns - qhelpers::adjustColumns(ui->functionsTreeView, 3, 0); + functionModel->endReloadFunctions(); + + // resize offset and size columns + qhelpers::adjustColumns(ui->functionsTreeView, 3, 0); + }); + Core()->getAsyncTaskManager()->start(task); } void FunctionsWidget::onFunctionsDoubleClicked(const QModelIndex &index) diff --git a/src/widgets/FunctionsWidget.h b/src/widgets/FunctionsWidget.h index 8c10b81c..fe155bcd 100644 --- a/src/widgets/FunctionsWidget.h +++ b/src/widgets/FunctionsWidget.h @@ -11,6 +11,7 @@ class MainWindow; class QTreeWidgetItem; +class FunctionsTask; namespace Ui { class FunctionsWidget; @@ -121,6 +122,8 @@ private: std::unique_ptr ui; MainWindow *main; + QSharedPointer task; + QList functions; QSet importAddresses; ut64 mainAdress;