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>
|
|
|
|
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/TempConfig.h"
|
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/AsyncTask.h"
|
|
|
|
#include "common/R2Task.h"
|
2018-03-04 17:42:02 +00:00
|
|
|
#include "Cutter.h"
|
2017-09-25 12:55:41 +00:00
|
|
|
#include "sdb.h"
|
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
Q_GLOBAL_STATIC(ccClass, uniqueInstance)
|
2017-04-18 08:33:35 +00:00
|
|
|
|
2017-04-09 17:12:36 +00:00
|
|
|
RCoreLocked::RCoreLocked(RCore *core)
|
|
|
|
: core(core)
|
|
|
|
{
|
|
|
|
r_th_lock_enter(core->lock);
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
RCoreLocked::RCoreLocked(RCoreLocked &&o)
|
2017-04-09 18:42:45 +00:00
|
|
|
: core(o.core)
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
2017-04-09 18:42:45 +00:00
|
|
|
o.core = nullptr;
|
2017-04-09 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCoreLocked::~RCoreLocked()
|
|
|
|
{
|
|
|
|
r_th_lock_leave(core->lock);
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
RCoreLocked::operator RCore *() const
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
RCore *RCoreLocked::operator->() const
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
RCoreLocked CutterCore::core() const
|
2017-04-09 17:12:36 +00:00
|
|
|
{
|
|
|
|
return RCoreLocked(this->core_);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CORE_LOCK() RCoreLocked core_lock__(this->core_)
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
CutterCore::CutterCore(QObject *parent) :
|
2017-03-29 10:18:37 +00:00
|
|
|
QObject(parent)
|
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
r_cons_new(); // initialize console
|
|
|
|
this->core_ = r_core_new();
|
2018-05-25 14:30:59 +00:00
|
|
|
|
2018-04-15 12:41:10 +00:00
|
|
|
#if defined(APPIMAGE) || defined(MACOS_R2_BUNDLED)
|
|
|
|
auto prefix = QDir(QCoreApplication::applicationDirPath());
|
2018-09-05 05:46:40 +00:00
|
|
|
#ifdef APPIMAGE
|
2018-09-30 20:00:53 +00:00
|
|
|
// Executable is in appdir/bin
|
|
|
|
prefix.cdUp();
|
|
|
|
qInfo() << "Setting r2 prefix =" << prefix.absolutePath() << " for AppImage.";
|
2018-09-05 05:46:40 +00:00
|
|
|
#else // MACOS_R2_BUNDLED
|
2018-09-30 20:00:53 +00:00
|
|
|
// Executable is in Contents/MacOS, prefix is Contents/Resources/r2
|
|
|
|
prefix.cdUp();
|
|
|
|
prefix.cd("Resources");
|
|
|
|
prefix.cd("r2");
|
|
|
|
qInfo() << "Setting r2 prefix =" << prefix.absolutePath() << " for macOS Application Bundle.";
|
2018-09-05 05:46:40 +00:00
|
|
|
#endif
|
2018-04-15 12:41:10 +00:00
|
|
|
setConfig("dir.prefix", prefix.absolutePath());
|
|
|
|
#endif
|
2018-05-26 16:21:23 +00:00
|
|
|
|
2018-07-14 19:04:13 +00:00
|
|
|
r_core_loadlibs(this->core_, R_CORE_LOADLIBS_ALL, NULL);
|
|
|
|
// IMPLICIT r_bin_iobind (core_->bin, core_->io);
|
|
|
|
|
|
|
|
// Otherwise r2 may ask the user for input and Cutter would freeze
|
|
|
|
setConfig("scr.interactive", false);
|
|
|
|
|
2018-05-26 16:21:23 +00:00
|
|
|
asyncTaskManager = new AsyncTaskManager(this);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
CutterCore *CutterCore::getInstance()
|
|
|
|
{
|
|
|
|
return uniqueInstance;
|
|
|
|
}
|
|
|
|
|
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>();
|
2017-04-09 19:55:06 +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;
|
2018-03-21 20:32:32 +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;
|
|
|
|
}
|
|
|
|
|
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>();
|
2017-04-09 19:55:06 +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;
|
|
|
|
SdbList *l = sdb_foreach_list(root, false);
|
2018-03-21 20:32:32 +00:00
|
|
|
ls_foreach(l, iter, vsi) {
|
2017-04-09 19:55:06 +00:00
|
|
|
SdbKv *nsi = (SdbKv *)vsi;
|
2018-10-12 10:28:55 +00:00
|
|
|
list << 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();
|
2017-04-09 19:55:06 +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
|
|
|
}
|
2017-04-09 19:55:06 +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();
|
2017-04-09 19:55:06 +00:00
|
|
|
Sdb *db = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 1);
|
2017-03-29 10:18:37 +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
|
|
|
CutterCore::~CutterCore()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
r_core_free(this->core_);
|
|
|
|
r_cons_free();
|
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
|
|
|
{
|
|
|
|
static const QRegExp regexp(";|@");
|
|
|
|
return s.replace(regexp, "_");
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:11:30 +00:00
|
|
|
/**
|
|
|
|
* @brief CutterCore::cmd send a command to radare2
|
|
|
|
* @param str the command you want to execute
|
|
|
|
* Note that if you want to seek to an address, you should use CutterCore::seek
|
|
|
|
* @return command output
|
|
|
|
*/
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::cmd(const QString &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
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
RVA offset = core_->offset;
|
2017-03-30 21:49:51 +00:00
|
|
|
QByteArray cmd = str.toUtf8();
|
2018-05-29 16:19:59 +00:00
|
|
|
r_core_task_sync_begin(core_);
|
2017-04-09 19:55:06 +00:00
|
|
|
char *res = r_core_cmd_str(this->core_, cmd.constData());
|
2018-05-29 16:19:59 +00:00
|
|
|
r_core_task_sync_end(core_);
|
2017-03-30 21:49:51 +00:00
|
|
|
QString o = QString(res ? res : "");
|
2017-03-30 03:07:34 +00:00
|
|
|
r_mem_free(res);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset != core_->offset) {
|
2017-10-09 18:08:35 +00:00
|
|
|
emit seekChanged(core_->offset);
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-12-20 22:50:26 +00:00
|
|
|
QString CutterCore::cmdRaw(const QString &str)
|
|
|
|
{
|
|
|
|
QString cmdStr = str;
|
|
|
|
cmdStr.replace('\"', "\\\"");
|
|
|
|
return cmd("\"" + cmdStr + "\"");
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QJsonDocument CutterCore::cmdj(const QString &str)
|
2017-04-18 08:33:35 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QByteArray cmd = str.toUtf8();
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2018-05-29 16:19:59 +00:00
|
|
|
r_core_task_sync_begin(core_);
|
2017-04-18 08:33:35 +00:00
|
|
|
char *res = r_core_cmd_str(this->core_, cmd.constData());
|
2018-05-29 16:19:59 +00:00
|
|
|
r_core_task_sync_end(core_);
|
|
|
|
QJsonDocument doc = parseJson(res, str);
|
|
|
|
r_mem_free(res);
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2018-05-29 16:19:59 +00:00
|
|
|
QString CutterCore::cmdTask(const QString &str)
|
|
|
|
{
|
2018-07-22 13:04:13 +00:00
|
|
|
R2Task task(str);
|
|
|
|
task.startTask();
|
|
|
|
task.joinTask();
|
|
|
|
return task.getResult();
|
2018-05-29 16:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument CutterCore::cmdjTask(const QString &str)
|
|
|
|
{
|
2018-07-22 13:04:13 +00:00
|
|
|
R2Task task(str);
|
|
|
|
task.startTask();
|
|
|
|
task.joinTask();
|
|
|
|
return parseJson(task.getResultRaw(), str);
|
2018-05-29 16:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument CutterCore::parseJson(const char *res, const QString &cmd)
|
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
QString resString = QString(res);
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (resString.isEmpty()) {
|
2017-11-25 14:15:58 +00:00
|
|
|
return QJsonDocument();
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonParseError jsonError;
|
|
|
|
QJsonDocument doc = res ? QJsonDocument::fromJson(resString.toUtf8(), &jsonError) : QJsonDocument();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (jsonError.error != QJsonParseError::NoError) {
|
2018-05-29 16:19:59 +00:00
|
|
|
if (!cmd.isNull()) {
|
|
|
|
eprintf("Failed to parse JSON for command \"%s\": %s\n", cmd.toLocal8Bit().constData(),
|
|
|
|
jsonError.errorString().toLocal8Bit().constData());
|
|
|
|
} else {
|
|
|
|
eprintf("Failed to parse JSON: %s\n", jsonError.errorString().toLocal8Bit().constData());
|
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
eprintf("%s\n", resString.toLocal8Bit().constData());
|
|
|
|
}
|
|
|
|
|
2017-04-18 08:33:35 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2018-06-20 09:24:28 +00:00
|
|
|
/**
|
|
|
|
* @brief CutterCore::loadFile
|
|
|
|
* Load initial file. TODO Maybe use the "o" commands?
|
|
|
|
* @param path File path
|
|
|
|
* @param baddr Base (RBin) address
|
|
|
|
* @param mapaddr Map address
|
|
|
|
* @param perms
|
|
|
|
* @param va
|
|
|
|
* @param loadbin Load RBin information
|
|
|
|
* @param forceBinPlugin
|
|
|
|
* @return
|
|
|
|
*/
|
2018-05-05 13:20:14 +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();
|
2017-03-29 10:18:37 +00:00
|
|
|
RCoreFile *f;
|
2018-05-05 13:20:14 +00:00
|
|
|
r_config_set_i(core_->config, "io.va", va);
|
2017-11-25 13:21:01 +00:00
|
|
|
|
2018-02-27 10:20:48 +00:00
|
|
|
f = r_core_file_open(core_, path.toUtf8().constData(), perms, mapaddr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!f) {
|
2017-04-09 19:55:06 +00:00
|
|
|
eprintf("r_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()) {
|
2017-09-29 11:32:53 +00:00
|
|
|
r_bin_force_plugin(r_core_get_bin(core_), forceBinPlugin.toUtf8().constData());
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
if (loadbin && va) {
|
|
|
|
if (!r_core_bin_load(core_, path.toUtf8().constData(), baddr)) {
|
|
|
|
eprintf("CANNOT GET RBIN INFO\n");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | (rw ? R_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 {
|
2017-03-29 10:18:37 +00:00
|
|
|
// load RBin information
|
|
|
|
// XXX only for sub-bins
|
2018-05-05 13:20:14 +00:00
|
|
|
r_core_bin_load(core, path.toUtf8(), baddr);
|
2017-04-09 19:55:06 +00:00
|
|
|
r_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 {
|
2017-03-29 10:18:37 +00:00
|
|
|
// Not loading RBin info coz va = false
|
|
|
|
}
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2018-03-01 12:16:23 +00:00
|
|
|
auto iod = core_->io ? core_->io->desc : NULL;
|
|
|
|
auto debug = core_->file && iod && (core_->file->fd == iod->fd) && iod->plugin && \
|
2018-03-21 20:32:32 +00:00
|
|
|
iod->plugin->isdbg;
|
2018-03-01 12:16:23 +00:00
|
|
|
|
|
|
|
if (!debug && r_flag_get (core_->flags, "entry0")) {
|
2018-03-21 20:32:32 +00:00
|
|
|
r_core_cmd0 (core_, "s entry0");
|
2018-03-01 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 16:00:21 +00:00
|
|
|
if (perms & R_PERM_W) {
|
2018-03-21 20:32:32 +00:00
|
|
|
r_core_cmd0 (core_, "omfg+w");
|
2018-03-01 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 17:12:36 +00:00
|
|
|
r_core_hash_load(core_, path.toUtf8().constData());
|
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();
|
|
|
|
RCoreFile *cf;
|
2018-09-22 16:00:21 +00:00
|
|
|
int flags = R_PERM_R;
|
|
|
|
if (rw) flags = R_PERM_RW;
|
2018-06-20 09:24:28 +00:00
|
|
|
cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL);
|
|
|
|
if (!cf) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_core_file_close (this->core_, cf);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::openFile(QString path, RVA mapaddr)
|
|
|
|
{
|
|
|
|
if (mapaddr != RVA_INVALID) {
|
|
|
|
cmd("o " + path + QString(" %1").arg(mapaddr));
|
|
|
|
} else {
|
|
|
|
cmd("o " + path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 22:50:26 +00:00
|
|
|
void CutterCore::renameFunction(const QString &oldName, const QString &newName)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-12-20 22:50:26 +00:00
|
|
|
cmdRaw("afn " + newName + " " + oldName);
|
|
|
|
emit functionRenamed(oldName, newName);
|
2017-11-27 08:22:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void CutterCore::delFunction(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("af- " + RAddressString(addr));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void CutterCore::delFlag(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("f-@" + RAddressString(addr));
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return cmdj("aoj @ " + RAddressString(addr)).array().first().toObject()["bytes"].toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::getInstructionOpcode(RVA addr)
|
|
|
|
{
|
|
|
|
return cmdj("aoj @ " + RAddressString(addr)).array().first().toObject()["opcode"].toString();
|
|
|
|
}
|
|
|
|
|
2018-02-12 20:12:13 +00:00
|
|
|
void CutterCore::editInstruction(RVA addr, const QString &inst)
|
|
|
|
{
|
2018-02-27 10:20:48 +00:00
|
|
|
cmd("wa " + inst + " @ " + RAddressString(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)
|
|
|
|
{
|
|
|
|
cmd("wao nop @ " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-03-10 07:27:09 +00:00
|
|
|
void CutterCore::jmpReverse(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("wao recj @ " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
2018-02-12 20:12:13 +00:00
|
|
|
void CutterCore::editBytes(RVA addr, const QString &bytes)
|
|
|
|
{
|
2018-02-27 10:20:48 +00:00
|
|
|
cmd("wx " + bytes + " @ " + RAddressString(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)
|
|
|
|
{
|
|
|
|
cmd("wv " + bytes + " @ " + RAddressString(addr));
|
|
|
|
emit stackChanged();
|
|
|
|
}
|
|
|
|
|
2018-08-04 18:05:56 +00:00
|
|
|
void CutterCore::setToCode(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("Cd- @ " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setToData(RVA addr, int size, int repeat)
|
|
|
|
{
|
|
|
|
if (size <= 0 || repeat <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cmd("Cd- @ " + RAddressString(addr));
|
|
|
|
cmd(QString::asprintf("Cd %d %d @ %lld", size, repeat, addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CutterCore::sizeofDataMeta(RVA addr)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int size = cmd("Cd. @ " + RAddressString(addr)).toInt(&ok);
|
|
|
|
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
|
|
|
{
|
2017-11-08 09:18:07 +00:00
|
|
|
cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr));
|
2017-07-11 11:05:42 +00:00
|
|
|
emit commentsChanged();
|
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
|
|
|
{
|
2017-11-02 06:48:32 +00:00
|
|
|
cmd("CC- @ " + QString::number(addr));
|
|
|
|
emit commentsChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 13:13:22 +00:00
|
|
|
void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2017-11-28 13:13:22 +00:00
|
|
|
offset = getOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->cmd("ahi " + r2BaseName + " @ " + QString::number(offset));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->cmd("ahb " + QString::number(bits) + " @ " + QString::number(offset));
|
|
|
|
emit instructionChanged(offset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// which means we either have to duplicate code from radare2
|
|
|
|
// here, or refactor radare2 API.
|
|
|
|
CORE_LOCK();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2018-01-27 13:11:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
cmd(QString("s %1").arg(offset));
|
2017-11-02 06:48:32 +00:00
|
|
|
// cmd already does emit seekChanged(core_->offset);
|
2018-05-24 13:42:27 +00:00
|
|
|
triggerRaisePrioritizedMemoryWidget();
|
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));
|
2018-05-24 13:42:27 +00:00
|
|
|
triggerRaisePrioritizedMemoryWidget();
|
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
|
|
|
{
|
2017-10-16 19:00:47 +00:00
|
|
|
cmd("s-");
|
2018-05-24 13:42:27 +00:00
|
|
|
triggerRaisePrioritizedMemoryWidget();
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 19:00:47 +00:00
|
|
|
void CutterCore::seekNext()
|
|
|
|
{
|
|
|
|
cmd("s+");
|
2018-05-24 13:42:27 +00:00
|
|
|
triggerRaisePrioritizedMemoryWidget();
|
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()
|
|
|
|
{
|
|
|
|
emit seekChanged(core_->offset);
|
|
|
|
}
|
|
|
|
|
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;
|
2018-03-21 20:32:32 +00:00
|
|
|
RVA offset = cmd("/O " + QString::number(count) + " @ " + QString::number(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();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
QJsonArray array = Core()->cmdj("pdj " + QString::number(count + 1) + "@" + QString::number(
|
|
|
|
startAddr)).array();
|
|
|
|
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;
|
|
|
|
RVA offset = instValue.toObject()["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();
|
2017-04-09 19:55:06 +00:00
|
|
|
return r_num_math(this->core_ ? this->core_->num : NULL, expr.toUtf8().constData());
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 14:36:40 +00:00
|
|
|
void CutterCore::setConfig(const QString &k, const QString &v)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2017-10-01 14:36:40 +00:00
|
|
|
r_config_set(core_->config, k.toUtf8().constData(), v.toUtf8().constData());
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 14:36:40 +00:00
|
|
|
void CutterCore::setConfig(const QString &k, int v)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2018-06-26 16:17:03 +00:00
|
|
|
r_config_set_i(core_->config, k.toUtf8().constData(), static_cast<ut64>(v));
|
2017-10-01 14:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setConfig(const QString &k, bool v)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
r_config_set_i(core_->config, k.toUtf8().constData(), v ? 1 : 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
int CutterCore::getConfigi(const QString &k)
|
2017-08-31 17:43:46 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QByteArray key = k.toUtf8();
|
2017-10-01 14:36:40 +00:00
|
|
|
return static_cast<int>(r_config_get_i(core_->config, key.constData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterCore::getConfigb(const QString &k)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
return r_config_get_i(core_->config, k.toUtf8().constData()) != 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::getConfig(const QString &k)
|
2017-09-02 08:17:48 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QByteArray key = k.toUtf8();
|
|
|
|
return QString(r_config_get(core_->config, key.constData()));
|
|
|
|
}
|
|
|
|
|
2018-03-22 08:42:54 +00:00
|
|
|
void CutterCore::setConfig(const QString &k, const QVariant &v)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2018-03-07 12:02:39 +00:00
|
|
|
void CutterCore::setBBSize(int size)
|
|
|
|
{
|
|
|
|
setConfig("anal.bb.maxsize", size);
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::assemble(const QString &code)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
2017-04-09 19:55:06 +00:00
|
|
|
RAsmCode *ac = r_asm_massemble(core_->assembler, code.toUtf8().constData());
|
2017-04-09 02:49:16 +00:00
|
|
|
QString hex(ac != nullptr ? ac->buf_hex : "");
|
2017-04-09 19:55:06 +00:00
|
|
|
r_asm_code_free(ac);
|
2017-03-29 10:18:37 +00:00
|
|
|
return hex;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QString CutterCore::disassemble(const QString &hex)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
RAsmCode *ac = r_asm_mdisassemble_hexstr(core_->assembler, hex.toUtf8().constData());
|
2017-04-09 19:55:06 +00:00
|
|
|
QString code = QString(ac != nullptr ? ac->buf_asm : "");
|
|
|
|
r_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
|
|
|
{
|
|
|
|
return cmd("pi 1@" + QString::number(addr)).simplified();
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
RAnalFunction *CutterCore::functionAt(ut64 addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-09 17:12:36 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
//return r_anal_fcn_find (core_->anal, addr, addr);
|
2017-04-09 19:55:06 +00:00
|
|
|
return r_anal_get_fcn_in(core_->anal, addr, 0);
|
2017-03-29 10:18:37 +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;
|
|
|
|
//afi~name:1[1] @ 0x08048e44
|
|
|
|
//ret = cmd("afi~name[1] @ " + addr);
|
2017-04-28 13:09:40 +00:00
|
|
|
ret = cmd(QString("fd @ ") + addr + "~[0]");
|
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-07-27 12:00:23 +00:00
|
|
|
void CutterCore::cmdEsil(QString command)
|
|
|
|
{
|
|
|
|
QString res = cmd(command);
|
|
|
|
if (res.contains("[ESIL] Stopped execution in an invalid instruction")) {
|
|
|
|
msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can disable this in Preferences");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 20:40:15 +00:00
|
|
|
QString CutterCore::createFunctionAt(RVA addr, QString name)
|
|
|
|
{
|
|
|
|
name.remove(QRegExp("[^a-zA-Z0-9_]"));
|
|
|
|
QString command = "af " + name + " " + RAddressString(addr);
|
|
|
|
QString ret = cmd(command);
|
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;
|
2018-03-21 20:32:32 +00:00
|
|
|
RVA value = cmdj("aoj @" + QString::number(
|
|
|
|
addr)).array().first().toObject().value("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
|
|
|
}
|
|
|
|
|
2018-09-08 07:12:08 +00:00
|
|
|
QString CutterCore::getDecompiledCodePDC(RVA addr)
|
2017-12-06 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cmd("pdc @ " + QString::number(addr));
|
|
|
|
}
|
|
|
|
|
2018-09-08 07:12:08 +00:00
|
|
|
bool CutterCore::getR2DecAvailable()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-09-08 07:12:08 +00:00
|
|
|
return cmd("e cmd.pdc=?").split('\n').contains("r2dec");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-08 07:12:08 +00:00
|
|
|
QString CutterCore::getDecompiledCodeR2Dec(RVA addr)
|
|
|
|
{
|
|
|
|
return cmd("pdd @ " + QString::number(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
QJsonDocument CutterCore::getStack(int size)
|
|
|
|
{
|
|
|
|
return cmdj("pxrj " + QString::number(size) + " @ r:SP");
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument CutterCore::getRegisterValues()
|
|
|
|
{
|
|
|
|
return cmdj("drj");
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:35:46 +00:00
|
|
|
QList<RegisterRefDescription> CutterCore::getRegisterRefs()
|
|
|
|
{
|
|
|
|
QList<RegisterRefDescription> ret;
|
|
|
|
QJsonArray registerRefArray = cmdj("drrj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : registerRefArray) {
|
|
|
|
QJsonObject regRefObject = value.toObject();
|
|
|
|
|
|
|
|
RegisterRefDescription regRef;
|
|
|
|
|
|
|
|
regRef.reg = regRefObject["reg"].toString();
|
|
|
|
regRef.value = regRefObject["value"].toString();
|
|
|
|
regRef.ref = regRefObject["ref"].toString();
|
|
|
|
|
|
|
|
ret << regRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-25 22:17:58 +00:00
|
|
|
QJsonObject CutterCore::getRegisterJson()
|
|
|
|
{
|
|
|
|
QJsonArray registerRefArray = cmdj("drrj").array();
|
|
|
|
QJsonObject registerJson;
|
|
|
|
for (QJsonValue value : registerRefArray) {
|
|
|
|
QJsonObject regRefObject = value.toObject();
|
|
|
|
|
|
|
|
QJsonObject registers;
|
|
|
|
registers.insert("value", regRefObject["value"]);
|
|
|
|
registers.insert("ref", regRefObject["ref"]);
|
|
|
|
registerJson.insert(regRefObject["reg"].toString(), registers);
|
|
|
|
}
|
|
|
|
return registerJson;
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
QString CutterCore::getRegisterName(QString registerRole)
|
|
|
|
{
|
|
|
|
return cmd("drn " + registerRole).trimmed();
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:57:15 +00:00
|
|
|
RVA CutterCore::getProgramCounterValue()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
if (currentlyDebugging) {
|
|
|
|
RVA addr = cmd("dr?`drn PC`").toULongLong(&ok, 16);
|
|
|
|
if (ok) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:05:20 +00:00
|
|
|
void CutterCore::setRegister(QString regName, QString regValue)
|
|
|
|
{
|
|
|
|
cmd("dr " + regName + "=" + 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
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::startDebug()
|
|
|
|
{
|
2018-06-15 17:33:17 +00:00
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
2018-08-06 14:48:28 +00:00
|
|
|
cmd("ood");
|
2018-06-12 08:43:14 +00:00
|
|
|
emit registersChanged();
|
2018-06-15 17:33:17 +00:00
|
|
|
if (!currentlyDebugging) {
|
2018-07-01 21:29:38 +00:00
|
|
|
setConfig("asm.flags", false);
|
2018-07-18 10:15:10 +00:00
|
|
|
currentlyDebugging = true;
|
2018-06-15 17:33:17 +00:00
|
|
|
emit changeDebugView();
|
2018-07-01 21:29:38 +00:00
|
|
|
emit flagsChanged();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
}
|
2018-07-24 23:15:38 +00:00
|
|
|
emit stackChanged();
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::startEmulation()
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
|
|
|
// clear registers, init esil state, stack, progcounter at current seek
|
|
|
|
cmd("ar0; aei; aeim; aeip");
|
|
|
|
emit registersChanged();
|
|
|
|
if (!currentlyDebugging || !currentlyEmulating) {
|
|
|
|
// prevent register flags from appearing during debug/emul
|
2018-10-03 11:30:12 +00:00
|
|
|
setConfig("asm.flags", false);
|
2018-07-01 21:29:38 +00:00
|
|
|
// allows to view self-modifying code changes or other binary changes
|
|
|
|
setConfig("io.cache", true);
|
2018-07-18 10:15:10 +00:00
|
|
|
currentlyDebugging = true;
|
|
|
|
currentlyEmulating = true;
|
2018-07-01 21:29:38 +00:00
|
|
|
emit changeDebugView();
|
|
|
|
emit flagsChanged();
|
|
|
|
}
|
2018-07-24 23:15:38 +00:00
|
|
|
emit stackChanged();
|
2018-07-23 23:13:09 +00:00
|
|
|
emit refreshCodeViews();
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::attachDebug(int pid)
|
|
|
|
{
|
|
|
|
if (!currentlyDebugging) {
|
|
|
|
offsetPriorDebugging = getOffset();
|
|
|
|
}
|
|
|
|
// attach to process with dbg plugin
|
|
|
|
cmd("o-*; e cfg.debug = true; o+ dbg://" + QString::number(pid));
|
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
if (!currentlyDebugging || !currentlyEmulating) {
|
|
|
|
// prevent register flags from appearing during debug/emul
|
|
|
|
setConfig("asm.flags", false);
|
2018-07-18 10:15:10 +00:00
|
|
|
currentlyDebugging = true;
|
2018-07-31 17:16:05 +00:00
|
|
|
currentlyOpenFile = getConfig("file.path");
|
|
|
|
currentlyAttachedToPID = pid;
|
2018-07-01 21:29:38 +00:00
|
|
|
emit flagsChanged();
|
2018-07-23 23:13:09 +00:00
|
|
|
emit changeDebugView();
|
2018-06-15 17:33:17 +00:00
|
|
|
}
|
2018-06-12 15:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stopDebug()
|
|
|
|
{
|
2018-06-22 15:57:15 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyEmulating) {
|
|
|
|
cmd("aeim-; aei-; wcr; .ar-");
|
|
|
|
currentlyEmulating = false;
|
2018-07-31 17:16:05 +00:00
|
|
|
} else if (currentlyAttachedToPID != -1) {
|
|
|
|
cmd(QString("dp- %1; o %2; .ar-").arg(QString::number(currentlyAttachedToPID), currentlyOpenFile));
|
|
|
|
currentlyAttachedToPID = -1;
|
2018-07-01 21:29:38 +00:00
|
|
|
} else {
|
2018-07-31 17:16:05 +00:00
|
|
|
cmd("dk 9; oo; .ar-");
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
2018-06-22 15:57:15 +00:00
|
|
|
seek(offsetPriorDebugging);
|
2018-07-01 21:29:38 +00:00
|
|
|
setConfig("asm.flags", true);
|
|
|
|
setConfig("io.cache", false);
|
2018-06-22 15:57:15 +00:00
|
|
|
currentlyDebugging = false;
|
2018-07-01 21:29:38 +00:00
|
|
|
emit flagsChanged();
|
2018-07-23 23:13:09 +00:00
|
|
|
emit changeDefinedView();
|
2018-06-22 15:57:15 +00:00
|
|
|
}
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueDebug()
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-08-06 11:48:26 +00:00
|
|
|
if (currentlyEmulating) {
|
|
|
|
cmdEsil("aec");
|
|
|
|
} else {
|
|
|
|
cmd("dc");
|
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
emit registersChanged();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
}
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueUntilDebug(QString offset)
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-08-06 12:19:52 +00:00
|
|
|
if (currentlyEmulating) {
|
2018-07-27 12:00:23 +00:00
|
|
|
cmdEsil("aecu " + offset);
|
2018-08-06 12:19:52 +00:00
|
|
|
} else {
|
|
|
|
cmd("dcu " + offset);
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
emit registersChanged();
|
|
|
|
emit refreshCodeViews();
|
|
|
|
}
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 23:02:16 +00:00
|
|
|
void CutterCore::continueUntilCall()
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-07-30 06:55:58 +00:00
|
|
|
if (currentlyEmulating) {
|
|
|
|
cmdEsil("aecc");
|
|
|
|
} else {
|
|
|
|
cmd("dcc");
|
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
}
|
2018-06-13 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::continueUntilSyscall()
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
|
|
|
if (currentlyEmulating) {
|
2018-07-27 12:00:23 +00:00
|
|
|
cmdEsil("aecs");
|
2018-07-01 21:29:38 +00:00
|
|
|
} else {
|
|
|
|
cmd("dcs");
|
|
|
|
}
|
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
}
|
2018-06-13 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
void CutterCore::stepDebug()
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-07-27 12:00:23 +00:00
|
|
|
cmdEsil("ds");
|
2018-07-01 21:29:38 +00:00
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
}
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::stepOverDebug()
|
|
|
|
{
|
2018-07-01 21:29:38 +00:00
|
|
|
if (currentlyDebugging) {
|
2018-07-27 12:00:23 +00:00
|
|
|
cmdEsil("dso");
|
2018-07-01 21:29:38 +00:00
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
}
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 06:55:39 +00:00
|
|
|
void CutterCore::stepOutDebug()
|
|
|
|
{
|
|
|
|
if (currentlyDebugging) {
|
|
|
|
cmd("dsf");
|
|
|
|
QString programCounterValue = cmd("dr?`drn PC`").trimmed();
|
|
|
|
seek(programCounterValue);
|
|
|
|
emit registersChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 11:49:22 +00:00
|
|
|
QStringList CutterCore::getDebugPlugins()
|
|
|
|
{
|
|
|
|
QStringList plugins;
|
|
|
|
QJsonArray pluginArray = cmdj("dLj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : pluginArray) {
|
|
|
|
QJsonObject pluginObject = value.toObject();
|
|
|
|
QString plugin = pluginObject["name"].toString();
|
|
|
|
plugins << plugin;
|
|
|
|
}
|
|
|
|
return plugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CutterCore::getActiveDebugPlugin()
|
|
|
|
{
|
|
|
|
return getConfig("dbg.backend");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::setDebugPlugin(QString plugin)
|
|
|
|
{
|
|
|
|
setConfig("dbg.backend", plugin);
|
|
|
|
}
|
|
|
|
|
2018-07-17 07:26:20 +00:00
|
|
|
void CutterCore::toggleBreakpoint(RVA addr)
|
2018-06-12 08:43:14 +00:00
|
|
|
{
|
2018-07-17 07:26:20 +00:00
|
|
|
cmd("dbs " + RAddressString(addr));
|
2018-06-12 08:43:14 +00:00
|
|
|
emit instructionChanged(addr);
|
2018-06-22 08:45:00 +00:00
|
|
|
emit breakpointsChanged();
|
|
|
|
}
|
|
|
|
|
2018-07-17 07:26:20 +00:00
|
|
|
void CutterCore::toggleBreakpoint(QString addr)
|
2018-06-26 07:38:44 +00:00
|
|
|
{
|
2018-07-17 07:26:20 +00:00
|
|
|
cmd("dbs " + addr);
|
2018-06-26 07:38:44 +00:00
|
|
|
emit instructionChanged(addr.toULongLong());
|
|
|
|
emit breakpointsChanged();
|
|
|
|
}
|
|
|
|
|
2018-06-22 08:45:00 +00:00
|
|
|
void CutterCore::delBreakpoint(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("db- " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
emit breakpointsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::delAllBreakpoints()
|
|
|
|
{
|
|
|
|
cmd("db-*");
|
2018-07-01 21:29:38 +00:00
|
|
|
emit refreshCodeViews();
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::enableBreakpoint(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("dbe " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
emit breakpointsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::disableBreakpoint(RVA addr)
|
|
|
|
{
|
|
|
|
cmd("dbd " + RAddressString(addr));
|
|
|
|
emit instructionChanged(addr);
|
|
|
|
emit breakpointsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<BreakpointDescription> CutterCore::getBreakpoints()
|
|
|
|
{
|
|
|
|
QList<BreakpointDescription> ret;
|
|
|
|
QJsonArray breakpointArray = cmdj("dbj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : breakpointArray) {
|
|
|
|
QJsonObject bpObject = value.toObject();
|
|
|
|
|
|
|
|
BreakpointDescription bp;
|
|
|
|
|
|
|
|
bp.addr = bpObject["addr"].toVariant().toULongLong();
|
|
|
|
bp.size = bpObject["size"].toVariant().toInt();
|
|
|
|
bp.permission = bpObject["prot"].toString();
|
|
|
|
bp.hw = bpObject["hw"].toBool();
|
|
|
|
bp.trace = bpObject["trace"].toBool();
|
|
|
|
bp.enabled = bpObject["enabled"].toBool();
|
|
|
|
|
|
|
|
ret << bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-06-06 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 16:20:16 +00:00
|
|
|
|
|
|
|
QList<RVA> CutterCore::getBreakpointsAddresses()
|
|
|
|
{
|
|
|
|
QList<BreakpointDescription> bps = getBreakpoints();
|
|
|
|
BreakpointDescription bp;
|
|
|
|
QList<RVA> bpAddresses;
|
2018-09-30 20:00:53 +00:00
|
|
|
foreach (bp, bps) {
|
2018-08-12 16:20:16 +00:00
|
|
|
bpAddresses << bp.addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bpAddresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterCore::isBreakpoint(QList<RVA> breakpoints, RVA addr)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
QJsonArray ProcessArray = cmdj("dplj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : ProcessArray) {
|
|
|
|
QJsonObject procObject = value.toObject();
|
|
|
|
|
|
|
|
ProcessDescription proc;
|
|
|
|
|
|
|
|
proc.pid = procObject["pid"].toVariant().toInt();
|
|
|
|
proc.uid = procObject["uid"].toVariant().toInt();
|
|
|
|
proc.status = procObject["status"].toString();
|
|
|
|
proc.path = procObject["path"].toString();
|
|
|
|
|
|
|
|
ret << proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
QList<MemoryMapDescription> CutterCore::getMemoryMap()
|
|
|
|
{
|
|
|
|
QList<MemoryMapDescription> ret;
|
|
|
|
QJsonArray memoryMapArray = cmdj("dmj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : memoryMapArray) {
|
|
|
|
QJsonObject memMapObject = value.toObject();
|
|
|
|
|
|
|
|
MemoryMapDescription memMap;
|
|
|
|
|
|
|
|
memMap.name = memMapObject["name"].toString();
|
|
|
|
memMap.fileName = memMapObject["file"].toString();
|
|
|
|
memMap.addrStart = memMapObject["addr"].toVariant().toULongLong();
|
|
|
|
memMap.addrEnd = memMapObject["addr_end"].toVariant().toULongLong();
|
|
|
|
memMap.type = memMapObject["type"].toString();
|
|
|
|
memMap.permission = memMapObject["perm"].toString();
|
|
|
|
|
|
|
|
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;
|
|
|
|
cmd("fs functions");
|
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
|
|
|
|
QString imps = cmd("ii~?").trimmed();
|
|
|
|
stats << imps;
|
|
|
|
|
|
|
|
cmd("fs symbols");
|
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
cmd("fs strings");
|
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
cmd("fs relocs");
|
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
cmd("fs sections");
|
|
|
|
stats << cmd("f~?").trimmed();
|
|
|
|
cmd("fs *");
|
|
|
|
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
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QString opcodes = cmd("?O");
|
|
|
|
this->opcodes = opcodes.split("\n");
|
|
|
|
// Remove the last empty element
|
|
|
|
this->opcodes.removeLast();
|
|
|
|
QString registers = cmd("drp~[1]");
|
|
|
|
this->regs = registers.split("\n");
|
|
|
|
this->regs.removeLast();
|
|
|
|
}
|
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
|
|
|
|
2018-03-07 07:52:13 +00:00
|
|
|
setConfig("anal.hasnext", false);
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("asm.lines.call", false);
|
|
|
|
setConfig("anal.autoname", true);
|
2017-08-31 17:43:46 +00:00
|
|
|
|
2017-10-01 14:36:40 +00:00
|
|
|
setConfig("cfg.fortunes.tts", false);
|
2017-03-30 16:47:50 +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;
|
|
|
|
|
|
|
|
QJsonArray jsonArray = cmdj("sj").array();
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : jsonArray)
|
2017-04-28 13:09:40 +00:00
|
|
|
ret << value.toVariant().toULongLong();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QStringList CutterCore::getAsmPluginNames()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
RListIter *it;
|
|
|
|
QStringList ret;
|
|
|
|
|
|
|
|
RAsmPlugin *ap;
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterRListForeach(core_->assembler->plugins, it, RAsmPlugin, ap) {
|
2017-05-03 09:09:57 +00:00
|
|
|
ret << ap->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QStringList CutterCore::getAnalPluginNames()
|
2017-05-03 09:09:57 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
RListIter *it;
|
|
|
|
QStringList ret;
|
|
|
|
|
|
|
|
RAnalPlugin *ap;
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterRListForeach(core_->anal->plugins, it, RAnalPlugin, ap) {
|
2017-05-03 09:09:57 +00:00
|
|
|
ret << ap->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:55:41 +00:00
|
|
|
QStringList CutterCore::getProjectNames()
|
2017-05-13 18:09:36 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QStringList ret;
|
|
|
|
|
2018-04-11 09:44:01 +00:00
|
|
|
QJsonArray jsonArray = cmdj("Pj").array();
|
2017-06-03 12:27:23 +00:00
|
|
|
for (QJsonValue value : jsonArray)
|
2017-05-13 18:09:36 +00:00
|
|
|
ret.append(value.toString());
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-29 11:32:53 +00:00
|
|
|
QList<RBinPluginDescription> CutterCore::getRBinPluginDescriptions(const QString &type)
|
|
|
|
{
|
|
|
|
QList<RBinPluginDescription> ret;
|
|
|
|
|
|
|
|
QJsonObject jsonRoot = cmdj("iLj").object();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (const QString &key : jsonRoot.keys()) {
|
2017-09-29 11:32:53 +00:00
|
|
|
if (!type.isNull() && key != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QJsonArray pluginArray = jsonRoot[key].toArray();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (const auto &pluginValue : pluginArray) {
|
2017-09-29 11:32:53 +00:00
|
|
|
QJsonObject pluginObject = pluginValue.toObject();
|
|
|
|
RBinPluginDescription desc;
|
|
|
|
desc.name = pluginObject["name"].toString();
|
|
|
|
desc.description = pluginObject["description"].toString();
|
|
|
|
desc.license = pluginObject["license"].toString();
|
|
|
|
desc.type = key;
|
|
|
|
ret.append(desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-09 15:05:40 +00:00
|
|
|
QList<RIOPluginDescription> CutterCore::getRIOPluginDescriptions()
|
|
|
|
{
|
|
|
|
QList<RIOPluginDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray plugins = cmdj("oLj").object()["IO_Plugins"].toArray();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef pluginValue : plugins) {
|
2018-03-09 15:05:40 +00:00
|
|
|
QJsonObject pluginObject = pluginValue.toObject();
|
|
|
|
RIOPluginDescription plugin;
|
|
|
|
|
|
|
|
plugin.name = pluginObject["Name"].toString();
|
|
|
|
plugin.description = pluginObject["Description"].toString();
|
|
|
|
plugin.license = pluginObject["License"].toString();
|
|
|
|
plugin.permissions = pluginObject["Permissions"].toString();
|
|
|
|
|
|
|
|
ret << plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<RCorePluginDescription> CutterCore::getRCorePluginDescriptions()
|
|
|
|
{
|
|
|
|
QList<RCorePluginDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray plugins = cmdj("Lsj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef pluginValue : plugins) {
|
2018-03-09 15:05:40 +00:00
|
|
|
QJsonObject pluginObject = pluginValue.toObject();
|
|
|
|
RCorePluginDescription plugin;
|
|
|
|
|
|
|
|
plugin.name = pluginObject["Name"].toString();
|
|
|
|
plugin.description = pluginObject["Description"].toString();
|
|
|
|
|
|
|
|
ret << plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-11 08:39:31 +00:00
|
|
|
QList<RAsmPluginDescription> CutterCore::getRAsmPluginDescriptions()
|
2018-03-09 15:05:40 +00:00
|
|
|
{
|
2018-03-11 08:39:31 +00:00
|
|
|
CORE_LOCK();
|
|
|
|
RListIter *it;
|
|
|
|
QList<RAsmPluginDescription> ret;
|
2018-03-09 15:05:40 +00:00
|
|
|
|
2018-03-11 08:39:31 +00:00
|
|
|
RAsmPlugin *ap;
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterRListForeach(core_->assembler->plugins, it, RAsmPlugin, ap) {
|
2018-03-11 08:39:31 +00:00
|
|
|
RAsmPluginDescription plugin;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2018-06-25 19:28:34 +00:00
|
|
|
return parseFunctionsJson(cmdjTask("aflj"));
|
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-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : importsArray) {
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonObject importObject = value.toObject();
|
|
|
|
|
|
|
|
ImportDescription import;
|
|
|
|
|
|
|
|
import.plt = importObject["plt"].toVariant().toULongLong();
|
|
|
|
import.ordinal = importObject["ordinal"].toInt();
|
|
|
|
import.bind = importObject["bind"].toString();
|
|
|
|
import.type = importObject["type"].toString();
|
|
|
|
import.name = importObject["name"].toString();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
QJsonArray importsArray = cmdj("iEj").array();
|
|
|
|
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : importsArray) {
|
2017-05-19 07:45:26 +00:00
|
|
|
QJsonObject importObject = value.toObject();
|
|
|
|
|
|
|
|
ExportDescription exp;
|
|
|
|
|
|
|
|
exp.vaddr = importObject["vaddr"].toVariant().toULongLong();
|
|
|
|
exp.paddr = importObject["paddr"].toVariant().toULongLong();
|
|
|
|
exp.size = importObject["size"].toVariant().toULongLong();
|
|
|
|
exp.type = importObject["type"].toString();
|
|
|
|
exp.name = importObject["name"].toString();
|
|
|
|
exp.flag_name = importObject["flagname"].toString();
|
|
|
|
|
|
|
|
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();
|
|
|
|
RListIter *it;
|
|
|
|
|
|
|
|
QList<SymbolDescription> ret;
|
|
|
|
|
|
|
|
RBinSymbol *bs;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) {
|
|
|
|
CutterRListForeach(core_->bin->cur->o->symbols, it, RBinSymbol, bs) {
|
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;
|
|
|
|
RBinAddr *entry;
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterRListForeach(core_->bin->cur->o->entries, it, RBinAddr, entry) {
|
2017-04-28 13:09:40 +00:00
|
|
|
SymbolDescription symbol;
|
|
|
|
symbol.vaddr = entry->vaddr;
|
|
|
|
symbol.name = QString("entry") + QString::number(n++);
|
|
|
|
symbol.bind = "";
|
|
|
|
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();
|
|
|
|
|
|
|
|
for (QJsonValue value : headersArray) {
|
|
|
|
QJsonObject headerObject = value.toObject();
|
|
|
|
|
|
|
|
HeaderDescription header;
|
|
|
|
|
|
|
|
header.vaddr = headerObject["vaddr"].toVariant().toULongLong();
|
|
|
|
header.paddr = headerObject["paddr"].toVariant().toULongLong();
|
|
|
|
header.value = headerObject["comment"].toString();
|
|
|
|
header.name = headerObject["name"].toString();
|
|
|
|
|
|
|
|
ret << header;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-24 15:37:37 +00:00
|
|
|
QList<ZignatureDescription> CutterCore::getAllZignatures()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ZignatureDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray zignaturesArray = cmdj("zj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : zignaturesArray) {
|
|
|
|
QJsonObject zignatureObject = value.toObject();
|
|
|
|
|
|
|
|
ZignatureDescription zignature;
|
|
|
|
|
|
|
|
zignature.name = zignatureObject["name"].toString();
|
|
|
|
zignature.bytes = zignatureObject["bytes"].toString();
|
|
|
|
zignature.offset = zignatureObject["offset"].toVariant().toULongLong();
|
|
|
|
for (QJsonValue ref : zignatureObject["refs"].toArray()) {
|
|
|
|
zignature.refs << ref.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject graphObject = zignatureObject["graph"].toObject();
|
|
|
|
zignature.cc = graphObject["cc"].toVariant().toULongLong();
|
|
|
|
zignature.nbbs = graphObject["nbbs"].toVariant().toULongLong();
|
|
|
|
zignature.edges = graphObject["edges"].toVariant().toULongLong();
|
|
|
|
zignature.ebbs = graphObject["ebbs"].toVariant().toULongLong();
|
|
|
|
|
|
|
|
ret << zignature;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : commentsArray) {
|
2017-04-28 13:09:40 +00:00
|
|
|
QJsonObject commentObject = value.toObject();
|
|
|
|
|
|
|
|
QString type = commentObject["type"].toString();
|
2017-04-28 13:38:01 +00:00
|
|
|
if (type != filterType)
|
2017-04-28 13:09:40 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
CommentDescription comment;
|
|
|
|
comment.offset = commentObject["offset"].toVariant().toULongLong();
|
|
|
|
comment.name = commentObject["name"].toString();
|
|
|
|
|
|
|
|
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();
|
|
|
|
RListIter *it;
|
|
|
|
QList<RelocDescription> ret;
|
|
|
|
|
|
|
|
RBinReloc *br;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) {
|
|
|
|
CutterRListForeach(core_->bin->cur->o->relocs, it, RBinReloc, br) {
|
2017-04-28 13:09:40 +00:00
|
|
|
RelocDescription reloc;
|
|
|
|
|
|
|
|
reloc.vaddr = br->vaddr;
|
|
|
|
reloc.paddr = br->paddr;
|
|
|
|
reloc.type = (br->additive ? "ADD_" : "SET_") + QString::number(br->type);
|
|
|
|
|
|
|
|
if (br->import)
|
|
|
|
reloc.name = br->import->name;
|
|
|
|
else
|
|
|
|
reloc.name = QString("reloc_%1").arg(QString::number(br->vaddr, 16));
|
|
|
|
|
|
|
|
ret << reloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : stringsArray) {
|
2018-02-10 17:50:00 +00:00
|
|
|
QJsonObject stringObject = value.toObject();
|
|
|
|
|
|
|
|
StringDescription string;
|
|
|
|
string.string = QString(QByteArray::fromBase64(stringObject["string"].toVariant().toByteArray()));
|
|
|
|
string.vaddr = stringObject["vaddr"].toVariant().toULongLong();
|
|
|
|
string.type = stringObject["type"].toString();
|
|
|
|
string.size = stringObject["size"].toVariant().toUInt();
|
|
|
|
string.length = stringObject["length"].toVariant().toUInt();
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-06-25 19:28:34 +00:00
|
|
|
QList<FunctionDescription> CutterCore::parseFunctionsJson(const QJsonDocument &doc)
|
|
|
|
{
|
|
|
|
QList<FunctionDescription> ret;
|
|
|
|
QJsonArray jsonArray = doc.array();
|
|
|
|
|
|
|
|
for (QJsonValue value : jsonArray) {
|
|
|
|
QJsonObject jsonObject = value.toObject();
|
|
|
|
|
|
|
|
FunctionDescription function;
|
|
|
|
|
|
|
|
function.offset = (RVA)jsonObject["offset"].toVariant().toULongLong();
|
|
|
|
function.size = (RVA)jsonObject["size"].toVariant().toULongLong();
|
|
|
|
function.nargs = (RVA)jsonObject["nargs"].toVariant().toULongLong();
|
|
|
|
function.nbbs = (RVA)jsonObject["nbbs"].toVariant().toULongLong();
|
|
|
|
function.nlocals = (RVA)jsonObject["nlocals"].toVariant().toULongLong();
|
|
|
|
function.cc = (RVA)jsonObject["cc"].toVariant().toULongLong();
|
|
|
|
function.calltype = jsonObject["calltype"].toString();
|
|
|
|
function.name = jsonObject["name"].toString();
|
2018-10-10 06:41:16 +00:00
|
|
|
function.edges = (RVA)jsonObject["edges"].toVariant().toULongLong();
|
|
|
|
function.cost = (RVA)jsonObject["cost"].toVariant().toULongLong();
|
|
|
|
function.calls = (RVA)jsonObject["outdegree"].toVariant().toULongLong();
|
|
|
|
function.stackframe = (RVA)jsonObject["stackframe"].toVariant().toULongLong();
|
2018-06-25 19:28:34 +00:00
|
|
|
|
|
|
|
ret << function;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : flagspacesArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject flagspaceObject = value.toObject();
|
|
|
|
|
|
|
|
FlagspaceDescription flagspace;
|
|
|
|
flagspace.name = flagspaceObject["name"].toString();
|
|
|
|
|
|
|
|
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())
|
|
|
|
cmd("fs " + flagspace);
|
|
|
|
else
|
|
|
|
cmd("fs *");
|
|
|
|
|
|
|
|
QJsonArray flagsArray = cmdj("fj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : flagsArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject flagObject = value.toObject();
|
|
|
|
|
|
|
|
FlagDescription flag;
|
|
|
|
flag.offset = flagObject["offset"].toVariant().toULongLong();
|
|
|
|
flag.size = flagObject["size"].toVariant().toULongLong();
|
|
|
|
flag.name = flagObject["name"].toString();
|
|
|
|
|
|
|
|
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();
|
|
|
|
QList<SectionDescription> ret;
|
|
|
|
|
2018-05-05 10:11:44 +00:00
|
|
|
QJsonDocument sectionsDoc = cmdj("iSj entropy");
|
|
|
|
QJsonObject sectionsObj = sectionsDoc.object();
|
|
|
|
QJsonArray sectionsArray = sectionsObj["sections"].toArray();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : sectionsArray) {
|
2017-05-03 09:09:57 +00:00
|
|
|
QJsonObject sectionObject = value.toObject();
|
|
|
|
|
|
|
|
QString name = sectionObject["name"].toString();
|
|
|
|
if (name.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SectionDescription section;
|
|
|
|
section.name = name;
|
|
|
|
section.vaddr = sectionObject["vaddr"].toVariant().toULongLong();
|
|
|
|
section.vsize = sectionObject["vsize"].toVariant().toULongLong();
|
|
|
|
section.paddr = sectionObject["paddr"].toVariant().toULongLong();
|
|
|
|
section.size = sectionObject["size"].toVariant().toULongLong();
|
|
|
|
section.flags = sectionObject["flags"].toString();
|
2018-05-05 10:11:44 +00:00
|
|
|
section.entropy = sectionObject["entropy"].toString();
|
2017-05-03 09:09:57 +00:00
|
|
|
|
|
|
|
ret << section;
|
|
|
|
}
|
|
|
|
return ret;
|
2017-05-13 18:09:36 +00:00
|
|
|
}
|
2017-06-07 10:56:55 +00:00
|
|
|
|
2018-10-20 18:20:06 +00:00
|
|
|
QList<SegmentDescription> CutterCore::getAllSegments()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<SegmentDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray segments = cmdj("iSSj").array();
|
|
|
|
|
|
|
|
for (QJsonValue value : segments) {
|
|
|
|
QJsonObject segmentObject = value.toObject();
|
|
|
|
|
|
|
|
QString name = segmentObject["name"].toString();
|
|
|
|
if (name.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SegmentDescription segment;
|
|
|
|
segment.name = name;
|
|
|
|
segment.vaddr = segmentObject["vaddr"].toVariant().toULongLong();
|
|
|
|
segment.paddr = segmentObject["paddr"].toVariant().toULongLong();
|
|
|
|
segment.size = segmentObject["size"].toVariant().toULongLong();
|
|
|
|
segment.vsize = segmentObject["vsize"].toVariant().toULongLong();
|
|
|
|
segment.perm = segmentObject["perm"].toString();
|
|
|
|
|
|
|
|
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-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : entrypointsArray) {
|
2017-07-13 18:49:12 +00:00
|
|
|
QJsonObject entrypointObject = value.toObject();
|
|
|
|
|
|
|
|
EntrypointDescription entrypoint;
|
|
|
|
entrypoint.vaddr = entrypointObject["vaddr"].toVariant().toULongLong();
|
|
|
|
entrypoint.paddr = entrypointObject["paddr"].toVariant().toULongLong();
|
|
|
|
entrypoint.baddr = entrypointObject["baddr"].toVariant().toULongLong();
|
|
|
|
entrypoint.laddr = entrypointObject["laddr"].toVariant().toULongLong();
|
|
|
|
entrypoint.haddr = entrypointObject["haddr"].toVariant().toULongLong();
|
|
|
|
entrypoint.type = entrypointObject["type"].toString();
|
|
|
|
|
|
|
|
ret << entrypoint;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-11 11:13:08 +00:00
|
|
|
QList<ClassDescription> CutterCore::getAllClassesFromBin()
|
2017-12-23 16:42:42 +00:00
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ClassDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray classesArray = cmdj("icj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef value : classesArray) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject classObject = value.toObject();
|
|
|
|
|
|
|
|
ClassDescription cls;
|
|
|
|
cls.name = classObject["classname"].toString();
|
|
|
|
cls.addr = classObject["addr"].toVariant().toULongLong();
|
|
|
|
cls.index = classObject["index"].toVariant().toULongLong();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef value2 : classObject["methods"].toArray()) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject methObject = value2.toObject();
|
|
|
|
|
|
|
|
ClassMethodDescription meth;
|
|
|
|
meth.name = methObject["name"].toString();
|
|
|
|
meth.addr = methObject["addr"].toVariant().toULongLong();
|
|
|
|
cls.methods << meth;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef value2 : classObject["fields"].toArray()) {
|
2017-12-23 16:42:42 +00:00
|
|
|
QJsonObject fieldObject = value2.toObject();
|
|
|
|
|
|
|
|
ClassFieldDescription field;
|
|
|
|
field.name = fieldObject["name"].toString();
|
|
|
|
field.addr = fieldObject["addr"].toVariant().toULongLong();
|
|
|
|
cls.fields << field;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret << cls;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-11 11:13:08 +00:00
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
QList<ClassDescription> CutterCore::getAllClassesFromFlags()
|
|
|
|
{
|
|
|
|
static const QRegularExpression classFlagRegExp("^class\\.(.*)$");
|
|
|
|
static const QRegularExpression methodFlagRegExp("^method\\.([^\\.]*)\\.(.*)$");
|
|
|
|
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ClassDescription> ret;
|
|
|
|
QMap<QString, ClassDescription *> classesCache;
|
|
|
|
|
|
|
|
QJsonArray flagsArray = cmdj("fj@F:classes").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef value : flagsArray) {
|
2018-03-11 11:13:08 +00:00
|
|
|
QJsonObject flagObject = value.toObject();
|
|
|
|
QString flagName = flagObject["name"].toString();
|
|
|
|
|
|
|
|
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);
|
|
|
|
ClassDescription *desc = nullptr;
|
|
|
|
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
|
|
|
ClassDescription cls = {};
|
|
|
|
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);
|
|
|
|
desc->addr = flagObject["offset"].toVariant().toULongLong();
|
|
|
|
desc->index = 0;
|
|
|
|
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);
|
|
|
|
ClassDescription *classDesc = nullptr;
|
|
|
|
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
|
|
|
|
ClassDescription cls;
|
|
|
|
cls.name = tr("Unknown (%1)").arg(className);
|
|
|
|
cls.addr = 0;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassMethodDescription meth;
|
|
|
|
meth.name = match.captured(2);
|
|
|
|
meth.addr = flagObject["offset"].toVariant().toULongLong();
|
|
|
|
classDesc->methods << meth;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-04 14:32:18 +00:00
|
|
|
QList<ResourcesDescription> CutterCore::getAllResources()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<ResourcesDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray resourcesArray = cmdj("iRj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef value : resourcesArray) {
|
2018-02-04 14:32:18 +00:00
|
|
|
QJsonObject resourceObject = value.toObject();
|
|
|
|
|
|
|
|
ResourcesDescription res;
|
2018-02-09 13:19:36 +00:00
|
|
|
res.name = resourceObject["name"].toInt();
|
2018-02-04 14:32:18 +00:00
|
|
|
res.vaddr = resourceObject["vaddr"].toVariant().toULongLong();
|
|
|
|
res.index = resourceObject["index"].toVariant().toULongLong();
|
|
|
|
res.type = resourceObject["type"].toString();
|
|
|
|
res.size = resourceObject["size"].toVariant().toULongLong();
|
|
|
|
res.lang = resourceObject["lang"].toString();
|
|
|
|
|
|
|
|
ret << res;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-26 22:26:18 +00:00
|
|
|
QList<VTableDescription> CutterCore::getAllVTables()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<VTableDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray vTablesArray = cmdj("avj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef vTableValue : vTablesArray) {
|
2018-02-26 22:26:18 +00:00
|
|
|
QJsonObject vTableObject = vTableValue.toObject();
|
|
|
|
|
|
|
|
VTableDescription res;
|
|
|
|
res.addr = vTableObject["offset"].toVariant().toULongLong();
|
|
|
|
QJsonArray methodArray = vTableObject["methods"].toArray();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValueRef methodValue : methodArray) {
|
2018-02-26 22:26:18 +00:00
|
|
|
QJsonObject methodObject = methodValue.toObject();
|
|
|
|
|
|
|
|
ClassMethodDescription method;
|
|
|
|
method.addr = methodObject["offset"].toVariant().toULongLong();
|
|
|
|
method.name = methodObject["name"].toString();
|
|
|
|
|
|
|
|
res.methods << method;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret << res;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-06 17:21:48 +00:00
|
|
|
QList<TypeDescription> CutterCore::getAllTypes()
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<TypeDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray typesArray = cmdj("tj").array();
|
|
|
|
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : typesArray) {
|
2018-03-06 17:21:48 +00:00
|
|
|
QJsonObject typeObject = value.toObject();
|
|
|
|
|
|
|
|
TypeDescription exp;
|
|
|
|
|
|
|
|
exp.type = typeObject["type"].toString();
|
|
|
|
exp.size = typeObject["size"].toVariant().toULongLong();
|
|
|
|
exp.format = typeObject["format"].toString();
|
|
|
|
|
|
|
|
ret << exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-08 12:24:15 +00:00
|
|
|
QList<SearchDescription> CutterCore::getAllSearch(QString search_for, QString space)
|
|
|
|
{
|
|
|
|
CORE_LOCK();
|
|
|
|
QList<SearchDescription> ret;
|
|
|
|
|
|
|
|
QJsonArray searchArray = cmdj(space + QString(" ") + search_for).array();
|
2018-03-21 20:32:32 +00:00
|
|
|
|
|
|
|
if (space == "/Rj") {
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : searchArray) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject searchObject = value.toObject();
|
|
|
|
SearchDescription exp;
|
|
|
|
exp.code = QString("");
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value2 : searchObject["opcodes"].toArray()) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject gadget = value2.toObject();
|
|
|
|
exp.code += gadget["opcode"].toString() + "; ";
|
|
|
|
}
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
exp.offset =
|
|
|
|
searchObject["opcodes"].toArray().first().toObject()["offset"].toVariant().toULongLong();
|
2018-03-16 09:07:41 +00:00
|
|
|
exp.size = searchObject["size"].toVariant().toULongLong();
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2018-03-16 09:07:41 +00:00
|
|
|
ret << exp;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : searchArray) {
|
2018-03-16 09:07:41 +00:00
|
|
|
QJsonObject searchObject = value.toObject();
|
|
|
|
SearchDescription exp;
|
2018-03-08 12:24:15 +00:00
|
|
|
|
2018-03-16 09:07:41 +00:00
|
|
|
exp.offset = searchObject["offset"].toVariant().toULongLong();
|
|
|
|
exp.size = searchObject["len"].toVariant().toULongLong();
|
|
|
|
exp.code = searchObject["code"].toString();
|
|
|
|
exp.data = searchObject["data"].toString();
|
|
|
|
|
|
|
|
ret << exp;
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 12:24:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-29 10:34:01 +00:00
|
|
|
BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount)
|
|
|
|
{
|
2018-07-06 16:00:26 +00:00
|
|
|
if (blocksCount == 0) {
|
|
|
|
BlockStatistics ret;
|
|
|
|
ret.from = ret.to = ret.blocksize = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-06-29 12:35:02 +00:00
|
|
|
QJsonObject statsObj = cmdj("p-j " + QString::number(blocksCount)).object();
|
2018-06-29 10:34:01 +00:00
|
|
|
|
|
|
|
BlockStatistics ret;
|
|
|
|
ret.from = statsObj["from"].toVariant().toULongLong();
|
|
|
|
ret.to = statsObj["to"].toVariant().toULongLong();
|
|
|
|
ret.blocksize = statsObj["blocksize"].toVariant().toULongLong();
|
|
|
|
|
|
|
|
QJsonArray blocksArray = statsObj["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();
|
|
|
|
BlockDescription block;
|
|
|
|
block.addr = blockObj["offset"].toVariant().toULongLong();
|
|
|
|
block.size = blockObj["size"].toVariant().toULongLong();
|
|
|
|
block.flags = blockObj["flags"].toInt(0);
|
|
|
|
block.functions = blockObj["functions"].toInt(0);
|
2018-07-01 12:29:01 +00:00
|
|
|
block.inFunctions = blockObj["in_functions"].toInt(0);
|
2018-06-29 10:34:01 +00:00
|
|
|
block.comments = blockObj["comments"].toInt(0);
|
|
|
|
block.symbols = blockObj["symbols"].toInt(0);
|
|
|
|
block.strings = blockObj["strings"].toInt(0);
|
|
|
|
|
|
|
|
block.rwx = 0;
|
|
|
|
QString rwxStr = blockObj["rwx"].toString();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.blocks << block;
|
|
|
|
}
|
2018-06-29 12:35:02 +00:00
|
|
|
|
2018-06-29 10:34:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-06-07 19:35:38 +00:00
|
|
|
QList<XrefDescription> ret = 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-03-21 20:32:32 +00:00
|
|
|
for (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;
|
2017-06-07 10:56:55 +00:00
|
|
|
xref.type = xrefObject["type"].toString();
|
|
|
|
|
|
|
|
if (!filterType.isNull() && filterType != xref.type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
xref.from = xrefObject["from"].toVariant().toULongLong();
|
2018-09-11 09:30:28 +00:00
|
|
|
if (!to) {
|
|
|
|
xref.from_str = RAddressString(xref.from);
|
|
|
|
} else {
|
|
|
|
QString fcn = xrefObject["fcn_name"].toString();
|
|
|
|
if (!fcn.isEmpty()) {
|
|
|
|
RVA fcnAddr = xrefObject["fcn_addr"].toVariant().toULongLong();
|
|
|
|
xref.from_str = fcn + " + 0x" + QString::number(xref.from - fcnAddr, 16);
|
|
|
|
} else {
|
|
|
|
xref.from_str = RAddressString(xref.from);
|
|
|
|
}
|
|
|
|
}
|
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-05 21:51:27 +00:00
|
|
|
if (to && !xrefObject.contains("to")) {
|
2017-06-07 10:56:55 +00:00
|
|
|
xref.to = addr;
|
2018-11-05 21:51:27 +00:00
|
|
|
} else {
|
2017-06-07 10:56:55 +00:00
|
|
|
xref.to = xrefObject["to"].toVariant().toULongLong();
|
2018-11-05 21:51:27 +00:00
|
|
|
}
|
2018-09-11 09:30:28 +00:00
|
|
|
xref.to_str = Core()->cmd("fd " + QString::number(xref.to)).trimmed();
|
2017-06-07 10:56:55 +00:00
|
|
|
|
|
|
|
ret << xref;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
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);
|
|
|
|
cmd(QString("f %1 %2 @ %3").arg(name).arg(size).arg(offset));
|
|
|
|
emit flagsChanged();
|
2017-07-13 18:49:12 +00:00
|
|
|
}
|
2017-09-27 20:23:18 +00:00
|
|
|
|
2017-11-30 21:30:51 +00:00
|
|
|
void CutterCore::triggerFlagsChanged()
|
|
|
|
{
|
|
|
|
emit flagsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::triggerVarsChanged()
|
|
|
|
{
|
|
|
|
emit varsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::triggerFunctionRenamed(const QString &prevName, const QString &newName)
|
|
|
|
{
|
|
|
|
emit functionRenamed(prevName, newName);
|
|
|
|
}
|
|
|
|
|
2017-09-27 20:23:18 +00:00
|
|
|
void CutterCore::loadPDB(const QString &file)
|
|
|
|
{
|
|
|
|
cmd("idp " + sanitizeStringForCommand(file));
|
|
|
|
}
|
2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
void CutterCore::openProject(const QString &name)
|
|
|
|
{
|
|
|
|
cmd("Po " + name);
|
|
|
|
|
|
|
|
QString notes = QString::fromUtf8(QByteArray::fromBase64(cmd("Pnj").toUtf8()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterCore::saveProject(const QString &name)
|
|
|
|
{
|
2018-11-02 06:48:17 +00:00
|
|
|
const QString &rv = cmd("Ps " + name.trimmed()).trimmed();
|
|
|
|
const bool ok = rv == name.trimmed();
|
2017-10-21 19:20:10 +00:00
|
|
|
cmd("Pnj " + notes.toUtf8().toBase64());
|
2018-11-02 06:48:17 +00:00
|
|
|
emit projectSaved(ok, name);
|
2017-10-21 19:20:10 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 07:54:24 +00:00
|
|
|
void CutterCore::deleteProject(const QString &name)
|
|
|
|
{
|
|
|
|
cmd("Pd " + name);
|
|
|
|
}
|
|
|
|
|
2017-10-21 19:20:10 +00:00
|
|
|
bool CutterCore::isProjectNameValid(const QString &name)
|
|
|
|
{
|
|
|
|
// see is_valid_project_name() in libr/core/project.c
|
|
|
|
static const QRegExp regexp(R"(^[a-zA-Z0-9\\\._:-]{1,}$)");
|
|
|
|
return regexp.exactMatch(name) && !name.endsWith(".zip") ;
|
|
|
|
}
|
|
|
|
|
2017-12-13 14:30:00 +00:00
|
|
|
QList<DisassemblyLine> CutterCore::disassembleLines(RVA offset, int lines)
|
|
|
|
{
|
2018-03-21 20:32:32 +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;
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue value : array) {
|
2017-12-13 14:30:00 +00:00
|
|
|
QJsonObject object = value.toObject();
|
|
|
|
|
|
|
|
DisassemblyLine line;
|
|
|
|
line.offset = object["offset"].toVariant().toULongLong();
|
|
|
|
line.text = object["text"].toString();
|
|
|
|
|
|
|
|
r << line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2017-12-14 12:45:03 +00:00
|
|
|
|
|
|
|
void CutterCore::loadScript(const QString &scriptname)
|
|
|
|
{
|
2018-09-23 19:57:20 +00:00
|
|
|
r_core_task_sync_begin(core_);
|
2018-07-24 17:50:55 +00:00
|
|
|
r_core_cmd_file(core_, scriptname.toUtf8().constData());
|
2018-09-23 19:57:20 +00:00
|
|
|
r_core_task_sync_end(core_);
|
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
|
|
|
|
2017-12-15 16:09:04 +00:00
|
|
|
QString CutterCore::getVersionInformation()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
QString ret;
|
|
|
|
struct vcs_t {
|
|
|
|
const char *name;
|
|
|
|
const char *(*callback)();
|
|
|
|
} vcs[] = {
|
|
|
|
{ "r_anal", &r_anal_version },
|
|
|
|
{ "r_lib", &r_lib_version },
|
|
|
|
{ "r_egg", &r_egg_version },
|
|
|
|
{ "r_asm", &r_asm_version },
|
|
|
|
{ "r_bin", &r_bin_version },
|
|
|
|
{ "r_cons", &r_cons_version },
|
|
|
|
{ "r_flag", &r_flag_version },
|
|
|
|
{ "r_core", &r_core_version },
|
|
|
|
{ "r_crypto", &r_crypto_version },
|
|
|
|
{ "r_bp", &r_bp_version },
|
|
|
|
{ "r_debug", &r_debug_version },
|
|
|
|
{ "r_hash", &r_hash_version },
|
|
|
|
{ "r_fs", &r_fs_version },
|
|
|
|
{ "r_io", &r_io_version },
|
|
|
|
{ "r_magic", &r_magic_version },
|
|
|
|
{ "r_parse", &r_parse_version },
|
|
|
|
{ "r_reg", &r_reg_version },
|
|
|
|
{ "r_sign", &r_sign_version },
|
|
|
|
{ "r_search", &r_search_version },
|
|
|
|
{ "r_syscall", &r_syscall_version },
|
|
|
|
{ "r_util", &r_util_version },
|
|
|
|
/* ... */
|
2018-03-21 20:32:32 +00:00
|
|
|
{NULL, NULL}
|
2017-12-15 16:09:04 +00:00
|
|
|
};
|
|
|
|
ret.append(QString("%1 r2\n").arg(R2_GITTAP));
|
|
|
|
for (i = 0; vcs[i].name; i++) {
|
2018-03-21 20:32:32 +00:00
|
|
|
struct vcs_t *v = &vcs[i];
|
|
|
|
const char *name = v->callback ();
|
|
|
|
ret.append(QString("%1 %2\n").arg(name, v->name));
|
2017-12-15 16:09:04 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2018-06-25 19:28:34 +00:00
|
|
|
|
2018-01-27 10:40:26 +00:00
|
|
|
QJsonArray CutterCore::getOpenedFiles()
|
|
|
|
{
|
|
|
|
QJsonDocument files = cmdj("oj");
|
|
|
|
return files.array();
|
|
|
|
}
|
2018-05-29 16:19:59 +00:00
|
|
|
|
2018-02-26 22:25:23 +00:00
|
|
|
QList<QString> CutterCore::getColorThemes()
|
|
|
|
{
|
|
|
|
QList<QString> r;
|
|
|
|
QJsonDocument themes = cmdj("ecoj");
|
2018-11-05 21:51:27 +00:00
|
|
|
for (auto 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
|
|
|
|
2018-07-18 10:15:10 +00:00
|
|
|
void CutterCore::setCutterPlugins(QList<CutterPlugin *> plugins)
|
2018-06-26 07:40:08 +00:00
|
|
|
{
|
|
|
|
this->plugins = plugins;
|
|
|
|
}
|
|
|
|
|
2018-07-18 10:15:10 +00:00
|
|
|
QList<CutterPlugin *> CutterCore::getCutterPlugins()
|
2018-06-26 07:40:08 +00:00
|
|
|
{
|
|
|
|
return plugins;
|
|
|
|
}
|