diff options
author | iximeow <me@iximeow.net> | 2019-11-28 02:24:11 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-01-12 16:10:13 -0800 |
commit | 93dc692b478920f9571631942b917eab7ba9c75c (patch) | |
tree | a8183d634f175e3cb3a7464463d3c66bc3a26b3c /src/lib.rs | |
parent | 16804307cfe6957c25c4c57dd7f0d5bd0b1f80fe (diff) |
update x86 to revised decoder trait
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 39 |
1 files changed, 34 insertions, 5 deletions
@@ -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<T: IntoIterator<Item=u8>>(bytes: T) -> Option<Self> { +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<Instruction> for InstDecoder { + fn decode<T: IntoIterator<Item=u8>>(&self, bytes: T) -> Option<Instruction> { let mut instr = Instruction::invalid(); match decode_one(bytes, &mut instr) { Some(_) => Some(instr), None => None } } - fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()> { - decode_one(bytes, self) + fn decode_into<T: IntoIterator<Item=u8>>(&self, instr: &mut Instruction, bytes: T) -> Option<()> { + decode_one(bytes, instr) } } |