Rizin
unix-like reverse engineering framework and cli tools
value.c File Reference

Go to the source code of this file.

Functions

RZ_API RZ_OWN RzILValrz_il_value_new (RzILTypePure type)
 
RZ_API RZ_OWN RzILValrz_il_value_new_bitv (RZ_NONNULL RzBitVector *bv)
 
RZ_API RZ_OWN RzILValrz_il_value_new_bool (RZ_NONNULL RzILBool *b)
 
RZ_API RZ_OWN RzILValrz_il_value_new_zero_of (RzILSortPure sort)
 
RZ_API RZ_OWN RzILValrz_il_value_dup (RZ_NONNULL const RzILVal *val)
 
RZ_API void rz_il_value_free (RZ_NULLABLE RzILVal *val)
 
RZ_API RzILSortPure rz_il_value_get_sort (RZ_NONNULL RzILVal *val)
 
RZ_API RZ_OWN RzBitVectorrz_il_value_to_bv (RZ_NONNULL const RzILVal *val)
 
RZ_API bool rz_il_value_eq (RZ_NONNULL const RzILVal *a, RZ_NONNULL const RzILVal *b)
 

Function Documentation

◆ rz_il_value_dup()

RZ_API RZ_OWN RzILVal* rz_il_value_dup ( RZ_NONNULL const RzILVal val)

Clone an RzILVal

Parameters
valRzILVal, pointer to the value you want to dump
Returns
dump RzILVal, pointer to the dumped value

Definition at line 85 of file value.c.

85  {
87  RzILBool *b = NULL;
88  RzBitVector *bv = NULL;
89 
90  switch (val->type) {
92  b = rz_il_bool_new(val->data.b->b);
93  return b ? rz_il_value_new_bool(b) : NULL;
95  bv = rz_bv_dup(val->data.bv);
96  return bv ? rz_il_value_new_bitv(bv) : NULL;
97  default:
99  return NULL;
100  }
101 }
ut16 val
Definition: armass64_const.h:6
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN RzILVal * rz_il_value_new_bitv(RZ_NONNULL RzBitVector *bv)
Definition: value.c:28
RZ_API RZ_OWN RzILVal * rz_il_value_new_bool(RZ_NONNULL RzILBool *b)
Definition: value.c:43
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
#define b(i)
Definition: sha256.c:42
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
structure for bitvector
Definition: rz_bitvector.h:19

References b, NULL, rz_bv_dup(), rz_il_bool_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_value_new_bitv(), rz_il_value_new_bool(), rz_return_val_if_fail, rz_warn_if_reached, and val.

Referenced by rz_il_event_var_read_new(), rz_il_event_var_write_new(), and setup_vm_init_state().

◆ rz_il_value_eq()

RZ_API bool rz_il_value_eq ( RZ_NONNULL const RzILVal a,
RZ_NONNULL const RzILVal b 
)

Check if two IL values are of equal sort and contents

Definition at line 157 of file value.c.

157  {
158  rz_return_val_if_fail(a && b, false);
159  if (a->type != b->type) {
160  return false;
161  }
162  switch (a->type) {
164  return a->data.b->b == b->data.b->b;
166  return rz_bv_eq(a->data.bv, b->data.bv);
167  default:
169  return false;
170  }
171 }
RZ_API bool rz_bv_eq(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1041
#define a(i)
Definition: sha256.c:41

References a, b, rz_bv_eq(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and rz_warn_if_reached.

◆ rz_il_value_free()

RZ_API void rz_il_value_free ( RZ_NULLABLE RzILVal val)

Free a RzILVal value

Parameters
valRzILVal, pointer to the RzILVal instance

Definition at line 107 of file value.c.

107  {
108  if (!val) {
109  return;
110  }
111  switch (val->type) {
113  rz_il_bool_free(val->data.b);
114  break;
116  rz_bv_free(val->data.bv);
117  break;
118  default:
119  break;
120  }
121  free(val);
122 }
RZ_API void rz_il_bool_free(RzILBool *bool_var)
Definition: bool.c:74
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85

References free(), rz_bv_free(), rz_il_bool_free(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, and val.

Referenced by rz_analysis_il_init_state_set_var(), rz_il_event_free(), rz_il_value_new_zero_of(), rz_il_var_set_bind(), rz_il_vm_pop_local_pure_var(), val_ht_free(), and var_state_free().

◆ rz_il_value_get_sort()

RZ_API RzILSortPure rz_il_value_get_sort ( RZ_NONNULL RzILVal val)

Get the sort that val belongs to

Definition at line 127 of file value.c.

127  {
128  RzILSortPure r = { 0 };
129  r.type = val->type;
130  if (val->type == RZ_IL_TYPE_PURE_BITVECTOR) {
131  r.props.bv.length = rz_bv_len(val->data.bv);
132  }
133  return r;
134 }
#define r
Definition: crypto_rc6.c:12
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1140

References r, rz_bv_len(), RZ_IL_TYPE_PURE_BITVECTOR, and val.

Referenced by rz_il_var_set_bind(), rz_il_vm_pop_local_pure_var(), rz_il_vm_push_local_pure_var(), and rz_il_vm_set_local_var().

◆ rz_il_value_new()

RZ_API RZ_OWN RzILVal* rz_il_value_new ( RzILTypePure  type)

Returns a new RzILVal (Any type)

Parameters
typeRzILVarType to set of the value
Returns
val RzILVal, pointer to this value

Definition at line 13 of file value.c.

13  {
14  RzILVal *ret;
15  ret = RZ_NEW0(RzILVal);
16  if (!ret) {
17  return NULL;
18  }
19  ret->type = type;
20  return ret;
21 }
int type
Definition: mipsasm.c:17
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzILTypePure type
type of value
Definition: value.h:25

References NULL, RZ_NEW0, type, and rz_il_val_t::type.

Referenced by rz_il_value_new_bitv(), rz_il_value_new_bool(), and rz_il_value_new_zero_of().

◆ rz_il_value_new_bitv()

RZ_API RZ_OWN RzILVal* rz_il_value_new_bitv ( RZ_NONNULL RzBitVector bv)

Returns a new RzILVal (Bitvector type)

Parameters
bvRzBitVector to set
Returns
val RzILVal, pointer to this value

Definition at line 28 of file value.c.

28  {
31  if (!ret) {
32  return NULL;
33  }
34  ret->data.bv = bv;
35  return ret;
36 }
RZ_API RZ_OWN RzILVal * rz_il_value_new(RzILTypePure type)
Definition: value.c:13
RzValUnion data
data pointer
Definition: value.h:26
RzBitVector * bv
Definition: value.h:17

References RzValUnion::bv, rz_il_val_t::data, NULL, RZ_IL_TYPE_PURE_BITVECTOR, rz_il_value_new(), and rz_return_val_if_fail.

Referenced by il_config(), rz_core_analysis_il_vm_set(), rz_il_evaluate_val(), rz_il_value_dup(), and rz_il_vm_sync_from_reg().

◆ rz_il_value_new_bool()

RZ_API RZ_OWN RzILVal* rz_il_value_new_bool ( RZ_NONNULL RzILBool b)

Returns a new RzILVal (Bool type)

Parameters
bRzILBool to set
Returns
val RzILVal, pointer to this value

Definition at line 43 of file value.c.

43  {
46  if (!ret) {
47  return NULL;
48  }
49  ret->data.b = b;
50  return ret;
51 }
RzILBool * b
Definition: value.h:18

References RzValUnion::b, b, rz_il_val_t::data, NULL, RZ_IL_TYPE_PURE_BOOL, rz_il_value_new(), and rz_return_val_if_fail.

Referenced by rz_core_analysis_il_vm_set(), rz_il_evaluate_val(), rz_il_value_dup(), and rz_il_vm_sync_from_reg().

◆ rz_il_value_new_zero_of()

RZ_API RZ_OWN RzILVal* rz_il_value_new_zero_of ( RzILSortPure  sort)

Create a value of the given sort filled with all zeroes or false

Definition at line 56 of file value.c.

56  {
57  RzILVal *ret = rz_il_value_new(sort.type);
58  if (!ret) {
59  return NULL;
60  }
61  switch (sort.type) {
63  ret->data.b = rz_il_bool_new(false);
64  if (!ret->data.b) {
65  rz_il_value_free(ret);
66  return NULL;
67  }
68  break;
70  ret->data.bv = rz_bv_new_zero(sort.props.bv.length);
71  if (!ret->data.bv) {
72  rz_il_value_free(ret);
73  return NULL;
74  }
75  break;
76  }
77  return ret;
78 }
RZ_API void rz_il_value_free(RZ_NULLABLE RzILVal *val)
Definition: value.c:107
#define rz_bv_new_zero(l)
Definition: rz_bitvector.h:105
struct rz_il_sort_pure_t::@283::@284 bv
union rz_il_sort_pure_t::@283 props
RzILTypePure type
Definition: sort.h:29

References RzValUnion::b, rz_il_sort_pure_t::bv, RzValUnion::bv, rz_il_val_t::data, NULL, rz_il_sort_pure_t::props, rz_bv_new_zero, rz_il_bool_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_value_free(), rz_il_value_new(), and rz_il_sort_pure_t::type.

Referenced by rz_il_vm_create_global_var().

◆ rz_il_value_to_bv()

RZ_API RZ_OWN RzBitVector* rz_il_value_to_bv ( RZ_NONNULL const RzILVal val)

Convert the value's contents to a bitvector. For bitvector values, this is simply a copy of the value, for boolean it is a 1-bit bitvector of 1 or 0.

Definition at line 141 of file value.c.

141  {
143  switch (val->type) {
145  return rz_bv_new_from_ut64(1, val->data.b->b ? 1 : 0);
147  return rz_bv_dup(val->data.bv);
148  default:
150  return NULL;
151  }
152 }
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161

References NULL, rz_bv_dup(), rz_bv_new_from_ut64(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, rz_warn_if_reached, and val.

Referenced by rz_il_value_stringify().