Rizin
unix-like reverse engineering framework and cli tools
il_events.c File Reference

Go to the source code of this file.

Functions

RZ_API void rz_il_event_free (RZ_NULLABLE RzILEvent *evt)
 
RZ_API RZ_OWN RzILEventrz_il_event_exception_new (RZ_NONNULL const char *exception)
 
RZ_API RZ_OWN RzILEventrz_il_event_pc_write_new (RZ_NONNULL const RzBitVector *old_pc, RZ_NONNULL const RzBitVector *new_pc)
 
RZ_API RZ_OWN RzILEventrz_il_event_mem_read_new (RZ_NONNULL const RzBitVector *address, RZ_NULLABLE const RzBitVector *value)
 
RZ_API RZ_OWN RzILEventrz_il_event_mem_write_new (RZ_NONNULL const RzBitVector *addr, RZ_NONNULL const RzBitVector *old_v, RZ_NONNULL const RzBitVector *new_v)
 
RZ_API RZ_OWN RzILEventrz_il_event_var_read_new (RZ_NONNULL const char *name, RZ_NULLABLE const RzILVal *value)
 
RZ_API RZ_OWN RzILEventrz_il_event_var_write_new (RZ_NONNULL const char *name, RZ_NULLABLE const RzILVal *old_v, RZ_NONNULL const RzILVal *new_v)
 

Function Documentation

◆ rz_il_event_exception_new()

RZ_API RZ_OWN RzILEvent* rz_il_event_exception_new ( RZ_NONNULL const char *  exception)

Creates an RzILEvent of type RZ_IL_EVENT_EXCEPTION

Parameters
exception,constchar, pointer to the exception message

Definition at line 52 of file il_events.c.

52  {
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 }
@ exception
Definition: aarch64.h:495
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_il_event_free(RZ_NULLABLE RzILEvent *evt)
Definition: il_events.c:11
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_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_IL_EVENT_EXCEPTION
Definition: rz_il_events.h:20
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NEW(x)
Definition: rz_types.h:285
RzILEventId type
Definition: rz_il_events.h:56
union rz_il_vm_event_t::@285 data

References rz_il_vm_event_t::data, exception, rz_il_vm_event_t::exception, NULL, RZ_IL_EVENT_EXCEPTION, rz_il_event_free(), RZ_LOG_ERROR, RZ_NEW, rz_return_val_if_fail, strdup(), and rz_il_vm_event_t::type.

Referenced by rz_il_handler_div().

◆ rz_il_event_free()

RZ_API void rz_il_event_free ( RZ_NULLABLE RzILEvent evt)

Frees an RzILEvent struct

Parameters
evt,RzILEvent,pointerto the RzILEvent to free

Definition at line 11 of file il_events.c.

11  {
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 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_il_value_free(RZ_NULLABLE RzILVal *val)
Definition: value.c:107
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
@ 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_VAR_WRITE
Definition: rz_il_events.h:25
@ RZ_IL_EVENT_PC_WRITE
Definition: rz_il_events.h:21

References free(), rz_bv_free(), RZ_IL_EVENT_EXCEPTION, RZ_IL_EVENT_MEM_READ, RZ_IL_EVENT_MEM_WRITE, RZ_IL_EVENT_PC_WRITE, RZ_IL_EVENT_VAR_READ, RZ_IL_EVENT_VAR_WRITE, rz_il_value_free(), and rz_warn_if_reached.

Referenced by rz_il_event_exception_new(), rz_il_event_mem_read_new(), rz_il_event_mem_write_new(), rz_il_event_pc_write_new(), rz_il_event_var_read_new(), rz_il_event_var_write_new(), rz_il_vm_event_add(), and rz_il_vm_init().

◆ rz_il_event_mem_read_new()

RZ_API RZ_OWN RzILEvent* rz_il_event_mem_read_new ( RZ_NONNULL const RzBitVector address,
RZ_NULLABLE const RzBitVector value 
)

Creates an RzILEvent of type RZ_IL_EVENT_MEM_READ

Parameters
addr,RzBitVector,addressof the memory where the read op has occurred
value,RzBitVector,valueread from the variable

Definition at line 100 of file il_events.c.

100  {
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 }
static int value
Definition: cmd_api.c:93
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
RZ_NONNULL RzBitVector * value
Definition: rz_il_events.h:30
RZ_NONNULL RzBitVector * address
Definition: rz_il_events.h:29
RzILEventMemRead mem_read
Definition: rz_il_events.h:60

References rz_il_vm_event_mem_read_t::address, rz_il_vm_event_t::data, rz_il_vm_event_t::mem_read, NULL, rz_bv_dup(), rz_il_event_free(), RZ_IL_EVENT_MEM_READ, RZ_NEW, rz_return_val_if_fail, rz_il_vm_event_t::type, value, and rz_il_vm_event_mem_read_t::value.

Referenced by rz_il_vm_mem_load(), and rz_il_vm_mem_loadw().

◆ rz_il_event_mem_write_new()

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 
)

Creates an RzILEvent of type RZ_IL_EVENT_MEM_WRITE

Parameters
addr,RzBitVector,addressof the memory that has changed
old_v,RzBitVector,oldvalue before the change
new_v,RzBitVector,newvalue after the change

Definition at line 125 of file il_events.c.

125  {
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 }
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
static int addr
Definition: z80asm.c:58

References addr, rz_il_vm_event_mem_write_t::address, rz_il_vm_event_t::data, rz_il_vm_event_t::mem_write, rz_il_vm_event_mem_write_t::new_value, NULL, rz_il_vm_event_mem_write_t::old_value, rz_bv_dup(), rz_il_event_free(), RZ_IL_EVENT_MEM_WRITE, RZ_NEW, rz_return_val_if_fail, and rz_il_vm_event_t::type.

Referenced by rz_il_vm_mem_store(), and rz_il_vm_mem_storew().

◆ rz_il_event_pc_write_new()

RZ_API RZ_OWN RzILEvent* rz_il_event_pc_write_new ( RZ_NONNULL const RzBitVector old_pc,
RZ_NONNULL const RzBitVector new_pc 
)

Creates an RzILEvent of type RZ_IL_EVENT_PC_WRITE

Parameters
old_pc,RzBitVector,oldprogram counter value before the change
new_pc,RzBitVector,newprogram counter value after the change

Definition at line 76 of file il_events.c.

76  {
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 }
RzILEventPCWrite pc_write
Definition: rz_il_events.h:59

References rz_il_vm_event_t::data, rz_il_vm_event_pc_write_t::new_pc, NULL, rz_il_vm_event_pc_write_t::old_pc, rz_il_vm_event_t::pc_write, rz_bv_dup(), rz_il_event_free(), RZ_IL_EVENT_PC_WRITE, RZ_NEW, rz_return_val_if_fail, and rz_il_vm_event_t::type.

Referenced by perform_jump(), and rz_il_vm_step().

◆ rz_il_event_var_read_new()

RZ_API RZ_OWN RzILEvent* rz_il_event_var_read_new ( RZ_NONNULL const char *  name,
RZ_NULLABLE const RzILVal value 
)

Creates an RzILEvent of type RZ_IL_EVENT_VAR_READ

Parameters
nameregister name that has changed
valuevalue read from the variable

Definition at line 152 of file il_events.c.

152  {
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 }
RZ_API RZ_OWN RzILVal * rz_il_value_dup(RZ_NONNULL const RzILVal *val)
Definition: value.c:85
Definition: z80asm.h:102
RzILEventVarRead var_read
Definition: rz_il_events.h:62
RZ_NONNULL char * variable
Definition: rz_il_events.h:34
RZ_NONNULL RzILVal * value
Definition: rz_il_events.h:35

References rz_il_vm_event_t::data, NULL, rz_il_event_free(), RZ_IL_EVENT_VAR_READ, rz_il_value_dup(), RZ_NEW, rz_return_val_if_fail, strdup(), rz_il_vm_event_t::type, value, rz_il_vm_event_var_read_t::value, rz_il_vm_event_t::var_read, and rz_il_vm_event_var_read_t::variable.

Referenced by rz_il_handler_var().

◆ rz_il_event_var_write_new()

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 
)

Creates an RzILEvent of type RZ_IL_EVENT_VAR_WRITE

Parameters
nameregister name that has changed
old_vold value before the change
new_vnew value after the change

Definition at line 177 of file il_events.c.

177  {
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 }
RzILEventVarWrite var_write
Definition: rz_il_events.h:63
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

References rz_il_vm_event_t::data, rz_il_vm_event_var_write_t::new_value, NULL, rz_il_vm_event_var_write_t::old_value, rz_il_event_free(), RZ_IL_EVENT_VAR_WRITE, rz_il_value_dup(), RZ_NEW, rz_return_val_if_fail, strdup(), rz_il_vm_event_t::type, rz_il_vm_event_t::var_write, and rz_il_vm_event_var_write_t::variable.

Referenced by il_event_new_write_from_var().