From 1a5ffd5221f99b0b05760226bd6d365b1a140a8b Mon Sep 17 00:00:00 2001 From: Giovanni Date: Fri, 24 Mar 2017 02:42:31 +0100 Subject: [PATCH] Fix sparc regressions, ahi s and pd@x --- libr/anal/p/anal_sparc_cs.c | 15 ++++++++++++++- libr/anal/p/anal_sparc_gnu.c | 5 +++++ libr/asm/p/asm_sparc_cs.c | 8 +++++--- libr/asm/p/asm_sparc_gnu.c | 15 +++++++++++---- libr/core/cmd_print.c | 2 +- libr/parse/parse.c | 16 ++++++++++++++-- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/libr/anal/p/anal_sparc_cs.c b/libr/anal/p/anal_sparc_cs.c index 9c485f07c8..c55c423f2f 100644 --- a/libr/anal/p/anal_sparc_cs.c +++ b/libr/anal/p/anal_sparc_cs.c @@ -18,7 +18,12 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { static int omode; cs_insn *insn; int mode, n, ret; - mode = CS_MODE_BIG_ENDIAN; + + if (!a->big_endian) { + return -1; + } + + mode = CS_MODE_LITTLE_ENDIAN; if (!strcmp (a->cpu, "v9")) mode |= CS_MODE_V9; if (mode != omode) { @@ -49,6 +54,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { op->size = insn->size; op->id = insn->id; switch (insn->id) { + case SPARC_INS_INVALID: + op->type = R_ANAL_OP_TYPE_ILL; + break; case SPARC_INS_MOV: op->type = R_ANAL_OP_TYPE_MOV; break; @@ -270,6 +278,10 @@ static int set_reg_profile(RAnal *anal) { return r_reg_set_profile_string (anal->reg, p); } +static int archinfo(RAnal *anal, int q) { + return 4; /* :D */ +} + RAnalPlugin r_anal_plugin_sparc_cs = { .name = "sparc", .desc = "Capstone SPARC analysis", @@ -277,6 +289,7 @@ RAnalPlugin r_anal_plugin_sparc_cs = { .license = "BSD", .arch = "sparc", .bits = 32|64, + .archinfo = archinfo, .op = &analop, .set_reg_profile = &set_reg_profile, }; diff --git a/libr/anal/p/anal_sparc_gnu.c b/libr/anal/p/anal_sparc_gnu.c index 5ea1a78540..2bedab96a7 100644 --- a/libr/anal/p/anal_sparc_gnu.c +++ b/libr/anal/p/anal_sparc_gnu.c @@ -603,6 +603,10 @@ static int set_reg_profile(RAnal *anal) { return r_reg_set_profile_string (anal->reg, p); } +static int archinfo(RAnal *anal, int q) { + return 4; /* :D */ +} + RAnalPlugin r_anal_plugin_sparc_gnu = { .name = "sparc.gnu", .desc = "SPARC analysis plugin", @@ -610,6 +614,7 @@ RAnalPlugin r_anal_plugin_sparc_gnu = { .arch = "sparc", .bits = 32 | 64, .op = &sparc_op, + .archinfo = archinfo, .set_reg_profile = set_reg_profile, }; diff --git a/libr/asm/p/asm_sparc_cs.c b/libr/asm/p/asm_sparc_cs.c index 3718244ac4..09dbcd97eb 100644 --- a/libr/asm/p/asm_sparc_cs.c +++ b/libr/asm/p/asm_sparc_cs.c @@ -8,8 +8,8 @@ static csh cd = 0; static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; - int n, ret = -1; - int mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN; + int n = -1, ret = -1; + int mode = CS_MODE_BIG_ENDIAN; if (a->cpu && *a->cpu) { if (!strcmp (a->cpu, "v9")) { mode |= CS_MODE_V9; @@ -30,7 +30,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (!op) { return 0; } - n = cs_disasm (cd, buf, len, a->pc, 1, &insn); + if (a->big_endian) { + n = cs_disasm (cd, buf, len, a->pc, 1, &insn); + } if (n < 1) { strcpy (op->buf_asm, "invalid"); op->size = 4; diff --git a/libr/asm/p/asm_sparc_gnu.c b/libr/asm/p/asm_sparc_gnu.c index d9293b3c4e..3af2eb41e9 100644 --- a/libr/asm/p/asm_sparc_gnu.c +++ b/libr/asm/p/asm_sparc_gnu.c @@ -49,7 +49,9 @@ static int buf_fprintf(void *stream, const char *format, ...) { static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { static struct disassemble_info disasm_obj; - if (len<4) return -1; + if (len < 4) { + return -1; + } buf_global = op->buf_asm; Offset = a->pc; // disasm inverted @@ -62,18 +64,23 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { disasm_obj.symbol_at_address_func = &symbol_at_address; disasm_obj.memory_error_func = &memory_error_func; disasm_obj.print_address_func = &print_address; - disasm_obj.endian = !a->big_endian; + disasm_obj.endian = a->big_endian; disasm_obj.fprintf_func = &buf_fprintf; disasm_obj.stream = stdout; disasm_obj.mach = ((a->bits == 64) ? bfd_mach_sparc_v9b : 0); - op->buf_asm[0]='\0'; + op->buf_asm[0] = '\0'; op->size = print_insn_sparc ((bfd_vma)Offset, &disasm_obj); - if (op->size == -1) + if (!strncmp (op->buf_asm, "unknown", 7)) { + strncpy (op->buf_asm, "invalid", R_ASM_BUFSIZE); + } + + if (op->size == -1) { strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE); + } return op->size; } diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index d67f900b18..5cdeedb0c7 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -3594,7 +3594,7 @@ static int cmd_print(void *data, const char *input) { break; case 0: /* "pd" -> will disassemble blocksize/4 instructions */ - if (*input == 'd') { + if (*input == 'd' && !core->fixedblock) { l /= 4; } break; diff --git a/libr/parse/parse.c b/libr/parse/parse.c index 0d323061a5..89e80ccc06 100644 --- a/libr/parse/parse.c +++ b/libr/parse/parse.c @@ -141,7 +141,19 @@ static char *findNextNumber(char *op) { if (!is_space) { is_space = (p == op || *o == ' ' || *o == ',' || *o == '['); } - if (is_space && IS_DIGIT(*p)) { + if (*p == '[') { + char *t = p; + p++; + if (!IS_DIGIT (*p)) { + for (;*p && *p != ']'; p++); + if (*p == ']') { + continue; + } else { + p = t; + } + } + } + if (is_space && IS_DIGIT (*p)) { return p; } o = p++; @@ -253,7 +265,7 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_ pnum += 2; } for (; *pnum; pnum++) { - if ((is_hex && ISHEXCHAR(*pnum)) || IS_DIGIT(*pnum)) { + if ((is_hex && ISHEXCHAR (*pnum)) || IS_DIGIT (*pnum)) { continue; } break;