mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-18 18:38:51 +00:00
Convert cmds {.
, afv[WR]j
} (#3017)
* remove `asyncCmd` `asyncCmdEsil`, `cmdjTask`, `cmdEsil`, `cmdjAt` * convert `afv[WR]j`
This commit is contained in:
parent
41c4857ed9
commit
756850ae27
2
rizin
2
rizin
@ -1 +1 @@
|
||||
Subproject commit a9c59ce1ddc44c498b6a9a02e36989a34f184286
|
||||
Subproject commit 32ef171354e2fde6194a354a1a350df357c08afc
|
@ -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;
|
||||
}
|
||||
|
@ -430,48 +430,6 @@ bool CutterCore::isDebugTaskInProgress()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<RizinTask> &task)
|
||||
{
|
||||
asyncCmd(command, task);
|
||||
|
||||
if (task.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(task.data(), &RizinCmdTask::finished, task.data(), [this, task]() {
|
||||
QString res = qobject_cast<RizinCmdTask *>(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<RizinTask> &task)
|
||||
{
|
||||
if (!task.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CORE_LOCK();
|
||||
|
||||
RVA offset = core->offset;
|
||||
|
||||
task = QSharedPointer<RizinTask>(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<void *(RzCore *)> fcn, QSharedPointer<RizinTask> &task)
|
||||
{
|
||||
if (!task.isNull()) {
|
||||
@ -492,6 +450,13 @@ bool CutterCore::asyncTask(std::function<void *(RzCore *)> fcn, QSharedPointer<R
|
||||
return true;
|
||||
}
|
||||
|
||||
void CutterCore::functionTask(std::function<void *(RzCore *)> fcn)
|
||||
{
|
||||
auto task = std::unique_ptr<RizinTask>(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<SearchDescription> CutterCore::getAllSearch(QString searchFor, QString spa
|
||||
QList<XrefDescription> 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<XrefDescription> xrefList = QList<XrefDescription>();
|
||||
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<RzAnalysisVar>(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;
|
||||
|
@ -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<RizinTask> &task);
|
||||
bool asyncCmd(const QString &str, QSharedPointer<RizinTask> &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<void *(RzCore *)> fcn, QSharedPointer<RizinTask> &task);
|
||||
void functionTask(std::function<void *(RzCore *)> 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<RizinTask> &task);
|
||||
bool asyncCmdEsil(const QString &command, QSharedPointer<RizinTask> &task)
|
||||
{
|
||||
return asyncCmdEsil(command.toUtf8().constData(), task);
|
||||
}
|
||||
|
||||
QString getRizinVersionReadable(const char *program = nullptr);
|
||||
QString getVersionInformation();
|
||||
|
||||
|
@ -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 <QUrl>
|
||||
#include <QTimer>
|
||||
#include <QEventLoop>
|
||||
|
Loading…
Reference in New Issue
Block a user