Update Rizin with RizinTask (#2517)

This commit is contained in:
Florian Märkl 2020-12-16 10:51:53 +01:00 committed by GitHub
parent cd10751327
commit 58745547a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 144 additions and 136 deletions

2
rizin

@ -1 +1 @@
Subproject commit 2ae7f4df15228a83d65f1a509675ee48b6237694
Subproject commit 8af2c6aa9bba10a310a77ecef82d44ee80aeb470

View File

@ -383,8 +383,8 @@ SOURCES += \
dialogs/MapFileDialog.cpp \
common/CommandTask.cpp \
common/ProgressIndicator.cpp \
common/R2Task.cpp \
dialogs/R2TaskDialog.cpp \
common/RizinTask.cpp \
dialogs/RizinTaskDialog.cpp \
widgets/DebugActions.cpp \
widgets/MemoryMapWidget.cpp \
dialogs/preferences/DebugOptionsWidget.cpp \
@ -536,8 +536,8 @@ HEADERS += \
common/CommandTask.h \
common/ProgressIndicator.h \
plugins/CutterPlugin.h \
common/R2Task.h \
dialogs/R2TaskDialog.h \
common/RizinTask.h \
dialogs/RizinTaskDialog.h \
widgets/DebugActions.h \
widgets/MemoryMapWidget.h \
dialogs/preferences/DebugOptionsWidget.h \
@ -643,7 +643,7 @@ FORMS += \
dialogs/VersionInfoDialog.ui \
widgets/ZignaturesWidget.ui \
dialogs/AsyncTaskDialog.ui \
dialogs/R2TaskDialog.ui \
dialogs/RizinTaskDialog.ui \
widgets/StackWidget.ui \
widgets/RegistersWidget.ui \
widgets/ThreadsWidget.ui \

View File

@ -33,8 +33,8 @@ void R2DecDecompiler::decompileAt(RVA addr)
if (task) {
return;
}
task = new R2Task("pddj @ " + QString::number(addr));
connect(task, &R2Task::finished, this, [this]() {
task = new RizinTask("pddj @ " + QString::number(addr));
connect(task, &RizinTask::finished, this, [this]() {
QJsonObject json = task->getResultJson().object();
delete task;
task = nullptr;

View File

@ -2,7 +2,7 @@
#define DECOMPILER_H
#include "CutterCommon.h"
#include "R2Task.h"
#include "RizinTask.h"
#include <rz_util/rz_annotated_code.h>
#include <QString>
@ -42,7 +42,7 @@ class R2DecDecompiler: public Decompiler
Q_OBJECT
private:
R2Task *task;
RizinTask *task;
public:
explicit R2DecDecompiler(QObject *parent = nullptr);

View File

@ -1,58 +0,0 @@
#include "R2Task.h"
R2Task::R2Task(const QString &cmd, bool transient)
{
task = rz_core_task_new(Core()->core(),
true,
cmd.toLocal8Bit().constData(),
static_cast<RzCoreTaskCallback>(&R2Task::taskFinishedCallback),
this);
task->transient = transient;
rz_core_task_incref(task);
}
R2Task::~R2Task()
{
rz_core_task_decref(task);
}
void R2Task::taskFinishedCallback(void *user, char *)
{
reinterpret_cast<R2Task *>(user)->taskFinished();
}
void R2Task::taskFinished()
{
emit finished();
}
void R2Task::startTask()
{
rz_core_task_enqueue(&Core()->core_->tasks, task);
}
void R2Task::breakTask()
{
rz_core_task_break(&Core()->core_->tasks, task->id);
}
void R2Task::joinTask()
{
rz_core_task_join(&Core()->core_->tasks, nullptr, task->id);
}
QString R2Task::getResult()
{
return QString::fromUtf8(task->res);
}
QJsonDocument R2Task::getResultJson()
{
return Core()->parseJson(task->res, task->cmd);
}
const char *R2Task::getResultRaw()
{
return task->res;
}

66
src/common/RizinTask.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "RizinTask.h"
#include <rz_core.h>
RizinTask::RizinTask(const QString &cmd, bool transient)
{
task = rz_core_cmd_task_new(Core()->core(),
cmd.toLocal8Bit().constData(),
static_cast<RzCoreCmdTaskFinished>(&RizinTask::taskFinishedCallback),
this);
task->transient = transient;
rz_core_task_incref(task);
}
RizinTask::~RizinTask()
{
rz_core_task_decref(task);
}
void RizinTask::taskFinishedCallback(const char *, void *user)
{
reinterpret_cast<RizinTask *>(user)->taskFinished();
}
void RizinTask::taskFinished()
{
emit finished();
}
void RizinTask::startTask()
{
rz_core_task_enqueue(&Core()->core_->tasks, task);
}
void RizinTask::breakTask()
{
rz_core_task_break(&Core()->core_->tasks, task->id);
}
void RizinTask::joinTask()
{
rz_core_task_join(&Core()->core_->tasks, nullptr, task->id);
}
QString RizinTask::getResult()
{
const char *res = rz_core_cmd_task_get_result(task);
if(!res) {
return nullptr;
}
return QString::fromUtf8(res);
}
QJsonDocument RizinTask::getResultJson()
{
const char *res = rz_core_cmd_task_get_result(task);
if(!res) {
return QJsonDocument();
}
return Core()->parseJson(res, nullptr);
}
const char *RizinTask::getResultRaw()
{
return rz_core_cmd_task_get_result(task);
}

View File

@ -4,21 +4,21 @@
#include "core/Cutter.h"
class R2Task: public QObject
class RizinTask: public QObject
{
Q_OBJECT
private:
RzCoreTask *task;
static void taskFinishedCallback(void *user, char *);
static void taskFinishedCallback(const char *, void *user);
void taskFinished();
public:
using Ptr = QSharedPointer<R2Task>;
using Ptr = QSharedPointer<RizinTask>;
explicit R2Task(const QString &cmd, bool transient = true);
~R2Task();
explicit RizinTask(const QString &cmd, bool transient = true);
~RizinTask();
void startTask();
void breakTask();

View File

@ -14,7 +14,7 @@
#include "common/BasicInstructionHighlighter.h"
#include "common/Configuration.h"
#include "common/AsyncTask.h"
#include "common/R2Task.h"
#include "common/RizinTask.h"
#include "common/Json.h"
#include "core/Cutter.h"
#include "Decompiler.h"
@ -394,7 +394,7 @@ bool CutterCore::isDebugTaskInProgress()
return false;
}
bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task)
bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<RizinTask> &task)
{
asyncCmd(command, task);
@ -402,7 +402,7 @@ bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task)
return false;
}
connect(task.data(), &R2Task::finished, task.data(), [this, task] () {
connect(task.data(), &RizinTask::finished, task.data(), [this, task] () {
QString res = task.data()->getResult();
if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) {
@ -413,7 +413,7 @@ bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task)
return true;
}
bool CutterCore::asyncCmd(const char *str, QSharedPointer<R2Task> &task)
bool CutterCore::asyncCmd(const char *str, QSharedPointer<RizinTask> &task)
{
if (!task.isNull()) {
return false;
@ -423,8 +423,8 @@ bool CutterCore::asyncCmd(const char *str, QSharedPointer<R2Task> &task)
RVA offset = core->offset;
task = QSharedPointer<R2Task>(new R2Task(str, true));
connect(task.data(), &R2Task::finished, task.data(), [this, offset, task] () {
task = QSharedPointer<RizinTask>(new RizinTask(str, true));
connect(task.data(), &RizinTask::finished, task.data(), [this, offset, task] () {
CORE_LOCK();
if (offset != core->offset) {
@ -494,7 +494,7 @@ QJsonDocument CutterCore::cmdjAt(const char *str, RVA address)
QString CutterCore::cmdTask(const QString &str)
{
R2Task task(str);
RizinTask task(str);
task.startTask();
task.joinTask();
return task.getResult();
@ -502,7 +502,7 @@ QString CutterCore::cmdTask(const QString &str)
QJsonDocument CutterCore::cmdjTask(const QString &str)
{
R2Task task(str);
RizinTask task(str);
task.startTask();
task.joinTask();
return parseJson(task.getResultRaw(), str);
@ -1602,7 +1602,7 @@ void CutterCore::setCurrentDebugThread(int tid)
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
emit registersChanged();
emit refreshCodeViews();
@ -1622,7 +1622,7 @@ void CutterCore::setCurrentDebugProcess(int pid)
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
emit registersChanged();
emit refreshCodeViews();
@ -1649,7 +1649,7 @@ void CutterCore::startDebug()
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
if (debugTaskDialog) {
delete debugTaskDialog;
}
@ -1668,7 +1668,7 @@ void CutterCore::startDebug()
emit debugTaskStateChanged();
});
debugTaskDialog = new R2TaskDialog(debugTask);
debugTaskDialog = new RizinTaskDialog(debugTask);
debugTaskDialog->setBreakOnClose(true);
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
debugTaskDialog->setDesc(tr("Starting native debug..."));
@ -1688,7 +1688,7 @@ void CutterCore::startEmulation()
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
if (debugTaskDialog) {
delete debugTaskDialog;
}
@ -1711,7 +1711,7 @@ void CutterCore::startEmulation()
emit debugTaskStateChanged();
});
debugTaskDialog = new R2TaskDialog(debugTask);
debugTaskDialog = new RizinTaskDialog(debugTask);
debugTaskDialog->setBreakOnClose(true);
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
debugTaskDialog->setDesc(tr("Starting emulation..."));
@ -1730,7 +1730,7 @@ void CutterCore::attachRemote(const QString &uri)
asyncCmd("e cfg.debug = true; oodf " + uri, debugTask);
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this, uri] () {
connect(debugTask.data(), &RizinTask::finished, this, [this, uri] () {
if (debugTaskDialog) {
delete debugTaskDialog;
}
@ -1767,7 +1767,7 @@ void CutterCore::attachRemote(const QString &uri)
emit debugTaskStateChanged();
});
debugTaskDialog = new R2TaskDialog(debugTask);
debugTaskDialog = new RizinTaskDialog(debugTask);
debugTaskDialog->setBreakOnClose(true);
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
debugTaskDialog->setDesc(tr("Connecting to: ") + uri);
@ -1786,7 +1786,7 @@ void CutterCore::attachDebug(int pid)
asyncCmd("e cfg.debug = true; oodf dbg://" + QString::number(pid), debugTask);
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this, pid] () {
connect(debugTask.data(), &RizinTask::finished, this, [this, pid] () {
if (debugTaskDialog) {
delete debugTaskDialog;
}
@ -1806,7 +1806,7 @@ void CutterCore::attachDebug(int pid)
emit debugTaskStateChanged();
});
debugTaskDialog = new R2TaskDialog(debugTask);
debugTaskDialog = new RizinTaskDialog(debugTask);
debugTaskDialog->setBreakOnClose(true);
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
debugTaskDialog->setDesc(tr("Attaching to process (") + QString::number(pid) + ")...");
@ -1890,7 +1890,7 @@ void CutterCore::continueDebug()
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit registersChanged();
@ -1918,7 +1918,7 @@ void CutterCore::continueUntilDebug(QString offset)
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit registersChanged();
@ -1947,7 +1947,7 @@ void CutterCore::continueUntilCall()
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit debugTaskStateChanged();
@ -1973,7 +1973,7 @@ void CutterCore::continueUntilSyscall()
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit debugTaskStateChanged();
@ -1999,7 +1999,7 @@ void CutterCore::stepDebug()
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit debugTaskStateChanged();
@ -2025,7 +2025,7 @@ void CutterCore::stepOverDebug()
}
emit debugTaskStateChanged();
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit debugTaskStateChanged();
@ -2045,7 +2045,7 @@ void CutterCore::stepOutDebug()
return;
}
connect(debugTask.data(), &R2Task::finished, this, [this] () {
connect(debugTask.data(), &RizinTask::finished, this, [this] () {
debugTask.clear();
syncAndSeekProgramCounter();
emit debugTaskStateChanged();

View File

@ -20,13 +20,13 @@ class AsyncTaskManager;
class BasicInstructionHighlighter;
class CutterCore;
class Decompiler;
class R2Task;
class R2TaskDialog;
class RizinTask;
class RizinTaskDialog;
#include "common/BasicBlockHighlighter.h"
#include "common/R2Task.h"
#include "common/RizinTask.h"
#include "common/Helpers.h"
#include "dialogs/R2TaskDialog.h"
#include "dialogs/RizinTaskDialog.h"
#include <rz_project.h>
@ -39,7 +39,7 @@ class CUTTER_EXPORT CutterCore: public QObject
Q_OBJECT
friend class RzCoreLocked;
friend class R2Task;
friend class RizinTask;
public:
explicit CutterCore(QObject *parent = nullptr);
@ -69,14 +69,14 @@ public:
* @brief send a command to Rizin asynchronously
* @param str the command you want to execute
* @param task a shared pointer that will be returned with the R2 command task
* @note connect to the &R2Task::finished signal to add your own logic once
* @note connect to the &RizinTask::finished signal to add your own logic once
* the command is finished. Use task->getResult()/getResultJson() for the
* return value.
* Once you have setup connections you can start the task with task->startTask()
* If you want to seek to an address, you should use CutterCore::seek.
*/
bool asyncCmd(const char *str, QSharedPointer<R2Task> &task);
bool asyncCmd(const QString &str, QSharedPointer<R2Task> &task) { return asyncCmd(str.toUtf8().constData(), task); }
bool asyncCmd(const char *str, QSharedPointer<RizinTask> &task);
bool asyncCmd(const QString &str, QSharedPointer<RizinTask> &task) { return asyncCmd(str.toUtf8().constData(), task); }
/**
* @brief Execute a Rizin command \a cmd. By nature, the API
@ -126,14 +126,14 @@ public:
* @brief send a command to Rizin and check for ESIL errors
* @param command the command you want to execute
* @param task a shared pointer that will be returned with the R2 command task
* @note connect to the &R2Task::finished signal to add your own logic once
* @note connect to the &RizinTask::finished signal to add your own logic once
* the command is finished. Use task->getResult()/getResultJson() for the
* return value.
* Once you have setup connections you can start the task with task->startTask()
* If you want to seek to an address, you should use CutterCore::seek.
*/
bool asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task);
bool asyncCmdEsil(const QString &command, QSharedPointer<R2Task> &task) { return asyncCmdEsil(command.toUtf8().constData(), task); }
bool asyncCmdEsil(const char *command, QSharedPointer<RizinTask> &task);
bool asyncCmdEsil(const QString &command, QSharedPointer<RizinTask> &task) { return asyncCmdEsil(command.toUtf8().constData(), task); }
QString getVersionInformation();
QJsonDocument parseJson(const char *res, const char *cmd = nullptr);
@ -725,8 +725,8 @@ private:
bool iocache = false;
BasicInstructionHighlighter biHighlighter;
QSharedPointer<R2Task> debugTask;
R2TaskDialog *debugTaskDialog;
QSharedPointer<RizinTask> debugTask;
RizinTaskDialog *debugTaskDialog;
QVector<QString> getCutterRCFilePaths() const;
};

View File

@ -1,22 +1,22 @@
#include "R2TaskDialog.h"
#include "common/R2Task.h"
#include "RizinTaskDialog.h"
#include "common/RizinTask.h"
#include <QCloseEvent>
#include "ui_R2TaskDialog.h"
#include "ui_RizinTaskDialog.h"
R2TaskDialog::R2TaskDialog(R2Task::Ptr task, QWidget *parent)
RizinTaskDialog::RizinTaskDialog(RizinTask::Ptr task, QWidget *parent)
: QDialog(parent),
ui(new Ui::R2TaskDialog),
ui(new Ui::RizinTaskDialog),
task(task)
{
ui->setupUi(this);
connect(task.data(), &R2Task::finished, this, [this]() {
connect(task.data(), &RizinTask::finished, this, [this]() {
close();
});
connect(&timer, &QTimer::timeout, this, &R2TaskDialog::updateProgressTimer);
connect(&timer, &QTimer::timeout, this, &RizinTaskDialog::updateProgressTimer);
timer.setInterval(1000);
timer.setSingleShot(false);
timer.start();
@ -25,11 +25,11 @@ R2TaskDialog::R2TaskDialog(R2Task::Ptr task, QWidget *parent)
updateProgressTimer();
}
R2TaskDialog::~R2TaskDialog()
RizinTaskDialog::~RizinTaskDialog()
{
}
void R2TaskDialog::updateProgressTimer()
void RizinTaskDialog::updateProgressTimer()
{
int secondsElapsed = elapsedTimer.elapsed() / 1000;
int minutesElapsed = secondsElapsed / 60;
@ -48,12 +48,12 @@ void R2TaskDialog::updateProgressTimer()
ui->timeLabel->setText(label);
}
void R2TaskDialog::setDesc(const QString &label)
void RizinTaskDialog::setDesc(const QString &label)
{
ui->descLabel->setText(label);
}
void R2TaskDialog::closeEvent(QCloseEvent *event)
void RizinTaskDialog::closeEvent(QCloseEvent *event)
{
if (breakOnClose) {
task->breakTask();
@ -64,7 +64,7 @@ void R2TaskDialog::closeEvent(QCloseEvent *event)
}
}
void R2TaskDialog::reject()
void RizinTaskDialog::reject()
{
task->breakTask();
setDesc("Attempting to stop the task...");

View File

@ -7,22 +7,22 @@
#include <QTimer>
#include <QElapsedTimer>
#include "common/R2Task.h"
#include "common/RizinTask.h"
#include "core/CutterCommon.h"
class R2Task;
class RizinTask;
namespace Ui {
class R2TaskDialog;
class RizinTaskDialog;
}
class CUTTER_EXPORT R2TaskDialog : public QDialog
class CUTTER_EXPORT RizinTaskDialog : public QDialog
{
Q_OBJECT
public:
using Ptr = QSharedPointer<R2Task>;
R2TaskDialog(Ptr task, QWidget *parent = nullptr);
~R2TaskDialog();
using Ptr = QSharedPointer<RizinTask>;
RizinTaskDialog(Ptr task, QWidget *parent = nullptr);
~RizinTaskDialog();
void setBreakOnClose(bool v) { breakOnClose = v; }
bool getBreakOnClose() { return breakOnClose; }
@ -38,8 +38,8 @@ protected:
void closeEvent(QCloseEvent *event) override;
private:
std::unique_ptr<Ui::R2TaskDialog> ui;
QSharedPointer<R2Task> task;
std::unique_ptr<Ui::RizinTaskDialog> ui;
QSharedPointer<RizinTask> task;
QTimer timer;
QElapsedTimer elapsedTimer;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>R2TaskDialog</class>
<widget class="QDialog" name="R2TaskDialog">
<class>RizinTaskDialog</class>
<widget class="QDialog" name="RizinTaskDialog">
<property name="geometry">
<rect>
<x>0</x>
@ -58,7 +58,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>R2TaskDialog</receiver>
<receiver>RizinTaskDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -74,7 +74,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>R2TaskDialog</receiver>
<receiver>RizinTaskDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">