From 7a45abbef5a1158e3ab676e666cbe69a2d57e36a Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 30 Mar 2019 20:02:20 -0700 Subject: fix incorrectly showing decode errors, add more system instructions --- src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index d693ee4..d0dbba3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -316,6 +316,13 @@ pub enum Opcode { RDTSC, RDMSR, RDPMC, + SLDT, + STR, + LLDT, + LTR, + VERR, + VERW, + JMPE, Invalid } #[derive(Debug)] @@ -2336,7 +2343,45 @@ fn read_operands>( Ok(()) } OperandCode::ModRM_0x0f00 => { - Ok(()) + let modrm = match bytes_iter.next() { + Some(b) => b, + None => return Err("Out of bytes".to_string()) + }; + *length += 1; + let (mod_bits, r, m) = octets_of(modrm); + if r == 0 { + instruction.opcode = Opcode::SLDT; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 1 { + instruction.opcode = Opcode::STR; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 2 { + instruction.opcode = Opcode::LLDT; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 3 { + instruction.opcode = Opcode::LTR; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 4 { + instruction.opcode = Opcode::VERR; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 5 { + instruction.opcode = Opcode::VERW; + instruction.operands[1] = Operand::Nothing; + read_E(bytes_iter, &instruction.prefixes, m, mod_bits, 2, &mut instruction.operands[0], length) + } else if r == 6 { + instruction.opcode = Opcode::JMPE; + instruction.operands = [Operand::Nothing, Operand::Nothing]; + Ok(()) + } else if r == 7 { + Err("Invalid modr/m bits".to_owned()) + } else { + unreachable!("r <= 8"); + } } OperandCode::ModRM_0x0f01 => { let opwidth = imm_width_from_prefixes_64(SizeCode::vq, &instruction.prefixes); @@ -2599,6 +2644,8 @@ fn read_operands>( Ok(()) } _ => { + instruction.operands = [Operand::Nothing, Operand::Nothing]; + instruction.opcode = Opcode::Invalid; // use std::hint::unreachable_unchecked; Err(format!("unsupported operand code: {:?}", operand_code)) // unsafe { unreachable_unchecked(); } -- cgit v1.1