From f3f4c68ba4f07e1edb1db70969af74d149ff981b Mon Sep 17 00:00:00 2001 From: tuz358 Date: Thu, 8 Mar 2018 11:39:03 +0900 Subject: [PATCH] Add mov_r32_rm32(0x8b) instruction --- include/instructions.h | 1 + instructions.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/instructions.h b/include/instructions.h index d578a62..dadcf0b 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -81,6 +81,7 @@ public: void jne_imm8(); // 0x75 void opcode_83(); // 0x83 void mov_rm32_r32(); // 0x89 + void mov_r32_rm32(); // 0x8b void nop(); // 0x90 void xchg_eax_r32(); // 0x91 ~ 0x97 void mov_eax_imm32(); // 0xb8 diff --git a/instructions.cpp b/instructions.cpp index d258d7b..12df674 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -75,6 +75,7 @@ void Instructions::init_instructions(){ this->instructions[0x75] = &Instructions::jne_imm8; this->instructions[0x83] = &Instructions::opcode_83; this->instructions[0x89] = &Instructions::mov_rm32_r32; + this->instructions[0x8b] = &Instructions::mov_r32_rm32; this->instructions[0x90] = &Instructions::nop; for(int i=0;i<7;i++){ this->instructions[0x91+i] = &Instructions::xchg_eax_r32; @@ -982,6 +983,56 @@ void Instructions::mov_rm32_r32(){ } } +void Instructions::mov_r32_rm32(){ + //printf("mov_r32_rm32 called.\n"); + uint32_t addr, dst, imm32; + uint8_t imm8; + + this->modrm = memory.read_uint8(this->eip); + this->calc_modrm(); + + switch (this->mod) { + case 0: + // mov R, [M] + // addr : M + this->eip++; + addr = this->registers[this->M]; + // dst : data of [M] + dst = memory.read_uint32(addr); + this->registers[this->R] = dst; + break; + case 1: + // mov R, [M+imm8] + this->eip++; + imm8 = memory.read_uint8(this->eip); + // addr : M + addr = this->registers[this->M]; + // dst : data of [M+imm8] + dst = memory.read_uint32(addr + imm8); + this->registers[this->R] = dst; + this->eip++; + break; + case 2: + // mov R, [M+imm32] + this->eip++; + imm32 = memory.read_uint32(this->eip); + imm32 = swap_endian32(imm32); + // addr : M + addr = this->registers[this->M]; + // dst : data of [M+imm32] + dst = memory.read_uint32(addr + imm32); + this->registers[this->R] = dst; + this->eip += 4; + break; + default: + // case mod == 3 + // mov R, M + this->eip++; + this->registers[this->R] = this->registers[this->M]; + break; + } +} + void Instructions::nop(){ //printf("nop called.\n"); }