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

Go to the source code of this file.

Functions

static void rz_config_hold_char_free (RzConfigHoldChar *hc)
 
static void rz_config_hold_num_free (RzConfigHoldNum *hc)
 
static int key_cmp_hold_s (const void *a, const void *b)
 
static int key_cmp_hold_i (const void *a, const void *b)
 
RZ_API bool rz_config_hold_s (RzConfigHold *h,...)
 Save the current values of a list of config options that have string values. More...
 
RZ_API bool rz_config_hold_i (RzConfigHold *h,...)
 Save the current values of a list of config options that have integer values. More...
 
RZ_API RzConfigHoldrz_config_hold_new (RzConfig *cfg)
 Create an opaque object to save/restore some configuration options. More...
 
RZ_API void rz_config_hold_restore (RzConfigHold *h)
 Restore whatever config options were previously saved in h. More...
 
RZ_API void rz_config_hold_free (RzConfigHold *h)
 Free a RzConfigHold object h. More...
 

Function Documentation

◆ key_cmp_hold_i()

static int key_cmp_hold_i ( const void *  a,
const void *  b 
)
static

Definition at line 23 of file hold.c.

23  {
24  const char *a_s = (const char *)a;
25  const RzConfigHoldNum *b_s = (const RzConfigHoldNum *)b;
26  return strcmp(a_s, b_s->key);
27 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, b, and rz_config_hold_num_t::key.

Referenced by rz_config_hold_i().

◆ key_cmp_hold_s()

static int key_cmp_hold_s ( const void *  a,
const void *  b 
)
static

Definition at line 17 of file hold.c.

17  {
18  const char *a_s = (const char *)a;
19  const RzConfigHoldChar *b_s = (const RzConfigHoldChar *)b;
20  return strcmp(a_s, b_s->key);
21 }

References a, b, and rz_config_hold_char_t::key.

Referenced by rz_config_hold_s().

◆ rz_config_hold_char_free()

static void rz_config_hold_char_free ( RzConfigHoldChar hc)
static

Definition at line 6 of file hold.c.

6  {
7  free(hc->key);
8  free(hc->value);
9  free(hc);
10 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), rz_config_hold_char_t::key, and rz_config_hold_char_t::value.

Referenced by rz_config_hold_s().

◆ rz_config_hold_free()

RZ_API void rz_config_hold_free ( RzConfigHold h)

Free a RzConfigHold object h.

Parameters
hReference to RzConfigHold

Definition at line 152 of file hold.c.

152  {
153  if (h) {
154  rz_list_free(h->list_num);
155  rz_list_free(h->list_char);
156  RZ_FREE(h);
157  }
158 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define RZ_FREE(x)
Definition: rz_types.h:369
#define h(i)
Definition: sha256.c:48

References h, RZ_FREE, and rz_list_free().

Referenced by analysis_emul_restore(), cmd_analysis_graph(), core_analysis_graph_construct_nodes(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), ds_print_esil_analysis(), get_body(), graph_construct_nodes(), rz_analyze_cycles_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_print(), rz_core_analysis_graph(), rz_core_analysis_types_propagation(), rz_core_disasm_pde(), rz_core_print_bb_custom(), rz_core_print_disasm(), rz_core_visual_graph(), and rz_core_visual_toggle_decompiler_disasm().

◆ rz_config_hold_i()

RZ_API bool rz_config_hold_i ( RzConfigHold h,
  ... 
)

Save the current values of a list of config options that have integer values.

Get the current values of a list of config variables (terminated by NULL) and save them in the RzConfigHold object h . rz_config_get_i is used to retrieve the current config values.

Parameters
hReference to RzConfigHold instance
...List of config variables to save, terminated by NULL.
Returns
true if at least one variable is correctly saved, false otherwise

Definition at line 81 of file hold.c.

81  {
82  va_list ap;
83  char *key;
84  if (!h) {
85  return false;
86  }
87  if (!h->list_num) {
89  if (!h->list_num) {
90  return false;
91  }
92  }
93  va_start(ap, h);
94  while ((key = va_arg(ap, char *))) {
95  if (rz_list_find(h->list_num, key, key_cmp_hold_i)) {
96  continue;
97  }
99  if (!hc) {
100  continue;
101  }
102  hc->key = strdup(key);
103  hc->value = rz_config_get_i(h->cfg, key);
104  rz_list_append(h->list_num, hc);
105  }
106  va_end(ap);
107  return true;
108 }
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static void rz_config_hold_num_free(RzConfigHoldNum *hc)
Definition: hold.c:12
static int key_cmp_hold_i(const void *a, const void *b)
Definition: hold.c:23
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
Definition: list.c:620
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
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")
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284

References h, rz_config_hold_num_t::key, key, key_cmp_hold_i(), rz_config_get_i(), rz_config_hold_num_free(), rz_list_append(), rz_list_find(), rz_list_newf(), RZ_NEW0, strdup(), and rz_config_hold_num_t::value.

Referenced by analysis_emul_init(), cmd_analysis_graph(), core_analysis_graph_construct_nodes(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), ds_print_esil_analysis(), get_body(), graph_construct_nodes(), rz_analyze_cycles_handler(), rz_cmd_print(), rz_core_analysis_graph(), rz_core_analysis_types_propagation(), rz_core_disasm_pde(), rz_core_print_bb_custom(), rz_core_print_disasm(), and rz_core_visual_graph().

◆ rz_config_hold_new()

RZ_API RzConfigHold* rz_config_hold_new ( RzConfig cfg)

Create an opaque object to save/restore some configuration options.

Parameters
cfgRzConfig reference
Returns
RzConfigHold allocated object

Definition at line 116 of file hold.c.

116  {
117  if (cfg) {
119  if (hold) {
120  hold->cfg = cfg;
121  return hold;
122  }
123  }
124  return NULL;
125 }
#define NULL
Definition: cris-opc.c:27
RzConfig * cfg
Definition: rz_config.h:71

References rz_config_hold_t::cfg, NULL, and RZ_NEW0.

Referenced by cmd_analysis_graph(), core_analysis_graph_construct_nodes(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), ds_print_esil_analysis(), get_body(), graph_construct_nodes(), rz_analyze_cycles_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_print(), rz_core_analysis_graph(), rz_core_analysis_type_match(), rz_core_analysis_types_propagation(), rz_core_disasm_pde(), rz_core_print_bb_custom(), rz_core_print_disasm(), rz_core_visual_graph(), and rz_core_visual_toggle_decompiler_disasm().

◆ rz_config_hold_num_free()

static void rz_config_hold_num_free ( RzConfigHoldNum hc)
static

Definition at line 12 of file hold.c.

12  {
13  free(hc->key);
14  free(hc);
15 }

References free(), and rz_config_hold_num_t::key.

Referenced by rz_config_hold_i().

◆ rz_config_hold_restore()

RZ_API void rz_config_hold_restore ( RzConfigHold h)

Restore whatever config options were previously saved in h.

Parameters
hReference to RzConfigHold

Definition at line 132 of file hold.c.

132  {
133  RzListIter *iter;
134  RzConfigHoldChar *hchar;
135  RzConfigHoldNum *hnum;
136  if (h) {
137  RzConfig *cfg = h->cfg;
138  rz_list_foreach (h->list_num, iter, hnum) {
139  (void)rz_config_set_i(cfg, hnum->key, hnum->value);
140  }
141  rz_list_foreach (h->list_char, iter, hchar) {
142  (void)rz_config_set(cfg, hchar->key, hchar->value);
143  }
144  }
145 }
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419

References h, rz_config_hold_num_t::key, rz_config_hold_char_t::key, rz_config_set(), rz_config_set_i(), rz_config_hold_num_t::value, and rz_config_hold_char_t::value.

Referenced by analysis_emul_restore(), cmd_analysis_graph(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), ds_print_esil_analysis(), get_body(), graph_construct_nodes(), rz_analyze_cycles_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_print(), rz_core_analysis_graph(), rz_core_analysis_types_propagation(), rz_core_disasm_pde(), rz_core_print_bb_custom(), rz_core_print_disasm(), rz_core_visual_graph(), and rz_core_visual_toggle_decompiler_disasm().

◆ rz_config_hold_s()

RZ_API bool rz_config_hold_s ( RzConfigHold h,
  ... 
)

Save the current values of a list of config options that have string values.

Get the current values of a list of config variables (terminated by NULL) and save them in the RzConfigHold object h . rz_config_get is used to retrieve the current config values.

Parameters
hReference to RzConfigHold instance
...List of config variables to save, terminated by NULL.
Returns
true if at least one variable is correctly saved, false otherwise

Definition at line 40 of file hold.c.

40  {
41  va_list ap;
42  char *key;
43  va_start(ap, h);
44  if (!h->list_char) {
46  if (!h->list_char) {
47  va_end(ap);
48  return false;
49  }
50  }
51  while ((key = va_arg(ap, char *))) {
52  if (rz_list_find(h->list_char, key, key_cmp_hold_s)) {
53  continue;
54  }
55  const char *val = rz_config_get(h->cfg, key);
56  if (!val) {
57  continue;
58  }
60  if (hc) {
61  hc->key = strdup(key);
62  hc->value = strdup(val);
63  rz_list_append(h->list_char, hc);
64  }
65  }
66  va_end(ap);
67  return true;
68 }
ut16 val
Definition: armass64_const.h:6
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
static int key_cmp_hold_s(const void *a, const void *b)
Definition: hold.c:17
static void rz_config_hold_char_free(RzConfigHoldChar *hc)
Definition: hold.c:6

References h, rz_config_hold_char_t::key, key, key_cmp_hold_s(), rz_config_get(), rz_config_hold_char_free(), rz_list_append(), rz_list_find(), rz_list_newf(), RZ_NEW0, strdup(), val, and rz_config_hold_char_t::value.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_core_print_disasm(), and rz_core_visual_toggle_decompiler_disasm().