Skip to content

Commit

Permalink
Unit Test fixes [Capstone to Zydis]
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar3q34 committed Jan 22, 2025
1 parent 99283d5 commit 187ebe4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions librz/arch/p/analysis/analysis_x86_zydis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1845,8 +1845,8 @@ static void set_access_info(RzReg *reg, RzAnalysisOp *op, ZydisDecodedInstructio
rz_list_append(ret, val);

// Register access info
ZydisRegister regs_read[zydecode->operand_count];
ZydisRegister regs_write[zydecode->operand_count];
ZydisRegister regs_read[ZYDIS_MAX_OPERAND_COUNT];
ZydisRegister regs_write[ZYDIS_MAX_OPERAND_COUNT];
ut8 read_count = 0;
ut8 write_count = 0;
for (int i = 0; i < zydecode->operand_count; i++) {
Expand Down
Binary file removed test/output_file
Binary file not shown.
6 changes: 3 additions & 3 deletions test/unit/test_analysis_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ bool test_rz_analysis_block_analyze_ops(void) {
block = rz_analysis_create_block(a, 0x1000, 0x17);
mu_assert_eq(block->ninstr, 0, "clean block");
rz_analysis_block_analyze_ops(block);
mu_assert_eq(block->ninstr, 3, "ninstr");
mu_assert_eq(block->ninstr, 6, "ninstr");
mu_assert_eq(rz_analysis_block_get_op_offset(block, 0), 0, "op offset");
mu_assert_eq(rz_analysis_block_get_op_offset(block, 1), 0x7, "op offset");
mu_assert_eq(rz_analysis_block_get_op_offset(block, 2), 0xa, "op offset");
Expand Down Expand Up @@ -947,7 +947,7 @@ bool test_rz_analysis_block_analyze_ops_sp(void) {
mu_assert_eq(rz_analysis_block_get_op_offset(block, 4), 0x9, "op offset");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 0), -8, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 1), -8, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 2), -0x28, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 2), 0x18, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 3), 0, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 4), -8, "sp delta");

Expand All @@ -962,7 +962,7 @@ bool test_rz_analysis_block_analyze_ops_sp(void) {
mu_assert_eq(rz_analysis_block_get_op_offset(block, 4), 0x9, "op offset");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 0), -8, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 1), -8, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 2), -0x28, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 2), 0x18, "sp delta");
// stack reset depends on the sp_entry, which makes the following difference to above:
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 3), 0x10, "sp delta");
mu_assert_eq(rz_analysis_block_get_op_sp_delta(block, 4), 8, "sp delta");
Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_analysis_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ bool test_rz_core_analysis_bytes() {
mu_assert_streq(ab->pseudo, "rbp = rsp", "rz_core_analysis_bytes pseudo");

ab = rz_iterator_next(iter);
mu_assert_streq(ab->opcode, "mov dword [rbp - 4], edi", "rz_core_analysis_bytes opcode");
mu_assert_streq(ab->pseudo, "dword [rbp - 4] = edi", "rz_core_analysis_bytes pseudo");
mu_assert_streq(ab->opcode, "mov dword [rbp-0x04], edi", "rz_core_analysis_bytes opcode");
mu_assert_streq(ab->pseudo, "dword [rbp-0x04] = edi", "rz_core_analysis_bytes pseudo");

rz_iterator_free(iter);
rz_core_free(core);
Expand Down Expand Up @@ -164,14 +164,14 @@ bool test_rz_core_print_disasm() {
mu_assert_eq(t->offset, 4, "rz_core_print_disasm offset");
mu_assert_eq(t->arrow, UT64_MAX, "rz_core_print_disasm arrow");
mu_assert_streq_free(rz_str_trim_dup(t->text),
"\x1b[32m0x00000004\x1b[0m \x1b[37mmov\x1b[0m\x1b[37m \x1b[0m\x1b[37mdword\x1b[0m\x1b[37m [\x1b[0m\x1b[36mrbp\x1b[0m\x1b[37m \x1b[0m\x1b[37m-\x1b[0m\x1b[37m \x1b[0m\x1b[33m4\x1b[0m\x1b[37m], \x1b[0m\x1b[36medi\x1b[0m\x1b[0m\x1b[0m",
"\x1b[32m0x00000004\x1b[0m \x1b[37mmov\x1b[0m\x1b[37m \x1b[0m\x1b[37mdword\x1b[0m\x1b[37m [\x1b[0m\x1b[36mrbp\x1b[0m\x1b[37m-\x1b[0m\x1b[33m0x04\x1b[0m\x1b[37m], \x1b[0m\x1b[36medi\x1b[0m\x1b[0m\x1b[0m",
"rz_core_print_disasm text");

t = rz_pvector_at(vec, 3);
mu_assert_eq(t->offset, 7, "rz_core_print_disasm offset");
mu_assert_eq(t->arrow, 1, "rz_core_print_disasm arrow");
mu_assert_streq_free(rz_str_trim_dup(t->text),
"\x1b[32m0x00000007\x1b[0m \x1b[32mjmp\x1b[0m\x1b[37m \x1b[0m\x1b[33m1\x1b[0m\x1b[0m\x1b[0m",
"\x1b[32m0x00000007\x1b[0m \x1b[32mjmp\x1b[0m\x1b[37m \x1b[0m\x1b[33m0x1\x1b[0m\x1b[0m\x1b[0m",
"rz_core_print_disasm text");

rz_core_free(core);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static bool test_rz_colorize_generic_2(void) {
RzStrBuf *colored_asm = rz_asm_colorize_asm_str(&asmop->buf_asm, p,
rz_asm_get_parse_param(a->reg, anaop->type), asmop->asm_toks);

RzStrBuf *expected = rz_strbuf_new("\x1b[37mmovabs\x1b[0m\x1b[37m \x1b[0m\x1b[36mrax\x1b[0m\x1b[37m, \x1b[0m\x1b[33m0x1122334455667788\x1b[0m");
RzStrBuf *expected = rz_strbuf_new("\x1b[37mmov\x1b[0m\x1b[37m \x1b[0m\x1b[36mrax\x1b[0m\x1b[37m, \x1b[0m\x1b[33m0x1122334455667788\x1b[0m");
char err_msg[2048];
snprintf(err_msg, sizeof(err_msg), "Colors of \"%s\" are incorrect. Should be \"%s\"\n.", rz_strbuf_get(colored_asm), rz_strbuf_get(expected));
mu_assert_true(rz_strbuf_equals(colored_asm, expected), err_msg);
Expand Down

0 comments on commit 187ebe4

Please sign in to comment.