diff --git a/rizin b/rizin index a9c59ce1..32ef1713 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit a9c59ce1ddc44c498b6a9a02e36989a34f184286 +Subproject commit 32ef171354e2fde6194a354a1a350df357c08afc diff --git a/src/common/RunScriptTask.cpp b/src/common/RunScriptTask.cpp index 7bac2d99..ca830b1a 100644 --- a/src/common/RunScriptTask.cpp +++ b/src/common/RunScriptTask.cpp @@ -16,7 +16,10 @@ void RunScriptTask::runTask() { if (!this->fileName.isNull()) { log(tr("Executing script...")); - Core()->cmdTask(". " + this->fileName); + Core()->functionTask([&](RzCore *core) { + rz_core_run_script(core, this->fileName.toUtf8().constData()); + return nullptr; + }); if (isInterrupted()) { return; } diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index ac8634b1..513806ff 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -430,48 +430,6 @@ bool CutterCore::isDebugTaskInProgress() return false; } -bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer &task) -{ - asyncCmd(command, task); - - if (task.isNull()) { - return false; - } - - connect(task.data(), &RizinCmdTask::finished, task.data(), [this, task]() { - QString res = qobject_cast(task.data())->getResult(); - - if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) { - msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can " - "disable this in Preferences"); - } - }); - - return true; -} - -bool CutterCore::asyncCmd(const char *str, QSharedPointer &task) -{ - if (!task.isNull()) { - return false; - } - - CORE_LOCK(); - - RVA offset = core->offset; - - task = QSharedPointer(new RizinCmdTask(str, true)); - connect(task.data(), &RizinTask::finished, task.data(), [this, offset, task]() { - CORE_LOCK(); - - if (offset != core->offset) { - updateSeek(); - } - }); - - return true; -} - bool CutterCore::asyncTask(std::function fcn, QSharedPointer &task) { if (!task.isNull()) { @@ -492,6 +450,13 @@ bool CutterCore::asyncTask(std::function fcn, QSharedPointer fcn) +{ + auto task = std::unique_ptr(new RizinFunctionTask(std::move(fcn), true)); + task->startTask(); + task->joinTask(); +} + QString CutterCore::cmdRawAt(const char *cmd, RVA address) { QString res; @@ -534,18 +499,6 @@ CutterJson CutterCore::cmdj(const char *str) return parseJson(res, str); } -CutterJson CutterCore::cmdjAt(const char *str, RVA address) -{ - CutterJson res; - RVA oldOffset = getOffset(); - seekSilent(address); - - res = cmdj(str); - - seekSilent(oldOffset); - return res; -} - QString CutterCore::cmdTask(const QString &str) { RizinCmdTask task(str); @@ -554,14 +507,6 @@ QString CutterCore::cmdTask(const QString &str) return task.getResult(); } -CutterJson CutterCore::cmdjTask(const QString &str) -{ - RizinCmdTask task(str); - task.startTask(); - task.joinTask(); - return task.getResultJson(); -} - CutterJson CutterCore::parseJson(char *res, const char *cmd) { if (!res) { @@ -1393,16 +1338,6 @@ QString CutterCore::flagAt(RVA addr) return core->flags->realnames && f->realname ? f->realname : f->name; } -void CutterCore::cmdEsil(const char *command) -{ - // use cmd and not cmdRaw because of unexpected commands - QString res = cmd(command); - if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) { - msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can disable " - "this in Preferences"); - } -} - void CutterCore::createFunctionAt(RVA addr) { createFunctionAt(addr, ""); @@ -4027,22 +3962,35 @@ QList CutterCore::getAllSearch(QString searchFor, QString spa QList CutterCore::getXRefsForVariable(QString variableName, bool findWrites, RVA offset) { + CORE_LOCK(); + auto fcn = functionIn(offset); + if (!fcn) { + return {}; + } + const auto typ = + findWrites ? RZ_ANALYSIS_VAR_ACCESS_TYPE_WRITE : RZ_ANALYSIS_VAR_ACCESS_TYPE_READ; QList xrefList = QList(); - for (CutterJson xrefObject : cmdjAt(findWrites ? "afvWj" : "afvRj", offset)) { - QString name = xrefObject[RJsonKey::name].toString(); - if (name == variableName) { - for (CutterJson address : xrefObject[RJsonKey::addrs]) { - XrefDescription xref; - RVA addr = address.toRVA(); - xref.from = addr; - xref.to = addr; - if (findWrites) { - xref.from_str = RzAddressString(addr); - } else { - xref.to_str = RzAddressString(addr); - } - xrefList << xref; + RzList *vars = rz_analysis_var_all_list(core->analysis, fcn); + for (const auto &v : CutterRzList(vars)) { + if (variableName != v->name) { + continue; + } + RzAnalysisVarAccess *acc; + CutterRzVectorForeach(&v->accesses, acc, RzAnalysisVarAccess) + { + if (!(acc->type & typ)) { + continue; } + XrefDescription xref; + RVA addr = fcn->addr + acc->offset; + xref.from = addr; + xref.to = addr; + if (findWrites) { + xref.from_str = RzAddressString(addr); + } else { + xref.to_str = RzAddressString(addr); + } + xrefList << xref; } } return xrefList; diff --git a/src/core/Cutter.h b/src/core/Cutter.h index c9b92636..7d8aa098 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -98,21 +98,6 @@ public: */ QString cmd(const char *str); QString cmd(const QString &str) { return cmd(str.toUtf8().constData()); } - /** - * @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 Rizin command task - * @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 &task); - bool asyncCmd(const QString &str, QSharedPointer &task) - { - return asyncCmd(str.toUtf8().constData(), task); - } /** * @brief send a task to Rizin @@ -120,6 +105,7 @@ public: * @return execute successful? */ bool asyncTask(std::function fcn, QSharedPointer &task); + void functionTask(std::function fcn); /** * @brief Execute a Rizin command \a cmd. By nature, the API @@ -188,31 +174,8 @@ public: CutterJson cmdj(const char *str); CutterJson cmdj(const QString &str) { return cmdj(str.toUtf8().constData()); } - CutterJson cmdjAt(const char *str, RVA address); QString cmdTask(const QString &str); - CutterJson cmdjTask(const QString &str); - /** - * @brief send a command to Rizin and check for ESIL errors - * @param command the command you want to execute - * @note If you want to seek to an address, you should use CutterCore::seek. - */ - void cmdEsil(const char *command); - void cmdEsil(const QString &command) { cmdEsil(command.toUtf8().constData()); } - /** - * @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 Rizin command task - * @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 &task); - bool asyncCmdEsil(const QString &command, QSharedPointer &task) - { - return asyncCmdEsil(command.toUtf8().constData(), task); - } + QString getRizinVersionReadable(const char *program = nullptr); QString getVersionInformation(); diff --git a/src/dialogs/AboutDialog.cpp b/src/dialogs/AboutDialog.cpp index d60a5566..aaca9b47 100644 --- a/src/dialogs/AboutDialog.cpp +++ b/src/dialogs/AboutDialog.cpp @@ -1,4 +1,3 @@ -#include "rz_version.h" #include "core/Cutter.h" #include "AboutDialog.h" @@ -7,7 +6,6 @@ #include "common/Configuration.h" #include "common/BugReporting.h" - #include #include #include