diff --git a/arch/AArch64/AArch64InstPrinter.c b/arch/AArch64/AArch64InstPrinter.c index 8db1887d9a..edcb8b9cd4 100644 --- a/arch/AArch64/AArch64InstPrinter.c +++ b/arch/AArch64/AArch64InstPrinter.c @@ -850,7 +850,7 @@ static void printVectorList(MCInst *MI, unsigned OpNum, #define PRINT_ALIAS_INSTR #include "AArch64GenAsmWriter.inc" -void AArch64_post_printer(csh handle, cs_insn *flat_insn, char *insn_asm) +void AArch64_post_printer(csh handle, cs_insn *flat_insn, char *insn_asm, MCInst *mci) { if (((cs_struct *)handle)->detail != CS_OPT_ON) return; diff --git a/arch/AArch64/AArch64InstPrinter.h b/arch/AArch64/AArch64InstPrinter.h index 961c1721d1..814793cc8e 100644 --- a/arch/AArch64/AArch64InstPrinter.h +++ b/arch/AArch64/AArch64InstPrinter.h @@ -23,6 +23,6 @@ void AArch64_printInst(MCInst *MI, SStream *O, void *); -void AArch64_post_printer(csh handle, cs_insn *pub_insn, char *insn_asm); +void AArch64_post_printer(csh handle, cs_insn *pub_insn, char *insn_asm, MCInst *mci); #endif diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c index 162a4c2faa..7e92e1ca12 100644 --- a/arch/ARM/ARMInstPrinter.c +++ b/arch/ARM/ARMInstPrinter.c @@ -233,7 +233,7 @@ static name_map insn_update_flgs[] = { { ARM_INS_UMULL, "umulls" }, }; -void ARM_post_printer(csh ud, cs_insn *insn, char *insn_asm) +void ARM_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) { if (((cs_struct *)ud)->detail != CS_OPT_ON) return; diff --git a/arch/ARM/ARMInstPrinter.h b/arch/ARM/ARMInstPrinter.h index 6d6700c1a6..e422fce15c 100644 --- a/arch/ARM/ARMInstPrinter.h +++ b/arch/ARM/ARMInstPrinter.h @@ -22,7 +22,7 @@ #include "../../SStream.h" void ARM_printInst(MCInst *MI, SStream *O, void *Info); -void ARM_post_printer(csh handle, cs_insn *pub_insn, char *mnem); +void ARM_post_printer(csh handle, cs_insn *pub_insn, char *mnem, MCInst *mci); // setup handle->get_regname void ARM_getRegName(cs_struct *handle, int value); diff --git a/arch/PowerPC/PPCInstPrinter.c b/arch/PowerPC/PPCInstPrinter.c index 84d98caaf3..784e654984 100644 --- a/arch/PowerPC/PPCInstPrinter.c +++ b/arch/PowerPC/PPCInstPrinter.c @@ -54,7 +54,7 @@ static void set_mem_access(MCInst *MI, bool status) } } -void PPC_post_printer(csh ud, cs_insn *insn, char *insn_asm) +void PPC_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) { if (((cs_struct *)ud)->detail != CS_OPT_ON) return; diff --git a/arch/PowerPC/PPCInstPrinter.h b/arch/PowerPC/PPCInstPrinter.h index 7699d7981f..59d38b0108 100644 --- a/arch/PowerPC/PPCInstPrinter.h +++ b/arch/PowerPC/PPCInstPrinter.h @@ -10,6 +10,6 @@ void PPC_printInst(MCInst *MI, SStream *O, void *Info); -void PPC_post_printer(csh ud, cs_insn *insn, char *insn_asm); +void PPC_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci); #endif diff --git a/arch/Sparc/SparcInstPrinter.c b/arch/Sparc/SparcInstPrinter.c index 5499216a45..b5e8498a0d 100644 --- a/arch/Sparc/SparcInstPrinter.c +++ b/arch/Sparc/SparcInstPrinter.c @@ -52,7 +52,7 @@ static void set_mem_access(MCInst *MI, bool status) } } -void Sparc_post_printer(csh ud, cs_insn *insn, char *insn_asm) +void Sparc_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) { if (((cs_struct *)ud)->detail != CS_OPT_ON) return; diff --git a/arch/Sparc/SparcInstPrinter.h b/arch/Sparc/SparcInstPrinter.h index 4e6a5cef37..5fbabd3b39 100644 --- a/arch/Sparc/SparcInstPrinter.h +++ b/arch/Sparc/SparcInstPrinter.h @@ -10,6 +10,6 @@ void Sparc_printInst(MCInst *MI, SStream *O, void *Info); -void Sparc_post_printer(csh ud, cs_insn *insn, char *insn_asm); +void Sparc_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci); #endif diff --git a/arch/SystemZ/SystemZInstPrinter.c b/arch/SystemZ/SystemZInstPrinter.c index ac1279d474..bc15f484df 100644 --- a/arch/SystemZ/SystemZInstPrinter.c +++ b/arch/SystemZ/SystemZInstPrinter.c @@ -31,7 +31,7 @@ static const char *getRegisterName(unsigned RegNo); -void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm) +void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) { /* if (((cs_struct *)ud)->detail != CS_OPT_ON) diff --git a/arch/SystemZ/SystemZInstPrinter.h b/arch/SystemZ/SystemZInstPrinter.h index 3a327ff14d..e5e1ddc390 100644 --- a/arch/SystemZ/SystemZInstPrinter.h +++ b/arch/SystemZ/SystemZInstPrinter.h @@ -10,6 +10,6 @@ void SystemZ_printInst(MCInst *MI, SStream *O, void *Info); -void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm); +void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci); #endif diff --git a/arch/X86/X86Mapping.c b/arch/X86/X86Mapping.c index 5739014ad8..edf4e64920 100644 --- a/arch/X86/X86Mapping.c +++ b/arch/X86/X86Mapping.c @@ -41573,8 +41573,79 @@ static insn_map insns[] = { // reduce x86 instructions #endif // post printer for X86. put all the hacky stuff here -void X86_post_printer(csh handle, cs_insn *insn, char *insn_asm) +void X86_post_printer(csh handle, cs_insn *insn, char *insn_asm, MCInst *mci) { +#ifndef CAPSTONE_DIET + cs_struct *ud = (cs_struct *)handle; + + if (ud->detail) { + if (ud->syntax != CS_OPT_SYNTAX_ATT) { // default syntax is Intel + // AT&T print this instruction without immediate 1? + switch (mci->Opcode) { + default: + break; + case X86_SAL8r1: + case X86_SAL16r1: + case X86_SAL32r1: + case X86_SAL64r1: + case X86_SAL8m1: + case X86_SAL16m1: + case X86_SAL32m1: + case X86_SAL64m1: + + case X86_SHL8r1: + case X86_SHL16r1: + case X86_SHL32r1: + case X86_SHL64r1: + case X86_SHL8m1: + case X86_SHL16m1: + case X86_SHL32m1: + case X86_SHL64m1: + + case X86_SHR8r1: + case X86_SHR16r1: + case X86_SHR32r1: + case X86_SHR64r1: + case X86_SHR8m1: + case X86_SHR16m1: + case X86_SHR32m1: + case X86_SHR64m1: + + case X86_SAR8r1: + case X86_SAR16r1: + case X86_SAR32r1: + case X86_SAR64r1: + case X86_SAR8m1: + case X86_SAR16m1: + case X86_SAR32m1: + case X86_SAR64m1: + + case X86_ROR8r1: + case X86_ROR16r1: + case X86_ROR32r1: + case X86_ROR64r1: + case X86_ROR8m1: + case X86_ROR16m1: + case X86_ROR32m1: + case X86_ROR64m1: + + case X86_ROL8r1: + case X86_ROL16r1: + case X86_ROL32r1: + case X86_ROL64r1: + case X86_ROL8m1: + case X86_ROL16m1: + case X86_ROL32m1: + case X86_ROL64m1: + + insn->detail->x86.operands[insn->detail->x86.op_count].type = X86_OP_IMM; + insn->detail->x86.operands[insn->detail->x86.op_count].imm = 1; + insn->detail->x86.op_count++; + break; + } + } + } +#endif } // given internal insn id, return public instruction info diff --git a/arch/X86/X86Mapping.h b/arch/X86/X86Mapping.h index 4fbeffef78..c958a2c1d0 100644 --- a/arch/X86/X86Mapping.h +++ b/arch/X86/X86Mapping.h @@ -30,7 +30,7 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id); const char *X86_insn_name(csh handle, unsigned int id); // post printer for X86. -void X86_post_printer(csh handle, cs_insn *pub_insn, char *insn_asm); +void X86_post_printer(csh handle, cs_insn *pub_insn, char *insn_asm, MCInst *mci); // return register of given instruction id // return 0 if not found diff --git a/cs.c b/cs.c index c037de56c2..05a5f1de35 100644 --- a/cs.c +++ b/cs.c @@ -278,7 +278,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI // post printer handles some corner cases (hacky) if (postprinter) - postprinter((csh)handle, insn, buffer); + postprinter((csh)handle, insn, buffer, mci); #ifndef CAPSTONE_DIET // fill in mnemonic & operands diff --git a/cs_priv.h b/cs_priv.h index 59362543b9..d3cd3e1268 100644 --- a/cs_priv.h +++ b/cs_priv.h @@ -13,7 +13,7 @@ typedef void (*Printer_t)(MCInst *MI, SStream *OS, void *info); // function to be called after Printer_t // this is the best time to gather insn's characteristics -typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem); +typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci); typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);