Beispiel #1
0
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
	int ret = 0;

	//len will end up in memcmp so check for negative	
	if (!anal || len < 0) return -1;
	if (anal->pcalign) {
		if (addr % anal->pcalign) {
			memset (op, 0, sizeof (RAnalOp));
			op->type = R_ANAL_OP_TYPE_ILL;
			op->addr = addr;
			op->size = 1;
			return -1;
		}
	}
	if (len > 0 && anal && memset (op, 0, sizeof (RAnalOp)) &&
		anal->cur && anal->cur->op && strcmp (anal->cur->name, "null")) {
		ret = anal->cur->op (anal, op, addr, data, len);
		op->addr = addr;
		op->var = get_used_var (anal, op);
		if (ret < 1) op->type = R_ANAL_OP_TYPE_ILL;
	} else {
		if (!memcmp (data, "\xff\xff\xff\xff", R_MIN(4, len))) {
			op->type = R_ANAL_OP_TYPE_ILL;
			ret = 2; // HACK
		} else {
			op->type = R_ANAL_OP_TYPE_MOV;
		}
	}
	return ret;
}
Beispiel #2
0
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, int mask) {
	//len will end up in memcmp so check for negative
	if (!anal || len < 0) {
		return -1;
	}

	anal->decode = mask & R_ANAL_OP_MASK_ESIL ? true : false;
	anal->fillval = mask & R_ANAL_OP_MASK_VAL ? true : false;
	if (anal->pcalign) {
		if (addr % anal->pcalign) {
			memset (op, 0, sizeof (RAnalOp));
			op->type = R_ANAL_OP_TYPE_ILL;
			op->addr = addr;
			op->size = 1;
			return -1;
		}
	}
	memset (op, 0, sizeof (RAnalOp));
	if (len > 0 && anal->cur && anal->cur->op) {
		//use core binding to set asm.bits correctly based on the addr
		//this is because of the hassle of arm/thumb
		if (anal && anal->coreb.archbits) {
			anal->coreb.archbits (anal->coreb.core, addr);
		}
		int ret = anal->cur->op (anal, op, addr, data, len);
		if (ret < 1) {
			op->type = R_ANAL_OP_TYPE_ILL;
		}
		op->addr = addr;
		/* consider at least 1 byte to be part of the opcode */
		if (op->nopcode < 1) {
			op->nopcode = 1;
		}
		//free the previous var in op->var
		RAnalVar *tmp = get_used_var (anal, op);
		if (tmp) {
			r_anal_var_free (op->var);
			op->var = tmp;
		}
		return ret;
	}
	if (!memcmp (data, "\xff\xff\xff\xff", R_MIN (4, len))) {
		op->type = R_ANAL_OP_TYPE_ILL;
		return R_MIN (2, len); // HACK
	}
	op->type = R_ANAL_OP_TYPE_MOV;
	if (op->cycles == 0) {
		op->cycles = defaultCycles (op);
	}
	return R_MIN (2, len); // HACK
}