Skip to content

Commit

Permalink
Fix capstone-engine#2079 via the post-printer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Apr 23, 2024
1 parent 911b15c commit 7639b41
Show file tree
Hide file tree
Showing 4 changed files with 29 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 @@ -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
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
3 changes: 3 additions & 0 deletions suite/cstest/issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7639b41

Please sign in to comment.