Use API for Functions (#1498)

This commit is contained in:
Florian Märkl 2019-05-01 13:34:15 +02:00 committed by GitHub
parent 1d20129a0a
commit c534b1bce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 77 deletions

View File

@ -1529,7 +1529,32 @@ QList<RAsmPluginDescription> CutterCore::getRAsmPluginDescriptions()
QList<FunctionDescription> CutterCore::getAllFunctions() QList<FunctionDescription> CutterCore::getAllFunctions()
{ {
return parseFunctionsJson(cmdjTask("aflj")); CORE_LOCK();
QList<FunctionDescription> ret;
ret.reserve(r_list_length(core_->anal->fcns));
RListIter *iter;
RAnalFunction *fcn;
CutterRListForeach (core_->anal->fcns, iter, RAnalFunction, fcn) {
FunctionDescription function;
function.offset = fcn->addr;
function.size = r_anal_fcn_size(fcn);
function.nargs = r_anal_var_count(core_->anal, fcn, 'b', 1) +
r_anal_var_count(core_->anal, fcn, 'r', 1) +
r_anal_var_count(core_->anal, fcn, 's', 1);
function.nlocals = r_anal_var_count(core_->anal, fcn, 'b', 0) +
r_anal_var_count(core_->anal, fcn, 'r', 0) +
r_anal_var_count(core_->anal, fcn, 's', 0);
function.nbbs = r_list_length (fcn->bbs);
function.calltype = fcn->cc ? QString::fromUtf8(fcn->cc) : QString();
function.name = fcn->name ? QString::fromUtf8(fcn->name) : QString();
function.edges = r_anal_fcn_count_edges(fcn, nullptr);
function.stackframe = fcn->maxstack;
ret.append(function);
}
return ret;
} }
QList<ImportDescription> CutterCore::getAllImports() QList<ImportDescription> CutterCore::getAllImports()
@ -1748,35 +1773,6 @@ QList<StringDescription> CutterCore::parseStringsJson(const QJsonDocument &doc)
return ret; return ret;
} }
QList<FunctionDescription> CutterCore::parseFunctionsJson(const QJsonDocument &doc)
{
QList<FunctionDescription> ret;
QJsonArray jsonArray = doc.array();
for (const QJsonValue &value : jsonArray) {
QJsonObject jsonObject = value.toObject();
FunctionDescription function;
function.offset = jsonObject[RJsonKey::offset].toVariant().toULongLong();
function.size = jsonObject[RJsonKey::size].toVariant().toULongLong();
function.nargs = jsonObject[RJsonKey::nargs].toVariant().toULongLong();
function.nbbs = jsonObject[RJsonKey::nbbs].toVariant().toULongLong();
function.nlocals = jsonObject[RJsonKey::nlocals].toVariant().toULongLong();
function.cc = jsonObject[RJsonKey::cc].toVariant().toULongLong();
function.calltype = jsonObject[RJsonKey::calltype].toString();
function.name = jsonObject[RJsonKey::name].toString();
function.edges = jsonObject[RJsonKey::edges].toVariant().toULongLong();
function.cost = jsonObject[RJsonKey::cost].toVariant().toULongLong();
function.calls = jsonObject[RJsonKey::outdegree].toVariant().toULongLong();
function.stackframe = jsonObject[RJsonKey::stackframe].toVariant().toULongLong();
ret << function;
}
return ret;
}
QList<FlagspaceDescription> CutterCore::getAllFlagspaces() QList<FlagspaceDescription> CutterCore::getAllFlagspaces()
{ {
CORE_LOCK(); CORE_LOCK();

View File

@ -362,7 +362,6 @@ public:
const QString &filterType = QString::null); const QString &filterType = QString::null);
QList<StringDescription> parseStringsJson(const QJsonDocument &doc); QList<StringDescription> parseStringsJson(const QJsonDocument &doc);
QList<FunctionDescription> parseFunctionsJson(const QJsonDocument &doc);
void handleREvent(int type, void *data); void handleREvent(int type, void *data);

View File

@ -17,12 +17,9 @@ struct FunctionDescription {
RVA nargs; RVA nargs;
RVA nbbs; RVA nbbs;
RVA nlocals; RVA nlocals;
RVA cc;
QString calltype; QString calltype;
QString name; QString name;
RVA edges; RVA edges;
RVA cost;
RVA calls;
RVA stackframe; RVA stackframe;
bool contains(RVA addr) const bool contains(RVA addr) const

View File

@ -132,16 +132,10 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
case 5: case 5:
return tr("Nlocals: %1").arg(RSizeString(function.nlocals)); return tr("Nlocals: %1").arg(RSizeString(function.nlocals));
case 6: case 6:
return tr("Cyclomatic complexity: %1").arg(RSizeString(function.cc));
case 7:
return tr("Call type: %1").arg(function.calltype); return tr("Call type: %1").arg(function.calltype);
case 8: case 7:
return tr("Edges: %1").arg(function.edges); return tr("Edges: %1").arg(function.edges);
case 9: case 8:
return tr("Cost: %1").arg(function.cost);
case 10:
return tr("Calls/OutDegree: %1").arg(function.calls);
case 11:
return tr("StackFrame: %1").arg(function.stackframe); return tr("StackFrame: %1").arg(function.stackframe);
default: default:
return QVariant(); return QVariant();
@ -158,20 +152,14 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return RAddressString(function.offset); return RAddressString(function.offset);
case NargsColumn: case NargsColumn:
return function.nargs; return function.nargs;
case NbbsColumn:
return function.nbbs;
case NlocalsColumn: case NlocalsColumn:
return function.nlocals; return function.nlocals;
case CcColumn: case NbbsColumn:
return function.cc; return function.nbbs;
case CalltypeColumn: case CalltypeColumn:
return function.calltype; return function.calltype;
case EdgesColumn: case EdgesColumn:
return function.edges; return function.edges;
case CostColumn:
return function.cost;
case CallsColumn:
return function.calls;
case FrameColumn: case FrameColumn:
return function.stackframe; return function.stackframe;
default: default:
@ -267,20 +255,14 @@ QVariant FunctionModel::headerData(int section, Qt::Orientation orientation, int
return tr("Offset"); return tr("Offset");
case NargsColumn: case NargsColumn:
return tr("Nargs"); return tr("Nargs");
case NbbsColumn:
return tr("Nbbs");
case NlocalsColumn: case NlocalsColumn:
return tr("Nlocals"); return tr("Nlocals");
case CcColumn: case NbbsColumn:
return tr("Cyclo. Comp."); return tr("Nbbs");
case CalltypeColumn: case CalltypeColumn:
return tr("Call type"); return tr("Call type");
case EdgesColumn: case EdgesColumn:
return tr("Edges"); return tr("Edges");
case CostColumn:
return tr("Cost");
case CallsColumn:
return tr("Calls/OutDeg.");
case FrameColumn: case FrameColumn:
return tr("StackFrame"); return tr("StackFrame");
default: default:
@ -402,33 +384,20 @@ bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QMode
if (left_function.nargs != right_function.nargs) if (left_function.nargs != right_function.nargs)
return left_function.nargs < right_function.nargs; return left_function.nargs < right_function.nargs;
break; break;
case FunctionModel::NbbsColumn:
if (left_function.nbbs != right_function.nbbs)
return left_function.nbbs < right_function.nbbs;
break;
case FunctionModel::NlocalsColumn: case FunctionModel::NlocalsColumn:
if (left_function.nlocals != right_function.nlocals) if (left_function.nlocals != right_function.nlocals)
return left_function.nlocals < right_function.nlocals; return left_function.nlocals < right_function.nlocals;
break; break;
case FunctionModel::CcColumn: case FunctionModel::NbbsColumn:
if (left_function.cc != right_function.cc) if (left_function.nbbs != right_function.nbbs)
return left_function.cc < right_function.cc; return left_function.nbbs < right_function.nbbs;
break; break;
case FunctionModel::CalltypeColumn: case FunctionModel::CalltypeColumn:
return left_function.calltype < right_function.calltype; return left_function.calltype < right_function.calltype;
break;
case FunctionModel::EdgesColumn: case FunctionModel::EdgesColumn:
if (left_function.edges != right_function.edges) if (left_function.edges != right_function.edges)
return left_function.edges < right_function.edges; return left_function.edges < right_function.edges;
break; break;
case FunctionModel::CostColumn:
if (left_function.cost != right_function.cost)
return left_function.cost < right_function.cost;
break;
case FunctionModel::CallsColumn:
if (left_function.calls != right_function.calls)
return left_function.calls < right_function.calls;
break;
case FunctionModel::FrameColumn: case FunctionModel::FrameColumn:
if (left_function.stackframe != right_function.stackframe) if (left_function.stackframe != right_function.stackframe)
return left_function.stackframe < right_function.stackframe; return left_function.stackframe < right_function.stackframe;

View File

@ -46,9 +46,8 @@ public:
static const int FunctionDescriptionRole = Qt::UserRole; static const int FunctionDescriptionRole = Qt::UserRole;
static const int IsImportRole = Qt::UserRole + 1; static const int IsImportRole = Qt::UserRole + 1;
enum Column { NameColumn = 0, SizeColumn, ImportColumn, OffsetColumn, NargsColumn, NbbsColumn, enum Column { NameColumn = 0, SizeColumn, ImportColumn, OffsetColumn, NargsColumn, NlocalsColumn,
NlocalsColumn, CcColumn, CalltypeColumn, EdgesColumn, CostColumn, CallsColumn, NbbsColumn, CalltypeColumn, EdgesColumn, FrameColumn, ColumnCount
FrameColumn, ColumnCount
}; };
FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, ut64 *mainAdress, FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *importAddresses, ut64 *mainAdress,