Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'spec> { /* private fields */ }
Expand description

Decoder for a compiled SLEIGH specification.

Implementations§

Source§

impl<'spec> Decoder<'spec>

Source

pub fn new(spec: &'spec CompiledSpec) -> Self

Creates a decoder for spec.

Source

pub fn decode_one<'bytes>( &self, addr: u64, bytes: &'bytes [u8], context: &ContextBytes, ) -> Result<Instruction<'spec, 'bytes>, DecodeError>

Decodes one instruction at addr from bytes.

§Errors

Returns a DecodeError: NoMatch if no constructor matches the bytes (including when they run out mid-instruction), InvalidContext if context is not this specification’s context length, InvalidAction if a disassembly action divides by zero or shifts past the word width, and AmbiguousMatch if several constructors match and none is more specific.

Decoding is pure: context is read, never written. An instruction that wants to change it for later instructions says so through Instruction::context_effects, and ContextDatabase is the opt-in store that feeds those back.

let decoder = Decoder::new(&spec);
let context = spec.new_context();

// `bytes` is the stream from `addr` on; only what the instruction
// needs is read, and the rest is left for the next call.
let instruction = decoder.decode_one(0x1000, &[1, 1, 1], &context)?;
assert_eq!(instruction.display()?, "inc");
assert_eq!(instruction.len(), 1);
assert_eq!(instruction.next_address(), 0x1001);
Source

pub fn decode_one_shaped<'bytes>( &self, addr: u64, bytes: &'bytes [u8], context: &ContextBytes, ) -> Result<(Instruction<'spec, 'bytes>, Shape), DecodeError>

decode_one, also reporting the instruction’s Shape: which bits chose its constructors and which fields are its parameters. Costs a little more than a plain decode.

Two encodings of one shape — equal after masking, whatever their parameters — decode to the same constructors and operand layout under the same context, so per-encoding work can be shared across them; see Shape.

Auto Trait Implementations§

§

impl<'spec> Freeze for Decoder<'spec>

§

impl<'spec> RefUnwindSafe for Decoder<'spec>

§

impl<'spec> Send for Decoder<'spec>

§

impl<'spec> Sync for Decoder<'spec>

§

impl<'spec> Unpin for Decoder<'spec>

§

impl<'spec> UnsafeUnpin for Decoder<'spec>

§

impl<'spec> UnwindSafe for Decoder<'spec>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.