Rizin
unix-like reverse engineering framework and cli tools
strbuf.c File Reference
#include "rz_types.h"
#include "rz_util.h"
#include <stdio.h>

Go to the source code of this file.

Functions

RZ_API RzStrBufrz_strbuf_new (const char *str)
 
RZ_API bool rz_strbuf_equals (RzStrBuf *sa, RzStrBuf *sb)
 
RZ_API bool rz_strbuf_is_empty (RzStrBuf *sb)
 
RZ_API int rz_strbuf_length (RzStrBuf *sb)
 
RZ_API void rz_strbuf_init (RzStrBuf *sb)
 
RZ_API const char * rz_strbuf_initf (RzStrBuf *sb, const char *fmt,...)
 
RZ_API bool rz_strbuf_copy (RzStrBuf *dst, RzStrBuf *src)
 
RZ_API bool rz_strbuf_reserve (RzStrBuf *sb, size_t len)
 
RZ_API bool rz_strbuf_setbin (RzStrBuf *sb, const ut8 *s, size_t l)
 
RZ_API bool rz_strbuf_slice (RZ_NONNULL RzStrBuf *sb, size_t from, size_t len)
 Cuts the current string into a substring. More...
 
RZ_API bool rz_strbuf_setptr (RzStrBuf *sb, char *s, int len)
 
RZ_API const char * rz_strbuf_set (RzStrBuf *sb, const char *s)
 
RZ_API const char * rz_strbuf_setf (RzStrBuf *sb, const char *fmt,...)
 
RZ_API const char * rz_strbuf_vsetf (RzStrBuf *sb, const char *fmt, va_list ap)
 
RZ_API bool rz_strbuf_prepend (RzStrBuf *sb, const char *s)
 
RZ_API bool rz_strbuf_append (RzStrBuf *sb, const char *s)
 
RZ_API bool rz_strbuf_append_n (RzStrBuf *sb, const char *s, size_t l)
 
RZ_API bool rz_strbuf_appendf (RzStrBuf *sb, const char *fmt,...)
 
RZ_API bool rz_strbuf_vappendf (RzStrBuf *sb, const char *fmt, va_list ap)
 
RZ_API char * rz_strbuf_get (RzStrBuf *sb)
 
RZ_API ut8rz_strbuf_getbin (RzStrBuf *sb, int *len)
 
static char * drain (RzStrBuf *sb)
 
RZ_API RZ_OWN char * rz_strbuf_drain (RzStrBuf *sb)
 
RZ_API RZ_OWN char * rz_strbuf_drain_nofree (RzStrBuf *sb)
 
RZ_API void rz_strbuf_free (RzStrBuf *sb)
 
RZ_API void rz_strbuf_fini (RzStrBuf *sb)
 

Function Documentation

◆ drain()

static char* drain ( RzStrBuf sb)
inlinestatic

Definition at line 334 of file strbuf.c.

334  {
335  return sb->ptr
336  ? sb->weakref
337  ? rz_mem_dup(sb->ptr, sb->ptrlen)
338  : sb->ptr
339  : strdup(sb->buf);
340 }
static SblHeader sb
Definition: bin_mbn.c:26
voidpf void * buf
Definition: ioapi.h:138
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API void * rz_mem_dup(const void *s, int l)
Definition: mem.c:319

References rz_mem_dup(), sb, and strdup().

Referenced by rz_strbuf_drain(), and rz_strbuf_drain_nofree().

◆ rz_strbuf_append()

RZ_API bool rz_strbuf_append ( RzStrBuf sb,
const char *  s 
)

Definition at line 222 of file strbuf.c.

222  {
223  rz_return_val_if_fail(sb && s, false);
224 
225  int l = strlen(s);
226  return rz_strbuf_append_n(sb, s, l);
227 }
static RzSocket * s
Definition: rtr.c:28
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_strbuf_append_n(RzStrBuf *sb, const char *s, size_t l)
Definition: strbuf.c:229

References rz_return_val_if_fail, rz_strbuf_append_n(), s, and sb.

Referenced by _6502_analysis_esil_update_flags(), _6502_op(), __draw_menu(), __draw_modal(), __esil_step_range_cb(), __generic_io_dest(), __init_menu_disasm_asm_settings_layout(), __init_menu_disasm_settings_layout(), __init_menu_screen_settings_layout(), argv_get_help(), base_type_to_format_no_unfold(), base_type_to_format_unfold(), callable_as_string(), cil_dis(), clear_flags(), close_optionals(), cmd_pxr(), construct_reloc_name(), dex_resolve_proto_id(), diff_unified_lines_hl(), disassemble(), do_handle_ts_unescape_arg(), do_print_child_help(), es_sign_n_64(), esil_branch_check_mask(), esil_branch_compare(), esil_branch_compare_single(), esil_call(), esil_callx(), fill_args(), fill_children_chars(), fill_colored_args(), fill_modes_children_chars(), fill_usage_strbuf(), fill_wrapped_comment(), flirt_pat_append_prelude(), flirt_pat_write_line(), format_cmd_kv(), gb_analysis_add_sp(), gb_analysis_esil_ret(), gb_analysis_load_hl(), gb_analysis_mov_hl_sp(), gb_analysis_mov_ime(), gb_analysis_xoaasc_imm(), generic_array_obj_to_string(), hex_disasm_with_templates(), il_op_effect_resolve(), il_op_pure_resolve(), il_opdmp_blk(), il_opdmp_bool_false(), il_opdmp_bool_true(), il_opdmp_cast(), il_opdmp_let(), il_opdmp_load(), il_opdmp_loadw(), il_opdmp_seq(), il_opdmp_seq_inner(), il_opdmp_set(), il_opdmp_store(), il_opdmp_storew(), lang_byte_array_asm(), lang_byte_array_bash(), lang_byte_array_c_cpp(), lang_byte_array_golang(), lang_byte_array_java(), lang_byte_array_kotlin(), lang_byte_array_nodejs(), lang_byte_array_objective_c_cpp(), lang_byte_array_rizin(), lua53_disasm(), lua54_disasm(), mnemonics(), opex(), opex64(), out_printf(), parse_function(), parse_simple_type(), parse_type(), parsed_args_iterateargs(), pdb_types_print_standard(), pj_raw(), print_byte(), print_cursor_l(), print_cursor_r(), prompt_add_file(), prompt_add_offset(), prompt_add_section(), read_string_val(), replace_directives_for(), replace_lines(), rz_analysis_cc_get(), rz_analysis_data_to_string(), rz_analysis_fcn_format_sig(), rz_analysis_var_get_constraints_readable(), rz_analysis_var_global_get_constraints_readable(), rz_arm_cs_analysis_op_32_esil(), rz_arm_cs_analysis_op_64_esil(), rz_asm_mdisassemble(), rz_bin_java_class_as_source_code(), rz_cmd_parsed_args_execstr(), rz_cons_echo(), rz_cons_grepbuf(), rz_cons_html_filter(), rz_core_analysis_all_vars_display(), rz_core_analysis_il_step_with_events(), rz_core_analysis_var_display(), rz_core_assembly_of_hex(), rz_core_bin_method_flags_str(), rz_core_bin_pdb_gvars_as_string(), rz_core_bin_relocs_print(), rz_core_print_hexdump_byline_str(), rz_core_print_string_c_cpp(), rz_core_types_as_c_all(), rz_core_types_enum_as_c_all(), rz_core_types_struct_as_c_all(), rz_core_types_typedef_as_c_all(), rz_core_types_union_as_c_all(), rz_graph_drawable_to_dot(), rz_il_event_stringify(), rz_pkcs7_cms_to_string(), rz_print_colorize_asm_str(), rz_print_hexdiff_str(), rz_print_hexdump_str(), rz_pseudo_convert(), rz_sign_flirt_parse_string_pattern_from_buffer(), rz_str_array_join(), rz_str_format_msvc_argv(), rz_str_list_join(), rz_str_repeat(), rz_str_stringify_raw_buffer(), rz_str_version(), rz_strbuf_vappendf(), rz_table_tocsv(), rz_table_tosimplestring(), rz_table_visual_list(), rz_type_format_10bytes(), rz_type_format_byte(), rz_type_format_char(), rz_type_format_data_internal(), rz_type_format_decchar(), rz_type_format_double(), rz_type_format_float(), rz_type_format_hex(), rz_type_format_hexflag(), rz_type_format_hexpairs(), rz_type_format_int(), rz_type_format_nulltermstring(), rz_type_format_nulltermwidestring(), rz_type_format_num(), rz_type_format_octal(), rz_type_format_quadword(), rz_type_format_string(), rz_type_format_time(), rz_type_format_u128(), rz_type_format_uleb(), rz_type_format_word(), sh_op_param_to_str(), strbuf_append_calc(), strings_print(), type_as_pretty_string(), type_decl_as_pretty_string(), type_to_format(), type_to_format_pair(), and update_flags().

◆ rz_strbuf_append_n()

RZ_API bool rz_strbuf_append_n ( RzStrBuf sb,
const char *  s,
size_t  l 
)

Definition at line 229 of file strbuf.c.

229  {
230  rz_return_val_if_fail(sb && s, false);
231 
232  if (sb->weakref) {
233  return false;
234  }
235 
236  // fast path if no chars to append
237  if (l == 0) {
238  return true;
239  }
240 
241  if ((sb->len + l + 1) <= sizeof(sb->buf)) {
242  memcpy(sb->buf + sb->len, s, l);
243  sb->buf[sb->len + l] = 0;
244  RZ_FREE(sb->ptr);
245  } else {
246  size_t newlen = sb->len + l + 128;
247  char *p = sb->ptr;
248  bool allocated = true;
249  if (!sb->ptr) {
250  p = malloc(newlen);
251  if (p && sb->len > 0) {
252  memcpy(p, sb->buf, sb->len);
253  }
254  } else if (sb->len + l + 1 > sb->ptrlen) {
255  if (SZT_MUL_OVFCHK(newlen, 2)) {
256  return false;
257  }
258  newlen *= 2;
259  p = realloc(sb->ptr, newlen);
260  } else {
261  allocated = false;
262  }
263  if (allocated) {
264  if (!p) {
265  return false;
266  }
267  sb->ptr = p;
268  sb->ptrlen = newlen;
269  }
270  if (p) {
271  memcpy(p + sb->len, s, l);
272  *(p + sb->len + l) = 0;
273  }
274  }
275  sb->len += l;
276  return true;
277 }
void * p
Definition: libc.cpp:67
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123
#define RZ_FREE(x)
Definition: rz_types.h:369

References malloc(), memcpy(), p, realloc(), RZ_FREE, rz_return_val_if_fail, s, and sb.

Referenced by __parse_string_on_cursor(), dex_resolve_proto_id(), diff_unified_append_data(), diff_unified_lines_hl(), hex_disasm_with_templates(), read_to_strbuf(), replace_lines(), rz_buf_get_nstring(), rz_cons_html_filter(), rz_print_colorize_asm_str(), rz_pseudo_convert(), rz_str_format_msvc_argv(), rz_strbuf_append(), and set_attr().

◆ rz_strbuf_appendf()

RZ_API bool rz_strbuf_appendf ( RzStrBuf sb,
const char *  fmt,
  ... 
)

Definition at line 279 of file strbuf.c.

279  {
280  va_list ap;
281 
282  rz_return_val_if_fail(sb && fmt, -1);
283 
284  va_start(ap, fmt);
285  bool ret = rz_strbuf_vappendf(sb, fmt, ap);
286  va_end(ap);
287  return ret;
288 }
RZ_API bool rz_strbuf_vappendf(RzStrBuf *sb, const char *fmt, va_list ap)
Definition: strbuf.c:290

References rz_return_val_if_fail, rz_strbuf_vappendf(), and sb.

◆ rz_strbuf_copy()

RZ_API bool rz_strbuf_copy ( RzStrBuf dst,
RzStrBuf src 
)

Definition at line 48 of file strbuf.c.

48  {
49  rz_return_val_if_fail(dst && src, false);
50  if (src->ptr) {
51  char *p = malloc(src->ptrlen);
52  if (!p) {
53  return false;
54  }
55  memcpy(p, src->ptr, src->ptrlen);
56  free(dst->ptr);
57  dst->ptr = p;
58  dst->ptrlen = src->ptrlen;
59  } else {
60  RZ_FREE(dst->ptr);
61  memcpy(dst->buf, src->buf, sizeof(dst->buf));
62  }
63  dst->len = src->len;
64  return true;
65 }
lzma_index * src
Definition: index.h:567
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
char * dst
Definition: lz4.h:724

References dst, free(), malloc(), memcpy(), p, RZ_FREE, rz_return_val_if_fail, and src.

Referenced by disassemble(), and rz_analysis_op_copy().

◆ rz_strbuf_drain()

RZ_API RZ_OWN char* rz_strbuf_drain ( RzStrBuf sb)

Definition at line 342 of file strbuf.c.

342  {
344  char *ret = drain(sb);
345  free(sb);
346  return ret;
347 }
#define NULL
Definition: cris-opc.c:27
static char * drain(RzStrBuf *sb)
Definition: strbuf.c:334

References drain(), free(), NULL, rz_return_val_if_fail, and sb.

Referenced by __config_toggle_cb(), __config_value_cb(), __op_refs(), __open_menu_cb(), __update_help(), __update_menu_contents(), argv_get_help(), avr_op(), cmd_print_fromage(), cmd_pxr(), construct_reloc_name(), dex_resolve_proto_id(), do_handle_ts_unescape_arg(), ds_build_op_str(), gdb_to_rz_profile(), group_get_help(), java_field_access_flags_readable(), java_method_access_flags_readable(), mnemonics(), parse_simple_type(), read_string_val(), replace_directives_for(), rz_analysis_cc_get(), rz_analysis_data_to_string(), rz_analysis_fcn_format_sig(), rz_asm_mdisassemble(), rz_asn1_print_hexdump_padded(), rz_asn1_to_string(), rz_axml_decode(), rz_base_type_as_format(), rz_bin_dex_access_flags_readable(), rz_bin_java_class_access_flags_readable(), rz_buf_get_nstring(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_get_help_json(), rz_cmd_help_search_handler(), rz_cmd_parsed_args_argstr(), rz_cmd_parsed_args_execstr(), rz_cmd_shell_mkdir_handler(), rz_cons_echo(), rz_cons_grepbuf(), rz_cons_html_filter(), rz_core_analysis_all_vars_display(), rz_core_analysis_hasrefs_to_depth(), rz_core_analysis_il_vm_status(), rz_core_analysis_var_display(), rz_core_assembly_of_hex(), rz_core_bin_method_flags_str(), rz_core_bin_relocs_print(), rz_core_disasm_instruction(), rz_core_esil_of_assembly(), rz_core_esil_of_hex(), rz_core_hex_of_assembly(), rz_core_print_hexdump_byline_str(), rz_core_print_string_c_cpp(), rz_core_types_as_c_all(), rz_core_types_enum_as_c_all(), rz_core_types_struct_as_c_all(), rz_core_types_typedef_as_c_all(), rz_core_types_union_as_c_all(), rz_core_visual_analysis(), rz_core_visual_analysis_refresh(), rz_core_visual_view_rop(), rz_core_yank_as_string(), rz_diff_unified_text(), rz_list_to_str(), rz_load_panels_layout(), rz_parse_pseudocode(), rz_pkcs7_cms_to_string(), rz_print_hexdiff_str(), rz_print_hexdump_str(), rz_protobuf_decode(), rz_run_get_environ_profile(), rz_str_array_join(), rz_str_list_join(), rz_str_repeat(), rz_str_trim_lines(), rz_str_version(), rz_str_widget_list(), rz_table_tocsv(), rz_table_tofancystring(), rz_table_tosimplestring(), rz_table_visual_list(), rz_type_as_format(), rz_type_as_format_pair(), rz_type_callable_as_string(), rz_type_callable_ptr_as_string(), rz_type_format_data(), rz_x509_crl_to_string(), sh_op_param_to_str(), sh_op_to_str(), show_config_options(), spp_eval_str(), strings_print(), type_as_pretty_string(), ut64_to_hex(), and wasm_dis().

◆ rz_strbuf_drain_nofree()

◆ rz_strbuf_equals()

RZ_API bool rz_strbuf_equals ( RzStrBuf sa,
RzStrBuf sb 
)

Definition at line 16 of file strbuf.c.

16  {
17  rz_return_val_if_fail(sa && sb, false);
18  if (sa->len != sb->len) {
19  return false;
20  }
21  return strcmp(rz_strbuf_get(sa), rz_strbuf_get(sb)) == 0;
22 }
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
size_t len
Definition: rz_strbuf.h:12

References RzStrBuf::len, rz_return_val_if_fail, rz_strbuf_get(), and sb.

◆ rz_strbuf_fini()

RZ_API void rz_strbuf_fini ( RzStrBuf sb)

Definition at line 365 of file strbuf.c.

365  {
366  if (sb && !sb->weakref) {
367  RZ_FREE(sb->ptr);
368  sb->ptr = NULL;
369  sb->len = 0;
370  sb->buf[0] = '\0';
371  }
372 }

References NULL, RZ_FREE, and sb.

Referenced by analop(), analysis_mask_avr(), calc_padding_len(), cil_analyze_op(), count_newlines(), database_load(), diff_unified_append_data(), diff_unified_json_data(), diff_unified_lines_hl(), disassemble(), ds_print_cmt_il(), fcnjoin(), fill_children_chars(), get_atomic_type(), get_callable_type(), get_enum_type(), get_struct_type(), get_typedef_type(), get_union_type(), get_word_from_canvas(), handle_skip_next_instruction(), mips_op(), parse_function(), parse_function_args_and_vars(), parse_typedef(), pj_free(), print_and_check_il(), runword(), rz_analysis_cc_del(), rz_analysis_cc_set_error(), rz_analysis_cc_set_self(), rz_analysis_esil_free(), rz_analysis_op_fini(), rz_asm_op_fini(), rz_core_analysis_il_vm_status(), rz_core_print_disasm(), rz_il_validate_effect(), rz_il_validate_pure(), rz_serialize_analysis_blocks_save(), rz_serialize_analysis_functions_save(), rz_sign_flirt_parse_string_pattern_from_buffer(), rz_sign_flirt_write_string_pattern_to_buffer(), rz_strbuf_free(), rz_subprocess_err(), rz_subprocess_free(), rz_subprocess_out(), rz_subprocess_stdout_read(), rz_subprocess_stdout_readline(), rz_subprocess_wait(), rz_test_test_database_load_fuzz(), save_atomic_type(), save_callable(), save_enum(), save_struct(), save_typedef(), save_union(), sdb_save_dwarf_function(), set_attr(), update_stat_for_op(), and ut64join().

◆ rz_strbuf_free()

RZ_API void rz_strbuf_free ( RzStrBuf sb)

Definition at line 358 of file strbuf.c.

358  {
359  if (sb) {
361  free(sb);
362  }
363 }
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365

References free(), rz_strbuf_fini(), and sb.

Referenced by __config_toggle_cb(), __config_value_cb(), __esil_step_range_cb(), __init_menu_color_settings_layout(), __init_menu_disasm_asm_settings_layout(), __init_menu_disasm_settings_layout(), __init_menu_screen_settings_layout(), __panels_refresh(), __parse_string_on_cursor(), __update_help_title(), __update_modal(), __update_panel_title(), argv_get_help(), c_parser_state_free(), c_parser_state_free_keep_ht(), c_parser_state_reset_keep_ht(), cmd_pxr(), core_analysis_bytes_standard(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), dex_resolve_proto_id(), ds_build_op_str(), fill_usage_strbuf(), gdb_to_rz_profile(), generic_array_obj_to_string(), INST_HANDLER(), main(), mk_reg_str(), parse_localvar(), pdb_types_print_standard(), print_rop(), read_string_val(), replace_directives_for(), rz_analysis_data_to_string(), rz_asm_token_string_free(), rz_axml_decode(), rz_buf_get_nstring(), rz_cmd_javac_handler(), rz_cmd_javaf_handler(), rz_cmd_javai_handler(), rz_cmd_javam_handler(), rz_cmd_javap_handler(), rz_cmd_javas_handler(), rz_cons_canvas_box(), rz_cons_grepbuf(), rz_core_analysis_il_step_with_events(), rz_core_analysis_il_vm_status(), rz_core_assembly_of_hex(), rz_core_bin_pdb_gvars_as_string(), rz_core_bin_sections_mapping_print(), rz_core_disasm_pdi_with_buf(), rz_core_esil_of_assembly(), rz_core_esil_of_hex(), rz_core_hex_of_assembly(), rz_core_print_disasm_all(), rz_core_visual_bit_editor(), rz_core_visual_esil(), rz_core_yank_as_string(), rz_debug_thread_list(), rz_diff_unified_text(), rz_parse_pseudocode(), rz_print_colorize_asm_str(), rz_sign_flirt_parse_string_pattern_from_buffer(), rz_table_visual_list(), rz_type_as_format_pair(), rz_type_callable_as_string(), rz_type_callable_ptr_as_string(), spp_run_str(), type_as_pretty_string(), and visual_help().

◆ rz_strbuf_get()

RZ_API char* rz_strbuf_get ( RzStrBuf sb)

Definition at line 321 of file strbuf.c.

321  {
323  return sb->ptr ? sb->ptr : sb->buf;
324 }

References NULL, rz_return_val_if_fail, and sb.

Referenced by __config_toggle_cb(), __config_value_cb(), __core_cmd_search_asm_byteswap(), __esil_step_range_cb(), __init_menu_color_settings_layout(), __init_menu_disasm_asm_settings_layout(), __init_menu_disasm_settings_layout(), __init_menu_screen_settings_layout(), __isInvalid(), __panels_refresh(), __parse_string_on_cursor(), __update_help_title(), __update_modal(), __update_panel_title(), assemble(), avr_op_analyze(), check_token_coverage(), core_analysis_bytes_standard(), count_newlines(), database_load(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), diff_unified_append_data(), diff_unified_json_data(), diff_unified_lines_hl(), disassemble(), do_assemble(), do_disassemble(), do_ref_search(), ds_atabs_option(), ds_print_cmt_il(), extract_arg(), fcnjoin(), fill_usage_strbuf(), flirt_pat_parse_line(), flirt_pat_write_line(), gbAsm(), generic_array_obj_to_string(), get_src_regname(), get_word_from_canvas(), hex_disasm_with_templates(), INST_HANDLER(), main(), mk_reg_str(), parse_function(), parse_function_args_and_vars(), parse_localvar(), parseHeap(), pdb_types_print_standard(), pj_string(), print_and_check_il(), print_rop(), run_basic_block_analysis(), rz_analysis_esil_trace_op(), rz_analysis_op_to_esil_string(), rz_asm_assemble(), rz_asm_massemble(), rz_asm_mdisassemble(), rz_asm_op_get_asm(), rz_asm_op_get_buf(), rz_asm_op_get_hex(), rz_asm_pseudo_intN(), rz_asm_rasm_assemble(), rz_asm_token_string_clone(), rz_asm_tokenize_asm_regex(), rz_cmd_javac_handler(), rz_cmd_javaf_handler(), rz_cmd_javai_handler(), rz_cmd_javam_handler(), rz_cmd_javap_handler(), rz_cmd_javas_handler(), rz_cmd_print(), rz_cons_canvas_box(), rz_core_analysis_il_step_with_events(), rz_core_analysis_il_vm_status(), rz_core_analysis_op(), rz_core_asm_back_disassemble(), rz_core_asm_strsearch(), rz_core_bin_pdb_gvars_as_string(), rz_core_bin_sections_mapping_print(), rz_core_cmp_disasm(), rz_core_disasm_instruction(), rz_core_disasm_pde(), rz_core_disasm_pdi_with_buf(), rz_core_op_str(), rz_core_print_disasm_all(), rz_core_visual_bit_editor(), rz_core_visual_esil(), rz_debug_thread_list(), rz_print_colorize_asm_str(), rz_serialize_analysis_blocks_save(), rz_serialize_analysis_functions_save(), rz_sign_flirt_parse_string_pattern_from_buffer(), rz_strbuf_equals(), rz_strbuf_set(), rz_strbuf_slice(), rz_subprocess_stdout_readline(), rz_table_tofancystring(), rz_table_tosimplestring(), rz_test_test_database_load_fuzz(), save_enum(), save_struct(), save_union(), sdb_save_dwarf_function(), set_attr(), showanalysis(), spp_run_str(), tokenize_asm_generic(), update_stat_for_op(), ut64join(), and visual_help().

◆ rz_strbuf_getbin()

RZ_API ut8* rz_strbuf_getbin ( RzStrBuf sb,
int len 
)

Definition at line 326 of file strbuf.c.

326  {
328  if (len) {
329  *len = sb->len;
330  }
331  return (ut8 *)(sb->ptr ? sb->ptr : sb->buf);
332 }
size_t len
Definition: 6502dis.c:15
uint8_t ut8
Definition: lh5801.h:11

References len, NULL, rz_return_val_if_fail, and sb.

Referenced by rz_cons_grepbuf(), rz_subprocess_err(), and rz_subprocess_out().

◆ rz_strbuf_init()

RZ_API void rz_strbuf_init ( RzStrBuf sb)

Definition at line 33 of file strbuf.c.

33  {
35  memset(sb, 0, sizeof(RzStrBuf));
36 }
return memset(p, 0, total)
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References memset(), rz_return_if_fail, and sb.

Referenced by _6502_op(), analop_esil(), analysis_mask_avr(), calc_padding_len(), cil_dis(), count_newlines(), database_load(), diff_unified_append_data(), diff_unified_json_data(), diff_unified_lines_hl(), ds_print_cmt_il(), fcnjoin(), fill_children_chars(), format_cmd_kv(), get_word_from_canvas(), handle_skip_next_instruction(), hex_disasm_with_templates(), main(), opex(), opex64(), parse_enum_type(), parse_function(), parse_function_args_and_vars(), parse_struct_member(), parse_typedef(), pj_new(), print_and_check_il(), replace_lines(), rz_analysis_esil_new(), rz_analysis_op_copy(), rz_analysis_var_get_constraints_readable(), rz_analysis_var_global_get_constraints_readable(), rz_arm_cs_analysis_op_32_esil(), rz_arm_cs_analysis_op_64_esil(), rz_asm_rasm_assemble(), rz_core_print_disasm(), rz_graph_drawable_to_dot(), rz_il_validate_effect(), rz_il_validate_pure(), rz_print_addr(), rz_print_byte(), rz_print_section_str(), rz_serialize_analysis_functions_save(), rz_sign_flirt_parse_string_pattern_from_buffer(), rz_sign_flirt_write_string_pattern_to_buffer(), rz_str_format_msvc_argv(), rz_str_stringify_raw_buffer(), rz_strbuf_initf(), rz_strbuf_set(), rz_subprocess_start_opt(), rz_subprocess_stdout_read(), rz_subprocess_stdout_readline(), rz_subprocess_wait(), rz_test_test_database_load_fuzz(), save_atomic_type(), save_callable(), save_enum(), save_struct(), save_typedef(), save_union(), sdb_save_dwarf_function(), set_attr(), set_prompt(), spp_eval_str(), update_stat_for_op(), and ut64join().

◆ rz_strbuf_initf()

RZ_API const char* rz_strbuf_initf ( RzStrBuf sb,
const char *  fmt,
  ... 
)

Definition at line 38 of file strbuf.c.

38  {
39  rz_return_val_if_fail(sb && fmt, NULL);
41  va_list ap;
42  va_start(ap, fmt);
43  const char *r = rz_strbuf_vsetf(sb, fmt, ap);
44  va_end(ap);
45  return r;
46 }
#define r
Definition: crypto_rc6.c:12
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
RZ_API const char * rz_strbuf_vsetf(RzStrBuf *sb, const char *fmt, va_list ap)
Definition: strbuf.c:177

References NULL, r, rz_return_val_if_fail, rz_strbuf_init(), rz_strbuf_vsetf(), and sb.

Referenced by get_atomic_type(), get_callable_type(), get_enum_type(), get_struct_type(), get_typedef_type(), get_union_type(), rz_analysis_cc_del(), rz_analysis_cc_set_error(), rz_analysis_cc_set_self(), rz_core_bin_field_build_flag_name(), and rz_core_bin_method_build_flag_name().

◆ rz_strbuf_is_empty()

RZ_API bool rz_strbuf_is_empty ( RzStrBuf sb)

Definition at line 24 of file strbuf.c.

24  {
25  return sb->len == 0;
26 }

References sb.

Referenced by fill_children_chars(), get_src_regname(), rz_core_bin_relocs_print(), rz_il_validate_effect(), rz_il_validate_pure(), and tokenize_asm_generic().

◆ rz_strbuf_length()

◆ rz_strbuf_new()

RZ_API RzStrBuf* rz_strbuf_new ( const char *  str)

Definition at line 8 of file strbuf.c.

8  {
10  if (str) {
12  }
13  return s;
14 }
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153

◆ rz_strbuf_prepend()

RZ_API bool rz_strbuf_prepend ( RzStrBuf sb,
const char *  s 
)

Definition at line 201 of file strbuf.c.

201  {
202  rz_return_val_if_fail(sb && s, false);
203  int l = strlen(s);
204  // fast path if no chars to append
205  if (l == 0) {
206  return true;
207  }
208  int newlen = l + sb->len;
209  char *ns = malloc(newlen + 1);
210  bool ret = false;
211  if (ns) {
212  memcpy(ns, s, l);
213  char *s = sb->ptr ? sb->ptr : sb->buf;
214  memcpy(ns + l, s, sb->len);
215  ns[newlen] = 0;
216  ret = rz_strbuf_set(sb, ns);
217  free(ns);
218  }
219  return ret;
220 }

References free(), malloc(), memcpy(), rz_return_val_if_fail, rz_strbuf_set(), s, and sb.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), fill_children_chars(), rz_table_tofancystring(), and ut64_to_hex().

◆ rz_strbuf_reserve()

RZ_API bool rz_strbuf_reserve ( RzStrBuf sb,
size_t  len 
)

Definition at line 67 of file strbuf.c.

67  {
68  rz_return_val_if_fail(sb, false);
69 
70  if ((sb->ptr && len < sb->ptrlen) || (!sb->ptr && len < sizeof(sb->buf))) {
71  return true;
72  }
73  char *newptr = realloc(sb->ptr, len + 1);
74  if (!newptr) {
75  return false;
76  }
77  if (!sb->ptr) {
78  memcpy(newptr, sb->buf, sizeof(sb->buf));
79  }
80  sb->ptr = newptr;
81  sb->ptrlen = len + 1;
82  return true;
83 }

References len, memcpy(), realloc(), rz_return_val_if_fail, and sb.

Referenced by rz_analysis_data_to_string(), and rz_parse_pseudocode().

◆ rz_strbuf_set()

RZ_API const char* rz_strbuf_set ( RzStrBuf sb,
const char *  s 
)

Definition at line 153 of file strbuf.c.

153  {
155  if (!s) {
157  return rz_strbuf_get(sb);
158  }
159  size_t len = strlen(s);
160  if (!rz_strbuf_setbin(sb, (const ut8 *)s, len)) {
161  return NULL;
162  }
163  sb->len = len;
164  return rz_strbuf_get(sb);
165 }
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t l)
Definition: strbuf.c:85

References len, NULL, rz_return_val_if_fail, rz_strbuf_get(), rz_strbuf_init(), rz_strbuf_setbin(), s, and sb.

Referenced by _6502_op(), _6502Disass(), __generic_io_dest(), __init_menu_disasm_asm_settings_layout(), __init_menu_disasm_settings_layout(), __init_menu_screen_settings_layout(), __panels_refresh(), analop_esil(), assemble_8051(), avr_op_analyze(), avr_unique(), construct_reloc_name(), dalvik_disassemble(), disassemble(), fill_children_chars(), gb_analysis_id(), gb_analysis_jmp_hl(), gb_analysis_load(), gb_analysis_load_hl(), gb_analysis_mov_scf(), gb_analysis_mov_sp_hl(), gb_analysis_store(), gb_analysis_store_hl(), gb_analysis_xor_ccf(), gb_analysis_xor_cpl(), gb_anop(), gbAsm(), hexagon_reverse_opcode(), i4004dis(), java_disassemble(), line_stringify(), mcs96_len(), parse(), parseHeap(), pj_reset(), rsp_op(), runword(), rz_analysis_op_hint(), rz_arm_cs_analysis_op_32_esil(), rz_arm_cs_analysis_op_64_esil(), rz_asm_disassemble(), rz_asm_op_set_asm(), rz_asm_pseudo_string(), rz_pseudo_convert(), rz_pyc_disasm(), rz_strbuf_new(), rz_strbuf_prepend(), rz_strbuf_vsetf(), set_invalid_op(), snesDisass(), spc700_disas(), strbuf_rev_append_char(), strbuf_rev_prepend_char(), update_stat_for_op(), and wasm_dis().

◆ rz_strbuf_setbin()

RZ_API bool rz_strbuf_setbin ( RzStrBuf sb,
const ut8 s,
size_t  l 
)

Definition at line 85 of file strbuf.c.

85  {
86  rz_return_val_if_fail(sb && s, false);
87  if (l >= sizeof(sb->buf)) {
88  char *ptr = sb->ptr;
89  if (!ptr || l + 1 > sb->ptrlen) {
90  ptr = malloc(l + 1);
91  if (!ptr) {
92  return false;
93  }
94  RZ_FREE(sb->ptr);
95  sb->ptrlen = l + 1;
96  sb->ptr = ptr;
97  }
98  memcpy(ptr, s, l);
99  ptr[l] = 0;
100  } else {
101  RZ_FREE(sb->ptr);
102  memcpy(sb->buf, s, l);
103  sb->buf[l] = 0;
104  }
105  sb->len = l;
106  sb->weakref = false;
107  return true;
108 }

References malloc(), memcpy(), RZ_FREE, rz_return_val_if_fail, s, and sb.

Referenced by _write_asm(), assemble(), assemble_8051(), binutils_assemble(), dalvik_assemble(), java_assemble(), rz_asm_op_set_buf(), rz_asm_op_set_hex(), rz_luac_asm(), rz_strbuf_set(), and update_stat_for_op().

◆ rz_strbuf_setf()

RZ_API const char* rz_strbuf_setf ( RzStrBuf sb,
const char *  fmt,
  ... 
)

Definition at line 167 of file strbuf.c.

167  {
168  rz_return_val_if_fail(sb && fmt, false);
169 
170  va_list ap;
171  va_start(ap, fmt);
172  const char *ret = rz_strbuf_vsetf(sb, fmt, ap);
173  va_end(ap);
174  return ret;
175 }

References rz_return_val_if_fail, rz_strbuf_vsetf(), and sb.

◆ rz_strbuf_setptr()

RZ_API bool rz_strbuf_setptr ( RzStrBuf sb,
char *  s,
int  len 
)

Definition at line 139 of file strbuf.c.

139  {
140  rz_return_val_if_fail(sb, false);
141  if (len < 0) {
142  sb->len = strlen(s);
143  sb->ptrlen = sb->len + 1;
144  } else {
145  sb->ptrlen = len;
146  sb->len = len;
147  }
148  sb->ptr = s;
149  sb->weakref = true;
150  return true;
151 }

References len, rz_return_val_if_fail, s, and sb.

◆ rz_strbuf_slice()

RZ_API bool rz_strbuf_slice ( RZ_NONNULL RzStrBuf sb,
size_t  from,
size_t  len 
)

Cuts the current string into a substring.

Only to be used on strings, not binary buffers. If len > sb->len - from, then the resulting size will be truncated appropriately.

Parameters
sbRzStrBuf to use
fromBegin index from where to cut
lenLength of the substring to cut
Returns
false when fails to to cut the current buffer into a substring

Definition at line 122 of file strbuf.c.

122  {
123  rz_return_val_if_fail(sb && from >= 0 && len >= 0, false);
124  if (from >= sb->len) {
125  // trying to cut outside the buf
126  return !sb->len && !from; // but it's fine if both are 0
127  }
128  char *s = rz_strbuf_get(sb);
129  len = RZ_MIN(sb->len - from, len);
130  if (from) {
131  memmove(s, s + from, len);
132  }
133  sb->len = len;
134  sb->ptrlen = len + 1;
135  s[len] = 0;
136  return true;
137 }
#define RZ_MIN(x, y)
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123

References from, len, RZ_MIN, rz_return_val_if_fail, rz_strbuf_get(), s, and sb.

Referenced by __update_panel_title(), flirt_pat_write_line(), parse_function_args_and_vars(), rz_analysis_fcn_format_sig(), sdb_save_dwarf_function(), and type_as_pretty_string().

◆ rz_strbuf_vappendf()

RZ_API bool rz_strbuf_vappendf ( RzStrBuf sb,
const char *  fmt,
va_list  ap 
)

Definition at line 290 of file strbuf.c.

290  {
291  int ret;
292  va_list ap2;
293  char string[1024];
294 
295  rz_return_val_if_fail(sb && fmt, -1);
296 
297  if (sb->weakref) {
298  return false;
299  }
300  va_copy(ap2, ap);
301  ret = vsnprintf(string, sizeof(string), fmt, ap);
302  if (ret >= sizeof(string)) {
303  char *p = malloc(ret + 1);
304  if (!p) {
305  va_end(ap2);
306  return false;
307  }
308  *p = 0;
309  vsnprintf(p, ret + 1, fmt, ap2);
310  ret = rz_strbuf_append(sb, p);
311  free(p);
312  } else if (ret >= 0) {
313  ret = rz_strbuf_append(sb, string);
314  } else {
315  ret = false;
316  }
317  va_end(ap2);
318  return ret;
319 }
vsnprintf
Definition: kernel.h:366
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222

References free(), malloc(), p, rz_return_val_if_fail, rz_strbuf_append(), sb, and vsnprintf.

Referenced by parser_debug(), parser_error(), parser_warning(), and rz_strbuf_appendf().

◆ rz_strbuf_vsetf()

RZ_API const char* rz_strbuf_vsetf ( RzStrBuf sb,
const char *  fmt,
va_list  ap 
)

Definition at line 177 of file strbuf.c.

177  {
178  rz_return_val_if_fail(sb && fmt, false);
179 
180  const char *ret = NULL;
181  va_list ap2;
182  va_copy(ap2, ap);
183  char string[1024];
184  int rc = vsnprintf(string, sizeof(string), fmt, ap);
185  if (rc >= sizeof(string)) {
186  char *p = malloc(rc + 1);
187  if (!p) {
188  goto done;
189  }
190  vsnprintf(p, rc + 1, fmt, ap2);
191  ret = rz_strbuf_set(sb, p);
192  free(p);
193  } else if (rc >= 0) {
194  ret = rz_strbuf_set(sb, string);
195  }
196 done:
197  va_end(ap2);
198  return ret;
199 }
struct tab * done
Definition: enough.c:233

References done, free(), malloc(), NULL, p, rz_return_val_if_fail, rz_strbuf_set(), sb, and vsnprintf.

Referenced by rz_strbuf_initf(), and rz_strbuf_setf().