[RzIL] Clarify what append actually does
high/low is more descriptive than x/y. Test has also been added.
This commit is contained in:
parent
b338949dd4
commit
5ddb19c692
6 changed files with 38 additions and 27 deletions
|
|
@ -335,7 +335,7 @@ static void il_opdmp_concat(RzILOpPure *op, RzStrBuf *sb, PJ *pj) {
|
|||
}
|
||||
|
||||
static void il_opdmp_append(RzILOpPure *op, RzStrBuf *sb, PJ *pj) {
|
||||
il_op_param_2("append", op->op.append, pure, x, pure, y);
|
||||
il_op_param_2("append", op->op.append, pure, high, pure, low);
|
||||
}
|
||||
|
||||
static void il_opdmp_load(RzILOpPure *op, RzStrBuf *sb, PJ *pj) {
|
||||
|
|
|
|||
|
|
@ -477,12 +477,12 @@ RZ_API RZ_OWN RzILOpBitVector *rz_il_op_new_shiftr(RZ_NONNULL RzILOpBool *fill_b
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief op structure for appending 2 bitv: MSB:LSB y:x
|
||||
* \brief op structure for appending 2 bitv: MSB:LSB high:low
|
||||
*/
|
||||
RZ_API RZ_OWN RzILOpBitVector *rz_il_op_new_append(RZ_NONNULL RzILOpBitVector *x, RZ_NONNULL RzILOpBitVector *y) {
|
||||
rz_return_val_if_fail(x && y, NULL);
|
||||
RZ_API RZ_OWN RzILOpBitVector *rz_il_op_new_append(RZ_NONNULL RzILOpBitVector *high, RZ_NONNULL RzILOpBitVector *low) {
|
||||
rz_return_val_if_fail(high && low, NULL);
|
||||
RzILOpBitVector *ret;
|
||||
rz_il_op_new_2(BitVector, RZ_IL_OP_APPEND, RzILOpArgsAppend, append, x, y);
|
||||
rz_il_op_new_2(BitVector, RZ_IL_OP_APPEND, RzILOpArgsAppend, append, high, low);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -828,7 +828,7 @@ RZ_API RzILOpPure *rz_il_op_pure_dup(RZ_NONNULL RzILOpPure *op) {
|
|||
rz_warn_if_reached();
|
||||
break;
|
||||
case RZ_IL_OP_APPEND:
|
||||
DUP_OP2(append, x, y);
|
||||
DUP_OP2(append, high, low);
|
||||
break;
|
||||
case RZ_IL_OP_LOAD:
|
||||
r->op.load.mem = op->op.load.mem;
|
||||
|
|
@ -955,7 +955,7 @@ RZ_API void rz_il_op_pure_free(RZ_NULLABLE RzILOpPure *op) {
|
|||
rz_warn_if_reached();
|
||||
break;
|
||||
case RZ_IL_OP_APPEND:
|
||||
rz_il_op_free_2(pure, append, x, y);
|
||||
rz_il_op_free_2(pure, append, high, low);
|
||||
break;
|
||||
case RZ_IL_OP_LOAD:
|
||||
rz_il_op_free_1(pure, load, key);
|
||||
|
|
|
|||
|
|
@ -132,11 +132,11 @@ void *rz_il_handler_append(RzILVM *vm, RzILOpBitVector *op, RzILPureType *type)
|
|||
|
||||
RzILOpArgsAppend *op_append = &op->op.append;
|
||||
|
||||
RzBitVector *x = rz_il_evaluate_bitv(vm, op_append->x);
|
||||
RzBitVector *y = rz_il_evaluate_bitv(vm, op_append->y);
|
||||
RzBitVector *result = x && y ? rz_bv_append(x, y) : NULL;
|
||||
rz_bv_free(x);
|
||||
rz_bv_free(y);
|
||||
RzBitVector *high = rz_il_evaluate_bitv(vm, op_append->high);
|
||||
RzBitVector *low = rz_il_evaluate_bitv(vm, op_append->low);
|
||||
RzBitVector *result = high && low ? rz_bv_append(high, low) : NULL;
|
||||
rz_bv_free(low);
|
||||
rz_bv_free(high);
|
||||
|
||||
*type = RZ_IL_PURE_TYPE_BITV;
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -141,11 +141,11 @@ typedef struct rz_il_op_args_cast_t {
|
|||
|
||||
/**
|
||||
* \struct rz_il_op_args_append_t
|
||||
* \brief op structure for appending 2 bitv: MSB:LSB bv1:bv2
|
||||
* \brief op structure for appending 2 bitv: MSB:LSB high:low
|
||||
*/
|
||||
typedef struct rz_il_op_args_append_t {
|
||||
RzILOpBitVector *x; ///< index of the bv 1
|
||||
RzILOpBitVector *y; ///< index of the bv 2
|
||||
RzILOpBitVector *high; ///< bitvector occupying the most significant bits
|
||||
RzILOpBitVector *low; ///< bitvector occupying the least significant bits
|
||||
} RzILOpArgsAppend;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -289,20 +289,15 @@ RZ_API RZ_OWN RzBitVector *rz_bv_cut_tail(RZ_NONNULL RzBitVector *bv, ut32 delta
|
|||
|
||||
/**
|
||||
* Append bv2 to bv1 to get new bitvector
|
||||
* \param bv1 RzBitVector
|
||||
* \param bv2 RzBitVector
|
||||
* \param high bitvector to occupy the most significant part of the result
|
||||
* \param low bitvector to occupy the least significant part of the result
|
||||
* \return ret RzBitVector, the new bitvector
|
||||
*/
|
||||
RZ_API RZ_OWN RzBitVector *rz_bv_append(RZ_NONNULL RzBitVector *bv1, RZ_NONNULL RzBitVector *bv2) {
|
||||
rz_return_val_if_fail(bv1 && bv2, NULL);
|
||||
|
||||
ut32 new_len = bv1->len + bv2->len;
|
||||
RzBitVector *ret = rz_bv_new(new_len);
|
||||
|
||||
// copy n bits from bv1
|
||||
rz_bv_copy_nbits(bv2, 0, ret, 0, bv2->len);
|
||||
rz_bv_copy_nbits(bv1, 0, ret, bv2->len, bv1->len);
|
||||
|
||||
RZ_API RZ_OWN RzBitVector *rz_bv_append(RZ_NONNULL RzBitVector *high, RZ_NONNULL RzBitVector *low) {
|
||||
rz_return_val_if_fail(high && low, NULL);
|
||||
RzBitVector *ret = rz_bv_new(high->len + low->len);
|
||||
rz_bv_copy_nbits(low, 0, ret, 0, low->len);
|
||||
rz_bv_copy_nbits(high, 0, ret, low->len, high->len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -554,6 +554,21 @@ static bool test_rzil_vm_op_storew_be() {
|
|||
mu_end;
|
||||
}
|
||||
|
||||
static bool test_rzil_vm_op_append() {
|
||||
RzILVM *vm = rz_il_vm_new(0, 8, true);
|
||||
|
||||
RzILOpPure *op = rz_il_op_new_append(rz_il_op_new_bitv_from_ut64(16, 0xc0ff), rz_il_op_new_bitv_from_ut64(8, 0xee));
|
||||
RzBitVector *r = rz_il_evaluate_bitv(vm, op);
|
||||
rz_il_op_pure_free(op);
|
||||
mu_assert_notnull(r, "eval");
|
||||
mu_assert_eq(rz_bv_len(r), 24, "eval len");
|
||||
mu_assert_eq(rz_bv_to_ut64(r), 0xc0ffee, "eval val");
|
||||
rz_bv_free(r);
|
||||
|
||||
rz_il_vm_free(vm);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool all_tests() {
|
||||
mu_run_test(test_rzil_vm_init);
|
||||
mu_run_test(test_rzil_vm_basic_operation);
|
||||
|
|
@ -574,6 +589,7 @@ bool all_tests() {
|
|||
mu_run_test(test_rzil_vm_op_storew_le);
|
||||
mu_run_test(test_rzil_vm_op_loadw_be);
|
||||
mu_run_test(test_rzil_vm_op_storew_be);
|
||||
mu_run_test(test_rzil_vm_op_append);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue