From 100df3bb32eb3d355d8039112a20a7bb82933493 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 21 Feb 2016 01:56:50 +0100 Subject: [PATCH] Better MIPS32BE ELF relocs, add Rx regs in mips.cs and add scr.wheelnkey, nN defaults to flag now --- libr/anal/p/anal_mips_cs.c | 2 ++ libr/bin/format/elf/elf.c | 11 ++++++- libr/core/config.c | 3 +- libr/core/visual.c | 66 +++++++++++++++++++++----------------- libr/include/r_util.h | 3 +- libr/util/mem.c | 16 +++++++++ 6 files changed, 69 insertions(+), 32 deletions(-) diff --git a/libr/anal/p/anal_mips_cs.c b/libr/anal/p/anal_mips_cs.c index 3620e6ad6d..24658971a9 100644 --- a/libr/anal/p/anal_mips_cs.c +++ b/libr/anal/p/anal_mips_cs.c @@ -852,6 +852,8 @@ static int set_reg_profile(RAnal *anal) { "=A1 a1\n" "=A2 a2\n" "=A3 a3\n" + "=R0 v0\n" + "=R1 v1\n" "gpr zero .32 0 0\n" "gpr at .32 4 0\n" "gpr v0 .32 8 0\n" diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index fa28f8367c..585f297947 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -536,8 +536,17 @@ static ut64 get_import_addr(struct Elf_(r_bin_elf_obj_t) *bin, int sym) { { RBinElfSection *s = get_section_by_name(bin, ".rela.plt"); if (s) { + ut8 buf[1024]; + const ut8 *base; plt_addr = s->rva + s->size; - plt_addr += 108; + len = r_buf_read_at (bin->b, s->offset + s->size, buf, sizeof (buf)); + len = sizeof (buf); // + base = r_mem_mem_aligned (buf, sizeof (buf), (const ut8*)"\x3c\x0f\x00", 3, 4); + if (base) { + plt_addr += (int)(size_t)(base - buf); + } else { + plt_addr += 108 + 8; // HARDCODED HACK + } plt_addr += k * 16; free (REL); return plt_addr; diff --git a/libr/core/config.c b/libr/core/config.c index 3417784982..e7f19a3b8e 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -1735,6 +1735,7 @@ R_API int r_core_config_init(RCore *core) { #else SETPREF("scr.responsive", "false", "Auto-adjust Visual depending on screen (e.g. unset asm.bytes)"); #endif + SETPREF("scr.wheelnkey", "false", "Use sn/sp and scr.nkey on wheel instead of scroll"); SETPREF("scr.wheel", "true", "Mouse wheel in Visual; temporaryly disable/reenable by right click/Enter)"); SETPREF("scr.atport", "false", "V@ starts a background http server and spawns an r2 -C"); SETI("scr.wheelspeed", 4, "Mouse wheel speed"); @@ -1749,7 +1750,7 @@ R_API int r_core_config_init(RCore *core) { SETCB("scr.interactive", "true", &cb_scrint, "Start in interactive mode"); SETI("scr.feedback", 1, "Set visual feedback level (1=arrow on jump, 2=every key (useful for videos))"); SETCB("scr.html", "false", &cb_scrhtml, "Disassembly uses HTML syntax"); - SETCB("scr.nkey", "fun", &cb_scrnkey, "Select the seek mode in visual"); + SETCB("scr.nkey", "flag", &cb_scrnkey, "Select the seek mode in visual"); SETCB("scr.pager", "", &cb_pager, "Select pager program (when output overflows the window)"); SETPREF("scr.pipecolor", "false", "Enable colors when using pipes"); SETPREF("scr.promptfile", "false", "Show user prompt file (used by r2 -q)"); diff --git a/libr/core/visual.c b/libr/core/visual.c index 43e13fa9b2..82ffda3b40 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -1357,25 +1357,29 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { if (core->print->cur_enabled) { cursor_nextrow (core, false); } else { - int times = wheelspeed; - if (times<1) times = 1; - while (times--) { - if (isDisasmPrint(core->printidx)) { - RAnalFunction *f = NULL; - if (true) { - f = r_anal_get_fcn_in (core->anal, core->offset, 0); + if (r_config_get_i (core->config, "scr.wheelnkey")) { + r_core_cmd0 (core, "sn"); + } else { + int times = wheelspeed; + if (times<1) times = 1; + while (times--) { + if (isDisasmPrint(core->printidx)) { + RAnalFunction *f = NULL; + if (true) { + f = r_anal_get_fcn_in (core->anal, core->offset, 0); + } + if (f && f->folded) { + cols = core->offset - f->addr + f->size; + } else { + r_asm_set_pc (core->assembler, core->offset); + cols = r_asm_disassemble (core->assembler, + &op, core->block, 32); + } + if (cols<1) cols = op.size; + if (cols<1) cols = 1; } - if (f && f->folded) { - cols = core->offset - f->addr + f->size; - } else { - r_asm_set_pc (core->assembler, core->offset); - cols = r_asm_disassemble (core->assembler, - &op, core->block, 32); - } - if (cols<1) cols = op.size; - if (cols<1) cols = 1; + r_core_seek (core, core->offset + cols, 1); } - r_core_seek (core, core->offset + cols, 1); } } break; @@ -1394,21 +1398,25 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { if (core->print->cur_enabled) { cursor_prevrow (core, false); } else { - int times = wheelspeed; - if (times<1) times = 1; - while (times--) { - if (isDisasmPrint (core->printidx)) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); - if (f && f->folded) { - cols = core->offset - f->addr; // + f->size; - if (cols<1) { - cols = 4; + if (r_config_get_i (core->config, "scr.wheelnkey")) { + r_core_cmd0(core, "sp"); + } else { + int times = wheelspeed; + if (times<1) times = 1; + while (times--) { + if (isDisasmPrint (core->printidx)) { + RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + if (f && f->folded) { + cols = core->offset - f->addr; // + f->size; + if (cols<1) { + cols = 4; + } + } else { + cols = prevopsz (core, core->offset); } - } else { - cols = prevopsz (core, core->offset); } + r_core_seek (core, core->offset - cols, 1); } - r_core_seek (core, core->offset - cols, 1); } } break; diff --git a/libr/include/r_util.h b/libr/include/r_util.h index c4489a3a22..3de5f5de60 100644 --- a/libr/include/r_util.h +++ b/libr/include/r_util.h @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2008-2015 - pancake */ +/* radare - LGPL - Copyright 2008-2016 - pancake */ #ifndef R2_UTIL_H #define R2_UTIL_H @@ -443,6 +443,7 @@ R_API void r_mem_copyloop (ut8 *dest, const ut8 *orig, int dsize, int osize); R_API void r_mem_copyendian (ut8 *dest, const ut8 *orig, int size, int endian); R_API int r_mem_cmp_mask (const ut8 *dest, const ut8 *orig, const ut8 *mask, int len); R_API const ut8 *r_mem_mem (const ut8 *haystack, int hlen, const ut8 *needle, int nlen); +R_API const ut8 *r_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align); #define r_num_abs(x) x>0?x:-x R_API void r_num_minmax_swap(ut64 *a, ut64 *b); diff --git a/libr/util/mem.c b/libr/util/mem.c index f148359ce8..9451b5e60f 100644 --- a/libr/util/mem.c +++ b/libr/util/mem.c @@ -204,6 +204,22 @@ R_API const ut8 *r_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int return NULL; } +// TODO: rename to r_mem_mem and refactor all calls to this function +R_API const ut8 *r_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align) { + int i, until = hlen-nlen+1; + if (align < 1) align = 1; + if (hlen<1 || nlen<1) + return NULL; + if (align>1) { + until -= (until % align); + } + for (i=0; i