Fetch Functions in Task

This commit is contained in:
Florian Märkl 2018-06-25 21:28:34 +02:00
parent 4001c80a11
commit 83c6fd5d22
10 changed files with 87 additions and 55 deletions

View File

@ -994,29 +994,7 @@ QList<RAsmPluginDescription> CutterCore::getRAsmPluginDescriptions()
QList<FunctionDescription> CutterCore::getAllFunctions() QList<FunctionDescription> CutterCore::getAllFunctions()
{ {
CORE_LOCK(); return parseFunctionsJson(cmdjTask("aflj"));
QList<FunctionDescription> 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;
} }
QList<ImportDescription> CutterCore::getAllImports() QList<ImportDescription> CutterCore::getAllImports()
@ -1233,6 +1211,31 @@ QList<StringDescription> CutterCore::parseStringsJson(const QJsonDocument &doc)
return ret; return ret;
} }
QList<FunctionDescription> CutterCore::parseFunctionsJson(const QJsonDocument &doc)
{
QList<FunctionDescription> 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<FlagspaceDescription> CutterCore::getAllFlagspaces() QList<FlagspaceDescription> CutterCore::getAllFlagspaces()
{ {
CORE_LOCK(); CORE_LOCK();
@ -1652,7 +1655,6 @@ void CutterCore::loadScript(const QString &scriptname)
{ {
r_core_cmd_file(core_, scriptname.toStdString().data()); r_core_cmd_file(core_, scriptname.toStdString().data());
} }
QString CutterCore::getVersionInformation() QString CutterCore::getVersionInformation()
{ {
int i; int i;
@ -1693,15 +1695,16 @@ QString CutterCore::getVersionInformation()
} }
return ret; return ret;
} }
QJsonArray CutterCore::getOpenedFiles() QJsonArray CutterCore::getOpenedFiles()
{ {
QJsonDocument files = cmdj("oj"); QJsonDocument files = cmdj("oj");
return files.array(); return files.array();
} }
QList<QString> CutterCore::getColorThemes() QList<QString> CutterCore::getColorThemes()
{ {
QList<QString> r; QList<QString> r;
@ -1722,7 +1725,6 @@ void CutterCore::joinTask(RCoreTask *task)
{ {
r_core_task_join(core_, nullptr, task); r_core_task_join(core_, nullptr, task);
} }
void CutterCore::deleteTask(RCoreTask *task) void CutterCore::deleteTask(RCoreTask *task)
{ {
r_core_task_del(core_, task->id); r_core_task_del(core_, task->id);

View File

@ -493,6 +493,7 @@ public:
const QString &filterType = QString::null); const QString &filterType = QString::null);
QList<StringDescription> parseStringsJson(const QJsonDocument &doc); QList<StringDescription> parseStringsJson(const QJsonDocument &doc);
QList<FunctionDescription> parseFunctionsJson(const QJsonDocument &doc);
/* Signals related */ /* Signals related */
void triggerVarsChanged(); void triggerVarsChanged();

View File

@ -167,7 +167,6 @@ SOURCES += \
widgets/RegistersWidget.cpp \ widgets/RegistersWidget.cpp \
widgets/BacktraceWidget.cpp \ widgets/BacktraceWidget.cpp \
dialogs/OpenFileDialog.cpp \ dialogs/OpenFileDialog.cpp \
utils/StringsTask.cpp \
utils/CommandTask.cpp \ utils/CommandTask.cpp \
utils/ProgressIndicator.cpp utils/ProgressIndicator.cpp
@ -252,6 +251,7 @@ HEADERS += \
widgets/BacktraceWidget.h \ widgets/BacktraceWidget.h \
dialogs/OpenFileDialog.h \ dialogs/OpenFileDialog.h \
utils/StringsTask.h \ utils/StringsTask.h \
utils/FunctionsTask.h \
utils/CommandTask.h \ utils/CommandTask.h \
utils/ProgressIndicator.h utils/ProgressIndicator.h

View File

@ -5,6 +5,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qRegisterMetaType<QList<StringDescription>>(); qRegisterMetaType<QList<StringDescription>>();
qRegisterMetaType<QList<FunctionDescription>>();
CutterApplication a(argc, argv); CutterApplication a(argc, argv);

View File

@ -56,7 +56,6 @@ private:
void prepareRun(); void prepareRun();
}; };
class AsyncTaskManager : public QObject class AsyncTaskManager : public QObject
{ {
Q_OBJECT Q_OBJECT

26
src/utils/FunctionsTask.h Normal file
View File

@ -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<FunctionDescription> &strings);
protected:
void runTask() override
{
auto functions = Core()->getAllFunctions();
emit fetchFinished(functions);
}
};
#endif //FUNCTIONSTASK_H

View File

@ -1,14 +0,0 @@
#include "StringsTask.h"
void StringsTask::runTask()
{
auto strings = Core()->getAllStrings();
/*RCoreTask *task = Core()->startTask("izzj");
Core()->joinTask(task);
QList<StringDescription> strings = Core()->parseStringsJson(task->msg->res);*/
emit stringSearchFinished(strings);
}

View File

@ -16,7 +16,11 @@ signals:
void stringSearchFinished(const QList<StringDescription> &strings); void stringSearchFinished(const QList<StringDescription> &strings);
protected: protected:
void runTask() override; void runTask() override
{
auto strings = Core()->getAllStrings();
emit stringSearchFinished(strings);
}
}; };
#endif //STRINGSASYNCTASK_H #endif //STRINGSASYNCTASK_H

View File

@ -6,6 +6,7 @@
#include "dialogs/CommentsDialog.h" #include "dialogs/CommentsDialog.h"
#include "dialogs/RenameDialog.h" #include "dialogs/RenameDialog.h"
#include "dialogs/XrefsDialog.h" #include "dialogs/XrefsDialog.h"
#include "utils/FunctionsTask.h"
#include <algorithm> #include <algorithm>
#include <QMenu> #include <QMenu>
@ -439,13 +440,20 @@ FunctionsWidget::~FunctionsWidget() {}
void FunctionsWidget::refreshTree() void FunctionsWidget::refreshTree()
{ {
if (task) {
task->wait();
}
task = QSharedPointer<FunctionsTask>(new FunctionsTask());
connect(task.data(), &FunctionsTask::fetchFinished, this, [this] (const QList<FunctionDescription> &functions) {
functionModel->beginReloadFunctions(); functionModel->beginReloadFunctions();
functions = Core()->getAllFunctions(); this->functions = functions;
importAddresses.clear(); importAddresses.clear();
for (ImportDescription import : Core()->getAllImports()) for (ImportDescription import : Core()->getAllImports()) {
importAddresses.insert(import.plt); importAddresses.insert(import.plt);
}
mainAdress = (ut64)Core()->cmdj("iMj").object()["vaddr"].toInt(); mainAdress = (ut64)Core()->cmdj("iMj").object()["vaddr"].toInt();
@ -453,6 +461,8 @@ void FunctionsWidget::refreshTree()
// resize offset and size columns // resize offset and size columns
qhelpers::adjustColumns(ui->functionsTreeView, 3, 0); qhelpers::adjustColumns(ui->functionsTreeView, 3, 0);
});
Core()->getAsyncTaskManager()->start(task);
} }
void FunctionsWidget::onFunctionsDoubleClicked(const QModelIndex &index) void FunctionsWidget::onFunctionsDoubleClicked(const QModelIndex &index)

View File

@ -11,6 +11,7 @@
class MainWindow; class MainWindow;
class QTreeWidgetItem; class QTreeWidgetItem;
class FunctionsTask;
namespace Ui { namespace Ui {
class FunctionsWidget; class FunctionsWidget;
@ -121,6 +122,8 @@ private:
std::unique_ptr<Ui::FunctionsWidget> ui; std::unique_ptr<Ui::FunctionsWidget> ui;
MainWindow *main; MainWindow *main;
QSharedPointer<FunctionsTask> task;
QList<FunctionDescription> functions; QList<FunctionDescription> functions;
QSet<RVA> importAddresses; QSet<RVA> importAddresses;
ut64 mainAdress; ut64 mainAdress;