Rizin
unix-like reverse engineering framework and cli tools
rz_il_vm.h File Reference

Go to the source code of this file.

Classes

struct  rz_il_vm_t
 Low-level VM to execute raw IL code. More...
 

Typedefs

typedef struct rz_il_vm_t RzILVM
 
typedef void *(* RzILOpPureHandler) (RzILVM *vm, RzILOpPure *op, RZ_NONNULL RZ_OUT RzILTypePure *type)
 Evaluation callback for a single pure opcode. More...
 
typedef bool(* RzILOpEffectHandler) (RzILVM *vm, RzILOpEffect *op)
 Evaluation (execution) callback for a single effect opcode. More...
 
typedef void(* RzILVmHook) (RzILVM *vm, RzILOpEffect *op)
 
typedef RZ_NULLABLE RzILValRzILLocalPurePrev
 

Functions

RZ_API RzILVMrz_il_vm_new (ut64 start_addr, ut32 addr_size, bool big_endian)
 
RZ_API void rz_il_vm_free (RzILVM *vm)
 
RZ_API bool rz_il_vm_init (RzILVM *vm, ut64 start_addr, ut32 addr_size, bool big_endian)
 
RZ_API void rz_il_vm_fini (RzILVM *vm)
 
RZ_API ut32 rz_il_vm_get_pc_len (RzILVM *vm)
 
RZ_API void rz_il_vm_event_add (RzILVM *vm, RzILEvent *evt)
 
RZ_API void rz_il_vm_clear_events (RzILVM *vm)
 
RZ_API void rz_il_vm_add_mem (RzILVM *vm, RzILMemIndex index, RZ_OWN RzILMem *mem)
 
RZ_API RzILMemrz_il_vm_get_mem (RzILVM *vm, RzILMemIndex index)
 
RZ_API RzBitVectorrz_il_vm_mem_load (RzILVM *vm, RzILMemIndex index, RzBitVector *key)
 
RZ_API void rz_il_vm_mem_store (RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
 
RZ_API RzBitVectorrz_il_vm_mem_loadw (RzILVM *vm, RzILMemIndex index, RzBitVector *key, ut32 n_bits)
 
RZ_API void rz_il_vm_mem_storew (RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
 
RZ_API RZ_BORROW RzBitVectorrz_il_hash_find_addr_by_lblname (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *lbl_name)
 
RZ_API RZ_BORROW RzILEffectLabelrz_il_vm_find_label_by_name (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *lbl_name)
 
RZ_API void rz_il_vm_add_label (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILEffectLabel *label)
 
RZ_API RZ_BORROW RzILEffectLabelrz_il_vm_create_label (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_NONNULL RZ_BORROW RzBitVector *addr)
 
RZ_API RZ_BORROW RzILEffectLabelrz_il_vm_create_label_lazy (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name)
 
RZ_API RZ_BORROW RzILEffectLabelrz_il_vm_update_label (RZ_NONNULL RzILVM *vm, RZ_NONNULL char *name, RZ_NONNULL RZ_BORROW RzBitVector *addr)
 
RZ_API RZ_BORROW RzILVarrz_il_vm_create_global_var (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILSortPure sort)
 
RZ_API void rz_il_vm_set_global_var (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
 
RZ_API void rz_il_vm_set_local_var (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
 
RZ_API RzILLocalPurePrev rz_il_vm_push_local_pure_var (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILVal *val)
 Create and assign a new local let binding. More...
 
RZ_API void rz_il_vm_pop_local_pure_var (RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILLocalPurePrev prev)
 Remove a local let binding and restore the state for the outer context. More...
 
RZ_API RZ_BORROW RzILVarrz_il_vm_get_var (RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
 
RZ_API RZ_OWN RzPVectorrz_il_vm_get_all_vars (RZ_NONNULL RzILVM *vm, RzILVarKind kind)
 
RZ_API RZ_BORROW RzILValrz_il_vm_get_var_value (RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
 
RZ_API RZ_NULLABLE RZ_OWN RzBitVectorrz_il_evaluate_bitv (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpBitVector *op)
 
RZ_API RZ_NULLABLE RZ_OWN RzILBoolrz_il_evaluate_bool (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpBool *op)
 
RZ_API RZ_NULLABLE RZ_OWN RzILValrz_il_evaluate_val (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op)
 
RZ_API RZ_NULLABLE RZ_OWN void * rz_il_evaluate_pure (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op, RZ_NONNULL RzILTypePure *type)
 
RZ_API bool rz_il_evaluate_effect (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
 
RZ_API bool rz_il_vm_step (RzILVM *vm, RzILOpEffect *op, ut64 fallthrough_addr)
 

Typedef Documentation

◆ RzILLocalPurePrev

Definition at line 86 of file rz_il_vm.h.

◆ RzILOpEffectHandler

typedef bool(* RzILOpEffectHandler) (RzILVM *vm, RzILOpEffect *op)

Evaluation (execution) callback for a single effect opcode.

Returns
false if an error occured and the execution should be aborted

Definition at line 30 of file rz_il_vm.h.

◆ RzILOpPureHandler

typedef void*(* RzILOpPureHandler) (RzILVM *vm, RzILOpPure *op, RZ_NONNULL RZ_OUT RzILTypePure *type)

Evaluation callback for a single pure opcode.

Parameters
typewhen returning a non-null value, this must be set to the respective type.
Returns
The evaluated value of the type indicated by *type, or NULL if an error occured and the execution should be aborted

Definition at line 24 of file rz_il_vm.h.

◆ RzILVM

typedef struct rz_il_vm_t RzILVM

Definition at line 1 of file rz_il_vm.h.

◆ RzILVmHook

typedef void(* RzILVmHook) (RzILVM *vm, RzILOpEffect *op)

Definition at line 32 of file rz_il_vm.h.

Function Documentation

◆ rz_il_evaluate_bitv()

RZ_API RZ_NULLABLE RZ_OWN RzBitVector* rz_il_evaluate_bitv ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpBitVector op 
)

Evaluate the given pure op, asserting it returns a bitvector.

Returns
value in bitvector, or NULL if an error occurred (e.g. the op returned some other type)

Definition at line 269 of file il_vm_eval.c.

269  {
270  rz_return_val_if_fail(vm && op, NULL);
271  // check type and auto convertion between bitv/bool/val
272  RzILTypePure type = -1;
273  void *res = eval_pure(vm, op, &type);
274  if (!res) {
275  // propagate error
276  return NULL;
277  }
279  RZ_LOG_ERROR("RzIL: type error: expected bitvector, got %s\n", pure_type_name(type));
280  return NULL;
281  }
282  return res;
283 }
#define NULL
Definition: cris-opc.c:27
static void * eval_pure(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op, RZ_NONNULL RzILTypePure *type)
Definition: il_vm_eval.c:240
static const char * pure_type_name(RzILTypePure type)
Definition: il_vm_eval.c:254
int type
Definition: mipsasm.c:17
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RzILTypePure
Definition: sort.h:23
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
Definition: dis.c:32

References eval_pure(), NULL, pure_type_name(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_LOG_ERROR, rz_return_val_if_fail, and type.

Referenced by rz_il_handler_add(), rz_il_handler_append(), rz_il_handler_cast(), rz_il_handler_div(), rz_il_handler_eq(), rz_il_handler_is_zero(), rz_il_handler_jmp(), rz_il_handler_load(), rz_il_handler_loadw(), rz_il_handler_logical_and(), rz_il_handler_logical_not(), rz_il_handler_logical_or(), rz_il_handler_logical_xor(), rz_il_handler_lsb(), rz_il_handler_mod(), rz_il_handler_msb(), rz_il_handler_mul(), rz_il_handler_neg(), rz_il_handler_sdiv(), rz_il_handler_shiftl(), rz_il_handler_shiftr(), rz_il_handler_sle(), rz_il_handler_smod(), rz_il_handler_store(), rz_il_handler_storew(), rz_il_handler_sub(), and rz_il_handler_ule().

◆ rz_il_evaluate_bool()

RZ_API RZ_NULLABLE RZ_OWN RzILBool* rz_il_evaluate_bool ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpBool op 
)

Evaluate the given pure op, asserting it returns a bool.

Returns
value in bool, or NULL if an error occurred (e.g. the op returned some other type)

Definition at line 289 of file il_vm_eval.c.

289  {
290  rz_return_val_if_fail(vm && op, NULL);
291  // check type and auto convertion between bitv/bool/val
292  RzILTypePure type = -1;
293  void *res = eval_pure(vm, op, &type);
294  if (!res) {
295  // propagate error
296  return NULL;
297  }
298  if (type != RZ_IL_TYPE_PURE_BOOL) {
299  RZ_LOG_ERROR("RzIL: type error: expected bool, got %s\n", pure_type_name(type));
300  return NULL;
301  }
302  return res;
303 }
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24

References eval_pure(), NULL, pure_type_name(), RZ_IL_TYPE_PURE_BOOL, RZ_LOG_ERROR, rz_return_val_if_fail, and type.

Referenced by rz_il_handler_bool_and(), rz_il_handler_bool_inv(), rz_il_handler_bool_or(), rz_il_handler_bool_xor(), rz_il_handler_branch(), rz_il_handler_cast(), rz_il_handler_ite(), rz_il_handler_repeat(), rz_il_handler_shiftl(), and rz_il_handler_shiftr().

◆ rz_il_evaluate_effect()

RZ_API bool rz_il_evaluate_effect ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpEffect op 
)

Evaluate (execute) the given effect op

Returns
false if an error occured and the execution should be aborted

Definition at line 341 of file il_vm_eval.c.

341  {
342  rz_return_val_if_fail(vm && op, false);
343  return eval_effect(vm, op);
344 }
static bool eval_effect(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
Definition: il_vm_eval.c:247

References eval_effect(), and rz_return_val_if_fail.

Referenced by rz_il_handler_blk(), rz_il_handler_branch(), rz_il_handler_repeat(), rz_il_handler_seq(), and rz_il_vm_step().

◆ rz_il_evaluate_pure()

RZ_API RZ_NULLABLE RZ_OWN void* rz_il_evaluate_pure ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpPure op,
RZ_NONNULL RzILTypePure type 
)

Evaluate the given pure op, returning the resulting value and its type.

Definition at line 332 of file il_vm_eval.c.

332  {
333  rz_return_val_if_fail(vm && op, NULL);
334  return eval_pure(vm, op, type);
335 }

References eval_pure(), NULL, rz_return_val_if_fail, and type.

Referenced by rz_il_handler_ite(), and rz_il_handler_let().

◆ rz_il_evaluate_val()

RZ_API RZ_NULLABLE RZ_OWN RzILVal* rz_il_evaluate_val ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpPure op 
)

Evaluate the given pure op, returning the resulting bool or bitvector.

Returns
val, RzILVal*, RzILVal type value

Definition at line 309 of file il_vm_eval.c.

309  {
310  rz_return_val_if_fail(vm && op, NULL);
311  // check type and auto convertion between bitv/bool/val
312  RzILTypePure type = -1;
313  void *res = eval_pure(vm, op, &type);
314  if (!res) {
315  // propagate error
316  return NULL;
317  }
318  switch (type) {
320  return rz_il_value_new_bool(res);
322  return rz_il_value_new_bitv(res);
323  default:
324  RZ_LOG_ERROR("RzIL: type error: got %s\n", pure_type_name(type));
325  return NULL;
326  }
327 }
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

References eval_pure(), NULL, pure_type_name(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_value_new_bitv(), rz_il_value_new_bool(), RZ_LOG_ERROR, rz_return_val_if_fail, and type.

Referenced by rz_il_handler_let(), and rz_il_handler_set().

◆ rz_il_hash_find_addr_by_lblname()

RZ_API RZ_BORROW RzBitVector* rz_il_hash_find_addr_by_lblname ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  lbl_name 
)

Find the bitvector address by given name

Parameters
vmRzILVM* vm, pointer to VM
lbl_namestring, the name of label
Returns
addr RzBitVector, address which has RzBitVector type

Definition at line 275 of file il_vm.c.

275  {
276  rz_return_val_if_fail(vm && lbl_name, NULL);
277  bool found = false;
278  RzILEffectLabel *label = ht_pp_find(vm->vm_global_label_table, lbl_name, &found);
279  if (!found) {
280  return NULL;
281  }
282  return label->addr;
283 }
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
Definition: dis.h:35

References found, NULL, and rz_return_val_if_fail.

◆ rz_il_vm_add_label()

RZ_API void rz_il_vm_add_label ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILEffectLabel label 
)

Definition at line 296 of file il_vm.c.

296  {
297  rz_return_if_fail(vm && label);
298  ht_pp_update(vm->vm_global_label_table, label->label_id, label);
299 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References rz_return_if_fail.

Referenced by rz_il_vm_create_label(), rz_il_vm_create_label_lazy(), and setup_vm_from_config().

◆ rz_il_vm_add_mem()

RZ_API void rz_il_vm_add_mem ( RzILVM vm,
RzILMemIndex  index,
RZ_OWN RzILMem mem 
)

Add a memory to VM at the given index. Ownership of the memory is transferred to the VM.

Definition at line 153 of file il_vm.c.

153  {
154  if (index < rz_pvector_len(&vm->vm_memory)) {
155  rz_mem_free(rz_pvector_at(&vm->vm_memory, index));
156  }
157  rz_pvector_reserve(&vm->vm_memory, index + 1);
158  // Fill up with NULLs until the given index
159  while (rz_pvector_len(&vm->vm_memory) < index + 1) {
161  }
162  rz_pvector_set(&vm->vm_memory, index, mem);
163 }
void * mem
Definition: libc.cpp:91
RZ_API void rz_mem_free(void *)
Definition: mem.c:361
static void ** rz_pvector_reserve(RzPVector *vec, size_t capacity)
Definition: rz_vector.h:312
static void rz_pvector_set(RzPVector *vec, size_t index, void *e)
Definition: rz_vector.h:241
static size_t rz_pvector_len(const RzPVector *vec)
Definition: rz_vector.h:231
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
static void * rz_pvector_at(const RzPVector *vec, size_t index)
Definition: rz_vector.h:236
RzPVector vm_memory
Memories available in the VM, by their index. May be sparse (contain NULLs).
Definition: rz_il_vm.h:41

References mem, NULL, rz_mem_free(), rz_pvector_at(), rz_pvector_len(), rz_pvector_push(), rz_pvector_reserve(), rz_pvector_set(), and rz_il_vm_t::vm_memory.

Referenced by setup_vm_from_config().

◆ rz_il_vm_clear_events()

RZ_API void rz_il_vm_clear_events ( RzILVM vm)

Remove any recorded events from vm->events

Definition at line 212 of file il_vm_eval.c.

212  {
213  rz_list_purge(vm->events);
214 }
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
RzList * events
List of events that has happened in the last step.
Definition: rz_il_vm.h:49

References rz_il_vm_t::events, and rz_list_purge().

Referenced by rz_il_vm_step().

◆ rz_il_vm_create_global_var()

RZ_API RZ_BORROW RzILVar* rz_il_vm_create_global_var ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RzILSortPure  sort 
)

Create a new global variable of the given sort and assign it to all-zero/false

Definition at line 175 of file il_vm.c.

175  {
177  RzILVar *var = rz_il_var_set_create_var(&vm->global_vars, name, sort);
178  if (!var) {
179  return NULL;
180  }
182  if (!val) {
183  return NULL;
184  }
185  rz_il_var_set_bind(&vm->global_vars, name, val);
186  return var;
187 }
ut16 val
Definition: armass64_const.h:6
RZ_API RZ_OWN RzILVal * rz_il_value_new_zero_of(RzILSortPure sort)
Definition: value.c:56
Definition: z80asm.h:102
Definition of a variable inside the vm.
Definition: variable.h:19
RZ_API RZ_BORROW RzILVar * rz_il_var_set_create_var(RzILVarSet *vs, const char *name, RzILSortPure sort)
Definition: variable.c:90
RZ_API bool rz_il_var_set_bind(RzILVarSet *vs, const char *name, RZ_OWN RzILVal *val)
Definition: variable.c:129

References NULL, rz_il_value_new_zero_of(), rz_il_var_set_bind(), rz_il_var_set_create_var(), rz_return_val_if_fail, and val.

Referenced by rz_il_vm_setup_reg_binding().

◆ rz_il_vm_create_label()

RZ_API RZ_BORROW RzILEffectLabel* rz_il_vm_create_label ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RZ_NONNULL RZ_BORROW RzBitVector addr 
)

Create a label in VM

Parameters
vmRzILVM, pointer to VM
namestring, name of label
addrRzBitVector, label address
Returns
lbl RzILEffectLabel, pointer to label instance

Definition at line 308 of file il_vm.c.

308  {
309  rz_return_val_if_fail(vm && name && addr, NULL);
311  lbl->addr = rz_bv_dup(addr);
312  rz_il_vm_add_label(vm, lbl);
313  return lbl;
314 }
RZ_API void rz_il_vm_add_label(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILEffectLabel *label)
Definition: il_vm.c:296
RZ_API RzILEffectLabel * rz_il_effect_label_new(RZ_NONNULL const char *name, RzILEffectLabelType type)
Definition: label.c:6
@ EFFECT_LABEL_ADDR
Definition: label.h:18
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
RzBitVector * addr
RzBitVector address if EFFECT_LABEL_ADDR.
Definition: label.h:27
static int addr
Definition: z80asm.c:58

References addr, rz_il_effect_label_t::addr, EFFECT_LABEL_ADDR, NULL, rz_bv_dup(), rz_il_effect_label_new(), rz_il_vm_add_label(), and rz_return_val_if_fail.

Referenced by rz_il_handler_blk().

◆ rz_il_vm_create_label_lazy()

RZ_API RZ_BORROW RzILEffectLabel* rz_il_vm_create_label_lazy ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name 
)

Create a label without address, use rz_il_vm_update_label to update address for it

Parameters
vmRzILVM, pointer to VM
namestring, name of this label
Returns
lbl RzILEffectLabel, pointer to label instance

Definition at line 322 of file il_vm.c.

322  {
325  lbl->addr = NULL;
326  rz_il_vm_add_label(vm, lbl);
327  return lbl;
328 }

References rz_il_effect_label_t::addr, EFFECT_LABEL_ADDR, NULL, rz_il_effect_label_new(), rz_il_vm_add_label(), and rz_return_val_if_fail.

◆ rz_il_vm_event_add()

RZ_API void rz_il_vm_event_add ( RzILVM vm,
RzILEvent evt 
)

Adds to the VM a new event into the VM event list

Parameters
vm,RzILVM,pointerto the VM
evt,RzILEvent,pointerto the event

Definition at line 201 of file il_vm_eval.c.

201  {
202  rz_return_if_fail(vm && vm->events && evt);
203  if (!rz_list_append(vm->events, evt)) {
205  rz_il_event_free(evt);
206  }
207 }
RZ_API void rz_il_event_free(RZ_NULLABLE RzILEvent *evt)
Definition: il_events.c:11
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
#define rz_warn_if_reached()
Definition: rz_assert.h:29

References rz_il_vm_t::events, rz_il_event_free(), rz_list_append(), rz_return_if_fail, and rz_warn_if_reached.

Referenced by perform_jump(), rz_il_handler_div(), rz_il_handler_var(), rz_il_set(), rz_il_vm_mem_load(), rz_il_vm_mem_loadw(), rz_il_vm_mem_store(), rz_il_vm_mem_storew(), and rz_il_vm_step().

◆ rz_il_vm_find_label_by_name()

RZ_API RZ_BORROW RzILEffectLabel* rz_il_vm_find_label_by_name ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  lbl_name 
)

Find the label instance by name

Parameters
vmRzILVM, pointer to VM
lbl_namestring, the name of label
Returns
lbl RzILEffectLabel, pointer to label instance

Definition at line 291 of file il_vm.c.

291  {
292  rz_return_val_if_fail(vm && lbl_name, NULL);
293  return ht_pp_find(vm->vm_global_label_table, lbl_name, NULL);
294 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_il_handler_goto().

◆ rz_il_vm_fini()

RZ_API void rz_il_vm_fini ( RzILVM vm)

Close and clean vm

Parameters
vmRzILVM* pointer to VM

Definition at line 93 of file il_vm.c.

93  {
97 
99 
100  ht_pp_free(vm->vm_global_label_table);
102 
107 
108  rz_bv_free(vm->pc);
109  vm->pc = NULL;
110 
111  rz_list_free(vm->events);
112  vm->events = NULL;
113 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
RZ_API void rz_pvector_fini(RzPVector *vec)
Definition: vector.c:331
RzILOpPureHandler * op_handler_pure_table
Array of Handler, handler can be indexed by opcode.
Definition: rz_il_vm.h:47
RzILVarSet local_vars
All local variables, created by local set ops.
Definition: rz_il_vm.h:39
RzILVarSet local_pure_vars
All local variables, during execution temporarily bound by let, only usable in pure expressions and i...
Definition: rz_il_vm.h:40
RzILVarSet global_vars
All global variables (usually bound to registers)
Definition: rz_il_vm.h:38
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
HtPP * vm_global_label_table
Hashtable to maintain the label and address.
Definition: rz_il_vm.h:44
RzILOpEffectHandler * op_handler_effect_table
Array of Handler, handler can be indexed by opcode.
Definition: rz_il_vm.h:48
RZ_API void rz_il_var_set_fini(RzILVarSet *vs)
Definition: variable.c:76

References rz_il_vm_t::events, free(), rz_il_vm_t::global_vars, rz_il_vm_t::local_pure_vars, rz_il_vm_t::local_vars, NULL, rz_il_vm_t::op_handler_effect_table, rz_il_vm_t::op_handler_pure_table, rz_il_vm_t::pc, rz_bv_free(), rz_il_var_set_fini(), rz_list_free(), rz_pvector_fini(), rz_il_vm_t::vm_global_label_table, and rz_il_vm_t::vm_memory.

Referenced by rz_il_vm_free(), and rz_il_vm_init().

◆ rz_il_vm_free()

RZ_API void rz_il_vm_free ( RzILVM vm)

Close, clean and free vm

Parameters
vmRzILVM* pointer to VM

Definition at line 134 of file il_vm.c.

134  {
135  if (!vm) {
136  return;
137  }
138  rz_il_vm_fini(vm);
139  free(vm);
140 }
RZ_API void rz_il_vm_fini(RzILVM *vm)
Definition: il_vm.c:93

References free(), and rz_il_vm_fini().

Referenced by rz_analysis_il_vm_free(), and setup_vm_from_config().

◆ rz_il_vm_get_all_vars()

RZ_API RZ_OWN RzPVector* rz_il_vm_get_all_vars ( RZ_NONNULL RzILVM vm,
RzILVarKind  kind 
)

Definition at line 256 of file il_vm.c.

256  {
258  return rz_il_var_set_get_all(var_set_of_kind(vm, kind));
259 }
static RzILVarSet * var_set_of_kind(RzILVM *vm, RzILVarKind kind)
Definition: il_vm.c:238
RZ_API RZ_OWN RzPVector * rz_il_var_set_get_all(RzILVarSet *vs)
Definition: variable.c:160

References NULL, rz_il_var_set_get_all(), rz_return_val_if_fail, and var_set_of_kind().

Referenced by rz_core_analysis_il_vm_status(), and rz_il_validate_global_context_new_from_vm().

◆ rz_il_vm_get_mem()

RZ_API RzILMem* rz_il_vm_get_mem ( RzILVM vm,
RzILMemIndex  index 
)

Definition at line 165 of file il_vm.c.

165  {
166  if (index >= rz_pvector_len(&vm->vm_memory)) {
167  return NULL;
168  }
169  return rz_pvector_at(&vm->vm_memory, index);
170 }

References NULL, rz_pvector_at(), rz_pvector_len(), and rz_il_vm_t::vm_memory.

Referenced by rz_il_vm_mem_load(), rz_il_vm_mem_loadw(), rz_il_vm_mem_store(), and rz_il_vm_mem_storew().

◆ rz_il_vm_get_pc_len()

RZ_API ut32 rz_il_vm_get_pc_len ( RzILVM vm)

Get the number of bits of the program counter bitvector

Definition at line 145 of file il_vm.c.

145  {
146  return rz_bv_len(vm->pc);
147 }
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1140

References rz_il_vm_t::pc, and rz_bv_len().

Referenced by rz_il_validate_global_context_new_from_vm().

◆ rz_il_vm_get_var()

RZ_API RZ_BORROW RzILVar* rz_il_vm_get_var ( RZ_NONNULL RzILVM vm,
RzILVarKind  kind,
const char *  name 
)

Definition at line 251 of file il_vm.c.

251  {
253  return rz_il_var_set_get(var_set_of_kind(vm, kind), name);
254 }
RZ_API RZ_BORROW RzILVar * rz_il_var_set_get(RzILVarSet *vs, const char *name)
Definition: variable.c:148

References NULL, rz_il_var_set_get(), rz_return_val_if_fail, and var_set_of_kind().

Referenced by rz_core_analysis_il_vm_set(), rz_il_set(), and rz_il_vm_sync_from_reg().

◆ rz_il_vm_get_var_value()

RZ_API RZ_BORROW RzILVal* rz_il_vm_get_var_value ( RZ_NONNULL RzILVM vm,
RzILVarKind  kind,
const char *  name 
)

Get the current value of the variable identified by its name and kind.

Definition at line 264 of file il_vm.c.

264  {
266  return rz_il_var_set_get_value(var_set_of_kind(vm, kind), name);
267 }
RZ_API RZ_BORROW RzILVal * rz_il_var_set_get_value(RzILVarSet *vs, const char *name)
Definition: variable.c:173

References NULL, rz_il_var_set_get_value(), rz_return_val_if_fail, and var_set_of_kind().

Referenced by bf_syscall_read(), bf_syscall_write(), il_event_new_write_from_var(), rz_core_analysis_il_vm_status(), rz_il_handler_var(), and rz_il_vm_sync_to_reg().

◆ rz_il_vm_init()

RZ_API bool rz_il_vm_init ( RzILVM vm,
ut64  start_addr,
ut32  addr_size,
bool  big_endian 
)

initiate an empty VM

Parameters
vmRzILVM, pointer to an empty VM
start_addrut64, initiation pc address
addr_sizeut32, size of the address in VM

Definition at line 27 of file il_vm.c.

27  {
28  rz_return_val_if_fail(vm, false);
29 
30  if (!rz_il_var_set_init(&vm->global_vars)) {
31  rz_il_vm_fini(vm);
32  return false;
33  }
34  if (!rz_il_var_set_init(&vm->local_vars)) {
35  rz_il_vm_fini(vm);
36  return false;
37  }
39  rz_il_vm_fini(vm);
40  return false;
41  }
43 
44  // Key : string
45  // Val : RzILEffectLabel
46  // Do not dump it since its single signed here, and will be free in `close`
47  HtPPOptions lbl_options = { 0 };
48  lbl_options.cmp = (HtPPListComparator)strcmp;
49  lbl_options.hashfn = (HtPPHashFunction)sdb_hash;
50  lbl_options.dupkey = (HtPPDupKey)strdup;
51  lbl_options.dupvalue = NULL;
52  lbl_options.freefn = (HtPPKvFreeFunc)free_label_kv;
53  lbl_options.elem_size = sizeof(HtPPKv);
54  lbl_options.calcsizeK = (HtPPCalcSizeK)strlen;
55  vm->vm_global_label_table = ht_pp_new_opt(&lbl_options);
56  if (!vm->vm_global_label_table) {
57  RZ_LOG_ERROR("RzIL: cannot allocate VM label hashmap\n");
58  rz_il_vm_fini(vm);
59  return false;
60  }
61 
62  vm->pc = rz_bv_new_from_ut64(addr_size, start_addr);
63  if (!vm->pc) {
64  RZ_LOG_ERROR("RzIL: cannot allocate VM program counter\n");
65  rz_il_vm_fini(vm);
66  return false;
67  }
68 
69  // init jump table of labels
74 
75  vm->lab_count = 0;
76  vm->val_count = 0;
77  vm->addr_size = addr_size;
78  vm->big_endian = big_endian;
79 
81  if (!vm->events) {
82  RZ_LOG_ERROR("RzIL: cannot allocate VM event list\n");
83  rz_il_vm_fini(vm);
84  return false;
85  }
86  return true;
87 }
RZ_API void rz_il_mem_free(RzILMem *mem)
Definition: mem.c:34
RZ_IPI RzILOpEffectHandler rz_il_op_handler_effect_table_default[RZ_IL_OP_EFFECT_MAX]
Definition: il_vm_eval.c:104
static void free_label_kv(HtPPKv *kv)
Definition: il_vm.c:16
RZ_IPI RzILOpPureHandler rz_il_op_handler_pure_table_default[RZ_IL_OP_PURE_MAX]
Definition: il_vm_eval.c:67
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
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_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
@ RZ_IL_OP_PURE_MAX
@ RZ_IL_OP_EFFECT_MAX
void *(* RzILOpPureHandler)(RzILVM *vm, RzILOpPure *op, RZ_NONNULL RZ_OUT RzILTypePure *type)
Evaluation callback for a single pure opcode.
Definition: rz_il_vm.h:24
bool(* RzILOpEffectHandler)(RzILVM *vm, RzILOpEffect *op)
Evaluation (execution) callback for a single effect opcode.
Definition: rz_il_vm.h:30
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43
RZ_API ut32 sdb_hash(const char *key)
Definition: util.c:22
ut32 lab_count
count for VM predefined things
Definition: rz_il_vm.h:42
ut32 addr_size
size of address space
Definition: rz_il_vm.h:43
bool big_endian
Sets the endianness of the memory reads/writes operations.
Definition: rz_il_vm.h:50
ut32 val_count
Definition: rz_il_vm.h:42
RZ_API bool rz_il_var_set_init(RzILVarSet *vs)
Definition: variable.c:60

References rz_il_vm_t::addr_size, rz_il_vm_t::big_endian, rz_il_vm_t::events, free_label_kv(), rz_il_vm_t::global_vars, rz_il_vm_t::lab_count, rz_il_vm_t::local_pure_vars, rz_il_vm_t::local_vars, memcpy(), NULL, rz_il_vm_t::op_handler_effect_table, rz_il_vm_t::op_handler_pure_table, rz_il_vm_t::pc, rz_bv_new_from_ut64(), rz_il_event_free(), rz_il_mem_free(), RZ_IL_OP_EFFECT_MAX, rz_il_op_handler_effect_table_default, rz_il_op_handler_pure_table_default, RZ_IL_OP_PURE_MAX, rz_il_var_set_init(), rz_il_vm_fini(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEWS0, rz_pvector_init(), rz_return_val_if_fail, sdb_hash(), strdup(), rz_il_vm_t::val_count, rz_il_vm_t::vm_global_label_table, and rz_il_vm_t::vm_memory.

Referenced by rz_il_vm_new().

◆ rz_il_vm_mem_load()

RZ_API RzBitVector* rz_il_vm_mem_load ( RzILVM vm,
RzILMemIndex  index,
RzBitVector key 
)

Load data from memory by given key and generates an RZ_IL_EVENT_MEM_READ event

Parameters
vmRzILVM, pointer to VM
keyRzBitVector, aka address, a key to load data from memory
Returns
val Bitvector, data at the address, has vm->min_unit_size length

Definition at line 124 of file il_vm_eval.c.

124  {
126  RzILMem *mem = rz_il_vm_get_mem(vm, index);
127  if (!mem) {
128  RZ_LOG_ERROR("Non-existent mem %u referenced\n", (unsigned int)index);
129  return NULL;
130  }
133  return value;
134 }
static int value
Definition: cmd_api.c:93
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 static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
RZ_API RzBitVector * rz_il_mem_load(RzILMem *mem, RzBitVector *key)
Definition: mem.c:79
RZ_API RZ_OWN RzILEvent * rz_il_event_mem_read_new(RZ_NONNULL const RzBitVector *address, RZ_NULLABLE const RzBitVector *value)
Definition: il_events.c:100
RZ_API RzILMem * rz_il_vm_get_mem(RzILVM *vm, RzILMemIndex index)
Definition: il_vm.c:165
RZ_API void rz_il_vm_event_add(RzILVM *vm, RzILEvent *evt)
Definition: il_vm_eval.c:201
structure for bitvector
Definition: rz_bitvector.h:19
A single memory as part of the RzIL VM.
Definition: mem.h:26

References key, mem, NULL, rz_il_event_mem_read_new(), rz_il_mem_load(), rz_il_vm_event_add(), rz_il_vm_get_mem(), RZ_LOG_ERROR, rz_return_val_if_fail, and value.

Referenced by bf_syscall_write(), and rz_il_handler_load().

◆ rz_il_vm_mem_loadw()

RZ_API RzBitVector* rz_il_vm_mem_loadw ( RzILVM vm,
RzILMemIndex  index,
RzBitVector key,
ut32  n_bits 
)

Load data from memory by given key and generates an RZ_IL_EVENT_MEM_READ event

Parameters
vmRzILVM, pointer to VM
keyRzBitVector, aka address, a key to load data from memory
Returns
val Bitvector, data at the address, has vm->min_unit_size length

Definition at line 163 of file il_vm_eval.c.

163  {
165  RzILMem *mem = rz_il_vm_get_mem(vm, index);
166  if (!mem) {
167  RZ_LOG_ERROR("Non-existent mem %u referenced\n", (unsigned int)index);
168  return NULL;
169  }
172  return value;
173 }
RZ_API RzBitVector * rz_il_mem_loadw(RzILMem *mem, RzBitVector *key, ut32 n_bits, bool big_endian)
Definition: mem.c:157

References rz_il_vm_t::big_endian, key, mem, NULL, rz_il_event_mem_read_new(), rz_il_mem_loadw(), rz_il_vm_event_add(), rz_il_vm_get_mem(), RZ_LOG_ERROR, rz_return_val_if_fail, and value.

Referenced by rz_il_handler_loadw().

◆ rz_il_vm_mem_store()

RZ_API void rz_il_vm_mem_store ( RzILVM vm,
RzILMemIndex  index,
RzBitVector key,
RzBitVector value 
)

Store data to memory by key, will create a key-value pair or update the key-value pair if key existed; also generates an RZ_IL_EVENT_MEM_WRITE event

Parameters
vmRzILVM* pointer to VM
keyRzBitVector, aka address, a key to store data from memory
valueRzBitVector, aka value to store in memory

Definition at line 144 of file il_vm_eval.c.

144  {
145  rz_return_if_fail(vm && key && value);
146  RzILMem *mem = rz_il_vm_get_mem(vm, index);
147  if (!mem) {
148  RZ_LOG_ERROR("Non-existent mem %u referenced\n", (unsigned int)index);
149  return;
150  }
151  RzBitVector *old_value = rz_il_mem_load(mem, key);
154  rz_bv_free(old_value);
155 }
RZ_API bool rz_il_mem_store(RzILMem *mem, RzBitVector *key, RzBitVector *value)
Definition: mem.c:93
RZ_API RZ_OWN RzILEvent * rz_il_event_mem_write_new(RZ_NONNULL const RzBitVector *addr, RZ_NONNULL const RzBitVector *old_v, RZ_NONNULL const RzBitVector *new_v)
Definition: il_events.c:125

References key, mem, rz_bv_free(), rz_il_event_mem_write_new(), rz_il_mem_load(), rz_il_mem_store(), rz_il_vm_event_add(), rz_il_vm_get_mem(), RZ_LOG_ERROR, rz_return_if_fail, and value.

Referenced by bf_syscall_read(), and rz_il_handler_store().

◆ rz_il_vm_mem_storew()

RZ_API void rz_il_vm_mem_storew ( RzILVM vm,
RzILMemIndex  index,
RzBitVector key,
RzBitVector value 
)

Store data to memory by key, will create a key-value pair or update the key-value pair if key existed; also generates an RZ_IL_EVENT_MEM_WRITE event

Parameters
vmRzILVM* pointer to VM
keyRzBitVector, aka address, a key to store data from memory
valueRzBitVector, aka value to store in memory

Definition at line 183 of file il_vm_eval.c.

183  {
184  rz_return_if_fail(vm && key && value);
185  RzILMem *mem = rz_il_vm_get_mem(vm, index);
186  if (!mem) {
187  RZ_LOG_ERROR("Non-existent mem %u referenced\n", (unsigned int)index);
188  return;
189  }
193  rz_bv_free(old_value);
194 }
RZ_API bool rz_il_mem_storew(RzILMem *mem, RzBitVector *key, RzBitVector *value, bool big_endian)
Definition: mem.c:169

References rz_il_vm_t::big_endian, key, mem, rz_bv_free(), rz_bv_len(), rz_il_event_mem_write_new(), rz_il_mem_loadw(), rz_il_mem_storew(), rz_il_vm_event_add(), rz_il_vm_get_mem(), RZ_LOG_ERROR, rz_return_if_fail, and value.

Referenced by rz_il_handler_storew().

◆ rz_il_vm_new()

RZ_API RzILVM* rz_il_vm_new ( ut64  start_addr,
ut32  addr_size,
bool  big_endian 
)

Create a new empty VM

Parameters
vmRzILVM, pointer to an empty VM
start_addrut64, initiation pc address
addr_sizeut32, size of the address in VM

Definition at line 121 of file il_vm.c.

121  {
122  RzILVM *vm = RZ_NEW0(RzILVM);
123  if (!vm) {
124  return NULL;
125  }
126  rz_il_vm_init(vm, start_addr, addr_size, big_endian);
127  return vm;
128 }
RZ_API bool rz_il_vm_init(RzILVM *vm, ut64 start_addr, ut32 addr_size, bool big_endian)
Definition: il_vm.c:27
#define RZ_NEW0(x)
Definition: rz_types.h:284
Low-level VM to execute raw IL code.
Definition: rz_il_vm.h:37

References NULL, rz_il_vm_init(), and RZ_NEW0.

Referenced by setup_vm_from_config().

◆ rz_il_vm_pop_local_pure_var()

RZ_API void rz_il_vm_pop_local_pure_var ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RzILLocalPurePrev  prev 
)

Remove a local let binding and restore the state for the outer context.

Parameters
prevpass here the return value of rz_il_vm_push_local_pure_var()

Definition at line 227 of file il_vm.c.

227  {
228  rz_return_if_fail(vm && name);
229  RzILVal *r = rz_il_var_set_remove_var(&vm->local_pure_vars, name);
230  rz_warn_if_fail(r); // the var should always be bound when calling this function
232  if (prev) {
233  rz_il_var_set_create_var(&vm->local_pure_vars, name, rz_il_value_get_sort(prev));
234  rz_il_var_set_bind(&vm->local_pure_vars, name, prev);
235  }
236 }
#define r
Definition: crypto_rc6.c:12
RZ_API RzILSortPure rz_il_value_get_sort(RZ_NONNULL RzILVal *val)
Definition: value.c:127
RZ_API void rz_il_value_free(RZ_NULLABLE RzILVal *val)
Definition: value.c:107
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35
RZ_API RZ_OWN RZ_NULLABLE RzILVal * rz_il_var_set_remove_var(RzILVarSet *vs, const char *name)
Definition: variable.c:107

References r, rz_il_value_free(), rz_il_value_get_sort(), rz_il_var_set_bind(), rz_il_var_set_create_var(), rz_il_var_set_remove_var(), rz_return_if_fail, and rz_warn_if_fail.

Referenced by rz_il_handler_let().

◆ rz_il_vm_push_local_pure_var()

RZ_API RzILLocalPurePrev rz_il_vm_push_local_pure_var ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RzILVal val 
)

Create and assign a new local let binding.

This is meant to be called right before evaluating the body of a let expression. Inside the body, name will then be bound to val. Because there might already exist an outer binding of the same name shadowing this one, the previous value is returned. After evaluating the body, call rz_il_vm_pop_local_pure_var(), passing this value.

Definition at line 215 of file il_vm.c.

215  {
216  rz_return_val_if_fail(vm && name && val, NULL);
217  RzILVal *r = rz_il_var_set_remove_var(&vm->local_pure_vars, name);
218  rz_il_var_set_create_var(&vm->local_pure_vars, name, rz_il_value_get_sort(val));
219  rz_il_var_set_bind(&vm->local_pure_vars, name, val);
220  return r;
221 }

References NULL, r, rz_il_value_get_sort(), rz_il_var_set_bind(), rz_il_var_set_create_var(), rz_il_var_set_remove_var(), rz_return_val_if_fail, and val.

Referenced by rz_il_handler_let().

◆ rz_il_vm_set_global_var()

RZ_API void rz_il_vm_set_global_var ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RZ_OWN RzILVal val 
)

Set the value of a global variable to the given value. The variable must already exist.

Definition at line 193 of file il_vm.c.

193  {
194  rz_return_if_fail(vm && name && val);
195  rz_il_var_set_bind(&vm->global_vars, name, val);
196 }

References rz_il_var_set_bind(), rz_return_if_fail, and val.

Referenced by rz_core_analysis_il_vm_set(), rz_il_set(), rz_il_vm_sync_from_reg(), and setup_vm_init_state().

◆ rz_il_vm_set_local_var()

RZ_API void rz_il_vm_set_local_var ( RZ_NONNULL RzILVM vm,
RZ_NONNULL const char *  name,
RZ_OWN RzILVal val 
)

Set the value of a local variable to the given value. The variable is created with the sort of val if it does not already exist.

Definition at line 202 of file il_vm.c.

202  {
203  rz_return_if_fail(vm && name && val);
205  rz_il_var_set_bind(&vm->local_vars, name, val);
206 }

References rz_il_value_get_sort(), rz_il_var_set_bind(), rz_il_var_set_create_var(), rz_return_if_fail, and val.

Referenced by rz_il_set().

◆ rz_il_vm_step()

RZ_API bool rz_il_vm_step ( RzILVM vm,
RzILOpEffect op,
ut64  fallthrough_addr 
)

Execute the opcodes uplifted from raw instructions.A list may contain multiple opcode trees

Parameters
vmpointer to VM
op_list,alist of op roots.
fallthrough_addrinitial address to set PC to. Thus also the address to "step to" if no explicit jump occurs.

Definition at line 222 of file il_vm_eval.c.

222  {
223  rz_return_val_if_fail(vm && op, false);
224 
226 
227  // Set the successor pc **before** evaluating. Any jmp/goto may then overwrite it again.
228  RzBitVector *next_pc = rz_bv_new_from_ut64(vm->pc->len, fallthrough_addr);
230  rz_bv_free(vm->pc);
231  vm->pc = next_pc;
232 
233  bool succ = rz_il_evaluate_effect(vm, op);
234 
235  // remove any local defined variable (local pure vars are unbound automatically)
237  return succ;
238 }
RZ_API RZ_OWN RzILEvent * rz_il_event_pc_write_new(RZ_NONNULL const RzBitVector *old_pc, RZ_NONNULL const RzBitVector *new_pc)
Definition: il_events.c:76
RZ_API void rz_il_vm_clear_events(RzILVM *vm)
Definition: il_vm_eval.c:212
RZ_API bool rz_il_evaluate_effect(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
Definition: il_vm_eval.c:341
ut32 len
number of bits – virtual / logical
Definition: rz_bitvector.h:25
RZ_API void rz_il_var_set_reset(RzILVarSet *vs)
Definition: variable.c:81

References bitvector_t::len, rz_il_vm_t::local_vars, rz_il_vm_t::pc, rz_bv_free(), rz_bv_new_from_ut64(), rz_il_evaluate_effect(), rz_il_event_pc_write_new(), rz_il_var_set_reset(), rz_il_vm_clear_events(), rz_il_vm_event_add(), and rz_return_val_if_fail.

Referenced by rz_analysis_il_vm_step().

◆ rz_il_vm_update_label()

RZ_API RZ_BORROW RzILEffectLabel* rz_il_vm_update_label ( RZ_NONNULL RzILVM vm,
RZ_NONNULL char *  name,
RZ_NONNULL RZ_BORROW RzBitVector addr 
)

Update the address info of a label

Parameters
vmRzILVM, pointer to VM
namestring, name of this label
Returns
lbl RzILEffectLabel, pointer to label instance

Definition at line 336 of file il_vm.c.

336  {
337  rz_return_val_if_fail(vm && name && addr, NULL);
338  RzILEffectLabel *lbl = ht_pp_find(vm->vm_global_label_table, name, NULL);
339  if (lbl->addr) {
340  rz_bv_free(lbl->addr);
341  }
342  lbl->addr = rz_bv_dup(addr);
343  return lbl;
344 }

References addr, rz_il_effect_label_t::addr, NULL, rz_bv_dup(), rz_bv_free(), and rz_return_val_if_fail.