Rizin
unix-like reverse engineering framework and cli tools
zones.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_flag.h>
5 #include <rz_util.h>
6 
7 static RzFlagZoneItem *rz_flag_zone_get(RzFlag *f, const char *name) {
9  RzFlagZoneItem *zi;
10  rz_list_foreach (f->zones, iter, zi) {
11  if (!strcmp(name, zi->name)) {
12  return zi;
13  }
14  }
15  return NULL;
16 }
17 
20  RzFlagZoneItem *zi;
21  rz_list_foreach (f->zones, iter, zi) {
22  if (RZ_BETWEEN(from, zi->from, to)) {
23  return zi;
24  }
25  }
26  return NULL;
27 }
28 
29 RZ_API bool rz_flag_zone_add(RzFlag *f, const char *name, ut64 addr) {
30  rz_return_val_if_fail(f && name && *name, false);
32  if (zi) {
33  if (addr < zi->from) {
34  zi->from = addr;
35  }
36  if (addr > zi->to) {
37  zi->to = addr;
38  }
39  } else {
40  if (!f->zones) {
42  }
43  zi = RZ_NEW0(RzFlagZoneItem);
44  zi->name = strdup(name);
45  zi->from = zi->to = addr;
46  rz_list_append(f->zones, zi);
47  }
48  return true;
49 }
50 
52  rz_list_free(f->zones);
54  return true;
55 }
56 
57 RZ_API bool rz_flag_zone_del(RzFlag *f, const char *name) {
59  RzFlagZoneItem *zi;
60  rz_list_foreach (f->zones, iter, zi) {
61  if (!strcmp(name, zi->name)) {
62  rz_list_delete(f->zones, iter);
63  return true;
64  }
65  }
66  return false;
67 }
68 
70  RzFlagZoneItem *zi = a;
71  free(zi->name);
72  free(zi);
73 }
74 
75 RZ_API bool rz_flag_zone_around(RzFlag *f, ut64 addr, const char **prev, const char **next) {
77  RzFlagZoneItem *zi;
78  *prev = *next = NULL;
79  ut64 h = UT64_MAX, l = 0LL;
80 
81  rz_list_foreach (f->zones, iter, zi) {
82  if (zi->from > addr) {
83  if (h == UT64_MAX) {
84  h = zi->from;
85  *next = zi->name;
86  } else {
87  if (zi->from < h) {
88  h = zi->from;
89  *next = zi->name;
90  }
91  }
92  }
93  if (zi->from < addr) {
94  if (l == UT64_MAX) {
95  l = zi->from;
96  *prev = zi->name;
97  } else {
98  if (zi->from >= l) {
99  l = zi->from;
100  *prev = zi->name;
101  }
102  }
103  }
104  if (zi->to <= addr) {
105  if (l == UT64_MAX) {
106  l = zi->to;
107  *prev = zi->name;
108  } else {
109  if (zi->to >= l) {
110  l = zi->to;
111  *prev = zi->name;
112  }
113  }
114  }
115  if (zi->to > addr) {
116  if (h == UT64_MAX) {
117  h = zi->to;
118  *next = zi->name;
119  } else {
120  if (zi->to < h) {
121  h = zi->to;
122  *next = zi->name;
123  }
124  }
125  }
126  }
127  return true;
128 }
129 
130 RZ_API RzList /*<char *>*/ *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows) {
132  int i;
133  for (i = 0; i < rows; i++) {
135  if (zi) {
136  rz_list_append(list, zi->name);
137  } else {
138  rz_list_append(list, "");
139  }
140  from += bsize;
141  }
142  return list;
143 }
lzma_index ** i
Definition: index.h:629
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void list(RzEgg *egg)
Definition: rz-gg.c:52
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 void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
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
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_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define UT64_MAX
Definition: rz_types_base.h:86
#define RZ_BETWEEN(x, y, z)
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
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Definition: z80asm.h:102
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58
static RzFlagZoneItem * rz_flag_zone_get_inrange(RzFlag *f, ut64 from, ut64 to)
Definition: zones.c:18
RZ_API bool rz_flag_zone_reset(RzFlag *f)
Definition: zones.c:51
RZ_API bool rz_flag_zone_around(RzFlag *f, ut64 addr, const char **prev, const char **next)
Definition: zones.c:75
RZ_API RzList * rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows)
Definition: zones.c:130
RZ_API bool rz_flag_zone_del(RzFlag *f, const char *name)
Definition: zones.c:57
RZ_API bool rz_flag_zone_add(RzFlag *f, const char *name, ut64 addr)
Definition: zones.c:29
static RzFlagZoneItem * rz_flag_zone_get(RzFlag *f, const char *name)
Definition: zones.c:7
RZ_API void rz_flag_zone_item_free(void *a)
Definition: zones.c:69