diff --git a/libr/core/bin.c b/libr/core/bin.c index 84ad87034d..cbbd44268b 100644 --- a/libr/core/bin.c +++ b/libr/core/bin.c @@ -600,7 +600,8 @@ static int bin_sections (RCore *r, int mode, ut64 baddr, int va, ut64 at, const int bits = section->bits; if (!arch) arch = info->arch; if (!bits) bits = info->bits; - r_io_section_set_archbits (r->io, section->offset, arch, bits); + r_io_section_set_archbits (r->io, + baddr+section->rva, arch, bits); } snprintf (str, R_FLAG_NAME_SIZE, "[%i] va=0x%08"PFMT64x" pa=0x%08"PFMT64x" sz=%" PFMT64d" vsz=%"PFMT64d" rwx=%c%c%c%c %s", @@ -650,7 +651,7 @@ static int bin_sections (RCore *r, int mode, ut64 baddr, int va, ut64 at, const if (!bits) bits = info->bits; r_cons_printf ("Sa %s %d @ 0x%08" PFMT64x"\n", arch, bits, - section->offset); + baddr+section->rva); } r_cons_printf ("f section.%s %"PFMT64d" 0x%08"PFMT64x"\n", section->name, section->size, va?baddr+section->rva:section->offset); @@ -664,14 +665,24 @@ static int bin_sections (RCore *r, int mode, ut64 baddr, int va, ut64 at, const R_BIN_SCN_WRITABLE (section->srwx)?'w':'-', R_BIN_SCN_EXECUTABLE (section->srwx)?'x':'-', section->name,va?baddr+section->rva:section->offset); - } else r_cons_printf ("idx=%02i addr=0x%08"PFMT64x" off=0x%08"PFMT64x" sz=%"PFMT64d" vsz=%"PFMT64d" " - "perm=%c%c%c%c name=%s\n", + } else { + char str[128]; + if (section->arch || section->bits) { + const char *arch = section->arch; + int bits = section->bits; + if (!arch) arch = info->arch; + if (!bits) bits = info->bits; + snprintf (str, sizeof (str), "arch=%s bits=%d ", arch, bits); + } else str[0] = 0; + r_cons_printf ("idx=%02i addr=0x%08"PFMT64x" off=0x%08"PFMT64x" sz=%"PFMT64d" vsz=%"PFMT64d" " + "perm=%c%c%c%c %sname=%s\n", i, baddr+section->rva, section->offset, section->size, section->vsize, R_BIN_SCN_SHAREABLE (section->srwx)?'s':'-', R_BIN_SCN_READABLE (section->srwx)?'r':'-', R_BIN_SCN_WRITABLE (section->srwx)?'w':'-', - R_BIN_SCN_EXECUTABLE (section->srwx)?'x':'-', - section->name); + R_BIN_SCN_EXECUTABLE (section->srwx)?'x':'-', + str, section->name); + } } i++; } diff --git a/libr/core/core.c b/libr/core/core.c index 87e71dd4fc..99d1d0f973 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -682,28 +682,6 @@ R_API int r_core_seek_align(RCore *core, ut64 align, int times) { return r_core_seek (core, seek+diff, 1); } -R_API int r_core_seek_delta(RCore *core, st64 addr) { - ut64 tmp = core->offset; - int ret; - if (addr == 0) - return R_TRUE; - if (addr>0LL) { - /* check end of file */ - if (0) addr = 0; // XXX tmp+addr>) { - else addr += tmp; - } else { - /* check < 0 */ - if (-addr > tmp) addr = 0; - else addr += tmp; - } - core->offset = addr; - ret = r_core_block_read (core, 0); - //if (ret == -1) - // memset (core->block, 0xff, core->blocksize); - // core->offset = tmp; - return ret; -} - R_API char *r_core_op_str(RCore *core, ut64 addr) { RAsmOp op; ut8 buf[64]; diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 3ac3588fc3..880211073d 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -208,6 +208,7 @@ toro: for (i=idx=ret=0; idx < len && lines < l; idx+=oplen,i++, lines++) { ut64 at = addr + idx; + r_core_seek_archbits (core, at); // slow but safe hint = r_core_hint_begin (core, hint, at); if (cbytes && idx>=l) break; diff --git a/libr/core/io.c b/libr/core/io.c index 44325f5afa..9de7574419 100644 --- a/libr/core/io.c +++ b/libr/core/io.c @@ -88,6 +88,27 @@ beach: return ret; } +R_API int r_core_seek_archbits (RCore *core, ut64 addr) { + static char *oldarch = NULL; + static int oldbits; + int bits = 0;// = core->io->section->bits; + const char *arch = r_io_section_get_archbits (core->io, core->offset, &bits); + if (arch && bits) { + oldarch = strdup (r_config_get (core->config, "asm.arch")); + oldbits = r_config_get_i (core->config, "asm.bits"); + r_config_set (core->config, "asm.arch", arch); + r_config_set_i (core->config, "asm.bits", bits); + return 1; + } + if (oldarch) { + r_config_set (core->config, "asm.arch", oldarch); + r_config_set_i (core->config, "asm.bits", oldbits); + free (oldarch); + oldarch = NULL; + } + return 0; +} + R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb) { RIOSection *newsection; ut64 old = core->offset; @@ -110,7 +131,7 @@ R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb) { //core->offset = addr; if (!core->io->va) return R_FALSE; - memset (core->block, 0xff, core->blocksize); + //memset (core->block, 0xff, core->blocksize); } else core->offset = addr; if (rb) { ret = r_core_block_read (core, 0); @@ -128,17 +149,35 @@ R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb) { } } if (core->section != newsection) {//&& core->io->section->arch) { - int bits = 0;// = core->io->section->bits; - const char *arch = r_io_section_get_archbits (core->io, core->offset, &bits); - if (arch && bits) { - r_config_set (core->config, "asm.arch", arch); - r_config_set_i (core->config, "asm.bits", bits); - } + r_core_seek_archbits (core, core->offset); core->section = core->io->section; } return (ret==-1)? R_FALSE: R_TRUE; } +R_API int r_core_seek_delta(RCore *core, st64 addr) { + ut64 tmp = core->offset; + int ret; + if (addr == 0) + return R_TRUE; + if (addr>0LL) { + /* check end of file */ + if (0) addr = 0; + else addr += tmp; + } else { + /* check < 0 */ + if (-addr > tmp) addr = 0; + else addr += tmp; + } + core->offset = addr; + ret = r_core_seek (core, addr, 1); + //ret = r_core_block_read (core, 0); + //if (ret == -1) + // memset (core->block, 0xff, core->blocksize); + // core->offset = tmp; + return ret; +} + R_API int r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size) { int ret; if (!core->io || !core->file || size<1) diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 802ab4d014..167d4a5530 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -174,6 +174,7 @@ R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb); R_API void r_core_seek_previous (RCore *core, const char *type); R_API void r_core_seek_next (RCore *core, const char *type); R_API int r_core_seek_align(RCore *core, ut64 align, int count); +R_API int r_core_seek_archbits (RCore *core, ut64 addr); R_API int r_core_block_read(RCore *core, int next); R_API int r_core_block_size(RCore *core, int bsize); R_API int r_core_read_at(RCore *core, ut64 addr, ut8 *buf, int size);