Rizin
unix-like reverse engineering framework and cli tools
il_events.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
2 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_il/rz_il_events.h>
6 
12  if (!evt) {
13  return;
14  }
15  switch (evt->type) {
17  free(evt->data.exception);
18  break;
20  rz_bv_free(evt->data.pc_write.old_pc);
21  rz_bv_free(evt->data.pc_write.new_pc);
22  break;
24  rz_bv_free(evt->data.mem_read.address);
25  rz_bv_free(evt->data.mem_read.value);
26  break;
28  free(evt->data.var_read.variable);
29  rz_il_value_free(evt->data.var_read.value);
30  break;
32  rz_bv_free(evt->data.mem_write.address);
33  rz_bv_free(evt->data.mem_write.old_value);
34  rz_bv_free(evt->data.mem_write.new_value);
35  break;
37  free(evt->data.var_write.variable);
38  rz_il_value_free(evt->data.var_write.old_value);
39  rz_il_value_free(evt->data.var_write.new_value);
40  break;
41  default:
43  break;
44  }
45  free(evt);
46 }
47 
54 
55  RzILEvent *evt = RZ_NEW(RzILEvent);
56  if (!evt) {
57  RZ_LOG_ERROR("RzIL: cannot allocate exception RzILEvent");
58  return NULL;
59  }
60 
63  if (!evt->data.exception) {
64  rz_il_event_free(evt);
65  RZ_LOG_ERROR("RzIL: cannot allocate exception string");
66  return NULL;
67  }
68  return evt;
69 }
70 
77  rz_return_val_if_fail(old_pc && new_pc, NULL);
78 
79  RzILEvent *evt = RZ_NEW(RzILEvent);
80  if (!evt) {
81  return NULL;
82  }
83 
85  evt->data.pc_write.old_pc = rz_bv_dup(old_pc);
86  evt->data.pc_write.new_pc = rz_bv_dup(new_pc);
87  if (!evt->data.pc_write.old_pc || !evt->data.pc_write.new_pc) {
88  rz_il_event_free(evt);
89  return NULL;
90  }
91 
92  return evt;
93 }
94 
101  rz_return_val_if_fail(address && value, NULL);
102 
103  RzILEvent *evt = RZ_NEW(RzILEvent);
104  if (!evt) {
105  return NULL;
106  }
107 
108  evt->type = RZ_IL_EVENT_MEM_READ;
109  evt->data.mem_read.address = rz_bv_dup(address);
111  if (!evt->data.mem_read.address || !evt->data.mem_read.value) {
112  rz_il_event_free(evt);
113  return NULL;
114  }
115 
116  return evt;
117 }
118 
126  rz_return_val_if_fail(addr && old_v && new_v, NULL);
127 
128  RzILEvent *evt = RZ_NEW(RzILEvent);
129  if (!evt) {
130  return NULL;
131  }
132 
135  evt->data.mem_write.old_value = rz_bv_dup(old_v);
136  evt->data.mem_write.new_value = rz_bv_dup(new_v);
137  if (!evt->data.mem_write.address ||
138  !evt->data.mem_write.old_value ||
139  !evt->data.mem_write.new_value) {
140  rz_il_event_free(evt);
141  return NULL;
142  }
143 
144  return evt;
145 }
146 
154 
155  RzILEvent *evt = RZ_NEW(RzILEvent);
156  if (!evt) {
157  return NULL;
158  }
159 
160  evt->type = RZ_IL_EVENT_VAR_READ;
161  evt->data.var_read.variable = strdup(name);
163  if (!evt->data.var_read.variable || !evt->data.var_read.value) {
164  rz_il_event_free(evt);
165  return NULL;
166  }
167 
168  return evt;
169 }
170 
178  rz_return_val_if_fail(name && old_v && new_v, NULL);
179 
180  RzILEvent *evt = RZ_NEW(RzILEvent);
181  if (!evt) {
182  return NULL;
183  }
184 
187  evt->data.var_write.old_value = rz_il_value_dup(old_v);
188  evt->data.var_write.new_value = rz_il_value_dup(new_v);
189  if (!evt->data.var_write.variable ||
190  !evt->data.var_write.old_value ||
191  !evt->data.var_write.new_value) {
192  rz_il_event_free(evt);
193  return NULL;
194  }
195 
196  return evt;
197 }
@ exception
Definition: aarch64.h:495
static int value
Definition: cmd_api.c:93
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzILVal * rz_il_value_dup(RZ_NONNULL const RzILVal *val)
Definition: value.c:85
RZ_API void rz_il_value_free(RZ_NULLABLE RzILVal *val)
Definition: value.c:107
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_event_free(RZ_NULLABLE RzILEvent *evt)
Definition: il_events.c:11
RZ_API RZ_OWN RzILEvent * rz_il_event_var_write_new(RZ_NONNULL const char *name, RZ_NULLABLE const RzILVal *old_v, RZ_NONNULL const RzILVal *new_v)
Definition: il_events.c:177
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
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 RZ_OWN RzILEvent * rz_il_event_exception_new(RZ_NONNULL const char *exception)
Definition: il_events.c:52
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
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
list of types of events that can happen on the VM
@ RZ_IL_EVENT_VAR_READ
Definition: rz_il_events.h:23
@ RZ_IL_EVENT_MEM_READ
Definition: rz_il_events.h:22
@ RZ_IL_EVENT_MEM_WRITE
Definition: rz_il_events.h:24
@ RZ_IL_EVENT_EXCEPTION
Definition: rz_il_events.h:20
@ RZ_IL_EVENT_VAR_WRITE
Definition: rz_il_events.h:25
@ RZ_IL_EVENT_PC_WRITE
Definition: rz_il_events.h:21
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_NEW(x)
Definition: rz_types.h:285
structure for bitvector
Definition: rz_bitvector.h:19
Definition: z80asm.h:102
RZ_NONNULL RzBitVector * value
Definition: rz_il_events.h:30
RZ_NONNULL RzBitVector * address
Definition: rz_il_events.h:29
RZ_NONNULL RzBitVector * old_value
Definition: rz_il_events.h:45
RZ_NONNULL RzBitVector * address
Definition: rz_il_events.h:44
RZ_NONNULL RzBitVector * new_value
Definition: rz_il_events.h:46
RzILEventMemWrite mem_write
Definition: rz_il_events.h:61
RzILEventId type
Definition: rz_il_events.h:56
RzILEventVarWrite var_write
Definition: rz_il_events.h:63
union rz_il_vm_event_t::@285 data
RzILEventMemRead mem_read
Definition: rz_il_events.h:60
RzILEventVarRead var_read
Definition: rz_il_events.h:62
RzILEventPCWrite pc_write
Definition: rz_il_events.h:59
RZ_NONNULL char * variable
Definition: rz_il_events.h:34
RZ_NONNULL RzILVal * value
Definition: rz_il_events.h:35
RZ_NONNULL RzILVal * new_value
Definition: rz_il_events.h:52
RZ_NONNULL RzILVal * old_value
Definition: rz_il_events.h:51
RZ_NONNULL char * variable
Definition: rz_il_events.h:50
static int addr
Definition: z80asm.c:58