Skip to content

Commit

Permalink
Using API for loading types instead of json cmd, fixed viewing of types
Browse files Browse the repository at this point in the history
  • Loading branch information
MalhotraPulak committed Aug 5, 2021
1 parent 5ac4eff commit 76e2837
Showing 1 changed file with 33 additions and 110 deletions.
143 changes: 33 additions & 110 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3561,123 +3561,39 @@ QList<VTableDescription> CutterCore::getAllVTables()
}

QList<TypeDescription> CutterCore::getAllTypes()
{
QList<TypeDescription> types;

types.append(getAllPrimitiveTypes());
types.append(getAllUnions());
types.append(getAllStructs());
types.append(getAllEnums());
types.append(getAllTypedefs());

return types;
}

QList<TypeDescription> CutterCore::getAllPrimitiveTypes()
{
CORE_LOCK();
QList<TypeDescription> primitiveTypes;

QJsonArray typesArray = cmdj("tj").array();
for (const QJsonValue &value : typesArray) {
QJsonObject typeObject = value.toObject();

TypeDescription exp;

exp.type = typeObject[RJsonKey::type].toString();
exp.size = (int)typeObject[RJsonKey::size].toVariant().toULongLong();
exp.category = tr("Primitive");
primitiveTypes << exp;
}

return primitiveTypes;
}

QList<TypeDescription> CutterCore::getAllUnions()
{
CORE_LOCK();
QList<TypeDescription> unions;

QJsonArray typesArray = cmdj("tuj").array();
for (const QJsonValue value : typesArray) {
QJsonObject typeObject = value.toObject();

TypeDescription exp;

exp.type = typeObject[RJsonKey::name].toString();
exp.category = "Union";
unions << exp;
}

return unions;
}

QList<TypeDescription> CutterCore::getAllStructs()
{
CORE_LOCK();
QList<TypeDescription> structs;

QJsonArray typesArray = cmdj("tsj").array();
for (const QJsonValue value : typesArray) {
QJsonObject typeObject = value.toObject();

TypeDescription exp;

exp.type = typeObject[RJsonKey::name].toString();
exp.size = 0;
exp.category = "Struct";
structs << exp;
}

return structs;
}

QList<TypeDescription> CutterCore::getAllEnums()
{
CORE_LOCK();
QList<TypeDescription> enums;

QJsonObject typesObject = cmdj("tej").object();
for (const QJsonValue value : typesObject.keys()) {
QJsonObject typeObject = value.toObject();

TypeDescription exp;

exp.type = typeObject[RJsonKey::name].toString();
exp.size = 0;
exp.category = "Enum";
enums << exp;
}

return enums;
}

QList<TypeDescription> CutterCore::getAllTypedefs()
{
CORE_LOCK();
QList<TypeDescription> typeDefs;

QJsonObject typesObject = cmdj("ttj").object();
for (const QJsonValue value : typesObject.keys()) {
QJsonObject typeObject = value.toObject();

TypeDescription exp;
QList<TypeDescription> types_desc;
RzList *types = rz_type_db_get_base_types(core->analysis->typedb);
RzListIter *it;
RzBaseType *btype;

exp.type = typeObject[RJsonKey::name].toString();
exp.size = 0;
exp.category = "Typedef";
typeDefs << exp;
CutterRListForeach(types, it, RzBaseType, btype)
{
TypeDescription typeDescription;
typeDescription.type = btype->name;
if (btype->kind == RZ_BASE_TYPE_KIND_STRUCT) {
typeDescription.category = "Struct";
} else if (btype->kind == RZ_BASE_TYPE_KIND_ENUM) {
typeDescription.category = "Enum";
} else if (btype->kind == RZ_BASE_TYPE_KIND_ATOMIC) {
typeDescription.category = "Primitive";
} else if (btype->kind == RZ_BASE_TYPE_KIND_TYPEDEF) {
typeDescription.category = "Typedef";
}
typeDescription.size = btype->size;
types_desc << typeDescription;
}

return typeDefs;
return types_desc;
}

QString CutterCore::addTypes(const char *str)
{
CORE_LOCK();
char *error_msg = nullptr;
int result = rz_type_parse_string(core->analysis->typedb, str, &error_msg);
// TODO fix adding and parsing types

QString error;

if (result && error_msg) {
Expand All @@ -3695,16 +3611,23 @@ QString CutterCore::getTypeAsC(QString name, QString category)
if (name.isEmpty() || category.isEmpty()) {
return output;
}
QString typeName = sanitizeStringForCommand(name);

const char *name_char = name.toStdString().c_str();
RzBaseType *rzBaseType;

if (category == "Struct") {
output = cmdRaw(QString("tsc %1").arg(typeName));
rzBaseType = rz_type_db_get_struct(core->analysis->typedb, name_char);
} else if (category == "Union") {
output = cmdRaw(QString("tuc %1").arg(typeName));
rzBaseType = rz_type_db_get_union(core->analysis->typedb, name_char);
} else if (category == "Enum") {
output = cmdRaw(QString("tec %1").arg(typeName));
rzBaseType = rz_type_db_get_enum(core->analysis->typedb, name_char);
} else if (category == "Typedef") {
output = cmdRaw(QString("ttc %1").arg(typeName));
rzBaseType = rz_type_db_get_typedef(core->analysis->typedb, name_char);
}

char *output_char = rz_type_db_base_type_as_string(core->analysis->typedb, rzBaseType);

output = QString(output_char);
return output;
}

Expand Down

0 comments on commit 76e2837

Please sign in to comment.