Skip to content

Commit

Permalink
Fix #16433 - Support movabs for x86_64's MOV r64, imm64 (#16527)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored Apr 11, 2020
1 parent 9079a7b commit 9227c67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libr/asm/p/asm_x86_nz.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,28 @@ static int opmov(RAsm *a, ut8 *data, const Opcode *op) {
return l;
}

// Only for MOV r64, imm64
static int opmovabs(RAsm *a, ut8 *data, const Opcode *op) {
if (!(a->bits == 64 && (op->operands[0].type & OT_GPREG) && !(op->operands[0].type & OT_MEMORY) &&
(op->operands[0].type & OT_QWORD) && (op->operands[1].type & OT_CONSTANT))) {
return -1;
}
int l = 0;
int byte_shift;
ut64 immediate;
if (op->operands[0].extended) {
data[l++] = 0x49;
} else {
data[l++] = 0x48;
}
data[l++] = 0xb8 | op->operands[0].reg;
immediate = op->operands[1].immediate * op->operands[1].sign;
for (byte_shift = 0; byte_shift < 8; byte_shift++) {
data[l++] = immediate >> (byte_shift * 8);
}
return l;
}

static int opmul(RAsm *a, ut8 *data, const Opcode *op) {
is_valid_registers (op);
int l = 0;
Expand Down Expand Up @@ -4339,6 +4361,7 @@ LookupTable oplookup[] = {
{"movsw", 0, NULL, 0x66a5, 2},
{"movzx", 0, &opmovx, 0},
{"movsx", 0, &opmovx, 0},
{"movabs", 0, &opmovabs, 0},
{"mul", 0, &opmul, 0},
{"mwait", 0, NULL, 0x0f01c9, 3},
{"neg", 0, &opneg, 0},
Expand Down
2 changes: 2 additions & 0 deletions test/new/db/asm/x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ aB "mov qword[r12], rsp" 49892424
aB "mov qword[r8 + 0x20], rax" 49894020
aB "mov r12, qword[r12]" 4d8b2424
a "mov eax,r12d" 4489e0
ad "movabs rax, 0xdeadbeef" 48b8efbeadde00000000
ad "movabs r12, 1" 49bc0100000000000000
a "inc al" fec0
a "inc BYTE PTR [r12]" 41fe0424
a "inc BYTE PTR [rbx+0x18]" fe4318
Expand Down

0 comments on commit 9227c67

Please sign in to comment.