Skip to content

Commit

Permalink
Merge pull request #2 from obs1dium/next
Browse files Browse the repository at this point in the history
move modrm, sib, disp back to cs_x86
  • Loading branch information
bughoho committed Nov 11, 2015
2 parents d3d3014 + 89f3cdb commit 22a60ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
12 changes: 6 additions & 6 deletions arch/X86/X86Disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,15 @@ static void update_pub_insn(cs_insn *pub, InternalInstruction *inter, uint8_t *p

pub->detail->x86.addr_size = inter->addressSize;

pub->detail->x86.encoding.modrm = inter->orgModRM;
pub->detail->x86.modrm = inter->orgModRM;
pub->detail->x86.encoding.modrm_offset = inter->modRMOffset;

pub->detail->x86.encoding.sib = inter->sib;
pub->detail->x86.encoding.sib_index = x86_map_sib_index(inter->sibIndex);
pub->detail->x86.encoding.sib_scale = inter->sibScale;
pub->detail->x86.encoding.sib_base = x86_map_sib_base(inter->sibBase);
pub->detail->x86.sib = inter->sib;
pub->detail->x86.sib_index = x86_map_sib_index(inter->sibIndex);
pub->detail->x86.sib_scale = inter->sibScale;
pub->detail->x86.sib_base = x86_map_sib_base(inter->sibBase);

pub->detail->x86.encoding.disp = inter->displacement;
pub->detail->x86.disp = inter->displacement;
pub->detail->x86.encoding.disp_offset = inter->displacementOffset;
pub->detail->x86.encoding.disp_size = inter->displacementSize;

Expand Down
29 changes: 16 additions & 13 deletions include/capstone/x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,10 @@ typedef struct cs_x86_op {
typedef struct cs_x86_encoding {
// ModR/M offset, or 0 when irrelevant
uint8_t modrm_offset;
// ModR/M byte
uint8_t modrm;

// SIB value, or 0 when irrelevant.
uint8_t sib;
// SIB index register, or X86_REG_INVALID when irrelevant.
x86_reg sib_index;
// SIB scale, only applicable if sib_index is valid.
int8_t sib_scale;
// SIB base register, or X86_REG_INVALID when irrelevant.
x86_reg sib_base;

// Displacement offset, or 0 when irrelevant.
uint8_t disp_offset;
uint8_t disp_size;
// Displacement value
int64_t disp;

// Immediate offset, or 0 when irrelevant.
uint8_t imm_offset;
Expand Down Expand Up @@ -308,6 +295,22 @@ typedef struct cs_x86 {
// Address size, which can be overrided with above prefix[5].
uint8_t addr_size;

// ModR/M byte
uint8_t modrm;

// SIB value, or 0 when irrelevant.
uint8_t sib;

// Displacement value, valid if encoding.disp_offset != 0
int64_t disp;

// SIB index register, or X86_REG_INVALID when irrelevant.
x86_reg sib_index;
// SIB scale, only applicable if sib_index is valid.
int8_t sib_scale;
// SIB base register, or X86_REG_INVALID when irrelevant.
x86_reg sib_base;

// XOP Code Condition
x86_xop_cc xop_cc;

Expand Down
18 changes: 9 additions & 9 deletions tests/test_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ static void print_insn_detail(csh ud, cs_mode mode, cs_insn *ins)
printf("\trex: 0x%x\n", x86->rex);

printf("\taddr_size: %u\n", x86->addr_size);
printf("\tmodrm: 0x%x\n", x86->encoding.modrm);
printf("\tdisp: 0x%"PRIx64 "\n", x86->encoding.disp);
printf("\tmodrm: 0x%x\n", x86->modrm);
printf("\tdisp: 0x%"PRIx64 "\n", x86->disp);

// SIB is not available in 16-bit mode
if ((mode & CS_MODE_16) == 0) {
printf("\tsib: 0x%x\n", x86->encoding.sib);
if (x86->encoding.sib_base != X86_REG_INVALID)
printf("\t\tsib_base: %s\n", cs_reg_name(handle, x86->encoding.sib_base));
if (x86->encoding.sib_index != X86_REG_INVALID)
printf("\t\tsib_index: %s\n", cs_reg_name(handle, x86->encoding.sib_index));
if (x86->encoding.sib_scale != 0)
printf("\t\tsib_scale: %d\n", x86->encoding.sib_scale);
printf("\tsib: 0x%x\n", x86->sib);
if (x86->sib_base != X86_REG_INVALID)
printf("\t\tsib_base: %s\n", cs_reg_name(handle, x86->sib_base));
if (x86->sib_index != X86_REG_INVALID)
printf("\t\tsib_index: %s\n", cs_reg_name(handle, x86->sib_index));
if (x86->sib_scale != 0)
printf("\t\tsib_scale: %d\n", x86->sib_scale);
}

// XOP code condition
Expand Down

0 comments on commit 22a60ae

Please sign in to comment.