Rizin
unix-like reverse engineering framework and cli tools
cmd_print.c File Reference
#include <rz_asm.h>
#include <rz_core.h>
#include <rz_config.h>
#include <rz_util.h>
#include <rz_type.h>
#include <rz_types.h>
#include <limits.h>
#include "../core_private.h"
#include "rz_util/rz_strbuf.h"

Go to the source code of this file.

Macros

#define PF_USAGE_STR   "pf[.k[.f[=v]]|[v]]|[n]|[0|cnt][fmt] [a0 a1 ...]"
 
#define append(x, y)
 
#define USE_PREFIXES   1
 
#define CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL(name, type)
 
#define CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN(name, type)
 

Functions

static void cmd_prc (RzCore *core, const ut8 *block, int len)
 
static void cmd_pCd (RzCore *core, const char *input)
 
static void findMethodBounds (RzList *methods, ut64 *min, ut64 *max)
 
static ut64 findClassBounds (RzCore *core, int *len)
 
static void cmd_pCD (RzCore *core, const char *input)
 
static void cmd_pCx (RzCore *core, const char *input, const char *xcmd)
 
static void cmd_print_eq_dict (RzCore *core, const ut8 *block, int bsz)
 
RZ_API void rz_core_set_asm_configs (RzCore *core, char *arch, ut32 bits, int segoff)
 
static void cmd_p_minus_e (RzCore *core, ut64 at, ut64 ate)
 
static void helpCmdTasks (RzCore *core)
 
static void print_format_help_help_help_help (RzCore *core)
 
static void cmd_print_fromage (RzCore *core, const char *input, const ut8 *data, int size)
 
RZ_API void rz_core_gadget_free (RzCoreGadget *g)
 Frees a visual print gadget. More...
 
RZ_API void rz_core_gadget_print (RzCore *core)
 Prints or displays the print gadgets while in visual mode. More...
 
RZ_IPI RzCmdStatus rz_cmd_print_gadget_print_as_rizin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_gadget_remove_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_gadget_move_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_gadget_add_handler (RzCore *core, int argc, const char **argv)
 
static void cmd_print_gadget (RzCore *core, const char *_input)
 
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_unix_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_dos_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_hfs_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_ntfs_handler (RzCore *core, int argc, const char **argv)
 
static void cmd_print_format (RzCore *core, const char *_input, const ut8 *block, int len)
 
static void annotated_hexdump (RzCore *core, int len)
 
RZ_API void rz_core_print_examine (RzCore *core, const char *str)
 
static bool cmd_print_pxA (RzCore *core, int len, RzOutputMode mode)
 
static ut8old_transform_op (RzCore *core, const char *val, char op, int *buflen)
 
static void cmd_print_op (RzCore *core, const char *input)
 
static void printraw (RzCore *core, int len)
 
static void _handle_call (RzCore *core, char *line, char **str)
 
static void disasm_strings (RzCore *core, const char *input, RzAnalysisFunction *fcn)
 
static void handle_entropy (RzCore *core, const char *name, const ut8 *block, int len)
 
static void hexprint (const ut8 *data, int len)
 
static void handle_hash_cfg (RzCore *core, const char *name, const ut8 *block, int len)
 
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_algo_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_print_magic_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
static void cmd_print_pv (RzCore *core, const char *input, bool useBytes)
 
static bool cmd_print_blocks (RzCore *core, const char *input)
 
static bool checkAnalType (RzAnalysisOp *op, int t)
 
static void matchBar (ut8 *ptr, int i)
 
static ut8analBars (RzCore *core, size_t type, size_t nblocks, size_t blocksize, size_t skipblocks, ut64 from)
 
static void core_print_columns (RzCore *core, const ut8 *buf, ut32 len, ut32 height)
 
static void cmd_print_bars (RzCore *core, const char *input)
 
static int bbcmp (RzAnalysisBlock *a, RzAnalysisBlock *b)
 
static void _pointer_table (RzCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, RzOutputMode mode)
 
static void __printPattern (RzCore *core, const char *_input)
 
static void pr_bb (RzCore *core, RzAnalysisFunction *fcn, RzAnalysisBlock *b, bool emu, ut64 saved_gp, ut8 *saved_arena, char p_type, bool fromHere)
 
static void disasm_until_ret (RzCore *core, ut64 addr, char type_print, const char *arg)
 
static void func_walk_blocks (RzCore *core, RzAnalysisFunction *f, char input, char type_print, bool fromHere)
 
static char cmd_pxb_p (char input)
 
static int cmd_pxb_k (const ut8 *buffer, int x)
 
static char * get_section_name (RzCore *core)
 
static void print_json_string (RzCore *core, const ut8 *block, ut32 len, RzStrEnc encoding, bool stop_at_nil)
 
static char * __op_refs (RzCore *core, RzAnalysisOp *op, int n)
 
static char * __refs (RzCore *core, ut64 x)
 
static bool cmd_pxr (RzCore *core, int len, RzCmdStateOutput *state, int wordsize, const char *query)
 
static void core_print_2bpp_row (const ut8 *buf, bool useColor)
 
static void core_print_2bpp_tiles (RzCore *core, ut32 tiles)
 
static void core_print_raw_buffer (RzStrStringifyOpt *opt)
 
RZ_IPI RzCmdStatus rz_print_string_c_cpp_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_hex_of_assembly_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_esil_of_assembly_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_assembly_of_hex_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_assembly_of_hex_alias_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_esil_of_hex_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI int rz_cmd_print (void *data, const char *input)
 
RZ_IPI int rz_cmd_hexdump (void *data, const char *input)
 
static int lenof (ut64 off, int two)
 
RZ_API void rz_print_offset_sg (RzPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label)
 
RZ_API void rz_print_offset (RzPrint *p, ut64 off, int invert, int offseg, int offdec, int delta, const char *label)
 
RZ_IPI RzCmdStatus rz_print_utf16le_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_utf32le_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_utf16be_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_utf32be_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_hexdump_annotated_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_op_analysis_color_map_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_bits_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_comments_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer_common_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
 
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer2_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer4_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer8_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_emoji_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_function_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hexii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_common_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, int wordsize)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_1_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_2_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_4_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexword_references_8_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_sparse_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_delta_pointer_table_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hexless_bytes_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hexless_words_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hexpair_bytes_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_print_hexdump_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_n_lines_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex_common_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex2_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex4_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex8_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hexl_common_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex2l_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex4l_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_hex8l_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_print_hexdump_oct_handler (RzCore *core, int argc, const char **argv)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_rizin_handler, RZ_LANG_BYTE_ARRAY_RIZIN)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_asm_handler, RZ_LANG_BYTE_ARRAY_ASM)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_bash_handler, RZ_LANG_BYTE_ARRAY_BASH)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_c_cpp_bytes_handler, RZ_LANG_BYTE_ARRAY_C_CPP_BYTES)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN (rz_cmd_print_byte_array_c_cpp_half_word_handler, RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN (rz_cmd_print_byte_array_c_cpp_word_handler, RZ_LANG_BYTE_ARRAY_C_CPP_WORDS)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN (rz_cmd_print_byte_array_c_cpp_double_word_handler, RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_golang_handler, RZ_LANG_BYTE_ARRAY_GOLANG)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_java_handler, RZ_LANG_BYTE_ARRAY_JAVA)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_json_handler, RZ_LANG_BYTE_ARRAY_JSON)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_kotlin_handler, RZ_LANG_BYTE_ARRAY_KOTLIN)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_nodejs_handler, RZ_LANG_BYTE_ARRAY_NODEJS)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_objc_handler, RZ_LANG_BYTE_ARRAY_OBJECTIVE_C)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_python_handler, RZ_LANG_BYTE_ARRAY_PYTHON)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_rust_handler, RZ_LANG_BYTE_ARRAY_RUST)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_swift_handler, RZ_LANG_BYTE_ARRAY_SWIFT)
 
 CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (rz_cmd_print_byte_array_yara_handler, RZ_LANG_BYTE_ARRAY_YARA)
 
static void disassembly_as_table (RzTable *t, RzCore *core, int n_instrs, int n_bytes)
 
static bool core_disassembly (RzCore *core, int n_bytes, int n_instrs, RzCmdStateOutput *state, bool cbytes)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_n_bytes_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instructions_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_all_possible_opcodes_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_all_possible_opcodes_treeview_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_basic_block_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_basic_block_as_text_json_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_comments_in_n_instructions_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instructions_with_flow_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_function_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_function_summary_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instrs_as_text_json_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassembly_all_methods_class_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_sizes_of_n_instructions_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
static void disassemble_till_return_is_found (RzCore *core, ut64 offset, ut64 limit, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_ropchain_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
static bool core_walk_function_blocks (RzCore *core, RzAnalysisFunction *f, RzCmdStateOutput *state, char type_print, bool fromHere)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_from_current_block_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_no_function_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_n_bytes_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_function_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_block_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_base64_encode_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_base64_decode_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_bitstream_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_print_byte_bitstream_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 

Variables

static const char * help_msg_pp []
 
static const char * help_msg_pc []
 
static const char * help_msg_pF []
 
static const char * help_msg_pr []
 
static const char * help_msg_prg []
 
static const char * help_msg_amper []
 
static const char * help_msg_at []
 
static const char * help_msg_at_at []
 
static const char * help_msg_at_at_at []
 
static const char * help_msg_p []
 
static const char * help_msg_p_equal []
 
static const char * help_msg_pj []
 
static const char * help_msg_p_minus []
 
static const char * help_msg_pf []
 
static const char * help_detail_pf []
 
static const char * help_detail2_pf []
 
static const char * help_msg_pi []
 
static const char * help_msg_pif []
 
static const char * help_msg_po []
 
static const char * help_msg_ps []
 
static const char * help_msg_pv []
 
static const char * help_msg_px []
 
const char * help_msg_pxA []
 
static const ut32 colormap [256]
 
static const char * help_msg_pg []
 

Macro Definition Documentation

◆ append

#define append (   x,
 
)
Value:
{ \
strcat(x, y); \
x += strlen(y); \
}
int x
Definition: mipsasm.c:20

Definition at line 1740 of file cmd_print.c.

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN

#define CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN (   name,
  type 
)
Value:
RZ_IPI RzCmdStatus name(RzCore *core, int argc, const char **argv) { \
bool big_endian = rz_config_get_b(core->config, "cfg.bigendian"); \
char *code = rz_lang_byte_array(core->block, core->blocksize, big_endian ? type##_BE : type##_LE); \
rz_cons_println(code); \
} \
RzCmdStatus result = code ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR; \
free(code); \
return result; \
}
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int type
Definition: mipsasm.c:17
const char * name
Definition: op.c:541
enum rz_cmd_status_t RzCmdStatus
@ 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
RZ_API RZ_OWN char * rz_lang_byte_array(RZ_NONNULL const ut8 *buffer, size_t size, RzLangByteArrayType type)
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
Definition: inftree9.h:24
ut8 * block
Definition: rz_core.h:305
ut32 blocksize
Definition: rz_core.h:303
RzConfig * config
Definition: rz_core.h:300

Definition at line 6223 of file cmd_print.c.

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL

#define CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL (   name,
  type 
)
Value:
RZ_IPI RzCmdStatus name(RzCore *core, int argc, const char **argv) { \
char *code = rz_lang_byte_array(core->block, core->blocksize, type); \
rz_cons_println(code); \
} \
RzCmdStatus result = code ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR; \
free(code); \
return result; \
}

Definition at line 6212 of file cmd_print.c.

◆ PF_USAGE_STR

#define PF_USAGE_STR   "pf[.k[.f[=v]]|[v]]|[n]|[0|cnt][fmt] [a0 a1 ...]"

Definition at line 15 of file cmd_print.c.

◆ USE_PREFIXES

#define USE_PREFIXES   1

Function Documentation

◆ __op_refs()

static char* __op_refs ( RzCore core,
RzAnalysisOp op,
int  n 
)
static

Definition at line 4430 of file cmd_print.c.

4430  {
4431  RzStrBuf *sb = rz_strbuf_new("");
4432  if (n) {
4433  // RzList *list = rz_analysis_xrefs_get_from (core->analysis, op->addr);
4434  RzList *list = rz_analysis_xrefs_get_to(core->analysis, op->addr);
4435  RzAnalysisXRef *xref;
4436  RzListIter *iter;
4437  rz_list_foreach (list, iter, xref) {
4438  rz_strbuf_appendf(sb, "0x%08" PFMT64x " ", xref->to);
4439  }
4440  } else {
4441  if (op->jump != UT64_MAX) {
4442  rz_strbuf_appendf(sb, "0x%08" PFMT64x " ", op->jump);
4443  }
4444  if (op->fail != UT64_MAX) {
4445  rz_strbuf_appendf(sb, "0x%08" PFMT64x " ", op->fail);
4446  }
4447  if (op->ptr != UT64_MAX) {
4448  if (rz_io_is_valid_offset(core->io, op->ptr, false)) {
4449  rz_strbuf_appendf(sb, "0x%08" PFMT64x " ", op->ptr);
4450  }
4451  }
4452  }
4453  char *res = rz_strbuf_drain(sb);
4454  rz_str_trim(res);
4455  return res;
4456 }
static SblHeader sb
Definition: bin_mbn.c:26
static void list(RzEgg *egg)
Definition: rz-gg.c:52
int n
Definition: mipsasm.c:19
RZ_API bool rz_io_is_valid_offset(RzIO *io, ut64 offset, int hasperm)
Definition: ioutils.c:20
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define PFMT64x
Definition: rz_types.h:393
#define UT64_MAX
Definition: rz_types_base.h:86
RzAnalysis * analysis
Definition: rz_core.h:322
RzIO * io
Definition: rz_core.h:313
Definition: dis.c:32
RZ_API RzList * rz_analysis_xrefs_get_to(RzAnalysis *analysis, ut64 addr)
Definition: xrefs.c:173

References rz_core_t::analysis, rz_core_t::io, list(), n, PFMT64x, rz_analysis_xrefs_get_to(), rz_io_is_valid_offset(), rz_str_trim(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), sb, rz_analysis_ref_t::to, and UT64_MAX.

Referenced by disassembly_as_table().

◆ __printPattern()

static void __printPattern ( RzCore core,
const char *  _input 
)
static

Definition at line 4043 of file cmd_print.c.

4043  {
4044  char *input = strdup(_input);
4045  const char *arg = rz_str_nextword(input, ' ');
4046  size_t i, j;
4047  st64 len = arg ? rz_num_math(core->num, arg) : core->blocksize;
4048  if (len < 1) {
4049  eprintf("Invalid length\n");
4050  return;
4051  }
4052  switch (input[0]) {
4053  case 'd': // "ppd"
4054  // debruijn pattern
4055  {
4056  ut8 *buf = (ut8 *)rz_debruijn_pattern(len, 0, NULL);
4057  for (i = 0; i < len; i++) {
4058  rz_cons_printf("%02x", buf[i]);
4059  }
4060  rz_cons_newline();
4061  free(buf);
4062  }
4063  break;
4064  case '1': // "pp1"
4065  // incremental byte sequence
4066  {
4067  int min = (core->offset & 0xff);
4068  for (i = 0; i < len; i++) {
4069  rz_cons_printf("%02zx", i + min);
4070  }
4071  rz_cons_newline();
4072  }
4073  break;
4074  case '2': // "pp2"
4075  // incremental half word sequences
4076  {
4077  // TODO: honor cfg.bigendian
4078  int min = (core->offset & 0xffff);
4079  for (i = 0; i < len; i++) {
4080  rz_cons_printf("%04zx", i + min);
4081  }
4082  rz_cons_newline();
4083  }
4084  break;
4085  case '4': // "pp4"
4086  // incremental half word sequences
4087  {
4088  // TODO: honor cfg.bigendian
4089  int min = (core->offset & UT32_MAX);
4090  for (i = 0; i < len; i++) {
4091  rz_cons_printf("%08zx", i + min);
4092  }
4093  rz_cons_newline();
4094  }
4095  break;
4096  case '8': // "pp8"
4097  // incremental half word sequences
4098  {
4099  // TODO: honor cfg.bigendian
4100  ut64 min = (core->offset);
4101  for (i = 0; i < len; i++) {
4102  rz_cons_printf("%016" PFMT64x, i + min);
4103  }
4104  rz_cons_newline();
4105  }
4106  break;
4107  case 'f': // "ppf"
4108  // zero ssled
4109  {
4110  ut8 *buf = (ut8 *)rz_debruijn_pattern(len, 0, NULL);
4111  for (i = 0; i < len; i++) {
4112  rz_cons_printf("%02x", 0xff);
4113  }
4114  rz_cons_newline();
4115  free(buf);
4116  }
4117  break;
4118  case '0': // "pp0"
4119  // zero ssled
4120  {
4121  ut8 *buf = (ut8 *)rz_debruijn_pattern(len, 0, NULL);
4122  for (i = 0; i < len; i++) {
4123  rz_cons_printf("%02x", 0);
4124  }
4125  rz_cons_newline();
4126  free(buf);
4127  }
4128  break;
4129  case 'a':
4130  // TODO
4131  {
4132  size_t bs = 4; // XXX hardcoded
4133  ut8 *buf = calloc(bs, 1);
4134  // for (;i>0;i--) { incDigitBuffer (buf, bs); }
4135  for (i = 0; i < len; i++) {
4136  incAlphaBuffer(buf, bs);
4137  for (j = 0; j < bs; j++) {
4138  rz_cons_printf("%c", buf[j] ? buf[j] : 'A');
4139  }
4140  rz_cons_printf(" ");
4141  }
4142  rz_cons_newline();
4143  free(buf);
4144  }
4145  break;
4146  case 'n': // "ppn"
4147  {
4148  size_t bs = 4; // XXX hardcoded
4149  ut8 *buf = calloc(bs, 1);
4150  // for (;i>0;i--) { incDigitBuffer (buf, bs); }
4151  for (i = 0; i < len; i++) {
4152  incDigitBuffer(buf, bs);
4153  for (j = 0; j < bs; j++) {
4154  rz_cons_printf("%c", buf[j] ? buf[j] : '0');
4155  }
4156  rz_cons_printf(" ");
4157  }
4158  rz_cons_newline();
4159  free(buf);
4160  } break;
4161  default:
4163  break;
4164  }
4165  free(input);
4166 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
static const char * help_msg_pp[]
Definition: cmd_print.c:17
static void incDigitBuffer(ut8 *buf, int bufsz)
Definition: cmd_search.c:2725
static void incAlphaBuffer(ut8 *buf, int bufsz)
Definition: cmd_search.c:2710
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
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
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define min(a, b)
Definition: qsort.h:83
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API RZ_OWN char * rz_debruijn_pattern(int size, int start, const char *charset)
Generate a cyclic pattern following the Debruijn pattern.
Definition: debruijn.c:80
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API char * rz_str_nextword(char *s, char ch)
Definition: str.c:3912
#define st64
Definition: rz_types_base.h:10
#define UT32_MAX
Definition: rz_types_base.h:99
ut64 offset
Definition: rz_core.h:301
RzNum * num
Definition: rz_core.h:316
static int blocksize
Definition: visual.c:15
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References rz_core_t::blocksize, calloc(), eprintf, free(), help_msg_pp, i, incAlphaBuffer(), incDigitBuffer(), input(), len, min, NULL, rz_core_t::num, rz_core_t::offset, PFMT64x, rz_cons_newline(), rz_cons_printf(), rz_core_cmd_help(), rz_debruijn_pattern(), rz_num_math(), rz_str_nextword(), st64, strdup(), UT32_MAX, and ut64().

Referenced by rz_cmd_print().

◆ __refs()

static char* __refs ( RzCore core,
ut64  x 
)
inlinestatic

Definition at line 4458 of file cmd_print.c.

4458  {
4459  if (!core->print->hasrefs) {
4460  return NULL;
4461  }
4462 
4463  char *refs = core->print->hasrefs(core->print->user, x, true);
4464  if (RZ_STR_ISNOTEMPTY(refs)) {
4465  rz_str_trim(refs);
4466  } else {
4467  RZ_FREE(refs);
4468  }
4469  return refs;
4470 }
#define RZ_FREE(x)
Definition: rz_types.h:369
RzPrint * print
Definition: rz_core.h:327
void * user
Definition: rz_print.h:110
RzPrintHasRefs hasrefs
Definition: rz_print.h:150

References rz_print_t::hasrefs, NULL, rz_core_t::print, RZ_FREE, RZ_STR_ISNOTEMPTY, rz_str_trim(), rz_print_t::user, and x.

Referenced by cmd_pxr().

◆ _handle_call()

static void _handle_call ( RzCore core,
char *  line,
char **  str 
)
static

Definition at line 2571 of file cmd_print.c.

2571  {
2572  rz_return_if_fail(core && line && str && core->rasm && core->rasm->cur);
2573  if (strstr(core->rasm->cur->arch, "x86")) {
2574  *str = strstr(line, "call ");
2575  } else if (strstr(core->rasm->cur->arch, "arm")) {
2576  *str = strstr(line, " b ");
2577  if (*str && strstr(*str, " 0x")) {
2578  /*
2579  * avoid treating branches to
2580  * non-symbols as calls
2581  */
2582  *str = NULL;
2583  }
2584  if (!*str) {
2585  *str = strstr(line, "bl ");
2586  }
2587  if (!*str) {
2588  *str = strstr(line, "bx ");
2589  }
2590  }
2591 }
line
Definition: setup.py:34
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
_RzAsmPlugin * cur
Definition: rz_asm.h:106
RzAsm * rasm
Definition: rz_core.h:323

References rz_asm_t::cur, setup::line, NULL, rz_core_t::rasm, rz_return_if_fail, and cmd_descs_generate::str.

Referenced by disasm_strings().

◆ _pointer_table()

static void _pointer_table ( RzCore core,
ut64  origin,
ut64  offset,
const ut8 buf,
int  len,
int  step,
RzOutputMode  mode 
)
static

Definition at line 4003 of file cmd_print.c.

4003  {
4004  if (step < 1) {
4005  step = 4;
4006  }
4007  if (!rz_io_is_valid_offset(core->io, origin, 0) ||
4008  !rz_io_is_valid_offset(core->io, offset, 0)) {
4009  return;
4010  }
4011  if (origin != offset) {
4012  if (mode == RZ_OUTPUT_MODE_RIZIN) {
4013  rz_cons_printf("CC-@ 0x%08" PFMT64x "\n", origin);
4014  rz_cons_printf("CC switch table @ 0x%08" PFMT64x "\n", origin);
4015  rz_cons_printf("axd 0x%" PFMT64x " @ 0x%08" PFMT64x "\n", origin, offset);
4016  }
4017  }
4018  int n = 0;
4019  for (int i = 0; (i + sizeof(st32)) <= len; i += step, n++) {
4020  st32 *delta = (st32 *)(buf + i);
4021  ut64 addr = offset + *delta;
4022  if (!rz_io_is_valid_offset(core->io, addr, 0)) {
4023  // Lets check for jmptbl with not relative addresses
4024  // Like: jmp dword [eax*4 + jmptbl.0x5435345]
4025  if (!rz_io_is_valid_offset(core->io, *delta, 0)) {
4026  break;
4027  }
4028  addr = *delta;
4029  }
4030  if (mode == RZ_OUTPUT_MODE_RIZIN) {
4031  rz_cons_printf("af case.%d.0x%" PFMT64x " 0x%08" PFMT64x "\n", n, offset, addr);
4032  rz_cons_printf("ax 0x%" PFMT64x " @ 0x%08" PFMT64x "\n", offset, addr);
4033  rz_cons_printf("ax 0x%" PFMT64x " @ 0x%08" PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :?
4034  // FIXME: "aho" doesn't accept anything here after the "case" word
4035  rz_cons_printf("aho case 0x%" PFMT64x " 0x%08" PFMT64x " @ 0x%08" PFMT64x "\n", (ut64)i, addr, offset + i); // wrong, but useful because forward xrefs dont work :?
4036  rz_cons_printf("ahs %d @ 0x%08" PFMT64x "\n", step, offset + i);
4037  } else {
4038  rz_cons_printf("0x%08" PFMT64x " -> 0x%08" PFMT64x "\n", offset + i, addr);
4039  }
4040  }
4041 }
static states step(struct re_guts *, sopno, sopno, states, int, states)
Definition: engine.c:888
voidpf uLong int origin
Definition: ioapi.h:144
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
#define st32
Definition: rz_types_base.h:12
static st64 delta
Definition: vmenus.c:2425
static int addr
Definition: z80asm.c:58

References addr, delta, i, rz_core_t::io, len, n, PFMT64x, rz_cons_printf(), rz_io_is_valid_offset(), RZ_OUTPUT_MODE_RIZIN, st32, step(), and ut64().

Referenced by rz_print_delta_pointer_table_handler().

◆ analBars()

static ut8* analBars ( RzCore core,
size_t  type,
size_t  nblocks,
size_t  blocksize,
size_t  skipblocks,
ut64  from 
)
static

Definition at line 3427 of file cmd_print.c.

3427  {
3428  size_t j, i = 0;
3429  ut8 *ptr = calloc(1, nblocks);
3430  if (!ptr) {
3431  eprintf("Error: failed to malloc memory");
3432  return NULL;
3433  }
3434  if (type == 'A') {
3435  ut64 to = from + (blocksize * nblocks) - 1;
3436  if (to < from) {
3437  return NULL;
3438  }
3439  RzCoreAnalysisStats *as = rz_core_analysis_get_stats(core, from, to, blocksize);
3440  if (!as) {
3441  free(ptr);
3442  return NULL;
3443  }
3444  for (size_t i = 0; i < RZ_MIN(nblocks, rz_vector_len(&as->blocks)); i++) {
3445  int value = 0;
3446  RzCoreAnalysisStatsItem *block = rz_vector_index_ptr(&as->blocks, i);
3447  value += block->functions;
3448  value += block->in_functions;
3449  value += block->comments;
3450  value += block->symbols;
3451  value += block->flags;
3452  value += block->strings;
3453  value += block->blocks;
3454  ptr[i] = RZ_MIN(255, value);
3455  }
3457  return ptr;
3458  }
3459  for (i = 0; i < nblocks; i++) {
3460  if (rz_cons_is_breaked()) {
3461  break;
3462  }
3463  ut64 off = from + (i + skipblocks) * blocksize;
3464  for (j = 0; j < blocksize; j++) {
3465  if (type == 'a') {
3466  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, off + j, 0);
3467  if (fcn) {
3468  ptr[i] = rz_list_length(fcn->bbs);
3469  }
3470  continue;
3471  }
3473  if (op) {
3474  if (op->size < 1) {
3475  // do nothing
3476  if (type == 'i') {
3477  matchBar(ptr, i);
3478  }
3479  } else {
3480  if (checkAnalType(op, type)) {
3481  matchBar(ptr, i);
3482  }
3483  }
3484  if (op->size > 0) {
3485  j += op->size - 1;
3486  }
3488  } else {
3489  if (type == 'i') {
3490  matchBar(ptr, i);
3491  }
3492  }
3493  }
3494  }
3495  return ptr;
3496 }
RZ_API void rz_core_analysis_stats_free(RzCoreAnalysisStats *s)
Definition: canalysis.c:3818
RZ_API RZ_OWN RzCoreAnalysisStats * rz_core_analysis_get_stats(RZ_NONNULL RzCore *core, ut64 from, ut64 to, ut64 step)
Definition: canalysis.c:3722
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
static int value
Definition: cmd_api.c:93
static bool checkAnalType(RzAnalysisOp *op, int t)
Definition: cmd_print.c:3385
static void matchBar(ut8 *ptr, int i)
Definition: cmd_print.c:3421
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
int off
Definition: pal.c:13
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
#define RZ_MIN(x, y)
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88
static size_t rz_vector_len(const RzVector *vec)
Definition: rz_vector.h:82
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::analysis, rz_analysis_function_t::bbs, blocksize, calloc(), checkAnalType(), eprintf, free(), from, i, matchBar(), NULL, off, rz_analysis_get_fcn_in(), rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, rz_cons_is_breaked(), rz_core_analysis_get_stats(), rz_core_analysis_op(), rz_core_analysis_stats_free(), rz_list_length(), RZ_MIN, rz_vector_index_ptr(), rz_vector_len(), to, type, ut64(), and value.

Referenced by cmd_print_bars().

◆ annotated_hexdump()

static void annotated_hexdump ( RzCore core,
int  len 
)
static

Definition at line 1745 of file cmd_print.c.

1745  {
1746  if (!len) {
1747  return;
1748  }
1749  const int usecolor = rz_config_get_i(core->config, "scr.color");
1750  int nb_cols = rz_config_get_i(core->config, "hex.cols");
1751  core->print->use_comments = rz_config_get_i(core->config, "hex.comments");
1752  int flagsz = rz_config_get_i(core->config, "hex.flagsz");
1753  bool showSection = rz_config_get_i(core->config, "hex.section");
1754  const ut8 *buf = core->block;
1755  ut64 addr = core->offset;
1756  int color_idx = 0;
1757  char *bytes, *chars;
1758  char *ebytes, *echars; // They'll walk over the vars above
1759  ut64 fend = UT64_MAX;
1760  int i, j, low, max, here, rows;
1761  bool marks = false, setcolor = true, hascolor = false;
1762  ut8 ch = 0;
1763  char *colors[10] = { NULL };
1764  for (i = 0; i < 10; i++) {
1765  colors[i] = rz_cons_rainbow_get(i, 10, false);
1766  }
1767  const int col = core->print->col;
1768  RzFlagItem *flag, *current_flag = NULL;
1769  char **note;
1770  int html = rz_config_get_i(core->config, "scr.html");
1771  int nb_cons_cols;
1772  bool compact = false;
1773 
1774  if (core->print) {
1775  compact = core->print->flags & RZ_PRINT_FLAGS_COMPACT;
1776  }
1777  char *format = compact ? " %X %X" : " %X %X ";
1778  int step = compact ? 4 : 5;
1779 
1780  // Adjust the number of columns
1781  if (nb_cols < 1) {
1782  nb_cols = 16;
1783  }
1784  nb_cols -= (nb_cols % 2); // nb_cols should be even
1785  if (nb_cols < 1) {
1786  return;
1787  }
1788 
1789  nb_cons_cols = 12 + nb_cols * 2 + (nb_cols / 2);
1790  nb_cons_cols += 17;
1791  rows = len / nb_cols;
1792 
1793  chars = calloc(nb_cols * 40, sizeof(char));
1794  if (!chars)
1795  goto err_chars;
1796  note = calloc(nb_cols, sizeof(char *));
1797  if (!note)
1798  goto err_note;
1799  bytes = calloc(nb_cons_cols * 40, sizeof(char));
1800  if (!bytes)
1801  goto err_bytes;
1802 #if 1
1803  int addrpadlen = strlen(sdb_fmt("%08" PFMT64x, addr)) - 8;
1804  char addrpad[32];
1805  if (addrpadlen > 0) {
1806  memset(addrpad, ' ', addrpadlen);
1807  addrpad[addrpadlen] = 0;
1808  // Compute, then show the legend
1809  strcpy(bytes, addrpad);
1810  } else {
1811  *addrpad = 0;
1812  addrpadlen = 0;
1813  }
1814  strcpy(bytes + addrpadlen, "- offset - ");
1815 #endif
1816  j = strlen(bytes);
1817  for (i = 0; i < nb_cols; i += 2) {
1818  sprintf(bytes + j, format, (i & 0xf), (i + 1) & 0xf);
1819  j += step;
1820  }
1821  j--;
1822  strcpy(bytes + j, " ");
1823  j += 2;
1824  for (i = 0; i < nb_cols; i++) {
1825  sprintf(bytes + j + i, "%0X", i % 17);
1826  }
1827  if (usecolor) {
1831  } else {
1833  }
1834  rz_cons_newline();
1835 
1836  // hexdump
1837  for (i = 0; i < rows; i++) {
1838  bytes[0] = '\0';
1839  chars[0] = '\0';
1840  ebytes = bytes;
1841  echars = chars;
1842  hascolor = false;
1843  ut64 ea = addr;
1844  if (core->print->pava) {
1845  ut64 va = rz_io_p2v(core->io, addr);
1846  if (va != UT64_MAX) {
1847  ea = va;
1848  }
1849  }
1850 
1851  if (usecolor) {
1852  append(ebytes, core->cons->context->pal.offset);
1853  }
1854  if (showSection) {
1855  const char *name = rz_core_get_section_name(core, ea);
1856  char *s = rz_str_newf("%20s ", name);
1857  append(ebytes, s);
1858  free(s);
1859  }
1860  ebytes += sprintf(ebytes, "0x%08" PFMT64x, ea);
1861  if (usecolor) {
1862  append(ebytes, Color_RESET);
1863  }
1864  append(ebytes, (col == 1) ? " |" : " ");
1865  bool hadflag = false;
1866  for (j = 0; j < nb_cols; j++) {
1867  setcolor = true;
1868  RZ_FREE(note[j]);
1869 
1870  // TODO: in pava mode we should read addr or ea? // imho ea. but wat about hdrs and such
1871  RzIntervalNode *meta_node = rz_meta_get_in(core->analysis, ea + j, RZ_META_TYPE_FORMAT);
1872  RzAnalysisMetaItem *meta = meta_node ? meta_node->data : NULL;
1873  if (meta && meta->type == RZ_META_TYPE_FORMAT && meta_node->start == addr + j) {
1874  rz_cons_printf(".format %s ; size=", meta->str);
1875  rz_core_cmdf(core, "pfs %s", meta->str);
1876  rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x, meta->str, meta_node->start);
1877  if (usecolor) {
1878  append(ebytes, Color_INVERT);
1879  append(echars, Color_INVERT);
1880  }
1881  hadflag = true;
1882  }
1883  if (meta) {
1884  meta = NULL;
1885  }
1886  // collect comments
1887  const char *comment = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, addr + j);
1888  if (comment) {
1889  note[j] = rz_str_newf(";%s", comment);
1890  marks = true;
1891  }
1892 
1893  // collect flags
1894  flag = rz_flag_get_i(core->flags, addr + j);
1895  if (flag) { // Beginning of a flag
1896  if (flagsz) {
1897  fend = addr + flagsz; // core->blocksize;
1898  } else {
1899  fend = addr + j + flag->size;
1900  }
1901  free(note[j]);
1902  note[j] = rz_str_prepend(strdup(flag->name), "/");
1903  marks = true;
1904  color_idx++;
1905  color_idx %= 10;
1906  current_flag = flag;
1907  if (showSection) {
1908  rz_cons_printf("%20s ", "");
1909  }
1910  if (flag->offset == addr + j) {
1911  if (usecolor) {
1912  append(ebytes, Color_INVERT);
1913  append(echars, Color_INVERT);
1914  }
1915  hadflag = true;
1916  }
1917  } else {
1918  // Are we past the current flag?
1919  if (current_flag && addr + j > (current_flag->offset + current_flag->size)) {
1920  setcolor = false;
1921  current_flag = NULL;
1922  }
1923  // Turn colour off if we're at the end of the current flag
1924  if (fend == UT64_MAX || fend <= addr + j) {
1925  setcolor = false;
1926  }
1927  }
1928  if (usecolor) {
1929  if (!setcolor) {
1930  const char *bytecolor = rz_print_byte_color(core->print, ch);
1931  if (bytecolor) {
1932  append(ebytes, bytecolor);
1933  append(echars, bytecolor);
1934  hascolor = true;
1935  }
1936  } else if (!hascolor) {
1937  hascolor = true;
1938  if (current_flag && current_flag->color) {
1939  char *ansicolor = rz_cons_pal_parse(current_flag->color, NULL);
1940  if (ansicolor) {
1941  append(ebytes, ansicolor);
1942  append(echars, ansicolor);
1943  free(ansicolor);
1944  }
1945  } else { // Use "random" colours
1946  append(ebytes, colors[color_idx]);
1947  append(echars, colors[color_idx]);
1948  }
1949  }
1950  }
1951  here = RZ_MIN((i * nb_cols) + j, core->blocksize);
1952  ch = buf[here];
1953  if (core->print->ocur != -1) {
1954  low = RZ_MIN(core->print->cur, core->print->ocur);
1955  max = RZ_MAX(core->print->cur, core->print->ocur);
1956  } else {
1957  low = max = core->print->cur;
1958  }
1959  if (core->print->cur_enabled) {
1960  if (low == max) {
1961  if (low == here) {
1962  if (html || !usecolor) {
1963  append(ebytes, "[");
1964  append(echars, "[");
1965  } else {
1966  append(echars, Color_INVERT);
1967  append(ebytes, Color_INVERT);
1968  }
1969  }
1970  } else {
1971  if (here >= low && here < max) {
1972  if (html || !usecolor) {
1973  append(ebytes, "[");
1974  append(echars, "[");
1975  } else {
1976  if (usecolor) {
1977  append(ebytes, Color_INVERT);
1978  append(echars, Color_INVERT);
1979  }
1980  }
1981  }
1982  }
1983  }
1984  sprintf(ebytes, "%02x", ch);
1985  // rz_print_byte (core->print, "%02x ", j, ch);
1986  ebytes += strlen(ebytes);
1987  if (hadflag) {
1988  if (usecolor) {
1989  append(ebytes, Color_INVERT_RESET);
1990  append(echars, Color_INVERT_RESET);
1991  }
1992  hadflag = false;
1993  }
1994  sprintf(echars, "%c", IS_PRINTABLE(ch) ? ch : '.');
1995  echars++;
1996  if (core->print->cur_enabled && max == here) {
1997  if (!html && usecolor) {
1998  append(ebytes, Color_RESET);
1999  append(echars, Color_RESET);
2000  }
2001  hascolor = false;
2002  }
2003 
2004  if (j < (nb_cols - 1) && (j % 2) && !compact) {
2005  append(ebytes, " ");
2006  }
2007 
2008  if (fend != UT64_MAX && fend == addr + j + 1) {
2009  if (!html && usecolor) {
2010  append(ebytes, Color_RESET);
2011  append(echars, Color_RESET);
2012  }
2013  fend = UT64_MAX;
2014  hascolor = false;
2015  }
2016  }
2017  if (!html && usecolor) {
2018  append(ebytes, Color_RESET);
2019  append(echars, Color_RESET);
2020  }
2021  append(ebytes, (col == 1) ? "| " : (col == 2) ? " |"
2022  : " ");
2023  if (col == 2) {
2024  append(echars, "|");
2025  }
2026 
2027  if (marks) { // show comments and flags
2028  int hasline = 0;
2029  int out_sz = nb_cons_cols + 20;
2030  char *out = calloc(out_sz, sizeof(char));
2031  memset(out, ' ', nb_cons_cols - 1);
2032  for (j = 0; j < nb_cols; j++) {
2033  if (note[j]) {
2034  int off = (j * 3) - (j / 2) + 13;
2035  int notej_len = strlen(note[j]);
2036  int sz = RZ_MIN(notej_len, nb_cons_cols - off);
2037  if (compact) {
2038  off -= (j / 2);
2039  } else {
2040  if (j % 2) {
2041  off--;
2042  }
2043  }
2044  memcpy(out + off, note[j], sz);
2045  if (sz < notej_len) {
2046  out[off + sz - 2] = '.';
2047  out[off + sz - 1] = '.';
2048  }
2049  hasline = (out[off] != ' ');
2050  RZ_FREE(note[j]);
2051  }
2052  }
2053  out[out_sz - 1] = 0;
2054  if (hasline) {
2055  rz_cons_strcat(addrpad);
2057  rz_cons_newline();
2058  }
2059  marks = false;
2060  free(out);
2061  }
2063  rz_cons_strcat(chars);
2064 
2065  if (core->print->use_comments) {
2066  for (j = 0; j < nb_cols; j++) {
2067  const char *comment = core->print->get_comments(core->print->user, addr + j);
2068  if (comment) {
2069  rz_cons_printf(" ; %s", comment);
2070  }
2071  }
2072  }
2073 
2074  rz_cons_newline();
2075  addr += nb_cols;
2076  }
2077 
2078  free(bytes);
2079 err_bytes:
2080  free(note);
2081 err_note:
2082  free(chars);
2083 err_chars:
2084  for (i = 0; i < RZ_ARRAY_SIZE(colors); i++) {
2085  free(colors[i]);
2086  }
2087 }
static ut8 bytes[32]
Definition: asm_arc.c:23
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
#define append(x, y)
Definition: cmd_print.c:1740
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
RZ_API const char * rz_core_get_section_name(RzCore *core, ut64 addr)
Definition: disasm.c:457
int max
Definition: enough.c:225
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
sprintf
Definition: kernel.h:365
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API const char * rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr)
Definition: meta.c:146
RZ_API RzIntervalNode * rz_meta_get_in(RzAnalysis *a, ut64 addr, RzAnalysisMetaType type)
Definition: meta.c:215
RZ_API char * rz_cons_rainbow_get(int idx, int last, bool bg)
Definition: pal.c:673
RZ_API char * rz_cons_pal_parse(const char *str, RzColor *outcol)
Definition: pal.c:281
struct @219 colors[]
RZ_API const char * rz_print_byte_color(RzPrint *p, int ch)
Definition: print.c:269
static RzSocket * s
Definition: rtr.c:28
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295
@ RZ_META_TYPE_FORMAT
Definition: rz_analysis.h:292
#define Color_RESET
Definition: rz_cons.h:617
#define Color_GREEN
Definition: rz_cons.h:627
#define Color_INVERT_RESET
Definition: rz_cons.h:607
#define Color_INVERT
Definition: rz_cons.h:606
RZ_API ut64 rz_io_p2v(RzIO *io, ut64 pa)
Definition: io.c:533
#define RZ_PRINT_FLAGS_COMPACT
Definition: rz_print.h:26
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_prepend(char *ptr, const char *string)
Definition: str.c:1027
#define IS_PRINTABLE(x)
Definition: rz_str_util.h:10
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define RZ_MAX(x, y)
Definition: z80asm.h:102
RzAnalysisMetaType type
Definition: rz_analysis.h:302
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
RzCons * cons
Definition: rz_core.h:312
RzFlag * flags
Definition: rz_core.h:330
char * color
Definition: rz_flag.h:41
ut64 offset
Definition: rz_flag.h:38
char * name
Definition: rz_flag.h:35
int flags
Definition: rz_print.h:137
bool use_comments
Definition: rz_print.h:139
RzPrintCommentCallback get_comments
Definition: rz_print.h:151
int ocur
Definition: rz_print.h:135
bool pava
Definition: rz_print.h:112
bool cur_enabled
Definition: rz_print.h:130

References addr, rz_core_t::analysis, append, rz_core_t::block, rz_core_t::blocksize, bytes, calloc(), rz_print_t::col, rz_flag_item_t::color, Color_GREEN, Color_INVERT, Color_INVERT_RESET, Color_RESET, colors, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, rz_print_t::cur, rz_print_t::cur_enabled, rz_interval_node_t::data, rz_core_t::flags, rz_print_t::flags, free(), rz_print_t::get_comments, make_dist_html::html, i, rz_core_t::io, IS_PRINTABLE, len, max, memcpy(), memset(), rz_flag_item_t::name, NULL, rz_print_t::ocur, off, rz_cons_printable_palette_t::offset, rz_core_t::offset, rz_flag_item_t::offset, out, rz_cons_context_t::pal, rz_print_t::pava, PFMT64x, rz_core_t::print, RZ_ARRAY_SIZE, rz_config_get_i(), rz_cons_newline(), rz_cons_pal_parse(), rz_cons_printf(), rz_cons_rainbow_get(), rz_cons_strcat(), rz_core_cmdf(), rz_core_get_section_name(), rz_flag_get_i(), RZ_FREE, rz_io_p2v(), RZ_MAX, rz_meta_get_in(), rz_meta_get_string(), RZ_META_TYPE_COMMENT, RZ_META_TYPE_FORMAT, RZ_MIN, rz_print_byte_color(), RZ_PRINT_FLAGS_COMPACT, rz_str_newf(), rz_str_prepend(), s, sdb_fmt(), rz_flag_item_t::size, sprintf, rz_interval_node_t::start, step(), rz_analysis_meta_item_t::str, strdup(), rz_analysis_meta_item_t::type, rz_print_t::use_comments, rz_print_t::user, ut64(), and UT64_MAX.

Referenced by rz_print_hexdump_annotated_handler().

◆ bbcmp()

static int bbcmp ( RzAnalysisBlock a,
RzAnalysisBlock b 
)
static

Definition at line 3998 of file cmd_print.c.

3998  {
3999  return a->addr - b->addr;
4000 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, and b.

Referenced by core_walk_function_blocks(), and func_walk_blocks().

◆ checkAnalType()

static bool checkAnalType ( RzAnalysisOp op,
int  t 
)
static

Definition at line 3385 of file cmd_print.c.

3385  {
3386  if (t == 'c') {
3387  switch (op->type) {
3391  return true;
3392  }
3393  } else if (t == 's') {
3394  if (op->family == RZ_ANALYSIS_OP_FAMILY_PRIV) {
3395  return true;
3396  }
3397  switch (op->type) {
3399  return true;
3400  }
3401  } else if (t == 'i') {
3402  switch (op->type) {
3405  return true;
3406  }
3407  } else if (t == 'j') {
3408  switch (op->type) {
3410  // case RZ_ANALYSIS_OP_TYPE_RJMP:
3411  // case RZ_ANALYSIS_OP_TYPE_UJMP:
3413  return true;
3414  default:
3415  break;
3416  }
3417  }
3418  return false;
3419 }
@ RZ_ANALYSIS_OP_FAMILY_PRIV
Definition: rz_analysis.h:316
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_SWI
Definition: rz_analysis.h:393
@ RZ_ANALYSIS_OP_TYPE_TRAP
Definition: rz_analysis.h:392
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RCALL
Definition: rz_analysis.h:380

References RZ_ANALYSIS_OP_FAMILY_PRIV, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_RCALL, RZ_ANALYSIS_OP_TYPE_SWI, RZ_ANALYSIS_OP_TYPE_TRAP, and RZ_ANALYSIS_OP_TYPE_UCALL.

Referenced by analBars().

◆ cmd_p_minus_e()

static void cmd_p_minus_e ( RzCore core,
ut64  at,
ut64  ate 
)
static

Definition at line 1065 of file cmd_print.c.

1065  {
1066  ut8 *blockptr = malloc(ate - at);
1067  if (!blockptr) {
1068  return;
1069  }
1070  if (rz_io_read_at(core->io, at, blockptr, (ate - at))) {
1071  ut8 entropy = (ut8)(rz_hash_entropy_fraction(core->hash, blockptr, (ate - at)) * 255);
1072  entropy = 9 * entropy / 200; // normalize entropy from 0 to 9
1073  if (rz_config_get_i(core->config, "scr.color")) {
1074  const char *color =
1075  (entropy > 6) ? Color_BGRED : (entropy > 3) ? Color_BGGREEN
1076  : Color_BGBLUE;
1077  rz_cons_printf("%s%d" Color_RESET, color, entropy);
1078  } else {
1079  rz_cons_printf("%d", entropy);
1080  }
1081  }
1082  free(blockptr);
1083 }
#define ut8
Definition: dcpu16.h:8
RZ_API double rz_hash_entropy_fraction(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len)
Definition: hash.c:45
void * malloc(size_t size)
Definition: malloc.c:123
#define Color_BGGREEN
Definition: rz_cons.h:628
#define Color_BGBLUE
Definition: rz_cons.h:636
#define Color_BGRED
Definition: rz_cons.h:624
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RzHash * hash
Definition: rz_core.h:389
static int color
Definition: visual.c:20

References color, Color_BGBLUE, Color_BGGREEN, Color_BGRED, Color_RESET, rz_core_t::config, free(), rz_core_t::hash, rz_core_t::io, malloc(), rz_config_get_i(), rz_cons_printf(), rz_hash_entropy_fraction(), rz_io_read_at(), and ut8.

Referenced by cmd_print_blocks().

◆ cmd_pCd()

static void cmd_pCd ( RzCore core,
const char *  input 
)
static

Definition at line 850 of file cmd_print.c.

850  {
851  int h, w = rz_cons_get_size(&h);
852  int colwidth = rz_config_get_i(core->config, "hex.cols") * 2.5;
853  if (colwidth < 1) {
854  colwidth = 16;
855  }
856  int i, columns = w / colwidth;
857  int rows = h - 2;
858  int obsz = core->blocksize;
859  int user_rows = rz_num_math(core->num, input);
860  bool asm_minicols = rz_config_get_i(core->config, "asm.minicols");
861  char *o_ao = strdup(rz_config_get(core->config, "asm.offset"));
862  char *o_ab = strdup(rz_config_get(core->config, "asm.bytes"));
863  if (asm_minicols) {
864  rz_config_set(core->config, "asm.offset", "false");
865  // rz_config_set (core->config, "asm.bytes", "false");
866  }
867  rz_config_set(core->config, "asm.bytes", "false");
868  if (user_rows > 0) {
869  rows = user_rows + 1;
870  }
872  ut64 osek = core->offset;
873  c->color = rz_config_get_i(core->config, "scr.color");
874  rz_core_block_size(core, rows * 32);
875  for (i = 0; i < columns; i++) {
876  (void)rz_cons_canvas_gotoxy(c, i * (w / columns), 0);
877  char *cmd = rz_str_newf("pdq %d @i:%d", rows, rows * i);
878  char *dis = rz_core_cmd_str(core, cmd);
880  free(cmd);
881  free(dis);
882  }
883  rz_core_block_size(core, obsz);
884  rz_core_seek(core, osek, true);
885 
888  if (asm_minicols) {
889  rz_config_set(core->config, "asm.offset", o_ao);
890  rz_config_set(core->config, "asm.bytes", o_ab);
891  }
892  rz_config_set(core->config, "asm.bytes", o_ab);
893  free(o_ao);
894  free(o_ab);
895 }
static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_snes.c:12
RZ_API void rz_cons_canvas_print(RzConsCanvas *c)
Definition: canvas.c:423
RZ_API void rz_cons_canvas_write(RzConsCanvas *c, const char *s)
Definition: canvas.c:283
RZ_API bool rz_cons_canvas_gotoxy(RzConsCanvas *c, int x, int y)
Definition: canvas.c:184
RZ_API RzConsCanvas * rz_cons_canvas_new(int w, int h)
Definition: canvas.c:223
RZ_API void rz_cons_canvas_free(RzConsCanvas *c)
Definition: canvas.c:150
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
#define w
Definition: crypto_rc6.c:13
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
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
#define c(i)
Definition: sha256.c:43
#define h(i)
Definition: sha256.c:48

References rz_core_t::blocksize, c, cmd, rz_core_t::config, dis(), free(), h, i, input(), rz_core_t::num, rz_core_t::offset, rz_config_get(), rz_config_get_i(), rz_config_set(), rz_cons_canvas_free(), rz_cons_canvas_gotoxy(), rz_cons_canvas_new(), rz_cons_canvas_print(), rz_cons_canvas_write(), rz_cons_get_size(), rz_core_block_size(), rz_core_cmd_str(), rz_core_seek(), rz_num_math(), rz_str_newf(), strdup(), ut64(), and w.

Referenced by rz_cmd_print().

◆ cmd_pCD()

static void cmd_pCD ( RzCore core,
const char *  input 
)
static

Definition at line 935 of file cmd_print.c.

935  {
936  int h, w = rz_cons_get_size(&h);
937  int i;
938  int rows = h - 2;
939  int obsz = core->blocksize;
940  int user_rows = rz_num_math(core->num, input);
941  bool asm_minicols = rz_config_get_i(core->config, "asm.minicols");
942  char *o_ao = strdup(rz_config_get(core->config, "asm.offset"));
943  char *o_ab = strdup(rz_config_get(core->config, "asm.bytes"));
944  if (asm_minicols) {
945  rz_config_set(core->config, "asm.offset", "false");
946  rz_config_set(core->config, "asm.bytes", "false");
947  }
948  rz_config_set(core->config, "asm.bytes", "false");
949  if (user_rows > 0) {
950  rows = user_rows + 1;
951  }
953  ut64 osek = core->offset;
954  c->color = rz_config_get_i(core->config, "scr.color");
955  rz_core_block_size(core, rows * 32);
956  char *cmd = NULL;
957  int columns = 2;
958  for (i = 0; i < columns; i++) {
959  switch (i) {
960  case 0:
961  (void)rz_cons_canvas_gotoxy(c, 0, 0);
962  cmd = rz_str_newf("dr;?e;?e backtrace:;dbt");
963  break;
964  case 1:
965  (void)rz_cons_canvas_gotoxy(c, 28, 0);
966  // cmd = rz_str_newf ("pxw 128@r:SP;pd@r:PC");
967  cmd = rz_str_newf("%s 128@r:SP;pd@ 0x%" PFMT64x, core->stkcmd, osek);
968  break;
969  }
970  char *dis = rz_core_cmd_str(core, cmd);
972  free(cmd);
973  free(dis);
974  }
975  rz_core_block_size(core, obsz);
976  rz_core_seek(core, osek, true);
977 
980  if (asm_minicols) {
981  rz_config_set(core->config, "asm.offset", o_ao);
982  rz_config_set(core->config, "asm.bytes", o_ab);
983  }
984  rz_config_set(core->config, "asm.bytes", o_ab);
985  free(o_ao);
986  free(o_ab);
987 }
char * stkcmd
Definition: rz_core.h:358

References rz_core_t::blocksize, c, cmd, rz_core_t::config, dis(), free(), h, i, input(), NULL, rz_core_t::num, rz_core_t::offset, PFMT64x, rz_config_get(), rz_config_get_i(), rz_config_set(), rz_cons_canvas_free(), rz_cons_canvas_gotoxy(), rz_cons_canvas_new(), rz_cons_canvas_print(), rz_cons_canvas_write(), rz_cons_get_size(), rz_core_block_size(), rz_core_cmd_str(), rz_core_seek(), rz_num_math(), rz_str_newf(), rz_core_t::stkcmd, strdup(), ut64(), and w.

Referenced by rz_cmd_print().

◆ cmd_pCx()

static void cmd_pCx ( RzCore core,
const char *  input,
const char *  xcmd 
)
static

Definition at line 989 of file cmd_print.c.

989  {
990  int h, w = rz_cons_get_size(&h);
991  int hex_cols = rz_config_get_i(core->config, "hex.cols");
992  int colwidth = hex_cols * 5;
993  int i, columns = w / (colwidth * 0.9);
994  int rows = h - 2;
995  int user_rows = rz_num_math(core->num, input);
996  rz_config_set_i(core->config, "hex.cols", colwidth / 5);
997  if (user_rows > 0) {
998  rows = user_rows + 1;
999  }
1000  RzConsCanvas *c = rz_cons_canvas_new(w, rows);
1001  if (!c) {
1002  eprintf("Couldn't allocate a canvas with %d rows\n", rows);
1003  goto err;
1004  }
1005 
1006  ut64 tsek = core->offset;
1007  c->color = rz_config_get_i(core->config, "scr.color");
1008  int bsize = hex_cols * rows;
1009  if (!strcmp(xcmd, "pxA")) {
1010  bsize *= 12;
1011  }
1012  for (i = 0; i < columns; i++) {
1013  (void)rz_cons_canvas_gotoxy(c, i * (w / columns), 0);
1014  char *cmd = rz_str_newf("%s %d @ %" PFMT64u, xcmd, bsize, tsek);
1015  char *dis = rz_core_cmd_str(core, cmd);
1016  if (dis) {
1018  free(dis);
1019  }
1020  free(cmd);
1021  tsek += bsize - 32;
1022  }
1023 
1026 err:
1027  rz_config_set_i(core->config, "hex.cols", hex_cols);
1028 }
static bool err
Definition: armass.c:435
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
#define PFMT64u
Definition: rz_types.h:395

References c, cmd, rz_core_t::config, dis(), eprintf, err, free(), h, i, input(), rz_core_t::num, rz_core_t::offset, PFMT64u, rz_config_get_i(), rz_config_set_i(), rz_cons_canvas_free(), rz_cons_canvas_gotoxy(), rz_cons_canvas_new(), rz_cons_canvas_print(), rz_cons_canvas_write(), rz_cons_get_size(), rz_core_cmd_str(), rz_num_math(), rz_str_newf(), ut64(), and w.

Referenced by rz_cmd_print().

◆ cmd_prc()

static void cmd_prc ( RzCore core,
const ut8 block,
int  len 
)
static

Definition at line 755 of file cmd_print.c.

755  {
756  const char *chars = " .,:;!O@#";
757  bool square = rz_config_get_i(core->config, "scr.square");
758  int i, j;
759  char ch, ch2, *color;
760  int cols = rz_config_get_i(core->config, "hex.cols");
761  bool show_color = rz_config_get_i(core->config, "scr.color");
762  bool show_flags = rz_config_get_i(core->config, "asm.flags");
763  bool show_section = rz_config_get_i(core->config, "hex.section");
764  bool show_offset = rz_config_get_i(core->config, "hex.offset");
765  bool show_cursor = core->print->cur_enabled;
766  bool show_unalloc = core->print->flags & RZ_PRINT_FLAGS_UNALLOC;
767  if (cols < 1 || cols > 0xfffff) {
768  cols = 32;
769  }
770  for (i = 0; i < len; i += cols) {
771  if (show_section) {
772  const char *name = rz_core_get_section_name(core, core->offset + i);
773  rz_cons_printf("%20s ", name ? name : "");
774  }
775  if (show_offset) {
776  rz_print_addr(core->print, core->offset + i);
777  }
778  for (j = i; j < i + cols; j++) {
779  if (j >= len) {
780  break;
781  }
782  if (show_color) {
783  ut32 color_val = colormap[block[j]];
784  // Brightness weights are based on
785  // https://twitter.com/DanHollick/status/1417895189239123968
786  // (normalized to red). I'm aware that max
787  // brightness is greater than 255 * 3.
788  int brightness = ((color_val & 0xff0000) >> 16) + 2 * ((color_val & 0xff00) >> 8) + (color_val & 0xff) / 3;
789  char *str = rz_str_newf("rgb:%s rgb:%06x",
790  brightness <= 0x7f * 3 ? "fff" : "000", color_val);
792  free(str);
793  if (show_cursor && core->print->cur == j) {
794  ch = '_';
795  } else {
796  ch = ' ';
797  }
798  } else {
799  color = strdup("");
800  if (show_cursor && core->print->cur == j) {
801  ch = '_';
802  } else {
803  const int idx = ((float)block[j] / 255) * (strlen(chars) - 1);
804  ch = chars[idx];
805  }
806  }
807  if (show_unalloc &&
808  !core->print->iob.is_valid_offset(core->print->iob.io, core->offset + j, false)) {
809  ch = core->print->io_unalloc_ch;
810  if (show_color) {
811  free(color);
813  if (ch == ' ') {
814  ch = '.';
815  }
816  } else {
817  ch = strchr(chars, ch) ? '?' : ch;
818  }
819  }
820  if (square) {
821  if (show_flags) {
822  RzFlagItem *fi = rz_flag_get_i(core->flags, core->offset + j);
823  if (fi) {
824  if (fi->name[1]) {
825  ch = fi->name[0];
826  ch2 = fi->name[1];
827  } else {
828  ch = ' ';
829  ch2 = fi->name[0];
830  }
831  } else {
832  ch2 = ch;
833  }
834  } else {
835  ch2 = ch;
836  }
837  rz_cons_printf("%s%c%c", color, ch, ch2);
838  } else {
839  rz_cons_printf("%s%c", color, ch);
840  }
841  free(color);
842  }
843  if (show_color) {
845  }
846  rz_cons_newline();
847  }
848 }
static const ut32 colormap[256]
Definition: cmd_print.c:495
uint32_t ut32
int idx
Definition: setup.py:197
RZ_API void rz_print_addr(RzPrint *p, ut64 addr)
Definition: print.c:489
#define RZ_PRINT_FLAGS_UNALLOC
Definition: rz_print.h:34
RzIOIsValidOff is_valid_offset
Definition: rz_io.h:257
RzIO * io
Definition: rz_io.h:232
char io_unalloc_ch
Definition: rz_print.h:165
RzIOBind iob
Definition: rz_print.h:111

References color, Color_RESET, colormap, rz_core_t::config, rz_print_t::cur, rz_print_t::cur_enabled, rz_core_t::flags, rz_print_t::flags, test-lz4-speed::float, free(), i, setup::idx, rz_io_bind_t::io, rz_print_t::io_unalloc_ch, rz_print_t::iob, rz_io_bind_t::is_valid_offset, len, rz_flag_item_t::name, NULL, rz_core_t::offset, rz_core_t::print, rz_config_get_i(), rz_cons_newline(), rz_cons_pal_parse(), rz_cons_printf(), rz_core_get_section_name(), rz_flag_get_i(), rz_print_addr(), RZ_PRINT_FLAGS_UNALLOC, rz_str_newf(), cmd_descs_generate::str, and strdup().

Referenced by rz_cmd_print().

◆ cmd_print_bars()

static void cmd_print_bars ( RzCore core,
const char *  input 
)
static

Definition at line 3554 of file cmd_print.c.

3554  {
3555  bool print_bars = false;
3556  ut8 *ptr = NULL;
3557  // p=e [nblocks] [totalsize] [skip]
3558  int nblocks = -1;
3559  ut64 totalsize = UT64_MAX;
3560  int skipblocks = -1;
3561  RzIOMap *map;
3562  RzListIter *iter;
3563  ut64 from = 0, to = 0;
3564  RzList *list = rz_core_get_boundaries_prot(core, -1, NULL, "zoom");
3565  if (!list) {
3566  goto beach;
3567  }
3568 
3569  ut64 blocksize = 0;
3570  int mode = 'b'; // e, p, b, ...
3571  int submode = 0; // q, j, ...
3572 
3573  if (input[0]) {
3574  char *spc = strchr(input, ' ');
3575  if (spc) {
3576  nblocks = rz_num_math(core->num, spc + 1);
3577  if (nblocks < 1) {
3578  goto beach;
3579  }
3580  spc = strchr(spc + 1, ' ');
3581  if (spc) {
3582  totalsize = rz_num_math(core->num, spc + 1);
3583  spc = strchr(spc + 1, ' ');
3584  if (spc) {
3585  skipblocks = rz_num_math(core->num, spc + 1);
3586  }
3587  }
3588  }
3589  mode = input[1];
3590  if (mode && mode != ' ' && input[2]) {
3591  submode = input[2];
3592  }
3593  }
3594  if (skipblocks < 0) {
3595  skipblocks = 0;
3596  }
3597  if (totalsize == UT64_MAX) {
3598  if (rz_config_get_b(core->config, "cfg.debug")) {
3599  RzDebugMap *map = rz_debug_map_get(core->dbg, core->offset);
3600  if (map) {
3601  totalsize = map->addr_end - map->addr;
3602  from = map->addr;
3603  }
3604  } else {
3605  if (core->file && core->io) {
3606  totalsize = rz_io_fd_size(core->io, core->file->fd);
3607  if ((st64)totalsize < 1) {
3608  totalsize = UT64_MAX;
3609  }
3610  }
3611  if (totalsize == UT64_MAX) {
3612  eprintf("Cannot determine file size\n");
3613  goto beach;
3614  }
3615  }
3616  }
3617  blocksize = (blocksize > 0) ? (totalsize / blocksize) : (core->blocksize);
3618  if (blocksize < 1) {
3619  eprintf("Invalid block size: %d\n", (int)blocksize);
3620  goto beach;
3621  }
3622  if (!rz_config_get_b(core->config, "cfg.debug")) {
3623  RzIOMap *map1 = rz_list_first(list);
3624  if (map1) {
3625  from = map1->itv.addr;
3626  rz_list_foreach (list, iter, map) {
3627  to = rz_itv_end(map->itv);
3628  }
3629  totalsize = to - from;
3630  } else {
3631  from = core->offset;
3632  }
3633  }
3634  if (nblocks < 1) {
3635  nblocks = totalsize / blocksize;
3636  } else {
3637  blocksize = totalsize / nblocks;
3638  if (blocksize < 1) {
3639  eprintf("Invalid block size: %d\n", (int)blocksize);
3640  goto beach;
3641  }
3642  }
3643  switch (mode) {
3644  case '?': // bars
3646  break;
3647  case '=': // "p=="
3648  switch (submode) {
3649  case '?':
3651  break;
3652  case '0': // 0x00 bytes
3653  case 'f': // 0xff bytes
3654  case 'F': // 0xff bytes
3655  case 'A': // analysis stats
3656  case 'a': // analysis basic blocks
3657  case 'p': // printable chars
3658  case 'z': // zero terminated strings
3659  case 'b': // zero terminated strings
3660  {
3661  ut64 i, j, k;
3662  ptr = calloc(1, nblocks);
3663  if (!ptr) {
3664  eprintf("Error: failed to malloc memory");
3665  goto beach;
3666  }
3667  ut8 *p = calloc(1, blocksize);
3668  if (!p) {
3669  RZ_FREE(ptr);
3670  eprintf("Error: failed to malloc memory");
3671  goto beach;
3672  }
3673  int len = 0;
3674  if (submode == 'A') {
3675  ut64 to = from + totalsize - 1;
3676  if (to < from) {
3677  free(p);
3678  goto beach;
3679  }
3680  RzCoreAnalysisStats *as = rz_core_analysis_get_stats(core, from, to, blocksize);
3681  if (!as) {
3682  free(p);
3683  goto beach;
3684  }
3685  for (size_t i = 0; i < RZ_MIN(nblocks, rz_vector_len(&as->blocks)); i++) {
3686  RzCoreAnalysisStatsItem *block = rz_vector_index_ptr(&as->blocks, i);
3687  int value = 0;
3688  value += block->functions;
3689  value += block->in_functions;
3690  value += block->comments;
3691  value += block->symbols;
3692  value += block->flags;
3693  value += block->strings;
3694  value += block->blocks;
3695  ptr[i] = 256 * value / blocksize;
3696  ptr[i] *= 3;
3697  }
3699  } else
3700  for (i = 0; i < nblocks; i++) {
3701  ut64 off = from + blocksize * (i + skipblocks);
3702  rz_io_read_at(core->io, off, p, blocksize);
3703  for (j = k = 0; j < blocksize; j++) {
3704  switch (submode) {
3705  case 'a': {
3706  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, off + j, 0);
3707  if (fcn) {
3708  k += rz_list_length(fcn->bbs);
3709  k = RZ_MAX(255, k);
3710  }
3711  } break;
3712  case '0':
3713  if (!p[j]) {
3714  k++;
3715  }
3716  break;
3717  case 'f':
3718  if (p[j] == 0xff) {
3719  k++;
3720  }
3721  break;
3722  case 'z':
3723  if ((IS_PRINTABLE(p[j]))) {
3724  if ((j + 1) < blocksize && p[j + 1] == 0) {
3725  k++;
3726  j++;
3727  }
3728  if (len++ > 8) {
3729  k++;
3730  }
3731  } else {
3732  len = 0;
3733  }
3734  break;
3735  case 'p':
3736  if ((IS_PRINTABLE(p[j]))) {
3737  k++;
3738  }
3739  break;
3740  }
3741  }
3742  ptr[i] = 256 * k / blocksize;
3743  }
3744  core_print_columns(core, ptr, nblocks, 14);
3745  free(p);
3746  } break;
3747  case 'e': // "p=e"
3748  {
3749  ut8 *p;
3750  int i = 0;
3751  ptr = calloc(1, nblocks);
3752  if (!ptr) {
3753  eprintf("Error: failed to malloc memory");
3754  goto beach;
3755  }
3756  p = malloc(blocksize);
3757  if (!p) {
3758  RZ_FREE(ptr);
3759  eprintf("Error: failed to malloc memory");
3760  goto beach;
3761  }
3762  for (i = 0; i < nblocks; i++) {
3763  ut64 off = from + (blocksize * (i + skipblocks));
3764  rz_io_read_at(core->io, off, p, blocksize);
3765  ptr[i] = (ut8)(255 * rz_hash_entropy_fraction(core->hash, p, blocksize));
3766  }
3767  free(p);
3768  core_print_columns(core, ptr, nblocks, 14);
3769  } break;
3770  default:
3771  core_print_columns(core, core->block, core->blocksize, 14);
3772  break;
3773  }
3774  break;
3775  case '2': // "p=2"
3776  {
3777  short *word = (short *)core->block;
3778  int i, words = core->blocksize / 2;
3779  int step = rz_num_math(core->num, input + 2);
3780  ut64 oldword = 0;
3781  for (i = 0; i < words; i++) {
3782  ut64 word64 = word[i] + ST16_MAX;
3783  rz_cons_printf("0x%08" PFMT64x " %8d ", core->offset + (i * 2), word[i]);
3784  rz_print_progressbar(core->print, word64 * 100 / UT16_MAX, 60);
3785  rz_cons_printf(" %" PFMT64d, word64 - oldword);
3786  oldword = word64;
3787  rz_cons_newline();
3788  i += step;
3789  }
3790  } break;
3791  case 'd': // "p=d"
3792  ptr = NULL;
3793  if (input[2]) {
3794  ut64 bufsz = rz_num_math(core->num, input + 3);
3795  ut64 curbsz = core->blocksize;
3796  if (bufsz < 1) {
3797  bufsz = curbsz;
3798  }
3799  if (bufsz > core->blocksize) {
3800  rz_core_block_size(core, bufsz);
3801  rz_core_block_read(core);
3802  }
3803  cmd_print_eq_dict(core, core->block, bufsz);
3804  if (bufsz != curbsz) {
3805  rz_core_block_size(core, curbsz);
3806  }
3807  } else {
3808  cmd_print_eq_dict(core, core->block, core->blocksize);
3809  }
3810  break;
3811  case 'j': // "p=j" cjmp and jmp
3812  case 'A': // "p=A" analysis info
3813  case 'a': // "p=a" bb info
3814  case 'c': // "p=c" calls
3815  case 'i': // "p=i" invalid
3816  case 's': // "p=s" syscalls
3817  if ((ptr = analBars(core, mode, nblocks, blocksize, skipblocks, from))) {
3818  print_bars = true;
3819  }
3820  break;
3821  case 'm': {
3822  ut8 *p;
3823  int j, i = 0;
3824  ptr = calloc(1, nblocks);
3825  if (!ptr) {
3826  eprintf("Error: failed to malloc memory");
3827  goto beach;
3828  }
3829  p = malloc(blocksize);
3830  if (!p) {
3831  RZ_FREE(ptr);
3832  eprintf("Error: failed to malloc memory");
3833  goto beach;
3834  }
3835  for (i = 0; i < nblocks; i++) {
3836  ut64 off = from + (blocksize * (i + skipblocks));
3837  for (j = 0; j < blocksize; j++) {
3838  if (rz_flag_get_at(core->flags, off + j, false)) {
3839  matchBar(ptr, i);
3840  }
3841  }
3842  }
3843  free(p);
3844  print_bars = true;
3845  } break;
3846  case 'e': // "p=e" entropy
3847  {
3848  ut8 *p;
3849  int i = 0;
3850  ptr = calloc(1, nblocks);
3851  if (!ptr) {
3852  eprintf("Error: failed to malloc memory");
3853  goto beach;
3854  }
3855  p = malloc(blocksize);
3856  if (!p) {
3857  RZ_FREE(ptr);
3858  eprintf("Error: failed to malloc memory");
3859  goto beach;
3860  }
3861  for (i = 0; i < nblocks; i++) {
3862  ut64 off = from + (blocksize * (i + skipblocks));
3863  rz_io_read_at(core->io, off, p, blocksize);
3864  ptr[i] = (ut8)(255 * rz_hash_entropy_fraction(core->hash, p, blocksize));
3865  }
3866  free(p);
3867  print_bars = true;
3868  } break;
3869  case '0': // 0x00 bytes
3870  case 'F': // 0xff bytes
3871  case 'p': // printable chars
3872  case 'z': // zero terminated strings
3873  {
3874  ut8 *p;
3875  ut64 i, j, k;
3876  ptr = calloc(1, nblocks);
3877  if (!ptr) {
3878  eprintf("Error: failed to malloc memory");
3879  goto beach;
3880  }
3881  p = calloc(1, blocksize);
3882  if (!p) {
3883  RZ_FREE(ptr);
3884  eprintf("Error: failed to malloc memory");
3885  goto beach;
3886  }
3887  int len = 0;
3888  for (i = 0; i < nblocks; i++) {
3889  ut64 off = from + blocksize * (i + skipblocks);
3890  rz_io_read_at(core->io, off, p, blocksize);
3891  for (j = k = 0; j < blocksize; j++) {
3892  switch (mode) {
3893  case '0':
3894  if (!p[j]) {
3895  k++;
3896  }
3897  break;
3898  case 'f':
3899  if (p[j] == 0xff) {
3900  k++;
3901  }
3902  break;
3903  case 'z':
3904  if ((IS_PRINTABLE(p[j]))) {
3905  if ((j + 1) < blocksize && p[j + 1] == 0) {
3906  k++;
3907  j++;
3908  }
3909  if (len++ > 8) {
3910  k++;
3911  }
3912  } else {
3913  len = 0;
3914  }
3915  break;
3916  case 'p':
3917  if ((IS_PRINTABLE(p[j]))) {
3918  k++;
3919  }
3920  break;
3921  }
3922  }
3923  ptr[i] = 256 * k / blocksize;
3924  }
3925  free(p);
3926  print_bars = true;
3927  } break;
3928  case 'b': // bytes
3929  case '\0':
3930  ptr = calloc(1, nblocks);
3931  rz_io_read_at(core->io, from, ptr, nblocks);
3932  // TODO: support print_bars
3933  rz_print_fill(core->print, ptr, nblocks, from, blocksize);
3934  RZ_FREE(ptr);
3935  break;
3936  }
3937  if (print_bars) {
3938  bool hex_offset = rz_config_get_i(core->config, "hex.offset");
3939  if (hex_offset) {
3940  core->print->flags |= RZ_PRINT_FLAGS_OFFSET;
3941  } else {
3942  core->print->flags &= ~RZ_PRINT_FLAGS_OFFSET;
3943  }
3944  int i;
3945  switch (submode) {
3946  case 'j': {
3947  PJ *pj = pj_new();
3948  if (!pj) {
3949  return;
3950  }
3951 
3952  pj_o(pj);
3953  pj_kn(pj, "blocksize", blocksize);
3954  pj_kn(pj, "address", from);
3955  pj_kn(pj, "size", totalsize);
3956  pj_k(pj, "entropy");
3957  pj_a(pj);
3958 
3959  for (i = 0; i < nblocks; i++) {
3960  ut8 ep = ptr[i];
3961  ut64 off = blocksize * i;
3962  off += from;
3963  pj_o(pj);
3964  pj_kn(pj, "addr", off);
3965  pj_ki(pj, "value", ep);
3966  pj_end(pj);
3967  }
3968  pj_end(pj);
3969  pj_end(pj);
3971  pj_free(pj);
3972  } break;
3973  case 'q':
3974  for (i = 0; i < nblocks; i++) {
3975  ut64 off = from + (blocksize * i);
3976  if (core->print->cur_enabled) {
3977  if (i == core->print->cur) {
3978  rz_cons_printf("> ");
3979  core->num->value = off;
3980  } else {
3981  rz_cons_printf(" ");
3982  }
3983  }
3984  rz_cons_printf("0x%08" PFMT64x " %d %d\n", off, i, ptr[i]);
3985  }
3986  break;
3987  default:
3988  core->print->num = core->num;
3989  rz_print_fill(core->print, ptr, nblocks, from, blocksize);
3990  break;
3991  }
3992  }
3993 beach:
3994  rz_list_free(list);
3995  free(ptr);
3996 }
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
static const char * help_msg_p_equal[]
Definition: cmd_print.c:235
static void core_print_columns(RzCore *core, const ut8 *buf, ut32 len, ut32 height)
Definition: cmd_print.c:3498
static ut8 * analBars(RzCore *core, size_t type, size_t nblocks, size_t blocksize, size_t skipblocks, ut64 from)
Definition: cmd_print.c:3427
static void cmd_print_eq_dict(RzCore *core, const ut8 *block, int bsz)
Definition: cmd_print.c:1030
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
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
const char * k
Definition: dsignal.c:11
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
void * p
Definition: libc.cpp:67
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_print_fill(RzPrint *p, const ut8 *arr, int size, ut64 addr, int step)
Definition: print.c:1346
RZ_API void rz_print_progressbar(RzPrint *p, int pc, int _cols)
Definition: print.c:1259
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
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_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
#define RZ_PRINT_FLAGS_OFFSET
Definition: rz_print.h:21
#define PFMT64d
Definition: rz_types.h:394
#define ST16_MAX
#define UT16_MAX
Definition: rz_pj.h:12
RzDebug * dbg
Definition: rz_core.h:329
RzCoreFile * file
Definition: rz_core.h:314
ut64 addr
Definition: rz_itv.h:15
RzInterval itv
Definition: rz_io.h:149
ut64 value
Definition: rz_num.h:63
RzNum * num
Definition: rz_print.h:156

References rz_interval_t::addr, analBars(), rz_core_t::analysis, rz_analysis_function_t::bbs, rz_core_t::block, blocksize, rz_core_t::blocksize, calloc(), cmd_print_eq_dict(), rz_core_t::config, core_print_columns(), rz_print_t::cur, rz_print_t::cur_enabled, rz_core_t::dbg, eprintf, rz_core_file_t::fd, rz_core_t::file, rz_core_t::flags, rz_print_t::flags, free(), from, rz_core_t::hash, help_msg_p_equal, i, input(), rz_core_t::io, IS_PRINTABLE, rz_io_map_t::itv, k, len, list(), malloc(), map(), matchBar(), NULL, rz_core_t::num, rz_print_t::num, off, rz_core_t::offset, p, PFMT64d, PFMT64x, pj_a(), pj_end(), pj_free(), pj_k(), pj_ki(), pj_kn(), pj_new(), pj_o(), pj_string(), rz_core_t::print, rz_analysis_get_fcn_in(), rz_config_get_b(), rz_config_get_i(), rz_cons_newline(), rz_cons_printf(), rz_cons_println(), rz_core_analysis_get_stats(), rz_core_analysis_stats_free(), rz_core_block_read(), rz_core_block_size(), rz_core_cmd_help(), rz_core_get_boundaries_prot(), rz_debug_map_get(), rz_flag_get_at(), RZ_FREE, rz_hash_entropy_fraction(), rz_io_fd_size(), rz_io_read_at(), rz_itv_end(), rz_list_first(), rz_list_free(), rz_list_length(), RZ_MAX, RZ_MIN, rz_num_math(), rz_print_fill(), RZ_PRINT_FLAGS_OFFSET, rz_print_progressbar(), rz_vector_index_ptr(), rz_vector_len(), ST16_MAX, st64, step(), to, UT16_MAX, ut64(), UT64_MAX, ut8, value, and rz_num_t::value.

Referenced by rz_cmd_print().

◆ cmd_print_blocks()

static bool cmd_print_blocks ( RzCore core,
const char *  input 
)
static

Definition at line 3185 of file cmd_print.c.

3185  {
3186  bool result = false;
3187  char mode = input[0];
3188  RzList *list = NULL;
3189  RzCoreAnalysisStats *as = NULL;
3190  RzTable *t = NULL;
3191  PJ *pj = NULL;
3192  if (mode == '?') {
3194  return false;
3195  }
3196 
3197  if (mode && mode != ' ') {
3198  input++;
3199  }
3200 
3201  int w = (input[0] == ' ')
3202  ? (int)rz_num_math(core->num, input + 1)
3203  : (int)(core->print->cols * 2.7);
3204  if (w == 0) {
3206  return false;
3207  }
3208  int cols = rz_config_get_i(core->config, "hex.cols");
3209  w = RZ_MAX(cols, w);
3210 
3211  ut64 off = core->offset;
3212  ut64 from = UT64_MAX;
3213  ut64 to = 0;
3214 
3215  list = rz_core_get_boundaries_prot(core, -1, NULL, "search");
3216  if (!list || rz_list_empty(list)) {
3217  RZ_LOG_ERROR("No range to calculate stats for.\n");
3218  result = true;
3219  goto cleanup;
3220  }
3221  RzListIter *iter;
3222  RzIOMap *map;
3223  rz_list_foreach (list, iter, map) {
3224  ut64 f = rz_itv_begin(map->itv);
3225  ut64 t = rz_itv_end(map->itv);
3226  if (f < from) {
3227  from = f;
3228  }
3229  if (t > to) {
3230  to = t;
3231  }
3232  }
3233  rz_list_free(list);
3234  list = NULL;
3235  ut64 piece = RZ_MAX((to - from) / w, 1);
3236  if (piece * w != to - from) {
3237  // add 1 to compute `piece = ceil((to - from) / w)` instead
3238  piece++;
3239  }
3240  as = rz_core_analysis_get_stats(core, from, to - 1, piece);
3241  if (!as) {
3242  goto cleanup;
3243  }
3244 
3245  switch (mode) {
3246  case 'j': // "p-j"
3247  pj = pj_new();
3248  if (!pj) {
3249  goto cleanup;
3250  }
3251  pj_o(pj);
3252  pj_kn(pj, "from", from);
3253  pj_kn(pj, "to", to);
3254  pj_ki(pj, "blocksize", piece);
3255  pj_k(pj, "blocks");
3256  pj_a(pj);
3257  break;
3258  case 'h': { // "p-h"
3259  t = rz_core_table(core);
3260  if (!t) {
3261  goto cleanup;
3262  }
3263  t->showSum = true;
3264  rz_table_set_columnsf(t, "sddddd", "offset", "flags", "funcs", "cmts", "syms", "str");
3265  break;
3266  }
3267  case 'e':
3268  default:
3269  rz_cons_printf("0x%08" PFMT64x " [", from);
3270  }
3271 
3272  bool use_color = rz_config_get_i(core->config, "scr.color");
3273  int len = 0;
3274  for (size_t i = 0; i < rz_vector_len(&as->blocks); i++) {
3275  RzCoreAnalysisStatsItem *block = rz_vector_index_ptr(&as->blocks, i);
3278  switch (mode) {
3279  case 'j':
3280  pj_o(pj);
3281  if ((block->flags) || (block->functions) || (block->comments) || (block->symbols) || (block->perm) || (block->strings)) {
3282  pj_kn(pj, "offset", at);
3283  pj_kn(pj, "size", ate - at);
3284  }
3285  if (block->flags) {
3286  pj_ki(pj, "flags", block->flags);
3287  }
3288  if (block->functions) {
3289  pj_ki(pj, "functions", block->functions);
3290  }
3291  if (block->in_functions) {
3292  pj_ki(pj, "in_functions", block->in_functions);
3293  }
3294  if (block->comments) {
3295  pj_ki(pj, "comments", block->comments);
3296  }
3297  if (block->symbols) {
3298  pj_ki(pj, "symbols", block->symbols);
3299  }
3300  if (block->strings) {
3301  pj_ki(pj, "strings", block->strings);
3302  }
3303  if (block->perm) {
3304  pj_ks(pj, "perm", rz_str_rwx_i(block->perm));
3305  }
3306  pj_end(pj);
3307  len++;
3308  break;
3309  case 'h':
3310  if ((block->flags) || (block->functions) || (block->comments) || (block->symbols) || (block->strings)) {
3311  rz_table_add_rowf(t, "sddddd", sdb_fmt("0x%09" PFMT64x "", at), block->flags,
3312  block->functions, block->comments, block->symbols, block->strings);
3313  }
3314  break;
3315  case 'e': // p-e
3316  cmd_p_minus_e(core, at, ate);
3317  break;
3318  default: { // p--
3319  if (off >= at && off < ate) {
3320  rz_cons_memcat("^", 1);
3321  } else {
3322  RzIOMap *s = rz_io_map_get(core->io, at);
3323  if (use_color) {
3324  if (s) {
3325  if (s->perm & RZ_PERM_X) {
3326  rz_cons_print(rz_cons_singleton()->context->pal.graph_ujump);
3327  } else {
3328  rz_cons_print(rz_cons_singleton()->context->pal.graph_true);
3329  }
3330  } else {
3331  rz_cons_print(rz_cons_singleton()->context->pal.graph_false);
3332  }
3333  }
3334  if (block->strings > 0) {
3335  rz_cons_memcat("z", 1);
3336  } else if (block->symbols > 0) {
3337  rz_cons_memcat("s", 1);
3338  } else if (block->functions > 0) {
3339  rz_cons_memcat("F", 1);
3340  } else if (block->comments > 0) {
3341  rz_cons_memcat("c", 1);
3342  } else if (block->flags > 0) {
3343  rz_cons_memcat(".", 1);
3344  } else if (block->in_functions > 0) {
3345  rz_cons_memcat("f", 1);
3346  } else {
3347  rz_cons_memcat("_", 1);
3348  }
3349  }
3350  } break;
3351  }
3352  }
3353  switch (mode) {
3354  case 'j':
3355  pj_end(pj);
3356  pj_end(pj);
3358  break;
3359  case 'h': {
3360  char *table_string = rz_table_tofancystring(t);
3361  if (!table_string) {
3362  goto cleanup;
3363  }
3364  rz_cons_printf("\n%s\n", table_string);
3365  free(table_string);
3366  break;
3367  }
3368  case 'e':
3369  default:
3370  if (use_color) {
3371  rz_cons_print(Color_RESET);
3372  }
3373  rz_cons_printf("] 0x%08" PFMT64x "\n", to);
3374  break;
3375  }
3376  result = true;
3377 cleanup:
3378  pj_free(pj);
3379  rz_table_free(t);
3380  rz_list_free(list);
3382  return result;
3383 }
RZ_API ut64 rz_core_analysis_stats_get_block_from(RZ_NONNULL const RzCoreAnalysisStats *s, size_t i)
Definition: canalysis.c:3829
RZ_API ut64 rz_core_analysis_stats_get_block_to(RZ_NONNULL const RzCoreAnalysisStats *s, size_t i)
Definition: canalysis.c:3837
static void cmd_p_minus_e(RzCore *core, ut64 at, ut64 ate)
Definition: cmd_print.c:1065
static const char * help_msg_p_minus[]
Definition: cmd_print.c:266
RZ_API int rz_cons_memcat(const char *str, int len)
Definition: cons.c:1224
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
void cleanup(void)
Definition: enough.c:244
RZ_API RzTable * rz_core_table(RzCore *core)
Definition: core.c:3449
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
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 RZ_OWN char * rz_table_tofancystring(RZ_NONNULL RzTable *t)
Convert the content of RzTable to string.
Definition: table.c:404
#define RZ_PERM_X
Definition: rz_types.h:95
static int
Definition: sfsocketcall.h:114
#define f(i)
Definition: sha256.c:46

References cleanup(), cmd_p_minus_e(), Color_RESET, rz_print_t::cols, rz_core_t::config, f, free(), from, help_msg_p_minus, i, input(), int, rz_core_t::io, len, list(), map(), NULL, rz_core_t::num, off, rz_core_t::offset, PFMT64x, pj_a(), pj_end(), pj_free(), pj_k(), pj_ki(), pj_kn(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_core_t::print, rz_config_get_i(), rz_cons_memcat(), rz_cons_printf(), rz_cons_println(), rz_cons_singleton(), rz_core_analysis_get_stats(), rz_core_analysis_stats_free(), rz_core_analysis_stats_get_block_from(), rz_core_analysis_stats_get_block_to(), rz_core_cmd_help(), rz_core_get_boundaries_prot(), rz_core_table(), rz_io_map_get(), rz_itv_begin(), rz_itv_end(), rz_list_free(), RZ_LOG_ERROR, RZ_MAX, rz_num_math(), RZ_PERM_X, rz_str_rwx_i(), rz_table_add_rowf(), rz_table_free(), rz_table_set_columnsf(), rz_table_tofancystring(), rz_vector_index_ptr(), rz_vector_len(), s, sdb_fmt(), RzTable::showSum, to, ut64(), UT64_MAX, and w.

Referenced by rz_cmd_print().

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN() [1/3]

CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN ( rz_cmd_print_byte_array_c_cpp_double_word_handler  ,
RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN() [2/3]

CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN ( rz_cmd_print_byte_array_c_cpp_half_word_handler  ,
RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN() [3/3]

CMD_PRINT_BYTE_ARRAY_HANDLER_ENDIAN ( rz_cmd_print_byte_array_c_cpp_word_handler  ,
RZ_LANG_BYTE_ARRAY_C_CPP_WORDS   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [1/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_asm_handler  ,
RZ_LANG_BYTE_ARRAY_ASM   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [2/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_bash_handler  ,
RZ_LANG_BYTE_ARRAY_BASH   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [3/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_c_cpp_bytes_handler  ,
RZ_LANG_BYTE_ARRAY_C_CPP_BYTES   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [4/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_golang_handler  ,
RZ_LANG_BYTE_ARRAY_GOLANG   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [5/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_java_handler  ,
RZ_LANG_BYTE_ARRAY_JAVA   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [6/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_json_handler  ,
RZ_LANG_BYTE_ARRAY_JSON   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [7/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_kotlin_handler  ,
RZ_LANG_BYTE_ARRAY_KOTLIN   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [8/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_nodejs_handler  ,
RZ_LANG_BYTE_ARRAY_NODEJS   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [9/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_objc_handler  ,
RZ_LANG_BYTE_ARRAY_OBJECTIVE_C   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [10/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_python_handler  ,
RZ_LANG_BYTE_ARRAY_PYTHON   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [11/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_rizin_handler  ,
RZ_LANG_BYTE_ARRAY_RIZIN   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [12/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_rust_handler  ,
RZ_LANG_BYTE_ARRAY_RUST   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [13/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_swift_handler  ,
RZ_LANG_BYTE_ARRAY_SWIFT   
)

◆ CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL() [14/14]

CMD_PRINT_BYTE_ARRAY_HANDLER_NORMAL ( rz_cmd_print_byte_array_yara_handler  ,
RZ_LANG_BYTE_ARRAY_YARA   
)

◆ cmd_print_eq_dict()

static void cmd_print_eq_dict ( RzCore core,
const ut8 block,
int  bsz 
)
static

Definition at line 1030 of file cmd_print.c.

1030  {
1031  int i;
1032  int min = -1;
1033  int max = 0;
1034  int dict = 0;
1035  int range = 0;
1036  bool histogram[256] = { 0 };
1037  for (i = 0; i < bsz; i++) {
1038  histogram[block[i]] = true;
1039  }
1040  for (i = 0; i < 256; i++) {
1041  if (histogram[i]) {
1042  if (min == -1) {
1043  min = i;
1044  }
1045  max = i;
1046  dict++;
1047  }
1048  }
1049  range = max - min;
1050  rz_cons_printf("min: %d 0x%x\n", min, min);
1051  rz_cons_printf("max: %d 0x%x\n", max, max);
1052  rz_cons_printf("unique (count): %d 0x%x\n", dict, dict);
1053  rz_cons_printf("range (max-min): %d 0x%x\n", range, range);
1054  rz_cons_printf("size (of block): %d 0x%x\n", bsz, bsz);
1055 }

References i, max, min, capstone::range, and rz_cons_printf().

Referenced by cmd_print_bars().

◆ cmd_print_format()

static void cmd_print_format ( RzCore core,
const char *  _input,
const ut8 block,
int  len 
)
static

Definition at line 1422 of file cmd_print.c.

1422  {
1423  char *input = NULL;
1424  int mode = RZ_PRINT_MUSTSEE;
1425  switch (_input[1]) {
1426  case '*': // "pf*"
1427  _input++;
1428  mode = RZ_PRINT_SEEFLAGS;
1429  break;
1430  case 'q': // "pfq"
1431  _input++;
1432  mode = RZ_PRINT_QUIET | RZ_PRINT_MUSTSEE;
1433  break;
1434  case 'd': // "pfd"
1435  _input++;
1436  mode = RZ_PRINT_DOT;
1437  break;
1438  case 'j': // "pfj"
1439  _input++;
1440  mode = RZ_PRINT_JSON;
1441  break;
1442  case 'v': // "pfv"
1443  _input++;
1444  mode = RZ_PRINT_VALUE | RZ_PRINT_MUSTSEE;
1445  break;
1446  case 'c': // "pfc"
1447  _input++;
1448  mode = RZ_PRINT_STRUCT;
1449  break;
1450  case 's': { // "pfs"
1451  const char *val = NULL;
1452  _input += 2;
1453  if (*_input == '.') {
1454  _input++;
1455  val = rz_type_db_format_get(core->analysis->typedb, _input);
1456  if (val) {
1458  } else {
1459  eprintf("Struct %s not defined\nUsage: pfs.struct_name | pfs format\n", _input);
1460  }
1461  } else if (*_input == ' ') {
1462  while (*_input == ' ' && *_input != '\0') {
1463  _input++;
1464  }
1465  if (*_input) {
1466  rz_cons_printf("%d\n", rz_type_format_struct_size(core->analysis->typedb, _input, mode, 0));
1467  } else {
1468  eprintf("Struct %s not defined\nUsage: pfs.struct_name | pfs format\n", _input);
1469  }
1470  } else {
1471  eprintf("Usage: pfs.struct_name | pfs format\n");
1472  }
1473  return;
1474  }
1475  case '?': // "pf?"
1476  _input += 2;
1477  if (*_input) {
1478  if (*_input == '?') {
1479  _input++;
1480  if (_input && *_input == '?') {
1481  _input++;
1482  if (_input && *_input == '?') {
1484  } else {
1486  }
1487  } else {
1489  }
1490  } else {
1491  const char *struct_name = rz_str_trim_head_ro(_input);
1492  const char *val = rz_type_db_format_get(core->analysis->typedb, struct_name);
1493  if (val) {
1494  rz_cons_printf("%s\n", val);
1495  } else {
1496  eprintf("Struct %s is not defined\n", _input);
1497  }
1498  }
1499  } else {
1501  }
1502  return;
1503  case 'o': // "pfo"
1504  if (_input[2] == '?') {
1505  char *prefix = rz_path_prefix(NULL);
1506  char *sdb_format = rz_path_home_prefix(RZ_SDB_FORMAT);
1507  eprintf("|Usage: pfo [format-file]\n"
1508  " %s\n"
1509  " " RZ_JOIN_3_PATHS("%s", RZ_SDB_FORMAT, "") "\n",
1510  sdb_format, prefix);
1511  free(sdb_format);
1512  free(prefix);
1513  } else if (_input[2] == ' ') {
1514  const char *fname = rz_str_trim_head_ro(_input + 3);
1515  char *home_formats = rz_path_home_prefix(RZ_SDB_FORMAT);
1516  char *home = rz_file_path_join(home_formats, fname);
1517  free(home_formats);
1518  char *system_formats = rz_path_system(RZ_SDB_FORMAT);
1519  char *path = rz_file_path_join(system_formats, fname);
1520  free(system_formats);
1521  if (rz_str_endswith(_input, ".h")) {
1522  char *error_msg = NULL;
1523  const char *dir = rz_config_get(core->config, "dir.types");
1524  int result = rz_type_parse_file(core->analysis->typedb, path, dir, &error_msg);
1525  if (!result) {
1526  rz_core_cmd0(core, ".ts*");
1527  } else {
1528  eprintf("Parse error: %s\n", error_msg);
1529  free(error_msg);
1530  }
1531  } else {
1532  if (!rz_core_cmd_file(core, home) && !rz_core_cmd_file(core, path)) {
1533  if (!rz_core_cmd_file(core, _input + 3)) {
1534  eprintf("pfo: cannot open format file at '%s'\n", path);
1535  }
1536  }
1537  }
1538  free(home);
1539  free(path);
1540  } else {
1541  RzList *files;
1542  RzListIter *iter;
1543  const char *fn;
1544  char *home = rz_path_home_prefix(RZ_SDB_FORMAT);
1545  if (home) {
1546  files = rz_sys_dir(home);
1547  rz_list_foreach (files, iter, fn) {
1548  if (*fn && *fn != '.') {
1550  }
1551  }
1553  free(home);
1554  }
1556  if (path) {
1557  files = rz_sys_dir(path);
1558  rz_list_foreach (files, iter, fn) {
1559  if (*fn && *fn != '.') {
1561  }
1562  }
1564  free(path);
1565  }
1566  }
1567  free(input);
1568  return;
1569  } // switch
1570 
1571  input = strdup(_input);
1572  /* syntax aliasing bridge for 'pf foo=xxd' -> 'pf.foo xxd' */
1573  if (input[1] == ' ') {
1574  char *eq = strchr(input + 2, '=');
1575  if (eq) {
1576  input[1] = '.';
1577  *eq = ' ';
1578  }
1579  }
1580 
1581  bool listFormats = false;
1582  if (input[1] == '.') {
1583  listFormats = true;
1584  } else if (!strcmp(input, "*") && mode == RZ_PRINT_SEEFLAGS) {
1585  listFormats = true;
1586  }
1587 
1588  core->print->reg = rz_core_reg_default(core);
1589  core->print->get_register = rz_reg_get;
1591 
1592  int o_blocksize = core->blocksize;
1593 
1594  if (listFormats) {
1595  core->print->num = core->num;
1596  /* print all stored format */
1597  if (!input[1] || !input[2]) { // "pf."
1598  RzListIter *iter;
1599  char *fmt = NULL;
1600  RzList *fmtl = rz_type_db_format_all(core->analysis->typedb);
1601  rz_list_foreach (fmtl, iter, fmt) {
1602  rz_cons_printf("pf.%s\n", fmt);
1603  }
1604  rz_list_free(fmtl);
1605  /* delete a format */
1606  } else if (input[1] && input[2] == '-') { // "pf-"
1607  if (input[3] == '*') { // "pf-*"
1609  } else { // "pf-xxx"
1611  }
1612  } else {
1613  char *name = strdup(input + (input[1] ? 2 : 1));
1614  char *space = strchr(name, ' ');
1615  char *eq = strchr(name, '=');
1616  char *dot = strchr(name, '.');
1617 
1618  if (eq && !dot) {
1619  *eq = ' ';
1620  space = eq;
1621  eq = NULL;
1622  }
1623 
1624  /* store a new format */
1625  if (space && (!eq || space < eq)) {
1626  *space++ = 0;
1627  if (strchr(name, '.')) {
1628  eprintf("Struct or fields name can not contain dot symbol (.)\n");
1629  } else {
1630  // pf.foo=xxx
1631  rz_type_db_format_set(core->analysis->typedb, name, space);
1632  }
1633  free(name);
1634  free(input);
1635  return;
1636  }
1637 
1638  if (!strchr(name, '.') &&
1640  eprintf("Cannot find '%s' format.\n", name);
1641  free(name);
1642  free(input);
1643  return;
1644  }
1645 
1646  char *delim = strchr(name, '.');
1647  if (delim) {
1648  int len = delim - name;
1649  if (len > 0) {
1650  name[len] = '\0';
1651  }
1652  }
1653 
1654  /* Load format from name into fmt to get the size */
1655  /* This make sure the whole structure will be printed */
1656  const char *fmt = NULL;
1657  fmt = rz_type_db_format_get(core->analysis->typedb, name);
1658  if (fmt) {
1659  int size = rz_type_format_struct_size(core->analysis->typedb, fmt, mode, 0) + 10;
1660  if (size > core->blocksize) {
1661  rz_core_block_size(core, size);
1662  }
1663  }
1664  /* display a format */
1665  if (dot) {
1666  *dot++ = 0;
1667  eq = strchr(dot, '=');
1668  if (eq) { // Write mode (pf.field=value)
1669  *eq++ = 0;
1670  mode = RZ_PRINT_MUSTSET;
1671  char *format = rz_type_format_data(core->analysis->typedb, core->print, core->offset,
1672  core->block, core->blocksize, name, mode, eq, dot);
1673  if (format) {
1674  rz_cons_print(format);
1675  free(format);
1676  }
1677  } else {
1678  char *format = rz_type_format_data(core->analysis->typedb, core->print, core->offset,
1679  core->block, core->blocksize, name, mode, NULL, dot);
1680  if (format) {
1681  rz_cons_print(format);
1682  free(format);
1683  }
1684  }
1685  } else {
1686  char *format = rz_type_format_data(core->analysis->typedb, core->print, core->offset,
1687  core->block, core->blocksize, name, mode, NULL, NULL);
1688  if (format) {
1689  rz_cons_print(format);
1690  free(format);
1691  }
1692  }
1693  free(name);
1694  }
1695  } else {
1696  /* This make sure the structure will be printed entirely */
1697  const char *fmt = rz_str_trim_head_ro(input + 1);
1698  int struct_sz = rz_type_format_struct_size(core->analysis->typedb, fmt, mode, 0);
1699  int size = RZ_MAX(core->blocksize, struct_sz);
1700  ut8 *buf = calloc(1, size);
1701  if (!buf) {
1702  eprintf("cannot allocate %d byte(s)\n", size);
1703  goto stage_left;
1704  }
1705  memcpy(buf, core->block, core->blocksize);
1706  /* check if fmt is '\d+ \d+<...>', common mistake due to usage string*/
1707  bool syntax_ok = true;
1708  char *args = strdup(fmt);
1709  if (!args) {
1710  rz_cons_printf("Error: Mem Allocation.");
1711  free(args);
1712  free(buf);
1713  goto stage_left;
1714  }
1715  const char *arg1 = strtok(args, " ");
1716  if (arg1 && rz_str_isnumber(arg1)) {
1717  syntax_ok = false;
1718  rz_cons_printf("Usage: pf [0|cnt][format-string]\n");
1719  }
1720  free(args);
1721  if (syntax_ok) {
1722  char *format = rz_type_format_data(core->analysis->typedb, core->print, core->offset,
1723  buf, size, fmt, mode, NULL, NULL);
1724  if (format) {
1725  rz_cons_print(format);
1726  free(format);
1727  }
1728  }
1729  free(buf);
1730  }
1731 stage_left:
1732  free(input);
1733  rz_core_block_size(core, o_blocksize);
1734 }
ut16 val
Definition: armass64_const.h:6
RZ_API int rz_type_parse_file(RzTypeDB *typedb, const char *path, const char *dir, char **error_msg)
Parses the C types file creating the new parser state.
Definition: c_cpp_parser.c:260
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API int rz_core_cmd_file(RzCore *core, const char *file)
Definition: cmd.c:5341
static const char * help_msg_pf[]
Definition: cmd_print.c:275
static const char * help_detail_pf[]
Definition: cmd_print.c:301
static const char * help_detail2_pf[]
Definition: cmd_print.c:342
static void print_format_help_help_help_help(RzCore *core)
Definition: cmd_print.c:1090
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
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
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void rz_type_db_format_set(RzTypeDB *typedb, const char *name, const char *fmt)
Definition: format.c:1912
RZ_API void rz_type_db_format_delete(RzTypeDB *typedb, const char *name)
Definition: format.c:1932
RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int mode, int n)
Definition: format.c:1515
RZ_API const char * rz_type_db_format_get(const RzTypeDB *typedb, const char *name)
Definition: format.c:1901
RZ_API RZ_OWN RzList * rz_type_db_format_all(RzTypeDB *typedb)
Definition: format.c:1925
RZ_API RZ_OWN char * rz_type_format_data(const RzTypeDB *typedb, RzPrint *p, ut64 seek, const ut8 *b, const int len, const char *formatname, int mode, const char *setval, char *ofield)
Definition: format.c:2749
unsigned short prefix[65536]
Definition: gun.c:163
voidpf void uLong size
Definition: ioapi.h:138
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
int args
Definition: mipsasm.c:18
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API RZ_OWN char * rz_path_home_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the home prefix.
Definition: path.c:182
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
RZ_API RZ_OWN char * rz_path_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the Rizin install prefix.
Definition: path.c:121
RZ_API bool rz_str_isnumber(const char *str)
Definition: str.c:3550
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216
#define RZ_JOIN_3_PATHS(p1, p2, p3)
Definition: rz_types.h:225
#define RZ_SDB_FORMAT
Definition: rz_userconf.h:87
RzTypeDB * typedb
Definition: rz_analysis.h:602
ut64(* get_register_value)(RzReg *reg, RzRegItem *item)
Definition: rz_print.h:159
RzRegItem *(* get_register)(RzReg *reg, const char *name, int type)
Definition: rz_print.h:158
RzReg * reg
Definition: rz_print.h:157
RZ_API void rz_type_db_format_purge(RzTypeDB *typedb)
Purges formats in the instance of the RzTypeDB.
Definition: type.c:108

References rz_core_t::analysis, args, rz_core_t::block, rz_core_t::blocksize, calloc(), rz_core_t::config, eprintf, eq, files, fn, create_tags_rz::fname, free(), rz_print_t::get_register, rz_print_t::get_register_value, help_detail2_pf, help_detail_pf, help_msg_pf, input(), len, memcpy(), name, NULL, rz_core_t::num, rz_print_t::num, rz_core_t::offset, path, prefix, rz_core_t::print, print_format_help_help_help_help(), rz_print_t::reg, rz_config_get(), rz_cons_printf(), rz_cons_println(), rz_core_block_size(), rz_core_cmd0(), rz_core_cmd_file(), rz_core_cmd_help(), rz_core_reg_default(), rz_file_path_join(), RZ_JOIN_3_PATHS, rz_list_free(), RZ_MAX, rz_path_home_prefix(), rz_path_prefix(), rz_path_system(), rz_reg_get(), rz_reg_get_value(), RZ_SDB_FORMAT, rz_str_endswith(), rz_str_isnumber(), rz_str_trim_head_ro(), rz_sys_dir(), rz_type_db_format_all(), rz_type_db_format_delete(), rz_type_db_format_get(), rz_type_db_format_purge(), rz_type_db_format_set(), rz_type_format_data(), rz_type_format_struct_size(), rz_type_parse_file(), strdup(), rz_analysis_t::typedb, and val.

Referenced by rz_cmd_print().

◆ cmd_print_fromage()

static void cmd_print_fromage ( RzCore core,
const char *  input,
const ut8 data,
int  size 
)
static

Definition at line 1098 of file cmd_print.c.

1098  {
1099  switch (*input) {
1100  case 'a': {
1101  asn1_setformat(input[1] != 'q');
1102  RASN1Object *asn1 = rz_asn1_create_object(data, size, data);
1103  if (asn1) {
1104  char *res = rz_asn1_to_string(asn1, 0, NULL);
1105  rz_asn1_free_object(asn1);
1106  if (res) {
1107  rz_cons_printf("%s\n", res);
1108  free(res);
1109  }
1110  } else {
1111  eprintf("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n");
1112  }
1113  } break;
1114  case 'x': // "pFx" x509
1115  {
1117  if (x509) {
1118  RzStrBuf *sb = rz_strbuf_new("");
1120  char *res = rz_strbuf_drain(sb);
1121  if (res) {
1122  rz_cons_printf("%s\n", res);
1123  free(res);
1124  }
1126  } else {
1127  eprintf("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n");
1128  }
1129  } break;
1130  case 'p': // "pFp"
1131  {
1132  RCMS *cms = rz_pkcs7_parse_cms(data, size);
1133  if (cms) {
1134  char *res = rz_pkcs7_cms_to_string(cms);
1135  if (res) {
1136  rz_cons_printf("%s\n", res);
1137  free(res);
1138  }
1139  rz_pkcs7_free_cms(cms);
1140  } else {
1141  eprintf("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n");
1142  }
1143  } break;
1144  case 'b': // "pFb"
1145  {
1146  char *s = rz_protobuf_decode(data, size, input[1] == 'v');
1147  if (s) {
1148  rz_cons_printf("%s", s);
1149  free(s);
1150  }
1151  } break;
1152  case 'A': // "pFA"
1153  {
1154  char *s = rz_axml_decode(data, size);
1155  if (s) {
1156  rz_cons_printf("%s", s);
1157  free(s);
1158  } else {
1159  eprintf("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n");
1160  }
1161  } break;
1162  default:
1163  case '?': // "pF?"
1165  break;
1166  }
1167 }
static const char * help_msg_pF[]
Definition: cmd_print.c:56
RZ_API char * rz_asn1_to_string(RASN1Object *object, ut32 depth, RzStrBuf *sb)
Definition: asn1.c:259
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
RZ_API void asn1_setformat(int fmt)
Definition: asn1.c:12
RZ_API RASN1Object * rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer)
Definition: asn1.c:120
RZ_API RZ_OWN char * rz_axml_decode(RZ_NONNULL const ut8 *buffer, const ut64 size)
Decode a buffer with Android XML to regular XML string representation.
Definition: axml.c:303
RZ_API RCMS * rz_pkcs7_parse_cms(const ut8 *buffer, ut32 length)
Definition: pkcs7.c:308
RZ_API void rz_pkcs7_free_cms(RCMS *container)
Definition: pkcs7.c:341
RZ_API char * rz_pkcs7_cms_to_string(RCMS *container)
Definition: pkcs7.c:479
RZ_API char * rz_protobuf_decode(const ut8 *buffer, const ut64 size, bool debug)
Definition: protobuf.c:146
RZ_API void rz_x509_free_certificate(RX509Certificate *certificate)
Definition: x509.c:387
RZ_API RX509Certificate * rz_x509_parse_certificate(RASN1Object *object)
Definition: x509.c:217
RZ_API void rz_x509_certificate_dump(RX509Certificate *cert, const char *pad, RzStrBuf *sb)
Definition: x509.c:546

References asn1_setformat(), eprintf, free(), help_msg_pF, input(), NULL, rz_asn1_create_object(), rz_asn1_free_object(), rz_asn1_to_string(), rz_axml_decode(), rz_cons_printf(), rz_core_cmd_help(), rz_pkcs7_cms_to_string(), rz_pkcs7_free_cms(), rz_pkcs7_parse_cms(), rz_protobuf_decode(), rz_strbuf_drain(), rz_strbuf_new(), rz_x509_certificate_dump(), rz_x509_free_certificate(), rz_x509_parse_certificate(), s, and sb.

Referenced by rz_cmd_print().

◆ cmd_print_gadget()

static void cmd_print_gadget ( RzCore core,
const char *  _input 
)
static

Definition at line 1260 of file cmd_print.c.

1260  {
1261  if (*_input == '?') { // "pg?"
1263  return;
1264  }
1265  if (*_input == '-') { // "pg-"
1266  // TODO support selecting one
1267  rz_list_free(core->gadgets);
1269  } else if (*_input == '*') { // "pg*"
1270  RzCoreGadget *g;
1271  RzListIter *iter;
1272  rz_list_foreach (core->gadgets, iter, g) {
1273  rz_cons_printf("\"pg %d %d %d %d %s\"\n", g->x, g->y, g->w, g->h, g->cmd);
1274  }
1275  } else if (*_input == 'b') { // "pgb"
1276  eprintf("TODO: Change gadget background color\n");
1277  } else if (*_input == 'm') { // "pgm"
1278  int nth = atoi(_input + 1);
1279  RzCoreGadget *g = rz_list_get_n(core->gadgets, nth);
1280  if (g) {
1281  char *input = strdup(_input);
1282  char *space = strchr(input, ' ');
1283  if (space) {
1284  space++;
1285  } else {
1286  space = "";
1287  }
1288  RzList *args = rz_str_split_list(space, " ", 0);
1289  char *x = rz_list_pop_head(args);
1290  char *y = rz_list_pop_head(args);
1291  char *w = rz_list_pop_head(args);
1292  char *h = rz_list_pop_head(args);
1293  if (x && y && w && h) {
1294  g->x = rz_num_math(core->num, x);
1295  g->y = rz_num_math(core->num, y);
1296  g->w = rz_num_math(core->num, w);
1297  g->h = rz_num_math(core->num, h);
1298  }
1299  rz_list_free(args);
1300  free(input);
1301  }
1302  } else if (*_input == ' ') { // "pg "
1303  char *input = strdup(_input);
1304  RzList *args = rz_str_split_list(input, " ", 0);
1305  char *x = rz_list_pop_head(args);
1306  char *y = rz_list_pop_head(args);
1307  char *w = rz_list_pop_head(args);
1308  char *h = rz_list_pop_head(args);
1309  if (x && y && w && h) {
1310  int X = rz_num_math(core->num, x);
1311  int Y = rz_num_math(core->num, y);
1312  int W = rz_num_math(core->num, w);
1313  int H = rz_num_math(core->num, h);
1314  char *cmd = rz_str_list_join(args, " ");
1315  if (cmd) {
1316  // eprintf ("%d %d %d %d (%s)\n", X, Y, W, H, cmd);
1318  g->x = X;
1319  g->y = Y;
1320  g->w = W;
1321  g->h = H;
1322  g->cmd = cmd;
1323  rz_list_append(core->gadgets, g);
1324  }
1325  }
1326  rz_list_free(args);
1327  free(input);
1328  } else if (!*_input) { // "pg"
1329  rz_core_gadget_print(core);
1330  } else {
1332  }
1333 }
#define X(x, b, m)
#define W(x, y, z)
#define H(x)
static const char * help_msg_pg[]
Definition: cmd_print.c:1197
RZ_API void rz_core_gadget_free(RzCoreGadget *g)
Frees a visual print gadget.
Definition: cmd_print.c:1174
RZ_API void rz_core_gadget_print(RzCore *core)
Prints or displays the print gadgets while in visual mode.
Definition: cmd_print.c:1185
struct @667 g
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API RZ_OWN void * rz_list_pop_head(RZ_NONNULL RzList *list)
Removes and returns the first element of the list.
Definition: list.c:401
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
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API RzList * rz_str_split_list(char *str, const char *c, int n)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3429
RZ_API char * rz_str_list_join(RzList *str, const char *sep)
Definition: str.c:3849
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzList * gadgets
Definition: rz_core.h:384

References args, cmd, eprintf, free(), g, rz_core_t::gadgets, h, H, help_msg_pg, input(), rz_core_t::num, rz_cons_printf(), rz_core_cmd_help(), rz_core_gadget_free(), rz_core_gadget_print(), rz_list_append(), rz_list_free(), rz_list_get_n(), rz_list_newf(), rz_list_pop_head(), RZ_NEW0, rz_num_math(), rz_str_list_join(), rz_str_split_list(), strdup(), W, w, X, and x.

Referenced by rz_cmd_print().

◆ cmd_print_op()

static void cmd_print_op ( RzCore core,
const char *  input 
)
static

Definition at line 2514 of file cmd_print.c.

2514  {
2515  ut8 *buf;
2516  int buflen = -1;
2517 
2518  if (!input[0])
2519  return;
2520  switch (input[1]) {
2521  case 'a':
2522  case 's':
2523  case 'A':
2524  case 'x':
2525  case 'r':
2526  case 'l':
2527  case 'm':
2528  case 'd':
2529  case 'o':
2530  case '2':
2531  case '4':
2532  if (input[2]) { // parse val from arg
2533  buf = old_transform_op(core, input + 3, input[1], &buflen);
2534  } else { // use clipboard instead of val
2535  buf = old_transform_op(core, NULL, input[1], &buflen);
2536  }
2537  break;
2538  case 'n':
2539  buf = old_transform_op(core, "ff", 'x', &buflen);
2540  break;
2541  case '\0':
2542  case '?':
2543  default:
2545  return;
2546  }
2547  if (buf) {
2548  rz_core_print_hexdump(core, core->offset, buf,
2549  buflen, 16, 1, 1);
2550  free(buf);
2551  }
2552 }
static ut8 * old_transform_op(RzCore *core, const char *val, char op, int *buflen)
Definition: cmd_print.c:2453
static const char * help_msg_po[]
Definition: cmd_print.c:401
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
ut64 buflen
Definition: core.c:76

References buflen, free(), help_msg_po, input(), NULL, rz_core_t::offset, old_transform_op(), rz_core_cmd_help(), and rz_core_print_hexdump().

Referenced by rz_cmd_print().

◆ cmd_print_pv()

static void cmd_print_pv ( RzCore core,
const char *  input,
bool  useBytes 
)
static

Definition at line 2986 of file cmd_print.c.

2986  {
2987  const char *stack[] = {
2988  "ret", "arg0", "arg1", "arg2", "arg3", "arg4", NULL
2989  };
2990  ut8 *block = core->block;
2991  int blocksize = core->blocksize;
2992  ut8 *block_end = core->block + blocksize;
2993  int i, n = core->rasm->bits / 8;
2994  int type = 'v';
2995  bool fixed_size = true;
2996  switch (input[0]) {
2997  case '1': // "pv1"
2998  n = 1;
2999  input++;
3000  break;
3001  case '2': // "pv2"
3002  n = 2;
3003  input++;
3004  break;
3005  case '4': // "pv4"
3006  n = 4;
3007  input++;
3008  break;
3009  case '8': // "pv8"
3010  n = 8;
3011  input++;
3012  break;
3013  default:
3014  if (*input && input[1] == 'j') {
3015  input++;
3016  }
3017  fixed_size = false;
3018  break;
3019  }
3020  const char *arg = strchr(input, ' ');
3021  if (arg) {
3022  arg = rz_str_trim_head_ro(arg + 1);
3023  } else {
3024  arg = input;
3025  }
3026  st64 repeat = rz_num_math(core->num, arg);
3027  if (repeat < 0) {
3028  repeat = 1;
3029  }
3030  if (useBytes && n > 0 && repeat > 0) {
3031  repeat /= n;
3032  }
3033  if (repeat < 1) {
3034  repeat = 1;
3035  }
3036  // variables can be
3037  switch (input[0]) {
3038  case 'z': // "pvz"
3039  type = 'z';
3040  if (input[1]) {
3041  input++;
3042  } else {
3043  rz_core_cmdf(core, "ps");
3044  break;
3045  }
3046  /* fallthrough */
3047  // case ' ': // "pv "
3048  for (i = 0; stack[i]; i++) {
3049  if (!strcmp(input + 1, stack[i])) {
3050  if (type == 'z') {
3051  rz_core_cmdf(core, "ps @ [`drn sp`+%d]", n * i);
3052  } else {
3053  rz_core_cmdf(core, "?v [`drn sp`+%d]", n * i);
3054  }
3055  }
3056  }
3057  break;
3058  case '*': { // "pv*"
3059  for (i = 0; i < repeat; i++) {
3060  const bool be = core->print->big_endian;
3061  ut64 at = core->offset + (i * n);
3062  ut8 *b = block + (i * n);
3063  switch (n) {
3064  case 1:
3065  rz_cons_printf("f pval.0x%08" PFMT64x " @ %d\n", at, rz_read_ble8(b));
3066  break;
3067  case 2:
3068  rz_cons_printf("f pval.0x%08" PFMT64x " @ %d\n", at, rz_read_ble16(b, be));
3069  break;
3070  case 4:
3071  rz_cons_printf("f pval.0x%08" PFMT64x " @ %d\n", at, rz_read_ble32(b, be));
3072  break;
3073  case 8:
3074  default:
3075  rz_cons_printf("f pval.0x%08" PFMT64x " @ %" PFMT64d "\n", at, rz_read_ble64(b, be));
3076  break;
3077  }
3078  }
3079  break;
3080  }
3081  case 'j': { // "pvj"
3082  PJ *pj = pj_new();
3083  if (!pj) {
3084  return;
3085  }
3086  pj_a(pj);
3087  ut64 at = core->offset;
3088  ut64 oldAt = at;
3089  for (i = 0; i < repeat; i++) {
3090  rz_core_seek(core, at, false);
3091  char *str = rz_core_cmd_str(core, "ps");
3092  rz_str_trim(str);
3093  char *p = str;
3094  if (p) {
3095  while (*p) {
3096  if (*p == '\\' && p[1] == 'x') {
3097  memmove(p, p + 4, strlen(p + 4) + 1);
3098  }
3099  p++;
3100  }
3101  }
3102  // rz_num_get is going to use a dangling pointer since the internal
3103  // token that RzNum holds ([$$]) has been already freed by rz_core_cmd_str
3104  // rz_num_math reloads a new token so the dangling pointer is gone
3105  pj_o(pj);
3106  pj_k(pj, "value");
3107  switch (n) {
3108  case 1:
3109  pj_i(pj, rz_read_ble8(block));
3110  break;
3111  case 2:
3112  pj_i(pj, rz_read_ble16(block, core->print->big_endian));
3113  break;
3114  case 4:
3115  pj_n(pj, (ut64)rz_read_ble32(block, core->print->big_endian));
3116  break;
3117  case 8:
3118  default:
3119  pj_n(pj, rz_read_ble64(block, core->print->big_endian));
3120  break;
3121  }
3122  pj_ks(pj, "string", str);
3123  pj_end(pj);
3124  free(str);
3125  at += n;
3126  }
3127  pj_end(pj);
3129  pj_free(pj);
3130  rz_core_seek(core, oldAt, false);
3131  break;
3132  }
3133  case '?': // "pv?"
3135  break;
3136  default:
3137  do {
3138  repeat--;
3139  if (block + 8 >= block_end) {
3140  eprintf("Truncated. TODO: use rz_io_read apis insgtead of depending on blocksize\n");
3141  break;
3142  }
3143  ut64 v;
3144  if (!fixed_size) {
3145  n = 0;
3146  }
3147  switch (n) {
3148  case 1:
3149  v = rz_read_ble8(block);
3150  rz_cons_printf("0x%02" PFMT64x "\n", v);
3151  block += 1;
3152  break;
3153  case 2:
3154  v = rz_read_ble16(block, core->print->big_endian);
3155  rz_cons_printf("0x%04" PFMT64x "\n", v);
3156  block += 2;
3157  break;
3158  case 4:
3159  v = rz_read_ble32(block, core->print->big_endian);
3160  rz_cons_printf("0x%08" PFMT64x "\n", v);
3161  block += 4;
3162  break;
3163  case 8:
3164  v = rz_read_ble64(block, core->print->big_endian);
3165  rz_cons_printf("0x%016" PFMT64x "\n", v);
3166  block += 8;
3167  break;
3168  default:
3169  v = rz_read_ble64(block, core->print->big_endian);
3170  switch (core->rasm->bits / 8) {
3171  case 1: rz_cons_printf("0x%02" PFMT64x "\n", v & UT8_MAX); break;
3172  case 2: rz_cons_printf("0x%04" PFMT64x "\n", v & UT16_MAX); break;
3173  case 4: rz_cons_printf("0x%08" PFMT64x "\n", v & UT32_MAX); break;
3174  case 8: rz_cons_printf("0x%016" PFMT64x "\n", v & UT64_MAX); break;
3175  default: break;
3176  }
3177  block += core->rasm->bits / 8;
3178  break;
3179  }
3180  } while (repeat > 0);
3181  break;
3182  }
3183 }
static const char * help_msg_pv[]
Definition: cmd_print.c:435
const char * v
Definition: dsignal.c:12
static void repeat(struct parse *, sopno, int, int)
Definition: regcomp.c:1155
static ut64 rz_read_ble64(const void *src, bool big_endian)
Definition: rz_endian.h:501
static ut8 rz_read_ble8(const void *src)
Definition: rz_endian.h:12
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
RZ_API PJ * pj_i(PJ *j, int d)
Definition: pj.c:284
RZ_API PJ * pj_n(PJ *j, ut64 n)
Definition: pj.c:252
#define UT8_MAX
int bits
Definition: rz_asm.h:100
int big_endian
Definition: rz_print.h:124
Definition: z80asm.h:140

References b, rz_print_t::big_endian, rz_asm_t::bits, rz_core_t::block, blocksize, rz_core_t::blocksize, eprintf, free(), help_msg_pv, i, input(), n, NULL, rz_core_t::num, rz_core_t::offset, p, PFMT64d, PFMT64x, pj_a(), pj_end(), pj_free(), pj_i(), pj_k(), pj_ks(), pj_n(), pj_new(), pj_o(), pj_string(), rz_core_t::print, rz_core_t::rasm, repeat(), rz_cons_printf(), rz_cons_println(), rz_core_cmd_help(), rz_core_cmd_str(), rz_core_cmdf(), rz_core_seek(), rz_num_math(), rz_read_ble16(), rz_read_ble32(), rz_read_ble64(), rz_read_ble8(), rz_str_trim(), rz_str_trim_head_ro(), st64, cmd_descs_generate::str, type, UT16_MAX, UT32_MAX, ut64(), UT64_MAX, UT8_MAX, and v.

Referenced by rz_cmd_print().

◆ cmd_print_pxA()

static bool cmd_print_pxA ( RzCore core,
int  len,
RzOutputMode  mode 
)
static

Definition at line 2175 of file cmd_print.c.

2175  {
2176  if (!len) {
2177  return true;
2178  }
2179  RzConsPrintablePalette *pal = &core->cons->context->pal;
2180  int show_offset = true;
2181  int cols = rz_config_get_i(core->config, "hex.cols");
2182  int show_color = rz_config_get_i(core->config, "scr.color");
2183  int onechar = rz_config_get_i(core->config, "hex.onechar");
2184  bool hex_offset = rz_config_get_i(core->config, "hex.offset");
2185  int bgcolor_in_heap = false;
2186  bool show_cursor = core->print->cur_enabled;
2187  char buf[2];
2188  char *bgcolor, *fgcolor, *text;
2189  ut64 i, c, oi;
2190  RzAnalysisOp op;
2191  ut8 *data;
2192  int datalen;
2193  switch (mode) {
2194  case RZ_OUTPUT_MODE_LONG:
2195  datalen = cols * 8 * core->cons->rows;
2196  data = malloc(datalen);
2197  rz_io_read_at(core->io, core->offset, data, datalen);
2198  len = datalen;
2199  break;
2201  data = core->block;
2202  datalen = core->blocksize;
2203  break;
2204  default:
2206  return false;
2207  }
2208  if (len < 1) {
2209  len = datalen;
2210  }
2211  if (len < 0 || len > datalen) {
2212  eprintf("Invalid length\n");
2213  return false;
2214  }
2215  if (onechar) {
2216  cols *= 4;
2217  } else {
2218  cols *= 2;
2219  }
2220  if (show_offset) {
2221  char offstr[128];
2222  snprintf(offstr, sizeof(offstr),
2223  "0x%08" PFMT64x " ", core->offset);
2224  if (strlen(offstr) > 12) {
2225  cols -= ((strlen(offstr) - 12) * 2);
2226  }
2227  }
2228  for (oi = i = c = 0; i < len; c++) {
2229  if (i && (cols != 0) && !(c % cols)) {
2230  show_offset = true;
2231  rz_cons_printf(" %" PFMT64u "\n", i - oi);
2232  oi = i;
2233  }
2234  if (show_offset && hex_offset) {
2235  rz_cons_printf("0x%08" PFMT64x " ", core->offset + i);
2236  show_offset = false;
2237  }
2238  if (bgcolor_in_heap) {
2239  free(bgcolor);
2240  bgcolor_in_heap = false;
2241  }
2242  bgcolor = Color_BGBLACK;
2243  fgcolor = Color_WHITE;
2244  text = NULL;
2245  if (rz_analysis_op(core->analysis, &op, core->offset + i, data + i, len - i, RZ_ANALYSIS_OP_MASK_BASIC) <= 0) {
2246  op.type = 0;
2247  bgcolor = Color_BGRED;
2248  op.size = 1;
2249  }
2250  switch (op.type) {
2256  text = "mv";
2257  bgcolor = pal->mov;
2258  fgcolor = Color_YELLOW;
2259  break;
2263  bgcolor = pal->push;
2264  fgcolor = Color_WHITE;
2265  text = "->";
2266  break;
2268  bgcolor = pal->swi;
2269  fgcolor = Color_WHITE;
2270  text = "io";
2271  break;
2275  // bgcolor = Color_BGRED;
2276  bgcolor = pal->trap; // rz_cons_swap_ground (pal->trap);
2277  fgcolor = Color_WHITE;
2278  text = "$$";
2279  break;
2281  text = "<-";
2282  bgcolor = rz_cons_swap_ground(pal->pop);
2283  bgcolor_in_heap = true;
2284  fgcolor = Color_WHITE;
2285  break;
2287  fgcolor = Color_WHITE;
2288  bgcolor = rz_cons_swap_ground(pal->nop);
2289  bgcolor_in_heap = true;
2290  text = "..";
2291  break;
2293  fgcolor = Color_BLACK;
2294  bgcolor = rz_cons_swap_ground(pal->math);
2295  bgcolor_in_heap = true;
2296  text = "_*";
2297  break;
2299  bgcolor = rz_cons_swap_ground(pal->math);
2300  bgcolor_in_heap = true;
2301  fgcolor = Color_BLACK;
2302  text = "_/";
2303  break;
2305  bgcolor = rz_cons_swap_ground(pal->bin);
2306  bgcolor_in_heap = true;
2307  fgcolor = Color_BLACK;
2308  text = "_&";
2309  break;
2311  bgcolor = rz_cons_swap_ground(pal->bin);
2312  bgcolor_in_heap = true;
2313  fgcolor = Color_BLACK;
2314  text = "_^";
2315  break;
2317  bgcolor = rz_cons_swap_ground(pal->bin);
2318  bgcolor_in_heap = true;
2319  fgcolor = Color_BLACK;
2320  text = "_|";
2321  break;
2323  bgcolor = rz_cons_swap_ground(pal->bin);
2324  bgcolor_in_heap = true;
2325  fgcolor = Color_BLACK;
2326  text = ">>";
2327  break;
2329  bgcolor = rz_cons_swap_ground(pal->bin);
2330  bgcolor_in_heap = true;
2331  fgcolor = Color_BLACK;
2332  text = "<<";
2333  break;
2335  bgcolor = rz_cons_swap_ground(pal->math);
2336  bgcolor_in_heap = true;
2337  fgcolor = Color_WHITE;
2338  text = "--";
2339  break;
2341  bgcolor = rz_cons_swap_ground(pal->math);
2342  bgcolor_in_heap = true;
2343  fgcolor = Color_WHITE;
2344  text = "++";
2345  break;
2352  bgcolor = rz_cons_swap_ground(pal->jmp);
2353  bgcolor_in_heap = true;
2354  fgcolor = Color_BLACK;
2355  text = "_J";
2356  break;
2359  bgcolor = rz_cons_swap_ground(pal->cjmp);
2360  bgcolor_in_heap = true;
2361  fgcolor = Color_BLACK;
2362  text = "cJ";
2363  break;
2370  bgcolor = rz_cons_swap_ground(pal->call);
2371  bgcolor_in_heap = true;
2372  fgcolor = Color_WHITE;
2373  text = "_C";
2374  break;
2377  bgcolor = rz_cons_swap_ground(pal->cmp);
2378  bgcolor_in_heap = true;
2379  fgcolor = Color_BLACK;
2380  text = "==";
2381  break;
2383  bgcolor = rz_cons_swap_ground(pal->ret);
2384  bgcolor_in_heap = true;
2385  fgcolor = Color_WHITE;
2386  text = "_R";
2387  break;
2388  case -1:
2391  bgcolor = rz_cons_swap_ground(pal->invalid);
2392  bgcolor_in_heap = true;
2393  fgcolor = Color_WHITE;
2394  text = "XX";
2395  break;
2396 #if 0
2397  default:
2398  color = Color_BGCYAN;
2399  fgcolor = Color_BLACK;
2400  break;
2401 #endif
2402  }
2403  int opsz = RZ_MAX(op.size, 1);
2404  if (show_cursor) {
2405  if (core->print->cur >= i && core->print->cur < i + opsz) {
2406  rz_cons_invert(1, 1);
2407  }
2408  }
2409  if (onechar) {
2410  if (text) {
2411  if (text[0] == '_' || text[0] == '.') {
2412  buf[0] = text[1];
2413  } else {
2414  buf[0] = text[0];
2415  }
2416  } else {
2417  buf[0] = '.';
2418  }
2419  buf[1] = 0;
2420  text = buf;
2421  }
2422  if (show_color) {
2423  if (!text) {
2424  text = " ";
2425  }
2426  rz_cons_printf("%s%s%s\x1b[0m", bgcolor, fgcolor, text);
2427  } else {
2428  if (text) {
2429  rz_cons_print(text);
2430  } else {
2431  rz_cons_print(" ");
2432  }
2433  }
2434  if (show_cursor) {
2435  if (core->print->cur >= i && core->print->cur < i + opsz) {
2436  rz_cons_invert(0, 1);
2437  }
2438  }
2439  i += opsz;
2441  }
2442  rz_cons_printf(" %" PFMT64d "\n", i - oi);
2443  if (bgcolor_in_heap) {
2444  free(bgcolor);
2445  }
2446  if (data != core->block) {
2447  free(data);
2448  }
2449 
2450  return true;
2451 }
ut8 op
Definition: 6502dis.c:13
RZ_API void rz_cons_invert(int set, int color)
Definition: cons.c:1662
RZ_API char * rz_cons_swap_ground(const char *col)
Definition: cons.c:1871
snprintf
Definition: kernel.h:364
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
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_ICALL
Definition: rz_analysis.h:381
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_MUL
Definition: rz_analysis.h:404
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UPUSH
Definition: rz_analysis.h:395
@ RZ_ANALYSIS_OP_TYPE_RPUSH
Definition: rz_analysis.h:396
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_IJMP
Definition: rz_analysis.h:371
@ RZ_ANALYSIS_OP_TYPE_IO
Definition: rz_analysis.h:403
@ RZ_ANALYSIS_OP_TYPE_UCCALL
Definition: rz_analysis.h:384
@ RZ_ANALYSIS_OP_TYPE_MJMP
Definition: rz_analysis.h:375
@ RZ_ANALYSIS_OP_TYPE_CMOV
Definition: rz_analysis.h:391
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_PUSH
Definition: rz_analysis.h:397
@ RZ_ANALYSIS_OP_TYPE_SHR
Definition: rz_analysis.h:406
@ RZ_ANALYSIS_OP_TYPE_IRJMP
Definition: rz_analysis.h:372
@ RZ_ANALYSIS_OP_TYPE_POP
Definition: rz_analysis.h:398
@ RZ_ANALYSIS_OP_TYPE_RJMP
Definition: rz_analysis.h:370
@ RZ_ANALYSIS_OP_TYPE_DIV
Definition: rz_analysis.h:405
@ RZ_ANALYSIS_OP_TYPE_CAST
Definition: rz_analysis.h:426
@ RZ_ANALYSIS_OP_TYPE_UCJMP
Definition: rz_analysis.h:377
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_SHL
Definition: rz_analysis.h:407
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
@ RZ_ANALYSIS_OP_TYPE_ACMP
Definition: rz_analysis.h:400
@ RZ_ANALYSIS_OP_TYPE_LEA
Definition: rz_analysis.h:417
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
@ RZ_ANALYSIS_OP_TYPE_NEW
Definition: rz_analysis.h:427
@ RZ_ANALYSIS_OP_TYPE_LENGTH
Definition: rz_analysis.h:425
@ RZ_ANALYSIS_OP_TYPE_IRCALL
Definition: rz_analysis.h:382
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define Color_WHITE
Definition: rz_cons.h:625
#define Color_BGBLACK
Definition: rz_cons.h:622
#define Color_YELLOW
Definition: rz_cons.h:631
#define Color_BGCYAN
Definition: rz_cons.h:634
#define Color_BLACK
Definition: rz_cons.h:621
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
int rows
Definition: rz_cons.h:508

References rz_core_t::analysis, rz_cons_printable_palette_t::bin, rz_core_t::block, rz_core_t::blocksize, c, rz_cons_printable_palette_t::call, rz_cons_printable_palette_t::cjmp, rz_cons_printable_palette_t::cmp, color, Color_BGBLACK, Color_BGCYAN, Color_BGRED, Color_BLACK, Color_WHITE, Color_YELLOW, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, rz_print_t::cur, rz_print_t::cur_enabled, eprintf, free(), i, rz_cons_printable_palette_t::invalid, rz_core_t::io, rz_cons_printable_palette_t::jmp, len, malloc(), rz_cons_printable_palette_t::math, rz_cons_printable_palette_t::mov, rz_cons_printable_palette_t::nop, NULL, rz_core_t::offset, op, rz_cons_context_t::pal, PFMT64d, PFMT64u, PFMT64x, rz_cons_printable_palette_t::pop, rz_core_t::print, rz_cons_printable_palette_t::push, rz_cons_printable_palette_t::ret, rz_cons_t::rows, rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_TYPE_ACMP, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CAST, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMOV, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_DIV, RZ_ANALYSIS_OP_TYPE_ICALL, RZ_ANALYSIS_OP_TYPE_IJMP, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_IO, RZ_ANALYSIS_OP_TYPE_IRCALL, RZ_ANALYSIS_OP_TYPE_IRJMP, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LEA, RZ_ANALYSIS_OP_TYPE_LENGTH, RZ_ANALYSIS_OP_TYPE_MJMP, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NEW, RZ_ANALYSIS_OP_TYPE_NOP, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_POP, RZ_ANALYSIS_OP_TYPE_PUSH, RZ_ANALYSIS_OP_TYPE_RCALL, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_RJMP, RZ_ANALYSIS_OP_TYPE_RPUSH, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_SWI, RZ_ANALYSIS_OP_TYPE_TRAP, RZ_ANALYSIS_OP_TYPE_UCALL, RZ_ANALYSIS_OP_TYPE_UCCALL, RZ_ANALYSIS_OP_TYPE_UCJMP, RZ_ANALYSIS_OP_TYPE_UJMP, RZ_ANALYSIS_OP_TYPE_UNK, RZ_ANALYSIS_OP_TYPE_UPUSH, RZ_ANALYSIS_OP_TYPE_XOR, rz_config_get_i(), rz_cons_invert(), rz_cons_printf(), rz_cons_swap_ground(), rz_io_read_at(), RZ_MAX, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, snprintf, rz_cons_printable_palette_t::swi, create_tags_rz::text, rz_cons_printable_palette_t::trap, and ut64().

Referenced by rz_print_op_analysis_color_map_handler().

◆ cmd_pxb_k()

static int cmd_pxb_k ( const ut8 buffer,
int  x 
)
inlinestatic

Definition at line 4369 of file cmd_print.c.

4369  {
4370  return buffer[3 - x] << (8 * x);
4371 }
Definition: buffer.h:15

References x.

Referenced by rz_print_hexdump_bits_handler().

◆ cmd_pxb_p()

static char cmd_pxb_p ( char  input)
inlinestatic

Definition at line 4365 of file cmd_print.c.

4365  {
4366  return IS_PRINTABLE(input) ? input : '.';
4367 }

References input(), and IS_PRINTABLE.

Referenced by rz_print_hexdump_bits_handler().

◆ cmd_pxr()

static bool cmd_pxr ( RzCore core,
int  len,
RzCmdStateOutput state,
int  wordsize,
const char *  query 
)
static

Definition at line 4472 of file cmd_print.c.

4472  {
4473  if (!len) {
4474  return true;
4475  }
4477  if (!sb) {
4478  return false;
4479  }
4480 
4481  const ut8 *buf = core->block;
4482 
4483  bool be = core->analysis->big_endian;
4484  int end = RZ_MIN(core->blocksize, len);
4485  int bitsize = wordsize * 8;
4486  RzOutputMode mode = state->mode;
4487  if (mode == RZ_OUTPUT_MODE_TABLE) {
4488  RzTable *t = state->d.t;
4489  RzTableColumnType *n = rz_table_type("number");
4490  RzTableColumnType *s = rz_table_type("string");
4491  rz_table_add_column(t, n, "addr", 0);
4492  rz_table_add_column(t, n, "value", 0);
4493  rz_table_add_column(t, s, "refs", 0);
4494  for (ut64 i = 0; i + wordsize < end; i += wordsize) {
4495  ut64 addr = core->offset + i;
4496  ut64 val = rz_read_ble(buf + i, be, bitsize);
4497  char *refs = __refs(core, val);
4498  rz_table_add_rowf(t, "xxs", addr, val, refs);
4499  RZ_FREE(refs);
4500  }
4501  rz_table_query(t, query);
4502  } else if (mode == RZ_OUTPUT_MODE_JSON) {
4503  PJ *pj = state->d.pj;
4504  const int hex_depth = (int)rz_config_get_i(core->config, "hex.depth");
4505  pj_a(pj);
4506  for (ut64 i = 0; i + wordsize < end; i += wordsize) {
4507  ut64 addr = core->offset + i;
4508  ut64 val = rz_read_ble(buf + i, be, bitsize);
4509  pj_o(pj);
4510  pj_kn(pj, "addr", addr);
4511  pj_kn(pj, "value", val);
4512  char *refs = __refs(core, val);
4513  if (refs) {
4514  char *refstr = rz_str_escape(refs);
4515  pj_ks(pj, "refstr", rz_str_trim_head_ro(refstr));
4516  free(refstr);
4517 
4518  pj_k(pj, "ref");
4519  free(rz_core_analysis_hasrefs_to_depth(core, val, pj, hex_depth));
4520  }
4521  pj_end(pj);
4522  }
4523  pj_end(pj);
4524  } else if (mode == RZ_OUTPUT_MODE_QUIET) {
4525  for (ut64 i = 0; i + wordsize < end; i += wordsize) {
4526  ut64 val = rz_read_ble(buf + i, be, bitsize);
4527  char *refs = __refs(core, val);
4528  rz_strbuf_appendf(sb, "%s\n", refs);
4529  }
4530  } else if (mode == RZ_OUTPUT_MODE_RIZIN) {
4531  for (ut64 i = 0; i + wordsize < end; i += wordsize) {
4532  ut64 addr = core->offset + i;
4533  ut64 val = rz_read_ble(buf + i, be, bitsize);
4534  rz_strbuf_appendf(sb, "f pxr.%" PFMT64x " @ 0x%" PFMT64x "\n", val, addr);
4535  }
4536  } else if (mode == RZ_OUTPUT_MODE_STANDARD) {
4537  const int ocols = core->print->cols;
4538  int bitsize = core->rasm->bits;
4539  /* Thumb is 16bit arm but handles 32bit data */
4540  if (bitsize == 16) {
4541  bitsize = 32;
4542  }
4543  core->print->cols = 1;
4544  core->print->flags |= RZ_PRINT_FLAGS_REFS;
4545  rz_strbuf_append(sb, rz_print_hexdump_str(core->print, core->offset, core->block, RZ_MIN(len, core->blocksize), wordsize * 8, bitsize / 8, 1));
4546  core->print->flags &= ~RZ_PRINT_FLAGS_REFS;
4547  core->print->cols = ocols;
4548  } else {
4550  rz_strbuf_free(sb);
4551  return false;
4552  }
4554  char *res = rz_strbuf_drain(sb);
4555  rz_cons_print(res);
4556  free(res);
4557  } else {
4558  rz_strbuf_free(sb);
4559  }
4560  return true;
4561 }
static char * __refs(RzCore *core, ut64 x)
Definition: cmd_print.c:4458
RZ_API char * rz_core_analysis_hasrefs_to_depth(RzCore *core, ut64 value, PJ *pj, int depth)
Definition: core.c:1853
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
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
Definition: rz_endian.h:517
#define RZ_PRINT_FLAGS_REFS
Definition: rz_print.h:22
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_API void rz_table_add_column(RzTable *t, RzTableColumnType *type, const char *name, int maxWidth)
Definition: table.c:134
RZ_API bool rz_table_query(RzTable *t, const char *q)
Definition: table.c:1050
RZ_API RzTableColumnType * rz_table_type(const char *name)
Definition: table.c:24
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
int cols
Definition: rz_print.h:136
Definition: dis.h:43

References __refs(), addr, rz_core_t::analysis, rz_analysis_t::big_endian, rz_asm_t::bits, rz_core_t::block, rz_core_t::blocksize, rz_print_t::cols, rz_core_t::config, test_evm::end, rz_print_t::flags, free(), i, int, len, n, NULL, rz_core_t::offset, PFMT64x, pj_a(), pj_end(), pj_k(), pj_kn(), pj_ks(), pj_o(), rz_core_t::print, rz_core_t::rasm, rz_config_get_i(), rz_core_analysis_hasrefs_to_depth(), RZ_FREE, RZ_MIN, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, RZ_PRINT_FLAGS_REFS, rz_print_hexdump_str(), rz_read_ble(), rz_str_escape(), rz_str_trim_head_ro(), rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), rz_table_add_column(), rz_table_add_rowf(), rz_table_query(), rz_table_type(), rz_warn_if_reached, s, sb, ut64(), and val.

Referenced by rz_print_hexword_references_common_handler().

◆ core_disassembly()

static bool core_disassembly ( RzCore core,
int  n_bytes,
int  n_instrs,
RzCmdStateOutput state,
bool  cbytes 
)
static

Definition at line 6289 of file cmd_print.c.

6289  {
6290  ut32 old_blocksize = core->blocksize;
6291  ut64 old_offset = core->offset;
6292  if (!rz_core_handle_backwards_disasm(core, &n_instrs, &n_bytes)) {
6293  return false;
6294  }
6295 
6296  RZ_LOG_VERBOSE("disassembly at: 0x%" PFMT64x " "
6297  "blocksize: %" PFMT32d " "
6298  "n_bytes: %" PFMT32d " "
6299  "n_instrs: %" PFMT32d "\n",
6300  core->offset, core->blocksize, n_bytes, n_instrs);
6301  RzCoreDisasmOptions disasm_options = {
6302  .cbytes = cbytes,
6303  };
6304  switch (state->mode) {
6306  rz_core_print_disasm(core, core->offset, core->block, n_bytes,
6307  n_bytes > 0 && !n_instrs ? n_bytes : n_instrs, state, &disasm_options);
6308  break;
6309  case RZ_OUTPUT_MODE_TABLE:
6310  disassembly_as_table(state->d.t, core, n_instrs, n_bytes);
6311  break;
6312  case RZ_OUTPUT_MODE_JSON:
6314  rz_core_print_disasm_json(core, core->offset, core->block, n_bytes, n_instrs, state->d.pj);
6316  break;
6317  case RZ_OUTPUT_MODE_QUIET:
6318  rz_core_disasm_pdi(core, n_instrs, n_bytes, 0);
6319  break;
6320  default:
6322  break;
6323  }
6324 
6325  rz_core_block_size(core, old_blocksize);
6326  if (core->offset != old_offset) {
6327  rz_core_seek(core, old_offset, true);
6328  }
6329  return true;
6330 }
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
static void disassembly_as_table(RzTable *t, RzCore *core, int n_instrs, int n_bytes)
Definition: cmd_print.c:6254
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 s...
Definition: disasm.c:5984
RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int nb_bytes, int nb_opcodes, PJ *pj)
Definition: disasm.c:6040
RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL ut8 *buf, int len, int nlines, RZ_NULLABLE RzCmdStateOutput *state, RZ_NULLABLE RzCoreDisasmOptions *options)
Disassemble len bytes and nlines opcodes restricted by len and nlines at the same time.
Definition: disasm.c:5336
RZ_API int rz_core_disasm_pdi(RzCore *core, int nb_opcodes, int nb_bytes, int fmt)
Definition: disasm.c:6558
#define RZ_LOG_VERBOSE(fmtstr,...)
Definition: rz_log.h:52
#define PFMT32d
Definition: rz_types.h:408

References rz_core_t::block, rz_core_t::blocksize, disassembly_as_table(), rz_core_t::offset, PFMT32d, PFMT64x, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_core_block_size(), rz_core_disasm_pdi(), rz_core_handle_backwards_disasm(), rz_core_print_disasm(), rz_core_print_disasm_json(), rz_core_seek(), RZ_LOG_VERBOSE, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_warn_if_reached, and ut64().

Referenced by rz_cmd_disassemble_recursively_no_function_handler(), rz_cmd_disassembly_n_bytes_handler(), and rz_cmd_disassembly_n_instructions_handler().

◆ core_print_2bpp_row()

static void core_print_2bpp_row ( const ut8 buf,
bool  useColor 
)
static

Definition at line 4563 of file cmd_print.c.

4563  {
4564  const char *symbols = "#=-.";
4565  for (ut32 i = 0, c = 0; i < 8; i++) {
4566  if (buf[1] & ((1 << 7) >> i)) {
4567  c = 2;
4568  }
4569  if (buf[0] & ((1 << 7) >> i)) {
4570  c++;
4571  }
4572  if (useColor) {
4573  char *color = "";
4574  switch (c) {
4575  case 0:
4576  color = Color_BGWHITE;
4577  break;
4578  case 1:
4579  color = Color_BGRED;
4580  break;
4581  case 2:
4582  color = Color_BGBLUE;
4583  break;
4584  case 3:
4585  color = Color_BGBLACK;
4586  break;
4587  }
4588  rz_cons_printf("%s ", color);
4589  } else {
4590  const char ch = symbols[c % 4];
4591  rz_cons_printf("%c%c", ch, ch);
4592  }
4593  c = 0;
4594  }
4595 }
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
#define Color_BGWHITE
Definition: rz_cons.h:626

References c, color, Color_BGBLACK, Color_BGBLUE, Color_BGRED, Color_BGWHITE, i, rz_cons_printf(), and symbols().

Referenced by core_print_2bpp_tiles().

◆ core_print_2bpp_tiles()

static void core_print_2bpp_tiles ( RzCore core,
ut32  tiles 
)
static

Definition at line 4597 of file cmd_print.c.

4597  {
4598  const ut8 *buf = core->block;
4599  bool useColor = rz_config_get_i(core->config, "scr.color") > 0;
4600  for (ut32 i = 0; i < 8; i++) {
4601  for (ut32 r = 0; r < tiles; r++) {
4602  core_print_2bpp_row(buf + 2 * i + r * 16, useColor);
4603  }
4604  if (useColor) {
4606  } else {
4607  rz_cons_printf("\n");
4608  }
4609  }
4610 }
static void core_print_2bpp_row(const ut8 *buf, bool useColor)
Definition: cmd_print.c:4563
#define r
Definition: crypto_rc6.c:12

References rz_core_t::block, Color_RESET, rz_core_t::config, core_print_2bpp_row(), i, r, rz_config_get_i(), and rz_cons_printf().

Referenced by rz_cmd_print().

◆ core_print_columns()

static void core_print_columns ( RzCore core,
const ut8 buf,
ut32  len,
ut32  height 
)
static

Definition at line 3498 of file cmd_print.c.

3498  {
3499  size_t i, j;
3500  bool colors = rz_config_get_i(core->config, "scr.color") > 0;
3501  RzCons *cons = rz_cons_singleton();
3502  RzConsPrintablePalette *pal = &cons->context->pal;
3503  ut32 cols = 78;
3504  ut32 rows = height > 0 ? height : 10;
3505  const char *vline = cons->use_utf8 ? RUNE_LINE_VERT : "|";
3506  const char *block = cons->use_utf8 ? UTF_BLOCK : "#";
3507  const char *kol[5];
3508  kol[0] = pal->call;
3509  kol[1] = pal->jmp;
3510  kol[2] = pal->cjmp;
3511  kol[3] = pal->mov;
3512  kol[4] = pal->nop;
3513  if (colors) {
3514  for (i = 0; i < rows; i++) {
3515  size_t threshold = i * (0xff / rows);
3516  size_t koli = i * 5 / rows;
3517  for (j = 0; j < cols; j++) {
3518  int realJ = j * len / cols;
3519  if (255 - buf[realJ] < threshold || (i + 1 == rows)) {
3520  if (core->print->histblock) {
3521  rz_cons_printf("%s%s%s", kol[koli], block, Color_RESET);
3522  } else {
3523  rz_cons_printf("%s%s%s", kol[koli], vline, Color_RESET);
3524  }
3525  } else {
3526  rz_cons_print(" ");
3527  }
3528  }
3529  rz_cons_print("\n");
3530  }
3531  return;
3532  }
3533 
3534  for (i = 0; i < rows; i++) {
3535  size_t threshold = i * (0xff / rows);
3536  for (j = 0; j < cols; j++) {
3537  size_t realJ = j * len / cols;
3538  if (255 - buf[realJ] < threshold) {
3539  if (core->print->histblock) {
3540  rz_cons_printf("%s%s%s", Color_BGGRAY, block, Color_RESET);
3541  } else {
3542  rz_cons_printf("%s", vline);
3543  }
3544  } else if (i + 1 == rows) {
3545  rz_cons_print("_");
3546  } else {
3547  rz_cons_print(" ");
3548  }
3549  }
3550  rz_cons_print("\n");
3551  }
3552 }
#define Color_BGGRAY
Definition: rz_cons.h:638
#define UTF_BLOCK
Definition: rz_cons.h:419
#define RUNE_LINE_VERT
Definition: rz_cons.h:401
bool use_utf8
Definition: rz_cons.h:559
bool histblock
Definition: rz_print.h:128
int height
Definition: main.c:10

References rz_cons_printable_palette_t::call, rz_cons_printable_palette_t::cjmp, Color_BGGRAY, Color_RESET, colors, rz_core_t::config, rz_cons_t::context, height, rz_print_t::histblock, i, rz_cons_printable_palette_t::jmp, len, rz_cons_printable_palette_t::mov, rz_cons_printable_palette_t::nop, rz_cons_context_t::pal, rz_core_t::print, RUNE_LINE_VERT, rz_config_get_i(), rz_cons_printf(), rz_cons_singleton(), rz_cons_t::use_utf8, and UTF_BLOCK.

Referenced by cmd_print_bars().

◆ core_print_raw_buffer()

static void core_print_raw_buffer ( RzStrStringifyOpt opt)
static

Definition at line 4612 of file cmd_print.c.

4612  {
4613  char *str = rz_str_stringify_raw_buffer(opt, NULL);
4614  if (str) {
4616  free(str);
4617  }
4618 }
RZ_API RZ_OWN char * rz_str_stringify_raw_buffer(RzStrStringifyOpt *option, RZ_NULLABLE RZ_OUT ut32 *length)
Converts a raw buffer to a printable string based on the selected options.
Definition: str.c:4141

References free(), NULL, rz_cons_strcat(), rz_str_stringify_raw_buffer(), and cmd_descs_generate::str.

Referenced by rz_cmd_print(), rz_print_utf16be_handler(), rz_print_utf16le_handler(), rz_print_utf32be_handler(), and rz_print_utf32le_handler().

◆ core_walk_function_blocks()

static bool core_walk_function_blocks ( RzCore core,
RzAnalysisFunction f,
RzCmdStateOutput state,
char  type_print,
bool  fromHere 
)
static

Definition at line 6851 of file cmd_print.c.

6851  {
6852  RzListIter *iter;
6853  RzAnalysisBlock *b = NULL;
6854  const char *orig_bb_middle = rz_config_get(core->config, "asm.bb.middle");
6855  rz_config_set_i(core->config, "asm.bb.middle", false);
6856 
6857  if (rz_list_length(f->bbs) >= 1) {
6858  ut32 fcn_size = rz_analysis_function_realsize(f);
6859  b = rz_list_get_top(f->bbs);
6860  if (b->size > fcn_size) {
6861  b->size = fcn_size;
6862  }
6863  }
6864 
6866  if (state->mode == RZ_OUTPUT_MODE_JSON) {
6867  rz_list_foreach (f->bbs, iter, b) {
6868  ut8 *buf = malloc(b->size);
6869  if (!buf) {
6870  RZ_LOG_ERROR("cannot allocate %" PFMT64u " byte(s)\n", b->size);
6871  return false;
6872  }
6873  (void)rz_io_read_at(core->io, b->addr, buf, b->size);
6874  rz_core_print_disasm_json(core, b->addr, buf, b->size, 0, state->d.pj);
6875  free(buf);
6876  }
6877  } else {
6878  bool asm_lines = rz_config_get_i(core->config, "asm.lines.bb");
6879  bool emu = rz_config_get_i(core->config, "asm.emu");
6880  ut64 saved_gp = 0;
6881  ut8 *saved_arena = NULL;
6882  int saved_stackptr = core->analysis->stackptr;
6883  if (emu) {
6884  saved_gp = core->analysis->gp;
6885  saved_arena = rz_reg_arena_peek(core->analysis->reg);
6886  }
6887  rz_config_set_i(core->config, "asm.lines.bb", 0);
6888  rz_list_foreach (f->bbs, iter, b) {
6889  pr_bb(core, f, b, emu, saved_gp, saved_arena, type_print, fromHere);
6890  }
6891  if (emu) {
6892  core->analysis->gp = saved_gp;
6893  if (saved_arena) {
6894  rz_reg_arena_poke(core->analysis->reg, saved_arena);
6895  RZ_FREE(saved_arena);
6896  }
6897  }
6898  core->analysis->stackptr = saved_stackptr;
6899  rz_config_set_i(core->config, "asm.lines.bb", asm_lines);
6900  }
6901  rz_config_set(core->config, "asm.bb.middle", orig_bb_middle);
6902  return true;
6903 }
RZ_API ut64 rz_analysis_function_realsize(const RzAnalysisFunction *fcn)
Definition: function.c:338
RZ_API ut8 * rz_reg_arena_peek(RzReg *reg)
Definition: arena.c:280
RZ_API void rz_reg_arena_poke(RzReg *reg, const ut8 *ret)
Definition: arena.c:293
static int bbcmp(RzAnalysisBlock *a, RzAnalysisBlock *b)
Definition: cmd_print.c:3998
static void pr_bb(RzCore *core, RzAnalysisFunction *fcn, RzAnalysisBlock *b, bool emu, ut64 saved_gp, ut8 *saved_arena, char p_type, bool fromHere)
Definition: cmd_print.c:4168
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:457
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
int(* RzListComparator)(const void *value, const void *list_data)
Definition: rz_list.h:33

References rz_core_t::analysis, b, bbcmp(), rz_core_t::config, f, free(), rz_analysis_t::gp, rz_core_t::io, malloc(), NULL, PFMT64u, pr_bb(), rz_analysis_t::reg, rz_analysis_function_realsize(), rz_config_get(), rz_config_get_i(), rz_config_set(), rz_config_set_i(), rz_core_print_disasm_json(), RZ_FREE, rz_io_read_at(), rz_list_get_top(), rz_list_length(), rz_list_sort(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, rz_reg_arena_peek(), rz_reg_arena_poke(), rz_analysis_t::stackptr, and ut64().

Referenced by rz_cmd_disassemble_recursively_from_current_block_handler(), and rz_cmd_disassemble_recursively_handler().

◆ disasm_strings()

static void disasm_strings ( RzCore core,
const char *  input,
RzAnalysisFunction fcn 
)
static

Definition at line 2596 of file cmd_print.c.

2596  {
2597  const char *linecolor = NULL;
2598  char *ox, *qo, *string = NULL;
2599  char *line, *s, *str, *string2 = NULL;
2600  char *switchcmp = NULL;
2601  int i, count, use_color = rz_config_get_i(core->config, "scr.color");
2602  bool show_comments = rz_config_get_i(core->config, "asm.comments");
2603  bool show_offset = rz_config_get_i(core->config, "asm.offset");
2604  bool asm_tabs = rz_config_get_i(core->config, "asm.tabs");
2605  bool scr_html = rz_config_get_i(core->config, "scr.html");
2606  bool asm_dwarf = rz_config_get_i(core->config, "asm.dwarf");
2607  bool asm_flags = rz_config_get_i(core->config, "asm.flags");
2608  bool asm_cmt_right = rz_config_get_i(core->config, "asm.cmt.right");
2609  bool asm_emu = rz_config_get_i(core->config, "asm.emu");
2610  bool emu_str = rz_config_get_i(core->config, "emu.str");
2611  rz_config_set_i(core->config, "emu.str", true);
2612  RzConsPrintablePalette *pal = &core->cons->context->pal;
2613  // force defaults
2614  rz_config_set_i(core->config, "asm.offset", true);
2615  rz_config_set_i(core->config, "asm.dwarf", true);
2616  rz_config_set_i(core->config, "scr.color", COLOR_MODE_DISABLED);
2617  rz_config_set_i(core->config, "asm.tabs", 0);
2618  rz_config_set_i(core->config, "scr.html", 0);
2619  rz_config_set_i(core->config, "asm.cmt.right", true);
2620 
2621  line = NULL;
2622  s = NULL;
2623  if (!strncmp(input, "dsb", 3)) {
2625  if (bb) {
2626  line = s = rz_core_cmd_strf(core, "pD %" PFMT64u " @ 0x%08" PFMT64x, bb->size, bb->addr);
2627  }
2628  } else if (!strncmp(input, "dsf", 3) || !strncmp(input, "dsr", 3)) {
2630  if (fcn) {
2631  line = s = rz_core_cmd_str(core, "pdr");
2632  } else {
2633  eprintf("Cannot find function.\n");
2634  rz_config_set_i(core->config, "scr.color", use_color);
2635  rz_config_set_i(core->config, "asm.cmt.right", asm_cmt_right);
2636  goto restore_conf;
2637  }
2638  } else if (!strncmp(input, "ds ", 3)) {
2639  line = s = rz_core_cmd_strf(core, "pD %s", input + 3);
2640  } else {
2641  line = s = rz_core_cmd_str(core, "pd");
2642  }
2643 
2644  rz_config_set_i(core->config, "scr.html", scr_html);
2645  rz_config_set_i(core->config, "scr.color", use_color);
2646  rz_config_set_i(core->config, "asm.cmt.right", asm_cmt_right);
2647  count = rz_str_split(s, '\n');
2648  if (!line || !*line || count < 1) {
2649  // RZ_FREE (s);
2650  goto restore_conf;
2651  }
2652  for (i = 0; i < count; i++) {
2653  ut64 addr = UT64_MAX;
2654  ox = strstr(line, "0x");
2655  qo = strchr(line, '\"');
2656  RZ_FREE(string);
2657  if (ox) {
2658  addr = rz_num_get(NULL, ox);
2659  }
2660  if (qo) {
2661  char *qoe = strrchr(qo + 1, '"');
2662  if (qoe) {
2663  int raw_len = qoe - qo - 1;
2664  int actual_len = 0;
2665  char *ptr = qo + 1;
2666  for (; ptr < qoe; ptr++) {
2667  if (*ptr == '\\' && ptr + 1 < qoe) {
2668  int i, body_len;
2669  switch (*(ptr + 1)) {
2670  case 'x':
2671  body_len = 3;
2672  break;
2673  case 'u':
2674  body_len = 5;
2675  break;
2676  case 'U':
2677  body_len = 9;
2678  break;
2679  default:
2680  body_len = 1;
2681  }
2682  for (i = 0; i < body_len && ptr < qoe; i++) {
2683  ptr++;
2684  }
2685  }
2686  actual_len++;
2687  }
2688  if (actual_len > 2) {
2689  string = rz_str_ndup(qo, raw_len + 2);
2690  }
2691  linecolor = RZ_CONS_COLOR(comment);
2692  }
2693  }
2694  ox = strstr(line, "; 0x");
2695  if (!ox) {
2696  ox = strstr(line, "@ 0x");
2697  }
2698  if (ox) {
2699  char *qoe = strchr(ox + 3, ' ');
2700  if (!qoe) {
2701  qoe = strchr(ox + 3, '\x1b');
2702  }
2703  int len = qoe ? qoe - ox : strlen(ox + 3);
2704  string2 = rz_str_ndup(ox + 2, len - 1);
2705  if (rz_num_get(NULL, string2) < 0x100) {
2706  RZ_FREE(string2);
2707  }
2708  }
2709  if (asm_flags) {
2710  str = strstr(line, ";-- ");
2711  if (str) {
2712  if (!rz_str_startswith(str + 4, "case")) {
2713  rz_cons_printf("%s\n", str);
2714  }
2715  }
2716  }
2717 #define USE_PREFIXES 1
2718 #if USE_PREFIXES
2719  // XXX leak
2720  str = strstr(line, " obj.");
2721  if (!str) {
2722  str = strstr(line, " str.");
2723  if (!str) {
2724  str = strstr(line, " imp.");
2725  if (!str) {
2726  str = strstr(line, " fcn.");
2727  if (!str) {
2728  str = strstr(line, " sub.");
2729  }
2730  }
2731  }
2732  }
2733 #else
2734  if (strchr(line, ';')) {
2735  const char *dot = rz_str_rchr(line, NULL, '.');
2736  if (dot) {
2737  const char *o = rz_str_rchr(line, dot, ' ');
2738  if (o) {
2739  str = (char *)o;
2740  } else {
2741  eprintf("Warning: missing summary reference: %s\n", dot);
2742  }
2743  }
2744  }
2745 #endif
2746  if (str) {
2747  str = strdup(str);
2748  char *qoe = NULL;
2749  if (!qoe) {
2750  qoe = strchr(str + 1, '\x1b');
2751  }
2752  if (!qoe) {
2753  qoe = strchr(str + 1, ';');
2754  }
2755  if (!qoe) {
2756  qoe = strchr(str + 1, ' ');
2757  }
2758  if (qoe) {
2759  free(string2);
2760  string2 = rz_str_ndup(str + 1, qoe - str - 1);
2761  } else {
2762  free(string2);
2763  string2 = strdup(str + 1);
2764  }
2765  if (string2) {
2766  RZ_FREE(string);
2767  string = string2;
2768  string2 = NULL;
2769  }
2770  }
2771  RZ_FREE(string2);
2772  _handle_call(core, line, &str);
2773  if (!str) {
2774  str = strstr(line, "sym.");
2775  if (!str) {
2776  str = strstr(line, "fcn.");
2777  }
2778  }
2779  if (str) {
2780  str = strdup(str);
2781  char *qoe = strchr(str, ';');
2782  if (qoe) {
2783  char *t = str;
2784  str = rz_str_ndup(str, qoe - str);
2785  free(t);
2786  }
2787  }
2788  if (str) {
2789  string2 = strdup(str);
2790  linecolor = RZ_CONS_COLOR(call);
2791  }
2792  if (!string && string2) {
2793  string = string2;
2794  string2 = NULL;
2795  }
2796  if (strstr(line, "XREF")) {
2797  addr = UT64_MAX;
2798  }
2799  if (addr != UT64_MAX) {
2800  const char *str = NULL;
2801  if (show_comments) {
2802  char *comment = rz_core_analysis_get_comments(core, addr);
2803  if (comment) {
2804  if (switchcmp) {
2805  if (strcmp(comment, switchcmp)) {
2806  if (show_offset) {
2807  rz_cons_printf("%s0x%08" PFMT64x " ", use_color ? pal->offset : "", addr);
2808  }
2809  rz_cons_printf("%s%s\n", use_color ? pal->comment : "", comment);
2810  }
2811  } else {
2812  if (show_offset) {
2813  rz_cons_printf("%s0x%08" PFMT64x " ", use_color ? pal->offset : "", addr);
2814  }
2815  rz_cons_printf("%s%s\n", use_color ? pal->comment : "", comment);
2816  }
2817  if (rz_str_startswith(comment, "switch table")) {
2818  switchcmp = strdup(comment);
2819  }
2820  RZ_FREE(comment);
2821  }
2822  }
2823 
2824  if (fcn) {
2825  bool label = false;
2826  /* show labels, basic blocks and (conditional) branches */
2827  RzAnalysisBlock *bb;
2828  RzListIter *iter;
2829  rz_list_foreach (fcn->bbs, iter, bb) {
2830  if (addr == bb->jump) {
2831  if (show_offset) {
2832  rz_cons_printf("%s0x%08" PFMT64x ":\n", use_color ? Color_YELLOW : "", addr);
2833  }
2834  label = true;
2835  break;
2836  }
2837  }
2838  if (!label && strstr(line, "->")) {
2839  rz_cons_printf("%s0x%08" PFMT64x ":\n", use_color ? Color_YELLOW : "", addr);
2840  }
2841  if (strstr(line, "=<")) {
2842  rz_list_foreach (fcn->bbs, iter, bb) {
2843  if (addr >= bb->addr && addr < bb->addr + bb->size) {
2844  const char *op;
2845  if (use_color) {
2846  op = (bb->fail == UT64_MAX) ? Color_GREEN "jmp" : "cjmp";
2847  } else {
2848  op = (bb->fail == UT64_MAX) ? "jmp" : "cjmp";
2849  }
2850  if (show_offset) {
2851  rz_cons_printf("%s0x%08" PFMT64x " " Color_RESET, use_color ? pal->offset : "", addr);
2852  }
2853  rz_cons_printf("%s 0x%08" PFMT64x "%s\n",
2854  op, bb->jump, use_color ? Color_RESET : "");
2855  break;
2856  }
2857  }
2858  }
2859  }
2860  if (string && *string) {
2861  if (string && !strncmp(string, "0x", 2)) {
2862  str = string;
2863  }
2864  if (string2 && !strncmp(string2, "0x", 2)) {
2865  str = string2;
2866  }
2867  ut64 ptr = rz_num_math(NULL, str);
2868  RzFlagItem *flag = NULL;
2869  if (str) {
2870  flag = rz_core_flag_get_by_spaces(core->flags, ptr);
2871  }
2872  if (!flag) {
2873  if (string && !strncmp(string, "0x", 2)) {
2874  RZ_FREE(string);
2875  }
2876  if (string2 && !strncmp(string2, "0x", 2)) {
2877  RZ_FREE(string2);
2878  }
2879  }
2880  if (string && addr != UT64_MAX && addr != UT32_MAX) {
2881  rz_str_trim(string);
2882  if (string2) {
2883  rz_str_trim(string2);
2884  }
2886  // eprintf ("---> %s\n", string);
2887  if (use_color) {
2888  if (show_offset) {
2889  rz_cons_printf("%s0x%08" PFMT64x " " Color_RESET, use_color ? pal->offset : "", addr);
2890  }
2891  rz_cons_printf("%s%s%s%s%s%s%s\n",
2892  linecolor ? linecolor : "",
2893  string2 ? string2 : "", string2 ? " " : "", string,
2894  flag ? " " : "", flag ? flag->name : "", Color_RESET);
2895  } else {
2896  if (show_offset) {
2897  rz_cons_printf("0x%08" PFMT64x " ", addr);
2898  }
2899  rz_cons_printf("%s%s%s%s%s\n",
2900  string2 ? string2 : "", string2 ? " " : "", string,
2901  flag ? " " : "", flag ? flag->name : "");
2902  }
2903  }
2904  }
2905  }
2906  line += strlen(line) + 1;
2907  }
2908  // rz_cons_printf ("%s", s);
2909  free(string2);
2910  free(string);
2911  free(s);
2912  free(str);
2913  free(switchcmp);
2914 restore_conf:
2915  rz_config_set_i(core->config, "asm.offset", show_offset);
2916  rz_config_set_i(core->config, "asm.dwarf", asm_dwarf);
2917  rz_config_set_i(core->config, "asm.tabs", asm_tabs);
2918  rz_config_set_i(core->config, "scr.html", scr_html);
2919  rz_config_set_i(core->config, "asm.emu", asm_emu);
2920  rz_config_set_i(core->config, "emu.str", emu_str);
2921 }
int call(int a, int b)
Definition: bcj_test.c:25
RZ_API RzAnalysisBlock * rz_analysis_find_most_relevant_block_in(RzAnalysis *analysis, ut64 off)
Definition: block.c:997
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
static void _handle_call(RzCore *core, char *line, char **str)
Definition: cmd_print.c:2571
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
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
RZ_API char * rz_core_analysis_get_comments(RzCore *core, ut64 addr)
Definition: core.c:2091
@ RZ_ANALYSIS_FCN_TYPE_NULL
Definition: rz_analysis.h:192
@ COLOR_MODE_DISABLED
Definition: rz_cons.h:442
#define RZ_CONS_COLOR(x)
Definition: rz_core.h:85
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API const char * rz_str_rchr(const char *base, const char *p, int ch)
Definition: str.c:829
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
RZ_API size_t rz_str_split(char *str, char ch)
Split string str in place by using ch as a delimiter.
Definition: str.c:406
Definition: dis.h:35

References _handle_call(), addr, rz_analysis_bb_t::addr, rz_core_t::analysis, rz_analysis_function_t::bbs, call(), Color_GREEN, COLOR_MODE_DISABLED, Color_RESET, Color_YELLOW, rz_cons_printable_palette_t::comment, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, count, eprintf, rz_analysis_bb_t::fail, rz_core_t::flags, free(), i, input(), rz_analysis_bb_t::jump, len, setup::line, rz_flag_item_t::name, NULL, rz_cons_printable_palette_t::offset, rz_core_t::offset, op, rz_cons_context_t::pal, PFMT64u, PFMT64x, RZ_ANALYSIS_FCN_TYPE_NULL, rz_analysis_find_most_relevant_block_in(), rz_analysis_get_fcn_in(), rz_config_get_i(), rz_config_set_i(), RZ_CONS_COLOR, rz_cons_printf(), rz_core_analysis_get_comments(), rz_core_cmd_str(), rz_core_cmd_strf(), rz_core_flag_get_by_spaces(), RZ_FREE, rz_num_get(), rz_num_math(), rz_str_ndup(), rz_str_rchr(), rz_str_split(), rz_str_startswith(), rz_str_trim(), s, rz_analysis_bb_t::size, cmd_descs_generate::str, strdup(), UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_cmd_disassemble_summarize_block_handler(), rz_cmd_disassemble_summarize_function_handler(), rz_cmd_disassemble_summarize_n_bytes_handler(), and rz_cmd_disassembly_function_summary_handler().

◆ disasm_until_ret()

static void disasm_until_ret ( RzCore core,
ut64  addr,
char  type_print,
const char *  arg 
)
static

Definition at line 4246 of file cmd_print.c.

4246  {
4247  int p = 0;
4248  const bool show_color = core->print->flags & RZ_PRINT_FLAGS_COLOR;
4249  int i, limit = 1024;
4250  if (arg && *arg && arg[1]) {
4251  limit = rz_num_math(core->num, arg + 1);
4252  }
4253  for (i = 0; i < limit; i++) {
4255  if (op) {
4256  char *mnem = op->mnemonic;
4257  char *m = malloc((strlen(mnem) * 2) + 32);
4258  strcpy(m, mnem);
4259  // rz_parse_parse (core->parser, op->mnemonic, m);
4260  if (type_print == 'q') {
4261  rz_cons_printf("%s\n", m);
4262  } else {
4263  if (show_color) {
4264  const char *offsetColor = rz_cons_singleton()->context->pal.offset; // TODO etooslow. must cache
4265  rz_cons_printf("%s0x%08" PFMT64x "" Color_RESET " %10s %s\n",
4266  offsetColor, addr + p, "", m);
4267  } else {
4268  rz_cons_printf("0x%08" PFMT64x " %10s %s\n", addr + p, "", m);
4269  }
4270  }
4271  switch (op->type & 0xfffff) {
4274  goto beach;
4275  break;
4276  }
4277  if (op->type == RZ_ANALYSIS_OP_TYPE_JMP) {
4278  addr = op->jump;
4279  } else {
4280  addr += op->size;
4281  }
4282  } else {
4283  eprintf("[pdp] Cannot get op at 0x%08" PFMT64x "\n", addr + p);
4285  break;
4286  }
4287  // rz_io_read_at (core->io, n, rbuf, 512);
4289  }
4290 beach:
4291  return;
4292 }
#define mnem(n, mn)
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
@ RZ_ANALYSIS_OP_MASK_DISASM
Definition: rz_analysis.h:445
#define RZ_PRINT_FLAGS_COLOR
Definition: rz_print.h:15

References addr, Color_RESET, rz_cons_t::context, eprintf, rz_print_t::flags, i, limit, regress::m, malloc(), mnem, rz_core_t::num, rz_cons_printable_palette_t::offset, p, rz_cons_context_t::pal, PFMT64x, rz_core_t::print, rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_UJMP, rz_cons_printf(), rz_cons_singleton(), rz_core_analysis_op(), rz_num_math(), and RZ_PRINT_FLAGS_COLOR.

Referenced by rz_cmd_print().

◆ disassemble_till_return_is_found()

static void disassemble_till_return_is_found ( RzCore core,
ut64  offset,
ut64  limit,
RzCmdStateOutput state 
)
static

Definition at line 6742 of file cmd_print.c.

6742  {
6743  bool src_color = rz_config_get_i(core->config, "scr.color") > 0;
6744  const char *off_color = src_color ? rz_cons_singleton()->context->pal.b0x00 : "";
6745  const char *ret_color = src_color ? rz_cons_singleton()->context->pal.jmp : "";
6746  const char *end_color = src_color ? Color_RESET : "";
6747 
6748  for (ut64 i = 0; i < limit; i++) {
6750  if (!op) {
6751  return;
6752  }
6753 
6754  switch (state->mode) {
6755  case RZ_OUTPUT_MODE_QUIET:
6756  rz_cons_printf("%s%s%s\n", ret_color, op->mnemonic, end_color);
6757  break;
6759  rz_cons_printf("%s0x%08" PFMT64x "%s %-11s%s\n", off_color, core->offset + i, ret_color, op->mnemonic, end_color);
6760  break;
6761  case RZ_OUTPUT_MODE_JSON:
6762  pj_o(state->d.pj);
6763  pj_ks(state->d.pj, "mnemonic", op->mnemonic);
6764  pj_kn(state->d.pj, "address", core->offset + i);
6765  pj_end(state->d.pj);
6766  break;
6767  default:
6769  break;
6770  }
6771 
6774  return;
6775  }
6776 
6777  if (op->type == RZ_ANALYSIS_OP_TYPE_JMP) {
6778  offset = op->jump;
6779  } else {
6780  offset += op->size;
6781  }
6782 
6784  }
6785 }

References rz_cons_printable_palette_t::b0x00, Color_RESET, rz_core_t::config, rz_cons_t::context, i, rz_cons_printable_palette_t::jmp, limit, rz_core_t::offset, rz_cons_context_t::pal, PFMT64x, pj_end(), pj_kn(), pj_ks(), pj_o(), rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_UJMP, rz_config_get_i(), rz_cons_printf(), rz_cons_singleton(), rz_core_analysis_op(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, and ut64().

Referenced by rz_cmd_disassemble_ropchain_handler().

◆ disassembly_as_table()

static void disassembly_as_table ( RzTable t,
RzCore core,
int  n_instrs,
int  n_bytes 
)
static

Definition at line 6254 of file cmd_print.c.

6254  {
6255  ut8 buffer[256];
6256  rz_table_set_columnsf(t, "snssssss", "name", "addr", "bytes", "disasm", "comment", "esil", "refs", "xrefs");
6257  const int minopsz = 1;
6259  const int addrbytes = core->io->addrbytes;
6260  ut64 offset = core->offset;
6261  ut64 inc = 0;
6262  for (int i = 0, j = 0; rz_disasm_check_end(n_instrs, i, n_bytes, j * addrbytes); i++, offset += inc, j += inc) {
6264  if (!op || op->size < 1) {
6265  i += minopsz;
6266  inc = minopsz;
6267  continue;
6268  }
6269  const char *comment = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, offset);
6270  if (!comment) {
6271  comment = "";
6272  }
6273  rz_io_read_at(core->io, offset, buffer, RZ_MIN(op->size, sizeof(buffer)));
6274  char *bytes = rz_hex_bin2strdup(buffer, op->size);
6275  RzFlagItem *flag = rz_flag_get_i(core->flags, offset);
6276  char *function_name = flag ? flag->name : "";
6277  const char *esil = RZ_STRBUF_SAFEGET(&op->esil);
6278  char *refs = __op_refs(core, op, 0);
6279  char *xrefs = __op_refs(core, op, 1);
6280  rz_table_add_rowf(t, "sXssssss", function_name, offset, bytes, op->mnemonic, comment, esil, refs, xrefs);
6281  free(bytes);
6282  free(xrefs);
6283  free(refs);
6284  inc = op->size;
6286  }
6287 }
static char * __op_refs(RzCore *core, RzAnalysisOp *op, int n)
Definition: cmd_print.c:4430
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: disasm.c:5804
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
@ RZ_ANALYSIS_OP_MASK_HINT
Definition: rz_analysis.h:443
RZ_API char * rz_hex_bin2strdup(const ut8 *in, int len)
Definition: hex.c:415
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
size_t addrbytes
Definition: rz_io.h:66

References __op_refs(), rz_io_t::addrbytes, rz_core_t::analysis, bytes, rz_core_t::flags, free(), i, rz_core_t::io, rz_flag_item_t::name, rz_core_t::offset, options, rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_MASK_ESIL, RZ_ANALYSIS_OP_MASK_HINT, rz_core_analysis_op(), rz_disasm_check_end(), rz_flag_get_i(), rz_hex_bin2strdup(), rz_io_read_at(), rz_meta_get_string(), RZ_META_TYPE_COMMENT, RZ_MIN, RZ_STRBUF_SAFEGET, rz_table_add_rowf(), rz_table_set_columnsf(), and ut64().

Referenced by core_disassembly().

◆ findClassBounds()

static ut64 findClassBounds ( RzCore core,
int len 
)
static

Definition at line 917 of file cmd_print.c.

917  {
918  ut64 min = 0, max = 0;
919  RzListIter *iter;
920  RzBinClass *c;
921  RzList *cs = rz_bin_get_classes(core->bin);
922  rz_list_foreach (cs, iter, c) {
923  if (!c || !c->name || !c->name[0]) {
924  continue;
925  }
926  findMethodBounds(c->methods, &min, &max);
927  if (len) {
928  *len = (max - min);
929  }
930  return min;
931  }
932  return 0;
933 }
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_classes(RZ_NONNULL RzBin *bin)
Definition: bin.c:883
static void findMethodBounds(RzList *methods, ut64 *min, ut64 *max)
Definition: cmd_print.c:897
RzBin * bin
Definition: rz_core.h:298

References rz_core_t::bin, c, test_evm::cs, findMethodBounds(), len, max, min, rz_bin_get_classes(), and ut64().

Referenced by rz_cmd_disassembly_all_methods_class_handler().

◆ findMethodBounds()

static void findMethodBounds ( RzList methods,
ut64 min,
ut64 max 
)
static

Definition at line 897 of file cmd_print.c.

897  {
898  RzBinSymbol *sym;
899  RzListIter *iter;
900  ut64 at_min = UT64_MAX;
901  ut64 at_max = 0LL;
902 
903  rz_list_foreach (methods, iter, sym) {
904  if (sym->vaddr) {
905  if (sym->vaddr < at_min) {
906  at_min = sym->vaddr;
907  }
908  if (sym->vaddr + sym->size > at_max) {
909  at_max = sym->vaddr + sym->size;
910  }
911  }
912  }
913  *min = at_min;
914  *max = at_max;
915 }

References max, min, rz_bin_symbol_t::size, ut64(), UT64_MAX, and rz_bin_symbol_t::vaddr.

Referenced by findClassBounds().

◆ func_walk_blocks()

static void func_walk_blocks ( RzCore core,
RzAnalysisFunction f,
char  input,
char  type_print,
bool  fromHere 
)
static

Definition at line 4294 of file cmd_print.c.

4294  {
4295  RzListIter *iter;
4296  RzAnalysisBlock *b = NULL;
4297  const char *orig_bb_middle = rz_config_get(core->config, "asm.bb.middle");
4298  rz_config_set_i(core->config, "asm.bb.middle", false);
4299  PJ *pj = NULL;
4300 
4301  // XXX: hack must be reviewed/fixed in code analysis
4302  if (!b) {
4303  if (rz_list_length(f->bbs) >= 1) {
4304  ut32 fcn_size = rz_analysis_function_realsize(f);
4305  b = rz_list_get_top(f->bbs);
4306  if (b->size > fcn_size) {
4307  b->size = fcn_size;
4308  }
4309  }
4310  }
4312  if (input == 'j' && b) {
4313  pj = pj_new();
4314  if (!pj) {
4315  return;
4316  }
4317  pj_a(pj);
4318  rz_list_foreach (f->bbs, iter, b) {
4319  if (fromHere) {
4320  if (b->addr < core->offset) {
4321  core->cons->null = true;
4322  } else {
4323  core->cons->null = false;
4324  }
4325  }
4326  ut8 *buf = malloc(b->size);
4327  if (buf) {
4328  rz_io_read_at(core->io, b->addr, buf, b->size);
4329  rz_core_print_disasm_json(core, b->addr, buf, b->size, 0, pj);
4330  free(buf);
4331  } else {
4332  eprintf("cannot allocate %" PFMT64u " byte(s)\n", b->size);
4333  }
4334  }
4335  pj_end(pj);
4336  rz_cons_printf("%s\n", pj_string(pj));
4337  pj_free(pj);
4338  } else {
4339  bool asm_lines = rz_config_get_i(core->config, "asm.lines.bb");
4340  bool emu = rz_config_get_i(core->config, "asm.emu");
4341  ut64 saved_gp = 0;
4342  ut8 *saved_arena = NULL;
4343  int saved_stackptr = core->analysis->stackptr;
4344  if (emu) {
4345  saved_gp = core->analysis->gp;
4346  saved_arena = rz_reg_arena_peek(core->analysis->reg);
4347  }
4348  rz_config_set_i(core->config, "asm.lines.bb", 0);
4349  rz_list_foreach (f->bbs, iter, b) {
4350  pr_bb(core, f, b, emu, saved_gp, saved_arena, type_print, fromHere);
4351  }
4352  if (emu) {
4353  core->analysis->gp = saved_gp;
4354  if (saved_arena) {
4355  rz_reg_arena_poke(core->analysis->reg, saved_arena);
4356  RZ_FREE(saved_arena);
4357  }
4358  }
4359  core->analysis->stackptr = saved_stackptr;
4360  rz_config_set_i(core->config, "asm.lines.bb", asm_lines);
4361  }
4362  rz_config_set(core->config, "asm.bb.middle", orig_bb_middle);
4363 }
int null
Definition: rz_cons.h:550

References rz_core_t::analysis, b, bbcmp(), rz_core_t::config, rz_core_t::cons, eprintf, f, free(), rz_analysis_t::gp, input(), rz_core_t::io, malloc(), NULL, rz_cons_t::null, rz_core_t::offset, PFMT64u, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), pr_bb(), rz_analysis_t::reg, rz_analysis_function_realsize(), rz_config_get(), rz_config_get_i(), rz_config_set(), rz_config_set_i(), rz_cons_printf(), rz_core_print_disasm_json(), RZ_FREE, rz_io_read_at(), rz_list_get_top(), rz_list_length(), rz_list_sort(), rz_reg_arena_peek(), rz_reg_arena_poke(), rz_analysis_t::stackptr, and ut64().

Referenced by rz_cmd_print().

◆ get_section_name()

static char* get_section_name ( RzCore core)
inlinestatic

Definition at line 4373 of file cmd_print.c.

4373  {
4374  const char *csection = rz_core_get_section_name(core, core->offset);
4375  if (RZ_STR_ISEMPTY(csection)) {
4376  return strdup("unknown");
4377  }
4378  csection = rz_str_trim_head_ro(csection);
4379  char *section_name = strdup(csection);
4380  rz_str_trim_tail(section_name);
4381  if (RZ_STR_ISEMPTY(section_name)) {
4382  free(section_name);
4383  return strdup("unknown");
4384  }
4385  return section_name;
4386 }
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
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67

References free(), rz_core_t::offset, rz_core_get_section_name(), RZ_STR_ISEMPTY, rz_str_trim_head_ro(), rz_str_trim_tail(), and strdup().

Referenced by print_json_string().

◆ handle_entropy()

static void handle_entropy ( RzCore core,
const char *  name,
const ut8 block,
int  len 
)
static

Definition at line 2923 of file cmd_print.c.

2923  {
2924  RzHashSize digest_size = 0;
2925  ut8 *digest = rz_hash_cfg_calculate_small_block(core->hash, name, block, len, &digest_size);
2926  if (!digest) {
2927  return;
2928  }
2929  double entropy = rz_read_be_double(digest);
2930  rz_cons_printf("%f\n", entropy);
2931  free(digest);
2932 }
RZ_API RZ_OWN ut8 * rz_hash_cfg_calculate_small_block(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NONNULL RzHashSize *osize)
Returns the digest size of the requested algorithm name.
Definition: hash.c:529
static double rz_read_be_double(const void *src)
Definition: rz_endian.h:157
ut32 RzHashSize
Definition: rz_hash.h:24

References free(), rz_core_t::hash, len, rz_cons_printf(), rz_hash_cfg_calculate_small_block(), and rz_read_be_double().

Referenced by rz_cmd_print_hash_cfg_handler().

◆ handle_hash_cfg()

static void handle_hash_cfg ( RzCore core,
const char *  name,
const ut8 block,
int  len 
)
static

Definition at line 2944 of file cmd_print.c.

2944  {
2945  RzHashSize digest_size = 0;
2946  ut8 *digest = rz_hash_cfg_calculate_small_block(core->hash, name, block, len, &digest_size);
2947  hexprint(digest, digest_size);
2948  free(digest);
2949 }
static void hexprint(const ut8 *data, int len)
Definition: cmd_print.c:2934

References free(), rz_core_t::hash, hexprint(), len, and rz_hash_cfg_calculate_small_block().

Referenced by rz_cmd_print_hash_cfg_handler().

◆ helpCmdTasks()

static void helpCmdTasks ( RzCore core)
static

Definition at line 1085 of file cmd_print.c.

1085  {
1086  // TODO: integrate with =h& and bg analysis/string/searches/..
1088 }
static const char * help_msg_amper[]
Definition: cmd_print.c:86

References help_msg_amper, and rz_core_cmd_help().

Referenced by rz_cmd_help().

◆ hexprint()

static void hexprint ( const ut8 data,
int  len 
)
inlinestatic

Definition at line 2934 of file cmd_print.c.

2934  {
2935  if (!data || len < 1) {
2936  return;
2937  }
2938  for (int i = 0; i < len; i++) {
2939  rz_cons_printf("%02x", data[i]);
2940  }
2941  rz_cons_newline();
2942 }

References i, len, rz_cons_newline(), and rz_cons_printf().

Referenced by handle_hash_cfg().

◆ lenof()

static int lenof ( ut64  off,
int  two 
)
static

Definition at line 5674 of file cmd_print.c.

5674  {
5675  char buf[64];
5676  buf[0] = 0;
5677  if (two) {
5678  snprintf(buf, sizeof(buf), "+0x%" PFMT64x, off);
5679  } else {
5680  snprintf(buf, sizeof(buf), "0x%08" PFMT64x, off);
5681  }
5682  return strlen(buf);
5683 }

References off, PFMT64x, and snprintf.

Referenced by rz_print_offset_sg().

◆ matchBar()

static void matchBar ( ut8 ptr,
int  i 
)
inlinestatic

Definition at line 3421 of file cmd_print.c.

3421  {
3422  if (ptr[i] < 0xff) {
3423  ptr[i]++;
3424  }
3425 }

References i.

Referenced by analBars(), and cmd_print_bars().

◆ old_transform_op()

static ut8* old_transform_op ( RzCore core,
const char *  val,
char  op,
int buflen 
)
static

Definition at line 2453 of file cmd_print.c.

2453  {
2454  RzCoreWriteOp wop;
2455  switch (op) {
2456  case '2':
2458  break;
2459  case '4':
2461  break;
2462  case '8':
2464  break;
2465  case 'a':
2466  wop = RZ_CORE_WRITE_OP_ADD;
2467  break;
2468  case 'A':
2469  wop = RZ_CORE_WRITE_OP_AND;
2470  break;
2471  case 'd':
2472  wop = RZ_CORE_WRITE_OP_DIV;
2473  break;
2474  case 'l':
2476  break;
2477  case 'm':
2478  wop = RZ_CORE_WRITE_OP_MUL;
2479  break;
2480  case 'o':
2481  wop = RZ_CORE_WRITE_OP_OR;
2482  break;
2483  case 'r':
2485  break;
2486  case 's':
2487  wop = RZ_CORE_WRITE_OP_SUB;
2488  break;
2489  case 'x':
2490  wop = RZ_CORE_WRITE_OP_XOR;
2491  break;
2492  default:
2493  wop = RZ_CORE_WRITE_OP_XOR;
2495  break;
2496  }
2497 
2498  ut8 *hex = NULL;
2499  int hexlen = -1;
2500  if (val) {
2502  hex = RZ_NEWS(ut8, (strlen(val) + 1) / 2);
2503  if (!hex) {
2504  return NULL;
2505  }
2506 
2507  hexlen = rz_hex_str2bin(val, hex);
2508  }
2509  ut8 *result = rz_core_transform_op(core, core->offset, wop, hex, hexlen, buflen);
2510  free(hex);
2511  return result;
2512 }
RZ_API RZ_OWN ut8 * rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen, int *buflen)
Transform a block of data at addr according to the operation op and the hexvalue hex.
Definition: cio.c:934
static const char hex[16]
Definition: print.c:21
RzCoreWriteOp
Definition: rz_core.h:105
@ RZ_CORE_WRITE_OP_BYTESWAP8
Swap the endianess of 8-bytes values.
Definition: rz_core.h:108
@ RZ_CORE_WRITE_OP_SHIFT_LEFT
Write the shift left of existing byte by argument value.
Definition: rz_core.h:116
@ RZ_CORE_WRITE_OP_AND
Write the bitwise-and of existing byte and argument value.
Definition: rz_core.h:113
@ RZ_CORE_WRITE_OP_SHIFT_RIGHT
Write the shift right of existing byte and argument value.
Definition: rz_core.h:117
@ RZ_CORE_WRITE_OP_BYTESWAP2
Swap the endianess of 2-bytes values.
Definition: rz_core.h:106
@ RZ_CORE_WRITE_OP_OR
Write the bitwise-or of existing byte and argument value.
Definition: rz_core.h:114
@ RZ_CORE_WRITE_OP_ADD
Write the addition of existing byte and argument value.
Definition: rz_core.h:109
@ RZ_CORE_WRITE_OP_MUL
Write the multiplication of existing byte and argument value.
Definition: rz_core.h:112
@ RZ_CORE_WRITE_OP_DIV
Write the division of existing byte and argument value.
Definition: rz_core.h:111
@ RZ_CORE_WRITE_OP_BYTESWAP4
Swap the endianess of 4-bytes values.
Definition: rz_core.h:107
@ RZ_CORE_WRITE_OP_XOR
Write the bitwise-xor of existing byte and argument value.
Definition: rz_core.h:115
@ RZ_CORE_WRITE_OP_SUB
Write the subtraction of existing byte and argument value.
Definition: rz_core.h:110
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
#define RZ_NEWS(x, y)
Definition: rz_types.h:283

References buflen, free(), hex, NULL, rz_core_t::offset, rz_core_transform_op(), RZ_CORE_WRITE_OP_ADD, RZ_CORE_WRITE_OP_AND, RZ_CORE_WRITE_OP_BYTESWAP2, RZ_CORE_WRITE_OP_BYTESWAP4, RZ_CORE_WRITE_OP_BYTESWAP8, RZ_CORE_WRITE_OP_DIV, RZ_CORE_WRITE_OP_MUL, RZ_CORE_WRITE_OP_OR, RZ_CORE_WRITE_OP_SHIFT_LEFT, RZ_CORE_WRITE_OP_SHIFT_RIGHT, RZ_CORE_WRITE_OP_SUB, RZ_CORE_WRITE_OP_XOR, rz_hex_str2bin(), RZ_NEWS, rz_str_trim_head_ro(), rz_warn_if_reached, and val.

Referenced by cmd_print_op().

◆ pr_bb()

static void pr_bb ( RzCore core,
RzAnalysisFunction fcn,
RzAnalysisBlock b,
bool  emu,
ut64  saved_gp,
ut8 saved_arena,
char  p_type,
bool  fromHere 
)
static

Definition at line 4168 of file cmd_print.c.

4168  {
4169  bool show_flags = rz_config_get_i(core->config, "asm.flags");
4170  const char *orig_bb_middle = rz_config_get(core->config, "asm.bb.middle");
4171  core->analysis->gp = saved_gp;
4172  if (fromHere) {
4173  if (b->addr < core->offset) {
4174  core->cons->null = true;
4175  } else {
4176  core->cons->null = false;
4177  }
4178  }
4179  if (emu) {
4180  if (b->parent_reg_arena) {
4181  ut64 gp;
4182  rz_reg_arena_poke(core->analysis->reg, b->parent_reg_arena);
4183  RZ_FREE(b->parent_reg_arena);
4184  gp = rz_reg_getv(core->analysis->reg, "gp");
4185  if (gp) {
4186  core->analysis->gp = gp;
4187  }
4188  } else {
4189  rz_reg_arena_poke(core->analysis->reg, saved_arena);
4190  }
4191  }
4192  if (b->parent_stackptr != INT_MAX) {
4193  core->analysis->stackptr = b->parent_stackptr;
4194  }
4195  rz_config_set_i(core->config, "asm.bb.middle", false);
4196  p_type == 'D'
4197  ? rz_core_cmdf(core, "pD %" PFMT64u " @ 0x%" PFMT64x, b->size, b->addr)
4198  : rz_core_cmdf(core, "pI %" PFMT64u " @ 0x%" PFMT64x, b->size, b->addr);
4199  rz_config_set(core->config, "asm.bb.middle", orig_bb_middle);
4200 
4201  if (b->jump != UT64_MAX) {
4202  if (b->jump > b->addr) {
4203  RzAnalysisBlock *jumpbb = rz_analysis_get_block_at(b->analysis, b->jump);
4204  if (jumpbb && rz_list_contains(jumpbb->fcns, fcn)) {
4205  if (emu && core->analysis->last_disasm_reg && !jumpbb->parent_reg_arena) {
4207  }
4208  if (jumpbb->parent_stackptr == INT_MAX) {
4209  jumpbb->parent_stackptr = core->analysis->stackptr + b->stackptr;
4210  }
4211  }
4212  }
4213  if (p_type == 'D' && show_flags) {
4214  rz_cons_printf("| ----------- true: 0x%08" PFMT64x, b->jump);
4215  }
4216  }
4217  if (b->fail != UT64_MAX) {
4218  if (b->fail > b->addr) {
4219  RzAnalysisBlock *failbb = rz_analysis_get_block_at(b->analysis, b->fail);
4220  if (failbb && rz_list_contains(failbb->fcns, fcn)) {
4221  if (emu && core->analysis->last_disasm_reg && !failbb->parent_reg_arena) {
4223  }
4224  if (failbb->parent_stackptr == INT_MAX) {
4225  failbb->parent_stackptr = core->analysis->stackptr + b->stackptr;
4226  }
4227  }
4228  }
4229  if (p_type == 'D' && show_flags) {
4230  rz_cons_printf(" false: 0x%08" PFMT64x, b->fail);
4231  }
4232  }
4233  if (p_type == 'D' && show_flags) {
4234  rz_cons_newline();
4235  }
4236 }
RZ_API ut8 * rz_reg_arena_dup(RzReg *reg, const ut8 *source)
Definition: arena.c:301
RZ_API RzAnalysisBlock * rz_analysis_get_block_at(RzAnalysis *analysis, ut64 addr)
Definition: block.c:90
#define INT_MAX
Definition: cp-demangle.c:131
RZ_API RZ_BORROW RzListIter * rz_list_contains(RZ_NONNULL const RzList *list, RZ_NONNULL const void *ptr)
Returns the RzListIter of the given pointer, if found.
Definition: list.c:592
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
ut8 * parent_reg_arena
Definition: rz_analysis.h:877
ut8 * last_disasm_reg
Definition: rz_analysis.h:569

References rz_core_t::analysis, b, rz_core_t::config, rz_core_t::cons, rz_analysis_bb_t::fcns, rz_analysis_t::gp, INT_MAX, rz_analysis_t::last_disasm_reg, rz_cons_t::null, rz_core_t::offset, rz_analysis_bb_t::parent_reg_arena, rz_analysis_bb_t::parent_stackptr, PFMT64u, PFMT64x, rz_analysis_t::reg, rz_analysis_get_block_at(), rz_config_get(), rz_config_get_i(), rz_config_set(), rz_config_set_i(), rz_cons_newline(), rz_cons_printf(), rz_core_cmdf(), RZ_FREE, rz_list_contains(), rz_reg_arena_dup(), rz_reg_arena_poke(), rz_reg_getv(), rz_analysis_t::stackptr, ut64(), and UT64_MAX.

Referenced by core_walk_function_blocks(), and func_walk_blocks().

◆ print_format_help_help_help_help()

static void print_format_help_help_help_help ( RzCore core)
static

Definition at line 1090 of file cmd_print.c.

1090  {
1091  const char *help_msg[] = {
1092  " STAHP IT!!!", "", "",
1093  NULL
1094  };
1095  rz_core_cmd_help(core, help_msg);
1096 }

References NULL, and rz_core_cmd_help().

Referenced by cmd_print_format().

◆ print_json_string()

static void print_json_string ( RzCore core,
const ut8 block,
ut32  len,
RzStrEnc  encoding,
bool  stop_at_nil 
)
static

Definition at line 4388 of file cmd_print.c.

4388  {
4389  char *section = get_section_name(core);
4390  if (!section) {
4391  return;
4392  }
4393  ut32 dlength = 0;
4394  RzStrStringifyOpt opt = { 0 };
4395  opt.buffer = block;
4396  opt.length = len;
4397  opt.encoding = encoding;
4398  opt.json = true;
4399  opt.stop_at_nil = stop_at_nil;
4400  char *dstring = rz_str_stringify_raw_buffer(&opt, &dlength);
4401  if (!dstring) {
4402  free(section);
4403  return;
4404  }
4405 
4406  PJ *pj = pj_new();
4407  if (!pj) {
4408  free(section);
4409  free(dstring);
4410  return;
4411  }
4412 
4413  const char *enc_name = rz_str_enc_as_string(encoding);
4414  pj_o(pj);
4415  pj_k(pj, "string");
4416  pj_raw(pj, "\"");
4417  pj_raw(pj, dstring);
4418  pj_raw(pj, "\"");
4419  pj_kn(pj, "offset", core->offset);
4420  pj_ks(pj, "section", section);
4421  pj_kn(pj, "length", dlength);
4422  pj_ks(pj, "type", enc_name);
4423  pj_end(pj);
4425  pj_free(pj);
4426  free(section);
4427  free(dstring);
4428 }
static char * get_section_name(RzCore *core)
Definition: cmd_print.c:4373
RZ_API void pj_raw(PJ *j, const char *k)
Definition: pj.c:7
RZ_API const char * rz_str_enc_as_string(RzStrEnc enc)
Definition: str.c:44
bool stop_at_nil
When enabled stops printing when '\0' is found.
Definition: rz_str.h:274
bool json
Encodes the output as a JSON string.
Definition: rz_str.h:273
const ut8 * buffer
String buffer (cannot be NULL).
Definition: rz_str.h:268
RzStrEnc encoding
String encoding type (cannot be RZ_STRING_ENC_GUESS)
Definition: rz_str.h:270
ut32 length
String buffer length.
Definition: rz_str.h:269

References rz_str_stringify_opt_t::buffer, cmd_descs_generate::encoding, rz_str_stringify_opt_t::encoding, free(), get_section_name(), rz_str_stringify_opt_t::json, len, rz_str_stringify_opt_t::length, rz_core_t::offset, pj_end(), pj_free(), pj_k(), pj_kn(), pj_ks(), pj_new(), pj_o(), pj_raw(), pj_string(), rz_cons_println(), rz_str_enc_as_string(), rz_str_stringify_raw_buffer(), and rz_str_stringify_opt_t::stop_at_nil.

Referenced by rz_cmd_print(), rz_print_utf16be_handler(), rz_print_utf16le_handler(), rz_print_utf32be_handler(), and rz_print_utf32le_handler().

◆ printraw()

static void printraw ( RzCore core,
int  len 
)
static

Definition at line 2554 of file cmd_print.c.

2554  {
2555  int obsz = core->blocksize;
2556  int restore_obsz = 0;
2557  if (len != obsz) {
2558  if (!rz_core_block_size(core, len)) {
2559  len = core->blocksize;
2560  } else {
2561  restore_obsz = 1;
2562  }
2563  }
2564  rz_print_raw(core->print, core->offset, core->block, len);
2565  if (restore_obsz) {
2566  (void)rz_core_block_size(core, obsz);
2567  }
2568  core->cons->newline = core->cmd_in_backticks ? false : true;
2569 }
#define false
RZ_API void rz_print_raw(RzPrint *p, ut64 addr, const ut8 *buf, int len)
Definition: print.c:1249
RZ_DEPRECATE bool newline
Definition: rz_cons.h:556
RZ_DEPRECATE bool cmd_in_backticks
Definition: rz_core.h:343

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::cmd_in_backticks, rz_core_t::cons, false, len, rz_cons_t::newline, rz_core_t::offset, rz_core_t::print, rz_core_block_size(), and rz_print_raw().

Referenced by rz_cmd_print().

◆ rz_assembly_of_hex_alias_handler()

RZ_IPI RzCmdStatus rz_assembly_of_hex_alias_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4672 of file cmd_print.c.

4672  {
4673  return rz_assembly_of_hex_handler(core, argc, argv, mode);
4674 }
RZ_IPI RzCmdStatus rz_assembly_of_hex_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode)
Definition: cmd_print.c:4650

References argv, and rz_assembly_of_hex_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_assembly_of_hex_handler()

RZ_IPI RzCmdStatus rz_assembly_of_hex_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4650 of file cmd_print.c.

4650  {
4651  ut8 *hex = calloc(1, strlen(argv[1]) + 1);
4652  if (!hex) {
4653  RZ_LOG_ERROR("Fail to allocate memory\n");
4654  return RZ_CMD_STATUS_ERROR;
4655  }
4656  int len = rz_hex_str2bin(argv[1], hex);
4657  if (len < 1) {
4658  RZ_LOG_ERROR("rz_hex_str2bin: invalid hexstr\n");
4659  free(hex);
4660  return RZ_CMD_STATUS_ERROR;
4661  }
4662  char *buf = rz_core_assembly_of_hex(core, hex, len);
4663  if (!buf) {
4664  free(hex);
4665  return RZ_CMD_STATUS_ERROR;
4666  }
4667  rz_cons_print(buf);
4668  free(buf);
4669  return RZ_CMD_STATUS_OK;
4670 }
RZ_API RZ_OWN char * rz_core_assembly_of_hex(RzCore *core, ut8 *hex, int len)
Get the assembly of the hexstr.
Definition: cprint.c:109

References argv, calloc(), free(), hex, len, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_assembly_of_hex(), rz_hex_str2bin(), and RZ_LOG_ERROR.

Referenced by rz_assembly_of_hex_alias_handler(), and rzshell_cmddescs_init().

◆ rz_cmd_base64_decode_handler()

RZ_IPI RzCmdStatus rz_cmd_base64_decode_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 7022 of file cmd_print.c.

7022  {
7023  ut8 *buf = rz_base64_decode_dyn((const char *)core->block, core->blocksize);
7024  if (!buf) {
7025  RZ_LOG_ERROR("rz_base64_decode_dyn: error\n");
7026  return RZ_CMD_STATUS_ERROR;
7027  }
7028  rz_cons_println((const char *)buf);
7029  free(buf);
7030  return RZ_CMD_STATUS_OK;
7031 }
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65

References rz_core_t::block, rz_core_t::blocksize, free(), rz_base64_decode_dyn(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_base64_encode_handler()

RZ_IPI RzCmdStatus rz_cmd_base64_encode_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 7011 of file cmd_print.c.

7011  {
7012  char *buf = rz_base64_encode_dyn((const unsigned char *)core->block, core->blocksize);
7013  if (!buf) {
7014  RZ_LOG_ERROR("rz_base64_encode_dyn: error\n");
7015  return RZ_CMD_STATUS_ERROR;
7016  }
7017  rz_cons_println((const char *)buf);
7018  free(buf);
7019  return RZ_CMD_STATUS_OK;
7020 }
RZ_API char * rz_base64_encode_dyn(const ut8 *bin, size_t sz)
Definition: ubase64.c:92

References rz_core_t::block, rz_core_t::blocksize, free(), rz_base64_encode_dyn(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_comments_in_n_instructions_handler()

RZ_IPI RzCmdStatus rz_cmd_comments_in_n_instructions_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6521 of file cmd_print.c.

6521  {
6522  st64 parsed = argc > 1 ? (st64)rz_num_math(core->num, argv[1]) : core->blocksize;
6523  if (parsed > ST16_MAX || parsed < ST16_MIN) {
6524  RZ_LOG_ERROR("the number of instructions is too big (%d < n_instrs < %d).\n", ST16_MAX, ST16_MIN);
6525  return RZ_CMD_STATUS_ERROR;
6526  }
6527  int n_instrs = parsed;
6528  if (rz_core_disasm_pdi(core, n_instrs, 0, 'C') < 0) {
6529  return RZ_CMD_STATUS_ERROR;
6530  }
6531  return RZ_CMD_STATUS_OK;
6532 }
#define ST16_MIN

References argv, rz_core_t::blocksize, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_disasm_pdi(), RZ_LOG_ERROR, rz_num_math(), ST16_MAX, ST16_MIN, and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_recursively_from_current_block_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_from_current_block_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6919 of file cmd_print.c.

6919  {
6920  RzAnalysisFunction *function = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
6921  // RZ_ANALYSIS_FCN_TYPE_FCN|RZ_ANALYSIS_FCN_TYPE_SYM);
6922  if (!function) {
6923  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6924  return RZ_CMD_STATUS_ERROR;
6925  }
6926 
6928  bool ret = core_walk_function_blocks(core, function, state, 'D', true);
6930  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
6931 }
static bool core_walk_function_blocks(RzCore *core, RzAnalysisFunction *f, RzCmdStateOutput *state, char type_print, bool fromHere)
Definition: cmd_print.c:6851

References rz_core_t::analysis, core_walk_function_blocks(), rz_core_t::offset, PFMT64x, rz_analysis_get_fcn_in(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_recursively_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6905 of file cmd_print.c.

6905  {
6906  RzAnalysisFunction *function = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
6907  // RZ_ANALYSIS_FCN_TYPE_FCN|RZ_ANALYSIS_FCN_TYPE_SYM);
6908  if (!function) {
6909  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6910  return RZ_CMD_STATUS_ERROR;
6911  }
6912 
6914  bool ret = core_walk_function_blocks(core, function, state, 'D', false);
6916  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
6917 }

References rz_core_t::analysis, core_walk_function_blocks(), rz_core_t::offset, PFMT64x, rz_analysis_get_fcn_in(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_recursively_no_function_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_recursively_no_function_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6933 of file cmd_print.c.

6933  {
6934  ut64 old_offset = core->offset;
6935  RzAnalysisOp aop = { 0 };
6936  ut32 aop_type;
6937  ut64 aop_jump;
6938  int aop_size;
6939 
6941  for (ut64 count = core->blocksize, offset = core->offset; count > 0; count--) {
6942  rz_core_seek(core, offset, true);
6943 
6944  rz_analysis_op_init(&aop);
6945  int ret = rz_analysis_op(core->analysis, &aop, offset, core->block, core->blocksize, RZ_ANALYSIS_OP_MASK_BASIC);
6946  if (ret > 0) {
6947  aop_type = aop.type;
6948  aop_jump = aop.jump;
6949  aop_size = aop.size;
6950  }
6951  rz_analysis_op_fini(&aop);
6952 
6953  if (ret < 1 || aop_size < 1) {
6954  offset++;
6955  continue;
6956  }
6957 
6958  core_disassembly(core, core->blocksize, 1, state, false);
6959 
6960  switch (aop_type) {
6962  offset = aop_jump;
6963  continue;
6965  break;
6967  count = 1; // stop disassembling when hitting RET
6968  break;
6969  default:
6970  break;
6971  }
6972  offset += aop_size;
6973  }
6975 
6976  rz_core_seek(core, old_offset, true);
6977  return RZ_CMD_STATUS_OK;
6978 }
static bool core_disassembly(RzCore *core, int n_bytes, int n_instrs, RzCmdStateOutput *state, bool cbytes)
Definition: cmd_print.c:6289
RZ_API void rz_analysis_op_init(RzAnalysisOp *op)
Definition: op.c:23

References rz_core_t::analysis, rz_core_t::block, rz_core_t::blocksize, core_disassembly(), count, rz_analysis_op_t::jump, rz_core_t::offset, rz_analysis_op(), rz_analysis_op_fini(), rz_analysis_op_init(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_UCJMP, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_OK, rz_core_seek(), rz_analysis_op_t::size, rz_analysis_op_t::type, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_ropchain_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_ropchain_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6787 of file cmd_print.c.

6787  {
6788  ut64 limit = argc > 1 ? rz_num_math(core->num, argv[1]) : 1024;
6789  if (limit > 1024) {
6790  RZ_LOG_ERROR("the limit value exceeds the max value (1024).\n");
6791  return RZ_CMD_STATUS_ERROR;
6792  }
6793  ut64 asm_bits = core->rasm->bits;
6794  bool big_endian = rz_config_get_b(core->config, "cfg.bigendian");
6795  bool src_color = rz_config_get_i(core->config, "scr.color") > 0;
6796 
6797  const char *off_color = src_color ? rz_cons_singleton()->context->pal.offset : "";
6798  const char *num_color = src_color ? rz_cons_singleton()->context->pal.num : "";
6799  const char *end_color = src_color ? Color_RESET : "";
6800 
6801  if (asm_bits < 64) {
6802  asm_bits = 32;
6803  }
6804 
6805  ut32 asm_bytes = asm_bits / 8;
6806  if (core->blocksize < asm_bytes) {
6807  RZ_LOG_ERROR("block size is not enough big to host a word (needs to be >= %u bytes).\n", asm_bytes);
6808  return RZ_CMD_STATUS_ERROR;
6809  }
6810 
6811  ut8 *bytes = RZ_NEWS0(ut8, core->blocksize);
6812  if (!bytes) {
6813  RZ_LOG_ERROR("cannot allocate buffer.\n");
6814  return RZ_CMD_STATUS_ERROR;
6815  }
6816 
6817  (void)rz_io_read_at(core->io, core->offset, bytes, core->blocksize);
6818 
6820  for (ut32 i = 0; i < core->blocksize - asm_bytes; i += asm_bytes) {
6821  ut64 number = rz_read_ble(bytes + i, big_endian, asm_bits);
6822  switch (state->mode) {
6823  case RZ_OUTPUT_MODE_QUIET:
6824  rz_cons_printf("%s0x%08" PFMT64x "%s %s0x%08" PFMT64x "%s\n", off_color, core->offset + i, end_color, num_color, number, end_color);
6826  break;
6828  rz_cons_printf("[%s0x%08" PFMT64x "%s] %s0x%08" PFMT64x "%s\n", off_color, core->offset + i, end_color, num_color, number, end_color);
6830  break;
6831  case RZ_OUTPUT_MODE_JSON:
6832  pj_o(state->d.pj);
6833  pj_kn(state->d.pj, "address", core->offset + i);
6834  pj_kn(state->d.pj, "bits", asm_bits);
6835  pj_kn(state->d.pj, "word", number);
6836  pj_ka(state->d.pj, "opcodes");
6838  pj_end(state->d.pj);
6839  pj_end(state->d.pj);
6840  break;
6841  default:
6843  return RZ_CMD_STATUS_ERROR;
6844  }
6845  }
6847 
6848  return RZ_CMD_STATUS_OK;
6849 }
static void disassemble_till_return_is_found(RzCore *core, ut64 offset, ut64 limit, RzCmdStateOutput *state)
Definition: cmd_print.c:6742
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282

References argv, rz_asm_t::bits, rz_core_t::blocksize, bytes, Color_RESET, rz_core_t::config, rz_cons_t::context, disassemble_till_return_is_found(), i, rz_core_t::io, limit, rz_cons_printable_palette_t::num, rz_core_t::num, rz_cons_printable_palette_t::offset, rz_core_t::offset, rz_cons_context_t::pal, PFMT64x, pj_end(), pj_ka(), pj_kn(), pj_o(), rz_core_t::rasm, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_config_get_i(), rz_cons_printf(), rz_cons_singleton(), rz_io_read_at(), RZ_LOG_ERROR, RZ_NEWS0, rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_read_ble(), rz_warn_if_reached, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_summarize_block_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_block_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6996 of file cmd_print.c.

6996  {
6997  ut64 n_bytes = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
6998  if (!n_bytes) {
6999  RZ_LOG_ERROR("Invalid number of bytes\n");
7000  return RZ_CMD_STATUS_ERROR;
7001  }
7002 
7003  // small patch to reuse disasm_strings which
7004  // needs to be rewritten entirely
7005  char input_cmd[256];
7006  rz_strf(input_cmd, "dsb 0x%" PFMT64x, n_bytes);
7007  disasm_strings(core, input_cmd, NULL);
7008  return RZ_CMD_STATUS_OK;
7009 }
static void disasm_strings(RzCore *core, const char *input, RzAnalysisFunction *fcn)
Definition: cmd_print.c:2596
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59

References argv, disasm_strings(), NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_num_math(), rz_strf, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_summarize_function_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_function_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6991 of file cmd_print.c.

6991  {
6992  disasm_strings(core, "dsf", NULL);
6993  return RZ_CMD_STATUS_OK;
6994 }

References disasm_strings(), NULL, and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassemble_summarize_n_bytes_handler()

RZ_IPI RzCmdStatus rz_cmd_disassemble_summarize_n_bytes_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6980 of file cmd_print.c.

6980  {
6981  ut64 n_bytes = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
6982 
6983  // small patch to reuse disasm_strings which
6984  // needs to be rewritten entirely
6985  char input_cmd[256];
6986  rz_strf(input_cmd, "ds 0x%" PFMT64x, n_bytes);
6987  disasm_strings(core, argc > 1 ? input_cmd : "ds", NULL);
6988  return RZ_CMD_STATUS_OK;
6989 }

References argv, disasm_strings(), NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_OK, rz_num_math(), rz_strf, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_all_methods_class_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_all_methods_class_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6659 of file cmd_print.c.

6659  {
6660  ut32 old_blocksize = core->blocksize;
6661  ut64 old_offset = core->offset;
6662 
6663  int len = 0;
6664  ut64 at = findClassBounds(core, &len);
6665  if (!at) {
6666  RZ_LOG_ERROR("Cannot find class at 0x%" PFMT64x ".\n", core->offset);
6667  return RZ_CMD_STATUS_ERROR;
6668  }
6669 
6670  rz_core_seek(core, at, true);
6671 
6672  // TODO: remove this and use C api.
6673  // on success returns 0 else negative
6674  int ret = rz_core_cmdf(core, "pD %d", len);
6675 
6676  rz_core_block_size(core, old_blocksize);
6677  rz_core_seek(core, old_offset, true);
6678  return ret >= 0 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
6679 }
static ut64 findClassBounds(RzCore *core, int *len)
Definition: cmd_print.c:917

References rz_core_t::blocksize, findClassBounds(), len, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_size(), rz_core_cmdf(), rz_core_seek(), RZ_LOG_ERROR, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_all_possible_opcodes_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_all_possible_opcodes_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6342 of file cmd_print.c.

6342  {
6343  ut64 n_bytes = argc > 1 ? rz_num_math(core->num, argv[1]) : core->blocksize;
6344  bool color = rz_config_get_i(core->config, "scr.color") > 0;
6345  RzAsmOp asm_op = { 0 };
6346  ut32 old_blocksize = core->blocksize;
6347 
6348  if (n_bytes > old_blocksize) {
6349  rz_core_block_size(core, n_bytes);
6350  rz_core_block_read(core);
6351  }
6352 
6355  for (ut64 position = 0; position < n_bytes && !rz_cons_is_breaked(); position++) {
6356  ut64 offset = core->offset + position;
6357  rz_asm_set_pc(core->rasm, offset);
6358  ut8 *buffer = core->block + position;
6359  ut32 length = n_bytes - position;
6360  int op_size = rz_asm_disassemble(core->rasm, &asm_op, buffer, length);
6361  char *op_hex = rz_hex_bin2strdup(buffer, RZ_MAX(op_size, 1));
6362  char *assembly = strdup(op_size > 0 ? rz_asm_op_get_asm(&asm_op) : "illegal");
6363  char *colored = NULL;
6364 
6365  if (color && state->mode != RZ_OUTPUT_MODE_JSON) {
6366  RzAnalysisOp aop = { 0 };
6368  RzStrBuf *colored_asm, *bw_str = rz_strbuf_new(assembly);
6369  colored_asm = rz_asm_colorize_asm_str(bw_str, core->print, rz_asm_get_parse_param(core->analysis->reg, aop.type), asm_op.asm_toks);
6370  colored = rz_strbuf_drain(colored_asm);
6371  }
6372 
6373  switch (state->mode) {
6375  rz_cons_printf("0x%08" PFMT64x " %20s %s\n", offset, op_hex, colored ? colored : assembly);
6376  break;
6377  case RZ_OUTPUT_MODE_JSON:
6378  pj_o(state->d.pj);
6379  pj_kn(state->d.pj, "addr", offset);
6380  pj_ks(state->d.pj, "bytes", op_hex);
6381  pj_ks(state->d.pj, "inst", assembly);
6382  pj_end(state->d.pj);
6383  break;
6384  case RZ_OUTPUT_MODE_QUIET:
6385  rz_cons_printf("%s\n", colored ? colored : assembly);
6386  break;
6387  default:
6389  break;
6390  }
6391  free(op_hex);
6392  free(assembly);
6393  free(colored);
6394  }
6397 
6398  if (n_bytes > old_blocksize) {
6399  rz_core_block_size(core, old_blocksize);
6400  rz_core_block_read(core);
6401  }
6402  return RZ_CMD_STATUS_OK;
6403 }
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
RZ_API RZ_OWN RzAsmParseParam * rz_asm_get_parse_param(RZ_NULLABLE const RzReg *reg, ut32 ana_op_type)
Does all kinds of NULL checks on the parameters and returns an initialized RzAsmParseParam or NULL on...
Definition: asm.c:1763
RZ_DEPRECATE RZ_API RZ_OWN RzStrBuf * rz_asm_colorize_asm_str(RZ_BORROW RzStrBuf *asm_str, RZ_BORROW RzPrint *p, RZ_NULLABLE const RzAsmParseParam *param, RZ_NULLABLE const RzAsmTokenString *toks)
Colors a given asm string and returns it. If toks is not NULL it uses the tokens to color the asm str...
Definition: asm.c:1741
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
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
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 length
Definition: sflib.h:133
@ RZ_ANALYSIS_OP_MASK_ALL
Definition: rz_analysis.h:447
RzAsmTokenString * asm_toks
Tokenized asm string.
Definition: rz_asm.h:74

References rz_core_t::analysis, argv, rz_asm_op_t::asm_toks, rz_core_t::block, rz_core_t::blocksize, color, rz_core_t::config, free(), length, NULL, rz_core_t::num, rz_core_t::offset, PFMT64x, pj_end(), pj_kn(), pj_ks(), pj_o(), rz_core_t::print, rz_core_t::rasm, rz_analysis_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_ALL, rz_asm_colorize_asm_str(), rz_asm_disassemble(), rz_asm_get_parse_param(), rz_asm_op_get_asm(), rz_asm_set_pc(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_OK, rz_config_get_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_printf(), rz_core_block_read(), rz_core_block_size(), rz_hex_bin2strdup(), RZ_MAX, rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_strbuf_drain(), rz_strbuf_new(), rz_warn_if_reached, strdup(), rz_analysis_op_t::type, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_all_possible_opcodes_treeview_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_all_possible_opcodes_treeview_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6405 of file cmd_print.c.

6405  {
6406  bool color = rz_config_get_i(core->config, "scr.color") > 0;
6407  RzAsmOp asm_op = { 0 };
6408  const ut32 n_bytes = 28; // uses 56 chars
6409  ut32 old_blocksize = core->blocksize;
6410 
6411  if (old_blocksize < n_bytes) {
6412  rz_core_block_size(core, 256);
6413  rz_core_block_read(core);
6414  }
6415 
6417  for (ut32 position = 0; position < n_bytes && !rz_cons_is_breaked(); position++) {
6418  ut64 offset = core->offset + position;
6419  rz_asm_set_pc(core->rasm, offset);
6420  ut8 *buffer = core->block + position;
6421  ut32 length = RZ_MAX(n_bytes - position, core->blocksize - position);
6422  int op_size = rz_asm_disassemble(core->rasm, &asm_op, buffer, length);
6423  if (op_size < 1) {
6424  continue;
6425  }
6426  op_size = RZ_MAX(op_size, 1);
6427  char *op_hex = rz_hex_bin2strdup(buffer, op_size);
6428  char *assembly = strdup(op_size > 0 ? rz_asm_op_get_asm(&asm_op) : "illegal");
6429  char *colored = NULL;
6430 
6431  if (color) {
6432  RzAnalysisOp aop = { 0 };
6434  RzStrBuf *colored_asm, *bw_str = rz_strbuf_new(assembly);
6435  colored_asm = rz_asm_colorize_asm_str(bw_str, core->print, rz_asm_get_parse_param(core->analysis->reg, aop.type), asm_op.asm_toks);
6436  colored = rz_strbuf_drain(colored_asm);
6437  }
6438 
6439  int padding = position * 2;
6440  int space = 60 - padding;
6441 
6442  if ((position + op_size) >= 30) {
6443  ut32 last = (30 - position) * 2;
6444  op_hex[last - 1] = '.';
6445  op_hex[last] = 0;
6446  }
6447 
6448  rz_cons_printf("0x%08" PFMT64x " %*s%*s %s\n", offset, padding, "", -space, op_hex, colored ? colored : assembly);
6449  free(op_hex);
6450  free(assembly);
6451  free(colored);
6452  }
6454 
6455  if (old_blocksize < n_bytes) {
6456  rz_core_block_size(core, old_blocksize);
6457  rz_core_block_read(core);
6458  }
6459  return RZ_CMD_STATUS_OK;
6460 }

References rz_core_t::analysis, rz_asm_op_t::asm_toks, rz_core_t::block, rz_core_t::blocksize, color, rz_core_t::config, free(), length, NULL, rz_core_t::offset, PFMT64x, rz_core_t::print, rz_core_t::rasm, rz_analysis_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_ALL, rz_asm_colorize_asm_str(), rz_asm_disassemble(), rz_asm_get_parse_param(), rz_asm_op_get_asm(), rz_asm_set_pc(), RZ_CMD_STATUS_OK, rz_config_get_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_printf(), rz_core_block_read(), rz_core_block_size(), rz_hex_bin2strdup(), RZ_MAX, rz_strbuf_drain(), rz_strbuf_new(), strdup(), rz_analysis_op_t::type, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_basic_block_as_text_json_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_basic_block_as_text_json_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6498 of file cmd_print.c.

6498  {
6500  core->num->value = 0;
6501  if (!b) {
6502  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6503  return RZ_CMD_STATUS_ERROR;
6504  }
6505 
6506  ut8 *block = malloc(b->size + 1);
6507  if (!block) {
6508  RZ_LOG_ERROR("Cannot allocate buffer\n");
6509  return RZ_CMD_STATUS_ERROR;
6510  }
6511  rz_io_read_at(core->io, b->addr, block, b->size);
6512  RzCoreDisasmOptions disasm_options = {
6513  .cbytes = 2,
6514  };
6515  core->num->value = rz_core_print_disasm(core, b->addr, block, b->size, 9999, state, &disasm_options);
6516 
6517  free(block);
6518  return RZ_CMD_STATUS_OK;
6519 }

References rz_core_t::analysis, b, free(), rz_core_t::io, malloc(), rz_core_t::num, rz_core_t::offset, PFMT64x, rz_analysis_find_most_relevant_block_in(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_print_disasm(), rz_io_read_at(), RZ_LOG_ERROR, and rz_num_t::value.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_basic_block_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_basic_block_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6462 of file cmd_print.c.

6462  {
6464  core->num->value = 0;
6465  if (!b) {
6466  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6467  return RZ_CMD_STATUS_ERROR;
6468  }
6469 
6470  ut8 *block = malloc(b->size + 1);
6471  if (!block) {
6472  RZ_LOG_ERROR("Cannot allocate buffer\n");
6473  return RZ_CMD_STATUS_ERROR;
6474  }
6475  rz_io_read_at(core->io, b->addr, block, b->size);
6476  RzCoreDisasmOptions disasm_options = {
6477  .cbytes = 2,
6478  };
6480  switch (state->mode) {
6482  core->num->value = rz_core_print_disasm(core, b->addr, block, b->size, 9999, state, &disasm_options);
6483  break;
6484  case RZ_OUTPUT_MODE_JSON:
6485  core->num->value = 1;
6486  rz_core_print_disasm_json(core, b->addr, block, b->size, 0, state->d.pj);
6487  break;
6488  default:
6490  break;
6491  }
6493 
6494  free(block);
6495  return RZ_CMD_STATUS_OK;
6496 }

References rz_core_t::analysis, b, free(), rz_core_t::io, malloc(), rz_core_t::num, rz_core_t::offset, PFMT64x, rz_analysis_find_most_relevant_block_in(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_print_disasm(), rz_core_print_disasm_json(), rz_io_read_at(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, and rz_num_t::value.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_function_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_function_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6546 of file cmd_print.c.

6546  {
6547  core->num->value = 0;
6548  ut32 old_blocksize = core->blocksize;
6550  if (!function) {
6551  function = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
6552  }
6553  if (!function) {
6554  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6555  return RZ_CMD_STATUS_ERROR;
6556  }
6557 
6558  if (state->mode == RZ_OUTPUT_MODE_JSON) {
6559  bool ret = rz_core_print_function_disasm_json(core, function, state->d.pj);
6560  rz_core_block_size(core, old_blocksize);
6561  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
6562  }
6563 
6564  ut64 linear_size = rz_analysis_function_linear_size(function);
6565  ut64 max_real_size = rz_analysis_function_realsize(function) + 4096;
6566  if (max_real_size < linear_size) {
6567  RZ_LOG_ERROR("Linear size differs too much from the bbsum, please use pdr instead.\n");
6568  return RZ_CMD_STATUS_ERROR;
6569  }
6570 
6571  ut64 start = function->addr; // For pdf, start disassembling at the entrypoint
6573  if (end <= start) {
6574  RZ_LOG_ERROR("Cannot print function because the end offset is less or equal to the start offset\n");
6575  return RZ_CMD_STATUS_ERROR;
6576  }
6577 
6578  ut64 size = end - start;
6579  ut8 *bytes = malloc(size);
6580  if (!bytes) {
6581  RZ_LOG_ERROR("Cannot allocate buffer\n");
6582  return RZ_CMD_STATUS_ERROR;
6583  }
6584 
6585  (void)rz_io_read_at(core->io, start, bytes, size);
6586  RzCoreDisasmOptions disasm_options = {
6587  .cbytes = 1,
6588  .function = function,
6589  };
6590  core->num->value = rz_core_print_disasm(core, start, bytes, size, size, state, &disasm_options);
6591  free(bytes);
6592 
6593  rz_core_block_size(core, old_blocksize);
6594  return RZ_CMD_STATUS_OK;
6595 }
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API ut64 rz_analysis_function_linear_size(RzAnalysisFunction *fcn)
Definition: function.c:318
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
RZ_API bool rz_core_print_function_disasm_json(RzCore *core, RzAnalysisFunction *fcn, PJ *pj)
Definition: disasm.c:6726
@ RZ_ANALYSIS_FCN_TYPE_ROOT
Definition: rz_analysis.h:198

References rz_core_t::analysis, rz_core_t::blocksize, bytes, test_evm::end, free(), rz_core_t::io, malloc(), rz_core_t::num, rz_core_t::offset, PFMT64x, RZ_ANALYSIS_FCN_TYPE_ROOT, rz_analysis_function_linear_size(), rz_analysis_function_max_addr(), rz_analysis_function_realsize(), rz_analysis_get_fcn_in(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_size(), rz_core_print_disasm(), rz_core_print_function_disasm_json(), rz_io_read_at(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, start, ut64(), and rz_num_t::value.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_function_summary_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_function_summary_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6597 of file cmd_print.c.

6597  {
6598  ut64 old_offset = core->offset;
6599  ut32 old_blocksize = core->blocksize;
6601  if (!function) {
6602  RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
6603  return RZ_CMD_STATUS_ERROR;
6604  }
6606  ut32 fs = rz_analysis_function_linear_size(function);
6607  rz_core_seek(core, old_offset, SEEK_SET);
6608  rz_core_block_size(core, RZ_MAX(rs, fs));
6609  disasm_strings(core, "dfs", function);
6610 
6611  rz_core_block_size(core, old_blocksize);
6612  rz_core_seek(core, old_offset, SEEK_SET);
6613  return RZ_CMD_STATUS_OK;
6614 }
#define rs()
@ RZ_ANALYSIS_FCN_TYPE_SYM
Definition: rz_analysis.h:195
@ RZ_ANALYSIS_FCN_TYPE_FCN
Definition: rz_analysis.h:193
#define SEEK_SET
Definition: zip.c:88

References rz_core_t::analysis, rz_core_t::blocksize, disasm_strings(), rz_core_t::offset, PFMT64x, rs, RZ_ANALYSIS_FCN_TYPE_FCN, RZ_ANALYSIS_FCN_TYPE_SYM, rz_analysis_function_linear_size(), rz_analysis_function_realsize(), rz_analysis_get_fcn_in(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_size(), rz_core_seek(), RZ_LOG_ERROR, RZ_MAX, SEEK_SET, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_n_bytes_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_n_bytes_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6332 of file cmd_print.c.

6332  {
6333  int n_bytes = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6334  return bool2status(core_disassembly(core, n_bytes, 0, state, true));
6335 }
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208

References argv, rz_core_t::blocksize, bool2status(), core_disassembly(), int, rz_core_t::num, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_n_instrs_as_text_json_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instrs_as_text_json_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6616 of file cmd_print.c.

6616  {
6617  ut32 old_blocksize = core->blocksize;
6618  ut64 old_offset = core->offset;
6619  core->num->value = 0;
6620 
6621  st64 parsed = argc > 1 ? (st64)rz_num_math(core->num, argv[1]) : 0;
6622  if (parsed > ST16_MAX || parsed < ST16_MIN) {
6623  RZ_LOG_ERROR("the number of instructions is too big (%d < n_instrs < %d).\n", ST16_MAX, ST16_MIN);
6624  return RZ_CMD_STATUS_ERROR;
6625  }
6626  int n_instrs = parsed;
6627  if (n_instrs < 0) {
6628  ut64 new_offset = old_offset;
6629  if (!rz_core_prevop_addr(core, old_offset, -n_instrs, &new_offset)) {
6630  new_offset = rz_core_prevop_addr_force(core, old_offset, -n_instrs);
6631  }
6632  ut32 new_blocksize = new_offset - old_blocksize;
6633  if (new_blocksize > old_blocksize) {
6634  rz_core_block_size(core, new_blocksize);
6635  }
6636  rz_core_seek(core, new_offset, true);
6637  } else {
6638  rz_core_block_read(core);
6639  }
6640 
6641  state->mode = RZ_OUTPUT_MODE_JSON;
6642 
6643  if (rz_cons_singleton()->is_html) {
6644  rz_cons_singleton()->is_html = false;
6645  rz_cons_singleton()->was_html = true;
6646  }
6647  RzCoreDisasmOptions disasm_options = {
6648  .cbytes = 1,
6649  };
6650  core->num->value = rz_core_print_disasm(core, core->offset, core->block, core->blocksize, RZ_ABS(n_instrs), state, &disasm_options);
6651 
6652  if (n_instrs < 0) {
6653  rz_core_block_size(core, old_blocksize);
6654  rz_core_seek(core, old_offset, true);
6655  }
6656  return RZ_CMD_STATUS_OK;
6657 }
@ RZ_ABS
bool was_html
Definition: rz_cons.h:506
bool is_html
Definition: rz_cons.h:505
RZ_API bool rz_core_prevop_addr(RzCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr)
Definition: visual.c:1173
RZ_API ut64 rz_core_prevop_addr_force(RzCore *core, ut64 start_addr, int numinstrs)
Definition: visual.c:1195

References argv, rz_core_t::block, rz_core_t::blocksize, rz_cons_t::is_html, rz_core_t::num, rz_core_t::offset, RZ_ABS, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_singleton(), rz_core_block_read(), rz_core_block_size(), rz_core_prevop_addr(), rz_core_prevop_addr_force(), rz_core_print_disasm(), rz_core_seek(), RZ_LOG_ERROR, rz_num_math(), RZ_OUTPUT_MODE_JSON, ST16_MAX, ST16_MIN, st64, ut64(), rz_num_t::value, and rz_cons_t::was_html.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_n_instructions_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instructions_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6337 of file cmd_print.c.

6337  {
6338  int n_instrs = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : 0;
6339  return bool2status(core_disassembly(core, argc > 1 && n_instrs == 0 ? 0 : (int)core->blocksize, n_instrs, state, false));
6340 }

References argv, rz_core_t::blocksize, bool2status(), core_disassembly(), int, rz_core_t::num, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_disassembly_n_instructions_with_flow_handler()

RZ_IPI RzCmdStatus rz_cmd_disassembly_n_instructions_with_flow_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6534 of file cmd_print.c.

6534  {
6535  st64 parsed = argc > 1 ? (st64)rz_num_math(core->num, argv[1]) : (core->blocksize / 4);
6536  if (parsed > ST16_MAX || parsed < ST16_MIN) {
6537  RZ_LOG_ERROR("the number of instructions is too big (%d < n_instrs < %d).\n", ST16_MAX, ST16_MIN);
6538  return RZ_CMD_STATUS_ERROR;
6539  }
6540  int n_instrs = parsed;
6541  // this command is going to be removed when esil will be removed.
6542  rz_core_disasm_pde(core, n_instrs, state);
6543  return RZ_CMD_STATUS_OK;
6544 }
RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, RzCmdStateOutput *state)
Definition: disasm.c:6581

References argv, rz_core_t::blocksize, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_disasm_pde(), RZ_LOG_ERROR, rz_num_math(), ST16_MAX, ST16_MIN, and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_hexdump()

RZ_IPI int rz_cmd_hexdump ( void *  data,
const char *  input 
)

Definition at line 5669 of file cmd_print.c.

5669  {
5670  // TODO: Use the API directly
5671  return rz_core_cmdf(data, "px%s", input);
5672 }

References input(), and rz_core_cmdf().

Referenced by rz_core_cmd_init(), and rzshell_cmddescs_init().

◆ rz_cmd_print()

RZ_IPI int rz_cmd_print ( void *  data,
const char *  input 
)

Definition at line 4700 of file cmd_print.c.

4700  {
4701  RzCore *core = (RzCore *)data;
4702  st64 l;
4703  int i, len, ret;
4704  ut8 *block;
4705  ut32 tbs = core->blocksize;
4706  ut64 n, off;
4707  ut64 tmpseek = UT64_MAX;
4708  ret = 0;
4709 
4711  off = UT64_MAX;
4712  l = len = core->blocksize;
4713  if (input[0] && input[1]) {
4714  int idx = (input[0] == 'h') ? 2 : 1;
4715  const char *p = off ? strchr(input + idx, ' ') : NULL;
4716  if (p) {
4717  l = (int)rz_num_math(core->num, p + 1);
4718  /* except disasm and memoryfmt (pd, pm) and overlay (po) */
4719  if (input[0] != 'd' && input[0] != 't' && input[0] != 'D' && input[0] != 'm' &&
4720  input[0] != 'a' && input[0] != 'f' && input[0] != 'i' &&
4721  input[0] != 'I' && input[0] != 'o') {
4722  if (l < 0) {
4723  off = core->offset + l;
4724  len = l = -l;
4725  tmpseek = core->offset;
4726  } else {
4727  len = l;
4728  if (l > core->blocksize) {
4729  if (!rz_core_block_size(core, l)) {
4730  goto beach;
4731  }
4732  }
4733  }
4734  } else {
4735  len = l;
4736  }
4737  }
4738  }
4739 
4740  if (len > core->blocksize) {
4741  len = core->blocksize;
4742  }
4743 
4744  if (input[0] != 'd' && input[0] != 'm' && input[0] != 'a' && input[0] != 'f' && input[0] != 'i') {
4745  n = core->blocksize_max;
4746  i = (int)n;
4747  if (i != n) {
4748  i = 0;
4749  }
4750  if (i && l > i) {
4751  eprintf("This block size is too big (0x%" PFMT64x
4752  " < 0x%" PFMT64x "). Did you mean 'p%c @ %s' instead?\n",
4753  n, l, *input, input + 2);
4754  goto beach;
4755  }
4756  }
4757  if (input[0] == 'x' || input[0] == 'D') {
4758  if (l > 0 && tmpseek == UT64_MAX) {
4759  if (!rz_core_block_size(core, l)) {
4760  eprintf("This block size is too big. Did you mean 'p%c @ %s' instead?\n",
4761  *input, input + 2);
4762  goto beach;
4763  }
4764  }
4765  }
4766 
4767  if (input[0] && input[0] != 'z' && input[1] == 'f' && input[2] != '?') {
4769  // RZ_ANALYSIS_FCN_TYPE_FCN|RZ_ANALYSIS_FCN_TYPE_SYM);
4770  if (f) {
4772  if (len > core->blocksize) {
4773  len = core->blocksize;
4774  }
4775  } else {
4776  eprintf("p: Cannot find function at 0x%08" PFMT64x "\n", core->offset);
4777  core->num->value = 0;
4778  goto beach;
4779  }
4780  }
4781  // TODO figure out why `f eax=33; f test=eax; pa call test` misassembles if len is 0
4782  core->num->value = len ? len : core->blocksize;
4783  if (off != UT64_MAX) {
4784  rz_core_seek(core, off, SEEK_SET);
4785  rz_core_block_read(core);
4786  }
4787  // TODO After core->block is removed, this should be changed to a block read.
4788  block = core->block;
4789  switch (*input) {
4790  case 'j': // "pj"
4791  if (input[1] == '?') {
4793  } else if (input[1] == '.') {
4794  if (input[2] == '.') {
4795  ut8 *data = calloc(core->offset + 1, 1);
4796  if (data) {
4797  data[core->offset] = 0;
4798  (void)rz_io_read_at(core->io, 0, data, core->offset);
4799  char *res = rz_print_json_path((const char *)data, core->offset);
4800  if (res) {
4801  eprintf("-> res(%s)\n", res);
4802  }
4803  /*
4804  char *res = rz_print_json_indent ((char*)data, false, " ", NULL);
4805  print_json_path (core, res);
4806  free (res);
4807 */
4808  } else {
4809  eprintf("Cannot allocate %d\n", (int)(core->offset));
4810  }
4811  } else {
4812  rz_core_cmdf(core, "pj %" PFMT64u " @ 0", core->offset);
4813  }
4814  } else {
4815  if (core->blocksize < 4 || !memcmp(core->block, "\xff\xff\xff\xff", 4)) {
4816  eprintf("Cannot read\n");
4817  } else {
4818  char *res = rz_print_json_indent((const char *)core->block, true, " ", NULL);
4819  rz_cons_printf("%s\n", res);
4820  free(res);
4821  }
4822  }
4823  break;
4824  case 'v': // "pv"
4825  cmd_print_pv(core, input + 1, false);
4826  break;
4827  case 'V': // "pv"
4828  cmd_print_pv(core, input + 1, true);
4829  break;
4830  case '-': // "p-"
4831  return cmd_print_blocks(core, input + 1);
4832  case '=': // "p="
4833  cmd_print_bars(core, input);
4834  break;
4835  case 'A': // "pA"
4836  {
4837  const ut64 saved_from = rz_config_get_i(core->config, "search.from"),
4838  saved_to = rz_config_get_i(core->config, "search.to"),
4839  saved_maxhits = rz_config_get_i(core->config, "search.maxhits");
4840 
4841  int want = rz_num_math(core->num, input + 1);
4842  if (input[1] == '?') {
4843  rz_core_cmd0(core, "/A?");
4844  } else {
4845  rz_config_set_i(core->config, "search.maxhits", want);
4846  rz_config_set_i(core->config, "search.from", core->offset);
4847  rz_config_set_i(core->config, "search.to", core->offset + core->blocksize);
4848  rz_core_cmd0(core, "/A");
4849  rz_config_set_i(core->config, "search.maxhits", saved_maxhits);
4850  rz_config_set_i(core->config, "search.from", saved_from);
4851  rz_config_set_i(core->config, "search.to", saved_to);
4852  }
4853  } break;
4854  case 'I': // "pI"
4855  switch (input[1]) {
4856  case 'f': // "pIf"
4857  {
4860  if (f) {
4863  break;
4864  }
4865  break;
4866  }
4867  case '?': // "pi?"
4868  rz_cons_printf("|Usage: p[iI][df] [len] print N instructions/bytes"
4869  "(f=func) (see pi? and pdq)\n");
4870  break;
4871  default:
4872  if (l) {
4874  }
4875  }
4876  break;
4877  case 'i': // "pi"
4878  switch (input[1]) {
4879  case '?':
4880  // rz_cons_printf ("|Usage: pi[defj] [num]\n");
4882  break;
4883  case 'u': // "piu" disasm until ret/jmp . todo: accept arg to specify type
4884  disasm_until_ret(core, core->offset, input[2], input + 2);
4885  break;
4886  case 'a': // "pia" is like "pda", but with "pi" output
4887  if (l != 0) {
4888  rz_core_print_disasm_all(core, core->offset,
4889  l, len, 'i');
4890  }
4891  break;
4892  case 'e': // "pie"
4893  if (l != 0) {
4894  rz_core_disasm_pdi(core, l, 0, 'e');
4895  }
4896  break;
4897  case 'f': // "pif"
4898  if (input[2] == '?') { // "pif?"
4900  } else if (input[2] == 'j') {
4901  rz_core_cmdf(core, "pdfj%s", input + 3);
4902  } else if (input[2] == 'c') { // "pifc"
4903  RzListIter *iter;
4904  RzAnalysisXRef *xrefi;
4905  RzList *refs = NULL;
4906  PJ *pj = NULL;
4907 
4908  // check for bounds
4909  if (input[3] != 0) {
4910  if (input[3] == 'j') { // "pifcj"
4911  pj = pj_new();
4912  pj_a(pj);
4913  }
4914  }
4915  // get function in current offset
4918 
4919  // validate that a function was found in the given address
4920  if (!f) {
4921  // print empty json object
4922  if (pj) {
4923  pj_end(pj);
4925  pj_free(pj);
4926  }
4927  break;
4928  }
4929  // get all the calls of the function
4930  refs = rz_core_analysis_fcn_get_calls(core, f);
4931 
4932  // sanity check
4933  if (!rz_list_empty(refs)) {
4934 
4935  // store current configurations
4936  RzConfigHold *hc = rz_config_hold_new(core->config);
4937  rz_config_hold_i(hc, "asm.offset", NULL);
4938  rz_config_hold_i(hc, "asm.comments", NULL);
4939  rz_config_hold_i(hc, "asm.tabs", NULL);
4940  rz_config_hold_i(hc, "asm.bytes", NULL);
4941  rz_config_hold_i(hc, "emu.str", NULL);
4942 
4943  // temporarily replace configurations
4944  rz_config_set_i(core->config, "asm.offset", false);
4945  rz_config_set_i(core->config, "asm.comments", false);
4946  rz_config_set_i(core->config, "asm.tabs", 0);
4947  rz_config_set_i(core->config, "asm.bytes", false);
4948  rz_config_set_i(core->config, "emu.str", false);
4949 
4950  // iterate over all call references
4951  rz_list_foreach (refs, iter, xrefi) {
4952  if (pj) {
4955  char *dst = rz_str_newf((f ? f->name : "0x%08" PFMT64x), xrefi->to);
4956  char *dst2 = NULL;
4958  RzBinReloc *rel = rz_core_getreloc(core, xrefi->to, op->size);
4959  if (rel) {
4960  if (rel && rel->import && rel->import->name) {
4961  dst2 = rel->import->name;
4962  } else if (rel && rel->symbol && rel->symbol->name) {
4963  dst2 = rel->symbol->name;
4964  }
4965  } else {
4966  dst2 = dst;
4967  }
4968  pj_o(pj);
4969  pj_ks(pj, "dest", dst2);
4970  pj_kn(pj, "addr", xrefi->to);
4971  pj_kn(pj, "at", xrefi->from);
4972  pj_end(pj);
4974  } else {
4975  char *s = rz_core_cmd_strf(core, "pdq %i @ 0x%08" PFMT64x, 1, xrefi->from);
4976  rz_cons_printf("%s", s);
4977  }
4978  }
4979 
4980  // restore saved configuration
4982  rz_config_hold_free(hc);
4983  }
4984  // print json object
4985  if (pj) {
4986  pj_end(pj);
4988  pj_free(pj);
4989  }
4990  } else if (l != 0) {
4993  if (f) {
4994  ut32 bsz = core->blocksize;
4995  // int fsz = rz_analysis_function_realsize (f);
4996  int fsz = rz_analysis_function_linear_size(f); // we want max-min here
4997  rz_core_block_size(core, fsz);
4998  rz_core_print_disasm_instructions(core, fsz, 0);
4999  rz_core_block_size(core, bsz);
5000  } else {
5002  core->blocksize, l);
5003  }
5004  }
5005  break;
5006  case 'r': // "pir"
5007  {
5010  if (f) {
5011  func_walk_blocks(core, f, input[2], 'I', input[2] == '.');
5012  } else {
5013  eprintf("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
5014  core->num->value = 0;
5015  }
5016  } break;
5017  case 'b': // "pib"
5018  {
5020  if (b) {
5021  rz_core_print_disasm_instructions(core, b->size - (core->offset - b->addr), 0);
5022  } else {
5023  eprintf("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
5024  core->num->value = 0;
5025  }
5026  } break;
5027  default: // "pi"
5028  if (l != 0) {
5030  }
5031  break;
5032  }
5033  goto beach;
5034  case 'p': // "pp"
5035  __printPattern(core, input + 1);
5036  break;
5037  case 's': // "ps"
5038  switch (input[1]) {
5039  case '?': // "ps?"
5041  break;
5042  case 'j': // "psj"
5043  if (l > 0) {
5044  if (input[2] == ' ' && input[3]) {
5045  len = rz_num_math(core->num, input + 3);
5046  len = RZ_MIN(len, core->blocksize);
5047  }
5049  print_json_string(core, core->block, len, enc, l != len);
5050  }
5051  break;
5052  case 'i': // "psi"
5053  if (l > 0) {
5054  ut8 *buf = malloc(1024 + 1);
5055  int delta = 512;
5056  ut8 *p, *e, *b;
5057  if (!buf) {
5058  return 0;
5059  }
5060  buf[1024] = 0;
5061  if (core->offset < delta) {
5062  delta = core->offset;
5063  }
5064  p = buf + delta;
5065  rz_io_read_at(core->io, core->offset - delta, buf, 1024);
5066  for (b = p; b > buf; b--) {
5067  if (!IS_PRINTABLE(*b)) {
5068  b++;
5069  break;
5070  }
5071  }
5072  for (e = p; e < (buf + 1024); e++) {
5073  if (!IS_PRINTABLE(*b)) {
5074  *e = 0;
5075  e--;
5076  break;
5077  }
5078  }
5079  rz_cons_strcat((const char *)b);
5080  rz_cons_newline();
5081  // rz_print_string (core->print, core->offset, b,
5082  // (size_t)(e-b), 0);
5083  free(buf);
5084  }
5085  break;
5086  case 'x': // "psx"
5087  if (l > 0) {
5088  RzStrStringifyOpt opt = { 0 };
5089  opt.buffer = block;
5090  opt.length = len;
5092  opt.escape_nl = true;
5093  core_print_raw_buffer(&opt);
5094  }
5095  break;
5096  case 'b': // "psb"
5097  if (l > 0) {
5098  int quiet = input[2] == 'q'; // "psbq"
5099  char *s = malloc(core->blocksize + 1);
5100  int i, j, hasnl = 0;
5101  if (s) {
5102  if (!quiet) {
5103  rz_print_offset(core->print, core->offset, 0, 0, 0, 0, NULL);
5104  }
5105  // TODO: filter more chars?
5106  for (i = j = 0; i < core->blocksize; i++) {
5107  char ch = (char)block[i];
5108  if (!ch) {
5109  if (!hasnl) {
5110  s[j] = 0;
5111  if (*s) {
5112  rz_cons_println(s);
5113  if (!quiet) {
5114  rz_print_offset(core->print, core->offset + i, 0, 0, 0, 0, NULL);
5115  }
5116  }
5117  j = 0;
5118  s[0] = 0;
5119  }
5120  hasnl = 1;
5121  continue;
5122  }
5123  hasnl = 0;
5124  if (IS_PRINTABLE(ch)) {
5125  s[j++] = ch;
5126  }
5127  }
5128  s[j] = 0;
5129  rz_cons_print(s); // TODO: missing newline?
5130  free(s);
5131  }
5132  }
5133  break;
5134  case 'z': // "psz"
5135  if (l > 0) {
5136  char *s = malloc(core->blocksize + 1);
5137  int i, j;
5138  if (s) {
5139  // TODO: filter more chars?
5140  for (i = j = 0; i < core->blocksize; i++) {
5141  char ch = (char)core->block[i];
5142  if (!ch) {
5143  break;
5144  }
5145  if (IS_PRINTABLE(ch)) {
5146  s[j++] = ch;
5147  }
5148  }
5149  s[j] = '\0';
5150  if (input[2] == 'j') { // pszj
5151  print_json_string(core, (const ut8 *)s, j, RZ_STRING_ENC_8BIT, true);
5152  } else {
5153  rz_cons_println(s);
5154  }
5155  free(s);
5156  }
5157  }
5158  break;
5159  case 'p': // "psp"
5160  if (l > 0) {
5161  int mylen = core->block[0];
5162  // TODO: add support for 2-4 byte length pascal strings
5163  if (mylen < core->blocksize) {
5164  if (input[2] == 'j') { // pspj
5165  print_json_string(core, core->block + 1, mylen, RZ_STRING_ENC_8BIT, true);
5166  } else {
5167  RzStrStringifyOpt opt = { 0 };
5168  opt.buffer = core->block + 1;
5169  opt.length = mylen;
5171  opt.stop_at_nil = true;
5172  core_print_raw_buffer(&opt);
5173  }
5174  core->num->value = mylen;
5175  } else {
5176  core->num->value = 0; // error
5177  }
5178  }
5179  break;
5180  case 'w': // "psw"
5181  if (l > 0) {
5182  if (input[2] == 'j') { // pswj
5183  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF16LE, true);
5184  } else {
5185  RzStrStringifyOpt opt = { 0 };
5186  opt.buffer = core->block;
5187  opt.length = len;
5189  opt.stop_at_nil = true;
5190  core_print_raw_buffer(&opt);
5191  }
5192  }
5193  break;
5194  case 'W': // "psW"
5195  if (l > 0) {
5196  if (input[2] == 'j') { // psWj
5197  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF32LE, true);
5198  } else {
5199  RzStrStringifyOpt opt = { 0 };
5200  opt.buffer = core->block;
5201  opt.length = len;
5203  opt.stop_at_nil = true;
5204  core_print_raw_buffer(&opt);
5205  }
5206  }
5207  break;
5208  case ' ': // "ps"
5209  {
5211  RzStrStringifyOpt opt = { 0 };
5212  opt.buffer = core->block;
5213  opt.length = l;
5214  opt.encoding = enc;
5215  core_print_raw_buffer(&opt);
5216  } break;
5217  case 'u': // "psu"
5218  if (l > 0) {
5219  bool json = input[2] == 'j'; // "psuj"
5220  if (input[2] == 'z') { // "psuz"
5221  int i, z;
5222  const char *p = (const char *)core->block;
5223  for (i = 0, z = 0; i < len; i++) {
5224  // looking for double zeros '\0\0'.
5225  if (!p[i] && !z)
5226  z = 1;
5227  else if (!p[i] && z) {
5228  len = i - 1;
5229  break;
5230  }
5231  }
5232  json = input[3] == 'j'; // "psuzj"
5233  }
5234  if (json) { // psuj
5235  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF16LE, true);
5236  } else {
5237  char *str = rz_str_utf16_encode((const char *)core->block, len);
5239  free(str);
5240  }
5241  }
5242  break;
5243  case 's': // "pss"
5244  if (l > 0) {
5245  int h, w = rz_cons_get_size(&h);
5246  int colwidth = rz_config_get_i(core->config, "hex.cols") * 2;
5247  int width = (colwidth == 32) ? w : colwidth; // w;
5248  int bs = core->blocksize;
5249  if (len == bs) {
5250  len = (h * w) / 3;
5251  rz_core_block_size(core, len);
5252  }
5253  RzStrStringifyOpt opt = { 0 };
5254  opt.buffer = core->block;
5255  opt.length = len;
5257  opt.wrap_at = width;
5258  core_print_raw_buffer(&opt);
5259  rz_core_block_size(core, bs);
5260  }
5261  break;
5262  case '+': // "ps+"
5263  if (l > 0) {
5264  const bool json = input[2] == 'j'; // ps+j
5265  ut64 bitness = rz_config_get_i(core->config, "asm.bits");
5266  if (bitness != 32 && bitness != 64) {
5267  eprintf("Error: bitness of %" PFMT64u " not supported\n", bitness);
5268  break;
5269  }
5270  if (*core->block & 0x1) { // "long" string
5271  if (bitness == 64) {
5272  rz_core_cmdf(core, "ps%c @ 0x%" PFMT64x, json ? 'j' : ' ', *((ut64 *)core->block + 2));
5273  } else {
5274  rz_core_cmdf(core, "ps%c @ 0x%" PFMT32x, json ? 'j' : ' ', *((ut32 *)core->block + 2));
5275  }
5276  } else if (json) {
5277  print_json_string(core, core->block + 1, len, RZ_STRING_ENC_8BIT, true);
5278  } else {
5279  RzStrStringifyOpt opt = { 0 };
5280  opt.buffer = core->block + 1;
5281  opt.length = len;
5283  opt.stop_at_nil = true;
5284  core_print_raw_buffer(&opt);
5285  }
5286  }
5287  break;
5288  default:
5289  if (l > 0) {
5290  RzStrStringifyOpt opt = { 0 };
5291  opt.buffer = core->block;
5292  opt.length = len;
5294  opt.stop_at_nil = true;
5295  core_print_raw_buffer(&opt);
5296  }
5297  break;
5298  }
5299  break;
5300  case 'm': // "pm"
5301  if (input[1] == '?') {
5302  rz_cons_printf("|Usage: pm [file|directory]\n"
5303  "| rz_magic will use given file/dir as reference\n"
5304  "| output of those magic can contain expressions like:\n"
5305  "| foo@ 0x40 # use 'foo' magic file on address 0x40\n"
5306  "| @ 0x40 # use current magic file on address 0x40\n"
5307  "| \\n # append newline\n"
5308  "| e dir.magic # defaults to " RZ_JOIN_2_PATHS("{RZ_PREFIX}", RZ_SDB_MAGIC) "\n"
5309  "| /m # search for magic signatures\n");
5310  } else if (input[1] == 'j') { // "pmj"
5311  const char *filename = rz_str_trim_head_ro(input + 2);
5312  PJ *pj = pj_new();
5313  rz_core_magic(core, filename, true, pj);
5315  pj_free(pj);
5316  } else {
5317  // XXX: need cmd_magic header for rz_core_magic
5318  const char *filename = rz_str_trim_head_ro(input + 1);
5319  rz_core_magic(core, filename, true, NULL);
5320  }
5321  break;
5322  case 'u': // "pu"
5323  if (input[1] == '?') {
5324  rz_cons_printf("|Usage: pu[w0] [len] print N url"
5325  "encoded bytes (w=wide, 0=stop at nil)\n");
5326  } else {
5327  if (l > 0) {
5328  RzStrStringifyOpt opt = { 0 };
5329  opt.buffer = core->block;
5330  opt.length = len;
5332  opt.stop_at_nil = input[1] == '0';
5333  opt.urlencode = true;
5334  core_print_raw_buffer(&opt);
5335  }
5336  }
5337  break;
5338  case 'c': // "pc"
5339  if (input[1] == '?') {
5341  } else if (l) {
5342  const ut8 *buf = core->block;
5343  int i = 0;
5344  int j = 0;
5345  if (input[1] == 'A') { // "pcA"
5346  rz_cons_printf("sub_0x%08" PFMT64x ":\n", core->offset);
5347  for (i = 0; i < len; i++) {
5348  RzAsmOp asmop = {
5349  0
5350  };
5351  (void)rz_asm_disassemble(core->rasm, &asmop, buf + i, len - i);
5352  int sz = asmop.size;
5353  if (sz < 1) {
5354  sz = 1;
5355  }
5356  rz_cons_printf(" .byte ");
5357  for (j = 0; j < sz; j++) {
5358  rz_cons_printf("%s0x%02x", j ? ", " : "", buf[i]);
5359  i++;
5360  }
5361  rz_cons_printf(" // %s\n", rz_strbuf_get(&asmop.buf_asm));
5362  i--;
5363  }
5364  rz_cons_printf(".equ shellcode_len, %d\n", len);
5365  } else {
5366  char *str = NULL;
5367  bool big_endian = rz_config_get_b(core->config, "cfg.bigendian");
5368  switch (input[1]) {
5369  case '*': // "pc*" // rizin commands
5371  break;
5372  case 'a': // "pca" // GAS asm
5374  break;
5375  case 'b': // "pcb" // bash shellscript
5377  break;
5378  case 'n': // "pcn" // nodejs
5380  break;
5381  case 'g': // "pcg" // golang
5383  break;
5384  case 'k': // "pck" kotlin
5386  break;
5387  case 's': // "pcs" // swift
5389  break;
5390  case 'r': // "pcr" // Rust
5392  break;
5393  case 'o': // "pco" // Objective-C
5395  break;
5396  case 'J': // "pcJ" // java
5398  break;
5399  case 'y': // "pcy" // yara
5401  break;
5402  case 'j': // "pcj" // json
5404  break;
5405  case 'p': // "pcp" // python
5407  break;
5408  case 'h': // "pch" // C half words with asm
5410  break;
5411  case 'w': // "pcw" // C words with asm
5413  break;
5414  case 'd': // "pcd" // C double-words with asm
5416  break;
5417  default: // "pc" // C bytes
5419  break;
5420  }
5421  if (str) {
5423  free(str);
5424  }
5425  }
5426  }
5427  break;
5428  case 'C': // "pC"
5429  switch (input[1]) {
5430  case 0:
5431  cmd_pCd(core, "");
5432  break;
5433  case ' ':
5434  case 'd':
5435  cmd_pCd(core, input + 2);
5436  break;
5437  case 'D':
5438  cmd_pCD(core, input + 2);
5439  break;
5440  case 'a':
5441  cmd_pCx(core, input + 2, "pxa");
5442  break;
5443  case 'A':
5444  cmd_pCx(core, input + 2, "pxA");
5445  break;
5446  case 'x':
5447  cmd_pCx(core, input + 2, "px");
5448  break;
5449  case 'w':
5450  cmd_pCx(core, input + 2, "pxw");
5451  break;
5452  case 'c':
5453  cmd_pCx(core, input + 2, "pc");
5454  break;
5455  default:
5456  eprintf("Usage: pCd\n");
5457  break;
5458  }
5459  break;
5460  case 'r': // "pr"
5461  switch (input[1]) {
5462  case 'c': // "prc" // color raw dump
5463  cmd_prc(core, block, len);
5464  break;
5465  case '?':
5467  break;
5468  case 'g': // "prg" // gunzip
5469  switch (input[2]) {
5470  case '?':
5472  break;
5473  case 'i': // "prgi"
5474  {
5475  int outlen = 0;
5476  int inConsumed = 0;
5477  ut8 *out;
5478  out = rz_inflate(block, core->blocksize, &inConsumed, &outlen);
5479  rz_cons_printf("%d\n", inConsumed);
5480  free(out);
5481  } break;
5482  case 'o': // "prgo"
5483  {
5484  int outlen = 0;
5485  ut8 *out;
5486  out = rz_inflate(block, core->blocksize, NULL, &outlen);
5487  rz_cons_printf("%d\n", outlen);
5488  free(out);
5489  } break;
5490  default: {
5491  int outlen = 0;
5492  ut8 *out;
5493  out = rz_inflate(block, core->blocksize, NULL, &outlen);
5494  if (out) {
5495  rz_cons_memcat((const char *)out, outlen);
5496  }
5497  free(out);
5498  }
5499  }
5500  break;
5501  /* TODO: compact */
5502  case 'x': // "prx"
5503  {
5504  int a = rz_config_get_i(core->config, "hex.bytes");
5505  rz_config_set_i(core->config, "hex.bytes", false);
5506  rz_core_cmdf(core, "px%s", input + 1);
5507  rz_config_set_i(core->config, "hex.bytes", a);
5508  } break;
5509  case 'z': // "prz"
5510  if (l != 0) {
5511  printraw(core, strlen((const char *)core->block));
5512  }
5513  break;
5514  default:
5515  if (l != 0) {
5516  printraw(core, len);
5517  }
5518  break;
5519  }
5520  break;
5521  case 'o': // "po"
5522  cmd_print_op(core, input);
5523  break;
5524  case 'x': // "px"
5525  {
5526  bool show_offset = rz_config_get_i(core->config, "hex.offset");
5527  if (show_offset) {
5528  core->print->flags |= RZ_PRINT_FLAGS_OFFSET;
5529  } else {
5530  core->print->flags &= ~RZ_PRINT_FLAGS_OFFSET;
5531  }
5532  int show_header = rz_config_get_i(core->config, "hex.header");
5533  if (show_header) {
5534  core->print->flags |= RZ_PRINT_FLAGS_HEADER;
5535  } else {
5536  core->print->flags &= ~RZ_PRINT_FLAGS_HEADER;
5537  }
5538  /* Don't show comments in default case */
5539  core->print->use_comments = false;
5540  }
5542  switch (input[1]) {
5543  case '/': // "px/"
5544  rz_core_print_examine(core, input + 2);
5545  break;
5546  case '?':
5547  default:
5549  break;
5550  }
5552  break;
5553  case '2': // "p2"
5554  if (l) {
5555  if (input[1] == '?') {
5556  rz_cons_printf("|Usage: p2 [number of bytes representing tiles]\n"
5557  "NOTE: Only full tiles will be printed\n");
5558  } else {
5559  core_print_2bpp_tiles(core, len / 16);
5560  }
5561  }
5562  break;
5563  case '8': // "p8"
5564  if (input[1] == '?') {
5565  rz_cons_printf("|Usage: p8[fj] [len] 8bit hexpair list of bytes (see pcj)\n");
5566  rz_cons_printf(" p8 : print hexpairs string\n");
5567  rz_cons_printf(" p8f : print hexpairs of function (linear)\n");
5568  rz_cons_printf(" p8j : print hexpairs in JSON array\n");
5569  } else if (l) {
5570  if (!rz_core_block_size(core, len)) {
5571  len = core->blocksize;
5572  }
5573  if (input[1] == 'j') { // "p8j"
5574  rz_core_cmdf(core, "pcj %s", input + 2);
5575  } else if (input[1] == 'f') { // "p8f"
5576  rz_core_cmdf(core, "p8 $FS @ $FB");
5577  } else {
5578  rz_core_block_read(core);
5579  block = core->block;
5580  rz_print_bytes(core->print, block, len, "%02x");
5581  }
5582  }
5583  break;
5584  case 'g': // "pg"
5585  cmd_print_gadget(core, input + 1);
5586  break;
5587  case 'f': // "pf"
5588  cmd_print_format(core, input, block, len);
5589  break;
5590  case 'F': // "pF"
5591  cmd_print_fromage(core, input + 1, block, len);
5592  break;
5593  case 'k': // "pk"
5594  if (input[1] == '?') {
5595  rz_cons_printf("|Usage: pk [len] print key in randomart\n");
5596  rz_cons_printf("|Usage: pkill [process-name]\n");
5597  } else if (!strncmp(input, "kill", 4)) {
5598  RzListIter *iter;
5599  RzDebugPid *pid;
5600  const char *arg = strchr(input, ' ');
5601  RzList *pids = (core->dbg->cur && core->dbg->cur->pids)
5602  ? core->dbg->cur->pids(core->dbg, 0)
5603  : NULL;
5604  if (arg && *++arg) {
5605  rz_list_foreach (pids, iter, pid) {
5606  if (strstr(pid->path, arg)) {
5607  rz_cons_printf("dk 9 %d\n", pid->pid);
5608  }
5609  // rz_debug_kill (core->dbg, pid->pid, pid->pid, 9); // kill -9
5610  }
5611  }
5612  rz_list_free(pids);
5613  } else if (l > 0) {
5614  len = len > core->blocksize ? core->blocksize : len;
5615  char *s = rz_hash_cfg_randomart(block, len, core->offset);
5616  rz_cons_println(s);
5617  free(s);
5618  }
5619  break;
5620  case 'K': // "pK"
5621  if (input[1] == '?') {
5622  rz_cons_printf("|Usage: pK [len] print key in randomart mosaic\n");
5623  } else if (l > 0) {
5624  len = len > core->blocksize ? core->blocksize : len;
5625  int w, h;
5626  RzConsCanvas *c;
5627  w = rz_cons_get_size(&h);
5628  ut64 offset0 = core->offset;
5629  int cols = (w / 20);
5630  int rows = (h / 12);
5631  int i, j;
5632  char *s;
5633  if (rows < 1) {
5634  rows = 1;
5635  }
5636  c = rz_cons_canvas_new(w, rows * 11);
5637  for (i = 0; i < rows; i++) {
5638  for (j = 0; j < cols; j++) {
5639  rz_cons_canvas_gotoxy(c, j * 20, i * 11);
5640  core->offset += len;
5641  rz_io_read_at(core->io, core->offset, core->block, len);
5642  s = rz_hash_cfg_randomart(core->block, len, core->offset);
5644  free(s);
5645  }
5646  }
5649  rz_io_read_at(core->io, offset0, core->block, len);
5650  core->offset = offset0;
5651  rz_cons_printf("\n");
5652  }
5653  break;
5654  default:
5656  break;
5657  }
5658 beach:
5659  if (tmpseek != UT64_MAX) {
5660  rz_core_seek(core, tmpseek, SEEK_SET);
5661  rz_core_block_read(core);
5662  }
5663  if (tbs != core->blocksize) {
5664  rz_core_block_size(core, tbs);
5665  }
5666  return ret;
5667 }
#define e(frag)
#define PFMT32x
RZ_API RzList * rz_core_analysis_fcn_get_calls(RzCore *core, RzAnalysisFunction *fcn)
Definition: canalysis.c:2663
static void rz_core_magic(RzCore *core, const char *file, int v, PJ *pj)
Definition: cmd_magic.c:192
static void cmd_print_format(RzCore *core, const char *_input, const ut8 *block, int len)
Definition: cmd_print.c:1422
RZ_API void rz_print_offset(RzPrint *p, ut64 off, int invert, int offseg, int offdec, int delta, const char *label)
Definition: cmd_print.c:5782
static void cmd_print_gadget(RzCore *core, const char *_input)
Definition: cmd_print.c:1260
static void cmd_pCD(RzCore *core, const char *input)
Definition: cmd_print.c:935
static void cmd_prc(RzCore *core, const ut8 *block, int len)
Definition: cmd_print.c:755
static const char * help_msg_pif[]
Definition: cmd_print.c:383
static void cmd_print_op(RzCore *core, const char *input)
Definition: cmd_print.c:2514
static const char * help_msg_pc[]
Definition: cmd_print.c:31
static bool cmd_print_blocks(RzCore *core, const char *input)
Definition: cmd_print.c:3185
static void func_walk_blocks(RzCore *core, RzAnalysisFunction *f, char input, char type_print, bool fromHere)
Definition: cmd_print.c:4294
static const char * help_msg_pi[]
Definition: cmd_print.c:371
static void printraw(RzCore *core, int len)
Definition: cmd_print.c:2554
static void print_json_string(RzCore *core, const ut8 *block, ut32 len, RzStrEnc encoding, bool stop_at_nil)
Definition: cmd_print.c:4388
static const char * help_msg_ps[]
Definition: cmd_print.c:418
static const char * help_msg_pr[]
Definition: cmd_print.c:69
static const char * help_msg_prg[]
Definition: cmd_print.c:78
static const char * help_msg_pj[]
Definition: cmd_print.c:258
static void cmd_print_bars(RzCore *core, const char *input)
Definition: cmd_print.c:3554
static const char * help_msg_px[]
Definition: cmd_print.c:446
static void disasm_until_ret(RzCore *core, ut64 addr, char type_print, const char *arg)
Definition: cmd_print.c:4246
static void cmd_print_pv(RzCore *core, const char *input, bool useBytes)
Definition: cmd_print.c:2986
static void cmd_pCx(RzCore *core, const char *input, const char *xcmd)
Definition: cmd_print.c:989
static const char * help_msg_p[]
Definition: cmd_print.c:198
static void cmd_pCd(RzCore *core, const char *input)
Definition: cmd_print.c:850
static void cmd_print_fromage(RzCore *core, const char *input, const ut8 *data, int size)
Definition: cmd_print.c:1098
RZ_API void rz_core_print_examine(RzCore *core, const char *str)
Definition: cmd_print.c:2089
static void __printPattern(RzCore *core, const char *_input)
Definition: cmd_print.c:4043
static void core_print_raw_buffer(RzStrStringifyOpt *opt)
Definition: cmd_print.c:4612
static void core_print_2bpp_tiles(RzCore *core, ut32 tiles)
Definition: cmd_print.c:4597
RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int mode)
Definition: disasm.c:6205
RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes)
Definition: disasm.c:6030
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
const char * filename
Definition: ioapi.h:137
RZ_API char * rz_print_json_indent(const char *s, bool color, const char *tab, const char **palette)
Definition: json_indent.c:254
RZ_API char * rz_print_json_path(const char *s, int pos)
Definition: json_indent.c:43
RZ_API RzBinReloc * rz_core_getreloc(RzCore *core, ut64 addr, int size)
Definition: core.c:178
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
char * dst
Definition: lz4.h:724
RZ_API void rz_print_init_rowoffsets(RzPrint *p)
Definition: print.c:1519
RZ_API void rz_print_bytes(RzPrint *p, const ut8 *buf, int len, const char *fmt)
Definition: print.c:1233
RZ_API RZ_OWN char * rz_hash_cfg_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address)
Generates a randomart that is meant to be an easily validate buffers.
Definition: randomart.c:55
RZ_API ut8 * rz_inflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped, automatically accepts either the zlib or gzip format,...
Definition: compression.c:18
@ RZ_LANG_BYTE_ARRAY_C_CPP_BYTES
@ RZ_LANG_BYTE_ARRAY_JAVA
@ RZ_LANG_BYTE_ARRAY_BASH
@ RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS_BE
@ RZ_LANG_BYTE_ARRAY_KOTLIN
@ RZ_LANG_BYTE_ARRAY_C_CPP_WORDS_BE
@ RZ_LANG_BYTE_ARRAY_RIZIN
@ RZ_LANG_BYTE_ARRAY_GOLANG
@ RZ_LANG_BYTE_ARRAY_PYTHON
@ RZ_LANG_BYTE_ARRAY_ASM
@ RZ_LANG_BYTE_ARRAY_C_CPP_WORDS_LE
@ RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS_LE
@ RZ_LANG_BYTE_ARRAY_OBJECTIVE_C
@ RZ_LANG_BYTE_ARRAY_YARA
@ RZ_LANG_BYTE_ARRAY_SWIFT
@ RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS_BE
@ RZ_LANG_BYTE_ARRAY_RUST
@ RZ_LANG_BYTE_ARRAY_JSON
@ RZ_LANG_BYTE_ARRAY_NODEJS
@ RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS_LE
#define RZ_PRINT_FLAGS_HEADER
Definition: rz_print.h:18
RZ_API char * rz_str_utf16_encode(const char *s, int len)
Definition: str.c:2993
RzStrEnc
Definition: rz_str.h:19
@ RZ_STRING_ENC_UTF32LE
Definition: rz_str.h:24
@ RZ_STRING_ENC_8BIT
Definition: rz_str.h:20
@ RZ_STRING_ENC_UTF16LE
Definition: rz_str.h:23
RZ_API RzStrEnc rz_str_guess_encoding_from_buffer(RZ_NONNULL const ut8 *buffer, ut32 length)
Tries to guess the string encoding method from the buffer.
Definition: str.c:4089
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
#define RZ_JOIN_2_PATHS(p1, p2)
Definition: rz_types.h:224
#define RZ_SDB_MAGIC
Definition: rz_userconf.h:86
RzStrBuf buf_asm
Definition: rz_asm.h:72
int size
Definition: rz_asm.h:67
char * name
Definition: rz_bin.h:701
RzBinImport * import
Definition: rz_bin.h:714
RzBinSymbol * symbol
Definition: rz_bin.h:713
char * name
Definition: rz_bin.h:675
ut32 blocksize_max
Definition: rz_core.h:304
RzList *(* pids)(RzDebug *dbg, int pid)
Definition: rz_debug.h:376
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295
bool urlencode
Encodes the output following RFC 3986.
Definition: rz_str.h:275
bool escape_nl
When enabled escapes new lines ( ).
Definition: rz_str.h:272
ut32 wrap_at
Adds a new line the output when it exeeds this value.
Definition: rz_str.h:271
int width
Definition: main.c:10
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References __printPattern(), a, rz_core_t::analysis, b, rz_core_t::block, blocksize, rz_core_t::blocksize, rz_core_t::blocksize_max, rz_asm_op_t::buf_asm, rz_str_stringify_opt_t::buffer, c, calloc(), cmd_pCd(), cmd_pCD(), cmd_pCx(), cmd_prc(), cmd_print_bars(), cmd_print_blocks(), cmd_print_format(), cmd_print_fromage(), cmd_print_gadget(), cmd_print_op(), cmd_print_pv(), rz_core_t::config, core_print_2bpp_tiles(), core_print_raw_buffer(), rz_debug_t::cur, rz_core_t::dbg, delta, disasm_until_ret(), dst, e, rz_str_stringify_opt_t::encoding, eprintf, rz_str_stringify_opt_t::escape_nl, f, rz_print_t::flags, free(), rz_analysis_ref_t::from, func_walk_blocks(), h, help_msg_p, help_msg_pc, help_msg_pi, help_msg_pif, help_msg_pj, help_msg_pr, help_msg_prg, help_msg_ps, help_msg_px, i, setup::idx, if(), rz_bin_reloc_t::import, input(), int, rz_core_t::io, IS_PRINTABLE, len, rz_str_stringify_opt_t::length, malloc(), n, rz_bin_symbol_t::name, rz_bin_import_t::name, NULL, rz_core_t::num, off, rz_core_t::offset, out, p, PFMT32x, PFMT64u, PFMT64x, pid, rz_debug_plugin_t::pids, pj_a(), pj_end(), pj_free(), pj_kn(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_core_t::print, print_json_string(), printraw(), rz_core_t::rasm, RZ_ANALYSIS_FCN_TYPE_FCN, RZ_ANALYSIS_FCN_TYPE_SYM, rz_analysis_find_most_relevant_block_in(), rz_analysis_function_linear_size(), rz_analysis_get_fcn_in(), rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, rz_asm_disassemble(), rz_config_get_b(), rz_config_get_i(), rz_config_hold_free(), rz_config_hold_i(), rz_config_hold_new(), rz_config_hold_restore(), rz_config_set_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_canvas_free(), rz_cons_canvas_gotoxy(), rz_cons_canvas_new(), rz_cons_canvas_print(), rz_cons_canvas_write(), rz_cons_get_size(), rz_cons_memcat(), rz_cons_newline(), rz_cons_printf(), rz_cons_println(), rz_cons_strcat(), rz_core_analysis_fcn_get_calls(), rz_core_analysis_op(), rz_core_block_read(), rz_core_block_size(), rz_core_cmd0(), rz_core_cmd_help(), rz_core_cmd_strf(), rz_core_cmdf(), rz_core_disasm_pdi(), rz_core_getreloc(), rz_core_magic(), rz_core_print_disasm_all(), rz_core_print_disasm_instructions(), rz_core_print_examine(), rz_core_seek(), rz_hash_cfg_randomart(), rz_inflate(), rz_io_read_at(), RZ_JOIN_2_PATHS, rz_lang_byte_array(), RZ_LANG_BYTE_ARRAY_ASM, RZ_LANG_BYTE_ARRAY_BASH, RZ_LANG_BYTE_ARRAY_C_CPP_BYTES, RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS_BE, RZ_LANG_BYTE_ARRAY_C_CPP_DOUBLEWORDS_LE, RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS_BE, RZ_LANG_BYTE_ARRAY_C_CPP_HALFWORDS_LE, RZ_LANG_BYTE_ARRAY_C_CPP_WORDS_BE, RZ_LANG_BYTE_ARRAY_C_CPP_WORDS_LE, RZ_LANG_BYTE_ARRAY_GOLANG, RZ_LANG_BYTE_ARRAY_JAVA, RZ_LANG_BYTE_ARRAY_JSON, RZ_LANG_BYTE_ARRAY_KOTLIN, RZ_LANG_BYTE_ARRAY_NODEJS, RZ_LANG_BYTE_ARRAY_OBJECTIVE_C, RZ_LANG_BYTE_ARRAY_PYTHON, RZ_LANG_BYTE_ARRAY_RIZIN, RZ_LANG_BYTE_ARRAY_RUST, RZ_LANG_BYTE_ARRAY_SWIFT, RZ_LANG_BYTE_ARRAY_YARA, rz_list_free(), RZ_MIN, rz_num_math(), rz_print_bytes(), RZ_PRINT_FLAGS_HEADER, RZ_PRINT_FLAGS_OFFSET, rz_print_init_rowoffsets(), rz_print_json_indent(), rz_print_json_path(), rz_print_offset(), RZ_SDB_MAGIC, rz_str_guess_encoding_from_buffer(), rz_str_newf(), rz_str_trim_head_ro(), rz_str_utf16_encode(), rz_strbuf_get(), RZ_STRING_ENC_8BIT, RZ_STRING_ENC_UTF16LE, RZ_STRING_ENC_UTF32LE, s, SEEK_SET, rz_asm_op_t::size, st64, rz_str_stringify_opt_t::stop_at_nil, cmd_descs_generate::str, rz_bin_reloc_t::symbol, rz_analysis_ref_t::to, rz_str_stringify_opt_t::urlencode, rz_print_t::use_comments, ut64(), UT64_MAX, rz_num_t::value, w, width, and rz_str_stringify_opt_t::wrap_at.

Referenced by rz_core_cmd_init(), and rzshell_cmddescs_init().

◆ rz_cmd_print_gadget_add_handler()

RZ_IPI RzCmdStatus rz_cmd_print_gadget_add_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1235 of file cmd_print.c.

1235  {
1236  char *cmd = NULL;
1237  if (argc == 1) {
1238  rz_core_gadget_print(core);
1239  } else {
1240  int x = rz_num_math(core->num, argv[1]);
1241  int y = rz_num_math(core->num, argv[2]);
1242  int w = rz_num_math(core->num, argv[3]);
1243  int h = rz_num_math(core->num, argv[4]);
1244  if (x && y && w && h) {
1245  cmd = rz_str_dup(cmd, argv[5]);
1246  if (cmd) {
1248  g->x = x;
1249  g->y = y;
1250  g->w = w;
1251  g->h = h;
1252  g->cmd = cmd;
1253  rz_list_append(core->gadgets, g);
1254  }
1255  }
1256  }
1257  return RZ_CMD_STATUS_OK;
1258 }
RZ_API char * rz_str_dup(char *ptr, const char *string)
Definition: str.c:1021

References argv, cmd, g, rz_core_t::gadgets, h, NULL, rz_core_t::num, RZ_CMD_STATUS_OK, rz_core_gadget_print(), rz_list_append(), RZ_NEW0, rz_num_math(), rz_str_dup(), w, and x.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_gadget_move_handler()

RZ_IPI RzCmdStatus rz_cmd_print_gadget_move_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1219 of file cmd_print.c.

1219  {
1220  int n = rz_num_math(core->num, argv[1]);
1221  int x = rz_num_math(core->num, argv[2]);
1222  int y = rz_num_math(core->num, argv[3]);
1223  int w = rz_num_math(core->num, argv[4]);
1224  int h = rz_num_math(core->num, argv[5]);
1225  RzCoreGadget *g = rz_list_get_n(core->gadgets, n);
1226  if (x && y && w && h) {
1227  g->x = x;
1228  g->y = y;
1229  g->w = w;
1230  g->h = h;
1231  }
1232  return RZ_CMD_STATUS_OK;
1233 }

References argv, g, rz_core_t::gadgets, h, n, rz_core_t::num, RZ_CMD_STATUS_OK, rz_list_get_n(), rz_num_math(), w, and x.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_gadget_print_as_rizin_handler()

RZ_IPI RzCmdStatus rz_cmd_print_gadget_print_as_rizin_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1206 of file cmd_print.c.

1206  {
1207  RzCoreGadget *g;
1208  RzListIter *iter;
1209  rz_list_foreach (core->gadgets, iter, g) {
1210  rz_cons_printf("\"pg %d %d %d %d %s\"\n", g->x, g->y, g->w, g->h, g->cmd);
1211  }
1212  return RZ_CMD_STATUS_OK;
1213 }

References g, rz_core_t::gadgets, RZ_CMD_STATUS_OK, and rz_cons_printf().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_gadget_remove_handler()

RZ_IPI RzCmdStatus rz_cmd_print_gadget_remove_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1214 of file cmd_print.c.

1214  {
1215  rz_list_free(core->gadgets);
1217  return RZ_CMD_STATUS_OK;
1218 }

References rz_core_t::gadgets, RZ_CMD_STATUS_OK, rz_core_gadget_free(), rz_list_free(), and rz_list_newf().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_hash_cfg_algo_list_handler()

RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_algo_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 2968 of file cmd_print.c.

2968  {
2969  return rz_core_hash_plugins_print(core->hash, state);
2970 }
RZ_API RzCmdStatus rz_core_hash_plugins_print(RzHash *hash, RzCmdStateOutput *state)
Definition: chash.c:34

References rz_core_t::hash, and rz_core_hash_plugins_print().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_hash_cfg_handler()

RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2951 of file cmd_print.c.

2951  {
2952  const RzHashPlugin *plugin = rz_hash_plugin_by_name(core->hash, argv[1]);
2953 
2954  if (!plugin) {
2955  RZ_LOG_ERROR("algorithm '%s' does not exists\n", argv[1]);
2956  return RZ_CMD_STATUS_ERROR;
2957  }
2958 
2959  if (!strncmp(plugin->name, "entropy", 7)) {
2960  handle_entropy(core, plugin->name, core->block, core->blocksize);
2961  } else {
2962  handle_hash_cfg(core, plugin->name, core->block, core->blocksize);
2963  }
2964 
2965  return RZ_CMD_STATUS_OK;
2966 }
static void handle_entropy(RzCore *core, const char *name, const ut8 *block, int len)
Definition: cmd_print.c:2923
static void handle_hash_cfg(RzCore *core, const char *name, const ut8 *block, int len)
Definition: cmd_print.c:2944
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_name(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name)
Definition: hash.c:120
const char * name
Definition: rz_hash.h:27

References argv, rz_core_t::block, rz_core_t::blocksize, handle_entropy(), handle_hash_cfg(), rz_core_t::hash, rz_hash_plugin_t::name, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_hash_plugin_by_name(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_magic_handler()

RZ_IPI RzCmdStatus rz_cmd_print_magic_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 2972 of file cmd_print.c.

2972  {
2973  if (mode == RZ_OUTPUT_MODE_JSON) {
2974  PJ *pj = pj_new();
2975  rz_core_magic(core, argv[1], true, pj);
2977  pj_free(pj);
2978  } else {
2979  // XXX: need cmd_magic header for rz_core_magic
2980  rz_core_magic(core, argv[1], true, NULL);
2981  }
2982  return RZ_CMD_STATUS_OK;
2983 }

References argv, NULL, pj_free(), pj_new(), pj_string(), RZ_CMD_STATUS_OK, rz_cons_println(), rz_core_magic(), and RZ_OUTPUT_MODE_JSON.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_timestamp_current_handler()

RZ_IPI RzCmdStatus rz_cmd_print_timestamp_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1357 of file cmd_print.c.

1357  {
1358  char *now = rz_time_date_now_to_string();
1359  rz_cons_printf("%s\n", now);
1360  free(now);
1361  return RZ_CMD_STATUS_OK;
1362 }
RZ_API RZ_OWN char * rz_time_date_now_to_string(void)
Returns the timestamp in string format of the current time (now)
Definition: time.c:278

References free(), RZ_CMD_STATUS_OK, rz_cons_printf(), and rz_time_date_now_to_string().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_timestamp_dos_handler()

RZ_IPI RzCmdStatus rz_cmd_print_timestamp_dos_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1364 of file cmd_print.c.

1364  {
1365  char *date = NULL;
1366  const ut8 *block = core->block;
1367  ut32 len = core->blocksize;
1368  if (len < sizeof(ut32)) {
1369  RZ_LOG_ERROR("The block size is less than 4.\n");
1370  return RZ_CMD_STATUS_ERROR;
1371  }
1372  for (ut64 i = 0; i < len; i += sizeof(ut32)) {
1373  ut32 dt = rz_read_le32(block + i);
1374  date = rz_time_date_dos_to_string(dt);
1375  rz_cons_printf("%s\n", date);
1376  free(date);
1377  }
1378  return RZ_CMD_STATUS_OK;
1379 }
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
RZ_API RZ_OWN char * rz_time_date_dos_to_string(ut32 timestamp)
Converts a dos date (ut32) and returns the timestamp in string format.
Definition: time.c:239

References rz_core_t::block, rz_core_t::blocksize, free(), i, len, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_LOG_ERROR, rz_read_le32(), rz_time_date_dos_to_string(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_timestamp_hfs_handler()

RZ_IPI RzCmdStatus rz_cmd_print_timestamp_hfs_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1381 of file cmd_print.c.

1381  {
1382  char *date = NULL;
1383  const ut8 *block = core->block;
1384  ut32 len = core->blocksize;
1385  bool big_endian = rz_config_get_b(core->config, "cfg.bigendian");
1386  int timezone = (int)rz_config_get_i(core->config, "time.zone");
1387  if (len < sizeof(ut32)) {
1388  RZ_LOG_ERROR("The block size is less than 4.\n");
1389  return RZ_CMD_STATUS_ERROR;
1390  }
1391 
1392  for (ut64 i = 0; i < len; i += sizeof(ut32)) {
1393  ut32 dt = rz_read_ble32(block + i, big_endian);
1394  // add timezone
1395  dt += timezone * (60 * 60);
1396  date = rz_time_date_hfs_to_string(dt);
1397  rz_cons_printf("%s\n", date);
1398  free(date);
1399  }
1400  return RZ_CMD_STATUS_OK;
1401 }
RZ_API RZ_OWN char * rz_time_date_hfs_to_string(ut32 timestamp)
Converts a Mac HFS+ date (ut32) and returns the timestamp in string format.
Definition: time.c:250

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, free(), i, int, len, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_config_get_i(), rz_cons_printf(), RZ_LOG_ERROR, rz_read_ble32(), rz_time_date_hfs_to_string(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_timestamp_ntfs_handler()

RZ_IPI RzCmdStatus rz_cmd_print_timestamp_ntfs_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1403 of file cmd_print.c.

1403  {
1404  char *date = NULL;
1405  const ut8 *block = core->block;
1406  ut32 len = core->blocksize;
1407  bool big_endian = rz_config_get_b(core->config, "cfg.bigendian");
1408  if (len < sizeof(ut64)) {
1409  RZ_LOG_ERROR("The block size is less than 8.\n");
1410  return RZ_CMD_STATUS_ERROR;
1411  }
1412 
1413  for (ut64 i = 0; i < len; i += sizeof(ut64)) {
1414  ut64 dt = rz_read_ble64(block + i, big_endian);
1415  date = rz_time_date_w32_to_string(dt);
1416  rz_cons_printf("%s\n", date);
1417  free(date);
1418  }
1419  return RZ_CMD_STATUS_OK;
1420 }
RZ_API RZ_OWN char * rz_time_date_w32_to_string(ut64 timestamp)
Converts a Win32 date (ut64) and returns the timestamp in string format.
Definition: time.c:261

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, free(), i, len, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_cons_printf(), RZ_LOG_ERROR, rz_read_ble64(), rz_time_date_w32_to_string(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_print_timestamp_unix_handler()

RZ_IPI RzCmdStatus rz_cmd_print_timestamp_unix_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1335 of file cmd_print.c.

1335  {
1336  char *date = NULL;
1337  const ut8 *block = core->block;
1338  ut32 len = core->blocksize;
1339  bool big_endian = rz_config_get_b(core->config, "cfg.bigendian");
1340  int timezone = (int)rz_config_get_i(core->config, "time.zone");
1341  if (len < sizeof(ut32)) {
1342  RZ_LOG_ERROR("The block size is less than 4.\n");
1343  return RZ_CMD_STATUS_ERROR;
1344  }
1345 
1346  for (ut64 i = 0; i < len; i += sizeof(ut32)) {
1347  ut32 dt = rz_read_ble32(block + i, big_endian);
1348  // add timezone
1349  dt += timezone * (60 * 60);
1350  date = rz_time_date_unix_to_string(dt);
1351  rz_cons_printf("%s\n", date);
1352  free(date);
1353  }
1354  return RZ_CMD_STATUS_OK;
1355 }
#define rz_time_date_unix_to_string
Definition: rz_time.h:38

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, free(), i, int, len, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_config_get_i(), rz_cons_printf(), RZ_LOG_ERROR, rz_read_ble32(), rz_time_date_unix_to_string, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_sizes_of_n_instructions_handler()

RZ_IPI RzCmdStatus rz_cmd_sizes_of_n_instructions_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6681 of file cmd_print.c.

6681  {
6682  ut32 old_blocksize = core->blocksize;
6683  ut64 old_offset = core->offset;
6684  st64 ret = 0;
6685 
6686  st64 parsed = argc > 1 ? (st64)rz_num_math(core->num, argv[1]) : (core->blocksize / 4);
6687  if (parsed > ST16_MAX || parsed < ST16_MIN) {
6688  RZ_LOG_ERROR("the number of instructions is too big (%d < n_instrs < %d).\n", ST16_MAX, ST16_MIN);
6689  return RZ_CMD_STATUS_ERROR;
6690  }
6691  int n_instrs = parsed;
6692  if (n_instrs < 0) {
6693  ut64 new_offset = old_offset;
6694  if (!rz_core_prevop_addr(core, old_offset, -n_instrs, &new_offset)) {
6695  new_offset = rz_core_prevop_addr_force(core, old_offset, -n_instrs);
6696  }
6697  ut32 new_blocksize = new_offset - old_blocksize;
6698  if (new_blocksize > old_blocksize) {
6699  rz_core_block_size(core, new_blocksize);
6700  }
6701  rz_core_seek(core, new_offset, true);
6702  } else {
6703  rz_core_block_read(core);
6704  }
6705 
6708  for (ut32 i = 0, j = 0; i < core->blocksize && j < RZ_ABS(n_instrs); i += ret, j++) {
6709  RzAsmOp asm_op = { 0 };
6710  ret = rz_asm_disassemble(core->rasm, &asm_op, core->block + i, core->blocksize - i);
6711  if (rz_cons_is_breaked()) {
6712  break;
6713  }
6714  // be sure to return 0 when it fails to disassemble the
6715  // instruction to uniform the output across all disassemblers.
6716  int op_size = ret < 1 ? 0 : ret;
6717  switch (state->mode) {
6719  rz_cons_printf("%d\n", op_size);
6720  break;
6721  case RZ_OUTPUT_MODE_JSON:
6722  pj_N(state->d.pj, op_size);
6723  break;
6724  default:
6726  return RZ_CMD_STATUS_ERROR;
6727  }
6728  if (ret < 1) {
6729  ret = 1;
6730  }
6731  }
6734 
6735  if (n_instrs < 0) {
6736  rz_core_block_size(core, old_blocksize);
6737  rz_core_seek(core, old_offset, true);
6738  }
6739  return RZ_CMD_STATUS_OK;
6740 }
RZ_API PJ * pj_N(PJ *j, st64 n)
Definition: pj.c:260

References argv, rz_core_t::block, rz_core_t::blocksize, i, NULL, rz_core_t::num, rz_core_t::offset, pj_N(), rz_core_t::rasm, RZ_ABS, rz_asm_disassemble(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_printf(), rz_core_block_read(), rz_core_block_size(), rz_core_prevop_addr(), rz_core_prevop_addr_force(), rz_core_seek(), RZ_LOG_ERROR, rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, ST16_MAX, ST16_MIN, st64, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_core_gadget_free()

RZ_API void rz_core_gadget_free ( RzCoreGadget g)

Frees a visual print gadget.

Parameters
greference to RzCoreGadget

Definition at line 1174 of file cmd_print.c.

1174  {
1175  free(g->cmd);
1176  free(g);
1177 }

References free(), and g.

Referenced by cmd_print_gadget(), rz_cmd_print_gadget_remove_handler(), and rz_core_init().

◆ rz_core_gadget_print()

RZ_API void rz_core_gadget_print ( RzCore core)

Prints or displays the print gadgets while in visual mode.

Parameters
corereference to RzCore

Definition at line 1185 of file cmd_print.c.

1185  {
1186  RzCoreGadget *g;
1187  RzListIter *iter;
1188  rz_list_foreach (core->gadgets, iter, g) {
1189  char *res = rz_core_cmd_str(core, g->cmd);
1190  if (res) {
1191  rz_cons_strcat_at(res, g->x, g->y, g->w, g->h);
1192  free(res);
1193  }
1194  }
1195 }
RZ_API void rz_cons_strcat_at(const char *_str, int x, char y, int w, int h)
Definition: cons.c:260

References free(), g, rz_core_t::gadgets, rz_cons_strcat_at(), and rz_core_cmd_str().

Referenced by __panels_refresh(), agraph_print(), cmd_print_gadget(), rz_cmd_print_gadget_add_handler(), rz_core_prompt(), and visual_refresh().

◆ rz_core_print_examine()

RZ_API void rz_core_print_examine ( RzCore core,
const char *  str 
)

Definition at line 2089 of file cmd_print.c.

2089  {
2090  char cmd[128], *p;
2091  ut64 addr = core->offset;
2092  int size = (core->analysis->bits / 4);
2093  int count = atoi(str);
2094  int i, n;
2095  if (count < 1) {
2096  count = 1;
2097  }
2098  // skipspaces
2099  while (*str >= '0' && *str <= '9') {
2100  str++;
2101  }
2102  // "px/" alone isn't a full command.
2103  if (!str[0]) {
2104  return;
2105  }
2106  switch (str[1]) {
2107  case 'b': size = 1; break;
2108  case 'h': size = 2; break;
2109  case 'd': size = 4; break;
2110  case 'w': size = 4; break;
2111  case 'g': size = 8; break;
2112  }
2113  if ((p = strchr(str, ' '))) {
2114  *p++ = 0;
2115  addr = rz_num_math(core->num, p);
2116  }
2117  switch (*str) {
2118  case '?':
2119  eprintf(
2120  "Format is x/[num][format][size]\n"
2121  "Num specifies the number of format elements to display\n"
2122  "Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n"
2123  " t(binary), f(float), a(address), i(instruction), c(char) and s(string),\n"
2124  " T(OSType), A(floating point values in hex).\n"
2125  "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n");
2126  break;
2127  case 's': // "x/s"
2128  rz_core_cmdf(core, "psb %d @ 0x%" PFMT64x, count * size, addr);
2129  break;
2130  case 'o': // "x/o"
2131  rz_core_cmdf(core, "pxo %d @ 0x%" PFMT64x, count * size, addr);
2132  break;
2133  case 'f':
2134  case 'A': // XXX (float in hex)
2135  n = 3;
2136  snprintf(cmd, sizeof(cmd), "pxo %d @ 0x%" PFMT64x,
2137  count * size, addr);
2138  strcpy(cmd, "pf ");
2139  for (i = 0; i < count && n < sizeof(cmd); i++) {
2140  cmd[n++] = 'f';
2141  }
2142  cmd[n] = 0;
2143  rz_core_cmd0(core, cmd);
2144  break;
2145  case 'x':
2146  switch (size) {
2147  default:
2148  case 1:
2149  rz_core_cmdf(core, "px %d @ 0x%" PFMT64x, count, addr);
2150  break;
2151  case 2:
2152  rz_core_cmdf(core, "px%c %d @ 0x%" PFMT64x,
2153  'h', count * 2, addr);
2154  break;
2155  case 4:
2156  rz_core_cmdf(core, "px%c %d @ 0x%" PFMT64x,
2157  'w', count * 4, addr);
2158  break;
2159  case 8:
2160  rz_core_cmdf(core, "px%c %d @ 0x%" PFMT64x,
2161  'q', count * 8, addr);
2162  break;
2163  }
2164  break;
2165  case 'a':
2166  case 'd':
2167  rz_core_cmdf(core, "pxw %d @ 0x%" PFMT64x, count * size, addr);
2168  break;
2169  case 'i':
2170  rz_core_cmdf(core, "pdq %d @ 0x%" PFMT64x, count, addr);
2171  break;
2172  }
2173 }

References addr, rz_core_t::analysis, rz_analysis_t::bits, cmd, count, eprintf, i, n, rz_core_t::num, rz_core_t::offset, p, PFMT64x, rz_core_cmd0(), rz_core_cmdf(), rz_num_math(), snprintf, cmd_descs_generate::str, and ut64().

Referenced by rz_cmd_print().

◆ rz_core_set_asm_configs()

RZ_API void rz_core_set_asm_configs ( RzCore core,
char *  arch,
ut32  bits,
int  segoff 
)

Definition at line 1057 of file cmd_print.c.

1057  {
1058  rz_config_set(core->config, "asm.arch", arch);
1059  rz_config_set_i(core->config, "asm.bits", bits);
1060  // XXX - this needs to be done here, because
1061  // if arch == x86 and bits == 16, segoff automatically changes
1062  rz_config_set_i(core->config, "asm.segoff", segoff);
1063 }
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13

References arch, bits(), rz_core_t::config, rz_config_set(), and rz_config_set_i().

◆ rz_esil_of_assembly_handler()

RZ_IPI RzCmdStatus rz_esil_of_assembly_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4640 of file cmd_print.c.

4640  {
4641  char *buf = rz_core_esil_of_assembly(core, argv[1]);
4642  if (!buf) {
4643  return RZ_CMD_STATUS_ERROR;
4644  }
4645  rz_cons_print(buf);
4646  free(buf);
4647  return RZ_CMD_STATUS_OK;
4648 }
RZ_API RZ_OWN char * rz_core_esil_of_assembly(RzCore *core, const char *assembly)
Get the esil of the assembly.
Definition: cprint.c:68

References argv, free(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_esil_of_assembly().

Referenced by rzshell_cmddescs_init().

◆ rz_esil_of_hex_handler()

RZ_IPI RzCmdStatus rz_esil_of_hex_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4676 of file cmd_print.c.

4676  {
4677  ut8 *hex = calloc(1, strlen(argv[1]) + 1);
4678  if (!hex) {
4679  RZ_LOG_ERROR("Fail to allocate memory\n");
4680  return RZ_CMD_STATUS_ERROR;
4681  }
4682  int len = rz_hex_str2bin(argv[1], hex);
4683  if (len < 1) {
4684  RZ_LOG_ERROR("rz_hex_str2bin: invalid hexstr\n");
4685  free(hex);
4686  return RZ_CMD_STATUS_ERROR;
4687  }
4688  char *buf = rz_core_esil_of_hex(core, hex, len);
4689  if (!buf) {
4690  // rz_core_esil_of_hex outputs the error message
4691  free(hex);
4692  return RZ_CMD_STATUS_ERROR;
4693  }
4694  rz_cons_print(buf);
4695  free(buf);
4696  free(hex);
4697  return RZ_CMD_STATUS_OK;
4698 }
RZ_API RZ_OWN char * rz_core_esil_of_hex(RzCore *core, ut8 *hex, int len)
Get the esil of the hexstr.
Definition: cprint.c:134

References argv, calloc(), free(), hex, len, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_esil_of_hex(), rz_hex_str2bin(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_hex_of_assembly_handler()

RZ_IPI RzCmdStatus rz_hex_of_assembly_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4630 of file cmd_print.c.

4630  {
4631  char *buf = rz_core_hex_of_assembly(core, argv[1]);
4632  if (!buf) {
4633  return RZ_CMD_STATUS_ERROR;
4634  }
4636  free(buf);
4637  return RZ_CMD_STATUS_OK;
4638 }
RZ_API RZ_OWN char * rz_core_hex_of_assembly(RzCore *core, const char *assembly)
Get the hexpair of the assembly.
Definition: cprint.c:41

References argv, free(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), and rz_core_hex_of_assembly().

Referenced by rzshell_cmddescs_init().

◆ rz_print_bitstream_handler()

RZ_IPI RzCmdStatus rz_print_bitstream_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 7033 of file cmd_print.c.

7033  {
7034  int len = (int)rz_num_math(core->num, argv[1]);
7035  int skip = (int)rz_num_math(core->num, argv[2]);
7036  if (len < 0 || skip < 0) {
7037  RZ_LOG_ERROR("len and skip should be positive numbers\n");
7038  return RZ_CMD_STATUS_ERROR;
7039  }
7040  // `pb len skip` means skip <skip> bits then print <len> bits
7041  char *buf = RZ_NEWS0(char, len + skip + 1);
7042  if (!buf) {
7043  RZ_LOG_ERROR("Fail to allocate memory\n");
7044  return RZ_CMD_STATUS_ERROR;
7045  }
7046  rz_str_bits(buf, core->block, len + skip, NULL);
7048  free(buf);
7049  return RZ_CMD_STATUS_OK;
7050 }
void skip(file *in, unsigned n)
Definition: gzappend.c:202
RZ_API int rz_str_bits(char *strout, const ut8 *buf, int len, const char *bitz)
Definition: str.c:195

References argv, rz_core_t::block, free(), int, len, NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), RZ_LOG_ERROR, RZ_NEWS0, rz_num_math(), rz_str_bits(), and skip().

Referenced by rzshell_cmddescs_init().

◆ rz_print_byte_bitstream_handler()

RZ_IPI RzCmdStatus rz_print_byte_bitstream_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 7052 of file cmd_print.c.

7052  {
7053  ut64 start = core->offset;
7054  int len = (int)rz_num_math(core->num, argv[1]);
7055  if (len < 0) {
7056  start = core->offset + len;
7057  len *= -1;
7058  }
7059  ut8 *bit_buf = RZ_NEWS0(ut8, len);
7060  char *str_buf = RZ_NEWS0(char, len * 8 + 1);
7061  if (!bit_buf || !str_buf) {
7062  RZ_LOG_ERROR("Fail to allocate memory\n");
7063  free(bit_buf);
7064  free(str_buf);
7065  return RZ_CMD_STATUS_ERROR;
7066  }
7067  rz_io_read_at(core->io, start, bit_buf, len);
7068  rz_str_bits(str_buf, (const ut8 *)bit_buf, len * 8, NULL);
7069  rz_cons_println(str_buf);
7070  free(bit_buf);
7071  free(str_buf);
7072  return RZ_CMD_STATUS_OK;
7073 }

References argv, free(), int, rz_core_t::io, len, NULL, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), rz_io_read_at(), RZ_LOG_ERROR, RZ_NEWS0, rz_num_math(), rz_str_bits(), start, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_print_delta_pointer_table_handler()

RZ_IPI RzCmdStatus rz_print_delta_pointer_table_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6111 of file cmd_print.c.

6111  {
6112  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6113  if (!len) {
6114  return RZ_CMD_STATUS_OK;
6115  }
6116  ut64 origin = argc > 2 ? rz_num_math(core->num, argv[2]) : core->offset;
6117  // _pointer_table does rz_core_cmd with @, so it modifies core->block
6118  // and this results in an UAF access when iterating over the jmptable
6119  // so we do a new allocation to avoid that issue
6120  ut8 *block = calloc(len, 1);
6121  if (!block) {
6122  return RZ_CMD_STATUS_ERROR;
6123  }
6124  memcpy(block, core->block, len);
6125  _pointer_table(core, origin, core->offset, block, len, 4, state->mode);
6126  free(block);
6127  return RZ_CMD_STATUS_OK;
6128 }
static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, RzOutputMode mode)
Definition: cmd_print.c:4003

References _pointer_table(), argv, rz_core_t::block, rz_core_t::blocksize, calloc(), free(), if(), int, len, memcpy(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_annotated_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_annotated_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 5874 of file cmd_print.c.

5874  {
5875  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
5876  if (len % 16) {
5877  len += 16 - (len % 16);
5878  }
5879  annotated_hexdump(core, len);
5880  return RZ_CMD_STATUS_OK;
5881 }
static void annotated_hexdump(RzCore *core, int len)
Definition: cmd_print.c:1745

References annotated_hexdump(), argv, rz_core_t::blocksize, if(), int, len, rz_core_t::num, RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_bits_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_bits_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 5888 of file cmd_print.c.

5888  {
5889  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
5890  if (!len) {
5891  return RZ_CMD_STATUS_OK;
5892  }
5893 
5894  char buf[32];
5895  for (int i = 0, c = 0; i < len; i++, c++) {
5896  if (c == 0) {
5897  ut64 ea = core->offset + i;
5898  if (core->print->pava) {
5899  ut64 va = rz_io_p2v(core->io, ea);
5900  if (va != UT64_MAX) {
5901  ea = va;
5902  }
5903  }
5904  char *string = rz_print_section_str(core->print, ea);
5905  rz_cons_print(string);
5906  free(string);
5907  rz_print_offset(core->print, ea, 0, 0, 0, 0, NULL);
5908  }
5909  rz_str_bits(buf, core->block + i, 8, NULL);
5910 
5911  // split bits
5912  memmove(buf + 5, buf + 4, 5);
5913  buf[4] = 0;
5914 
5915  rz_print_cursor(core->print, i, 1, 1);
5916  rz_cons_printf("%s.%s ", buf, buf + 5);
5917  rz_print_cursor(core->print, i, 1, 0);
5918  if (c == 3) {
5919  const ut8 *b = core->block + i - 3;
5920  int (*k)(const ut8 *, int) = cmd_pxb_k;
5921  char (*p)(char) = cmd_pxb_p;
5922 
5923  int n = k(b, 0) | k(b, 1) | k(b, 2) | k(b, 3);
5924  rz_cons_printf("0x%08x %c%c%c%c\n",
5925  n, p(b[0]), p(b[1]), p(b[2]), p(b[3]));
5926  c = -1;
5927  }
5928  }
5929  return RZ_CMD_STATUS_OK;
5930 }
static char cmd_pxb_p(char input)
Definition: cmd_print.c:4365
static int cmd_pxb_k(const ut8 *buffer, int x)
Definition: cmd_print.c:4369
RZ_API void rz_print_cursor(RzPrint *p, int cur, int len, int set)
Definition: print.c:166
RZ_API char * rz_print_section_str(RzPrint *p, ut64 at)
Definition: print.c:511

References argv, b, rz_core_t::block, rz_core_t::blocksize, c, cmd_pxb_k(), cmd_pxb_p(), free(), i, if(), int, rz_core_t::io, k, len, n, NULL, rz_core_t::num, rz_core_t::offset, p, rz_print_t::pava, rz_core_t::print, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_io_p2v(), rz_num_math(), rz_print_cursor(), rz_print_offset(), rz_print_section_str(), rz_str_bits(), ut64(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_comments_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_comments_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 5932 of file cmd_print.c.

5932  {
5933  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
5935 }
RZ_IPI bool rz_core_print_hexdump_or_hexdiff(RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, int len, bool use_comments)

References argv, rz_core_t::blocksize, bool2status(), int, len, rz_core_t::num, rz_core_t::offset, rz_core_print_hexdump_or_hexdiff(), rz_num_math(), and RZ_OUTPUT_MODE_STANDARD.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_emoji_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_emoji_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 5956 of file cmd_print.c.

5956  {
5957  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
5958  if (!len) {
5959  return RZ_CMD_STATUS_OK;
5960  }
5961  static const char emoji[] = {
5962  '\x8c', '\x80', '\x8c', '\x82', '\x8c', '\x85', '\x8c', '\x88',
5963  '\x8c', '\x99', '\x8c', '\x9e', '\x8c', '\x9f', '\x8c', '\xa0',
5964  '\x8c', '\xb0', '\x8c', '\xb1', '\x8c', '\xb2', '\x8c', '\xb3',
5965  '\x8c', '\xb4', '\x8c', '\xb5', '\x8c', '\xb7', '\x8c', '\xb8',
5966  '\x8c', '\xb9', '\x8c', '\xba', '\x8c', '\xbb', '\x8c', '\xbc',
5967  '\x8c', '\xbd', '\x8c', '\xbe', '\x8c', '\xbf', '\x8d', '\x80',
5968  '\x8d', '\x81', '\x8d', '\x82', '\x8d', '\x83', '\x8d', '\x84',
5969  '\x8d', '\x85', '\x8d', '\x86', '\x8d', '\x87', '\x8d', '\x88',
5970  '\x8d', '\x89', '\x8d', '\x8a', '\x8d', '\x8b', '\x8d', '\x8c',
5971  '\x8d', '\x8d', '\x8d', '\x8e', '\x8d', '\x8f', '\x8d', '\x90',
5972  '\x8d', '\x91', '\x8d', '\x92', '\x8d', '\x93', '\x8d', '\x94',
5973  '\x8d', '\x95', '\x8d', '\x96', '\x8d', '\x97', '\x8d', '\x98',
5974  '\x8d', '\x9c', '\x8d', '\x9d', '\x8d', '\x9e', '\x8d', '\x9f',
5975  '\x8d', '\xa0', '\x8d', '\xa1', '\x8d', '\xa2', '\x8d', '\xa3',
5976  '\x8d', '\xa4', '\x8d', '\xa5', '\x8d', '\xa6', '\x8d', '\xa7',
5977  '\x8d', '\xa8', '\x8d', '\xa9', '\x8d', '\xaa', '\x8d', '\xab',
5978  '\x8d', '\xac', '\x8d', '\xad', '\x8d', '\xae', '\x8d', '\xaf',
5979  '\x8d', '\xb0', '\x8d', '\xb1', '\x8d', '\xb2', '\x8d', '\xb3',
5980  '\x8d', '\xb4', '\x8d', '\xb5', '\x8d', '\xb6', '\x8d', '\xb7',
5981  '\x8d', '\xb8', '\x8d', '\xb9', '\x8d', '\xba', '\x8d', '\xbb',
5982  '\x8d', '\xbc', '\x8e', '\x80', '\x8e', '\x81', '\x8e', '\x82',
5983  '\x8e', '\x83', '\x8e', '\x84', '\x8e', '\x85', '\x8e', '\x88',
5984  '\x8e', '\x89', '\x8e', '\x8a', '\x8e', '\x8b', '\x8e', '\x8c',
5985  '\x8e', '\x8d', '\x8e', '\x8e', '\x8e', '\x8f', '\x8e', '\x92',
5986  '\x8e', '\x93', '\x8e', '\xa0', '\x8e', '\xa1', '\x8e', '\xa2',
5987  '\x8e', '\xa3', '\x8e', '\xa4', '\x8e', '\xa5', '\x8e', '\xa6',
5988  '\x8e', '\xa7', '\x8e', '\xa8', '\x8e', '\xa9', '\x8e', '\xaa',
5989  '\x8e', '\xab', '\x8e', '\xac', '\x8e', '\xad', '\x8e', '\xae',
5990  '\x8e', '\xaf', '\x8e', '\xb0', '\x8e', '\xb1', '\x8e', '\xb2',
5991  '\x8e', '\xb3', '\x8e', '\xb4', '\x8e', '\xb5', '\x8e', '\xb7',
5992  '\x8e', '\xb8', '\x8e', '\xb9', '\x8e', '\xba', '\x8e', '\xbb',
5993  '\x8e', '\xbd', '\x8e', '\xbe', '\x8e', '\xbf', '\x8f', '\x80',
5994  '\x8f', '\x81', '\x8f', '\x82', '\x8f', '\x83', '\x8f', '\x84',
5995  '\x8f', '\x86', '\x8f', '\x87', '\x8f', '\x88', '\x8f', '\x89',
5996  '\x8f', '\x8a', '\x90', '\x80', '\x90', '\x81', '\x90', '\x82',
5997  '\x90', '\x83', '\x90', '\x84', '\x90', '\x85', '\x90', '\x86',
5998  '\x90', '\x87', '\x90', '\x88', '\x90', '\x89', '\x90', '\x8a',
5999  '\x90', '\x8b', '\x90', '\x8c', '\x90', '\x8d', '\x90', '\x8e',
6000  '\x90', '\x8f', '\x90', '\x90', '\x90', '\x91', '\x90', '\x92',
6001  '\x90', '\x93', '\x90', '\x94', '\x90', '\x95', '\x90', '\x96',
6002  '\x90', '\x97', '\x90', '\x98', '\x90', '\x99', '\x90', '\x9a',
6003  '\x90', '\x9b', '\x90', '\x9c', '\x90', '\x9d', '\x90', '\x9e',
6004  '\x90', '\x9f', '\x90', '\xa0', '\x90', '\xa1', '\x90', '\xa2',
6005  '\x90', '\xa3', '\x90', '\xa4', '\x90', '\xa5', '\x90', '\xa6',
6006  '\x90', '\xa7', '\x90', '\xa8', '\x90', '\xa9', '\x90', '\xaa',
6007  '\x90', '\xab', '\x90', '\xac', '\x90', '\xad', '\x90', '\xae',
6008  '\x90', '\xaf', '\x90', '\xb0', '\x90', '\xb1', '\x90', '\xb2',
6009  '\x90', '\xb3', '\x90', '\xb4', '\x90', '\xb5', '\x90', '\xb6',
6010  '\x90', '\xb7', '\x90', '\xb8', '\x90', '\xb9', '\x90', '\xba',
6011  '\x90', '\xbb', '\x90', '\xbc', '\x90', '\xbd', '\x90', '\xbe',
6012  '\x91', '\x80', '\x91', '\x82', '\x91', '\x83', '\x91', '\x84',
6013  '\x91', '\x85', '\x91', '\x86', '\x91', '\x87', '\x91', '\x88',
6014  '\x91', '\x89', '\x91', '\x8a', '\x91', '\x8b', '\x91', '\x8c',
6015  '\x91', '\x8d', '\x91', '\x8e', '\x91', '\x8f', '\x91', '\x90',
6016  '\x91', '\x91', '\x91', '\x92', '\x91', '\x93', '\x91', '\x94',
6017  '\x91', '\x95', '\x91', '\x96', '\x91', '\x97', '\x91', '\x98',
6018  '\x91', '\x99', '\x91', '\x9a', '\x91', '\x9b', '\x91', '\x9c',
6019  '\x91', '\x9d', '\x91', '\x9e', '\x91', '\x9f', '\x91', '\xa0',
6020  '\x91', '\xa1', '\x91', '\xa2', '\x91', '\xa3', '\x91', '\xa4',
6021  '\x91', '\xa5', '\x91', '\xa6', '\x91', '\xa7', '\x91', '\xa8',
6022  '\x91', '\xa9', '\x91', '\xaa', '\x91', '\xae', '\x91', '\xaf',
6023  '\x91', '\xba', '\x91', '\xbb', '\x91', '\xbc', '\x91', '\xbd',
6024  '\x91', '\xbe', '\x91', '\xbf', '\x92', '\x80', '\x92', '\x81',
6025  '\x92', '\x82', '\x92', '\x83', '\x92', '\x84', '\x92', '\x85'
6026  };
6027  int cols = core->print->cols;
6028  if (cols < 1) {
6029  cols = 1;
6030  }
6031  for (int i = 0; i < len; i += cols) {
6032  rz_print_addr(core->print, core->offset + i);
6033  for (int j = i; j < i + cols; j += 1) {
6034  ut8 *p = (ut8 *)core->block + j;
6035  if (j < len) {
6036  rz_cons_printf("\xf0\x9f%c%c ", emoji[*p * 2], emoji[*p * 2 + 1]);
6037  } else {
6038  rz_cons_print(" ");
6039  }
6040  }
6041  rz_cons_print(" ");
6042  for (int j = i; j < len && j < i + cols; j += 1) {
6043  ut8 *p = (ut8 *)core->block + j;
6044  rz_print_byte(core->print, "%c", j, *p);
6045  }
6046  rz_cons_newline();
6047  }
6048  return RZ_CMD_STATUS_OK;
6049 }
RZ_API void rz_print_byte(RzPrint *p, const char *fmt, int idx, ut8 ch)
Definition: print.c:552

References argv, rz_core_t::block, rz_core_t::blocksize, rz_print_t::cols, i, if(), int, len, rz_core_t::num, rz_core_t::offset, p, rz_core_t::print, RZ_CMD_STATUS_OK, rz_cons_newline(), rz_cons_printf(), rz_num_math(), rz_print_addr(), and rz_print_byte().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_function_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_function_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6051 of file cmd_print.c.

6051  {
6052  return RZ_CMD_STATUS_ERROR;
6053 }

References RZ_CMD_STATUS_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6165 of file cmd_print.c.

6165  {
6166  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6167  return bool2status(rz_core_print_hexdump_or_hexdiff(core, state->mode, core->offset, len, false));
6168 }

References argv, rz_core_t::blocksize, bool2status(), int, len, rz_core_t::num, rz_core_t::offset, rz_core_print_hexdump_or_hexdiff(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex2_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex2_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6180 of file cmd_print.c.

6180  {
6181  return rz_print_hexdump_hex_common_handler(core, argc, argv, state, 2);
6182 }
RZ_IPI RzCmdStatus rz_print_hexdump_hex_common_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
Definition: cmd_print.c:6175

References argv, and rz_print_hexdump_hex_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex2l_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex2l_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6197 of file cmd_print.c.

6197  {
6198  return rz_print_hexdump_hexl_common_handler(core, argc, argv, state, 2);
6199 }
RZ_IPI RzCmdStatus rz_print_hexdump_hexl_common_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
Definition: cmd_print.c:6190

References argv, and rz_print_hexdump_hexl_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex4_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex4_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6183 of file cmd_print.c.

6183  {
6184  return rz_print_hexdump_hex_common_handler(core, argc, argv, state, 4);
6185 }

References argv, and rz_print_hexdump_hex_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex4l_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex4l_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6200 of file cmd_print.c.

6200  {
6201  return rz_print_hexdump_hexl_common_handler(core, argc, argv, state, 4);
6202 }

References argv, and rz_print_hexdump_hexl_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex8_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex8_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6186 of file cmd_print.c.

6186  {
6187  return rz_print_hexdump_hex_common_handler(core, argc, argv, state, 8);
6188 }

References argv, and rz_print_hexdump_hex_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex8l_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex8l_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6203 of file cmd_print.c.

6203  {
6204  return rz_print_hexdump_hexl_common_handler(core, argc, argv, state, 8);
6205 }

References argv, and rz_print_hexdump_hexl_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hex_common_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hex_common_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state,
ut8  n 
)

Definition at line 6175 of file cmd_print.c.

6175  {
6176  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6177  return bool2status(rz_core_print_dump(core, state->mode, core->offset, n, len, RZ_CORE_PRINT_FORMAT_TYPE_HEXADECIMAL));
6178 }
RZ_IPI bool rz_core_print_dump(RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, ut8 n, int len, RzCorePrintFormatType format)
Definition: cprint.c:322

References argv, rz_core_t::blocksize, bool2status(), int, len, n, rz_core_t::num, rz_core_t::offset, rz_core_print_dump(), and rz_num_math().

Referenced by rz_print_hexdump_hex2_handler(), rz_print_hexdump_hex4_handler(), and rz_print_hexdump_hex8_handler().

◆ rz_print_hexdump_hexii_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hexii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6055 of file cmd_print.c.

6055  {
6056  core->print->show_offset = rz_config_get_i(core->config, "hex.offset");
6057  rz_print_hexii(core->print, core->offset, core->block,
6058  (int)core->blocksize, rz_config_get_i(core->config, "hex.cols"));
6059  return RZ_CMD_STATUS_OK;
6060 }
RZ_API void rz_print_hexii(RzPrint *rp, ut64 addr, const ut8 *buf, int len, int step)
Definition: print.c:318
bool show_offset
Definition: rz_print.h:166

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, rz_core_t::offset, rz_core_t::print, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_print_hexii(), and rz_print_t::show_offset.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hexl_common_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hexl_common_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state,
ut8  n 
)

Definition at line 6190 of file cmd_print.c.

6190  {
6191  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6192  bool hex_offset = rz_config_get_b(core->config, "hex.offset");
6193  bool quiet = state->mode == RZ_OUTPUT_MODE_QUIET || state->mode == RZ_OUTPUT_MODE_QUIETEST;
6194  return bool2status(rz_core_print_hexdump_byline(core, !quiet && hex_offset, core->offset, len, n));
6195 }
RZ_IPI bool rz_core_print_hexdump_byline(RZ_NONNULL RzCore *core, bool hex_offset, ut64 addr, int len, ut8 size)
Definition: cprint.c:466
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47

References argv, rz_core_t::blocksize, bool2status(), rz_core_t::config, int, len, n, rz_core_t::num, rz_core_t::offset, rz_config_get_b(), rz_core_print_hexdump_byline(), rz_num_math(), RZ_OUTPUT_MODE_QUIET, and RZ_OUTPUT_MODE_QUIETEST.

Referenced by rz_print_hexdump_hex2l_handler(), rz_print_hexdump_hex4l_handler(), and rz_print_hexdump_hex8l_handler().

◆ rz_print_hexdump_hexless_bytes_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hexless_bytes_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6130 of file cmd_print.c.

6130  {
6131  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6132  core->print->flags |= RZ_PRINT_FLAGS_NONHEX;
6133  rz_core_print_hexdump(core, core->offset,
6134  core->block, len, 8, 1, 1);
6135  core->print->flags &= ~RZ_PRINT_FLAGS_NONHEX;
6136  return RZ_CMD_STATUS_OK;
6137 }
#define RZ_PRINT_FLAGS_NONHEX
Definition: rz_print.h:27

References argv, rz_core_t::block, rz_core_t::blocksize, rz_print_t::flags, int, len, rz_core_t::num, rz_core_t::offset, rz_core_t::print, RZ_CMD_STATUS_OK, rz_core_print_hexdump(), rz_num_math(), and RZ_PRINT_FLAGS_NONHEX.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hexless_words_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hexless_words_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6139 of file cmd_print.c.

6139  {
6140  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6141  if (!len) {
6142  return RZ_CMD_STATUS_OK;
6143  }
6144  ut8 *buf = calloc(len, 4);
6145  if (!buf) {
6146  return RZ_CMD_STATUS_ERROR;
6147  }
6148  rz_io_read_at(core->io, core->offset, buf, len * 4);
6149  core->print->flags |= RZ_PRINT_FLAGS_NONHEX;
6150  rz_core_print_hexdump(core, core->offset, buf, len * 4, 8, 1, 1);
6151  core->print->flags &= ~RZ_PRINT_FLAGS_NONHEX;
6152  free(buf);
6153  return RZ_CMD_STATUS_OK;
6154 }

References argv, rz_core_t::blocksize, calloc(), rz_print_t::flags, free(), if(), int, rz_core_t::io, len, rz_core_t::num, rz_core_t::offset, rz_core_t::print, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_print_hexdump(), rz_io_read_at(), rz_num_math(), and RZ_PRINT_FLAGS_NONHEX.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_hexpair_bytes_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_hexpair_bytes_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6156 of file cmd_print.c.

6156  {
6157  int len = (int)rz_str_nlen((const char *)core->block, core->blocksize);
6158  if (!len) {
6159  return RZ_CMD_STATUS_OK;
6160  }
6161  rz_print_bytes(core->print, core->block, len, "%02x");
6162  return RZ_CMD_STATUS_OK;
6163 }
RZ_API size_t rz_str_nlen(const char *s, size_t n)
Definition: str.c:1949

References rz_core_t::block, rz_core_t::blocksize, int, len, rz_core_t::print, RZ_CMD_STATUS_OK, rz_print_bytes(), and rz_str_nlen().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_n_lines_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_n_lines_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6170 of file cmd_print.c.

6170  {
6171  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6172  return bool2status(rz_core_print_hexdump_or_hexdiff(core, state->mode, core->offset, core->print->cols * len, false));
6173 }

References argv, rz_core_t::blocksize, bool2status(), rz_print_t::cols, int, len, rz_core_t::num, rz_core_t::offset, rz_core_t::print, rz_core_print_hexdump_or_hexdiff(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_oct_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_oct_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6207 of file cmd_print.c.

6207  {
6208  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6209  return bool2status(rz_core_print_dump(core, RZ_OUTPUT_MODE_STANDARD, core->offset, 1, len, RZ_CORE_PRINT_FORMAT_TYPE_OCTAL));
6210 }

References argv, rz_core_t::blocksize, bool2status(), int, len, rz_core_t::num, rz_core_t::offset, rz_core_print_dump(), rz_num_math(), and RZ_OUTPUT_MODE_STANDARD.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_signed_integer2_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer2_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 5946 of file cmd_print.c.

5946  {
5948 }
RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer_common_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, ut8 n)
Definition: cmd_print.c:5937

References argv, and rz_print_hexdump_signed_integer_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_signed_integer4_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer4_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 5949 of file cmd_print.c.

5949  {
5951 }

References argv, and rz_print_hexdump_signed_integer_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_signed_integer8_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer8_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 5952 of file cmd_print.c.

5952  {
5954 }

References argv, and rz_print_hexdump_signed_integer_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_signed_integer_common_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer_common_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state,
ut8  n 
)

◆ rz_print_hexdump_signed_integer_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_signed_integer_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 5943 of file cmd_print.c.

5943  {
5945 }

References argv, and rz_print_hexdump_signed_integer_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexdump_sparse_handler()

RZ_IPI RzCmdStatus rz_print_hexdump_sparse_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 6100 of file cmd_print.c.

6100  {
6101  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6102  if (!len) {
6103  return RZ_CMD_STATUS_OK;
6104  }
6105  core->print->flags |= RZ_PRINT_FLAGS_SPARSE;
6106  rz_core_print_hexdump(core, core->offset, core->block, len, 16, 1, 1);
6107  core->print->flags &= (int)(((ut32)-1) & (~RZ_PRINT_FLAGS_SPARSE));
6108  return RZ_CMD_STATUS_OK;
6109 }
#define RZ_PRINT_FLAGS_SPARSE
Definition: rz_print.h:19

References argv, rz_core_t::block, rz_core_t::blocksize, rz_print_t::flags, if(), int, len, rz_core_t::num, rz_core_t::offset, rz_core_t::print, RZ_CMD_STATUS_OK, rz_core_print_hexdump(), rz_num_math(), and RZ_PRINT_FLAGS_SPARSE.

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexword_references_1_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_1_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6084 of file cmd_print.c.

6084  {
6085  return rz_print_hexword_references_common_handler(core, argc, argv, state, 1);
6086 }
RZ_IPI RzCmdStatus rz_print_hexword_references_common_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state, int wordsize)
Definition: cmd_print.c:6062

References argv, and rz_print_hexword_references_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexword_references_2_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_2_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6088 of file cmd_print.c.

6088  {
6089  return rz_print_hexword_references_common_handler(core, argc, argv, state, 2);
6090 }

References argv, and rz_print_hexword_references_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexword_references_4_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_4_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6092 of file cmd_print.c.

6092  {
6093  return rz_print_hexword_references_common_handler(core, argc, argv, state, 4);
6094 }

References argv, and rz_print_hexword_references_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexword_references_8_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_8_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6096 of file cmd_print.c.

6096  {
6097  return rz_print_hexword_references_common_handler(core, argc, argv, state, 8);
6098 }

References argv, and rz_print_hexword_references_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_hexword_references_common_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_common_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state,
int  wordsize 
)

Definition at line 6062 of file cmd_print.c.

6062  {
6063  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
6064  const char *query = argc > 2 ? argv[2] : NULL;
6065  switch (wordsize) {
6066  case 1:
6067  case 2:
6068  case 4:
6069  case 8:
6070  cmd_pxr(core, len, state, wordsize, query);
6071  break;
6072  default:
6074  return RZ_CMD_STATUS_ERROR;
6075  }
6076  return RZ_CMD_STATUS_OK;
6077 }
static bool cmd_pxr(RzCore *core, int len, RzCmdStateOutput *state, int wordsize, const char *query)
Definition: cmd_print.c:4472

References argv, rz_core_t::blocksize, cmd_pxr(), int, len, NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_num_math(), and rz_warn_if_reached.

Referenced by rz_print_hexword_references_1_handler(), rz_print_hexword_references_2_handler(), rz_print_hexword_references_4_handler(), rz_print_hexword_references_8_handler(), and rz_print_hexword_references_handler().

◆ rz_print_hexword_references_handler()

RZ_IPI RzCmdStatus rz_print_hexword_references_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 6079 of file cmd_print.c.

6079  {
6080  int wordsize = rz_analysis_get_address_bits(core->analysis) / 8;
6081  return rz_print_hexword_references_common_handler(core, argc, argv, state, wordsize);
6082 }
RZ_API int rz_analysis_get_address_bits(RzAnalysis *analysis)
The actual size of an address in bits.
Definition: analysis.c:303

References rz_core_t::analysis, argv, rz_analysis_get_address_bits(), and rz_print_hexword_references_common_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_print_offset()

RZ_API void rz_print_offset ( RzPrint p,
ut64  off,
int  invert,
int  offseg,
int  offdec,
int  delta,
const char *  label 
)

Definition at line 5782 of file cmd_print.c.

5782  {
5783  rz_print_offset_sg(p, off, invert, offseg, 4, offdec, delta, label);
5784 }
static unsigned invert(unsigned x)
Definition: aesdata.c:73
RZ_API void rz_print_offset_sg(RzPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label)
Definition: cmd_print.c:5685

References delta, invert(), off, p, and rz_print_offset_sg().

Referenced by rz_cmd_print(), and rz_print_hexdump_bits_handler().

◆ rz_print_offset_sg()

RZ_API void rz_print_offset_sg ( RzPrint p,
ut64  off,
int  invert,
int  offseg,
int  seggrn,
int  offdec,
int  delta,
const char *  label 
)

Definition at line 5685 of file cmd_print.c.

5685  {
5686  char space[32] = {
5687  0
5688  };
5689  const char *reset = p->resetbg ? Color_RESET : Color_RESET_NOBG;
5690  bool show_color = p->flags & RZ_PRINT_FLAGS_COLOR;
5691  if (show_color) {
5692  char rgbstr[32];
5693  const char *k = rz_cons_singleton()->context->pal.offset; // TODO etooslow. must cache
5694  const char *inv = invert ? RZ_CONS_INVERT(true, true) : "";
5695  if (p->flags & RZ_PRINT_FLAGS_RAINBOW) {
5696  k = rz_cons_rgb_str_off(rgbstr, sizeof(rgbstr), off);
5697  }
5698  if (offseg) {
5699  ut32 s, a;
5700  a = off & 0xffff;
5701  s = ((off - a) >> seggrn) & 0xffff;
5702  if (offdec) {
5703  snprintf(space, sizeof(space), "%d:%d", s, a);
5704  rz_cons_printf("%s%s%9s%s", k, inv, space, reset);
5705  } else {
5706  rz_cons_printf("%s%s%04x:%04x%s", k, inv, s, a, reset);
5707  }
5708  } else {
5709  int sz = lenof(off, 0);
5710  int sz2 = lenof(delta, 1);
5711  if (delta > 0 || label) {
5712  if (label) {
5713  const int label_padding = 10;
5714  if (delta > 0) {
5715  const char *pad = rz_str_pad(' ', sz - sz2 + label_padding);
5716  if (offdec) {
5717  rz_cons_printf("%s%s%s%s+%d%s", k, inv, label, reset, delta, pad);
5718  } else {
5719  rz_cons_printf("%s%s%s%s+0x%x%s", k, inv, label, reset, delta, pad);
5720  }
5721  } else {
5722  const char *pad = rz_str_pad(' ', sz + label_padding);
5723  rz_cons_printf("%s%s%s%s%s", k, inv, label, reset, pad);
5724  }
5725  } else {
5726  const char *pad = rz_str_pad(' ', sz - sz2);
5727  if (offdec) {
5728  rz_cons_printf("%s+%d%s", pad, delta, reset);
5729  } else {
5730  rz_cons_printf("%s+0x%x%s", pad, delta, reset);
5731  }
5732  }
5733  } else {
5734  if (offdec) {
5735  snprintf(space, sizeof(space), "%" PFMT64u, off);
5736  rz_cons_printf("%s%s%10s%s", k, inv, space, reset);
5737  } else {
5738  if (p->wide_offsets) {
5739  rz_cons_printf("%s%s0x%016" PFMT64x "%s", k, inv, off, reset);
5740  } else {
5741  rz_cons_printf("%s%s0x%08" PFMT64x "%s", k, inv, off, reset);
5742  }
5743  }
5744  }
5745  }
5746  rz_cons_print(" ");
5747  } else {
5748  if (offseg) {
5749  ut32 s, a;
5750  a = off & 0xffff;
5751  s = (off - a) >> seggrn;
5752  if (offdec) {
5753  snprintf(space, sizeof(space), "%d:%d", s & 0xffff, a & 0xffff);
5754  rz_cons_printf("%9s%s", space, reset);
5755  } else {
5756  rz_cons_printf("%04x:%04x", s & 0xFFFF, a & 0xFFFF);
5757  }
5758  } else {
5759  int sz = lenof(off, 0);
5760  int sz2 = lenof(delta, 1);
5761  const char *pad = rz_str_pad(' ', sz - 5 - sz2 - 3);
5762  if (delta > 0) {
5763  if (offdec) {
5764  rz_cons_printf("%s+%d%s", pad, delta, reset);
5765  } else {
5766  rz_cons_printf("%s+0x%x%s", pad, delta, reset);
5767  }
5768  } else {
5769  if (offdec) {
5770  snprintf(space, sizeof(space), "%" PFMT64u, off);
5771  rz_cons_printf("%10s", space);
5772  } else {
5773  rz_cons_printf("0x%08" PFMT64x " ", off);
5774  }
5775  }
5776  }
5777  }
5778 }
static int lenof(ut64 off, int two)
Definition: cmd_print.c:5674
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API char * rz_cons_rgb_str_off(char *outstr, size_t sz, ut64 off)
Definition: rgb.c:209
#define Color_RESET_NOBG
Definition: rz_cons.h:618
#define RZ_PRINT_FLAGS_RAINBOW
Definition: rz_print.h:29
RZ_API const char * rz_str_pad(const char ch, int len)
Definition: str.c:3236

References a, Color_RESET, Color_RESET_NOBG, rz_cons_t::context, delta, invert(), k, lenof(), off, rz_cons_printable_palette_t::offset, p, pad(), rz_cons_context_t::pal, PFMT64u, PFMT64x, rz_cons_printf(), rz_cons_rgb_str_off(), rz_cons_singleton(), RZ_PRINT_FLAGS_COLOR, RZ_PRINT_FLAGS_RAINBOW, rz_str_pad(), s, and snprintf.

Referenced by ds_print_offset(), rz_core_disasm_pdi_with_buf(), and rz_print_offset().

◆ rz_print_op_analysis_color_map_handler()

RZ_IPI RzCmdStatus rz_print_op_analysis_color_map_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 5883 of file cmd_print.c.

5883  {
5884  int len = argc > 1 ? (int)rz_num_math(core->num, argv[1]) : (int)core->blocksize;
5885  return bool2status(cmd_print_pxA(core, len, state->mode));
5886 }
static bool cmd_print_pxA(RzCore *core, int len, RzOutputMode mode)
Definition: cmd_print.c:2175

References argv, rz_core_t::blocksize, bool2status(), cmd_print_pxA(), int, len, rz_core_t::num, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_print_string_c_cpp_handler()

RZ_IPI RzCmdStatus rz_print_string_c_cpp_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 4620 of file cmd_print.c.

4620  {
4621  char *str = rz_core_print_string_c_cpp(core);
4622  if (!str) {
4623  return RZ_CMD_STATUS_ERROR;
4624  }
4626  rz_free(str);
4627  return RZ_CMD_STATUS_OK;
4628 }
RZ_API RZ_OWN char * rz_core_print_string_c_cpp(RzCore *core)
Definition: cprint.c:13
#define rz_free(x)
Definition: rz_alloc.h:44

References RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), rz_core_print_string_c_cpp(), rz_free, and cmd_descs_generate::str.

Referenced by rzshell_cmddescs_init().

◆ rz_print_utf16be_handler()

RZ_IPI RzCmdStatus rz_print_utf16be_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 5830 of file cmd_print.c.

5830  {
5831  ut64 oldsize = core->blocksize;
5832  ut64 len = argc == 2 ? rz_num_math(core->num, argv[1]) : oldsize;
5833  if (len > oldsize) {
5834  rz_core_block_size(core, len);
5835  }
5836  if (mode == RZ_OUTPUT_MODE_JSON) {
5837  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF16BE, true);
5838  } else {
5839  RzStrStringifyOpt opt = { 0 };
5840  opt.buffer = core->block;
5841  opt.length = len;
5843  opt.stop_at_nil = true;
5844  core_print_raw_buffer(&opt);
5845  }
5846  if (len > oldsize) {
5847  rz_core_block_size(core, oldsize);
5848  }
5849  return RZ_CMD_STATUS_OK;
5850 }
@ RZ_STRING_ENC_UTF16BE
Definition: rz_str.h:25

References argv, rz_core_t::block, rz_core_t::blocksize, rz_str_stringify_opt_t::buffer, core_print_raw_buffer(), rz_str_stringify_opt_t::encoding, len, rz_str_stringify_opt_t::length, rz_core_t::num, print_json_string(), RZ_CMD_STATUS_OK, rz_core_block_size(), rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_STRING_ENC_UTF16BE, rz_str_stringify_opt_t::stop_at_nil, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_print_utf16le_handler()

RZ_IPI RzCmdStatus rz_print_utf16le_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 5786 of file cmd_print.c.

5786  {
5787  ut64 oldsize = core->blocksize;
5788  ut64 len = argc == 2 ? rz_num_math(core->num, argv[1]) : oldsize;
5789  if (len > oldsize) {
5790  rz_core_block_size(core, len);
5791  }
5792  if (mode == RZ_OUTPUT_MODE_JSON) {
5793  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF16LE, true);
5794  } else {
5795  RzStrStringifyOpt opt = { 0 };
5796  opt.buffer = core->block;
5797  opt.length = len;
5799  opt.stop_at_nil = true;
5800  core_print_raw_buffer(&opt);
5801  }
5802  if (len > oldsize) {
5803  rz_core_block_size(core, oldsize);
5804  }
5805  return RZ_CMD_STATUS_OK;
5806 }

References argv, rz_core_t::block, rz_core_t::blocksize, rz_str_stringify_opt_t::buffer, core_print_raw_buffer(), rz_str_stringify_opt_t::encoding, len, rz_str_stringify_opt_t::length, rz_core_t::num, print_json_string(), RZ_CMD_STATUS_OK, rz_core_block_size(), rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_STRING_ENC_UTF16LE, rz_str_stringify_opt_t::stop_at_nil, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_print_utf32be_handler()

RZ_IPI RzCmdStatus rz_print_utf32be_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 5852 of file cmd_print.c.

5852  {
5853  ut64 oldsize = core->blocksize;
5854  ut64 len = argc == 2 ? rz_num_math(core->num, argv[1]) : oldsize;
5855  if (len > oldsize) {
5856  rz_core_block_size(core, len);
5857  }
5858  if (mode == RZ_OUTPUT_MODE_JSON) {
5859  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF32BE, true);
5860  } else {
5861  RzStrStringifyOpt opt = { 0 };
5862  opt.buffer = core->block;
5863  opt.length = len;
5865  opt.stop_at_nil = true;
5866  core_print_raw_buffer(&opt);
5867  }
5868  if (len > oldsize) {
5869  rz_core_block_size(core, oldsize);
5870  }
5871  return RZ_CMD_STATUS_OK;
5872 }
@ RZ_STRING_ENC_UTF32BE
Definition: rz_str.h:26

References argv, rz_core_t::block, rz_core_t::blocksize, rz_str_stringify_opt_t::buffer, core_print_raw_buffer(), rz_str_stringify_opt_t::encoding, len, rz_str_stringify_opt_t::length, rz_core_t::num, print_json_string(), RZ_CMD_STATUS_OK, rz_core_block_size(), rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_STRING_ENC_UTF32BE, rz_str_stringify_opt_t::stop_at_nil, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_print_utf32le_handler()

RZ_IPI RzCmdStatus rz_print_utf32le_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 5808 of file cmd_print.c.

5808  {
5809  ut64 oldsize = core->blocksize;
5810  ut64 len = argc == 2 ? rz_num_math(core->num, argv[1]) : oldsize;
5811  if (len > oldsize) {
5812  rz_core_block_size(core, len);
5813  }
5814  if (mode == RZ_OUTPUT_MODE_JSON) {
5815  print_json_string(core, core->block, len, RZ_STRING_ENC_UTF32LE, true);
5816  } else {
5817  RzStrStringifyOpt opt = { 0 };
5818  opt.buffer = core->block;
5819  opt.length = len;
5821  opt.stop_at_nil = true;
5822  core_print_raw_buffer(&opt);
5823  }
5824  if (len > oldsize) {
5825  rz_core_block_size(core, oldsize);
5826  }
5827  return RZ_CMD_STATUS_OK;
5828 }

References argv, rz_core_t::block, rz_core_t::blocksize, rz_str_stringify_opt_t::buffer, core_print_raw_buffer(), rz_str_stringify_opt_t::encoding, len, rz_str_stringify_opt_t::length, rz_core_t::num, print_json_string(), RZ_CMD_STATUS_OK, rz_core_block_size(), rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_STRING_ENC_UTF32LE, rz_str_stringify_opt_t::stop_at_nil, and ut64().

Referenced by rzshell_cmddescs_init().

Variable Documentation

◆ colormap

const ut32 colormap[256]
static

Definition at line 495 of file cmd_print.c.

Referenced by cmd_prc().

◆ help_detail2_pf

const char* help_detail2_pf[]
static
Initial value:
= {
"pf:", PF_USAGE_STR, "",
"Examples:", "", "",
"pf", " 3xi foo bar", "3-array of struct, each with named fields: 'foo' as hex, and 'bar' as int",
"pf", " B (BitFldType)arg_name`", "bitfield type",
"pf", " E (EnumType)arg_name`", "enum type",
"pf", " obj=xxdz prev next size name", "Same as above",
"pf", " *z*i*w nb name blob", "Print the pointers with given labels",
"pf", " iwq foo bar troll", "Print the iwq format with foo, bar, troll as the respective names for the fields",
"pf", " 0iwq foo bar troll", "Same as above, but considered as a union (all fields at offset 0)",
"pf.", "obj xxdz prev next size name", "Define the obj format as xxdz",
"pf.", "plop ? (troll)mystruct", "Use structure troll previously defined",
"pfj.", "plop @ 0x14", "Apply format object at the given offset",
"pf", " 10xiz pointer length string", "Print a size 10 array of the xiz struct with its field names",
"pf", " 5sqw string quad word", "Print an array with sqw struct along with its field names",
"pf", " {integer}? (bifc)", "Print integer times the following format (bifc)",
"pf", " [4]w[7]i", "Print an array of 4 words and then an array of 7 integers",
"pf", " ic...?i foo bar \"(pf xw yo foo)troll\" yo", "Print nested anonymous structures",
"pf", " ;..x", "Print value located 6 bytes from current offset",
"pf", " [10]z[3]i[10]Zb", "Print an fixed size str, widechar, and var",
"pfj", " +F @ 0x14", "Print the content at given offset with flag",
"pf", " n2", "print signed short (2 bytes) value. Use N instead of n for printing unsigned values",
"pf", " [2]? (plop)structname @ 0", "Prints an array of structs",
"pf", " eqew bigWord beef", "Swap endianness and print with given labels",
"pf", ".foo rr (eax)reg1 (eip)reg2", "Create object referencing to register values ",
"pf", " tt troll plop", "print time stamps with labels troll and plop",
}
#define PF_USAGE_STR
Definition: cmd_print.c:15

Definition at line 342 of file cmd_print.c.

Referenced by cmd_print_format().

◆ help_detail_pf

const char* help_detail_pf[]
static

Definition at line 301 of file cmd_print.c.

Referenced by cmd_print_format().

◆ help_msg_amper

const char* help_msg_amper[]
static
Initial value:
= {
"Usage:", "&[-|<cmd>]", "Manage tasks (WARNING: Experimental. Use with caution!)",
"&", " <cmd>", "run <cmd> in a new background task",
"&t", " <cmd>", "run <cmd> in a new transient background task (auto-delete when it is finished)",
"&", "", "list all tasks",
"&j", "", "list all tasks (in JSON)",
"&=", " 3", "show output of task 3",
"&b", " 3", "break task 3",
"&-", " 1", "delete task #1 or schedule for deletion when it is finished",
"&", "-*", "delete all done tasks",
"&?", "", "show this help",
"&&", " 3", "wait until task 3 is finished",
"&&", "", "wait until all tasks are finished",
}

Definition at line 86 of file cmd_print.c.

Referenced by helpCmdTasks().

◆ help_msg_at

const char* help_msg_at[]
static

Definition at line 102 of file cmd_print.c.

Referenced by rz_cmd_help(), and rz_core_cmd_subst_i().

◆ help_msg_at_at

const char* help_msg_at_at[]
static
Initial value:
= {
"@@", "", " # foreach iterator command:",
"x", " @@ sym.*", "run 'x' over all flags matching 'sym.' in current flagspace",
"x", " @@dbt[abs]", "run 'x' command on every backtrace address, bp or sp",
"x", " @@.file", "run 'x' over the offsets specified in the file (one offset per line)",
"x", " @@=off1 off2 ..", "manual list of offsets",
"x", " @@/x 9090", "temporary set cmd.hit to run a command on each search result",
"x", " @@k sdbquery", "run 'x' on all offsets returned by that sdbquery",
"x", " @@t", "run 'x' on all threads (see dp)",
"x", " @@b", "run 'x' on all basic blocks of current function (see afb)",
"x", " @@i", "run 'x' on all instructions of the current function (see pdr)",
"x", " @@iS", "run 'x' on all sections adjusting blocksize",
"x", " @@f", "run 'x' on all functions (see aflq)",
"x", " @@f:write", "run 'x' on all functions matching write in the name",
"x", " @@s:from to step", "run 'x' on all offsets from, to incrementing by step",
"x", " @@c:cmd", "the same as @@=`` without the backticks",
"x", " @@=`pdf~call[0]`", "run 'x' at every call offset of the current function",
}

Definition at line 154 of file cmd_print.c.

Referenced by rz_cmd_help(), and rz_core_cmd_foreach().

◆ help_msg_at_at_at

const char* help_msg_at_at_at[]
static
Initial value:
= {
"@@@", "", " # foreach offset+size iterator command:",
"x", " @@@=", "[addr] [size] ([addr] [size] ...)",
"x", " @@@b", "basic blocks of current function",
"x", " @@@c:cmd", "Same as @@@=`cmd`, without the backticks",
"x", " @@@C:cmd", "comments matching",
"x", " @@@i", "imports",
"x", " @@@r", "registers",
"x", " @@@s", "symbols",
"x", " @@@st", "strings",
"x", " @@@S", "sections",
"x", " @@@m", "io.maps",
"x", " @@@M", "dbg.maps (See ?$?~size)",
"x", " @@@f", "flags",
"x", " @@@f:hit*", "flags matching glob expression",
"x", " @@@F", "functions (set fcn size which may be incorrect if not linear)",
"x", " @@@F:glob", "functions matching glob expression",
"x", " @@@t", "threads",
"x", " @@@r", "regs",
}

Definition at line 175 of file cmd_print.c.

Referenced by rz_cmd_help(), and rz_core_cmd_foreach3().

◆ help_msg_p

const char* help_msg_p[]
static

Definition at line 198 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_p_equal

const char* help_msg_p_equal[]
static
Initial value:
= {
"Usage:", "p=[=bep?][qj] [N] ([len]) ([offset]) ", "show entropy/printable chars/chars bars",
"e ", "zoom.in", "specify range for zoom",
"p=", "", "print bytes of current block in bars",
"p==", "[..]", "same subcommands as p=, using column bars instead of rows",
"p=", "0", "number of 0x00 bytes for each filesize/blocksize",
"p=", "2", "short (signed int16) bars, good for waves",
"p=", "a", "analysis bbs maps",
"p=", "A", "analysis stats maps (see p-)",
"p=", "b", "same as above",
"p=", "c", "number of calls per block",
"p=", "d", "min/max/number of unique bytes in block",
"p=", "e", "entropy for each filesize/blocksize",
"p=", "F", "number of 0xFF bytes for each filesize/blocksize",
"p=", "i", "number of invalid instructions per block",
"p=", "j", "number of jumps and conditional jumps in block",
"p=", "m", "number of flags and marks in block",
"p=", "p", "number of printable bytes for each filesize/blocksize",
"p=", "s", "number of syscall and privileged instructions",
"p=", "z", "number of chars in strings in block",
}

Definition at line 235 of file cmd_print.c.

Referenced by cmd_print_bars().

◆ help_msg_p_minus

const char* help_msg_p_minus[]
static
Initial value:
= {
"Usage:", "p-[hj] [nblocks] ", "bar|json|histogram blocks",
"p-", "", "show ascii-art bar of metadata in file boundaries",
"p-e", "", "show ascii-art bar of entropy per block",
"p-h", "", "show histogram analysis of metadata per block",
"p-j", "", "show json format",
}

Definition at line 266 of file cmd_print.c.

Referenced by cmd_print_blocks().

◆ help_msg_pc

const char* help_msg_pc[]
static
Initial value:
= {
"Usage:", "pc", " # Print in code",
"pc", "", "C",
"pc*", "", "print 'wx' rizin commands",
"pcA", "", ".bytes with instructions in comments",
"pca", "", "GAS .byte blob",
"pcd", "", "C dwords (8 byte)",
"pch", "", "C half-words (2 byte)",
"pci", "", "C array of bytes with instructions",
"pcJ", "", "javascript",
"pcj", "", "json",
"pck", "", "kotlin",
"pco", "", "Objective-C",
"pcp", "", "python",
"pcr", "", "rust",
"pcS", "", "shellscript that reconstructs the bin",
"pcs", "", "string",
"pcv", "", "JaVa",
"pcV", "", "V (vlang.io)",
"pcw", "", "C words (4 byte)",
"pcy", "", "yara",
"pcz", "", "Swift",
}

Definition at line 31 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_pF

const char* help_msg_pF[]
static
Initial value:
= {
"Usage: pF[apdbA]", "[len]", "parse ASN1, PKCS, X509, DER, protobuf, axml",
"pFa", "[len]", "decode ASN1 from current block",
"pFaq", "[len]", "decode ASN1 from current block (quiet output)",
"pFb", "[len]", "decode raw proto buffers.",
"pFbv", "[len]", "decode raw proto buffers (verbose).",
"pFo", "[len]", "decode ASN1 OID",
"pFp", "[len]", "decode PKCS7",
"pFx", "[len]", "Same with X509",
"pFA", "[len]", "decode Android Binary XML from current block",
}

Definition at line 56 of file cmd_print.c.

Referenced by cmd_print_fromage().

◆ help_msg_pf

const char* help_msg_pf[]
static
Initial value:
= {
"pf:", PF_USAGE_STR, "",
"Commands:", "", "",
"pf", " fmt", "Show data using the given format-string. See 'pf\?\?' and 'pf\?\?\?'.",
"pf", "?", "Show this help",
"pf", "??", "Format characters",
"pf", "???", "pf usage examples",
"pf* ", "fmt_name|fmt", "Show data using (named) format as rizin flag create commands",
"pf.", "", "List all format definitions",
"pf.", "fmt_name", "Show data using named format",
"pf.", "fmt_name.field_name", "Show specific data field using named format",
"pf.", "fmt_name.field_name=33", "Set new value for the specified field in named format",
"pf.", "fmt_name.field_name[i]", "Show element i of array field_name",
"pf.", "name [0|cnt]fmt", "Define a new named format",
"pf?", "fmt_name", "Show the definition of a named format",
"pfc ", "fmt_name|fmt", "Show data using (named) format as C string",
"pfd.", "fmt_name", "Show data using named format as graphviz commands",
"pfj ", "fmt_name|fmt", "Show data using (named) format in JSON",
"pfo", " fdf_name", "Load a Format Definition File (fdf)",
"pfo", "", "List all format definition files (fdf)",
"pfq", " fmt ...", "Quiet print format (do now show address)",
"pfs", "[.fmt_name| fmt]", "Print the size of (named) format in bytes",
"pfv.", "fmt_name[.field]", "Print value(s) only for named format. Useful for one-liners",
}

Definition at line 275 of file cmd_print.c.

Referenced by cmd_print_format().

◆ help_msg_pg

const char* help_msg_pg[]
static
Initial value:
= {
"Usage: pg[-]", "[asm|hex]", "print (dis)assembled",
"pg", " [x y w h cmd]", "add a new gadget",
"pg", "", "print them all",
"pg", "*", "print the gadgets as rizin commands",
"pg-", "*", "remove all the gadgets",
}

Definition at line 1197 of file cmd_print.c.

Referenced by cmd_print_gadget().

◆ help_msg_pi

const char* help_msg_pi[]
static
Initial value:
= {
"Usage:", "pi[befr] [num]", "",
"pia", "", "print all possible opcodes (byte per byte)",
"pib", "", "print instructions of basic block",
"pie", "", "print offset + esil expression",
"pif", "[?]", "print instructions of function",
"pir", "", "like 'pdr' but with 'pI' output",
"piu", "[q] [limit]", "disasm until ujmp or ret is found (see pdp)",
"pix", " [hexpairs]", "alias for pad",
}

Definition at line 371 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_pif

const char* help_msg_pif[]
static
Initial value:
= {
"Usage:",
"pif[cj]",
"",
"pif?",
"",
"print this help message",
"pifc",
"",
"print all calls from this function",
"pifcj",
"",
"print all calls from this function in JSON format",
"pifj",
"",
"print instructions of function in JSON format",
}

Definition at line 383 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_pj

const char* help_msg_pj[]
static
Initial value:
= {
"Usage:", "pj[..] [size]", "",
"pj", "", "print current block as indented JSON",
"pj.", "", "print as indented JSON from 0 to the current offset",
"pj..", "", "print JSON path from 0 to the current offset",
}

Definition at line 258 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_po

const char* help_msg_po[]
static
Initial value:
= {
"Usage:", "po[24aAdlmorsx]", " [hexpairs] @ addr[!bsize]",
"po[24aAdlmorsx]", "", "without hexpair values, clipboard is used",
"po2", " [val]", "2= 2 byte endian swap",
"po4", " [val]", "4= 4 byte endian swap",
"poa", " [val]", "+= addition (f.ex: poa 0102)",
"poA", " [val]", "&= and",
"pod", " [val]", "/= divide",
"pol", " [val]", "<<= shift left",
"pom", " [val]", "*= multiply",
"poo", " [val]", "|= or",
"por", " [val]", ">>= shift right",
"pos", " [val]", "-= substraction",
"pox", " [val]", "^= xor (f.ex: pox 0x90)",
}

Definition at line 401 of file cmd_print.c.

Referenced by cmd_print_op().

◆ help_msg_pp

const char* help_msg_pp[]
static
Initial value:
= {
"Usage: pp[d]", "", "print patterns",
"pp0", "", "print buffer filled with zeros",
"pp1", "", "print incremental byte pattern (honor lower bits of cur address and bsize)",
"pp2", "", "print incremental word pattern",
"pp4", "", "print incremental dword pattern",
"pp8", "", "print incremental qword pattern",
"ppa", "[lu]", "latin alphabet (lowercase, uppercases restrictions)",
"ppd", "", "print debruijn pattern (see rz-gg -P, -q and wopD)",
"ppf", "", "print buffer filled with 0xff",
"ppn", "", "numeric pin patterns",
}

Definition at line 17 of file cmd_print.c.

Referenced by __printPattern().

◆ help_msg_pr

const char* help_msg_pr[]
static
Initial value:
= {
"Usage: pr[glx]", "[size]", "print N raw bytes",
"prc", "[=fep..]", "print bytes as colors in palette",
"prg", "[?]", "print raw GUNZIPped block",
"prx", "", "printable chars with real offset (hyew)",
"prz", "", "print raw zero terminated string",
}

Definition at line 69 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_prg

const char* help_msg_prg[]
static
Initial value:
= {
"Usage: prg[io]", "", "print raw GUNZIPped block",
"prg", "", "print gunzipped data of current block",
"prgi", "", "show consumed bytes when inflating",
"prgo", "", "show output bytes after inflating",
}

Definition at line 78 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_ps

const char* help_msg_ps[]
static
Initial value:
= {
"Usage:", "ps[bijqpsuwWxz+] [N]", "Print String",
"ps", "", "print string",
"ps+", "[j]", "print libc++ std::string (same-endian, ascii, zero-terminated)",
"psb", "", "print strings in current block",
"psi", "", "print string inside curseek",
"psj", "", "print string in JSON format",
"psp", "[j]", "print pascal string",
"pss", "", "print string in screen (wrap width)",
"psu", "[zj]", "print utf16 unicode (json)",
"psw", "[j]", "print 16bit wide little endian string",
"psW", "[j]", "print 32bit wide little endian string",
"psx", "", "show string with escaped chars",
"psz", "[j]", "print zero-terminated string",
}

Definition at line 418 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_pv

const char* help_msg_pv[]
static
Initial value:
= {
"Usage: pv[j][1,2,4,8,z]", "", "",
"pv", "", "print bytes based on asm.bits",
"pv1", "", "print 1 byte in memory",
"pv2", "", "print 2 bytes in memory",
"pv4", "", "print 4 bytes in memory",
"pv8", "", "print 8 bytes in memory",
"pvz", "", "print value as string (alias for ps)",
}

Definition at line 435 of file cmd_print.c.

Referenced by cmd_print_pv().

◆ help_msg_px

const char* help_msg_px[]
static
Initial value:
= {
"Usage:", "px[0afoswqWqQ][f]", " # Print heXadecimal",
"px", "", "show hexdump",
"px/", "", "same as x/ in gdb (help x)",
"px0", "", "8bit hexpair list of bytes until zero byte",
"pxa", "", "show annotated hexdump",
"pxA", "[?]", "show op analysis color map",
"pxb", "", "dump bits in hexdump form",
"pxc", "", "show hexdump with comments",
"pxd", "[?1248]", "signed integer dump (1 byte, 2 and 4)",
"pxe", "", "emoji hexdump! :)",
"pxf", "", "show hexdump of current function",
"pxh", "", "show hexadecimal half-words dump (16bit)",
"pxH", "", "same as above, but one per line",
"pxi", "", "HexII compact binary representation",
"pxl", "", "display N lines (rows) of hexdump",
"pxo", "", "show octal dump",
"pxq", "", "show hexadecimal quad-words dump (64bit)",
"pxQ", "[q]", "same as above, but one per line",
"pxr", "[1248][qj]", "show hexword references (q=quiet, j=json)",
"pxs", "", "show hexadecimal in sparse mode",
"pxt", "[*.] [origin]", "show delta pointer table in rizin commands",
"pxw", "", "show hexadecimal words dump (32bit)",
"pxW", "[q]", "same as above, but one per line (q=quiet)",
"pxx", "", "show N bytes of hex-less hexdump",
"pxX", "", "show N words of hex-less hexdump",
}

Definition at line 446 of file cmd_print.c.

Referenced by rz_cmd_print().

◆ help_msg_pxA

const char* help_msg_pxA[]
Initial value:
= {
"Usage: pxA [len]", "", "show op analysis color map",
"$$", "", "int/swi/trap/new\n",
"+-*/", "", "math ops\n",
"->", "", "push\n",
"..", "", "nop\n",
"<-", "", "pop\n",
"<<>>", "", "shift ops\n",
"==", "", "cmp/test\n",
"XX", "", "invalid\n",
"_C", "", "call\n",
"_J", "", "jump\n",
"_R", "", "ret\n",
"cJ", "", "conditional jump\n",
"io", "", "in/out ops\n",
"mv", "", "move,lea,li\n",
"|&^", "", "bin ops\n",
}

Definition at line 475 of file cmd_print.c.