diff --git a/libr/asm/asm.c b/libr/asm/asm.c index 7df0ff0ac9d5b..69f146ffd1466 100644 --- a/libr/asm/asm.c +++ b/libr/asm/asm.c @@ -369,6 +369,10 @@ R_API bool r_asm_use(RAsm *a, const char *name) { } if (a->analb.anal) { if (a->analb.use (a->analb.anal, name)) { + a->dcur = a->analb.anal->arch->session; + if (a->dcur) { + a->ecur = a->dcur->encoder ? a->dcur->encoder : a->dcur; + } load_asm_descriptions (a); return true; } @@ -447,6 +451,7 @@ R_API int r_asm_disassemble(RAsm *a, RAnalOp *op, const ut8 *buf, int len) { int ret = 0; op->size = 4; + op->addr = a->pc; r_anal_op_set_mnemonic (op, op->addr, ""); if (a->config->codealign) { const int mod = a->pc % a->config->codealign; @@ -456,9 +461,10 @@ R_API int r_asm_disassemble(RAsm *a, RAnalOp *op, const ut8 *buf, int len) { return -1; } } - if (a->analb.anal) { - ret = a->analb.decode (a->analb.anal, op, a->pc, buf, len, - R_ARCH_OP_MASK_ESIL | R_ARCH_OP_MASK_DISASM); + if (a->dcur) { + if (r_arch_session_decode (a->dcur, op, R_ARCH_OP_MASK_ESIL | R_ARCH_OP_MASK_DISASM)) { + ret = op->size; + } } if (ret < 0) { ret = 0; @@ -568,16 +574,14 @@ static int r_asm_assemble_single(RAsm *a, RAnalOp *op, const char *buf) { return 0; } r_str_case (b, false); // to-lower - if (a->analb.anal) { - ut8 buf[256] = { 0 }; - a->analb.anal->arch->cfg->endian = a->config->endian; - // XXX we should use just RArch and ecur/dcur - ret = a->analb.encode (a->analb.anal, a->pc, b, buf, sizeof (buf)); - if (ret > 0) { - r_anal_op_set_bytes (op, a->pc, buf, R_MIN (ret, sizeof (buf))); + if (a->ecur) { + op->addr = a->pc; + r_anal_op_set_mnemonic (op, op->addr, b); + if (r_arch_session_encode (a->ecur, op, 0)) { + ret = op->size; } } else { - R_LOG_ERROR ("Cannot assemble because there are no anal binds into the asm instance %p", a); + R_LOG_ERROR ("Cannot assemble because there are no arch sessions into the asm instance %p", a); ret = -1; #if 0 } else if (ase) { @@ -595,9 +599,8 @@ R_API RAsmCode *r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) { ut64 pc = a->pc; ut64 idx; int ret; - // XXX move from io to archconfig!! and remove the dependency on core! - const size_t addrbytes = a->user? ((RCore *)a->user)->io->addrbytes: 1; - int mininstrsize = 1; // TODO: use r_arch_info (); + const size_t addrbytes = a->config->addrbytes > 0 ? a->config->addrbytes : 1; + int mininstrsize = r_arch_info (a->arch, R_ARCH_INFO_MINOP_SIZE); RAsmCode *acode = r_asm_code_new (); if (!acode) { diff --git a/libr/include/r_asm.h b/libr/include/r_asm.h index eabc2e92c6cb4..4856f8474d14b 100644 --- a/libr/include/r_asm.h +++ b/libr/include/r_asm.h @@ -26,6 +26,7 @@ typedef struct r_asm_code_t { ut8 *bytes; char *assembly; #else + // TODO: is this really necessary? // imho this asmcode should contain multiple archops RAnalOp op; // we have those fields already inside RAnalOp #endif