From 93dc692b478920f9571631942b917eab7ba9c75c Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 28 Nov 2019 02:24:11 -0800 Subject: update x86 to revised decoder trait --- src/lib.rs | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bea7698..956d4db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ mod display; use std::hint::unreachable_unchecked; -use yaxpeax_arch::{Arch, Decodable, LengthedInstruction}; +use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; #[cfg(feature="use-serde")] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] @@ -757,6 +757,7 @@ pub struct x86_64; impl Arch for x86_64 { type Address = u64; type Instruction = Instruction; + type Decoder = InstDecoder; type Operand = Operand; } @@ -770,16 +771,44 @@ impl LengthedInstruction for Instruction { } } -impl Decodable for Instruction { - fn decode>(bytes: T) -> Option { +pub struct InstDecoder { + flags: u64, +} + +impl InstDecoder { + /// Instantiates an x86_64 decoder that decodes the bare minimum of x86_64. + /// + /// Pedantic and only decodes what the spec says is well-defined, rejecting undefined sequences + /// and any instructions defined by extensions. + fn minimal() -> Self { + InstDecoder { + flags: 0, + } + } +} + +impl Default for InstDecoder { + /// Instantiates an x86_64 decoder that probably decodes what you want. + /// + /// Attempts to match real processors in interpretation of undefined sequences, and decodes any + /// instruction defined in any extension. + fn default() -> Self { + Self { + flags: 0xffffffff_ffffffff, + } + } +} + +impl Decoder for InstDecoder { + fn decode>(&self, bytes: T) -> Option { let mut instr = Instruction::invalid(); match decode_one(bytes, &mut instr) { Some(_) => Some(instr), None => None } } - fn decode_into>(&mut self, bytes: T) -> Option<()> { - decode_one(bytes, self) + fn decode_into>(&self, instr: &mut Instruction, bytes: T) -> Option<()> { + decode_one(bytes, instr) } } -- cgit v1.1