diff --git a/libr/anal/anal.c b/libr/anal/anal.c index 9dfb95de9a..a135b200fe 100644 --- a/libr/anal/anal.c +++ b/libr/anal/anal.c @@ -485,6 +485,14 @@ R_API void r_anal_purge(RAnal *anal) { r_anal_purge_imports (anal); } + +static int default_archinfo(int res, int q) { + if (res < 1) { + return 1; + } + return res; +} + // XXX deprecate. use r_arch_info() when all anal plugs get moved // XXX this function should NEVER return -1. it should provide all valid values, even if the delegate does not R_API R_DEPRECATE int r_anal_archinfo(RAnal *anal, int query) { @@ -497,17 +505,15 @@ R_API R_DEPRECATE int r_anal_archinfo(RAnal *anal, int query) { const char *const b = anal->config->arch; if (!strcmp (a, b)) { int res = r_arch_info (anal->arch, query); - if (res != -1) { - return res; - } - return res; + return default_archinfo (res, query); } } + int res = -1; // this is the anal archinfo fallback if (anal->cur && anal->cur->archinfo) { - return anal->cur->archinfo (anal, query); + res = anal->cur->archinfo (anal, query); } - return -1; + return default_archinfo (res, query); } R_API bool r_anal_is_aligned(RAnal *anal, const ut64 addr) { diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index d5d6041c4f..2f81a85136 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -2239,7 +2239,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int (void)r_asm_disassemble (core->rasm, &asmop, buf + idx, len - idx); esilstr = R_STRBUF_SAFEGET (&op.esil); opexstr = R_STRBUF_SAFEGET (&op.opex); - char *mnem = strdup (r_asm_op_get_asm (&asmop)); + char *mnem = strdup (r_str_get (r_asm_op_get_asm (&asmop))); char *sp = strchr (mnem, ' '); if (sp) { *sp = 0; @@ -6157,50 +6157,30 @@ static void cmd_anal_info(RCore *core, const char *input) { PJ *pj = pj_new (); pj_o (pj); int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); - if (v > 0) { - pj_ki (pj, "minopsz", v); - } + pj_ki (pj, "minopsz", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); - if (v > 0) { - pj_ki (pj, "maxopsz", v); - } + pj_ki (pj, "maxopsz", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE); - if (v > 0) { - pj_ki (pj, "invopsz", v); - } + pj_ki (pj, "invopsz", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_DATA_ALIGN); - if (v > 0) { - pj_ki (pj, "dtalign", v); - } + pj_ki (pj, "dtalign", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - if (v > 0) { - pj_ki (pj, "pcalign", v); - } + pj_ki (pj, "pcalign", v); pj_end (pj); char *s = pj_drain (pj); r_cons_printf ("%s\n", s); free (s); } else { int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); - if (v > 0) { - r_cons_printf ("minopsz %d\n", v); - } + r_cons_printf ("minopsz %d\n", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); - if (v > 0) { - r_cons_printf ("maxopsz %d\n", v); - } + r_cons_printf ("maxopsz %d\n", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE); - if (v > 0) { - r_cons_printf ("invopsz %d\n", v); - } + r_cons_printf ("invopsz %d\n", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_DATA_ALIGN); - if (v > 0) { - r_cons_printf ("dtalign %d\n", v); - } + r_cons_printf ("dtalign %d\n", v); v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - if (v > 0) { - r_cons_printf ("pcalign %d\n", v); - } + r_cons_printf ("pcalign %d\n", v); } break; case 'i': // "aii" diff --git a/test/db/anal/snes b/test/db/anal/snes index ff69743ff6..d3ab630bb1 100644 --- a/test/db/anal/snes +++ b/test/db/anal/snes @@ -46,6 +46,7 @@ snes minopsz 1 maxopsz 3 invopsz 1 +dtalign 1 pcalign 1 0x00400000 0x00400039 diff --git a/test/db/cmd/cmd_i b/test/db/cmd/cmd_i index 7c5e7158e2..3050b98875 100644 --- a/test/db/cmd/cmd_i +++ b/test/db/cmd/cmd_i @@ -245,7 +245,7 @@ nth paddr vaddr bind type size lib name e cfg.bigendian=false e asm.bits=64 e asm.dwarf=false -e asm.pcalign=0 +e asm.pcalign=1 fs imports fs symbols fs exports @@ -293,7 +293,7 @@ block 0x100 e cfg.bigendian=false e asm.bits=64 e asm.dwarf=false -e asm.pcalign=0 +e asm.pcalign=1 baddr 0x0 binsz 1024 bits 64 @@ -314,7 +314,7 @@ va false e cfg.bigendian=false e asm.bits=64 e asm.dwarf=false -e asm.pcalign=0 +e asm.pcalign=1 EOF RUN diff --git a/test/db/formats/elf/v850 b/test/db/formats/elf/v850 index 27af1a1e3a..89f4d625ac 100644 --- a/test/db/formats/elf/v850 +++ b/test/db/formats/elf/v850 @@ -10,6 +10,7 @@ EOF EXPECT=<