47 goto rz_type_db_new_fail;
51 goto rz_type_db_new_fail;
55 goto rz_type_db_new_fail;
59 goto rz_type_db_new_fail;
67 ht_pp_free(typedb->
types);
82 ht_pp_free(typedb->
types);
99 ht_pp_free(typedb->
types);
335 RZ_LOG_DEBUG(
"callable types: loaded \"%s\"\n", dbpath);
342 RZ_LOG_DEBUG(
"callable types: loaded \"%s\"\n", dbpath);
375 rz_list_foreach (enums,
iter,
e) {
393 rz_list_foreach (unions,
iter, u) {
411 rz_list_foreach (structs,
iter,
s) {
429 rz_list_foreach (typedefs,
iter, t) {
465 return btype !=
NULL;
545 if (!strcmp(cas->
name, member)) {
565 rz_list_foreach (enums,
iter,
e) {
598 for (
i = 0;
i < 32;
i++) {
856 bool is_anon =
false;
857 switch (
type->kind) {
859 if (!
type->identifier.name) {
862 is_anon = !strncmp(
type->identifier.name,
"anonymous ", strlen(
"anonymous "));
864 ht_pp_find(used_types,
type->identifier.name, self_ref);
865 *self_ref = *self_ref && !is_anon;
866 *self_ref_typename = *self_ref ?
strdup(
type->identifier.name) :
NULL;
872 switch (btype->
kind) {
875 if (!is_anon || print_anon) {
881 if (!is_anon || print_anon) {
887 if (!is_anon || print_anon) {
895 RZ_LOG_ERROR(
"Failed to get type representation of typedef of base type: %s\n", btype->
name);
927 if (
type->array.count) {
951 if (unfold_level < 0) {
960 no_end_semicolon = no_end_semicolon && (indent_level == 0);
962 end_newline = end_newline && (indent_level == 0);
964 if (indent_level == 0) {
967 anon_only = anon_only || anon_only_strict;
968 bool unfold_all = !anon_only && unfold_level;
969 bool unfold_anon = unfold_level;
971 char *separator =
" ";
973 indent = indent_level;
978 for (
int i = 0;
i < indent;
i++) {
985 bool self_ref =
false;
986 char *self_ref_typename =
NULL;
997 unfold_anon = unfold_all =
false;
998 }
else if (self_ref_typename) {
999 ht_pp_insert(used_types, self_ref_typename,
NULL);
1002 bool is_anon =
false;
1004 is_anon = !strncmp(
type->identifier.name,
"anonymous ", 10);
1016 switch (btype->
kind) {
1018 if (unfold_all || (is_anon && unfold_anon)) {
1030 for (
int i = 0;
i < indent;
i++) {
1037 if (unfold_all || (is_anon && unfold_anon)) {
1049 for (
int i = 0;
i < indent;
i++) {
1056 if (unfold_all || (is_anon && unfold_anon)) {
1067 for (
int i = 0;
i < indent;
i++) {
1079 for (
int i = 0;
i < indent;
i++) {
1101 rz_strbuf_appendf(
buf,
"%s%s%s", pointer_str ? pointer_str :
"", identifier ? identifier :
"", array_str ? array_str :
"");
1102 if (!no_end_semicolon) {
1108 if (self_ref_typename) {
1109 ht_pp_delete(used_types, self_ref_typename);
1110 free(self_ref_typename);
1133 if (unfold_level < 0) {
1136 HtPP *used_types = ht_pp_new0();
1138 RZ_LOG_ERROR(
"Failed to create hashtable while pretty printing types")
1142 ht_pp_free(used_types);
1158 switch (
type->kind) {
1161 return type->identifier.name;
1171 return type->callable->name;
1187 switch (
type->kind) {
1196 newtype->
array.count =
type->array.count;
1201 newtype->
pointer.is_const =
type->pointer.is_const;
1220 if (type1->kind != type2->kind) {
1223 switch (type1->kind) {
1225 return !strcmp(type1->identifier.name, type2->identifier.name);
1230 if (type1->array.count != type2->array.count) {
1237 return !strcmp(type1->callable->name, type2->callable->name);
1277 switch (
type->kind) {
1317 char *error_msg =
NULL;
1326 ht_pp_insert(typedb->
types, t->
name, t);
RZ_API void rz_type_base_type_free(RzBaseType *type)
Frees the RzBaseType instance and all of its members.
RZ_API RZ_OWN RzList * rz_type_db_get_base_types(const RzTypeDB *typedb)
Returns the list of all basic types.
RZ_API RZ_BORROW RzBaseType * rz_type_db_get_compound_type(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the compound RzBaseType in the types database given the name.
RZ_API RZ_BORROW RzBaseType * rz_type_db_get_base_type(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the RzBaseType in the types database given the name.
RZ_API bool rz_type_db_delete_base_type(RzTypeDB *typedb, RZ_NONNULL RzBaseType *type)
Removes RzBaseType from the Types DB.
RZ_API RZ_OWN RzList * rz_type_db_get_base_types_of_kind(const RzTypeDB *typedb, RzBaseTypeKind kind)
Returns the list of all basic types of the chosen kind.
int bits(struct state *s, int need)
RZ_API RZ_OWN RzTypeParser * rz_type_parser_init(HtPP *types, HtPP *callables)
Creates a new instance of the C type parser.
RZ_API void rz_type_parser_free(RZ_NONNULL RzTypeParser *parser)
Frees the instance of the C type parser without destroying hashtables.
RZ_API int rz_type_parse_string_stateless(RzTypeParser *parser, const char *code, char **error_msg)
Parses the C type string reusing the existing parser state.
RZ_API void Ht_() free(HtName_(Ht) *ht)
static void freefn(HtName_(Ht) *ht, HT_(Kv) *kv)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
insn_type_descr_t types[]
#define rz_warn_if_reached()
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
#define rz_io_bind_init(x)
#define RZ_LOG_DEBUG(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
#define RZ_STR_ISNOTEMPTY(x)
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API size_t rz_str_nlen(const char *s, size_t n)
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
RZ_API bool rz_strbuf_slice(RZ_NONNULL RzStrBuf *sb, size_t from, size_t len)
Cuts the current string into a substring.
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
RZ_API void rz_strbuf_free(RzStrBuf *sb)
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API int rz_strbuf_length(RzStrBuf *sb)
@ RZ_BASE_TYPE_KIND_TYPEDEF
@ RZ_BASE_TYPE_KIND_ATOMIC
@ RZ_BASE_TYPE_KIND_UNION
@ RZ_BASE_TYPE_KIND_STRUCT
@ RZ_TYPE_IDENTIFIER_KIND_STRUCT
@ RZ_TYPE_IDENTIFIER_KIND_ENUM
@ RZ_TYPE_IDENTIFIER_KIND_UNION
@ RZ_TYPE_PRINT_NO_END_SEMICOLON
@ RZ_TYPE_PRINT_SHOW_TYPEDEF
@ RZ_TYPE_PRINT_UNFOLD_ANON_ONLY
@ RZ_TYPE_PRINT_UNFOLD_ANON_ONLY_STRICT
@ RZ_TYPE_PRINT_END_NEWLINE
@ RZ_TYPE_PRINT_MULTILINE
@ RZ_TYPE_PRINT_ANONYMOUS
@ RZ_TYPE_KIND_IDENTIFIER
#define rz_vector_foreach(vec, it)
static size_t rz_vector_len(const RzVector *vec)
RZ_API bool rz_type_db_load_callables_sdb(RzTypeDB *typedb, RZ_NONNULL const char *path)
Loads the callable types from compiled SDB specified by path.
RZ_API bool rz_type_db_load_sdb(RzTypeDB *typedb, RZ_NONNULL const char *path)
Loads the types from compiled SDB specified by path.
RzBaseTypeStruct struct_data
RzBaseTypeUnion union_data
struct rz_type_t::@292::@295 pointer
struct rz_type_t::@292::@294 identifier
struct rz_type_t::@292::@296 array
int addr_bits
size of a pointer if > 0, otherwise bits is used.
const char * default_type
RZ_API RZ_OWN RzCallable * rz_type_callable_clone(RZ_BORROW RZ_NONNULL const RzCallable *callable)
Creates an exact clone of the RzCallable type.
RZ_API bool rz_type_func_exist(RzTypeDB *typedb, RZ_NONNULL const char *name)
Checks if the RzCallable type exists in the database given the name.
RZ_API RZ_OWN char * rz_type_callable_ptr_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the callable pointer C representation.
RZ_API void rz_type_callable_free(RZ_NONNULL RzCallable *callable)
Frees the RzCallable.
RZ_API bool rz_type_func_delete(RzTypeDB *typedb, RZ_NONNULL const char *name)
Removes RzCallable type from the types database.
RZ_API RZ_OWN char * rz_type_callable_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzCallable *callable)
Returns the callable C representation.
RZ_API bool rz_type_is_callable_ptr_nested(RZ_NONNULL const RzType *type)
Checks if the RzType is the nested pointer to the RzCallable.
RZ_API void rz_type_db_set_address_bits(RzTypeDB *typedb, int addr_bits)
Set the RzType target adress size.
static char * type_as_pretty_string(const RzTypeDB *typedb, const RzType *type, const char *identifier, HtPP *used_types, unsigned int opts, int unfold_level, int indent_level)
RZ_API ut64 rz_type_db_union_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the union type size in bits (target dependent)
RZ_API void rz_type_db_reload(RzTypeDB *typedb, const char *types_dir)
Re-initializes the types database for current target.
RZ_API ut64 rz_type_db_base_get_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the base type size in bits (target dependent)
RZ_API int rz_type_kind(RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the kind (RzBaseTypeKind) of the type.
static void formats_ht_free(HtPPKv *kv)
RZ_API void rz_type_db_set_os(RzTypeDB *typedb, const char *os)
Set the RzType target architecture operating system.
RZ_API RZ_BORROW const char * rz_type_identifier(RZ_NONNULL const RzType *type)
Returns the type C identifier.
RZ_API void rz_type_db_set_bits(RzTypeDB *typedb, int bits)
Set the RzType target architecture bits.
RZ_API ut64 rz_type_db_get_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Returns the type size in bits (target dependent)
RZ_API bool rz_types_equal(RZ_NONNULL const RzType *type1, RZ_NONNULL const RzType *type2)
Checks if two types are identical.
RZ_API void rz_type_db_free(RzTypeDB *typedb)
Frees the instance of the RzTypeDB.
static bool type_decl_as_pretty_string(const RzTypeDB *typedb, const RzType *type, HtPP *used_types, struct PrettyHelperBufs phbuf, bool *self_ref, char **self_ref_typename, bool zero_vla, bool print_anon, bool show_typedefs)
RZ_API RZ_OWN char * rz_type_declaration_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the type C declaration representation.
RZ_API void rz_type_db_purge(RzTypeDB *typedb)
Purges the instance of the RzTypeDB.
static void set_default_type(RzTypeTarget *target, int bits)
RZ_API RZ_BORROW const char * rz_type_db_enum_member_by_val(const RzTypeDB *typedb, RZ_NONNULL const char *name, ut64 val)
Returns the enum case name matching the cpecified value.
RZ_API bool rz_type_exists(RzTypeDB *typedb, RZ_NONNULL const char *name)
Checks if the type exists in the Type database.
RZ_API bool rz_type_db_edit_base_type(RzTypeDB *typedb, RZ_NONNULL const char *name, RZ_NONNULL const char *typestr)
Edits the existing base type given the new C code.
RZ_API void rz_type_free(RZ_NULLABLE RzType *type)
Frees the RzType.
RZ_API ut64 rz_type_db_typedef_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the typedef type size in bits (target dependent)
RZ_API RZ_OWN RzType * rz_type_clone(RZ_BORROW RZ_NONNULL const RzType *type)
Creates an exact clone of the RzType.
RZ_API void rz_type_db_set_endian(RzTypeDB *typedb, bool big_endian)
Set the RzType target architecture CPU.
RZ_API RZ_OWN char * rz_type_as_pretty_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type, RZ_NULLABLE const char *identifier, unsigned int opts, int unfold_level)
Return a string contining the type pretty printed according to the options provided.
RZ_API RzBaseType * rz_type_db_get_enum(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the enum base type matching the specified name.
RZ_API RZ_BORROW RzBaseType * rz_type_get_base_type(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the RzBaseType for the chosen RzType.
RZ_API ut64 rz_type_db_enum_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the enum type size in bits (target dependent)
RZ_API ut8 rz_type_db_pointer_size(const RzTypeDB *typedb)
Returns the pointer size for the current RzTypeDB target set.
RZ_API ut64 rz_type_db_struct_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the struct type size in bits (target dependent)
RZ_API RZ_OWN RzList * rz_type_db_enum_names(RzTypeDB *typedb)
Returns the list of all enum names.
RZ_API RZ_OWN char * rz_type_db_enum_get_bitfield(const RzTypeDB *typedb, RZ_NONNULL const char *name, ut64 val)
Returns all matching bitfields as an OR mask given the resulting value.
RZ_API RzTypeDB * rz_type_db_new()
Creates a new instance of the RzTypeDB.
RZ_API void rz_type_db_init(RzTypeDB *typedb, const char *types_dir, const char *arch, int bits, const char *os)
Initializes the types database for specified arch, bits, OS.
static void types_ht_free(HtPPKv *kv)
RZ_API bool rz_type_db_del(RzTypeDB *typedb, RZ_NONNULL const char *name)
Removes the type from the database.
static void callables_ht_free(HtPPKv *kv)
RZ_API RZ_OWN RzList * rz_type_db_union_names(RzTypeDB *typedb)
Returns the list of all union names.
RZ_API ut64 rz_type_db_atomic_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzBaseType *btype)
Returns the atomic type size in bits (target dependent)
RZ_API RZ_OWN RzList * rz_type_db_struct_names(RzTypeDB *typedb)
Returns the list of all struct names.
RZ_API RZ_OWN RzList * rz_type_db_all(RzTypeDB *typedb)
Returns the list of all type names.
RZ_API int rz_type_db_enum_member_by_name(const RzTypeDB *typedb, RZ_NONNULL const char *name, const char *member)
Returns the enum case value matched by the enum case name.
RZ_API RZ_OWN char * rz_type_identifier_declaration_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type, RZ_NONNULL const char *identifier)
Returns the type C representation with identifier.
RZ_API RzBaseType * rz_type_db_get_typedef(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the typedef base type matching the specified name.
RZ_API RZ_OWN RzList * rz_type_db_typedef_names(RzTypeDB *typedb)
Returns the list of all typedef (type aliases) names.
RZ_API RzBaseType * rz_type_db_get_union(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the union base type matching the specified name.
RZ_API RZ_OWN char * rz_type_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the type C representation.
RZ_API RzBaseType * rz_type_db_get_struct(const RzTypeDB *typedb, RZ_NONNULL const char *name)
returns the struct base type matching the specified name
RZ_API RZ_OWN RzList * rz_type_db_find_enums_by_val(const RzTypeDB *typedb, ut64 val)
Returns all enums and cases name matching the specified value.
RZ_API void rz_type_db_format_purge(RzTypeDB *typedb)
Purges formats in the instance of the RzTypeDB.
RZ_API void rz_type_db_set_cpu(RzTypeDB *typedb, const char *cpu)
Set the RzType target architecture CPU.
ut64(WINAPI *w32_GetEnabledXStateFeatures)()