2017-04-18 08:33:35 +00:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
2018-03-11 11:13:08 +00:00
|
|
|
#include <QRegularExpression>
|
2018-04-15 12:41:10 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QCoreApplication>
|
2020-03-26 13:07:33 +00:00
|
|
|
#include <QVector>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QStandardPaths>
|
2018-04-15 12:41:10 +00:00
|
|
|
|
2019-10-06 17:35:44 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <memory>
|
|
|
|
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/TempConfig.h"
|
2019-11-17 18:44:10 +00:00
|
|
|
#include "common/BasicInstructionHighlighter.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/AsyncTask.h"
|
2020-12-16 09:51:53 +00:00
|
|
|
#include "common/RizinTask.h"
|
2020-12-18 09:47:50 +00:00
|
|
|
#include "dialogs/RizinTaskDialog.h"
|
2018-08-17 11:27:07 +00:00
|
|
|
#include "common/Json.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2019-07-15 12:08:44 +00:00
|
|
|
#include "Decompiler.h"
|
2020-12-01 11:45:26 +00:00
|
|
|
|
|
|
|
#include <rz_asm.h>
|
|
|
|
#include <rz_cmd.h>
|
|
|
|
#include <sdb.h>
|
2017-09-25 12:55:41 +00:00
|
|
|
|
2019-02-20 17:52:11 +00:00
|
|
|
Q_GLOBAL_STATIC(CutterCore, uniqueInstance)
|
2017-04-18 08:33:35 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
#define RZ_JSON_KEY(name) static const QString name = QStringLiteral(#name)
|
2018-11-20 07:45:42 +00:00
|
|
|
|
|
|
|
namespace RJsonKey {
|
2021-01-24 14:50:13 +00:00
|
|
|
RZ_JSON_KEY(addr);
|
|
|
|
RZ_JSON_KEY(addrs);
|
|
|
|
RZ_JSON_KEY(addr_end);
|
|
|
|
RZ_JSON_KEY(arrow);
|
|
|
|
RZ_JSON_KEY(baddr);
|
|
|
|
RZ_JSON_KEY(bind);
|
|
|
|
RZ_JSON_KEY(blocks);
|
|
|
|
RZ_JSON_KEY(blocksize);
|
|
|
|
RZ_JSON_KEY(bytes);
|
|
|
|
RZ_JSON_KEY(calltype);
|
|
|
|
RZ_JSON_KEY(cc);
|
|
|
|
RZ_JSON_KEY(classname);
|
|
|
|
RZ_JSON_KEY(code);
|
|
|
|
RZ_JSON_KEY(comment);
|
|
|
|
RZ_JSON_KEY(comments);
|
|
|
|
RZ_JSON_KEY(cost);
|
|
|
|
RZ_JSON_KEY(data);
|
|
|
|
RZ_JSON_KEY(description);
|
|
|
|
RZ_JSON_KEY(ebbs);
|
|
|
|
RZ_JSON_KEY(edges);
|
|
|
|
RZ_JSON_KEY(enabled);
|
|
|
|
RZ_JSON_KEY(entropy);
|
|
|
|
RZ_JSON_KEY(fcn_addr);
|
|
|
|
RZ_JSON_KEY(fcn_name);
|
|
|
|
RZ_JSON_KEY(fields);
|
|
|
|
RZ_JSON_KEY(file);
|
|
|
|
RZ_JSON_KEY(flags);
|
|
|
|
RZ_JSON_KEY(flagname);
|
|
|
|
RZ_JSON_KEY(format);
|
|
|
|
RZ_JSON_KEY(from);
|
|
|
|
RZ_JSON_KEY(functions);
|
|
|
|
RZ_JSON_KEY(graph);
|
|
|
|
RZ_JSON_KEY(haddr);
|
|
|
|
RZ_JSON_KEY(hw);
|
|
|
|
RZ_JSON_KEY(in_functions);
|
|
|
|
RZ_JSON_KEY(index);
|
|
|
|
RZ_JSON_KEY(jump);
|
|
|
|
RZ_JSON_KEY(laddr);
|
|
|
|
RZ_JSON_KEY(lang);
|
|
|
|
RZ_JSON_KEY(len);
|
|
|
|
RZ_JSON_KEY(length);
|
|
|
|
RZ_JSON_KEY(license);
|
|
|
|
RZ_JSON_KEY(methods);
|
|
|
|
RZ_JSON_KEY(name);
|
|
|
|
RZ_JSON_KEY(realname);
|
|
|
|
RZ_JSON_KEY(nargs);
|
|
|
|
RZ_JSON_KEY(nbbs);
|
|
|
|
RZ_JSON_KEY(nlocals);
|
|
|
|
RZ_JSON_KEY(offset);
|
|
|
|
RZ_JSON_KEY(opcode);
|
|
|
|
RZ_JSON_KEY(opcodes);
|
|
|
|
RZ_JSON_KEY(ordinal);
|
|
|
|
RZ_JSON_KEY(libname);
|
|
|
|
RZ_JSON_KEY(outdegree);
|
|
|
|
RZ_JSON_KEY(paddr);
|
|
|
|
RZ_JSON_KEY(path);
|
|
|
|
RZ_JSON_KEY(perm);
|
|
|
|
RZ_JSON_KEY(pid);
|
|
|
|
RZ_JSON_KEY(plt);
|
|
|
|
RZ_JSON_KEY(prot);
|
|
|
|
RZ_JSON_KEY(ref);
|
|
|
|
RZ_JSON_KEY(refs);
|
|
|
|
RZ_JSON_KEY(reg);
|
|
|
|
RZ_JSON_KEY(rwx);
|
|
|
|
RZ_JSON_KEY(section);
|
|
|
|
RZ_JSON_KEY(sections);
|
|
|
|
RZ_JSON_KEY(size);
|
|
|
|
RZ_JSON_KEY(stackframe);
|
|
|
|
RZ_JSON_KEY(status);
|
|
|
|
RZ_JSON_KEY(string);
|
|
|
|
RZ_JSON_KEY(strings);
|
|
|
|
RZ_JSON_KEY(symbols);
|
|
|
|
RZ_JSON_KEY(text);
|
|
|
|
RZ_JSON_KEY(to);
|
|
|
|
RZ_JSON_KEY(trace);
|
|
|
|
RZ_JSON_KEY(type);
|
|
|
|
RZ_JSON_KEY(uid);
|
|
|
|
RZ_JSON_KEY(vaddr);
|
|
|
|
RZ_JSON_KEY(value);
|
|
|
|
RZ_JSON_KEY(vsize);
|
2020-10-28 12:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef RZ_JSON_KEY
|
2018-11-20 07:45:42 +00:00
|
|
|
|
2020-01-04 18:05:49 +00:00
|
|
|
static void updateOwnedCharPtr(char *&variable, const QString &newValue)
|
|
|
|
{
|
|
|
|
auto data = newValue.toUtf8();
|
2020-10-28 12:28:04 +00:00
|
|
|
RZ_FREE(variable)
|
2020-01-04 18:05:49 +00:00
|
|
|
variable = strdup(data.data());
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
static QString fromOwnedCharPtr(char *str)
|
|
|
|
{
|
2020-04-16 17:31:15 +00:00
|
|
|
QString result(str ? str : "");
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_mem_free(str);
|
2020-04-16 17:31:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
RzCoreLocked::RzCoreLocked(CutterCore *core) : core(core)
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
core->coreMutex.lock();
|
|
|
|
assert(core->coreLockDepth >= 0);
|
|
|
|
core->coreLockDepth++;
|
|
|
|
if (core->coreLockDepth == 1) {
|
|
|
|
assert(core->coreBed);
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_cons_sleep_end(core->coreBed);
|
2019-08-30 15:31:30 +00:00
|
|
|
core->coreBed = nullptr;
|
|
|
|
}
|
2017-04-09 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCoreLocked::~RzCoreLocked()
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
assert(core->coreLockDepth > 0);
|
|
|
|
core->coreLockDepth--;
|
|
|
|
if (core->coreLockDepth == 0) {
|
2020-10-28 12:28:04 +00:00
|
|
|
core->coreBed = rz_cons_sleep_begin();
|
2019-08-30 15:31:30 +00:00
|
|
|
}
|
|
|
|
core->coreMutex.unlock();
|
2017-04-09 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCoreLocked::operator RzCore *() const
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
return core->core_;
|
2017-04-09 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCore *RzCoreLocked::operator->() const
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
return core->core_;
|
2017-04-09 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
#define CORE_LOCK() RzCoreLocked core(this)
|
2017-04-09 17:12:36 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
static void cutterREventCallback(RzEvent *, int type, void *user, void *data)
|
2019-02-07 10:42:53 +00:00
|
|
|
{
|
|
|
|
auto core = reinterpret_cast<CutterCore *>(user);
|
|
|
|
core->handleREvent(type, data);
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
CutterCore::CutterCore(QObject *parent)
|
|
|
|
: QObject(parent)
|
2020-11-30 07:42:13 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
2021-01-24 14:50:13 +00:00
|
|
|
,
|
|
|
|
coreMutex(QMutex::Recursive)
|
2020-11-30 07:42:13 +00:00
|
|
|
#endif
|
2019-02-20 17:52:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CutterCore *CutterCore::instance()
|
|
|
|
{
|
|
|
|
return uniqueInstance;
|
|
|
|
}
|
|
|
|
|
2020-04-20 21:22:10 +00:00
|
|
|
void CutterCore::initialize(bool loadPlugins)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2021-04-20 03:34:52 +00:00
|
|
|
auto prefix = QDir(QCoreApplication::applicationDirPath());
|
|
|
|
|
|
|
|
#if defined(CUTTER_ENABLE_PACKAGING) && defined(Q_OS_WIN)
|
|
|
|
auto prefixBytes = prefix.absolutePath().toUtf8();
|
|
|
|
rz_sys_prefix(prefixBytes.constData());
|
|
|
|
#endif
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_cons_new(); // initialize console
|
2020-10-28 12:28:04 +00:00
|
|
|
core_ = rz_core_new();
|
|
|
|
rz_core_task_sync_begin(&core_->tasks);
|
|
|
|
coreBed = rz_cons_sleep_begin();
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2019-02-07 10:42:53 +00:00
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
rz_event_hook(core_->analysis->ev, RZ_EVENT_ALL, cutterREventCallback, this);
|
2018-05-25 14:30:59 +00:00
|
|
|
|
2020-12-06 18:00:13 +00:00
|
|
|
#if defined(APPIMAGE) || defined(MACOS_RZ_BUNDLED)
|
2021-01-24 14:50:13 +00:00
|
|
|
# ifdef APPIMAGE
|
2018-09-30 20:00:53 +00:00
|
|
|
// Executable is in appdir/bin
|
|
|
|
prefix.cdUp();
|
2020-12-13 09:33:08 +00:00
|
|
|
qInfo() << "Setting Rizin prefix =" << prefix.absolutePath() << " for AppImage.";
|
2021-01-24 14:50:13 +00:00
|
|
|
# else // MACOS_RZ_BUNDLED
|
2020-12-16 10:59:23 +00:00
|
|
|
// Executable is in Contents/MacOS, prefix is Contents/Resources/rz
|
2018-09-30 20:00:53 +00:00
|
|
|
prefix.cdUp();
|
|
|
|
prefix.cd("Resources");
|
2021-01-24 14:50:13 +00:00
|
|
|
qInfo() << "Setting Rizin prefix =" << prefix.absolutePath()
|
|
|
|
<< " for macOS Application Bundle.";
|
2018-04-15 12:41:10 +00:00
|
|
|
setConfig("dir.prefix", prefix.absolutePath());
|
2021-04-20 03:34:52 +00:00
|
|
|
# endif
|
2019-08-30 11:41:14 +00:00
|
|
|
|
|
|
|
auto pluginsDir = prefix;
|
2020-12-06 18:00:13 +00:00
|
|
|
if (pluginsDir.cd("share/rizin/plugins")) {
|
2020-12-13 09:33:08 +00:00
|
|
|
qInfo() << "Setting Rizin plugins dir =" << pluginsDir.absolutePath();
|
2019-08-30 11:41:14 +00:00
|
|
|
setConfig("dir.plugins", pluginsDir.absolutePath());
|
|
|
|
} else {
|
2020-12-13 09:33:08 +00:00
|
|
|
qInfo() << "Rizin plugins dir under" << pluginsDir.absolutePath() << "does not exist!";
|
2019-08-30 11:41:14 +00:00
|
|
|
}
|
2018-04-15 12:41:10 +00:00
|
|
|
#endif
|
2018-05-26 16:21:23 +00:00
|
|
|
|
2020-04-20 21:22:10 +00:00
|
|
|
if (!loadPlugins) {
|
|
|
|
setConfig("cfg.plugins", 0);
|
|
|
|
}
|
|
|
|
if (getConfigi("cfg.plugins")) {
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_loadlibs(this->core_, RZ_CORE_LOADLIBS_ALL, nullptr);
|
2020-04-20 21:22:10 +00:00
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
// IMPLICIT rz_bin_iobind (core_->bin, core_->io);
|
2018-07-14 19:04:13 +00:00
|
|
|
|
2020-12-13 09:33:08 +00:00
|
|
|
// Otherwise Rizin may ask the user for input and Cutter would freeze
|
2018-07-14 19:04:13 +00:00
|
|
|
setConfig("scr.interactive", false);
|
|
|
|
|
2019-02-19 18:56:59 +00:00
|
|
|
// Initialize graph node highlighter
|
|
|
|
bbHighlighter = new BasicBlockHighlighter();
|
|
|
|
|
|
|
|
// Initialize Async tasks manager
|
2018-05-26 16:21:23 +00:00
|
|
|
asyncTaskManager = new AsyncTaskManager(this);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 15:31:30 +00:00
|
|
|
CutterCore::~CutterCore()
|
|
|
|
{
|
|
|
|
delete bbHighlighter;
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_cons_sleep_end(coreBed);
|
|
|
|
rz_core_task_sync_end(&core_->tasks);
|
|
|
|
rz_core_free(this->core_);
|
|
|
|
rz_cons_free();
|
2019-08-30 15:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCoreLocked CutterCore::core()
|
2019-08-30 15:31:30 +00:00
|
|
|
{
|
2020-10-28 12:28:04 +00:00
|
|
|
return RzCoreLocked(this);
|
2019-08-30 15:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 20:38:20 +00:00
|
|
|
QDir CutterCore::getCutterRCDefaultDirectory() const
|
2020-03-26 13:07:33 +00:00
|
|
|
{
|
2020-05-20 20:38:20 +00:00
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QString> CutterCore::getCutterRCFilePaths() const
|
|
|
|
{
|
|
|
|
QVector<QString> result;
|
|
|
|
result.push_back(QFileInfo(QDir::home(), ".cutterrc").absoluteFilePath());
|
2020-03-26 13:07:33 +00:00
|
|
|
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation);
|
2021-01-24 14:50:13 +00:00
|
|
|
for (auto &location : locations) {
|
2020-05-20 20:38:20 +00:00
|
|
|
result.push_back(QFileInfo(QDir(location), ".cutterrc").absoluteFilePath());
|
2020-03-26 13:07:33 +00:00
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
result.push_back(QFileInfo(getCutterRCDefaultDirectory(), "rc")
|
|
|
|
.absoluteFilePath()); // File in config editor is from this path
|
2020-03-26 13:07:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-11 10:32:56 +00:00
|
|
|
void CutterCore::loadCutterRC()
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2020-05-20 20:38:20 +00:00
|
|
|
const auto result = getCutterRCFilePaths();
|
2021-01-24 14:50:13 +00:00
|
|
|
for (auto &cutterRCFilePath : result) {
|
2020-05-20 20:38:20 +00:00
|
|
|
auto cutterRCFileInfo = QFileInfo(cutterRCFilePath);
|
|
|
|
if (!cutterRCFileInfo.exists() || !cutterRCFileInfo.isFile()) {
|
2020-03-26 13:07:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-20 20:38:20 +00:00
|
|
|
qInfo() << "Loading initialization file from " << cutterRCFilePath;
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_cmd_file(core, cutterRCFilePath.toUtf8().constData());
|
2020-05-20 20:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::loadDefaultCutterRC()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
auto cutterRCFilePath = QFileInfo(getCutterRCDefaultDirectory(), "rc").absoluteFilePath();
|
|
|
|
const auto cutterRCFileInfo = QFileInfo(cutterRCFilePath);
|
|
|
|
if (!cutterRCFileInfo.exists() || !cutterRCFileInfo.isFile()) {
|
|
|
|
return;
|
2019-07-11 10:32:56 +00:00
|
|
|
}
|
2020-05-20 20:38:20 +00:00
|
|
|
qInfo() << "Loading initialization file from " << cutterRCFilePath;
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_cmd_file(core, cutterRCFilePath.toUtf8().constData());
|
2019-07-11 10:32:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<QString> CutterCore::sdbList(QString path)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2017-03-29 10:18:37 +00:00
|
|
|
QList<QString> list = QList<QString>();
|
2019-08-30 15:31:30 +00:00
|
|
|
Sdb *root = sdb_ns_path(core->sdb, path.toUtf8().constData(), 0);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (root) {
|
2017-03-29 10:18:37 +00:00
|
|
|
void *vsi;
|
|
|
|
ls_iter_t *iter;
|
2021-01-24 14:50:13 +00:00
|
|
|
ls_foreach(root->ns, iter, vsi)
|
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
SdbNs *nsi = (SdbNs *)vsi;
|
2017-03-30 21:49:51 +00:00
|
|
|
list << nsi->name;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
using SdbListPtr = std::unique_ptr<SdbList, decltype(&ls_free)>;
|
2019-07-28 21:42:25 +00:00
|
|
|
static SdbListPtr makeSdbListPtr(SdbList *list)
|
|
|
|
{
|
2021-01-24 14:50:13 +00:00
|
|
|
return { list, ls_free };
|
2019-07-28 21:42:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<QString> CutterCore::sdbListKeys(QString path)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2017-03-29 10:18:37 +00:00
|
|
|
QList<QString> list = QList<QString>();
|
2019-08-30 15:31:30 +00:00
|
|
|
Sdb *root = sdb_ns_path(core->sdb, path.toUtf8().constData(), 0);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (root) {
|
2017-03-29 10:18:37 +00:00
|
|
|
void *vsi;
|
|
|
|
ls_iter_t *iter;
|
2019-07-28 21:42:25 +00:00
|
|
|
SdbListPtr l = makeSdbListPtr(sdb_foreach_list(root, false));
|
2021-01-24 14:50:13 +00:00
|
|
|
ls_foreach(l, iter, vsi)
|
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
SdbKv *nsi = (SdbKv *)vsi;
|
2018-11-19 07:45:04 +00:00
|
|
|
list << reinterpret_cast<char *>(nsi->base.key);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::sdbGet(QString path, QString key)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2019-08-30 15:31:30 +00:00
|
|
|
Sdb *db = sdb_ns_path(core->sdb, path.toUtf8().constData(), 0);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (db) {
|
2017-03-30 21:49:51 +00:00
|
|
|
const char *val = sdb_const_get(db, key.toUtf8().constData(), 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
if (val && *val)
|
2017-03-30 21:49:51 +00:00
|
|
|
return val;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2019-03-23 10:54:34 +00:00
|
|
|
return QString();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
bool CutterCore::sdbSet(QString path, QString key, QString val)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2019-08-30 15:31:30 +00:00
|
|
|
Sdb *db = sdb_ns_path(core->sdb, path.toUtf8().constData(), 1);
|
2021-01-24 14:50:13 +00:00
|
|
|
if (!db)
|
|
|
|
return false;
|
2017-04-09 19:55:06 +00:00
|
|
|
return sdb_set(db, key.toUtf8().constData(), val.toUtf8().constData(), 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::sanitizeStringForCommand(QString s)
|
2017-07-11 11:05:42 +00:00
|
|
|
{
|
2019-10-13 14:59:12 +00:00
|
|
|
static const QRegularExpression regexp(";|@");
|
2018-11-26 22:34:34 +00:00
|
|
|
return s.replace(regexp, QStringLiteral("_"));
|
2017-07-11 11:05:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
QString CutterCore::cmd(const char *str)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2017-05-13 18:09:36 +00:00
|
|
|
|
2019-08-30 15:31:30 +00:00
|
|
|
RVA offset = core->offset;
|
2020-10-28 12:28:04 +00:00
|
|
|
char *res = rz_core_cmd_str(core, str);
|
2020-04-16 17:31:15 +00:00
|
|
|
QString o = fromOwnedCharPtr(res);
|
2019-08-30 15:31:30 +00:00
|
|
|
|
|
|
|
if (offset != core->offset) {
|
2019-01-13 14:20:07 +00:00
|
|
|
updateSeek();
|
2017-10-09 18:08:35 +00:00
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2019-12-04 12:27:38 +00:00
|
|
|
bool CutterCore::isRedirectableDebugee()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging || currentlyAttachedToPID != -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are only able to redirect locally debugged unix processes
|
2021-09-14 21:40:01 +00:00
|
|
|
RzCoreLocked core(Core());
|
|
|
|
RzList *descs = rz_id_storage_list(core->io->files);
|
|
|
|
RzListIter *it;
|
|
|
|
RzIODesc *desc;
|
|
|
|
CutterRzListForeach(descs, it, RzIODesc, desc) {
|
|
|
|
QString URI = QString(desc->uri);
|
2019-12-04 12:27:38 +00:00
|
|
|
if (URI.contains("ptrace") | URI.contains("mach")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-31 09:50:08 +00:00
|
|
|
bool CutterCore::isDebugTaskInProgress()
|
|
|
|
{
|
|
|
|
if (!debugTask.isNull()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-18 09:47:50 +00:00
|
|
|
bool CutterCore::asyncCmdEsil(const char *command, QSharedPointer<RizinCmdTask> &task)
|
2019-10-31 09:50:08 +00:00
|
|
|
{
|
|
|
|
asyncCmd(command, task);
|
|
|
|
|
|
|
|
if (task.isNull()) {
|
2019-12-11 11:26:54 +00:00
|
|
|
return false;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(task.data(), &RizinCmdTask::finished, task.data(), [this, task]() {
|
2019-10-31 09:50:08 +00:00
|
|
|
QString res = task.data()->getResult();
|
|
|
|
|
|
|
|
if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) {
|
2021-01-24 14:50:13 +00:00
|
|
|
msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can "
|
|
|
|
"disable this in Preferences");
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
});
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
return true;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 09:47:50 +00:00
|
|
|
bool CutterCore::asyncCmd(const char *str, QSharedPointer<RizinCmdTask> &task)
|
2019-10-31 09:50:08 +00:00
|
|
|
{
|
|
|
|
if (!task.isNull()) {
|
2019-12-11 11:26:54 +00:00
|
|
|
return false;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CORE_LOCK();
|
|
|
|
|
|
|
|
RVA offset = core->offset;
|
|
|
|
|
2020-12-18 09:47:50 +00:00
|
|
|
task = QSharedPointer<RizinCmdTask>(new RizinCmdTask(str, true));
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(task.data(), &RizinCmdTask::finished, task.data(), [this, offset, task]() {
|
2019-10-31 09:50:08 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
|
|
|
|
if (offset != core->offset) {
|
|
|
|
updateSeek();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-11 11:26:54 +00:00
|
|
|
return true;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 09:36:36 +00:00
|
|
|
QString CutterCore::cmdRawAt(const char *cmd, RVA address)
|
|
|
|
{
|
|
|
|
QString res;
|
|
|
|
RVA oldOffset = getOffset();
|
|
|
|
seekSilent(address);
|
|
|
|
|
2020-03-19 17:29:04 +00:00
|
|
|
res = cmdRaw(cmd);
|
2020-03-19 09:36:36 +00:00
|
|
|
|
|
|
|
seekSilent(oldOffset);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:29:04 +00:00
|
|
|
QString CutterCore::cmdRaw(const char *cmd)
|
2017-12-20 22:50:26 +00:00
|
|
|
{
|
2020-03-19 17:29:04 +00:00
|
|
|
QString res;
|
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_cons_push();
|
2020-03-19 17:29:04 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
// rz_cmd_call does not return the output of the command
|
|
|
|
rz_cmd_call(core->rcmd, cmd);
|
2020-03-19 17:29:04 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
// we grab the output straight from rz_cons
|
|
|
|
res = rz_cons_get_buffer();
|
2020-03-19 17:29:04 +00:00
|
|
|
|
|
|
|
// cleaning up
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_cons_pop();
|
|
|
|
rz_cons_echo(NULL);
|
|
|
|
|
2020-03-19 17:29:04 +00:00
|
|
|
return res;
|
2017-12-20 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonDocument CutterCore::cmdj(const char *str)
|
2017-04-18 08:33:35 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
char *res;
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
res = rz_core_cmd_str(core, str);
|
2019-08-30 15:31:30 +00:00
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2018-05-29 16:19:59 +00:00
|
|
|
QJsonDocument doc = parseJson(res, str);
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_mem_free(res);
|
2018-05-29 16:19:59 +00:00
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2020-07-28 19:49:50 +00:00
|
|
|
QJsonDocument CutterCore::cmdjAt(const char *str, RVA address)
|
|
|
|
{
|
|
|
|
QJsonDocument res;
|
|
|
|
RVA oldOffset = getOffset();
|
|
|
|
seekSilent(address);
|
|
|
|
|
|
|
|
res = cmdj(str);
|
|
|
|
|
|
|
|
seekSilent(oldOffset);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-05-29 16:19:59 +00:00
|
|
|
QString CutterCore::cmdTask(const QString &str)
|
|
|
|
{
|
2020-12-18 09:47:50 +00:00
|
|
|
RizinCmdTask task(str);
|
2018-07-22 13:04:13 +00:00
|
|
|
task.startTask();
|
|
|
|
task.joinTask();
|
|
|
|
return task.getResult();
|
2018-05-29 16:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument CutterCore::cmdjTask(const QString &str)
|
|
|
|
{
|
2020-12-18 09:47:50 +00:00
|
|
|
RizinCmdTask task(str);
|
2018-07-22 13:04:13 +00:00
|
|
|
task.startTask();
|
|
|
|
task.joinTask();
|
|
|
|
return parseJson(task.getResultRaw(), str);
|
2018-05-29 16:19:59 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonDocument CutterCore::parseJson(const char *res, const char *cmd)
|
2018-05-29 16:19:59 +00:00
|
|
|
{
|
2018-11-26 22:34:34 +00:00
|
|
|
QByteArray json(res);
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
if (json.isEmpty()) {
|
2017-11-25 14:15:58 +00:00
|
|
|
return QJsonDocument();
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonParseError jsonError;
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(json, &jsonError);
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (jsonError.error != QJsonParseError::NoError) {
|
2021-02-19 14:32:58 +00:00
|
|
|
// don't call trimmed() before knowing that parsing failed to avoid copying huge jsons all
|
|
|
|
// the time
|
2021-01-24 13:12:01 +00:00
|
|
|
if (json.trimmed().isEmpty()) {
|
|
|
|
return doc;
|
|
|
|
}
|
2018-11-26 22:34:34 +00:00
|
|
|
if (cmd) {
|
|
|
|
eprintf("Failed to parse JSON for command \"%s\": %s\n", cmd,
|
2018-05-29 16:19:59 +00:00
|
|
|
jsonError.errorString().toLocal8Bit().constData());
|
|
|
|
} else {
|
2021-01-24 14:50:13 +00:00
|
|
|
eprintf("Failed to parse JSON: %s\n",
|
|
|
|
jsonError.errorString().toLocal8Bit().constData());
|
2018-05-29 16:19:59 +00:00
|
|
|
}
|
2020-03-04 07:39:52 +00:00
|
|
|
const int MAX_JSON_DUMP_SIZE = 8 * 1024;
|
|
|
|
if (json.length() > MAX_JSON_DUMP_SIZE) {
|
|
|
|
int originalSize = json.length();
|
|
|
|
json.resize(MAX_JSON_DUMP_SIZE);
|
|
|
|
eprintf("%d bytes total: %s ...\n", originalSize, json.constData());
|
|
|
|
} else {
|
|
|
|
eprintf("%s\n", json.constData());
|
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 08:33:35 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
QStringList CutterCore::autocomplete(const QString &cmd, RzLinePromptType promptType, size_t limit)
|
2019-04-26 15:07:11 +00:00
|
|
|
{
|
2020-10-28 12:28:04 +00:00
|
|
|
RzLineBuffer buf;
|
2019-04-26 15:07:11 +00:00
|
|
|
int c = snprintf(buf.data, sizeof(buf.data), "%s", cmd.toUtf8().constData());
|
|
|
|
if (c < 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
buf.index = buf.length = std::min((int)(sizeof(buf.data) - 1), c);
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzLineCompletion completion;
|
|
|
|
rz_line_completion_init(&completion, limit);
|
|
|
|
rz_core_autocomplete(core(), &completion, &buf, promptType);
|
2019-04-26 15:07:11 +00:00
|
|
|
|
|
|
|
QStringList r;
|
2020-10-28 12:28:04 +00:00
|
|
|
r.reserve(rz_pvector_len(&completion.args));
|
|
|
|
for (size_t i = 0; i < rz_pvector_len(&completion.args); i++) {
|
2021-01-24 14:50:13 +00:00
|
|
|
r.push_back(QString::fromUtf8(
|
|
|
|
reinterpret_cast<const char *>(rz_pvector_at(&completion.args, i))));
|
2019-04-26 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_line_completion_fini(&completion);
|
2019-04-26 15:07:11 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-06-20 09:24:28 +00:00
|
|
|
/**
|
|
|
|
* @brief CutterCore::loadFile
|
2021-09-14 08:13:19 +00:00
|
|
|
* Load initial file.
|
2018-06-20 09:24:28 +00:00
|
|
|
* @param path File path
|
2020-10-28 12:28:04 +00:00
|
|
|
* @param baddr Base (RzBin) address
|
2018-06-20 09:24:28 +00:00
|
|
|
* @param mapaddr Map address
|
|
|
|
* @param perms
|
|
|
|
* @param va
|
2020-10-28 12:28:04 +00:00
|
|
|
* @param loadbin Load RzBin information
|
2018-06-20 09:24:28 +00:00
|
|
|
* @param forceBinPlugin
|
|
|
|
* @return
|
|
|
|
*/
|
2021-01-24 14:50:13 +00:00
|
|
|
bool CutterCore::loadFile(QString path, ut64 baddr, ut64 mapaddr, int perms, int va, bool loadbin,
|
|
|
|
const QString &forceBinPlugin)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCoreFile *f;
|
|
|
|
rz_config_set_i(core->config, "io.va", va);
|
2017-11-25 13:21:01 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
f = rz_core_file_open(core, path.toUtf8().constData(), perms, mapaddr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!f) {
|
2020-10-28 12:28:04 +00:00
|
|
|
eprintf("rz_core_file_open failed\n");
|
2017-03-29 10:18:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!forceBinPlugin.isNull()) {
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_bin_force_plugin(rz_core_get_bin(core), forceBinPlugin.toUtf8().constData());
|
2017-09-29 11:32:53 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
if (loadbin && va) {
|
2020-10-28 12:28:04 +00:00
|
|
|
if (!rz_core_bin_load(core, path.toUtf8().constData(), baddr)) {
|
2018-05-05 13:20:14 +00:00
|
|
|
eprintf("CANNOT GET RBIN INFO\n");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
|
2020-10-28 12:28:04 +00:00
|
|
|
if (!rz_core_file_open(core, path.toUtf8(), RZ_IO_READ | (rw ? RZ_IO_WRITE : 0, mapaddr))) {
|
2017-04-09 19:55:06 +00:00
|
|
|
eprintf("Cannot open file\n");
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2020-10-28 12:28:04 +00:00
|
|
|
// load RzBin information
|
2017-03-29 10:18:37 +00:00
|
|
|
// XXX only for sub-bins
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_bin_load(core, path.toUtf8(), baddr);
|
|
|
|
rz_bin_select_idx(core->bin, NULL, idx);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2020-10-28 12:28:04 +00:00
|
|
|
// Not loading RzBin info coz va = false
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2019-08-30 15:31:30 +00:00
|
|
|
auto iod = core->io ? core->io->desc : NULL;
|
2021-01-24 14:50:13 +00:00
|
|
|
auto debug =
|
|
|
|
core->file && iod && (core->file->fd == iod->fd) && iod->plugin && iod->plugin->isdbg;
|
2018-03-01 12:16:23 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
if (!debug && rz_flag_get(core->flags, "entry0")) {
|
|
|
|
rz_core_cmd0(core, "s entry0");
|
2018-03-01 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
if (perms & RZ_PERM_W) {
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_core_cmd0(core, "omfg+w");
|
2018-03-01 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
fflush(stdout);
|
2017-03-29 10:18:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-20 09:24:28 +00:00
|
|
|
bool CutterCore::tryFile(QString path, bool rw)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzCoreFile *cf;
|
|
|
|
int flags = RZ_PERM_R;
|
2021-01-24 14:50:13 +00:00
|
|
|
if (rw)
|
|
|
|
flags = RZ_PERM_RW;
|
2020-10-28 12:28:04 +00:00
|
|
|
cf = rz_core_file_open(core, path.toUtf8().constData(), flags, 0LL);
|
2018-06-20 09:24:28 +00:00
|
|
|
if (!cf) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-04 09:05:34 +00:00
|
|
|
rz_core_file_close(cf);
|
2018-06-20 09:24:28 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
2020-12-13 09:33:08 +00:00
|
|
|
* @brief Maps a file using Rizin API
|
2019-03-06 20:30:39 +00:00
|
|
|
* @param path Path to file
|
|
|
|
* @param mapaddr Map Address
|
|
|
|
* @return bool
|
2019-02-05 19:35:54 +00:00
|
|
|
*/
|
2020-04-07 13:20:52 +00:00
|
|
|
bool CutterCore::mapFile(QString path, RVA mapaddr)
|
2018-06-20 09:24:28 +00:00
|
|
|
{
|
2019-02-05 19:35:54 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
RVA addr = mapaddr != RVA_INVALID ? mapaddr : 0;
|
2021-01-24 14:50:13 +00:00
|
|
|
ut64 baddr =
|
|
|
|
Core()->getFileInfo().object()["bin"].toObject()["baddr"].toVariant().toULongLong();
|
2020-10-28 12:28:04 +00:00
|
|
|
if (rz_core_file_open(core, path.toUtf8().constData(), RZ_PERM_RX, addr)) {
|
|
|
|
rz_core_bin_load(core, path.toUtf8().constData(), baddr);
|
2018-06-20 09:24:28 +00:00
|
|
|
} else {
|
2019-02-05 19:35:54 +00:00
|
|
|
return false;
|
2018-06-20 09:24:28 +00:00
|
|
|
}
|
2019-02-05 19:35:54 +00:00
|
|
|
return true;
|
2018-06-20 09:24:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 08:56:38 +00:00
|
|
|
void CutterCore::renameFunction(const RVA offset, const QString &newName)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
cmdRaw("afn " + newName + " " + RzAddressString(offset));
|
2020-07-16 08:56:38 +00:00
|
|
|
emit functionRenamed(offset, newName);
|
2017-11-27 08:22:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void CutterCore::delFunction(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
cmdRaw("af- " + RzAddressString(addr));
|
2017-12-11 13:07:12 +00:00
|
|
|
emit functionsChanged();
|
|
|
|
}
|
|
|
|
|
2017-11-27 08:22:52 +00:00
|
|
|
void CutterCore::renameFlag(QString old_name, QString new_name)
|
|
|
|
{
|
2017-12-20 22:50:26 +00:00
|
|
|
cmdRaw("fr " + old_name + " " + new_name);
|
2017-12-03 20:23:02 +00:00
|
|
|
emit flagsChanged();
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 08:32:46 +00:00
|
|
|
void CutterCore::renameFunctionVariable(QString newName, QString oldName, RVA functionAddress)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *function = rz_analysis_get_function_at(core->analysis, functionAddress);
|
2021-01-24 14:50:13 +00:00
|
|
|
RzAnalysisVar *variable =
|
|
|
|
rz_analysis_function_get_var_byname(function, oldName.toUtf8().constData());
|
2020-08-06 08:32:46 +00:00
|
|
|
if (variable) {
|
2020-12-07 07:57:11 +00:00
|
|
|
rz_analysis_var_rename(variable, newName.toUtf8().constData(), true);
|
2020-08-06 08:32:46 +00:00
|
|
|
}
|
|
|
|
emit refreshCodeViews();
|
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void CutterCore::delFlag(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("f-", addr);
|
2017-12-11 13:07:12 +00:00
|
|
|
emit flagsChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-11 16:40:52 +00:00
|
|
|
void CutterCore::delFlag(const QString &name)
|
|
|
|
{
|
|
|
|
cmdRaw("f-" + name);
|
|
|
|
emit flagsChanged();
|
|
|
|
}
|
|
|
|
|
2018-09-14 17:20:54 +00:00
|
|
|
QString CutterCore::getInstructionBytes(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
return cmdj("aoj @ " + RzAddressString(addr))
|
2021-01-24 14:50:13 +00:00
|
|
|
.array()
|
|
|
|
.first()
|
|
|
|
.toObject()[RJsonKey::bytes]
|
|
|
|
.toString();
|
2018-09-14 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::getInstructionOpcode(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
return cmdj("aoj @ " + RzAddressString(addr))
|
2021-01-24 14:50:13 +00:00
|
|
|
.array()
|
|
|
|
.first()
|
|
|
|
.toObject()[RJsonKey::opcode]
|
|
|
|
.toString();
|
2018-09-14 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 20:12:13 +00:00
|
|
|
void CutterCore::editInstruction(RVA addr, const QString &inst)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("wa %1").arg(inst), addr);
|
2018-02-12 20:12:13 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-03-05 14:20:55 +00:00
|
|
|
void CutterCore::nopInstruction(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("wao nop", addr);
|
2018-03-05 14:20:55 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-03-10 07:27:09 +00:00
|
|
|
void CutterCore::jmpReverse(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("wao recj", addr);
|
2018-03-10 07:27:09 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-02-12 20:12:13 +00:00
|
|
|
void CutterCore::editBytes(RVA addr, const QString &bytes)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("wx %1").arg(bytes), addr);
|
2018-02-12 20:12:13 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-07-24 23:15:38 +00:00
|
|
|
void CutterCore::editBytesEndian(RVA addr, const QString &bytes)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("wv %1").arg(bytes), addr);
|
2018-07-24 23:15:38 +00:00
|
|
|
emit stackChanged();
|
|
|
|
}
|
|
|
|
|
2018-08-04 18:05:56 +00:00
|
|
|
void CutterCore::setToCode(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("Cd-", addr);
|
2018-08-04 18:05:56 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2019-12-18 14:26:51 +00:00
|
|
|
void CutterCore::setAsString(RVA addr, int size, StringTypeFormats type)
|
2018-11-16 21:27:07 +00:00
|
|
|
{
|
2021-01-24 14:50:13 +00:00
|
|
|
if (RVA_INVALID == addr) {
|
2019-12-18 14:26:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString command;
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
switch (type) {
|
|
|
|
case StringTypeFormats::None: {
|
2020-03-21 13:25:50 +00:00
|
|
|
command = "Cs";
|
2019-12-18 14:26:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
case StringTypeFormats::ASCII_LATIN1: {
|
2020-03-21 13:25:50 +00:00
|
|
|
command = "Csa";
|
2019-12-18 14:26:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
case StringTypeFormats::UTF8: {
|
2020-03-21 13:25:50 +00:00
|
|
|
command = "Cs8";
|
2019-12-18 14:26:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
seekAndShow(addr);
|
|
|
|
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("%1 %2").arg(command).arg(size), addr);
|
2019-12-18 14:26:51 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::removeString(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("Cs-", addr);
|
2018-11-16 21:27:07 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2019-12-18 14:26:51 +00:00
|
|
|
QString CutterCore::getString(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
return cmdRawAt("ps", addr);
|
2019-12-18 14:26:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 18:05:56 +00:00
|
|
|
void CutterCore::setToData(RVA addr, int size, int repeat)
|
|
|
|
{
|
|
|
|
if (size <= 0 || repeat <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("Cd-", addr);
|
|
|
|
cmdRawAt(QString("Cd %1 %2").arg(size).arg(repeat), addr);
|
2018-08-04 18:05:56 +00:00
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CutterCore::sizeofDataMeta(RVA addr)
|
|
|
|
{
|
|
|
|
bool ok;
|
2020-03-21 13:25:50 +00:00
|
|
|
int size = cmdRawAt("Cd.", addr).toInt(&ok);
|
2018-08-04 18:05:56 +00:00
|
|
|
return (ok ? size : 0);
|
|
|
|
}
|
|
|
|
|
2017-12-01 10:46:13 +00:00
|
|
|
void CutterCore::setComment(RVA addr, const QString &cmt)
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("CCu base64:%1").arg(QString(cmt.toLocal8Bit().toBase64())), addr);
|
2020-08-29 05:15:47 +00:00
|
|
|
emit commentsChanged(addr);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void CutterCore::delComment(RVA addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt("CC-", addr);
|
2020-08-29 05:15:47 +00:00
|
|
|
emit commentsChanged(addr);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 07:09:30 +00:00
|
|
|
/**
|
|
|
|
* @brief Gets the comment present at a specific address
|
|
|
|
* @param addr The address to be checked
|
|
|
|
* @return String containing comment
|
|
|
|
*/
|
|
|
|
QString CutterCore::getCommentAt(RVA addr)
|
|
|
|
{
|
2020-04-16 17:31:15 +00:00
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
return rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, addr);
|
2020-04-04 07:09:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 10:59:23 +00:00
|
|
|
void CutterCore::setImmediateBase(const QString &rzBaseName, RVA offset)
|
2017-11-28 13:13:22 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2017-11-28 13:13:22 +00:00
|
|
|
offset = getOffset();
|
|
|
|
}
|
|
|
|
|
2020-12-16 10:59:23 +00:00
|
|
|
this->cmdRawAt(QString("ahi %1").arg(rzBaseName), offset);
|
2017-11-28 13:13:22 +00:00
|
|
|
emit instructionChanged(offset);
|
|
|
|
}
|
|
|
|
|
2018-02-12 09:48:06 +00:00
|
|
|
void CutterCore::setCurrentBits(int bits, RVA offset)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2018-02-12 09:48:06 +00:00
|
|
|
offset = getOffset();
|
|
|
|
}
|
|
|
|
|
2020-03-21 13:25:50 +00:00
|
|
|
this->cmdRawAt(QString("ahb %1").arg(bits), offset);
|
2018-02-12 09:48:06 +00:00
|
|
|
emit instructionChanged(offset);
|
|
|
|
}
|
|
|
|
|
2019-02-24 17:25:38 +00:00
|
|
|
void CutterCore::applyStructureOffset(const QString &structureOffset, RVA offset)
|
|
|
|
{
|
|
|
|
if (offset == RVA_INVALID) {
|
|
|
|
offset = getOffset();
|
|
|
|
}
|
|
|
|
|
2020-03-21 13:25:50 +00:00
|
|
|
this->cmdRawAt("aht " + structureOffset, offset);
|
2019-02-24 17:25:38 +00:00
|
|
|
emit instructionChanged(offset);
|
|
|
|
}
|
|
|
|
|
2020-03-19 09:36:36 +00:00
|
|
|
void CutterCore::seekSilent(ut64 offset)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
if (offset == RVA_INVALID) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_seek(core, offset, true);
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:11:30 +00:00
|
|
|
void CutterCore::seek(ut64 offset)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-10-16 19:00:47 +00:00
|
|
|
// Slower than using the API, but the API is not complete
|
2020-12-16 10:59:23 +00:00
|
|
|
// which means we either have to duplicate code from rizin
|
|
|
|
// here, or refactor rizin API.
|
2017-10-16 19:00:47 +00:00
|
|
|
CORE_LOCK();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2018-01-27 13:11:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-03-21 13:25:50 +00:00
|
|
|
|
2021-01-24 16:03:05 +00:00
|
|
|
RVA o_offset = core->offset;
|
|
|
|
rz_core_seek_and_save(core, offset, true);
|
|
|
|
if (o_offset != core->offset) {
|
|
|
|
updateSeek();
|
|
|
|
}
|
2019-07-19 19:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::showMemoryWidget()
|
|
|
|
{
|
|
|
|
emit showMemoryWidgetRequested();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::seekAndShow(ut64 offset)
|
|
|
|
{
|
|
|
|
seek(offset);
|
|
|
|
showMemoryWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::seekAndShow(QString offset)
|
|
|
|
{
|
|
|
|
seek(offset);
|
|
|
|
showMemoryWidget();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 08:55:54 +00:00
|
|
|
void CutterCore::seek(QString thing)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-04-13 08:55:54 +00:00
|
|
|
cmdRaw(QString("s %1").arg(thing));
|
2020-05-02 16:10:02 +00:00
|
|
|
updateSeek();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 19:00:47 +00:00
|
|
|
void CutterCore::seekPrev()
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
2021-02-19 14:32:58 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
rz_core_seek_undo(core);
|
2021-01-24 16:03:05 +00:00
|
|
|
updateSeek();
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 19:00:47 +00:00
|
|
|
void CutterCore::seekNext()
|
|
|
|
{
|
2021-02-19 14:32:58 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
rz_core_seek_redo(core);
|
2021-01-24 16:03:05 +00:00
|
|
|
updateSeek();
|
2017-10-16 19:00:47 +00:00
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
|
2018-09-06 17:32:12 +00:00
|
|
|
void CutterCore::updateSeek()
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
emit seekChanged(getOffset());
|
2018-09-06 17:32:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:48:32 +00:00
|
|
|
RVA CutterCore::prevOpAddr(RVA startAddr, int count)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2017-12-17 09:58:25 +00:00
|
|
|
bool ok;
|
2020-03-21 13:25:50 +00:00
|
|
|
RVA offset = cmdRawAt(QString("/O %1").arg(count), startAddr).toULongLong(&ok, 16);
|
2017-12-17 09:58:25 +00:00
|
|
|
return ok ? offset : startAddr - count;
|
2017-11-02 06:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RVA CutterCore::nextOpAddr(RVA startAddr, int count)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
QJsonArray array =
|
|
|
|
Core()->cmdj("pdj " + QString::number(count + 1) + "@" + QString::number(startAddr))
|
|
|
|
.array();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (array.isEmpty()) {
|
2017-11-02 06:48:32 +00:00
|
|
|
return startAddr + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonValue instValue = array.last();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!instValue.isObject()) {
|
2017-11-02 06:48:32 +00:00
|
|
|
return startAddr + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok;
|
2018-11-20 07:45:42 +00:00
|
|
|
RVA offset = instValue.toObject()[RJsonKey::offset].toVariant().toULongLong(&ok);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!ok) {
|
2017-11-02 06:48:32 +00:00
|
|
|
return startAddr + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2017-10-16 19:00:47 +00:00
|
|
|
RVA CutterCore::getOffset()
|
|
|
|
{
|
|
|
|
return core_->offset;
|
|
|
|
}
|
2017-09-27 20:23:18 +00:00
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
ut64 CutterCore::math(const QString &expr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return rz_num_math(core ? core->num : NULL, expr.toUtf8().constData());
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
ut64 CutterCore::num(const QString &expr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return rz_num_get(core ? core->num : NULL, expr.toUtf8().constData());
|
2018-08-17 11:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::itoa(ut64 num, int rdx)
|
|
|
|
{
|
|
|
|
return QString::number(num, rdx);
|
|
|
|
}
|
|
|
|
|
2020-07-20 20:11:31 +00:00
|
|
|
void CutterCore::setConfig(const char *k, const char *v)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_config_set(core->config, k, v);
|
2020-07-20 20:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setConfig(const QString &k, const char *v)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_config_set(core->config, k.toUtf8().constData(), v);
|
2020-07-20 20:11:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
void CutterCore::setConfig(const char *k, const QString &v)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_config_set(core->config, k, v.toUtf8().constData());
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
void CutterCore::setConfig(const char *k, int v)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_config_set_i(core->config, k, static_cast<ut64>(v));
|
2017-10-01 14:36:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
void CutterCore::setConfig(const char *k, bool v)
|
2017-10-01 14:36:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_config_set_i(core->config, k, v ? 1 : 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
int CutterCore::getConfigi(const char *k)
|
2017-08-31 17:43:46 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return static_cast<int>(rz_config_get_i(core->config, k));
|
2017-10-01 14:36:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +00:00
|
|
|
ut64 CutterCore::getConfigut64(const char *k)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return rz_config_get_i(core->config, k);
|
2019-01-24 22:29:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
bool CutterCore::getConfigb(const char *k)
|
2017-10-01 14:36:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return rz_config_get_i(core->config, k) != 0;
|
2017-10-01 14:36:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 16:27:47 +00:00
|
|
|
QString CutterCore::getConfigDescription(const char *k)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
RzConfigNode *node = rz_config_node_get(core->config, k);
|
2020-06-06 16:02:24 +00:00
|
|
|
return node ? QString(node->desc) : QString("Unrecognized configuration key");
|
2020-03-08 16:27:47 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
void CutterCore::triggerRefreshAll()
|
|
|
|
{
|
|
|
|
emit refreshAll();
|
|
|
|
}
|
|
|
|
|
2017-10-01 14:36:40 +00:00
|
|
|
void CutterCore::triggerAsmOptionsChanged()
|
|
|
|
{
|
|
|
|
emit asmOptionsChanged();
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:13:44 +00:00
|
|
|
void CutterCore::triggerGraphOptionsChanged()
|
|
|
|
{
|
|
|
|
emit graphOptionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-08-27 11:16:48 +00:00
|
|
|
void CutterCore::message(const QString &msg, bool debug)
|
|
|
|
{
|
|
|
|
if (msg.isEmpty())
|
|
|
|
return;
|
|
|
|
if (debug) {
|
|
|
|
qDebug() << msg;
|
|
|
|
emit newDebugMessage(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emit newMessage(msg);
|
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
QString CutterCore::getConfig(const char *k)
|
2017-09-02 08:17:48 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return QString(rz_config_get(core->config, k));
|
2017-09-02 08:17:48 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
void CutterCore::setConfig(const char *k, const QVariant &v)
|
2018-03-22 08:42:54 +00:00
|
|
|
{
|
2018-07-18 10:15:10 +00:00
|
|
|
switch (v.type()) {
|
2018-03-22 08:42:54 +00:00
|
|
|
case QVariant::Type::Bool:
|
|
|
|
setConfig(k, v.toBool());
|
|
|
|
break;
|
|
|
|
case QVariant::Type::Int:
|
|
|
|
setConfig(k, v.toInt());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setConfig(k, v.toString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
void CutterCore::setCPU(QString arch, QString cpu, int bits)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-08-14 15:07:52 +00:00
|
|
|
if (arch != nullptr) {
|
|
|
|
setConfig("asm.arch", arch);
|
|
|
|
}
|
|
|
|
if (cpu != nullptr) {
|
|
|
|
setConfig("asm.cpu", cpu);
|
|
|
|
}
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("asm.bits", bits);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 10:35:31 +00:00
|
|
|
void CutterCore::setEndianness(bool big)
|
|
|
|
{
|
|
|
|
setConfig("cfg.bigendian", big);
|
|
|
|
}
|
|
|
|
|
2019-03-29 17:11:41 +00:00
|
|
|
QByteArray CutterCore::assemble(const QString &code)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzAsmCode *ac = rz_asm_massemble(core->rasm, code.toUtf8().constData());
|
2019-03-29 17:11:41 +00:00
|
|
|
QByteArray res;
|
|
|
|
if (ac && ac->bytes) {
|
|
|
|
res = QByteArray(reinterpret_cast<const char *>(ac->bytes), ac->len);
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_asm_code_free(ac);
|
2019-03-29 17:11:41 +00:00
|
|
|
return res;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 17:11:41 +00:00
|
|
|
QString CutterCore::disassemble(const QByteArray &data)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
RzAsmCode *ac = rz_asm_mdisassemble(core->rasm, reinterpret_cast<const ut8 *>(data.constData()),
|
|
|
|
data.length());
|
2019-03-29 17:11:41 +00:00
|
|
|
QString code;
|
|
|
|
if (ac && ac->assembly) {
|
|
|
|
code = QString::fromUtf8(ac->assembly);
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_asm_code_free(ac);
|
2017-03-29 10:18:37 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::disassembleSingleInstruction(RVA addr)
|
2017-06-07 15:48:36 +00:00
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
return cmdRawAt("pi 1", addr).simplified();
|
2017-06-07 15:48:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *CutterCore::functionIn(ut64 addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
RzList *fcns = rz_analysis_get_functions_in(core->analysis, addr);
|
|
|
|
RzAnalysisFunction *fcn = !rz_list_empty(fcns)
|
|
|
|
? reinterpret_cast<RzAnalysisFunction *>(rz_list_first(fcns))
|
|
|
|
: nullptr;
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_list_free(fcns);
|
2020-01-15 19:19:24 +00:00
|
|
|
return fcn;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *CutterCore::functionAt(ut64 addr)
|
2020-01-15 19:19:24 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
return rz_analysis_get_function_at(core->analysis, addr);
|
2020-01-15 19:19:24 +00:00
|
|
|
}
|
2019-05-30 08:41:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief finds the start address of a function in a given address
|
|
|
|
* @param addr - an address which belongs to a function
|
|
|
|
* @returns if function exists, return its start address. Otherwise return RVA_INVALID
|
|
|
|
*/
|
|
|
|
RVA CutterCore::getFunctionStart(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *fcn = Core()->functionIn(addr);
|
2019-05-30 08:41:14 +00:00
|
|
|
return fcn ? fcn->addr : RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief finds the end address of a function in a given address
|
|
|
|
* @param addr - an address which belongs to a function
|
|
|
|
* @returns if function exists, return its end address. Otherwise return RVA_INVALID
|
|
|
|
*/
|
|
|
|
RVA CutterCore::getFunctionEnd(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *fcn = Core()->functionIn(addr);
|
2019-05-30 08:41:14 +00:00
|
|
|
return fcn ? fcn->addr : RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief finds the last instruction of a function in a given address
|
|
|
|
* @param addr - an address which belongs to a function
|
2021-01-24 14:50:13 +00:00
|
|
|
* @returns if function exists, return the address of its last instruction. Otherwise return
|
|
|
|
* RVA_INVALID
|
2019-05-30 08:41:14 +00:00
|
|
|
*/
|
|
|
|
RVA CutterCore::getLastFunctionInstruction(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *fcn = Core()->functionIn(addr);
|
2019-05-30 08:41:14 +00:00
|
|
|
if (!fcn) {
|
|
|
|
return RVA_INVALID;
|
|
|
|
}
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisBlock *lastBB = (RzAnalysisBlock *)rz_list_last(fcn->bbs);
|
2021-01-24 14:50:13 +00:00
|
|
|
return lastBB ? rz_analysis_block_get_op_addr(lastBB, lastBB->ninstr - 1) : RVA_INVALID;
|
2019-05-30 08:41:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::cmdFunctionAt(QString addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QString ret;
|
2020-03-21 13:25:50 +00:00
|
|
|
// Use cmd because cmdRaw would not work with grep
|
|
|
|
ret = cmd(QString("fd @ %1~[0]").arg(addr));
|
2017-03-29 10:18:37 +00:00
|
|
|
return ret.trimmed();
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::cmdFunctionAt(RVA addr)
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
return cmdFunctionAt(QString::number(addr));
|
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
void CutterCore::cmdEsil(const char *command)
|
2018-07-27 12:00:23 +00:00
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
// use cmd and not cmdRaw because of unexpected commands
|
2018-07-27 12:00:23 +00:00
|
|
|
QString res = cmd(command);
|
2018-11-26 22:34:34 +00:00
|
|
|
if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) {
|
2021-01-24 14:50:13 +00:00
|
|
|
msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can disable "
|
|
|
|
"this in Preferences");
|
2018-07-27 12:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 13:58:58 +00:00
|
|
|
QString CutterCore::createFunctionAt(RVA addr)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
QString ret = cmdRaw(QString("af %1").arg(addr));
|
2019-09-25 13:58:58 +00:00
|
|
|
emit functionsChanged();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-12-10 20:40:15 +00:00
|
|
|
QString CutterCore::createFunctionAt(RVA addr, QString name)
|
|
|
|
{
|
2021-02-24 08:10:54 +00:00
|
|
|
static const QRegularExpression regExp("[^a-zA-Z0-9_.]");
|
2018-11-26 22:34:34 +00:00
|
|
|
name.remove(regExp);
|
2020-03-21 13:25:50 +00:00
|
|
|
QString ret = cmdRawAt(QString("af %1").arg(name), addr);
|
2017-12-11 13:07:12 +00:00
|
|
|
emit functionsChanged();
|
2017-12-10 20:40:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-18 09:13:08 +00:00
|
|
|
QJsonDocument CutterCore::getRegistersInfo()
|
|
|
|
{
|
|
|
|
return cmdj("aeafj");
|
|
|
|
}
|
|
|
|
|
2017-11-28 11:56:38 +00:00
|
|
|
RVA CutterCore::getOffsetJump(RVA addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-28 11:56:38 +00:00
|
|
|
bool ok;
|
2021-01-24 14:50:13 +00:00
|
|
|
RVA value = cmdj("aoj @" + QString::number(addr))
|
|
|
|
.array()
|
|
|
|
.first()
|
|
|
|
.toObject()
|
|
|
|
.value(RJsonKey::jump)
|
|
|
|
.toVariant()
|
|
|
|
.toULongLong(&ok);
|
2017-11-28 11:56:38 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!ok) {
|
2017-11-28 11:56:38 +00:00
|
|
|
return RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 12:08:44 +00:00
|
|
|
QList<Decompiler *> CutterCore::getDecompilers()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2019-07-15 12:08:44 +00:00
|
|
|
return decompilers;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 12:08:44 +00:00
|
|
|
Decompiler *CutterCore::getDecompilerById(const QString &id)
|
2018-09-08 07:12:08 +00:00
|
|
|
{
|
2019-07-15 12:08:44 +00:00
|
|
|
for (Decompiler *dec : decompilers) {
|
|
|
|
if (dec->getId() == id) {
|
|
|
|
return dec;
|
2019-07-12 08:57:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-15 12:08:44 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-07-12 08:57:07 +00:00
|
|
|
|
2019-07-15 12:08:44 +00:00
|
|
|
bool CutterCore::registerDecompiler(Decompiler *decompiler)
|
|
|
|
{
|
|
|
|
if (getDecompilerById(decompiler->getId())) {
|
|
|
|
return false;
|
2019-07-12 08:57:07 +00:00
|
|
|
}
|
2019-07-15 12:08:44 +00:00
|
|
|
decompiler->setParent(this);
|
|
|
|
decompilers.push_back(decompiler);
|
|
|
|
return true;
|
2018-09-08 07:12:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 22:31:15 +00:00
|
|
|
QJsonDocument CutterCore::getFileInfo()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-02-10 22:31:15 +00:00
|
|
|
return cmdj("ij");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 18:53:14 +00:00
|
|
|
QJsonDocument CutterCore::getFileVersionInfo()
|
|
|
|
{
|
|
|
|
return cmdj("iVj");
|
|
|
|
}
|
|
|
|
|
2018-05-05 12:58:26 +00:00
|
|
|
QJsonDocument CutterCore::getSignatureInfo()
|
|
|
|
{
|
|
|
|
return cmdj("iCj");
|
|
|
|
}
|
|
|
|
|
2020-01-30 17:40:27 +00:00
|
|
|
// Utility function to check if a telescoped item exists and add it with prefixes to the desc
|
|
|
|
static inline const QString appendVar(QString &dst, const QString val, const QString prepend_val,
|
2021-01-24 14:50:13 +00:00
|
|
|
const QString append_val)
|
2020-01-30 17:40:27 +00:00
|
|
|
{
|
|
|
|
if (!val.isEmpty()) {
|
|
|
|
dst += prepend_val + val + append_val;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefDescription CutterCore::formatRefDesc(QJsonObject refItem)
|
|
|
|
{
|
|
|
|
RefDescription desc;
|
|
|
|
|
|
|
|
// Ignore empty refs and refs that only contain addr
|
|
|
|
if (refItem.size() <= 1) {
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString str = refItem["string"].toVariant().toString();
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
desc.ref = str;
|
|
|
|
desc.refColor = ConfigColor("comment");
|
|
|
|
} else {
|
|
|
|
QString type, string;
|
|
|
|
do {
|
|
|
|
desc.ref += " ->";
|
|
|
|
appendVar(desc.ref, refItem["reg"].toVariant().toString(), " @", "");
|
|
|
|
appendVar(desc.ref, refItem["mapname"].toVariant().toString(), " (", ")");
|
|
|
|
appendVar(desc.ref, refItem["section"].toVariant().toString(), " (", ")");
|
|
|
|
appendVar(desc.ref, refItem["func"].toVariant().toString(), " ", "");
|
|
|
|
type = appendVar(desc.ref, refItem["type"].toVariant().toString(), " ", "");
|
|
|
|
appendVar(desc.ref, refItem["perms"].toVariant().toString(), " ", "");
|
|
|
|
appendVar(desc.ref, refItem["asm"].toVariant().toString(), " \"", "\"");
|
|
|
|
string = appendVar(desc.ref, refItem["string"].toVariant().toString(), " ", "");
|
|
|
|
if (!string.isNull()) {
|
|
|
|
// There is no point in adding ascii and addr info after a string
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!refItem["value"].isNull()) {
|
2021-09-14 13:32:04 +00:00
|
|
|
appendVar(desc.ref, RzAddressString(refItem["value"].toVariant().toULongLong()), " ",
|
2021-01-24 14:50:13 +00:00
|
|
|
"");
|
2020-01-30 17:40:27 +00:00
|
|
|
}
|
|
|
|
refItem = refItem["ref"].toObject();
|
|
|
|
} while (!refItem.empty());
|
|
|
|
|
|
|
|
// Set the ref's color according to the last item type
|
|
|
|
if (type == "ascii" || !string.isEmpty()) {
|
|
|
|
desc.refColor = ConfigColor("comment");
|
|
|
|
} else if (type == "program") {
|
|
|
|
desc.refColor = ConfigColor("fname");
|
|
|
|
} else if (type == "library") {
|
|
|
|
desc.refColor = ConfigColor("floc");
|
|
|
|
} else if (type == "stack") {
|
|
|
|
desc.refColor = ConfigColor("offset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QJsonObject> CutterCore::getRegisterRefs(int depth)
|
|
|
|
{
|
|
|
|
QList<QJsonObject> ret;
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject registers = cmdj("drj").object();
|
|
|
|
|
|
|
|
for (const QString &key : registers.keys()) {
|
|
|
|
QJsonObject reg;
|
|
|
|
reg["value"] = registers.value(key);
|
|
|
|
reg["ref"] = getAddrRefs(registers.value(key).toVariant().toULongLong(), depth);
|
|
|
|
reg["name"] = key;
|
|
|
|
ret.append(reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-10 20:46:49 +00:00
|
|
|
QList<QJsonObject> CutterCore::getStack(int size, int depth)
|
2018-06-06 11:05:20 +00:00
|
|
|
{
|
2020-01-10 20:46:49 +00:00
|
|
|
QList<QJsonObject> stack;
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORE_LOCK();
|
|
|
|
bool ret;
|
2020-03-21 13:25:50 +00:00
|
|
|
RVA addr = cmdRaw("dr SP").toULongLong(&ret, 16);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (!ret) {
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
int base = core->analysis->bits;
|
2020-01-10 20:46:49 +00:00
|
|
|
for (int i = 0; i < size; i += base / 8) {
|
|
|
|
if ((base == 32 && addr + i >= UT32_MAX) || (base == 16 && addr + i >= UT16_MAX)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.append(getAddrRefs(addr + i, depth));
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
QJsonObject CutterCore::getAddrRefs(RVA addr, int depth)
|
|
|
|
{
|
2020-01-10 20:46:49 +00:00
|
|
|
QJsonObject json;
|
|
|
|
if (depth < 1 || addr == UT64_MAX) {
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORE_LOCK();
|
2020-05-16 17:28:34 +00:00
|
|
|
int bits = core->rasm->bits;
|
2020-01-10 20:46:49 +00:00
|
|
|
QByteArray buf = QByteArray();
|
2020-12-07 07:57:11 +00:00
|
|
|
ut64 type = rz_core_analysis_address(core, addr);
|
2020-01-10 20:46:49 +00:00
|
|
|
|
|
|
|
json["addr"] = QString::number(addr);
|
|
|
|
|
|
|
|
// Search for the section the addr is in, avoid duplication for heap/stack with type
|
2021-01-24 14:50:13 +00:00
|
|
|
if (!(type & RZ_ANALYSIS_ADDR_TYPE_HEAP || type & RZ_ANALYSIS_ADDR_TYPE_STACK)) {
|
2020-01-10 20:46:49 +00:00
|
|
|
// Attempt to find the address within a map
|
2020-10-28 12:28:04 +00:00
|
|
|
RzDebugMap *map = rz_debug_map_get(core->dbg, addr);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (map && map->name && map->name[0]) {
|
|
|
|
json["mapname"] = map->name;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
RzBinSection *sect = rz_bin_get_section_at(rz_bin_cur_object(core->bin), addr, true);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (sect && sect->name[0]) {
|
|
|
|
json["section"] = sect->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the address points to a register
|
2020-10-28 12:28:04 +00:00
|
|
|
RzFlagItem *fi = rz_flag_get_i(core->flags, addr);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (fi) {
|
2020-10-28 12:28:04 +00:00
|
|
|
RzRegItem *r = rz_reg_get(core->dbg->reg, fi->name, -1);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (r) {
|
|
|
|
json["reg"] = r->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to find the address within a function
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, addr, 0);
|
2020-01-10 20:46:49 +00:00
|
|
|
if (fcn) {
|
|
|
|
json["fcn"] = fcn->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update type and permission information
|
|
|
|
if (type != 0) {
|
2020-12-07 18:20:47 +00:00
|
|
|
if (type & RZ_ANALYSIS_ADDR_TYPE_HEAP) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "heap";
|
2020-12-07 18:20:47 +00:00
|
|
|
} else if (type & RZ_ANALYSIS_ADDR_TYPE_STACK) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "stack";
|
2020-12-07 18:20:47 +00:00
|
|
|
} else if (type & RZ_ANALYSIS_ADDR_TYPE_PROGRAM) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "program";
|
2020-12-07 18:20:47 +00:00
|
|
|
} else if (type & RZ_ANALYSIS_ADDR_TYPE_LIBRARY) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "library";
|
2020-12-07 18:20:47 +00:00
|
|
|
} else if (type & RZ_ANALYSIS_ADDR_TYPE_ASCII) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "ascii";
|
2020-12-07 18:20:47 +00:00
|
|
|
} else if (type & RZ_ANALYSIS_ADDR_TYPE_SEQUENCE) {
|
2020-01-10 20:46:49 +00:00
|
|
|
json["type"] = "sequence";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString perms = "";
|
2020-12-07 18:20:47 +00:00
|
|
|
if (type & RZ_ANALYSIS_ADDR_TYPE_READ) {
|
2020-01-10 20:46:49 +00:00
|
|
|
perms += "r";
|
|
|
|
}
|
2020-12-07 18:20:47 +00:00
|
|
|
if (type & RZ_ANALYSIS_ADDR_TYPE_WRITE) {
|
2020-01-10 20:46:49 +00:00
|
|
|
perms += "w";
|
|
|
|
}
|
2020-12-07 18:20:47 +00:00
|
|
|
if (type & RZ_ANALYSIS_ADDR_TYPE_EXEC) {
|
2020-10-28 12:28:04 +00:00
|
|
|
RzAsmOp op;
|
2020-01-10 20:46:49 +00:00
|
|
|
buf.resize(32);
|
|
|
|
perms += "x";
|
|
|
|
// Instruction disassembly
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_io_read_at(core->io, addr, (unsigned char *)buf.data(), buf.size());
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_asm_set_pc(core->rasm, addr);
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_asm_disassemble(core->rasm, &op, (unsigned char *)buf.data(), buf.size());
|
2020-10-28 12:28:04 +00:00
|
|
|
json["asm"] = rz_asm_op_get_asm(&op);
|
2020-01-10 20:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!perms.isEmpty()) {
|
|
|
|
json["perms"] = perms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to telescope further if depth permits it
|
2021-03-20 21:12:06 +00:00
|
|
|
if ((type & RZ_ANALYSIS_ADDR_TYPE_READ)) {
|
2020-01-10 20:46:49 +00:00
|
|
|
buf.resize(64);
|
|
|
|
ut32 *n32 = (ut32 *)buf.data();
|
|
|
|
ut64 *n64 = (ut64 *)buf.data();
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_io_read_at(core->io, addr, (unsigned char *)buf.data(), buf.size());
|
|
|
|
ut64 n = (bits == 64) ? *n64 : *n32;
|
2020-01-10 20:46:49 +00:00
|
|
|
// The value of the next address will serve as an indication that there's more to
|
|
|
|
// telescope if we have reached the depth limit
|
|
|
|
json["value"] = QString::number(n);
|
2021-03-20 21:12:06 +00:00
|
|
|
if (depth && n != addr && !(type & RZ_ANALYSIS_ADDR_TYPE_EXEC)) {
|
2020-01-10 20:46:49 +00:00
|
|
|
// Make sure we aren't telescoping the same address
|
|
|
|
QJsonObject ref = getAddrRefs(n, depth - 1);
|
|
|
|
if (!ref.empty() && !ref["type"].isNull()) {
|
|
|
|
// If the dereference of the current pointer is an ascii character we
|
|
|
|
// might have a string in this address
|
|
|
|
if (ref["type"].toString().contains("ascii")) {
|
|
|
|
buf.resize(128);
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_io_read_at(core->io, addr, (unsigned char *)buf.data(), buf.size());
|
2020-01-10 20:46:49 +00:00
|
|
|
QString strVal = QString(buf);
|
|
|
|
// Indicate that the string is longer than the printed value
|
|
|
|
if (strVal.size() == buf.size()) {
|
|
|
|
strVal += "...";
|
|
|
|
}
|
|
|
|
json["string"] = strVal;
|
|
|
|
}
|
|
|
|
json["ref"] = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return json;
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 15:51:56 +00:00
|
|
|
QJsonDocument CutterCore::getProcessThreads(int pid)
|
|
|
|
{
|
|
|
|
if (-1 == pid) {
|
|
|
|
// Return threads list of the currently debugged PID
|
|
|
|
return cmdj("dptj");
|
|
|
|
} else {
|
|
|
|
return cmdj("dptj " + QString::number(pid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:21:06 +00:00
|
|
|
QVector<Chunk> CutterCore::getHeapChunks(RVA arena_addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QVector<Chunk> chunks_vector;
|
|
|
|
ut64 m_arena;
|
|
|
|
|
|
|
|
if (!arena_addr) {
|
|
|
|
// if arena_addr is zero get base address of main arena
|
|
|
|
RzList *arenas = rz_heap_arenas_list(core);
|
|
|
|
if (arenas->length == 0) {
|
|
|
|
rz_list_free(arenas);
|
|
|
|
return chunks_vector;
|
|
|
|
}
|
|
|
|
m_arena = ((RzArenaListItem *)arenas->head->data)->addr;
|
|
|
|
rz_list_free(arenas);
|
|
|
|
} else {
|
|
|
|
m_arena = arena_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get chunks using api and store them in a chunks_vector
|
|
|
|
RzList *chunks = rz_heap_chunks_list(core, m_arena);
|
|
|
|
RzListIter *iter;
|
|
|
|
RzHeapChunkListItem *data;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(chunks, iter, RzHeapChunkListItem, data)
|
2021-06-27 20:21:06 +00:00
|
|
|
{
|
|
|
|
Chunk chunk;
|
|
|
|
chunk.offset = data->addr;
|
|
|
|
chunk.size = (int)data->size;
|
|
|
|
chunk.status = QString(data->status);
|
|
|
|
chunks_vector.append(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
rz_list_free(chunks);
|
|
|
|
return chunks_vector;
|
|
|
|
}
|
|
|
|
|
2021-07-16 13:48:10 +00:00
|
|
|
int CutterCore::getArchBits()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
return core->dbg->bits;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:21:06 +00:00
|
|
|
QVector<Arena> CutterCore::getArenas()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QVector<Arena> arena_vector;
|
|
|
|
|
|
|
|
// get arenas using API and store them in arena_vector
|
|
|
|
RzList *arenas = rz_heap_arenas_list(core);
|
|
|
|
RzListIter *iter;
|
|
|
|
RzArenaListItem *data;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(arenas, iter, RzArenaListItem, data)
|
2021-06-27 20:21:06 +00:00
|
|
|
{
|
|
|
|
Arena arena;
|
|
|
|
arena.offset = data->addr;
|
|
|
|
arena.type = QString(data->type);
|
2021-07-16 13:48:10 +00:00
|
|
|
arena.last_remainder = data->arena->last_remainder;
|
|
|
|
arena.top = data->arena->top;
|
|
|
|
arena.next = data->arena->next;
|
|
|
|
arena.next_free = data->arena->next_free;
|
|
|
|
arena.system_mem = data->arena->system_mem;
|
|
|
|
arena.max_system_mem = data->arena->max_system_mem;
|
2021-06-27 20:21:06 +00:00
|
|
|
arena_vector.append(arena);
|
|
|
|
}
|
|
|
|
|
|
|
|
rz_list_free(arenas);
|
|
|
|
return arena_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
RzHeapChunkSimple *CutterCore::getHeapChunk(ut64 addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
return rz_heap_chunk(core, addr);
|
|
|
|
}
|
|
|
|
|
2021-07-02 10:19:27 +00:00
|
|
|
QVector<RzHeapBin *> CutterCore::getHeapBins(ut64 arena_addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QVector<RzHeapBin *> bins_vector;
|
|
|
|
|
|
|
|
MallocState *arena = rz_heap_get_arena(core, arena_addr);
|
|
|
|
if (!arena) {
|
|
|
|
return bins_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get small, large, unsorted bins
|
|
|
|
for (int i = 0; i <= NBINS - 2; i++) {
|
|
|
|
RzHeapBin *bin = rz_heap_bin_content(core, arena, i, arena_addr);
|
|
|
|
if (!bin) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!rz_list_length(bin->chunks)) {
|
|
|
|
rz_heap_bin_free_64(bin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bins_vector.append(bin);
|
|
|
|
}
|
|
|
|
// get fastbins
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
RzHeapBin *bin = rz_heap_fastbin_content(core, arena, i);
|
|
|
|
if (!bin) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!rz_list_length(bin->chunks)) {
|
|
|
|
rz_heap_bin_free_64(bin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bins_vector.append(bin);
|
|
|
|
}
|
2021-07-16 13:48:10 +00:00
|
|
|
// get tcache bins
|
|
|
|
RzList *tcache_bins = rz_heap_tcache_content(core, arena_addr);
|
|
|
|
RzListIter *iter;
|
|
|
|
RzHeapBin *bin;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(tcache_bins, iter, RzHeapBin, bin)
|
2021-07-16 13:48:10 +00:00
|
|
|
{
|
|
|
|
if (!bin) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!rz_list_length(bin->chunks)) {
|
|
|
|
rz_heap_bin_free_64(bin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bins_vector.append(bin);
|
|
|
|
}
|
2021-07-02 10:19:27 +00:00
|
|
|
return bins_vector;
|
|
|
|
}
|
|
|
|
|
2021-07-16 13:48:10 +00:00
|
|
|
bool CutterCore::writeHeapChunk(RzHeapChunkSimple *chunk_simple)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
return rz_heap_write_chunk(core, chunk_simple);
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:43:42 +00:00
|
|
|
QJsonDocument CutterCore::getChildProcesses(int pid)
|
|
|
|
{
|
|
|
|
// Return the currently debugged process and it's children
|
|
|
|
if (-1 == pid) {
|
|
|
|
return cmdj("dpj");
|
|
|
|
}
|
|
|
|
// Return the given pid and it's child processes
|
|
|
|
return cmdj("dpj " + QString::number(pid));
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
QJsonDocument CutterCore::getRegisterValues()
|
|
|
|
{
|
|
|
|
return cmdj("drj");
|
|
|
|
}
|
|
|
|
|
2018-12-19 08:39:23 +00:00
|
|
|
QList<VariableDescription> CutterCore::getVariables(RVA at)
|
|
|
|
{
|
|
|
|
QList<VariableDescription> ret;
|
|
|
|
QJsonObject varsObject = cmdj(QString("afvj @ %1").arg(at)).object();
|
|
|
|
|
|
|
|
auto addVars = [&](VariableDescription::RefType refType, const QJsonArray &array) {
|
|
|
|
for (const QJsonValue &varValue : array) {
|
|
|
|
QJsonObject varObject = varValue.toObject();
|
|
|
|
VariableDescription desc;
|
|
|
|
desc.refType = refType;
|
|
|
|
desc.name = varObject["name"].toString();
|
|
|
|
desc.type = varObject["type"].toString();
|
|
|
|
ret << desc;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
addVars(VariableDescription::RefType::SP, varsObject["sp"].toArray());
|
|
|
|
addVars(VariableDescription::RefType::BP, varsObject["bp"].toArray());
|
|
|
|
addVars(VariableDescription::RefType::Reg, varsObject["reg"].toArray());
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-17 13:01:05 +00:00
|
|
|
QVector<RegisterRefValueDescription> CutterCore::getRegisterRefValues()
|
2018-07-25 22:17:58 +00:00
|
|
|
{
|
|
|
|
QJsonArray registerRefArray = cmdj("drrj").array();
|
2020-04-17 13:01:05 +00:00
|
|
|
QVector<RegisterRefValueDescription> result;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2020-04-17 13:01:05 +00:00
|
|
|
for (const QJsonValue value : registerRefArray) {
|
2018-07-25 22:17:58 +00:00
|
|
|
QJsonObject regRefObject = value.toObject();
|
|
|
|
|
2020-04-17 13:01:05 +00:00
|
|
|
RegisterRefValueDescription desc;
|
|
|
|
desc.name = regRefObject[RJsonKey::reg].toString();
|
|
|
|
desc.value = regRefObject[RJsonKey::value].toString();
|
|
|
|
desc.ref = regRefObject[RJsonKey::ref].toString();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2020-04-17 13:01:05 +00:00
|
|
|
result.push_back(desc);
|
2018-07-25 22:17:58 +00:00
|
|
|
}
|
2020-04-17 13:01:05 +00:00
|
|
|
return result;
|
2018-07-25 22:17:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
QString CutterCore::getRegisterName(QString registerRole)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
return cmdRaw("drn " + registerRole).trimmed();
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:57:15 +00:00
|
|
|
RVA CutterCore::getProgramCounterValue()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
if (currentlyDebugging) {
|
2020-03-21 13:25:50 +00:00
|
|
|
// Use cmd because cmdRaw would not work with inner command backticked
|
|
|
|
// TODO: Risky command due to changes in API, search for something safer
|
2020-12-19 21:32:51 +00:00
|
|
|
RVA addr = cmd("dr `drn PC`").toULongLong(&ok, 16);
|
2018-06-22 15:57:15 +00:00
|
|
|
if (ok) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
void CutterCore::setRegister(QString regName, QString regValue)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw(QString("dr %1=%2").arg(regName).arg(regValue));
|
2018-06-12 08:43:14 +00:00
|
|
|
emit registersChanged();
|
2018-07-23 23:13:09 +00:00
|
|
|
emit refreshCodeViews();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 15:51:56 +00:00
|
|
|
void CutterCore::setCurrentDebugThread(int tid)
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!asyncCmd("dpt=" + QString::number(tid), debugTask)) {
|
|
|
|
return;
|
2019-12-09 18:43:42 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
emit registersChanged();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
emit stackChanged();
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
emit switchedThread();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2019-12-09 18:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setCurrentDebugProcess(int pid)
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging || !asyncCmd("dp=" + QString::number(pid), debugTask)) {
|
2019-12-09 18:43:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
emit registersChanged();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
emit stackChanged();
|
|
|
|
emit flagsChanged();
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
emit switchedProcess();
|
2019-12-09 18:43:42 +00:00
|
|
|
emit debugTaskStateChanged();
|
2019-12-11 11:26:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2019-10-22 15:51:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
void CutterCore::startDebug()
|
|
|
|
{
|
2018-06-15 17:33:17 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
2018-10-28 13:13:45 +00:00
|
|
|
currentlyOpenFile = getConfig("file.path");
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
if (!asyncCmd("ood", debugTask)) {
|
|
|
|
return;
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
2019-10-31 09:50:08 +00:00
|
|
|
emit debugTaskStateChanged();
|
2019-12-11 11:26:54 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
|
|
|
|
emit registersChanged();
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
setConfig("asm.flags", false);
|
|
|
|
currentlyDebugging = true;
|
2019-12-13 17:30:55 +00:00
|
|
|
emit toggleDebugView();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit refreshCodeViews();
|
|
|
|
}
|
2019-12-11 22:18:40 +00:00
|
|
|
|
|
|
|
emit codeRebased();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit stackChanged();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
2020-12-16 09:51:53 +00:00
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
debugTaskDialog->setDesc(tr("Starting native debug..."));
|
|
|
|
debugTaskDialog->show();
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::startEmulation()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
// clear registers, init esil state, stack, progcounter at current seek
|
2019-12-11 11:26:54 +00:00
|
|
|
asyncCmd("aei; aeim; aeip", debugTask);
|
|
|
|
|
2019-10-31 09:50:08 +00:00
|
|
|
emit debugTaskStateChanged();
|
2019-12-11 11:26:54 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
|
|
|
|
if (!currentlyDebugging || !currentlyEmulating) {
|
|
|
|
// prevent register flags from appearing during debug/emul
|
|
|
|
setConfig("asm.flags", false);
|
|
|
|
// allows to view self-modifying code changes or other binary changes
|
|
|
|
setConfig("io.cache", true);
|
|
|
|
currentlyDebugging = true;
|
|
|
|
currentlyEmulating = true;
|
2019-12-13 17:30:55 +00:00
|
|
|
emit toggleDebugView();
|
2019-12-11 11:26:54 +00:00
|
|
|
}
|
2019-12-11 22:18:40 +00:00
|
|
|
|
2019-12-11 11:26:54 +00:00
|
|
|
emit registersChanged();
|
|
|
|
emit stackChanged();
|
2019-12-11 22:18:40 +00:00
|
|
|
emit codeRebased();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit refreshCodeViews();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
2020-12-16 09:51:53 +00:00
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
debugTaskDialog->setDesc(tr("Starting emulation..."));
|
|
|
|
debugTaskDialog->show();
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 08:50:07 +00:00
|
|
|
void CutterCore::attachRemote(const QString &uri)
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// connect to a debugger with the given plugin
|
2021-03-31 16:01:39 +00:00
|
|
|
asyncCmd("e cfg.debug=true; oodf " + uri, debugTask);
|
2019-11-20 08:50:07 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this, uri]() {
|
2019-11-20 08:50:07 +00:00
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
// Check if we actually connected
|
|
|
|
bool connected = false;
|
2021-09-14 21:40:01 +00:00
|
|
|
RzCoreLocked core(Core());
|
|
|
|
RzList *descs = rz_id_storage_list(core->io->files);
|
|
|
|
RzListIter *it;
|
|
|
|
RzIODesc *desc;
|
|
|
|
CutterRzListForeach(descs, it, RzIODesc, desc) {
|
|
|
|
QString fileUri = QString(desc->uri);
|
2019-11-20 08:50:07 +00:00
|
|
|
if (!fileUri.compare(uri)) {
|
|
|
|
connected = true;
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 21:32:51 +00:00
|
|
|
seekAndShow(getProgramCounterValue());
|
2019-11-20 08:50:07 +00:00
|
|
|
if (!connected) {
|
|
|
|
emit attachedRemote(false);
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit registersChanged();
|
|
|
|
if (!currentlyDebugging || !currentlyEmulating) {
|
|
|
|
// prevent register flags from appearing during debug/emul
|
|
|
|
setConfig("asm.flags", false);
|
|
|
|
currentlyDebugging = true;
|
2019-12-13 17:30:55 +00:00
|
|
|
emit toggleDebugView();
|
2019-11-20 08:50:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 20:21:06 +00:00
|
|
|
currentlyRemoteDebugging = true;
|
2019-12-11 22:18:40 +00:00
|
|
|
emit codeRebased();
|
2019-11-20 08:50:07 +00:00
|
|
|
emit attachedRemote(true);
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
2020-12-16 09:51:53 +00:00
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
2019-11-20 08:50:07 +00:00
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTaskDialog->setDesc(tr("Connecting to: ") + uri);
|
2019-11-20 08:50:07 +00:00
|
|
|
debugTaskDialog->show();
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
debugTask->startTask();
|
2019-11-20 08:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
void CutterCore::attachDebug(int pid)
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
2019-10-31 09:50:08 +00:00
|
|
|
|
2021-08-12 21:28:10 +00:00
|
|
|
QString attach_command = currentlyOpenFile.isEmpty() ? "o" : "oodf";
|
2018-07-01 21:29:38 +00:00
|
|
|
// attach to process with dbg plugin
|
2021-08-12 21:28:10 +00:00
|
|
|
asyncCmd("e cfg.debug=true;" + attach_command + " dbg://" + QString::number(pid), debugTask);
|
|
|
|
|
2019-10-31 09:50:08 +00:00
|
|
|
emit debugTaskStateChanged();
|
2019-12-11 11:26:54 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this, pid]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
if (!currentlyDebugging || !currentlyEmulating) {
|
|
|
|
// prevent register flags from appearing during debug/emul
|
|
|
|
setConfig("asm.flags", false);
|
|
|
|
currentlyDebugging = true;
|
|
|
|
currentlyOpenFile = getConfig("file.path");
|
|
|
|
currentlyAttachedToPID = pid;
|
2019-12-13 17:30:55 +00:00
|
|
|
emit toggleDebugView();
|
2019-12-11 11:26:54 +00:00
|
|
|
}
|
2019-12-11 22:18:40 +00:00
|
|
|
|
|
|
|
emit codeRebased();
|
|
|
|
emit debugTaskStateChanged();
|
2019-12-11 11:26:54 +00:00
|
|
|
});
|
|
|
|
|
2020-12-16 09:51:53 +00:00
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
debugTaskDialog->setDesc(tr("Attaching to process (") + QString::number(pid) + ")...");
|
|
|
|
debugTaskDialog->show();
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::suspendDebug()
|
|
|
|
{
|
2020-01-04 18:05:49 +00:00
|
|
|
debugTask->breakTask();
|
2018-06-12 15:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stopDebug()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!debugTask.isNull()) {
|
|
|
|
suspendDebug();
|
|
|
|
}
|
|
|
|
|
|
|
|
currentlyDebugging = false;
|
2021-02-13 17:35:57 +00:00
|
|
|
currentlyTracing = false;
|
2021-06-27 20:21:06 +00:00
|
|
|
currentlyRemoteDebugging = false;
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
2021-02-13 17:35:57 +00:00
|
|
|
cmdEsil("aeim-; aei-; wcr; .ar-; aets-");
|
2019-12-11 11:26:54 +00:00
|
|
|
currentlyEmulating = false;
|
|
|
|
} else if (currentlyAttachedToPID != -1) {
|
2020-03-21 13:25:50 +00:00
|
|
|
// Use cmd because cmdRaw would not work with command concatenation
|
2021-01-24 14:50:13 +00:00
|
|
|
cmd(QString("dp- %1; o %2; .ar-")
|
|
|
|
.arg(QString::number(currentlyAttachedToPID), currentlyOpenFile));
|
2019-12-11 11:26:54 +00:00
|
|
|
currentlyAttachedToPID = -1;
|
|
|
|
} else {
|
|
|
|
QString ptraceFiles = "";
|
|
|
|
// close ptrace file descriptors left open
|
2021-09-14 21:40:01 +00:00
|
|
|
RzCoreLocked core(Core());
|
|
|
|
RzList *descs = rz_id_storage_list(core->io->files);
|
|
|
|
RzListIter *it;
|
|
|
|
RzIODesc *desc;
|
|
|
|
CutterRzListForeach(descs, it, RzIODesc, desc) {
|
|
|
|
QString URI = QString(desc->uri);
|
2019-12-11 11:26:54 +00:00
|
|
|
if (URI.contains("ptrace")) {
|
2021-09-14 21:40:01 +00:00
|
|
|
ptraceFiles += "o-" + QString::number(desc->fd) + ";";
|
2018-10-28 13:13:45 +00:00
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2020-03-21 13:25:50 +00:00
|
|
|
// Use cmd because cmdRaw would not work with command concatenation
|
2019-12-13 18:32:49 +00:00
|
|
|
cmd("doc" + ptraceFiles);
|
2018-06-22 15:57:15 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
setConfig("asm.flags", true);
|
|
|
|
setConfig("io.cache", false);
|
2019-12-11 22:18:40 +00:00
|
|
|
emit codeRebased();
|
2019-12-13 17:30:55 +00:00
|
|
|
emit toggleDebugView();
|
2019-12-11 11:26:54 +00:00
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
emit debugTaskStateChanged();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 13:13:45 +00:00
|
|
|
void CutterCore::syncAndSeekProgramCounter()
|
|
|
|
{
|
2020-12-19 21:32:51 +00:00
|
|
|
seekAndShow(getProgramCounterValue());
|
2018-10-28 13:13:45 +00:00
|
|
|
emit registersChanged();
|
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
void CutterCore::continueDebug()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aec", debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dc", debugTask)) {
|
|
|
|
return;
|
2018-08-06 11:48:26 +00:00
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueBackDebug()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aecb", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dcb", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit refreshCodeViews();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueUntilDebug(QString offset)
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-31 09:50:08 +00:00
|
|
|
|
2019-12-11 11:26:54 +00:00
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aecu " + offset, debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dcu " + offset, debugTask)) {
|
|
|
|
return;
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 23:02:16 +00:00
|
|
|
void CutterCore::continueUntilCall()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aecc", debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dcc", debugTask)) {
|
|
|
|
return;
|
2018-07-30 06:55:58 +00:00
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-13 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueUntilSyscall()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aecs", debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dcs", debugTask)) {
|
|
|
|
return;
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-13 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
void CutterCore::stepDebug()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aes", debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("ds", debugTask)) {
|
|
|
|
return;
|
2018-10-28 13:13:45 +00:00
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stepOverDebug()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aeso", debugTask)) {
|
|
|
|
return;
|
2019-10-31 09:50:08 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dso", debugTask)) {
|
|
|
|
return;
|
2018-10-28 13:13:45 +00:00
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 06:55:39 +00:00
|
|
|
void CutterCore::stepOutDebug()
|
|
|
|
{
|
2019-12-11 11:26:54 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
2018-07-30 06:55:39 +00:00
|
|
|
}
|
2019-12-11 11:26:54 +00:00
|
|
|
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
if (!asyncCmd("dsf", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
2019-12-11 11:26:54 +00:00
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
2021-02-13 17:35:57 +00:00
|
|
|
emit refreshCodeViews();
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stepBackDebug()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aesb", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dsb", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
|
|
|
debugTask.clear();
|
|
|
|
syncAndSeekProgramCounter();
|
|
|
|
emit refreshCodeViews();
|
2019-12-11 11:26:54 +00:00
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTask->startTask();
|
2018-07-30 06:55:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 11:49:22 +00:00
|
|
|
QStringList CutterCore::getDebugPlugins()
|
|
|
|
{
|
|
|
|
QStringList plugins;
|
|
|
|
QJsonArray pluginArray = cmdj("dLj").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : pluginArray) {
|
2018-06-14 11:49:22 +00:00
|
|
|
QJsonObject pluginObject = value.toObject();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QString plugin = pluginObject[RJsonKey::name].toString();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-06-14 11:49:22 +00:00
|
|
|
plugins << plugin;
|
|
|
|
}
|
|
|
|
return plugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::getActiveDebugPlugin()
|
|
|
|
{
|
|
|
|
return getConfig("dbg.backend");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setDebugPlugin(QString plugin)
|
|
|
|
{
|
|
|
|
setConfig("dbg.backend", plugin);
|
|
|
|
}
|
|
|
|
|
2021-02-13 17:35:57 +00:00
|
|
|
void CutterCore::startTraceSession()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging || currentlyTracing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aets+", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dts+", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
|
|
|
|
currentlyTracing = true;
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
debugTaskDialog->setDesc(tr("Creating debug tracepoint..."));
|
|
|
|
debugTaskDialog->show();
|
|
|
|
|
|
|
|
debugTask->startTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stopTraceSession()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging || !currentlyTracing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentlyEmulating) {
|
|
|
|
if (!asyncCmdEsil("aets-", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!asyncCmd("dts-", debugTask)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
|
|
|
|
connect(debugTask.data(), &RizinTask::finished, this, [this]() {
|
|
|
|
if (debugTaskDialog) {
|
|
|
|
delete debugTaskDialog;
|
|
|
|
}
|
|
|
|
debugTask.clear();
|
|
|
|
|
|
|
|
currentlyTracing = false;
|
|
|
|
emit debugTaskStateChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
debugTaskDialog = new RizinTaskDialog(debugTask);
|
|
|
|
debugTaskDialog->setBreakOnClose(true);
|
|
|
|
debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
debugTaskDialog->setDesc(tr("Stopping debug session..."));
|
|
|
|
debugTaskDialog->show();
|
|
|
|
|
|
|
|
debugTask->startTask();
|
|
|
|
}
|
|
|
|
|
2018-07-17 07:26:20 +00:00
|
|
|
void CutterCore::toggleBreakpoint(RVA addr)
|
2018-06-12 08:43:14 +00:00
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw(QString("dbs %1").arg(addr));
|
2020-08-02 09:51:56 +00:00
|
|
|
emit breakpointsChanged(addr);
|
2018-06-26 07:38:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 18:05:49 +00:00
|
|
|
void CutterCore::addBreakpoint(const BreakpointDescription &config)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzBreakpointItem *breakpoint = nullptr;
|
2020-01-04 18:05:49 +00:00
|
|
|
int watchpoint_prot = 0;
|
|
|
|
if (config.hw) {
|
2020-10-28 12:28:04 +00:00
|
|
|
watchpoint_prot = config.permission & ~(RZ_BP_PROT_EXEC);
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto address = config.addr;
|
|
|
|
char *module = nullptr;
|
|
|
|
QByteArray moduleNameData;
|
|
|
|
if (config.type == BreakpointDescription::Named) {
|
|
|
|
address = Core()->math(config.positionExpression);
|
|
|
|
} else if (config.type == BreakpointDescription::Module) {
|
|
|
|
address = 0;
|
|
|
|
moduleNameData = config.positionExpression.toUtf8();
|
|
|
|
module = moduleNameData.data();
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
breakpoint = rz_debug_bp_add(core->dbg, address, (config.hw && watchpoint_prot == 0),
|
2021-01-24 14:50:13 +00:00
|
|
|
watchpoint_prot, watchpoint_prot, module, config.moduleDelta);
|
2020-01-22 23:07:41 +00:00
|
|
|
if (!breakpoint) {
|
|
|
|
QMessageBox::critical(nullptr, tr("Breakpoint error"), tr("Failed to create breakpoint"));
|
|
|
|
return;
|
|
|
|
}
|
2020-01-04 18:05:49 +00:00
|
|
|
if (config.type == BreakpointDescription::Named) {
|
|
|
|
updateOwnedCharPtr(breakpoint->expr, config.positionExpression);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.hw) {
|
|
|
|
breakpoint->size = config.size;
|
|
|
|
}
|
|
|
|
if (config.type == BreakpointDescription::Named) {
|
|
|
|
updateOwnedCharPtr(breakpoint->name, config.positionExpression);
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = std::find(core->dbg->bp->bps_idx,
|
2021-01-24 14:50:13 +00:00
|
|
|
core->dbg->bp->bps_idx + core->dbg->bp->bps_idx_count, breakpoint)
|
|
|
|
- core->dbg->bp->bps_idx;
|
2020-01-04 18:05:49 +00:00
|
|
|
|
|
|
|
breakpoint->enabled = config.enabled;
|
|
|
|
if (config.trace) {
|
|
|
|
setBreakpointTrace(index, config.trace);
|
|
|
|
}
|
|
|
|
if (!config.condition.isEmpty()) {
|
|
|
|
updateOwnedCharPtr(breakpoint->cond, config.condition);
|
|
|
|
}
|
|
|
|
if (!config.command.isEmpty()) {
|
|
|
|
updateOwnedCharPtr(breakpoint->data, config.command);
|
|
|
|
}
|
2020-08-02 09:51:56 +00:00
|
|
|
emit breakpointsChanged(breakpoint->addr);
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::updateBreakpoint(int index, const BreakpointDescription &config)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
if (auto bp = rz_bp_get_index(core->dbg->bp, index)) {
|
|
|
|
rz_bp_del(core->dbg->bp, bp->addr);
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
|
|
|
// Delete by index currently buggy,
|
|
|
|
// required for breakpoints with non address based position
|
2021-01-24 14:50:13 +00:00
|
|
|
// rz_bp_del_index(core->dbg->bp, index);
|
2020-01-04 18:05:49 +00:00
|
|
|
addBreakpoint(config);
|
|
|
|
}
|
|
|
|
|
2018-06-22 08:45:00 +00:00
|
|
|
void CutterCore::delBreakpoint(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
cmdRaw("db- " + RzAddressString(addr));
|
2020-08-02 09:51:56 +00:00
|
|
|
emit breakpointsChanged(addr);
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::delAllBreakpoints()
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("db-*");
|
2018-07-01 21:29:38 +00:00
|
|
|
emit refreshCodeViews();
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::enableBreakpoint(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
cmdRaw("dbe " + RzAddressString(addr));
|
2020-08-02 09:51:56 +00:00
|
|
|
emit breakpointsChanged(addr);
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::disableBreakpoint(RVA addr)
|
|
|
|
{
|
2021-09-14 13:32:04 +00:00
|
|
|
cmdRaw("dbd " + RzAddressString(addr));
|
2020-08-02 09:51:56 +00:00
|
|
|
emit breakpointsChanged(addr);
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 20:51:55 +00:00
|
|
|
void CutterCore::setBreakpointTrace(int index, bool enabled)
|
|
|
|
{
|
|
|
|
if (enabled) {
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw(QString("dbite %1").arg(index));
|
2019-12-26 20:51:55 +00:00
|
|
|
} else {
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw(QString("dbitd %1").arg(index));
|
2019-12-26 20:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 10:59:23 +00:00
|
|
|
static BreakpointDescription breakpointDescriptionFromRizin(int index, rz_bp_item_t *bpi)
|
2018-06-22 08:45:00 +00:00
|
|
|
{
|
2020-01-04 18:05:49 +00:00
|
|
|
BreakpointDescription bp;
|
|
|
|
bp.addr = bpi->addr;
|
|
|
|
bp.index = index;
|
|
|
|
bp.size = bpi->size;
|
|
|
|
if (bpi->expr) {
|
|
|
|
bp.positionExpression = bpi->expr;
|
|
|
|
bp.type = BreakpointDescription::Named;
|
|
|
|
}
|
|
|
|
bp.name = bpi->name;
|
|
|
|
bp.permission = bpi->perm;
|
|
|
|
bp.command = bpi->data;
|
|
|
|
bp.condition = bpi->cond;
|
|
|
|
bp.hw = bpi->hw;
|
|
|
|
bp.trace = bpi->trace;
|
|
|
|
bp.enabled = bpi->enabled;
|
|
|
|
return bp;
|
|
|
|
}
|
2018-06-22 08:45:00 +00:00
|
|
|
|
2020-01-04 18:05:49 +00:00
|
|
|
int CutterCore::breakpointIndexAt(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
return rz_bp_get_index_at(core->dbg->bp, addr);
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
2018-06-22 08:45:00 +00:00
|
|
|
|
2020-01-04 18:05:49 +00:00
|
|
|
BreakpointDescription CutterCore::getBreakpointAt(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
int index = breakpointIndexAt(addr);
|
2020-10-28 12:28:04 +00:00
|
|
|
auto bp = rz_bp_get_index(core->dbg->bp, index);
|
2020-01-04 18:05:49 +00:00
|
|
|
if (bp) {
|
2020-12-16 10:59:23 +00:00
|
|
|
return breakpointDescriptionFromRizin(index, bp);
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
|
|
|
return BreakpointDescription();
|
|
|
|
}
|
2018-06-22 08:45:00 +00:00
|
|
|
|
2020-01-04 18:05:49 +00:00
|
|
|
QList<BreakpointDescription> CutterCore::getBreakpoints()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<BreakpointDescription> ret;
|
2021-01-24 14:50:13 +00:00
|
|
|
// TODO: use higher level API, don't touch rizin bps_idx directly
|
2020-01-04 18:05:49 +00:00
|
|
|
for (int i = 0; i < core->dbg->bp->bps_idx_count; i++) {
|
|
|
|
if (auto bpi = core->dbg->bp->bps_idx[i]) {
|
2020-12-16 10:59:23 +00:00
|
|
|
ret.push_back(breakpointDescriptionFromRizin(i, bpi));
|
2020-01-04 18:05:49 +00:00
|
|
|
}
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 16:20:16 +00:00
|
|
|
QList<RVA> CutterCore::getBreakpointsAddresses()
|
|
|
|
{
|
|
|
|
QList<RVA> bpAddresses;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const BreakpointDescription &bp : getBreakpoints()) {
|
2018-08-12 16:20:16 +00:00
|
|
|
bpAddresses << bp.addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bpAddresses;
|
|
|
|
}
|
|
|
|
|
2019-12-19 17:58:30 +00:00
|
|
|
QList<RVA> CutterCore::getBreakpointsInFunction(RVA funcAddr)
|
|
|
|
{
|
|
|
|
QList<RVA> allBreakpoints = getBreakpointsAddresses();
|
|
|
|
QList<RVA> functionBreakpoints;
|
|
|
|
|
|
|
|
// Use std manipulations to take only the breakpoints that belong to this function
|
2021-01-24 14:50:13 +00:00
|
|
|
std::copy_if(allBreakpoints.begin(), allBreakpoints.end(),
|
|
|
|
std::back_inserter(functionBreakpoints),
|
|
|
|
[this, funcAddr](RVA BPadd) { return getFunctionStart(BPadd) == funcAddr; });
|
2019-12-19 17:58:30 +00:00
|
|
|
return functionBreakpoints;
|
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
bool CutterCore::isBreakpoint(const QList<RVA> &breakpoints, RVA addr)
|
2018-08-12 16:20:16 +00:00
|
|
|
{
|
|
|
|
return breakpoints.contains(addr);
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
QJsonDocument CutterCore::getBacktrace()
|
|
|
|
{
|
|
|
|
return cmdj("dbtj");
|
|
|
|
}
|
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
QList<ProcessDescription> CutterCore::getAllProcesses()
|
|
|
|
{
|
|
|
|
QList<ProcessDescription> ret;
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonArray processArray = cmdj("dplj").array();
|
2018-07-01 21:29:38 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : processArray) {
|
2018-07-01 21:29:38 +00:00
|
|
|
QJsonObject procObject = value.toObject();
|
|
|
|
|
|
|
|
ProcessDescription proc;
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
proc.pid = procObject[RJsonKey::pid].toInt();
|
|
|
|
proc.uid = procObject[RJsonKey::uid].toInt();
|
2018-11-20 07:45:42 +00:00
|
|
|
proc.status = procObject[RJsonKey::status].toString();
|
|
|
|
proc.path = procObject[RJsonKey::path].toString();
|
2018-07-01 21:29:38 +00:00
|
|
|
|
|
|
|
ret << proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
QList<MemoryMapDescription> CutterCore::getMemoryMap()
|
|
|
|
{
|
|
|
|
QList<MemoryMapDescription> ret;
|
|
|
|
QJsonArray memoryMapArray = cmdj("dmj").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : memoryMapArray) {
|
2018-06-12 08:43:14 +00:00
|
|
|
QJsonObject memMapObject = value.toObject();
|
|
|
|
|
|
|
|
MemoryMapDescription memMap;
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
memMap.name = memMapObject[RJsonKey::name].toString();
|
|
|
|
memMap.fileName = memMapObject[RJsonKey::file].toString();
|
|
|
|
memMap.addrStart = memMapObject[RJsonKey::addr].toVariant().toULongLong();
|
|
|
|
memMap.addrEnd = memMapObject[RJsonKey::addr_end].toVariant().toULongLong();
|
|
|
|
memMap.type = memMapObject[RJsonKey::type].toString();
|
|
|
|
memMap.permission = memMapObject[RJsonKey::perm].toString();
|
2018-06-12 08:43:14 +00:00
|
|
|
|
|
|
|
ret << memMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QStringList CutterCore::getStats()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QStringList stats;
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs functions");
|
|
|
|
|
|
|
|
// The cmd coomand is frequently used in this function because
|
|
|
|
// cmdRaw would not work with grep
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
|
|
|
|
QString imps = cmd("ii~?").trimmed();
|
|
|
|
stats << imps;
|
|
|
|
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs symbols");
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs strings");
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs relocs");
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs sections");
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs *");
|
2017-03-29 10:18:37 +00:00
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
|
2018-09-30 17:46:36 +00:00
|
|
|
void CutterCore::setGraphEmpty(bool empty)
|
|
|
|
{
|
|
|
|
emptyGraph = empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterCore::isGraphEmpty()
|
|
|
|
{
|
|
|
|
return emptyGraph;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
void CutterCore::getOpcodes()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2019-03-23 10:54:34 +00:00
|
|
|
this->opcodes = cmdList("?O");
|
|
|
|
this->regs = cmdList("drp~[1]");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-03-30 16:47:50 +00:00
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
void CutterCore::setSettings()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("scr.interactive", false);
|
2018-02-02 10:56:07 +00:00
|
|
|
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("hex.pairs", false);
|
|
|
|
setConfig("asm.xrefs", false);
|
|
|
|
|
2018-05-24 06:21:12 +00:00
|
|
|
setConfig("asm.tabs.once", true);
|
|
|
|
setConfig("asm.flags.middle", 2);
|
2017-11-28 13:24:35 +00:00
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
setConfig("analysis.hasnext", false);
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("asm.lines.call", false);
|
2017-08-31 17:43:46 +00:00
|
|
|
|
2017-10-22 10:21:44 +00:00
|
|
|
// Colors
|
2018-02-26 22:25:23 +00:00
|
|
|
setConfig("scr.color", COLOR_MODE_DISABLED);
|
2018-03-08 13:02:34 +00:00
|
|
|
|
|
|
|
// Don't show hits
|
|
|
|
setConfig("search.flags", false);
|
2017-03-30 16:47:50 +00:00
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<RVA> CutterCore::getSeekHistory()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<RVA> ret;
|
2021-09-14 08:13:19 +00:00
|
|
|
RzListIter *it;
|
|
|
|
RzCoreSeekItem *undo;
|
|
|
|
RzList *list = rz_core_seek_list(core);
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(list, it, RzCoreSeekItem, undo) { ret << undo->offset; }
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QStringList CutterCore::getAsmPluginNames()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzListIter *it;
|
2017-05-03 09:09:57 +00:00
|
|
|
QStringList ret;
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzAsmPlugin *ap;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->rasm->plugins, it, RzAsmPlugin, ap) { ret << ap->name; }
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
QStringList CutterCore::getAnalysisPluginNames()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzListIter *it;
|
2017-05-03 09:09:57 +00:00
|
|
|
QStringList ret;
|
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisPlugin *ap;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->analysis->plugins, it, RzAnalysisPlugin, ap) { ret << ap->name; }
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzBinPluginDescription> CutterCore::getRBinPluginDescriptions(const QString &type)
|
2017-09-29 11:32:53 +00:00
|
|
|
{
|
2021-09-19 08:58:08 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzBinPluginDescription> ret;
|
2021-09-19 08:58:08 +00:00
|
|
|
RzListIter *it;
|
|
|
|
RzBinPlugin *bp;
|
|
|
|
CutterRzListForeach(core->bin->plugins, it, RzBinPlugin, bp) {
|
|
|
|
RzBinPluginDescription desc;
|
|
|
|
desc.name = bp->name ? bp->name : "";
|
|
|
|
desc.description = bp->desc ? bp->desc : "";
|
|
|
|
desc.license = bp->license ? bp->license : "";
|
|
|
|
desc.type = "bin";
|
|
|
|
ret.append(desc);
|
|
|
|
}
|
|
|
|
RzBinXtrPlugin *bx;
|
|
|
|
CutterRzListForeach(core->bin->binxtrs, it, RzBinXtrPlugin, bx) {
|
|
|
|
RzBinPluginDescription desc;
|
|
|
|
desc.name = bx->name ? bx->name : "";
|
|
|
|
desc.description = bx->desc ? bx->desc : "";
|
|
|
|
desc.license = bx->license ? bx->license : "";
|
|
|
|
desc.type = "xtr";
|
|
|
|
ret.append(desc);
|
2017-09-29 11:32:53 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzIOPluginDescription> CutterCore::getRIOPluginDescriptions()
|
2018-03-09 15:05:40 +00:00
|
|
|
{
|
2021-09-19 08:58:08 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzIOPluginDescription> ret;
|
2021-09-19 08:58:08 +00:00
|
|
|
RzListIter *it;
|
|
|
|
RzIOPlugin *p;
|
|
|
|
CutterRzListForeach(core->io->plugins, it, RzIOPlugin, p) {
|
|
|
|
RzIOPluginDescription desc;
|
|
|
|
desc.name = p->name ? p->name : "";
|
|
|
|
desc.description = p->desc ? p->desc : "";
|
|
|
|
desc.license = p->license ? p->license : "";
|
|
|
|
desc.permissions =
|
|
|
|
QString("r") +
|
|
|
|
(p->write ? "w" : "_") +
|
|
|
|
(p->isdbg ? "d" : "_");
|
|
|
|
if (p->uris) {
|
|
|
|
desc.uris = QString::fromUtf8(p->uris).split(",");
|
|
|
|
}
|
|
|
|
ret.append(desc);
|
2018-03-09 15:05:40 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzCorePluginDescription> CutterCore::getRCorePluginDescriptions()
|
2018-03-09 15:05:40 +00:00
|
|
|
{
|
2021-09-19 08:58:08 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzCorePluginDescription> ret;
|
2021-09-19 08:58:08 +00:00
|
|
|
RzListIter *it;
|
|
|
|
RzCorePlugin *p;
|
|
|
|
CutterRzListForeach(core->plugins, it, RzCorePlugin, p) {
|
|
|
|
RzCorePluginDescription desc;
|
|
|
|
desc.name = p->name ? p->name : "";
|
|
|
|
desc.description = p->desc ? p->desc : "";
|
|
|
|
desc.license = p->license ? p->license : "";
|
|
|
|
ret.append(desc);
|
2018-03-09 15:05:40 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
QList<RzAsmPluginDescription> CutterCore::getRAsmPluginDescriptions()
|
2018-03-09 15:05:40 +00:00
|
|
|
{
|
2018-03-11 08:39:31 +00:00
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzListIter *it;
|
|
|
|
QList<RzAsmPluginDescription> ret;
|
2018-03-09 15:05:40 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzAsmPlugin *ap;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->rasm->plugins, it, RzAsmPlugin, ap)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2020-10-28 12:28:04 +00:00
|
|
|
RzAsmPluginDescription plugin;
|
2018-03-11 08:39:31 +00:00
|
|
|
|
|
|
|
plugin.name = ap->name;
|
|
|
|
plugin.architecture = ap->arch;
|
|
|
|
plugin.author = ap->author;
|
|
|
|
plugin.version = ap->version;
|
|
|
|
plugin.cpus = ap->cpus;
|
|
|
|
plugin.description = ap->desc;
|
|
|
|
plugin.license = ap->license;
|
|
|
|
|
|
|
|
ret << plugin;
|
|
|
|
}
|
2018-03-09 15:05:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<FunctionDescription> CutterCore::getAllFunctions()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
2019-05-01 11:34:15 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<FunctionDescription> funcList;
|
2020-12-07 07:57:11 +00:00
|
|
|
funcList.reserve(rz_list_length(core->analysis->fcns));
|
2019-05-01 11:34:15 +00:00
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzListIter *iter;
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisFunction *fcn;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->analysis->fcns, iter, RzAnalysisFunction, fcn)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2019-05-01 11:34:15 +00:00
|
|
|
FunctionDescription function;
|
|
|
|
function.offset = fcn->addr;
|
2020-12-07 07:57:11 +00:00
|
|
|
function.linearSize = rz_analysis_function_linear_size(fcn);
|
2021-01-24 14:50:13 +00:00
|
|
|
function.nargs = rz_analysis_var_count(core->analysis, fcn, 'b', 1)
|
|
|
|
+ rz_analysis_var_count(core->analysis, fcn, 'r', 1)
|
|
|
|
+ rz_analysis_var_count(core->analysis, fcn, 's', 1);
|
|
|
|
function.nlocals = rz_analysis_var_count(core->analysis, fcn, 'b', 0)
|
|
|
|
+ rz_analysis_var_count(core->analysis, fcn, 'r', 0)
|
|
|
|
+ rz_analysis_var_count(core->analysis, fcn, 's', 0);
|
|
|
|
function.nbbs = rz_list_length(fcn->bbs);
|
2019-05-01 11:34:15 +00:00
|
|
|
function.calltype = fcn->cc ? QString::fromUtf8(fcn->cc) : QString();
|
|
|
|
function.name = fcn->name ? QString::fromUtf8(fcn->name) : QString();
|
2020-12-07 07:57:11 +00:00
|
|
|
function.edges = rz_analysis_function_count_edges(fcn, nullptr);
|
2019-05-01 11:34:15 +00:00
|
|
|
function.stackframe = fcn->maxstack;
|
2019-05-17 11:40:50 +00:00
|
|
|
funcList.append(function);
|
2019-05-01 11:34:15 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return funcList;
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<ImportDescription> CutterCore::getAllImports()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ImportDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray importsArray = cmdj("iij").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : importsArray) {
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonObject importObject = value.toObject();
|
|
|
|
|
|
|
|
ImportDescription import;
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
import.plt = importObject[RJsonKey::plt].toVariant().toULongLong();
|
|
|
|
import.ordinal = importObject[RJsonKey::ordinal].toInt();
|
|
|
|
import.bind = importObject[RJsonKey::bind].toString();
|
|
|
|
import.type = importObject[RJsonKey::type].toString();
|
2020-01-25 07:18:53 +00:00
|
|
|
import.libname = importObject[RJsonKey::libname].toString();
|
2018-11-20 07:45:42 +00:00
|
|
|
import.name = importObject[RJsonKey::name].toString();
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
ret << import;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<ExportDescription> CutterCore::getAllExports()
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ExportDescription> ret;
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonArray exportsArray = cmdj("iEj").array();
|
2017-05-19 07:45:26 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : exportsArray) {
|
|
|
|
QJsonObject exportObject = value.toObject();
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
ExportDescription exp;
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
exp.vaddr = exportObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
exp.paddr = exportObject[RJsonKey::paddr].toVariant().toULongLong();
|
|
|
|
exp.size = exportObject[RJsonKey::size].toVariant().toULongLong();
|
|
|
|
exp.type = exportObject[RJsonKey::type].toString();
|
|
|
|
exp.name = exportObject[RJsonKey::name].toString();
|
|
|
|
exp.flag_name = exportObject[RJsonKey::flagname].toString();
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
ret << exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<SymbolDescription> CutterCore::getAllSymbols()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
RzListIter *it;
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
QList<SymbolDescription> ret;
|
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
RzBinSymbol *bs;
|
2019-08-30 15:31:30 +00:00
|
|
|
if (core && core->bin && core->bin->cur && core->bin->cur->o) {
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->bin->cur->o->symbols, it, RzBinSymbol, bs)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
QString type = QString(bs->bind) + " " + QString(bs->type);
|
|
|
|
SymbolDescription symbol;
|
|
|
|
symbol.vaddr = bs->vaddr;
|
|
|
|
symbol.name = QString(bs->name);
|
|
|
|
symbol.bind = QString(bs->bind);
|
|
|
|
symbol.type = QString(bs->type);
|
|
|
|
ret << symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* list entrypoints as symbols too */
|
|
|
|
int n = 0;
|
2020-10-28 12:28:04 +00:00
|
|
|
RzBinAddr *entry;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach(core->bin->cur->o->entries, it, RzBinAddr, entry)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
SymbolDescription symbol;
|
|
|
|
symbol.vaddr = entry->vaddr;
|
|
|
|
symbol.name = QString("entry") + QString::number(n++);
|
2019-03-23 10:54:34 +00:00
|
|
|
symbol.bind.clear();
|
2017-04-28 13:09:40 +00:00
|
|
|
symbol.type = "entry";
|
|
|
|
ret << symbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-21 17:34:41 +00:00
|
|
|
QList<HeaderDescription> CutterCore::getAllHeaders()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<HeaderDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray headersArray = cmdj("ihj").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : headersArray) {
|
2018-05-21 17:34:41 +00:00
|
|
|
QJsonObject headerObject = value.toObject();
|
|
|
|
|
|
|
|
HeaderDescription header;
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
header.vaddr = headerObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
header.paddr = headerObject[RJsonKey::paddr].toVariant().toULongLong();
|
|
|
|
header.value = headerObject[RJsonKey::comment].toString();
|
|
|
|
header.name = headerObject[RJsonKey::name].toString();
|
2018-05-21 17:34:41 +00:00
|
|
|
|
|
|
|
ret << header;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-24 15:37:37 +00:00
|
|
|
QList<ZignatureDescription> CutterCore::getAllZignatures()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<ZignatureDescription> zignatures;
|
2018-05-24 15:37:37 +00:00
|
|
|
|
|
|
|
QJsonArray zignaturesArray = cmdj("zj").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : zignaturesArray) {
|
2018-05-24 15:37:37 +00:00
|
|
|
QJsonObject zignatureObject = value.toObject();
|
|
|
|
|
|
|
|
ZignatureDescription zignature;
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
zignature.name = zignatureObject[RJsonKey::name].toString();
|
|
|
|
zignature.bytes = zignatureObject[RJsonKey::bytes].toString();
|
|
|
|
zignature.offset = zignatureObject[RJsonKey::offset].toVariant().toULongLong();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &ref : zignatureObject[RJsonKey::refs].toArray()) {
|
2018-05-24 15:37:37 +00:00
|
|
|
zignature.refs << ref.toString();
|
|
|
|
}
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QJsonObject graphObject = zignatureObject[RJsonKey::graph].toObject();
|
|
|
|
zignature.cc = graphObject[RJsonKey::cc].toVariant().toULongLong();
|
|
|
|
zignature.nbbs = graphObject[RJsonKey::nbbs].toVariant().toULongLong();
|
|
|
|
zignature.edges = graphObject[RJsonKey::edges].toVariant().toULongLong();
|
|
|
|
zignature.ebbs = graphObject[RJsonKey::ebbs].toVariant().toULongLong();
|
2018-05-24 15:37:37 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
zignatures << zignature;
|
2018-05-24 15:37:37 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return zignatures;
|
2018-05-24 15:37:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<CommentDescription> CutterCore::getAllComments(const QString &filterType)
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<CommentDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray commentsArray = cmdj("CCj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : commentsArray) {
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonObject commentObject = value.toObject();
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QString type = commentObject[RJsonKey::type].toString();
|
2017-04-28 13:38:01 +00:00
|
|
|
if (type != filterType)
|
2017-04-28 13:09:40 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
CommentDescription comment;
|
2018-11-20 07:45:42 +00:00
|
|
|
comment.offset = commentObject[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
comment.name = commentObject[RJsonKey::name].toString();
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
ret << comment;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<RelocDescription> CutterCore::getAllRelocs()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<RelocDescription> ret;
|
|
|
|
|
2019-08-30 15:31:30 +00:00
|
|
|
if (core && core->bin && core->bin->cur && core->bin->cur->o) {
|
2021-06-04 09:05:34 +00:00
|
|
|
auto relocs = rz_bin_object_patch_relocs(core->bin->cur, core->bin->cur->o);
|
2021-06-29 17:36:26 +00:00
|
|
|
if (!relocs) {
|
|
|
|
return ret;
|
|
|
|
}
|
2021-06-04 09:05:34 +00:00
|
|
|
for (size_t i = 0; i < relocs->relocs_count; i++) {
|
|
|
|
RzBinReloc *reloc = relocs->relocs[i];
|
|
|
|
RelocDescription desc;
|
|
|
|
desc.vaddr = reloc->vaddr;
|
|
|
|
desc.paddr = reloc->paddr;
|
|
|
|
desc.type = (reloc->additive ? "ADD_" : "SET_") + QString::number(reloc->type);
|
|
|
|
|
|
|
|
if (reloc->import)
|
|
|
|
desc.name = reloc->import->name;
|
2017-04-28 13:09:40 +00:00
|
|
|
else
|
2021-06-04 09:05:34 +00:00
|
|
|
desc.name = QString("reloc_%1").arg(QString::number(reloc->vaddr, 16));
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2021-06-04 09:05:34 +00:00
|
|
|
ret << desc;
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<StringDescription> CutterCore::getAllStrings()
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
2018-05-29 16:19:59 +00:00
|
|
|
return parseStringsJson(cmdjTask("izzj"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<StringDescription> CutterCore::parseStringsJson(const QJsonDocument &doc)
|
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
QList<StringDescription> ret;
|
2018-05-28 15:19:58 +00:00
|
|
|
|
2018-08-24 16:06:07 +00:00
|
|
|
QJsonArray stringsArray = doc.array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : stringsArray) {
|
2018-02-10 17:50:00 +00:00
|
|
|
QJsonObject stringObject = value.toObject();
|
|
|
|
|
|
|
|
StringDescription string;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2019-11-23 15:03:23 +00:00
|
|
|
string.string = stringObject[RJsonKey::string].toString();
|
2018-11-20 07:45:42 +00:00
|
|
|
string.vaddr = stringObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
string.type = stringObject[RJsonKey::type].toString();
|
|
|
|
string.size = stringObject[RJsonKey::size].toVariant().toUInt();
|
|
|
|
string.length = stringObject[RJsonKey::length].toVariant().toUInt();
|
|
|
|
string.section = stringObject[RJsonKey::section].toString();
|
2018-02-10 17:50:00 +00:00
|
|
|
|
|
|
|
ret << string;
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2017-04-28 13:38:01 +00:00
|
|
|
}
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<FlagspaceDescription> CutterCore::getAllFlagspaces()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<FlagspaceDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray flagspacesArray = cmdj("fsj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : flagspacesArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject flagspaceObject = value.toObject();
|
|
|
|
|
|
|
|
FlagspaceDescription flagspace;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
flagspace.name = flagspaceObject[RJsonKey::name].toString();
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
ret << flagspace;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<FlagDescription> CutterCore::getAllFlags(QString flagspace)
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<FlagDescription> ret;
|
|
|
|
|
|
|
|
if (!flagspace.isEmpty())
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs " + flagspace);
|
2017-05-03 09:09:57 +00:00
|
|
|
else
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("fs *");
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
QJsonArray flagsArray = cmdj("fj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : flagsArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject flagObject = value.toObject();
|
|
|
|
|
|
|
|
FlagDescription flag;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
flag.offset = flagObject[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
flag.size = flagObject[RJsonKey::size].toVariant().toULongLong();
|
|
|
|
flag.name = flagObject[RJsonKey::name].toString();
|
2020-01-25 07:18:53 +00:00
|
|
|
flag.realname = flagObject[RJsonKey::realname].toString();
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
ret << flag;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<SectionDescription> CutterCore::getAllSections()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<SectionDescription> sections;
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2018-05-05 10:11:44 +00:00
|
|
|
QJsonDocument sectionsDoc = cmdj("iSj entropy");
|
|
|
|
QJsonObject sectionsObj = sectionsDoc.object();
|
2018-11-20 07:45:42 +00:00
|
|
|
QJsonArray sectionsArray = sectionsObj[RJsonKey::sections].toArray();
|
2018-05-05 10:11:44 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : sectionsArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject sectionObject = value.toObject();
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QString name = sectionObject[RJsonKey::name].toString();
|
2017-05-03 09:09:57 +00:00
|
|
|
if (name.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SectionDescription section;
|
|
|
|
section.name = name;
|
2018-11-20 07:45:42 +00:00
|
|
|
section.vaddr = sectionObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
section.vsize = sectionObject[RJsonKey::vsize].toVariant().toULongLong();
|
|
|
|
section.paddr = sectionObject[RJsonKey::paddr].toVariant().toULongLong();
|
|
|
|
section.size = sectionObject[RJsonKey::size].toVariant().toULongLong();
|
2019-05-16 10:48:14 +00:00
|
|
|
section.perm = sectionObject[RJsonKey::perm].toString();
|
2021-01-24 14:50:13 +00:00
|
|
|
section.entropy = sectionObject[RJsonKey::entropy].toString();
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
sections << section;
|
2017-05-03 09:09:57 +00:00
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
return sections;
|
2017-05-13 18:09:36 +00:00
|
|
|
}
|
2017-06-07 10:56:55 +00:00
|
|
|
|
2018-11-17 19:17:16 +00:00
|
|
|
QStringList CutterCore::getSectionList()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QStringList ret;
|
|
|
|
|
|
|
|
QJsonArray sectionsArray = cmdj("iSj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : sectionsArray) {
|
2018-11-20 07:45:42 +00:00
|
|
|
ret << value.toObject()[RJsonKey::name].toString();
|
2018-11-17 19:17:16 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-20 18:20:06 +00:00
|
|
|
QList<SegmentDescription> CutterCore::getAllSegments()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<SegmentDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray segments = cmdj("iSSj").array();
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : segments) {
|
2018-10-20 18:20:06 +00:00
|
|
|
QJsonObject segmentObject = value.toObject();
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QString name = segmentObject[RJsonKey::name].toString();
|
2018-10-20 18:20:06 +00:00
|
|
|
if (name.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SegmentDescription segment;
|
|
|
|
segment.name = name;
|
2018-11-20 07:45:42 +00:00
|
|
|
segment.vaddr = segmentObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
segment.paddr = segmentObject[RJsonKey::paddr].toVariant().toULongLong();
|
|
|
|
segment.size = segmentObject[RJsonKey::size].toVariant().toULongLong();
|
|
|
|
segment.vsize = segmentObject[RJsonKey::vsize].toVariant().toULongLong();
|
2021-01-24 14:50:13 +00:00
|
|
|
segment.perm = segmentObject[RJsonKey::perm].toString();
|
2018-10-20 18:20:06 +00:00
|
|
|
|
|
|
|
ret << segment;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QList<EntrypointDescription> CutterCore::getAllEntrypoint()
|
2017-07-13 18:49:12 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<EntrypointDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray entrypointsArray = cmdj("iej").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : entrypointsArray) {
|
2017-07-13 18:49:12 +00:00
|
|
|
QJsonObject entrypointObject = value.toObject();
|
|
|
|
|
|
|
|
EntrypointDescription entrypoint;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
entrypoint.vaddr = entrypointObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
entrypoint.paddr = entrypointObject[RJsonKey::paddr].toVariant().toULongLong();
|
|
|
|
entrypoint.baddr = entrypointObject[RJsonKey::baddr].toVariant().toULongLong();
|
|
|
|
entrypoint.laddr = entrypointObject[RJsonKey::laddr].toVariant().toULongLong();
|
|
|
|
entrypoint.haddr = entrypointObject[RJsonKey::haddr].toVariant().toULongLong();
|
|
|
|
entrypoint.type = entrypointObject[RJsonKey::type].toString();
|
2017-07-13 18:49:12 +00:00
|
|
|
|
|
|
|
ret << entrypoint;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<BinClassDescription> CutterCore::getAllClassesFromBin()
|
2017-12-23 16:42:42 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<BinClassDescription> ret;
|
2017-12-23 16:42:42 +00:00
|
|
|
|
|
|
|
QJsonArray classesArray = cmdj("icj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : classesArray) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject classObject = value.toObject();
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassDescription cls;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
cls.name = classObject[RJsonKey::classname].toString();
|
|
|
|
cls.addr = classObject[RJsonKey::addr].toVariant().toULongLong();
|
|
|
|
cls.index = classObject[RJsonKey::index].toVariant().toULongLong();
|
2017-12-23 16:42:42 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value2 : classObject[RJsonKey::methods].toArray()) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject methObject = value2.toObject();
|
|
|
|
|
2019-01-31 16:45:58 +00:00
|
|
|
BinClassMethodDescription meth;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
meth.name = methObject[RJsonKey::name].toString();
|
|
|
|
meth.addr = methObject[RJsonKey::addr].toVariant().toULongLong();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
cls.methods << meth;
|
|
|
|
}
|
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value2 : classObject[RJsonKey::fields].toArray()) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject fieldObject = value2.toObject();
|
|
|
|
|
2019-01-31 16:45:58 +00:00
|
|
|
BinClassFieldDescription field;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
field.name = fieldObject[RJsonKey::name].toString();
|
|
|
|
field.addr = fieldObject[RJsonKey::addr].toVariant().toULongLong();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
cls.fields << field;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret << cls;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<BinClassDescription> CutterCore::getAllClassesFromFlags()
|
2018-03-11 11:13:08 +00:00
|
|
|
{
|
|
|
|
static const QRegularExpression classFlagRegExp("^class\\.(.*)$");
|
|
|
|
static const QRegularExpression methodFlagRegExp("^method\\.([^\\.]*)\\.(.*)$");
|
|
|
|
|
|
|
|
CORE_LOCK();
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<BinClassDescription> ret;
|
|
|
|
QMap<QString, BinClassDescription *> classesCache;
|
2018-03-11 11:13:08 +00:00
|
|
|
|
|
|
|
QJsonArray flagsArray = cmdj("fj@F:classes").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : flagsArray) {
|
2018-03-11 11:13:08 +00:00
|
|
|
QJsonObject flagObject = value.toObject();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QString flagName = flagObject[RJsonKey::name].toString();
|
2018-03-11 11:13:08 +00:00
|
|
|
|
|
|
|
QRegularExpressionMatch match = classFlagRegExp.match(flagName);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (match.hasMatch()) {
|
2018-03-11 11:13:08 +00:00
|
|
|
QString className = match.captured(1);
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassDescription *desc = nullptr;
|
2018-03-11 11:13:08 +00:00
|
|
|
auto it = classesCache.find(className);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (it == classesCache.end()) {
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassDescription cls = {};
|
2018-03-11 11:13:08 +00:00
|
|
|
ret << cls;
|
|
|
|
desc = &ret.last();
|
|
|
|
classesCache[className] = desc;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-03-11 11:13:08 +00:00
|
|
|
desc = it.value();
|
|
|
|
}
|
|
|
|
desc->name = match.captured(1);
|
2018-11-20 07:45:42 +00:00
|
|
|
desc->addr = flagObject[RJsonKey::offset].toVariant().toULongLong();
|
2018-08-17 11:27:07 +00:00
|
|
|
desc->index = RVA_INVALID;
|
2018-03-11 11:13:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = methodFlagRegExp.match(flagName);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (match.hasMatch()) {
|
2018-03-11 11:13:08 +00:00
|
|
|
QString className = match.captured(1);
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassDescription *classDesc = nullptr;
|
2018-03-11 11:13:08 +00:00
|
|
|
auto it = classesCache.find(className);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (it == classesCache.end()) {
|
2018-03-11 11:13:08 +00:00
|
|
|
// add a new stub class, will be replaced if class flag comes after it
|
2018-08-17 11:27:07 +00:00
|
|
|
BinClassDescription cls;
|
2018-03-11 11:13:08 +00:00
|
|
|
cls.name = tr("Unknown (%1)").arg(className);
|
2018-08-17 11:27:07 +00:00
|
|
|
cls.addr = RVA_INVALID;
|
2018-03-11 11:13:08 +00:00
|
|
|
cls.index = 0;
|
|
|
|
ret << cls;
|
|
|
|
classDesc = &ret.last();
|
|
|
|
classesCache[className] = classDesc;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-03-11 11:13:08 +00:00
|
|
|
classDesc = it.value();
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:45:58 +00:00
|
|
|
BinClassMethodDescription meth;
|
2018-03-11 11:13:08 +00:00
|
|
|
meth.name = match.captured(2);
|
2018-11-20 07:45:42 +00:00
|
|
|
meth.addr = flagObject[RJsonKey::offset].toVariant().toULongLong();
|
2018-03-11 11:13:08 +00:00
|
|
|
classDesc->methods << meth;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<QString> CutterCore::getAllAnalysisClasses(bool sorted)
|
2018-08-17 11:27:07 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2018-08-17 11:27:07 +00:00
|
|
|
QList<QString> ret;
|
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
SdbListPtr l = makeSdbListPtr(rz_analysis_class_get_all(core->analysis, sorted));
|
2018-08-17 11:27:07 +00:00
|
|
|
if (!l) {
|
|
|
|
return ret;
|
|
|
|
}
|
2019-01-31 16:45:58 +00:00
|
|
|
ret.reserve(static_cast<int>(l->length));
|
2018-08-17 11:27:07 +00:00
|
|
|
|
|
|
|
SdbListIter *it;
|
|
|
|
void *entry;
|
2021-01-24 14:50:13 +00:00
|
|
|
ls_foreach(l, it, entry)
|
|
|
|
{
|
2018-08-17 11:27:07 +00:00
|
|
|
auto kv = reinterpret_cast<SdbKv *>(entry);
|
|
|
|
ret.append(QString::fromUtf8(reinterpret_cast<const char *>(kv->base.key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisMethodDescription> CutterCore::getAnalysisClassMethods(const QString &cls)
|
2019-01-31 16:45:58 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisMethodDescription> ret;
|
2019-01-31 16:45:58 +00:00
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzVector *meths = rz_analysis_class_method_get_all(core->analysis, cls.toUtf8().constData());
|
2019-01-31 16:45:58 +00:00
|
|
|
if (!meths) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.reserve(static_cast<int>(meths->len));
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisMethod *meth;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzVectorForeach(meths, meth, RzAnalysisMethod)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2021-09-15 18:48:02 +00:00
|
|
|
AnalysisMethodDescription desc;
|
2019-01-31 16:45:58 +00:00
|
|
|
desc.name = QString::fromUtf8(meth->name);
|
|
|
|
desc.addr = meth->addr;
|
|
|
|
desc.vtableOffset = meth->vtable_offset;
|
2019-02-01 14:51:29 +00:00
|
|
|
ret.append(desc);
|
2019-01-31 16:45:58 +00:00
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_vector_free(meths);
|
2019-01-31 16:45:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisBaseClassDescription> CutterCore::getAnalysisClassBaseClasses(const QString &cls)
|
2019-01-31 16:45:58 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisBaseClassDescription> ret;
|
2019-01-31 16:45:58 +00:00
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzVector *bases = rz_analysis_class_base_get_all(core->analysis, cls.toUtf8().constData());
|
2019-01-31 16:45:58 +00:00
|
|
|
if (!bases) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.reserve(static_cast<int>(bases->len));
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisBaseClass *base;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzVectorForeach(bases, base, RzAnalysisBaseClass)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2021-09-15 18:48:02 +00:00
|
|
|
AnalysisBaseClassDescription desc;
|
2019-01-31 16:45:58 +00:00
|
|
|
desc.id = QString::fromUtf8(base->id);
|
|
|
|
desc.offset = base->offset;
|
|
|
|
desc.className = QString::fromUtf8(base->class_name);
|
2019-02-01 14:51:29 +00:00
|
|
|
ret.append(desc);
|
2019-01-31 16:45:58 +00:00
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_vector_free(bases);
|
2019-01-31 16:45:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisVTableDescription> CutterCore::getAnalysisClassVTables(const QString &cls)
|
2019-01-31 16:45:58 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-09-15 18:48:02 +00:00
|
|
|
QList<AnalysisVTableDescription> acVtables;
|
2019-01-31 16:45:58 +00:00
|
|
|
|
2020-12-07 07:57:11 +00:00
|
|
|
RzVector *vtables = rz_analysis_class_vtable_get_all(core->analysis, cls.toUtf8().constData());
|
2019-01-31 16:45:58 +00:00
|
|
|
if (!vtables) {
|
2019-05-17 11:40:50 +00:00
|
|
|
return acVtables;
|
2019-01-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
acVtables.reserve(static_cast<int>(vtables->len));
|
2020-12-07 07:57:11 +00:00
|
|
|
RzAnalysisVTable *vtable;
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzVectorForeach(vtables, vtable, RzAnalysisVTable)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2021-09-15 18:48:02 +00:00
|
|
|
AnalysisVTableDescription desc;
|
2019-01-31 16:45:58 +00:00
|
|
|
desc.id = QString::fromUtf8(vtable->id);
|
|
|
|
desc.offset = vtable->offset;
|
|
|
|
desc.addr = vtable->addr;
|
2019-05-17 11:40:50 +00:00
|
|
|
acVtables.append(desc);
|
2019-01-31 16:45:58 +00:00
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_vector_free(vtables);
|
2019-01-31 16:45:58 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return acVtables;
|
2019-01-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 12:40:41 +00:00
|
|
|
void CutterCore::createNewClass(const QString &cls)
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
rz_analysis_class_create(core->analysis, cls.toUtf8().constData());
|
2019-02-07 12:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::renameClass(const QString &oldName, const QString &newName)
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_analysis_class_rename(core->analysis, oldName.toUtf8().constData(),
|
|
|
|
newName.toUtf8().constData());
|
2019-02-07 12:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::deleteClass(const QString &cls)
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2020-12-07 07:57:11 +00:00
|
|
|
rz_analysis_class_delete(core->analysis, cls.toUtf8().constData());
|
2019-02-07 12:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
bool CutterCore::getAnalysisMethod(const QString &cls, const QString &meth, AnalysisMethodDescription *desc)
|
2019-02-01 20:40:34 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-09-15 18:48:02 +00:00
|
|
|
RzAnalysisMethod analysisMeth;
|
2021-01-24 14:50:13 +00:00
|
|
|
if (rz_analysis_class_method_get(core->analysis, cls.toUtf8().constData(),
|
2021-09-15 18:48:02 +00:00
|
|
|
meth.toUtf8().constData(), &analysisMeth)
|
2021-01-24 14:50:13 +00:00
|
|
|
!= RZ_ANALYSIS_CLASS_ERR_SUCCESS) {
|
2019-02-01 20:40:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-15 18:48:02 +00:00
|
|
|
desc->name = QString::fromUtf8(analysisMeth.name);
|
|
|
|
desc->addr = analysisMeth.addr;
|
|
|
|
desc->vtableOffset = analysisMeth.vtable_offset;
|
|
|
|
rz_analysis_class_method_fini(&analysisMeth);
|
2019-02-01 20:40:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
void CutterCore::setAnalysisMethod(const QString &className, const AnalysisMethodDescription &meth)
|
2019-02-01 20:40:34 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-09-15 18:48:02 +00:00
|
|
|
RzAnalysisMethod analysisMeth;
|
|
|
|
analysisMeth.name = strdup(meth.name.toUtf8().constData());
|
|
|
|
analysisMeth.addr = meth.addr;
|
|
|
|
analysisMeth.vtable_offset = meth.vtableOffset;
|
|
|
|
rz_analysis_class_method_set(core->analysis, className.toUtf8().constData(), &analysisMeth);
|
|
|
|
rz_analysis_class_method_fini(&analysisMeth);
|
2019-02-01 20:40:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:48:02 +00:00
|
|
|
void CutterCore::renameAnalysisMethod(const QString &className, const QString &oldMethodName,
|
2021-01-24 14:50:13 +00:00
|
|
|
const QString &newMethodName)
|
2019-02-01 20:40:34 +00:00
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
rz_analysis_class_method_rename(core->analysis, className.toUtf8().constData(),
|
|
|
|
oldMethodName.toUtf8().constData(),
|
|
|
|
newMethodName.toUtf8().constData());
|
2019-02-01 20:40:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 14:32:18 +00:00
|
|
|
QList<ResourcesDescription> CutterCore::getAllResources()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<ResourcesDescription> resources;
|
2018-02-04 14:32:18 +00:00
|
|
|
|
|
|
|
QJsonArray resourcesArray = cmdj("iRj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : resourcesArray) {
|
2018-02-04 14:32:18 +00:00
|
|
|
QJsonObject resourceObject = value.toObject();
|
|
|
|
|
|
|
|
ResourcesDescription res;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2020-04-15 16:20:57 +00:00
|
|
|
res.name = resourceObject[RJsonKey::name].toString();
|
2018-11-20 07:45:42 +00:00
|
|
|
res.vaddr = resourceObject[RJsonKey::vaddr].toVariant().toULongLong();
|
|
|
|
res.index = resourceObject[RJsonKey::index].toVariant().toULongLong();
|
|
|
|
res.type = resourceObject[RJsonKey::type].toString();
|
|
|
|
res.size = resourceObject[RJsonKey::size].toVariant().toULongLong();
|
|
|
|
res.lang = resourceObject[RJsonKey::lang].toString();
|
2018-02-04 14:32:18 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
resources << res;
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
return resources;
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 22:26:18 +00:00
|
|
|
QList<VTableDescription> CutterCore::getAllVTables()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<VTableDescription> vtables;
|
2018-02-26 22:26:18 +00:00
|
|
|
|
|
|
|
QJsonArray vTablesArray = cmdj("avj").array();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &vTableValue : vTablesArray) {
|
2018-02-26 22:26:18 +00:00
|
|
|
QJsonObject vTableObject = vTableValue.toObject();
|
|
|
|
|
|
|
|
VTableDescription res;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
res.addr = vTableObject[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
QJsonArray methodArray = vTableObject[RJsonKey::methods].toArray();
|
2018-02-26 22:26:18 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &methodValue : methodArray) {
|
2018-02-26 22:26:18 +00:00
|
|
|
QJsonObject methodObject = methodValue.toObject();
|
|
|
|
|
2019-01-31 16:45:58 +00:00
|
|
|
BinClassMethodDescription method;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
method.addr = methodObject[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
method.name = methodObject[RJsonKey::name].toString();
|
2018-02-26 22:26:18 +00:00
|
|
|
|
|
|
|
res.methods << method;
|
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
vtables << res;
|
2018-02-26 22:26:18 +00:00
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
return vtables;
|
2018-02-26 22:26:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 17:21:48 +00:00
|
|
|
QList<TypeDescription> CutterCore::getAllTypes()
|
2019-02-01 16:11:50 +00:00
|
|
|
{
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<TypeDescription> types;
|
2019-02-01 16:11:50 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
types.append(getAllPrimitiveTypes());
|
|
|
|
types.append(getAllUnions());
|
|
|
|
types.append(getAllStructs());
|
|
|
|
types.append(getAllEnums());
|
|
|
|
types.append(getAllTypedefs());
|
2019-02-01 16:11:50 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return types;
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
QList<TypeDescription> CutterCore::getBaseType(RzBaseTypeKind kind, const char *category)
|
2018-03-06 17:21:48 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2021-09-07 09:12:07 +00:00
|
|
|
QList<TypeDescription> types;
|
2018-03-06 17:21:48 +00:00
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
RzList *ts = rz_type_db_get_base_types_of_kind(core->analysis->typedb, kind);
|
|
|
|
RzBaseType *type;
|
|
|
|
RzListIter *iter;
|
2018-03-06 17:21:48 +00:00
|
|
|
|
2021-09-14 13:32:04 +00:00
|
|
|
CutterRzListForeach (ts, iter, RzBaseType, type) {
|
2018-03-06 17:21:48 +00:00
|
|
|
TypeDescription exp;
|
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
exp.type = type->name;
|
|
|
|
exp.size = rz_type_db_base_get_bitsize(core->analysis->typedb, type);
|
|
|
|
exp.format = rz_type_format(core->analysis->typedb, type->name);
|
|
|
|
exp.category = tr(category);
|
|
|
|
types << exp;
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
2021-09-07 09:12:07 +00:00
|
|
|
rz_list_free(ts);
|
2019-02-01 16:11:50 +00:00
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
return types;
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
2018-03-06 17:21:48 +00:00
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
QList<TypeDescription> CutterCore::getAllPrimitiveTypes()
|
2019-02-01 16:11:50 +00:00
|
|
|
{
|
2021-09-07 09:12:07 +00:00
|
|
|
return getBaseType(RZ_BASE_TYPE_KIND_ATOMIC, "Primitive");
|
|
|
|
}
|
2019-02-01 16:11:50 +00:00
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
QList<TypeDescription> CutterCore::getAllUnions()
|
|
|
|
{
|
|
|
|
return getBaseType(RZ_BASE_TYPE_KIND_UNION, "Union");
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<TypeDescription> CutterCore::getAllStructs()
|
|
|
|
{
|
2021-09-07 09:12:07 +00:00
|
|
|
return getBaseType(RZ_BASE_TYPE_KIND_STRUCT, "Struct");
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<TypeDescription> CutterCore::getAllEnums()
|
|
|
|
{
|
2021-09-07 09:12:07 +00:00
|
|
|
return getBaseType(RZ_BASE_TYPE_KIND_ENUM, "Enum");
|
2019-02-01 16:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<TypeDescription> CutterCore::getAllTypedefs()
|
|
|
|
{
|
2021-09-07 09:12:07 +00:00
|
|
|
return getBaseType(RZ_BASE_TYPE_KIND_TYPEDEF, "Typedef");
|
2018-03-06 17:21:48 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 09:12:07 +00:00
|
|
|
QString CutterCore::getTypeAsC(QString name)
|
2019-06-13 06:22:20 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QString output = "Failed to fetch the output.";
|
2021-09-07 09:12:07 +00:00
|
|
|
if (name.isEmpty()) {
|
2019-06-13 06:22:20 +00:00
|
|
|
return output;
|
|
|
|
}
|
2021-09-07 09:12:07 +00:00
|
|
|
char *earg = rz_cmd_escape_arg(name.toUtf8().constData(), RZ_CMD_ESCAPE_ONE_ARG);
|
|
|
|
// TODO: use API for `tc` command once available
|
|
|
|
QString result = cmd(QString("tc %1").arg(earg));
|
|
|
|
free(earg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-04 21:45:17 +00:00
|
|
|
bool CutterCore::isAddressMapped(RVA addr)
|
|
|
|
{
|
|
|
|
// If value returned by "om. @ addr" is empty means that address is not mapped
|
2020-03-21 13:25:50 +00:00
|
|
|
return !Core()->cmdRawAt(QString("om."), addr).isEmpty();
|
2019-03-04 21:45:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 13:11:46 +00:00
|
|
|
QList<SearchDescription> CutterCore::getAllSearch(QString searchFor, QString space, QString in)
|
2018-03-08 12:24:15 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<SearchDescription> searchRef;
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2021-01-24 13:11:46 +00:00
|
|
|
QJsonArray searchArray;
|
|
|
|
{
|
|
|
|
TempConfig cfg;
|
|
|
|
cfg.set("search.in", in);
|
|
|
|
searchArray = cmdj(QString("%1 %2").arg(space, searchFor)).array();
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
|
|
|
|
if (space == "/Rj") {
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : searchArray) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject searchObject = value.toObject();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-03-16 09:07:41 +00:00
|
|
|
SearchDescription exp;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2019-03-23 10:54:34 +00:00
|
|
|
exp.code.clear();
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value2 : searchObject[RJsonKey::opcodes].toArray()) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject gadget = value2.toObject();
|
2018-11-20 07:45:42 +00:00
|
|
|
exp.code += gadget[RJsonKey::opcode].toString() + "; ";
|
2018-03-16 09:07:41 +00:00
|
|
|
}
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
exp.offset = searchObject[RJsonKey::opcodes]
|
|
|
|
.toArray()
|
|
|
|
.first()
|
|
|
|
.toObject()[RJsonKey::offset]
|
|
|
|
.toVariant()
|
|
|
|
.toULongLong();
|
2018-11-20 07:45:42 +00:00
|
|
|
exp.size = searchObject[RJsonKey::size].toVariant().toULongLong();
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
searchRef << exp;
|
2018-03-16 09:07:41 +00:00
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : searchArray) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject searchObject = value.toObject();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-03-16 09:07:41 +00:00
|
|
|
SearchDescription exp;
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
exp.offset = searchObject[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
exp.size = searchObject[RJsonKey::len].toVariant().toULongLong();
|
|
|
|
exp.code = searchObject[RJsonKey::code].toString();
|
|
|
|
exp.data = searchObject[RJsonKey::data].toString();
|
2018-03-16 09:07:41 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
searchRef << exp;
|
2018-03-16 09:07:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
return searchRef;
|
2018-03-08 12:24:15 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 10:34:01 +00:00
|
|
|
BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount)
|
|
|
|
{
|
2019-05-17 11:40:50 +00:00
|
|
|
BlockStatistics blockStats;
|
2018-07-06 16:00:26 +00:00
|
|
|
if (blocksCount == 0) {
|
2019-05-17 11:40:50 +00:00
|
|
|
blockStats.from = blockStats.to = blockStats.blocksize = 0;
|
|
|
|
return blockStats;
|
2018-07-06 16:00:26 +00:00
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
|
2020-07-20 20:11:31 +00:00
|
|
|
QJsonObject statsObj;
|
|
|
|
|
|
|
|
// User TempConfig here to set the search boundaries to all sections. This makes sure
|
|
|
|
// that the Visual Navbar will show all the relevant addresses.
|
|
|
|
{
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("search.in", "bin.sections");
|
|
|
|
statsObj = cmdj("p-j " + QString::number(blocksCount)).object();
|
|
|
|
}
|
2018-06-29 10:34:01 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
blockStats.from = statsObj[RJsonKey::from].toVariant().toULongLong();
|
|
|
|
blockStats.to = statsObj[RJsonKey::to].toVariant().toULongLong();
|
|
|
|
blockStats.blocksize = statsObj[RJsonKey::blocksize].toVariant().toULongLong();
|
2018-06-29 10:34:01 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
QJsonArray blocksArray = statsObj[RJsonKey::blocks].toArray();
|
2018-07-01 12:29:01 +00:00
|
|
|
|
2018-06-29 12:35:02 +00:00
|
|
|
for (const QJsonValue &value : blocksArray) {
|
2018-06-29 10:34:01 +00:00
|
|
|
QJsonObject blockObj = value.toObject();
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-06-29 10:34:01 +00:00
|
|
|
BlockDescription block;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
block.addr = blockObj[RJsonKey::offset].toVariant().toULongLong();
|
|
|
|
block.size = blockObj[RJsonKey::size].toVariant().toULongLong();
|
|
|
|
block.flags = blockObj[RJsonKey::flags].toInt(0);
|
|
|
|
block.functions = blockObj[RJsonKey::functions].toInt(0);
|
|
|
|
block.inFunctions = blockObj[RJsonKey::in_functions].toInt(0);
|
|
|
|
block.comments = blockObj[RJsonKey::comments].toInt(0);
|
|
|
|
block.symbols = blockObj[RJsonKey::symbols].toInt(0);
|
|
|
|
block.strings = blockObj[RJsonKey::strings].toInt(0);
|
2018-06-29 10:34:01 +00:00
|
|
|
|
|
|
|
block.rwx = 0;
|
2018-11-20 07:45:42 +00:00
|
|
|
QString rwxStr = blockObj[RJsonKey::rwx].toString();
|
2018-06-29 10:34:01 +00:00
|
|
|
if (rwxStr.length() == 3) {
|
|
|
|
if (rwxStr[0] == 'r') {
|
|
|
|
block.rwx |= (1 << 0);
|
|
|
|
}
|
|
|
|
if (rwxStr[1] == 'w') {
|
|
|
|
block.rwx |= (1 << 1);
|
|
|
|
}
|
|
|
|
if (rwxStr[2] == 'x') {
|
|
|
|
block.rwx |= (1 << 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
blockStats.blocks << block;
|
2018-06-29 10:34:01 +00:00
|
|
|
}
|
2018-06-29 12:35:02 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return blockStats;
|
2018-06-29 10:34:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
QList<XrefDescription> CutterCore::getXRefsForVariable(QString variableName, bool findWrites,
|
|
|
|
RVA offset)
|
2020-07-28 19:49:50 +00:00
|
|
|
{
|
|
|
|
QList<XrefDescription> xrefList = QList<XrefDescription>();
|
|
|
|
QJsonArray xrefsArray;
|
|
|
|
if (findWrites) {
|
|
|
|
xrefsArray = cmdjAt("afvWj", offset).array();
|
|
|
|
} else {
|
|
|
|
xrefsArray = cmdjAt("afvRj", offset).array();
|
|
|
|
}
|
|
|
|
for (const QJsonValue &value : xrefsArray) {
|
|
|
|
QJsonObject xrefObject = value.toObject();
|
|
|
|
QString name = xrefObject[RJsonKey::name].toString();
|
|
|
|
if (name == variableName) {
|
|
|
|
QJsonArray addressArray = xrefObject[RJsonKey::addrs].toArray();
|
|
|
|
for (const QJsonValue &address : addressArray) {
|
|
|
|
XrefDescription xref;
|
|
|
|
RVA addr = address.toVariant().toULongLong();
|
|
|
|
xref.from = addr;
|
|
|
|
xref.to = addr;
|
|
|
|
if (findWrites) {
|
2021-09-14 13:32:04 +00:00
|
|
|
xref.from_str = RzAddressString(addr);
|
2020-07-28 19:49:50 +00:00
|
|
|
} else {
|
2021-09-14 13:32:04 +00:00
|
|
|
xref.to_str = RzAddressString(addr);
|
2020-07-28 19:49:50 +00:00
|
|
|
}
|
|
|
|
xrefList << xref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return xrefList;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_function,
|
|
|
|
const QString &filterType)
|
2017-06-07 10:56:55 +00:00
|
|
|
{
|
2019-05-17 11:40:50 +00:00
|
|
|
QList<XrefDescription> xrefList = QList<XrefDescription>();
|
2017-06-07 10:56:55 +00:00
|
|
|
|
|
|
|
QJsonArray xrefsArray;
|
|
|
|
|
2018-11-05 21:51:27 +00:00
|
|
|
if (to) {
|
2017-06-07 10:56:55 +00:00
|
|
|
xrefsArray = cmdj("axtj@" + QString::number(addr)).array();
|
2018-11-05 21:51:27 +00:00
|
|
|
} else {
|
2017-06-07 10:56:55 +00:00
|
|
|
xrefsArray = cmdj("axfj@" + QString::number(addr)).array();
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2017-06-07 10:56:55 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &value : xrefsArray) {
|
2017-06-07 10:56:55 +00:00
|
|
|
QJsonObject xrefObject = value.toObject();
|
|
|
|
|
2017-06-07 19:35:38 +00:00
|
|
|
XrefDescription xref;
|
2018-11-26 22:34:34 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
xref.type = xrefObject[RJsonKey::type].toString();
|
2017-06-07 10:56:55 +00:00
|
|
|
|
|
|
|
if (!filterType.isNull() && filterType != xref.type)
|
|
|
|
continue;
|
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
xref.from = xrefObject[RJsonKey::from].toVariant().toULongLong();
|
2018-09-11 09:30:28 +00:00
|
|
|
if (!to) {
|
2021-09-14 13:32:04 +00:00
|
|
|
xref.from_str = RzAddressString(xref.from);
|
2018-09-11 09:30:28 +00:00
|
|
|
} else {
|
2018-11-20 07:45:42 +00:00
|
|
|
QString fcn = xrefObject[RJsonKey::fcn_name].toString();
|
2018-09-11 09:30:28 +00:00
|
|
|
if (!fcn.isEmpty()) {
|
2018-11-20 07:45:42 +00:00
|
|
|
RVA fcnAddr = xrefObject[RJsonKey::fcn_addr].toVariant().toULongLong();
|
2018-09-11 09:30:28 +00:00
|
|
|
xref.from_str = fcn + " + 0x" + QString::number(xref.from - fcnAddr, 16);
|
|
|
|
} else {
|
2021-09-14 13:32:04 +00:00
|
|
|
xref.from_str = RzAddressString(xref.from);
|
2018-09-11 09:30:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-07 10:56:55 +00:00
|
|
|
|
2018-11-05 21:51:27 +00:00
|
|
|
if (!whole_function && !to && xref.from != addr) {
|
2017-06-08 22:40:43 +00:00
|
|
|
continue;
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2017-06-08 22:40:43 +00:00
|
|
|
|
2018-11-20 07:45:42 +00:00
|
|
|
if (to && !xrefObject.contains(RJsonKey::to)) {
|
2017-06-07 10:56:55 +00:00
|
|
|
xref.to = addr;
|
2018-11-05 21:51:27 +00:00
|
|
|
} else {
|
2018-11-20 07:45:42 +00:00
|
|
|
xref.to = xrefObject[RJsonKey::to].toVariant().toULongLong();
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2020-03-21 13:25:50 +00:00
|
|
|
xref.to_str = Core()->cmdRaw(QString("fd %1").arg(xref.to)).trimmed();
|
2017-06-07 10:56:55 +00:00
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
xrefList << xref;
|
2017-06-07 10:56:55 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 11:40:50 +00:00
|
|
|
return xrefList;
|
2017-07-11 11:05:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
void CutterCore::addFlag(RVA offset, QString name, RVA size)
|
2017-07-11 11:05:42 +00:00
|
|
|
{
|
|
|
|
name = sanitizeStringForCommand(name);
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRawAt(QString("f %1 %2").arg(name).arg(size), offset);
|
2017-07-11 11:05:42 +00:00
|
|
|
emit flagsChanged();
|
2017-07-13 18:49:12 +00:00
|
|
|
}
|
2017-09-27 20:23:18 +00:00
|
|
|
|
2020-04-04 07:09:30 +00:00
|
|
|
/**
|
|
|
|
* @brief Gets all the flags present at a specific address
|
|
|
|
* @param addr The address to be checked
|
|
|
|
* @return String containing all the flags which are comma-separated
|
|
|
|
*/
|
|
|
|
QString CutterCore::listFlagsAsStringAt(RVA addr)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2021-01-24 14:50:13 +00:00
|
|
|
char *flagList = rz_flag_get_liststr(core->flags, addr);
|
2020-04-16 17:31:15 +00:00
|
|
|
QString result = fromOwnedCharPtr(flagList);
|
2020-04-14 07:58:25 +00:00
|
|
|
return result;
|
2020-04-04 07:09:30 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
QString CutterCore::nearestFlag(RVA offset, RVA *flagOffsetOut)
|
|
|
|
{
|
|
|
|
auto r = cmdj(QString("fdj @") + QString::number(offset)).object();
|
|
|
|
QString name = r.value("name").toString();
|
|
|
|
if (flagOffsetOut) {
|
2021-02-24 08:10:54 +00:00
|
|
|
auto offsetValue = r.value("offset");
|
|
|
|
*flagOffsetOut = offsetValue.isUndefined() ? offset : offsetValue.toVariant().toULongLong();
|
2019-08-19 13:35:25 +00:00
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-02-07 10:42:53 +00:00
|
|
|
void CutterCore::handleREvent(int type, void *data)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_NEW: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClass *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classNew(QString::fromUtf8(ev->name));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_DEL: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClass *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classDeleted(QString::fromUtf8(ev->name));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_RENAME: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClassRename *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classRenamed(QString::fromUtf8(ev->name_old), QString::fromUtf8(ev->name_new));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_ATTR_SET: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClassAttrSet *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classAttrsChanged(QString::fromUtf8(ev->attr.class_name));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_ATTR_DEL: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClassAttr *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classAttrsChanged(QString::fromUtf8(ev->class_name));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_CLASS_ATTR_RENAME: {
|
|
|
|
auto ev = reinterpret_cast<RzEventClassAttrRename *>(data);
|
2019-02-07 10:42:53 +00:00
|
|
|
emit classAttrsChanged(QString::fromUtf8(ev->attr.class_name));
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 12:28:04 +00:00
|
|
|
case RZ_EVENT_DEBUG_PROCESS_FINISHED: {
|
2021-01-24 14:50:13 +00:00
|
|
|
auto ev = reinterpret_cast<RzEventDebugProcessFinished *>(data);
|
2019-12-20 15:41:48 +00:00
|
|
|
emit debugProcessFinished(ev->pid);
|
2019-12-20 12:58:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-07 10:42:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 21:30:51 +00:00
|
|
|
void CutterCore::triggerFlagsChanged()
|
|
|
|
{
|
|
|
|
emit flagsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::triggerVarsChanged()
|
|
|
|
{
|
|
|
|
emit varsChanged();
|
|
|
|
}
|
|
|
|
|
2020-07-16 08:56:38 +00:00
|
|
|
void CutterCore::triggerFunctionRenamed(const RVA offset, const QString &newName)
|
2017-11-30 21:30:51 +00:00
|
|
|
{
|
2020-07-16 08:56:38 +00:00
|
|
|
emit functionRenamed(offset, newName);
|
2017-11-30 21:30:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 20:23:18 +00:00
|
|
|
void CutterCore::loadPDB(const QString &file)
|
|
|
|
{
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("idp " + sanitizeStringForCommand(file));
|
2017-09-27 20:23:18 +00:00
|
|
|
}
|
2017-10-21 19:20:10 +00:00
|
|
|
|
2017-12-13 14:30:00 +00:00
|
|
|
QList<DisassemblyLine> CutterCore::disassembleLines(RVA offset, int lines)
|
|
|
|
{
|
2021-01-24 14:50:13 +00:00
|
|
|
QJsonArray array = cmdj(QString("pdJ ") + QString::number(lines) + QString(" @ ")
|
|
|
|
+ QString::number(offset))
|
|
|
|
.array();
|
2017-12-13 14:30:00 +00:00
|
|
|
QList<DisassemblyLine> r;
|
|
|
|
|
2019-02-15 12:33:23 +00:00
|
|
|
for (const QJsonValueRef &value : array) {
|
2017-12-13 14:30:00 +00:00
|
|
|
QJsonObject object = value.toObject();
|
|
|
|
DisassemblyLine line;
|
2018-11-20 07:45:42 +00:00
|
|
|
line.offset = object[RJsonKey::offset].toVariant().toULongLong();
|
2019-02-15 12:33:23 +00:00
|
|
|
line.text = ansiEscapeToHtml(object[RJsonKey::text].toString());
|
2021-01-24 14:50:13 +00:00
|
|
|
const auto &arrow = object[RJsonKey::arrow];
|
|
|
|
line.arrow = arrow.isNull() ? RVA_INVALID : arrow.toVariant().toULongLong();
|
2017-12-13 14:30:00 +00:00
|
|
|
r << line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2017-12-14 12:45:03 +00:00
|
|
|
|
2019-04-22 08:43:34 +00:00
|
|
|
/**
|
|
|
|
* @brief return hexdump of <size> from an <offset> by a given formats
|
|
|
|
* @param address - the address from which to print the hexdump
|
2021-01-24 14:50:13 +00:00
|
|
|
* @param size - number of bytes to print
|
2019-04-22 08:43:34 +00:00
|
|
|
* @param format - the type of hexdump (qwords, words. decimal, etc)
|
|
|
|
*/
|
|
|
|
QString CutterCore::hexdump(RVA address, int size, HexdumpFormats format)
|
|
|
|
{
|
|
|
|
QString command = "px";
|
|
|
|
switch (format) {
|
|
|
|
case HexdumpFormats::Normal:
|
|
|
|
break;
|
|
|
|
case HexdumpFormats::Half:
|
|
|
|
command += "h";
|
|
|
|
break;
|
|
|
|
case HexdumpFormats::Word:
|
|
|
|
command += "w";
|
|
|
|
break;
|
|
|
|
case HexdumpFormats::Quad:
|
|
|
|
command += "q";
|
|
|
|
break;
|
|
|
|
case HexdumpFormats::Signed:
|
|
|
|
command += "d";
|
|
|
|
break;
|
|
|
|
case HexdumpFormats::Octal:
|
|
|
|
command += "o";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
return cmdRawAt(QString("%1 %2").arg(command).arg(size), address);
|
2019-04-22 08:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 17:11:41 +00:00
|
|
|
QByteArray CutterCore::hexStringToBytes(const QString &hex)
|
|
|
|
{
|
|
|
|
QByteArray hexChars = hex.toUtf8();
|
|
|
|
QByteArray bytes;
|
|
|
|
bytes.reserve(hexChars.length() / 2);
|
2020-10-28 12:28:04 +00:00
|
|
|
int size = rz_hex_str2bin(hexChars.constData(), reinterpret_cast<ut8 *>(bytes.data()));
|
2019-03-29 17:11:41 +00:00
|
|
|
bytes.resize(size);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::bytesToHexString(const QByteArray &bytes)
|
|
|
|
{
|
|
|
|
QByteArray hex;
|
|
|
|
hex.resize(bytes.length() * 2);
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_hex_bin2str(reinterpret_cast<const ut8 *>(bytes.constData()), bytes.size(), hex.data());
|
2019-03-29 17:11:41 +00:00
|
|
|
return QString::fromUtf8(hex);
|
|
|
|
}
|
|
|
|
|
2017-12-14 12:45:03 +00:00
|
|
|
void CutterCore::loadScript(const QString &scriptname)
|
|
|
|
{
|
2019-08-30 15:31:30 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_core_cmd_file(core, scriptname.toUtf8().constData());
|
2019-08-30 15:31:30 +00:00
|
|
|
}
|
2018-09-26 19:05:32 +00:00
|
|
|
triggerRefreshAll();
|
2017-12-14 12:45:03 +00:00
|
|
|
}
|
2018-07-24 17:50:55 +00:00
|
|
|
|
2021-02-24 17:52:35 +00:00
|
|
|
QString CutterCore::getRizinVersionReadable()
|
|
|
|
{
|
|
|
|
return QString("%1 (%2)").arg(QString::fromUtf8(RZ_VERSION),
|
|
|
|
QString::fromUtf8(RZ_GITTIP).left(7));
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:09:04 +00:00
|
|
|
QString CutterCore::getVersionInformation()
|
|
|
|
{
|
|
|
|
int i;
|
2019-05-17 11:40:50 +00:00
|
|
|
QString versionInfo;
|
2021-01-24 14:50:13 +00:00
|
|
|
struct vcs_t
|
|
|
|
{
|
2017-12-15 16:09:04 +00:00
|
|
|
const char *name;
|
|
|
|
const char *(*callback)();
|
|
|
|
} vcs[] = {
|
2020-12-07 07:57:11 +00:00
|
|
|
{ "rz_analysis", &rz_analysis_version },
|
2020-10-28 12:28:04 +00:00
|
|
|
{ "rz_lib", &rz_lib_version },
|
|
|
|
{ "rz_egg", &rz_egg_version },
|
|
|
|
{ "rz_asm", &rz_asm_version },
|
|
|
|
{ "rz_bin", &rz_bin_version },
|
|
|
|
{ "rz_cons", &rz_cons_version },
|
|
|
|
{ "rz_flag", &rz_flag_version },
|
|
|
|
{ "rz_core", &rz_core_version },
|
|
|
|
{ "rz_crypto", &rz_crypto_version },
|
|
|
|
{ "rz_bp", &rz_bp_version },
|
|
|
|
{ "rz_debug", &rz_debug_version },
|
2021-06-04 09:05:34 +00:00
|
|
|
{ "rz_msg_digest", &rz_msg_digest_version },
|
2020-10-28 12:28:04 +00:00
|
|
|
{ "rz_io", &rz_io_version },
|
2019-01-15 18:45:53 +00:00
|
|
|
#if !USE_LIB_MAGIC
|
2020-10-28 12:28:04 +00:00
|
|
|
{ "rz_magic", &rz_magic_version },
|
2019-01-14 20:28:03 +00:00
|
|
|
#endif
|
2020-10-28 12:28:04 +00:00
|
|
|
{ "rz_parse", &rz_parse_version },
|
|
|
|
{ "rz_reg", &rz_reg_version },
|
|
|
|
{ "rz_sign", &rz_sign_version },
|
|
|
|
{ "rz_search", &rz_search_version },
|
|
|
|
{ "rz_syscall", &rz_syscall_version },
|
|
|
|
{ "rz_util", &rz_util_version },
|
2017-12-15 16:09:04 +00:00
|
|
|
/* ... */
|
2021-01-24 14:50:13 +00:00
|
|
|
{ NULL, NULL }
|
2017-12-15 16:09:04 +00:00
|
|
|
};
|
2021-02-24 17:52:35 +00:00
|
|
|
versionInfo.append(QString("%1 rz\n").arg(getRizinVersionReadable()));
|
2017-12-15 16:09:04 +00:00
|
|
|
for (i = 0; vcs[i].name; i++) {
|
2018-03-21 20:32:32 +00:00
|
|
|
struct vcs_t *v = &vcs[i];
|
2021-01-24 14:50:13 +00:00
|
|
|
const char *name = v->callback();
|
2019-05-17 11:40:50 +00:00
|
|
|
versionInfo.append(QString("%1 %2\n").arg(name, v->name));
|
2017-12-15 16:09:04 +00:00
|
|
|
}
|
2019-05-17 11:40:50 +00:00
|
|
|
return versionInfo;
|
2017-12-15 16:09:04 +00:00
|
|
|
}
|
2018-06-25 19:28:34 +00:00
|
|
|
|
2018-02-26 22:25:23 +00:00
|
|
|
QList<QString> CutterCore::getColorThemes()
|
|
|
|
{
|
|
|
|
QList<QString> r;
|
|
|
|
QJsonDocument themes = cmdj("ecoj");
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QJsonValue &s : themes.array()) {
|
2018-02-26 22:25:23 +00:00
|
|
|
r << s.toString();
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2018-02-26 22:25:23 +00:00
|
|
|
return r;
|
|
|
|
}
|
2018-05-29 16:19:59 +00:00
|
|
|
|
2019-02-15 12:33:23 +00:00
|
|
|
QString CutterCore::ansiEscapeToHtml(const QString &text)
|
|
|
|
{
|
|
|
|
int len;
|
2020-10-28 12:28:04 +00:00
|
|
|
char *html = rz_cons_html_filter(text.toUtf8().constData(), &len);
|
2019-02-15 12:33:23 +00:00
|
|
|
if (!html) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
QString r = QString::fromUtf8(html, len);
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_mem_free(html);
|
2019-02-15 12:33:23 +00:00
|
|
|
return r;
|
2019-02-19 14:11:01 +00:00
|
|
|
}
|
2019-02-19 18:56:59 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
BasicBlockHighlighter *CutterCore::getBBHighlighter()
|
2019-02-19 18:56:59 +00:00
|
|
|
{
|
|
|
|
return bbHighlighter;
|
|
|
|
}
|
2019-04-22 08:43:34 +00:00
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
BasicInstructionHighlighter *CutterCore::getBIHighlighter()
|
2019-11-17 18:44:10 +00:00
|
|
|
{
|
|
|
|
return &biHighlighter;
|
|
|
|
}
|
2019-04-22 08:43:34 +00:00
|
|
|
|
2020-03-19 09:36:36 +00:00
|
|
|
void CutterCore::setIOCache(bool enabled)
|
|
|
|
{
|
2020-05-23 11:41:12 +00:00
|
|
|
if (enabled) {
|
|
|
|
// disable write mode when cache is enabled
|
|
|
|
setWriteMode(false);
|
|
|
|
}
|
2020-03-19 09:36:36 +00:00
|
|
|
setConfig("io.cache", enabled);
|
|
|
|
this->iocache = enabled;
|
2020-05-23 11:41:12 +00:00
|
|
|
|
2020-03-19 09:36:36 +00:00
|
|
|
emit ioCacheChanged(enabled);
|
2020-05-23 11:41:12 +00:00
|
|
|
emit ioModeChanged();
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterCore::isIOCacheEnabled() const
|
|
|
|
{
|
|
|
|
return iocache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::commitWriteCache()
|
|
|
|
{
|
2020-05-23 11:41:12 +00:00
|
|
|
// Temporarily disable cache mode
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("io.cache", false);
|
2020-03-19 09:36:36 +00:00
|
|
|
if (!isWriteModeEnabled()) {
|
2020-05-23 11:41:12 +00:00
|
|
|
cmdRaw("oo+");
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("wci");
|
|
|
|
cmdRaw("oo");
|
2020-03-19 09:36:36 +00:00
|
|
|
} else {
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("wci");
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable or disable write-mode. Avoid unecessary changes if not need.
|
|
|
|
void CutterCore::setWriteMode(bool enabled)
|
|
|
|
{
|
|
|
|
bool writeModeState = isWriteModeEnabled();
|
|
|
|
|
2020-05-23 11:41:12 +00:00
|
|
|
if (writeModeState == enabled && !this->iocache) {
|
|
|
|
// New mode is the same as current and IO Cache is disabled. Do nothing.
|
2020-03-19 09:36:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2020-03-19 09:36:36 +00:00
|
|
|
// Change from read-only to write-mode
|
|
|
|
if (enabled && !writeModeState) {
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("oo+");
|
2021-01-24 14:50:13 +00:00
|
|
|
// Change from write-mode to read-only
|
2020-03-19 09:36:36 +00:00
|
|
|
} else {
|
2020-03-21 13:25:50 +00:00
|
|
|
cmdRaw("oo");
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
2020-05-23 11:41:12 +00:00
|
|
|
// Disable cache mode because we specifically set write or
|
|
|
|
// read-only modes.
|
|
|
|
setIOCache(false);
|
2021-01-24 14:50:13 +00:00
|
|
|
writeModeChanged(enabled);
|
2020-05-23 11:41:12 +00:00
|
|
|
emit ioModeChanged();
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterCore::isWriteModeEnabled()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
QJsonArray ans = cmdj("oj").array();
|
2021-01-24 14:50:13 +00:00
|
|
|
return find_if(begin(ans), end(ans),
|
|
|
|
[](const QJsonValue &v) { return v.toObject().value("raised").toBool(); })
|
|
|
|
->toObject()
|
|
|
|
.value("writable")
|
|
|
|
.toBool();
|
2020-03-19 09:36:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 08:43:34 +00:00
|
|
|
/**
|
|
|
|
* @brief get a compact disassembly preview for tooltips
|
|
|
|
* @param address - the address from which to print the disassembly
|
2021-01-24 14:50:13 +00:00
|
|
|
* @param num_of_lines - number of instructions to print
|
2019-04-22 08:43:34 +00:00
|
|
|
*/
|
|
|
|
QStringList CutterCore::getDisassemblyPreview(RVA address, int num_of_lines)
|
|
|
|
{
|
2021-01-24 14:50:13 +00:00
|
|
|
QList<DisassemblyLine> disassemblyLines;
|
|
|
|
{
|
|
|
|
// temporarily simplify the disasm output to get it colorful and simple to read
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.color", COLOR_MODE_16M)
|
2019-04-22 08:43:34 +00:00
|
|
|
.set("asm.lines", false)
|
|
|
|
.set("asm.var", false)
|
|
|
|
.set("asm.comments", false)
|
|
|
|
.set("asm.bytes", false)
|
|
|
|
.set("asm.lines.fcn", false)
|
|
|
|
.set("asm.lines.out", false)
|
|
|
|
.set("asm.lines.bb", false)
|
|
|
|
.set("asm.bb.line", false);
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
disassemblyLines = disassembleLines(address, num_of_lines + 1);
|
|
|
|
}
|
|
|
|
QStringList disasmPreview;
|
|
|
|
for (const DisassemblyLine &line : disassemblyLines) {
|
|
|
|
disasmPreview << line.text;
|
|
|
|
if (disasmPreview.length() >= num_of_lines) {
|
|
|
|
disasmPreview << "...";
|
|
|
|
break;
|
2019-04-22 08:43:34 +00:00
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
}
|
|
|
|
if (!disasmPreview.isEmpty()) {
|
|
|
|
return disasmPreview;
|
|
|
|
} else {
|
|
|
|
return QStringList();
|
|
|
|
}
|
2019-04-22 08:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get a compact hexdump preview for tooltips
|
|
|
|
* @param address - the address from which to print the hexdump
|
2021-01-24 14:50:13 +00:00
|
|
|
* @param size - number of bytes to print
|
2019-04-22 08:43:34 +00:00
|
|
|
*/
|
|
|
|
QString CutterCore::getHexdumpPreview(RVA address, int size)
|
2021-01-24 14:50:13 +00:00
|
|
|
{
|
2019-04-22 08:43:34 +00:00
|
|
|
// temporarily simplify the disasm output to get it colorful and simple to read
|
|
|
|
TempConfig tempConfig;
|
2021-01-24 14:50:13 +00:00
|
|
|
tempConfig.set("scr.color", COLOR_MODE_16M)
|
|
|
|
.set("asm.offset", true)
|
|
|
|
.set("hex.header", false)
|
|
|
|
.set("hex.cols", 16);
|
|
|
|
return ansiEscapeToHtml(hexdump(address, size, HexdumpFormats::Normal))
|
|
|
|
.replace(QLatin1Char('\n'), "<br>");
|
2019-04-22 08:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 16:03:48 +00:00
|
|
|
QByteArray CutterCore::ioRead(RVA addr, int len)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
|
|
|
|
QByteArray array;
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
return array;
|
|
|
|
|
|
|
|
/* Zero-copy */
|
|
|
|
array.resize(len);
|
2020-10-28 12:28:04 +00:00
|
|
|
if (!rz_io_read_at(core->io, addr, (uint8_t *)array.data(), len)) {
|
2019-05-16 16:03:48 +00:00
|
|
|
qWarning() << "Can't read data" << addr << len;
|
|
|
|
array.fill(0xff);
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
return array;
|
2019-05-16 16:03:48 +00:00
|
|
|
}
|