Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Classes | |
struct | rz_il_validate_global_context_t |
struct | LocalContext |
struct | LocalContextMeet |
struct | local_pure_var_t |
Effect | |
#define | VALIDATOR_EFFECT_ARGS |
#define | VALIDATOR_EFFECT_NAME(op) validate_effect_##op |
#define | VALIDATOR_EFFECT(op) static bool VALIDATOR_EFFECT_NAME(op)(VALIDATOR_EFFECT_ARGS) |
#define | VALIDATOR_DESCEND_PURE(op, sort) |
#define | VALIDATOR_DESCEND_EFFECT(op, etype, ectx, cleanup) |
typedef bool(* | ValidateEffectFn) (VALIDATOR_EFFECT_ARGS) |
static ValidateEffectFn | validate_effect_table [RZ_IL_OP_EFFECT_MAX] |
static bool | validate_effect (VALIDATOR_EFFECT_ARGS) |
VALIDATOR_EFFECT (empty) | |
VALIDATOR_EFFECT (nop) | |
VALIDATOR_EFFECT (store) | |
VALIDATOR_EFFECT (storew) | |
VALIDATOR_EFFECT (set) | |
VALIDATOR_EFFECT (jmp) | |
VALIDATOR_EFFECT (goto) | |
VALIDATOR_EFFECT (seq) | |
VALIDATOR_EFFECT (blk) | |
VALIDATOR_EFFECT (repeat) | |
VALIDATOR_EFFECT (branch) | |
RZ_API bool | rz_il_validate_effect (RZ_NULLABLE RzILOpEffect *op, RZ_NONNULL RzILValidateGlobalContext *ctx, RZ_NULLABLE RZ_OUT HtPP **local_var_sorts_out, RZ_NULLABLE RZ_OUT RzILTypeEffect *type_out, RZ_NULLABLE RZ_OUT RzILValidateReport *report_out) |
#define VALIDATOR_ASSERT | ( | condition, | |
... | |||
) |
Definition at line 276 of file il_validate.c.
#define VALIDATOR_DESCEND | ( | op, | |
sort | |||
) |
Definition at line 283 of file il_validate.c.
Definition at line 640 of file il_validate.c.
#define VALIDATOR_DESCEND_PURE | ( | op, | |
sort | |||
) |
Definition at line 634 of file il_validate.c.
#define VALIDATOR_EFFECT | ( | op | ) | static bool VALIDATOR_EFFECT_NAME(op)(VALIDATOR_EFFECT_ARGS) |
Definition at line 633 of file il_validate.c.
#define VALIDATOR_EFFECT_ARGS |
Definition at line 622 of file il_validate.c.
Definition at line 632 of file il_validate.c.
#define VALIDATOR_PURE | ( | op | ) | static bool VALIDATOR_PURE_NAME(op)(VALIDATOR_PURE_ARGS) |
Definition at line 275 of file il_validate.c.
#define VALIDATOR_PURE_ARGS |
Definition at line 263 of file il_validate.c.
Definition at line 274 of file il_validate.c.
typedef struct local_pure_var_t LocalPureVar |
Linked list (stack) of let-bound vars
While descending, new var definitions are pushed, thus shadowing other vars of the same name when searching from the head.
typedef bool(* ValidateEffectFn) (VALIDATOR_EFFECT_ARGS) |
Definition at line 630 of file il_validate.c.
typedef bool(* ValidatePureFn) (VALIDATOR_PURE_ARGS) |
Definition at line 272 of file il_validate.c.
|
static |
Definition at line 161 of file il_validate.c.
References dst, local_context_init(), local_var_copy_avail_cb(), local_var_copy_known_cb(), and src.
Referenced by VALIDATOR_EFFECT().
|
static |
Definition at line 136 of file il_validate.c.
Referenced by rz_il_validate_effect(), rz_il_validate_pure(), and VALIDATOR_EFFECT().
|
static |
Definition at line 122 of file il_validate.c.
References NULL, var_kv_free(), and var_kv_unown_free().
Referenced by local_context_copy(), rz_il_validate_effect(), and rz_il_validate_pure().
|
static |
Meet (intersection) of two contexts, usually when two control flow paths meet. Known types for local vars are always kept from both, to ensure they always have the same type in the entire expression. Available local vars are intersected. This fails when a
and b
both know about a local var, but don't agree about its type.
a
First input operand, this will also be modified in-place to contain the result. b
Second input operand, will not be modified. report_builder
On failure, will be appended with an error message op_name
Name of the op in which the meet is being performed, for the error message
Definition at line 228 of file il_validate.c.
References a, b, LocalContextMeet::failed, local_var_meet_avail_cb(), and local_var_meet_known_cb().
Referenced by VALIDATOR_EFFECT().
|
static |
Definition at line 152 of file il_validate.c.
References dst, k, NULL, rz_il_sort_pure_eq(), rz_return_val_if_fail, and v.
Referenced by local_context_copy().
|
static |
Definition at line 141 of file il_validate.c.
References dst, k, RZ_NEW, and v.
Referenced by local_context_copy().
|
static |
Definition at line 206 of file il_validate.c.
References LocalContextMeet::dst, k, LocalContext::local_vars_available, NULL, and LocalContextMeet::src.
Referenced by local_context_meet().
|
static |
Definition at line 179 of file il_validate.c.
References LocalContextMeet::dst, LocalContextMeet::failed, free(), k, LocalContext::local_vars_known, NULL, LocalContextMeet::op_name, LocalContextMeet::report_builder, rz_il_sort_pure_eq(), rz_il_sort_pure_stringify(), RZ_NEW, rz_strbuf_appendf(), and v.
Referenced by local_context_meet().
RZ_API bool rz_il_validate_effect | ( | RZ_NULLABLE RzILOpEffect * | op, |
RZ_NONNULL RzILValidateGlobalContext * | ctx, | ||
RZ_NULLABLE RZ_OUT HtPP ** | local_var_sorts_out, | ||
RZ_NULLABLE RZ_OUT RzILTypeEffect * | type_out, | ||
RZ_NULLABLE RZ_OUT RzILValidateReport * | report_out | ||
) |
Run validation (type-checking and other checks) on an effect. op
the op to be checked. May be null, which will always be reported as invalid. ctx
global context, defining available global vars and mems local_var_sorts_out
optionally returns a map of local variable names defined in the effect to their sorts type_put
optionally returns the type of effects that the ops perform, i.e. ctrl, data, both or none report_out
optionally returns a readable report containing details about why the validation failed
ctx
Definition at line 846 of file il_validate.c.
References local_context_fini(), local_context_init(), LocalContext::local_vars_known, NULL, RZ_IL_TYPE_EFFECT_NONE, rz_str_trim_tail(), rz_strbuf_drain_nofree(), rz_strbuf_fini(), rz_strbuf_init(), rz_strbuf_is_empty(), type, valid, and validate_effect().
Referenced by print_and_check_il().
RZ_API void rz_il_validate_global_context_add_mem | ( | RzILValidateGlobalContext * | ctx, |
RzILMemIndex | idx, | ||
ut32 | key_len, | ||
ut32 | val_len | ||
) |
Define a new memory in ctx
Definition at line 69 of file il_validate.c.
References setup::idx, rz_return_if_fail, and ut64().
Referenced by rz_il_validate_global_context_new_from_vm().
RZ_API void rz_il_validate_global_context_add_var | ( | RzILValidateGlobalContext * | ctx, |
RZ_NONNULL const char * | name, | ||
RzILSortPure | sort | ||
) |
Define a new global variable in ctx
Definition at line 56 of file il_validate.c.
References RZ_NEW, and rz_return_if_fail.
Referenced by rz_il_validate_global_context_new_from_vm().
RZ_API void rz_il_validate_global_context_free | ( | RzILValidateGlobalContext * | ctx | ) |
RZ_API RzILValidateGlobalContext* rz_il_validate_global_context_new_empty | ( | ut32 | pc_len | ) |
Create a new global context for validation Vars and mems can be added manually with rz_il_validate_global_context_add_* functions.
Definition at line 32 of file il_validate.c.
References free(), NULL, RZ_NEW0, rz_return_val_if_fail, and var_kv_free().
Referenced by rz_il_validate_global_context_new_from_vm().
RZ_API RzILValidateGlobalContext* rz_il_validate_global_context_new_from_vm | ( | RZ_NONNULL RzILVM * | vm | ) |
Create a new context for IL validation based on the global vars and mems in vm
Definition at line 77 of file il_validate.c.
References i, mem, rz_il_var_t::name, NULL, rz_il_mem_key_len(), rz_il_mem_value_len(), rz_il_validate_global_context_add_mem(), rz_il_validate_global_context_add_var(), rz_il_validate_global_context_new_empty(), RZ_IL_VAR_KIND_GLOBAL, rz_il_vm_get_all_vars(), rz_il_vm_get_pc_len(), rz_pvector_at(), rz_pvector_foreach, rz_pvector_free(), rz_pvector_len(), rz_return_val_if_fail, and rz_il_var_t::sort.
Referenced by print_and_check_il().
RZ_API bool rz_il_validate_pure | ( | RZ_NULLABLE RzILOpPure * | op, |
RZ_NONNULL RzILValidateGlobalContext * | ctx, | ||
RZ_NULLABLE RZ_OUT RzILSortPure * | sort_out, | ||
RZ_NULLABLE RZ_OUT RzILValidateReport * | report_out | ||
) |
Run validation (type-checking and other checks) on a pure expression and determine its sort. op
the op to be checked. May be null, which will always be reported as invalid. ctx
global context, defining available global vars and mems sort_out
optionally returns the sort of the expression, if it is valid report_out
optionally returns a readable report containing details about why the validation failed
ctx
Definition at line 584 of file il_validate.c.
References local_context_fini(), local_context_init(), NULL, rz_str_trim_tail(), rz_strbuf_drain_nofree(), rz_strbuf_fini(), rz_strbuf_init(), rz_strbuf_is_empty(), local_pure_var_t::sort, valid, and validate_pure().
|
static |
Definition at line 830 of file il_validate.c.
References op::code, rz_return_val_if_fail, validate_effect_table, and VALIDATOR_ASSERT.
Referenced by rz_il_validate_effect().
|
static |
Definition at line 569 of file il_validate.c.
References op::code, rz_return_val_if_fail, validate_pure_table, and VALIDATOR_ASSERT.
Referenced by rz_il_validate_pure(), and VALIDATOR_PURE().
VALIDATOR_EFFECT | ( | blk | ) |
Definition at line 764 of file il_validate.c.
References args, RZ_IL_TYPE_EFFECT_CTRL, RZ_IL_TYPE_EFFECT_DATA, VALIDATOR_ASSERT, and VALIDATOR_DESCEND_EFFECT.
VALIDATOR_EFFECT | ( | branch | ) |
Definition at line 797 of file il_validate.c.
References args, local_context_copy(), local_context_fini(), local_context_meet(), RZ_IL_TYPE_PURE_BOOL, sc, val, VALIDATOR_ASSERT, VALIDATOR_DESCEND_EFFECT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_EFFECT | ( | empty | ) |
Definition at line 647 of file il_validate.c.
References RZ_IL_TYPE_EFFECT_NONE.
VALIDATOR_EFFECT | ( | goto | ) |
Definition at line 741 of file il_validate.c.
References args, RZ_IL_TYPE_EFFECT_CTRL, and VALIDATOR_ASSERT.
VALIDATOR_EFFECT | ( | jmp | ) |
Definition at line 729 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, rz_il_sort_pure_t::props, RZ_IL_TYPE_EFFECT_CTRL, RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_EFFECT | ( | nop | ) |
Definition at line 652 of file il_validate.c.
References RZ_IL_TYPE_EFFECT_NONE.
VALIDATOR_EFFECT | ( | repeat | ) |
Definition at line 777 of file il_validate.c.
References args, local_context_copy(), local_context_fini(), local_context_meet(), RZ_IL_TYPE_EFFECT_DATA, RZ_IL_TYPE_PURE_BOOL, sc, val, VALIDATOR_ASSERT, VALIDATOR_DESCEND_EFFECT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_EFFECT | ( | seq | ) |
Definition at line 749 of file il_validate.c.
References args, RZ_IL_TYPE_EFFECT_CTRL, VALIDATOR_ASSERT, and VALIDATOR_DESCEND_EFFECT.
VALIDATOR_EFFECT | ( | set | ) |
Definition at line 696 of file il_validate.c.
References args, free(), NULL, rz_il_sort_pure_eq(), rz_il_sort_pure_stringify(), RZ_IL_TYPE_EFFECT_DATA, RZ_NEW, rz_str_get_null(), rz_strbuf_appendf(), local_pure_var_t::sort, VALIDATOR_ASSERT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_EFFECT | ( | store | ) |
Definition at line 657 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, found, rz_il_sort_pure_t::props, RZ_IL_TYPE_EFFECT_DATA, RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, UT32_MAX, ut64(), VALIDATOR_ASSERT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_EFFECT | ( | storew | ) |
Definition at line 678 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, found, rz_il_sort_pure_t::props, RZ_IL_TYPE_EFFECT_DATA, RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, ut64(), VALIDATOR_ASSERT, and VALIDATOR_DESCEND_PURE.
VALIDATOR_PURE | ( | append | ) |
Definition at line 487 of file il_validate.c.
References rz_il_sort_pure_t::bv, rz_il_sort_pure_t::props, rz_il_sort_pure_bv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, VALIDATOR_DESCEND, and x.
VALIDATOR_PURE | ( | bitv | ) |
Definition at line 327 of file il_validate.c.
References rz_bv_len(), rz_il_sort_pure_bv(), and rz_strbuf_appendf().
VALIDATOR_PURE | ( | bitv_binop | ) |
'a bitv -> 'a bitv -> 'a bitv ops e.g. add, sub, mul, div, ...
Definition at line 341 of file il_validate.c.
References rz_il_sort_pure_t::bv, op::code, rz_il_sort_pure_t::props, rz_il_op_pure_code_stringify(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, VALIDATOR_DESCEND, and x.
VALIDATOR_PURE | ( | bitv_bool_unop | ) |
'a bitv -> bool ops e.g. msb, lsb
Definition at line 423 of file il_validate.c.
References op::code, rz_il_op_pure_code_stringify(), rz_il_sort_pure_bool(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, VALIDATOR_DESCEND, and x.
VALIDATOR_PURE | ( | bitv_unop | ) |
'a bitv -> 'a bitv ops e.g. bitwise negation
Definition at line 436 of file il_validate.c.
References op::code, rz_il_op_pure_code_stringify(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, VALIDATOR_DESCEND, and x.
VALIDATOR_PURE | ( | bool_binop | ) |
bool -> bool -> bool ops e.g. and, or, ...
Definition at line 406 of file il_validate.c.
References op::code, rz_il_op_pure_code_stringify(), rz_il_sort_pure_bool(), RZ_IL_TYPE_PURE_BOOL, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, VALIDATOR_DESCEND, and x.
VALIDATOR_PURE | ( | bool_const | ) |
Definition at line 322 of file il_validate.c.
References rz_il_sort_pure_bool().
VALIDATOR_PURE | ( | cast | ) |
Definition at line 474 of file il_validate.c.
References args, op::code, rz_il_op_pure_code_stringify(), rz_il_sort_pure_bv(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | cmp | ) |
Definition at line 460 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, op::code, rz_il_sort_pure_t::props, rz_il_op_pure_code_stringify(), rz_il_sort_pure_bool(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | inv | ) |
Definition at line 393 of file il_validate.c.
References args, rz_il_sort_pure_bool(), RZ_IL_TYPE_PURE_BOOL, local_pure_var_t::sort, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | ite | ) |
Definition at line 356 of file il_validate.c.
References args, free(), rz_il_sort_pure_eq(), rz_il_sort_pure_stringify(), RZ_IL_TYPE_PURE_BOOL, rz_str_get_null(), rz_strbuf_appendf(), sc, VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | let | ) |
Definition at line 378 of file il_validate.c.
References args, local_pure_var_t::name, local_pure_var_t::sort, validate_pure(), VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | load | ) |
Definition at line 500 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, found, rz_il_sort_pure_t::props, rz_il_sort_pure_bv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, UT32_MAX, ut64(), VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | loadw | ) |
Definition at line 516 of file il_validate.c.
References args, rz_il_sort_pure_t::bv, found, rz_il_sort_pure_t::props, rz_il_sort_pure_bv(), RZ_IL_TYPE_PURE_BITVECTOR, rz_il_sort_pure_t::type, ut64(), VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | shift | ) |
Definition at line 445 of file il_validate.c.
References args, op::code, rz_il_op_pure_code_stringify(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_sort_pure_t::type, VALIDATOR_ASSERT, and VALIDATOR_DESCEND.
VALIDATOR_PURE | ( | var | ) |
Definition at line 290 of file il_validate.c.
References args, local_pure_var_t::next, NULL, RZ_IL_VAR_KIND_GLOBAL, RZ_IL_VAR_KIND_LOCAL, RZ_IL_VAR_KIND_LOCAL_PURE, local_pure_var_t::sort, and VALIDATOR_ASSERT.
|
static |
Definition at line 19 of file il_validate.c.
References free().
Referenced by local_context_init(), and rz_il_validate_global_context_new_empty().
|
static |
|
static |
Definition at line 816 of file il_validate.c.
Referenced by validate_effect().
|
static |
Definition at line 532 of file il_validate.c.
Referenced by validate_pure().