Rizin
unix-like reverse engineering framework and cli tools
flag.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2007-2020 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2007-2020 ret2libc <sirmy15@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_flag.h>
6 #include <rz_util.h>
7 #include <rz_cons.h>
8 #include <stdio.h>
9 
10 RZ_LIB_VERSION(rz_flag);
11 
12 #define IS_FI_NOTIN_SPACE(f, i) (rz_flag_space_cur(f) && (i)->space != rz_flag_space_cur(f))
13 #define IS_FI_IN_SPACE(fi, sp) (!(sp) || (fi)->space == (sp))
14 #define STRDUP_OR_NULL(s) (!RZ_STR_ISEMPTY(s) ? strdup(s) : NULL)
15 
16 static const char *str_callback(RzNum *user, ut64 off, int *ok) {
17  RzFlag *f = (RzFlag *)user;
18  if (ok) {
19  *ok = 0;
20  }
21  if (f) {
22  const RzList *list = rz_flag_get_list(f, off);
24  if (item) {
25  if (ok) {
26  *ok = true;
27  }
28  return item->name;
29  }
30  }
31  return NULL;
32 }
33 
34 static void flag_skiplist_free(void *data) {
35  RzFlagsAtOffset *item = (RzFlagsAtOffset *)data;
36  rz_list_free(item->flags);
37  free(data);
38 }
39 
40 static int flag_skiplist_cmp(const void *va, const void *vb) {
41  const RzFlagsAtOffset *a = (RzFlagsAtOffset *)va, *b = (RzFlagsAtOffset *)vb;
42  if (a->off == b->off) {
43  return 0;
44  }
45  return a->off < b->off ? -1 : 1;
46 }
47 
48 static ut64 num_callback(RzNum *user, const char *name, int *ok) {
49  RzFlag *f = (RzFlag *)user;
50  if (ok) {
51  *ok = 0;
52  }
53  RzFlagItem *item = ht_pp_find(f->ht_name, name, NULL);
54  if (item) {
55  // NOTE: to avoid warning infinite loop here we avoid recursivity
56  if (item->alias) {
57  return 0LL;
58  }
59  if (ok) {
60  *ok = 1;
61  }
62  return item->offset;
63  }
64  return 0LL;
65 }
66 
67 static void free_item_realname(RzFlagItem *item) {
68  if (item->name != item->realname) {
69  free(item->realname);
70  }
71 }
72 
73 static void free_item_name(RzFlagItem *item) {
74  if (item->name != item->realname) {
75  free(item->name);
76  }
77 }
78 
79 /* return the list of flag at the nearest position.
80  dir == -1 -> result <= off
81  dir == 0 -> result == off
82  dir == 1 -> result >= off*/
84  RzFlagsAtOffset key = { .off = off };
85  RzFlagsAtOffset *flags = (dir >= 0)
86  ? rz_skiplist_get_geq(f->by_off, &key)
87  : rz_skiplist_get_leq(f->by_off, &key);
88  return (dir == 0 && flags && flags->off != off) ? NULL : flags;
89 }
90 
91 static void remove_offsetmap(RzFlag *f, RzFlagItem *item) {
92  rz_return_if_fail(f && item);
94  if (flags) {
95  rz_list_delete_data(flags->flags, item);
96  if (rz_list_empty(flags->flags)) {
97  rz_skiplist_delete(f->by_off, flags);
98  }
99  }
100 }
101 
104  if (res) {
105  return res;
106  }
107 
108  // there is no existing flagsAtOffset, we create one now
109  res = RZ_NEW(RzFlagsAtOffset);
110  if (!res) {
111  return NULL;
112  }
113 
114  res->flags = rz_list_new();
115  if (!res->flags) {
116  free(res);
117  return NULL;
118  }
119 
120  res->off = off;
121  rz_skiplist_insert(f->by_off, res);
122  return res;
123 }
124 
125 static char *filter_item_name(const char *name) {
126  char *res = strdup(name);
127  if (!res) {
128  return NULL;
129  }
130 
131  rz_str_trim(res);
132  rz_name_filter(res, 0, true);
133  return res;
134 }
135 
136 static void set_name(RzFlagItem *item, char *name) {
137  free_item_name(item);
138  item->name = name;
139  free_item_realname(item);
140  item->realname = item->name;
141 }
142 
143 static bool update_flag_item_offset(RzFlag *f, RzFlagItem *item, ut64 newoff, bool is_new, bool force) {
144  if (item->offset != newoff || force) {
145  if (!is_new) {
146  remove_offsetmap(f, item);
147  }
148  item->offset = newoff;
149 
150  RzFlagsAtOffset *flagsAtOffset = flags_at_offset(f, newoff);
151  if (!flagsAtOffset) {
152  return false;
153  }
154 
155  rz_list_append(flagsAtOffset->flags, item);
156  return true;
157  }
158 
159  return false;
160 }
161 
162 static bool update_flag_item_name(RzFlag *f, RzFlagItem *item, const char *newname, bool force) {
163  if (!f || !item || !newname) {
164  return false;
165  }
166  if (!force && (item->name == newname || (item->name && !strcmp(item->name, newname)))) {
167  return false;
168  }
169  char *fname = filter_item_name(newname);
170  if (!fname) {
171  return false;
172  }
173  bool res = (item->name)
174  ? ht_pp_update_key(f->ht_name, item->name, fname)
175  : ht_pp_insert(f->ht_name, fname, item);
176  if (res) {
177  set_name(item, fname);
178  return true;
179  }
180  free(fname);
181  return false;
182 }
183 
184 static void ht_free_flag(HtPPKv *kv) {
185  free(kv->key);
186  rz_flag_item_free(kv->value);
187 }
188 
189 static bool count_flags(RzFlagItem *fi, void *user) {
190  int *count = (int *)user;
191  (*count)++;
192  return true;
193 }
194 
195 static bool unset_flags_space(RzFlagItem *fi, void *user) {
196  fi->space = NULL;
197  return true;
198 }
199 
200 static void count_flags_in_space(RzEvent *ev, int type, void *user, void *data) {
201  RzSpaces *sp = (RzSpaces *)ev->user;
203  RzSpaceEvent *spe = (RzSpaceEvent *)data;
204  rz_flag_foreach_space(f, spe->data.count.space, count_flags, &spe->res);
205 }
206 
207 static void unset_flagspace(RzEvent *ev, int type, void *user, void *data) {
208  RzSpaces *sp = (RzSpaces *)ev->user;
210  const RzSpaceEvent *spe = (const RzSpaceEvent *)data;
212 }
213 
214 static void new_spaces(RzFlag *f) {
215  rz_spaces_init(&f->spaces, "fs");
218 }
219 
221  RzFlag *f = RZ_NEW0(RzFlag);
222  if (!f) {
223  return NULL;
224  }
225  f->num = rz_num_new(&num_callback, &str_callback, f);
226  if (!f->num) {
227  rz_flag_free(f);
228  return NULL;
229  }
230  f->base = 0;
231  f->zones = NULL;
232  f->tags = sdb_new0();
233  f->ht_name = ht_pp_new(NULL, ht_free_flag, NULL);
235  rz_list_free(f->zones);
236  new_spaces(f);
237  return f;
238 }
239 
242 
244  if (!n) {
245  return NULL;
246  }
247  n->color = STRDUP_OR_NULL(item->color);
248  n->comment = STRDUP_OR_NULL(item->comment);
249  n->alias = STRDUP_OR_NULL(item->alias);
250  n->name = STRDUP_OR_NULL(item->name);
251  n->realname = STRDUP_OR_NULL(item->realname);
252  n->offset = item->offset;
253  n->size = item->size;
254  n->space = item->space;
255  return n;
256 }
257 
259  if (!item) {
260  return;
261  }
262  free(item->color);
263  free(item->comment);
264  free(item->alias);
265  /* release only one of the two pointers if they are the same */
266  free_item_name(item);
267  free(item->realname);
268  free(item);
269 }
270 
273  rz_skiplist_free(f->by_off);
274  ht_pp_free(f->ht_name);
275  sdb_free(f->tags);
276  rz_spaces_fini(&f->spaces);
277  rz_num_free(f->num);
278  rz_list_free(f->zones);
279  free(f);
280  return NULL;
281 }
282 
284  rz_return_val_if_fail(f && item, NULL);
285  if (item->alias) {
286  item->offset = rz_num_math(f->num, item->alias);
287  }
288  return item;
289 }
290 
291 /* return true if flag.* exist at offset. Otherwise, false is returned.
292  * For example (f, "sym", 3, 0x1000)*/
293 RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off) {
294  rz_return_val_if_fail(f && flag_prefix, false);
295  RzListIter *iter = NULL;
296  RzFlagItem *item = NULL;
297  const RzList *list = rz_flag_get_list(f, off);
298  if (list) {
299  rz_list_foreach (list, iter, item) {
300  if (item->name && !strncmp(item->name, flag_prefix, fp_size)) {
301  return true;
302  }
303  }
304  }
305  return false;
306 }
307 
308 /* return the flag item with name "name" in the RzFlag "f", if it exists.
309  * Otherwise, NULL is returned. */
312  RzFlagItem *r = ht_pp_find(f->ht_name, name, NULL);
313  return r ? evalFlag(f, r) : NULL;
314 }
315 
316 /* return the first flag item that can be found at offset "off", or NULL otherwise */
319  const RzList *list = rz_flag_get_list(f, off);
320  return list ? evalFlag(f, rz_list_get_top(list)) : NULL;
321 }
322 
323 /* return the first flag that matches an offset ordered by the order of
324  * operands to the function.
325  * Pass in the name of each space, in order, followed by a NULL */
328 
329  const RzList *list = rz_flag_get_list(f, off);
330  RzFlagItem *ret = NULL;
331  const char *spacename;
332  RzSpace **spaces;
333  RzListIter *iter;
334  RzFlagItem *flg;
335  va_list ap, aq;
336  size_t n_spaces = 0, i;
337 
338  va_start(ap, off);
339  // some quick checks for common cases
340  if (rz_list_empty(list)) {
341  goto beach;
342  }
343  if (rz_list_length(list) == 1) {
344  ret = rz_list_get_top(list);
345  goto beach;
346  }
347 
348  // count spaces in the vaarg
349  va_copy(aq, ap);
350  spacename = va_arg(aq, const char *);
351  while (spacename) {
352  n_spaces++;
353  spacename = va_arg(aq, const char *);
354  }
355  va_end(aq);
356 
357  // get RzSpaces from the names
358  i = 0;
359  spaces = RZ_NEWS(RzSpace *, n_spaces);
360  spacename = va_arg(ap, const char *);
361  while (spacename) {
362  RzSpace *space = rz_flag_space_get(f, spacename);
363  if (space) {
364  spaces[i++] = space;
365  }
366  spacename = va_arg(ap, const char *);
367  }
368  n_spaces = i;
369 
370  ut64 min_space_i = n_spaces + 1;
371  rz_list_foreach (list, iter, flg) {
372  // get the "priority" of the flag flagspace and
373  // check if better than what we found so far
374  for (i = 0; i < n_spaces; i++) {
375  if (flg->space == spaces[i]) {
376  break;
377  }
378  if (i >= min_space_i) {
379  break;
380  }
381  }
382 
383  if (i < min_space_i) {
384  min_space_i = i;
385  ret = flg;
386  }
387  if (!min_space_i) {
388  // this is the best flag we can find, let's stop immediately
389  break;
390  }
391  }
392  free(spaces);
393 beach:
394  va_end(ap);
395  return ret ? evalFlag(f, ret) : NULL;
396 }
397 
398 static bool isFunctionFlag(const char *n) {
399  return (!strncmp(n, "sym.func.", 9) || !strncmp(n, "method.", 7) || !strncmp(n, "sym.", 4) || !strncmp(n, "func.", 5) || !strncmp(n, "fcn.0", 5));
400 }
401 
402 /* returns the last flag item defined before or at the given offset.
403  * NULL is returned if such a item is not found. */
406 
407  RzFlagItem *nice = NULL;
408  RzListIter *iter;
409  const RzFlagsAtOffset *flags_at = rz_flag_get_nearest_list(f, off, -1);
410  if (!flags_at) {
411  return NULL;
412  }
413  if (flags_at->off == off) {
414  RzFlagItem *item;
415  rz_list_foreach (flags_at->flags, iter, item) {
416  if (IS_FI_NOTIN_SPACE(f, item)) {
417  continue;
418  }
419  if (nice) {
420  if (isFunctionFlag(nice->name)) {
421  nice = item;
422  }
423  } else {
424  nice = item;
425  }
426  }
427  if (nice) {
428  return evalFlag(f, nice);
429  }
430  }
431 
432  if (!closest) {
433  return NULL;
434  }
435  while (!nice && flags_at) {
436  RzFlagItem *item;
437  rz_list_foreach (flags_at->flags, iter, item) {
438  if (IS_FI_NOTIN_SPACE(f, item)) {
439  continue;
440  }
441  if (item->offset == off) {
442  eprintf("XXX Should never happend\n");
443  return evalFlag(f, item);
444  }
445  nice = item;
446  break;
447  }
448  if (!nice && flags_at->off) {
449  flags_at = rz_flag_get_nearest_list(f, flags_at->off - 1, -1);
450  } else {
451  flags_at = NULL;
452  }
453  }
454  return nice ? evalFlag(f, nice) : NULL;
455 }
456 
457 static bool append_to_list(RzFlagItem *fi, void *user) {
458  RzList *ret = (RzList *)user;
459  rz_list_append(ret, fi);
460  return true;
461 }
462 
463 RZ_API RzList /*<RzFlagItem *>*/ *rz_flag_all_list(RzFlag *f, bool by_space) {
464  RzList *ret = rz_list_new();
465  if (!ret) {
466  return NULL;
467  }
468 
469  RzSpace *cur = by_space ? rz_flag_space_cur(f) : NULL;
471  return ret;
472 }
473 
474 /* return the list of flag items that are associated with a given offset */
475 RZ_API const RzList /*<RzFlagItem *>*/ *rz_flag_get_list(RzFlag *f, ut64 off) {
476  const RzFlagsAtOffset *item = rz_flag_get_nearest_list(f, off, 0);
477  return item ? item->flags : NULL;
478 }
479 
481  RzFlagItem *fi;
482  RzListIter *iter;
483  const RzList *list = rz_flag_get_list(f, off);
484  char *p = NULL;
485  rz_list_foreach (list, iter, fi) {
486  p = rz_str_appendf(p, "%s%s",
487  fi->realname, iter->n ? "," : "");
488  }
489  return p;
490 }
491 
492 // Set a new flag named `name` at offset `off`. If there's already a flag with
493 // the same name, slightly change the name by appending ".%d" as suffix
496  if (!rz_flag_get(f, name)) {
497  return rz_flag_set(f, name, off, size);
498  }
499  int i, newNameSize = strlen(name);
500  char *newName = malloc(newNameSize + 16);
501  if (!newName) {
502  return NULL;
503  }
504  strcpy(newName, name);
505  for (i = 0;; i++) {
506  snprintf(newName + newNameSize, 15, ".%d", i);
507  if (!rz_flag_get(f, newName)) {
508  RzFlagItem *fi = rz_flag_set(f, newName, off, size);
509  if (fi) {
510  free(newName);
511  return fi;
512  }
513  }
514  }
515  return NULL;
516 }
517 
518 /* create or modify an existing flag item with the given name and parameters.
519  * The realname of the item will be the same as the name.
520  * NULL is returned in case of any errors during the process. */
523 
524  bool is_new = false;
525  char *itemname = filter_item_name(name);
526  if (!itemname) {
527  return NULL;
528  }
529 
530  RzFlagItem *item = rz_flag_get(f, itemname);
531  free(itemname);
532  if (item && item->offset == off) {
533  item->size = size;
534  return item;
535  }
536 
537  if (!item) {
538  item = RZ_NEW0(RzFlagItem);
539  if (!item) {
540  goto err;
541  }
542  is_new = true;
543  }
544 
545  item->space = rz_flag_space_cur(f);
546  item->size = size;
547 
548  update_flag_item_offset(f, item, off + f->base, is_new, true);
549  update_flag_item_name(f, item, name, true);
550  return item;
551 err:
552  rz_flag_item_free(item);
553  return NULL;
554 }
555 
556 /* add/replace/remove the alias of a flag item */
557 RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias) {
558  rz_return_if_fail(item);
559  free(item->alias);
560  item->alias = RZ_STR_ISEMPTY(alias) ? NULL : strdup(alias);
561 }
562 
563 /* add/replace/remove the comment of a flag item */
564 RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment) {
565  rz_return_if_fail(item);
566  free(item->comment);
567  item->comment = RZ_STR_ISEMPTY(comment) ? NULL : strdup(comment);
568 }
569 
570 /* add/replace/remove the realname of a flag item */
571 RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname) {
572  rz_return_if_fail(item);
573  free_item_realname(item);
574  item->realname = RZ_STR_ISEMPTY(realname) ? NULL : strdup(realname);
575 }
576 
577 /* add/replace/remove the color of a flag item */
578 RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color) {
580  free(item->color);
581  item->color = (color && *color) ? strdup(color) : NULL;
582  return item->color;
583 }
584 
585 /* change the name of a flag item, if the new name is available.
586  * true is returned if everything works well, false otherwise */
587 RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name) {
588  rz_return_val_if_fail(f && item && name && *name, false);
589  return update_flag_item_name(f, item, name, false);
590 }
591 
592 /* \brief unset the given flag \p item.
593  *
594  * return true if the item is successfully unset, false otherwise.
595  * NOTE: the item is freed.
596  */
598  rz_return_val_if_fail(f && item, false);
599  remove_offsetmap(f, item);
600  ht_pp_delete(f->ht_name, item->name);
601  return true;
602 }
603 
604 /* \brief unset the first flag item found at offset \p off.
605  *
606  * return true if such a flag is found and unset, false otherwise.
607  */
609  rz_return_val_if_fail(f, false);
610  RzFlagItem *item = rz_flag_get_i(f, off);
611  if (item && rz_flag_unset(f, item)) {
612  return true;
613  }
614  return false;
615 }
616 
620 };
621 
622 static bool unset_off_foreach(void *user, const void *k, const void *v) {
623  struct unset_off_foreach_t *u = (struct unset_off_foreach_t *)user;
624  RzFlagItem *fi = (RzFlagItem *)v;
625  if (u->offset == fi->offset) {
626  rz_flag_unset(u->f, fi);
627  }
628  return true;
629 }
630 
631 /* \brief unset the all flag items found at offset \p off.
632  *
633  * return true if at least one flag is found and unset, false otherwise.
634  */
636  rz_return_val_if_fail(f, false);
637  struct unset_off_foreach_t u = { f, off };
638  ht_pp_foreach(f->ht_name, unset_off_foreach, &u);
639  return true;
640 }
641 
644  int n;
645 };
646 
647 static bool unset_foreach(RzFlagItem *fi, void *user) {
648  struct unset_foreach_t *u = (struct unset_foreach_t *)user;
649  if (IS_FI_NOTIN_SPACE(u->f, fi)) {
650  return true;
651  }
652  rz_flag_unset(u->f, fi);
653  u->n++;
654  return true;
655 }
656 
657 /* unset all the flag items that satisfy the given glob.
658  * return the number of unset items. -1 on error */
659 // XXX This is O(n^n) because unset_globa iterates all flags and unset too.
660 RZ_API int rz_flag_unset_glob(RzFlag *f, const char *glob) {
662 
663  struct unset_foreach_t u = { .f = f, .n = 0 };
665  return u.n;
666 }
667 
668 /* unset the flag item with the given name.
669  * returns true if the item is found and unset, false otherwise. */
670 RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name) {
671  rz_return_val_if_fail(f, false);
672  RzFlagItem *item = ht_pp_find(f->ht_name, name, NULL);
673  return item && rz_flag_unset(f, item);
674 }
675 
676 /* unset all flag items in the RzFlag f */
679  ht_pp_free(f->ht_name);
680  f->ht_name = ht_pp_new(NULL, ht_free_flag, NULL);
681  rz_skiplist_purge(f->by_off);
682  rz_spaces_fini(&f->spaces);
683  new_spaces(f);
684 }
685 
692 RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name) {
693  rz_flag_space_push(f, space_name);
694  RzList *flags = rz_flag_all_list(f, true);
695  RzFlagItem *flag;
696  RzListIter *iter;
697  rz_list_foreach (flags, iter, flag) {
698  rz_flag_unset(f, flag);
699  }
700  rz_flag_space_pop(f);
702 }
703 
710  int n;
711 };
712 
713 static bool flag_relocate_foreach(RzFlagItem *fi, void *user) {
714  struct flag_relocate_t *u = (struct flag_relocate_t *)user;
715  ut64 fn = fi->offset & u->neg_mask;
716  ut64 on = u->off & u->neg_mask;
717  if (fn == on) {
718  ut64 fm = fi->offset & u->off_mask;
719  ut64 om = u->to & u->off_mask;
720  update_flag_item_offset(u->f, fi, (u->to & u->neg_mask) + fm + om, false, false);
721  u->n++;
722  }
723  return true;
724 }
725 
728  struct flag_relocate_t u = {
729  .f = f,
730  .off = off,
731  .off_mask = off_mask,
732  .neg_mask = ~(off_mask),
733  .to = to,
734  .n = 0
735  };
736 
738  return u.n;
739 }
740 
742  rz_return_val_if_fail(f, false);
743  RzFlagItem *item = rz_flag_get_i(f, at);
744  if (item) {
745  rz_flag_set(f, item->name, to, item->size);
746  return true;
747  }
748  return false;
749 }
750 
751 // BIND
753  rz_return_if_fail(f && fb);
754  fb->f = f;
756  fb->get = rz_flag_get;
757  fb->get_at = rz_flag_get_at;
760  fb->set = rz_flag_set;
761  fb->unset = rz_flag_unset;
764  fb->set_fs = rz_flag_space_set;
765  fb->push_fs = rz_flag_space_push;
766  fb->pop_fs = rz_flag_space_pop;
767  fb->rename = rz_flag_rename;
768 }
769 
770 static bool flag_count_foreach(RzFlagItem *fi, void *user) {
771  int *count = (int *)user;
772  (*count)++;
773  return true;
774 }
775 
776 RZ_API int rz_flag_count(RzFlag *f, const char *glob) {
777  int count = 0;
780  return count;
781 }
782 
783 #define FOREACH_BODY(condition) \
784  RzSkipListNode *it, *tmp; \
785  RzFlagsAtOffset *flags_at; \
786  RzListIter *it2, *tmp2; \
787  RzFlagItem *fi; \
788  rz_skiplist_foreach_safe(f->by_off, it, tmp, flags_at) { \
789  if (flags_at) { \
790  rz_list_foreach_safe (flags_at->flags, it2, tmp2, fi) { \
791  if (condition) { \
792  if (!cb(fi, user)) { \
793  return; \
794  } \
795  } \
796  } \
797  } \
798  }
799 
801  FOREACH_BODY(true);
802 }
803 
804 RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user) {
805  pfx_len = pfx_len < 0 ? strlen(pfx) : pfx_len;
806  FOREACH_BODY(!strncmp(fi->name, pfx, pfx_len));
807 }
808 
815  FOREACH_BODY(fi->offset >= from && fi->offset <= to);
816 }
817 
818 RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user) {
819  FOREACH_BODY(!glob || rz_str_glob(fi->name, glob));
820 }
821 
822 RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RzSpace *space, RzFlagItemCb cb, void *user) {
823  FOREACH_BODY(IS_FI_IN_SPACE(fi, space) && (!glob || rz_str_glob(fi->name, glob)));
824 }
825 
826 RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user) {
827  FOREACH_BODY(IS_FI_IN_SPACE(fi, space));
828 }
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
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 count
Definition: sflib.h:98
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
uint16_t ut16
uint32_t ut32
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
static ut64 num_callback(RzNum *user, const char *name, int *ok)
Definition: flag.c:48
RZ_API void rz_flag_bind(RzFlag *f, RzFlagBind *fb)
Definition: flag.c:752
RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name)
Definition: flag.c:587
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
static char * filter_item_name(const char *name)
Definition: flag.c:125
static const char * str_callback(RzNum *user, ut64 off, int *ok)
Definition: flag.c:16
RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:822
RZ_API RzFlagItem * rz_flag_item_clone(RzFlagItem *item)
Definition: flag.c:240
RZ_API RzFlag * rz_flag_free(RzFlag *f)
Definition: flag.c:271
RZ_API int rz_flag_count(RzFlag *f, const char *glob)
Definition: flag.c:776
static bool append_to_list(RzFlagItem *fi, void *user)
Definition: flag.c:457
RZ_API void rz_flag_item_free(RzFlagItem *item)
Definition: flag.c:258
RZ_API void rz_flag_foreach_range(RZ_NONNULL RzFlag *f, ut64 from, ut64 to, RzFlagItemCb cb, void *user)
Definition: flag.c:813
RZ_API const char * rz_flag_item_set_color(RzFlagItem *item, const char *color)
Definition: flag.c:578
#define IS_FI_IN_SPACE(fi, sp)
Definition: flag.c:13
#define FOREACH_BODY(condition)
Definition: flag.c:783
static void count_flags_in_space(RzEvent *ev, int type, void *user, void *data)
Definition: flag.c:200
RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name)
Unset all flag items in the space with the given name.
Definition: flag.c:692
static bool count_flags(RzFlagItem *fi, void *user)
Definition: flag.c:189
RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment)
Definition: flag.c:564
RZ_API RzFlagItem * rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:494
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
Definition: flag.c:804
RZ_API bool rz_flag_unset_all_off(RzFlag *f, ut64 off)
Definition: flag.c:635
RZ_API RzList * rz_flag_all_list(RzFlag *f, bool by_space)
Definition: flag.c:463
static RzFlagsAtOffset * rz_flag_get_nearest_list(RzFlag *f, ut64 off, int dir)
Definition: flag.c:83
static bool update_flag_item_name(RzFlag *f, RzFlagItem *item, const char *newname, bool force)
Definition: flag.c:162
RZ_LIB_VERSION(rz_flag)
RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias)
Definition: flag.c:557
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
static void new_spaces(RzFlag *f)
Definition: flag.c:214
RZ_API char * rz_flag_get_liststr(RzFlag *f, ut64 off)
Definition: flag.c:480
static RzFlagItem * evalFlag(RzFlag *f, RzFlagItem *item)
Definition: flag.c:283
static bool flag_relocate_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:713
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
static bool unset_off_foreach(void *user, const void *k, const void *v)
Definition: flag.c:622
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
static void ht_free_flag(HtPPKv *kv)
Definition: flag.c:184
static void free_item_name(RzFlagItem *item)
Definition: flag.c:73
RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off)
Definition: flag.c:293
RZ_API void rz_flag_unset_all(RzFlag *f)
Definition: flag.c:677
static void set_name(RzFlagItem *item, char *name)
Definition: flag.c:136
static RzFlagsAtOffset * flags_at_offset(RzFlag *f, ut64 off)
Definition: flag.c:102
static bool flag_count_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:770
RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item)
Definition: flag.c:597
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
RZ_API bool rz_flag_move(RzFlag *f, ut64 at, ut64 to)
Definition: flag.c:741
static void unset_flagspace(RzEvent *ev, int type, void *user, void *data)
Definition: flag.c:207
static bool unset_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:647
static void flag_skiplist_free(void *data)
Definition: flag.c:34
static bool unset_flags_space(RzFlagItem *fi, void *user)
Definition: flag.c:195
RZ_API RzFlagItem * rz_flag_get_by_spaces(RzFlag *f, ut64 off,...)
Definition: flag.c:326
static bool isFunctionFlag(const char *n)
Definition: flag.c:398
static bool update_flag_item_offset(RzFlag *f, RzFlagItem *item, ut64 newoff, bool is_new, bool force)
Definition: flag.c:143
static int flag_skiplist_cmp(const void *va, const void *vb)
Definition: flag.c:40
RZ_API int rz_flag_unset_glob(RzFlag *f, const char *glob)
Definition: flag.c:660
RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:826
RZ_API int rz_flag_relocate(RzFlag *f, ut64 off, ut64 off_mask, ut64 to)
Definition: flag.c:726
RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname)
Definition: flag.c:571
#define STRDUP_OR_NULL(s)
Definition: flag.c:14
RZ_API RzFlag * rz_flag_new(void)
Definition: flag.c:220
static void remove_offsetmap(RzFlag *f, RzFlagItem *item)
Definition: flag.c:91
RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user)
Definition: flag.c:818
RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 off)
Definition: flag.c:608
static void free_item_realname(RzFlagItem *item)
Definition: flag.c:67
RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user)
Definition: flag.c:800
#define IS_FI_NOTIN_SPACE(f, i)
Definition: flag.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
void * p
Definition: libc.cpp:67
const char * spaces(int count)
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
Definition: list.c:148
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:457
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void * malloc(size_t size)
Definition: malloc.c:123
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 nice
Definition: sflib.h:61
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
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")
@ ok
Definition: lz4.c:1706
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
const char * name
Definition: op.c:541
int off
Definition: pal.c:13
#define eprintf(x, y...)
Definition: rlcc.c:7
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RzEventCallbackHandle rz_event_hook(RzEvent *ev, int type, RzEventCallback cb, void *user)
Definition: event.c:58
bool(* RzFlagItemCb)(RzFlagItem *fi, void *user)
Definition: rz_flag.h:74
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
Definition: unum.c:75
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API void rz_num_free(RzNum *num)
Definition: unum.c:87
RZ_API void * rz_skiplist_get_geq(RzSkipList *list, void *data)
Definition: skiplist.c:273
RZ_API bool rz_skiplist_delete(RzSkipList *list, void *data)
Definition: skiplist.c:201
RZ_API void rz_skiplist_purge(RzSkipList *list)
Definition: skiplist.c:128
RZ_API void * rz_skiplist_get_leq(RzSkipList *list, void *data)
Definition: skiplist.c:278
RZ_API RzSkipList * rz_skiplist_new(RzListFree freefn, RzListComparator comparefn)
Definition: skiplist.c:107
RZ_API void rz_skiplist_free(RzSkipList *list)
Definition: skiplist.c:145
RZ_API RzSkipListNode * rz_skiplist_insert(RzSkipList *list, void *data)
Definition: skiplist.c:156
RZ_API void rz_spaces_fini(RzSpaces *sp)
Definition: spaces.c:59
@ RZ_SPACE_EVENT_COUNT
Definition: rz_spaces.h:34
@ RZ_SPACE_EVENT_UNSET
Definition: rz_spaces.h:36
RZ_API bool rz_spaces_init(RzSpaces *sp, const char *name)
Definition: spaces.c:16
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API bool rz_str_glob(const char *str, const char *glob)
Definition: str.c:2368
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_NEW(x)
Definition: rz_types.h:285
#define container_of(ptr, type, member)
Definition: rz_types.h:650
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
RzFlag * f
Definition: flag.c:705
ut64 off
Definition: flag.c:706
ut64 off_mask
Definition: flag.c:707
ut64 neg_mask
Definition: flag.c:708
Definition: z80asm.h:102
void * user
Definition: rz_event.h:15
RzFlagExistAt exist_at
Definition: rz_flag.h:79
RzFlagGetAtBySpaces get_at_by_spaces
Definition: rz_flag.h:82
RzFlagSet set
Definition: rz_flag.h:84
RzFlagRename rename
Definition: rz_flag.h:91
RzFlagGet get
Definition: rz_flag.h:80
RzFlagGetAt get_at
Definition: rz_flag.h:81
RzFlagGetList get_list
Definition: rz_flag.h:83
RzFlagSetSpace set_fs
Definition: rz_flag.h:88
RzFlagPopSpace pop_fs
Definition: rz_flag.h:90
RzFlagUnsetName unset_name
Definition: rz_flag.h:86
RzFlagUnsetOff unset_off
Definition: rz_flag.h:87
RzFlag * f
Definition: rz_flag.h:78
RzFlagPushSpace push_fs
Definition: rz_flag.h:89
RzFlagUnset unset
Definition: rz_flag.h:85
RzSpace * space
Definition: rz_flag.h:40
char * color
Definition: rz_flag.h:41
char * alias
Definition: rz_flag.h:43
ut64 offset
Definition: rz_flag.h:38
char * comment
Definition: rz_flag.h:42
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35
RzList * flags
Definition: rz_flag.h:31
struct rz_space_event_t::@311::@313 unset
struct rz_space_event_t::@311::@312 count
union rz_space_event_t::@311 data
RzFlag * f
Definition: flag.c:643
RzFlag * f
Definition: flag.c:618
static int color
Definition: visual.c:20
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const char * cb[]
Definition: z80_tab.h:176
static int sp
Definition: z80asm.c:91