Rizin
unix-like reverse engineering framework and cli tools
|
#include <rz_il/definitions/definitions.h>
#include <rz_il/rz_il_opcodes.h>
#include <rz_il/rz_il_events.h>
#include <rz_il/rz_il_reg.h>
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 RzILVal * | RzILLocalPurePrev |
typedef RZ_NULLABLE RzILVal* RzILLocalPurePrev |
Definition at line 86 of file rz_il_vm.h.
typedef bool(* RzILOpEffectHandler) (RzILVM *vm, RzILOpEffect *op) |
Evaluation (execution) callback for a single effect opcode.
Definition at line 30 of file rz_il_vm.h.
typedef void*(* RzILOpPureHandler) (RzILVM *vm, RzILOpPure *op, RZ_NONNULL RZ_OUT RzILTypePure *type) |
Evaluation callback for a single pure opcode.
type | when returning a non-null value, this must be set to the respective type. |
Definition at line 24 of file rz_il_vm.h.
typedef struct rz_il_vm_t RzILVM |
Definition at line 1 of file rz_il_vm.h.
typedef void(* RzILVmHook) (RzILVM *vm, RzILOpEffect *op) |
Definition at line 32 of file rz_il_vm.h.
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.
Definition at line 269 of file il_vm_eval.c.
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_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.
Definition at line 289 of file il_vm_eval.c.
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_API bool rz_il_evaluate_effect | ( | RZ_NONNULL RzILVM * | vm, |
RZ_NONNULL RzILOpEffect * | op | ||
) |
Evaluate (execute) the given effect op
Definition at line 341 of file il_vm_eval.c.
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_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.
References eval_pure(), NULL, rz_return_val_if_fail, and type.
Referenced by rz_il_handler_ite(), and rz_il_handler_let().
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.
Definition at line 309 of file il_vm_eval.c.
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_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
vm | RzILVM* vm, pointer to VM |
lbl_name | string, the name of label |
Definition at line 275 of file il_vm.c.
References found, NULL, and rz_return_val_if_fail.
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.
References rz_return_if_fail.
Referenced by rz_il_vm_create_label(), rz_il_vm_create_label_lazy(), and setup_vm_from_config().
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.
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().
Remove any recorded events from vm->events
Definition at line 212 of file il_vm_eval.c.
References rz_il_vm_t::events, and rz_list_purge().
Referenced by rz_il_vm_step().
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.
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_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
vm | RzILVM, pointer to VM |
name | string, name of label |
addr | RzBitVector, label address |
Definition at line 308 of file il_vm.c.
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_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
vm | RzILVM, pointer to VM |
name | string, name of this label |
Definition at line 322 of file il_vm.c.
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.
Adds to the VM a new event into the VM event list
vm,RzILVM,pointer | to the VM |
evt,RzILEvent,pointer | to the event |
Definition at line 201 of file il_vm_eval.c.
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_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
vm | RzILVM, pointer to VM |
lbl_name | string, the name of label |
Definition at line 291 of file il_vm.c.
References NULL, and rz_return_val_if_fail.
Referenced by rz_il_handler_goto().
Close and clean vm
vm | RzILVM* pointer to VM |
Definition at line 93 of file il_vm.c.
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().
Close, clean and free vm
vm | RzILVM* pointer to VM |
Definition at line 134 of file il_vm.c.
References free(), and rz_il_vm_fini().
Referenced by rz_analysis_il_vm_free(), and setup_vm_from_config().
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.
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_API RzILMem* rz_il_vm_get_mem | ( | RzILVM * | vm, |
RzILMemIndex | index | ||
) |
Definition at line 165 of file il_vm.c.
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().
Get the number of bits of the program counter bitvector
Definition at line 145 of file il_vm.c.
References rz_il_vm_t::pc, and rz_bv_len().
Referenced by rz_il_validate_global_context_new_from_vm().
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.
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_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.
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().
initiate an empty VM
vm | RzILVM, pointer to an empty VM |
start_addr | ut64, initiation pc address |
addr_size | ut32, size of the address in VM |
Definition at line 27 of file il_vm.c.
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_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
vm | RzILVM, pointer to VM |
key | RzBitVector, aka address, a key to load data from memory |
vm->min_unit_size
length Definition at line 124 of file il_vm_eval.c.
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_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
vm | RzILVM, pointer to VM |
key | RzBitVector, aka address, a key to load data from memory |
vm->min_unit_size
length Definition at line 163 of file il_vm_eval.c.
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_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
vm | RzILVM* pointer to VM |
key | RzBitVector, aka address, a key to store data from memory |
value | RzBitVector, aka value to store in memory |
Definition at line 144 of file il_vm_eval.c.
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_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
vm | RzILVM* pointer to VM |
key | RzBitVector, aka address, a key to store data from memory |
value | RzBitVector, aka value to store in memory |
Definition at line 183 of file il_vm_eval.c.
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().
Create a new empty VM
vm | RzILVM, pointer to an empty VM |
start_addr | ut64, initiation pc address |
addr_size | ut32, size of the address in VM |
Definition at line 121 of file il_vm.c.
References NULL, rz_il_vm_init(), and RZ_NEW0.
Referenced by setup_vm_from_config().
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.
prev | pass here the return value of rz_il_vm_push_local_pure_var() |
Definition at line 227 of file il_vm.c.
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_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.
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_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.
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_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.
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_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
vm | pointer to VM |
op_list,a | list of op roots. |
fallthrough_addr | initial 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.
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_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
vm | RzILVM, pointer to VM |
name | string, name of this label |
Definition at line 336 of file il_vm.c.
References addr, rz_il_effect_label_t::addr, NULL, rz_bv_dup(), rz_bv_free(), and rz_return_val_if_fail.