Fix sparc regressions, ahi s and pd@x

This commit is contained in:
Giovanni 2017-03-24 02:42:31 +01:00 committed by radare
parent b862dc5587
commit 1a5ffd5221
6 changed files with 50 additions and 11 deletions

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;