Rizin
unix-like reverse engineering framework and cli tools
analysis_il_trace.c File Reference
#include <rz_analysis.h>

Go to the source code of this file.

Functions

static void htup_vector_free (HtUPKv *kv)
 
RZ_API RzAnalysisRzilTracerz_analysis_rzil_trace_new (RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *rzil)
 
RZ_API void rz_analysis_rzil_trace_free (RzAnalysisEsilTrace *trace)
 
RZ_API void rz_analysis_rzil_trace_op (RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *rzil, RZ_NONNULL RzAnalysisLiftedILOp op)
 

Function Documentation

◆ htup_vector_free()

static void htup_vector_free ( HtUPKv *  kv)
static

IL trace should also these info

  1. mem.read address & data
  2. mem.write address & data
  3. reg.read name & data
  4. reg.write name & data

Definition at line 14 of file analysis_il_trace.c.

14  {
15  rz_vector_free(kv->value);
16 }
RZ_API void rz_vector_free(RzVector *vec)
Definition: vector.c:75

References rz_vector_free().

Referenced by rz_analysis_rzil_trace_new().

◆ rz_analysis_rzil_trace_free()

RZ_API void rz_analysis_rzil_trace_free ( RzAnalysisEsilTrace trace)

Free an IL trace

Parameters
tracetrace to be free

Definition at line 74 of file analysis_il_trace.c.

74  {
75  size_t i;
76  if (!trace) {
77  return;
78  }
79 
80  ht_up_free(trace->registers);
81  ht_up_free(trace->memory);
82  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
83  rz_reg_arena_free(trace->arena[i]);
84  }
86  trace->instructions = NULL;
87  RZ_FREE(trace);
88 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_reg_arena_free(RzRegArena *ra)
Definition: arena.c:189
#define NULL
Definition: cris-opc.c:27
@ RZ_REG_TYPE_LAST
Definition: rz_reg.h:34
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
RzRegArena * arena[RZ_REG_TYPE_LAST]
Definition: rz_analysis.h:1017

References rz_analysis_esil_trace_t::arena, i, rz_analysis_esil_trace_t::instructions, rz_analysis_esil_trace_t::memory, NULL, rz_analysis_esil_trace_t::registers, RZ_FREE, rz_pvector_free(), rz_reg_arena_free(), and RZ_REG_TYPE_LAST.

◆ rz_analysis_rzil_trace_new()

RZ_API RzAnalysisRzilTrace* rz_analysis_rzil_trace_new ( RzAnalysis analysis,
RZ_NONNULL RzAnalysisILVM rzil 
)

Create a new trace to collect infos

Parameters
analysispointer to RzAnalysis
rzilRZ_IL instance
Returns
pointer to RzilTrace

Definition at line 24 of file analysis_il_trace.c.

24  {
26  size_t i;
28  if (!trace) {
29  return NULL;
30  }
31 
32  // TODO : maybe we could remove memory && register in rzil trace ?
33  trace->registers = ht_up_new(NULL, htup_vector_free, NULL);
34  if (!trace->registers) {
35  RZ_LOG_ERROR("rzil: Cannot allocate hasmap for trace registers\n");
36  goto error;
37  }
38  trace->memory = ht_up_new(NULL, htup_vector_free, NULL);
39  if (!trace->memory) {
40  RZ_LOG_ERROR("rzil: Cannot allocate hasmap for trace memory\n");
41  goto error;
42  }
44  if (!trace->instructions) {
45  RZ_LOG_ERROR("rzil: Cannot allocate vector for trace instructions\n");
46  goto error;
47  }
48 
49  // TODO : Integrate with stack panel in the future
50 
51  // Save initial registers arenas
52  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
53  RzRegArena *a = analysis->reg->regset[i].arena;
54  RzRegArena *b = rz_reg_arena_new(a->size);
55  if (!b) {
56  RZ_LOG_ERROR("rzil: Cannot allocate register arena for trace\n");
57  goto error;
58  }
59  if (b->bytes && a->bytes && b->size > 0) {
60  memcpy(b->bytes, a->bytes, b->size);
61  }
62  trace->arena[i] = b;
63  }
64  return trace;
65 error:
67  return NULL;
68 }
static void htup_vector_free(HtUPKv *kv)
RZ_API RzRegArena * rz_reg_arena_new(size_t size)
Definition: arena.c:170
RZ_API void rz_analysis_esil_trace_free(RzAnalysisEsilTrace *trace)
Definition: esil_trace.c:79
RZ_API void rz_analysis_il_trace_instruction_free(RzILTraceInstruction *instruction)
Definition: il_trace.c:53
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
RzRegArena * arena
Definition: rz_reg.h:136
RzRegSet regset[RZ_REG_TYPE_LAST]
Definition: rz_reg.h:150
void error(const char *msg)
Definition: untgz.c:593

References a, rz_analysis_esil_trace_t::arena, rz_reg_set_t::arena, b, error(), htup_vector_free(), i, rz_analysis_esil_trace_t::instructions, memcpy(), rz_analysis_esil_trace_t::memory, NULL, rz_analysis_t::reg, rz_analysis_esil_trace_t::registers, rz_reg_t::regset, rz_analysis_esil_trace_free(), rz_analysis_il_trace_instruction_free(), RZ_LOG_ERROR, RZ_NEW0, rz_pvector_new(), rz_reg_arena_new(), RZ_REG_TYPE_LAST, and rz_return_val_if_fail.

◆ rz_analysis_rzil_trace_op()

RZ_API void rz_analysis_rzil_trace_op ( RzAnalysis analysis,
RZ_NONNULL RzAnalysisILVM rzil,
RZ_NONNULL RzAnalysisLiftedILOp  op 
)

This function should be called after executing the IL op Collect trace info (target and data of mem/reg read/write)

Parameters
analysisRzAnalysis
rzilIL instance
opRzAnalysisRzilOp, a general IL op structure (Designed for switching between different implementations of IL op struct)

Definition at line 97 of file analysis_il_trace.c.

97  {
98  // TODO : rewrite this file when migrate to new op structure
99 }