MCPcopy Create free account
hub / github.com/capstone-engine/capstone / readOpcode

Function readOpcode

arch/X86/X86DisassemblerDecoder.c:765–882  ·  view source on GitHub ↗

* readOpcode - Reads the opcode (excepting the ModR/M byte in the case of * extended or escape opcodes). * * @param insn - The instruction whose opcode is to be read. * @return - 0 if the opcode could be read successfully; nonzero otherwise. */

Source from the content-addressed store, hash-verified

763 * @return - 0 if the opcode could be read successfully; nonzero otherwise.
764 */
765static int readOpcode(struct InternalInstruction* insn)
766{
767 uint8_t current;
768
769 // dbgprintf(insn, "readOpcode()");
770
771 insn->opcodeType = ONEBYTE;
772
773 if (insn->vectorExtensionType == TYPE_EVEX) {
774 switch (mmFromEVEX2of4(insn->vectorExtensionPrefix[1])) {
775 default:
776 // dbgprintf(insn, "Unhandled mm field for instruction (0x%hhx)",
777 // mmFromEVEX2of4(insn->vectorExtensionPrefix[1]));
778 return -1;
779 case VEX_LOB_0F:
780 insn->opcodeType = TWOBYTE;
781 return consumeByte(insn, &insn->opcode);
782 case VEX_LOB_0F38:
783 insn->opcodeType = THREEBYTE_38;
784 return consumeByte(insn, &insn->opcode);
785 case VEX_LOB_0F3A:
786 insn->opcodeType = THREEBYTE_3A;
787 return consumeByte(insn, &insn->opcode);
788 }
789 } else if (insn->vectorExtensionType == TYPE_VEX_3B) {
790 switch (mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1])) {
791 default:
792 // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)",
793 // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1]));
794 return -1;
795 case VEX_LOB_0F:
796 //insn->twoByteEscape = 0x0f;
797 insn->opcodeType = TWOBYTE;
798 return consumeByte(insn, &insn->opcode);
799 case VEX_LOB_0F38:
800 //insn->twoByteEscape = 0x0f;
801 insn->opcodeType = THREEBYTE_38;
802 return consumeByte(insn, &insn->opcode);
803 case VEX_LOB_0F3A:
804 //insn->twoByteEscape = 0x0f;
805 insn->opcodeType = THREEBYTE_3A;
806 return consumeByte(insn, &insn->opcode);
807 }
808 } else if (insn->vectorExtensionType == TYPE_VEX_2B) {
809 //insn->twoByteEscape = 0x0f;
810 insn->opcodeType = TWOBYTE;
811 return consumeByte(insn, &insn->opcode);
812 } else if (insn->vectorExtensionType == TYPE_XOP) {
813 switch (mmmmmFromXOP2of3(insn->vectorExtensionPrefix[1])) {
814 default:
815 // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)",
816 // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1]));
817 return -1;
818 case XOP_MAP_SELECT_8:
819 insn->opcodeType = XOP8_MAP;
820 return consumeByte(insn, &insn->opcode);
821 case XOP_MAP_SELECT_9:
822 insn->opcodeType = XOP9_MAP;

Callers 1

decodeInstructionFunction · 0.85

Calls 2

consumeByteFunction · 0.85
readModRMFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…