Rizin
unix-like reverse engineering framework and cli tools
visual_tabs.inc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2019 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 static void rz_core_visual_tab_free(RzCoreVisualTab *tab) {
5  free(tab);
6 }
7 
8 static int __core_visual_tab_count(RzCore *core) {
9  return core->visual.tabs ? rz_list_length(core->visual.tabs) : 0;
10 }
11 
12 static char *__core_visual_tab_string(RzCore *core, const char *kolor) {
13  int hex_cols = rz_config_get_i(core->config, "hex.cols");
14  int scr_color = rz_config_get_i(core->config, "scr.color");
15  if (hex_cols < 4) {
16  return strdup("");
17  }
18  int i = 0;
19  char *str = NULL;
20  int tabs = rz_list_length(core->visual.tabs);
21  if (scr_color > 0) {
22  // TODO: use theme
23  if (tabs > 0) {
24  str = rz_str_appendf(str, "%s-+__", kolor);
25  }
26  for (i = 0; i < tabs; i++) {
28  const char *name = (tab && *tab->name) ? tab->name : NULL;
29  if (i == core->visual.tab) {
30  str = rz_str_appendf(str, Color_WHITE "_/ %s \\_%s", name ? name : "t=", kolor);
31  } else {
32  str = rz_str_appendf(str, "_%s(%d)_", name ? name : "", i + 1);
33  }
34  }
35  } else {
36  if (tabs > 0) {
37  str = rz_str_append(str, "___");
38  }
39  for (i = 0; i < tabs; i++) {
40  const char *name = NULL;
42  if (tab && *tab->name) {
43  name = tab->name;
44  }
45  if (i == core->visual.tab) {
46  str = rz_str_appendf(str, "_/ %d:%s \\_", i + 1, name ? name : "'=");
47  } else {
48  str = rz_str_appendf(str, "_(t%d%s%s)__", i + 1, name ? ":" : "", name ? name : "");
49  }
50  }
51  }
52  if (str) {
53  int n = 79 - rz_str_ansi_len(str);
54  if (n > 0) {
55  str = rz_str_append(str, rz_str_pad('_', n));
56  }
58  }
59  return str;
60 }
61 
62 static void visual_tabset(RzCore *core, RzCoreVisualTab *tab) {
63  rz_return_if_fail(core && tab);
64 
65  rz_core_seek(core, tab->offset, true);
66  core->printidx = tab->printidx;
67  core->print->cur_enabled = tab->cur_enabled;
68  core->print->cur = tab->cur;
69  core->print->ocur = tab->ocur;
70  disMode = tab->disMode;
71  hexMode = tab->hexMode;
72  printMode = tab->printMode;
73  current3format = tab->current3format;
74  current4format = tab->current4format;
75  current5format = tab->current5format;
78  rz_config_set_i(core->config, "asm.offset", tab->asm_offset);
79  rz_config_set_i(core->config, "asm.instr", tab->asm_instr);
80  rz_config_set_i(core->config, "asm.bytes", tab->asm_bytes);
81  rz_config_set_i(core->config, "asm.indent", tab->asm_indent);
82  rz_config_set_i(core->config, "asm.cmt.col", tab->asm_cmt_col);
83  rz_config_set_i(core->config, "hex.cols", tab->cols);
84  rz_config_set_i(core->config, "scr.dumpcols", tab->dumpCols);
89 }
90 
91 static void visual_tabget(RzCore *core, RzCoreVisualTab *tab) {
92  rz_return_if_fail(core && tab);
93 
94  tab->offset = core->offset;
95  tab->printidx = core->printidx;
96  tab->asm_offset = rz_config_get_i(core->config, "asm.offset");
97  tab->asm_instr = rz_config_get_i(core->config, "asm.instr");
98  tab->asm_indent = rz_config_get_i(core->config, "asm.indent");
99  tab->asm_bytes = rz_config_get_i(core->config, "asm.bytes");
100  tab->asm_cmt_col = rz_config_get_i(core->config, "asm.cmt.col");
101  tab->cur_enabled = core->print->cur_enabled;
102  tab->cur = core->print->cur;
103  tab->ocur = core->print->ocur;
104  tab->cols = rz_config_get_i(core->config, "hex.cols");
105  tab->dumpCols = rz_config_get_i(core->config, "scr.dumpcols");
106  tab->disMode = disMode;
107  tab->hexMode = hexMode;
108  tab->printMode = printMode;
109  tab->current3format = current3format;
110  tab->current4format = current4format;
111  tab->current5format = current5format;
112  // tab->cols = core->print->cols;
113 }
114 
115 static RzCoreVisualTab *rz_core_visual_tab_new(RzCore *core) {
117  if (tab) {
118  visual_tabget(core, tab);
119  }
120  return tab;
121 }
122 
123 static void rz_core_visual_tab_update(RzCore *core) {
124  if (!core->visual.tabs) {
125  return;
126  }
128  if (tab) {
129  visual_tabget(core, tab);
130  }
131 }
132 
133 static RzCoreVisualTab *visual_newtab(RzCore *core) {
134  if (!core->visual.tabs) {
135  core->visual.tabs = rz_list_newf((RzListFree)rz_core_visual_tab_free);
136  if (!core->visual.tabs) {
137  return NULL;
138  }
139  core->visual.tab = -1;
140  visual_newtab(core);
141  }
142  core->visual.tab++;
143  RzCoreVisualTab *tab = rz_core_visual_tab_new(core);
144  if (tab) {
145  rz_list_append(core->visual.tabs, tab);
146  visual_tabset(core, tab);
147  }
148  return tab;
149 }
150 
151 static void visual_nthtab(RzCore *core, int n) {
152  if (!core->visual.tabs || n < 0 || n >= rz_list_length(core->visual.tabs)) {
153  return;
154  }
155  core->visual.tab = n;
157  if (tab) {
158  visual_tabset(core, tab);
159  }
160 }
161 
162 static void visual_tabname(RzCore *core) {
163  if (!core->visual.tabs) {
164  return;
165  }
166  char name[32] = { 0 };
167  prompt_read("tab name: ", name, sizeof(name));
169  if (tab) {
170  strcpy(tab->name, name);
171  }
172 }
173 
174 static void visual_nexttab(RzCore *core) {
175  if (!core->visual.tabs) {
176  return;
177  }
178  if (core->visual.tab >= rz_list_length(core->visual.tabs) - 1) {
179  core->visual.tab = -1;
180  }
181  core->visual.tab++;
183  if (tab) {
184  visual_tabset(core, tab);
185  }
186 }
187 
188 static void visual_prevtab(RzCore *core) {
189  if (!core->visual.tabs) {
190  return;
191  }
192  if (core->visual.tab < 1) {
193  core->visual.tab = rz_list_length(core->visual.tabs) - 1;
194  } else {
195  core->visual.tab--;
196  }
198  if (tab) {
199  visual_tabset(core, tab);
200  }
201 }
202 
203 static void visual_closetab(RzCore *core) {
204  if (!core->visual.tabs) {
205  return;
206  }
208  if (tab) {
210  const int tabsCount = rz_list_length(core->visual.tabs);
211  if (tabsCount > 0) {
212  if (core->visual.tab > 0) {
213  core->visual.tab--;
214  }
216  if (tab) {
217  visual_tabset(core, tab);
218  }
219  } else {
220  rz_list_free(core->visual.tabs);
221  core->visual.tabs = NULL;
222  }
223  }
224 }
static int disMode
Definition: agraph.c:14
lzma_index ** i
Definition: index.h:629
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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 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_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
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
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")
@ RZ_ABS
int n
Definition: mipsasm.c:19
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define Color_RESET
Definition: rz_cons.h:617
#define Color_WHITE
Definition: rz_cons.h:625
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
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 size_t rz_str_ansi_len(const char *str)
Definition: str.c:1945
RZ_API const char * rz_str_pad(const char ch, int len)
Definition: str.c:3236
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
Definition: z80asm.h:102
RzCoreVisualMode printidx
Definition: rz_core.h:357
ut64 offset
Definition: rz_core.h:301
RzCoreVisual visual
Definition: rz_core.h:351
RzPrint * print
Definition: rz_core.h:327
RzConfig * config
Definition: rz_core.h:300
RzList * tabs
Definition: rz_core.h:241
int ocur
Definition: rz_print.h:135
bool cur_enabled
Definition: rz_print.h:130
Definition: enough.c:118
static const char * print3Formats[PRINT_3_FORMATS]
Definition: visual.c:71
static int printMode
Definition: visual.c:19
static const char * printfmtSingle[NPF]
Definition: visual.c:34
#define PRINT_5_FORMATS
Definition: visual.c:54
RZ_API void rz_core_visual_applyDisMode(RzCore *core, int disMode)
Definition: visual.c:174
static void prompt_read(const char *p, char *buf, int buflen)
Definition: visual.c:662
#define PRINT_4_FORMATS
Definition: visual.c:53
#define PRINT_3_FORMATS
Definition: visual.c:52
#define PRINT_HEX_FORMATS
Definition: visual.c:51
RZ_API void rz_core_visual_applyHexMode(RzCore *core, int hexMode)
Definition: visual.c:84
static int current4format
Definition: visual.c:75
static const char * print4Formats[PRINT_4_FORMATS]
Definition: visual.c:76
static const char * printHexFormats[PRINT_HEX_FORMATS]
Definition: visual.c:58
static int current5format
Definition: visual.c:79
static const char * print5Formats[PRINT_5_FORMATS]
Definition: visual.c:80
static int hexMode
Definition: visual.c:18
static int current3format
Definition: visual.c:70
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4