From 506a454f7d366c86b3c91e2aab7f403714f84daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20=C3=80lvarez=20i=20Capilla?= Date: Mon, 14 Feb 2022 20:13:53 +0100 Subject: [PATCH] a cagar a la via --- libr/core/casm.c | 10 +++++----- libr/core/cmd_print.c | 12 +++++++----- libr/core/disasm.c | 5 ++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libr/core/casm.c b/libr/core/casm.c index 0bdef909859c4..10423b5a88772 100644 --- a/libr/core/casm.c +++ b/libr/core/casm.c @@ -485,7 +485,6 @@ static int is_hit_inrange(RCoreAsmHit *hit, ut64 start_range, ut64 end_range){ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { RAsmOp op; // if (n > core->blocksize) n = core->blocksize; - ut64 at; ut32 idx = 0, hit_count; int numinstr, asmlen, ii; const int addrbytes = core->io->addrbytes; @@ -494,8 +493,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { if (!hits) { return NULL; } - - len = R_MIN (len - len % addrbytes, addrbytes * addr); + len = R_MIN (len - (len % addrbytes), addrbytes * addr); if (len < 1) { r_list_free (hits); return NULL; @@ -509,7 +507,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { free (buf); return NULL; } - if (!r_io_read_at (core->io, addr - len / addrbytes, buf, len)) { + if (!r_io_read_at (core->io, addr - (len / addrbytes), buf, len)) { r_list_free (hits); free (buf); return NULL; @@ -536,7 +534,9 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { break; } } - at = addr - idx / addrbytes; + + ut64 at = addr - idx / addrbytes; + r_asm_set_pc (core->rasm, at); for (hit_count = 0; hit_count < n; hit_count++) { int instrlen = r_asm_disassemble (core->rasm, &op, diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index 46ffcce3bec6e..cc2c794e104f9 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -1221,9 +1221,11 @@ static void cmd_pdj(RCore *core, const char *arg, ut8* block, int len) { } pj_a (pj); ut8 *data = malloc (core->blocksize); - memcpy (data, core->block, core->blocksize); - r_core_print_disasm_json (core, core->offset, data, core->blocksize, nblines, pj); - free (data); + if (data) { + memcpy (data, core->block, core->blocksize); + r_core_print_disasm_json (core, core->offset, data, core->blocksize, nblines, pj); + free (data); + } pj_end (pj); r_cons_println (pj_string (pj)); pj_free (pj); @@ -5947,7 +5949,7 @@ static int cmd_print(void *data, const char *input) { pd_result = false; } break; - case 'j': // pdj + case 'j': // "pdj" processed_cmd = true; if (*input == 'D') { cmd_pDj (core, input + 2); @@ -6039,7 +6041,7 @@ static int cmd_print(void *data, const char *input) { bs1 - (bs - bs % addrbytes)); } core->num->value = r_core_print_disasm (core, - off, block1, + addr - bs1, block1, R_MAX (bs, bs1), l, 0, NULL, false, formatted_json, NULL, NULL); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 8a928db494f2b..29db84199f37b 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -6271,7 +6271,6 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte eprintf ("Too many backward instructions\n"); return false; } - if (r_core_prevop_addr (core, core->offset, nb_opcodes, &addr)) { nbytes = old_offset - addr; } else if (!r_core_asm_bwdis_len (core, &nbytes, &addr, nb_opcodes)) { @@ -6291,10 +6290,10 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte count = R_MIN (nb_bytes, nbytes); if (count > 0) { r_io_read_at (core->io, addr, buf, count); - r_io_read_at (core->io, addr+count, buf+count, nb_bytes-count); + r_io_read_at (core->io, addr + count, buf + count, nb_bytes-count); } else { if (nb_bytes > 0) { - memset (buf, 0xff, nb_bytes); + memset (buf, core->io->Oxff, nb_bytes); } } } else {