From 2ab6907746098fbed6b35d1fec021b91ce9ad5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 11 Mar 2018 12:13:08 +0100 Subject: [PATCH] Add CutterCore::getAllClassesFromFlags() --- src/Cutter.cpp | 75 ++++++++++++++++++++++++++++++++++- src/Cutter.h | 3 +- src/widgets/ClassesWidget.cpp | 2 +- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 18be525d..c43ec761 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "utils/Configuration.h" #include "Cutter.h" @@ -1264,7 +1265,7 @@ QList CutterCore::getAllEntrypoint() return ret; } -QList CutterCore::getAllClasses() +QList CutterCore::getAllClassesFromBin() { CORE_LOCK(); QList ret; @@ -1304,6 +1305,78 @@ QList CutterCore::getAllClasses() return ret; } +#include + +QList CutterCore::getAllClassesFromFlags() +{ + static const QRegularExpression classFlagRegExp("^class\\.(.*)$"); + static const QRegularExpression methodFlagRegExp("^method\\.([^\\.]*)\\.(.*)$"); + + CORE_LOCK(); + QList ret; + QMap classesCache; + + QJsonArray flagsArray = cmdj("fj@F:classes").array(); + for (QJsonValueRef value : flagsArray) + { + QJsonObject flagObject = value.toObject(); + QString flagName = flagObject["name"].toString(); + + QRegularExpressionMatch match = classFlagRegExp.match(flagName); + if (match.hasMatch()) + { + QString className = match.captured(1); + ClassDescription *desc = nullptr; + auto it = classesCache.find(className); + if (it == classesCache.end()) + { + ClassDescription cls = {}; + ret << cls; + desc = &ret.last(); + classesCache[className] = desc; + } + else + { + desc = it.value(); + } + desc->name = match.captured(1); + desc->addr = flagObject["offset"].toVariant().toULongLong(); + desc->index = 0; + continue; + } + + match = methodFlagRegExp.match(flagName); + if (match.hasMatch()) + { + QString className = match.captured(1); + ClassDescription *classDesc = nullptr; + auto it = classesCache.find(className); + if (it == classesCache.end()) + { + // 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; + } + else + { + classDesc = it.value(); + } + + ClassMethodDescription meth; + meth.name = match.captured(2); + meth.addr = flagObject["offset"].toVariant().toULongLong(); + classDesc->methods << meth; + continue; + } + } + return ret; +} + QList CutterCore::getAllResources() { CORE_LOCK(); diff --git a/src/Cutter.h b/src/Cutter.h index f0686871..770dfcbf 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -415,7 +415,8 @@ public: QList getAllFlags(QString flagspace = NULL); QList getAllSections(); QList getAllEntrypoint(); - QList getAllClasses(); + QList getAllClassesFromBin(); + QList getAllClassesFromFlags(); QList getAllResources(); QList getAllVTables(); QList getAllTypes(); diff --git a/src/widgets/ClassesWidget.cpp b/src/widgets/ClassesWidget.cpp index 9b24289f..d115b5e3 100644 --- a/src/widgets/ClassesWidget.cpp +++ b/src/widgets/ClassesWidget.cpp @@ -261,7 +261,7 @@ ClassesWidget::~ClassesWidget() {} void ClassesWidget::refreshClasses() { model->beginReload(); - classes = CutterCore::getInstance()->getAllClasses(); + classes = CutterCore::getInstance()->getAllClassesFromBin(); model->endReload(); ui->classesTreeView->resizeColumnToContents(0);