Rizin
unix-like reverse engineering framework and cli tools
helpers.c File Reference
#include <rz_util.h>
#include <rz_type.h>
#include <string.h>

Go to the source code of this file.

Functions

RZ_API RZ_OWN RzTyperz_type_identifier_of_base_type (const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, bool is_const)
 Creates a new RzType indentifier from the given RzBaseType. More...
 
RZ_API RZ_OWN RzTyperz_type_identifier_of_base_type_str (const RzTypeDB *typedb, RZ_NONNULL const char *name)
 Creates a new RzType indentifier from the given RzBaseType name. More...
 
RZ_API RZ_OWN RzTyperz_type_pointer_of_base_type (const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, bool is_const)
 Creates a new pointer RzType from the given RzBaseType. More...
 
RZ_API RZ_OWN RzTyperz_type_pointer_of_base_type_str (const RzTypeDB *typedb, RZ_NONNULL const char *name, bool is_const)
 Creates a new pointer RzType from the given RzBaseType name. More...
 
RZ_API RZ_OWN RzTyperz_type_pointer_of_type (const RzTypeDB *typedb, RZ_NONNULL RzType *type, bool is_const)
 Creates a new pointer RzType from the given RzType. More...
 
RZ_API RZ_OWN RzTyperz_type_array_of_base_type (const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, size_t count)
 Creates a new array RzType from the given RzBaseType. More...
 
RZ_API RZ_OWN RzTyperz_type_array_of_base_type_str (const RzTypeDB *typedb, RZ_NONNULL const char *name, size_t count)
 Creates a new array RzType from the given RzBaseType name. More...
 
RZ_API RZ_OWN RzTyperz_type_array_of_type (const RzTypeDB *typedb, RZ_NONNULL RzType *type, size_t count)
 Creates a new array RzType from the given RzType. More...
 
RZ_API bool rz_type_atomic_eq (const RzTypeDB *typedb, RZ_NONNULL const RzType *typ1, RZ_NONNULL const RzType *typ2)
 Checks if two atomic RzTypes are equivalent. More...
 
RZ_API bool rz_type_atomic_str_eq (const RzTypeDB *typedb, RZ_NONNULL const RzType *typ1, RZ_NONNULL const char *name)
 Checks if two atomic types (RzType and RzBaseType) are equivalent. More...
 
RZ_API bool rz_type_atomic_is_void (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the RzType is "void". More...
 
RZ_API bool rz_type_atomic_is_const (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the atomic RzType is "const". More...
 
RZ_API bool rz_type_pointer_is_const (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the pointer RzType is "const". More...
 
static bool type_is_atomic_ptr (RZ_NONNULL const RzType *type, RZ_NONNULL const char *name)
 
static bool type_is_atomic_ptr_nested (RZ_NONNULL const RzType *type, RZ_NONNULL const char *name)
 
RZ_API bool rz_type_is_void_ptr (RZ_NONNULL const RzType *type)
 Checks if the pointer RzType is abstract pointer ("void *") More...
 
RZ_API bool rz_type_is_void_ptr_nested (RZ_NONNULL const RzType *type)
 Checks if the pointer RzType is a nested abstract pointer ("void **", "vpod ***", etc) More...
 
RZ_API bool rz_type_is_char_ptr (RZ_NONNULL const RzType *type)
 Checks if the pointer RzType is a string ("char *" or "const char *") More...
 
RZ_API bool rz_type_is_char_ptr_nested (RZ_NONNULL const RzType *type)
 Checks if the pointer RzType is a nested pointer of string ("char **", "char ***", etc) More...
 
RZ_API bool rz_type_is_identifier (RZ_NONNULL const RzType *type)
 Checks if the RzType is identifier. More...
 
RZ_API bool rz_type_is_strictly_atomic (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the RzType is strictly atomic. More...
 
RZ_API bool rz_type_is_atomic (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the RzType is atomic or derivative of it. More...
 
RZ_API bool rz_type_is_default (const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
 Checks if the RzType is default. More...
 
RZ_API RZ_OWN RzTyperz_type_new_default (const RzTypeDB *typedb)
 Creates a new instance of the default RzType type. More...
 
RZ_API bool rz_type_integral_set_sign (const RzTypeDB *typedb, RZ_NONNULL RzType **type, bool sign)
 If the type is unsigned it sets the sign. More...
 
RZ_API RZ_BORROW const char * rz_type_cond_tostring (RzTypeCond cc)
 RzTypeCond enum to string. More...
 
RZ_API RzTypeCond rz_type_cond_invert (RzTypeCond cond)
 return the inverted condition More...
 
RZ_API bool rz_type_cond_eval (RzTypeCond cond, st64 arg0, st64 arg1)
 evaluate the type condition on the arguments and return a bool accordingly. More...
 
RZ_API bool rz_type_cond_eval_single (RzTypeCond cond, st64 arg0)
 Same as rz_type_cond_eval, but it assumes arg1 to be 0. More...
 

Function Documentation

◆ rz_type_array_of_base_type()

RZ_API RZ_OWN RzType* rz_type_array_of_base_type ( const RzTypeDB typedb,
RZ_NONNULL const RzBaseType btype,
size_t  count 
)

Creates a new array RzType from the given RzBaseType.

Parameters
typedbType Database instance
btypeRzBaseType pointer
countThe number of the array elements

Definition at line 124 of file helpers.c.

124  {
126  if (!type) {
127  return NULL;
128  }
129  RzType *t = rz_type_identifier_of_base_type(typedb, btype, false);
130  if (!t) {
132  return NULL;
133  }
134  type->kind = RZ_TYPE_KIND_ARRAY;
135  type->array.type = t;
136  type->array.count = count;
137  return type;
138 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
RZ_API RZ_OWN RzType * rz_type_identifier_of_base_type(const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, bool is_const)
Creates a new RzType indentifier from the given RzBaseType.
Definition: helpers.c:15
int type
Definition: mipsasm.c:17
@ RZ_TYPE_KIND_ARRAY
Definition: rz_type.h:130
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API void rz_type_free(RZ_NULLABLE RzType *type)
Frees the RzType.
Definition: type.c:1273

References count, NULL, RZ_NEW0, rz_type_free(), rz_type_identifier_of_base_type(), RZ_TYPE_KIND_ARRAY, and type.

Referenced by rz_type_array_of_base_type_str().

◆ rz_type_array_of_base_type_str()

RZ_API RZ_OWN RzType* rz_type_array_of_base_type_str ( const RzTypeDB typedb,
RZ_NONNULL const char *  name,
size_t  count 
)

Creates a new array RzType from the given RzBaseType name.

Parameters
typedbType Database instance
nameRzBaseType name
countThe number of the array elements

Definition at line 147 of file helpers.c.

147  {
148  rz_return_val_if_fail(typedb && name && count, NULL);
149  RzBaseType *btype = rz_type_db_get_base_type(typedb, name);
150  if (!btype) {
151  return NULL;
152  }
153  return rz_type_array_of_base_type(typedb, btype, count);
154 }
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.
Definition: base.c:57
RZ_API RZ_OWN RzType * rz_type_array_of_base_type(const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, size_t count)
Creates a new array RzType from the given RzBaseType.
Definition: helpers.c:124
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Definition: z80asm.h:102

References count, NULL, rz_return_val_if_fail, rz_type_array_of_base_type(), and rz_type_db_get_base_type().

◆ rz_type_array_of_type()

RZ_API RZ_OWN RzType* rz_type_array_of_type ( const RzTypeDB typedb,
RZ_NONNULL RzType type,
size_t  count 
)

Creates a new array RzType from the given RzType.

Parameters
typedbType Database instance
typeRzType pointer
countThe number of the array elements

Definition at line 163 of file helpers.c.

163  {
164  RzType *newtype = RZ_NEW0(RzType);
165  if (!newtype) {
166  return NULL;
167  }
168  newtype->kind = RZ_TYPE_KIND_ARRAY;
169  newtype->array.type = type;
170  newtype->array.count = count;
171  return newtype;
172 }
RzTypeKind kind
Definition: rz_type.h:155
struct rz_type_t::@292::@296 array

References rz_type_t::array, count, rz_type_t::kind, NULL, RZ_NEW0, RZ_TYPE_KIND_ARRAY, and type.

◆ rz_type_atomic_eq()

RZ_API bool rz_type_atomic_eq ( const RzTypeDB typedb,
RZ_NONNULL const RzType typ1,
RZ_NONNULL const RzType typ2 
)

Checks if two atomic RzTypes are equivalent.

Parameters
typedbType Database instance
typ1First RzType type
typ2Second RzType type

Definition at line 183 of file helpers.c.

183  {
184  // We aim to compare only atomic types, we can't compare more complex ones for now
185  rz_return_val_if_fail(typ1 && typ2, false);
187  rz_return_val_if_fail(typ1->identifier.kind == RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, false);
188  rz_return_val_if_fail(typ2->identifier.kind == RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, false);
189  rz_return_val_if_fail(typ1->identifier.name, false);
190  rz_return_val_if_fail(typ2->identifier.name, false);
191  RzBaseType *btyp1 = rz_type_db_get_base_type(typedb, typ1->identifier.name);
192  RzBaseType *btyp2 = rz_type_db_get_base_type(typedb, typ2->identifier.name);
193  if (!btyp1 || !btyp2) {
194  return false;
195  }
197  return btyp1->name == btyp2->name && btyp1->size == btyp2->size;
198  // TODO: Should we also compare the btyp->type?
199 }
@ RZ_BASE_TYPE_KIND_ATOMIC
Definition: rz_type.h:77
@ RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED
Definition: rz_type.h:135
@ RZ_TYPE_KIND_IDENTIFIER
Definition: rz_type.h:128
char * name
Definition: rz_type.h:112
RzBaseTypeKind kind
Definition: rz_type.h:115

References rz_base_type_t::kind, rz_base_type_t::name, RZ_BASE_TYPE_KIND_ATOMIC, rz_return_val_if_fail, rz_type_db_get_base_type(), RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, and rz_base_type_t::size.

◆ rz_type_atomic_is_const()

RZ_API bool rz_type_atomic_is_const ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the atomic RzType is "const".

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 246 of file helpers.c.

246  {
247  rz_return_val_if_fail(type, false);
248  if (type->kind != RZ_TYPE_KIND_IDENTIFIER) {
249  return false;
250  }
251  return type->identifier.is_const;
252 }

References rz_return_val_if_fail, RZ_TYPE_KIND_IDENTIFIER, and type.

◆ rz_type_atomic_is_void()

RZ_API bool rz_type_atomic_is_void ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the RzType is "void".

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 232 of file helpers.c.

232  {
233  rz_return_val_if_fail(type, false);
234  if (type->kind != RZ_TYPE_KIND_IDENTIFIER) {
235  return false;
236  }
237  return !strcmp(type->identifier.name, "void");
238 }

References rz_return_val_if_fail, RZ_TYPE_KIND_IDENTIFIER, and type.

Referenced by var_type_set().

◆ rz_type_atomic_str_eq()

RZ_API bool rz_type_atomic_str_eq ( const RzTypeDB typedb,
RZ_NONNULL const RzType typ1,
RZ_NONNULL const char *  name 
)

Checks if two atomic types (RzType and RzBaseType) are equivalent.

Parameters
typedbType Database instance
typ1First RzType type
typ2Second RzBaseType type name

Definition at line 208 of file helpers.c.

208  {
209  // We aim to compare only atomic types, we can't compare more complex ones for now
210  rz_return_val_if_fail(typ1 && name, false);
211  rz_return_val_if_fail(typ1->kind == RZ_TYPE_KIND_IDENTIFIER, false);
212  rz_return_val_if_fail(typ1->identifier.kind == RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, false);
213  rz_return_val_if_fail(typ1->identifier.name, false);
214  RzBaseType *btyp1 = rz_type_db_get_base_type(typedb, typ1->identifier.name);
215  RzBaseType *btyp2 = rz_type_db_get_base_type(typedb, name);
216  if (!btyp1 || !btyp2) {
217  return false;
218  }
220  return btyp1->name == btyp2->name && btyp1->size == btyp2->size;
221  // TODO: Should we also compare the btyp->type?
222 }

References rz_base_type_t::kind, rz_base_type_t::name, RZ_BASE_TYPE_KIND_ATOMIC, rz_return_val_if_fail, rz_type_db_get_base_type(), RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, and rz_base_type_t::size.

Referenced by rz_core_analysis_var_display().

◆ rz_type_cond_eval()

RZ_API bool rz_type_cond_eval ( RzTypeCond  cond,
st64  arg0,
st64  arg1 
)

evaluate the type condition on the arguments and return a bool accordingly.

Parameters
condRzTypeCond
arg0
arg1
Returns
bool

Definition at line 534 of file helpers.c.

534  {
535  switch (cond) {
536  case RZ_TYPE_COND_EQ: return arg0 == arg1;
537  case RZ_TYPE_COND_NE: return arg0 != arg1;
538  case RZ_TYPE_COND_GE: return arg0 >= arg1;
539  case RZ_TYPE_COND_GT: return arg0 > arg1;
540  case RZ_TYPE_COND_LE: return arg0 <= arg1;
541  case RZ_TYPE_COND_LT: return arg0 < arg1;
542  default: return false;
543  }
544  return false;
545 }
@ RZ_TYPE_COND_LE
Less or equal.
Definition: rz_type.h:188
@ RZ_TYPE_COND_GE
Greater or equal.
Definition: rz_type.h:186
@ RZ_TYPE_COND_EQ
Equal.
Definition: rz_type.h:184
@ RZ_TYPE_COND_NE
Not equal.
Definition: rz_type.h:185
@ RZ_TYPE_COND_GT
Greater than.
Definition: rz_type.h:187
@ RZ_TYPE_COND_LT
Less than.
Definition: rz_type.h:189
#define cond(bop, top, mask, flags)

References cond, RZ_TYPE_COND_EQ, RZ_TYPE_COND_GE, RZ_TYPE_COND_GT, RZ_TYPE_COND_LE, RZ_TYPE_COND_LT, and RZ_TYPE_COND_NE.

Referenced by rz_analysis_cond_eval().

◆ rz_type_cond_eval_single()

RZ_API bool rz_type_cond_eval_single ( RzTypeCond  cond,
st64  arg0 
)

Same as rz_type_cond_eval, but it assumes arg1 to be 0.

Parameters
condRzTypeCond
arg0
Returns
bool

Definition at line 554 of file helpers.c.

554  {
555  switch (cond) {
556  case RZ_TYPE_COND_EQ: return !arg0;
557  case RZ_TYPE_COND_NE: return arg0;
558  case RZ_TYPE_COND_GT: return arg0 > 0;
559  case RZ_TYPE_COND_GE: return arg0 >= 0;
560  case RZ_TYPE_COND_LT: return arg0 < 0;
561  case RZ_TYPE_COND_LE: return arg0 <= 0;
562  default: return false;
563  }
564  return false;
565 }

References cond, RZ_TYPE_COND_EQ, RZ_TYPE_COND_GE, RZ_TYPE_COND_GT, RZ_TYPE_COND_LE, RZ_TYPE_COND_LT, and RZ_TYPE_COND_NE.

Referenced by rz_analysis_cond_eval().

◆ rz_type_cond_invert()

RZ_API RzTypeCond rz_type_cond_invert ( RzTypeCond  cond)

return the inverted condition

Parameters
condRzTypeCond
Returns
RzTypeCond

Definition at line 504 of file helpers.c.

504  {
505  switch (cond) {
506  case RZ_TYPE_COND_LE:
507  return RZ_TYPE_COND_GT;
508  case RZ_TYPE_COND_LT:
509  return RZ_TYPE_COND_GE;
510  case RZ_TYPE_COND_GE:
511  return RZ_TYPE_COND_LT;
512  case RZ_TYPE_COND_GT:
513  return RZ_TYPE_COND_LE;
514  case RZ_TYPE_COND_AL:
515  return RZ_TYPE_COND_NV;
516  case RZ_TYPE_COND_NE:
517  return RZ_TYPE_COND_EQ;
518  case RZ_TYPE_COND_EQ:
519  return RZ_TYPE_COND_NE;
520  default:
522  break;
523  }
524  return 0;
525 }
#define rz_warn_if_reached()
Definition: rz_assert.h:29
@ RZ_TYPE_COND_NV
Never executed must be a nop? :D.
Definition: rz_type.h:190
@ RZ_TYPE_COND_AL
Always executed (no condition)
Definition: rz_type.h:183

References cond, RZ_TYPE_COND_AL, RZ_TYPE_COND_EQ, RZ_TYPE_COND_GE, RZ_TYPE_COND_GT, RZ_TYPE_COND_LE, RZ_TYPE_COND_LT, RZ_TYPE_COND_NE, RZ_TYPE_COND_NV, and rz_warn_if_reached.

Referenced by propagate_types_among_used_variables().

◆ rz_type_cond_tostring()

RZ_API RZ_BORROW const char* rz_type_cond_tostring ( RzTypeCond  cc)

RzTypeCond enum to string.

Parameters
ccRzTypeCond
Returns
const char *

Definition at line 471 of file helpers.c.

471  {
472  switch (cc) {
473  case RZ_TYPE_COND_EQ: return "eq";
474  case RZ_TYPE_COND_NV: return "nv";
475  case RZ_TYPE_COND_NE: return "ne";
476  case RZ_TYPE_COND_HS: return "hs";
477  case RZ_TYPE_COND_LO: return "lo";
478  case RZ_TYPE_COND_MI: return "mi";
479  case RZ_TYPE_COND_PL: return "pl";
480  case RZ_TYPE_COND_VS: return "vs";
481  case RZ_TYPE_COND_VC: return "vc";
482  case RZ_TYPE_COND_HI: return "hi";
483  case RZ_TYPE_COND_LS: return "ls";
484  case RZ_TYPE_COND_GE: return "ge";
485  case RZ_TYPE_COND_LT: return "lt";
486  case RZ_TYPE_COND_GT: return "gt";
487  case RZ_TYPE_COND_LE: return "le";
488  case RZ_TYPE_COND_AL: return "al";
489  case RZ_TYPE_COND_HEX_SCL_TRUE: return "scl-t";
490  case RZ_TYPE_COND_HEX_SCL_FALSE: return "scl-f";
491  case RZ_TYPE_COND_HEX_VEC_TRUE: return "vec-t";
492  case RZ_TYPE_COND_HEX_VEC_FALSE: return "vec-f";
493  case RZ_TYPE_COND_EXCEPTION: return "excptn";
494  }
495  return "??";
496 }
@ RZ_TYPE_COND_LO
Carry clear Less than.
Definition: rz_type.h:192
@ RZ_TYPE_COND_VS
Overflow Unordered.
Definition: rz_type.h:195
@ RZ_TYPE_COND_HEX_SCL_TRUE
Definition: rz_type.h:199
@ RZ_TYPE_COND_HEX_VEC_TRUE
Definition: rz_type.h:201
@ RZ_TYPE_COND_VC
No overflow Not unordered.
Definition: rz_type.h:196
@ RZ_TYPE_COND_HEX_SCL_FALSE
Definition: rz_type.h:200
@ RZ_TYPE_COND_LS
Unsigned lower or same Less than or equal.
Definition: rz_type.h:198
@ RZ_TYPE_COND_HS
Carry set >, ==, or unordered.
Definition: rz_type.h:191
@ RZ_TYPE_COND_MI
Minus, negative Less than.
Definition: rz_type.h:193
@ RZ_TYPE_COND_HI
Unsigned higher Greater than, or unordered.
Definition: rz_type.h:197
@ RZ_TYPE_COND_HEX_VEC_FALSE
Definition: rz_type.h:202
@ RZ_TYPE_COND_PL
Plus, positive or zero >, ==, or unordered.
Definition: rz_type.h:194
@ RZ_TYPE_COND_EXCEPTION
Definition: rz_type.h:203

References RZ_TYPE_COND_AL, RZ_TYPE_COND_EQ, RZ_TYPE_COND_EXCEPTION, RZ_TYPE_COND_GE, RZ_TYPE_COND_GT, RZ_TYPE_COND_HEX_SCL_FALSE, RZ_TYPE_COND_HEX_SCL_TRUE, RZ_TYPE_COND_HEX_VEC_FALSE, RZ_TYPE_COND_HEX_VEC_TRUE, RZ_TYPE_COND_HI, RZ_TYPE_COND_HS, RZ_TYPE_COND_LE, RZ_TYPE_COND_LO, RZ_TYPE_COND_LS, RZ_TYPE_COND_LT, RZ_TYPE_COND_MI, RZ_TYPE_COND_NE, RZ_TYPE_COND_NV, RZ_TYPE_COND_PL, RZ_TYPE_COND_VC, and RZ_TYPE_COND_VS.

Referenced by core_analysis_bytes_json(), and core_analysis_bytes_standard().

◆ rz_type_identifier_of_base_type()

RZ_API RZ_OWN RzType* rz_type_identifier_of_base_type ( const RzTypeDB typedb,
RZ_NONNULL const RzBaseType btype,
bool  is_const 
)

Creates a new RzType indentifier from the given RzBaseType.

Parameters
typedbType Database instance
btypeRzBaseType pointer
is_constSet the identifier to "const" if true

Definition at line 15 of file helpers.c.

15  {
16  rz_return_val_if_fail(typedb && btype, NULL);
18  if (!type) {
19  return NULL;
20  }
22  type->identifier.name = strdup(btype->name);
23  type->identifier.is_const = is_const;
24  switch (btype->kind) {
26  type->identifier.kind = RZ_TYPE_IDENTIFIER_KIND_STRUCT;
27  break;
29  type->identifier.kind = RZ_TYPE_IDENTIFIER_KIND_UNION;
30  break;
32  type->identifier.kind = RZ_TYPE_IDENTIFIER_KIND_ENUM;
33  break;
34  default:
35  type->identifier.kind = RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED;
36  break;
37  }
38  return type;
39 }
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")
@ RZ_BASE_TYPE_KIND_UNION
Definition: rz_type.h:74
@ RZ_BASE_TYPE_KIND_STRUCT
Definition: rz_type.h:73
@ RZ_BASE_TYPE_KIND_ENUM
Definition: rz_type.h:75
@ RZ_TYPE_IDENTIFIER_KIND_STRUCT
Definition: rz_type.h:136
@ RZ_TYPE_IDENTIFIER_KIND_ENUM
Definition: rz_type.h:138
@ RZ_TYPE_IDENTIFIER_KIND_UNION
Definition: rz_type.h:137

References NULL, RZ_BASE_TYPE_KIND_ENUM, RZ_BASE_TYPE_KIND_STRUCT, RZ_BASE_TYPE_KIND_UNION, RZ_NEW0, rz_return_val_if_fail, RZ_TYPE_IDENTIFIER_KIND_ENUM, RZ_TYPE_IDENTIFIER_KIND_STRUCT, RZ_TYPE_IDENTIFIER_KIND_UNION, RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, strdup(), and type.

Referenced by rz_analysis_function_blocks_switch_type_handler(), rz_type_array_of_base_type(), rz_type_db_base_type_as_pretty_string(), rz_type_db_base_type_as_string(), rz_type_identifier_of_base_type_str(), rz_type_integral_set_sign(), rz_type_new_default(), rz_type_path_by_offset(), and rz_type_pointer_of_base_type().

◆ rz_type_identifier_of_base_type_str()

RZ_API RZ_OWN RzType* rz_type_identifier_of_base_type_str ( const RzTypeDB typedb,
RZ_NONNULL const char *  name 
)

Creates a new RzType indentifier from the given RzBaseType name.

Parameters
typedbType Database instance
nameRzBaseType name

Definition at line 47 of file helpers.c.

47  {
48  rz_return_val_if_fail(typedb && name, NULL);
49  RzBaseType *btype = rz_type_db_get_base_type(typedb, name);
50  if (!btype) {
51  return NULL;
52  }
53  return rz_type_identifier_of_base_type(typedb, btype, false);
54 }

References NULL, rz_return_val_if_fail, rz_type_db_get_base_type(), and rz_type_identifier_of_base_type().

Referenced by path_walker().

◆ rz_type_integral_set_sign()

RZ_API bool rz_type_integral_set_sign ( const RzTypeDB typedb,
RZ_NONNULL RzType **  type,
bool  sign 
)

If the type is unsigned it sets the sign.

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 430 of file helpers.c.

430  {
431  rz_return_val_if_fail(type && *type, false);
432  RzType *t = *type;
433  if (t->kind != RZ_TYPE_KIND_IDENTIFIER) {
434  return false;
435  }
436  if (rz_type_is_integral(typedb, t)) {
437  const char *identifier = rz_type_identifier(t);
438  if (!identifier) {
439  return false;
440  }
441  RzBaseType *btype = rz_type_db_get_base_type(typedb, identifier);
442  if (!btype) {
443  return false;
444  }
446  // We only change typesubclass if it's different from the current one
447  if (rz_base_type_typeclass(typedb, btype) == typesubclass) {
448  return true;
449  }
450  size_t typesize = rz_type_db_base_get_bitsize(typedb, btype);
451  RzBaseType *signedbtype = rz_type_typeclass_get_default_sized(typedb, typesubclass, typesize);
452  if (!signedbtype) {
453  return false;
454  }
455  RzType *signedtype = rz_type_identifier_of_base_type(typedb, signedbtype, false);
456  if (!signedtype) {
457  return false;
458  }
459  rz_type_free(t);
460  *type = signedtype;
461  }
462  return false;
463 }
RzTypeTypeclass
Definition: rz_type.h:61
@ RZ_TYPE_TYPECLASS_INTEGRAL_SIGNED
Definition: rz_type.h:67
@ RZ_TYPE_TYPECLASS_INTEGRAL_UNSIGNED
Definition: rz_type.h:68
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)
Definition: type.c:755
RZ_API RZ_BORROW const char * rz_type_identifier(RZ_NONNULL const RzType *type)
Returns the type C identifier.
Definition: type.c:1155
RZ_API bool rz_type_is_integral(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Checks if the RzType is Integral typeclass.
Definition: typeclass.c:218
RZ_API RZ_OWN RzBaseType * rz_type_typeclass_get_default_sized(const RzTypeDB *typedb, RzTypeTypeclass typeclass, size_t size)
Returns the default base type given the typeclass and size.
Definition: typeclass.c:370
RZ_API RzTypeTypeclass rz_base_type_typeclass(const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *type)
Gets the base type class.
Definition: typeclass.c:147

References rz_type_t::kind, rz_base_type_typeclass(), rz_return_val_if_fail, rz_type_db_base_get_bitsize(), rz_type_db_get_base_type(), rz_type_free(), rz_type_identifier(), rz_type_identifier_of_base_type(), rz_type_is_integral(), RZ_TYPE_KIND_IDENTIFIER, rz_type_typeclass_get_default_sized(), RZ_TYPE_TYPECLASS_INTEGRAL_SIGNED, RZ_TYPE_TYPECLASS_INTEGRAL_UNSIGNED, and type.

Referenced by var_type_set_sign().

◆ rz_type_is_atomic()

RZ_API bool rz_type_is_atomic ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the RzType is atomic or derivative of it.

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 371 of file helpers.c.

371  {
372  rz_return_val_if_fail(type, false);
373  if (type->kind == RZ_TYPE_KIND_POINTER) {
374  return rz_type_is_atomic(typedb, type->pointer.type);
375  }
376  if (type->kind == RZ_TYPE_KIND_ARRAY) {
377  return rz_type_is_atomic(typedb, type->array.type);
378  }
379  if (type->kind != RZ_TYPE_KIND_IDENTIFIER) {
380  return false;
381  }
382  if (type->identifier.kind != RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED) {
383  return false;
384  }
385  rz_return_val_if_fail(type->identifier.name, false);
386  RzBaseType *btyp = rz_type_db_get_base_type(typedb, type->identifier.name);
387  if (!btyp) {
388  return false;
389  }
390  return btyp->kind == RZ_BASE_TYPE_KIND_ATOMIC;
391 }
RZ_API bool rz_type_is_atomic(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Checks if the RzType is atomic or derivative of it.
Definition: helpers.c:371
@ RZ_TYPE_KIND_POINTER
Definition: rz_type.h:129

References rz_base_type_t::kind, RZ_BASE_TYPE_KIND_ATOMIC, rz_return_val_if_fail, rz_type_db_get_base_type(), RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_ARRAY, RZ_TYPE_KIND_IDENTIFIER, RZ_TYPE_KIND_POINTER, and type.

Referenced by base_type_to_format_unfold().

◆ rz_type_is_char_ptr()

RZ_API bool rz_type_is_char_ptr ( RZ_NONNULL const RzType type)

Checks if the pointer RzType is a string ("char *" or "const char *")

Parameters
typeRzType type pointer

Definition at line 318 of file helpers.c.

318  {
319  rz_return_val_if_fail(type, false);
320  return type_is_atomic_ptr(type, "char");
321 }
static bool type_is_atomic_ptr(RZ_NONNULL const RzType *type, RZ_NONNULL const char *name)
Definition: helpers.c:268

References rz_return_val_if_fail, type, and type_is_atomic_ptr().

Referenced by rz_type_as_format().

◆ rz_type_is_char_ptr_nested()

RZ_API bool rz_type_is_char_ptr_nested ( RZ_NONNULL const RzType type)

Checks if the pointer RzType is a nested pointer of string ("char **", "char ***", etc)

Parameters
typeRzType type pointer

Definition at line 328 of file helpers.c.

328  {
329  rz_return_val_if_fail(type, false);
330  return type_is_atomic_ptr_nested(type, "char");
331 }
static bool type_is_atomic_ptr_nested(RZ_NONNULL const RzType *type, RZ_NONNULL const char *name)
Definition: helpers.c:279

References rz_return_val_if_fail, type, and type_is_atomic_ptr_nested().

Referenced by var_type_simple_to_complex().

◆ rz_type_is_default()

RZ_API bool rz_type_is_default ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the RzType is default.

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 399 of file helpers.c.

399  {
400  rz_return_val_if_fail(type, false);
401  if (type->kind != RZ_TYPE_KIND_IDENTIFIER) {
402  return false;
403  }
404  if (type->identifier.kind != RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED) {
405  return false;
406  }
407  return !strcmp(type->identifier.name, typedb->target->default_type) && !type->identifier.is_const;
408 }
RzTypeTarget * target
Definition: rz_type.h:36
const char * default_type
Definition: rz_type.h:26

References rz_type_target_t::default_type, rz_return_val_if_fail, RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, rz_type_db_t::target, and type.

Referenced by var_type_set().

◆ rz_type_is_identifier()

RZ_API bool rz_type_is_identifier ( RZ_NONNULL const RzType type)

Checks if the RzType is identifier.

Parameters
typeRzType type pointer

Definition at line 338 of file helpers.c.

338  {
339  rz_return_val_if_fail(type, false);
340  return type->kind == RZ_TYPE_KIND_IDENTIFIER;
341 }

References rz_return_val_if_fail, RZ_TYPE_KIND_IDENTIFIER, and type.

Referenced by base_type_to_format_unfold().

◆ rz_type_is_strictly_atomic()

RZ_API bool rz_type_is_strictly_atomic ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the RzType is strictly atomic.

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 349 of file helpers.c.

349  {
350  rz_return_val_if_fail(type, false);
351  if (type->kind != RZ_TYPE_KIND_IDENTIFIER) {
352  return false;
353  }
354  if (type->identifier.kind != RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED) {
355  return false;
356  }
357  rz_return_val_if_fail(type->identifier.name, false);
358  RzBaseType *btyp = rz_type_db_get_base_type(typedb, type->identifier.name);
359  if (!btyp) {
360  return false;
361  }
362  return btyp->kind == RZ_BASE_TYPE_KIND_ATOMIC;
363 }

References rz_base_type_t::kind, RZ_BASE_TYPE_KIND_ATOMIC, rz_return_val_if_fail, rz_type_db_get_base_type(), RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, and type.

Referenced by rz_analysis_var_resolve_overlaps(), and rz_core_analysis_var_display().

◆ rz_type_is_void_ptr()

RZ_API bool rz_type_is_void_ptr ( RZ_NONNULL const RzType type)

Checks if the pointer RzType is abstract pointer ("void *")

Parameters
typeRzType type pointer

Definition at line 298 of file helpers.c.

298  {
299  rz_return_val_if_fail(type, false);
300  return type_is_atomic_ptr(type, "void");
301 }

References rz_return_val_if_fail, type, and type_is_atomic_ptr().

Referenced by rz_type_as_format(), and var_type_set().

◆ rz_type_is_void_ptr_nested()

RZ_API bool rz_type_is_void_ptr_nested ( RZ_NONNULL const RzType type)

Checks if the pointer RzType is a nested abstract pointer ("void **", "vpod ***", etc)

Parameters
typeRzType type pointer

Definition at line 308 of file helpers.c.

308  {
309  rz_return_val_if_fail(type, false);
310  return type_is_atomic_ptr_nested(type, "void");
311 }

References rz_return_val_if_fail, type, and type_is_atomic_ptr_nested().

◆ rz_type_new_default()

RZ_API RZ_OWN RzType* rz_type_new_default ( const RzTypeDB typedb)

Creates a new instance of the default RzType type.

Parameters
typedbType Database instance

Definition at line 415 of file helpers.c.

415  {
416  rz_return_val_if_fail(typedb, NULL);
417  RzBaseType *btype = rz_type_db_get_base_type(typedb, typedb->target->default_type);
418  if (!btype) {
419  return NULL;
420  }
421  return rz_type_identifier_of_base_type(typedb, btype, false);
422 }

References rz_type_target_t::default_type, NULL, rz_return_val_if_fail, rz_type_db_get_base_type(), rz_type_identifier_of_base_type(), and rz_type_db_t::target.

◆ rz_type_pointer_is_const()

RZ_API bool rz_type_pointer_is_const ( const RzTypeDB typedb,
RZ_NONNULL const RzType type 
)

Checks if the pointer RzType is "const".

Parameters
typedbType Database instance
typeRzType type pointer

Definition at line 260 of file helpers.c.

260  {
261  rz_return_val_if_fail(type, false);
262  if (type->kind != RZ_TYPE_KIND_POINTER) {
263  return false;
264  }
265  return type->pointer.is_const;
266 }

References rz_return_val_if_fail, RZ_TYPE_KIND_POINTER, and type.

◆ rz_type_pointer_of_base_type()

RZ_API RZ_OWN RzType* rz_type_pointer_of_base_type ( const RzTypeDB typedb,
RZ_NONNULL const RzBaseType btype,
bool  is_const 
)

Creates a new pointer RzType from the given RzBaseType.

Parameters
typedbType Database instance
btypeRzBaseType pointer
is_constSet the pointer to "const" if true

Definition at line 63 of file helpers.c.

63  {
65  if (!type) {
66  return NULL;
67  }
68  RzType *t = rz_type_identifier_of_base_type(typedb, btype, false);
69  if (!t) {
71  return NULL;
72  }
73  type->kind = RZ_TYPE_KIND_POINTER;
74  type->pointer.type = t;
75  type->pointer.is_const = is_const;
76  return type;
77 }

References NULL, RZ_NEW0, rz_type_free(), rz_type_identifier_of_base_type(), RZ_TYPE_KIND_POINTER, and type.

Referenced by rz_type_pointer_of_base_type_str().

◆ rz_type_pointer_of_base_type_str()

RZ_API RZ_OWN RzType* rz_type_pointer_of_base_type_str ( const RzTypeDB typedb,
RZ_NONNULL const char *  name,
bool  is_const 
)

Creates a new pointer RzType from the given RzBaseType name.

Parameters
typedbType Database instance
nameRzBaseType name
is_constSet the pointer to "const" if true

Definition at line 86 of file helpers.c.

86  {
87  rz_return_val_if_fail(typedb && name, NULL);
88  RzBaseType *btype = rz_type_db_get_base_type(typedb, name);
89  if (!btype) {
90  return NULL;
91  }
92  return rz_type_pointer_of_base_type(typedb, btype, is_const);
93 }
RZ_API RZ_OWN RzType * rz_type_pointer_of_base_type(const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, bool is_const)
Creates a new pointer RzType from the given RzBaseType.
Definition: helpers.c:63

References NULL, rz_return_val_if_fail, rz_type_db_get_base_type(), and rz_type_pointer_of_base_type().

Referenced by rz_type_pointer_of_type().

◆ rz_type_pointer_of_type()

RZ_API RZ_OWN RzType* rz_type_pointer_of_type ( const RzTypeDB typedb,
RZ_NONNULL RzType type,
bool  is_const 
)

Creates a new pointer RzType from the given RzType.

Parameters
typedbType Database instance
typeRzType pointer
is_constSet the pointer to "const" if true

Definition at line 102 of file helpers.c.

102  {
103  rz_return_val_if_fail(typedb && type, NULL);
104  if (type->kind == RZ_TYPE_KIND_IDENTIFIER) {
105  return rz_type_pointer_of_base_type_str(typedb, type->identifier.name, is_const);
106  }
107  RzType *newtype = RZ_NEW0(RzType);
108  if (!newtype) {
109  return NULL;
110  }
111  newtype->kind = RZ_TYPE_KIND_POINTER;
112  newtype->pointer.type = type;
113  newtype->pointer.is_const = is_const;
114  return newtype;
115 }
RZ_API RZ_OWN RzType * rz_type_pointer_of_base_type_str(const RzTypeDB *typedb, RZ_NONNULL const char *name, bool is_const)
Creates a new pointer RzType from the given RzBaseType name.
Definition: helpers.c:86
struct rz_type_t::@292::@295 pointer

References rz_type_t::kind, NULL, rz_type_t::pointer, RZ_NEW0, rz_return_val_if_fail, RZ_TYPE_KIND_IDENTIFIER, RZ_TYPE_KIND_POINTER, rz_type_pointer_of_base_type_str(), and type.

Referenced by var_type_set().

◆ type_is_atomic_ptr()

static bool type_is_atomic_ptr ( RZ_NONNULL const RzType type,
RZ_NONNULL const char *  name 
)
static

Definition at line 268 of file helpers.c.

268  {
269  rz_return_val_if_fail(type && name, false);
270  if (type->kind != RZ_TYPE_KIND_POINTER) {
271  return false;
272  }
273  // There should not exist pointers to the empty types
274  RzType *ptr = type->pointer.type;
275  rz_return_val_if_fail(ptr, false);
276  return ptr->kind == RZ_TYPE_KIND_IDENTIFIER && ptr->identifier.kind == RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED && !strcmp(ptr->identifier.name, name);
277 }
struct rz_type_t::@292::@294 identifier

References rz_type_t::identifier, rz_type_t::kind, rz_return_val_if_fail, RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, RZ_TYPE_KIND_POINTER, and type.

Referenced by rz_type_is_char_ptr(), and rz_type_is_void_ptr().

◆ type_is_atomic_ptr_nested()

static bool type_is_atomic_ptr_nested ( RZ_NONNULL const RzType type,
RZ_NONNULL const char *  name 
)
static

Definition at line 279 of file helpers.c.

279  {
280  rz_return_val_if_fail(type && name, false);
281  if (type->kind != RZ_TYPE_KIND_POINTER) {
282  return false;
283  }
284  // There should not exist pointers to the empty types
285  RzType *ptr = type->pointer.type;
286  rz_return_val_if_fail(ptr, false);
287  if (ptr->kind == RZ_TYPE_KIND_POINTER) {
288  return type_is_atomic_ptr_nested(ptr, name);
289  }
290  return ptr->kind == RZ_TYPE_KIND_IDENTIFIER && ptr->identifier.kind == RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED && !strcmp(ptr->identifier.name, name);
291 }

References rz_type_t::identifier, rz_type_t::kind, rz_return_val_if_fail, RZ_TYPE_IDENTIFIER_KIND_UNSPECIFIED, RZ_TYPE_KIND_IDENTIFIER, RZ_TYPE_KIND_POINTER, and type.

Referenced by rz_type_is_char_ptr_nested(), and rz_type_is_void_ptr_nested().