diff --git a/libr/core/casm.c b/libr/core/casm.c index 7b3044973cd37..4b2178478c347 100644 --- a/libr/core/casm.c +++ b/libr/core/casm.c @@ -487,7 +487,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) { // if (n > core->blocksize) n = core->blocksize; - ut64 at; ut32 idx = 0, hit_count; int numinstr, asmlen, ii; const int addrbytes = core->io->addrbytes; @@ -496,8 +495,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; @@ -511,7 +509,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; @@ -538,7 +536,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++) { RAnalOp op; diff --git a/libr/core/cmd_print.inc.c b/libr/core/cmd_print.inc.c index 927349ca3b7d9..f13fcc09a88fe 100644 --- a/libr/core/cmd_print.inc.c +++ b/libr/core/cmd_print.inc.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2023 - pancake */ +/* radare - LGPL - Copyright 2009-2024 - pancake */ #if R_INCLUDE_BEGIN @@ -5357,6 +5357,7 @@ static ut8 *decode_text(RCore *core, ut64 offset, size_t len, bool zeroend) { } static bool cmd_pi(RCore *core, const char *input, int len, int l, ut8 *block) { + // len is block_len char ch = input[1]; if (ch == '+' || ch == '-' || IS_DIGIT (ch)) { ch = ' '; @@ -6282,12 +6283,9 @@ static int cmd_print(void *data, const char *input) { return 0; } - const char *sp = NULL; - if (input[1] == '.' || input[1] == '+') { - sp = input + 2; - } else { - sp = strchr (input + 1, ' '); - } + const char *sp = (input[1] == '.' || input[1] == '+') + ? input + 2: strchr (input + 1, ' '); + if (IS_DIGIT (input[1])) { sp = input + 1; } else if (!sp && input[1] == '-') { @@ -6314,12 +6312,15 @@ static int cmd_print(void *data, const char *input) { l = use_blocksize; } // may be unnecessary, fixes 'pd 1;pdj 100;pd 1' bug +#if 0 + core->offset = at; // "pd" doesnt know about the current offset for pd -X +#endif r_core_block_read (core); switch (input[1]) { case 'C': // "pdC" r_core_disasm_pdi (core, l, 0, 'C'); - pd_result = 0; + pd_result = false; processed_cmd = true; break; case 'v': // "pdv" // east decompiler @@ -6340,7 +6341,7 @@ static int cmd_print(void *data, const char *input) { break; case 'c': // "pdc" // "pDc" r_core_pseudo_code (core, input + 2); - pd_result = 0; + pd_result = false; processed_cmd = true; break; case ',': // "pd," @@ -6489,7 +6490,7 @@ static int cmd_print(void *data, const char *input) { r_core_return_value (core, dislen); } free (block); - pd_result = 0; + pd_result = false; } } else { R_LOG_ERROR ("Cannot find function at 0x%08"PFMT64x, core->offset); @@ -6566,7 +6567,7 @@ static int cmd_print(void *data, const char *input) { pj_end (pj); r_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); - pd_result = 0; + pd_result = false; r_config_set (core->config, "asm.bbmiddle", orig_bb_middle); } else if (f) { ut64 linearsz = r_anal_function_linear_size (f); @@ -6585,7 +6586,7 @@ static int cmd_print(void *data, const char *input) { // r_core_cmdf (core, "pD %d @ 0x%08" PFMT64x, f->_size > 0 ? f->_size: r_anal_function_realsize (f), f->addr); } } - pd_result = 0; + pd_result = false; } else { R_LOG_ERROR ("pdf: Cannot find function at 0x%08"PFMT64x, core->offset); processed_cmd = true; @@ -6627,17 +6628,17 @@ static int cmd_print(void *data, const char *input) { } } r_cons_break_pop (); - pd_result = 0; + pd_result = false; } break; - case 'j': // pdj + case 'j': // "pdj" processed_cmd = true; if (*input == 'D') { cmd_pDj (core, input + 2); } else { cmd_pdj (core, input + 2, block); } - pd_result = 0; + pd_result = false; break; case 'J': // pdJ formatted_json = true; @@ -6651,7 +6652,7 @@ static int cmd_print(void *data, const char *input) { case '?': // "pd?" processed_cmd = true; r_core_cmd_help (core, help_msg_pd); - pd_result = 0; + pd_result = false; case '.': case '-': case '+': @@ -8369,7 +8370,7 @@ static int cmd_print(void *data, const char *input) { if (myblock) { free (block); } - if (tmpseek != UT64_MAX) { + if (tmpseek != UT64_MAX && tmpseek != core->offset) { r_core_seek (core, tmpseek, SEEK_SET); r_core_block_read (core); } diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 753342658d582..302c2cfd41abd 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -6917,7 +6917,6 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte R_LOG_ERROR ("Too many backward instructions"); 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)) { @@ -6940,7 +6939,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte 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 { diff --git a/libr/util/print.c b/libr/util/print.c index e576e62b41dc8..ee914f0046294 100644 --- a/libr/util/print.c +++ b/libr/util/print.c @@ -793,8 +793,6 @@ R_API void r_print_hexii(RPrint *rp, ut64 addr, const ut8 *buf, int len, int ste /* set screen_bounds to addr if the cursor is not visible on the screen anymore. * Note: screen_bounds is set only the first time this happens. */ R_API void r_print_set_screenbounds(RPrint *p, ut64 addr) { - int r, rc; - r_return_if_fail (p); if (!p->screen_bounds) { @@ -808,6 +806,7 @@ R_API void r_print_set_screenbounds(RPrint *p, ut64 addr) { } if (p->screen_bounds == 1) { + int r, rc; (void)p->consbind.get_size (&r); (void)p->consbind.get_cursor (&rc);