Skip to content

Commit

Permalink
x86: handle MOV32cr, MOV32dr, MOV32rc, MOV32rd
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Apr 24, 2014
1 parent 2a9c0e0 commit 0902bf2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arch/X86/X86Disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ static void update_pub_insn(cs_insn_flat *pub, InternalInstruction *inter)
pub->x86.disp_size = inter->displacementSize;
pub->x86.imm_size = inter->immediateSize;

pub->x86.modrm = inter->modRM;
pub->x86.modrm = inter->orgModRM;
pub->x86.sib = inter->sib;
pub->x86.disp = inter->displacement;

Expand Down
8 changes: 8 additions & 0 deletions arch/X86/X86DisassemblerDecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@ static int readOpcode(struct InternalInstruction* insn)
if (consumeByte(insn, &current))
return -1;

// save this first byte for MOV32cr, MOV32dr, MOV32rc, MOV32rd
insn->firstByte = current;

if (current == 0x0f) {
// dbgprintf(insn, "Found a two-byte escape prefix (0x%hhx)", current);

Expand Down Expand Up @@ -1314,6 +1317,11 @@ static int readModRM(struct InternalInstruction* insn)
if (consumeByte(insn, &insn->modRM))
return -1;
insn->consumedModRM = TRUE;
insn->orgModRM = insn->modRM;
// handle MOV32cr, MOV32dr, MOV32rc, MOV32rd by pretending they have MRM.mod = 0xC
if ((insn->firstByte == 0x0f && insn->mode == MODE_32BIT && insn->opcodeType == TWOBYTE) &&
(insn->opcode >= 0x20 && insn->opcode <= 0x23 ))
insn->modRM |= 0xC0;

mod = modFromModRM(insn->modRM);
rm = rmFromModRM(insn->modRM);
Expand Down
4 changes: 4 additions & 0 deletions arch/X86/X86DisassemblerDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ typedef struct InternalInstruction {
BOOL consumedModRM;
uint8_t modRM;

// special data to handle MOV32cr, MOV32dr, MOV32rc, MOV32rd
uint8_t firstByte; // save the first byte in stream
uint8_t orgModRM; // save original modRM because we will modify modRM

/* The SIB byte, used for more complex 32- or 64-bit memory operands */
BOOL consumedSIB;
uint8_t sib;
Expand Down

0 comments on commit 0902bf2

Please sign in to comment.