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

Go to the source code of this file.

Classes

struct  list_addr
 

Functions

RZ_API RZ_OWN RzAnalysisVarGlobalrz_analysis_var_global_new (RZ_NONNULL const char *name, ut64 addr)
 Create a new instance of global variable. More...
 
int global_var_node_cmp (const void *incoming, const RBNode *in_tree, void *user)
 
RZ_API RZ_OWN bool rz_analysis_var_global_add (RzAnalysis *analysis, RZ_NONNULL RzAnalysisVarGlobal *global_var)
 Add the global variable into hashtable. More...
 
RZ_API void rz_analysis_var_global_free (RzAnalysisVarGlobal *glob)
 Free the global variable instance. More...
 
RZ_API RZ_NULLABLE RzFlagItemrz_analysis_var_global_get_flag_item (RzAnalysisVarGlobal *glob)
 Get the flag item corresponding to the given variable. More...
 
RZ_API bool rz_analysis_var_global_delete (RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisVarGlobal *glob)
 Delete and free the global variable. More...
 
RZ_API bool rz_analysis_var_global_delete_byname (RzAnalysis *analysis, RZ_NONNULL const char *name)
 Delete and free the global variable by its name. More...
 
RZ_API bool rz_analysis_var_global_delete_byaddr_at (RzAnalysis *analysis, ut64 addr)
 Same as rz_analysis_var_global_delete_byname at the address. More...
 
RZ_API bool rz_analysis_var_global_delete_byaddr_in (RzAnalysis *analysis, ut64 addr)
 Same as rz_analysis_var_global_delete_byname in the address. More...
 
RZ_API RZ_BORROW RzAnalysisVarGlobalrz_analysis_var_global_get_byname (RzAnalysis *analysis, RZ_NONNULL const char *name)
 Get the instance of global variable by its name. More...
 
RZ_API RZ_BORROW RzAnalysisVarGlobalrz_analysis_var_global_get_byaddr_at (RzAnalysis *analysis, ut64 addr)
 Get the instance of global variable at the address. More...
 
RZ_API RZ_BORROW RzAnalysisVarGlobalrz_analysis_var_global_get_byaddr_in (RzAnalysis *analysis, ut64 addr)
 Get the instance of global variable contains the address. More...
 
static bool global_var_collect_cb (void *user, const void *k, const void *v)
 
RZ_API RZ_OWN RzListrz_analysis_var_global_get_all (RzAnalysis *analysis)
 Get all of the added global variables. More...
 
RZ_API bool rz_analysis_var_global_rename (RzAnalysis *analysis, RZ_NONNULL const char *old_name, RZ_NONNULL const char *newname)
 Rename the global variable. More...
 
RZ_API void rz_analysis_var_global_set_type (RzAnalysisVarGlobal *glob, RZ_NONNULL RZ_BORROW RzType *type)
 Set the type of the global variable. More...
 
RZ_API void rz_analysis_var_global_add_constraint (RzAnalysisVarGlobal *glob, RzTypeConstraint *constraint)
 Add a constaint to global variable. More...
 
RZ_API RZ_OWN char * rz_analysis_var_global_get_constraints_readable (RzAnalysisVarGlobal *glob)
 Get the pritable string of global variable constraints. More...
 

Function Documentation

◆ global_var_collect_cb()

static bool global_var_collect_cb ( void *  user,
const void *  k,
const void *  v 
)
static

Definition at line 246 of file var_global.c.

246  {
247  RzList *l = user;
249  rz_list_append(l, glob);
250  return true;
251 }
const char * v
Definition: dsignal.c:12
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
Global variables.
Definition: rz_analysis.h:744

References rz_list_append(), and v.

Referenced by rz_analysis_var_global_get_all().

◆ global_var_node_cmp()

int global_var_node_cmp ( const void *  incoming,
const RBNode in_tree,
void *  user 
)

Definition at line 28 of file var_global.c.

28  {
29  ut64 ia = *(ut64 *)incoming;
30  ut64 ta = container_of(in_tree, const RzAnalysisVarGlobal, rb)->addr;
31  if (ia < ta) {
32  return -1;
33  } else if (ia > ta) {
34  return 1;
35  }
36  return 0;
37 }
#define container_of(ptr, type, member)
Definition: rz_types.h:650
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References container_of, and ut64().

Referenced by rz_analysis_var_global_add(), rz_analysis_var_global_delete(), rz_analysis_var_global_get_byaddr_at(), and rz_analysis_var_global_get_byaddr_in().

◆ rz_analysis_var_global_add()

RZ_API RZ_OWN bool rz_analysis_var_global_add ( RzAnalysis analysis,
RZ_NONNULL RzAnalysisVarGlobal global_var 
)

Add the global variable into hashtable.

Parameters
analysisRzAnalysis
global_varGlobal variable instance
Returns
true if succeed

Definition at line 46 of file var_global.c.

46  {
47  rz_return_val_if_fail(analysis && global_var, false);
48 
49  RzAnalysisVarGlobal *existing_glob = NULL;
50  if ((existing_glob = rz_analysis_var_global_get_byaddr_in(analysis, global_var->addr))) {
51  RZ_LOG_ERROR("Global variable %s at 0x%" PFMT64x " already exists!\n", existing_glob->name, existing_glob->addr);
52  return false;
53  }
54  if ((existing_glob = rz_analysis_var_global_get_byname(analysis, global_var->name))) {
55  RZ_LOG_ERROR("Global variable %s at 0x%" PFMT64x " already exists!\n", existing_glob->name, existing_glob->addr);
56  return false;
57  }
58  if (!ht_pp_insert(analysis->ht_global_var, global_var->name, global_var)) {
59  return false;
60  }
61  if (!rz_rbtree_aug_insert(&analysis->global_var_tree, &global_var->addr, &global_var->rb, global_var_node_cmp, NULL, NULL)) {
62  return false;
63  }
64 
65  global_var->analysis = analysis;
66  rz_flag_space_push(global_var->analysis->flb.f, "globals");
67  rz_flag_set(global_var->analysis->flb.f, global_var->name, global_var->addr, rz_type_db_get_bitsize(global_var->analysis->typedb, global_var->type) / 8);
68  rz_flag_space_pop(global_var->analysis->flb.f);
69 
70  return true;
71 }
#define NULL
Definition: cris-opc.c:27
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum)
Returns true if the node was inserted successfully.
Definition: rbtree.c:163
#define PFMT64x
Definition: rz_types.h:393
HtPP * ht_global_var
Definition: rz_analysis.h:624
RBTree global_var_tree
Definition: rz_analysis.h:625
ut64 addr
address of the global variable
Definition: rz_analysis.h:747
char * name
name of the variable
Definition: rz_analysis.h:746
RZ_API ut64 rz_type_db_get_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Returns the type size in bits (target dependent)
Definition: type.c:779
RZ_API RZ_BORROW RzAnalysisVarGlobal * rz_analysis_var_global_get_byname(RzAnalysis *analysis, RZ_NONNULL const char *name)
Get the instance of global variable by its name.
Definition: var_global.c:190
int global_var_node_cmp(const void *incoming, const RBNode *in_tree, void *user)
Definition: var_global.c:28
RZ_API RZ_BORROW RzAnalysisVarGlobal * rz_analysis_var_global_get_byaddr_in(RzAnalysis *analysis, ut64 addr)
Get the instance of global variable contains the address.
Definition: var_global.c:228

References rz_analysis_var_global_t::addr, global_var_node_cmp(), rz_analysis_t::global_var_tree, rz_analysis_t::ht_global_var, rz_analysis_var_global_t::name, NULL, PFMT64x, rz_analysis_var_global_get_byaddr_in(), rz_analysis_var_global_get_byname(), rz_flag_set(), RZ_LOG_ERROR, rz_rbtree_aug_insert(), rz_return_val_if_fail, and rz_type_db_get_bitsize().

Referenced by rz_analysis_global_variable_add_handler().

◆ rz_analysis_var_global_add_constraint()

RZ_API void rz_analysis_var_global_add_constraint ( RzAnalysisVarGlobal glob,
RzTypeConstraint constraint 
)

Add a constaint to global variable.

Parameters
globGlobal variable instance
constraintRzTypeConstraint
Returns
void

Definition at line 320 of file var_global.c.

320  {
321  rz_return_if_fail(glob && constraint);
322  rz_vector_push(&glob->constraints, constraint);
323 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197

References rz_analysis_var_global_t::constraints, rz_return_if_fail, and rz_vector_push().

◆ rz_analysis_var_global_delete()

RZ_API bool rz_analysis_var_global_delete ( RZ_NONNULL RzAnalysis analysis,
RZ_NONNULL RzAnalysisVarGlobal glob 
)

Delete and free the global variable.

Parameters
analysisRzAnalysis
globglobal variable to be deleted
Returns
true if succeed

Definition at line 121 of file var_global.c.

121  {
122  rz_return_val_if_fail(analysis && glob, false);
123 
124  // We need to delete RBTree first because ht_pp_delete will free its member
125  bool deleted = rz_rbtree_delete(&analysis->global_var_tree, &glob->addr, global_var_node_cmp, NULL, NULL, NULL);
126  return deleted ? ht_pp_delete(analysis->ht_global_var, glob->name) : deleted;
127 }
RZ_API bool rz_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user)
Returns true if a node with an equal key is deleted.
Definition: rbtree.c:263

References global_var_node_cmp(), NULL, rz_rbtree_delete(), and rz_return_val_if_fail.

Referenced by rz_analysis_var_global_delete_byaddr_at(), rz_analysis_var_global_delete_byaddr_in(), and rz_analysis_var_global_delete_byname().

◆ rz_analysis_var_global_delete_byaddr_at()

RZ_API bool rz_analysis_var_global_delete_byaddr_at ( RzAnalysis analysis,
ut64  addr 
)

Same as rz_analysis_var_global_delete_byname at the address.

Parameters
analysisRzAnalysis
addrGlobal Variable address
Returns
true if succeed

Definition at line 154 of file var_global.c.

154  {
155  rz_return_val_if_fail(analysis, false);
157  if (!glob) {
158  RZ_LOG_ERROR("No global variable found at 0x%" PFMT64x "\n", addr);
159  return false;
160  }
161 
162  return rz_analysis_var_global_delete(analysis, glob);
163 }
RZ_API RZ_BORROW RzAnalysisVarGlobal * rz_analysis_var_global_get_byaddr_at(RzAnalysis *analysis, ut64 addr)
Get the instance of global variable at the address.
Definition: var_global.c:207
RZ_API bool rz_analysis_var_global_delete(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisVarGlobal *glob)
Delete and free the global variable.
Definition: var_global.c:121
static int addr
Definition: z80asm.c:58

References addr, PFMT64x, rz_analysis_var_global_delete(), rz_analysis_var_global_get_byaddr_at(), RZ_LOG_ERROR, and rz_return_val_if_fail.

◆ rz_analysis_var_global_delete_byaddr_in()

RZ_API bool rz_analysis_var_global_delete_byaddr_in ( RzAnalysis analysis,
ut64  addr 
)

Same as rz_analysis_var_global_delete_byname in the address.

Parameters
analysisRzAnalysis
addrGlobal Variable address
Returns
true if succeed

Definition at line 172 of file var_global.c.

172  {
173  rz_return_val_if_fail(analysis, false);
175  if (!glob) {
176  RZ_LOG_ERROR("No global variable found in 0x%" PFMT64x "\n", addr);
177  return false;
178  }
179 
180  return rz_analysis_var_global_delete(analysis, glob);
181 }

References addr, PFMT64x, rz_analysis_var_global_delete(), rz_analysis_var_global_get_byaddr_in(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by rz_analysis_global_variable_delete_byaddr_handler().

◆ rz_analysis_var_global_delete_byname()

RZ_API bool rz_analysis_var_global_delete_byname ( RzAnalysis analysis,
RZ_NONNULL const char *  name 
)

Delete and free the global variable by its name.

Parameters
analysisRzAnalysis
nameGlobal Variable name
Returns
true if succeed

Definition at line 136 of file var_global.c.

136  {
137  rz_return_val_if_fail(analysis && name, false);
139  if (!glob) {
140  RZ_LOG_ERROR("No global variable found having name %s\n", name);
141  return false;
142  }
143 
144  return rz_analysis_var_global_delete(analysis, glob);
145 }
Definition: z80asm.h:102

References rz_analysis_var_global_delete(), rz_analysis_var_global_get_byname(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by rz_analysis_global_variable_delete_byname_handler().

◆ rz_analysis_var_global_free()

RZ_API void rz_analysis_var_global_free ( RzAnalysisVarGlobal glob)

Free the global variable instance.

Parameters
globGlobal variable instance
Returns
void

Definition at line 79 of file var_global.c.

79  {
80  if (!glob) {
81  return;
82  }
84  if (flag) {
85  rz_flag_unset(glob->analysis->flb.f, flag);
86  }
87  RZ_FREE(glob->name);
88  rz_type_free(glob->type);
90  RZ_FREE(glob);
91 }
RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item)
Definition: flag.c:597
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61
RzFlagBind flb
Definition: rz_analysis.h:575
RZ_BORROW RzAnalysis * analysis
analysis pertaining to this global variable
Definition: rz_analysis.h:750
RzType * type
type of the variable
Definition: rz_analysis.h:748
RzFlag * f
Definition: rz_flag.h:78
RZ_API void rz_type_free(RZ_NULLABLE RzType *type)
Frees the RzType.
Definition: type.c:1273
RZ_API RZ_NULLABLE RzFlagItem * rz_analysis_var_global_get_flag_item(RzAnalysisVarGlobal *glob)
Get the flag item corresponding to the given variable.
Definition: var_global.c:101

References rz_analysis_var_global_t::analysis, rz_analysis_var_global_t::constraints, rz_flag_bind_t::f, rz_analysis_t::flb, rz_analysis_var_global_t::name, rz_analysis_var_global_get_flag_item(), rz_flag_unset(), RZ_FREE, rz_type_free(), rz_vector_fini(), and rz_analysis_var_global_t::type.

Referenced by global_kv_free(), and rz_analysis_global_variable_add_handler().

◆ rz_analysis_var_global_get_all()

RZ_API RZ_OWN RzList* rz_analysis_var_global_get_all ( RzAnalysis analysis)

Get all of the added global variables.

Parameters
analysisRzAnalysis
Returns
RzList *

Definition at line 259 of file var_global.c.

259  {
260  rz_return_val_if_fail(analysis, NULL);
261  RzList *globals = rz_list_new();
262  if (!globals) {
263  return NULL;
264  }
265  ht_pp_foreach(analysis->ht_global_var, global_var_collect_cb, globals);
266  return globals;
267 }
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
static bool global_var_collect_cb(void *user, const void *k, const void *v)
Definition: var_global.c:246

References global_var_collect_cb(), rz_analysis_t::ht_global_var, NULL, rz_list_new(), and rz_return_val_if_fail.

Referenced by autocmplt_cmd_arg_global_var(), and rz_analysis_var_global_list_show().

◆ rz_analysis_var_global_get_byaddr_at()

RZ_API RZ_BORROW RzAnalysisVarGlobal* rz_analysis_var_global_get_byaddr_at ( RzAnalysis analysis,
ut64  addr 
)

Get the instance of global variable at the address.

Parameters
analysisRzAnalysis
addrGlobal variable address
Returns
RzAnalysisVarGlobal *

Definition at line 207 of file var_global.c.

207  {
208  rz_return_val_if_fail(analysis, NULL);
209 
211  if (!node) {
212  return NULL;
213  }
215  if (!var) {
216  return NULL;
217  }
218  return var;
219 }
RZ_API RBNode * rz_rbtree_find(RBNode *root, void *data, RBComparator cmp, void *user)
Definition: rbtree.c:267

References addr, container_of, global_var_node_cmp(), rz_analysis_t::global_var_tree, NULL, rz_rbtree_find(), and rz_return_val_if_fail.

Referenced by rz_analysis_var_global_delete_byaddr_at().

◆ rz_analysis_var_global_get_byaddr_in()

RZ_API RZ_BORROW RzAnalysisVarGlobal* rz_analysis_var_global_get_byaddr_in ( RzAnalysis analysis,
ut64  addr 
)

Get the instance of global variable contains the address.

Parameters
analysisRzAnalysis
addrGlobal variable address
Returns
RzAnalysisVarGlobal *

Definition at line 228 of file var_global.c.

228  {
229  rz_return_val_if_fail(analysis, NULL);
230 
232  if (!node) {
233  return NULL;
234  }
236  if (!var) {
237  return NULL;
238  }
239  ut64 size = rz_type_db_get_bitsize(analysis->typedb, var->type) / 8;
240  if (addr >= var->addr + size) {
241  return NULL;
242  }
243  return var;
244 }
voidpf void uLong size
Definition: ioapi.h:138
RZ_API RBNode * rz_rbtree_upper_bound(RBNode *root, void *data, RBComparator cmp, void *user)
Definition: rbtree.c:313
RzTypeDB * typedb
Definition: rz_analysis.h:602

References addr, rz_analysis_var_global_t::addr, container_of, global_var_node_cmp(), rz_analysis_t::global_var_tree, NULL, rz_rbtree_upper_bound(), rz_return_val_if_fail, rz_type_db_get_bitsize(), rz_analysis_var_global_t::type, rz_analysis_t::typedb, and ut64().

Referenced by rz_analysis_var_global_add(), and rz_analysis_var_global_delete_byaddr_in().

◆ rz_analysis_var_global_get_byname()

RZ_API RZ_BORROW RzAnalysisVarGlobal* rz_analysis_var_global_get_byname ( RzAnalysis analysis,
RZ_NONNULL const char *  name 
)

Get the instance of global variable by its name.

Parameters
analysisRzAnalysis
nameGlobal variable name
Returns
RzAnalysisVarGlobal *

Definition at line 190 of file var_global.c.

190  {
191  rz_return_val_if_fail(analysis && name, NULL);
192  return (RzAnalysisVarGlobal *)ht_pp_find(analysis->ht_global_var, name, NULL);
193 }

References rz_analysis_t::ht_global_var, NULL, and rz_return_val_if_fail.

Referenced by rz_analysis_global_variable_retype_handler(), rz_analysis_var_global_add(), rz_analysis_var_global_delete_byname(), rz_analysis_var_global_list_show(), and rz_analysis_var_global_rename().

◆ rz_analysis_var_global_get_constraints_readable()

RZ_API RZ_OWN char* rz_analysis_var_global_get_constraints_readable ( RzAnalysisVarGlobal glob)

Get the pritable string of global variable constraints.

Parameters
globGlobal variable instance
Returns
char *

Definition at line 331 of file var_global.c.

331  {
332  size_t n = glob->constraints.len;
333  if (!n) {
334  return NULL;
335  }
336  bool low = false, high = false;
337  RzStrBuf sb;
338  rz_strbuf_init(&sb);
339  size_t i;
340  for (i = 0; i < n; i += 1) {
342  switch (constr->cond) {
343  case RZ_TYPE_COND_LE:
344  if (high) {
345  rz_strbuf_append(&sb, " && ");
346  }
347  rz_strbuf_appendf(&sb, "<= 0x%" PFMT64x "", constr->val);
348  low = true;
349  break;
350  case RZ_TYPE_COND_LT:
351  if (high) {
352  rz_strbuf_append(&sb, " && ");
353  }
354  rz_strbuf_appendf(&sb, "< 0x%" PFMT64x "", constr->val);
355  low = true;
356  break;
357  case RZ_TYPE_COND_GE:
358  rz_strbuf_appendf(&sb, ">= 0x%" PFMT64x "", constr->val);
359  high = true;
360  break;
361  case RZ_TYPE_COND_GT:
362  rz_strbuf_appendf(&sb, "> 0x%" PFMT64x "", constr->val);
363  high = true;
364  break;
365  default:
366  break;
367  }
368  if (low && high && i != n - 1) {
369  rz_strbuf_append(&sb, " || ");
370  low = false;
371  high = false;
372  }
373  }
374  return rz_strbuf_drain_nofree(&sb);
375 }
lzma_index ** i
Definition: index.h:629
static SblHeader sb
Definition: bin_mbn.c:26
int n
Definition: mipsasm.c:19
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
Definition: strbuf.c:349
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
@ RZ_TYPE_COND_LE
Less or equal.
Definition: rz_type.h:188
@ RZ_TYPE_COND_GE
Greater or equal.
Definition: rz_type.h:186
@ RZ_TYPE_COND_GT
Greater than.
Definition: rz_type.h:187
@ RZ_TYPE_COND_LT
Less than.
Definition: rz_type.h:189
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88
type constrained by the type conditions
Definition: rz_type.h:209
RzTypeCond cond
Definition: rz_type.h:210
size_t len
Definition: rz_vector.h:47

References rz_type_constraint_t::cond, rz_analysis_var_global_t::constraints, i, rz_vector_t::len, n, NULL, PFMT64x, rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain_nofree(), rz_strbuf_init(), RZ_TYPE_COND_GE, RZ_TYPE_COND_GT, RZ_TYPE_COND_LE, RZ_TYPE_COND_LT, rz_vector_index_ptr(), sb, and rz_type_constraint_t::val.

◆ rz_analysis_var_global_get_flag_item()

RZ_API RZ_NULLABLE RzFlagItem* rz_analysis_var_global_get_flag_item ( RzAnalysisVarGlobal glob)

Get the flag item corresponding to the given variable.

This will search for the matching flag that has been created along with the global variable. It can happen that the flag has manually been deleted, in which case this returns NULL.

Returns
a flag item or NULL

Definition at line 101 of file var_global.c.

101  {
103  RzAnalysis *a = glob->analysis;
104  if (!a) {
105  return NULL;
106  }
107  RzFlagItem *r = rz_flag_get(a->flb.f, glob->name);
108  if (r && r->offset != glob->addr) {
109  return NULL;
110  }
111  return r;
112 }
#define r
Definition: crypto_rc6.c:12
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
#define a(i)
Definition: sha256.c:41

References a, rz_analysis_var_global_t::addr, rz_analysis_var_global_t::analysis, rz_analysis_var_global_t::name, NULL, r, rz_flag_get(), and rz_return_val_if_fail.

Referenced by rz_analysis_var_global_free(), rz_analysis_var_global_rename(), and rz_analysis_var_global_set_type().

◆ rz_analysis_var_global_new()

RZ_API RZ_OWN RzAnalysisVarGlobal* rz_analysis_var_global_new ( RZ_NONNULL const char *  name,
ut64  addr 
)

Create a new instance of global variable.

Parameters
namevariable name
addrvariable address
commentvariable comment
Returns
RzAnalysisVarGlobal *

Definition at line 15 of file var_global.c.

15  {
18  if (!glob) {
19  return NULL;
20  }
21  glob->name = strdup(name);
22  glob->addr = addr;
23  glob->analysis = NULL;
24 
25  return glob;
26 }
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_NEW0(x)
Definition: rz_types.h:284

References addr, rz_analysis_var_global_t::addr, rz_analysis_var_global_t::analysis, rz_analysis_var_global_t::name, NULL, RZ_NEW0, rz_return_val_if_fail, and strdup().

Referenced by rz_analysis_global_variable_add_handler().

◆ rz_analysis_var_global_rename()

RZ_API bool rz_analysis_var_global_rename ( RzAnalysis analysis,
RZ_NONNULL const char *  old_name,
RZ_NONNULL const char *  newname 
)

Rename the global variable.

Parameters
analysisRzAnalysis
old_nameThe old name of the global variable
newnameThe new name of the global variable
Returns
true if succeed

Definition at line 277 of file var_global.c.

277  {
278  rz_return_val_if_fail(analysis && old_name && newname, false);
279  RzAnalysisVarGlobal *glob = rz_analysis_var_global_get_byname(analysis, old_name);
280  if (!glob) {
281  RZ_LOG_ERROR("Global variable '%s' does not exist!\n", old_name);
282  return false;
283  }
284 
286  if (flag) {
287  rz_flag_rename(analysis->flb.f, flag, newname);
288  }
289 
290  RZ_FREE(glob->name);
291  glob->name = strdup(newname);
292  return ht_pp_update_key(analysis->ht_global_var, old_name, newname);
293 }
RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name)
Definition: flag.c:587

References rz_flag_bind_t::f, rz_analysis_t::flb, rz_analysis_t::ht_global_var, rz_analysis_var_global_t::name, rz_analysis_var_global_get_byname(), rz_analysis_var_global_get_flag_item(), rz_flag_rename(), RZ_FREE, RZ_LOG_ERROR, rz_return_val_if_fail, and strdup().

Referenced by rz_analysis_global_variable_rename_handler().

◆ rz_analysis_var_global_set_type()

RZ_API void rz_analysis_var_global_set_type ( RzAnalysisVarGlobal glob,
RZ_NONNULL RZ_BORROW RzType type 
)

Set the type of the global variable.

Parameters
globGlobal variable instance
typeThe type to set. RzType*
Returns
void

Definition at line 302 of file var_global.c.

302  {
303  rz_return_if_fail(glob && type);
304  rz_type_free(glob->type);
305  glob->type = type;
306 
308  if (flag) {
309  flag->size = rz_type_db_get_bitsize(glob->analysis->typedb, glob->type) / 8;
310  }
311 }
int type
Definition: mipsasm.c:17

References rz_analysis_var_global_t::analysis, rz_analysis_var_global_get_flag_item(), rz_return_if_fail, rz_type_db_get_bitsize(), rz_type_free(), rz_flag_item_t::size, type, rz_analysis_var_global_t::type, and rz_analysis_t::typedb.

Referenced by rz_analysis_global_variable_add_handler(), and rz_analysis_global_variable_retype_handler().