Skip to content

Commit

Permalink
Assemble the memory operand [0x0] correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpuchert authored and radare committed Feb 6, 2015
1 parent 95ee95f commit 4c0dd46
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libr/asm/p/asm_x86_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,9 @@ static int write_asm(ut8 *data, Opcode *opcode_ptr, Operand *operands) {
if (regmem_op->scale[0] == 1 && regmem_op->scale[1] == 0 && regmem_op->regs[0] != 4) {
rm = regmem_op->regs[0];
}
else if (regmem_op->scale[0] == 0) { // Special case: [0x0]
rm = 5;
}
else { // Otherwise, we need a SIB byte
if (regmem_op->scale[1] == 0) {
if (regmem_op->scale[0] != 1)
Expand All @@ -873,15 +876,16 @@ static int write_asm(ut8 *data, Opcode *opcode_ptr, Operand *operands) {
if (mod != 3 && rm == 4)
data[l++] = make_SIB(scale, index, base);

if (regmem_op->type & OT_MEMORY && regmem_op->offset) {
if (regmem_op->type & OT_MEMORY && (mod > 0 || (mod == 0 && rm == 5))) {
if (mod == 1) {
data[l++] = *(ut8 *)&regmem_op->offset;
}
else {
data[l++] = *((ut8 *)&regmem_op->offset + 0);
data[l++] = *((ut8 *)&regmem_op->offset + 1);
data[l++] = *((ut8 *)&regmem_op->offset + 2);
data[l++] = *((ut8 *)&regmem_op->offset + 3);
ut8 *offset_ptr = (ut8 *)&regmem_op->offset;
data[l++] = *(offset_ptr + 0);
data[l++] = *(offset_ptr + 1);
data[l++] = *(offset_ptr + 2);
data[l++] = *(offset_ptr + 3);
}
}
}
Expand Down

0 comments on commit 4c0dd46

Please sign in to comment.