Skip to content

Commit d7a63bb

Browse files
committed
fix neg reads
1 parent 16ecc26 commit d7a63bb

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

libr/core/casm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
507507
free (buf);
508508
return NULL;
509509
}
510-
if (!r_io_read_at (core->io, addr - (len / addrbytes), buf, len)) {
510+
if (!r_io_read_at (core->io, addr - len / addrbytes, buf, len)) {
511511
r_list_free (hits);
512512
free (buf);
513513
return NULL;

libr/core/cmd_print.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5491,22 +5491,21 @@ static int cmd_print(void *data, const char *input) {
54915491
r_print_init_rowoffsets (core->print);
54925492
tmpseek = core->offset;
54935493
l = len = core->blocksize;
5494+
bool must_read = false;
54945495
if (input[0] && input[1]) {
54955496
int idx = (input[0] == 'h')? 2: 1;
54965497
const char *p = strchr (input + idx, ' ');
54975498
if (!p) {
54985499
p = strchr (input, '-');
5499-
if (p) {
5500-
p--;
5501-
}
55025500
}
55035501
if (p) {
5504-
l = (int) r_num_math (core->num, p + 1);
5502+
l = (int) r_num_math (core->num, p);
55055503
/* except disasm and memoryfmt (pd, pm) and overlay (po) */
55065504
if (input[0] != 'd' && input[0] != 't' && input[0] != 'D' && input[0] != 'm' &&
55075505
input[0] != 'a' && input[0] != 'f' && input[0] != 'i' &&
55085506
input[0] != 'I' && input[0] != 'o') {
55095507
if (l < 0) {
5508+
must_read = true;
55105509
off = core->offset + l;
55115510
len = l = -l;
55125511
} else {
@@ -5518,34 +5517,37 @@ static int cmd_print(void *data, const char *input) {
55185517
}
55195518
}
55205519
} else {
5521-
len = l;
55225520
if (l < 0) {
5521+
must_read = true;
55235522
off = core->offset + l;
5523+
len = -len;
5524+
} else {
5525+
len = l;
55245526
}
55255527
}
55265528
}
55275529
}
55285530
int olen = len;
55295531
at = off;
5530-
if (len < 0) {
5531-
len = -len;
5532-
}
55335532
const int padding = core->blocksize + 256;
55345533
block = malloc (len + padding);
55355534
// if (!block) die
55365535
if (block) {
5537-
if (len > core->blocksize) {
5536+
if (!must_read && len > core->blocksize) {
55385537
memset (block, core->io->Oxff, len + padding);
55395538
r_io_read_at (core->io, off, block, len);
55405539
} else {
55415540
block = calloc (1, len + padding);
55425541
if (block) {
5542+
ut64 oo = core->offset;
5543+
core->offset = at;
55435544
r_core_block_read (core);
55445545
memset (block, core->io->Oxff, len + padding);
55455546
r_io_read_at (core->io, off, block, len);
55465547
if (off == core->offset) {
55475548
memcpy (block, core->block, R_MIN (core->blocksize, len));
55485549
}
5550+
core->offset = oo;
55495551
}
55505552
}
55515553
} else {

0 commit comments

Comments
 (0)