From 399a38771393c202a741336643118991290b4b1b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 19 Sep 2023 16:30:09 +0300 Subject: [PATCH] Avoid MOVD/MOVQ disassemble mismatch with old/new capstone versions --- ir_disasm.c | 6 ++++++ tests/x86/conv_004.irt | 2 +- tests/x86/conv_010.irt | 2 +- tests/x86_64/conv_004.irt | 2 +- tests/x86_64/conv_010.irt | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ir_disasm.c b/ir_disasm.c index 592bd4ea..d666bfd8 100644 --- a/ir_disasm.c +++ b/ir_disasm.c @@ -488,6 +488,12 @@ int ir_disasm(const char *name, fprintf(f, " %" PRIx64 ":", insn->address); } p = insn->op_str; +#if defined(IR_TARGET_X64) && (CS_API_MAJOR < 5) + /* Fix capstone MOVD/MOVQ disassemble mismatch */ + if (insn->id == X86_INS_MOVQ && strcmp(insn->mnemonic, "movd") == 0) { + insn->mnemonic[3] = 'q'; + } +#endif if (strlen(p) == 0) { fprintf(f, "\t%s\n", insn->mnemonic); continue; diff --git a/tests/x86/conv_004.irt b/tests/x86/conv_004.irt index 76c13e7b..9a36e42d 100644 --- a/tests/x86/conv_004.irt +++ b/tests/x86/conv_004.irt @@ -15,5 +15,5 @@ x86 } --EXPECT-- test: - movd %xmm0, %rax + movq %xmm0, %rax retq diff --git a/tests/x86/conv_010.irt b/tests/x86/conv_010.irt index 6cdf1e85..2ae85c6b 100644 --- a/tests/x86/conv_010.irt +++ b/tests/x86/conv_010.irt @@ -15,5 +15,5 @@ x86 } --EXPECT-- test: - movd %rdi, %xmm0 + movq %rdi, %xmm0 retq diff --git a/tests/x86_64/conv_004.irt b/tests/x86_64/conv_004.irt index 0729b180..11087f8f 100644 --- a/tests/x86_64/conv_004.irt +++ b/tests/x86_64/conv_004.irt @@ -13,5 +13,5 @@ x86_64 } --EXPECT-- test: - movd %xmm0, %rax + movq %xmm0, %rax retq diff --git a/tests/x86_64/conv_010.irt b/tests/x86_64/conv_010.irt index a6c1a2d5..3967624d 100644 --- a/tests/x86_64/conv_010.irt +++ b/tests/x86_64/conv_010.irt @@ -13,5 +13,5 @@ x86_64 } --EXPECT-- test: - movd %rdi, %xmm0 + movq %rdi, %xmm0 retq