Beispiel #1
0
static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
{
    const int no_alias = 1;
    struct riscv_opcode *o = NULL;
    insn_t word = 0;
    int xlen = anal->bits;

    op->size = 4;
    op->addr = addr;
    op->type = R_ANAL_OP_TYPE_UNK;

    memcpy (&word, data, 4);
    o = get_opcode (word);
    if (o == NULL) {
        return op->size;
    }

    for(; o < &riscv_opcodes[NUMOPCODES]; o++) {
        if ( !(o->match_func)(o, word) ) continue;
        if ( no_alias && (o->pinfo & INSN_ALIAS) ) continue;
        if ( isdigit (o->subset[0]) && atoi (o->subset) != xlen) continue;
        else break;
    }
#define is_any(...) _is_any(NARGS(__VA_ARGS__), o->name, __VA_ARGS__)

// branch/jumps/calls/rets
    if (is_any ("jal")) {
        // decide wether it's ret or call
        int rd = (word >> OP_SH_RD) & OP_MASK_RD;
        op->type = (rd == 0) ? R_ANAL_OP_TYPE_RET : R_ANAL_OP_TYPE_CALL;
        op->jump = EXTRACT_UJTYPE_IMM (word) + addr;
        op->fail = addr + 4;
    } else if(is_any ("jr")) {
Beispiel #2
0
static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
	const int no_alias = 1;
	struct riscv_opcode *o = NULL;
	ut64 word = 0;
	int xlen = anal->bits;

	op->size = 4;
	op->addr = addr;
	op->type = R_ANAL_OP_TYPE_UNK;

	word = (len >= sizeof (ut64))? r_read_ble64 (data, anal->big_endian): r_read_ble16 (data, anal->big_endian);

	o = get_opcode (word);
	if (word == UT64_MAX) {
		op->type = R_ANAL_OP_TYPE_ILL;
		return -1;
	}
	if (!o || !o->name) return op->size;

	for (; o < &riscv_opcodes[NUMOPCODES]; o++) {
		// XXX ASAN segfault if ( !(o->match_func)(o, word) ) continue;
		if ( no_alias && (o->pinfo & INSN_ALIAS) ) continue;
		if ( isdigit ((int)(o->subset[0])) && atoi (o->subset) != xlen) continue;
		else {
			break;
		}
	}

	if (!o || !o->name) {
		return -1;
	}
// branch/jumps/calls/rets
	if (is_any ("jal")) {
		// decide wether it's ret or call
		int rd = (word >> OP_SH_RD) & OP_MASK_RD;
		op->type = (rd == 0) ? R_ANAL_OP_TYPE_RET: R_ANAL_OP_TYPE_CALL;
		op->jump = EXTRACT_UJTYPE_IMM (word) + addr;
		op->fail = addr + 4;
	} else if (is_any ("jr")) {