Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert cmds {., afv[WR]j} #3017

Merged
merged 11 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rizin
Submodule rizin updated 43 files
+20 −0 librz/analysis/arch/ppc/ppc_analysis.h
+825 −0 librz/analysis/arch/ppc/ppc_il.c
+179 −0 librz/analysis/arch/ppc/ppc_il.h
+64 −0 librz/analysis/arch/ppc/ppc_il_flag_ops.c
+1,541 −0 librz/analysis/arch/ppc/ppc_il_ops.c
+1 −0 librz/analysis/il/analysis_il.c
+3 −0 librz/analysis/meson.build
+509 −183 librz/analysis/p/analysis_ppc_cs.c
+47 −0 librz/bin/bin.c
+8 −0 librz/bin/bobj.c
+2 −4 librz/cons/html.c
+19 −5 librz/core/cmd/cmd_help.c
+3 −0 librz/core/core_private.h
+2 −1 librz/core/fortune.c
+78 −1 librz/core/golang.c
+1 −1 librz/il/il_opcodes.c
+3 −2 librz/il/il_reg.c
+1 −1 librz/il/theory_effect.c
+3 −0 librz/include/rz_bin.h
+0 −2 librz/include/rz_cmd.h
+1 −1 librz/include/rz_core.h
+2 −1 librz/include/rz_heap_glibc.h
+11 −5 librz/include/rz_il/rz_il_opbuilder_begin.h
+8 −0 librz/include/rz_il/rz_il_opbuilder_end.h
+1 −0 librz/include/rz_il/rz_il_opcodes.h
+2 −0 librz/include/rz_types.h
+1 −1 librz/include/rz_userconf.h.in
+2 −2 librz/include/rz_util/rz_buf.h
+15 −0 librz/reg/rvalue.c
+4 −0 librz/util/bitvector.c
+4 −0 librz/util/compression.c
+4 −4 librz/util/strbuf.c
+6 −1 librz/util/version.c
+2 −2 meson.build
+6 −62 test/db/abi/platforms/reg_profile
+21 −7 test/db/analysis/golang
+129 −0 test/db/analysis/ppc
+253 −0 test/db/asm/ppc_64
+23 −0 test/db/cmd/cmd_ar
+0 −1 test/db/cmd/cmd_pde
+46 −0 test/db/rzil/ppc32
+619 −0 test/db/rzil/ppc64
+18 −0 test/unit/test_cons.c
5 changes: 4 additions & 1 deletion src/common/RunScriptTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
118 changes: 33 additions & 85 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,37 +437,15 @@ 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)
bool CutterCore::asyncTask(std::function<void *(RzCore *)> fcn, QSharedPointer<RizinTask> &task)
{
if (!task.isNull()) {
return false;
}

CORE_LOCK();

RVA offset = core->offset;

task = QSharedPointer<RizinTask>(new RizinCmdTask(str, true));
task = QSharedPointer<RizinTask>(new RizinFunctionTask(std::move(fcn), true));
connect(task.data(), &RizinTask::finished, task.data(), [this, offset, task]() {
CORE_LOCK();

Expand All @@ -479,24 +457,11 @@ bool CutterCore::asyncCmd(const char *str, QSharedPointer<RizinTask> &task)
return true;
}

bool CutterCore::asyncTask(std::function<void *(RzCore *)> fcn, QSharedPointer<RizinTask> &task)
void CutterCore::functionTask(std::function<void *(RzCore *)> fcn)
{
if (!task.isNull()) {
return false;
}

CORE_LOCK();
RVA offset = core->offset;
task = QSharedPointer<RizinTask>(new RizinFunctionTask(std::move(fcn), true));
connect(task.data(), &RizinTask::finished, task.data(), [this, offset, task]() {
CORE_LOCK();

if (offset != core->offset) {
updateSeek();
}
});

return true;
auto task = std::unique_ptr<RizinTask>(new RizinFunctionTask(std::move(fcn), true));
task->startTask();
task->joinTask();
XVilka marked this conversation as resolved.
Show resolved Hide resolved
}

QString CutterCore::cmdRawAt(const char *cmd, RVA address)
Expand Down Expand Up @@ -541,18 +506,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);
Expand All @@ -561,14 +514,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) {
Expand Down Expand Up @@ -1399,16 +1344,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, "");
Expand Down Expand Up @@ -4033,22 +3968,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;
Expand Down
41 changes: 2 additions & 39 deletions src/core/Cutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,14 @@ class CUTTER_EXPORT CutterCore : public QObject
*/
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
* @param fcn the task you want to execute
* @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
Expand Down Expand Up @@ -187,31 +173,8 @@ class CUTTER_EXPORT CutterCore : public QObject

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();

Expand Down
2 changes: 0 additions & 2 deletions src/dialogs/AboutDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "rz_version.h"
#include "core/Cutter.h"
#include "AboutDialog.h"

Expand All @@ -7,7 +6,6 @@
#include "common/Configuration.h"
#include "common/BugReporting.h"


#include <QUrl>
#include <QTimer>
#include <QEventLoop>
Expand Down