diff --git a/instructions.cpp b/instructions.cpp index b3ad5a9..c560b1a 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -297,372 +297,31 @@ void Instructions::template_eax_imm32(int calc_type){ } } -void Instructions::add_rm32_r32(){ - //printf("add_rm32_r32 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: - // add [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst + this->registers[this->R]); - break; - case 1: - // add [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst + this->registers[this->R]); - this->eip++; - break; - case 2: - // add [M+imm32], R - 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); - memory.write_uint32(addr, dst + this->registers[this->R]); - this->eip += 4; - break; - default: - // case mod == 3 - // add M, R - this->eip++; - this->registers[this->M] += this->registers[this->R]; - break; - } -} - -void Instructions::add_r32_rm32(){ this->template_r32_rm32(ADD); } +void Instructions::add_rm32_r32() { this->template_rm32_r32(ADD); } +void Instructions::add_r32_rm32() { this->template_r32_rm32(ADD); } void Instructions::add_eax_imm32(){ this->template_eax_imm32(ADD); } -void Instructions::or_rm32_r32(){ - //printf("or_rm32_r32 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 [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst | this->registers[this->R]); - break; - case 1: - // or [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst | this->registers[this->R]); - this->eip++; - break; - case 2: - // or [M+imm32], R - 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); - memory.write_uint32(addr, dst | this->registers[this->R]); - this->eip += 4; - break; - default: - // case mod == 3 - // or M, R - this->eip++; - this->registers[this->M] |= this->registers[this->R]; - break; - } -} - -void Instructions::or_r32_rm32(){ this->template_r32_rm32(OR); } +void Instructions::or_rm32_r32() { this->template_rm32_r32(OR); } +void Instructions::or_r32_rm32() { this->template_r32_rm32(OR); } void Instructions::or_eax_imm32(){ this->template_eax_imm32(OR); } -void Instructions::adc_rm32_r32(){ - //printf("adc_rm32_r32 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: - // adc [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst + this->registers[this->R] + get_flag(CF)); - break; - case 1: - // adc [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst + this->registers[this->R] + get_flag(CF)); - this->eip++; - break; - case 2: - // adc [M+imm32], R - 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); - memory.write_uint32(addr, dst + this->registers[this->R] + get_flag(CF)); - this->eip += 4; - break; - default: - // case mod == 3 - // adc M, R - this->eip++; - this->registers[this->M] += this->registers[this->R] + get_flag(CF); - break; - } -} - -void Instructions::adc_r32_rm32(){ this->template_r32_rm32(ADC); } +void Instructions::adc_rm32_r32() { this->template_rm32_r32(ADC); } +void Instructions::adc_r32_rm32() { this->template_r32_rm32(ADC); } void Instructions::adc_eax_imm32(){ this->template_eax_imm32(ADC); } -void Instructions::sbb_rm32_r32(){ - //printf("sbb_rm32_r32 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: - // sbb [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst - (this->registers[this->R] + get_flag(CF))); - break; - case 1: - // sbb [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst - (this->registers[this->R] + get_flag(CF))); - this->eip++; - break; - case 2: - // sbb [M+imm32], R - 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); - memory.write_uint32(addr, dst - (this->registers[this->R] + get_flag(CF))); - this->eip += 4; - break; - default: - // case mod == 3 - // sbb M, R - this->eip++; - this->registers[this->M] -= this->registers[this->R] + get_flag(CF); - break; - } -} - -void Instructions::sbb_r32_rm32(){ this->template_r32_rm32(SBB); } +void Instructions::sbb_rm32_r32() { this->template_rm32_r32(SBB); } +void Instructions::sbb_r32_rm32() { this->template_r32_rm32(SBB); } void Instructions::sbb_eax_imm32(){ this->template_eax_imm32(SBB); } -void Instructions::and_rm32_r32(){ - //printf("and_rm32_r32 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: - // and [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst & this->registers[this->R]); - break; - case 1: - // and [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst & this->registers[this->R]); - this->eip++; - break; - case 2: - // and [M+imm32], R - 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); - memory.write_uint32(addr, dst & this->registers[this->R]); - this->eip += 4; - break; - default: - // case mod == 3 - // and M, R - this->eip++; - this->registers[this->M] &= this->registers[this->R]; - break; - } -} - +void Instructions::and_rm32_r32() { this->template_rm32_r32(AND); } void Instructions::and_r32_rm32() { this->template_r32_rm32(AND); } void Instructions::and_eax_imm32(){ this->template_eax_imm32(AND); } -void Instructions::sub_rm32_r32(){ - //printf("sub_rm32_r32 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: - // sub [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst - this->registers[this->R]); - break; - case 1: - // sub [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst - this->registers[this->R]); - break; - case 2: - // sub [M+imm32], R - 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); - memory.write_uint32(addr, dst - this->registers[this->R]); - this->eip += 4; - break; - default: - // case mod == 3 - // sub M, R - this->eip++; - this->registers[this->M] -= this->registers[this->R]; - break; - } -} - +void Instructions::sub_rm32_r32() { this->template_rm32_r32(SUB); } void Instructions::sub_r32_rm32() { this->template_r32_rm32(SUB); } void Instructions::sub_eax_imm32(){ this->template_eax_imm32(SUB); } -void Instructions::xor_rm32_r32(){ - //printf("xor_rm32_r32 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: - // xor [M], R - // addr : M - this->eip++; - addr = this->registers[this->M]; - // dst : data of [M] - dst = memory.read_uint32(addr); - memory.write_uint32(addr, dst ^ this->registers[this->R]); - break; - case 1: - // xor [M+imm8], R - 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); - memory.write_uint32(addr + imm8, dst ^ this->registers[this->R]); - break; - case 2: - // xor [M+imm32], R - 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); - memory.write_uint32(addr, dst ^ this->registers[this->R]); - this->eip += 4; - break; - default: - // case mod == 3 - // xor M, R - this->eip++; - this->registers[this->M] ^= this->registers[this->R]; - break; - } -} - +void Instructions::xor_rm32_r32() { this->template_rm32_r32(XOR); } void Instructions::xor_r32_rm32() { this->template_r32_rm32(XOR); } void Instructions::xor_eax_imm32(){ this->template_eax_imm32(XOR); }