Rizin
unix-like reverse engineering framework and cli tools
core_private.h File Reference
#include <rz_types.h>
#include <rz_core.h>
#include <rz_il.h>

Go to the source code of this file.

Functions

RZ_IPI void rz_core_kuery_print (RzCore *core, const char *k)
 
RZ_IPI int rz_output_mode_to_char (RzOutputMode mode)
 
RZ_IPI int bb_cmpaddr (const void *_a, const void *_b)
 
RZ_IPI int fcn_cmpaddr (const void *_a, const void *_b)
 
RZ_IPI int rz_core_analysis_set_reg (RzCore *core, const char *regname, ut64 val)
 
RZ_IPI void rz_core_analysis_esil_init (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_init_mem_p (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_step_over_until (RzCore *core, ut64 addr)
 
RZ_IPI void rz_core_analysis_esil_step_over_untilexpr (RzCore *core, const char *expr)
 
RZ_IPI void rz_core_analysis_esil_references_all_functions (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_emulate (RzCore *core, ut64 addr, ut64 until_addr, int off)
 
RZ_IPI void rz_core_analysis_esil_emulate_bb (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_default (RzCore *core)
 
RZ_IPI void rz_core_analysis_il_reinit (RzCore *core)
 
RZ_IPI bool rz_core_analysis_il_vm_set (RzCore *core, const char *var_name, ut64 value)
 Set a vm variable from user input. More...
 
RZ_IPI void rz_core_analysis_il_vm_status (RzCore *core, const char *varname, RzOutputMode mode)
 
RZ_IPI bool rz_core_il_step (RzCore *core)
 
RZ_IPI bool rz_core_analysis_il_step_with_events (RzCore *core, PJ *pj)
 
RZ_IPI bool rz_core_analysis_var_rename (RzCore *core, const char *name, const char *newname)
 
RZ_IPI char * rz_core_analysis_function_signature (RzCore *core, RzOutputMode mode, char *fcn_name)
 
RZ_IPI bool rz_core_analysis_function_delete_var (RzCore *core, RzAnalysisFunction *fcn, RzAnalysisVarKind kind, const char *id)
 
RZ_IPI char * rz_core_analysis_var_display (RzCore *core, RzAnalysisVar *var, bool add_name)
 
RZ_IPI char * rz_core_analysis_all_vars_display (RzCore *core, RzAnalysisFunction *fcn, bool add_name)
 
RZ_IPI bool rz_analysis_var_global_list_show (RzAnalysis *analysis, RzCmdStateOutput *state, RZ_NULLABLE const char *name)
 
RZ_IPI bool rz_core_analysis_types_propagation (RzCore *core)
 
RZ_IPI bool rz_core_analysis_function_set_signature (RzCore *core, RzAnalysisFunction *fcn, const char *newsig)
 
RZ_IPI void rz_core_analysis_function_signature_editor (RzCore *core, ut64 addr)
 
RZ_IPI void rz_core_analysis_bbs_asciiart (RzCore *core, RzAnalysisFunction *fcn)
 
RZ_IPI void rz_core_analysis_fcn_returns (RzCore *core, RzAnalysisFunction *fcn)
 
RZ_IPI void rz_core_analysis_bbs_info_print (RzCore *core, RzAnalysisFunction *fcn, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_analysis_bb_info_print (RzCore *core, RzAnalysisBlock *bb, ut64 addr, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_analysis_function_until (RzCore *core, ut64 addr_end)
 
RZ_IPI void rz_core_analysis_value_pointers (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_analysis_cc_print (RzCore *core, RZ_NONNULL const char *cc, RZ_NULLABLE PJ *pj)
 Print Calling Convention info. More...
 
RZ_IPI void rz_core_spaces_print (RzCore *core, RzSpaces *spaces, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_meta_print (RzCore *core, RzAnalysisMetaItem *d, ut64 start, ut64 size, bool show_full, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_meta_print_list_at (RzCore *core, ut64 addr, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_meta_print_list_all (RzCore *core, int type, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_meta_print_list_in_function (RzCore *core, int type, ut64 addr, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_meta_append (RzCore *core, const char *newcomment, RzAnalysisMetaType mtype, ut64 addr)
 
RZ_IPI void rz_core_meta_editor (RzCore *core, RzAnalysisMetaType mtype, ut64 addr)
 
RZ_IPI void rz_core_types_enum_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_enum_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_union_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_union_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_union_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_union_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_struct_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_struct_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_typedef_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_typedef_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c (RzTypeDB *typedb, const RzBaseType *btype)
 
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c_all (RzTypeDB *typedb)
 
RZ_IPI RZ_OWN char * rz_core_base_type_as_c (RzCore *core, RZ_NONNULL RzBaseType *type, bool multiline)
 
RZ_IPI void rz_core_types_calling_conventions_print (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_function_print (RzTypeDB *typedb, const char *function, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_function_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_function_noreturn_print (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_show_format (RzCore *core, const char *name, RzOutputMode mode)
 
RZ_IPI void rz_core_types_struct_print_format_all (RzCore *core)
 
RZ_IPI void rz_core_types_union_print_format_all (RzCore *core)
 
RZ_IPI void rz_core_types_link_print (RzCore *core, RzType *type, ut64 addr, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_link_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_link_show (RzCore *core, ut64 addr)
 
RZ_IPI void rz_core_types_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_types_define (RzCore *core, const char *type)
 
RZ_IPI bool rz_types_open_file (RzCore *core, const char *path)
 
RZ_IPI bool rz_types_open_editor (RzCore *core, RZ_NONNULL const char *typename)
 
RZ_IPI void rz_core_agraph_add_node (RzCore *core, const char *title, const char *body, int color)
 
RZ_IPI void rz_core_agraph_del_node (RzCore *core, const char *title)
 
RZ_IPI void rz_core_agraph_add_edge (RzCore *core, const char *un, const char *vn)
 
RZ_IPI void rz_core_agraph_del_edge (RzCore *core, const char *un, const char *vn)
 
RZ_IPI void rz_core_agraph_reset (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_ascii (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_tiny (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_sdb (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_interactive (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_dot (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_rizin (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_json (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_gml (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_write (RzCore *core, const char *filename)
 
RZ_IPI RzCmdStatus rz_core_bin_plugin_print (const RzBinPlugin *bp, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_core_binxtr_plugin_print (const RzBinXtrPlugin *bx, RzCmdStateOutput *state)
 
RZ_IPI RzListrz_core_reg_flags_candidates (RzCore *core, RzReg *reg)
 
RZ_IPI void rz_core_reg_print_diff (RzReg *reg, RzList *items)
 Print registers that have changed since the last step (drd/ard) More...
 
RZ_IPI void rz_core_debug_sync_bits (RzCore *core)
 
RZ_IPI void rz_core_debug_single_step_in (RzCore *core)
 
RZ_IPI void rz_core_debug_single_step_over (RzCore *core)
 
RZ_IPI void rz_core_debug_continue (RzCore *core)
 
RZ_IPI void rz_core_debug_attach (RzCore *core, int pid)
 
RZ_IPI void rz_core_debug_print_status (RzCore *core)
 
RZ_IPI void rz_core_debug_bp_add (RzCore *core, ut64 addr, const char *arg_perm, bool hwbp, bool watch)
 
RZ_IPI RzCoreIOMapInforz_core_io_map_info_new (RzCoreFile *cf, int perm_orig)
 
RZ_IPI void rz_core_io_map_info_free (RzCoreIOMapInfo *info)
 
RZ_IPI void rz_core_flag_print (RzFlag *f, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_flag_real_name_print (RzFlag *f, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_flag_range_print (RzFlag *f, RzCmdStateOutput *state, ut64 range_from, ut64 range_to)
 
RZ_IPI bool rz_disasm_check_end (int nb_opcodes, int i_opcodes, int nb_bytes, int i_bytes)
 Is i_opcodes < nb_opcodes and i_bytes < nb_bytes ? More...
 
RZ_IPI void rz_core_asm_bb_middle (RZ_NONNULL RzCore *core, ut64 at, RZ_INOUT RZ_NONNULL int *oplen, RZ_NONNULL int *ret)
 Update oplen by "asm.bb.middle" and "asm.flags.middle". More...
 
RZ_IPI bool rz_core_handle_backwards_disasm (RZ_NONNULL RzCore *core, RZ_NONNULL RZ_INOUT int *pn_opcodes, RZ_NONNULL RZ_INOUT int *pn_bytes)
 Converting negative numbers n_opcodes and n_opcodes to positive numbers n_opcodes and n_opcodes and seek the appropriate offset. More...
 
RZ_IPI bool rz_core_print_hexdump_diff (RZ_NONNULL RzCore *core, ut64 aa, ut64 ba, ut64 len)
 
RZ_IPI bool rz_core_print_dump (RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, ut8 n, int len, RzCorePrintFormatType format)
 
RZ_IPI bool rz_core_print_hexdump_or_hexdiff (RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, int len, bool use_comments)
 
RZ_IPI bool rz_core_print_hexdump_byline (RZ_NONNULL RzCore *core, bool hex_offset, ut64 addr, int len, ut8 size)
 
RZ_IPI bool rz_core_seek_to_register (RzCore *core, const char *input, bool is_silent)
 
RZ_IPI int rz_core_seek_opcode_forward (RzCore *core, int n, bool silent)
 
RZ_IPI int rz_core_seek_opcode (RzCore *core, int numinstr, bool silent)
 
RZ_IPI bool rz_core_seek_bb_instruction (RzCore *core, int index)
 
RZ_IPI void rz_core_meta_comment_add (RzCore *core, const char *comment, ut64 addr)
 
RZ_IPI void rz_core_flag_describe (RzCore *core, ut64 addr, bool strict_offset, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_static_debug_stop (void *u)
 
RZ_IPI RzCmdStatus rz_regs_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_regs_columns_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_references_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI void rz_regs_show_valgroup (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
 
RZ_IPI RzCmdStatus rz_regs_valgroup_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_push_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_pop_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_swap_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_zero_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_hexdump_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_stack_size_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_write_hex_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_args_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_reg_types_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_roles_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_flags_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, bool unset)
 
RZ_IPI RzCmdStatus rz_reg_profile_handler (RzCore *core, RzReg *reg, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_reg_profile_comments_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_profile_open_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_profile_gdb_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_cond_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_cc_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_diff_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_prev_handler (RzCore *core, RzReg *reg, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_regs_fpu_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI void rz_core_print_hexdump (RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
 
RZ_IPI void rz_core_print_jsondump (RZ_NONNULL RzCore *core, RZ_NONNULL const ut8 *buf, int len, int wordsize)
 
RZ_IPI void rz_core_print_hexdiff (RZ_NONNULL RzCore *core, ut64 aa, RZ_NONNULL const ut8 *_a, ut64 ba, RZ_NONNULL const ut8 *_b, int len, int scndcol)
 
RZ_IPI bool rz_core_cmd_lastcmd_repeat (RzCore *core, bool next)
 
static RzCmdStatus bool2status (bool val)
 

Function Documentation

◆ bb_cmpaddr()

RZ_IPI int bb_cmpaddr ( const void *  _a,
const void *  _b 
)

Definition at line 35 of file canalysis.c.

35  {
36  const RzAnalysisBlock *a = _a, *b = _b;
37  return (a->addr > b->addr) - (a->addr < b->addr);
38 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, and b.

◆ bool2status()

static RzCmdStatus bool2status ( bool  val)
inlinestatic

Definition at line 208 of file core_private.h.

208  {
210 }
ut16 val
Definition: armass64_const.h:6
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26

References RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and val.

Referenced by open_core_file(), reopen_nobin_headers(), rz_analyse_name_handler(), rz_analysis_continue_until_call_handler(), rz_analysis_continue_until_syscall_handler(), rz_analysis_function_add_recu_handler(), rz_analysis_hint_set_offset_handler(), rz_analyze_all_objc_references_handler(), rz_analyze_recursively_all_function_types_handler(), rz_analyze_xrefs_section_bytes_handler(), rz_apply_signatures_from_sigdb_handler(), rz_basefind_compute_handler(), rz_cmd_debug_handler_set_handler(), rz_cmd_debug_process_close_handler(), rz_cmd_debug_step_back_handler(), rz_cmd_debug_step_frame_handler(), rz_cmd_debug_step_handler(), rz_cmd_debug_step_line_handler(), rz_cmd_debug_step_over_handler(), rz_cmd_debug_step_skip_handler(), rz_cmd_disassembly_n_bytes_handler(), rz_cmd_disassembly_n_instructions_handler(), rz_cmd_eval_color_load_theme_handler(), rz_cmd_info_archs_handler(), rz_cmd_info_binary_handler(), rz_cmd_info_class_as_source_handler(), rz_cmd_info_class_fields_handler(), rz_cmd_info_class_methods_handler(), rz_cmd_info_classes_handler(), rz_cmd_info_cur_export_handler(), rz_cmd_info_cur_section_handler(), rz_cmd_info_cur_segment_handler(), rz_cmd_info_cur_symbol_handler(), rz_cmd_info_dwarf_handler(), rz_cmd_info_entry_handler(), rz_cmd_info_entryexits_handler(), rz_cmd_info_exports_handler(), rz_cmd_info_fields_handler(), rz_cmd_info_guess_size_handler(), rz_cmd_info_handler(), rz_cmd_info_headers_handler(), rz_cmd_info_imports_handler(), rz_cmd_info_libs_handler(), rz_cmd_info_main_handler(), rz_cmd_info_memory_handler(), rz_cmd_info_pdb_load_handler(), rz_cmd_info_relocs_handler(), rz_cmd_info_resources_handler(), rz_cmd_info_sections_handler(), rz_cmd_info_segments_handler(), rz_cmd_info_signature_handler(), rz_cmd_info_source_handler(), rz_cmd_info_sourcelines_handler(), rz_cmd_info_sourcelines_here_handler(), rz_cmd_info_strings_handler(), rz_cmd_info_symbols_handler(), rz_cmd_info_trycatch_handler(), rz_cmd_info_versions_handler(), rz_cmd_info_whole_strings_handler(), rz_flag_add_handler(), rz_flag_append_handler(), rz_flag_comment_handler(), rz_flag_move_handler(), rz_flag_remove_handler(), rz_flag_space_add_handler(), rz_flag_space_remove_all_handler(), rz_flag_space_remove_handler(), rz_flag_space_rename_handler(), rz_flag_space_stack_pop_handler(), rz_flag_space_stack_push_handler(), rz_meta_format_handler(), rz_meta_hidden_handler(), rz_meta_magic_handler(), rz_open_handler(), rz_open_write_handler(), rz_print_commands_after_traps_handler(), rz_print_hexdump_comments_handler(), rz_print_hexdump_handler(), rz_print_hexdump_hex_common_handler(), rz_print_hexdump_hexl_common_handler(), rz_print_hexdump_n_lines_handler(), rz_print_hexdump_oct_handler(), rz_print_hexdump_signed_integer_common_handler(), rz_print_op_analysis_color_map_handler(), rz_push_escaped_handler(), rz_reopen_binary_handler(), rz_reopen_nobin_handler(), rz_reopen_nobin_write_handler(), rz_write_assembly_opcode_handler(), rz_write_block_handler(), rz_write_debruijn_handler(), rz_write_duplicate_handler(), rz_write_extend_hexbytes_handler(), rz_write_extend_shift_handler(), rz_write_extend_zero_handler(), rz_write_handler(), rz_write_mask_reset_handler(), rz_write_mask_set_handler(), rz_write_op_2byteswap_handler(), rz_write_op_4byteswap_handler(), rz_write_op_8byteswap_handler(), rz_write_op_decrypt_handler(), rz_write_op_encrypt_handler(), rz_write_op_sequence_handler(), rz_write_pcache_commit_handler(), rz_write_wide_string_handler(), rz_write_zero_string_handler(), rz_yank_hex_print_handler(), rz_yank_hexpairs_handler(), rz_yank_paste_handler(), rz_yank_print_handler(), rz_yank_string_handler(), rz_yank_string_print_handler(), rz_yank_to_handler(), and write_op_val().

◆ fcn_cmpaddr()

RZ_IPI int fcn_cmpaddr ( const void *  _a,
const void *  _b 
)

Definition at line 40 of file canalysis.c.

40  {
41  const RzAnalysisFunction *a = _a, *b = _b;
42  return (a->addr > b->addr) - (a->addr < b->addr);
43 }

References a, and b.

Referenced by rz_analysis_function_list_ascii_handler().

◆ rz_analysis_var_global_list_show()

RZ_IPI bool rz_analysis_var_global_list_show ( RzAnalysis analysis,
RzCmdStateOutput state,
RZ_NULLABLE const char *  name 
)

Definition at line 6220 of file canalysis.c.

6220  {
6221  rz_return_val_if_fail(analysis && state, false);
6222  RzList *global_vars = NULL;
6223  RzAnalysisVarGlobal *glob = NULL;
6224  if (name) {
6225  global_vars = rz_list_new();
6226  if (!global_vars) {
6227  return false;
6228  }
6229  glob = rz_analysis_var_global_get_byname(analysis, name);
6230  if (!glob) {
6231  RZ_LOG_ERROR("Global variable '%s' does not exist!\n", name);
6232  rz_list_free(global_vars);
6233  return false;
6234  }
6235  rz_list_append(global_vars, glob);
6236  } else {
6237  global_vars = rz_analysis_var_global_get_all(analysis);
6238  }
6239 
6240  RzListIter *it = NULL;
6241  char *var_type = NULL;
6242  bool json = state->mode == RZ_OUTPUT_MODE_JSON;
6243  PJ *pj = json ? state->d.pj : NULL;
6244 
6246  if (!global_vars) {
6248  return false;
6249  }
6250  rz_list_foreach (global_vars, it, glob) {
6251  var_type = rz_type_as_string(analysis->typedb, glob->type);
6252  if (!var_type) {
6253  continue;
6254  }
6255  switch (state->mode) {
6257  rz_cons_printf("global %s %s @ 0x%" PFMT64x "\n",
6258  var_type, glob->name, glob->addr);
6259  break;
6260  case RZ_OUTPUT_MODE_JSON:
6261  pj_o(pj);
6262  pj_ks(pj, "name", glob->name);
6263  pj_ks(pj, "type", var_type);
6264  char addr[32];
6265  rz_strf(addr, "0x%" PFMT64x, glob->addr);
6266  pj_ks(pj, "addr", addr);
6267  pj_end(pj);
6268  break;
6269  default:
6270  break;
6271  }
6272  free(var_type);
6273  }
6275  rz_list_free(global_vars);
6276  return true;
6277 }
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define PFMT64x
Definition: rz_types.h:393
Definition: z80asm.h:102
Definition: rz_pj.h:12
RzTypeDB * typedb
Definition: rz_analysis.h:602
Global variables.
Definition: rz_analysis.h:744
RzType * type
type of the variable
Definition: rz_analysis.h:748
ut64 addr
address of the global variable
Definition: rz_analysis.h:747
char * name
name of the variable
Definition: rz_analysis.h:746
Definition: dis.h:43
RZ_API RZ_OWN char * rz_type_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the type C representation.
Definition: type.c:817
RZ_API RZ_OWN RzList * rz_analysis_var_global_get_all(RzAnalysis *analysis)
Get all of the added global variables.
Definition: var_global.c:259
RZ_API RZ_BORROW RzAnalysisVarGlobal * rz_analysis_var_global_get_byname(RzAnalysis *analysis, RZ_NONNULL const char *name)
Get the instance of global variable by its name.
Definition: var_global.c:190
static int addr
Definition: z80asm.c:58

References addr, rz_analysis_var_global_t::addr, free(), rz_analysis_var_global_t::name, NULL, PFMT64x, pj_end(), pj_ks(), pj_o(), rz_analysis_var_global_get_all(), rz_analysis_var_global_get_byname(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cons_printf(), rz_list_append(), rz_list_free(), rz_list_new(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_return_val_if_fail, rz_strf, rz_type_as_string(), rz_analysis_var_global_t::type, and rz_analysis_t::typedb.

Referenced by rz_analysis_print_global_variable_handler().

◆ rz_core_agraph_add_edge()

RZ_IPI void rz_core_agraph_add_edge ( RzCore core,
const char *  un,
const char *  vn 
)

Definition at line 39 of file cagraph.c.

39  {
40  RzANode *u = rz_agraph_get_node(core->graph, un);
41  RzANode *v = rz_agraph_get_node(core->graph, vn);
42  if (!u) {
43  rz_cons_printf("Node %s not found!\n", un);
44  return;
45  } else if (!v) {
46  rz_cons_printf("Node %s not found!\n", vn);
47  return;
48  }
49  rz_agraph_add_edge(core->graph, u, v);
50 }
RZ_API RzANode * rz_agraph_get_node(const RzAGraph *g, const char *title)
Definition: agraph.c:3852
RZ_API void rz_agraph_add_edge(const RzAGraph *g, RzANode *a, RzANode *b)
Definition: agraph.c:3862
const char * v
Definition: dsignal.c:12
RzAGraph * graph
Definition: rz_core.h:333

References rz_core_t::graph, rz_agraph_add_edge(), rz_agraph_get_node(), rz_cons_printf(), and v.

Referenced by cmd_agraph_edge().

◆ rz_core_agraph_add_node()

RZ_IPI void rz_core_agraph_add_node ( RzCore core,
const char *  title,
const char *  body,
int  color 
)

Definition at line 12 of file cagraph.c.

12  {
13  char *b = strdup(body);
14  if (rz_str_startswith(b, "base64:")) {
15  char *newbody = strdup(b);
16  if (!newbody) {
17  free(b);
18  return;
19  }
20  b = rz_str_replace(newbody, "\\n", "", true);
21  newbody = (char *)rz_base64_decode_dyn(b + strlen("base64:"), -1);
22  free(b);
23  if (!newbody) {
24  return;
25  }
26  b = newbody;
27  }
28  if (!RZ_STR_ISEMPTY(b)) {
29  b = rz_str_append(b, "\n");
30  }
32  free(b);
33 }
RZ_API RzANode * rz_agraph_add_node_with_color(const RzAGraph *g, const char *title, const char *body, int color)
Definition: agraph.c:3726
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 ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
static int color
Definition: visual.c:20

References b, color, free(), rz_core_t::graph, rz_agraph_add_node_with_color(), rz_base64_decode_dyn(), rz_str_append(), RZ_STR_ISEMPTY, rz_str_replace(), rz_str_startswith(), and strdup().

Referenced by cmd_agraph_node().

◆ rz_core_agraph_del_edge()

RZ_IPI void rz_core_agraph_del_edge ( RzCore core,
const char *  un,
const char *  vn 
)

Definition at line 52 of file cagraph.c.

52  {
53  RzANode *u = rz_agraph_get_node(core->graph, un);
54  RzANode *v = rz_agraph_get_node(core->graph, vn);
55  if (!u) {
56  rz_cons_printf("Node %s not found!\n", un);
57  return;
58  } else if (!v) {
59  rz_cons_printf("Node %s not found!\n", vn);
60  return;
61  }
62  rz_agraph_del_edge(core->graph, u, v);
63 }
RZ_API void rz_agraph_del_edge(const RzAGraph *g, RzANode *a, RzANode *b)
Definition: agraph.c:3880

References rz_core_t::graph, rz_agraph_del_edge(), rz_agraph_get_node(), rz_cons_printf(), and v.

Referenced by cmd_agraph_edge().

◆ rz_core_agraph_del_node()

RZ_IPI void rz_core_agraph_del_node ( RzCore core,
const char *  title 
)

Definition at line 35 of file cagraph.c.

35  {
36  rz_agraph_del_node(core->graph, title);
37 }
RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title)
Definition: agraph.c:3769

References rz_core_t::graph, and rz_agraph_del_node().

Referenced by cmd_agraph_node().

◆ rz_core_agraph_print_ascii()

RZ_IPI void rz_core_agraph_print_ascii ( RzCore core)

Definition at line 65 of file cagraph.c.

65  {
66  core->graph->can->linemode = rz_config_get_i(core->config, "graph.linemode");
67  core->graph->can->color = rz_config_get_i(core->config, "scr.color");
68  rz_agraph_set_title(core->graph, rz_config_get(core->config, "graph.title"));
69  rz_agraph_print(core->graph);
70 }
RZ_API void rz_agraph_set_title(RzAGraph *g, const char *title)
Definition: agraph.c:3720
RZ_API void rz_agraph_print(RzAGraph *g)
Definition: agraph.c:3687
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RzConsCanvas * can
Definition: rz_agraph.h:47
RzConfig * config
Definition: rz_core.h:300

References rz_ascii_graph_t::can, rz_cons_canvas_t::color, rz_core_t::config, rz_core_t::graph, rz_cons_canvas_t::linemode, rz_agraph_print(), rz_agraph_set_title(), rz_config_get(), and rz_config_get_i().

Referenced by cmd_analysis_graph(), and rz_core_agraph_print().

◆ rz_core_agraph_print_dot()

RZ_IPI void rz_core_agraph_print_dot ( RzCore core)

Definition at line 147 of file cagraph.c.

147  {
148  const char *font = rz_config_get(core->config, "graph.font");
149  rz_cons_printf("digraph code {\nrankdir=LR;\noutputorder=edgesfirst\ngraph [bgcolor=azure];\n"
150  "edge [arrowhead=normal, color=\"#3030c0\" style=bold weight=2];\n"
151  "node [fillcolor=white, style=filled shape=box "
152  "fontname=\"%s\" fontsize=\"8\"];\n",
153  font);
156  rz_cons_printf("}\n");
157 }
RZ_API void rz_agraph_foreach_edge(RzAGraph *g, RAEdgeCallback cb, void *user)
Definition: agraph.c:3837
RZ_API void rz_agraph_foreach(RzAGraph *g, RzANodeCallback cb, void *user)
Definition: agraph.c:3829
static void agraph_print_edge_dot(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:125
static void agraph_print_node_dot(RzANode *n, void *user)
Definition: cagraph.c:112

References agraph_print_edge_dot(), agraph_print_node_dot(), rz_core_t::config, rz_core_t::graph, NULL, rz_agraph_foreach(), rz_agraph_foreach_edge(), rz_config_get(), and rz_cons_printf().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_gml()

RZ_IPI void rz_core_agraph_print_gml ( RzCore core)

Definition at line 195 of file cagraph.c.

195  {
196  rz_cons_printf("graph\n[\n"
197  "hierarchic 1\n"
198  "label \"\"\n"
199  "directed 1\n");
202  rz_cons_print("]\n");
203 }
static void agraph_print_edge_gml(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:187
static void agraph_print_node_gml(RzANode *n, void *user)
Definition: cagraph.c:179

References agraph_print_edge_gml(), agraph_print_node_gml(), rz_core_t::graph, NULL, rz_agraph_foreach(), rz_agraph_foreach_edge(), and rz_cons_printf().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_interactive()

RZ_IPI void rz_core_agraph_print_interactive ( RzCore core)

Definition at line 88 of file cagraph.c.

88  {
90  if (!ran) {
91  eprintf("This graph contains no nodes\n");
92  return;
93  }
94 
95  ut64 oseek = core->offset;
96  rz_agraph_set_title(core->graph, rz_config_get(core->config, "graph.title"));
97  rz_agraph_set_curnode(core->graph, ran);
98  core->graph->force_update_seek = true;
99  core->graph->need_set_layout = true;
100  core->graph->layout = rz_config_get_i(core->config, "graph.layout");
101  bool ov = rz_cons_is_interactive();
102  core->graph->need_update_dim = true;
103  int update_seek = rz_core_visual_graph(core, core->graph, NULL, true);
104  rz_config_set_i(core->config, "scr.interactive", ov);
105  rz_cons_show_cursor(true);
106  rz_cons_enable_mouse(false);
107  if (update_seek != -1) {
108  rz_core_seek(core, oseek, false);
109  }
110 }
RZ_API int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_fcn, int is_interactive)
Definition: agraph.c:4114
RZ_API RzANode * rz_agraph_get_first_node(const RzAGraph *g)
Definition: agraph.c:3846
RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *a)
Definition: agraph.c:2696
static void update_seek(RzConsCanvas *can, RzANode *n, int force)
Definition: agraph.c:2511
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API bool rz_cons_enable_mouse(const bool enable)
Definition: cons.c:500
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
RZ_API void rz_cons_show_cursor(int cursor)
Definition: cons.c:1581
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
int force_update_seek
Definition: rz_agraph.h:71
bool need_set_layout
Definition: rz_agraph.h:69
ut64 offset
Definition: rz_core.h:301
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::config, eprintf, rz_ascii_graph_t::force_update_seek, rz_core_t::graph, rz_ascii_graph_t::layout, rz_ascii_graph_t::need_set_layout, rz_ascii_graph_t::need_update_dim, NULL, rz_core_t::offset, rz_agraph_get_first_node(), rz_agraph_set_curnode(), rz_agraph_set_title(), rz_config_get(), rz_config_get_i(), rz_config_set_i(), rz_cons_enable_mouse(), rz_cons_is_interactive(), rz_cons_show_cursor(), rz_core_seek(), rz_core_visual_graph(), update_seek(), and ut64().

Referenced by dot_trace_traverse(), rz_core_agraph_print(), and rz_core_visual_graph().

◆ rz_core_agraph_print_json()

RZ_IPI void rz_core_agraph_print_json ( RzCore core)

Definition at line 164 of file cagraph.c.

164  {
165  PJ *pj = pj_new();
166  if (!pj) {
167  return;
168  }
169  pj_o(pj);
170  pj_k(pj, "nodes");
171  pj_a(pj);
172  rz_agraph_print_json(core->graph, pj);
173  pj_end(pj);
174  pj_end(pj);
176  pj_free(pj);
177 }
RZ_API void rz_agraph_print_json(RzAGraph *g, PJ *pj)
Definition: agraph.c:3694
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81

References rz_core_t::graph, pj_a(), pj_end(), pj_free(), pj_k(), pj_new(), pj_o(), pj_string(), rz_agraph_print_json(), and rz_cons_println().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_rizin()

RZ_IPI void rz_core_agraph_print_rizin ( RzCore core)

Definition at line 159 of file cagraph.c.

159  {
162 }
static void agraph_print_node(RzANode *n, void *user)
Definition: cagraph.c:133
static void agraph_print_edge(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:129

References agraph_print_edge(), agraph_print_node(), rz_core_t::graph, NULL, rz_agraph_foreach(), and rz_agraph_foreach_edge().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_sdb()

RZ_IPI void rz_core_agraph_print_sdb ( RzCore core)

Definition at line 81 of file cagraph.c.

81  {
82  Sdb *db = rz_agraph_get_sdb(core->graph);
83  char *o = sdb_querys(db, "null", 0, "*");
84  rz_cons_print(o);
85  free(o);
86 }
RZ_API Sdb * rz_agraph_get_sdb(RzAGraph *g)
Definition: agraph.c:3679
RZ_API char * sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd)
Definition: query.c:164
Definition: sdb.h:63

References free(), rz_core_t::graph, rz_agraph_get_sdb(), and sdb_querys().

Referenced by cmd_analysis_graph(), and rz_core_agraph_print().

◆ rz_core_agraph_print_tiny()

RZ_IPI void rz_core_agraph_print_tiny ( RzCore core)

Definition at line 72 of file cagraph.c.

72  {
73  core->graph->is_tiny = true;
74  int e = rz_config_get_i(core->config, "graph.edges");
75  rz_config_set_i(core->config, "graph.edges", 0);
76  rz_core_visual_graph(core, core->graph, NULL, false);
77  rz_config_set_i(core->config, "graph.edges", e);
78  core->graph->is_tiny = false;
79 }
#define e(frag)

References rz_core_t::config, e, rz_core_t::graph, rz_ascii_graph_t::is_tiny, NULL, rz_config_get_i(), rz_config_set_i(), and rz_core_visual_graph().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_write()

RZ_IPI void rz_core_agraph_print_write ( RzCore core,
const char *  filename 
)

Definition at line 2561 of file cmd_analysis.c.

2561  {
2562  convert_dotcmd_to_image(core, "aggd", filename);
2563 }
static bool convert_dotcmd_to_image(RzCore *core, char *rz_cmd, const char *save_path)
const char * filename
Definition: ioapi.h:137

References convert_dotcmd_to_image().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_reset()

RZ_IPI void rz_core_agraph_reset ( RzCore core)

Definition at line 8 of file cagraph.c.

8  {
9  rz_agraph_reset(core->graph);
10 }
RZ_API void rz_agraph_reset(RzAGraph *g)
Definition: agraph.c:3889

References rz_core_t::graph, and rz_agraph_reset().

Referenced by cmd_analysis_graph(), dot_trace_traverse(), and rz_core_visual_graph().

◆ rz_core_analysis_all_vars_display()

RZ_IPI char* rz_core_analysis_all_vars_display ( RzCore core,
RzAnalysisFunction fcn,
bool  add_name 
)

Definition at line 6206 of file canalysis.c.

6206  {
6207  RzListIter *iter;
6208  RzAnalysisVar *p;
6211  rz_list_foreach (list, iter, p) {
6212  char *r = rz_core_analysis_var_display(core, p, add_name);
6213  rz_strbuf_append(sb, r);
6214  free(r);
6215  }
6216  rz_list_free(list);
6217  return rz_strbuf_drain(sb);
6218 }
static SblHeader sb
Definition: bin_mbn.c:26
RZ_IPI char * rz_core_analysis_var_display(RzCore *core, RzAnalysisVar *var, bool add_name)
Definition: canalysis.c:6148
#define r
Definition: crypto_rc6.c:12
void * p
Definition: libc.cpp:67
static void list(RzEgg *egg)
Definition: rz-gg.c:52
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
RzAnalysis * analysis
Definition: rz_core.h:322
RZ_DEPRECATE RZ_API RzList * rz_analysis_var_all_list(RzAnalysis *analysis, RzAnalysisFunction *fcn)
Definition: var.c:1135

References rz_core_t::analysis, core_noretl::core, free(), list(), NULL, p, r, rz_analysis_var_all_list(), rz_core_analysis_var_display(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), and sb.

Referenced by backtrace_vars(), and rz_analysis_function_vars_display_handler().

◆ rz_core_analysis_bb_info_print()

RZ_IPI void rz_core_analysis_bb_info_print ( RzCore core,
RzAnalysisBlock bb,
ut64  addr,
RzCmdStateOutput state 
)

Definition at line 496 of file canalysis.c.

496  {
497  rz_return_if_fail(core && bb && state);
498  rz_cmd_state_output_set_columnsf(state, "xdxx", "addr", "size", "jump", "fail");
500  bb_info_print(core, fcn, bb, addr, state->mode, state->d.pj, state->d.t);
501 }
static void bb_info_print(RzCore *core, RzAnalysisFunction *fcn, RzAnalysisBlock *bb, ut64 addr, RzOutputMode mode, PJ *pj, RzTable *t)
Definition: canalysis.c:363
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References addr, bb_info_print(), rz_analysis_bb_t::fcns, rz_cmd_state_output_set_columnsf(), rz_list_first(), and rz_return_if_fail.

Referenced by rz_analysis_basic_block_info_handler(), and rz_analysis_function_blocks_info_handler().

◆ rz_core_analysis_bbs_asciiart()

RZ_IPI void rz_core_analysis_bbs_asciiart ( RzCore core,
RzAnalysisFunction fcn 
)

Definition at line 305 of file canalysis.c.

305  {
307  if (!flist) {
308  return;
309  }
310  RzListIter *iter;
312  ls_foreach (fcn->bbs, iter, b) {
313  RzInterval inter = (RzInterval){ b->addr, b->size };
314  RzListInfo *info = rz_listinfo_new(NULL, inter, inter, -1, NULL);
315  if (!info) {
316  break;
317  }
318  rz_list_append(flist, info);
319  }
320  RzTable *table = rz_core_table(core);
321  rz_table_visual_list(table, flist, core->offset, core->blocksize,
322  rz_cons_get_size(NULL), rz_config_get_i(core->config, "scr.color"));
323  rz_cons_printf("\n%s\n", rz_table_tostring(table));
324  rz_table_free(table);
325  rz_list_free(flist);
326 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API RzTable * rz_core_table(RzCore *core)
Definition: core.c:3449
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
#define ls_foreach(list, it, pos)
Definition: ls.h:31
struct rz_interval_t RzInterval
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API void rz_table_visual_list(RzTable *table, RzList *list, ut64 seek, ut64 len, int width, bool va)
Definition: table.c:1205
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510
ut32 blocksize
Definition: rz_core.h:303
RZ_API RzListInfo * rz_listinfo_new(const char *name, RzInterval pitv, RzInterval vitv, int perm, const char *extra)
Definition: visual.c:4020
RZ_API void rz_listinfo_free(RzListInfo *info)
Definition: visual.c:4032

References b, rz_analysis_function_t::bbs, rz_core_t::blocksize, rz_core_t::config, info(), ls_foreach, NULL, rz_core_t::offset, rz_config_get_i(), rz_cons_get_size(), rz_cons_printf(), rz_core_table(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_listinfo_free(), rz_listinfo_new(), rz_table_free(), rz_table_tostring(), and rz_table_visual_list().

Referenced by rz_analysis_function_blocks_asciiart_handler().

◆ rz_core_analysis_bbs_info_print()

RZ_IPI void rz_core_analysis_bbs_info_print ( RzCore core,
RzAnalysisFunction fcn,
RzCmdStateOutput state 
)

Definition at line 478 of file canalysis.c.

478  {
479  rz_return_if_fail(core && fcn && state);
480  RzListIter *iter;
481  RzAnalysisBlock *bb;
483  rz_cmd_state_output_set_columnsf(state, "xdxx", "addr", "size", "jump", "fail");
484  if (state->mode == RZ_OUTPUT_MODE_RIZIN) {
485  rz_cons_printf("fs blocks\n");
486  }
487 
488  rz_list_sort(fcn->bbs, bb_cmp);
489  rz_list_foreach (fcn->bbs, iter, bb) {
490  bb_info_print(core, fcn, bb, bb->addr, state->mode, state->d.pj, state->d.t);
491  }
492 
494 }
static int bb_cmp(const void *a, const void *b)
Definition: canalysis.c:472
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
Definition: list.c:743
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41

References rz_analysis_bb_t::addr, bb_cmp(), bb_info_print(), rz_analysis_function_t::bbs, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cmd_state_output_set_columnsf(), rz_cons_printf(), rz_list_sort(), RZ_OUTPUT_MODE_RIZIN, and rz_return_if_fail.

Referenced by rz_analysis_function_blocks_list_handler().

◆ rz_core_analysis_cc_print()

RZ_IPI void rz_core_analysis_cc_print ( RzCore core,
RZ_NONNULL const char *  cc,
RZ_NULLABLE PJ pj 
)

Print Calling Convention info.

Parameters
coreThe RzCore instance
ccCalling Convention name
pjOptional PJ instance for JSON mode

Definition at line 6686 of file canalysis.c.

6686  {
6687  rz_return_if_fail(core && cc);
6688  if (pj) {
6689  pj_o(pj);
6690  }
6691  if (pj) {
6692  pj_ks(pj, "name", cc);
6693  } else {
6694  rz_cons_printf("name: %s\n", cc);
6695  }
6696  const char *regname = rz_analysis_cc_ret(core->analysis, cc);
6697  if (regname) {
6698  if (pj) {
6699  pj_ks(pj, "ret", regname);
6700  } else {
6701  rz_cons_printf("ret: %s\n", regname);
6702  }
6703  }
6704  if (pj) {
6705  pj_ka(pj, "args");
6706  }
6707  int maxargs = rz_analysis_cc_max_arg(core->analysis, cc);
6708  for (int i = 0; i < maxargs; i++) {
6709  regname = rz_analysis_cc_arg(core->analysis, cc, i);
6710  if (pj) {
6711  pj_s(pj, regname);
6712  } else {
6713  rz_cons_printf("arg%d: %s\n", i, regname);
6714  }
6715  }
6716  if (pj) {
6717  pj_end(pj);
6718  }
6719  regname = rz_analysis_cc_self(core->analysis, cc);
6720  if (regname) {
6721  if (pj) {
6722  pj_ks(pj, "self", regname);
6723  } else {
6724  rz_cons_printf("self: %s\n", regname);
6725  }
6726  }
6727  regname = rz_analysis_cc_error(core->analysis, cc);
6728  if (regname) {
6729  if (pj) {
6730  pj_ks(pj, "error", regname);
6731  } else {
6732  rz_cons_printf("error: %s\n", regname);
6733  }
6734  }
6735  if (pj) {
6736  pj_end(pj);
6737  }
6738 }
lzma_index ** i
Definition: index.h:629
RZ_API const char * rz_analysis_cc_arg(RzAnalysis *analysis, const char *convention, int n)
Definition: cc.c:122
RZ_API const char * rz_analysis_cc_self(RzAnalysis *analysis, const char *convention)
Definition: cc.c:138
RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc)
Definition: cc.c:171
RZ_API const char * rz_analysis_cc_error(RzAnalysis *analysis, const char *convention)
Definition: cc.c:155
RZ_API const char * rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention)
Definition: cc.c:194
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
static char * regname(int reg)
Definition: dis.c:71

References rz_core_t::analysis, core_noretl::core, i, pj_end(), pj_ka(), pj_ks(), pj_o(), pj_s(), regname(), rz_analysis_cc_arg(), rz_analysis_cc_error(), rz_analysis_cc_max_arg(), rz_analysis_cc_ret(), rz_analysis_cc_self(), rz_cons_printf(), and rz_return_if_fail.

Referenced by rz_analysis_function_cc_reg_usage_handler(), and rz_core_types_calling_conventions_print().

◆ rz_core_analysis_esil_default()

RZ_IPI void rz_core_analysis_esil_default ( RzCore core)

Definition at line 409 of file cil.c.

409  {
410  RzIOMap *map;
411  RzListIter *iter;
412  RzList *list = rz_core_get_boundaries_prot(core, -1, NULL, "analysis");
413  if (!list) {
414  return;
415  }
416  if (!strcmp("range", rz_config_get(core->config, "analysis.in"))) {
417  ut64 from = rz_config_get_i(core->config, "analysis.from");
418  ut64 to = rz_config_get_i(core->config, "analysis.to");
419  if (to > from) {
421  } else {
422  eprintf("Assert: analysis.from > analysis.to\n");
423  }
424  } else {
425  rz_list_foreach (list, iter, map) {
426  if (map->perm & RZ_PERM_X) {
427  rz_core_analysis_esil(core, map->itv.addr, map->itv.size, NULL);
428  }
429  }
430  }
432 }
RZ_API void rz_core_analysis_esil(RzCore *core, ut64 addr, ut64 size, RZ_NULLABLE RzAnalysisFunction *fcn)
Definition: canalysis.c:4499
RZ_API RZ_OWN RzList * rz_core_get_boundaries_prot(RzCore *core, int perm, const char *mode, const char *prefix)
Definition: cmd_search.c:577
size_t map(int syms, int left, int len)
Definition: enough.c:237
#define RZ_PERM_X
Definition: rz_types.h:95
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125

References rz_core_t::config, eprintf, from, list(), map(), NULL, rz_config_get(), rz_config_get_i(), rz_core_analysis_esil(), rz_core_get_boundaries_prot(), rz_list_free(), RZ_PERM_X, to, and ut64().

Referenced by objc_analyze(), and rz_analysis_all_esil_handler().

◆ rz_core_analysis_esil_emulate()

RZ_IPI void rz_core_analysis_esil_emulate ( RzCore core,
ut64  addr,
ut64  until_addr,
int  off 
)

Emulate n_instr instructions from addr. If until_addr is specified and that address is met before all the instructions are emulated, stop there.

Definition at line 305 of file cil.c.

305  {
306  RzAnalysisEsil *esil = core->analysis->esil;
307  int i = 0, j = 0;
308  ut8 *buf = NULL;
309  RzAnalysisOp aop = { 0 };
310  int ret, bsize = RZ_MAX(4096, core->blocksize);
311  const int mininstrsz = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE);
312  const int minopcode = RZ_MAX(1, mininstrsz);
313  const char *pc = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_PC);
314  int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
315  int iotrap = rz_config_get_i(core->config, "esil.iotrap");
316  ut64 addrsize = rz_config_get_i(core->config, "esil.addr.size");
317 
318  if (!esil) {
319  eprintf("Warning: cmd_espc: creating new esil instance\n");
320  if (!(esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
321  return;
322  }
323  core->analysis->esil = esil;
324  }
325  buf = malloc(bsize);
326  if (!buf) {
327  eprintf("Cannot allocate %d byte(s)\n", bsize);
328  return;
329  }
330  if (addr == -1) {
331  addr = rz_reg_getv(core->analysis->reg, pc);
332  }
333  (void)rz_analysis_esil_setup(core->analysis->esil, core->analysis, 0, 0, 0); // int romem, int stats, int nonull) {
334  ut64 cursp = rz_reg_getv(core->analysis->reg, "SP");
335  ut64 oldoff = core->offset;
337  for (i = 0, j = 0; j < off; i++, j++) {
338  if (rz_cons_is_breaked()) {
339  break;
340  }
341  if (i >= (bsize - 32)) {
342  i = 0;
343  eprintf("Warning: Chomp\n");
344  }
345  if (!i) {
346  rz_io_read_at(core->io, addr, buf, bsize);
347  }
348  if (addr == until_addr) {
349  break;
350  }
351  ret = rz_analysis_op(core->analysis, &aop, addr, buf + i, bsize - i, flags);
352  if (ret < 1) {
353  eprintf("Failed analysis at 0x%08" PFMT64x "\n", addr);
354  break;
355  }
356  // skip calls and such
357  if (aop.type == RZ_ANALYSIS_OP_TYPE_CALL) {
358  // nothing
359  } else {
360  rz_reg_setv(core->analysis->reg, "PC", aop.addr + aop.size);
361  const char *e = RZ_STRBUF_SAFEGET(&aop.esil);
362  if (e && *e) {
363  // eprintf (" 0x%08llx %d %s\n", aop.addr, ret, aop.mnemonic);
364  (void)rz_analysis_esil_parse(esil, e);
365  }
366  }
367  int inc = (core->search->align > 0) ? core->search->align - 1 : ret - 1;
368  if (inc < 0) {
369  inc = minopcode;
370  }
371  i += inc;
372  addr += ret; // aop.size;
373  rz_analysis_op_fini(&aop);
374  }
375  rz_core_seek(core, oldoff, true);
376  rz_reg_setv(core->analysis->reg, "SP", cursp);
377  free(buf);
378 }
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API RzAnalysisEsil * rz_analysis_esil_new(int stacksize, int iotrap, unsigned int addrsize)
Definition: esil.c:85
RZ_API bool rz_analysis_esil_setup(RzAnalysisEsil *esil, RzAnalysis *analysis, int romem, int stats, int nonull)
Definition: esil.c:3298
RZ_API bool rz_analysis_esil_parse(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:2998
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
int off
Definition: pal.c:13
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
@ RZ_ANALYSIS_OP_MASK_DISASM
Definition: rz_analysis.h:445
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
@ RZ_ANALYSIS_OP_MASK_HINT
Definition: rz_analysis.h:443
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
#define RZ_MAX(x, y)
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584
RzSearch * search
Definition: rz_core.h:331
RzIO * io
Definition: rz_core.h:313
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References addr, rz_analysis_op_t::addr, rz_search_t::align, rz_core_t::analysis, rz_core_t::blocksize, rz_core_t::config, e, eprintf, rz_analysis_t::esil, rz_analysis_op_t::esil, flags, free(), i, if(), rz_core_t::io, malloc(), NULL, off, rz_core_t::offset, pc, PFMT64x, rz_analysis_t::reg, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE, rz_analysis_esil_new(), rz_analysis_esil_parse(), rz_analysis_esil_setup(), rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_MASK_ESIL, RZ_ANALYSIS_OP_MASK_HINT, RZ_ANALYSIS_OP_TYPE_CALL, rz_config_get_i(), rz_cons_is_breaked(), rz_core_seek(), rz_io_read_at(), RZ_MAX, rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_PC, rz_reg_setv(), RZ_STRBUF_SAFEGET, rz_core_t::search, rz_analysis_op_t::size, rz_analysis_op_t::type, and ut64().

Referenced by rz_core_analysis_esil_emulate_bb(), rz_il_step_evaluate_handler(), and rz_il_step_handler().

◆ rz_core_analysis_esil_emulate_bb()

RZ_IPI void rz_core_analysis_esil_emulate_bb ( RzCore core)

Definition at line 380 of file cil.c.

380  {
382  if (!bb) {
383  RZ_LOG_ERROR("Cannot find basic block for 0x%08" PFMT64x "\n", core->offset);
384  return;
385  }
387 }
RZ_API RzAnalysisBlock * rz_analysis_find_most_relevant_block_in(RzAnalysis *analysis, ut64 off)
Definition: block.c:997
RZ_IPI void rz_core_analysis_esil_emulate(RzCore *core, ut64 addr, ut64 until_addr, int off)
Definition: cil.c:305
#define UT64_MAX
Definition: rz_types_base.h:86

References rz_analysis_bb_t::addr, rz_core_t::analysis, rz_analysis_bb_t::ninstr, rz_core_t::offset, PFMT64x, rz_analysis_find_most_relevant_block_in(), rz_core_analysis_esil_emulate(), RZ_LOG_ERROR, and UT64_MAX.

Referenced by cmd_analysis_esil().

◆ rz_core_analysis_esil_init()

◆ rz_core_analysis_esil_init_mem_p()

RZ_IPI void rz_core_analysis_esil_init_mem_p ( RzCore core)

Definition at line 213 of file cil.c.

213  {
215  RzAnalysisEsil *esil = core->analysis->esil;
216  ut64 addr = 0x100000;
217  ut32 size = 0xf0000;
218  RzFlagItem *fi = rz_flag_get(core->flags, "aeim.stack");
219  if (fi) {
220  addr = fi->offset;
221  size = fi->size;
222  } else {
224  }
225  if (esil) {
226  esil->stack_addr = addr;
227  esil->stack_size = size;
228  }
229  initialize_stack(core, addr, size);
230  return;
231 }
RZ_API void rz_core_analysis_esil_init_mem(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Definition: cil.c:149
static void initialize_stack(RzCore *core, ut64 addr, ut64 size)
Definition: cil.c:76
RZ_IPI void rz_core_analysis_esil_init(RzCore *core)
Definition: cil.c:43
uint32_t ut32
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
voidpf void uLong size
Definition: ioapi.h:138
#define UT32_MAX
Definition: rz_types_base.h:99
RzFlag * flags
Definition: rz_core.h:330
ut64 offset
Definition: rz_flag.h:38

References addr, rz_core_t::analysis, rz_analysis_t::esil, rz_core_t::flags, initialize_stack(), NULL, rz_flag_item_t::offset, rz_core_analysis_esil_init(), rz_core_analysis_esil_init_mem(), rz_flag_get(), rz_flag_item_t::size, rz_analysis_esil_t::stack_addr, rz_analysis_esil_t::stack_size, UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_analysis_esil_init_mem_p_handler().

◆ rz_core_analysis_esil_references_all_functions()

RZ_IPI void rz_core_analysis_esil_references_all_functions ( RzCore core)

Definition at line 290 of file cil.c.

290  {
291  RzListIter *it;
292  RzAnalysisFunction *fcn;
293  rz_list_foreach (core->analysis->fcns, it, fcn) {
296  rz_core_analysis_esil(core, from, to - from, fcn);
297  }
298 }
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API ut64 rz_analysis_function_min_addr(RzAnalysisFunction *fcn)
Definition: function.c:323
RzList * fcns
Definition: rz_analysis.h:565

References rz_core_t::analysis, rz_analysis_t::fcns, from, rz_analysis_function_max_addr(), rz_analysis_function_min_addr(), rz_core_analysis_esil(), to, and ut64().

Referenced by rz_analysis_all_esil_functions_handler(), and rz_core_analysis_everything().

◆ rz_core_analysis_esil_step_over_until()

RZ_IPI void rz_core_analysis_esil_step_over_until ( RzCore core,
ut64  addr 
)

Definition at line 280 of file cil.c.

280  {
281  rz_core_esil_step(core, addr, NULL, NULL, true);
283 }
RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver)
Definition: cmd_analysis.c:860
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106

References addr, NULL, rz_core_esil_step(), and rz_core_reg_update_flags().

Referenced by rz_il_step_over_until_addr_handler(), rz_il_step_skip_handler(), and rz_il_step_skip_until_addr_handler().

◆ rz_core_analysis_esil_step_over_untilexpr()

RZ_IPI void rz_core_analysis_esil_step_over_untilexpr ( RzCore core,
const char *  expr 
)

Definition at line 285 of file cil.c.

285  {
286  rz_core_esil_step(core, UT64_MAX, expr, NULL, true);
288 }
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167

References expr(), NULL, rz_core_esil_step(), rz_core_reg_update_flags(), and UT64_MAX.

Referenced by rz_il_step_skip_until_expr_handler(), and rz_il_step_until_expr_handler().

◆ rz_core_analysis_fcn_returns()

RZ_IPI void rz_core_analysis_fcn_returns ( RzCore core,
RzAnalysisFunction fcn 
)

Definition at line 328 of file canalysis.c.

328  {
329  RzListIter *iter;
331  ls_foreach (fcn->bbs, iter, b) {
332  if (b->jump == UT64_MAX) {
333  ut64 retaddr = rz_analysis_block_get_op_addr(b, b->ninstr - 1);
334  if (retaddr == UT64_MAX) {
335  break;
336  }
337 
338  rz_cons_printf("0x%08" PFMT64x "\n", retaddr);
339  }
340  }
341 }
RZ_API ut64 rz_analysis_block_get_op_addr(RzAnalysisBlock *block, size_t i)
Definition: block.c:1016

References b, rz_analysis_function_t::bbs, ls_foreach, PFMT64x, rz_analysis_block_get_op_addr(), rz_cons_printf(), ut64(), and UT64_MAX.

Referenced by rz_analysis_function_returns_handler().

◆ rz_core_analysis_function_delete_var()

RZ_IPI bool rz_core_analysis_function_delete_var ( RzCore core,
RzAnalysisFunction fcn,
RzAnalysisVarKind  kind,
const char *  id 
)

Definition at line 6133 of file canalysis.c.

6133  {
6134  RzAnalysisVar *var = NULL;
6135  if (IS_DIGIT(*id)) {
6136  int delta = rz_num_math(core->num, id);
6137  var = rz_analysis_function_get_var(fcn, kind, delta);
6138  } else {
6139  var = rz_analysis_function_get_var_byname(fcn, id);
6140  }
6141  if (!var || var->kind != kind) {
6142  return false;
6143  }
6145  return true;
6146 }
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
RzAnalysisVarKind kind
Definition: rz_analysis.h:728
RzNum * num
Definition: rz_core.h:316
RZ_API RZ_BORROW RzAnalysisVar * rz_analysis_function_get_var(RzAnalysisFunction *fcn, char kind, int delta)
Definition: var.c:259
RZ_API RZ_BORROW RzAnalysisVar * rz_analysis_function_get_var_byname(RzAnalysisFunction *fcn, const char *name)
Definition: var.c:247
RZ_API void rz_analysis_var_delete(RzAnalysisVar *var)
Definition: var.c:192
static st64 delta
Definition: vmenus.c:2425

References core_noretl::core, delta, IS_DIGIT, rz_analysis_var_t::kind, NULL, rz_core_t::num, rz_analysis_function_get_var(), rz_analysis_function_get_var_byname(), rz_analysis_var_delete(), and rz_num_math().

Referenced by analysis_function_vars_del(), and rz_analysis_function_vars_del_handler().

◆ rz_core_analysis_function_set_signature()

RZ_IPI bool rz_core_analysis_function_set_signature ( RzCore core,
RzAnalysisFunction fcn,
const char *  newsig 
)

Definition at line 6380 of file canalysis.c.

6380  {
6381  bool res = false;
6382  char *fcnname = NULL;
6383  char *fcnstr = rz_str_newf("%s;", newsig);
6384  char *fcnstr_copy = strdup(fcnstr);
6385  char *fcnname_aux = strtok(fcnstr_copy, "(");
6386  if (!fcnname_aux) {
6387  goto err;
6388  }
6389  rz_str_trim_tail(fcnname_aux);
6390  const char *ls = rz_str_lchr(fcnname_aux, ' ');
6391  fcnname = strdup(ls ? ls : fcnname_aux);
6392  if (!fcnname) {
6393  goto err;
6394  }
6395  // TODO: move this into rz_analysis_function_set_type_str()
6396  if (strcmp(fcn->name, fcnname)) {
6397  (void)rz_core_analysis_function_rename(core, fcn->addr, fcnname);
6398  fcn = rz_analysis_get_fcn_in(core->analysis, fcn->addr, -1);
6399  }
6400  rz_analysis_function_set_type_str(core->analysis, fcn, fcnstr);
6401  res = true;
6402 err:
6403  free(fcnname);
6404  free(fcnstr_copy);
6405  free(fcnstr);
6406  return res;
6407 }
static bool err
Definition: armass.c:435
RZ_API bool rz_core_analysis_function_rename(RzCore *core, ut64 addr, const char *_name)
Definition: canalysis.c:5270
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API bool rz_analysis_function_set_type_str(RzAnalysis *a, RZ_NONNULL RzAnalysisFunction *f, RZ_NONNULL const char *sig)
Parses the function type and sets it for the given function.
Definition: fcn.c:1985
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API RZ_BORROW char * rz_str_trim_tail(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string and replaces them w...
Definition: str_trim.c:125

References rz_analysis_function_t::addr, rz_core_t::analysis, core_noretl::core, err, free(), rz_analysis_function_t::name, NULL, rz_analysis_function_set_type_str(), rz_analysis_get_fcn_in(), rz_core_analysis_function_rename(), rz_str_lchr(), rz_str_newf(), rz_str_trim_tail(), and strdup().

Referenced by rz_analysis_function_signature_handler(), and rz_core_analysis_function_signature_editor().

◆ rz_core_analysis_function_signature()

RZ_IPI char* rz_core_analysis_function_signature ( RzCore core,
RzOutputMode  mode,
char *  fcn_name 
)

Definition at line 5382 of file canalysis.c.

5382  {
5383  RzListIter *iter;
5385  RzAnalysisFunction *fcn;
5386  if (fcn_name) {
5387  fcn = rz_analysis_get_function_byname(core->analysis, fcn_name);
5388  } else {
5389  fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
5390  if (fcn) {
5391  fcn_name = fcn->name;
5392  }
5393  }
5394  if (!fcn) {
5395  return NULL;
5396  }
5397  char *signature = NULL;
5398 
5399  if (mode == RZ_OUTPUT_MODE_JSON) {
5400  PJ *j = pj_new();
5401  if (!j) {
5402  return NULL;
5403  }
5404  pj_a(j);
5405 
5406  char *key = NULL;
5407  if (fcn_name) {
5408  key = resolve_fcn_name(core->analysis, fcn_name);
5409  }
5410 
5411  if (key) {
5412  RzType *ret_type = rz_type_func_ret(core->analysis->typedb, key);
5413  char *ret_type_str = NULL;
5414  if (ret_type) {
5415  ret_type_str = rz_type_as_string(core->analysis->typedb, ret_type);
5416  }
5418  pj_o(j);
5419  pj_ks(j, "name", rz_str_get_null(key));
5420  if (ret_type_str) {
5421  pj_ks(j, "return", ret_type_str);
5422  }
5423  pj_k(j, "args");
5424  pj_a(j);
5425  if (nargs) {
5426  RzList *list = rz_core_get_func_args(core, fcn_name);
5427  rz_list_foreach (list, iter, arg) {
5428  char *type = rz_type_as_string(core->analysis->typedb, arg->orig_c_type);
5429  pj_o(j);
5430  pj_ks(j, "name", arg->name);
5431  pj_ks(j, "type", type);
5432  pj_end(j);
5433  free(type);
5434  }
5435  rz_list_free(list);
5436  }
5437  pj_end(j);
5438  pj_ki(j, "count", nargs);
5439  pj_end(j);
5440  free(ret_type_str);
5441  free(key);
5442  } else {
5443  pj_o(j);
5444  pj_ks(j, "name", rz_str_get_null(fcn_name));
5445  pj_k(j, "args");
5446  pj_a(j);
5447 
5448  RzAnalysisFcnVarsCache cache;
5449  rz_analysis_fcn_vars_cache_init(core->analysis, &cache, fcn);
5450  int nargs = 0;
5451  RzAnalysisVar *var;
5452  rz_list_foreach (cache.rvars, iter, var) {
5453  nargs++;
5454  pj_o(j);
5455  pj_ks(j, "name", var->name);
5456  char *vartype = rz_type_as_string(core->analysis->typedb, var->type);
5457  pj_ks(j, "type", vartype);
5458  pj_end(j);
5459  free(vartype);
5460  }
5461  rz_list_foreach (cache.bvars, iter, var) {
5462  if (var->delta <= 0) {
5463  continue;
5464  }
5465  nargs++;
5466  pj_o(j);
5467  pj_ks(j, "name", var->name);
5468  char *vartype = rz_type_as_string(core->analysis->typedb, var->type);
5469  pj_ks(j, "type", vartype);
5470  pj_end(j);
5471  free(vartype);
5472  }
5473  rz_list_foreach (cache.svars, iter, var) {
5474  if (!var->isarg) {
5475  continue;
5476  }
5477  nargs++;
5478  pj_o(j);
5479  pj_ks(j, "name", var->name);
5480  char *vartype = rz_type_as_string(core->analysis->typedb, var->type);
5481  pj_ks(j, "type", vartype);
5482  pj_end(j);
5483  free(vartype);
5484  }
5486 
5487  pj_end(j);
5488  pj_ki(j, "count", nargs);
5489  pj_end(j);
5490  }
5491  pj_end(j);
5492  signature = strdup(pj_string(j));
5493  pj_free(j);
5494  } else {
5495  signature = rz_analysis_fcn_format_sig(core->analysis, fcn, fcn_name, NULL, NULL, NULL);
5496  }
5497  return signature;
5498 }
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
static char * signature(RzBinFile *bf, bool json)
Definition: bin_pe.c:117
RZ_API RZ_OWN RzList * rz_core_get_func_args(RzCore *core, const char *fcn_name)
Definition: carg.c:276
RZ_API char * resolve_fcn_name(RzAnalysis *analysis, const char *func_name)
Definition: carg.c:86
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
RZ_API RzAnalysisFunction * rz_analysis_get_function_byname(RzAnalysis *a, const char *name)
Definition: fcn.c:1729
const char int mode
Definition: ioapi.h:137
int type
Definition: mipsasm.c:17
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
static const char * rz_str_get_null(const char *str)
Definition: rz_str.h:190
const char * name
Definition: sparc-opc.c:1838
RZ_API int rz_type_func_args_count(RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the RzCallable type in types database and returns arguments' count.
Definition: function.c:262
RZ_API RZ_BORROW RzType * rz_type_func_ret(RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the RzCallable type in types database and returns return type.
Definition: function.c:215
RZ_API void rz_analysis_fcn_vars_cache_fini(RzAnalysisFcnVarsCache *cache)
Definition: var.c:1223
RZ_API char * rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, RZ_NULLABLE char *fcn_name, RZ_NULLABLE RzAnalysisFcnVarsCache *reuse_cache, RZ_NULLABLE const char *fcn_name_pre, RZ_NULLABLE const char *fcn_name_post)
Definition: var.c:1232
RZ_API void rz_analysis_fcn_vars_cache_init(RzAnalysis *analysis, RzAnalysisFcnVarsCache *cache, RzAnalysisFunction *fcn)
Definition: var.c:1209

References rz_core_t::analysis, arg(), rz_analysis_var_t::delta, free(), rz_analysis_var_t::isarg, key, list(), arg::name, rz_analysis_function_t::name, rz_analysis_var_t::name, cmd_descs_generate::nargs, NULL, rz_core_t::offset, pj_a(), pj_end(), pj_free(), pj_k(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), resolve_fcn_name(), rz_analysis_fcn_format_sig(), rz_analysis_fcn_vars_cache_fini(), rz_analysis_fcn_vars_cache_init(), rz_analysis_get_fcn_in(), rz_analysis_get_function_byname(), rz_core_get_func_args(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_str_get_null(), rz_type_as_string(), rz_type_func_args_count(), rz_type_func_ret(), signature(), strdup(), type, rz_analysis_var_t::type, and rz_analysis_t::typedb.

Referenced by agraph_update_title(), and function_print_to_json().

◆ rz_core_analysis_function_signature_editor()

RZ_IPI void rz_core_analysis_function_signature_editor ( RzCore core,
ut64  addr 
)

Definition at line 6409 of file canalysis.c.

6409  {
6411  if (!f) {
6412  eprintf("Cannot find function in 0x%08" PFMT64x "\n", core->offset);
6413  return;
6414  }
6415 
6417  char *data = rz_core_editor(core, NULL, sig);
6418  if (sig && data) {
6420  }
6421  free(sig);
6422  free(data);
6423 }
RZ_IPI bool rz_core_analysis_function_set_signature(RzCore *core, RzAnalysisFunction *fcn, const char *newsig)
Definition: canalysis.c:6380
RZ_API RZ_OWN char * rz_analysis_function_get_signature(RZ_NONNULL RzAnalysisFunction *function)
Definition: fcn.c:1895
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
#define f(i)
Definition: sha256.c:46

References rz_core_t::analysis, core_noretl::core, eprintf, f, free(), NULL, rz_core_t::offset, PFMT64x, rz_analysis_function_get_signature(), rz_analysis_get_fcn_in(), rz_core_analysis_function_set_signature(), and rz_core_editor().

Referenced by rz_analysis_function_signature_editor_handler(), rz_core_visual_analysis(), and rz_core_visual_define().

◆ rz_core_analysis_function_until()

RZ_IPI void rz_core_analysis_function_until ( RzCore core,
ut64  addr_end 
)

Definition at line 6425 of file canalysis.c.

6425  {
6426  rz_return_if_fail(core->offset <= addr_end);
6427  ut64 addr = core->offset;
6428  int depth = 1;
6429  ut64 a, b;
6430  const char *c;
6431  a = rz_config_get_i(core->config, "analysis.from");
6432  b = rz_config_get_i(core->config, "analysis.to");
6433  c = rz_config_get(core->config, "analysis.limits");
6434  rz_config_set_i(core->config, "analysis.from", addr);
6435  rz_config_set_i(core->config, "analysis.to", addr_end);
6436  rz_config_set(core->config, "analysis.limits", "true");
6437 
6439  if (fcn) {
6440  rz_analysis_function_resize(fcn, addr_end - addr);
6441  }
6444  fcn = rz_analysis_get_fcn_in(core->analysis, addr, 0);
6445  if (fcn) {
6446  rz_analysis_function_resize(fcn, addr_end - addr);
6447  }
6448  rz_config_set_i(core->config, "analysis.from", a);
6449  rz_config_set_i(core->config, "analysis.to", b);
6450  rz_config_set(core->config, "analysis.limits", c ? c : "");
6451 }
RZ_API int rz_core_analysis_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth)
Definition: canalysis.c:2026
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API int rz_analysis_function_resize(RzAnalysisFunction *fcn, int newsize)
Definition: fcn.c:90
@ RZ_ANALYSIS_XREF_TYPE_NULL
Definition: rz_analysis.h:899
#define c(i)
Definition: sha256.c:43

References a, addr, rz_core_t::analysis, b, c, rz_core_t::config, core_noretl::core, rz_core_t::offset, rz_analysis_function_resize(), rz_analysis_get_fcn_in(), RZ_ANALYSIS_XREF_TYPE_NULL, rz_config_get(), rz_config_get_i(), rz_config_set(), rz_config_set_i(), rz_core_analysis_fcn(), rz_return_if_fail, ut64(), and UT64_MAX.

Referenced by rz_analysis_function_until_handler().

◆ rz_core_analysis_il_reinit()

RZ_IPI void rz_core_analysis_il_reinit ( RzCore core)

Definition at line 434 of file cil.c.

434  {
436  if (core->analysis->il_vm) {
437  // initialize the program counter with the current offset
440  }
441 }
RZ_API bool rz_analysis_il_vm_setup(RzAnalysis *analysis)
Definition: analysis_il.c:285
RZ_API bool rz_reg_set_value_by_role(RzReg *reg, RzRegisterId role, ut64 val)
Definition: rvalue.c:269
RzAnalysisILVM * il_vm
user-faced VM, NEVER use this for any analysis passes!
Definition: rz_analysis.h:585

References rz_core_t::analysis, rz_analysis_t::il_vm, rz_core_t::offset, rz_analysis_t::reg, rz_analysis_il_vm_setup(), rz_core_reg_update_flags(), RZ_REG_NAME_PC, and rz_reg_set_value_by_role().

Referenced by rz_il_vm_initialize_handler().

◆ rz_core_analysis_il_step_with_events()

RZ_IPI bool rz_core_analysis_il_step_with_events ( RzCore core,
PJ pj 
)

Perform a single step at the PC given by analysis->reg in RzIL and print any events that happened

Returns
false if an error occured (e.g. invalid op)

Definition at line 655 of file cil.c.

655  {
656  if (!rz_core_il_step(core)) {
657  return false;
658  }
659 
660  if (!core->analysis || !core->analysis->il_vm) {
661  return false;
662  }
663 
664  RzILVM *vm = core->analysis->il_vm->vm;
665 
666  RzStrBuf *sb = NULL;
667  RzListIter *it;
668  RzILEvent *evt;
669 
670  bool evt_read = rz_config_get_b(core->config, "rzil.step.events.read");
671  bool evt_write = rz_config_get_b(core->config, "rzil.step.events.write");
672 
673  if (!evt_read && !evt_write) {
674  RZ_LOG_ERROR("RzIL: cannot print events when all the events are disabled.");
675  RZ_LOG_ERROR("RzIL: please set 'rzil.step.events.read' or/and 'rzil.step.events.write' to true and try again.");
676  return false;
677  }
678 
679  if (!pj) {
680  sb = rz_strbuf_new("");
681  }
682  rz_list_foreach (vm->events, it, evt) {
683  if (!evt_read && (evt->type == RZ_IL_EVENT_MEM_READ || evt->type == RZ_IL_EVENT_VAR_READ)) {
684  continue;
685  } else if (!evt_write && (evt->type != RZ_IL_EVENT_MEM_READ && evt->type != RZ_IL_EVENT_VAR_READ)) {
686  continue;
687  }
688  if (!pj) {
690  rz_strbuf_append(sb, "\n");
691  } else {
692  rz_il_event_json(evt, pj);
693  }
694  }
695  if (!pj) {
696  rz_cons_print(rz_strbuf_get(sb));
698  }
699  return true;
700 }
RZ_IPI bool rz_core_il_step(RzCore *core)
Definition: cil.c:630
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API void rz_il_event_json(RZ_NONNULL RzILEvent *evt, RZ_NONNULL PJ *pj)
Definition: il_export.c:797
RZ_API void rz_il_event_stringify(RZ_NONNULL const RzILEvent *evt, RZ_NONNULL RzStrBuf *sb)
Definition: il_export.c:753
@ RZ_IL_EVENT_VAR_READ
Definition: rz_il_events.h:23
@ RZ_IL_EVENT_MEM_READ
Definition: rz_il_events.h:22
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_NONNULL RzILVM * vm
low-level vm to execute IL code
Definition: rz_analysis.h:1156
RzILEventId type
Definition: rz_il_events.h:56
Low-level VM to execute raw IL code.
Definition: rz_il_vm.h:37
RzList * events
List of events that has happened in the last step.
Definition: rz_il_vm.h:49

References rz_core_t::analysis, rz_core_t::config, rz_il_vm_t::events, rz_analysis_t::il_vm, NULL, rz_config_get_b(), rz_core_il_step(), rz_il_event_json(), RZ_IL_EVENT_MEM_READ, rz_il_event_stringify(), RZ_IL_EVENT_VAR_READ, RZ_LOG_ERROR, rz_strbuf_append(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_new(), sb, rz_il_vm_event_t::type, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_step_with_events_handler().

◆ rz_core_analysis_il_vm_set()

RZ_IPI bool rz_core_analysis_il_vm_set ( RzCore core,
const char *  var_name,
ut64  value 
)

Set a vm variable from user input.

Returns
whether the set succeeded

Sets the given var, or "PC" to the given value. The type of the variable is handled dynamically. This is intended for setting from user input only.

Definition at line 451 of file cil.c.

451  {
452  rz_return_val_if_fail(core && core->analysis && var_name, false);
453 
454  RzAnalysisILVM *vm = core->analysis->il_vm;
455  if (!vm) {
456  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
457  return false;
458  }
459 
460  if (!strcmp(var_name, "PC")) {
462  rz_bv_free(vm->vm->pc);
463  vm->vm->pc = bv;
464  return true;
465  }
466 
467  RzILVar *var = rz_il_vm_get_var(vm->vm, RZ_IL_VAR_KIND_GLOBAL, var_name);
468  if (!var) {
469  return false;
470  }
471  RzILVal *val = NULL;
472  switch (var->sort.type) {
475  break;
478  break;
479  }
480  if (val) {
481  rz_il_vm_set_global_var(vm->vm, var_name, val);
482  }
483  return true;
484 }
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
static int value
Definition: cmd_api.c:93
RZ_API RZ_OWN RzILVal * rz_il_value_new_bitv(RZ_NONNULL RzBitVector *bv)
Definition: value.c:28
RZ_API RZ_OWN RzILVal * rz_il_value_new_bool(RZ_NONNULL RzILBool *b)
Definition: value.c:43
RZ_API void rz_il_vm_set_global_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
Definition: il_vm.c:193
RZ_API RZ_BORROW RzILVar * rz_il_vm_get_var(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:251
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
structure for bitvector
Definition: rz_bitvector.h:19
ut32 len
number of bits – virtual / logical
Definition: rz_bitvector.h:25
High-level RzIL vm to emulate disassembled code.
Definition: rz_analysis.h:1155
struct rz_il_sort_pure_t::@283::@284 bv
union rz_il_sort_pure_t::@283 props
RzILTypePure type
Definition: sort.h:29
Definition of a variable inside the vm.
Definition: variable.h:19
RzILSortPure sort
"type" of the variable
Definition: variable.h:21
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
@ RZ_IL_VAR_KIND_GLOBAL
global var, usually bound to a physical representation like a register.
Definition: variable.h:47

References rz_core_t::analysis, rz_il_sort_pure_t::bv, rz_analysis_t::il_vm, bitvector_t::len, NULL, rz_il_vm_t::pc, rz_il_sort_pure_t::props, rz_bv_free(), rz_bv_new_from_ut64(), rz_il_bool_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_value_new_bitv(), rz_il_value_new_bool(), RZ_IL_VAR_KIND_GLOBAL, rz_il_vm_get_var(), rz_il_vm_set_global_var(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_il_var_t::sort, rz_il_sort_pure_t::type, val, value, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_status_handler().

◆ rz_core_analysis_il_vm_status()

RZ_IPI void rz_core_analysis_il_vm_status ( RzCore core,
const char *  varname,
RzOutputMode  mode 
)

Definition at line 531 of file cil.c.

531  {
532  RzAnalysisILVM *vm = core->analysis->il_vm;
533  if (!vm) {
534  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
535  return;
536  }
537 
538  ILPrint p = { 0 };
539  p.mode = mode;
540 
541  switch (mode) {
543  p.ptr = rz_strbuf_new("");
544  break;
546  p.ptr = rz_table_new();
547  rz_table_set_columnsf(p_tbl(p.ptr), "sss", "variable", "type", "value");
548  break;
549  case RZ_OUTPUT_MODE_JSON:
550  p.ptr = pj_new();
551  pj_o(p_pj(p.ptr));
552  break;
553  default:
554  break;
555  }
556 
557  if (!var_name || !strcmp(var_name, "PC")) {
558  p.name = "PC";
560  }
561 
563  if (global_vars) {
564  void **it;
565  rz_pvector_foreach (global_vars, it) {
566  RzILVar *var = *it;
567  if (var_name && strcmp(var_name, var->name)) {
568  continue;
569  }
570  p.name = var->name;
572  if (!val) {
573  continue;
574  }
575  switch (val->type) {
577  rzil_print_register_bitv(val->data.bv, &p);
578  break;
580  rzil_print_register_bool(val->data.b->b, &p);
581  break;
582  default:
584  break;
585  }
586  if (var_name) {
587  break;
588  }
589  if (rz_strbuf_length(p_sb(p.ptr)) > 95) {
590  rz_cons_printf("%s\n", rz_strbuf_get(p_sb(p.ptr)));
591  rz_strbuf_fini(p_sb(p.ptr));
592  }
593  }
594  rz_pvector_free(global_vars);
595  }
596 
597  char *out = NULL;
598  switch (mode) {
600  if (rz_strbuf_length(p_sb(p.ptr)) > 0) {
601  out = rz_strbuf_drain(p_sb(p.ptr));
602  } else {
603  rz_strbuf_free(p_sb(p.ptr));
604  return;
605  }
606  break;
608  out = rz_table_tostring((RzTable *)p.ptr);
609  rz_table_free(p_tbl(p.ptr));
610  break;
611  case RZ_OUTPUT_MODE_JSON:
612  pj_end(p_pj(p.ptr));
613  out = pj_drain(p_pj(p.ptr));
614  break;
615  default:
616  return;
617  }
618 
619  rz_cons_printf("%s\n", out);
620  free(out);
621 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static void rzil_print_register_bitv(RzBitVector *number, ILPrint *p)
Definition: cil.c:512
static void rzil_print_register_bool(bool value, ILPrint *p)
Definition: cil.c:495
#define p_sb(x)
Definition: cil.c:491
#define p_tbl(x)
Definition: cil.c:492
#define p_pj(x)
Definition: cil.c:493
RZ_API RZ_OWN RzPVector * rz_il_vm_get_all_vars(RZ_NONNULL RzILVM *vm, RzILVarKind kind)
Definition: il_vm.c:256
RZ_API RZ_BORROW RzILVal * rz_il_vm_get_var_value(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:264
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API char * pj_drain(PJ *j)
Definition: pj.c:50
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
RZ_API void rz_table_set_columnsf(RzTable *t, const char *fmt,...)
Specify the types and names of the referenced table.
Definition: table.c:234
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
char * name
Definition: variable.h:20

References rz_core_t::analysis, free(), rz_analysis_t::il_vm, rz_il_var_t::name, NULL, out, p, p_pj, p_sb, p_tbl, rz_il_vm_t::pc, pj_drain(), pj_end(), pj_new(), pj_o(), rz_cons_printf(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, RZ_IL_VAR_KIND_GLOBAL, rz_il_vm_get_all_vars(), rz_il_vm_get_var_value(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_pvector_foreach, rz_pvector_free(), rz_strbuf_drain(), rz_strbuf_fini(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_length(), rz_strbuf_new(), rz_table_free(), rz_table_new(), rz_table_set_columnsf(), rz_table_tostring(), rz_warn_if_reached, rzil_print_register_bitv(), rzil_print_register_bool(), val, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_status_handler().

◆ rz_core_analysis_set_reg()

RZ_IPI int rz_core_analysis_set_reg ( RzCore core,
const char *  regname,
ut64  val 
)

Definition at line 389 of file cil.c.

389  {
390  RzRegItem *r = rz_reg_get(core->analysis->reg, regname, -1);
391  if (!r) {
392  int role = rz_reg_get_name_idx(regname);
393  if (role != -1) {
394  const char *alias = rz_reg_get_name(core->analysis->reg, role);
395  if (alias) {
396  r = rz_reg_get(core->analysis->reg, alias, -1);
397  }
398  }
399  }
400  if (!r) {
401  eprintf("ar: Unknown register '%s'\n", regname);
402  return -1;
403  }
404  rz_reg_set_value(core->analysis->reg, r, val);
406  return 0;
407 }
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API int rz_reg_get_name_idx(const char *type)
Definition: reg.c:102
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186

References rz_core_t::analysis, eprintf, r, rz_analysis_t::reg, regname(), rz_core_reg_update_flags(), rz_reg_get(), rz_reg_get_name(), rz_reg_get_name_idx(), rz_reg_set_value(), and val.

Referenced by cmd_analysis_esil(), rz_analysis_aefa(), rz_analysis_esil_init_p_handler(), rz_core_analysis_esil_init_regs(), and rz_core_visual_cmd().

◆ rz_core_analysis_types_propagation()

RZ_IPI bool rz_core_analysis_types_propagation ( RzCore core)

Definition at line 6325 of file canalysis.c.

6325  {
6326  RzListIter *it;
6327  RzAnalysisFunction *fcn;
6328  ut64 seek;
6329  if (rz_config_get_b(core->config, "cfg.debug")) {
6330  eprintf("TOFIX: aaft can't run in debugger mode.\n");
6331  return false;
6332  }
6333  RzConfigHold *hold = rz_config_hold_new(core->config);
6334  rz_config_hold_i(hold, "io.va", "io.pcache.write", NULL);
6335  bool io_cache = rz_config_get_b(core->config, "io.pcache.write");
6336  if (!io_cache) {
6337  // XXX. we shouldnt need this, but it breaks 'rizin -c aaa -w ls'
6338  rz_config_set_b(core->config, "io.pcache.write", true);
6339  }
6340  const bool delete_regs = !rz_flag_space_count(core->flags, RZ_FLAGS_FS_REGISTERS);
6341  seek = core->offset;
6342  rz_reg_arena_push(core->analysis->reg);
6346  ut8 *saved_arena = rz_reg_arena_peek(core->analysis->reg);
6347 
6348  // loop count of rz_core_analysis_type_match
6349  // TODO : figure out the reason to hold a `LOOP COUNT` in type_match
6350  // HtUU <addr->loop_count>
6351  HtUU *loop_table = ht_uu_new0();
6352 
6353  // Iterating Reverse so that we get function in top-bottom call order
6354  rz_list_foreach_prev(core->analysis->fcns, it, fcn) {
6355  int ret = rz_core_seek(core, fcn->addr, true);
6356  if (!ret) {
6357  continue;
6358  }
6359  rz_reg_arena_poke(core->analysis->reg, saved_arena);
6360  rz_analysis_esil_set_pc(core->analysis->esil, fcn->addr);
6361  rz_core_analysis_type_match(core, fcn, loop_table);
6362  if (rz_cons_is_breaked()) {
6363  break;
6364  }
6366  }
6367  if (delete_regs) {
6369  }
6370  rz_core_seek(core, seek, true);
6371  rz_reg_arena_pop(core->analysis->reg);
6373  rz_config_hold_restore(hold);
6374  rz_config_hold_free(hold);
6375  free(saved_arena);
6376  ht_uu_free(loop_table);
6377  return true;
6378 }
RZ_API void rz_core_analysis_type_match(RzCore *core, RzAnalysisFunction *fcn, HtUU *loop_table)
Definition: analysis_tp.c:816
RZ_API ut8 * rz_reg_arena_peek(RzReg *reg)
Definition: arena.c:280
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236
RZ_API void rz_reg_arena_pop(RzReg *reg)
Definition: arena.c:216
RZ_API void rz_reg_arena_zero(RzReg *reg, RzRegisterType type)
Definition: arena.c:261
RZ_API void rz_reg_arena_poke(RzReg *reg, const ut8 *ret)
Definition: arena.c:293
RZ_API void rz_core_analysis_esil_init_mem_del(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Remove ESIL VM stack.
Definition: cil.c:241
RZ_API void rz_core_debug_clear_register_flags(RzCore *core)
Definition: cmd_debug.c:1449
RZ_API RzConfigNode * rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name, bool value)
Definition: config.c:201
RZ_API bool rz_analysis_esil_set_pc(RzAnalysisEsil *esil, ut64 addr)
Definition: esil.c:155
RZ_API void rz_config_hold_restore(RzConfigHold *h)
Restore whatever config options were previously saved in h.
Definition: hold.c:132
RZ_API RzConfigHold * rz_config_hold_new(RzConfig *cfg)
Create an opaque object to save/restore some configuration options.
Definition: hold.c:116
RZ_API bool rz_config_hold_i(RzConfigHold *h,...)
Save the current values of a list of config options that have integer values.
Definition: hold.c:81
RZ_API void rz_config_hold_free(RzConfigHold *h)
Free a RzConfigHold object h.
Definition: hold.c:152
#define RZ_FLAGS_FS_REGISTERS
Definition: rz_core.h:61
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
RZ_API void rz_analysis_fcn_vars_add_types(RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn)
Updates the types database for function arguments.
Definition: var.c:1383
static int seek(char *argv[])

References rz_analysis_function_t::addr, rz_core_t::analysis, rz_core_t::config, core_noretl::core, eprintf, rz_analysis_t::esil, rz_analysis_t::fcns, rz_core_t::flags, free(), NULL, rz_core_t::offset, rz_analysis_t::reg, rz_analysis_esil_set_pc(), rz_analysis_fcn_vars_add_types(), rz_config_get_b(), rz_config_hold_free(), rz_config_hold_i(), rz_config_hold_new(), rz_config_hold_restore(), rz_config_set_b(), rz_cons_is_breaked(), rz_core_analysis_esil_init(), rz_core_analysis_esil_init_mem(), rz_core_analysis_esil_init_mem_del(), rz_core_analysis_type_match(), rz_core_debug_clear_register_flags(), rz_core_seek(), RZ_FLAGS_FS_REGISTERS, rz_reg_arena_peek(), rz_reg_arena_poke(), rz_reg_arena_pop(), rz_reg_arena_push(), rz_reg_arena_zero(), RZ_REG_TYPE_ANY, seek(), UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_analyze_recursively_all_function_types_handler(), and rz_core_analysis_everything().

◆ rz_core_analysis_value_pointers()

RZ_IPI void rz_core_analysis_value_pointers ( RzCore core,
RzOutputMode  mode 
)

Definition at line 6502 of file canalysis.c.

6502  {
6503  ut64 o_align = rz_config_get_i(core->config, "search.align");
6504  const char *analysisin = rz_config_get(core->config, "analysis.in");
6505  char *tmp = strdup(analysisin);
6506  bool is_debug = rz_config_get_b(core->config, "cfg.debug");
6508  rz_config_set_i(core->config, "search.align", archAlign);
6509  rz_config_set(core->config, "analysis.in", "io.maps.x");
6510  rz_core_notify_done(core, "Finding xrefs in noncode section with analysis.in=io.maps");
6511 
6512  int vsize = 4; // 32bit dword
6513  if (core->rasm->bits == 64) {
6514  vsize = 8;
6515  }
6516 
6517  // body
6518  rz_core_notify_done(core, "Analyze value pointers (aav)");
6520  if (is_debug) {
6521  RzList *list = rz_core_get_boundaries_prot(core, 0, "dbg.map", "analysis");
6522  RzListIter *iter;
6523  RzIOMap *map;
6524  if (!list) {
6525  goto beach;
6526  }
6527  rz_list_foreach (list, iter, map) {
6528  if (rz_cons_is_breaked()) {
6529  break;
6530  }
6531  rz_core_notify_done(core, "from 0x%" PFMT64x " to 0x%" PFMT64x " (aav)", map->itv.addr, rz_itv_end(map->itv));
6532  (void)rz_core_search_value_in_range(core, map->itv,
6533  map->itv.addr, rz_itv_end(map->itv), vsize, _CbInRangeAav, (void *)&mode);
6534  }
6535  rz_list_free(list);
6536  } else {
6537  RzList *list = rz_core_get_boundaries_prot(core, 0, NULL, "analysis");
6538  if (!list) {
6539  goto beach;
6540  }
6541  RzListIter *iter, *iter2;
6542  RzIOMap *map, *map2;
6543  ut64 from = UT64_MAX;
6544  ut64 to = UT64_MAX;
6545  // find values pointing to non-executable regions
6546  rz_list_foreach (list, iter2, map2) {
6547  if (rz_cons_is_breaked()) {
6548  break;
6549  }
6550  // TODO: Reduce multiple hits for same addr
6551  from = rz_itv_begin(map2->itv);
6552  to = rz_itv_end(map2->itv);
6553  if ((to - from) > MAX_SCAN_SIZE) {
6554  rz_core_notify_done(core, "Skipping large region (from 0x%08" PFMT64x " to 0x%08" PFMT64x ")", from, to);
6555  continue;
6556  }
6557  rz_core_notify_done(core, "Value from 0x%08" PFMT64x " to 0x%08" PFMT64x " (aav)", from, to);
6558  rz_list_foreach (list, iter, map) {
6559  ut64 begin = map->itv.addr;
6560  ut64 end = rz_itv_end(map->itv);
6561  if (rz_cons_is_breaked()) {
6562  break;
6563  }
6564  if (end - begin > UT32_MAX) {
6565  rz_core_notify_done(core, "Skipping huge range");
6566  continue;
6567  }
6568  rz_core_notify_done(core, "0x%08" PFMT64x "-0x%08" PFMT64x " in 0x%" PFMT64x "-0x%" PFMT64x " (aav)", from, to, begin, end);
6569  (void)rz_core_search_value_in_range(core, map->itv, from, to, vsize, _CbInRangeAav, (void *)&mode);
6570  }
6571  }
6572  rz_list_free(list);
6573  }
6574 beach:
6576  // end
6577  rz_config_set(core->config, "analysis.in", tmp);
6578  free(tmp);
6579  rz_config_set_i(core->config, "search.align", o_align);
6580 }
#define MAX_SCAN_SIZE
Definition: canalysis.c:28
static void _CbInRangeAav(RzCore *core, ut64 from, ut64 to, int vsize, void *user)
Definition: canalysis.c:6461
RZ_API int rz_core_search_value_in_range(RzCore *core, RzInterval search_itv, ut64 vmin, ut64 vmax, int vsize, inRangeCb cb, void *cb_user)
Definition: canalysis.c:4895
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 void rz_core_notify_done(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the end of a task which succeeded.
Definition: core.c:60
#define RZ_ANALYSIS_ARCHINFO_ALIGN
Definition: rz_analysis.h:100
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
int bits
Definition: rz_asm.h:100
RzAsm * rasm
Definition: rz_core.h:323
RzInterval itv
Definition: rz_io.h:149

References _CbInRangeAav(), rz_core_t::analysis, rz_asm_t::bits, rz_core_t::config, core_noretl::core, test_evm::end, free(), from, rz_io_map_t::itv, list(), map(), MAX_SCAN_SIZE, NULL, PFMT64x, rz_core_t::rasm, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_ALIGN, rz_config_get(), rz_config_get_b(), rz_config_get_i(), rz_config_set(), rz_config_set_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_get_boundaries_prot(), rz_core_notify_done(), rz_core_search_value_in_range(), rz_itv_begin(), rz_itv_end(), rz_list_free(), strdup(), autogen_x86imm::tmp, to, UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_analyze_value_to_maps_handler(), and rz_core_analysis_everything().

◆ rz_core_analysis_var_display()

RZ_IPI char* rz_core_analysis_var_display ( RzCore core,
RzAnalysisVar var,
bool  add_name 
)

Definition at line 6148 of file canalysis.c.

6148  {
6149  RzAnalysis *analysis = core->analysis;
6151  char *fmt = rz_type_as_format(analysis->typedb, var->type);
6152  RzRegItem *i;
6153  if (!fmt) {
6154  return rz_strbuf_drain(sb);
6155  }
6156  bool usePxr = rz_type_is_strictly_atomic(core->analysis->typedb, var->type) && rz_type_atomic_str_eq(core->analysis->typedb, var->type, "int");
6157  if (add_name) {
6158  rz_strbuf_appendf(sb, "%s %s = ", var->isarg ? "arg" : "var", var->name);
6159  }
6160  switch (var->kind) {
6162  i = rz_reg_index_get(analysis->reg, var->delta);
6163  if (i) {
6164  char *r;
6165  if (usePxr) {
6166  r = rz_core_cmd_strf(core, "pxr $w @r:%s", i->name);
6167  } else {
6168  r = rz_core_cmd_strf(core, "pf r (%s)", i->name);
6169  }
6170  rz_strbuf_append(sb, r);
6171  free(r);
6172  } else {
6173  RZ_LOG_DEBUG("register not found\n");
6174  }
6175  break;
6176  case RZ_ANALYSIS_VAR_KIND_BPV: {
6177  const st32 real_delta = var->delta + var->fcn->bp_off;
6178  const ut32 udelta = RZ_ABS(real_delta);
6179  const char sign = real_delta >= 0 ? '+' : '-';
6180  char *r;
6181  if (usePxr) {
6182  r = rz_core_cmd_strf(core, "pxr $w @ %s%c0x%x", analysis->reg->name[RZ_REG_NAME_BP], sign, udelta);
6183  } else {
6184  r = rz_core_cmd_strf(core, "pf %s @ %s%c0x%x", fmt, analysis->reg->name[RZ_REG_NAME_BP], sign, udelta);
6185  }
6186  rz_strbuf_append(sb, r);
6187  free(r);
6188  } break;
6189  case RZ_ANALYSIS_VAR_KIND_SPV: {
6190  ut32 udelta = RZ_ABS(var->delta + var->fcn->maxstack);
6191  char *r;
6192  if (usePxr) {
6193  r = rz_core_cmd_strf(core, "pxr $w @ %s+0x%x", analysis->reg->name[RZ_REG_NAME_SP], udelta);
6194  } else {
6195  r = rz_core_cmd_strf(core, "pf %s @ %s+0x%x", fmt, analysis->reg->name[RZ_REG_NAME_SP], udelta);
6196  }
6197  rz_strbuf_append(sb, r);
6198  free(r);
6199  break;
6200  }
6201  }
6202  free(fmt);
6203  return rz_strbuf_drain(sb);
6204 }
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
RZ_API RZ_OWN char * rz_type_as_format(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Represents the RzType as a pf format string.
Definition: format.c:3005
RZ_API bool rz_type_atomic_str_eq(const RzTypeDB *typedb, RZ_NONNULL const RzType *typ1, RZ_NONNULL const char *name)
Checks if two atomic types (RzType and RzBaseType) are equivalent.
Definition: helpers.c:208
RZ_API bool rz_type_is_strictly_atomic(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Checks if the RzType is strictly atomic.
Definition: helpers.c:349
@ RZ_ABS
RZ_API RzRegItem * rz_reg_index_get(RzReg *reg, int idx)
Definition: reg.c:262
@ RZ_ANALYSIS_VAR_KIND_REG
Definition: rz_analysis.h:703
@ RZ_ANALYSIS_VAR_KIND_SPV
Definition: rz_analysis.h:705
@ RZ_ANALYSIS_VAR_KIND_BPV
Definition: rz_analysis.h:704
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define st32
Definition: rz_types_base.h:12
RzAnalysisFunction * fcn
Definition: rz_analysis.h:726
char * name[RZ_REG_NAME_LAST]
Definition: rz_reg.h:149

References rz_core_t::analysis, rz_analysis_function_t::bp_off, core_noretl::core, rz_analysis_var_t::delta, rz_analysis_var_t::fcn, free(), i, rz_analysis_var_t::isarg, rz_analysis_var_t::kind, rz_analysis_function_t::maxstack, rz_analysis_var_t::name, rz_reg_t::name, NULL, r, rz_analysis_t::reg, RZ_ABS, RZ_ANALYSIS_VAR_KIND_BPV, RZ_ANALYSIS_VAR_KIND_REG, RZ_ANALYSIS_VAR_KIND_SPV, rz_core_cmd_strf(), RZ_LOG_DEBUG, rz_reg_index_get(), RZ_REG_NAME_BP, RZ_REG_NAME_SP, rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_as_format(), rz_type_atomic_str_eq(), rz_type_is_strictly_atomic(), sb, st32, rz_analysis_var_t::type, and rz_analysis_t::typedb.

Referenced by ds_show_functions(), ds_show_functions_argvar(), rz_analysis_function_vars_display_handler(), and rz_core_analysis_all_vars_display().

◆ rz_core_analysis_var_rename()

RZ_IPI bool rz_core_analysis_var_rename ( RzCore core,
const char *  name,
const char *  newname 
)

Definition at line 5728 of file canalysis.c.

5728  {
5730  if (!name) {
5732  if (var) {
5733  name = var->name;
5734  } else {
5735  eprintf("Cannot find var @ 0x%08" PFMT64x "\n", core->offset);
5737  return false;
5738  }
5739  }
5740  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, -1);
5741  if (fcn) {
5743  if (v1) {
5744  rz_analysis_var_rename(v1, newname, true);
5745  } else {
5746  eprintf("Cant find var by name\n");
5747  return false;
5748  }
5749  } else {
5750  eprintf("afv: Cannot find function in 0x%08" PFMT64x "\n", core->offset);
5752  return false;
5753  }
5755  return true;
5756 }
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
@ v1
Definition: lanai.h:85
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
Definition: dis.c:32
RZ_API bool rz_analysis_var_rename(RzAnalysisVar *var, const char *new_name, bool verbose)
Definition: var.c:348
RZ_DEPRECATE RZ_API RzAnalysisVar * rz_analysis_get_used_function_var(RzAnalysis *analysis, ut64 addr)
Definition: var.c:398

References rz_core_t::analysis, core_noretl::core, eprintf, rz_analysis_var_t::name, NULL, rz_core_t::offset, PFMT64x, rz_analysis_function_get_var_byname(), rz_analysis_get_fcn_in(), rz_analysis_get_used_function_var(), rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, rz_analysis_var_rename(), rz_core_analysis_op(), and v1.

Referenced by rz_analysis_function_vars_rename_handler(), and variable_rename().

◆ rz_core_asm_bb_middle()

RZ_IPI void rz_core_asm_bb_middle ( RZ_NONNULL RzCore core,
ut64  at,
RZ_INOUT RZ_NONNULL int oplen,
RZ_NONNULL int ret 
)

Update oplen by "asm.bb.middle" and "asm.flags.middle".

Parameters
coreRzCore reference
atAddress
[in,out]oplenOpcode length
retValue by call rz_asm_disassemble

Definition at line 1684 of file disasm.c.

1685  {
1686  rz_return_if_fail(core && oplen && ret);
1687  bool midbb = rz_config_get_b(core->config, "asm.bb.middle");
1688  RzDisasmState ds = {
1689  .at = at,
1690  .oplen = *oplen,
1691  };
1692  int skip_bytes_flag = handleMidFlags(core, &ds, false);
1693  int skip_bytes_bb = midbb ? handleMidBB(core, &ds) : 0;
1694  if (skip_bytes_flag && ds.midflags > RZ_MIDFLAGS_SHOW) {
1695  *oplen = *ret = skip_bytes_flag;
1696  }
1697  if (skip_bytes_bb && skip_bytes_bb < *ret) {
1698  *oplen = skip_bytes_bb;
1699  }
1700 }
static int handleMidBB(RzCore *core, RzDisasmState *ds)
Definition: disasm.c:1657
static int handleMidFlags(RzCore *core, RzDisasmState *ds, bool print)
Definition: disasm.c:1616
int midflags
Definition: disasm.c:208

References RzDisasmState::at, handleMidBB(), handleMidFlags(), RzDisasmState::midflags, rz_config_get_b(), and rz_return_if_fail.

Referenced by rz_core_analysis_bytes().

◆ rz_core_base_type_as_c()

RZ_IPI RZ_OWN char* rz_core_base_type_as_c ( RzCore core,
RZ_NONNULL RzBaseType type,
bool  multiline 
)

Definition at line 408 of file ctypes.c.

408  {
410 
411  unsigned int multiline_opt = 0;
412  if (multiline) {
413  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
414  }
416 }
RZ_API RZ_OWN char * rz_type_db_base_type_as_pretty_string(RZ_NONNULL const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, unsigned int opts, int unfold_level)
Returns C representation as string of RzBaseType.
Definition: base.c:219
@ RZ_TYPE_PRINT_END_NEWLINE
Definition: rz_type.h:222
@ RZ_TYPE_PRINT_MULTILINE
Definition: rz_type.h:216
@ RZ_TYPE_PRINT_ANONYMOUS
Definition: rz_type.h:221

References rz_core_t::analysis, NULL, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, RZ_TYPE_PRINT_MULTILINE, type, and rz_analysis_t::typedb.

Referenced by rz_core_types_as_c(), and rz_types_open_editor().

◆ rz_core_bin_plugin_print()

RZ_IPI RzCmdStatus rz_core_bin_plugin_print ( const RzBinPlugin bp,
RzCmdStateOutput state 
)

Definition at line 4783 of file cbin.c.

4783  {
4785 
4786  rz_cmd_state_output_set_columnsf(state, "sss", "type", "name", "description");
4787 
4788  switch (state->mode) {
4789  case RZ_OUTPUT_MODE_QUIET:
4790  rz_cons_printf("%s\n", bp->name);
4791  break;
4792  case RZ_OUTPUT_MODE_JSON:
4793  pj_o(state->d.pj);
4794  pj_ks(state->d.pj, "name", bp->name);
4795  pj_ks(state->d.pj, "description", bp->desc);
4796  if (bp->license) {
4797  pj_ks(state->d.pj, "license", bp->license);
4798  }
4799  if (bp->version) {
4800  pj_ks(state->d.pj, "version", bp->version);
4801  }
4802  if (bp->license) {
4803  pj_ks(state->d.pj, "author", bp->license);
4804  }
4805  pj_end(state->d.pj);
4806  break;
4808  rz_cons_printf("bin %-11s %s (%s) %s %s\n",
4809  bp->name, bp->desc, bp->license ? bp->license : "???",
4810  bp->version ? bp->version : "",
4811  bp->author ? bp->author : "");
4812  break;
4813  case RZ_OUTPUT_MODE_TABLE:
4814  rz_table_add_rowf(state->d.t, "sss", "bin", bp->name, bp->desc);
4815  break;
4816  default:
4819  }
4820  return RZ_CMD_STATUS_OK;
4821 }
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
char * desc
Definition: rz_bin.h:510
char * name
Definition: rz_bin.h:509
char * license
Definition: rz_bin.h:513
char * version
Definition: rz_bin.h:512
char * author
Definition: rz_bin.h:511

References rz_bin_plugin_t::author, rz_bin_plugin_t::desc, rz_bin_plugin_t::license, rz_bin_plugin_t::name, pj_end(), pj_ks(), pj_o(), rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_return_val_if_fail, rz_table_add_rowf(), rz_warn_if_reached, and rz_bin_plugin_t::version.

Referenced by rz_cmd_info_plugins_handler(), and rz_core_bin_plugins_print().

◆ rz_core_binxtr_plugin_print()

RZ_IPI RzCmdStatus rz_core_binxtr_plugin_print ( const RzBinXtrPlugin bx,
RzCmdStateOutput state 
)

Definition at line 4823 of file cbin.c.

4823  {
4825 
4826  const char *name = NULL;
4827 
4828  rz_cmd_state_output_set_columnsf(state, "sss", "type", "name", "description");
4829  switch (state->mode) {
4830  case RZ_OUTPUT_MODE_QUIET:
4831  rz_cons_printf("%s\n", bx->name);
4832  break;
4833  case RZ_OUTPUT_MODE_JSON:
4834  pj_o(state->d.pj);
4835  pj_ks(state->d.pj, "name", bx->name);
4836  pj_ks(state->d.pj, "description", bx->desc);
4837  pj_ks(state->d.pj, "license", bx->license ? bx->license : "???");
4838  pj_end(state->d.pj);
4839  break;
4841  name = strncmp(bx->name, "xtr.", 4) ? bx->name : bx->name + 3;
4842  rz_cons_printf("xtr %-11s %s (%s)\n", name,
4843  bx->desc, bx->license ? bx->license : "???");
4844  break;
4845  case RZ_OUTPUT_MODE_TABLE:
4846  rz_table_add_rowf(state->d.t, "sss", "xtr", bx->name, bx->desc);
4847  break;
4848  default:
4851  }
4852  return RZ_CMD_STATUS_OK;
4853 }

References rz_bin_xtr_plugin_t::desc, rz_bin_xtr_plugin_t::license, rz_bin_xtr_plugin_t::name, NULL, pj_end(), pj_ks(), pj_o(), rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_return_val_if_fail, rz_table_add_rowf(), and rz_warn_if_reached.

Referenced by rz_cmd_info_plugins_handler(), and rz_core_bin_plugins_print().

◆ rz_core_cmd_lastcmd_repeat()

RZ_IPI bool rz_core_cmd_lastcmd_repeat ( RzCore core,
bool  next 
)

Definition at line 216 of file cmd.c.

216  {
217  int res = -1;
218  // Fix for backtickbug px`~`
219  if (!core->lastcmd || core->cons->context->cmd_depth < 1) {
220  return false;
221  }
222  switch (*core->lastcmd) {
223  case '.':
224  if (core->lastcmd[1] == '(') { // macro call
225  res = rz_core_cmd0(core, core->lastcmd);
226  }
227  break;
228  case 'd': // debug
229  res = rz_core_cmd0(core, core->lastcmd);
230  switch (core->lastcmd[1]) {
231  case 's':
232  case 'c':
233  rz_core_seek_to_register(core, "PC", false);
234  rz_core_cmd0(core, "pd 1");
235  }
236  break;
237  case 'p': // print
238  case 'x':
239  case '$':
240  if (!strncmp(core->lastcmd, "pd", 2)) {
241  if (core->lastcmd[2] == ' ') {
242  ut64 addr = rz_num_math(core->num, core->lastcmd + 3);
243  rz_core_seek_opcode(core, addr, false);
244  } else {
245  rz_core_cmd0(core, "so `pi~?`");
246  }
247  } else {
248  if (next) {
249  rz_core_seek(core, core->offset + core->blocksize, true);
250  } else {
251  if (core->blocksize > core->offset) {
252  rz_core_seek(core, 0, true);
253  } else {
254  rz_core_seek(core, core->offset - core->blocksize, true);
255  }
256  }
257  }
258  res = rz_core_cmd0(core, core->lastcmd);
259  break;
260  }
261  core->is_lastcmd = true;
262  return res != -1;
263 }
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_IPI bool rz_core_seek_to_register(RzCore *core, const char *regname, bool is_silent)
Definition: cmd_seek.c:22
RZ_IPI int rz_core_seek_opcode(RzCore *core, int n, bool silent)
Definition: cmd_seek.c:86
RzConsContext * context
Definition: rz_cons.h:502
RzCons * cons
Definition: rz_core.h:312
bool is_lastcmd
Definition: rz_core.h:338
char * lastcmd
Definition: rz_core.h:337

References addr, rz_core_t::blocksize, rz_cons_context_t::cmd_depth, rz_core_t::cons, rz_cons_t::context, rz_core_t::is_lastcmd, rz_core_t::lastcmd, rz_core_t::num, rz_core_t::offset, rz_core_cmd0(), rz_core_seek(), rz_core_seek_opcode(), rz_core_seek_to_register(), rz_num_math(), and ut64().

Referenced by DEFINE_HANDLE_TS_FCN(), rz_core_cmd_nullcallback(), rz_core_cmd_subst(), rz_interpret_handler(), and rz_repeat_forward_handler().

◆ rz_core_debug_attach()

RZ_IPI void rz_core_debug_attach ( RzCore core,
int  pid 
)

Definition at line 284 of file cdebug.c.

284  {
285  char buf[20];
286 
288  if (pid > 0) {
289  rz_debug_attach(core->dbg, pid);
290  } else {
291  if (core->file && core->io) {
292  rz_debug_attach(core->dbg, rz_io_fd_get_pid(core->io, core->file->fd));
293  }
294  }
295  rz_debug_select(core->dbg, core->dbg->pid, core->dbg->tid);
296  rz_config_set_i(core->config, "dbg.swstep", (core->dbg->cur && !core->dbg->cur->canstep));
297  rz_io_system(core->io, rz_strf(buf, "pid %d", core->dbg->pid));
298 }
RZ_API bool rz_debug_reg_profile_sync(RzDebug *dbg)
Definition: dreg.c:116
RZ_API int rz_debug_attach(RzDebug *dbg, int pid)
Definition: debug.c:445
RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid)
Definition: debug.c:595
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
RZ_API char * rz_io_system(RzIO *io, const char *cmd)
Definition: io.c:411
RZ_API int rz_io_fd_get_pid(RzIO *io, int fd)
Definition: io_fd.c:92
RzDebug * dbg
Definition: rz_core.h:329
RzCoreFile * file
Definition: rz_core.h:314
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295

References rz_debug_plugin_t::canstep, rz_core_t::config, rz_debug_t::cur, rz_core_t::dbg, rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, rz_debug_t::pid, pid, rz_config_set_i(), rz_debug_attach(), rz_debug_reg_profile_sync(), rz_debug_select(), rz_io_fd_get_pid(), rz_io_system(), rz_strf, and rz_debug_t::tid.

Referenced by cmd_debug_pid(), and rz_core_setup_debugger().

◆ rz_core_debug_bp_add()

RZ_IPI void rz_core_debug_bp_add ( RzCore core,
ut64  addr,
const char *  arg_perm,
bool  hwbp,
bool  watch 
)

Definition at line 1574 of file cmd_debug.c.

1574  {
1575  RzBreakpointItem *bpi;
1576  int rw = 0;
1577 
1578  if (watch) {
1579  rw = rz_str_rwx(arg_perm);
1580  rw &= RZ_PERM_RWX; // filter out the rwx bits only
1581  if (rw == 0) {
1582  RZ_LOG_WARN("Invalid permissions provided for setting watchpoint. Defaulting to \"rw\".\n");
1583  rw = RZ_PERM_RW;
1584  }
1585  }
1586  bpi = rz_debug_bp_add(core->dbg, addr, hwbp, watch, rw, NULL, 0);
1587  if (!bpi) {
1588  RZ_LOG_ERROR("Cannot set breakpoint at 0x%" PFMT64x "\n", addr);
1589  return;
1590  }
1592  if (f) {
1593  if (addr > f->offset) {
1594  char *name = rz_str_newf("%s+0x%" PFMT64x, f->name, addr - f->offset);
1595  rz_bp_item_set_name(bpi, name);
1596  free(name);
1597  } else {
1598  bpi->name = strdup(f->name);
1599  }
1600  } else {
1601  char *name = rz_str_newf("0x%08" PFMT64x, addr);
1602  rz_bp_item_set_name(bpi, name);
1603  free(name);
1604  }
1605 }
RZ_API bool rz_bp_item_set_name(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *name)
set the name for a RzBreakpointItem
Definition: bp.c:489
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
RZ_API RZ_BORROW RzBreakpointItem * rz_debug_bp_add(RZ_NONNULL RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, RZ_NULLABLE const char *module, st64 m_delta)
Definition: debug.c:270
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_PERM_RWX
Definition: rz_types.h:98
char * name
Definition: rz_bp.h:42

References addr, rz_core_t::dbg, f, rz_core_t::flags, free(), rz_bp_item_t::name, NULL, PFMT64x, rz_bp_item_set_name(), rz_core_flag_get_by_spaces(), rz_debug_bp_add(), RZ_LOG_ERROR, RZ_LOG_WARN, RZ_PERM_RW, RZ_PERM_RWX, rz_str_newf(), rz_str_rwx(), and strdup().

Referenced by __watch_points_cb(), rz_cmd_debug_add_bp_handler(), rz_cmd_debug_add_hw_bp_handler(), and rz_cmd_debug_add_watchpoint_handler().

◆ rz_core_debug_continue()

RZ_IPI void rz_core_debug_continue ( RzCore core)

Definition at line 81 of file cdebug.c.

81  {
82  if (rz_core_is_debug(core)) {
84  rz_reg_arena_swap(core->dbg->reg, true);
85 #if __linux__
86  core->dbg->continue_all_threads = true;
87 #endif
88  rz_debug_continue(core->dbg);
92  } else {
93  rz_core_esil_step(core, UT64_MAX, "0", NULL, false);
95  }
96 }
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
RZ_API bool rz_core_is_debug(RzCore *core)
Check whether the core is in debug mode (equivalent to cfg.debug)
Definition: cdebug.c:13
RZ_IPI void rz_core_static_debug_stop(void *u)
Definition: cmd_debug.c:1565
RZ_API void rz_core_dbg_follow_seek_register(RzCore *core)
Seek to PC if needed.
Definition: cmd_debug.c:474
RZ_API int rz_debug_continue(RzDebug *dbg)
Definition: debug.c:1332
bool continue_all_threads
Definition: rz_debug.h:272
RzReg * reg
Definition: rz_debug.h:286

References rz_debug_t::continue_all_threads, rz_core_t::dbg, NULL, rz_debug_t::reg, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_esil_step(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_core_static_debug_stop(), rz_debug_continue(), rz_reg_arena_swap(), and UT64_MAX.

Referenced by __continue_cb(), __panels_process(), graph_continue(), rz_cmd_debug_continue_execution_handler(), and visual_nkey().

◆ rz_core_debug_print_status()

RZ_IPI void rz_core_debug_print_status ( RzCore core)

Definition at line 356 of file cdebug.c.

356  {
357  RzReg *reg = rz_core_reg_default(core);
358  RzList *ritems = rz_reg_filter_items_covered(reg->allregs);
359  if (ritems) {
360  rz_core_reg_print_diff(reg, ritems);
361  rz_list_free(ritems);
362  }
363  ut64 old_address = core->offset;
366  rz_core_seek(core, old_address, true);
367  rz_cons_flush();
368 }
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_IPI void rz_core_reg_print_diff(RzReg *reg, RzList *items)
Print registers that have changed since the last step (drd/ard)
Definition: creg.c:116
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes)
Definition: disasm.c:6030
#define reg(n)
RZ_API RZ_OWN RzList * rz_reg_filter_items_covered(RZ_BORROW RZ_NONNULL const RzList *regs)
Filter out all register items that are smaller than but covered entirely by some other register.
Definition: reg.c:489
RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role)
Definition: rvalue.c:181

References rz_core_t::offset, reg, rz_cons_flush(), rz_core_print_disasm_instructions(), rz_core_reg_default(), rz_core_reg_print_diff(), rz_core_seek(), rz_list_free(), rz_reg_filter_items_covered(), rz_reg_get_value_by_role(), RZ_REG_NAME_PC, and ut64().

Referenced by rz_core_prompt_loop().

◆ rz_core_debug_single_step_in()

RZ_IPI void rz_core_debug_single_step_in ( RzCore core)

Definition at line 193 of file cdebug.c.

193  {
194  if (rz_core_is_debug(core)) {
195  if (core->print->cur_enabled) {
196  rz_core_debug_continue_until(core, core->offset, core->offset + core->print->cur);
197  core->print->cur_enabled = 0;
198  } else {
199  rz_core_debug_step_one(core, 1);
200  }
201  } else {
202  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
204  }
205 }
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to)
Definition: cdebug.c:98
RZ_API bool rz_core_debug_step_one(RzCore *core, int times)
Definition: cdebug.c:56
RzPrint * print
Definition: rz_core.h:327
bool cur_enabled
Definition: rz_print.h:130

References rz_print_t::cur, rz_print_t::cur_enabled, NULL, rz_core_t::offset, rz_core_t::print, rz_core_debug_continue_until(), rz_core_debug_step_one(), rz_core_esil_step(), rz_core_is_debug(), rz_core_reg_update_flags(), and UT64_MAX.

Referenced by __panel_single_step_in(), graph_single_step_in(), rz_core_visual_cmd(), and visual_nkey().

◆ rz_core_debug_single_step_over()

RZ_IPI void rz_core_debug_single_step_over ( RzCore core)

Definition at line 207 of file cdebug.c.

207  {
208  bool io_cache = rz_config_get_b(core->config, "io.cache");
209  rz_config_set_b(core->config, "io.cache", false);
210  if (rz_core_is_debug(core)) {
211  if (core->print->cur_enabled) {
213  rz_reg_arena_swap(core->dbg->reg, true);
218  core->print->cur_enabled = 0;
219  } else {
220  rz_core_debug_step_over(core, 1);
223  }
224  } else {
226  }
227  rz_config_set_b(core->config, "io.cache", io_cache);
228 }
RZ_API bool rz_core_debug_step_over(RzCore *core, int steps)
Step over.
Definition: cdebug.c:802
RZ_API void rz_core_analysis_esil_step_over(RZ_NONNULL RzCore *core)
Definition: cil.c:269
RZ_API int rz_debug_continue_until_optype(RzDebug *dbg, int type, int over)
Definition: debug.c:1345
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385

References rz_core_t::config, rz_print_t::cur_enabled, rz_core_t::dbg, rz_core_t::print, rz_debug_t::reg, RZ_ANALYSIS_OP_TYPE_RET, rz_config_get_b(), rz_config_set_b(), rz_cons_break_pop(), rz_cons_break_push(), rz_core_analysis_esil_step_over(), rz_core_dbg_follow_seek_register(), rz_core_debug_step_over(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_core_static_debug_stop(), rz_debug_continue_until_optype(), and rz_reg_arena_swap().

Referenced by __panel_single_step_over(), graph_single_step_over(), rz_core_visual_cmd(), and visual_nkey().

◆ rz_core_debug_sync_bits()

RZ_IPI void rz_core_debug_sync_bits ( RzCore core)

Definition at line 184 of file cdebug.c.

184  {
185  if (rz_core_is_debug(core)) {
186  ut64 asm_bits = rz_config_get_i(core->config, "asm.bits");
187  if (asm_bits != core->dbg->bits * 8) {
188  rz_config_set_i(core->config, "asm.bits", core->dbg->bits * 8);
189  }
190  }
191 }
int bits
Definition: rz_debug.h:243

References rz_debug_t::bits, rz_core_t::config, rz_core_t::dbg, rz_config_get_i(), rz_config_set_i(), rz_core_is_debug(), and ut64().

Referenced by rz_core_dbg_follow_seek_register(), and rz_core_visual_title().

◆ rz_core_flag_describe()

RZ_IPI void rz_core_flag_describe ( RzCore core,
ut64  addr,
bool  strict_offset,
RzCmdStateOutput state 
)

Definition at line 327 of file cmd_flag.c.

327  {
328  RzFlagItem *f = rz_flag_get_at(core->flags, addr, !strict_offset);
329  if (!f) {
330  return;
331  }
332  PJ *pj = state->d.pj;
333  switch (state->mode) {
334  case RZ_OUTPUT_MODE_JSON:
335  pj_o(pj);
336  pj_kn(pj, "offset", f->offset);
337  pj_ks(pj, "name", f->name);
338  // Print flag's real name if defined
339  if (f->realname) {
340  pj_ks(pj, "realname", f->realname);
341  }
342  pj_end(pj);
343  break;
345  // Print realname if exists and asm.flags.real is enabled
346  const char *name = core->flags->realnames && f->realname ? f->realname : f->name;
347  if (f->offset != addr) {
348  rz_cons_printf("%s + %d\n", name, (int)(addr - f->offset));
349  } else {
351  }
352  break;
353  }
354  default:
356  break;
357  }
358 }
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
bool realnames
Definition: rz_flag.h:49

References addr, f, rz_core_t::flags, pj_end(), pj_kn(), pj_ks(), pj_o(), rz_flag_t::realnames, rz_cons_printf(), rz_cons_println(), rz_flag_get_at(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, and rz_warn_if_reached.

Referenced by rz_core_visual_xrefs(), and rz_flag_describe_handler().

◆ rz_core_flag_print()

RZ_IPI void rz_core_flag_print ( RzFlag f,
RzCmdStateOutput state 
)

Definition at line 169 of file cflag.c.

169  {
170  flag_print(f, state, UT64_MAX, UT64_MAX, false);
171 }
static void flag_print(RzFlag *f, RzCmdStateOutput *state, ut64 range_from, ut64 range_to, bool in_range)
Definition: cflag.c:112

References f, flag_print(), and UT64_MAX.

Referenced by rz_flag_list_handler().

◆ rz_core_flag_range_print()

RZ_IPI void rz_core_flag_range_print ( RzFlag f,
RzCmdStateOutput state,
ut64  range_from,
ut64  range_to 
)

Definition at line 184 of file cflag.c.

184  {
185  flag_print(f, state, range_from, range_to, true);
186 }

References f, flag_print(), print_flag_t::range_from, and print_flag_t::range_to.

Referenced by rz_flag_list_at_handler(), and rz_flag_range_handler().

◆ rz_core_flag_real_name_print()

RZ_IPI void rz_core_flag_real_name_print ( RzFlag f,
RzCmdStateOutput state 
)

Definition at line 173 of file cflag.c.

173  {
174  struct print_flag_t u = {
175  .f = f,
176  .in_range = false,
177  .range_from = UT64_MAX,
178  .range_to = UT64_MAX,
179  .real = true
180  };
181  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_orig_name, &u);
182 }
static bool print_flag_orig_name(RzFlagItem *flag, void *user)
Definition: cflag.c:83
RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:826
RzFlag * f
Definition: cflag.c:11

References print_flag_t::f, f, print_flag_orig_name(), rz_flag_foreach_space(), and UT64_MAX.

◆ rz_core_handle_backwards_disasm()

RZ_IPI bool rz_core_handle_backwards_disasm ( RZ_NONNULL RzCore core,
RZ_NONNULL RZ_INOUT int pn_opcodes,
RZ_NONNULL RZ_INOUT int pn_bytes 
)

Converting negative numbers n_opcodes and n_opcodes to positive numbers n_opcodes and n_opcodes and seek the appropriate offset.

Parameters
coreRzCore reference
pn_opcodesPointer to n_opcodes
pn_bytesPointer to n_bytes
Returns
success

Definition at line 5984 of file disasm.c.

5985  {
5986  rz_return_val_if_fail(core && pn_opcodes && pn_bytes, false);
5987 
5988  if (*pn_opcodes > ST16_MAX || *pn_opcodes < ST16_MIN) {
5989  RZ_LOG_ERROR("the number of instructions is too big (%d < n_instrs < %d).\n", ST16_MAX, ST16_MIN);
5990  return false;
5991  }
5992  if (!*pn_opcodes && !*pn_bytes) {
5993  core->blocksize = 0;
5994  return true;
5995  }
5996  const ut64 old_offset = core->offset;
5997  const ut32 old_blocksize = core->blocksize;
5998  ut64 offset = old_offset;
5999  const int x_bytes = *pn_bytes
6000  ? RZ_MIN(RZ_ABS(*pn_bytes), RZ_CORE_MAX_DISASM)
6001  : (int)core->blocksize;
6002 
6003  if (*pn_opcodes < 0) {
6004  *pn_opcodes = -*pn_opcodes;
6005  *pn_bytes = x_bytes;
6006  if (!rz_core_prevop_addr(core, old_offset, *pn_opcodes, &offset)) {
6007  offset = rz_core_prevop_addr_force(core, old_offset, *pn_opcodes);
6008  }
6009  } else {
6010  if (*pn_bytes < 0) {
6011  offset = old_offset - x_bytes;
6012  }
6013  *pn_bytes = x_bytes;
6014  }
6015 
6016  if (*pn_bytes > old_blocksize) {
6017  rz_core_block_size(core, *pn_bytes);
6018  }
6019  if (offset != old_offset) {
6020  rz_core_seek(core, offset, true);
6021  } else {
6022  rz_core_block_read(core);
6023  }
6024  return true;
6025 }
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
voidpf uLong offset
Definition: ioapi.h:144
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
#define ST16_MAX
#define RZ_MIN(x, y)
#define ST16_MIN
static int
Definition: sfsocketcall.h:114
RZ_API bool rz_core_prevop_addr(RzCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr)
Definition: visual.c:1173
static int blocksize
Definition: visual.c:15
RZ_API ut64 rz_core_prevop_addr_force(RzCore *core, ut64 start_addr, int numinstrs)
Definition: visual.c:1195

References if(), int, RZ_ABS, rz_core_block_read(), rz_core_block_size(), rz_core_prevop_addr(), rz_core_prevop_addr_force(), rz_core_seek(), RZ_LOG_ERROR, RZ_MIN, rz_return_val_if_fail, ST16_MAX, ST16_MIN, and ut64().

Referenced by core_disassembly(), rz_core_disasm_pdi(), rz_core_print_disasm_instructions(), and rz_core_print_disasm_json().

◆ rz_core_il_step()

RZ_IPI bool rz_core_il_step ( RzCore core)

Perform a single step at the PC given by analysis->reg in RzIL

Returns
false if an error occured (e.g. invalid op)

Definition at line 630 of file cil.c.

630  {
631  if (!core->analysis || !core->analysis->il_vm) {
632  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
633  return false;
634  }
636  switch (r) {
639  return true;
641  RZ_LOG_ERROR("RzIL: invalid instruction or lifting not implemented at address 0x%08" PFMT64x "\n",
643  break;
644  default:
645  RZ_LOG_ERROR("RzIL: stepping failed.\n");
646  break;
647  }
648  return false;
649 }
RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg)
Definition: analysis_il.c:240
RzAnalysisILStepResult
Definition: rz_analysis.h:1161
@ RZ_ANALYSIS_IL_STEP_INVALID_OP
Definition: rz_analysis.h:1165
@ RZ_ANALYSIS_IL_STEP_RESULT_SUCCESS
Definition: rz_analysis.h:1162

References rz_core_t::analysis, rz_analysis_t::il_vm, PFMT64x, r, rz_analysis_t::reg, RZ_ANALYSIS_IL_STEP_INVALID_OP, RZ_ANALYSIS_IL_STEP_RESULT_SUCCESS, rz_analysis_il_vm_step(), rz_core_reg_update_flags(), RZ_LOG_ERROR, rz_reg_get_value_by_role(), and RZ_REG_NAME_PC.

Referenced by rz_core_analysis_il_step_with_events(), rz_il_vm_step_handler(), and rz_il_vm_step_until_addr_handler().

◆ rz_core_io_map_info_free()

RZ_IPI void rz_core_io_map_info_free ( RzCoreIOMapInfo info)

Definition at line 1679 of file cfile.c.

1679  {
1680  free(info);
1681 }

References free(), and info().

Referenced by rz_core_file_io_map_deleted().

◆ rz_core_io_map_info_new()

RZ_IPI RzCoreIOMapInfo* rz_core_io_map_info_new ( RzCoreFile cf,
int  perm_orig 
)

Definition at line 1669 of file cfile.c.

1669  {
1671  if (!info) {
1672  return NULL;
1673  }
1674  info->cf = cf;
1675  info->perm_orig = perm_orig;
1676  return info;
1677 }
#define RZ_NEW(x)
Definition: rz_types.h:285

References info(), NULL, and RZ_NEW.

Referenced by add_map(), and io_create_mem_map().

◆ rz_core_kuery_print()

RZ_IPI void rz_core_kuery_print ( RzCore core,
const char *  k 
)

Definition at line 634 of file cmd.c.

634  {
635  char *out = sdb_querys(core->sdb, NULL, 0, k);
636  if (out) {
637  rz_cons_print(out);
638  }
639  free(out);
640 }
const char * k
Definition: dsignal.c:11
Sdb * sdb
Definition: rz_core.h:365

References free(), k, NULL, out, rz_core_t::sdb, and sdb_querys().

Referenced by rz_cmd_kuery(), and rz_core_types_calling_conventions_print().

◆ rz_core_meta_append()

RZ_IPI void rz_core_meta_append ( RzCore core,
const char *  newcomment,
RzAnalysisMetaType  mtype,
ut64  addr 
)

Definition at line 376 of file cmeta.c.

376  {
377  const char *comment = rz_meta_get_string(core->analysis, mtype, addr);
378  char *nc = strdup(newcomment);
379  rz_str_unescape(nc);
380  if (comment) {
381  char *text = rz_str_newf("%s %s", comment, nc);
382  if (text) {
383  rz_meta_set_string(core->analysis, mtype, addr, text);
384  free(text);
385  } else {
386  rz_sys_perror("malloc");
387  }
388  } else {
389  rz_meta_set_string(core->analysis, mtype, addr, nc);
390  }
391  free(nc);
392 }
RZ_API const char * rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr)
Definition: meta.c:146
RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, const char *s)
Definition: meta.c:141
RZ_API int rz_str_unescape(char *buf)
Definition: str.c:1300
#define rz_sys_perror(x)
Definition: rz_types.h:336

References addr, rz_core_t::analysis, free(), rz_meta_get_string(), rz_meta_set_string(), rz_str_newf(), rz_str_unescape(), rz_sys_perror, strdup(), and create_tags_rz::text.

Referenced by add_comment(), rz_comment_append_handler(), and rz_comment_handler().

◆ rz_core_meta_comment_add()

RZ_IPI void rz_core_meta_comment_add ( RzCore core,
const char *  comment,
ut64  addr 
)

Definition at line 17 of file cmd_meta.c.

17  {
18  const char *oldcomment = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, addr);
19  if (!oldcomment || (oldcomment && !strstr(oldcomment, comment))) {
21  }
22 }
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295

References addr, rz_core_t::analysis, rz_meta_get_string(), rz_meta_set_string(), and RZ_META_TYPE_COMMENT.

Referenced by add_arch_platform_flag_comment_cb(), and rz_comment_unique_handler().

◆ rz_core_meta_editor()

RZ_IPI void rz_core_meta_editor ( RzCore core,
RzAnalysisMetaType  mtype,
ut64  addr 
)

Definition at line 394 of file cmeta.c.

394  {
395  const char *comment = rz_meta_get_string(core->analysis, mtype, addr);
396  char *out = rz_core_editor(core, NULL, comment);
397  if (out) {
398  rz_meta_del(core->analysis, mtype, addr, 1);
399  rz_meta_set_string(core->analysis, mtype, addr, out);
400  free(out);
401  }
402 }
RZ_API void rz_meta_del(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, ut64 size)
Definition: meta.c:187

References addr, rz_core_t::analysis, free(), NULL, out, rz_core_editor(), rz_meta_del(), rz_meta_get_string(), and rz_meta_set_string().

Referenced by add_comment(), rz_comment_editor_handler(), and rz_meta_type_editor_handler().

◆ rz_core_meta_print()

RZ_IPI void rz_core_meta_print ( RzCore core,
RzAnalysisMetaItem d,
ut64  start,
ut64  size,
bool  show_full,
RzCmdStateOutput state 
)

Definition at line 74 of file cmeta.c.

74  {
75  if (rz_spaces_current(&core->analysis->meta_spaces) &&
76  rz_spaces_current(&core->analysis->meta_spaces) != d->space) {
77  return;
78  }
79  PJ *pj = state->d.pj;
80  RzOutputMode mode = state->mode;
81  char *pstr, *base64_str;
82  char *str = NULL;
83  if (d->str) {
84  if (d->type == RZ_META_TYPE_STRING) {
85  str = meta_string_escape(core, d);
86  } else {
87  str = rz_str_escape(d->str);
88  }
89  }
90  if (str || d->type == RZ_META_TYPE_DATA) {
91  if (d->type == RZ_META_TYPE_STRING && !*str) {
92  free(str);
93  return;
94  }
95  if (!str) {
96  pstr = "";
97  } else if (d->type == RZ_META_TYPE_FORMAT) {
98  pstr = str;
99  } else if (d->type == RZ_META_TYPE_STRING) {
100  pstr = str;
101  } else if (d->type == RZ_META_TYPE_VARTYPE) {
102  // Sanitize (don't escape) Ct comments so we can see "char *", etc.
103  free(str);
104  str = strdup(d->str);
106  pstr = str;
107  } else if (d->type != RZ_META_TYPE_COMMENT) {
108  rz_name_filter(str, 0, true);
109  pstr = str;
110  } else {
111  pstr = d->str;
112  }
113  switch (mode) {
114  case RZ_OUTPUT_MODE_JSON:
115  pj_o(pj);
116  pj_kn(pj, "offset", start);
117  pj_ks(pj, "type", rz_meta_type_to_string(d->type));
118 
119  if (d->type == RZ_META_TYPE_HIGHLIGHT) {
120  pj_k(pj, "color");
121  ut8 r = 0, g = 0, b = 0, A = 0;
122  const char *esc = strchr(d->str, '\x1b');
123  if (esc) {
124  rz_cons_rgb_parse(esc, &r, &g, &b, &A);
125  char *rgb_str = rz_cons_rgb_tostring(r, g, b);
126  base64_str = rz_base64_encode_dyn((const ut8 *)rgb_str, strlen(rgb_str));
127  if (d->type == RZ_META_TYPE_STRING && base64_str) {
128  pj_s(pj, base64_str);
129  } else {
130  pj_s(pj, rgb_str);
131  }
132  free(base64_str);
133  free(rgb_str);
134  } else {
135  pj_s(pj, str);
136  }
137  } else {
138  pj_k(pj, "name");
139  if (d->type == RZ_META_TYPE_STRING && (base64_str = rz_base64_encode_dyn((const ut8 *)d->str, strlen(d->str)))) {
140  pj_s(pj, base64_str);
141  free(base64_str);
142  } else {
143  pj_s(pj, rz_str_get(str));
144  }
145  }
146  if (d->type == RZ_META_TYPE_DATA) {
147  pj_kn(pj, "size", size);
148  } else if (d->type == RZ_META_TYPE_STRING) {
149  const char *enc = rz_str_enc_as_string(d->subtype);
150  pj_ks(pj, "enc", enc);
151  pj_kb(pj, "ascii", rz_str_is_ascii(d->str));
152  }
153  pj_end(pj);
154  break;
156  default:
157  switch (d->type) {
158  case RZ_META_TYPE_COMMENT: {
159  const char *type = rz_meta_type_to_string(d->type);
160  char *s = sdb_encode((const ut8 *)pstr, -1);
161  if (!s) {
162  s = strdup(pstr);
163  }
164  if (mode == RZ_OUTPUT_MODE_RIZIN) {
165  if (!strcmp(type, "CCu")) {
166  rz_cons_printf("%s base64:%s @ 0x%08" PFMT64x "\n",
167  type, s, start);
168  } else {
169  rz_cons_printf("%s %s @ 0x%08" PFMT64x "\n",
170  type, pstr, start);
171  }
172  } else {
173  if (!strcmp(type, "CCu")) {
174  char *mys = rz_str_escape(pstr);
175  rz_cons_printf("0x%08" PFMT64x " %s \"%s\"\n",
176  start, type, mys);
177  free(mys);
178  } else {
179  rz_cons_printf("0x%08" PFMT64x " %s \"%s\"\n",
180  start, type, pstr);
181  }
182  }
183  free(s);
184  } break;
185  case RZ_META_TYPE_STRING:
186  if (mode == RZ_OUTPUT_MODE_RIZIN) {
187  char cmd[] = "Cs#";
188  switch (d->subtype) {
189  case RZ_STRING_ENC_8BIT:
190  case RZ_STRING_ENC_UTF8:
191  cmd[2] = d->subtype;
192  break;
195  cmd[2] = 'w';
196  break;
199  cmd[2] = 'W';
200  break;
201  default:
202  cmd[2] = 0;
203  }
204  rz_cons_printf("%s %" PFMT64u " @ 0x%08" PFMT64x " # %s\n",
205  cmd, size, start, pstr);
206  } else {
207  const char *enc;
208  if (d->subtype == RZ_STRING_ENC_8BIT) {
209  enc = rz_str_is_ascii(d->str) ? "ascii" : "8bit";
210  } else {
211  enc = rz_str_enc_as_string(d->subtype);
212  }
213  if (show_full || mode == RZ_OUTPUT_MODE_LONG) {
214  rz_cons_printf("0x%08" PFMT64x " %s[%" PFMT64u "] \"%s\"\n",
215  start, enc, size, pstr);
216  } else if (mode == RZ_OUTPUT_MODE_STANDARD) {
217  rz_cons_printf("%s[%" PFMT64u "] \"%s\"\n",
218  enc, size, pstr);
219  } else {
220  rz_cons_printf("\"%s\"\n", pstr);
221  }
222  }
223  break;
224  case RZ_META_TYPE_HIDE:
225  case RZ_META_TYPE_DATA:
226  if (mode == RZ_OUTPUT_MODE_RIZIN) {
227  rz_cons_printf("%s %" PFMT64u " @ 0x%08" PFMT64x "\n",
228  rz_meta_type_to_string(d->type),
229  size, start);
230  } else {
231  if (show_full || mode == RZ_OUTPUT_MODE_LONG) {
232  const char *dtype = d->type == RZ_META_TYPE_HIDE ? "hidden" : "data";
233  rz_cons_printf("0x%08" PFMT64x " %s %s %" PFMT64u "\n",
234  start, dtype,
235  rz_meta_type_to_string(d->type), size);
236  } else {
237  rz_cons_printf("%" PFMT64u "\n", size);
238  }
239  }
240  break;
241  case RZ_META_TYPE_MAGIC:
242  case RZ_META_TYPE_FORMAT:
243  if (mode == RZ_OUTPUT_MODE_RIZIN) {
244  rz_cons_printf("%s %" PFMT64u " %s @ 0x%08" PFMT64x "\n",
245  rz_meta_type_to_string(d->type),
246  size, pstr, start);
247  } else {
248  if (show_full || mode == RZ_OUTPUT_MODE_LONG) {
249  const char *dtype = d->type == RZ_META_TYPE_MAGIC ? "magic" : "format";
250  rz_cons_printf("0x%08" PFMT64x " %s %" PFMT64u " %s\n",
251  start, dtype, size, pstr);
252  } else {
253  rz_cons_printf("%" PFMT64u " %s\n", size, pstr);
254  }
255  }
256  break;
258  if (mode == RZ_OUTPUT_MODE_RIZIN) {
259  rz_cons_printf("%s %s @ 0x%08" PFMT64x "\n",
260  rz_meta_type_to_string(d->type), pstr, start);
261  } else {
262  rz_cons_printf("0x%08" PFMT64x " %s\n", start, pstr);
263  }
264  break;
265  case RZ_META_TYPE_HIGHLIGHT: {
266  ut8 r = 0, g = 0, b = 0, A = 0;
267  const char *esc = strchr(d->str, '\x1b');
268  rz_cons_rgb_parse(esc, &r, &g, &b, &A);
269  rz_cons_printf("%s rgb:%02x%02x%02x @ 0x%08" PFMT64x "\n",
270  rz_meta_type_to_string(d->type), r, g, b, start);
271  // TODO: d->size
272  } break;
273  default:
274  if (mode == RZ_OUTPUT_MODE_RIZIN) {
275  rz_cons_printf("%s %" PFMT64u " 0x%08" PFMT64x " # %s\n",
276  rz_meta_type_to_string(d->type),
277  size, start, pstr);
278  } else {
279  // TODO: use b64 here
280  rz_cons_printf("0x%08" PFMT64x " array[%" PFMT64u "] %s %s\n",
281  start, size,
282  rz_meta_type_to_string(d->type), pstr);
283  }
284  break;
285  }
286  break;
287  }
288  if (str) {
289  free(str);
290  }
291  }
292 }
#define A(x)
Definition: arc.h:165
RZ_API char * sdb_encode(const ut8 *bin, int len)
Definition: base64.c:18
static char * meta_string_escape(RzCore *core, RzAnalysisMetaItem *mi)
Definition: cmeta.c:46
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
struct @667 g
RZ_API const char * rz_meta_type_to_string(int type)
Definition: meta.c:236
RZ_API int rz_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a)
Definition: rgb.c:113
RZ_API char * rz_cons_rgb_tostring(ut8 r, ut8 g, ut8 b)
Definition: rgb.c:322
static RzSocket * s
Definition: rtr.c:28
@ RZ_META_TYPE_VARTYPE
Definition: rz_analysis.h:297
@ RZ_META_TYPE_DATA
Definition: rz_analysis.h:289
@ RZ_META_TYPE_HIGHLIGHT
Definition: rz_analysis.h:296
@ RZ_META_TYPE_HIDE
Definition: rz_analysis.h:294
@ RZ_META_TYPE_MAGIC
Definition: rz_analysis.h:293
@ RZ_META_TYPE_STRING
Definition: rz_analysis.h:291
@ RZ_META_TYPE_FORMAT
Definition: rz_analysis.h:292
RZ_API char * rz_base64_encode_dyn(const ut8 *bin, size_t sz)
Definition: ubase64.c:92
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
static RzSpace * rz_spaces_current(RzSpaces *sp)
Definition: rz_spaces.h:91
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
RZ_API const char * rz_str_enc_as_string(RzStrEnc enc)
Definition: str.c:44
@ RZ_STRING_ENC_UTF32LE
Definition: rz_str.h:24
@ RZ_STRING_ENC_8BIT
Definition: rz_str.h:20
@ RZ_STRING_ENC_UTF32BE
Definition: rz_str.h:26
@ RZ_STRING_ENC_UTF8
Definition: rz_str.h:21
@ RZ_STRING_ENC_UTF16LE
Definition: rz_str.h:23
@ RZ_STRING_ENC_UTF16BE
Definition: rz_str.h:25
RZ_API bool rz_str_is_ascii(const char *str)
Definition: str.c:1988
RZ_API void rz_str_sanitize(char *c)
Definition: str.c:1381
#define PFMT64u
Definition: rz_types.h:395
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
#define d(i)
Definition: sha256.c:44
RzSpaces meta_spaces
Definition: rz_analysis.h:601

References A, rz_core_t::analysis, b, cmd, d, free(), g, rz_analysis_t::meta_spaces, meta_string_escape(), NULL, PFMT64u, PFMT64x, pj_end(), pj_k(), pj_kb(), pj_kn(), pj_ks(), pj_o(), pj_s(), r, rz_base64_encode_dyn(), rz_cons_printf(), rz_cons_rgb_parse(), rz_cons_rgb_tostring(), RZ_META_TYPE_COMMENT, RZ_META_TYPE_DATA, RZ_META_TYPE_FORMAT, RZ_META_TYPE_HIDE, RZ_META_TYPE_HIGHLIGHT, RZ_META_TYPE_MAGIC, RZ_META_TYPE_STRING, rz_meta_type_to_string(), RZ_META_TYPE_VARTYPE, rz_name_filter(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_spaces_current(), rz_str_enc_as_string(), rz_str_escape(), rz_str_get(), rz_str_is_ascii(), rz_str_sanitize(), RZ_STRING_ENC_8BIT, RZ_STRING_ENC_UTF16BE, RZ_STRING_ENC_UTF16LE, RZ_STRING_ENC_UTF32BE, RZ_STRING_ENC_UTF32LE, RZ_STRING_ENC_UTF8, s, sdb_encode(), start, cmd_descs_generate::str, strdup(), and type.

Referenced by print_meta_list(), rz_core_meta_print_list_at(), and rz_meta_string_at_handler().

◆ rz_core_meta_print_list_all()

RZ_IPI void rz_core_meta_print_list_all ( RzCore core,
int  type,
RzCmdStateOutput state 
)

◆ rz_core_meta_print_list_at()

RZ_IPI void rz_core_meta_print_list_at ( RzCore core,
ut64  addr,
RzCmdStateOutput state 
)

Definition at line 326 of file cmeta.c.

326  {
329  if (!nodes) {
330  return;
331  }
333  void **it;
334  rz_pvector_foreach (nodes, it) {
335  RzIntervalNode *node = *it;
336  rz_core_meta_print(core, node->data, node->start, rz_meta_node_size(node), true, state);
337  }
338  rz_pvector_free(nodes);
340 }
static RzPVector * collect_nodes_at(RzAnalysis *analysis, RzAnalysisMetaType type, RZ_NULLABLE const RzSpace *space, ut64 addr)
Definition: cmeta.c:313
RZ_IPI void rz_core_meta_print(RzCore *core, RzAnalysisMetaItem *d, ut64 start, ut64 size, bool show_full, RzCmdStateOutput *state)
Definition: cmeta.c:74
@ RZ_META_TYPE_ANY
Definition: rz_analysis.h:288

References addr, rz_core_t::analysis, collect_nodes_at(), rz_interval_node_t::data, rz_analysis_t::meta_spaces, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_core_meta_print(), RZ_META_TYPE_ANY, rz_pvector_foreach, rz_pvector_free(), rz_spaces_current(), and rz_interval_node_t::start.

Referenced by rz_meta_list_at_handler().

◆ rz_core_meta_print_list_in_function()

RZ_IPI void rz_core_meta_print_list_in_function ( RzCore core,
int  type,
ut64  addr,
RzCmdStateOutput state 
)

◆ rz_core_print_dump()

RZ_IPI bool rz_core_print_dump ( RZ_NONNULL RzCore core,
RzOutputMode  mode,
ut64  addr,
ut8  n,
int  len,
RzCorePrintFormatType  format 
)

Definition at line 322 of file cprint.c.

323  {
324  char *string = rz_core_print_dump_str(core, mode, addr, n, len, format);
325  if (!string) {
326  RZ_LOG_ERROR("fail to print dump at 0x%" PFMT64x "\n", addr);
327  return false;
328  }
329  rz_cons_print(string);
330  return true;
331 }
size_t len
Definition: 6502dis.c:15
RZ_API char * rz_core_print_dump_str(RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, ut8 n, int len, RzCorePrintFormatType format)
Print dump at addr.
Definition: cprint.c:281
int n
Definition: mipsasm.c:19

References addr, len, n, PFMT64x, rz_core_print_dump_str(), and RZ_LOG_ERROR.

Referenced by rz_print_hexdump_hex_common_handler(), rz_print_hexdump_oct_handler(), and rz_print_hexdump_signed_integer_common_handler().

◆ rz_core_print_hexdiff()

RZ_IPI void rz_core_print_hexdiff ( RZ_NONNULL RzCore core,
ut64  aa,
RZ_NONNULL const ut8 _a,
ut64  ba,
RZ_NONNULL const ut8 _b,
int  len,
int  scndcol 
)

Definition at line 182 of file cprint.c.

182  {
183  char *string = rz_print_hexdiff_str(core->print, aa, _a, ba, _b, len, scndcol);
184  if (!string) {
185  RZ_LOG_ERROR("fail to print hexdiff between 0x%" PFMT64x " and 0x%" PFMT64x "\n", aa, ba);
186  return;
187  }
188  rz_cons_print(string);
189  free(string);
190 }
RZ_API RZ_OWN char * rz_print_hexdiff_str(RZ_NONNULL RzPrint *p, ut64 aa, RZ_NONNULL const ut8 *_a, ut64 ba, RZ_NONNULL const ut8 *_b, int len, int scndcol)
Print hexdump diff between _a and _b.
Definition: print.c:1172

References free(), len, PFMT64x, RZ_LOG_ERROR, and rz_print_hexdiff_str().

Referenced by rizin_compare_unified(), rz_cmd_cmp_hex_block_handler(), and rz_cmd_cmp_hex_diff_lines_handler().

◆ rz_core_print_hexdump()

RZ_IPI void rz_core_print_hexdump ( RZ_NONNULL RzCore core,
ut64  addr,
RZ_NONNULL const ut8 buf,
int  len,
int  base,
int  step,
size_t  zoomsz 
)

Definition at line 161 of file cprint.c.

162  {
163  char *string = rz_print_hexdump_str(core->print, addr, buf, len, base, step, zoomsz);
164  if (!string) {
165  RZ_LOG_ERROR("fail to print hexdump at 0x%" PFMT64x "\n", addr);
166  return;
167  }
168  rz_cons_print(string);
169  free(string);
170 }
static states step(struct re_guts *, sopno, sopno, states, int, states)
Definition: engine.c:888
RZ_API RZ_OWN char * rz_print_hexdump_str(RZ_NONNULL RzPrint *p, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
Prints a hexdump of buf at addr.
Definition: print.c:573

References addr, free(), len, PFMT64x, RZ_LOG_ERROR, rz_print_hexdump_str(), and step().

Referenced by cmd_print_op(), ds_print_meta_infos(), print_heap_chunk(), rz_cmd_heap_chunks_print_handler(), rz_core_disasm_pdi_with_buf(), rz_core_yank_print_hexdump(), rz_print_hexdump_hexless_bytes_handler(), rz_print_hexdump_hexless_words_handler(), rz_print_hexdump_sparse_handler(), rz_reg_arenas_hexdump_handler(), and search_collisions().

◆ rz_core_print_hexdump_byline()

RZ_IPI bool rz_core_print_hexdump_byline ( RZ_NONNULL RzCore core,
bool  hex_offset,
ut64  addr,
int  len,
ut8  size 
)

Definition at line 466 of file cprint.c.

466  {
467  char *string = rz_core_print_hexdump_byline_str(core, hexoffset, addr, len, size);
468  if (!string) {
469  RZ_LOG_ERROR("fail to print hexdump by line at 0x%" PFMT64x "\n", addr);
470  return false;
471  }
472  rz_cons_print(string);
473  free(string);
474  return true;
475 }
RZ_API RZ_OWN char * rz_core_print_hexdump_byline_str(RZ_NONNULL RzCore *core, bool hex_offset, ut64 addr, int len, ut8 size)
Hexdump at addr.
Definition: cprint.c:406

References addr, free(), len, PFMT64x, rz_core_print_hexdump_byline_str(), and RZ_LOG_ERROR.

Referenced by rz_print_hexdump_hexl_common_handler().

◆ rz_core_print_hexdump_diff()

RZ_IPI bool rz_core_print_hexdump_diff ( RZ_NONNULL RzCore core,
ut64  aa,
ut64  ba,
ut64  len 
)

Definition at line 219 of file cprint.c.

219  {
220  char *string = rz_core_print_hexdump_diff_str(core, aa, ba, len);
221  if (!string) {
222  RZ_LOG_ERROR("fail to print hexdump diff between 0x%" PFMT64x " and 0x%" PFMT64x "\n", aa, ba);
223  return false;
224  }
225  rz_cons_print(string);
226  free(string);
227  return true;
228 }
RZ_API char * rz_core_print_hexdump_diff_str(RZ_NONNULL RzCore *core, ut64 aa, ut64 ba, ut64 len)
Print hexdump diff between aa and ba with len.
Definition: cprint.c:195

References free(), len, PFMT64x, rz_core_print_hexdump_diff_str(), and RZ_LOG_ERROR.

◆ rz_core_print_hexdump_or_hexdiff()

RZ_IPI bool rz_core_print_hexdump_or_hexdiff ( RZ_NONNULL RzCore core,
RzOutputMode  mode,
ut64  addr,
int  len,
bool  use_comments 
)

◆ rz_core_print_jsondump()

RZ_IPI void rz_core_print_jsondump ( RZ_NONNULL RzCore core,
RZ_NONNULL const ut8 buf,
int  len,
int  wordsize 
)

Definition at line 172 of file cprint.c.

172  {
173  char *string = rz_print_jsondump_str(core->print, buf, len, wordsize);
174  if (!string) {
175  RZ_LOG_ERROR("fail to print json hexdump\n");
176  return;
177  }
178  rz_cons_print(string);
179  free(string);
180 }
RZ_API RZ_OWN char * rz_print_jsondump_str(RZ_NONNULL RzPrint *p, RZ_NONNULL const ut8 *buf, int len, int wordsize)
Print dump in json format.
Definition: print.c:1583

References free(), len, RZ_LOG_ERROR, and rz_print_jsondump_str().

◆ rz_core_reg_flags_candidates()

RZ_IPI RzList* rz_core_reg_flags_candidates ( RzCore core,
RzReg reg 
)

Construct the list of registers that should be applied as flags by default (e.g. because their size matches the pointer size)

Definition at line 60 of file creg.c.

60  {
62  if (!l) {
63  return NULL;
64  }
66  RzList *ret = rz_list_new();
67  if (!ret) {
68  return NULL;
69  }
72  RzRegItem *item;
73  rz_list_foreach (l, iter, item) {
74  if (size != 0 && size != item->size && item != pc) {
75  continue;
76  }
77  rz_list_push(ret, item);
78  }
79  return ret;
80 }
RZ_API int rz_analysis_get_address_bits(RzAnalysis *analysis)
The actual size of an address in bits.
Definition: analysis.c:303
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API RzRegItem * rz_reg_get_by_role(RzReg *reg, RzRegisterId role)
Definition: reg.c:154
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120

References rz_core_t::analysis, NULL, pc, reg, rz_analysis_get_address_bits(), rz_list_new(), rz_list_push(), rz_reg_get_by_role(), rz_reg_get_list(), RZ_REG_NAME_PC, RZ_REG_TYPE_GPR, and rz_reg_item_t::size.

Referenced by regs_to_flags(), and rz_reg_flags_handler().

◆ rz_core_reg_print_diff()

RZ_IPI void rz_core_reg_print_diff ( RzReg reg,
RzList items 
)

Print registers that have changed since the last step (drd/ard)

Definition at line 116 of file creg.c.

116  {
117  RzListIter *iter;
118  RzRegItem *item;
119  rz_list_foreach (items, iter, item) {
120  ut64 newval = rz_reg_get_value(reg, item);
121  rz_reg_arena_swap(reg, false);
122  ut64 oldval = rz_reg_get_value(reg, item);
123  rz_reg_arena_swap(reg, false);
124  ut64 delta = newval - oldval;
125  if (delta) {
127  "%s = 0x%" PFMT64x " was 0x%" PFMT64x " delta 0x%" PFMT64x "\n",
128  item->name, newval, oldval, delta);
129  }
130  }
131 }
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
char * name
Definition: rz_reg.h:118

References delta, rz_reg_item_t::name, PFMT64x, reg, rz_cons_printf(), rz_reg_arena_swap(), rz_reg_get_value(), and ut64().

Referenced by rz_core_debug_print_status(), and rz_regs_diff_handler().

◆ rz_core_seek_bb_instruction()

RZ_IPI bool rz_core_seek_bb_instruction ( RzCore core,
int  index 
)

Definition at line 453 of file seek.c.

453  {
455  if (!bb) {
456  RZ_LOG_ERROR("Can't find a basic block for 0x%08" PFMT64x "\n", core->offset);
457  return false;
458  }
459  // handle negative indices
460  if (index < 0) {
461  index = bb->ninstr + index;
462  }
463  if (!(index >= 0 && index < bb->ninstr)) {
464  RZ_LOG_ERROR("The current basic block has %d instructions\n", bb->ninstr);
465  return false;
466  }
467  ut64 inst_addr = rz_analysis_block_get_op_addr(bb, index);
468  return rz_core_seek(core, inst_addr, true);
469 }

References rz_core_t::analysis, rz_analysis_bb_t::ninstr, rz_core_t::offset, PFMT64x, rz_analysis_block_get_op_addr(), rz_analysis_find_most_relevant_block_in(), rz_core_seek(), RZ_LOG_ERROR, and ut64().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_core_cmd_subst_i(), and rz_core_visual_graph().

◆ rz_core_seek_opcode()

RZ_IPI int rz_core_seek_opcode ( RzCore core,
int  numinstr,
bool  silent 
)

Definition at line 86 of file cmd_seek.c.

86  {
87  int val = (n < 0)
90  core->num->value = val;
91  return val;
92 }
RZ_IPI int rz_core_seek_opcode_backward(RzCore *core, int numinstr, bool silent)
Definition: cmd_seek.c:27
RZ_IPI int rz_core_seek_opcode_forward(RzCore *core, int n, bool silent)
Definition: cmd_seek.c:65
ut64 value
Definition: rz_num.h:63

References n, rz_core_t::num, rz_core_seek_opcode_backward(), rz_core_seek_opcode_forward(), test-lz4-list::silent, val, and rz_num_t::value.

Referenced by cmd_seek_opcode(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), graphNodeMove(), rz_core_cmd_lastcmd_repeat(), rz_core_cmd_subst_i(), and rz_core_visual_graph().

◆ rz_core_seek_opcode_forward()

RZ_IPI int rz_core_seek_opcode_forward ( RzCore core,
int  n,
bool  silent 
)

Definition at line 65 of file cmd_seek.c.

65  {
66  // N forward instructions
67  int i, ret, val = 0;
68  if (!silent) {
69  rz_core_seek_mark(core);
70  }
71  for (val = i = 0; i < n; i++) {
73  ret = rz_analysis_op(core->analysis, &op, core->offset, core->block,
75  if (ret < 1) {
76  ret = 1;
77  }
78  rz_core_seek_delta(core, ret, false);
80  val += ret;
81  }
82  rz_core_seek_save(core);
83  return val;
84 }
ut8 op
Definition: 6502dis.c:13
RZ_API bool rz_core_seek_delta(RzCore *core, st64 delta, bool save)
Seek relative to current offset and optionally save the current offset in seek history.
Definition: seek.c:152
RZ_API bool rz_core_seek_mark(RzCore *core)
Mark current state (offset+cursor) as the next state to save in history.
Definition: seek.c:57
RZ_API bool rz_core_seek_save(RzCore *core)
Save last marked position, if any, in the seek history.
Definition: seek.c:87
ut8 * block
Definition: rz_core.h:305

References rz_core_t::analysis, rz_core_t::block, rz_core_t::blocksize, i, n, rz_core_t::offset, op, rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_BASIC, rz_core_seek_delta(), rz_core_seek_mark(), rz_core_seek_save(), test-lz4-list::silent, and val.

Referenced by rz_core_seek_opcode().

◆ rz_core_seek_to_register()

RZ_IPI bool rz_core_seek_to_register ( RzCore core,
const char *  input,
bool  is_silent 
)

Definition at line 22 of file cmd_seek.c.

22  {
24  return rz_core_seek_opt(core, off, true, !is_silent);
25 }
RZ_API ut64 rz_core_reg_getv_by_role_or_name(RzCore *core, const char *name)
rz_reg_getv_by_role_or_name() on rz_core_reg_default()
Definition: creg.c:24
RZ_API bool rz_core_seek_opt(RzCore *core, ut64 addr, bool rb, bool save)
Seek to addr and optionally save the current offset in seek history.
Definition: seek.c:141

References off, regname(), rz_core_reg_getv_by_role_or_name(), rz_core_seek_opt(), and ut64().

Referenced by agraph_refresh(), rz_core_cmd_lastcmd_repeat(), rz_core_dbg_follow_seek_register(), rz_core_esil_step(), rz_core_file_reopen(), rz_core_file_reopen_debug(), rz_core_file_reopen_remote_debug(), rz_core_setup_debugger(), rz_core_visual_graph(), and rz_seek_register_handler().

◆ rz_core_spaces_print()

RZ_IPI void rz_core_spaces_print ( RzCore core,
RzSpaces spaces,
RzCmdStateOutput state 
)

Definition at line 9 of file cmeta.c.

9  {
10  const RzSpace *cur = rz_spaces_current(spaces);
12  RzSpace *s;
13  PJ *pj = state->d.pj;
14  RzSpaceIter it;
15  rz_spaces_foreach(spaces, it, s) {
16  int count = rz_spaces_count(spaces, s->name);
17  switch (state->mode) {
19  pj_o(pj);
20  pj_ks(pj, "name", s->name);
21  pj_ki(pj, "count", count);
22  pj_kb(pj, "selected", cur == s);
23  pj_end(pj);
24  break;
26  rz_cons_printf("%s\n", s->name);
27  break;
29  rz_cons_printf("%s %s\n", spaces->name, s->name);
30  break;
32  rz_cons_printf("%5d %c %s\n", count,
33  (!cur || cur == s) ? '*' : '.', s->name);
34  break;
35  default:
37  break;
38  }
39  }
42  rz_cons_printf("%s %s # current\n", spaces->name, rz_spaces_current_name(spaces));
43  }
44 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
const char * spaces(int count)
#define rz_spaces_foreach(sp, it, s)
Definition: rz_spaces.h:105
static const char * rz_spaces_current_name(RzSpaces *sp)
Definition: rz_spaces.h:95
RZ_API int rz_spaces_count(RzSpaces *sp, const char *name)
Definition: spaces.c:167

References count, pj_end(), pj_kb(), pj_ki(), pj_ks(), pj_o(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_spaces_count(), rz_spaces_current(), rz_spaces_current_name(), rz_spaces_foreach, rz_warn_if_reached, s, and spaces().

Referenced by rz_flag_space_list_handler(), and rz_meta_space_list_handler().

◆ rz_core_static_debug_stop()

◆ rz_core_types_calling_conventions_print()

RZ_IPI void rz_core_types_calling_conventions_print ( RzCore core,
RzOutputMode  mode 
)

Definition at line 19 of file ctypes.c.

19  {
22  const char *cc;
23  switch (mode) {
25  rz_list_foreach (list, iter, cc) {
26  rz_cons_println(cc);
27  }
28  } break;
29  case RZ_OUTPUT_MODE_JSON: {
30  PJ *pj = pj_new();
31  pj_a(pj);
32  rz_list_foreach (list, iter, cc) {
33  rz_core_analysis_cc_print(core, cc, pj);
34  }
35  pj_end(pj);
36  rz_cons_printf("%s\n", pj_string(pj));
37  pj_free(pj);
38  } break;
39  case RZ_OUTPUT_MODE_LONG: {
40  rz_list_foreach (list, iter, cc) {
41  char *ccexpr = rz_analysis_cc_get(core->analysis, cc);
42  rz_cons_printf("%s\n", ccexpr);
43  free(ccexpr);
44  }
45  } break;
46  case RZ_OUTPUT_MODE_RIZIN: {
47  rz_list_foreach (list, iter, cc) {
48  char *ccexpr = rz_analysis_cc_get(core->analysis, cc);
49  rz_cons_printf("tcc \"%s\"\n", ccexpr);
50  free(ccexpr);
51  }
52  } break;
53  case RZ_OUTPUT_MODE_SDB:
54  rz_core_kuery_print(core, "analysis/cc/*");
55  break;
56  default:
58  break;
59  }
61 }
RZ_IPI void rz_core_analysis_cc_print(RzCore *core, RZ_NONNULL const char *cc, RZ_NULLABLE PJ *pj)
Print Calling Convention info.
Definition: canalysis.c:6686
RZ_API char * rz_analysis_cc_get(RzAnalysis *analysis, const char *name)
Definition: cc.c:75
RZ_API RzList * rz_analysis_calling_conventions(RzAnalysis *analysis)
Definition: cc.c:226
RZ_IPI void rz_core_kuery_print(RzCore *core, const char *k)
Definition: cmd.c:634
@ RZ_OUTPUT_MODE_SDB
Definition: rz_types.h:43

References rz_core_t::analysis, free(), list(), pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_analysis_calling_conventions(), rz_analysis_cc_get(), rz_cons_printf(), rz_cons_println(), rz_core_analysis_cc_print(), rz_core_kuery_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_SDB, RZ_OUTPUT_MODE_STANDARD, and rz_warn_if_reached.

Referenced by cb_analysiscc(), cb_analysissyscc(), rz_analysis_function_cc_list_handler(), and rz_type_cc_list_handler().

◆ rz_core_types_enum_as_c()

RZ_IPI RZ_OWN char* rz_core_types_enum_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

Definition at line 123 of file ctypes.c.

123  {
124  rz_return_val_if_fail(btype, NULL);
126 
127  unsigned int multiline_opt = 0;
128  if (multiline) {
129  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
130  }
132 }
@ RZ_BASE_TYPE_KIND_ENUM
Definition: rz_type.h:75
RzBaseTypeKind kind
Definition: rz_type.h:115

References rz_base_type_t::kind, NULL, RZ_BASE_TYPE_KIND_ENUM, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, and RZ_TYPE_PRINT_MULTILINE.

Referenced by rz_core_types_enum_as_c_all(), rz_type_enum_c_handler(), and rz_type_enum_c_nl_handler().

◆ rz_core_types_enum_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_enum_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 134 of file ctypes.c.

134  {
136  RzListIter *it;
137  RzBaseType *btype;
138  RzStrBuf *buf = rz_strbuf_new("");
139  rz_list_foreach (enumlist, it, btype) {
140  char *str = rz_core_types_enum_as_c(typedb, btype, multiline);
141  if (str) {
143  }
144  free(str);
145  }
146  rz_list_free(enumlist);
147  return rz_strbuf_drain(buf);
148 }
RZ_API RZ_OWN RzList * rz_type_db_get_base_types_of_kind(const RzTypeDB *typedb, RzBaseTypeKind kind)
Returns the list of all basic types of the chosen kind.
Definition: base.c:100
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:123

References free(), RZ_BASE_TYPE_KIND_ENUM, rz_core_types_enum_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_enum_c_handler(), and rz_type_enum_c_nl_handler().

◆ rz_core_types_enum_print()

RZ_IPI void rz_core_types_enum_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 65 of file ctypes.c.

65  {
66  rz_return_if_fail(core && btype);
68 
69  switch (mode) {
70  case RZ_OUTPUT_MODE_JSON: {
72  pj_o(pj);
73  if (btype && !rz_vector_empty(&btype->enum_data.cases)) {
74  pj_ks(pj, "name", btype->name);
75  pj_k(pj, "values");
76  pj_o(pj);
77  RzTypeEnumCase *cas;
78  rz_vector_foreach(&btype->enum_data.cases, cas) {
79  pj_kn(pj, cas->name, cas->val);
80  }
81  pj_end(pj);
82  }
83  pj_end(pj);
84  break;
85  }
87  if (btype && !rz_vector_empty(&btype->enum_data.cases)) {
88  RzTypeEnumCase *cas;
89  rz_vector_foreach(&btype->enum_data.cases, cas) {
90  rz_cons_printf("%s = 0x%" PFMT64x "\n", cas->name, cas->val);
91  }
92  }
93  break;
94  }
96  rz_cons_println(btype->name);
97  break;
98  default:
100  break;
101  }
102 }
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
static bool rz_vector_empty(const RzVector *vec)
Definition: rz_vector.h:74
RzVector cases
Definition: rz_type.h:108
char * name
Definition: rz_type.h:112
RzBaseTypeEnum enum_data
Definition: rz_type.h:119

References rz_base_type_enum_t::cases, rz_base_type_t::enum_data, rz_base_type_t::kind, rz_type_enum_case_t::name, rz_base_type_t::name, PFMT64x, pj_end(), pj_k(), pj_kn(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_ENUM, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, and rz_type_enum_case_t::val.

Referenced by rz_core_types_enum_print_all(), and rz_type_list_enum_handler().

◆ rz_core_types_enum_print_all()

RZ_IPI void rz_core_types_enum_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 104 of file ctypes.c.

104  {
106  RzListIter *it;
107  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
108  if (mode == RZ_OUTPUT_MODE_JSON) {
109  pj_a(pj);
110  }
111  RzBaseType *btype;
112  rz_list_foreach (enumlist, it, btype) {
113  rz_core_types_enum_print(core, btype, mode, pj);
114  }
115  rz_list_free(enumlist);
116  if (mode == RZ_OUTPUT_MODE_JSON) {
117  pj_end(pj);
119  pj_free(pj);
120  }
121 }
RZ_IPI void rz_core_types_enum_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:65

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_ENUM, rz_cons_println(), rz_core_types_enum_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_enum_handler().

◆ rz_core_types_function_noreturn_print()

RZ_IPI void rz_core_types_function_noreturn_print ( RzCore core,
RzOutputMode  mode 
)

Definition at line 553 of file ctypes.c.

553  {
555  switch (mode) {
556  case RZ_OUTPUT_MODE_JSON:
557  nonreturn_print_json(core, noretl);
558  break;
559  default:
560  nonreturn_print(core, noretl);
561  break;
562  }
563  rz_list_free(noretl);
564 }
static bool nonreturn_print(RzCore *core, RzList *noretl)
Definition: ctypes.c:530
static bool nonreturn_print_json(RzCore *core, RzList *noretl)
Definition: ctypes.c:539
RZ_API RZ_OWN RzList * rz_type_noreturn_function_names(RzTypeDB *typedb)
Returns the list of all noreturn function type names.
Definition: function.c:588

References rz_core_t::analysis, nonreturn_print(), nonreturn_print_json(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_noreturn_function_names(), and rz_analysis_t::typedb.

Referenced by rz_type_list_noreturn_handler().

◆ rz_core_types_function_print()

RZ_IPI void rz_core_types_function_print ( RzTypeDB typedb,
const char *  function,
RzOutputMode  mode,
PJ pj 
)

Definition at line 472 of file ctypes.c.

472  {
473  rz_return_if_fail(function);
474  RzCallable *callable = rz_type_func_get(typedb, function);
475  if (!callable) {
476  return;
477  }
478  char *ret = callable->ret ? rz_type_as_string(typedb, callable->ret) : NULL;
479  void **it;
480  switch (mode) {
481  case RZ_OUTPUT_MODE_JSON: {
482  rz_return_if_fail(pj);
483  pj_o(pj);
484  pj_ks(pj, "name", function);
485  pj_ks(pj, "ret", ret);
486  pj_k(pj, "args");
487  pj_a(pj);
488  rz_pvector_foreach (callable->args, it) {
489  RzCallableArg *arg = (RzCallableArg *)*it;
490  char *typestr = rz_type_as_string(typedb, arg->type);
491  pj_o(pj);
492  pj_ks(pj, "type", rz_str_get_null(typestr));
493  pj_ks(pj, "name", rz_str_get_null(arg->name));
494  pj_end(pj);
495  free(typestr);
496  }
497  pj_end(pj);
498  pj_end(pj);
499  } break;
500  default: {
501  char *str = rz_type_callable_as_string(typedb, callable);
502  rz_cons_printf("%s;\n", str);
503  free(str);
504  } break;
505  }
506  free(ret);
507 }
RzPVector * args
optional for the time being
Definition: rz_type.h:149
RZ_NULLABLE RzType * ret
Definition: rz_type.h:148
RZ_API RZ_BORROW RzCallable * rz_type_func_get(RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the RzCallable from the database by name.
Definition: function.c:162
RZ_API RZ_OWN char * rz_type_callable_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzCallable *callable)
Returns the callable C representation.
Definition: function.c:487

References rz_callable_at::args, free(), arg::name, NULL, pj_a(), pj_end(), pj_k(), pj_ks(), pj_o(), rz_callable_at::ret, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, rz_pvector_foreach, rz_return_if_fail, rz_str_get_null(), rz_type_as_string(), rz_type_callable_as_string(), rz_type_func_get(), and cmd_descs_generate::str.

Referenced by rz_core_types_function_print_all(), and rz_type_list_function_handler().

◆ rz_core_types_function_print_all()

RZ_IPI void rz_core_types_function_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 509 of file ctypes.c.

509  {
510  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
511  if (mode == RZ_OUTPUT_MODE_JSON) {
512  pj_a(pj);
513  }
515  RzListIter *iter;
516  char *name;
517  rz_list_foreach (l, iter, name) {
519  }
520  rz_list_free(l);
521  if (mode == RZ_OUTPUT_MODE_JSON) {
522  pj_end(pj);
524  pj_free(pj);
525  }
526 }
RZ_IPI void rz_core_types_function_print(RzTypeDB *typedb, const char *function, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:472
const char * name
Definition: op.c:541
RZ_API RZ_OWN RzList * rz_type_function_names(RzTypeDB *typedb)
Returns the list of all function type names.
Definition: function.c:567

References rz_core_t::analysis, name, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_cons_println(), rz_core_types_function_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_function_names(), and rz_analysis_t::typedb.

Referenced by rz_type_list_function_handler().

◆ rz_core_types_link_print()

RZ_IPI void rz_core_types_link_print ( RzCore core,
RzType type,
ut64  addr,
RzOutputMode  mode,
PJ pj 
)

Definition at line 879 of file ctypes.c.

879  {
881  char *typestr = rz_type_as_string(core->analysis->typedb, type);
882  if (!typestr) {
883  return;
884  }
885  switch (mode) {
886  case RZ_OUTPUT_MODE_JSON: {
887  rz_return_if_fail(pj);
888  pj_o(pj);
889  char *saddr = rz_str_newf("0x%08" PFMT64x, addr);
890  pj_ks(pj, saddr, typestr);
891  pj_end(pj);
892  free(saddr);
893  break;
894  }
896  rz_cons_printf("0x%08" PFMT64x " = %s\n", addr, typestr);
897  break;
899  rz_cons_printf("tl \"%s\" 0x%" PFMT64x "\n", typestr, addr);
900  break;
901  case RZ_OUTPUT_MODE_LONG: {
902  char *fmt = rz_type_as_format(core->analysis->typedb, type);
903  if (!fmt) {
904  eprintf("Can't fint type %s", typestr);
905  }
906  rz_cons_printf("(%s)\n", typestr);
907  rz_core_cmdf(core, "pf %s @ 0x%" PFMT64x "\n", fmt, addr);
908  free(fmt);
909  break;
910  }
911  default:
913  break;
914  }
915  free(typestr);
916 }
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413

References addr, rz_core_t::analysis, eprintf, free(), PFMT64x, pj_end(), pj_ks(), pj_o(), rz_cons_printf(), rz_core_cmdf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_str_newf(), rz_type_as_format(), rz_type_as_string(), rz_warn_if_reached, type, and rz_analysis_t::typedb.

Referenced by rz_core_types_link_show(), and typelink_print_cb().

◆ rz_core_types_link_print_all()

RZ_IPI void rz_core_types_link_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 931 of file ctypes.c.

931  {
932  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
933  if (mode == RZ_OUTPUT_MODE_JSON) {
934  pj_a(pj);
935  }
936  struct coremodepj c = { core, mode, pj };
937  ht_up_foreach(core->analysis->type_links, typelink_print_cb, &c);
938  if (mode == RZ_OUTPUT_MODE_JSON) {
939  pj_end(pj);
941  pj_free(pj);
942  }
943 }
static bool typelink_print_cb(void *user, ut64 k, const void *v)
Definition: ctypes.c:924
RzCore * core
Definition: ctypes.c:919
PJ * pj
Definition: ctypes.c:921
HtUP * type_links
Definition: rz_analysis.h:603

References rz_core_t::analysis, c, coremodepj::core, NULL, coremodepj::pj, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, rz_analysis_t::type_links, and typelink_print_cb().

Referenced by rz_type_link_handler().

◆ rz_core_types_link_show()

RZ_IPI void rz_core_types_link_show ( RzCore core,
ut64  addr 
)

Definition at line 975 of file ctypes.c.

975  {
977  if (link) {
979  }
980 }
RZ_IPI void rz_core_types_link_print(RzCore *core, RzType *type, ut64 addr, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:879
static static fork const void static count static fd link
Definition: sflib.h:33

References addr, rz_core_t::analysis, coremodepj::core, link, NULL, rz_analysis_type_link_at(), rz_core_types_link_print(), and RZ_OUTPUT_MODE_LONG.

Referenced by rz_type_link_show_handler().

◆ rz_core_types_print_all()

RZ_IPI void rz_core_types_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 984 of file ctypes.c.

984  {
985  RzListIter *it;
986  RzBaseType *btype;
988  switch (mode) {
989  case RZ_OUTPUT_MODE_JSON: {
990  PJ *pj = pj_new();
991  if (!pj) {
992  return;
993  }
994  pj_a(pj);
995  rz_list_foreach (types, it, btype) {
996  pj_o(pj);
997  // rz_str_trim(format_s);
998  pj_ks(pj, "type", btype->name);
999  pj_ki(pj, "size", btype->size);
1000  // pj_ks(pj, "format", format_s);
1001  pj_end(pj);
1002  }
1003  pj_end(pj);
1005  pj_free(pj);
1006  break;
1007  }
1009  rz_list_foreach (types, it, btype) {
1010  rz_cons_println(btype->name);
1011  }
1012  break;
1013  case RZ_OUTPUT_MODE_RIZIN:
1014  rz_list_foreach (types, it, btype) {
1015  char *fmt = rz_type_format(core->analysis->typedb, btype->name);
1016  if (fmt) {
1017  rz_cons_printf("pf.%s %s\n", btype->name, fmt);
1018  free(fmt);
1019  }
1020  }
1021  break;
1022  default:
1024  break;
1025  }
1027 }
RZ_API RZ_OWN RzList * rz_type_db_get_base_types(const RzTypeDB *typedb)
Returns the list of all basic types.
Definition: base.c:120
RZ_API RZ_OWN char * rz_type_format(RZ_NONNULL const RzTypeDB *typedb, RZ_NONNULL const char *name)
Represents the RzBaseType as a pf format string.
Definition: format.c:2965
insn_type_descr_t types[]
Definition: or1k_disas.c:7

References rz_core_t::analysis, coremodepj::core, free(), rz_base_type_t::name, coremodepj::pj, pj_a(), pj_end(), pj_free(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_cons_printf(), rz_cons_println(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_type_db_get_base_types(), rz_type_format(), rz_warn_if_reached, rz_base_type_t::size, rz_analysis_t::typedb, and types.

Referenced by rz_type_handler().

◆ rz_core_types_show_format()

RZ_IPI void rz_core_types_show_format ( RzCore core,
const char *  name,
RzOutputMode  mode 
)

Definition at line 568 of file ctypes.c.

568  {
569  char *fmt = rz_type_format(core->analysis->typedb, name);
570  if (fmt) {
571  switch (mode) {
572  case RZ_OUTPUT_MODE_JSON: {
573  PJ *pj = pj_new();
574  if (!pj) {
575  free(fmt);
576  return;
577  }
578  pj_o(pj);
579  pj_ks(pj, "name", name);
580  pj_ks(pj, "format", fmt);
581  pj_end(pj);
582  rz_cons_printf("%s", pj_string(pj));
583  pj_free(pj);
584  } break;
585  case RZ_OUTPUT_MODE_RIZIN: {
586  rz_cons_printf("pf.%s %s\n", name, fmt);
587  } break;
589  // FIXME: Not really a standard format
590  // We should think about better representation by default here
591  rz_cons_printf("pf %s\n", fmt);
592  } break;
593  default:
594  break;
595  }
596  free(fmt);
597  } else {
598  eprintf("Cannot find '%s' type\n", name);
599  }
600 }

References rz_core_t::analysis, eprintf, free(), pj_end(), pj_free(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_type_format(), and rz_analysis_t::typedb.

Referenced by rz_core_types_struct_print_format_all(), rz_core_types_union_print_format_all(), rz_type_handler(), rz_type_list_structure_handler(), and rz_type_list_union_handler().

◆ rz_core_types_struct_as_c()

RZ_IPI RZ_OWN char* rz_core_types_struct_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

◆ rz_core_types_struct_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_struct_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 320 of file ctypes.c.

320  {
322  RzListIter *it;
323  RzBaseType *btype;
324  RzStrBuf *buf = rz_strbuf_new("");
325  rz_list_foreach (structlist, it, btype) {
326  char *str = rz_core_types_struct_as_c(typedb, btype, multiline);
327  if (str) {
329  }
330  free(str);
331  }
332  rz_list_free(structlist);
333  return rz_strbuf_drain(buf);
334 }
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:312

References free(), RZ_BASE_TYPE_KIND_STRUCT, rz_core_types_struct_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_structure_c_handler(), and rz_type_structure_c_nl_handler().

◆ rz_core_types_struct_print()

RZ_IPI void rz_core_types_struct_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 246 of file ctypes.c.

246  {
247  rz_return_if_fail(core && btype);
249 
250  switch (mode) {
251  case RZ_OUTPUT_MODE_JSON: {
252  rz_return_if_fail(pj);
253  pj_o(pj);
254  pj_ks(pj, "name", btype->name);
255  pj_k(pj, "members");
256  pj_o(pj);
257  RzTypeStructMember *memb;
258  rz_vector_foreach(&btype->struct_data.members, memb) {
259  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
260  pj_ks(pj, memb->name, mtype);
261  free(mtype);
262  }
263  pj_end(pj);
264  pj_end(pj);
265  break;
266  }
267  case RZ_OUTPUT_MODE_LONG: {
268  rz_cons_printf("struct %s:\n", btype->name);
269  if (btype && !rz_vector_empty(&btype->union_data.members)) {
270  RzTypeStructMember *memb;
271  ut64 offset = 0;
272  rz_vector_foreach(&btype->struct_data.members, memb) {
273  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
274  ut64 size = rz_type_db_get_bitsize(core->analysis->typedb, memb->type) / 8;
275  rz_cons_printf("\t%s: %s (size = %" PFMT64d ", offset = %" PFMT64d ")\n",
276  memb->name, mtype, size, offset);
277  offset += size;
278  free(mtype);
279  }
280  }
281  break;
282  }
285  rz_cons_println(btype->name);
286  break;
287  default:
289  break;
290  }
291 }
#define PFMT64d
Definition: rz_types.h:394
RzBaseTypeStruct struct_data
Definition: rz_type.h:118
RzBaseTypeUnion union_data
Definition: rz_type.h:120
RzVector members
Definition: rz_type.h:104
RZ_API ut64 rz_type_db_get_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Returns the type size in bits (target dependent)
Definition: type.c:779

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_struct_t::members, rz_base_type_union_t::members, rz_type_struct_member_t::name, rz_base_type_t::name, PFMT64d, pj_end(), pj_k(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_STRUCT, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_type_db_get_bitsize(), rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, rz_base_type_t::struct_data, rz_type_struct_member_t::type, rz_analysis_t::typedb, rz_base_type_t::union_data, and ut64().

Referenced by rz_core_types_struct_print_all(), and rz_type_list_structure_handler().

◆ rz_core_types_struct_print_all()

RZ_IPI void rz_core_types_struct_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 293 of file ctypes.c.

293  {
295  RzListIter *it;
296  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
297  if (mode == RZ_OUTPUT_MODE_JSON) {
298  pj_a(pj);
299  }
300  RzBaseType *btype;
301  rz_list_foreach (structlist, it, btype) {
302  rz_core_types_struct_print(core, btype, mode, pj);
303  }
304  rz_list_free(structlist);
305  if (mode == RZ_OUTPUT_MODE_JSON) {
306  pj_end(pj);
308  pj_free(pj);
309  }
310 }
RZ_IPI void rz_core_types_struct_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:246

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_STRUCT, rz_cons_println(), rz_core_types_struct_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_structure_handler().

◆ rz_core_types_struct_print_format_all()

RZ_IPI void rz_core_types_struct_print_format_all ( RzCore core)

Definition at line 602 of file ctypes.c.

602  {
603  RzTypeDB *typedb = core->analysis->typedb;
605  RzListIter *it;
606  RzBaseType *btype;
607  rz_list_foreach (structlist, it, btype) {
609  }
610  rz_list_free(structlist);
611 }
RZ_IPI void rz_core_types_show_format(RzCore *core, const char *name, RzOutputMode mode)
Definition: ctypes.c:568

References rz_core_t::analysis, rz_base_type_t::name, RZ_BASE_TYPE_KIND_STRUCT, rz_core_types_show_format(), rz_list_free(), RZ_OUTPUT_MODE_RIZIN, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_structure_handler().

◆ rz_core_types_typedef_as_c()

◆ rz_core_types_typedef_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_typedef_as_c_all ( RzTypeDB typedb)

Definition at line 392 of file ctypes.c.

392  {
394  RzListIter *it;
395  RzBaseType *btype;
396  RzStrBuf *buf = rz_strbuf_new("");
397  rz_list_foreach (typedeflist, it, btype) {
398  char *str = rz_core_types_typedef_as_c(typedb, btype);
399  if (str) {
401  }
402  free(str);
403  }
404  rz_list_free(typedeflist);
405  return rz_strbuf_drain(buf);
406 }
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c(RzTypeDB *typedb, const RzBaseType *btype)
Definition: ctypes.c:385

References free(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_core_types_typedef_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), and rz_type_typedef_c_handler().

◆ rz_core_types_typedef_print()

RZ_IPI void rz_core_types_typedef_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 338 of file ctypes.c.

338  {
339  rz_return_if_fail(core && btype);
341 
342  char *typestr = rz_type_as_string(core->analysis->typedb, btype->type);
343  switch (mode) {
344  case RZ_OUTPUT_MODE_JSON: {
345  rz_return_if_fail(pj);
346  pj_o(pj);
347  pj_ks(pj, "name", btype->name);
348  pj_ks(pj, "type", typestr);
349  pj_end(pj);
350  break;
351  }
353  rz_cons_printf("%s = %s\n", btype->name, typestr);
354  break;
355  }
357  rz_cons_println(btype->name);
358  break;
359  default:
361  break;
362  }
363  free(typestr);
364 }
RzType * type
Definition: rz_type.h:113

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_t::name, pj_end(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_warn_if_reached, rz_base_type_t::type, and rz_analysis_t::typedb.

Referenced by rz_core_types_typedef_print_all(), and rz_type_list_typedef_handler().

◆ rz_core_types_typedef_print_all()

RZ_IPI void rz_core_types_typedef_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 366 of file ctypes.c.

366  {
368  RzListIter *it;
369  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
370  if (mode == RZ_OUTPUT_MODE_JSON) {
371  pj_a(pj);
372  }
373  RzBaseType *btype;
374  rz_list_foreach (typedeflist, it, btype) {
375  rz_core_types_typedef_print(core, btype, mode, pj);
376  }
377  rz_list_free(typedeflist);
378  if (mode == RZ_OUTPUT_MODE_JSON) {
379  pj_end(pj);
381  pj_free(pj);
382  }
383 }
RZ_IPI void rz_core_types_typedef_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:338

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_cons_println(), rz_core_types_typedef_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_typedef_handler().

◆ rz_core_types_union_as_c()

RZ_IPI RZ_OWN char* rz_core_types_union_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

Definition at line 217 of file ctypes.c.

217  {
218  rz_return_val_if_fail(btype, NULL);
220 
221  unsigned int multiline_opt = 0;
222  if (multiline) {
223  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
224  }
226 }
@ RZ_BASE_TYPE_KIND_UNION
Definition: rz_type.h:74

References rz_base_type_t::kind, NULL, RZ_BASE_TYPE_KIND_UNION, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, and RZ_TYPE_PRINT_MULTILINE.

Referenced by rz_core_types_union_as_c_all(), rz_type_union_c_handler(), and rz_type_union_c_nl_handler().

◆ rz_core_types_union_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_union_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 228 of file ctypes.c.

228  {
230  RzListIter *it;
231  RzBaseType *btype;
232  RzStrBuf *buf = rz_strbuf_new("");
233  rz_list_foreach (unionlist, it, btype) {
234  char *str = rz_core_types_union_as_c(typedb, btype, multiline);
235  if (str) {
237  }
238  free(str);
239  }
240  rz_list_free(unionlist);
241  return rz_strbuf_drain(buf);
242 }
RZ_IPI RZ_OWN char * rz_core_types_union_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:217

References free(), RZ_BASE_TYPE_KIND_UNION, rz_core_types_union_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_union_c_handler(), and rz_type_union_c_nl_handler().

◆ rz_core_types_union_print()

RZ_IPI void rz_core_types_union_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 152 of file ctypes.c.

152  {
153  rz_return_if_fail(core && btype);
155 
156  switch (mode) {
157  case RZ_OUTPUT_MODE_JSON: {
158  rz_return_if_fail(pj);
159  pj_o(pj);
160  if (btype && !rz_vector_empty(&btype->union_data.members)) {
161  pj_ks(pj, "name", btype->name);
162  pj_k(pj, "members");
163  pj_o(pj);
164  RzTypeUnionMember *memb;
165  rz_vector_foreach(&btype->union_data.members, memb) {
166  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
167  pj_ks(pj, memb->name, mtype);
168  free(mtype);
169  }
170  pj_end(pj);
171  }
172  pj_end(pj);
173  break;
174  }
175  case RZ_OUTPUT_MODE_LONG: {
176  rz_cons_printf("union %s:\n", btype->name);
177  if (btype && !rz_vector_empty(&btype->union_data.members)) {
178  RzTypeUnionMember *memb;
179  rz_vector_foreach(&btype->union_data.members, memb) {
180  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
181  ut64 size = rz_type_db_get_bitsize(core->analysis->typedb, memb->type) / 8;
182  rz_cons_printf("\t%s: %s (size = %" PFMT64d ")\n", memb->name, mtype, size);
183  free(mtype);
184  }
185  }
186  break;
187  }
190  rz_cons_println(btype->name);
191  break;
192  default:
194  break;
195  }
196 }

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_union_t::members, rz_type_union_member_t::name, rz_base_type_t::name, PFMT64d, pj_end(), pj_k(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_UNION, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_type_db_get_bitsize(), rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, rz_type_union_member_t::type, rz_analysis_t::typedb, rz_base_type_t::union_data, and ut64().

Referenced by rz_core_types_union_print_all(), and rz_type_list_union_handler().

◆ rz_core_types_union_print_all()

RZ_IPI void rz_core_types_union_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 198 of file ctypes.c.

198  {
200  RzListIter *it;
201  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
202  if (mode == RZ_OUTPUT_MODE_JSON) {
203  pj_a(pj);
204  }
205  RzBaseType *btype;
206  rz_list_foreach (unionlist, it, btype) {
207  rz_core_types_union_print(core, btype, mode, pj);
208  }
209  rz_list_free(unionlist);
210  if (mode == RZ_OUTPUT_MODE_JSON) {
211  pj_end(pj);
213  pj_free(pj);
214  }
215 }
RZ_IPI void rz_core_types_union_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:152

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_UNION, rz_cons_println(), rz_core_types_union_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_union_handler().

◆ rz_core_types_union_print_format_all()

RZ_IPI void rz_core_types_union_print_format_all ( RzCore core)

Definition at line 613 of file ctypes.c.

613  {
614  RzTypeDB *typedb = core->analysis->typedb;
616  RzListIter *it;
617  RzBaseType *btype;
618  rz_list_foreach (unionlist, it, btype) {
620  }
621  rz_list_free(unionlist);
622 }

References rz_core_t::analysis, rz_base_type_t::name, RZ_BASE_TYPE_KIND_UNION, rz_core_types_show_format(), rz_list_free(), RZ_OUTPUT_MODE_RIZIN, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_union_handler().

◆ rz_disasm_check_end()

RZ_IPI bool rz_disasm_check_end ( int  nb_opcodes,
int  i_opcodes,
int  nb_bytes,
int  i_bytes 
)

Is i_opcodes < nb_opcodes and i_bytes < nb_bytes ?

Definition at line 5804 of file disasm.c.

5804  {
5805  if (nb_opcodes > 0) {
5806  if (nb_bytes > 0) {
5807  return i_opcodes < nb_opcodes && i_bytes < nb_bytes;
5808  }
5809  return i_opcodes < nb_opcodes;
5810  }
5811  return i_bytes < nb_bytes;
5812 }

Referenced by disassembly_as_table(), rz_core_analysis_bytes(), rz_core_disasm_pdi_with_buf(), and rz_core_print_disasm_instructions_with_buf().

◆ rz_output_mode_to_char()

RZ_IPI int rz_output_mode_to_char ( RzOutputMode  mode)

Definition at line 73 of file cmd_api.c.

73  {
74  size_t i;
75  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
76  if (argv_modes[i].mode == mode) {
77  return argv_modes[i].suffix[0];
78  }
79  }
80  return -1;
81 }
static const struct argv_modes_t argv_modes[]
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
const char * suffix
Definition: cmd_api.c:58

References argv_modes, i, RZ_ARRAY_SIZE, and argv_modes_t::suffix.

Referenced by rz_cmd_debug_trace_graph_handler().

◆ rz_reg_arenas_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 483 of file cmd_regs.c.

483  {
484  int i, j;
485  RzRegArena *a;
486  RzListIter *iter;
487  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
488  RzRegSet *rs = &reg->regset[i];
489  j = 0;
490  rz_list_foreach (rs->pool, iter, a) {
491  rz_cons_printf("%s %p %d %d %s %d\n",
492  (a == rs->arena) ? "*" : ".", a,
493  i, j, rz_reg_get_type(i), a->size);
494  j++;
495  }
496  }
497  return RZ_CMD_STATUS_OK;
498 }
#define rs()
RZ_API const char * rz_reg_get_type(int idx)
Definition: reg.c:68
@ RZ_REG_TYPE_LAST
Definition: rz_reg.h:34

References a, i, reg, rs, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get_type(), and RZ_REG_TYPE_LAST.

◆ rz_reg_arenas_hexdump_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_hexdump_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 544 of file cmd_regs.c.

544  {
545  int t = RZ_REG_TYPE_GPR;
546  if (argc > 1) {
547  t = rz_reg_type_by_name(argv[1]);
548  if (t < 0) {
549  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
550  return RZ_CMD_STATUS_ERROR;
551  }
552  }
553  bool failed;
554  SYNC_READ(t, failed);
555  if (failed) {
556  return RZ_CMD_STATUS_ERROR;
557  }
558  int len = 0;
559  ut8 *buf = rz_reg_get_bytes(reg, t, &len);
560  if (buf) {
561  rz_core_print_hexdump(core, 0LL, buf, len, 32, 4, 1);
562  free(buf);
563  }
564  return RZ_CMD_STATUS_OK;
565 }
RZ_API ut8 * rz_reg_get_bytes(RzReg *reg, int type, int *size)
Definition: arena.c:8
#define SYNC_READ(type, failed)
Definition: cmd_regs.c:9
RZ_IPI void rz_core_print_hexdump(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
Definition: cprint.c:161
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API int rz_reg_type_by_name(const char *str)
Returns the register type for the given type abbreviation.
Definition: reg.c:83

References argv, free(), len, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_print_hexdump(), RZ_LOG_ERROR, rz_reg_get_bytes(), rz_reg_type_by_name(), RZ_REG_TYPE_GPR, and SYNC_READ.

◆ rz_reg_arenas_pop_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_pop_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 511 of file cmd_regs.c.

511  {
513  bool failed;
514  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
515  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
516 }
#define SYNC_WRITE(type, failed)
Definition: cmd_regs.c:26

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_pop(), RZ_REG_TYPE_ANY, and SYNC_WRITE.

◆ rz_reg_arenas_push_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_push_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 500 of file cmd_regs.c.

500  {
501  bool failed;
502  SYNC_READ(RZ_REG_TYPE_ANY, failed);
503  if (failed) {
504  return RZ_CMD_STATUS_ERROR;
505  }
507  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
508  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
509 }

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_push(), RZ_REG_TYPE_ANY, SYNC_READ, and SYNC_WRITE.

◆ rz_reg_arenas_stack_size_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_stack_size_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 567 of file cmd_regs.c.

567  {
568  rz_cons_printf("%d\n", (int)rz_list_length(reg->regset[0].pool));
569  return RZ_CMD_STATUS_OK;
570 }
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109

References reg, RZ_CMD_STATUS_OK, rz_cons_printf(), and rz_list_length().

◆ rz_reg_arenas_swap_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_swap_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 518 of file cmd_regs.c.

518  {
519  bool failed;
520  SYNC_READ(RZ_REG_TYPE_ANY, failed);
521  if (failed) {
522  return RZ_CMD_STATUS_ERROR;
523  }
524  rz_reg_arena_swap(reg, false);
525  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
526  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
527 }

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_swap(), RZ_REG_TYPE_ANY, SYNC_READ, and SYNC_WRITE.

◆ rz_reg_arenas_write_hex_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_write_hex_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 572 of file cmd_regs.c.

572  {
575  if (argc > 2) {
577  if (type < 0 || type >= RZ_REG_TYPE_LAST) {
578  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
579  return RZ_CMD_STATUS_ERROR;
580  }
581  }
582  bool failed;
583  SYNC_READ(type, failed);
584  if (failed) {
585  return RZ_CMD_STATUS_ERROR;
586  }
587  const char *hex = argv[1];
588  size_t maxsz = (strlen(hex) + 1) / 2;
589  if (!maxsz) {
590  return RZ_CMD_STATUS_ERROR;
591  }
592  ut8 *buf = malloc(maxsz);
593  if (!buf) {
594  return RZ_CMD_STATUS_ERROR;
595  }
596  int sz = rz_hex_str2bin(hex, buf);
597  if (sz <= 0) {
598  RZ_LOG_ERROR("Invalid hex string given.\n");
599  free(buf);
600  return RZ_CMD_STATUS_ERROR;
601  }
602  RzRegArena *a = reg->regset[type].arena;
603  if (!a || !a->bytes) {
604  free(buf);
605  // nothing to write, this is fine
606  return RZ_CMD_STATUS_OK;
607  }
608  memcpy(a->bytes, buf, RZ_MIN(sz, a->size));
609  free(buf);
610  SYNC_WRITE(type, failed);
611  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
612 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const char hex[16]
Definition: print.c:21
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
RzRegisterType
Definition: rz_reg.h:20

References a, argv, free(), hex, malloc(), memcpy(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_hex_str2bin(), RZ_LOG_ERROR, RZ_MIN, rz_reg_type_by_name(), RZ_REG_TYPE_GPR, RZ_REG_TYPE_LAST, rz_return_val_if_fail, SYNC_READ, SYNC_WRITE, and type.

◆ rz_reg_arenas_zero_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_zero_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 529 of file cmd_regs.c.

529  {
530  int t = RZ_REG_TYPE_ANY;
531  if (argc > 1) {
532  t = rz_reg_type_by_name(argv[1]);
533  if (t < 0) {
534  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
535  return RZ_CMD_STATUS_ERROR;
536  }
537  }
539  bool failed;
540  SYNC_WRITE(t, failed);
541  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
542 }

References argv, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_reg_arena_zero(), RZ_REG_TYPE_ANY, rz_reg_type_by_name(), and SYNC_WRITE.

◆ rz_reg_cc_handler()

RZ_IPI RzCmdStatus rz_reg_cc_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 797 of file cmd_regs.c.

797  {
798  char *s = rz_reg_profile_to_cc(reg);
799  if (s) {
800  rz_cons_printf("%s\n", s);
801  free(s);
802  }
803  return RZ_CMD_STATUS_OK;
804 }
RZ_API char * rz_reg_profile_to_cc(RzReg *reg)
Definition: profile.c:652

References free(), reg, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_profile_to_cc(), and s.

◆ rz_reg_cond_handler()

RZ_IPI RzCmdStatus rz_reg_cond_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 776 of file cmd_regs.c.

776  {
777  bool failed;
778  SYNC_READ(RZ_REG_TYPE_ANY, failed);
779  if (failed) {
780  return RZ_CMD_STATUS_ERROR;
781  }
783  if (!rf) {
784  return RZ_CMD_STATUS_ERROR;
785  }
786  rz_cons_printf("| s:%d z:%d c:%d o:%d p:%d\n",
787  rf->s, rf->z, rf->c, rf->o, rf->p);
788  for (int i = 0; i < RZ_REG_COND_LAST; i++) {
789  rz_cons_printf("%d %s\n",
790  rz_reg_cond_bits(reg, i, rf),
792  }
793  free(rf);
794  return RZ_CMD_STATUS_OK;
795 }
RZ_API int rz_reg_cond_bits(RzReg *r, int type, RzRegFlags *f)
Definition: rcond.c:102
RZ_API RzRegFlags * rz_reg_cond_retrieve(RzReg *r, RzRegFlags *f)
Definition: rcond.c:219
RZ_API const char * rz_reg_cond_to_string(int n)
Definition: rcond.c:48
#define RZ_REG_COND_LAST
Definition: rz_reg.h:93

References rz_reg_flags_t::c, free(), i, NULL, rz_reg_flags_t::o, rz_reg_flags_t::p, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_cond_bits(), RZ_REG_COND_LAST, rz_reg_cond_retrieve(), rz_reg_cond_to_string(), RZ_REG_TYPE_ANY, rz_reg_flags_t::s, SYNC_READ, and rz_reg_flags_t::z.

◆ rz_reg_flags_handler()

RZ_IPI RzCmdStatus rz_reg_flags_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
bool  unset 
)

Definition at line 658 of file cmd_regs.c.

658  {
659  const char *filter = argc > 1 && *argv[1] ? argv[1] : NULL;
660  RzList *ritems;
661  if (filter) {
662  ritems = filter_reg_items(reg, filter);
663  if (!ritems) {
665  return RZ_CMD_STATUS_ERROR;
666  }
667  } else {
668  ritems = rz_core_reg_flags_candidates(core, reg);
669  if (!ritems) {
670  return RZ_CMD_STATUS_ERROR;
671  }
672  }
673  if (!unset) {
674  rz_cons_print("fss+ " RZ_FLAGS_FS_REGISTERS "\n");
675  bool failed;
676  SYNC_READ_LIST(ritems, failed);
677  if (failed) {
678  rz_list_free(ritems);
679  return RZ_CMD_STATUS_ERROR;
680  }
681  }
682  RzListIter *iter;
683  RzRegItem *item;
684  rz_list_foreach (ritems, iter, item) {
685  if (!unset) {
686  ut64 v = rz_reg_get_value(reg, item);
687  rz_cons_printf("f+ %s @ 0x%" PFMT64x "\n", item->name, v);
688  } else {
689  rz_cons_printf("f- %s\n", item->name);
690  }
691  }
692  if (!unset) {
693  rz_cons_print("fss-\n");
694  }
695  rz_list_free(ritems);
696  return RZ_CMD_STATUS_OK;
697 }
#define SYNC_READ_LIST(ritems, failed)
Definition: cmd_regs.c:17
static void print_reg_not_found(const char *arg)
Definition: cmd_regs.c:124
static RzList * filter_reg_items(RzReg *reg, RZ_NULLABLE const char *filter)
Definition: cmd_regs.c:36
RZ_IPI RzList * rz_core_reg_flags_candidates(RzCore *core, RzReg *reg)
Definition: creg.c:60

References argv, filter_reg_items(), rz_reg_item_t::name, NULL, PFMT64x, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_reg_flags_candidates(), RZ_FLAGS_FS_REGISTERS, rz_list_free(), rz_reg_get_value(), SYNC_READ_LIST, ut64(), and v.

◆ rz_reg_profile_comments_handler()

RZ_IPI RzCmdStatus rz_reg_profile_comments_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 749 of file cmd_regs.c.

749  {
750  if (reg->reg_profile_cmt) {
751  rz_cons_println(reg->reg_profile_cmt);
752  }
753  return RZ_CMD_STATUS_OK;
754 }

References reg, RZ_CMD_STATUS_OK, and rz_cons_println().

◆ rz_reg_profile_gdb_handler()

RZ_IPI RzCmdStatus rz_reg_profile_gdb_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 762 of file cmd_regs.c.

762  {
764  char *rz_profile = rz_reg_parse_gdb_profile(argv[1]);
765  if (!rz_profile) {
766  RZ_LOG_ERROR("Cannot parse gdb profile.\n");
767  core->num->value = 1;
768  return RZ_CMD_STATUS_ERROR;
769  }
770  rz_cons_println(rz_profile);
771  core->num->value = 0;
772  free(rz_profile);
773  return RZ_CMD_STATUS_OK;
774 }
RZ_API char * rz_reg_parse_gdb_profile(const char *profile_file)
Definition: profile.c:631

References argv, free(), rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_cons_println(), RZ_LOG_ERROR, rz_reg_parse_gdb_profile(), rz_return_val_if_fail, and rz_num_t::value.

◆ rz_reg_profile_handler()

RZ_IPI RzCmdStatus rz_reg_profile_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 699 of file cmd_regs.c.

699  {
700  switch (state->mode) {
702  if (reg->reg_profile_str) {
703  rz_cons_println(reg->reg_profile_str);
704  } else {
705  eprintf("No register profile defined.\n");
706  }
707  break;
708  case RZ_OUTPUT_MODE_JSON: {
709  RzListIter *iter;
710  RzRegItem *r;
711  int i;
712  PJ *pj = state->d.pj;
713  pj_o(pj);
714  pj_k(pj, "alias_info");
715  pj_a(pj);
716  for (i = 0; i < RZ_REG_NAME_LAST; i++) {
717  if (reg->name[i]) {
718  pj_o(pj);
719  pj_kn(pj, "role", i);
720  pj_ks(pj, "role_str", rz_reg_get_role(i));
721  pj_ks(pj, "reg", reg->name[i]);
722  pj_end(pj);
723  }
724  }
725  pj_end(pj);
726  pj_k(pj, "reg_info");
727  pj_a(pj);
728  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
729  rz_list_foreach (reg->regset[i].regs, iter, r) {
730  pj_o(pj);
731  pj_kn(pj, "type", r->type);
732  pj_ks(pj, "type_str", rz_reg_get_type(r->type));
733  pj_ks(pj, "name", r->name);
734  pj_kn(pj, "size", r->size);
735  pj_kn(pj, "offset", r->offset);
736  pj_end(pj);
737  }
738  }
739  pj_end(pj);
740  pj_end(pj);
741  break;
742  }
743  default:
744  break;
745  }
746  return RZ_CMD_STATUS_OK;
747 }
RZ_API const char * rz_reg_get_role(int role)
Definition: reg.c:172
@ RZ_REG_NAME_LAST
Definition: rz_reg.h:71

References eprintf, i, pj_a(), pj_end(), pj_k(), pj_kn(), pj_ks(), pj_o(), r, reg, RZ_CMD_STATUS_OK, rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_reg_get_role(), rz_reg_get_type(), RZ_REG_NAME_LAST, and RZ_REG_TYPE_LAST.

◆ rz_reg_profile_open_handler()

RZ_IPI RzCmdStatus rz_reg_profile_open_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 756 of file cmd_regs.c.

756  {
759  return RZ_CMD_STATUS_OK;
760 }
RZ_API bool rz_reg_set_profile(RzReg *reg, const char *profile)
Definition: profile.c:486

References argv, reg, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_reg_set_profile(), and rz_return_val_if_fail.

◆ rz_reg_roles_handler()

RZ_IPI RzCmdStatus rz_reg_roles_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 647 of file cmd_regs.c.

647  {
648  for (int i = 0; i < RZ_REG_NAME_LAST; i++) {
649  rz_cons_print(rz_reg_get_role(i));
650  if (reg->name[i]) {
651  rz_cons_printf(" -> %s", reg->name[i]);
652  }
653  rz_cons_print("\n");
654  }
655  return RZ_CMD_STATUS_OK;
656 }

References i, reg, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get_role(), and RZ_REG_NAME_LAST.

◆ rz_reg_types_handler()

RZ_IPI RzCmdStatus rz_reg_types_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 640 of file cmd_regs.c.

640  {
641  for (int i = 0; i < RZ_REG_TYPE_LAST; i++) {
643  }
644  return RZ_CMD_STATUS_OK;
645 }

References i, RZ_CMD_STATUS_OK, rz_cons_println(), rz_reg_get_type(), and RZ_REG_TYPE_LAST.

◆ rz_regs_args_handler()

RZ_IPI RzCmdStatus rz_regs_args_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 614 of file cmd_regs.c.

614  {
615  RzList *ritems = rz_list_new();
616  if (!ritems) {
617  return RZ_CMD_STATUS_ERROR;
618  }
619  for (int i = RZ_REG_NAME_A0; i <= RZ_REG_NAME_A9; i++) {
620  const char *name = rz_reg_get_name(reg, i);
621  if (!name) {
622  break;
623  }
625  if (!item) {
626  continue;
627  }
628  rz_list_push(ritems, item);
629  }
631  if (rz_list_empty(ritems)) {
632  eprintf("No argument roles defined.\n");
633  } else {
634  r = references_handler(core, reg, sync_cb, ritems, mode);
635  }
636  rz_list_free(ritems);
637  return r;
638 }
static RzCmdStatus references_handler(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RzList *ritems, RzOutputMode mode)
Definition: cmd_regs.c:346
enum rz_cmd_status_t RzCmdStatus
@ RZ_REG_NAME_A9
Definition: rz_reg.h:58
@ RZ_REG_NAME_A0
Definition: rz_reg.h:49

References eprintf, i, r, references_handler(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_list_free(), rz_list_new(), rz_list_push(), rz_reg_get(), rz_reg_get_name(), RZ_REG_NAME_A0, RZ_REG_NAME_A9, and RZ_REG_TYPE_ANY.

◆ rz_regs_columns_handler()

RZ_IPI RzCmdStatus rz_regs_columns_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 298 of file cmd_regs.c.

298  {
299  const char *filter = argc > 1 ? argv[1] : NULL;
300  RzList *ritems = rz_core_reg_filter_items_sync(core, reg, sync_cb, filter);
301  if (!ritems) {
303  return RZ_CMD_STATUS_ERROR;
304  }
305 
306  int cols = 4; // how many registers in a row
307  int colwidth = 24;
308  RzListIter *iter;
309  RzRegItem *item;
310  char whites[32], content[300];
311  char strvalue[256] = { 0 };
312  size_t idx = 0;
313  rz_list_foreach (ritems, iter, item) {
314  const char *color = get_reg_color(core, reg, item);
315  if (color) {
316  rz_cons_print(color);
317  }
318  format_reg_value(reg, item, strvalue, sizeof(strvalue));
319  int len = snprintf(content, sizeof(content), "%7s %s", item->name, strvalue);
320  if (len < 0) {
321  break;
322  }
323  rz_cons_print(content);
324  if (color) {
325  rz_cons_print(Color_RESET);
326  }
327  if ((idx + 1) % cols) {
328  int rem = colwidth - strlen(content);
329  rem = RZ_MIN(sizeof(whites) - 1, RZ_MAX(0, rem));
330  memset(whites, ' ', rem);
331  whites[rem] = 0;
332  rz_cons_print(whites);
333  } else {
334  rz_cons_print("\n");
335  }
336  idx++;
337  }
338  if (idx % cols) {
339  // only print newline if not already done in the loop above
340  rz_cons_print("\n");
341  }
342  rz_list_free(ritems);
343  return RZ_CMD_STATUS_OK;
344 }
static const char * get_reg_color(RzCore *core, RzReg *reg, RzRegItem *item)
Definition: cmd_regs.c:172
RZ_API RZ_OWN RzList * rz_core_reg_filter_items_sync(RZ_NONNULL RzCore *core, RZ_NONNULL RzReg *reg, RzCmdRegSync sync_cb, RZ_NULLABLE const char *filter)
Definition: cmd_regs.c:203
static void format_reg_value(RzReg *reg, RzRegItem *item, char *out, size_t out_size)
Format the value of a register as a nice hex string.
Definition: cmd_regs.c:87
snprintf
Definition: kernel.h:364
return memset(p, 0, total)
int idx
Definition: setup.py:197
#define Color_RESET
Definition: rz_cons.h:617

References argv, color, Color_RESET, format_reg_value(), get_reg_color(), setup::idx, len, memset(), rz_reg_item_t::name, NULL, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_reg_filter_items_sync(), rz_list_free(), RZ_MAX, RZ_MIN, and snprintf.

◆ rz_regs_diff_handler()

RZ_IPI RzCmdStatus rz_regs_diff_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 806 of file cmd_regs.c.

806  {
807  bool failed;
808  SYNC_READ(RZ_REG_TYPE_ANY, failed);
809  if (failed) {
810  return RZ_CMD_STATUS_ERROR;
811  }
812  rz_core_reg_print_diff(reg, reg->allregs);
813  return RZ_CMD_STATUS_OK;
814 }

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_reg_print_diff(), RZ_REG_TYPE_ANY, and SYNC_READ.

◆ rz_regs_fpu_handler()

RZ_IPI RzCmdStatus rz_regs_fpu_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 824 of file cmd_regs.c.

824  {
825  // TODO: everything here needs to be rewritten. It was taken from the old "drf" command.
826  bool failed;
827  if (argc <= 1) {
828  // TODO: Do not use this hack to print fpu register:
829  // By sending a negative value, this is signalling all the way through to the debug plugin,
830  // which then does the printing.
831  // This should be rewritten directly above the RzReg.
832  SYNC_READ(-RZ_REG_TYPE_FPU, failed);
833  if (failed) {
834  return RZ_CMD_STATUS_ERROR;
835  }
836  return RZ_CMD_STATUS_OK;
837  }
838  char *name = rz_str_trim_dup(argv[1]);
839  char *eq = strchr(name, '=');
840  if (eq) {
841  *eq++ = 0;
842  }
843  char *p = strchr(name, ' ');
844  if (p) {
845  *p++ = 0;
846  }
848  SYNC_READ(RZ_REG_TYPE_GPR, failed);
849  if (failed) {
850  goto error;
851  }
852  SYNC_READ(RZ_REG_TYPE_FPU, failed);
853  if (failed) {
854  goto error;
855  }
856  RzRegItem *item = rz_reg_get(reg, name, -1);
857  if (item) {
858  if (eq) {
859  long double val = 0.0f;
860 #if __windows__
861  double dval = 0.0f;
862  sscanf(eq, "%lf", (double *)&dval);
863  val = dval;
864 #else
865  sscanf(eq, "%Lf", &val);
866 #endif
867  rz_reg_set_double(reg, item, val);
868  SYNC_WRITE(RZ_REG_TYPE_GPR, failed);
869  if (failed) {
870  goto error;
871  }
872  SYNC_WRITE(RZ_REG_TYPE_FPU, failed);
873  if (failed) {
874  goto error;
875  }
876  } else {
877  long double res = rz_reg_get_longdouble(reg, item);
878  rz_cons_printf("%Lf\n", res);
879  }
880  } else {
881  /* note, that negative type forces sync to print the regs from the backend */
882  eprintf("cannot find multimedia register '%s'\n", name);
883  }
884 
885 error:
886  free(name);
887  return ret;
888 }
RZ_API bool rz_reg_set_double(RzReg *reg, RzRegItem *item, double value)
Definition: double.c:40
RZ_API long double rz_reg_get_longdouble(RzReg *reg, RzRegItem *item)
Definition: double.c:67
@ RZ_REG_TYPE_FPU
Definition: rz_reg.h:23
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78
void error(const char *msg)
Definition: untgz.c:593

References argv, eprintf, eq, error(), free(), p, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get(), rz_reg_get_longdouble(), rz_reg_set_double(), RZ_REG_TYPE_FPU, RZ_REG_TYPE_GPR, rz_str_trim_dup(), SYNC_READ, SYNC_WRITE, and val.

◆ rz_regs_handler()

RZ_IPI RzCmdStatus rz_regs_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 283 of file cmd_regs.c.

283  {
284  const char *filter = argc > 1 ? argv[1] : NULL;
285 
286  // check if the argument is an assignment like reg=0x42
287  if (filter) {
288  char *eq = strchr(filter, '=');
289  if (eq) {
290  return assign_reg(core, reg, sync_cb, filter, eq - filter);
291  }
292  }
293 
294  // just show
295  return show_regs_handler(core, reg, sync_cb, filter, state);
296 }
static RzCmdStatus assign_reg(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RZ_NONNULL const char *arg, size_t eq_pos)
(Sub)handler for register assignments like reg=0x42
Definition: cmd_regs.c:159
static RzCmdStatus show_regs_handler(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const char *filter, RzCmdStateOutput *state)
Definition: cmd_regs.c:219

References argv, assign_reg(), eq, NULL, reg, and show_regs_handler().

◆ rz_regs_prev_handler()

RZ_IPI RzCmdStatus rz_regs_prev_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 816 of file cmd_regs.c.

816  {
817  const char *filter = argc > 1 ? argv[1] : NULL;
818  rz_reg_arena_swap(reg, false);
819  RzCmdStatus r = show_regs_handler(core, reg, NULL, filter, state); // sync_cb = NULL on purpose to not overwrite
820  rz_reg_arena_swap(reg, false);
821  return r;
822 }

References argv, NULL, r, reg, rz_reg_arena_swap(), and show_regs_handler().

◆ rz_regs_references_handler()

RZ_IPI RzCmdStatus rz_regs_references_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 392 of file cmd_regs.c.

392  {
393  const char *filter = argc > 1 ? argv[1] : NULL;
394  RzList *ritems = filter_reg_items(reg, filter);
395  if (!ritems) {
397  return RZ_CMD_STATUS_ERROR;
398  }
399  RzCmdStatus r = references_handler(core, reg, sync_cb, ritems, mode);
400  rz_list_free(ritems);
401  return r;
402 }

References argv, filter_reg_items(), NULL, print_reg_not_found(), r, references_handler(), reg, RZ_CMD_STATUS_ERROR, and rz_list_free().

◆ rz_regs_show_valgroup()

RZ_IPI void rz_regs_show_valgroup ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
const RzList list 
)

Definition at line 423 of file cmd_regs.c.

423  {
424  int use_colors = rz_config_get_i(core->config, "scr.color");
425 
426  RzListIter *iter;
427  RzRegItem *r;
428  HtUP *db = ht_up_new0();
429  rz_list_foreach (list, iter, r) {
430  if (r->size != core->rasm->bits) {
431  continue;
432  }
434  RzList *list = ht_up_find(db, value, NULL);
435  if (!list) {
437  ht_up_update(db, value, list);
438  }
439  rz_list_append(list, r->name);
440  }
441 
442  RzList *sorted = rz_list_newf(free);
443  ht_up_foreach(db, valgroup_regcb, sorted);
444  ut64 *addr;
445  rz_list_foreach (sorted, iter, addr) {
446  rz_cons_printf("0x%08" PFMT64x " ", *addr);
447  RzList *list = ht_up_find(db, *addr, NULL);
448  if (list) {
449  RzListIter *iter;
450  const char *r;
451  if (use_colors) {
453  }
454  rz_list_foreach (list, iter, r) {
455  rz_cons_printf(" %s", r);
456  }
457  if (use_colors) {
459  }
460  char *rrstr = rz_core_analysis_hasrefs(core, *addr, true);
461  if (rrstr && *rrstr && strchr(rrstr, 'R')) {
462  rz_cons_printf(" ;%s%s", rrstr, use_colors ? Color_RESET : "");
463  }
464  rz_cons_newline();
465  }
466  }
467  rz_list_free(sorted);
468  ht_up_free(db);
469 }
static bool valgroup_regcb(void *u, const ut64 k, const void *v)
Definition: cmd_regs.c:416
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
RZ_API char * rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode)
Definition: core.c:1805
#define Color_YELLOW
Definition: rz_cons.h:631

References addr, rz_asm_t::bits, Color_RESET, Color_YELLOW, rz_core_t::config, free(), list(), NULL, PFMT64x, r, rz_core_t::rasm, reg, rz_config_get_i(), rz_cons_newline(), rz_cons_printf(), rz_cons_strcat(), rz_core_analysis_hasrefs(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_reg_get_value(), ut64(), valgroup_regcb(), and value.

Referenced by rz_core_debug_ri(), and rz_regs_valgroup_handler().

◆ rz_regs_valgroup_handler()

RZ_IPI RzCmdStatus rz_regs_valgroup_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 471 of file cmd_regs.c.

471  {
472  const char *filter = argc > 1 ? argv[1] : NULL;
474  if (!list) {
476  return RZ_CMD_STATUS_ERROR;
477  }
478  rz_regs_show_valgroup(core, reg, sync_cb, list);
480  return RZ_CMD_STATUS_OK;
481 }
RZ_IPI void rz_regs_show_valgroup(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
Definition: cmd_regs.c:423

References argv, filter_reg_items(), list(), NULL, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_list_free(), and rz_regs_show_valgroup().

◆ rz_types_define()

RZ_IPI void rz_types_define ( RzCore core,
const char *  type 
)

Definition at line 1029 of file ctypes.c.

1029  {
1030  // Add trailing semicolon to force the valid C syntax
1031  // It allows us to skip the trailing semicolon in the input
1032  // to reduce the unnecessary typing
1033  char *tmp = rz_str_newf("%s;", type);
1034  if (!tmp) {
1035  return;
1036  }
1037  char *error_msg = NULL;
1038  RzTypeDB *typedb = core->analysis->typedb;
1039  int result = rz_type_parse_string_stateless(typedb->parser, tmp, &error_msg);
1040  if (result && error_msg) {
1041  eprintf("%s", error_msg);
1042  free(error_msg);
1043  }
1044 }
RZ_API int rz_type_parse_string_stateless(RzTypeParser *parser, const char *code, char **error_msg)
Parses the C type string reusing the existing parser state.
Definition: c_cpp_parser.c:227
RzTypeParser * parser
Definition: rz_type.h:37

References rz_core_t::analysis, coremodepj::core, eprintf, free(), NULL, rz_type_db_t::parser, rz_str_newf(), rz_type_parse_string_stateless(), autogen_x86imm::tmp, type, and rz_analysis_t::typedb.

Referenced by rz_type_define_handler().

◆ rz_types_open_editor()

RZ_IPI bool rz_types_open_editor ( RzCore core,
RZ_NONNULL const char *  typename 
)

Definition at line 1075 of file ctypes.c.

1075  {
1076  rz_return_val_if_fail(name, false);
1077  RzTypeDB *typedb = core->analysis->typedb;
1079  if (!t) {
1080  return false;
1081  }
1082  char *str = rz_core_base_type_as_c(core, t, true);
1083  if (!str) {
1084  RZ_LOG_ERROR("Cannot generate C representation of type \"%s\"\n", name);
1085  return false;
1086  }
1087  bool result = false;
1088  char *tmp = rz_core_editor(core, NULL, str);
1089  if (tmp) {
1090  result = rz_type_db_edit_base_type(typedb, t->name, tmp);
1091  free(tmp);
1092  }
1093  free(str);
1094  return result;
1095 }
RZ_API RZ_BORROW RzBaseType * rz_type_db_get_compound_type(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the compound RzBaseType in the types database given the name.
Definition: base.c:234
RZ_IPI RZ_OWN char * rz_core_base_type_as_c(RzCore *core, RZ_NONNULL RzBaseType *type, bool multiline)
Definition: ctypes.c:408
RZ_API bool rz_type_db_edit_base_type(RzTypeDB *typedb, RZ_NONNULL const char *name, RZ_NONNULL const char *typestr)
Edits the existing base type given the new C code.
Definition: type.c:1305

References rz_core_t::analysis, coremodepj::core, free(), rz_base_type_t::name, NULL, rz_core_base_type_as_c(), rz_core_editor(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_type_db_edit_base_type(), rz_type_db_get_compound_type(), cmd_descs_generate::str, autogen_x86imm::tmp, and rz_analysis_t::typedb.

Referenced by rz_type_open_editor_handler().

◆ rz_types_open_file()

RZ_IPI bool rz_types_open_file ( RzCore core,
const char *  path 
)

Definition at line 1046 of file ctypes.c.

1046  {
1047  const char *dir = rz_config_get(core->config, "dir.types");
1048  RzTypeDB *typedb = core->analysis->typedb;
1049  if (!strcmp(path, "-")) {
1050  char *tmp = rz_core_editor(core, "*.h", "");
1051  if (tmp) {
1052  char *error_msg = NULL;
1053  int result = rz_type_parse_string_stateless(typedb->parser, tmp, &error_msg);
1054  if (result && error_msg) {
1055  RZ_LOG_ERROR("%s", error_msg);
1056  free(error_msg);
1057  }
1058  free(tmp);
1059  }
1060  } else {
1061  if (!rz_file_exists(path)) {
1062  RZ_LOG_ERROR("File \"%s\" does not exist\n", path);
1063  return false;
1064  }
1065  char *error_msg = NULL;
1066  int result = rz_type_parse_file_stateless(typedb->parser, path, dir, &error_msg);
1067  if (result && error_msg) {
1068  RZ_LOG_ERROR("%s", error_msg);
1069  free(error_msg);
1070  }
1071  }
1072  return true;
1073 }
RZ_API int rz_type_parse_file_stateless(RzTypeParser *parser, const char *path, const char *dir, char **error_msg)
Parses the C types file reusing the existing parser state.
Definition: c_cpp_parser.c:239
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192

References rz_core_t::analysis, rz_core_t::config, coremodepj::core, free(), NULL, rz_type_db_t::parser, path, rz_config_get(), rz_core_editor(), rz_file_exists(), RZ_LOG_ERROR, rz_type_parse_file_stateless(), rz_type_parse_string_stateless(), autogen_x86imm::tmp, and rz_analysis_t::typedb.

Referenced by rz_type_open_file_handler().