From 7639b417a497e282b7f2053e6e9d2d084e42e518 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Tue, 23 Apr 2024 17:13:07 -0500 Subject: [PATCH] Fix #2079 via the post-printer. --- arch/X86/X86Mapping.c | 23 +++++++++++++++++++++++ arch/X86/X86Mapping.h | 2 ++ arch/X86/X86Module.c | 2 +- suite/cstest/issues.cs | 3 +++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/X86/X86Mapping.c b/arch/X86/X86Mapping.c index 2a3d67ea10..1a46065ff8 100644 --- a/arch/X86/X86Mapping.c +++ b/arch/X86/X86Mapping.c @@ -2240,4 +2240,27 @@ unsigned short X86_register_map(unsigned short id) return 0; } +/// The post-printer function. Used to fixup flaws in the disassembly information +/// of certain instructions. +void X86_postprinter(csh handle, cs_insn *insn, char *mnem, MCInst *mci) { + if (!insn || !insn->detail) { + return; + } + switch (insn->id) { + default: + break; + case X86_INS_RCL: + // Addmissing 1 immediate + if (insn->detail->x86.op_count > 1) { + return; + } + insn->detail->x86.operands[1].imm = 1; + insn->detail->x86.operands[1].type = X86_OP_IMM; + insn->detail->x86.operands[1].access = CS_AC_READ; + insn->detail->x86.op_count++; + break; + } +} + + #endif diff --git a/arch/X86/X86Mapping.h b/arch/X86/X86Mapping.h index 89bbfcd8c4..c6dc40377f 100644 --- a/arch/X86/X86Mapping.h +++ b/arch/X86/X86Mapping.h @@ -91,4 +91,6 @@ unsigned short X86_register_map(unsigned short id); unsigned int find_insn(unsigned int id); +void X86_postprinter(csh handle, cs_insn *insn, char *mnem, MCInst *mci); + #endif diff --git a/arch/X86/X86Module.c b/arch/X86/X86Module.c index 2ec5625de4..ed080a797c 100644 --- a/arch/X86/X86Module.c +++ b/arch/X86/X86Module.c @@ -26,7 +26,7 @@ cs_err X86_global_init(cs_struct *ud) ud->insn_id = X86_get_insn_id; ud->insn_name = X86_insn_name; ud->group_name = X86_group_name; - ud->post_printer = NULL; + ud->post_printer = X86_postprinter; #ifndef CAPSTONE_DIET ud->reg_access = X86_reg_access; #endif diff --git a/suite/cstest/issues.cs b/suite/cstest/issues.cs index 699bbe5f21..d56b1dce6d 100644 --- a/suite/cstest/issues.cs +++ b/suite/cstest/issues.cs @@ -1043,3 +1043,6 @@ !# CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN, None 0x0: 0x00,0x00,0x00,0x4c == st4 {v0.16b, v1.16b, v2.16b, v3.16b}, [x0] +!# issue 2079 +!# CS_ARCH_X86, CS_MODE_32, CS_OPT_DETAIL +0x0: 0xd1,0x10 == rcl dword ptr [eax] ; operands[1].type: IMM = 0x1