Rizin
unix-like reverse engineering framework and cli tools
rz_il_vm.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Florian Märkl <info@florianmaerkl.de>
2 // SPDX-FileCopyrightText: 2021 heersin <teablearcher@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #ifndef RZ_IL_VM_H
6 #define RZ_IL_VM_H
7 
9 #include <rz_il/rz_il_opcodes.h>
10 #include <rz_il/rz_il_events.h>
11 #include <rz_il/rz_il_reg.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef struct rz_il_vm_t RzILVM;
18 
24 typedef void *(*RzILOpPureHandler)(RzILVM *vm, RzILOpPure *op, RZ_NONNULL RZ_OUT RzILTypePure *type);
25 
31 
32 typedef void (*RzILVmHook)(RzILVM *vm, RzILOpEffect *op);
33 
37 struct rz_il_vm_t {
41  RzPVector /*<RzILMem>*/ vm_memory;
50  bool big_endian;
51 };
52 
53 // VM high level operations
54 RZ_API RzILVM *rz_il_vm_new(ut64 start_addr, ut32 addr_size, bool big_endian);
55 RZ_API void rz_il_vm_free(RzILVM *vm);
56 RZ_API bool rz_il_vm_init(RzILVM *vm, ut64 start_addr, ut32 addr_size, bool big_endian);
57 RZ_API void rz_il_vm_fini(RzILVM *vm);
58 
60 
61 // VM Event operations
64 
65 // Memory operations
68 
73 
74 // Labels
81 
82 // Variables
92 
93 // Evaluation (Emulation)
99 
100 RZ_API bool rz_il_vm_step(RzILVM *vm, RzILOpEffect *op, ut64 fallthrough_addr);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif // RZ_IL_VM_H
ut8 op
Definition: 6502dis.c:13
ut16 val
Definition: armass64_const.h:6
static int value
Definition: cmd_api.c:93
#define RZ_API
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
uint32_t ut32
void * mem
Definition: libc.cpp:91
ut32 RzILMemIndex
Definition: mem.h:14
int type
Definition: mipsasm.c:17
list of types of events that can happen on the VM
signatures of core theory opcodes
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 void rz_il_vm_set_local_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
Definition: il_vm.c:202
RZ_API RZ_BORROW RzBitVector * rz_il_hash_find_addr_by_lblname(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *lbl_name)
Definition: il_vm.c:275
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
RZ_API void rz_il_vm_set_global_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
Definition: il_vm.c:193
RZ_API void rz_il_vm_add_mem(RzILVM *vm, RzILMemIndex index, RZ_OWN RzILMem *mem)
Definition: il_vm.c:153
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_clear_events(RzILVM *vm)
Definition: il_vm_eval.c:212
RZ_API void rz_il_vm_mem_storew(RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
Definition: il_vm_eval.c:183
RZ_API void rz_il_vm_fini(RzILVM *vm)
Definition: il_vm.c:93
RZ_API bool rz_il_evaluate_effect(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILOpEffect *op)
Definition: il_vm_eval.c:341
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 void rz_il_vm_mem_store(RzILVM *vm, RzILMemIndex index, RzBitVector *key, RzBitVector *value)
Definition: il_vm_eval.c:144
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
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
RZ_API RZ_BORROW RzILEffectLabel * rz_il_vm_update_label(RZ_NONNULL RzILVM *vm, RZ_NONNULL char *name, RZ_NONNULL RZ_BORROW RzBitVector *addr)
Definition: il_vm.c:336
bool(* RzILOpEffectHandler)(RzILVM *vm, RzILOpEffect *op)
Evaluation (execution) callback for a single effect opcode.
Definition: rz_il_vm.h:30
RZ_API RzBitVector * rz_il_vm_mem_load(RzILVM *vm, RzILMemIndex index, RzBitVector *key)
Definition: il_vm_eval.c:124
RZ_API RZ_BORROW RzILEffectLabel * rz_il_vm_create_label_lazy(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name)
Definition: il_vm.c:322
void(* RzILVmHook)(RzILVM *vm, RzILOpEffect *op)
Definition: rz_il_vm.h:32
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
RZ_NULLABLE RzILVal * RzILLocalPurePrev
Definition: rz_il_vm.h:86
RZ_API RZ_OWN RzPVector * rz_il_vm_get_all_vars(RZ_NONNULL RzILVM *vm, RzILVarKind kind)
Definition: il_vm.c:256
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
RZ_API RzBitVector * rz_il_vm_mem_loadw(RzILVM *vm, RzILMemIndex index, RzBitVector *key, ut32 n_bits)
Definition: il_vm_eval.c:163
RZ_API RzILMem * rz_il_vm_get_mem(RzILVM *vm, RzILMemIndex index)
Definition: il_vm.c:165
RZ_API RZ_BORROW RzILVar * rz_il_vm_create_global_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RzILSortPure sort)
Definition: il_vm.c:175
RZ_API bool rz_il_vm_step(RzILVM *vm, RzILOpEffect *op, ut64 fallthrough_addr)
Definition: il_vm_eval.c:222
RZ_API RzILVM * rz_il_vm_new(ut64 start_addr, ut32 addr_size, bool big_endian)
Definition: il_vm.c:121
RZ_API void rz_il_vm_free(RzILVM *vm)
Definition: il_vm.c:134
RZ_API void rz_il_vm_event_add(RzILVM *vm, RzILEvent *evt)
Definition: il_vm_eval.c:201
RZ_API bool rz_il_vm_init(RzILVM *vm, ut64 start_addr, ut32 addr_size, bool big_endian)
Definition: il_vm.c:27
RZ_API RZ_BORROW RzILVar * rz_il_vm_get_var(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:251
RZ_API ut32 rz_il_vm_get_pc_len(RzILVM *vm)
Definition: il_vm.c:145
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
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
RZ_API void rz_il_vm_add_label(RZ_NONNULL RzILVM *vm, RZ_NONNULL RzILEffectLabel *label)
Definition: il_vm.c:296
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
RzILTypePure
Definition: sort.h:23
structure for bitvector
Definition: rz_bitvector.h:19
Definition: dis.h:35
Definition: z80asm.h:102
A single memory as part of the RzIL VM.
Definition: mem.h:26
An IL op performing a pure computation, 'a pure.
Holds a set of variable definitions and their current contents This is meant only as a low-level cont...
Definition: variable.h:31
Definition of a variable inside the vm.
Definition: variable.h:19
Low-level VM to execute raw IL code.
Definition: rz_il_vm.h:37
RzILOpPureHandler * op_handler_pure_table
Array of Handler, handler can be indexed by opcode.
Definition: rz_il_vm.h:47
RzILVarSet local_vars
All local variables, created by local set ops.
Definition: rz_il_vm.h:39
ut32 lab_count
count for VM predefined things
Definition: rz_il_vm.h:42
RzList * events
List of events that has happened in the last step.
Definition: rz_il_vm.h:49
ut32 addr_size
size of address space
Definition: rz_il_vm.h:43
bool big_endian
Sets the endianness of the memory reads/writes operations.
Definition: rz_il_vm.h:50
ut32 val_count
Definition: rz_il_vm.h:42
RzILVarSet local_pure_vars
All local variables, during execution temporarily bound by let, only usable in pure expressions and i...
Definition: rz_il_vm.h:40
RzILVarSet global_vars
All global variables (usually bound to registers)
Definition: rz_il_vm.h:38
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
RzPVector vm_memory
Memories available in the VM, by their index. May be sparse (contain NULLs).
Definition: rz_il_vm.h:41
HtPP * vm_global_label_table
Hashtable to maintain the label and address.
Definition: rz_il_vm.h:44
HtPP * vm_local_label_table
Hashtable to maintain the label and address.
Definition: rz_il_vm.h:45
RzILOpEffectHandler * op_handler_effect_table
Array of Handler, handler can be indexed by opcode.
Definition: rz_il_vm.h:48
#define bool
Definition: sysdefs.h:146
Definition: dis.c:32
RzILVarKind
Definition: variable.h:46
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58