From 3ac59f02f5e01903ac613ec0766fc8eaeb00d355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 18 Apr 2017 10:33:35 +0200 Subject: [PATCH] Add QRCore::cmdj, Use iij to fix crash when import name contains spaces (#133) * Fix crash when import name contains spaces * QRCore::cmdj, Get imports with iij --- src/qrcore.cpp | 41 ++++++++++++++++++++++++++++------------- src/qrcore.h | 2 ++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/qrcore.cpp b/src/qrcore.cpp index dc9de681..2c670e04 100644 --- a/src/qrcore.cpp +++ b/src/qrcore.cpp @@ -1,6 +1,9 @@ #include "qrcore.h" #include "sdb.h" +#include +#include + #define DB this->db RCoreLocked::RCoreLocked(RCore *core) @@ -215,6 +218,16 @@ QString QRCore::cmd(const QString &str) return o; } +QJsonDocument QRCore::cmdj(const QString &str) +{ + CORE_LOCK(); + QByteArray cmd = str.toUtf8(); + char *res = r_core_cmd_str(this->core_, cmd.constData()); + QJsonDocument doc = res ? QJsonDocument::fromJson(QByteArray(res)) : QJsonDocument(); + r_mem_free(res); + return doc; +} + bool QRCore::loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int bits = 0, int idx, bool loadbin) { QNOTUSED(loadaddr); @@ -453,21 +466,23 @@ QList QRCore::getList(const QString &type, const QString &subtype) } else if (subtype == "imports") { + QJsonArray importsArray = cmdj("iij").array(); - QStringList lines = this->cmd("ii").split("\n"); - foreach (QString line, lines) + foreach(QJsonValue value, importsArray) { - QStringList tmp = line.split(" "); - if (tmp.length() > 2) - { - QString final; - foreach (QString field, tmp) - { - QString value = field.split("=")[1]; - final.append(value + ","); - } - ret << final; - } + QJsonObject importObject = value.toObject(); + unsigned long plt = (unsigned long)importObject["plt"].toVariant().toULongLong(); + int ordinal = importObject["ordinal"].toInt(); + + QString final = QString("%1,%2,%3,%4,%5,").arg( + QString::asprintf("%#o", ordinal), + QString::asprintf("%#010lx", plt), + importObject["bind"].toString(), + importObject["type"].toString(), + importObject["name"].toString()); + + + ret << final; } } else if (subtype == "entrypoints") diff --git a/src/qrcore.h b/src/qrcore.h index 88bb5158..7bde2823 100644 --- a/src/qrcore.h +++ b/src/qrcore.h @@ -6,6 +6,7 @@ #include #include #include +#include //Workaround for compile errors on Windows #ifdef _WIN32 @@ -58,6 +59,7 @@ public: int fcnBasicBlockCount(ut64 addr); int fcnEndBbs(QString addr); QString cmd(const QString &str); + QJsonDocument cmdj(const QString &str); void renameFunction(QString prev_name, QString new_name); void setComment(QString addr, QString cmt); void delComment(ut64 addr);