Rizin
unix-like reverse engineering framework and cli tools
cons.c File Reference
#include <rz_cons.h>
#include <rz_util.h>
#include <rz_util/rz_print.h>
#include <rz_windows.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

Go to the source code of this file.

Classes

struct  RzConsStack
 
struct  RzConsBreakStack
 

Macros

#define COUNT_LINES   1
 
#define CTX(x)   I.context->x
 
#define I   rz_cons_instance
 
#define MOAR   (4096 * 8)
 

Functions

 RZ_LIB_VERSION (rz_cons)
 
static void cons_grep_reset (RzConsGrep *grep)
 
static void ctx_rowcol_calc_reset (void)
 
static void break_stack_free (void *ptr)
 
static void cons_stack_free (void *ptr)
 
static RzConsStackcons_stack_dump (bool recreate)
 
static void cons_stack_load (RzConsStack *data, bool free_current)
 
static void cons_context_init (RzConsContext *context, RZ_NULLABLE RzConsContext *parent)
 
static void cons_context_deinit (RzConsContext *context)
 
static void __break_signal (int sig)
 
static void __cons_write_ll (const char *buf, int len)
 
static void __cons_write (const char *obuf, int olen)
 
RZ_API RzColor rz_cons_color_random (ut8 alpha)
 
RZ_API void rz_cons_color (int fg, int r, int g, int b)
 
RZ_API void rz_cons_println (const char *str)
 
RZ_API void rz_cons_strcat_justify (const char *str, int j, char c)
 
RZ_API void rz_cons_strcat_at (const char *_str, int x, char y, int w, int h)
 
RZ_API RzConsrz_cons_singleton (void)
 
RZ_API void rz_cons_break_clear (void)
 
RZ_API void rz_cons_context_break_push (RzConsContext *context, RzConsBreak cb, void *user, bool sig)
 
RZ_API void rz_cons_context_break_pop (RzConsContext *context, bool sig)
 
RZ_API void rz_cons_break_push (RzConsBreak cb, void *user)
 
RZ_API void rz_cons_break_pop (void)
 
RZ_API bool rz_cons_is_interactive (void)
 
RZ_API bool rz_cons_default_context_is_interactive (void)
 
RZ_API bool rz_cons_is_breaked (void)
 
RZ_API int rz_cons_get_cur_line (void)
 
RZ_API void rz_cons_break_timeout (int timeout)
 
RZ_API void rz_cons_break_end (void)
 
RZ_API void * rz_cons_sleep_begin (void)
 
RZ_API void rz_cons_sleep_end (void *user)
 
void resizeWin (void)
 
RZ_API void rz_cons_set_click (int x, int y)
 
RZ_API bool rz_cons_get_click (int *x, int *y)
 
RZ_API void rz_cons_enable_highlight (const bool enable)
 
RZ_API bool rz_cons_enable_mouse (const bool enable)
 
RZ_API RzConsrz_cons_new (void)
 
RZ_API RzConsrz_cons_free (void)
 
static bool palloc (int moar)
 
RZ_API int rz_cons_eof (void)
 
RZ_API void rz_cons_gotoxy (int x, int y)
 
RZ_API void rz_cons_goto_origin_reset (void)
 
RZ_API void rz_cons_fill_line (void)
 
RZ_API void rz_cons_clear_line (int std_err)
 
RZ_API void rz_cons_clear00 (void)
 
RZ_API void rz_cons_reset_colors (void)
 
RZ_API void rz_cons_clear (void)
 
RZ_API void rz_cons_reset (void)
 
RZ_API const char * rz_cons_get_buffer (void)
 Return the current RzCons buffer. More...
 
RZ_API RZ_OWN char * rz_cons_get_buffer_dup (void)
 Return a newly allocated buffer containing what's currently in RzCons buffer. More...
 
RZ_API int rz_cons_get_buffer_len (void)
 
RZ_API void rz_cons_filter (void)
 
RZ_API void rz_cons_push (void)
 
RZ_API void rz_cons_pop (void)
 
RZ_API RzConsContextrz_cons_context_new (RZ_NULLABLE RzConsContext *parent)
 
RZ_API void rz_cons_context_free (RzConsContext *context)
 
RZ_API void rz_cons_context_load (RzConsContext *context)
 
RZ_API void rz_cons_context_reset (void)
 
RZ_API bool rz_cons_context_is_main (void)
 
RZ_API void rz_cons_context_break (RzConsContext *context)
 
RZ_API void rz_cons_last (void)
 
static bool lastMatters (void)
 
RZ_API void rz_cons_echo (const char *msg)
 
RZ_API void rz_cons_flush (void)
 
RZ_API void rz_cons_visual_flush (void)
 
static int real_strlen (const char *ptr, int len)
 
RZ_API void rz_cons_visual_write (char *buffer)
 
RZ_API void rz_cons_printf_list (const char *format, va_list ap)
 
RZ_API int rz_cons_printf (const char *format,...)
 
RZ_API int rz_cons_get_column (void)
 
RZ_API int rz_cons_memcat (const char *str, int len)
 
RZ_API void rz_cons_memset (char ch, int len)
 
RZ_API void rz_cons_strcat (const char *str)
 
RZ_API void rz_cons_newline (void)
 
RZ_API int rz_cons_get_cursor (RZ_NONNULL int *rows)
 Calculates the aproximated x,y coordinates of the cursor before flushing. More...
 
RZ_API bool rz_cons_isatty (void)
 
RZ_API int rz_cons_get_size (int *rows)
 
RZ_API void rz_cons_show_cursor (int cursor)
 
RZ_API void rz_cons_set_raw (bool is_raw)
 
RZ_API void rz_cons_set_utf8 (bool b)
 
RZ_API void rz_cons_invert (int set, int color)
 
RZ_API bool rz_cons_set_cup (bool enable)
 
RZ_API void rz_cons_column (int c)
 
RZ_API void rz_cons_set_interactive (bool x)
 
RZ_API void rz_cons_set_last_interactive (void)
 
RZ_API void rz_cons_set_title (const char *str)
 
RZ_API void rz_cons_zero (void)
 
RZ_API void rz_cons_highlight (const char *word)
 
RZ_API char * rz_cons_lastline (int *len)
 
RZ_API char * rz_cons_lastline_utf8_ansi_len (int *len)
 
RZ_API char * rz_cons_swap_ground (const char *col)
 
RZ_API bool rz_cons_drop (int n)
 
RZ_API void rz_cons_chop (void)
 
RZ_API void rz_cons_bind (RzConsBind *bind)
 
RZ_API const char * rz_cons_get_rune (const ut8 ch)
 
RZ_API void rz_cons_breakword (RZ_NULLABLE const char *s)
 
RZ_API void rz_cons_cmd_help (const char *help[], bool use_color)
 
RZ_API void rz_cons_clear_buffer (void)
 
RZ_API void rz_cons_set_flush (bool flush)
 Set whether RzCons should flush content to screen or not. More...
 

Variables

static RzConsContext rz_cons_context_default = { { { { 0 } } } }
 
static RzCons rz_cons_instance = { 0 }
 
static bool lasti = false
 

Macro Definition Documentation

◆ COUNT_LINES

#define COUNT_LINES   1

Definition at line 15 of file cons.c.

◆ CTX

#define CTX (   x)    I.context->x

Definition at line 16 of file cons.c.

◆ I

#define I   rz_cons_instance

Definition at line 22 of file cons.c.

◆ MOAR

#define MOAR   (4096 * 8)

Definition at line 684 of file cons.c.

Function Documentation

◆ __break_signal()

static void __break_signal ( int  sig)
static

Definition at line 146 of file cons.c.

146  {
148 }
static RzConsContext rz_cons_context_default
Definition: cons.c:20
RZ_API void rz_cons_context_break(RzConsContext *context)
Definition: cons.c:917

References rz_cons_context_break(), and rz_cons_context_default.

Referenced by rz_cons_context_break_push().

◆ __cons_write()

static void __cons_write ( const char *  obuf,
int  olen 
)
inlinestatic

Definition at line 169 of file cons.c.

169  {
170  const size_t bucket = 64 * 1024;
171  size_t i;
172  if (olen < 0) {
173  olen = strlen(obuf);
174  }
175  for (i = 0; (i + bucket) < olen; i += bucket) {
176  __cons_write_ll(obuf + i, bucket);
177  }
178  if (i < olen) {
179  __cons_write_ll(obuf + i, olen - i);
180  }
181 }
lzma_index ** i
Definition: index.h:629
static void __cons_write_ll(const char *buf, int len)
Definition: cons.c:150
static unsigned char * obuf
Definition: z80asm.c:36

References __cons_write_ll(), i, and obuf.

Referenced by rz_cons_flush(), and rz_cons_visual_write().

◆ __cons_write_ll()

static void __cons_write_ll ( const char *  buf,
int  len 
)
inlinestatic

Definition at line 150 of file cons.c.

150  {
151 #if __WINDOWS__
152  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
153  rz_xwrite(I.fdout, buf, len);
154  } else {
155  if (I.fdout == 1) {
156  rz_cons_w32_print(buf, len, false);
157  } else {
158  rz_xwrite(I.fdout, buf, len);
159  }
160  }
161 #else
162  if (I.fdout < 1) {
163  I.fdout = 1;
164  }
165  rz_xwrite(I.fdout, buf, len);
166 #endif
167 }
size_t len
Definition: 6502dis.c:15
#define I
Definition: cons.c:22
voidpf void * buf
Definition: ioapi.h:138
@ RZ_VIRT_TERM_MODE_DISABLE
Windows only: Use console c api for everything (Windows <= 8)
Definition: rz_cons.h:449
#define rz_xwrite(fd, buf, count)
Definition: rz_types.h:642

References I, len, RZ_VIRT_TERM_MODE_DISABLE, and rz_xwrite.

Referenced by __cons_write().

◆ break_stack_free()

static void break_stack_free ( void *  ptr)
static

Definition at line 47 of file cons.c.

47  {
49  free(b);
50 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define b(i)
Definition: sha256.c:42

References b, and free().

Referenced by cons_context_init(), rz_cons_break_end(), and rz_cons_context_break_pop().

◆ cons_context_deinit()

static void cons_context_deinit ( RzConsContext context)
static

Definition at line 138 of file cons.c.

138  {
139  rz_stack_free(context->cons_stack);
140  context->cons_stack = NULL;
141  rz_stack_free(context->break_stack);
142  context->break_stack = NULL;
144 }
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_cons_pal_free(RzConsContext *ctx)
Definition: pal.c:247
RZ_API void rz_stack_free(RzStack *s)
Definition: stack.c:29

References NULL, rz_cons_pal_free(), and rz_stack_free().

Referenced by rz_cons_context_free(), and rz_cons_free().

◆ cons_context_init()

static void cons_context_init ( RzConsContext context,
RZ_NULLABLE RzConsContext parent 
)
static

Definition at line 111 of file cons.c.

111  {
112  context->breaked = false;
113  context->cmd_depth = RZ_CONS_CMD_DEPTH + 1;
114  context->buffer = NULL;
115  context->buffer_sz = 0;
116  context->lastEnabled = true;
117  context->buffer_len = 0;
118  context->is_interactive = false;
119  context->cons_stack = rz_stack_newf(6, cons_stack_free);
120  context->break_stack = rz_stack_newf(6, break_stack_free);
121  context->event_interrupt = NULL;
122  context->event_interrupt_data = NULL;
123  context->pageable = true;
124  context->log_callback = NULL;
125  context->noflush = false;
126 
127  if (parent) {
128  context->color_mode = parent->color_mode;
129  rz_cons_pal_copy(context, parent);
130  } else {
131  context->color_mode = COLOR_MODE_DISABLED;
133  }
134 
135  cons_grep_reset(&context->grep);
136 }
static void break_stack_free(void *ptr)
Definition: cons.c:47
static void cons_grep_reset(RzConsGrep *grep)
Definition: cons.c:796
static void cons_stack_free(void *ptr)
Definition: cons.c:52
RZ_API void rz_cons_pal_init(RzConsContext *ctx)
Definition: pal.c:154
RZ_API void rz_cons_pal_copy(RzConsContext *dst, RzConsContext *src)
Definition: pal.c:258
#define RZ_CONS_CMD_DEPTH
Definition: rz_cons.h:55
@ COLOR_MODE_DISABLED
Definition: rz_cons.h:442
RZ_API RzStack * rz_stack_newf(ut32 n, RzStackFree f)
Definition: stack.c:21
zip_uint8_t buffer[BUFSIZE]

References break_stack_free(), context::buffer, COLOR_MODE_DISABLED, cons_grep_reset(), cons_stack_free(), NULL, RZ_CONS_CMD_DEPTH, rz_cons_pal_copy(), rz_cons_pal_init(), and rz_stack_newf().

Referenced by rz_cons_context_new(), and rz_cons_new().

◆ cons_grep_reset()

static void cons_grep_reset ( RzConsGrep grep)
static

Definition at line 796 of file cons.c.

796  {
797  RZ_FREE(grep->str);
798  ZERO_FILL(*grep);
799  grep->line = -1;
800  grep->sort = -1;
801  grep->sort_invert = false;
802 }
#define ZERO_FILL(x)
Definition: rz_types.h:281
#define RZ_FREE(x)
Definition: rz_types.h:369
char * str
Definition: rz_cons.h:75
bool sort_invert
Definition: rz_cons.h:87

References rz_cons_grep_t::line, RZ_FREE, rz_cons_grep_t::sort, rz_cons_grep_t::sort_invert, rz_cons_grep_t::str, and ZERO_FILL.

Referenced by cons_context_init(), and rz_cons_reset().

◆ cons_stack_dump()

static RzConsStack* cons_stack_dump ( bool  recreate)
static

Definition at line 63 of file cons.c.

63  {
65  if (data) {
66  if (CTX(buffer)) {
67  data->buf = CTX(buffer);
68  data->buf_len = CTX(buffer_len);
69  data->buf_size = CTX(buffer_sz);
70  }
71  data->noflush = CTX(noflush);
72  data->grep = RZ_NEW0(RzConsGrep);
73  if (data->grep) {
74  memcpy(data->grep, &CTX(grep), sizeof(RzConsGrep));
75  if (CTX(grep).str) {
76  data->grep->str = strdup(CTX(grep).str);
77  }
78  }
79  if (recreate && CTX(buffer_sz) > 0) {
80  CTX(buffer) = malloc(CTX(buffer_sz));
82  if (!CTX(buffer)) {
83  CTX(buffer) = data->buf;
84  free(data);
85  return NULL;
86  }
87  } else {
88  CTX(buffer) = NULL;
89  }
90  }
91  return data;
92 }
#define CTX(x)
Definition: cons.c:16
static void ctx_rowcol_calc_reset(void)
Definition: cons.c:41
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
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
int buf_len
Definition: cons.c:27
char * buf
Definition: cons.c:26
bool noflush
Definition: cons.c:30
RzConsGrep * grep
Definition: cons.c:29
int buf_size
Definition: cons.c:28
Definition: buffer.h:15

References RzConsStack::buf, RzConsStack::buf_len, RzConsStack::buf_size, CTX, ctx_rowcol_calc_reset(), free(), RzConsStack::grep, malloc(), memcpy(), RzConsStack::noflush, NULL, RZ_NEW0, cmd_descs_generate::str, rz_cons_grep_t::str, and strdup().

Referenced by rz_cons_push().

◆ cons_stack_free()

static void cons_stack_free ( void *  ptr)
static

Definition at line 52 of file cons.c.

52  {
53  RzConsStack *s = (RzConsStack *)ptr;
54  free(s->buf);
55  if (s->grep) {
56  RZ_FREE(s->grep->str);
57  CTX(grep.str) = NULL;
58  }
59  free(s->grep);
60  free(s);
61 }
static RzSocket * s
Definition: rtr.c:28

References CTX, free(), NULL, RZ_FREE, and s.

Referenced by cons_context_init(), and rz_cons_pop().

◆ cons_stack_load()

static void cons_stack_load ( RzConsStack data,
bool  free_current 
)
static

Definition at line 94 of file cons.c.

94  {
95  rz_return_if_fail(data);
96  if (free_current) {
97  free(CTX(buffer));
98  }
99  CTX(buffer) = data->buf;
100  data->buf = NULL;
101  CTX(buffer_len) = data->buf_len;
102  CTX(buffer_sz) = data->buf_size;
103  if (data->grep) {
104  free(CTX(grep).str);
105  memcpy(&CTX(grep), data->grep, sizeof(RzConsGrep));
106  }
107  CTX(noflush) = data->noflush;
109 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References RzConsStack::buf, RzConsStack::buf_len, RzConsStack::buf_size, CTX, ctx_rowcol_calc_reset(), free(), RzConsStack::grep, memcpy(), RzConsStack::noflush, NULL, rz_return_if_fail, and cmd_descs_generate::str.

Referenced by rz_cons_pop().

◆ ctx_rowcol_calc_reset()

static void ctx_rowcol_calc_reset ( void  )
static

Definition at line 41 of file cons.c.

41  {
42  CTX(row) = 0;
43  CTX(col) = 0;
44  CTX(rowcol_calc_start) = 0;
45 }

References CTX.

Referenced by cons_stack_dump(), cons_stack_load(), rz_cons_filter(), rz_cons_highlight(), and rz_cons_reset().

◆ lastMatters()

static bool lastMatters ( void  )
static

Definition at line 935 of file cons.c.

935  {
936  return (CTX(buffer_len) > 0) && (CTX(lastEnabled) && !I.filter && CTX(grep).nstrings < 1 && !CTX(grep).tokens_used && !CTX(grep).less && !CTX(grep).json && !I.is_html);
937 }

References CTX, and I.

Referenced by rz_cons_flush().

◆ palloc()

static bool palloc ( int  moar)
static

Definition at line 685 of file cons.c.

685  {
686  void *temp;
687  if (moar <= 0) {
688  return false;
689  }
690  if (!CTX(buffer)) {
691  int new_sz;
692  if ((INT_MAX - MOAR) < moar) {
693  return false;
694  }
695  new_sz = moar + MOAR;
696  temp = calloc(1, new_sz);
697  if (temp) {
698  CTX(buffer_sz) = new_sz;
699  CTX(buffer) = temp;
700  (CTX(buffer))[0] = '\0';
701  }
702  } else if (moar + CTX(buffer_len) > CTX(buffer_sz)) {
703  char *new_buffer;
704  int old_buffer_sz = CTX(buffer_sz);
705  if ((INT_MAX - MOAR - moar) < CTX(buffer_sz)) {
706  return false;
707  }
708  CTX(buffer_sz) += moar + MOAR;
709  new_buffer = realloc(CTX(buffer), CTX(buffer_sz));
710  if (new_buffer) {
711  CTX(buffer) = new_buffer;
712  } else {
713  CTX(buffer_sz) = old_buffer_sz;
714  return false;
715  }
716  }
717  return true;
718 }
static RzBuffer * new_buffer(RzBufferType type, void *user)
Definition: buf.c:244
#define MOAR
Definition: cons.c:684
#define INT_MAX
Definition: cp-demangle.c:131
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * calloc(size_t number, size_t size)
Definition: malloc.c:102

References calloc(), CTX, INT_MAX, MOAR, new_buffer(), and realloc().

Referenced by rz_cons_memcat(), rz_cons_memset(), and rz_cons_printf_list().

◆ real_strlen()

static int real_strlen ( const char *  ptr,
int  len 
)
static

Definition at line 1087 of file cons.c.

1087  {
1088  int utf8len = rz_str_len_utf8(ptr);
1089  int ansilen = rz_str_ansi_len(ptr);
1090  int diff = len - utf8len;
1091  if (diff > 0) {
1092  diff--;
1093  }
1094  return ansilen - diff;
1095 }
RZ_API size_t rz_str_ansi_len(const char *str)
Definition: str.c:1945
RZ_API size_t rz_str_len_utf8(const char *s)
Definition: str.c:2709

References len, rz_str_ansi_len(), and rz_str_len_utf8().

Referenced by rz_cons_visual_write().

◆ resizeWin()

void resizeWin ( void  )

Definition at line 471 of file cons.c.

471  {
472  if (I.event_resize) {
473  I.event_resize(I.event_data);
474  }
475 }

References I.

Referenced by rz_cons_readchar().

◆ rz_cons_bind()

RZ_API void rz_cons_bind ( RzConsBind bind)

Definition at line 1910 of file cons.c.

1910  {
1911  if (!bind) {
1912  return;
1913  }
1914  bind->get_size = rz_cons_get_size;
1915  bind->get_cursor = rz_cons_get_cursor;
1916  bind->cb_printf = rz_cons_printf;
1917  bind->cb_flush = rz_cons_flush;
1918  bind->cb_grep = rz_cons_grep;
1919  bind->is_breaked = rz_cons_is_breaked;
1920 }
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API int rz_cons_get_cursor(RZ_NONNULL int *rows)
Calculates the aproximated x,y coordinates of the cursor before flushing.
Definition: cons.c:1298
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API void rz_cons_grep(const char *grep)
Definition: grep.c:874
static bind
Definition: sfsocketcall.h:114

References bind, rz_cons_flush(), rz_cons_get_cursor(), rz_cons_get_size(), rz_cons_grep(), rz_cons_is_breaked(), and rz_cons_printf().

Referenced by rz_core_init().

◆ rz_cons_break_clear()

RZ_API void rz_cons_break_clear ( void  )

Definition at line 304 of file cons.c.

304  {
305  CTX(breaked) = false;
306 }
static bool breaked

References breaked, and CTX.

◆ rz_cons_break_end()

RZ_API void rz_cons_break_end ( void  )

Definition at line 427 of file cons.c.

427  {
428  CTX(breaked) = false;
429  I.timeout = 0;
430 #if __UNIX__
431  rz_sys_signal(SIGINT, SIG_IGN);
432 #endif
433  if (!rz_stack_is_empty(CTX(break_stack))) {
434  // free all the stack
435  rz_stack_free(CTX(break_stack));
436  // create another one
437  CTX(break_stack) = rz_stack_newf(6, break_stack_free);
438  CTX(event_interrupt_data) = NULL;
439  CTX(event_interrupt) = NULL;
440  }
441 }
RZ_API bool rz_stack_is_empty(RzStack *s)
Definition: stack.c:68
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
Definition: sys.c:178

References break_stack_free(), breaked, CTX, I, NULL, rz_stack_free(), rz_stack_is_empty(), rz_stack_newf(), and rz_sys_signal().

Referenced by set_layout().

◆ rz_cons_break_pop()

RZ_API void rz_cons_break_pop ( void  )

Definition at line 361 of file cons.c.

361  {
362  rz_cons_context_break_pop(I.context, true);
363 }
RZ_API void rz_cons_context_break_pop(RzConsContext *context, bool sig)
Definition: cons.c:335

References I, and rz_cons_context_break_pop().

Referenced by __read(), _analysis_calls(), agraph_print_edges(), cmd_dcu(), cmd_search_bin(), core_perform_auto_analysis(), debug_trace_calls(), DEFINE_HANDLE_TS_FCN(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_analysis_search(), do_asm_search(), do_esil_search(), do_section_search(), do_string_search(), do_syscall_search(), draw_horizontal_line(), draw_vertical_line(), gdbr_connect(), gdbr_lock_leave(), lang_pipe_run(), linux_dbg_wait(), macro_call(), print_cmd_analysis_after_traps_print(), rtr_visual(), rtti_msvc_read_base_class_array(), rz_analysis_class_recover_from_rzbin(), rz_analysis_reflines_get(), rz_analysis_rtti_print_all(), rz_analysis_rtti_recover_all(), rz_analysis_vtable_search(), rz_cmd_debug(), rz_cmd_debug_continue_back_handler(), rz_cmd_debug_continue_call_handler(), rz_cmd_debug_continue_exception_handler(), rz_cmd_debug_continue_execution_handler(), rz_cmd_debug_continue_fork_handler(), rz_cmd_debug_continue_mapped_io_handler(), rz_cmd_debug_continue_ret_handler(), rz_cmd_debug_continue_send_signal_handler(), rz_cmd_debug_continue_syscall(), rz_cmd_debug_continue_traptrace_handler(), rz_cmd_debug_continue_unknown_call_handler(), rz_cmd_debug_continue_until(), rz_cmd_debug_step_cond_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_print(), rz_cmd_search(), rz_cmd_sizes_of_n_instructions_handler(), rz_cons_canvas_write(), rz_cons_flush(), rz_core_analysis_all(), rz_core_analysis_calls(), rz_core_analysis_cycles(), rz_core_analysis_esil(), rz_core_analysis_search(), rz_core_analysis_search_xrefs(), rz_core_analysis_type_match(), rz_core_analysis_value_pointers(), rz_core_asm_strsearch(), rz_core_bin_apply_strings(), rz_core_bin_print_source_line_info(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_subst(), rz_core_cmd_subst_i(), rz_core_debug_continue(), rz_core_debug_continue_until(), rz_core_debug_single_step_over(), rz_core_debug_step_until_frame(), rz_core_disasm_pdi_with_buf(), rz_core_dump(), rz_core_esil_step(), rz_core_link_stroff(), rz_core_print_disasm(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions_with_buf(), rz_core_rtr_cmds(), rz_core_rtr_http_run(), rz_core_search_rop(), rz_core_search_value_in_range(), rz_core_serve(), rz_core_visual_define(), rz_core_visual_graph(), rz_debug_bochs_wait(), rz_debug_continue_kill(), rz_debug_esil_step(), rz_line_readline_cb(), search_collisions(), search_hash(), search_similar_pattern(), set_layout(), step_until(), step_until_esil(), step_until_flag(), step_until_inst(), step_until_optype(), type_match(), update_graph_sizes(), w32_dbg_wait(), windbg_wait(), winkd_lock_enter(), and winkd_lock_leave().

◆ rz_cons_break_push()

RZ_API void rz_cons_break_push ( RzConsBreak  cb,
void *  user 
)

Definition at line 357 of file cons.c.

357  {
358  rz_cons_context_break_push(I.context, cb, user, true);
359 }
RZ_API void rz_cons_context_break_push(RzConsContext *context, RzConsBreak cb, void *user, bool sig)
Definition: cons.c:308
static const char * cb[]
Definition: z80_tab.h:176

References cb, I, and rz_cons_context_break_push().

Referenced by __read(), _analysis_calls(), cmd_dcu(), cmd_search_bin(), core_perform_auto_analysis(), debug_trace_calls(), DEFINE_HANDLE_TS_FCN(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_analysis_search(), do_asm_search(), do_esil_search(), do_section_search(), do_string_search(), do_syscall_search(), draw_horizontal_line(), draw_vertical_line(), gdbr_connect(), gdbr_lock_enter(), gdbr_lock_tryenter(), lang_pipe_run(), linux_dbg_wait(), macro_call(), print_cmd_analysis_after_traps_print(), rtr_visual(), rtti_msvc_read_base_class_array(), rz_analysis_class_recover_from_rzbin(), rz_analysis_reflines_get(), rz_analysis_rtti_print_all(), rz_analysis_rtti_recover_all(), rz_analysis_vtable_search(), rz_cmd_debug(), rz_cmd_debug_continue_back_handler(), rz_cmd_debug_continue_call_handler(), rz_cmd_debug_continue_exception_handler(), rz_cmd_debug_continue_execution_handler(), rz_cmd_debug_continue_fork_handler(), rz_cmd_debug_continue_mapped_io_handler(), rz_cmd_debug_continue_ret_handler(), rz_cmd_debug_continue_send_signal_handler(), rz_cmd_debug_continue_syscall(), rz_cmd_debug_continue_traptrace_handler(), rz_cmd_debug_continue_unknown_call_handler(), rz_cmd_debug_continue_until(), rz_cmd_debug_step_cond_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_print(), rz_cmd_search(), rz_cmd_sizes_of_n_instructions_handler(), rz_cons_canvas_write(), rz_cons_flush(), rz_core_analysis_all(), rz_core_analysis_calls(), rz_core_analysis_cycles(), rz_core_analysis_esil(), rz_core_analysis_search(), rz_core_analysis_search_xrefs(), rz_core_analysis_type_match(), rz_core_analysis_value_pointers(), rz_core_asm_strsearch(), rz_core_bin_apply_strings(), rz_core_bin_print_source_line_info(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_subst(), rz_core_cmd_subst_i(), rz_core_debug_continue(), rz_core_debug_continue_until(), rz_core_debug_single_step_over(), rz_core_debug_step_until_frame(), rz_core_disasm_pdi_with_buf(), rz_core_dump(), rz_core_esil_step(), rz_core_link_stroff(), rz_core_print_disasm(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions_with_buf(), rz_core_rtr_cmds(), rz_core_rtr_http_run(), rz_core_search_rop(), rz_core_search_value_in_range(), rz_core_serve(), rz_core_visual_define(), rz_core_visual_graph(), rz_debug_bochs_wait(), rz_debug_esil_step(), rz_line_readline_cb(), search_collisions(), search_hash(), search_similar_pattern(), step_until(), step_until_esil(), step_until_flag(), step_until_inst(), step_until_optype(), type_match(), w32_dbg_wait(), windbg_wait(), and winkd_lock_enter().

◆ rz_cons_break_timeout()

RZ_API void rz_cons_break_timeout ( int  timeout)

Definition at line 421 of file cons.c.

421  {
422  I.timeout = (timeout && !I.timeout)
423  ? rz_time_now_mono() + ((ut64)timeout << 20)
424  : 0;
425 }
RZ_API ut64 rz_time_now_mono(void)
Returns the current time in microseconds, using the monotonic clock.
Definition: time.c:102
uv_timer_t timeout
Definition: main.c:9
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References I, rz_time_now_mono(), timeout, and ut64().

Referenced by core_perform_auto_analysis().

◆ rz_cons_breakword()

RZ_API void rz_cons_breakword ( RZ_NULLABLE const char *  s)

Definition at line 1939 of file cons.c.

1939  {
1940  free(I.break_word);
1941  if (s) {
1942  I.break_word = strdup(s);
1943  I.break_word_len = strlen(s);
1944  } else {
1945  I.break_word = NULL;
1946  I.break_word_len = 0;
1947  }
1948 }

References free(), I, NULL, s, and strdup().

Referenced by cb_scrbreakword().

◆ rz_cons_chop()

RZ_API void rz_cons_chop ( void  )

Definition at line 1900 of file cons.c.

1900  {
1901  while (CTX(buffer_len) > 0) {
1902  char ch = CTX(buffer)[CTX(buffer_len) - 1];
1903  if (ch != '\n' && !IS_WHITESPACE(ch)) {
1904  break;
1905  }
1906  (CTX(buffer_len))--;
1907  }
1908 }
#define IS_WHITESPACE(x)
Definition: rz_str_util.h:13

References CTX, and IS_WHITESPACE.

Referenced by print_fcn_arg().

◆ rz_cons_clear()

RZ_API void rz_cons_clear ( void  )

◆ rz_cons_clear00()

◆ rz_cons_clear_buffer()

RZ_API void rz_cons_clear_buffer ( void  )

Definition at line 1992 of file cons.c.

1992  {
1993  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
1994  rz_xwrite(1, "\x1b"
1995  "c\x1b[3J",
1996  6);
1997  }
1998 }

References I, RZ_VIRT_TERM_MODE_DISABLE, and rz_xwrite.

◆ rz_cons_clear_line()

RZ_API void rz_cons_clear_line ( int  std_err)

Definition at line 756 of file cons.c.

756  {
757 #if __WINDOWS__
758  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
759  fprintf(std_err ? stderr : stdout, "%s", RZ_CONS_CLEAR_LINE);
760  } else {
761  char white[1024];
762  memset(&white, ' ', sizeof(white));
763  if (I.columns > 0 && I.columns < sizeof(white)) {
764  white[I.columns - 1] = 0;
765  } else if (I.columns == 0) {
766  white[0] = 0;
767  } else {
768  white[sizeof(white) - 1] = 0; // HACK
769  }
770  fprintf(std_err ? stderr : stdout, "\r%s\r", white);
771  }
772 #else
773  fprintf(std_err ? stderr : stdout, "%s", RZ_CONS_CLEAR_LINE);
774 #endif
775  fflush(std_err ? stderr : stdout);
776 }
return memset(p, 0, total)
#define RZ_CONS_CLEAR_LINE
Definition: rz_cons.h:593

References I, memset(), RZ_CONS_CLEAR_LINE, and RZ_VIRT_TERM_MODE_DISABLE.

Referenced by __core_analysis_fcn(), __print_prompt(), core_perform_auto_analysis(), do_esil_search(), do_string_search(), goto_asmqjmps(), loganalysis(), print_rline_task(), rz_analyze_cycles_handler(), rz_cmd_analysis(), rz_cmd_search(), rz_core_analysis_cycles(), rz_core_magic_at(), rz_line_readline_cb(), and visual_prompt().

◆ rz_cons_cmd_help()

RZ_API void rz_cons_cmd_help ( const char *  help[],
bool  use_color 
)

Definition at line 1954 of file cons.c.

1954  {
1955  RzCons *cons = rz_cons_singleton();
1956  const char *pal_args_color = use_color ? cons->context->pal.args : "",
1957  *pal_help_color = use_color ? cons->context->pal.help : "",
1958  *pal_input_color = use_color ? cons->context->pal.input : "",
1959  *pal_reset = use_color ? cons->context->pal.reset : "";
1960  int i, max_length = 0;
1961  const char *usage_str = "Usage:";
1962 
1963  for (i = 0; help[i]; i += 3) {
1964  int len0 = strlen(help[i]);
1965  int len1 = strlen(help[i + 1]);
1966  if (i) {
1967  max_length = RZ_MAX(max_length, len0 + len1);
1968  }
1969  }
1970 
1971  for (i = 0; help[i]; i += 3) {
1972  if (!strncmp(help[i], usage_str, strlen(usage_str))) {
1973  // Lines matching Usage: should always be the first in inline doc
1974  rz_cons_printf("%s%s %s %s%s\n", pal_args_color,
1975  help[i], help[i + 1], help[i + 2], pal_reset);
1976  continue;
1977  }
1978  if (!help[i + 1][0] && !help[i + 2][0]) {
1979  // no need to indent the sections lines
1980  rz_cons_printf("%s%s%s\n", pal_help_color, help[i], pal_reset);
1981  } else {
1982  // these are the normal lines
1983  int str_length = strlen(help[i]) + strlen(help[i + 1]);
1984  int padding = (str_length < max_length) ? (max_length - str_length) : 0;
1985  rz_cons_printf("| %s%s%s%s%*s %s%s%s\n",
1986  pal_input_color, help[i], pal_args_color, help[i + 1],
1987  padding, "", pal_help_color, help[i + 2], pal_reset);
1988  }
1989  }
1990 }
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
#define RZ_MAX(x, y)
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502

References rz_cons_printable_palette_t::args, rz_cons_t::context, cmd_descs_generate::help, rz_cons_printable_palette_t::help, i, rz_cons_printable_palette_t::input, rz_cons_context_t::pal, rz_cons_printable_palette_t::reset, rz_cons_printf(), rz_cons_singleton(), and RZ_MAX.

Referenced by rz_cons_grep_help(), and rz_core_cmd_help().

◆ rz_cons_color()

RZ_API void rz_cons_color ( int  fg,
int  r,
int  g,
int  b 
)

Definition at line 217 of file cons.c.

217  {
218  int k;
219  r = RZ_DIM(r, 0, 255);
220  g = RZ_DIM(g, 0, 255);
221  b = RZ_DIM(b, 0, 255);
222  if (r == g && g == b) { // b&w
223  k = 232 + (int)(((r + g + b) / 3) / 10.3);
224  } else {
225  r = (int)(r / 42.6);
226  g = (int)(g / 42.6);
227  b = (int)(b / 42.6);
228  k = 16 + (r * 36) + (g * 6) + b;
229  }
230  rz_cons_printf("\x1b[%d;5;%dm", fg ? 48 : 38, k);
231 }
#define r
Definition: crypto_rc6.c:12
const char * k
Definition: dsignal.c:11
struct @667 g
#define RZ_DIM(x, y, z)
static int
Definition: sfsocketcall.h:114

References b, g, int, k, r, rz_cons_printf(), and RZ_DIM.

◆ rz_cons_color_random()

RZ_API RzColor rz_cons_color_random ( ut8  alpha)

Definition at line 183 of file cons.c.

183  {
184  RzColor rcolor = { 0 };
185  if (CTX(color_mode) > COLOR_MODE_16) {
186  rcolor.r = rz_num_rand(0xff);
187  rcolor.g = rz_num_rand(0xff);
188  rcolor.b = rz_num_rand(0xff);
189  rcolor.a = alpha;
190  return rcolor;
191  }
192  int r = rz_num_rand(16);
193  switch (r) {
194  case 0:
195  case 1: rcolor = (RzColor)RzColor_RED; break;
196  case 2:
197  case 3: rcolor = (RzColor)RzColor_WHITE; break;
198  case 4:
199  case 5: rcolor = (RzColor)RzColor_GREEN; break;
200  case 6:
201  case 7: rcolor = (RzColor)RzColor_MAGENTA; break;
202  case 8:
203  case 9: rcolor = (RzColor)RzColor_YELLOW; break;
204  case 10:
205  case 11: rcolor = (RzColor)RzColor_CYAN; break;
206  case 12:
207  case 13: rcolor = (RzColor)RzColor_BLUE; break;
208  case 14:
209  case 15: rcolor = (RzColor)RzColor_GRAY; break;
210  }
211  if (r & 1) {
213  }
214  return rcolor;
215 }
RzColor rcolor
Definition: pal.c:97
#define RzColor_WHITE
Definition: rz_cons.h:706
@ COLOR_MODE_16
Definition: rz_cons.h:443
#define RzColor_YELLOW
Definition: rz_cons.h:712
#define RzColor_RED
Definition: rz_cons.h:704
#define RzColor_GREEN
Definition: rz_cons.h:708
struct rcolor_t RzColor
#define RzColor_MAGENTA
Definition: rz_cons.h:710
#define RzColor_GRAY
Definition: rz_cons.h:735
@ RZ_CONS_ATTR_BOLD
Definition: rz_cons.h:171
#define RzColor_CYAN
Definition: rz_cons.h:714
#define RzColor_BLUE
Definition: rz_cons.h:716
RZ_API int rz_num_rand(int max)
Definition: unum.c:47
ut8 g
Definition: rz_cons.h:183
ut8 b
Definition: rz_cons.h:184
ut8 r
Definition: rz_cons.h:182
ut8 a
Definition: rz_cons.h:181
ut8 attr
Definition: rz_cons.h:180

References rcolor_t::a, rcolor_t::attr, rcolor_t::b, COLOR_MODE_16, CTX, rcolor_t::g, r, rcolor_t::r, rcolor, RZ_CONS_ATTR_BOLD, rz_num_rand(), RzColor_BLUE, RzColor_CYAN, RzColor_GRAY, RzColor_GREEN, RzColor_MAGENTA, RzColor_RED, RzColor_WHITE, and RzColor_YELLOW.

Referenced by rz_cons_pal_parse(), and rz_cons_pal_random().

◆ rz_cons_column()

RZ_API void rz_cons_column ( int  c)

Definition at line 1707 of file cons.c.

1707  {
1708  char *b = malloc(CTX(buffer_len) + 1);
1709  if (!b) {
1710  return;
1711  }
1712  memcpy(b, CTX(buffer), CTX(buffer_len));
1713  b[CTX(buffer_len)] = 0;
1714  rz_cons_reset();
1715  // align current buffer N chars right
1716  rz_cons_strcat_justify(b, c, 0);
1717  rz_cons_gotoxy(0, 0);
1718  free(b);
1719 }
RZ_API void rz_cons_strcat_justify(const char *str, int j, char c)
Definition: cons.c:238
RZ_API void rz_cons_reset(void)
Definition: cons.c:804
#define c(i)
Definition: sha256.c:43

References b, c, CTX, free(), malloc(), memcpy(), rz_cons_gotoxy(), rz_cons_reset(), and rz_cons_strcat_justify().

Referenced by rz_cmd_help(), rz_core_visual_analysis_refresh(), and visual_refresh().

◆ rz_cons_context_break()

RZ_API void rz_cons_context_break ( RzConsContext context)

Definition at line 917 of file cons.c.

917  {
918  if (!context) {
920  }
921  context->breaked = true;
922  if (context->event_interrupt) {
923  context->event_interrupt(context->event_interrupt_data);
924  }
925 }

References rz_cons_context_default.

Referenced by __break_signal(), and rz_core_task_break_cb().

◆ rz_cons_context_break_pop()

RZ_API void rz_cons_context_break_pop ( RzConsContext context,
bool  sig 
)

Definition at line 335 of file cons.c.

335  {
336  if (!context->break_stack) {
337  return;
338  }
339  // restore old state
341  b = rz_stack_pop(context->break_stack);
342  if (b) {
343  context->event_interrupt = b->event_interrupt;
344  context->event_interrupt_data = b->event_interrupt_data;
346  } else {
347  // there is not more elements in the stack
348 #if __UNIX__
349  if (sig && rz_cons_context_is_main()) {
350  rz_sys_signal(SIGINT, SIG_IGN);
351  }
352 #endif
353  context->breaked = false;
354  }
355 }
RZ_API bool rz_cons_context_is_main(void)
Definition: cons.c:913
RZ_API void * rz_stack_pop(RzStack *s)
Definition: stack.c:59

References b, break_stack_free(), NULL, rz_cons_context_is_main(), rz_stack_pop(), and rz_sys_signal().

Referenced by core_task_ctx_fini(), and rz_cons_break_pop().

◆ rz_cons_context_break_push()

RZ_API void rz_cons_context_break_push ( RzConsContext context,
RzConsBreak  cb,
void *  user,
bool  sig 
)

Definition at line 308 of file cons.c.

308  {
309  if (!context->break_stack) {
310  return;
311  }
312 
313  // if we don't have any element in the stack start the signal
315  if (!b) {
316  return;
317  }
318  if (rz_stack_is_empty(context->break_stack)) {
319 #if __UNIX__
320  if (sig && rz_cons_context_is_main()) {
321  rz_sys_signal(SIGINT, __break_signal);
322  }
323 #endif
324  context->breaked = false;
325  }
326  // save the actual state
327  b->event_interrupt = context->event_interrupt;
328  b->event_interrupt_data = context->event_interrupt_data;
329  rz_stack_push(context->break_stack, b);
330  // configure break
331  context->event_interrupt = cb;
332  context->event_interrupt_data = user;
333 }
static void __break_signal(int sig)
Definition: cons.c:146
RZ_API bool rz_stack_push(RzStack *s, void *el)
Definition: stack.c:42

References __break_signal(), b, cb, rz_cons_context_is_main(), RZ_NEW0, rz_stack_is_empty(), rz_stack_push(), and rz_sys_signal().

Referenced by core_task_ctx_init(), and rz_cons_break_push().

◆ rz_cons_context_free()

RZ_API void rz_cons_context_free ( RzConsContext context)

Definition at line 897 of file cons.c.

897  {
898  if (!context) {
899  return;
900  }
902  free(context);
903 }
static void cons_context_deinit(RzConsContext *context)
Definition: cons.c:138

References cons_context_deinit(), and free().

Referenced by core_task_ctx_fini().

◆ rz_cons_context_is_main()

RZ_API bool rz_cons_context_is_main ( void  )

Definition at line 913 of file cons.c.

913  {
914  return I.context == &rz_cons_context_default;
915 }

References I, and rz_cons_context_default.

Referenced by linux_dbg_wait(), rz_cons_context_break_pop(), and rz_cons_context_break_push().

◆ rz_cons_context_load()

RZ_API void rz_cons_context_load ( RzConsContext context)

Definition at line 905 of file cons.c.

905  {
906  I.context = context;
907 }

References I.

Referenced by rz_core_task_ctx_switch().

◆ rz_cons_context_new()

RZ_API RzConsContext* rz_cons_context_new ( RZ_NULLABLE RzConsContext parent)

Definition at line 888 of file cons.c.

888  {
890  if (!context) {
891  return NULL;
892  }
893  cons_context_init(context, parent);
894  return context;
895 }
static void cons_context_init(RzConsContext *context, RZ_NULLABLE RzConsContext *parent)
Definition: cons.c:111

References cons_context_init(), NULL, and RZ_NEW0.

Referenced by core_task_ctx_init().

◆ rz_cons_context_reset()

RZ_API void rz_cons_context_reset ( void  )

Definition at line 909 of file cons.c.

909  {
910  I.context = &rz_cons_context_default;
911 }

References I, and rz_cons_context_default.

Referenced by rz_core_task_ctx_switch().

◆ rz_cons_default_context_is_interactive()

RZ_API bool rz_cons_default_context_is_interactive ( void  )

Definition at line 369 of file cons.c.

369  {
371 }
bool is_interactive
Definition: rz_cons.h:485

References rz_cons_context_t::is_interactive, and rz_cons_context_default.

Referenced by cmd_task_runner().

◆ rz_cons_drop()

RZ_API bool rz_cons_drop ( int  n)

Definition at line 1891 of file cons.c.

1891  {
1892  if (n > CTX(buffer_len)) {
1893  CTX(buffer_len) = 0;
1894  return false;
1895  }
1896  CTX(buffer_len) -= n;
1897  return true;
1898 }
int n
Definition: mipsasm.c:19

References CTX, and n.

Referenced by ds_print_meta_infos(), and rz_analysis_rtti_print_all().

◆ rz_cons_echo()

RZ_API void rz_cons_echo ( const char *  msg)

Definition at line 939 of file cons.c.

939  {
940  static RzStrBuf *echodata = NULL; // TODO: move into RzConsInstance? maybe nope
941  if (msg) {
942  if (echodata) {
943  rz_strbuf_append(echodata, msg);
944  rz_strbuf_append(echodata, "\n");
945  } else {
946  echodata = rz_strbuf_new(msg);
947  }
948  } else {
949  if (echodata) {
950  char *data = rz_strbuf_drain(echodata);
951  rz_cons_strcat(data);
952  rz_cons_newline();
953  echodata = NULL;
954  free(data);
955  }
956  }
957 }
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119

References free(), msg, NULL, rz_cons_newline(), rz_cons_strcat(), rz_strbuf_append(), rz_strbuf_drain(), and rz_strbuf_new().

Referenced by __handle_cmd_str_cache(), core_cmd_raw(), core_cmd_raw_node(), rz_core_prompt_exec(), and rz_core_visual_prompt().

◆ rz_cons_enable_highlight()

RZ_API void rz_cons_enable_highlight ( const bool  enable)

Definition at line 496 of file cons.c.

496  {
497  I.enable_highlight = enable;
498 }

References I.

Referenced by cmd_analysis_graph(), and rz_cons_highlight().

◆ rz_cons_enable_mouse()

RZ_API bool rz_cons_enable_mouse ( const bool  enable)

Definition at line 500 of file cons.c.

500  {
501  if ((I.mouse && enable) || (!I.mouse && !enable)) {
502  return I.mouse;
503  }
504 #if __WINDOWS__
505  if (I.vtmode == RZ_VIRT_TERM_MODE_COMPLETE) {
506 #endif
507  const char *click = enable
508  ? "\x1b[?1000;1006;1015h"
509  : "\x1b[?1000;1006;1015l";
510  // const char *old = enable ? "\x1b[?1001s" "\x1b[?1000h" : "\x1b[?1001r" "\x1b[?1000l";
511  bool enabled = I.mouse;
512  const size_t click_len = strlen(click);
513  if (write(2, click, click_len) != click_len) {
514  return false;
515  }
516  I.mouse = enable;
517  return enabled;
518 #if __WINDOWS__
519  }
520  DWORD mode;
521  HANDLE h;
522  bool enabled = I.mouse;
523  h = GetStdHandle(STD_INPUT_HANDLE);
524  GetConsoleMode(h, &mode);
526  mode = enable
527  ? (mode | ENABLE_MOUSE_INPUT) & ~ENABLE_QUICK_EDIT_MODE
528  : (mode & ~ENABLE_MOUSE_INPUT) | ENABLE_QUICK_EDIT_MODE;
529  if (SetConsoleMode(h, mode)) {
530  I.mouse = enable;
531  }
532  return enabled;
533 #else
534  return false;
535 #endif
536 }
static static fork write
Definition: sflib.h:33
const char int mode
Definition: ioapi.h:137
@ RZ_VIRT_TERM_MODE_COMPLETE
All the sequences goes through VT (Windows Terminal, mintty, all OSs)
Definition: rz_cons.h:451
#define h(i)
Definition: sha256.c:48
#define ENABLE_QUICK_EDIT_MODE
Definition: winapi.h:4629
#define ENABLE_EXTENDED_FLAGS
Definition: winapi.h:4633
DWORD * HANDLE
DWORD

References DWORD, ENABLE_EXTENDED_FLAGS, ENABLE_QUICK_EDIT_MODE, h, HANDLE, I, RZ_VIRT_TERM_MODE_COMPLETE, and write.

Referenced by __holdMouseState(), __panels_process(), add_comment(), agraph_follow_innodes(), cmd_analysis_graph(), rz_cons_controlz(), rz_cons_fgets(), rz_cons_hud(), rz_core_agraph_print_interactive(), rz_core_graph_print(), rz_core_visual(), rz_core_visual_cmd(), rz_core_visual_panels_root(), rz_core_visual_prompt_input(), rz_core_visual_showcursor(), rz_core_visual_xrefs(), rz_diff_hex_visual(), rz_line_readline_cb(), showcursor(), and visual_comma().

◆ rz_cons_eof()

RZ_API int rz_cons_eof ( void  )

Definition at line 720 of file cons.c.

720  {
721  return feof(I.fdin);
722 }

References I.

◆ rz_cons_fill_line()

RZ_API void rz_cons_fill_line ( void  )

Definition at line 737 of file cons.c.

737  {
738  char *p, white[1024];
739  int cols = I.columns - 1;
740  if (cols < 1) {
741  return;
742  }
743  p = (cols >= sizeof(white))
744  ? malloc(cols + 1)
745  : white;
746  if (p) {
747  memset(p, ' ', cols);
748  p[cols] = 0;
749  rz_cons_strcat(p);
750  if (white != p) {
751  free(p);
752  }
753  }
754 }
void * p
Definition: libc.cpp:67

References free(), I, malloc(), memset(), p, and rz_cons_strcat().

Referenced by handleHints(), and rz_core_visual_define().

◆ rz_cons_filter()

RZ_API void rz_cons_filter ( void  )

Definition at line 836 of file cons.c.

836  {
837  /* grep */
838  if (I.filter || CTX(grep).nstrings > 0 || CTX(grep).tokens_used || CTX(grep).less || CTX(grep).json) {
839  (void)rz_cons_grepbuf();
840  I.filter = false;
841  }
842  /* html */
843  if (I.is_html) {
844  int newlen = 0;
845  char *input = rz_str_ndup(CTX(buffer), CTX(buffer_len));
846  char *res = rz_cons_html_filter(input, &newlen);
847  free(CTX(buffer));
848  CTX(buffer) = res;
849  CTX(buffer_len) = newlen;
850  CTX(buffer_sz) = newlen;
852  free(input);
853  }
854  if (I.was_html) {
855  I.is_html = true;
856  I.was_html = false;
857  }
858 }
RZ_API void rz_cons_grepbuf(void)
Definition: grep.c:463
RZ_API char * rz_cons_html_filter(const char *ptr, int *newlen)
Definition: html.c:34
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References CTX, ctx_rowcol_calc_reset(), free(), I, input(), rz_cons_grepbuf(), rz_cons_html_filter(), and rz_str_ndup().

Referenced by core_cmd_raw(), core_cmd_raw_node(), oldinput_get_help(), and rz_cons_flush().

◆ rz_cons_flush()

RZ_API void rz_cons_flush ( void  )

Definition at line 959 of file cons.c.

959  {
960  const char *tee = I.teefile;
961  if (CTX(noflush)) {
962  return;
963  }
964  if (I.null) {
965  rz_cons_reset();
966  return;
967  }
968  if (lastMatters() && !CTX(lastMode)) {
969  // snapshot of the output
970  if (CTX(buffer_len) > CTX(lastLength)) {
971  free(CTX(lastOutput));
972  CTX(lastOutput) = malloc(CTX(buffer_len) + 1);
973  }
974  CTX(lastLength) = CTX(buffer_len);
975  memcpy(CTX(lastOutput), CTX(buffer), CTX(buffer_len));
976  } else {
977  CTX(lastMode) = false;
978  }
979  rz_cons_filter();
980  if (rz_cons_is_interactive() && I.fdout == 1) {
981  /* Use a pager if the output doesn't fit on the terminal window. */
982  if (CTX(pageable) && CTX(buffer) && I.pager && *I.pager && CTX(buffer_len) > 0 && rz_str_char_count(CTX(buffer), '\n') >= I.rows) {
983  (CTX(buffer))[CTX(buffer_len) - 1] = 0;
984  if (!strcmp(I.pager, "..")) {
985  char *str = rz_str_ndup(CTX(buffer), CTX(buffer_len));
986  CTX(pageable) = false;
988  rz_cons_reset();
989  free(str);
990  return;
991  } else {
993  rz_cons_reset();
994  }
995  } else if (CTX(buffer_len) > CONS_MAX_USER) {
996 #if COUNT_LINES
997  int i, lines = 0;
998  for (i = 0; CTX(buffer)[i]; i++) {
999  if (CTX(buffer)[i] == '\n') {
1000  lines++;
1001  }
1002  }
1003  if (lines > 0 && !rz_cons_yesno('n', "Do you want to print %d lines? (y/N)", lines)) {
1004  rz_cons_reset();
1005  return;
1006  }
1007 #else
1008  char buf[8];
1009  rz_num_units(buf, sizeof(buf), CTX(buffer_len));
1010  if (!rz_cons_yesno('n', "Do you want to print %s chars? (y/N)", buf)) {
1011  rz_cons_reset();
1012  return;
1013  }
1014 #endif
1015  // fix | more | less problem
1016  rz_cons_set_raw(true);
1017  }
1018  }
1019  if (tee && *tee) {
1020  FILE *d = rz_sys_fopen(tee, "a+");
1021  if (d) {
1022  if (CTX(buffer_len) != fwrite(CTX(buffer), 1, CTX(buffer_len), d)) {
1023  eprintf("rz_cons_flush: fwrite: error (%s)\n", tee);
1024  }
1025  fclose(d);
1026  } else {
1027  eprintf("Cannot write on '%s'\n", tee);
1028  }
1029  }
1030  rz_cons_highlight(I.highlight);
1031 
1032  // is_html must be a filter, not a write endpoint
1033  if (rz_cons_is_interactive()) {
1034  if (I.linesleep > 0 && I.linesleep < 1000) {
1035  int i = 0;
1036  int pagesize = RZ_MAX(1, I.pagesize);
1037  char *ptr = CTX(buffer);
1038  char *nl = strchr(ptr, '\n');
1039  int len = CTX(buffer_len);
1040  (CTX(buffer))[CTX(buffer_len)] = 0;
1042  while (nl && !rz_cons_is_breaked()) {
1043  __cons_write(ptr, nl - ptr + 1);
1044  if (I.linesleep && !(i % pagesize)) {
1045  rz_sys_usleep(I.linesleep * 1000);
1046  }
1047  ptr = nl + 1;
1048  nl = strchr(ptr, '\n');
1049  i++;
1050  }
1051  __cons_write(ptr, CTX(buffer) + len - ptr);
1053  } else {
1054  __cons_write(CTX(buffer), CTX(buffer_len));
1055  }
1056  } else {
1057  __cons_write(CTX(buffer), CTX(buffer_len));
1058  }
1059 
1060  rz_cons_reset();
1061  if (I.newline) {
1062  eprintf("\n");
1063  I.newline = false;
1064  }
1065 }
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
static bool lastMatters(void)
Definition: cons.c:935
RZ_API void rz_cons_filter(void)
Definition: cons.c:836
RZ_API void rz_cons_set_raw(bool is_raw)
Definition: cons.c:1617
RZ_API void rz_cons_highlight(const char *word)
Definition: cons.c:1756
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
static void __cons_write(const char *obuf, int olen)
Definition: cons.c:169
RZ_API bool rz_cons_yesno(int def, const char *fmt,...)
Definition: input.c:666
RZ_API int rz_cons_less_str(const char *str, const char *exitkeys)
Definition: less.c:10
string FILE
Definition: benchmark.py:21
#define eprintf(x, y...)
Definition: rlcc.c:7
#define CONS_MAX_USER
Definition: rz_cons.h:41
RZ_API char * rz_num_units(char *buf, size_t len, ut64 number)
Definition: unum.c:108
RZ_API int rz_str_char_count(const char *string, char ch)
Definition: str.c:611
RZ_API FILE * rz_sys_fopen(const char *path, const char *mode)
Definition: sys.c:1815
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
Definition: sys.c:317
RZ_API int rz_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr)
Definition: sys.c:590
#define d(i)
Definition: sha256.c:44

References __cons_write(), CONS_MAX_USER, CTX, d, eprintf, benchmark::FILE, free(), I, i, lastMatters(), len, lines(), malloc(), memcpy(), NULL, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_filter(), rz_cons_highlight(), rz_cons_is_breaked(), rz_cons_is_interactive(), rz_cons_less_str(), rz_cons_reset(), rz_cons_set_raw(), rz_cons_yesno(), RZ_MAX, rz_num_units(), rz_str_char_count(), rz_str_ndup(), rz_sys_cmd_str_full(), rz_sys_fopen(), rz_sys_usleep(), and cmd_descs_generate::str.

Referenced by __calculator_cb(), __cons_cb_fkey(), __continue_cb(), __core_visual_view_graph_update(), __handle_tab(), __handle_visual_mark(), __io_continue(), __io_kill(), __listPlugins(), __panel_all_clear(), __panels_refresh(), __print_prompt(), __rap_reg_profile(), __rtr_shell(), __show_status(), __show_status_input(), __show_status_yesno(), __system_shell_cb(), __update_modal(), add_comment(), agraph_follow_innodes(), agraph_print(), agraph_refresh(), config_visual_hit(), convert_dot_str_to_image(), convert_dotcmd_to_image(), core_basefind_progess_status(), DEFINE_HANDLE_TS_FCN(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_iter_offsets(), find_autocomplete(), foreachOffset(), goto_asmqjmps(), handleHints(), macro_call(), nextword(), pager_printpage(), print_rline_task(), rabin_do_operation(), readline_callback(), rtr_visual(), run_commands(), rz_analyze_cycles_handler(), rz_cmd_debug_dmi(), rz_cmd_debug_map_current_handler(), rz_cmd_help(), rz_cmd_kuery(), rz_cons_any_key(), rz_cons_bind(), rz_cons_fgets(), rz_cons_memcat(), rz_cons_message(), rz_core_cmd_foreach(), rz_core_cmd_pipe_old(), rz_core_cmd_str_pipe(), rz_core_cmd_subst(), rz_core_cmd_subst_i(), rz_core_debug_breakpoint_hit(), rz_core_debug_print_status(), rz_core_debug_syscall_hit(), rz_core_flush(), rz_core_print_scrollbar(), rz_core_print_scrollbar_bottom(), rz_core_prompt_exec(), rz_core_visual_analysis(), rz_core_visual_analysis_classes(), rz_core_visual_analysis_refresh(), rz_core_visual_bit_editor(), rz_core_visual_browse(), rz_core_visual_classes(), rz_core_visual_cmd(), rz_core_visual_colors(), rz_core_visual_comments(), rz_core_visual_config(), rz_core_visual_debugtraces_help(), rz_core_visual_define(), rz_core_visual_esil(), rz_core_visual_hud(), rz_core_visual_prompt(), rz_core_visual_show_char(), rz_core_visual_showcursor(), rz_core_visual_trackflags(), rz_core_visual_view_graph(), rz_core_visual_view_rop(), rz_core_visual_xrefs(), rz_diff_draw_tui(), rz_diff_hex_visual(), rz_lang_prompt(), rz_line_readline_cb(), rz_main_rizin(), rz_main_rz_asm(), rz_main_rz_bin(), rz_main_rz_sign(), search_collisions(), selection_widget_draw(), selection_widget_update(), showcursor(), visual_help(), visual_offset(), visual_prompt(), visual_refresh(), and visual_seek_animation().

◆ rz_cons_free()

RZ_API RzCons* rz_cons_free ( void  )

Definition at line 658 of file cons.c.

658  {
659  if (I.refcnt <= 0) {
660  return NULL;
661  }
662  I.refcnt--;
663  if (I.refcnt != 0) {
664  return &I;
665  }
666 #if __WINDOWS__
667  restore_console_state();
668 #endif
669  if (I.line) {
670  rz_line_free();
671  I.line = NULL;
672  }
673  RZ_FREE(I.input->readbuffer);
674  RZ_FREE(I.input);
675  RZ_FREE(CTX(buffer));
676  RZ_FREE(I.break_word);
677  cons_context_deinit(I.context);
678  RZ_FREE(CTX(lastOutput));
679  CTX(lastLength) = 0;
680  RZ_FREE(I.pager);
681  return NULL;
682 }
RZ_API void rz_line_free(void)
Definition: line.c:41

References cons_context_deinit(), CTX, I, NULL, RZ_FREE, and rz_line_free().

Referenced by rz_core_fini(), rz_diff_hex_visual(), rz_main_rizin(), rz_main_rz_agent(), and rzfind_open_file().

◆ rz_cons_get_buffer()

RZ_API const char* rz_cons_get_buffer ( void  )

Return the current RzCons buffer.

Definition at line 819 of file cons.c.

819  {
820  // check len otherwise it will return trash
821  return CTX(buffer_len) ? CTX(buffer) : NULL;
822 }

References CTX, and NULL.

Referenced by core_cmd_raw(), core_cmd_raw_node(), delete_last_comment(), ds_align_comment(), ds_newline(), ds_print_meta_infos(), ds_print_ptr(), rz_cons_get_buffer_dup(), and rz_core_bin_pdb_load().

◆ rz_cons_get_buffer_dup()

RZ_API RZ_OWN char* rz_cons_get_buffer_dup ( void  )

Return a newly allocated buffer containing what's currently in RzCons buffer.

Definition at line 827 of file cons.c.

827  {
828  const char *s = rz_cons_get_buffer();
829  return s ? strdup(s) : NULL;
830 }
RZ_API const char * rz_cons_get_buffer(void)
Return the current RzCons buffer.
Definition: cons.c:819

References NULL, rz_cons_get_buffer(), s, and strdup().

Referenced by __io_reg_profile(), __reg_read(), ds_newline(), get_graph_string(), oldinput_get_help(), and rz_core_cmd_foreach().

◆ rz_cons_get_buffer_len()

RZ_API int rz_cons_get_buffer_len ( void  )

Definition at line 832 of file cons.c.

832  {
833  return CTX(buffer_len);
834 }

References CTX.

Referenced by core_cmd_raw(), core_cmd_raw_node(), ds_begin_line(), and ds_print_meta_infos().

◆ rz_cons_get_click()

RZ_API bool rz_cons_get_click ( int x,
int y 
)

Definition at line 484 of file cons.c.

484  {
485  if (x) {
486  *x = I.click_x;
487  }
488  if (y) {
489  *y = I.click_y;
490  }
491  bool set = I.click_set;
492  I.click_set = false;
493  return set;
494 }
int x
Definition: mipsasm.c:20

References I, and x.

Referenced by __create_almighty(), __drag_and_resize(), __handle_mouse(), and rz_core_visual_cmd().

◆ rz_cons_get_column()

RZ_API int rz_cons_get_column ( void  )

Definition at line 1214 of file cons.c.

1214  {
1215  char *line = strrchr(CTX(buffer), '\n');
1216  if (!line) {
1217  line = CTX(buffer);
1218  }
1219  (CTX(buffer))[CTX(buffer_len)] = 0;
1220  return rz_str_ansi_len(line);
1221 }
line
Definition: setup.py:34

References CTX, setup::line, and rz_str_ansi_len().

◆ rz_cons_get_cur_line()

RZ_API int rz_cons_get_cur_line ( void  )

Definition at line 387 of file cons.c.

387  {
388  int curline = 0;
389 #if __WINDOWS__
390  CONSOLE_SCREEN_BUFFER_INFO info;
391  if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info)) {
392  return 0;
393  }
394  curline = info.dwCursorPosition.Y - info.srWindow.Top;
395 #endif
396 #if __UNIX__
397  char buf[8];
398  struct termios save, raw;
399  // flush the Arrow keys escape keys which was messing up the output
400  fflush(stdout);
401  (void)tcgetattr(0, &save);
402  cfmakeraw(&raw);
403  (void)tcsetattr(0, TCSANOW, &raw);
404  if (isatty(fileno(stdin))) {
406  if (read(0, buf, sizeof(buf)) != sizeof(buf)) {
407  if (isdigit(buf[2])) {
408  curline = (buf[2] - '0');
409  }
410  if (isdigit(buf[3])) {
411  curline = curline * 10 + (buf[3] - '0');
412  }
413  }
414  }
415  }
416  (void)tcsetattr(0, TCSANOW, &save);
417 #endif
418  return curline;
419 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static int save
Definition: main.c:14
#define RZ_CONS_GET_CURSOR_POSITION
Definition: rz_cons.h:599
#define isdigit(c)
Definition: safe-ctype.h:131
#define TCSANOW
Definition: sftypes.h:998
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References info(), isdigit, read(), RZ_CONS_GET_CURSOR_POSITION, save, TCSANOW, and write.

Referenced by core_basefind_progess_status(), rz_core_bin_basefind_print(), and selection_widget_draw().

◆ rz_cons_get_cursor()

RZ_API int rz_cons_get_cursor ( RZ_NONNULL int rows)

Calculates the aproximated x,y coordinates of the cursor before flushing.

Parameters
[out]rowsRow number of the cursor
Returns
Column number of the cursor

Definition at line 1298 of file cons.c.

1298  {
1299  rz_return_val_if_fail(rows, 0);
1300  int col = CTX(col);
1301  int row = CTX(row);
1302  if (CTX(rowcol_calc_start) > CTX(buffer_len)) {
1304  CTX(rowcol_calc_start) = 0;
1305  }
1306  if (!CTX(buffer)) {
1307  *rows = 0;
1308  return 0;
1309  }
1310  const char *last_line = CTX(buffer) + CTX(rowcol_calc_start);
1311  const char *ptr;
1312  while ((ptr = strchr(last_line, '\n'))) {
1313  last_line = ++ptr;
1314  row++;
1315  };
1316  const char *last_escape = last_line;
1317  while ((ptr = strchr(last_escape, '\x1b'))) {
1318  // ignore ansi chars, copypasta from rz_str_ansi_len
1319  col += ptr - last_escape;
1320  char ch2 = *++ptr;
1321  if (ch2 == '\\') {
1322  ptr++;
1323  } else if (ch2 == ']') {
1324  if (!strncmp(ptr + 2 + 5, "rgb:", 4)) {
1325  ptr += 18;
1326  }
1327  } else if (ch2 == '[') {
1328  for (++ptr; *ptr && *ptr != 'J' && *ptr != 'm' && *ptr != 'H'; ptr++) {
1329  ;
1330  }
1331  }
1332  last_escape = ptr;
1333  }
1334  *rows = row;
1335  CTX(row) = row;
1336  CTX(col) = col;
1337  CTX(rowcol_calc_start) = CTX(buffer_len);
1338  return col;
1339 }
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References CTX, rz_return_val_if_fail, and rz_warn_if_reached.

Referenced by rz_cons_bind().

◆ rz_cons_get_rune()

RZ_API const char* rz_cons_get_rune ( const ut8  ch)

Definition at line 1922 of file cons.c.

1922  {
1923  switch (ch) {
1924  case RUNECODE_LINE_HORIZ: return RUNE_LINE_HORIZ;
1925  case RUNECODE_LINE_VERT: return RUNE_LINE_VERT;
1926  case RUNECODE_LINE_CROSS: return RUNE_LINE_CROSS;
1927  case RUNECODE_CORNER_TL: return RUNE_CORNER_TL;
1928  case RUNECODE_CORNER_TR: return RUNE_CORNER_TR;
1929  case RUNECODE_CORNER_BR: return RUNE_CORNER_BR;
1930  case RUNECODE_CORNER_BL: return RUNE_CORNER_BL;
1935  }
1936  return NULL;
1937 }
#define RUNECODE_LINE_HORIZ
Definition: rz_cons.h:374
#define RUNE_LINE_CROSS
Definition: rz_cons.h:402
#define RUNECODE_CURVE_CORNER_TL
Definition: rz_cons.h:378
#define RUNE_CURVE_CORNER_TL
Definition: rz_cons.h:413
#define RUNECODE_CORNER_BL
Definition: rz_cons.h:371
#define RUNE_LINE_HORIZ
Definition: rz_cons.h:403
#define RUNE_CORNER_TR
Definition: rz_cons.h:408
#define RUNECODE_CORNER_BR
Definition: rz_cons.h:370
#define RUNECODE_LINE_VERT
Definition: rz_cons.h:368
#define RUNE_CORNER_BL
Definition: rz_cons.h:406
#define RUNECODE_LINE_CROSS
Definition: rz_cons.h:369
#define RUNECODE_CURVE_CORNER_BR
Definition: rz_cons.h:380
#define RUNE_CORNER_TL
Definition: rz_cons.h:407
#define RUNECODE_CURVE_CORNER_BL
Definition: rz_cons.h:381
#define RUNE_CORNER_BR
Definition: rz_cons.h:405
#define RUNECODE_CURVE_CORNER_TR
Definition: rz_cons.h:379
#define RUNECODE_CORNER_TL
Definition: rz_cons.h:375
#define RUNE_CURVE_CORNER_BR
Definition: rz_cons.h:415
#define RUNE_CURVE_CORNER_BL
Definition: rz_cons.h:416
#define RUNE_LINE_VERT
Definition: rz_cons.h:401
#define RUNECODE_CORNER_TR
Definition: rz_cons.h:376
#define RUNE_CURVE_CORNER_TR
Definition: rz_cons.h:414

References NULL, RUNE_CORNER_BL, RUNE_CORNER_BR, RUNE_CORNER_TL, RUNE_CORNER_TR, RUNE_CURVE_CORNER_BL, RUNE_CURVE_CORNER_BR, RUNE_CURVE_CORNER_TL, RUNE_CURVE_CORNER_TR, RUNE_LINE_CROSS, RUNE_LINE_HORIZ, RUNE_LINE_VERT, RUNECODE_CORNER_BL, RUNECODE_CORNER_BR, RUNECODE_CORNER_TL, RUNECODE_CORNER_TR, RUNECODE_CURVE_CORNER_BL, RUNECODE_CURVE_CORNER_BR, RUNECODE_CURVE_CORNER_TL, RUNECODE_CURVE_CORNER_TR, RUNECODE_LINE_CROSS, RUNECODE_LINE_HORIZ, and RUNECODE_LINE_VERT.

Referenced by rz_cons_canvas_to_string().

◆ rz_cons_get_size()

RZ_API int rz_cons_get_size ( int rows)

Definition at line 1446 of file cons.c.

1446  {
1447 #if __WINDOWS__
1448  CONSOLE_SCREEN_BUFFER_INFO csbi;
1449  bool ret = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
1450  if (ret) {
1451  I.columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
1452  I.rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
1453  } else {
1454  if (I.term_xterm) {
1455  ret = __xterm_get_size();
1456  }
1457  if (!ret || (I.columns == -1 && I.rows == 0)) {
1458  // Stdout is probably redirected so we set default values
1459  I.columns = 80;
1460  I.rows = 23;
1461  }
1462  }
1463 #elif EMSCRIPTEN
1464  I.columns = 80;
1465  I.rows = 23;
1466 #elif __UNIX__
1467  struct winsize win = { 0 };
1468  if (isatty(0) && !ioctl(0, TIOCGWINSZ, &win)) {
1469  if ((!win.ws_col) || (!win.ws_row)) {
1470  const char *tty = isatty(1) ? ttyname(1) : NULL;
1471  int fd = open(tty ? tty : "/dev/tty", O_RDONLY);
1472  if (fd != -1) {
1473  int ret = ioctl(fd, TIOCGWINSZ, &win);
1474  if (ret || !win.ws_col || !win.ws_row) {
1475  win.ws_col = 80;
1476  win.ws_row = 23;
1477  }
1478  close(fd);
1479  }
1480  }
1481  I.columns = win.ws_col;
1482  I.rows = win.ws_row;
1483  } else {
1484  I.columns = 80;
1485  I.rows = 23;
1486  }
1487 #else
1488  char *str = rz_sys_getenv("COLUMNS");
1489  if (str) {
1490  I.columns = atoi(str);
1491  I.rows = 23; // XXX. windows must get console size
1492  free(str);
1493  } else {
1494  I.columns = 80;
1495  I.rows = 23;
1496  }
1497 #endif
1498 #if SIMULATE_ADB_SHELL
1499  I.rows = 0;
1500  I.columns = 0;
1501 #endif
1502 #if SIMULATE_MAYHEM
1503  // expect tons of crashes
1504  I.rows = -1;
1505  I.columns = -1;
1506 #endif
1507  if (I.rows < 0) {
1508  I.rows = 0;
1509  }
1510  if (I.columns < 0) {
1511  I.columns = 0;
1512  }
1513  if (I.force_columns) {
1514  I.columns = I.force_columns;
1515  }
1516  if (I.force_rows) {
1517  I.rows = I.force_rows;
1518  }
1519  if (I.fix_columns) {
1520  I.columns += I.fix_columns;
1521  }
1522  if (I.fix_rows) {
1523  I.rows += I.fix_rows;
1524  }
1525  if (rows) {
1526  *rows = I.rows;
1527  }
1528  I.rows = RZ_MAX(0, I.rows);
1529  return RZ_MAX(0, I.columns);
1530 }
static static fork const void static count close
Definition: sflib.h:33
static static sync static getppid static getegid const char static filename ioctl
Definition: sflib.h:62
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
Definition: sys.c:483
#define TIOCGWINSZ
Definition: sftypes.h:721
#define O_RDONLY
Definition: sftypes.h:486
unsigned short ws_row
Definition: sftypes.h:784
unsigned short ws_col
Definition: sftypes.h:785
uv_tty_t tty
Definition: main.c:7
static const z80_opcode fd[]
Definition: z80_tab.h:997

References close, fd, free(), I, ioctl, NULL, O_RDONLY, RZ_MAX, rz_sys_getenv(), cmd_descs_generate::str, TIOCGWINSZ, tty, winsize::ws_col, and winsize::ws_row.

Referenced by __add_cmd_panel(), __add_cmdf_panel(), __add_help_panel(), __adjust_side_panels(), __call_visual_graph(), __core_visual_view_graph_update(), __do_panels_resize(), __fix_layout_h(), __handle_mouse(), __handle_mouse_on_panel(), __layout_default(), __move_panel_to_down(), __move_panel_to_left(), __move_panel_to_right(), __move_panel_to_up(), __panels_new(), __panels_process(), __panels_refresh(), __print_prompt(), agraph_print(), cb_scrcolumns(), cmd_pCd(), cmd_pCD(), cmd_pCx(), desc_list_visual_cb(), ds_show_xrefs(), fill_wrapped_comment(), flagbars(), goto_asmqjmps(), hud_filter(), num_callback(), print_debug_maps_ascii_art(), print_options(), readline_callback(), rz_analysis_function_list_ascii_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_info_section_bars_handler(), rz_cmd_print(), rz_cons_bind(), rz_cons_less_str(), rz_cons_message(), rz_cons_new(), rz_cons_strcat_at(), rz_core_analysis_bbs_asciiart(), rz_core_print_scrollbar(), rz_core_print_scrollbar_bottom(), rz_core_visual(), rz_core_visual_analysis(), rz_core_visual_analysis_classes(), rz_core_visual_analysis_refresh(), rz_core_visual_analysis_refresh_column(), rz_core_visual_classes(), rz_core_visual_cmd(), rz_core_visual_colors(), rz_core_visual_config(), rz_core_visual_define(), rz_core_visual_graph(), rz_core_visual_prompt_input(), rz_core_visual_trackflags(), rz_core_visual_view_rop(), rz_core_visual_xrefs(), rz_debug_traces_ascii(), rz_diff_hex_visual(), rz_diff_resize_buffer(), rz_line_readline_cb(), rz_open_binary_list_ascii_handler(), rz_open_maps_list_ascii_handler(), show_config_options(), var_functions_show(), var_variables_show(), visual_flagzone(), visual_offset(), and visual_responsive().

◆ rz_cons_goto_origin_reset()

RZ_API void rz_cons_goto_origin_reset ( void  )

Definition at line 732 of file cons.c.

732  {
733  rz_cons_gotoxy(0, 0);
735 }

References Color_RESET, rz_cons_gotoxy(), and rz_cons_strcat().

Referenced by rz_diff_draw_tui(), rz_diff_hex_visual(), and visual_refresh().

◆ rz_cons_gotoxy()

◆ rz_cons_highlight()

RZ_API void rz_cons_highlight ( const char *  word)

Definition at line 1756 of file cons.c.

1756  {
1757  int l, *cpos = NULL;
1758  char *rword = NULL, *res, *clean = NULL;
1759  char *inv[2] = {
1760  RZ_CONS_INVERT(true, true),
1761  RZ_CONS_INVERT(false, true)
1762  };
1763  int linv[2] = {
1764  strlen(inv[0]),
1765  strlen(inv[1])
1766  };
1767 
1768  if (!I.enable_highlight) {
1770  return;
1771  }
1772  if (word && *word && CTX(buffer)) {
1773  int word_len = strlen(word);
1774  char *orig;
1775  clean = rz_str_ndup(CTX(buffer), CTX(buffer_len));
1776  l = rz_str_ansi_filter(clean, &orig, &cpos, -1);
1777  free(CTX(buffer));
1778  CTX(buffer) = orig;
1779  if (I.highlight) {
1780  if (strcmp(word, I.highlight)) {
1781  free(I.highlight);
1782  I.highlight = strdup(word);
1783  }
1784  } else {
1785  I.highlight = strdup(word);
1786  }
1787  rword = malloc(word_len + linv[0] + linv[1] + 1);
1788  if (!rword) {
1789  free(cpos);
1790  free(clean);
1791  return;
1792  }
1793  strcpy(rword, inv[0]);
1794  strcpy(rword + linv[0], word);
1795  strcpy(rword + linv[0] + word_len, inv[1]);
1796  res = rz_str_replace_thunked(CTX(buffer), clean, cpos,
1797  l, word, rword, 1);
1798  if (res) {
1799  CTX(buffer) = res;
1800  CTX(buffer_len) = CTX(buffer_sz) = strlen(res);
1801  }
1802  free(rword);
1803  free(clean);
1804  free(cpos);
1806  /* don't free orig - it's assigned
1807  * to CTX(buffer) and possibly realloc'd */
1808  } else {
1809  RZ_FREE(I.highlight);
1810  }
1811 }
RZ_API void rz_cons_enable_highlight(const bool enable)
Definition: cons.c:496
RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len)
Definition: str.c:2124
RZ_API char * rz_str_replace_thunked(char *str, char *clean, int *thunk, int clen, const char *key, const char *val, int g)
Definition: str.c:1233

References CTX, ctx_rowcol_calc_reset(), free(), I, malloc(), NULL, rz_cons_enable_highlight(), RZ_FREE, rz_str_ansi_filter(), rz_str_ndup(), rz_str_replace_thunked(), and strdup().

Referenced by cb_scrhighlight(), rz_cons_flush(), and rz_cons_visual_flush().

◆ rz_cons_invert()

RZ_API void rz_cons_invert ( int  set,
int  color 
)

Definition at line 1662 of file cons.c.

1662  {
1663  rz_cons_strcat(RZ_CONS_INVERT(set, color));
1664 }
static int color
Definition: visual.c:20

References color, and rz_cons_strcat().

Referenced by cmd_print_pxA().

◆ rz_cons_is_breaked()

RZ_API bool rz_cons_is_breaked ( void  )

Definition at line 373 of file cons.c.

373  {
374  if (I.cb_break) {
375  I.cb_break(I.user);
376  }
377  if (I.timeout) {
378  if (rz_time_now_mono() > I.timeout) {
379  CTX(breaked) = true;
380  eprintf("\nTimeout!\n");
381  I.timeout = 0;
382  }
383  }
384  return CTX(breaked);
385 }

References breaked, CTX, eprintf, I, and rz_time_now_mono().

Referenced by __childrenFlagsOf(), __core_analysis_fcn(), _analysis_calls(), agraph_print_edges(), analBars(), analPaths(), analysis_block_cb(), basefind_pointer_map_iter(), cmd_dcu(), cmd_search_bin(), core_basefind_check_ctrl_c(), core_basefind_progess_status(), core_perform_auto_analysis(), DEFINE_HANDLE_TS_FCN(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_analysis_search(), do_asm_search(), do_debug_trace_calls(), do_esil_search(), do_section_search(), do_string_search(), do_syscall_search(), draw_horizontal_line(), draw_vertical_line(), get_crossing_matrix(), lang_pipe_run(), linux_handle_signals(), macro_call(), objc_find_refs(), print_cmd_analysis_after_traps_print(), rtr_visual(), rtti_msvc_read_base_class_array(), run_basic_block_analysis(), rz_analysis_class_recover_from_rzbin(), rz_analysis_reflines_get(), rz_analysis_rtti_print_all(), rz_analysis_run_tasks(), rz_analysis_vtable_search(), rz_analyze_function_linked_offsets_handler(), rz_cmd_analysis(), rz_cmd_debug(), rz_cmd_debug_continue_mapped_io_handler(), rz_cmd_debug_step_cond_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_search(), rz_cmd_sizes_of_n_instructions_handler(), rz_cons_bind(), rz_cons_canvas_write(), rz_cons_flush(), rz_cons_new(), rz_core_analysis_all(), rz_core_analysis_calls(), rz_core_analysis_continue_until_call(), rz_core_analysis_continue_until_syscall(), rz_core_analysis_cycles(), rz_core_analysis_esil(), rz_core_analysis_esil_emulate(), rz_core_analysis_everything(), rz_core_analysis_fcn(), rz_core_analysis_propagate_noreturn(), rz_core_analysis_refs(), rz_core_analysis_resolve_golang_strings(), rz_core_analysis_search(), rz_core_analysis_search_xrefs(), rz_core_analysis_sigdb_apply(), rz_core_analysis_type_match(), rz_core_analysis_types_propagation(), rz_core_analysis_value_pointers(), rz_core_asm_back_disassemble(), rz_core_asm_back_disassemble_all(), rz_core_asm_bwdisassemble(), rz_core_asm_strsearch(), rz_core_bin_apply_strings(), rz_core_bin_print_source_line_info(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_subst(), rz_core_debug_continue_until(), rz_core_debug_step_until_frame(), rz_core_disasm_pdi_with_buf(), rz_core_dump(), rz_core_esil_step(), rz_core_file_open(), rz_core_link_stroff(), rz_core_print_disasm(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions_with_buf(), rz_core_rtr_cmds(), rz_core_rtr_http_run(), rz_core_search_prelude(), rz_core_search_rop(), rz_core_search_value_in_range(), rz_core_serve(), rz_core_visual(), rz_core_visual_graph(), rz_debug_continue_kill(), rz_debug_esil_step(), rz_diff_hex_visual(), rz_il_vm_step_until_addr_handler(), rz_line_readline_cb(), search_collisions(), search_hash(), search_similar_pattern_in(), set_layout(), step_until(), step_until_esil(), step_until_flag(), step_until_inst(), step_until_optype(), update_graph_sizes(), winkd_lock_enter(), and winkd_send_state_manipulate_req().

◆ rz_cons_is_interactive()

◆ rz_cons_isatty()

RZ_API bool rz_cons_isatty ( void  )

Definition at line 1341 of file cons.c.

1341  {
1342 #if __UNIX__
1343  struct winsize win = { 0 };
1344  const char *tty;
1345  struct stat sb;
1346 
1347  if (!isatty(1)) {
1348  return false;
1349  }
1350  if (ioctl(1, TIOCGWINSZ, &win)) {
1351  return false;
1352  }
1353  if (!win.ws_col || !win.ws_row) {
1354  return false;
1355  }
1356  tty = ttyname(1);
1357  if (!tty) {
1358  return false;
1359  }
1360  if (stat(tty, &sb) || !S_ISCHR(sb.st_mode)) {
1361  return false;
1362  }
1363  return true;
1364 #elif __WINDOWS__
1365  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
1366  if (GetFileType(hOut) == FILE_TYPE_CHAR) {
1367  return true;
1368  }
1369 #endif
1370  /* non-UNIX do not have ttys */
1371  return false;
1372 }
static SblHeader sb
Definition: bin_mbn.c:26
static stat
Definition: sflib.h:131
Definition: sftypes.h:80

References HANDLE, ioctl, sb, stat, TIOCGWINSZ, tty, winsize::ws_col, and winsize::ws_row.

Referenced by rz_main_rizin().

◆ rz_cons_last()

RZ_API void rz_cons_last ( void  )

Definition at line 927 of file cons.c.

927  {
928  if (!CTX(lastEnabled)) {
929  return;
930  }
931  CTX(lastMode) = true;
932  rz_cons_memcat(CTX(lastOutput), CTX(lastLength));
933 }
RZ_API int rz_cons_memcat(const char *str, int len)
Definition: cons.c:1224

References CTX, and rz_cons_memcat().

Referenced by rz_last_output_handler().

◆ rz_cons_lastline()

RZ_API char* rz_cons_lastline ( int len)

Definition at line 1813 of file cons.c.

1813  {
1814  char *b = CTX(buffer) + CTX(buffer_len);
1815  while (b > CTX(buffer)) {
1816  if (*b == '\n') {
1817  b++;
1818  break;
1819  }
1820  b--;
1821  }
1822  if (len) {
1823  int delta = b - CTX(buffer);
1824  *len = CTX(buffer_len) - delta;
1825  }
1826  return b;
1827 }
static st64 delta
Definition: vmenus.c:2425

References b, CTX, delta, and len.

Referenced by ds_print_relocs(), and rz_cons_lastline_utf8_ansi_len().

◆ rz_cons_lastline_utf8_ansi_len()

RZ_API char* rz_cons_lastline_utf8_ansi_len ( int len)

Definition at line 1831 of file cons.c.

1831  {
1832  if (!len) {
1833  return rz_cons_lastline(0);
1834  }
1835 
1836  char *b = CTX(buffer) + CTX(buffer_len);
1837  int l = 0;
1838  int last_possible_ansi_end = 0;
1839  char ch = '\0';
1840  char ch2;
1841  while (b > CTX(buffer)) {
1842  ch2 = ch;
1843  ch = *b;
1844 
1845  if (ch == '\n') {
1846  b++;
1847  l--;
1848  break;
1849  }
1850 
1851  // utf-8
1852  if ((ch & 0xc0) != 0x80) {
1853  l++;
1854  }
1855 
1856  // ansi
1857  if (ch == 'J' || ch == 'm' || ch == 'H') {
1858  last_possible_ansi_end = l - 1;
1859  } else if (ch == '\x1b' && ch2 == '[') {
1860  l = last_possible_ansi_end;
1861  }
1862 
1863  b--;
1864  }
1865 
1866  *len = l;
1867  return b;
1868 }
RZ_API char * rz_cons_lastline(int *len)
Definition: cons.c:1813

References b, CTX, len, and rz_cons_lastline().

◆ rz_cons_memcat()

RZ_API int rz_cons_memcat ( const char *  str,
int  len 
)

Definition at line 1224 of file cons.c.

1224  {
1225  if (len < 0) {
1226  return -1;
1227  }
1228  if (I.echo) {
1229  // Here to silent pedantic meson flags ...
1230  int rlen;
1231  if ((rlen = write(2, str, len)) != len) {
1232  return rlen;
1233  }
1234  }
1235  if (str && len > 0 && !I.null) {
1236  if (palloc(len + 1)) {
1237  memcpy(CTX(buffer) + CTX(buffer_len), str, len);
1238  CTX(buffer_len) += len;
1239  (CTX(buffer))[CTX(buffer_len)] = 0;
1240  }
1241  }
1242  if (I.flush) {
1243  rz_cons_flush();
1244  }
1245  if (I.break_word && str && len > 0) {
1246  if (rz_mem_mem((const ut8 *)str, len, (const ut8 *)I.break_word, I.break_word_len)) {
1247  CTX(breaked) = true;
1248  }
1249  }
1250  return len;
1251 }
static bool palloc(int moar)
Definition: cons.c:685
uint8_t ut8
Definition: lh5801.h:11
RZ_API const ut8 * rz_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int nlen)
Definition: mem.c:246

References breaked, CTX, I, len, memcpy(), palloc(), rz_cons_flush(), rz_mem_mem(), cmd_descs_generate::str, and write.

Referenced by cmd_print_blocks(), core_cmd_pipe(), mywrite(), rz_cmd_print(), rz_cons_last(), rz_cons_strcat(), rz_cons_strcat_at(), rz_cons_strcat_justify(), rz_core_cmd_pipe_old(), rz_core_yank_print(), rz_core_yank_print_string(), selection_widget_draw(), and system_common_handler().

◆ rz_cons_memset()

RZ_API void rz_cons_memset ( char  ch,
int  len 
)

Definition at line 1253 of file cons.c.

1253  {
1254  if (!I.null && len > 0) {
1255  if (palloc(len + 1)) {
1256  memset(CTX(buffer) + CTX(buffer_len), ch, len);
1257  CTX(buffer_len) += len;
1258  (CTX(buffer))[CTX(buffer_len)] = 0;
1259  }
1260  }
1261 }

References CTX, I, len, memset(), and palloc().

Referenced by ds_align_comment(), ds_print_relocs(), and rz_cons_strcat_justify().

◆ rz_cons_new()

RZ_API RzCons* rz_cons_new ( void  )

Definition at line 589 of file cons.c.

589  {
590  I.refcnt++;
591  if (I.refcnt != 1) {
592  return &I;
593  }
594  I.rgbstr = rz_cons_rgb_str_off;
595  I.line = rz_line_new();
596  I.enable_highlight = true;
597  I.highlight = NULL;
598  I.is_wine = -1;
599  I.blankline = true;
600  I.teefile = NULL;
601  I.fix_columns = 0;
602  I.fix_rows = 0;
603  I.mouse_event = 0;
604  I.force_rows = 0;
605  I.force_columns = 0;
606  I.event_resize = NULL;
607  I.event_data = NULL;
608  I.linesleep = 0;
609  I.fdin = stdin;
610  I.fdout = 1;
611  I.break_lines = false;
612  I.lines = 0;
613 
614  I.input = RZ_NEW0(RzConsInputContext);
615  I.input->bufactive = true;
616  I.context = &rz_cons_context_default;
617  cons_context_init(I.context, NULL);
618 
619  rz_cons_get_size(&I.pagesize);
620  I.num = NULL;
621  I.null = 0;
622 #if __WINDOWS__
623  save_console_state();
624  I.vtmode = rz_cons_detect_vt_mode();
625  set_console_codepage_to_utf8();
626 #else
627  I.vtmode = RZ_VIRT_TERM_MODE_COMPLETE;
628 #endif
629 #if EMSCRIPTEN
630  /* do nothing here :? */
631 #elif __UNIX__
632  tcgetattr(0, &I.term_buf);
633  memcpy(&I.term_raw, &I.term_buf, sizeof(I.term_raw));
634  I.term_raw.c_iflag &= ~(BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
635  I.term_raw.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
636  I.term_raw.c_cflag &= ~(CSIZE | PARENB);
637  I.term_raw.c_cflag |= CS8;
638  I.term_raw.c_cc[VMIN] = 1; // Solaris stuff hehe
639  rz_sys_signal(SIGWINCH, resize);
640 #elif __WINDOWS__
641  I.term_buf = I.old_input_mode | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT;
642  I.term_raw = ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
643  if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)__w32_control, TRUE)) {
644  eprintf("rz_cons: Cannot set control console handler\n");
645  }
646 #endif
647  I.pager = NULL; /* no pager by default */
648  I.mouse = 0;
649  I.show_vals = false;
650  rz_cons_reset();
652 
654 
655  return &I;
656 }
RZ_API RzLine * rz_line_new(void)
Definition: line.c:19
#define TRUE
Definition: mybfd.h:103
RZ_API void rz_print_set_is_interrupted_cb(RzPrintIsInterruptedCallback cb)
Definition: print.c:52
RZ_API void rz_cons_rgb_init(void)
Definition: rgb.c:106
RZ_API char * rz_cons_rgb_str_off(char *outstr, size_t sz, ut64 off)
Definition: rgb.c:209
#define CS8
Definition: sftypes.h:942
#define BRKINT
Definition: sftypes.h:871
#define ISIG
Definition: sftypes.h:970
#define VMIN
Definition: sftypes.h:857
#define ICANON
Definition: sftypes.h:971
#define PARMRK
Definition: sftypes.h:873
#define IXON
Definition: sftypes.h:880
#define ECHO
Definition: sftypes.h:973
#define IGNCR
Definition: sftypes.h:877
#define IEXTEN
Definition: sftypes.h:984
#define PARENB
Definition: sftypes.h:945
#define INLCR
Definition: sftypes.h:876
#define CSIZE
Definition: sftypes.h:938
#define ECHONL
Definition: sftypes.h:976
#define ICRNL
Definition: sftypes.h:878
#define ISTRIP
Definition: sftypes.h:875
#define SIGWINCH
Definition: win.h:88

References BRKINT, cons_context_init(), CS8, CSIZE, ECHO, ECHONL, eprintf, I, ICANON, ICRNL, IEXTEN, IGNCR, INLCR, ISIG, ISTRIP, IXON, memcpy(), NULL, PARENB, PARMRK, rz_cons_context_default, rz_cons_get_size(), rz_cons_is_breaked(), rz_cons_reset(), rz_cons_rgb_init(), rz_cons_rgb_str_off(), rz_line_new(), RZ_NEW0, rz_print_set_is_interrupted_cb(), rz_sys_signal(), RZ_VIRT_TERM_MODE_COMPLETE, SIGWINCH, TRUE, and VMIN.

Referenced by rz_core_init(), rz_main_rizin(), rz_main_rz_agent(), rz_main_rz_bin(), and rzfind_open_file().

◆ rz_cons_newline()

RZ_API void rz_cons_newline ( void  )

Definition at line 1274 of file cons.c.

1274  {
1275  if (!I.null) {
1276  rz_cons_strcat("\n");
1277  }
1278 #if 0
1279 This place is wrong to manage the color reset, can interfire with rzpipe output sending resetchars
1280 and break json output appending extra chars.
1281 this code now is managed into output.c:118 at function rz_cons_w32_print
1282 now the console color is reset with each \n (same stuff do it here but in correct place ... i think)
1283 
1284 #if __WINDOWS__
1286 #else
1288 #endif
1289  if (I.is_html) rz_cons_strcat ("<br />\n");
1290 #endif
1291 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
RZ_API void rz_cons_reset_colors(void)
Definition: cons.c:783
#define Color_RESET_ALL
Definition: rz_cons.h:620
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
Definition: inftree9.h:24
diff_output_t output
Definition: zipcmp.c:237

References color, Color_RESET_ALL, I, i, in, n, output, rz_cons_reset_colors(), rz_cons_strcat(), and to.

Referenced by __printPattern(), agraph_print(), annotated_hexdump(), bb_info_print(), bin_pe_versioninfo(), classdump_cpp(), classdump_java(), cmd_prc(), cmd_print_bars(), core_cmp_bits(), ds_newline(), fcn_list_print_info(), function_print_calls(), hexprint(), iter_dbt_commands(), pr_bb(), print_arena_stats(), print_bin_content(), print_format_values(), print_heap_fastbin(), print_instruction_ops(), print_main_arena_bins(), print_rop(), print_tcache_content(), rz_agraph_print(), rz_analysis_list_vtables(), rz_analysis_xrefs_from_list_handler(), rz_cmd_alias(), rz_cmd_debug_display_bt_oneline_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_help(), rz_cmd_print(), rz_cmd_shell_uname_handler(), rz_cons_echo(), rz_cons_grepbuf(), rz_cons_pal_list(), rz_cons_pal_show_256(), rz_cons_pal_show_gs(), rz_cons_pal_show_rgb(), rz_cons_println(), rz_cons_strcat_justify(), rz_core_asm_plugin_print(), rz_core_cmd_foreach(), rz_core_disasm_pdi_with_buf(), rz_core_hash_plugins_print(), rz_core_print_func_args(), rz_core_visual_bit_editor(), rz_core_visual_colors(), rz_core_visual_comments(), rz_core_visual_config(), rz_core_visual_esil(), rz_core_visual_graph(), rz_core_visual_xrefs(), rz_core_yank_dump(), rz_core_yank_print(), rz_core_yank_print_string(), rz_print_hexdump_emoji_handler(), rz_regs_show_valgroup(), showBuffer(), showmem(), showregs(), siglistcb(), var_accesses_list(), var_variables_show(), and visual_flagzone().

◆ rz_cons_pop()

RZ_API void rz_cons_pop ( void  )

Definition at line 876 of file cons.c.

876  {
877  if (!CTX(cons_stack)) {
878  return;
879  }
880  RzConsStack *data = (RzConsStack *)rz_stack_pop(CTX(cons_stack));
881  if (!data) {
882  return;
883  }
884  cons_stack_load(data, true);
885  cons_stack_free((void *)data);
886 }
static void cons_stack_load(RzConsStack *data, bool free_current)
Definition: cons.c:94

References cons_stack_free(), cons_stack_load(), CTX, and rz_stack_pop().

Referenced by __io_reg_profile(), backtrace_vars(), core_cmd_raw(), core_cmd_raw_node(), function_task_runner(), get_cf_offset(), get_fcn_name(), oldinput_get_help(), rz_core_bin_pdb_load(), rz_core_cmd_foreach(), rz_core_debug_breakpoint_hit(), and rz_core_print_disasm().

◆ rz_cons_printf()

RZ_API int rz_cons_printf ( const char *  format,
  ... 
)

Definition at line 1202 of file cons.c.

1202  {
1203  va_list ap;
1204  if (!format || !*format) {
1205  return -1;
1206  }
1207  va_start(ap, format);
1208  rz_cons_printf_list(format, ap);
1209  va_end(ap);
1210 
1211  return 0;
1212 }
RZ_API void rz_cons_printf_list(const char *format, va_list ap)
Definition: cons.c:1170

References rz_cons_printf_list().

Referenced by __cons_cb_fkey(), __core_cmd_search_asm_byteswap(), __core_cmd_search_asm_infinite(), __handle_tab(), __handle_visual_mark(), __preline_flag(), __printPattern(), __printRecursive(), __show_status(), _aeli_iter(), _cb_hit(), _CbInRangeAav(), _CbInRangeSearchV(), _ds_comment_align_(), _pointer_table(), add_footer(), add_header(), agraph_follow_innodes(), agraph_print_edge(), agraph_print_edge_dot(), agraph_print_edge_gml(), agraph_print_node_dot(), agraph_print_node_gml(), analysis_class_print(), analysis_class_print_as_cmd(), analysis_fcn_data(), analysis_fcn_data_gaps(), annotated_hexdump(), apply_maps_as_flags(), asciiart_backtrace(), backtrace_vars(), bb_info_print(), bin_class_print_rizin(), bin_elf_versioninfo_verneed(), bin_elf_versioninfo_versym(), bin_memory_print_rec(), bin_pe_versioninfo(), bin_resources_print_standard(), bin_trycatch(), callback_foreach_kv(), cb_binstrenc(), cb_emuskip(), cb_graphformat(), cb_scrstrconv(), cb_searchin(), cb_strfilter(), cb_strpurge(), cb_zoombyte(), classdump_c(), classdump_cpp(), classdump_java(), classdump_objc(), cmd_address_info(), cmd_aea(), cmd_agraph_edge(), cmd_agraph_node(), cmd_analysis_esil(), cmd_analysis_ucall_ref(), cmd_debug_current_modules(), cmd_debug_modules(), cmd_p_minus_e(), cmd_prc(), cmd_print_bars(), cmd_print_blocks(), cmd_print_eq_dict(), cmd_print_format(), cmd_print_fromage(), cmd_print_gadget(), cmd_print_pv(), cmd_print_pxA(), cmd_search_bin(), config_print_node(), config_visual_hit(), consumeBuffer(), convert_dot_str_to_image(), convert_dotcmd_to_image(), core_analysis_bytes_desc(), core_analysis_bytes_esil(), core_analysis_bytes_size(), core_analysis_color_curr_node(), core_analysis_graph_construct_edges(), core_analysis_graph_construct_nodes(), core_analysis_name_print(), core_analysis_var_list_show(), core_basefind_progess_status(), core_bin_file_print(), core_cmp_bits(), core_print_2bpp_row(), core_print_2bpp_tiles(), core_print_columns(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), desc_list_visual_cb(), dex_print_class_def(), dex_print_class_def_exports(), dex_print_encoded_field(), dex_print_encoded_method(), disasm_strings(), disasm_until_ret(), disassemble_till_return_is_found(), do_analysis_search(), do_asm_search(), do_ref_search(), do_section_search(), do_string_search(), do_syscall_search(), dot_trace_traverse(), ds_begin_line(), ds_cdiv_optimization(), ds_comment_(), ds_control_flow_comments(), ds_disassemble(), ds_print_asmop_payload(), ds_print_bbline(), ds_print_comments_right(), ds_print_cycles(), ds_print_data_type(), ds_print_dwarf(), ds_print_family(), ds_print_labels(), ds_print_meta_infos(), ds_print_middle(), ds_print_offset(), ds_print_op_size(), ds_print_optype(), ds_print_pre(), ds_print_ref_lines(), ds_print_relocs(), ds_print_shortcut(), ds_print_show_bytes(), ds_print_trace(), ds_show_flags(), ds_show_functions(), ds_show_functions_argvar(), end_state(), entries_initfini_print(), fcn_list_bbs(), fcn_print_info(), fcn_print_trace_info(), flag_tag_print(), flag_zone_list(), flagbar_foreach(), flirt_print_indentation(), flirt_print_module(), flirt_print_node(), flirt_print_node_pattern(), foreach_offset_annotation(), func_walk_blocks(), function_list_print(), function_list_print_as_cmd(), function_list_print_quiet(), function_print_calls(), goto_asmqjmps(), handle_entropy(), handle_ts_stmt(), handleHints(), hexprint(), hint_node_print(), list_all_functions_at_vtable_offset(), list_vars(), listOpDescriptions(), meta_variable_comment_print(), open_maps_show(), pr_bb(), print_arch(), print_arena_stats(), print_arg_str(), print_bin_content(), print_cmd_analysis_after_traps_print(), print_debug_map_line(), print_debug_maps_ascii_art(), print_demangler_info(), print_fcn_arg(), print_flag_name(), print_flag_orig_name(), print_flag_rizin(), print_format_values(), print_fpu(), print_function_labels_cb(), print_graph_agg(), print_heap_chunk_simple(), print_heap_fastbin(), print_hint_h_format(), print_hint_tree(), print_instruction_ops(), print_instruction_trace(), print_largebin_description(), print_line_op(), print_malloc_states(), print_node_options(), print_offset_in_binary_line_bar(), print_options(), print_rline_task(), print_rop(), print_smallbin_description(), print_source_info(), print_space_stack(), print_stats(), print_tcache_content(), print_trampolines(), print_unsortedbin_description(), printAnalPaths(), printPadded(), printVarSummary(), readline_callback(), rizin_compare_unified(), rizin_compare_words(), rop_kuery(), rtr_visual(), rtti_itanium_print_class_type_info(), rtti_itanium_print_si_class_type_info(), rtti_itanium_print_vmi_class_type_info(), rtti_msvc_print_base_class_descriptor(), rtti_msvc_print_class_hierarchy_descriptor(), rtti_msvc_print_complete_object_locator(), rtti_msvc_print_type_descriptor(), rz_analysis_basic_block_find_paths_handler(), rz_analysis_basic_block_list_handler(), rz_analysis_class_base_list_handler(), rz_analysis_class_list_handler(), rz_analysis_class_vtable_list_handler(), rz_analysis_esil_trace_list(), rz_analysis_function_address_handler(), rz_analysis_function_args_and_vars_xrefs_handler(), rz_analysis_function_autoname_handler(), rz_analysis_function_count_handler(), rz_analysis_function_describe_offset_handler(), rz_analysis_function_import_list_handler(), rz_analysis_function_list_ascii_handler(), rz_analysis_function_size_sum_handler(), rz_analysis_function_vars_dis_refs_handler(), rz_analysis_function_vars_handler(), rz_analysis_function_vars_stackframe_handler(), rz_analysis_function_xrefs_handler(), rz_analysis_functions_map_handler(), rz_analysis_list_struct_offsets_handler(), rz_analysis_list_vtables(), rz_analysis_syscall_print_handler(), rz_analysis_var_global_list_show(), rz_analysis_xrefs_copy_handler(), rz_analysis_xrefs_from_list_handler(), rz_analysis_xrefs_list_handler(), rz_analysis_xrefs_to_graph_cmd_handler(), rz_analysis_xrefs_to_list_handler(), rz_analyze_cycles_handler(), rz_bin_pdb_download(), rz_block_handler(), rz_block_max_handler(), rz_cmd_alias(), rz_cmd_analysis(), rz_cmd_arena_print_handler(), rz_cmd_debug(), rz_cmd_debug_bp_set_expr_cur_offset_handler(), rz_cmd_debug_display_bt_handler(), rz_cmd_debug_display_bt_oneline_handler(), rz_cmd_debug_list_bp_handler(), rz_cmd_debug_list_bp_indexes_handler(), rz_cmd_debug_process_profile_edit_handler(), rz_cmd_debug_show_bp_index_handler(), rz_cmd_debug_show_cur_bp_handler(), rz_cmd_debug_trace_handler(), rz_cmd_dexs_handler(), rz_cmd_disassemble_ropchain_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_eval_color_load_theme_handler(), rz_cmd_heap_chunks_print_handler(), rz_cmd_heap_tcache_print_handler(), rz_cmd_help(), rz_cmd_help_search_handler(), rz_cmd_info_demangle_handler(), rz_cmd_info_hashes_handler(), rz_cmd_info_section_bars_handler(), rz_cmd_print(), rz_cmd_print_gadget_print_as_rizin_handler(), rz_cmd_print_timestamp_current_handler(), rz_cmd_print_timestamp_dos_handler(), rz_cmd_print_timestamp_hfs_handler(), rz_cmd_print_timestamp_ntfs_handler(), rz_cmd_print_timestamp_unix_handler(), rz_cmd_remote(), rz_cmd_search(), rz_cmd_shell_cat_handler(), rz_cmd_shell_uname_handler(), rz_cmd_sizes_of_n_instructions_handler(), rz_cmd_state_output_print(), rz_comment_filelink_handler(), rz_cons_any_key(), rz_cons_bind(), rz_cons_cmd_help(), rz_cons_color(), rz_cons_gotoxy(), rz_cons_hud(), rz_cons_pal_list(), rz_cons_pal_show(), rz_cons_pal_show_256(), rz_cons_pal_show_gs(), rz_cons_pal_show_rgb(), rz_cons_set_title(), rz_convert_mne_handler(), rz_core_agraph_add_edge(), rz_core_agraph_del_edge(), rz_core_agraph_print_dot(), rz_core_agraph_print_gml(), rz_core_analysis_bbs_asciiart(), rz_core_analysis_bbs_info_print(), rz_core_analysis_callgraph(), rz_core_analysis_cc_print(), rz_core_analysis_coderefs(), rz_core_analysis_data(), rz_core_analysis_datarefs(), rz_core_analysis_fcn_returns(), rz_core_analysis_function_strings_print(), rz_core_analysis_graph(), rz_core_analysis_il_vm_status(), rz_core_analysis_paths(), rz_core_analysis_sigdb_apply(), rz_core_annotated_code_print(), rz_core_annotated_code_print_json(), rz_core_asm_plugin_print(), rz_core_bin_basefind_print(), rz_core_bin_class_fields_print(), rz_core_bin_class_methods_print(), rz_core_bin_classes_print(), rz_core_bin_dwarf_print_abbrev_section(), rz_core_bin_dwarf_print_aranges(), rz_core_bin_dwarf_print_attr_value(), rz_core_bin_dwarf_print_debug_info(), rz_core_bin_dwarf_print_line_units(), rz_core_bin_dwarf_print_loc(), rz_core_bin_export_info(), rz_core_bin_fields_print(), rz_core_bin_imports_print(), rz_core_bin_info_print(), rz_core_bin_libs_print(), rz_core_bin_main_print(), rz_core_bin_plugin_print(), rz_core_bin_print_source_line_sample(), rz_core_bin_relocs_print(), rz_core_bin_sections_print(), rz_core_bin_size_print(), rz_core_binxtr_plugin_print(), rz_core_clippy(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_init(), rz_core_cmd_subst(), rz_core_cmd_subst_i(), rz_core_cmp_disasm_print(), rz_core_cmp_print(), rz_core_cmpwatch_show(), rz_core_core_plugin_print(), rz_core_debug_esil(), rz_core_debug_kill(), rz_core_debug_plugin_print(), rz_core_disasm_pdi_with_buf(), rz_core_esil_dumpstack(), rz_core_esil_step(), rz_core_file_binlist(), rz_core_file_print(), rz_core_flag_describe(), rz_core_flirt_dump_file(), rz_core_fortune_list(), rz_core_fortune_list_types(), rz_core_fortune_print_random(), rz_core_graph_print(), rz_core_hash_plugin_print(), rz_core_init(), rz_core_io_cache_print(), rz_core_io_pcache_print(), rz_core_io_plugin_print(), rz_core_lang_plugin_print(), rz_core_magic_at(), rz_core_meta_print(), rz_core_parser_plugin_print(), rz_core_print_bb_custom(), rz_core_print_bb_gml(), rz_core_print_disasm(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions_with_buf(), rz_core_print_func_args(), rz_core_print_scrollbar(), rz_core_print_scrollbar_bottom(), rz_core_raw_file_print(), rz_core_reg_print_diff(), rz_core_rtr_cmds(), rz_core_rtr_list(), rz_core_spaces_print(), rz_core_syscall(), rz_core_task_list(), rz_core_task_print(), rz_core_types_calling_conventions_print(), rz_core_types_enum_print(), rz_core_types_function_print(), rz_core_types_link_print(), rz_core_types_print_all(), rz_core_types_show_format(), rz_core_types_struct_print(), rz_core_types_typedef_print(), rz_core_types_union_print(), rz_core_visual_analysis(), rz_core_visual_analysis_classes(), rz_core_visual_analysis_refresh(), rz_core_visual_analysis_refresh_column(), rz_core_visual_bit_editor(), rz_core_visual_browse(), rz_core_visual_classes(), rz_core_visual_cmd(), rz_core_visual_colors(), rz_core_visual_comments(), rz_core_visual_config(), rz_core_visual_debugtraces(), rz_core_visual_debugtraces_help(), rz_core_visual_define(), rz_core_visual_esil(), rz_core_visual_graph(), rz_core_visual_mark_dump(), rz_core_visual_show_char(), rz_core_visual_title(), rz_core_visual_trackflags(), rz_core_visual_view_graph(), rz_core_visual_view_rop(), rz_core_visual_xrefs(), rz_core_yank_dump(), rz_debug_trace_print(), rz_debug_traces_ascii(), rz_debug_wait(), rz_egg_config_handler(), rz_egg_list_plugins_handler(), rz_egg_show_config_handler(), rz_eval_getset_handler(), rz_flag_distance_handler(), rz_flag_hexdump_handler(), rz_flag_length_handler(), rz_flag_realname_handler(), rz_flag_tag_search_handler(), rz_flag_zone_around_handler(), rz_flirt_create_handler(), rz_flirt_scan_handler(), rz_global_imports_handler(), rz_heap_tcache_content(), rz_il_vm_status_handler(), rz_il_vm_step_until_addr_handler(), rz_io_system_run_oldhandler(), rz_line_autocomplete(), rz_line_hist_list(), rz_list_mne_handler(), rz_main_rz_bin(), rz_main_rz_sign(), rz_meta_data_at_handler(), rz_open_binary_list_ascii_handler(), rz_open_binary_show_handler(), rz_open_maps_list_ascii_handler(), rz_print_analysis_details_handler(), rz_print_areas_no_functions_handler(), rz_print_hexdump_bits_handler(), rz_print_hexdump_emoji_handler(), rz_print_offset_sg(), rz_reg_arenas_handler(), rz_reg_arenas_stack_size_handler(), rz_reg_cc_handler(), rz_reg_cond_handler(), rz_reg_flags_handler(), rz_reg_roles_handler(), rz_regs_fpu_handler(), rz_regs_show_valgroup(), rz_resize_handler(), rz_resolve_jemalloc(), rz_seek_handler(), rz_seek_history_list_handler(), rz_seek_search(), rz_type_enum_bitfield_handler(), rz_write_debruijn_find_handler(), rzil_print_register_bitv(), rzil_print_register_bool(), search_hash(), search_similar_pattern_in(), selection_widget_draw(), show_analysis_classes(), show_class(), show_regs_handler(), showBuffer(), showmem(), showreg(), showregs(), siglistcb(), step_until_flag(), strings_print(), symbols_print(), syscall_dump(), syscalls_dump(), trace_traverse_pre(), types_cc_print(), types_xrefs(), types_xrefs_all(), types_xrefs_graph(), types_xrefs_summary(), var_accesses_list(), var_functions_show(), var_variables_show(), visual_flagzone(), visual_help(), visual_prompt(), visual_refresh(), visual_seek_animation(), xref_list_print_as_cmd(), xrefs_graph(), and xrefs_list_print().

◆ rz_cons_printf_list()

RZ_API void rz_cons_printf_list ( const char *  format,
va_list  ap 
)

Definition at line 1170 of file cons.c.

1170  {
1171  size_t size, written;
1172  va_list ap2, ap3;
1173 
1174  va_copy(ap2, ap);
1175  va_copy(ap3, ap);
1176  if (I.null || !format) {
1177  va_end(ap2);
1178  va_end(ap3);
1179  return;
1180  }
1181  if (strchr(format, '%')) {
1182  if (palloc(MOAR + strlen(format) * 20)) {
1183  club:
1184  size = CTX(buffer_sz) - CTX(buffer_len); /* remaining space in CTX(buffer) */
1185  written = vsnprintf(CTX(buffer) + CTX(buffer_len), size, format, ap3);
1186  if (written >= size) { /* not all bytes were written */
1187  if (palloc(written + 1)) { /* + 1 byte for \0 termination */
1188  va_end(ap3);
1189  va_copy(ap3, ap2);
1190  goto club;
1191  }
1192  }
1193  CTX(buffer_len) += written;
1194  }
1195  } else {
1196  rz_cons_strcat(format);
1197  }
1198  va_end(ap2);
1199  va_end(ap3);
1200 }
voidpf void uLong size
Definition: ioapi.h:138
vsnprintf
Definition: kernel.h:366

References CTX, I, MOAR, palloc(), rz_cons_strcat(), and vsnprintf.

Referenced by ds_comment_(), ds_comment_esil(), and rz_cons_printf().

◆ rz_cons_println()

RZ_API void rz_cons_println ( const char *  str)

Definition at line 233 of file cons.c.

233  {
234  rz_cons_print(str);
235  rz_cons_newline();
236 }

References rz_cons_newline(), and cmd_descs_generate::str.

Referenced by bin_versioninfo(), cmd_aea(), cmd_analysis_esil(), cmd_debug_pid(), cmd_print_bars(), cmd_print_blocks(), cmd_print_format(), cmd_print_pv(), config_print_node(), core_analysis_name_print(), do_analysis_search(), egg_option(), meta_variable_comment_append(), nonreturn_print(), nonreturn_print_json(), pager_printpage(), print_demangler_info(), print_format_values(), print_json_string(), print_main_arena_bins(), print_malloc_states(), rabin_do_operation(), rop_kuery(), rtr_visual(), rz_analysis_function_address_handler(), rz_analysis_function_cc_set_get_handler(), rz_analysis_function_signature_handler(), rz_analysis_list_vtables(), rz_analysis_rtti_demangle_class_name_handler(), rz_analysis_syscall_name_handler(), rz_analysis_syscall_number_handler(), rz_analysis_syscall_show_handler(), rz_analyze_opcode_handler(), rz_cmd_alias(), rz_cmd_analysis(), rz_cmd_base64_decode_handler(), rz_cmd_base64_encode_handler(), rz_cmd_debug_dmi(), rz_cmd_debug_dmS_handler(), rz_cmd_debug_name_bp_handler(), rz_cmd_eval_color_list_current_theme_handler(), rz_cmd_help(), rz_cmd_info_demangle_handler(), rz_cmd_javac_handler(), rz_cmd_javaf_handler(), rz_cmd_javai_handler(), rz_cmd_javam_handler(), rz_cmd_javap_handler(), rz_cmd_javar_handler(), rz_cmd_kuery(), rz_cmd_print(), rz_cmd_print_magic_handler(), rz_cmd_search(), rz_cmd_shell_echo_handler(), rz_cmd_shell_env_handler(), rz_cmd_shell_pwd_handler(), rz_cmd_shell_which_handler(), rz_cmd_state_output_print(), rz_comment_at_handler(), rz_cons_grepbuf(), rz_cons_message(), rz_convert_mne_handler(), rz_core_agraph_print_json(), rz_core_analysis_callgraph(), rz_core_analysis_data(), rz_core_asm_plugin_print(), rz_core_asm_plugins_print(), rz_core_bin_classes_print(), rz_core_bin_imports_print(), rz_core_bin_signatures_print(), rz_core_debug_kill(), rz_core_disasm_pdi_with_buf(), rz_core_file_print(), rz_core_flag_describe(), rz_core_graph_print(), rz_core_hash_plugins_print(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions_with_buf(), rz_core_rtr_cmd(), rz_core_rtr_http_run(), rz_core_task_list(), rz_core_types_calling_conventions_print(), rz_core_types_enum_print(), rz_core_types_enum_print_all(), rz_core_types_function_print_all(), rz_core_types_link_print_all(), rz_core_types_print_all(), rz_core_types_struct_print(), rz_core_types_struct_print_all(), rz_core_types_typedef_print(), rz_core_types_typedef_print_all(), rz_core_types_union_print(), rz_core_types_union_print_all(), rz_core_visual_analysis(), rz_core_visual_hud(), rz_core_yank_dump(), rz_debug_signal_list(), rz_eval_spaces_handler(), rz_eval_type_handler(), rz_flag_color_handler(), rz_flag_comment_handler(), rz_flag_describe_at_handler(), rz_flag_describe_closest_handler(), rz_heap_debug_block_win(), rz_heap_list_w32(), rz_hex_of_assembly_handler(), rz_il_vm_step_with_events_handler(), rz_main_rz_bin(), rz_meta_type_current_handler(), rz_print_bitstream_handler(), rz_print_byte_bitstream_handler(), rz_print_string_c_cpp_handler(), rz_reg_profile_comments_handler(), rz_reg_profile_gdb_handler(), rz_reg_profile_handler(), rz_reg_types_handler(), rz_resize_human_handler(), rz_type_function_cc_handler(), rz_type_list_enum_handler(), rz_type_list_function_handler(), rz_type_list_structure_handler(), rz_type_list_typedef_handler(), rz_type_list_union_handler(), show_config_options(), task_output(), types_cc_print(), types_enum_member_find(), types_enum_member_find_all(), types_xrefs_function(), var_functions_show(), and w32_list_heaps_blocks().

◆ rz_cons_push()

RZ_API void rz_cons_push ( void  )

Definition at line 860 of file cons.c.

860  {
861  if (!CTX(cons_stack)) {
862  return;
863  }
864  RzConsStack *data = cons_stack_dump(true);
865  if (!data) {
866  return;
867  }
868  rz_stack_push(CTX(cons_stack), data);
869  CTX(buffer_len) = 0;
870  if (CTX(buffer)) {
871  memset(CTX(buffer), 0, CTX(buffer_sz));
872  }
873  CTX(noflush) = true;
874 }
static RzConsStack * cons_stack_dump(bool recreate)
Definition: cons.c:63

References cons_stack_dump(), CTX, memset(), and rz_stack_push().

Referenced by __io_reg_profile(), backtrace_vars(), core_cmd_raw(), core_cmd_raw_node(), function_task_runner(), get_cf_offset(), get_fcn_name(), oldinput_get_help(), rz_core_bin_pdb_load(), rz_core_cmd_foreach(), rz_core_debug_breakpoint_hit(), and rz_core_print_disasm().

◆ rz_cons_reset()

RZ_API void rz_cons_reset ( void  )

Definition at line 804 of file cons.c.

804  {
805  if (CTX(buffer)) {
806  (CTX(buffer))[0] = '\0';
807  }
808  CTX(buffer_len) = 0;
809  I.lines = 0;
810  I.lastline = CTX(buffer);
811  cons_grep_reset(&CTX(grep));
812  CTX(pageable) = true;
814 }

References cons_grep_reset(), CTX, ctx_rowcol_calc_reset(), and I.

Referenced by __io_maps(), __reg_read(), ds_newline(), get_graph_string(), rz_cons_column(), rz_cons_flush(), rz_cons_less_str(), rz_cons_new(), rz_cons_visual_flush(), rz_core_cmd_str_pipe(), rz_main_rizin(), rz_main_rz_sign(), and visual_refresh().

◆ rz_cons_reset_colors()

RZ_API void rz_cons_reset_colors ( void  )

Definition at line 783 of file cons.c.

783  {
785 }
#define Color_RESET_BG
Definition: rz_cons.h:619

References Color_RESET, Color_RESET_BG, and rz_cons_strcat().

Referenced by pager_printpage(), rz_cons_less_str(), rz_cons_newline(), and rz_core_visual_prompt_input().

◆ rz_cons_set_click()

RZ_API void rz_cons_set_click ( int  x,
int  y 
)

Definition at line 477 of file cons.c.

477  {
478  I.click_x = x;
479  I.click_y = y;
480  I.click_set = true;
481  I.mouse_event = 1;
482 }

References I, and x.

Referenced by __parseMouseEvent(), and rz_cons_arrow_to_hjkl().

◆ rz_cons_set_cup()

RZ_API bool rz_cons_set_cup ( bool  enable)

Definition at line 1672 of file cons.c.

1672  {
1673 #if __UNIX__
1674  const char *code = enable
1675  ? "\x1b[?1049h"
1676  "\x1b"
1677  "7\x1b[?47h"
1678  : "\x1b[?1049l"
1679  "\x1b[?47l"
1680  "\x1b"
1681  "8";
1682  const size_t code_len = strlen(code);
1683  if (write(2, code, code_len) != code_len) {
1684  return false;
1685  }
1686  fflush(stdout);
1687 #elif __WINDOWS__
1688  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
1689  if (enable) {
1690  const char *code = enable // xterm + xterm-color
1691  ? "\x1b[?1049h\x1b"
1692  "7\x1b[?47h"
1693  : "\x1b[?1049l\x1b[?47l"
1694  "\x1b"
1695  "8";
1696  const size_t code_len = strlen(code);
1697  if (write(2, code, code_len) != code_len) {
1698  return false;
1699  }
1700  }
1701  fflush(stdout);
1702  }
1703 #endif
1704  return true;
1705 }

References I, RZ_VIRT_TERM_MODE_DISABLE, and write.

Referenced by rz_core_visual().

◆ rz_cons_set_flush()

RZ_API void rz_cons_set_flush ( bool  flush)

Set whether RzCons should flush content to screen or not.

Parameters
flushIf true, calls to rz_cons_flush and rz_cons_visual_flush would flush cons content to the screen, otherwise they will not.

Definition at line 2006 of file cons.c.

2006  {
2007  CTX(noflush) = !flush;
2008 }

References CTX.

Referenced by oldinput_get_help(), and rz_core_debug_breakpoint_hit().

◆ rz_cons_set_interactive()

RZ_API void rz_cons_set_interactive ( bool  x)

◆ rz_cons_set_last_interactive()

RZ_API void rz_cons_set_last_interactive ( void  )

◆ rz_cons_set_raw()

RZ_API void rz_cons_set_raw ( bool  is_raw)

void rz_cons_set_raw( [0,1] )

Change canonicality of the terminal

For optimization reasons, there's no initialization flag, so you need to ensure that the make the first call to rz_cons_set_raw() with '1' and the next calls ^=1, so: 1, 0, 1, 0, 1, ...

If you doesn't use this order you'll probably loss your terminal properties.

Definition at line 1617 of file cons.c.

1617  {
1618  static int oldraw = -1;
1619  if (oldraw != -1) {
1620  if (is_raw == oldraw) {
1621  return;
1622  }
1623  }
1624 #if EMSCRIPTEN
1625  /* do nothing here */
1626 #elif __UNIX__
1627  // enforce echo off
1628  if (is_raw) {
1629  I.term_raw.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
1630  tcsetattr(0, TCSANOW, &I.term_raw);
1631  } else {
1632  tcsetattr(0, TCSANOW, &I.term_buf);
1633  }
1634 #elif __WINDOWS__
1635  DWORD mode;
1636  HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
1637  GetConsoleMode(h, &mode);
1638  if (is_raw) {
1639  if (I.term_xterm) {
1640  rz_sys_xsystem("stty raw -echo");
1641  } else {
1642  SetConsoleMode(h, mode & I.term_raw);
1643  }
1644  } else {
1645  if (I.term_xterm) {
1646  rz_sys_xsystem("stty -raw echo");
1647  } else {
1648  SetConsoleMode(h, mode | I.term_buf);
1649  }
1650  }
1651 #else
1652 #warning No raw console supported for this platform
1653 #endif
1654  fflush(stdout);
1655  oldraw = is_raw;
1656 }
#define rz_sys_xsystem(cmd)
Definition: rz_sys.h:83

References DWORD, ECHO, ECHONL, h, HANDLE, I, ICANON, IEXTEN, ISIG, rz_sys_xsystem, and TCSANOW.

Referenced by __prompt(), __system_shell_cb(), add_comment(), config_visual_hit(), rz_cmd_help(), rz_cons_fgets(), rz_cons_flush(), rz_cons_hud(), rz_cons_less_str(), rz_cons_readchar(), rz_cons_readchar_timeout(), rz_cons_yesno(), rz_core_visual(), rz_core_visual_analysis(), rz_core_visual_analysis_classes(), rz_core_visual_bit_editor(), rz_core_visual_classes(), rz_core_visual_cmd(), rz_core_visual_config(), rz_core_visual_config_hud(), rz_core_visual_define(), rz_core_visual_esil(), rz_core_visual_trackflags(), rz_core_visual_view_graph(), rz_core_visual_view_rop(), rz_line_readline_cb(), and rz_main_rizin().

◆ rz_cons_set_title()

RZ_API void rz_cons_set_title ( const char *  str)

Definition at line 1733 of file cons.c.

1733  {
1734 #if __WINDOWS__
1735 #if defined(_UNICODE)
1736  wchar_t *wstr = rz_utf8_to_utf16_l(str, strlen(str));
1737  if (wstr) {
1738  SetConsoleTitleW(wstr);
1739  RZ_FREE(wstr);
1740  }
1741 #else // defined(_UNICODE)
1742  SetConsoleTitle(str);
1743 #endif // defined(_UNICODE)
1744 #else
1745  rz_cons_printf("\x1b]0;%s\007", str);
1746 #endif
1747 }

References rz_cons_printf(), RZ_FREE, and cmd_descs_generate::str.

Referenced by rz_cmd_help().

◆ rz_cons_set_utf8()

RZ_API void rz_cons_set_utf8 ( bool  b)

Definition at line 1658 of file cons.c.

1658  {
1659  I.use_utf8 = b;
1660 }

References b, and I.

Referenced by cb_utf8().

◆ rz_cons_show_cursor()

RZ_API void rz_cons_show_cursor ( int  cursor)

Definition at line 1581 of file cons.c.

1581  {
1582 #if __WINDOWS__
1583  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
1584 #endif
1585  rz_xwrite(1, cursor ? "\x1b[?25h" : "\x1b[?25l", 6);
1586 #if __WINDOWS__
1587  } else {
1588  static HANDLE hStdout = NULL;
1589  static DWORD size = -1;
1590  CONSOLE_CURSOR_INFO cursor_info;
1591  if (!hStdout) {
1592  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
1593  }
1594  if (size == -1) {
1595  GetConsoleCursorInfo(hStdout, &cursor_info);
1596  size = cursor_info.dwSize;
1597  }
1598  cursor_info.dwSize = size;
1599  cursor_info.bVisible = cursor ? TRUE : FALSE;
1600  SetConsoleCursorInfo(hStdout, &cursor_info);
1601  }
1602 #endif
1603 }
#define FALSE
Definition: mybfd.h:102

References DWORD, FALSE, HANDLE, I, NULL, RZ_VIRT_TERM_MODE_DISABLE, rz_xwrite, and TRUE.

Referenced by __prompt(), agraph_follow_innodes(), cmd_analysis_graph(), config_visual_hit(), prompt(), rz_cons_controlz(), rz_cons_fgets(), rz_cons_hud(), rz_cons_less_str(), rz_core_agraph_print_interactive(), rz_core_graph_print(), rz_core_visual(), rz_core_visual_analysis(), rz_core_visual_analysis_classes(), rz_core_visual_bit_editor(), rz_core_visual_classes(), rz_core_visual_colors(), rz_core_visual_config(), rz_core_visual_config_hud(), rz_core_visual_define(), rz_core_visual_esil(), rz_core_visual_prompt_input(), rz_core_visual_showcursor(), rz_core_visual_trackflags(), rz_core_visual_view_graph(), rz_core_visual_view_rop(), rz_diff_hex_visual(), and showcursor().

◆ rz_cons_singleton()

RZ_API RzCons* rz_cons_singleton ( void  )

Definition at line 300 of file cons.c.

300  {
301  return &I;
302 }

References I.

Referenced by __holdMouseState(), __print_prompt(), __update_prompt_color(), agraph_refresh(), agraph_sdb_init(), agraph_toggle_mini(), agraph_toggle_tiny(), apply_line_style(), argv_get_help(), cb_breaklines(), cb_color(), cb_color_getter(), cb_fixcolumns(), cb_fixrows(), cb_rows(), cb_screcho(), cb_scrflush(), cb_scrhtml(), cb_scrint(), cb_scrlast(), cb_scrlinesleep(), cb_scrpagesize(), cb_teefile(), cmd_print_blocks(), core_analysis_graph_construct_edges(), core_analysis_graph_construct_nodes(), core_analysis_graph_label(), core_cmp_bits(), core_print_columns(), core_task_ctx_init(), disasm_until_ret(), disassemble_till_return_is_found(), do_print_child_help(), fill_colored_args(), fill_details_do(), fill_usage_strbuf(), fill_wrapped_comment(), get_node_color(), jemalloc_get_bins(), jemalloc_get_chunks(), jemalloc_print_narenas(), palColorFor(), parse_grep_expression(), print_arena_stats(), print_bin_content(), print_debug_maps_ascii_art(), print_double_linked_list_bin(), print_double_linked_list_bin_graph(), print_double_linked_list_bin_simple(), print_heap_bin(), print_heap_chunk(), print_heap_chunk_simple(), print_heap_fastbin(), print_inst_minfo(), print_largebin_description(), print_malloc_info(), print_malloc_states(), print_offset_in_binary_line_bar(), print_search_progress(), print_smallbin_description(), print_tcache_content(), print_unsortedbin_description(), prompt(), rizin_compare_words(), rz_cmd_arena_print_handler(), rz_cmd_disassemble_ropchain_handler(), rz_cmd_disassembly_n_instrs_as_text_json_handler(), rz_cmd_eval_color_highlight_current_instruction_handler(), rz_cmd_eval_color_highlight_instruction_word_handler(), rz_cmd_heap_arena_bins_print_handler(), rz_cmd_heap_bins_list_print(), rz_cmd_heap_chunks_print_handler(), rz_cmd_heap_fastbins_print(), rz_cmd_heap_info_print_handler(), rz_cmd_main_arena_print_handler(), rz_cons_cmd_help(), rz_cons_fgets(), rz_cons_grep_line(), rz_cons_grepbuf(), rz_cons_less(), rz_cons_pal_show(), rz_cons_pal_update_event(), rz_cons_rainbow_get(), rz_cons_rgb_str(), rz_cons_set_interactive(), rz_cons_set_last_interactive(), rz_core_analysis_callgraph(), rz_core_analysis_data(), rz_core_analysis_graph(), rz_core_annotated_code_print(), rz_core_cmp_disasm_print(), rz_core_config_init(), rz_core_fgets(), rz_core_fini(), rz_core_init(), rz_core_rtr_http_stop(), rz_core_rtr_rap_run(), rz_core_visual(), rz_core_visual_analysis(), rz_core_visual_analysis_refresh(), rz_core_visual_append_help(), rz_core_visual_cmd(), rz_core_visual_colors(), rz_core_visual_hud(), rz_core_vmenu_append_help(), rz_core_wait(), rz_debug_continue_syscalls(), rz_debug_traces_ascii(), rz_diff_draw_tui(), rz_diff_hex_visual(), rz_heap_chunks_list(), rz_interpret_handler(), rz_line_autocomplete(), rz_line_readline_cb(), rz_line_set_prompt(), rz_main_rz_agent(), rz_print_offset_sg(), selection_widget_draw(), selection_widget_erase(), tiny_RzANode_print(), utf8_line_horiz(), utf8_line_vert(), and var_functions_show().

◆ rz_cons_sleep_begin()

RZ_API void* rz_cons_sleep_begin ( void  )

Definition at line 443 of file cons.c.

443  {
444  if (!I.cb_sleep_begin) {
445  return NULL;
446  }
447  return I.cb_sleep_begin(I.user);
448 }

References I, and NULL.

Referenced by gdbr_connect(), gdbr_lock_enter(), lang_pipe_run(), linux_dbg_wait(), linux_set_options(), rz_cmd_shell_sleep_handler(), rz_cons_readchar(), rz_core_rtr_cmd(), rz_core_rtr_cmds(), rz_core_rtr_http_run(), rz_debug_winkd_wait(), send_vcont(), system_common_handler(), and w32_dbg_wait().

◆ rz_cons_sleep_end()

RZ_API void rz_cons_sleep_end ( void *  user)

◆ rz_cons_strcat()

RZ_API void rz_cons_strcat ( const char *  str)

Definition at line 1263 of file cons.c.

1263  {
1264  int len;
1265  if (!str || I.null) {
1266  return;
1267  }
1268  len = strlen(str);
1269  if (len > 0) {
1271  }
1272 }

References I, len, rz_cons_memcat(), and cmd_descs_generate::str.

Referenced by __preline_flag(), agraph_print(), annotated_hexdump(), core_print_raw_buffer(), ds_control_flow_comments(), ds_end_line_highlight(), ds_print_color_reset(), ds_print_comments_right(), ds_print_core_vmode(), ds_print_cycles(), ds_print_data_type(), ds_print_esil_analysis(), ds_print_indent(), ds_print_labels(), ds_print_meta_infos(), ds_print_middle(), ds_print_offset(), ds_print_opstr(), ds_print_ptr(), ds_print_shortcut(), ds_print_show_cursor(), ds_print_trace(), ds_show_comments_describe(), ds_show_comments_right(), ds_show_flags(), ds_show_refs(), ds_start_line_highlight(), printCol(), rz_cmd_alias(), rz_cmd_call(), rz_cmd_print(), rz_cons_canvas_print(), rz_cons_canvas_print_region(), rz_cons_clear(), rz_cons_echo(), rz_cons_fill_line(), rz_cons_goto_origin_reset(), rz_cons_invert(), rz_cons_newline(), rz_cons_pal_list(), rz_cons_printf_list(), rz_cons_reset_colors(), rz_cons_strcat_at(), rz_core_bind(), rz_core_cmd_foreach(), rz_core_print_disasm_all(), rz_core_print_scrollbar(), rz_core_print_scrollbar_bottom(), rz_core_visual(), rz_core_visual_analysis_refresh(), rz_core_visual_cmd(), rz_core_visual_comments(), rz_core_visual_title(), rz_core_visual_view_rop(), rz_regs_show_valgroup(), siglistcb(), and visual_refresh().

◆ rz_cons_strcat_at()

RZ_API void rz_cons_strcat_at ( const char *  _str,
int  x,
char  y,
int  w,
int  h 
)

Definition at line 260 of file cons.c.

260  {
261  int i, o, len;
262  int cols = 0;
263  int rows = 0;
264  if (x < 0 || y < 0) {
265  int H, W = rz_cons_get_size(&H);
266  if (x < 0) {
267  x += W;
268  }
269  if (y < 0) {
270  y += H;
271  }
272  }
273  char *str = rz_str_ansi_crop(_str, 0, 0, w + 1, h);
275  for (o = i = len = 0; str[i]; i++, len++) {
276  if (w < 0 || rows > w) {
277  break;
278  }
279  if (str[i] == '\n') {
280  rz_cons_gotoxy(x, y + rows);
281  int ansilen = rz_str_ansi_len(str + o);
282  cols = RZ_MIN(w, ansilen);
283  const char *end = rz_str_ansi_chrn(str + o, cols);
284  cols = end - str + o;
285  rz_cons_memcat(str + o, RZ_MIN(len, cols));
286  o = i + 1;
287  len = 0;
288  rows++;
289  }
290  }
291  if (len > 1) {
292  rz_cons_gotoxy(x, y + rows);
293  rz_cons_memcat(str + o, len);
294  }
297  free(str);
298 }
#define W(x, y, z)
#define H(x)
#define w
Definition: crypto_rc6.c:13
#define RZ_CONS_CURSOR_SAVE
Definition: rz_cons.h:597
#define RZ_CONS_CURSOR_RESTORE
Definition: rz_cons.h:598
RZ_API const char * rz_str_ansi_chrn(const char *str, size_t n)
Definition: str.c:2098
RZ_API char * rz_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2)
Definition: str.c:2174
#define RZ_MIN(x, y)

References Color_RESET, test_evm::end, free(), h, H, i, len, RZ_CONS_CURSOR_RESTORE, RZ_CONS_CURSOR_SAVE, rz_cons_get_size(), rz_cons_gotoxy(), rz_cons_memcat(), rz_cons_strcat(), RZ_MIN, rz_str_ansi_chrn(), rz_str_ansi_crop(), rz_str_ansi_len(), cmd_descs_generate::str, W, w, and x.

Referenced by __core_visual_view_graph_update(), rz_core_gadget_print(), and rz_core_visual_view_rop().

◆ rz_cons_strcat_justify()

RZ_API void rz_cons_strcat_justify ( const char *  str,
int  j,
char  c 
)

Definition at line 238 of file cons.c.

238  {
239  int i, o, len;
240  for (o = i = len = 0; str[i]; i++, len++) {
241  if (str[i] == '\n') {
242  rz_cons_memset(' ', j);
243  if (c) {
244  rz_cons_memset(c, 1);
245  rz_cons_memset(' ', 1);
246  }
247  rz_cons_memcat(str + o, len);
248  if (str[o + len] == '\n') {
249  rz_cons_newline();
250  }
251  o = i + 1;
252  len = 0;
253  }
254  }
255  if (len > 1) {
256  rz_cons_memcat(str + o, len);
257  }
258 }
RZ_API void rz_cons_memset(char ch, int len)
Definition: cons.c:1253

References c, i, len, rz_cons_memcat(), rz_cons_memset(), rz_cons_newline(), and cmd_descs_generate::str.

Referenced by ds_show_comments_right(), and rz_cons_column().

◆ rz_cons_swap_ground()

RZ_API char* rz_cons_swap_ground ( const char *  col)

Definition at line 1871 of file cons.c.

1871  {
1872  if (!col) {
1873  return NULL;
1874  }
1875  if (!strncmp(col, "\x1b[48;5;", 7)) {
1876  /* rgb background */
1877  return rz_str_newf("\x1b[38;5;%s", col + 7);
1878  } else if (!strncmp(col, "\x1b[38;5;", 7)) {
1879  /* rgb foreground */
1880  return rz_str_newf("\x1b[48;5;%s", col + 7);
1881  } else if (!strncmp(col, "\x1b[4", 3)) {
1882  /* is background */
1883  return rz_str_newf("\x1b[3%s", col + 3);
1884  } else if (!strncmp(col, "\x1b[3", 3)) {
1885  /* is foreground */
1886  return rz_str_newf("\x1b[4%s", col + 3);
1887  }
1888  return strdup(col);
1889 }
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References NULL, rz_str_newf(), and strdup().

Referenced by cmd_print_pxA().

◆ rz_cons_visual_flush()

RZ_API void rz_cons_visual_flush ( void  )

Definition at line 1067 of file cons.c.

1067  {
1068  if (CTX(noflush)) {
1069  return;
1070  }
1071  rz_cons_highlight(I.highlight);
1072  if (!I.null) {
1073 /* TODO: this ifdef must go in the function body */
1074 #if __WINDOWS__
1075  if (I.vtmode != RZ_VIRT_TERM_MODE_DISABLE) {
1077  } else {
1078  rz_cons_w32_print(CTX(buffer), CTX(buffer_len), true);
1079  }
1080 #else
1082 #endif
1083  }
1084  rz_cons_reset();
1085 }
RZ_API void rz_cons_visual_write(char *buffer)
Definition: cons.c:1097

References CTX, I, rz_cons_highlight(), rz_cons_reset(), rz_cons_visual_write(), and RZ_VIRT_TERM_MODE_DISABLE.

Referenced by agraph_print(), rz_cons_hud(), rz_core_visual_analysis_classes(), rz_core_visual_bit_editor(), rz_core_visual_classes(), rz_core_visual_comments(), rz_core_visual_config(), rz_core_visual_debugtraces(), rz_core_visual_esil(), rz_core_visual_trackflags(), and visual_refresh().

◆ rz_cons_visual_write()

RZ_API void rz_cons_visual_write ( char *  buffer)

Definition at line 1097 of file cons.c.

1097  {
1098  char white[1024];
1099  int cols = I.columns;
1100  int alen, plen, lines = I.rows;
1101  bool break_lines = I.break_lines;
1102  const char *endptr;
1103  char *nl, *ptr = buffer, *pptr;
1104 
1105  if (I.null) {
1106  return;
1107  }
1108  memset(&white, ' ', sizeof(white));
1109  while ((nl = strchr(ptr, '\n'))) {
1110  int len = ((int)(size_t)(nl - ptr)) + 1;
1111  int lines_needed = 0;
1112 
1113  *nl = 0;
1114  alen = real_strlen(ptr, len);
1115  *nl = '\n';
1116  pptr = ptr > buffer ? ptr - 1 : ptr;
1117  plen = ptr > buffer ? len : len - 1;
1118 
1119  if (break_lines) {
1120  lines_needed = alen / cols + (alen % cols == 0 ? 0 : 1);
1121  }
1122  if ((break_lines && lines < lines_needed && lines > 0) || (!break_lines && alen > cols)) {
1123  int olen = len;
1124  endptr = rz_str_ansi_chrn(ptr, (break_lines ? cols * lines : cols) + 1);
1125  endptr++;
1126  len = endptr - ptr;
1127  plen = ptr > buffer ? len : len - 1;
1128  if (lines > 0) {
1129  __cons_write(pptr, plen);
1130  if (len != olen) {
1133  }
1134  }
1135  } else {
1136  if (lines > 0) {
1137  int w = cols - (alen % cols == 0 ? cols : alen % cols);
1138  __cons_write(pptr, plen);
1139  if (I.blankline && w > 0) {
1140  if (w > sizeof(white) - 1) {
1141  w = sizeof(white) - 1;
1142  }
1143  __cons_write(white, w);
1144  }
1145  }
1146  // TRICK to empty columns.. maybe buggy in w32
1147  if (rz_mem_mem((const ut8 *)ptr, len, (const ut8 *)"\x1b[0;0H", 6)) {
1148  lines = I.rows;
1149  __cons_write(pptr, plen);
1150  }
1151  }
1152  if (break_lines) {
1153  lines -= lines_needed;
1154  } else {
1155  lines--; // do not use last line
1156  }
1157  ptr = nl + 1;
1158  }
1159  /* fill the rest of screen */
1160  if (lines > 0) {
1161  if (cols > sizeof(white)) {
1162  cols = sizeof(white);
1163  }
1164  while (--lines >= 0) {
1165  __cons_write(white, cols);
1166  }
1167  }
1168 }
struct buffer buffer
static int real_strlen(const char *ptr, int len)
Definition: cons.c:1087
#define RZ_CONS_CLEAR_FROM_CURSOR_TO_END
Definition: rz_cons.h:595

References __cons_write(), Color_RESET, I, int, len, lines(), memset(), real_strlen(), RZ_CONS_CLEAR_FROM_CURSOR_TO_END, rz_mem_mem(), rz_str_ansi_chrn(), and w.

Referenced by rz_cons_visual_flush().

◆ rz_cons_zero()

RZ_API void rz_cons_zero ( void  )

Definition at line 1749 of file cons.c.

1749  {
1750  if (I.line) {
1751  I.line->zerosep = true;
1752  }
1753  rz_xwrite(1, "", 1);
1754 }

References I, and rz_xwrite.

Referenced by rz_core_prompt_exec(), and rz_main_rizin().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_cons  )

Variable Documentation

◆ lasti

bool lasti = false
static

Definition at line 1722 of file cons.c.

Referenced by rz_cons_set_interactive(), and rz_cons_set_last_interactive().

◆ rz_cons_context_default

RzConsContext rz_cons_context_default = { { { { 0 } } } }
static

◆ rz_cons_instance

RzCons rz_cons_instance = { 0 }
static

Definition at line 21 of file cons.c.