From 10d45e5c9ee0f676665a8a5bbbae7b462137865e Mon Sep 17 00:00:00 2001 From: tuz358 Date: Tue, 6 Mar 2018 10:51:16 +0900 Subject: [PATCH] Add or_r32_rm32(0x0b) instruction --- include/instructions.h | 1 + instructions.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/instructions.h b/include/instructions.h index 6cefbd6..cbd5aab 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -31,6 +31,7 @@ public: void add_r32_rm32(); // 0x03 void add_eax_imm32(); // 0x05 void or_rm32_r32(); // 0x09 + void or_r32_rm32(); // 0x0b void xor_rm32_r32(); // 0x31 void inc_eax(); // 0x40 void inc_ecx(); // 0x41 diff --git a/instructions.cpp b/instructions.cpp index d949d54..89c609e 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -24,6 +24,7 @@ void Instructions::init_instructions(){ this->instructions[0x03] = &Instructions::add_r32_rm32; this->instructions[0x05] = &Instructions::add_eax_imm32; this->instructions[0x09] = &Instructions::or_rm32_r32; + this->instructions[0x0b] = &Instructions::or_r32_rm32; this->instructions[0x31] = &Instructions::xor_rm32_r32; this->instructions[0x40] = &Instructions::inc_eax; this->instructions[0x41] = &Instructions::inc_ecx; @@ -254,6 +255,56 @@ void Instructions::or_rm32_r32(){ } } +void Instructions::or_r32_rm32(){ + //printf("or_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: + // or 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: + // or 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: + // or 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); // error + this->registers[this->R] |= dst; + this->eip += 4; + break; + default: + // case mod == 3 + // or R, M + this->eip++; + this->registers[this->R] |= this->registers[this->M]; + break; + } +} + void Instructions::xor_rm32_r32(){ //printf("xor_rm32_r32 called.\n"); uint32_t addr, dst, imm32;