Rizin
unix-like reverse engineering framework and cli tools
il_vm_eval.c File Reference
#include <rz_il/rz_il_vm.h>

Go to the source code of this file.

Functions

void * rz_il_handler_ite (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_var (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_let (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_bitv (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_msb (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_lsb (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_is_zero (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_eq (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_ule (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_sle (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_neg (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_logical_not (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_add (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_sub (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_mul (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_div (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_sdiv (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_mod (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_smod (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_shiftl (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_shiftr (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_logical_and (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_logical_or (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_logical_xor (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_bool_false (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 also known as b0 More...
 
void * rz_il_handler_bool_true (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 also known as b1 More...
 
void * rz_il_handler_bool_and (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_bool_or (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_bool_xor (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_bool_inv (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 also known as boolean not More...
 
void * rz_il_handler_cast (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
void * rz_il_handler_append (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
bool rz_il_handler_empty (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_nop (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_set (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_jmp (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_goto (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_seq (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_blk (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_repeat (RzILVM *vm, RzILOpEffect *op)
 
bool rz_il_handler_branch (RzILVM *vm, RzILOpEffect *op)
 
void * rz_il_handler_load (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
bool rz_il_handler_store (RzILVM *vm, RzILOpEffect *op)
 
void * rz_il_handler_loadw (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
bool rz_il_handler_storew (RzILVM *vm, RzILOpEffect *op)
 
void * rz_il_handler_pure_unimplemented (RzILVM *vm, RzILOpPure *op, RzILTypePure *type)
 
bool rz_il_handler_effect_unimplemented (RzILVM *vm, RzILOpEffect *op)
 
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 void rz_il_vm_event_add (RzILVM *vm, RzILEvent *evt)
 
RZ_API void rz_il_vm_clear_events (RzILVM *vm)
 
RZ_API bool rz_il_vm_step (RzILVM *vm, RzILOpEffect *op, ut64 fallthrough_addr)
 
static void * eval_pure (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op, RZ_NONNULL RzILTypePure *type)
 
static bool eval_effect (RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
 
static const char * pure_type_name (RzILTypePure type)
 
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)
 

Variables

RZ_IPI RzILOpPureHandler rz_il_op_handler_pure_table_default [RZ_IL_OP_PURE_MAX]
 
RZ_IPI RzILOpEffectHandler rz_il_op_handler_effect_table_default [RZ_IL_OP_EFFECT_MAX]
 

Detailed Description

RzIL Virtual Machine Evaluation (Emulation)

Definition in file il_vm_eval.c.

Function Documentation

◆ eval_effect()

static bool eval_effect ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpEffect op 
)
static

Definition at line 247 of file il_vm_eval.c.

247  {
248  rz_return_val_if_fail(vm && op, NULL);
249  RzILOpEffectHandler handler = vm->op_handler_effect_table[op->code];
250  rz_return_val_if_fail(handler, NULL);
251  return handler(vm, op);
252 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
bool(* RzILOpEffectHandler)(RzILVM *vm, RzILOpEffect *op)
Evaluation (execution) callback for a single effect opcode.
Definition: rz_il_vm.h:30
Definition: dis.c:32
struct op_code code
Definition: dis.c:33

References op::code, NULL, and rz_return_val_if_fail.

Referenced by rz_il_evaluate_effect().

◆ eval_pure()

static void* eval_pure ( RZ_NONNULL RzILVM vm,
RZ_NONNULL RzILOpPure op,
RZ_NONNULL RzILTypePure type 
)
static

Definition at line 240 of file il_vm_eval.c.

240  {
241  rz_return_val_if_fail(vm && op && type, NULL);
242  RzILOpPureHandler handler = vm->op_handler_pure_table[op->code];
243  rz_return_val_if_fail(handler, NULL);
244  return handler(vm, op, type);
245 }
int type
Definition: mipsasm.c:17
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

References op::code, NULL, rz_return_val_if_fail, and type.

Referenced by rz_il_evaluate_bitv(), rz_il_evaluate_bool(), rz_il_evaluate_pure(), and rz_il_evaluate_val().

◆ pure_type_name()

static const char* pure_type_name ( RzILTypePure  type)
static

Definition at line 254 of file il_vm_eval.c.

254  {
255  switch (type) {
257  return "bitvector";
259  return "bool";
260  default:
261  return "unknown";
262  }
263 }
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25

References RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, and type.

Referenced by rz_il_evaluate_bitv(), rz_il_evaluate_bool(), and rz_il_evaluate_val().

◆ 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 }
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
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RzILTypePure
Definition: sort.h:23

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 }

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_handler_add()

void* rz_il_handler_add ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 114 of file theory_bitv.c.

114  {
115  rz_return_val_if_fail(vm && op && type, NULL);
116 
117  RzILOpArgsAdd *op_add = &op->op.add;
118 
119  RzBitVector *x = rz_il_evaluate_bitv(vm, op_add->x);
120  RzBitVector *y = rz_il_evaluate_bitv(vm, op_add->y);
121  RzBitVector *result = x && y ? rz_bv_add(x, y, NULL) : NULL;
122 
123  rz_bv_free(x);
124  rz_bv_free(y);
125 
127  return result;
128 }
RZ_API RZ_NULLABLE RZ_OWN RzBitVector * rz_il_evaluate_bitv(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpBitVector *op)
Definition: il_vm_eval.c:269
int x
Definition: mipsasm.c:20
RZ_API RZ_OWN RzBitVector * rz_bv_add(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *carry)
Definition: bitvector.c:683
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
structure for bitvector
Definition: rz_bitvector.h:19
op structure for two-operand algorithm and logical operations ('s bitv -> 's bitv -> 's bitv)
Definition: rz_il_opcodes.h:97
RzILOpBitVector * x
left operand
Definition: rz_il_opcodes.h:98
RzILOpBitVector * y
right operand
Definition: rz_il_opcodes.h:99

References NULL, rz_bv_add(), rz_bv_free(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_append()

void* rz_il_handler_append ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 130 of file theory_bitv.c.

130  {
131  rz_return_val_if_fail(vm && op && type, NULL);
132 
133  RzILOpArgsAppend *op_append = &op->op.append;
134 
135  RzBitVector *high = rz_il_evaluate_bitv(vm, op_append->high);
136  RzBitVector *low = rz_il_evaluate_bitv(vm, op_append->low);
137  RzBitVector *result = high && low ? rz_bv_append(high, low) : NULL;
138  rz_bv_free(low);
139  rz_bv_free(high);
140 
142  return result;
143 }
RZ_API RZ_OWN RzBitVector * rz_bv_append(RZ_NONNULL RzBitVector *bv1, RZ_NONNULL RzBitVector *bv2)
Definition: bitvector.c:326
op structure for appending 2 bitv: MSB:LSB high:low
RzILOpBitVector * low
bitvector occupying the least significant bits
RzILOpBitVector * high
bitvector occupying the most significant bits

References rz_il_op_args_append_t::high, rz_il_op_args_append_t::low, NULL, rz_bv_append(), rz_bv_free(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, and type.

◆ rz_il_handler_bitv()

void* rz_il_handler_bitv ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 336 of file theory_bitv.c.

336  {
337  rz_return_val_if_fail(vm && op && type, NULL);
338  RzILOpArgsBv *op_bitv = &op->op.bitv;
339 
340  RzBitVector *bv = rz_bv_dup(op_bitv->value);
341 
343  return bv;
344 }
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
value is a bitvector constant.
Definition: rz_il_opcodes.h:51
RzBitVector * value
value of bitvector
Definition: rz_il_opcodes.h:52

References NULL, rz_bv_dup(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, and rz_il_op_args_bv_t::value.

◆ rz_il_handler_blk()

bool rz_il_handler_blk ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 89 of file theory_effect.c.

89  {
90  rz_return_val_if_fail(vm && op, false);
91 
92  RzILOpArgsBlk *op_blk = &op->op.blk;
93  if (op_blk->label) {
94  rz_il_vm_create_label(vm, op_blk->label, vm->pc); // create the label if `blk` is labelled
95  }
96 
97  return rz_il_evaluate_effect(vm, op_blk->data_eff) && rz_il_evaluate_effect(vm, op_blk->ctrl_eff);
98 }
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)
Definition: il_vm.c:308
RZ_API bool rz_il_evaluate_effect(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
Definition: il_vm_eval.c:341
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
op structure for blk (label -> data eff -> ctrl eff -> unit eff)
RzILOpEffect * data_eff
index of data_eff
const char * label
name of the label, const one
RzILOpEffect * ctrl_eff
index of ctrl_eff

References rzil_op_blk_t::ctrl_eff, rzil_op_blk_t::data_eff, rzil_op_blk_t::label, rz_il_vm_t::pc, rz_il_evaluate_effect(), rz_il_vm_create_label(), and rz_return_val_if_fail.

◆ rz_il_handler_bool_and()

void* rz_il_handler_bool_and ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 29 of file theory_bool.c.

29  {
30  rz_return_val_if_fail(vm && op && type, NULL);
31 
32  RzILOpArgsBoolAnd *op_and = &op->op.booland;
33  RzILBool *x = rz_il_evaluate_bool(vm, op_and->x);
34  RzILBool *y = rz_il_evaluate_bool(vm, op_and->y);
35 
36  RzILBool *result = x && y ? rz_il_bool_and(x, y) : NULL;
38  rz_il_bool_free(y);
39 
41  return result;
42 }
RZ_API RzILBool * rz_il_bool_and(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:26
RZ_API void rz_il_bool_free(RzILBool *bool_var)
Definition: bool.c:74
RZ_API RZ_NULLABLE RZ_OWN RzILBool * rz_il_evaluate_bool(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpBool *op)
Definition: il_vm_eval.c:289
op structure for and, or and xor (bool -> bool -> bool)
RzILOpBool * x
left operand
RzILOpBool * y
right operand

References NULL, rz_il_bool_and(), rz_il_bool_free(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_bool_operation_t::x, and rz_il_op_args_bool_operation_t::y.

◆ rz_il_handler_bool_false()

void* rz_il_handler_bool_false ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

also known as b0

Definition at line 10 of file theory_bool.c.

10  {
11  rz_return_val_if_fail(vm && op && type, NULL);
12 
13  RzILBool *ret = rz_il_bool_new(false);
15  return ret;
16 }
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11

References NULL, rz_il_bool_new(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and type.

◆ rz_il_handler_bool_inv()

void* rz_il_handler_bool_inv ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

also known as boolean not

Definition at line 77 of file theory_bool.c.

77  {
78  rz_return_val_if_fail(vm && op && type, NULL);
79 
80  RzILOpArgsBoolInv *op_inv = &op->op.boolinv;
81  RzILBool *x = rz_il_evaluate_bool(vm, op_inv->x);
82  RzILBool *result = x ? rz_il_bool_not(x) : NULL;
84 
86  return result;
87 }
RZ_API RzILBool * rz_il_bool_not(RZ_NONNULL RzILBool *a)
Definition: bool.c:63
op structure for inv (!bool -> bool)
RzILOpBool * x
single operand

References NULL, rz_il_bool_free(), rz_il_bool_not(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, and rz_il_op_args_bool_inv_t::x.

◆ rz_il_handler_bool_or()

void* rz_il_handler_bool_or ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 44 of file theory_bool.c.

44  {
45  rz_return_val_if_fail(vm && op && type, NULL);
46 
47  RzILOpArgsBoolOr *op_or = &op->op.boolor;
48  RzILBool *x = rz_il_evaluate_bool(vm, op_or->x);
49  RzILBool *y = rz_il_evaluate_bool(vm, op_or->y);
50 
51  RzILBool *result = x && y ? rz_il_bool_or(x, y) : NULL;
53  rz_il_bool_free(y);
54 
56  return result;
57 }
RZ_API RzILBool * rz_il_bool_or(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:39

References NULL, rz_il_bool_free(), rz_il_bool_or(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_bool_operation_t::x, and rz_il_op_args_bool_operation_t::y.

◆ rz_il_handler_bool_true()

void* rz_il_handler_bool_true ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

also known as b1

Definition at line 21 of file theory_bool.c.

21  {
22  rz_return_val_if_fail(vm && op && type, NULL);
23 
24  RzILBool *ret = rz_il_bool_new(true);
26  return ret;
27 }

References NULL, rz_il_bool_new(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and type.

◆ rz_il_handler_bool_xor()

void* rz_il_handler_bool_xor ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 59 of file theory_bool.c.

59  {
60  rz_return_val_if_fail(vm && op && type, NULL);
61 
62  RzILOpArgsBoolXor *op_xor = &op->op.boolxor;
63  RzILBool *x = rz_il_evaluate_bool(vm, op_xor->x);
64  RzILBool *y = rz_il_evaluate_bool(vm, op_xor->y);
65 
66  RzILBool *result = x && y ? rz_il_bool_xor(x, y) : NULL;
68  rz_il_bool_free(y);
69 
71  return result;
72 }
RZ_API RzILBool * rz_il_bool_xor(RZ_NONNULL RzILBool *a, RZ_NONNULL RzILBool *b)
Definition: bool.c:52

References NULL, rz_il_bool_free(), rz_il_bool_xor(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_bool_operation_t::x, and rz_il_op_args_bool_operation_t::y.

◆ rz_il_handler_branch()

bool rz_il_handler_branch ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 118 of file theory_effect.c.

118  {
119  rz_return_val_if_fail(vm && op, false);
120 
121  RzILOpArgsBranch *op_branch = &op->op.branch;
122 
123  RzILBool *condition = rz_il_evaluate_bool(vm, op_branch->condition);
124  if (!condition) {
125  return false;
126  }
127  bool ret;
128  if (condition->b) {
129  ret = rz_il_evaluate_effect(vm, op_branch->true_eff);
130  } else {
131  ret = rz_il_evaluate_effect(vm, op_branch->false_eff);
132  }
133  rz_il_bool_free(condition);
134 
135  return ret;
136 }
bool b
Definition: bool.h:15
op structure for branch (bool -> 'a eff -> 'a eff -> 'a eff)
RZ_NONNULL RzILOpEffect * true_eff
effect for when condition evaluates to true
RZ_NONNULL RzILOpEffect * false_eff
effect for when condition evaluates to false

References rz_il_bool_t::b, rz_il_op_args_branch_t::condition, rz_il_op_args_branch_t::false_eff, rz_il_bool_free(), rz_il_evaluate_bool(), rz_il_evaluate_effect(), rz_return_val_if_fail, and rz_il_op_args_branch_t::true_eff.

◆ rz_il_handler_cast()

void* rz_il_handler_cast ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 346 of file theory_bitv.c.

346  {
347  rz_return_val_if_fail(vm && op && type, NULL);
348 
349  RzILOpArgsCast *op_cast = &op->op.cast;
350  RzILBool *fill = rz_il_evaluate_bool(vm, op_cast->fill);
351  if (!fill) {
352  return NULL;
353  }
354  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_cast->val);
355  if (!bv) {
356  return NULL;
357  }
358 
359  RzBitVector *ret = rz_bv_new(op_cast->length);
360  rz_bv_set_all(ret, fill->b);
361  rz_bv_copy_nbits(bv, 0, ret, 0, RZ_MIN(bv->len, ret->len));
362 
363  rz_il_bool_free(fill);
364  rz_bv_free(bv);
365 
367  return ret;
368 }
RZ_API bool rz_bv_set_all(RZ_NONNULL RzBitVector *bv, bool b)
Definition: bitvector.c:367
RZ_API RZ_OWN RzBitVector * rz_bv_new(ut32 length)
Definition: bitvector.c:71
RZ_API ut32 rz_bv_copy_nbits(RZ_NONNULL const RzBitVector *src, ut32 src_start_pos, RZ_NONNULL RzBitVector *dst, ut32 dst_start_pos, ut32 nbit)
Definition: bitvector.c:210
#define RZ_MIN(x, y)
ut32 len
number of bits – virtual / logical
Definition: rz_bitvector.h:25
op structure for casting bitv
RzILOpBool * fill
If m = size val - length > 0 then m fill-bits are prepended to the most significant part of the vecto...
RzILOpBitVector * val
value to cast
ut32 length
new bits length

References rz_il_bool_t::b, rz_il_op_args_cast_t::fill, bitvector_t::len, rz_il_op_args_cast_t::length, NULL, rz_bv_copy_nbits(), rz_bv_free(), rz_bv_new(), rz_bv_set_all(), rz_il_bool_free(), rz_il_evaluate_bitv(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_MIN, rz_return_val_if_fail, type, and rz_il_op_args_cast_t::val.

◆ rz_il_handler_div()

void* rz_il_handler_div ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 221 of file theory_bitv.c.

221  {
222  rz_return_val_if_fail(vm && op && type, NULL);
223 
224  RzILOpArgsDiv *op_div = &op->op.div;
225 
226  RzBitVector *x = rz_il_evaluate_bitv(vm, op_div->x);
227  RzBitVector *y = rz_il_evaluate_bitv(vm, op_div->y);
228  RzBitVector *result = NULL;
229  if (x && y) {
230  if (rz_bv_is_zero_vector(y)) {
231  result = rz_bv_new(y->len);
232  rz_bv_set_all(result, true);
233  rz_il_vm_event_add(vm, rz_il_event_exception_new("division by zero"));
234  } else {
235  result = rz_bv_div(x, y);
236  }
237  }
238 
239  rz_bv_free(x);
240  rz_bv_free(y);
241 
243  return result;
244 }
RZ_API RZ_OWN RzILEvent * rz_il_event_exception_new(RZ_NONNULL const char *exception)
Definition: il_events.c:52
RZ_API void rz_il_vm_event_add(RzILVM *vm, RzILEvent *evt)
Definition: il_vm_eval.c:201
RZ_API bool rz_bv_is_zero_vector(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1021
RZ_API RZ_OWN RzBitVector * rz_bv_div(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:808

References bitvector_t::len, NULL, rz_bv_div(), rz_bv_free(), rz_bv_is_zero_vector(), rz_bv_new(), rz_bv_set_all(), rz_il_evaluate_bitv(), rz_il_event_exception_new(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_vm_event_add(), rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_effect_unimplemented()

bool rz_il_handler_effect_unimplemented ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 76 of file theory_init.c.

76  {
78  RZ_LOG_ERROR("RzIL: unimplemented op handler (%d).\n", (int)op->code);
79  return false;
80 }

References op::code, NULL, RZ_LOG_ERROR, and rz_return_val_if_fail.

◆ rz_il_handler_empty()

bool rz_il_handler_empty ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 28 of file theory_effect.c.

28  {
29  rz_return_val_if_fail(vm && op, false);
30  RZ_LOG_WARN("Encountered an empty instruction at %s", rz_bv_as_string(vm->pc))
31  return true;
32 }
#define true
RZ_API RZ_OWN char * rz_bv_as_string(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:98
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56

References rz_il_vm_t::pc, rz_bv_as_string(), RZ_LOG_WARN, and rz_return_val_if_fail.

◆ rz_il_handler_eq()

void* rz_il_handler_eq ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 69 of file theory_bitv.c.

69  {
70  rz_return_val_if_fail(vm && op && type, NULL);
71 
72  RzILOpArgsSle *op_sle = &op->op.sle;
73 
74  RzBitVector *x = rz_il_evaluate_bitv(vm, op_sle->x);
75  RzBitVector *y = rz_il_evaluate_bitv(vm, op_sle->y);
76  RzILBool *result = x && y ? rz_il_bool_new(rz_bv_eq(x, y)) : NULL;
77  rz_bv_free(x);
78  rz_bv_free(y);
79 
81  return result;
82 }
RZ_API bool rz_bv_eq(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1041
op structure for binary comparison ops ('a bitv -> 'a bitv -> bool)
RzILOpBitVector * x
index of operand 1
RzILOpBitVector * y
index of operand 2

References NULL, rz_bv_eq(), rz_bv_free(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_cmp_t::x, and rz_il_op_args_cmp_t::y.

◆ rz_il_handler_goto()

bool rz_il_handler_goto ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 66 of file theory_effect.c.

66  {
67  rz_return_val_if_fail(vm && op, false);
68  RzILOpArgsGoto *op_goto = &op->op.goto_;
69  const char *lname = op_goto->lbl;
71  if (!label) {
72  return false;
73  }
74  if (label->type == EFFECT_LABEL_SYSCALL || label->type == EFFECT_LABEL_HOOK) {
75  RzILVmHook internal_hook = (RzILVmHook)label->hook;
76  internal_hook(vm, op);
77  } else {
78  perform_jump(vm, rz_bv_dup(label->addr));
79  }
80  return true;
81 }
RZ_API RZ_BORROW RzILEffectLabel * rz_il_vm_find_label_by_name(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *lbl_name)
Definition: il_vm.c:291
@ EFFECT_LABEL_HOOK
Definition: label.h:20
@ EFFECT_LABEL_SYSCALL
Definition: label.h:19
void(* RzILVmHook)(RzILVM *vm, RzILOpEffect *op)
Definition: rz_il_vm.h:32
Definition: dis.h:35
op structure for goto (label -> ctrl eff)
const char * lbl
name of the label, const one
static void perform_jump(RzILVM *vm, RZ_OWN RzBitVector *dst)
Definition: theory_effect.c:50

References EFFECT_LABEL_HOOK, EFFECT_LABEL_SYSCALL, rz_il_op_args_goto_t::lbl, perform_jump(), rz_bv_dup(), rz_il_vm_find_label_by_name(), and rz_return_val_if_fail.

◆ rz_il_handler_is_zero()

void* rz_il_handler_is_zero ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 31 of file theory_bitv.c.

31  {
32  rz_return_val_if_fail(vm && op && type, NULL);
33 
34  RzILOpArgsLsb *op_lsb = &op->op.lsb;
35  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_lsb->bv);
36  RzILBool *result = bv ? rz_il_bool_new(rz_bv_is_zero_vector(bv)) : NULL;
37  rz_bv_free(bv);
38 
40  return result;
41 }
op structure for 's bitv -> bool [MSB] msb x is the most significant bit of x. [LSB] lsb x is the lea...
Definition: rz_il_opcodes.h:61
RzILOpBitVector * bv
Definition: rz_il_opcodes.h:62

References rz_il_op_args_un_bv_b_t::bv, NULL, rz_bv_free(), rz_bv_is_zero_vector(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and type.

◆ rz_il_handler_ite()

void* rz_il_handler_ite ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 7 of file theory_init.c.

7  {
9 
10  RzILOpArgsIte *op_ite = &op->op.ite;
11 
12  RzILBool *condition = rz_il_evaluate_bool(vm, op_ite->condition);
13  if (!condition) {
14  return NULL;
15  }
16  RzILVal *ret;
17  if (condition->b) {
18  ret = rz_il_evaluate_pure(vm, op_ite->x, type); // true branch
19  } else {
20  ret = rz_il_evaluate_pure(vm, op_ite->y, type); // false branch
21  }
22  rz_il_bool_free(condition);
23  return ret;
24 }
RZ_API RZ_NULLABLE RZ_OWN void * rz_il_evaluate_pure(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op, RZ_NONNULL RzILTypePure *type)
Definition: il_vm_eval.c:332
op structure for ite (bool -> 'a pure -> 'a pure -> 'a pure)
RzILOpPure * y
index of RzILVal operand 2
RzILOpPure * x
index of RzILVal operand 1
RzILOpBool * condition
index of BOOL condition

References rz_il_bool_t::b, rz_il_op_args_ite_t::condition, NULL, rz_il_bool_free(), rz_il_evaluate_bool(), rz_il_evaluate_pure(), rz_return_val_if_fail, type, rz_il_op_args_ite_t::x, and rz_il_op_args_ite_t::y.

◆ rz_il_handler_jmp()

bool rz_il_handler_jmp ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 56 of file theory_effect.c.

56  {
57  rz_return_val_if_fail(vm && op, false);
58  RzBitVector *dst = rz_il_evaluate_bitv(vm, op->op.jmp.dst);
59  if (!dst) {
60  return false;
61  }
62  perform_jump(vm, dst);
63  return true;
64 }
char * dst
Definition: lz4.h:724

References dst, perform_jump(), rz_il_evaluate_bitv(), and rz_return_val_if_fail.

◆ rz_il_handler_let()

void* rz_il_handler_let ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 57 of file theory_init.c.

57  {
58  rz_return_val_if_fail(vm && op && type, NULL);
59  RzILOpArgsLet *args = &op->op.let;
60  RzILVal *v = rz_il_evaluate_val(vm, args->exp);
61  if (!v) {
62  return NULL;
63  }
65  void *r = rz_il_evaluate_pure(vm, args->body, type);
66  rz_il_vm_pop_local_pure_var(vm, args->name, prev);
67  return r;
68 }
#define r
Definition: crypto_rc6.c:12
const char * v
Definition: dsignal.c:12
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.
Definition: il_vm.c:215
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.
Definition: il_vm.c:227
RZ_API RZ_NULLABLE RZ_OWN RzILVal * rz_il_evaluate_val(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpPure *op)
Definition: il_vm_eval.c:309
int args
Definition: mipsasm.c:18
RZ_NULLABLE RzILVal * RzILLocalPurePrev
Definition: rz_il_vm.h:86
op structure for let_ : 'a var -> 'a pure -> 'b pure -> 'b pure

References args, NULL, r, rz_il_evaluate_pure(), rz_il_evaluate_val(), rz_il_vm_pop_local_pure_var(), rz_il_vm_push_local_pure_var(), rz_return_val_if_fail, type, and v.

◆ rz_il_handler_load()

void* rz_il_handler_load ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 8 of file theory_mem.c.

8  {
10  RzILOpArgsLoad *op_load = &op->op.load;
11 
12  RzBitVector *addr = rz_il_evaluate_bitv(vm, op_load->key);
13  if (!addr) {
14  return NULL;
15  }
16  RzBitVector *ret = rz_il_vm_mem_load(vm, op_load->mem, addr);
19  return ret;
20 }
RZ_API RzBitVector * rz_il_vm_mem_load(RzILVM *vm, RzILMemIndex index, RzBitVector *key)
Definition: il_vm_eval.c:124
op structure for load (('a, 'b) mem -> 'a bitv -> 'b bitv)
RzILMemIndex mem
index of the mem inside the vm to use
RzILOpBitVector * key
index of the cell (address) in mem, must have exactly the size of a key in the memory
static int addr
Definition: z80asm.c:58

References addr, rz_il_op_args_load_t::key, rz_il_op_args_load_t::mem, NULL, rz_bv_free(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_vm_mem_load(), rz_return_val_if_fail, and type.

◆ rz_il_handler_loadw()

void* rz_il_handler_loadw ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 41 of file theory_mem.c.

41  {
42  rz_return_val_if_fail(vm && op && type, NULL);
43  RzILOpArgsLoadW *op_loadw = &op->op.loadw;
44 
45  RzBitVector *addr = rz_il_evaluate_bitv(vm, op_loadw->key);
46  if (!addr) {
47  return NULL;
48  }
49  RzBitVector *ret = rz_il_vm_mem_loadw(vm, op_loadw->mem, addr, op_loadw->n_bits);
52  return ret;
53 }
RZ_API RzBitVector * rz_il_vm_mem_loadw(RzILVM *vm, RzILMemIndex index, RzBitVector *key, ut32 n_bits)
Definition: il_vm_eval.c:163
Load an entire word of arbitrary bit size from a memory.
RzILOpBitVector * key
memory index of the RzBitVector key (address)
RzILMemIndex mem
index of the mem inside the vm to use
ut32 n_bits
n of bits to read, and of the resulting bitvector

References addr, rz_il_op_args_loadw_t::key, rz_il_op_args_loadw_t::mem, rz_il_op_args_loadw_t::n_bits, NULL, rz_bv_free(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_vm_mem_loadw(), rz_return_val_if_fail, and type.

◆ rz_il_handler_logical_and()

void* rz_il_handler_logical_and ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 145 of file theory_bitv.c.

145  {
146  rz_return_val_if_fail(vm && op && type, NULL);
147 
148  RzILOpArgsAdd *op_add = &op->op.add;
149 
150  RzBitVector *x = rz_il_evaluate_bitv(vm, op_add->x);
151  RzBitVector *y = rz_il_evaluate_bitv(vm, op_add->y);
152  RzBitVector *result = x && y ? rz_bv_and(x, y) : NULL;
153  rz_bv_free(x);
154  rz_bv_free(y);
155 
157  return result;
158 }
RZ_API RZ_OWN RzBitVector * rz_bv_and(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:546

References NULL, rz_bv_and(), rz_bv_free(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_logical_not()

void* rz_il_handler_logical_not ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 56 of file theory_bitv.c.

56  {
57  rz_return_val_if_fail(vm && op && type, NULL);
58 
59  RzILOpArgsLogNot *op_not = &op->op.lognot;
60 
61  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_not->bv);
62  RzBitVector *result = bv ? rz_bv_not(bv) : NULL;
63  rz_bv_free(bv);
64 
66  return result;
67 }
#define rz_bv_not
Definition: rz_bitvector.h:59
RzILOpBitVector * bv
unary operand
Definition: rz_il_opcodes.h:77

References rz_il_op_args_bv_unop_t::bv, NULL, rz_bv_free(), rz_bv_not, rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, and type.

◆ rz_il_handler_logical_or()

void* rz_il_handler_logical_or ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 160 of file theory_bitv.c.

160  {
161  rz_return_val_if_fail(vm && op && type, NULL);
162 
163  RzILOpArgsAdd *op_add = &op->op.add;
164 
165  RzBitVector *x = rz_il_evaluate_bitv(vm, op_add->x);
166  RzBitVector *y = rz_il_evaluate_bitv(vm, op_add->y);
167  RzBitVector *result = x && y ? rz_bv_or(x, y) : NULL;
168  rz_bv_free(x);
169  rz_bv_free(y);
170 
172  return result;
173 }
RZ_API RZ_OWN RzBitVector * rz_bv_or(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:573

References NULL, rz_bv_free(), rz_bv_or(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_logical_xor()

void* rz_il_handler_logical_xor ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 175 of file theory_bitv.c.

175  {
176  rz_return_val_if_fail(vm && op && type, NULL);
177 
178  RzILOpArgsAdd *op_add = &op->op.add;
179 
180  RzBitVector *x = rz_il_evaluate_bitv(vm, op_add->x);
181  RzBitVector *y = rz_il_evaluate_bitv(vm, op_add->y);
182  RzBitVector *result = x && y ? rz_bv_xor(x, y) : NULL;
183  rz_bv_free(x);
184  rz_bv_free(y);
185 
187  return result;
188 }
RZ_API RZ_OWN RzBitVector * rz_bv_xor(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:600

References NULL, rz_bv_free(), rz_bv_xor(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_lsb()

void* rz_il_handler_lsb ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 19 of file theory_bitv.c.

19  {
20  rz_return_val_if_fail(vm && op && type, NULL);
21 
22  RzILOpArgsLsb *op_lsb = &op->op.lsb;
23  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_lsb->bv);
24  RzILBool *result = bv ? rz_il_bool_new(rz_bv_lsb(bv)) : NULL;
25  rz_bv_free(bv);
26 
28  return result;
29 }
RZ_API bool rz_bv_lsb(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1012

References rz_il_op_args_un_bv_b_t::bv, NULL, rz_bv_free(), rz_bv_lsb(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and type.

◆ rz_il_handler_mod()

void* rz_il_handler_mod ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 261 of file theory_bitv.c.

261  {
262  rz_return_val_if_fail(vm && op && type, NULL);
263 
264  RzILOpArgsMod *op_mod = &op->op.mod;
265 
266  RzBitVector *x = rz_il_evaluate_bitv(vm, op_mod->x);
267  RzBitVector *y = rz_il_evaluate_bitv(vm, op_mod->y);
268  RzBitVector *result = x && y ? rz_bv_mod(x, y) : NULL;
269  rz_bv_free(x);
270  rz_bv_free(y);
271 
273  return result;
274 }
RZ_API RZ_OWN RzBitVector * rz_bv_mod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:865

References NULL, rz_bv_free(), rz_bv_mod(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_msb()

void* rz_il_handler_msb ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 7 of file theory_bitv.c.

7  {
9 
10  RzILOpArgsMsb *op_msb = &op->op.msb;
11  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_msb->bv);
12  RzILBool *result = bv ? rz_il_bool_new(rz_bv_msb(bv)) : NULL;
13  rz_bv_free(bv);
14 
16  return result;
17 }
RZ_API bool rz_bv_msb(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1003

References rz_il_op_args_un_bv_b_t::bv, NULL, rz_bv_free(), rz_bv_msb(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, and type.

◆ rz_il_handler_mul()

void* rz_il_handler_mul ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 205 of file theory_bitv.c.

205  {
206  rz_return_val_if_fail(vm && op && type, NULL);
207 
208  RzILOpArgsMul *op_mul = &op->op.mul;
209 
210  RzBitVector *x = rz_il_evaluate_bitv(vm, op_mul->x);
211  RzBitVector *y = rz_il_evaluate_bitv(vm, op_mul->y);
212  RzBitVector *result = x && y ? rz_bv_mul(x, y) : NULL;
213 
214  rz_bv_free(x);
215  rz_bv_free(y);
216 
218  return result;
219 }
RZ_API RZ_OWN RzBitVector * rz_bv_mul(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:734

References NULL, rz_bv_free(), rz_bv_mul(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_neg()

void* rz_il_handler_neg ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 43 of file theory_bitv.c.

43  {
44  rz_return_val_if_fail(vm && op && type, NULL);
45 
46  RzILOpArgsNeg *neg = &op->op.neg;
47 
48  RzBitVector *bv_arg = rz_il_evaluate_bitv(vm, neg->bv);
49  RzBitVector *bv_result = bv_arg ? rz_bv_neg(bv_arg) : NULL;
50  rz_bv_free(bv_arg);
51 
53  return bv_result;
54 }
static ut32 neg(ArmOp *op)
Definition: armass64.c:981
#define rz_bv_neg
Definition: rz_bitvector.h:58

References neg(), NULL, rz_bv_free(), rz_bv_neg, rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, and type.

◆ rz_il_handler_nop()

bool rz_il_handler_nop ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 34 of file theory_effect.c.

34  {
35  rz_return_val_if_fail(vm && op, false);
36  return true;
37 }

References rz_return_val_if_fail.

◆ rz_il_handler_pure_unimplemented()

void* rz_il_handler_pure_unimplemented ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 70 of file theory_init.c.

70  {
71  rz_return_val_if_fail(vm && op && type, NULL);
72  RZ_LOG_ERROR("RzIL: unimplemented op handler (%d).\n", (int)op->code);
73  return NULL;
74 }

References op::code, NULL, RZ_LOG_ERROR, rz_return_val_if_fail, and type.

◆ rz_il_handler_repeat()

bool rz_il_handler_repeat ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 100 of file theory_effect.c.

100  {
101  rz_return_val_if_fail(vm && op, NULL);
102 
103  RzILOpArgsRepeat *op_repeat = &op->op.repeat;
104  bool res = true;
105  RzILBool *condition;
106  while ((condition = rz_il_evaluate_bool(vm, op_repeat->condition))) {
107  if (!condition->b) {
108  break;
109  }
110  res = res && rz_il_evaluate_effect(vm, op_repeat->data_eff);
111  rz_il_bool_free(condition);
112  }
113  rz_il_bool_free(condition);
114 
115  return res;
116 }
op structure for repeat (bool -> data eff -> data eff)
RzILOpBool * condition
index of BOOL condition
RzILOpEffect * data_eff
index of data effect

References rz_il_bool_t::b, rzil_op_repeat_t::condition, rzil_op_repeat_t::data_eff, NULL, rz_il_bool_free(), rz_il_evaluate_bool(), rz_il_evaluate_effect(), and rz_return_val_if_fail.

◆ rz_il_handler_sdiv()

void* rz_il_handler_sdiv ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 246 of file theory_bitv.c.

246  {
247  rz_return_val_if_fail(vm && op && type, NULL);
248 
249  RzILOpArgsSdiv *op_sdiv = &op->op.sdiv;
250 
251  RzBitVector *x = rz_il_evaluate_bitv(vm, op_sdiv->x);
252  RzBitVector *y = rz_il_evaluate_bitv(vm, op_sdiv->y);
253  RzBitVector *result = x && y ? rz_bv_sdiv(x, y) : NULL;
254  rz_bv_free(x);
255  rz_bv_free(y);
256 
258  return result;
259 }
RZ_API RZ_OWN RzBitVector * rz_bv_sdiv(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:893

References NULL, rz_bv_free(), rz_bv_sdiv(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_seq()

bool rz_il_handler_seq ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 83 of file theory_effect.c.

83  {
84  rz_return_val_if_fail(vm && op, false);
85  RzILOpArgsSeq *op_seq = &op->op.seq;
86  return rz_il_evaluate_effect(vm, op_seq->x) && rz_il_evaluate_effect(vm, op_seq->y);
87 }
op structure for Seq ('a eff -> 'a eff -> 'a eff)
RzILOpEffect * y
perform this second
RzILOpEffect * x
perform this first

References rz_il_evaluate_effect(), rz_return_val_if_fail, rz_il_op_args_seq_t::x, and rz_il_op_args_seq_t::y.

◆ rz_il_handler_set()

bool rz_il_handler_set ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 39 of file theory_effect.c.

39  {
40  rz_return_val_if_fail(vm && op, false);
41  RzILOpArgsSet *set_op = &op->op.set;
42  RzILVal *val = rz_il_evaluate_val(vm, set_op->x);
43  if (!val) {
44  return false;
45  }
46  rz_il_set(vm, set_op->v, set_op->is_local, val);
47  return true;
48 }
ut16 val
Definition: armass64_const.h:6
op structure for set ('a var -> 'a pure -> data eff)
bool is_local
whether a global variable should be set or a local optionally created and set
const char * v
name of variable, const one
RzILOpPure * x
value to set the variable to
static void rz_il_set(RzILVM *vm, const char *var_name, bool is_local, RZ_OWN RzILVal *val)
Definition: theory_effect.c:17

References rz_il_op_args_set_t::is_local, rz_il_evaluate_val(), rz_il_set(), rz_return_val_if_fail, rz_il_op_args_set_t::v, val, and rz_il_op_args_set_t::x.

◆ rz_il_handler_shiftl()

void* rz_il_handler_shiftl ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 291 of file theory_bitv.c.

291  {
292  rz_return_val_if_fail(vm && op && type, NULL);
293 
294  RzILOpArgsShiftLeft *op_shiftl = &op->op.shiftl;
295 
296  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_shiftl->x);
297  RzBitVector *shift = rz_il_evaluate_bitv(vm, op_shiftl->y);
298  RzILBool *fill_bit = rz_il_evaluate_bool(vm, op_shiftl->fill_bit);
299 
300  RzBitVector *result = NULL;
301  if (bv && shift && fill_bit) {
302  result = rz_bv_dup(bv);
303  rz_bv_lshift_fill(result, rz_bv_to_ut32(shift), fill_bit->b);
304  }
305  rz_bv_free(shift);
306  rz_bv_free(bv);
307  rz_il_bool_free(fill_bit);
308 
310  return result;
311 }
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
Definition: arm_il32.c:190
RZ_API bool rz_bv_lshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
Definition: bitvector.c:469
RZ_API ut32 rz_bv_to_ut32(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1435
op structure for lshift and rshift (bool -> 's bitv -> 'b bitv -> 's bitv)
RzILOpBitVector * x
index of operand 1
RzILOpBitVector * y
index of operand 2
RzILOpBool * fill_bit
index of fill bit

References rz_il_bool_t::b, rz_il_op_args_shift_t::fill_bit, NULL, rz_bv_dup(), rz_bv_free(), rz_bv_lshift_fill(), rz_bv_to_ut32(), rz_il_bool_free(), rz_il_evaluate_bitv(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, shift(), type, rz_il_op_args_shift_t::x, and rz_il_op_args_shift_t::y.

◆ rz_il_handler_shiftr()

void* rz_il_handler_shiftr ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 313 of file theory_bitv.c.

313  {
314  rz_return_val_if_fail(vm && op && type, NULL);
315 
316  RzILOpArgsShiftRight *op_shr = &op->op.shiftr;
317 
318  RzBitVector *bv = rz_il_evaluate_bitv(vm, op_shr->x);
319  RzBitVector *shift = rz_il_evaluate_bitv(vm, op_shr->y);
320  RzILBool *fill_bit = rz_il_evaluate_bool(vm, op_shr->fill_bit);
321 
322  RzBitVector *result = NULL;
323  if (bv && shift && fill_bit) {
324  result = rz_bv_dup(bv);
325  rz_bv_rshift_fill(result, rz_bv_to_ut32(shift), fill_bit->b);
326  }
327 
328  rz_bv_free(shift);
329  rz_bv_free(bv);
330  rz_il_bool_free(fill_bit);
331 
333  return result;
334 }
RZ_API bool rz_bv_rshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
Definition: bitvector.c:508

References rz_il_bool_t::b, rz_il_op_args_shift_t::fill_bit, NULL, rz_bv_dup(), rz_bv_free(), rz_bv_rshift_fill(), rz_bv_to_ut32(), rz_il_bool_free(), rz_il_evaluate_bitv(), rz_il_evaluate_bool(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, shift(), type, rz_il_op_args_shift_t::x, and rz_il_op_args_shift_t::y.

◆ rz_il_handler_sle()

void* rz_il_handler_sle ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 84 of file theory_bitv.c.

84  {
85  rz_return_val_if_fail(vm && op && type, NULL);
86 
87  RzILOpArgsSle *op_sle = &op->op.sle;
88 
89  RzBitVector *x = rz_il_evaluate_bitv(vm, op_sle->x);
90  RzBitVector *y = rz_il_evaluate_bitv(vm, op_sle->y);
91  RzILBool *result = x && y ? rz_il_bool_new(rz_bv_sle(x, y)) : NULL;
92  rz_bv_free(x);
93  rz_bv_free(y);
94 
96  return result;
97 }
RZ_API bool rz_bv_sle(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1064

References NULL, rz_bv_free(), rz_bv_sle(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_cmp_t::x, and rz_il_op_args_cmp_t::y.

◆ rz_il_handler_smod()

void* rz_il_handler_smod ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 276 of file theory_bitv.c.

276  {
277  rz_return_val_if_fail(vm && op && type, NULL);
278 
279  RzILOpArgsSmod *op_smod = &op->op.smod;
280 
281  RzBitVector *x = rz_il_evaluate_bitv(vm, op_smod->x);
282  RzBitVector *y = rz_il_evaluate_bitv(vm, op_smod->y);
283  RzBitVector *result = x && y ? rz_bv_smod(x, y) : NULL;
284  rz_bv_free(x);
285  rz_bv_free(y);
286 
288  return result;
289 }
RZ_API RZ_OWN RzBitVector * rz_bv_smod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:952

References NULL, rz_bv_free(), rz_bv_smod(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_store()

bool rz_il_handler_store ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 22 of file theory_mem.c.

22  {
24 
25  RzILOpArgsStore *op_store = &op->op.store;
26 
27  RzBitVector *addr = rz_il_evaluate_bitv(vm, op_store->key);
28  RzBitVector *value = rz_il_evaluate_bitv(vm, op_store->value);
29 
30  bool ret = false;
31  if (addr && value) {
32  ret = true;
33  rz_il_vm_mem_store(vm, op_store->mem, addr, value);
34  }
37 
38  return ret;
39 }
static int value
Definition: cmd_api.c:93
RZ_API void rz_il_vm_mem_store(RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
Definition: il_vm_eval.c:144
op structure for store (('a, 'b) mem -> 'a bitv -> 'b bitv -> ('a, 'b) mem)
RzILOpBitVector * value
value to store, must have exactly the size of a memory cell
RzILOpBitVector * key
address where to store to, must have exactly the size of a key in the memory
RzILMemIndex mem
index of memory in the vm to use

References addr, rz_il_op_args_store_t::key, rz_il_op_args_store_t::mem, NULL, rz_bv_free(), rz_il_evaluate_bitv(), rz_il_vm_mem_store(), rz_return_val_if_fail, value, and rz_il_op_args_store_t::value.

◆ rz_il_handler_storew()

bool rz_il_handler_storew ( RzILVM vm,
RzILOpEffect op 
)

Definition at line 55 of file theory_mem.c.

55  {
57 
58  RzILOpArgsStoreW *op_storew = &op->op.storew;
59 
60  RzBitVector *addr = rz_il_evaluate_bitv(vm, op_storew->key);
61  RzBitVector *value = rz_il_evaluate_bitv(vm, op_storew->value);
62 
63  bool ret = false;
64  if (addr && value) {
65  ret = true;
66  rz_il_vm_mem_storew(vm, op_storew->mem, addr, value);
67  }
68 
71 
72  return ret;
73 }
RZ_API void rz_il_vm_mem_storew(RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
Definition: il_vm_eval.c:183
Store an entire word of arbitrary bit size into a memory.
RzILOpBitVector * value
value to store, arbitrary size
RzILMemIndex mem
index of memory in the vm to use
RzILOpBitVector * key
address where to store to

References addr, rz_il_op_args_storew_t::key, rz_il_op_args_storew_t::mem, NULL, rz_bv_free(), rz_il_evaluate_bitv(), rz_il_vm_mem_storew(), rz_return_val_if_fail, value, and rz_il_op_args_storew_t::value.

◆ rz_il_handler_sub()

void* rz_il_handler_sub ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 190 of file theory_bitv.c.

190  {
191  rz_return_val_if_fail(vm && op && type, NULL);
192 
193  RzILOpArgsSub *op_sub = &op->op.sub;
194 
195  RzBitVector *x = rz_il_evaluate_bitv(vm, op_sub->x);
196  RzBitVector *y = rz_il_evaluate_bitv(vm, op_sub->y);
197  RzBitVector *result = x && y ? rz_bv_sub(x, y, NULL) : NULL;
198  rz_bv_free(x);
199  rz_bv_free(y);
200 
202  return result;
203 }
RZ_API RZ_OWN RzBitVector * rz_bv_sub(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *borrow)
Definition: bitvector.c:715

References NULL, rz_bv_free(), rz_bv_sub(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_return_val_if_fail, type, x, rz_il_op_args_alg_log_operations_t::x, and rz_il_op_args_alg_log_operations_t::y.

◆ rz_il_handler_ule()

void* rz_il_handler_ule ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 99 of file theory_bitv.c.

99  {
100  rz_return_val_if_fail(vm && op && type, NULL);
101 
102  RzILOpArgsUle *op_ule = &op->op.ule;
103 
104  RzBitVector *x = rz_il_evaluate_bitv(vm, op_ule->x);
105  RzBitVector *y = rz_il_evaluate_bitv(vm, op_ule->y);
106  RzILBool *result = x && y ? rz_il_bool_new(rz_bv_ule(x, y)) : NULL;
107  rz_bv_free(x);
108  rz_bv_free(y);
109 
111  return result;
112 }
RZ_API bool rz_bv_ule(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1052

References NULL, rz_bv_free(), rz_bv_ule(), rz_il_bool_new(), rz_il_evaluate_bitv(), RZ_IL_TYPE_PURE_BOOL, rz_return_val_if_fail, type, x, rz_il_op_args_cmp_t::x, and rz_il_op_args_cmp_t::y.

◆ rz_il_handler_var()

void* rz_il_handler_var ( RzILVM vm,
RzILOpPure op,
RzILTypePure type 
)

Definition at line 26 of file theory_init.c.

26  {
27  rz_return_val_if_fail(vm && op && type, NULL);
28 
29  RzILOpArgsVar *var_op = &op->op.var;
30  RzILVal *val = rz_il_vm_get_var_value(vm, var_op->kind, var_op->v);
31  if (!val) {
32  RZ_LOG_ERROR("RzIL: reading value of variable \"%s\" of kind %s failed.\n",
33  var_op->v, rz_il_var_kind_name(var_op->kind));
34  return NULL;
35  }
36 
37  if (var_op->kind == RZ_IL_VAR_KIND_GLOBAL) {
39  }
40 
41  void *ret = NULL;
42  switch (val->type) {
45  ret = rz_il_bool_new(val->data.b->b);
46  break;
49  ret = rz_bv_dup(val->data.bv);
50  break;
51  default:
52  break;
53  }
54  return ret;
55 }
RZ_API RZ_OWN RzILEvent * rz_il_event_var_read_new(RZ_NONNULL const char *name, RZ_NULLABLE const RzILVal *value)
Definition: il_events.c:152
RZ_API RZ_BORROW RzILVal * rz_il_vm_get_var_value(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:264
op structure for var ('a var -> 'a pure)
RzILVarKind kind
set of variables to pick from
const char * v
name of variable, const one
const char * rz_il_var_kind_name(RzILVarKind kind)
Definition: variable.c:181
@ RZ_IL_VAR_KIND_GLOBAL
global var, usually bound to a physical representation like a register.
Definition: variable.h:47

References rz_il_op_args_var_t::kind, NULL, rz_bv_dup(), rz_il_bool_new(), rz_il_event_var_read_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, RZ_IL_VAR_KIND_GLOBAL, rz_il_var_kind_name(), rz_il_vm_event_add(), rz_il_vm_get_var_value(), RZ_LOG_ERROR, rz_return_val_if_fail, type, rz_il_op_args_var_t::v, and val.

◆ 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_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
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

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_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 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
void * mem
Definition: libc.cpp:91
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
bool big_endian
Sets the endianness of the memory reads/writes operations.
Definition: rz_il_vm.h:50

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
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1140

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_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 RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
RzILVarSet local_vars
All local variables, created by local set ops.
Definition: rz_il_vm.h:39
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().

Variable Documentation

◆ rz_il_op_handler_effect_table_default

RZ_IPI RzILOpEffectHandler rz_il_op_handler_effect_table_default[RZ_IL_OP_EFFECT_MAX]
Initial value:
= {
}
bool rz_il_handler_branch(RzILVM *vm, RzILOpEffect *op)
bool rz_il_handler_nop(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:34
bool rz_il_handler_jmp(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:56
bool rz_il_handler_set(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:39
bool rz_il_handler_goto(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:66
bool rz_il_handler_empty(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:28
bool rz_il_handler_storew(RzILVM *vm, RzILOpEffect *op)
Definition: theory_mem.c:55
bool rz_il_handler_seq(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:83
bool rz_il_handler_store(RzILVM *vm, RzILOpEffect *op)
Definition: theory_mem.c:22
bool rz_il_handler_repeat(RzILVM *vm, RzILOpEffect *op)
bool rz_il_handler_blk(RzILVM *vm, RzILOpEffect *op)
Definition: theory_effect.c:89
@ RZ_IL_OP_BLK
@ RZ_IL_OP_GOTO
@ RZ_IL_OP_SEQ
@ RZ_IL_OP_NOP
@ RZ_IL_OP_JMP
@ RZ_IL_OP_EMPTY
@ RZ_IL_OP_STORE
@ RZ_IL_OP_STOREW
@ RZ_IL_OP_REPEAT
@ RZ_IL_OP_BRANCH
@ RZ_IL_OP_SET

Definition at line 104 of file il_vm_eval.c.

Referenced by rz_il_vm_init().

◆ rz_il_op_handler_pure_table_default

RZ_IPI RzILOpPureHandler rz_il_op_handler_pure_table_default[RZ_IL_OP_PURE_MAX]

Definition at line 67 of file il_vm_eval.c.

Referenced by rz_il_vm_init().