From 79cd0c80a858448713aedd3d607dc363be891d8c Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 23 May 2020 21:02:32 -0700 Subject: fix important memory decode error in long mode add tests for modrm/sib decoding, xsave extensions --- src/long_mode/mod.rs | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs index 58d4c57..146a535 100644 --- a/src/long_mode/mod.rs +++ b/src/long_mode/mod.rs @@ -4906,14 +4906,28 @@ fn read_sib>(bytes_iter: &mut T, instr: &mut Instruction, m OperandSpec::DispU32 } else { - let reg = RegSpec::from_parts(0b100, instr.prefixes.rex().x(), addr_width); - instr.modrm_mmm = reg; - - if disp == 0 { - OperandSpec::Deref + if instr.prefixes.rex().x() { + let reg = RegSpec::from_parts(0b100, true, addr_width); + instr.sib_index = reg; + let scale = 1u8 << (sibbyte >> 6); + instr.scale = scale; + + if disp == 0 { + OperandSpec::RegIndexBaseScale + } else { + instr.disp = disp as i64 as u64; + OperandSpec::RegIndexBaseScaleDisp + } } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegDisp + let reg = RegSpec::from_parts(0b101, instr.prefixes.rex().b(), addr_width); + instr.modrm_mmm = reg; + + if disp == 0 { + OperandSpec::Deref + } else { + instr.disp = disp as i64 as u64; + OperandSpec::RegDisp + } } } } else { @@ -4952,11 +4966,25 @@ fn read_sib>(bytes_iter: &mut T, instr: &mut Instruction, m }; if ((sibbyte >> 3) & 7) == 0b100 { - if disp == 0 { - OperandSpec::Deref + if instr.prefixes.rex().x() { + let reg = RegSpec::from_parts(0b100, true, addr_width); + instr.sib_index = reg; + let scale = 1u8 << (sibbyte >> 6); + instr.scale = scale; + + if disp == 0 { + OperandSpec::RegIndexBaseScale + } else { + instr.disp = disp as i64 as u64; + OperandSpec::RegIndexBaseScaleDisp + } } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegDisp + if disp == 0 { + OperandSpec::Deref + } else { + instr.disp = disp as i64 as u64; + OperandSpec::RegDisp + } } } else { instr.sib_index = RegSpec::from_parts((sibbyte >> 3) & 7, instr.prefixes.rex().x(), addr_width); -- cgit v1.1