Rizin
unix-like reverse engineering framework and cli tools
value.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2010-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_analysis.h>
5 
6 RZ_API RzAnalysisValue *rz_analysis_value_new(void) { // macro for this ?
7  return RZ_NEW0(RzAnalysisValue);
8 }
9 
11  /* TODO */
12  return NULL;
13 }
14 
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 }
27 
28 // TODO: move into .h as #define free
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 }
39 
40 // mul*value+regbase+regidx+delta
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 }
64 
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 }
82 
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 }
RZ_API char * rz_analysis_value_to_string(RzAnalysisValue *value)
Definition: value.c:83
RZ_API ut64 rz_analysis_value_to_ut64(RzAnalysis *analysis, RzAnalysisValue *val)
Definition: value.c:41
RZ_API int rz_analysis_value_set_ut64(RzAnalysis *analysis, RzAnalysisValue *val, ut64 num)
Definition: value.c:65
RZ_API void rz_analysis_value_free(RzAnalysisValue *value)
Definition: value.c:29
RZ_API RzAnalysisValue * rz_analysis_value_new_from_string(const char *str)
Definition: value.c:10
RZ_API RzAnalysisValue * rz_analysis_value_new(void)
Definition: value.c:6
RZ_API RzAnalysisValue * rz_analysis_value_copy(RzAnalysisValue *ov)
Definition: value.c:15
ut16 val
Definition: armass64_const.h:6
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static int value
Definition: cmd_api.c:93
#define RZ_API
#define NULL
Definition: cris-opc.c:27
const char * v
Definition: dsignal.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
#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
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 RZ_NEW0(x)
Definition: rz_types.h:284
#define PFMT64x
Definition: rz_types.h:393
#define UT64_MAX
Definition: rz_types_base.h:86
RzIOBind iob
Definition: rz_analysis.h:574
RzIOWriteAt write_at
Definition: rz_io.h:241
RzIO * io
Definition: rz_io.h:232
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58