Fix arm64 disassembler and obey op->size

This commit is contained in:
pancake 2013-12-11 03:06:51 +01:00
parent 0df2759c18
commit bd6824baaf
4 changed files with 38 additions and 23 deletions

View File

@ -303,10 +303,11 @@ R_API int r_asm_set_pc(RAsm *a, ut64 pc) {
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int oplen, ret = op->payload = 0;
op->size = 1;
op->size = 4;
if (a->cur && a->cur->disassemble)
ret = a->cur->disassemble (a, op, buf, len);
oplen = r_asm_op_get_size (op);
oplen = op->size;
if (oplen>len) oplen = len;
if (oplen<1) oplen = 1;
if (ret > 0) {

View File

@ -115,14 +115,14 @@ static int buf_fprintf(void *stream, const char *format, ...) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
static char *oldcpu = NULL;
static int oldcpucode = 0;
int cpucode = 0;
int opsize, cpucode = 0;
struct disassemble_info obj;
char *options = (a->bits==16)? "force-thumb": "no-force-thumb";
if (len<2) return -1;
memset (bytes, 0, sizeof (buf));
memcpy (bytes, buf, len<4?len:4);
if (len<(a->bits/8)) return -1;
if (a->bits<64 && len<(a->bits/8)) return -1;
buf_global = op->buf_asm;
Offset = a->pc;
@ -130,18 +130,18 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
memset (&obj,'\0', sizeof (struct disassemble_info));
arm_mode = a->bits;
cpucode = oldcpucode;
/* select cpu */
if (a->cpu) {
if (oldcpu != a->cpu) {
cpucode = atoi (a->cpu);
if (!strcmp ("v5j", a->cpu))
cpucode = 9;
cpucode = oldcpucode;
/* select cpu */
if (a->cpu) {
if (oldcpu != a->cpu) {
cpucode = atoi (a->cpu);
if (!strcmp ("v5j", a->cpu))
cpucode = 9;
}
}
}
obj.arch = 0;
obj.mach = cpucode;
oldcpucode = cpucode;
obj.arch = 0;
obj.mach = cpucode;
oldcpucode = cpucode;
obj.buffer = bytes;
obj.read_memory_func = &arm_buffer_read_memory;
@ -166,9 +166,12 @@ oldcpucode = cpucode;
print_insn_little_arm ((bfd_vma)Offset, &obj):
print_insn_big_arm ((bfd_vma)Offset, &obj);
}
if (op->size == -1)
opsize = op->size;
if (op->size == -1) {
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
return op->size;
op->size = 4;
}
return opsize;
}
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {

View File

@ -44,6 +44,7 @@ static int modify(RAsm *a, ut8 *buf, int field, ut64 val) {
}
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int opsize;
static ud_t d;
ud_init (&d);
ud_set_syntax (&d, (a->syntax==R_ASM_SYNTAX_ATT)?
@ -53,11 +54,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
ud_set_mode (&d, a->bits);
op->size = ud_disassemble (&d);
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s", ud_insn_asm (&d));
if (!op->size || strstr (op->buf_asm, "invalid"))
op->size = -1;
if (op->size<1)
op->size = -1;
return op->size;
opsize = op->size;
if (op->size<1 || strstr (op->buf_asm, "invalid"))
opsize = -1;
return opsize;
}
RAsmPlugin r_asm_plugin_x86 = {

View File

@ -1249,8 +1249,19 @@ toro:
r_cons_printf (" ; 0x%08"PFMT64x"\n", analop.ptr);
}
} else {
if (analop.ptr != UT64_MAX && analop.ptr)
r_cons_printf (" ; 0x%08"PFMT64x" ", analop.ptr);
if (analop.ptr != UT64_MAX && analop.ptr) {
char msg[32];
ut8 *b = buf+idx;
int bsz = len-idx;
const char *kind = r_anal_data_kind (core->anal, analop.ptr, buf, bsz);
if (kind && !strcmp (kind, "text")) {
*msg = '"';
snprintf (msg+1, sizeof (msg)-2, "%s", buf+idx);
strcat (msg, "\"");
}
// analyze if its string
r_cons_printf (" ; %s 0x%08"PFMT64x" ", msg, analop.ptr);
}
}
if (show_comments && show_comment_right && comment) {
int c = r_cons_get_column ();