Fix endian issue in mips.gnu assembler

This commit is contained in:
pancake 2016-09-02 17:11:49 +02:00
parent aab6ebf06b
commit 90fb18dcfc

View File

@ -80,10 +80,11 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
disasm_obj.stream = stdout;
op->buf_asm[0] = '\0';
if (disasm_obj.endian == BFD_ENDIAN_LITTLE)
if (disasm_obj.endian == BFD_ENDIAN_LITTLE) {
op->size = print_insn_little_mips ((bfd_vma)Offset, &disasm_obj);
else
} else {
op->size = print_insn_big_mips ((bfd_vma)Offset, &disasm_obj);
}
if (op->size == -1)
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
return op->size;
@ -91,8 +92,14 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
static int assemble(RAsm *a, RAsmOp *op, const char *str) {
int ret = mips_assemble (str, a->pc, op->buf);
if (!a->big_endian)
r_mem_swapendian (op->buf, op->buf, op->size);
if (a->big_endian) {
ut8 tmp = op->buf[0];
op->buf[0] = op->buf[3];
op->buf[3] = tmp;
tmp = op->buf[1];
op->buf[1] = op->buf[2];
op->buf[2] = tmp;
}
return ret;
}