diff --git a/MCInst.c b/MCInst.c index d0bdc68e..7b97ed00 100644 --- a/MCInst.c +++ b/MCInst.c @@ -17,12 +17,17 @@ void MCInst_Init(MCInst *inst) { +#if 0 + // this loop consumes 2% of the whole disasm work unsigned int i; - for (i = 0; i < 48; i++) { inst->Operands[i].Kind = kInvalid; inst->Operands[i].ImmVal = 0; } +#endif + // unnecessary to initialize in loop . its expensive and inst->size shuold be honored + inst->Operands[0].Kind = kInvalid; + inst->Operands[0].ImmVal = 0; inst->Opcode = 0; inst->OpcodePub = 0; diff --git a/arch/X86/X86DisassemblerDecoder.c b/arch/X86/X86DisassemblerDecoder.c index 35d93046..22acab36 100644 --- a/arch/X86/X86DisassemblerDecoder.c +++ b/arch/X86/X86DisassemblerDecoder.c @@ -1147,13 +1147,13 @@ static int getID(struct InternalInstruction *insn) } } - if (getIDWithAttrMask(&instructionID, insn, attrMask)) { - return -1; - } - /* The following clauses compensate for limitations of the tables. */ if (insn->mode != MODE_64BIT && insn->vectorExtensionType != TYPE_NO_VEX_XOP) { + if (getIDWithAttrMask(&instructionID, insn, attrMask)) { + return -1; + } + /* * The tables can't distinquish between cases where the W-bit is used to * select register size and cases where its a required part of the opcode. @@ -1218,6 +1218,9 @@ static int getID(struct InternalInstruction *insn) return 0; } + if (getIDWithAttrMask(&instructionID, insn, attrMask)) { + return -1; + } if ((insn->mode == MODE_16BIT || insn->hasOpSize) && !(attrMask & ATTR_OPSIZE)) { @@ -1438,15 +1441,15 @@ static int readModRM(struct InternalInstruction* insn) if (insn->consumedModRM) return 0; - insn->modRMOffset = (uint8_t)(insn->readerCursor - insn->startLocation); + insn->modRMOffset = (uint8_t)(insn->readerCursor - insn->startLocation); if (consumeByte(insn, &insn->modRM)) return -1; insn->consumedModRM = true; - // save original ModRM for later reference - insn->orgModRM = insn->modRM; + // save original ModRM for later reference + insn->orgModRM = insn->modRM; // handle MOVcr, MOVdr, MOVrc, MOVrd by pretending they have MRM.mod = 3 if ((insn->firstByte == 0x0f && insn->opcodeType == TWOBYTE) && diff --git a/cs.c b/cs.c index e1669523..f67ddcb5 100644 --- a/cs.c +++ b/cs.c @@ -554,6 +554,15 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI postprinter((csh)handle, insn, buffer, mci); #ifndef CAPSTONE_DIET + char *tab = strchr (buffer, '\t'); + if (tab) { + *tab = 0; + } + strncpy (insn->mnemonic, buffer, sizeof (insn->mnemonic) - 1); + if (tab) { + strcpy (insn->op_str, tab + 1); + } +#if 0 // fill in mnemonic & operands // find first space or tab mnem = insn->mnemonic; @@ -568,6 +577,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI } *mnem = '\0'; +#endif // we might have customized mnemonic if (handle->mnem_list) { @@ -588,6 +598,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI } } +#if 0 // copy @op_str if (*sp) { // find the next non-space char @@ -598,6 +609,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI } else insn->op_str[0] = '\0'; #endif +#endif } // how many bytes will we skip when encountering data (CS_OPT_SKIPDATA)?