Add CutterCore::getBlockStatistics()

This commit is contained in:
Florian Märkl 2018-06-29 12:34:01 +02:00
parent 1553ac30e2
commit 1a0f307dcb
2 changed files with 60 additions and 0 deletions

View File

@ -1540,6 +1540,47 @@ QList<SearchDescription> CutterCore::getAllSearch(QString search_for, QString sp
return ret; return ret;
} }
BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount)
{
QJsonObject statsObj = cmdj("p- " + QString::number(blocksCount)).object();
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();
for (QJsonValue value : blocksArray) {
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);
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;
}
return ret;
}
QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_function, QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_function,
const QString &filterType) const QString &filterType)
{ {

View File

@ -275,6 +275,24 @@ struct VTableDescription {
QList<ClassMethodDescription> methods; QList<ClassMethodDescription> methods;
}; };
struct BlockDescription {
RVA addr;
RVA size;
int flags;
int functions;
int comments;
int symbols;
int strings;
ut8 rwx;
};
struct BlockStatistics {
RVA from;
RVA to;
RVA blocksize;
QList<BlockDescription> blocks;
};
Q_DECLARE_METATYPE(FunctionDescription) Q_DECLARE_METATYPE(FunctionDescription)
Q_DECLARE_METATYPE(ImportDescription) Q_DECLARE_METATYPE(ImportDescription)
Q_DECLARE_METATYPE(ExportDescription) Q_DECLARE_METATYPE(ExportDescription)
@ -490,6 +508,7 @@ public:
QList<VTableDescription> getAllVTables(); QList<VTableDescription> getAllVTables();
QList<TypeDescription> getAllTypes(); QList<TypeDescription> getAllTypes();
QList<SearchDescription> getAllSearch(QString search_for, QString space); QList<SearchDescription> getAllSearch(QString search_for, QString space);
BlockStatistics getBlockStatistics(unsigned int blocksCount);
QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function, QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function,
const QString &filterType = QString::null); const QString &filterType = QString::null);