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

Go to the source code of this file.

Functions

RZ_API RzAnalysisValuerz_analysis_value_new (void)
 
RZ_API RzAnalysisValuerz_analysis_value_new_from_string (const char *str)
 
RZ_API RzAnalysisValuerz_analysis_value_copy (RzAnalysisValue *ov)
 
RZ_API void rz_analysis_value_free (RzAnalysisValue *value)
 
RZ_API ut64 rz_analysis_value_to_ut64 (RzAnalysis *analysis, RzAnalysisValue *val)
 
RZ_API int rz_analysis_value_set_ut64 (RzAnalysis *analysis, RzAnalysisValue *val, ut64 num)
 
RZ_API char * rz_analysis_value_to_string (RzAnalysisValue *value)
 

Function Documentation

◆ rz_analysis_value_copy()

RZ_API RzAnalysisValue* rz_analysis_value_copy ( RzAnalysisValue ov)

Definition at line 15 of file value.c.

15  {
17 
19  if (!v) {
20  return NULL;
21  }
22 
23  memcpy(v, ov, sizeof(RzAnalysisValue));
24  // reference to reg and regdelta should be kept
25  return v;
26 }
#define NULL
Definition: cris-opc.c:27
const char * v
Definition: dsignal.c:12
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_NEW0(x)
Definition: rz_types.h:284

References memcpy(), NULL, RZ_NEW0, rz_return_val_if_fail, and v.

Referenced by rz_analysis_op_copy().

◆ rz_analysis_value_free()

RZ_API void rz_analysis_value_free ( RzAnalysisValue value)

Definition at line 29 of file value.c.

29  {
30  free(value);
31 #if 0
32  ut64 pval = (ut64)(size_t)value;
33  if (pval && pval != UT64_MAX) {
34  /* TODO: free RzRegItem objects? */
35  free (value);
36  }
37 #endif
38 }
static int value
Definition: cmd_api.c:93
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define UT64_MAX
Definition: rz_types_base.h:86
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References free(), ut64(), UT64_MAX, and value.

Referenced by rz_analysis_cond_fini(), rz_analysis_op_copy(), rz_analysis_op_fini(), and set_access_info().

◆ rz_analysis_value_new()

◆ rz_analysis_value_new_from_string()

RZ_API RzAnalysisValue* rz_analysis_value_new_from_string ( const char *  str)

Definition at line 10 of file value.c.

10  {
11  /* TODO */
12  return NULL;
13 }

References NULL.

◆ rz_analysis_value_set_ut64()

RZ_API int rz_analysis_value_set_ut64 ( RzAnalysis analysis,
RzAnalysisValue val,
ut64  num 
)

Definition at line 65 of file value.c.

65  {
66  if (val->memref) {
67  if (analysis->iob.io) {
68  ut8 data[8];
70  rz_mem_set_num(data, val->memref, num);
71  analysis->iob.write_at(analysis->iob.io, addr, data, val->memref);
72  } else {
73  RZ_LOG_ERROR("No IO binded to rz_analysis\n");
74  }
75  } else {
76  if (val->reg) {
77  rz_reg_set_value(analysis->reg, val->reg, num);
78  }
79  }
80  return false; // is this necessary
81 }
RZ_API ut64 rz_analysis_value_to_ut64(RzAnalysis *analysis, RzAnalysisValue *val)
Definition: value.c:41
ut16 val
Definition: armass64_const.h:6
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API int rz_mem_set_num(ut8 *dest, int dest_size, ut64 num)
Definition: mem.c:168
RzIOBind iob
Definition: rz_analysis.h:574
RzIOWriteAt write_at
Definition: rz_io.h:241
RzIO * io
Definition: rz_io.h:232
static int addr
Definition: z80asm.c:58

References addr, rz_io_bind_t::io, rz_analysis_t::iob, num, rz_analysis_t::reg, rz_analysis_value_to_ut64(), RZ_LOG_ERROR, rz_mem_set_num(), rz_reg_set_value(), ut64(), val, and rz_io_bind_t::write_at.

◆ rz_analysis_value_to_string()

RZ_API char* rz_analysis_value_to_string ( RzAnalysisValue value)

Definition at line 83 of file value.c.

83  {
84  char *out = NULL;
85  if (value) {
86  out = rz_str_new("");
87  if (!value->base && !value->reg) {
88  if (value->imm != -1LL) {
89  out = rz_str_appendf(out, "0x%" PFMT64x, value->imm);
90  } else {
91  out = rz_str_append(out, "-1");
92  }
93  } else {
94  if (value->memref) {
95  switch (value->memref) {
96  case 1: out = rz_str_append(out, "(char)"); break;
97  case 2: out = rz_str_append(out, "(short)"); break;
98  case 4: out = rz_str_append(out, "(word)"); break;
99  case 8: out = rz_str_append(out, "(dword)"); break;
100  }
101  out = rz_str_append(out, "[");
102  }
103  if (value->mul) {
104  out = rz_str_appendf(out, "%d*", value->mul);
105  }
106  if (value->reg) {
107  out = rz_str_appendf(out, "%s", value->reg->name);
108  }
109  if (value->regdelta) {
110  out = rz_str_appendf(out, "+%s", value->regdelta->name);
111  }
112  if (value->base != 0) {
113  out = rz_str_appendf(out, "0x%" PFMT64x, value->base);
114  }
115  if (value->delta > 0) {
116  out = rz_str_appendf(out, "+0x%" PFMT64x, value->delta);
117  } else if (value->delta < 0) {
118  out = rz_str_appendf(out, "-0x%" PFMT64x, -value->delta);
119  }
120  if (value->memref) {
121  out = rz_str_append(out, "]");
122  }
123  }
124  }
125  return out;
126 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
#define PFMT64x
Definition: rz_types.h:393

References NULL, out, PFMT64x, rz_str_append(), rz_str_appendf(), rz_str_new(), and value.

Referenced by rz_analysis_cond_to_string(), and rz_analysis_op_to_string().

◆ rz_analysis_value_to_ut64()

RZ_API ut64 rz_analysis_value_to_ut64 ( RzAnalysis analysis,
RzAnalysisValue val 
)

Definition at line 41 of file value.c.

41  {
42  ut64 num;
43  if (!val) {
44  return 0LL;
45  }
46  num = val->base + (val->delta * (val->mul ? val->mul : 1));
47  if (val->reg) {
48  num += rz_reg_get_value(analysis->reg, val->reg);
49  }
50  if (val->regdelta) {
51  num += rz_reg_get_value(analysis->reg, val->regdelta);
52  }
53  switch (val->memref) {
54  case 1:
55  case 2:
56  case 4:
57  case 8:
58  // analysis->bio ...
59  RZ_LOG_DEBUG("memref for to_ut64 not supported\n");
60  break;
61  }
62  return num;
63 }
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49

References num, rz_analysis_t::reg, RZ_LOG_DEBUG, rz_reg_get_value(), ut64(), and val.

Referenced by rz_analysis_cond_eval(), and rz_analysis_value_set_ut64().