From 2e26ead446ebb7aa0d698dcea3036ab7e7bd790b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 28 May 2018 17:19:58 +0200 Subject: [PATCH] Get Strings from r2 API --- src/Cutter.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 21f44b8d..d629fcf0 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -1177,10 +1177,11 @@ QList CutterCore::getAllRelocs() QList CutterCore::getAllStrings() { - CORE_LOCK(); + //CORE_LOCK(); QList ret; - QJsonDocument stringsDoc = cmdj("izzj"); - QJsonObject stringsObj = stringsDoc.object(); + //QJsonDocument stringsDoc = cmdj("izzj"); + + /*QJsonObject stringsObj = stringsDoc.object(); QJsonArray stringsArray = stringsObj["strings"].toArray(); for (QJsonValue value : stringsArray) { QJsonObject stringObject = value.toObject(); @@ -1195,6 +1196,56 @@ QList CutterCore::getAllStrings() ret << string; } + return ret;*/ + + + RBinFile *bf = r_core_bin_cur(core_); + if (!bf) { + return {}; + } + + int min = getConfigi("bin.minstr"); + int rawstrTmp = bf->rawstr; + bf->rawstr = 2; + RList *list = r_bin_file_get_strings(bf, min, 0); + bf->rawstr = rawstrTmp; + + if (!list) { + return {}; + } + + RListIter *iter; + void *s; + r_list_foreach (list, iter, s) { + RBinString *str = reinterpret_cast(s); + StringDescription string; + + switch (str->type) { + case R_STRING_TYPE_ASCII: + string.string = QString::fromUtf8(str->string); + string.type = "ASCII"; + break; + case R_STRING_TYPE_UTF8: + string.string = QString::fromUtf8(str->string); + string.type = "UTF-8"; + break; + default: + // TODO: utf-16, utf-32, etc. + string.string = QString::fromUtf8(str->string); + string.type = "TODO"; + break; + } + string.string = QString::fromUtf8(str->string); + + string.vaddr = str->vaddr; + string.size = str->size; + string.length = str->length; + + ret << string; + } + + r_list_free(list); + return ret; }