Rizin
unix-like reverse engineering framework and cli tools
cprint.c File Reference
#include <rz_core.h>

Go to the source code of this file.

Macros

#define STRING_CHUNK   16
 

Functions

RZ_API RZ_OWN char * rz_core_print_string_c_cpp (RzCore *core)
 
RZ_API RZ_OWN char * rz_core_hex_of_assembly (RzCore *core, const char *assembly)
 Get the hexpair of the assembly. More...
 
RZ_API RZ_OWN char * rz_core_esil_of_assembly (RzCore *core, const char *assembly)
 Get the esil of the assembly. More...
 
RZ_API RZ_OWN char * rz_core_assembly_of_hex (RzCore *core, ut8 *hex, int len)
 Get the assembly of the hexstr. More...
 
RZ_API RZ_OWN char * rz_core_esil_of_hex (RzCore *core, ut8 *hex, int len)
 Get the esil of the hexstr. More...
 
RZ_IPI void rz_core_print_hexdump (RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
 
RZ_IPI void rz_core_print_jsondump (RZ_NONNULL RzCore *core, RZ_NONNULL const ut8 *buf, int len, int wordsize)
 
RZ_IPI void rz_core_print_hexdiff (RZ_NONNULL RzCore *core, ut64 aa, RZ_NONNULL const ut8 *_a, ut64 ba, RZ_NONNULL const ut8 *_b, int len, int scndcol)
 
RZ_API char * rz_core_print_hexdump_diff_str (RZ_NONNULL RzCore *core, ut64 aa, ut64 ba, ut64 len)
 Print hexdump diff between aa and ba with len. More...
 
RZ_IPI bool rz_core_print_hexdump_diff (RZ_NONNULL RzCore *core, ut64 aa, ut64 ba, ut64 len)
 
static st8 format_type_to_base (const RzCorePrintFormatType format, const ut8 n)
 
static void fix_size_from_format (const RzCorePrintFormatType format, ut8 *size)
 
static void len_fixup (RzCore *core, ut64 *addr, int *len)
 
RZ_API char * rz_core_print_dump_str (RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, ut8 n, int len, RzCorePrintFormatType format)
 Print dump at addr. More...
 
RZ_IPI bool rz_core_print_dump (RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, ut8 n, int len, RzCorePrintFormatType format)
 
RZ_API char * rz_core_print_hexdump_or_hexdiff_str (RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, int len, bool use_comment)
 Print hexdump at addr, but maybe print hexdiff if (diff.from or diff.to),. More...
 
RZ_IPI bool rz_core_print_hexdump_or_hexdiff (RZ_NONNULL RzCore *core, RZ_NULLABLE RzOutputMode mode, ut64 addr, int len, bool use_comment)
 
static char * ut64_to_hex (const ut64 x, const ut8 width)
 
RZ_API RZ_OWN char * rz_core_print_hexdump_byline_str (RZ_NONNULL RzCore *core, bool hex_offset, ut64 addr, int len, ut8 size)
 Hexdump at addr. More...
 
RZ_IPI bool rz_core_print_hexdump_byline (RZ_NONNULL RzCore *core, bool hexoffset, ut64 addr, int len, ut8 size)
 

Macro Definition Documentation

◆ STRING_CHUNK

#define STRING_CHUNK   16

Definition at line 6 of file cprint.c.

Function Documentation

◆ fix_size_from_format()

static void fix_size_from_format ( const RzCorePrintFormatType  format,
ut8 size 
)
inlinestatic

Definition at line 242 of file cprint.c.

242  {
243  if (format != RZ_CORE_PRINT_FORMAT_TYPE_INTEGER) {
244  return;
245  }
246  static const st8 sizes[] = {
247  0, 4, 2, [4] = 4, [8] = 4
248  };
249  if (*size >= sizeof(sizes)) {
250  return;
251  }
252  *size = sizes[*size];
253 }
voidpf void uLong size
Definition: ioapi.h:138
#define st8
Definition: rz_types_base.h:16

References st8.

Referenced by rz_core_print_dump_str().

◆ format_type_to_base()

static st8 format_type_to_base ( const RzCorePrintFormatType  format,
const ut8  n 
)
inlinestatic

Definition at line 230 of file cprint.c.

230  {
231  static const st8 bases[][9] = {
232  { 0, 8 },
233  { 0, -1, -10, [4] = 10, [8] = -8 },
234  { 0, 16, 32, [4] = 32, [8] = 64 },
235  };
236  if (format >= RZ_CORE_PRINT_FORMAT_TYPE_INVALID || n >= sizeof(bases[0])) {
237  return 0;
238  }
239  return bases[format][n];
240 }
int n
Definition: mipsasm.c:19

References n, and st8.

Referenced by rz_core_print_dump_str().

◆ len_fixup()

static void len_fixup ( RzCore core,
ut64 addr,
int len 
)
inlinestatic

Definition at line 255 of file cprint.c.

255  {
256  if (!len) {
257  return;
258  }
259  bool is_positive = *len > 0;
260  if (RZ_ABS(*len) > core->blocksize_max) {
261  RZ_LOG_ERROR("this <len> is too big (0x%" PFMT32x
262  " < 0x%" PFMT32x ").",
263  *len, core->blocksize_max);
264  *len = (int)core->blocksize_max;
265  }
266  if (is_positive) {
267  return;
268  }
269  *len = RZ_ABS(*len);
270  if (addr) {
271  *addr = *addr - *len;
272  }
273 }
size_t len
Definition: 6502dis.c:15
#define PFMT32x
@ RZ_ABS
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
static int
Definition: sfsocketcall.h:114
ut32 blocksize_max
Definition: rz_core.h:304
static int addr
Definition: z80asm.c:58

References addr, rz_core_t::blocksize_max, int, len, PFMT32x, RZ_ABS, and RZ_LOG_ERROR.

Referenced by rz_core_print_dump_str(), rz_core_print_hexdump_byline_str(), and rz_core_print_hexdump_or_hexdiff_str().

◆ rz_core_assembly_of_hex()

RZ_API RZ_OWN char* rz_core_assembly_of_hex ( RzCore core,
ut8 hex,
int  len 
)

Get the assembly of the hexstr.

Parameters
coreRzCore
hexhex
lenlength of hex
Returns
a string containing the assembly of the hexstr

Definition at line 109 of file cprint.c.

109  {
110  RzStrBuf *buf = rz_strbuf_new("");
111  if (!buf) {
112  RZ_LOG_ERROR("Fail to allocate memory\n");
113  return NULL;
114  }
115  rz_asm_set_pc(core->rasm, core->offset);
116  RzAsmCode *acode = rz_asm_mdisassemble(core->rasm, hex, len);
117  if (!acode) {
118  RZ_LOG_ERROR("Invalid hexstr\n");
120  return NULL;
121  }
122  rz_strbuf_append(buf, acode->assembly);
123  rz_asm_code_free(acode);
124  return rz_strbuf_drain(buf);
125 }
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
RZ_API RzAsmCode * rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len)
Definition: asm.c:743
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
#define NULL
Definition: cris-opc.c:27
voidpf void * buf
Definition: ioapi.h:138
static const char hex[16]
Definition: print.c:21
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
char * assembly
Definition: rz_asm.h:81
ut64 offset
Definition: rz_core.h:301
RzAsm * rasm
Definition: rz_core.h:323

References rz_asm_code_t::assembly, hex, len, NULL, rz_core_t::offset, rz_core_t::rasm, rz_asm_code_free(), rz_asm_mdisassemble(), rz_asm_set_pc(), RZ_LOG_ERROR, rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_free(), and rz_strbuf_new().

Referenced by rz_assembly_of_hex_handler().

◆ rz_core_esil_of_assembly()

RZ_API RZ_OWN char* rz_core_esil_of_assembly ( RzCore core,
const char *  assembly 
)

Get the esil of the assembly.

Parameters
coreRzCore
assemblyassembly
Returns
a string containing the esil of the assembly

Definition at line 68 of file cprint.c.

68  {
69  RzStrBuf *buf = rz_strbuf_new("");
70  if (!buf) {
71  RZ_LOG_ERROR("Fail to allocate memory\n");
72  return NULL;
73  }
74  rz_asm_set_pc(core->rasm, core->offset);
75  RzAsmCode *acode = rz_asm_massemble(core->rasm, assembly);
76  if (!acode) {
77  RZ_LOG_ERROR("Fail to assemble by rz_asm_massemble()\n");
79  return NULL;
80  }
81  int printed = 0, bufsz = acode->len;
82  RzAnalysisOp aop = { 0 };
83  while (printed < bufsz) {
84  aop.size = 0;
85  if (rz_analysis_op(core->analysis, &aop, core->offset,
86  (const ut8 *)acode->bytes + printed, bufsz - printed, RZ_ANALYSIS_OP_MASK_ESIL) <= 0 ||
87  aop.size < 1) {
88  RZ_LOG_ERROR("Cannot decode instruction\n");
89  rz_analysis_op_fini(&aop);
91  rz_asm_code_free(acode);
92  return NULL;
93  }
95  printed += aop.size;
96  rz_analysis_op_fini(&aop);
97  }
98  rz_asm_code_free(acode);
99  return rz_strbuf_drain(buf);
100 }
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
uint8_t ut8
Definition: lh5801.h:11
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_MASK_ESIL
Definition: rz_analysis.h:441
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
ut8 * bytes
Definition: rz_asm.h:80
RzAnalysis * analysis
Definition: rz_core.h:322

References rz_core_t::analysis, rz_asm_code_t::bytes, rz_analysis_op_t::esil, rz_asm_code_t::len, NULL, rz_core_t::offset, rz_core_t::rasm, rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_ESIL, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_pc(), RZ_LOG_ERROR, rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), RZ_STRBUF_SAFEGET, and rz_analysis_op_t::size.

Referenced by rz_esil_of_assembly_handler().

◆ rz_core_esil_of_hex()

RZ_API RZ_OWN char* rz_core_esil_of_hex ( RzCore core,
ut8 hex,
int  len 
)

Get the esil of the hexstr.

Parameters
coreRzCore
hexhex
lenlength of hex
Returns
a string containing the esil of the hexstr

Definition at line 134 of file cprint.c.

134  {
135  RzStrBuf *buf = rz_strbuf_new("");
136  if (!buf) {
137  RZ_LOG_ERROR("Fail to allocate memory\n");
138  goto fail;
139  }
140  int printed = 0;
141  RzAnalysisOp aop = { 0 };
142  while (printed < len) {
143  aop.size = 0;
144  if (rz_analysis_op(core->analysis, &aop, core->offset,
145  (const ut8 *)hex + printed, len - printed, RZ_ANALYSIS_OP_MASK_ESIL) <= 0 ||
146  aop.size < 1) {
147  RZ_LOG_ERROR("Cannot decode instruction\n");
148  rz_analysis_op_fini(&aop);
149  goto fail;
150  }
152  printed += aop.size;
153  rz_analysis_op_fini(&aop);
154  }
155  return rz_strbuf_drain(buf);
156 fail:
158  return NULL;
159 }
#define fail(test)
Definition: tests.h:29

References rz_core_t::analysis, rz_analysis_op_t::esil, fail, hex, len, NULL, rz_core_t::offset, rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_ESIL, RZ_LOG_ERROR, rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), RZ_STRBUF_SAFEGET, and rz_analysis_op_t::size.

Referenced by rz_esil_of_hex_handler().

◆ rz_core_hex_of_assembly()

RZ_API RZ_OWN char* rz_core_hex_of_assembly ( RzCore core,
const char *  assembly 
)

Get the hexpair of the assembly.

Parameters
coreRzCore
assemblyassembly
Returns
a string containing the hexpair of the assembly

Definition at line 41 of file cprint.c.

41  {
42  RzStrBuf *buf = rz_strbuf_new("");
43  if (!buf) {
44  RZ_LOG_ERROR("Fail to allocate memory\n");
45  return NULL;
46  }
47  rz_asm_set_pc(core->rasm, core->offset);
48  RzAsmCode *acode = rz_asm_massemble(core->rasm, assembly);
49  if (!acode) {
50  RZ_LOG_ERROR("Fail to assemble by rz_asm_massemble()\n");
52  return NULL;
53  }
54  for (int i = 0; i < acode->len; i++) {
55  ut8 b = acode->bytes[i]; // core->print->big_endian? (bytes - 1 - i): i ];
56  rz_strbuf_appendf(buf, "%02x", b);
57  }
58  rz_asm_code_free(acode);
59  return rz_strbuf_drain(buf);
60 }
lzma_index ** i
Definition: index.h:629
#define b(i)
Definition: sha256.c:42

References b, rz_asm_code_t::bytes, i, rz_asm_code_t::len, NULL, rz_core_t::offset, rz_core_t::rasm, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_pc(), RZ_LOG_ERROR, rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_free(), and rz_strbuf_new().

Referenced by rz_hex_of_assembly_handler().

◆ rz_core_print_dump()

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

Definition at line 322 of file cprint.c.

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

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

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

◆ rz_core_print_dump_str()

RZ_API char* rz_core_print_dump_str ( RZ_NONNULL RzCore core,
RzOutputMode  mode,
ut64  addr,
ut8  n,
int  len,
RzCorePrintFormatType  format 
)

Print dump at addr.

Parameters
nWord size by bytes (1,2,4,8)
lenDump bytes length
formatPrint format, such as RZ_CORE_PRINT_FORMAT_TYPE_HEXADECIMAL

Definition at line 281 of file cprint.c.

282  {
283  rz_return_val_if_fail(core, false);
284  if (!len) {
285  return NULL;
286  }
287  st8 base = format_type_to_base(format, n);
288  if (!base) {
289  return NULL;
290  }
291  len_fixup(core, &addr, &len);
292  ut8 *buffer = malloc(len);
293  if (!buffer) {
294  return NULL;
295  }
296 
297  char *string = NULL;
298  rz_io_read_at(core->io, addr, buffer, len);
299  RzPrint *print = core->print;
301  bool old_use_comments = print->use_comments;
302  print->use_comments = false;
303 
304  switch (mode) {
305  case RZ_OUTPUT_MODE_JSON:
306  string = rz_print_jsondump_str(print, buffer, len, n * 8);
307  break;
309  fix_size_from_format(format, &n);
310  string = rz_print_hexdump_str(print, addr, buffer, len, base, (int)n, 1);
311  break;
312  default:
314  break;
315  }
316 
317  print->use_comments = old_use_comments;
318  free(buffer);
319  return string;
320 }
static void len_fixup(RzCore *core, ut64 *addr, int *len)
Definition: cprint.c:255
static st8 format_type_to_base(const RzCorePrintFormatType format, const ut8 n)
Definition: cprint.c:230
static void fix_size_from_format(const RzCorePrintFormatType format, ut8 *size)
Definition: cprint.c:242
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API void rz_print_init_rowoffsets(RzPrint *p)
Definition: print.c:1519
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
RZ_API RZ_OWN char * rz_print_jsondump_str(RZ_NONNULL RzPrint *p, RZ_NONNULL const ut8 *buf, int len, int wordsize)
Print dump in json format.
Definition: print.c:1583
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
Definition: buffer.h:15
bool use_comments
Definition: rz_print.h:139

References addr, fix_size_from_format(), format_type_to_base(), free(), len, len_fixup(), malloc(), n, NULL, rz_io_read_at(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_print_hexdump_str(), rz_print_init_rowoffsets(), rz_print_jsondump_str(), rz_return_val_if_fail, rz_warn_if_reached, st8, and rz_print_t::use_comments.

Referenced by rz_core_print_dump().

◆ rz_core_print_hexdiff()

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

Definition at line 182 of file cprint.c.

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

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

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

◆ rz_core_print_hexdump()

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

Definition at line 161 of file cprint.c.

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

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

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

◆ rz_core_print_hexdump_byline()

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

Definition at line 466 of file cprint.c.

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

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

Referenced by rz_print_hexdump_hexl_common_handler().

◆ rz_core_print_hexdump_byline_str()

RZ_API RZ_OWN char* rz_core_print_hexdump_byline_str ( RZ_NONNULL RzCore core,
bool  hex_offset,
ut64  addr,
int  len,
ut8  size 
)

Hexdump at addr.

Parameters
lenDump bytes length
sizeWord size by bytes (1,2,4,8)
Returns
Hexdump string

Definition at line 406 of file cprint.c.

407  {
408  rz_return_val_if_fail(core, false);
409  if (!len) {
410  return NULL;
411  }
412  len_fixup(core, &addr, &len);
413  ut8 *buffer = malloc(len);
414  if (!buffer) {
415  return NULL;
416  }
417 
418  rz_io_read_at(core->io, addr, buffer, len);
419  const int round_len = len - (len % size);
421  for (int i = 0; i < round_len; i += size) {
422  const char *a, *b;
423  char *fn;
424  RzPrint *p = core->print;
425  RzFlagItem *f;
426  ut64 v = rz_read_ble(buffer + i, p->big_endian, size * 8);
427  if (p->colorfor) {
428  a = p->colorfor(p->user, v, true);
429  if (a && *a) {
430  b = Color_RESET;
431  } else {
432  a = b = "";
433  }
434  } else {
435  a = b = "";
436  }
437  f = rz_flag_get_at(core->flags, v, true);
438  fn = NULL;
439  if (f) {
440  st64 delta = (st64)(v - f->offset);
441  if (delta >= 0 && delta < 8192) {
442  if (v == f->offset) {
443  fn = strdup(f->name);
444  } else {
445  fn = rz_str_newf("%s+%" PFMT64d, f->name, v - f->offset);
446  }
447  }
448  }
449  char *vstr = ut64_to_hex(v, size * 2);
450  if (vstr) {
451  if (hex_offset) {
452  rz_strbuf_append(sb, rz_print_section_str(core->print, addr + i));
453  rz_strbuf_appendf(sb, "0x%08" PFMT64x " %s%s%s%s%s\n",
454  (ut64)addr + i, a, vstr, b, fn ? " " : "", fn ? fn : "");
455  } else {
456  rz_strbuf_appendf(sb, "%s%s%s\n", a, vstr, b);
457  }
458  }
459  free(vstr);
460  free(fn);
461  }
462  free(buffer);
463  return rz_strbuf_drain(sb);
464 }
static SblHeader sb
Definition: bin_mbn.c:26
static char * ut64_to_hex(const ut64 x, const ut8 width)
Definition: cprint.c:389
const char * v
Definition: dsignal.c:12
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
void * p
Definition: libc.cpp:67
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
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API char * rz_print_section_str(RzPrint *p, ut64 at)
Definition: print.c:511
#define Color_RESET
Definition: rz_cons.h:617
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
Definition: rz_endian.h:517
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64d
Definition: rz_types.h:394
#define st64
Definition: rz_types_base.h:10
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
static st64 delta
Definition: vmenus.c:2425
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References a, addr, b, Color_RESET, delta, f, fn, free(), i, len, len_fixup(), malloc(), NULL, p, PFMT64d, PFMT64x, rz_flag_get_at(), rz_io_read_at(), rz_print_section_str(), rz_read_ble(), rz_return_val_if_fail, rz_str_newf(), rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), sb, st64, strdup(), ut64(), ut64_to_hex(), and v.

Referenced by rz_core_print_hexdump_byline().

◆ rz_core_print_hexdump_diff()

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

Definition at line 219 of file cprint.c.

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

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

◆ rz_core_print_hexdump_diff_str()

RZ_API char* rz_core_print_hexdump_diff_str ( RZ_NONNULL RzCore core,
ut64  aa,
ut64  ba,
ut64  len 
)

Print hexdump diff between aa and ba with len.

Definition at line 195 of file cprint.c.

195  {
196  rz_return_val_if_fail(core && core->cons && len > 0, false);
197  ut8 *a = malloc(len);
198  if (!a) {
199  return NULL;
200  }
201  ut8 *b = malloc(len);
202  if (!b) {
203  free(a);
204  return NULL;
205  }
206 
207  RZ_LOG_VERBOSE("print hexdump diff 0x%" PFMT64x " 0x%" PFMT64x " with len:%" PFMT64d "\n", aa, ba, len);
208 
209  rz_io_read_at(core->io, aa, a, (int)len);
210  rz_io_read_at(core->io, ba, b, (int)len);
211  int col = core->cons->columns > 123;
212  char *pstr = rz_print_hexdiff_str(core->print, aa, a,
213  ba, b, (int)len, col);
214  free(a);
215  free(b);
216  return pstr;
217 }
#define RZ_LOG_VERBOSE(fmtstr,...)
Definition: rz_log.h:52

References a, b, free(), len, malloc(), NULL, PFMT64d, PFMT64x, rz_io_read_at(), RZ_LOG_VERBOSE, rz_print_hexdiff_str(), and rz_return_val_if_fail.

Referenced by rz_core_print_hexdump_diff(), and rz_core_print_hexdump_or_hexdiff_str().

◆ rz_core_print_hexdump_or_hexdiff()

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

Definition at line 378 of file cprint.c.

379  {
380  char *string = rz_core_print_hexdump_or_hexdiff_str(core, mode, addr, len, use_comment);
381  if (!string) {
382  RZ_LOG_ERROR("fail to print hexdump at 0x%" PFMT64x "\n", addr);
383  return false;
384  }
385  rz_cons_print(string);
386  return true;
387 }
RZ_API char * rz_core_print_hexdump_or_hexdiff_str(RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, int len, bool use_comment)
Print hexdump at addr, but maybe print hexdiff if (diff.from or diff.to),.
Definition: cprint.c:337

References addr, len, PFMT64x, rz_core_print_hexdump_or_hexdiff_str(), and RZ_LOG_ERROR.

◆ rz_core_print_hexdump_or_hexdiff_str()

RZ_API char* rz_core_print_hexdump_or_hexdiff_str ( RZ_NONNULL RzCore core,
RzOutputMode  mode,
ut64  addr,
int  len,
bool  use_comment 
)

Print hexdump at addr, but maybe print hexdiff if (diff.from or diff.to),.

See also
"el diff"
Parameters
lenDump bytes length

Definition at line 337 of file cprint.c.

338  {
339  rz_return_val_if_fail(core, false);
340  if (!len) {
341  return NULL;
342  }
343 
344  char *string = NULL;
345  RzPrint *print = core->print;
346  bool old_use_comments = print->use_comments;
347  print->use_comments = use_comment ? print->flags & RZ_PRINT_FLAGS_COMMENT : false;
348  switch (mode) {
350  ut64 from = rz_config_get_i(core->config, "diff.from");
351  ut64 to = rz_config_get_i(core->config, "diff.to");
352  if (from == to && !from) {
353  len_fixup(core, &addr, &len);
354  ut8 *buffer = malloc(len);
355  if (!buffer) {
356  return NULL;
357  }
358  rz_io_read_at(core->io, addr, buffer, len);
359  string = rz_print_hexdump_str(core->print, rz_core_pava(core, addr), buffer, len, 16, 1, 1);
360  free(buffer);
361  } else {
362  string = rz_core_print_hexdump_diff_str(core, addr, addr + to - from, len);
363  }
364  core->num->value = len;
365  break;
366  }
367  case RZ_OUTPUT_MODE_JSON:
368  string = rz_print_jsondump_str(core->print, core->block, len, 8);
369  break;
370  default:
372  break;
373  }
374  print->use_comments = old_use_comments;
375  return string;
376 }
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API ut64 rz_core_pava(RzCore *core, ut64 addr)
Definition: disasm.c:364
#define RZ_PRINT_FLAGS_COMMENT
Definition: rz_print.h:25
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
int flags
Definition: rz_print.h:137

References addr, rz_print_t::flags, free(), from, len, len_fixup(), malloc(), NULL, rz_config_get_i(), rz_core_pava(), rz_core_print_hexdump_diff_str(), rz_io_read_at(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, RZ_PRINT_FLAGS_COMMENT, rz_print_hexdump_str(), rz_print_jsondump_str(), rz_return_val_if_fail, rz_warn_if_reached, to, rz_print_t::use_comments, and ut64().

Referenced by rz_core_print_hexdump_or_hexdiff().

◆ rz_core_print_jsondump()

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

Definition at line 172 of file cprint.c.

172  {
173  char *string = rz_print_jsondump_str(core->print, buf, len, wordsize);
174  if (!string) {
175  RZ_LOG_ERROR("fail to print json hexdump\n");
176  return;
177  }
178  rz_cons_print(string);
179  free(string);
180 }

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

◆ rz_core_print_string_c_cpp()

RZ_API RZ_OWN char* rz_core_print_string_c_cpp ( RzCore core)

Return a C/C++ string defination with block size as the length

Parameters
coreRzCore
Returns
a string defination or NULL if the error happens

Definition at line 13 of file cprint.c.

13  {
14  ut64 value;
15  size_t size = core->blocksize;
17 
18  if (!sb) {
19  RZ_LOG_ERROR("Fail to allocate the memory\n");
20  return NULL;
21  }
22  rz_strbuf_appendf(sb, "#define STRING_SIZE %" PFMTSZd "\nconst char s[STRING_SIZE] = \"", size);
23  for (size_t pos = 0; pos < size; pos++) {
24  if (pos && !(pos % STRING_CHUNK)) {
25  // newline and padding for long string
26  rz_strbuf_appendf(sb, "\"\n \"");
27  }
28  value = rz_read_ble(core->block + pos, false, 8);
29  rz_strbuf_appendf(sb, "\\x%02" PFMT64x, value);
30  }
31  rz_strbuf_append(sb, "\";");
32  return rz_strbuf_drain(sb);
33 }
static int value
Definition: cmd_api.c:93
#define STRING_CHUNK
Definition: cprint.c:6
#define PFMTSZd
Definition: rz_types.h:398
ut8 * block
Definition: rz_core.h:305
ut32 blocksize
Definition: rz_core.h:303
int pos
Definition: main.c:11

References rz_core_t::block, rz_core_t::blocksize, NULL, PFMT64x, PFMTSZd, pos, RZ_LOG_ERROR, rz_read_ble(), rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), sb, STRING_CHUNK, ut64(), and value.

Referenced by rz_print_string_c_cpp_handler().

◆ ut64_to_hex()

static char* ut64_to_hex ( const ut64  x,
const ut8  width 
)
inlinestatic

Definition at line 389 of file cprint.c.

389  {
391  rz_strbuf_appendf(sb, "%" PFMT64x, x);
393  if (len < width) {
395  }
396  rz_strbuf_prepend(sb, "0x");
397  return rz_strbuf_drain(sb);
398 }
int x
Definition: mipsasm.c:20
RZ_API const char * rz_str_pad(const char ch, int len)
Definition: str.c:3236
RZ_API bool rz_strbuf_prepend(RzStrBuf *sb, const char *s)
Definition: strbuf.c:201
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
int width
Definition: main.c:10

References len, NULL, PFMT64x, rz_str_pad(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_length(), rz_strbuf_new(), rz_strbuf_prepend(), sb, width, and x.

Referenced by rz_core_print_hexdump_byline_str().