Skip to content

Commit

Permalink
Fix #2079 via the post-printer. (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 authored Apr 30, 2024
1 parent eb4fc2d commit b2d5b43
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
23 changes: 23 additions & 0 deletions arch/X86/X86Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,4 +2244,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
2 changes: 2 additions & 0 deletions arch/X86/X86Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion arch/X86/X86Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions suite/cstest/issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,7 @@
!# issue 2128
!# CS_ARCH_X86, CS_MODE_64, CS_OPT_DETAIL
0x0: 0x4c,0x85,0x7d,0x30 == test qword ptr [rbp + 0x30], r15 ; operands[1].type: REG = r15 ; operands[1].access: READ ; Registers read: rbp r15 ; Registers modified: rflags

!# issue 2079
!# CS_ARCH_X86, CS_MODE_32, CS_OPT_DETAIL
0x0: 0xd1,0x10 == rcl dword ptr [eax] ; operands[1].type: IMM = 0x1

0 comments on commit b2d5b43

Please sign in to comment.