Skip to content

Commit

Permalink
x86: add immediate operand (1) for SHL/SHR/ROR/ROL/SAR/SAL in detail …
Browse files Browse the repository at this point in the history
…mode & Intel syntax
  • Loading branch information
aquynh committed May 19, 2014
1 parent f338657 commit 6456481
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 14 deletions.
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64InstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion arch/PowerPC/PPCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arch/PowerPC/PPCInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion arch/Sparc/SparcInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arch/Sparc/SparcInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion arch/SystemZ/SystemZInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arch/SystemZ/SystemZInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
73 changes: 72 additions & 1 deletion arch/X86/X86Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion arch/X86/X86Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6456481

Please sign in to comment.