Rizin
unix-like reverse engineering framework and cli tools
cmd_cmp.c File Reference
#include <rz_cmp.h>
#include "../core_private.h"

Go to the source code of this file.

Functions

static int rizin_compare_words (RzCore *core, ut64 of, ut64 od, int len, int ws)
 
static bool rizin_compare_unified (RzCore *core, RzCompareData *cmp)
 
static bool core_cmp_bits (RzCore *core, RzCompareData *cmp)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_string_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_bits_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_addr_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_bytes_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_hex_block_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_hex_diff_lines_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_disasm_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_file_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified1_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified2_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified4_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified8_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_unified_disasm_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_add_memory_watcher_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_list_compare_watchers_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_reset_watcher_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_update_watcher_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_remove_watcher_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_hexpair_string_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_cmp_hex_block_hexdiff_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 

Function Documentation

◆ core_cmp_bits()

static bool core_cmp_bits ( RzCore core,
RzCompareData cmp 
)
static

Definition at line 72 of file cmd_cmp.c.

72  {
73  const bool scr_color = rz_config_get_i(core->config, "scr.color");
74  int i;
76  const char *color = scr_color ? pal->offset : "";
77  const char *color_end = scr_color ? Color_RESET : "";
78  if (rz_config_get_i(core->config, "hex.header")) {
79  char *n = rz_str_newf("0x%08" PFMT64x, cmp->addr1);
80  const char *extra = rz_str_pad(' ', strlen(n) - 10);
81  free(n);
82  rz_cons_printf("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, extra, color_end);
83  }
84  color = scr_color ? pal->graph_false : "";
85  color_end = scr_color ? Color_RESET : "";
86 
87  rz_cons_printf("%s0x%08" PFMT64x "%s ", color, cmp->addr1, color_end);
88  for (i = 7; i >= 0; i--) {
89  bool b0 = (cmp->data1[0] & 1 << i) ? 1 : 0;
90  bool b1 = (cmp->data2[0] & 1 << i) ? 1 : 0;
91  color = scr_color ? (b0 == b1) ? "" : b0 ? pal->graph_true
92  : pal->graph_false
93  : "";
94  color_end = scr_color ? Color_RESET : "";
95  rz_cons_printf("%s%d%s ", color, b0, color_end);
96  }
97  color = scr_color ? pal->graph_true : "";
98  color_end = scr_color ? Color_RESET : "";
99  rz_cons_printf("\n%s0x%08" PFMT64x "%s ", color, cmp->addr2, color_end);
100  for (i = 7; i >= 0; i--) {
101  bool b0 = (cmp->data1[0] & 1 << i) ? 1 : 0;
102  bool b1 = (cmp->data2[0] & 1 << i) ? 1 : 0;
103  color = scr_color ? (b0 == b1) ? "" : b1 ? pal->graph_true
104  : pal->graph_false
105  : "";
106  color_end = scr_color ? Color_RESET : "";
107  rz_cons_printf("%s%d%s ", color, b1, color_end);
108  }
109  rz_cons_newline();
110 
111  return true;
112 }
lzma_index ** i
Definition: index.h:629
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int n
Definition: mipsasm.c:19
#define Color_RESET
Definition: rz_cons.h:617
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_pad(const char ch, int len)
Definition: str.c:3236
#define PFMT64x
Definition: rz_types.h:393
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
RzConfig * config
Definition: rz_core.h:300
static int color
Definition: visual.c:20

References b1, cmp(), color, Color_RESET, rz_core_t::config, rz_cons_t::context, free(), rz_cons_printable_palette_t::graph_false, rz_cons_printable_palette_t::graph_true, i, n, rz_cons_printable_palette_t::offset, rz_cons_context_t::pal, PFMT64x, rz_config_get_i(), rz_cons_newline(), rz_cons_printf(), rz_cons_singleton(), rz_str_newf(), and rz_str_pad().

Referenced by rz_cmd_cmp_bits_handler().

◆ rizin_compare_unified()

static bool rizin_compare_unified ( RzCore core,
RzCompareData cmp 
)
static

Definition at line 48 of file cmd_cmp.c.

48  {
49  int i, min = 1, inc = 16;
50  int headers = B_IS_SET(core->print->flags, RZ_PRINT_FLAGS_HEADER);
51  if (headers) {
53  }
54  for (i = 0; i < cmp->len; i += inc) {
55  min = RZ_MIN(16, (cmp->len - i));
56  if (!memcmp(cmp->data1 + i, cmp->data2 + i, min)) {
57  rz_cons_printf(" ");
58  rz_core_print_hexdiff(core, cmp->addr1 + i, cmp->data1 + i, cmp->addr1 + i, cmp->data1 + i, min, 0);
59  } else {
60  rz_cons_printf("- ");
61  rz_core_print_hexdiff(core, cmp->addr1 + i, cmp->data1 + i, cmp->addr2 + i, cmp->data2 + i, min, 0);
62  rz_cons_printf("+ ");
63  rz_core_print_hexdiff(core, cmp->addr2 + i, cmp->data2 + i, cmp->addr1 + i, cmp->data1 + i, min, 0);
64  }
65  }
66  if (headers) {
68  }
69  return true;
70 }
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: cprint.c:182
#define min(a, b)
Definition: qsort.h:83
#define RZ_PRINT_FLAGS_HEADER
Definition: rz_print.h:18
#define RZ_MIN(x, y)
#define B_SET(x, n)
#define B_IS_SET(x, n)
#define B_UNSET(x, n)
RzPrint * print
Definition: rz_core.h:327
int flags
Definition: rz_print.h:137

References B_IS_SET, B_SET, B_UNSET, cmp(), rz_print_t::flags, i, min, rz_core_t::print, rz_cons_printf(), rz_core_print_hexdiff(), RZ_MIN, and RZ_PRINT_FLAGS_HEADER.

Referenced by rz_cmd_cmp_unified_handler().

◆ rizin_compare_words()

static int rizin_compare_words ( RzCore core,
ut64  of,
ut64  od,
int  len,
int  ws 
)
static

Definition at line 7 of file cmd_cmp.c.

7  {
8  int i;
9  bool useColor = rz_config_get_i(core->config, "scr.color") != 0;
10  utAny v0, v1;
12  for (i = 0; i < len; i += ws) {
13  memset(&v0, 0, sizeof(v0));
14  memset(&v1, 0, sizeof(v1));
15  rz_io_nread_at(core->io, of + i, (ut8 *)&v0, ws);
16  rz_io_nread_at(core->io, od + i, (ut8 *)&v1, ws);
17  char ch = (v0.v64 == v1.v64) ? '=' : '!';
18  const char *color = useColor ? ch == '=' ? "" : pal->graph_false : "";
19  const char *colorEnd = useColor ? Color_RESET : "";
20 
21  if (useColor) {
22  rz_cons_printf("%s0x%08" PFMT64x " " Color_RESET, pal->offset, of + i);
23  } else {
24  rz_cons_printf("0x%08" PFMT64x " ", of + i);
25  }
26  switch (ws) {
27  case 1:
28  rz_cons_printf("%s0x%02x %c 0x%02x%s\n", color,
29  (ut32)(v0.v8 & 0xff), ch, (ut32)(v1.v8 & 0xff), colorEnd);
30  break;
31  case 2:
32  rz_cons_printf("%s0x%04hx %c 0x%04hx%s\n", color,
33  v0.v16, ch, v1.v16, colorEnd);
34  break;
35  case 4:
36  rz_cons_printf("%s0x%08" PFMT32x " %c 0x%08" PFMT32x "%s\n", color,
37  v0.v32, ch, v1.v32, colorEnd);
38  break;
39  case 8:
40  rz_cons_printf("%s0x%016" PFMT64x " %c 0x%016" PFMT64x "%s\n",
41  color, v0.v64, ch, v1.v64, colorEnd);
42  break;
43  }
44  }
45  return 0;
46 }
size_t len
Definition: 6502dis.c:15
#define PFMT32x
uint32_t ut32
@ v0
Definition: lanai.h:84
@ v1
Definition: lanai.h:85
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:338
RzIO * io
Definition: rz_core.h:313

References color, Color_RESET, rz_core_t::config, rz_cons_t::context, rz_cons_printable_palette_t::graph_false, i, rz_core_t::io, len, memset(), rz_cons_printable_palette_t::offset, rz_cons_context_t::pal, PFMT32x, PFMT64x, rz_config_get_i(), rz_cons_printf(), rz_cons_singleton(), rz_io_nread_at(), v0, and v1.

Referenced by rz_cmd_cmp_unified1_handler(), rz_cmd_cmp_unified2_handler(), rz_cmd_cmp_unified4_handler(), and rz_cmd_cmp_unified8_handler().

◆ rz_cmd_cmp_add_memory_watcher_handler()

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

Definition at line 289 of file cmd_cmp.c.

289  {
290  return rz_core_cmpwatch_add(core, core->offset, atoi(argv[1]), argv[2]) ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
291 }
RZ_API bool rz_core_cmpwatch_add(RzCore *core, ut64 addr, int size, const char *cmd)
Add a memory watcher at address addr od size size and command cmd.
Definition: cmp.c:337
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
@ 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
ut64 offset
Definition: rz_core.h:301

References argv, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_cmpwatch_add().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_addr_handler()

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

Definition at line 144 of file cmd_cmp.c.

144  {
145  RzCompareData *cmp = rz_core_cmp_mem_mem(core, core->offset, rz_num_math(core->num, argv[1]), rz_num_math(core->num, argv[2]));
146  if (!cmp) {
147  return RZ_CMD_STATUS_ERROR;
148  }
149  int val = rz_core_cmp_print(core, cmp, state);
151  return val != -1 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
152 }
ut16 val
Definition: armass64_const.h:6
RZ_API void rz_core_cmp_free(RzCompareData *cmp)
Free RzCompareData object.
Definition: cmp.c:226
RZ_API RZ_OWN RzCompareData * rz_core_cmp_mem_mem(RzCore *core, ut64 addr1, ut64 addr2, ut32 len)
Compare memory at addr1 with the memory at addr2.
Definition: cmp.c:17
RZ_API int rz_core_cmp_print(RzCore *core, RZ_NONNULL const RzCompareData *cmp, RzCmdStateOutput *state)
Print a comparison cmp according to the print mode mode.
Definition: cmp.c:93
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RzNum * num
Definition: rz_core.h:316
Definition: dis.h:43

References argv, cmp(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_mem(), rz_core_cmp_print(), rz_num_math(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_bits_handler()

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

Definition at line 133 of file cmd_cmp.c.

133  {
134  RzCompareData *cmp = rz_core_cmp_mem_mem(core, core->offset, rz_num_math(core->num, argv[1]), 1);
135  if (!cmp) {
136  return RZ_CMD_STATUS_ERROR;
137  }
138  bool val = core_cmp_bits(core, cmp);
141 }
static bool core_cmp_bits(RzCore *core, RzCompareData *cmp)
Definition: cmd_cmp.c:72

References argv, cmp(), core_cmp_bits(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_mem(), rz_num_math(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_bytes_handler()

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

Definition at line 155 of file cmd_cmp.c.

155  {
157  ut64 sz = rz_num_math(core->num, argv[2]);
158  if (sz > 8) {
159  RZ_LOG_ERROR("Cannot compare more than 8 bytes. Use the c command instead.\n");
160  return ret;
161  }
162 
163  ut64 num = rz_num_math(core->num, argv[1]);
164  ut64 mask = -1;
165  mask >>= 8 - sz;
166  ut64 valid_num = num & mask;
167  RzCompareData *cmp = rz_core_cmp_mem_data(core, core->offset, (ut8 *)&valid_num, sz);
168  if (!cmp) {
169  goto end;
170  }
171  int val = rz_core_cmp_print(core, cmp, state);
172  ret = val != -1 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
173 
174 end:
176  return ret;
177 }
#define mask()
RZ_API RZ_OWN RzCompareData * rz_core_cmp_mem_data(RzCore *core, ut64 addr, RZ_NONNULL const ut8 *data, ut32 len)
Compare mem at addr with data data.
Definition: cmp.c:56
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 static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
enum rz_cmd_status_t RzCmdStatus
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References argv, cmp(), test_evm::end, mask, rz_core_t::num, num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_data(), rz_core_cmp_print(), RZ_LOG_ERROR, rz_num_math(), ut64(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_disasm_handler()

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

Definition at line 211 of file cmd_cmp.c.

211  {
212  RzList *cmp = rz_core_cmp_disasm(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize);
213  bool ret = rz_core_cmp_disasm_print(core, cmp, false);
214  rz_list_free(cmp);
215  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
216 }
RZ_API bool rz_core_cmp_disasm_print(RzCore *core, const RzList *compare, bool unified)
Print the instruction comparison data compare.
Definition: cmp.c:243
RZ_API RZ_OWN RzList * rz_core_cmp_disasm(RzCore *core, ut64 addr1, ut64 addr2, ut32 len)
Compare the instructions at addr1 and addr2.
Definition: cmp.c:161
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
ut32 blocksize
Definition: rz_core.h:303

References argv, rz_core_t::blocksize, cmp(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_disasm(), rz_core_cmp_disasm_print(), rz_list_free(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_file_handler()

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

Definition at line 219 of file cmd_cmp.c.

219  {
220  FILE *fd = rz_sys_fopen(argv[1], "rb");
221  if (!fd) {
222  RZ_LOG_ERROR("Cannot open file: %s\n", argv[1]);
223  return RZ_CMD_STATUS_ERROR;
224  }
226  ut8 *buf = (ut8 *)malloc(core->blocksize);
227  if (!buf) {
228  goto return_goto;
229  }
230  if (fread(buf, 1, core->blocksize, fd) < 1) {
231  RZ_LOG_ERROR("Cannot read file: %s\n", argv[1]);
232  goto return_goto;
233  }
234  RzCompareData *cmp = rz_core_cmp_mem_data(core, core->offset, buf, core->blocksize);
235  if (!cmp) {
236  goto return_goto;
237  }
238  int val = rz_core_cmp_print(core, cmp, state);
241 
242 return_goto:
243  free(buf);
244  fclose(fd);
245  return stat;
246 }
voidpf void * buf
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
static stat
Definition: sflib.h:131
string FILE
Definition: benchmark.py:21
RZ_API FILE * rz_sys_fopen(const char *path, const char *mode)
Definition: sys.c:1815
Definition: sftypes.h:80
static const z80_opcode fd[]
Definition: z80_tab.h:997

References argv, rz_core_t::blocksize, cmp(), fd, benchmark::FILE, free(), malloc(), rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_data(), rz_core_cmp_print(), RZ_LOG_ERROR, rz_sys_fopen(), stat, and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_hex_block_handler()

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

Definition at line 180 of file cmd_cmp.c.

180  {
181  ut64 addr = rz_num_math(core->num, argv[1]);
182  bool col = core->cons->columns > 123;
183  ut8 *b = malloc(core->blocksize);
184  if (b) {
185  memset(b, 0xff, core->blocksize);
186  rz_io_nread_at(core->io, addr, b, core->blocksize);
187  rz_core_print_hexdiff(core, core->offset, core->block, addr, b, core->blocksize, col);
188  }
189  free(b);
190  return RZ_CMD_STATUS_OK;
191 }
#define b(i)
Definition: sha256.c:42
int columns
Definition: rz_cons.h:510
RzCons * cons
Definition: rz_core.h:312
ut8 * block
Definition: rz_core.h:305
static int addr
Definition: z80asm.c:58

References addr, argv, b, rz_core_t::block, rz_core_t::blocksize, rz_cons_t::columns, rz_core_t::cons, free(), rz_core_t::io, malloc(), memset(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_core_print_hexdiff(), rz_io_nread_at(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_hex_block_hexdiff_handler()

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

Definition at line 351 of file cmd_cmp.c.

351  {
352  unsigned char *buf = malloc(core->blocksize);
353  bool ret = false;
354  if (!buf) {
355  goto return_goto;
356  }
357  if (rz_io_nread_at(core->io, rz_num_math(core->num, argv[1]), buf, core->blocksize) == -1) {
358  RZ_LOG_ERROR("Cannot read hexdump at %s\n", argv[1]);
359  goto return_goto;
360  }
361 
362  RzCompareData *cmp = rz_core_cmp_mem_data(core, core->offset, buf, core->blocksize);
363  if (!cmp) {
364  free(cmp);
365  goto return_goto;
366  }
367  int val = rz_core_cmp_print(core, cmp, state);
369  ret = val != -1;
370 
371 return_goto:
372  free(buf);
373  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
374 }

References argv, rz_core_t::blocksize, cmp(), free(), rz_core_t::io, malloc(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_data(), rz_core_cmp_print(), rz_io_nread_at(), RZ_LOG_ERROR, rz_num_math(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_hex_diff_lines_handler()

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

Definition at line 194 of file cmd_cmp.c.

194  {
195  ut32 oflags = core->print->flags;
197  ut64 addr = rz_num_math(core->num, argv[1]);
198  bool col = core->cons->columns > 123;
199  ut8 *b = malloc(core->blocksize);
200  if (b) {
201  memset(b, 0xff, core->blocksize);
202  rz_io_nread_at(core->io, addr, b, core->blocksize);
203  rz_core_print_hexdiff(core, core->offset, core->block, addr, b, core->blocksize, col);
204  }
205  free(b);
206  core->print->flags = oflags;
207  return RZ_CMD_STATUS_OK;
208 }
#define RZ_PRINT_FLAGS_DIFFOUT
Definition: rz_print.h:23

References addr, argv, b, rz_core_t::block, rz_core_t::blocksize, rz_cons_t::columns, rz_core_t::cons, rz_print_t::flags, free(), rz_core_t::io, malloc(), memset(), rz_core_t::num, rz_core_t::offset, rz_core_t::print, RZ_CMD_STATUS_OK, rz_core_print_hexdiff(), rz_io_nread_at(), rz_num_math(), RZ_PRINT_FLAGS_DIFFOUT, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_hexpair_string_handler()

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

Definition at line 315 of file cmd_cmp.c.

315  {
316  char *input = strdup(argv[1]);
318  unsigned char *buf;
319  int ret = false;
320  if (!(buf = (ut8 *)malloc(strlen(input) + 1))) {
321  goto return_goto;
322  }
323  ret = rz_hex_bin2str(core->block, strlen(input) / 2, (char *)buf);
324  for (int i = 0; i < ret * 2; i++) {
325  if (input[i] == '.') {
326  input[i] = buf[i];
327  }
328  }
329  ret = rz_hex_str2bin(input, buf);
330  if (ret < 1) {
331  RZ_LOG_ERROR("Cannot parse hexpair\n");
332  ret = false;
333  goto return_goto;
334  }
335  RzCompareData *cmp = rz_core_cmp_mem_data(core, core->offset, buf, strlen(input) / 2);
336  if (!cmp) {
337  goto return_goto;
338  }
339  core->num->value = cmp->same ? 0 : 1;
340  int val = rz_core_cmp_print(core, cmp, state);
342  ret = val != -1;
343 
344 return_goto:
345  free(input);
346  free(buf);
347  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
348 }
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 int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
RZ_API void rz_str_remove_char(char *str, char c)
Definition: str.c:173
ut64 value
Definition: rz_num.h:63
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References argv, rz_core_t::block, cmp(), free(), i, input(), malloc(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_data(), rz_core_cmp_print(), rz_hex_bin2str(), rz_hex_str2bin(), RZ_LOG_ERROR, rz_str_remove_char(), strdup(), val, and rz_num_t::value.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_list_compare_watchers_handler()

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

Definition at line 294 of file cmd_cmp.c.

294  {
296  return RZ_CMD_STATUS_OK;
297 }
RZ_API void rz_core_cmpwatch_show(RzCore *core, ut64 addr, RzOutputMode mode)
Show/print the memory watcher present at address addr.
Definition: cmp.c:397
const char int mode
Definition: ioapi.h:137
#define UT64_MAX
Definition: rz_types_base.h:86

References RZ_CMD_STATUS_OK, rz_core_cmpwatch_show(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_remove_watcher_handler()

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

Definition at line 310 of file cmd_cmp.c.

310  {
312 }
RZ_API bool rz_core_cmpwatch_del(RzCore *core, ut64 addr)
Delete a memory watcher at address addr.
Definition: cmp.c:375

References rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_cmpwatch_del().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_reset_watcher_handler()

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

Definition at line 300 of file cmd_cmp.c.

300  {
302 }
RZ_API bool rz_core_cmpwatch_revert(RzCore *core, ut64 addr)
Revert/reset a memory watcher at address addr.
Definition: cmp.c:458

References rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_cmpwatch_revert().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_string_handler()

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

Definition at line 115 of file cmd_cmp.c.

115  {
117  char *unescaped = strdup(argv[1]);
118  int len = rz_str_unescape(unescaped);
119  RzCompareData *cmp = rz_core_cmp_mem_data(core, core->offset, (ut8 *)unescaped, len);
120  if (!cmp) {
121  goto end;
122  }
123  int val = rz_core_cmp_print(core, cmp, state);
124  ret = val != -1 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
125 
126 end:
128  free(unescaped);
129  return ret;
130 }
RZ_API int rz_str_unescape(char *buf)
Definition: str.c:1300

References argv, cmp(), test_evm::end, free(), len, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_data(), rz_core_cmp_print(), rz_str_unescape(), strdup(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_unified1_handler()

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

Definition at line 257 of file cmd_cmp.c.

257  {
258  rizin_compare_words(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize, 1);
259  return RZ_CMD_STATUS_OK;
260 }
static int rizin_compare_words(RzCore *core, ut64 of, ut64 od, int len, int ws)
Definition: cmd_cmp.c:7

References argv, rz_core_t::blocksize, rz_core_t::num, rz_core_t::offset, rizin_compare_words(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_unified2_handler()

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

Definition at line 263 of file cmd_cmp.c.

263  {
264  rizin_compare_words(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize, 2);
265  return RZ_CMD_STATUS_OK;
266 }

References argv, rz_core_t::blocksize, rz_core_t::num, rz_core_t::offset, rizin_compare_words(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_unified4_handler()

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

Definition at line 269 of file cmd_cmp.c.

269  {
270  rizin_compare_words(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize, 4);
271  return RZ_CMD_STATUS_OK;
272 }

References argv, rz_core_t::blocksize, rz_core_t::num, rz_core_t::offset, rizin_compare_words(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_unified8_handler()

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

Definition at line 275 of file cmd_cmp.c.

275  {
276  rizin_compare_words(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize, 8);
277  return RZ_CMD_STATUS_OK;
278 }

References argv, rz_core_t::blocksize, rz_core_t::num, rz_core_t::offset, rizin_compare_words(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_unified_disasm_handler()

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

◆ rz_cmd_cmp_unified_handler()

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

Definition at line 249 of file cmd_cmp.c.

249  {
250  RzCompareData *cmp = rz_core_cmp_mem_mem(core, core->offset, rz_num_math(core->num, argv[1]), core->blocksize);
251  bool ret = rizin_compare_unified(core, cmp);
253  return ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
254 }
static bool rizin_compare_unified(RzCore *core, RzCompareData *cmp)
Definition: cmd_cmp.c:48

References argv, rz_core_t::blocksize, cmp(), rz_core_t::num, rz_core_t::offset, rizin_compare_unified(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmp_free(), rz_core_cmp_mem_mem(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_cmp_update_watcher_handler()

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

Definition at line 305 of file cmd_cmp.c.

305  {
307 }
RZ_API bool rz_core_cmpwatch_update(RzCore *core, ut64 addr)
Update the memory watcher at address addr.
Definition: cmp.c:430

References rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_cmpwatch_update().

Referenced by rzshell_cmddescs_init().